Skip to content

Send empty WinGet COM searches as a substring query - #5641

Merged
Gabriel Dufresne (GabrielDuf) merged 1 commit into
mainfrom
fix/issue-5639
Nov 2, 2026
Merged

Gabriel Dufresne (GabrielDuf) merged 1 commit into
mainfrom
fix/issue-5639

Conversation

@GabrielDuf

@GabrielDuf Gabriel Dufresne (GabrielDuf) commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Root cause

For an empty Discover query, NativeWinGetHelper.FindPackages_UnSafe (the COM path) built a FindPackagesOptions with no Filters and no Selectors, only ResultLimit. In winget's COM layer that becomes a SearchRequest with no Query, no Inclusions and no Filters, so IsForEverything() is true. For a REST source the 1.0 serializer then sends a manifestSearch body of {"MaximumResults":100,"FetchAllManifests":true} with no Query. FetchAllManifests is optional on the server side, and the reporter's Winget-Repo server answers it with zero matches and no error, which matches the log (search began on the catalog and finished with nothing found).

winget search "" behaves differently: the CLI turns the empty positional query into SearchRequest.Query = RequestMatch(Substring, ""), so the REST body carries Query {KeyWord:"", MatchType:"Substring"}, and that server treats an empty keyword as matching everything. WinGetCliHelper and PingetCliHelper already pass search "" per source, so only the COM helper took the "fetch everything" path. Nothing caught it because the pre-indexed community winget source honours an everything-request.

Fix

NativeWinGetHelper now sends an empty query the way the CLI does: a Selector with PackageMatchField.CatalogDefault, an empty value and ContainsCaseInsensitive, keeping ResultLimit = SearchLimits.MaxEmptyQueryResultsPerSource. In winget's COM layer a CatalogDefault selector maps to SearchRequest.Query and ContainsCaseInsensitive maps to MatchType::Substring. It has to be a Selector, not a Filter, because COM rejects CatalogDefault in Filters with E_INVALIDARG. Non-empty queries are unchanged (Name/Id/Moniker filters, no limit).

The per-search plan moved into a pure static NativeWinGetHelper.GetSearchRequests(query) returning NativeSearchRequest(Field, IsSelector, ResultLimit) records, so the choice is testable without COM activation. The task dictionary key changed from PackageMatchField? to PackageMatchField because every request now has a field.

Verification

  • dotnet build of UniGetUI.PackageEngine.Tests (x64): 0 errors; warnings are existing ones in untouched files.
  • dotnet format whitespace verify: exit 0. dotnet format style reports no diagnostics in the changed files (the solution-wide style check already exits 2 on main from unrelated IDE0044/IDE0060 warnings).
  • Filtered tests WinGetManagerTests.NativeWinGetHelperSearches*: 2 run, 2 passed.
  • Live on the community source: winget search "" --source winget --count 5 lists packages, and Find-WinGetPackage -Query '' (Microsoft.WinGet.Client 1.29.380, which builds the same empty CatalogDefault selector through COM) returned 100 packages. So COM accepts the selector and the community source does not regress.
  • Not verified: a private REST server like the reporter's. The claim that it works there rests on the reporter's working winget search --query "", which produces the same REST request body. The NativeAOT publish was not run; the change adds no reflection or interop surface. The full suite is left to CI.

Regression test

  • WinGetManagerTests.NativeWinGetHelperSearchesEmptyQueryThroughCatalogDefaultSelector
  • WinGetManagerTests.NativeWinGetHelperSearchesQueryByNameIdAndMonikerFilters

Without the fix they fail to compile (GetSearchRequests is missing); with it both pass. They check the request plan, not the COM options or the REST body built from it; swapping the Selectors/Filters branch inside FindPackages_UnSafe would not be caught, and a deeper test would need WinGet COM activation. This is not a UI change.

Non-blocking review notes

  • The existing // Name filter comment and FilterName variable now also describe the CatalogDefault selector, so they are slightly misleading. The comment is old and only moved.
  • A server that ignores FetchAllManifests is arguably the server's gap; matching the CLI's request is the robust client-side answer.
  • On the community winget source an empty search is now a substring query rather than an everything-request, as in the winget CLI and PowerShell module; checked live, it returns the same capped first 100.

Closes #5639

For an empty Discover query the COM helper built FindPackagesOptions with
no filters and no selectors, only a result limit. In winget's COM layer
that becomes a SearchRequest with no Query, no Inclusions and no Filters,
so IsForEverything() is true and a REST source receives a manifestSearch
body of {"MaximumResults":100,"FetchAllManifests":true} with no Query.
FetchAllManifests is optional server-side, and some REST servers answer
it with zero matches and no error, while `winget search ""` works.

The CLI turns the empty positional query into Query =
RequestMatch(Substring, ""), which servers treat as matching everything.
The helper now does the same through a CatalogDefault selector with an
empty value and ContainsCaseInsensitive, keeping the result limit. It
must be a selector, because COM rejects CatalogDefault in Filters with
E_INVALIDARG. Non-empty queries are unchanged.

The per-search plan moved into a pure GetSearchRequests(query) so the
choice can be tested without COM activation.

Fixes #5639

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change aligning empty WinGet COM searches with CLI behavior.

No open issues 🎉

What changed in this PR

Aligns empty WinGet COM searches with CLI behavior to address empty Discover results from private REST repositories reported in #5639.

Changes:

  • Uses an empty CatalogDefault substring selector while preserving the per-source result limit and existing non-empty search behavior.
  • Extracts request planning into a testable helper and adds regression tests for empty and non-empty queries.
File Description
src/​UniGetUI.PackageEngine.Tests/​WinGetManagerTests.cs Adds tests for selector, filter, and result-limit choices.
src/​UniGetUI.PackageEngine.Managers.WinGet/​ClientHelpers/​NativeWinGetHelper.cs Extracts request planning and applies the empty-query selector to COM searches.

Review effort: Balanced

@randy-but-a-ro randy-but-a-ro Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Pull request was approved automatically: the AI review is complete and all its review threads are resolved. 🎉

Integration Details
{
	"deliveryId": "96d23850-d469-11f1-900c-fde14c7c4786",
	"headSha": "c0c58881859564556d648b773db29929020c20cc",
	"reviewer": "copilot-pull-request-reviewer[bot]"
}

@GabrielDuf
Gabriel Dufresne (GabrielDuf) merged commit 2a03ddc into main Nov 2, 2026
6 checks passed
@GabrielDuf
Gabriel Dufresne (GabrielDuf) deleted the fix/issue-5639 branch November 2, 2026 13:25
martesi added a commit to martesi/UniGetUI that referenced this pull request Nov 2, 2026
Use a catalog-default selector for empty COM searches. Restore the bounded CLI search and installer URL handling, and remove the unsupported Agent broker path from Classic.

Upstream-Commit: 2a03ddc
Upstream-PR: Devolutions#5641
martesi added a commit to martesi/UniGetUI that referenced this pull request Nov 2, 2026
Classic-Source-Commit: 1e22e54
Upstream-Commit: 2a03ddc
Upstream-PR: Devolutions#5641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Empty Discover search returns "No results"

2 participants