From fafb582ae28cf41ae93d7a5c74afa8d223c00ec1 Mon Sep 17 00:00:00 2001 From: Michael Jolley Date: Sat, 21 Feb 2026 18:47:27 -0800 Subject: [PATCH] Fix CmdPal apps extension ignoring the fallback results limit setting (#45716) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary MainListPage hardcoded _appResultLimit = 10 instead of reading from AllAppsCommandProvider.TopLevelResultLimit, which correctly parses the user's SearchResultLimit setting. This meant changing the results limit in settings had no effect on the apps extension fallback results. ## Changes - `MainListPage.cs` — Replaced the hardcoded _appResultLimit = 10 field with a computed property AppResultLimit that delegates to AllAppsCommandProvider.TopLevelResultLimit. - `MainListPageResultFactoryTests.cs` — Added three regression tests: - `Merge_AppLimitOfOne_ReturnsOnlyTopApp` — verifies limit of 1 returns only the top app - `Merge_AppLimitOfZero_ReturnsNoApps` — verifies limit of 0 returns no apps - `Merge_AppLimitOfOne_WithOtherResults_AppsAreLimited` — verifies apps are limited even when mixed with other result types ## Validation - [X] Existing tests pass - [X] New regression tests cover edge cases for the appResultLimit parameter ## Linked Issues - Fixes #45654 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Commands/MainListPage.cs | 5 +- .../MainListPageResultFactoryTests.cs | 69 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs index 325f9b5ff8..50a9fd92c3 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs @@ -47,7 +47,8 @@ public sealed partial class MainListPage : DynamicListPage, private bool _includeApps; private bool _filteredItemsIncludesApps; - private int _appResultLimit = 10; + + private int AppResultLimit => AllAppsCommandProvider.TopLevelResultLimit; private InterlockedBoolean _refreshRunning; private InterlockedBoolean _refreshRequested; @@ -190,7 +191,7 @@ public sealed partial class MainListPage : DynamicListPage, validScoredFallbacks, _filteredApps, validFallbacks, - _appResultLimit); + AppResultLimit); } } } diff --git a/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/MainListPageResultFactoryTests.cs b/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/MainListPageResultFactoryTests.cs index 5cb60ca03b..13b583a495 100644 --- a/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/MainListPageResultFactoryTests.cs +++ b/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/MainListPageResultFactoryTests.cs @@ -120,6 +120,75 @@ public partial class MainListPageResultFactoryTests Assert.AreEqual("A2", result[1].Title); } + [TestMethod] + public void Merge_AppLimitOfOne_ReturnsOnlyTopApp() + { + var apps = new List> + { + S("A1", 100), + S("A2", 90), + S("A3", 80), + }; + + var result = MainListPageResultFactory.Create( + null, + null, + apps, + null, + appResultLimit: 1); + + Assert.AreEqual(1, result.Length); + Assert.AreEqual("A1", result[0].Title); + } + + [TestMethod] + public void Merge_AppLimitOfZero_ReturnsNoApps() + { + var apps = new List> + { + S("A1", 100), + S("A2", 90), + }; + + var result = MainListPageResultFactory.Create( + null, + null, + apps, + null, + appResultLimit: 0); + + Assert.AreEqual(0, result.Length); + } + + [TestMethod] + public void Merge_AppLimitOfOne_WithOtherResults_AppsAreLimited() + { + var filtered = new List> + { + S("F1", 100), + S("F2", 50), + }; + + var apps = new List> + { + S("A1", 90), + S("A2", 80), + S("A3", 70), + }; + + var result = MainListPageResultFactory.Create( + filtered, + null, + apps, + null, + appResultLimit: 1); + + Assert.AreEqual(3, result.Length); + Assert.AreEqual("F1", result[0].Title); + Assert.AreEqual("A1", result[1].Title); + Assert.AreEqual("F2", result[2].Title); + } + [TestMethod] public void Merge_FiltersEmptyFallbacks() {