Skip to content

Consume the WinUI Gallery published sample index - #895

Merged
Nikola Metulev (nmetulev) merged 6 commits into
mainfrom
jay/gallery-index
Sep 22, 2026
Merged

Nikola Metulev (nmetulev) merged 6 commits into
mainfrom
jay/gallery-index

Conversation

@Jaylyn-Barbee

Copy link
Copy Markdown
Contributor

Description

Replaces the WinUI Gallery scraper with the machine-readable sample index now published by microsoft/WinUI-Gallery#2232 at catalog/windows-samples.json.

The old path reconstructed the corpus by downloading Gallery metadata and hundreds of individual source files. This change consumes the upstream index in one request and deletes GalleryFetcher.cs entirely. A shared SampleIndexFetcher now handles the Gallery and Reactor indexes.

The published index contains Gallery source verbatim, so GalleryProvider preserves the pasteability normalization users relied on: Gallery-private page types and namespaces become app-local placeholders, calls to Gallery's internal UIHelper are removed, and XAML event attributes are retained only when the emitted C# defines the handler. Samples remain complete rather than being truncated; find-ui retrieves one selected sample at a time, and measurement showed recovering a truncated sample costs more tokens than serving it whole.

Gallery xmlnsImports are now rendered in the **Setup:** line instead of being discarded by the Toolkit-only formatter gate.

Usage Example

winapp find-ui "animated icon"
winapp find-ui --id gallery-animatedicon-2

The selected sample now includes the namespace declaration published by Gallery:

**Setup:** `xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"`

A cold corpus refresh fetches the Gallery index once rather than making up to 433 requests.

Related Issue

Closes: #809

Upstream index: microsoft/WinUI-Gallery#2232

Depends on the index-consumption foundation from #852.

Type of Change

  • ♻️ Refactor
  • ⚡ Performance
  • 🐛 Bug fix

Checklist

  • New tests added for the published-index corpus contract and pasteability guards
  • Tested against the live WinUI Gallery index
  • Tested locally on Windows
  • Full build and packaging completed
  • No command syntax or workflow documentation changes required

Additional Notes

Before → after:

Metric Scraper Published index
Gallery HTTP requests on a cold refresh up to 433 1
Scenarios 330 327
Controls 114 115
XAML samples 295 290
C# samples 107 116
Scenarios with no usable code 5 0

The three removed scenarios are upstream omissions rather than parser loss. Search enrichment preserves exact tag parity across all 127 controls represented by the shared Gallery tag data.

Validation:

  • scripts/build-cli.ps1 -SkipTests completed successfully, including NativeAOT, npm, NuGet, and MSIX packaging.
  • 179/179 find-ui, Gallery, sample-index, snapshot, formatter, Toolkit, and Reactor tests passed.
  • A fresh live bake produced 327 Gallery, 48 Toolkit, and 95 Reactor scenarios at cache version 23.
  • Runtime checks confirmed unbacked handlers and Gallery-private helpers are removed, Gallery namespace imports are printed, and Toolkit/Reactor output remains intact.

The full CLI suite was not used as the local signal because unrelated network/UI-dependent tests block on this machine; PR CI remains the complete repository gate.

AI Description

This section is auto-generated by AI when the PR is opened or updated. To opt out, delete this entire section including the marker comments.

Replace the Gallery scraper with the published sample index, preserve pasteability normalization, surface Gallery xmlns imports, and re-bake the embedded corpus.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 034ffdc8-3308-4286-96d8-e02406110630
Comment thread src/winapp-CLI/WinApp.Cli/Services/Controls/GalleryProvider.cs Dismissed
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

⏳ Build in progress — metrics below are from a previous commit and will update when the current build finishes.

Build Metrics Report

Validation passed. All required build and validation jobs succeeded.

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 57.28 MB 57.26 MB 📉 -24.5 KB (-0.04%)
CLI (x64) 57.32 MB 57.30 MB 📉 -23.5 KB (-0.04%)
MSIX (ARM64) 23.78 MB 23.79 MB 📈 +7.1 KB (+0.03%)
MSIX (x64) 25.25 MB 25.24 MB 📉 -9.8 KB (-0.04%)
NPM Package 49.62 MB 49.60 MB 📉 -15.8 KB (-0.03%)
NuGet Package 49.72 MB 49.70 MB 📉 -19.1 KB (-0.04%)

.NET Test Results (TRX reports)

Other suites are reflected in the overall validation status above.

✅ 7794 passed, 37 skipped out of 7831 tests in 1224.8s (+7 tests, -4.2s vs. baseline)

Test Coverage

✅ 86% line coverage, 80.7% branch coverage · ✅ +0.4% vs. baseline

CLI Startup Time

63ms median (x64, winapp --version) · ✅ no change vs. baseline

Try This Build

Installs the MSIX for your architecture, replacing any previously installed build. Needs the GitHub CLI — the command offers to install it and sign you in if it is missing.

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) 895
Switching between builds often?

Put the tool on your PATH once:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPath

Then this build is just:

winapp-pr 895

Run winapp-pr with no arguments to pick from a list of open PRs.


Updated 2026-09-22 17:40:17 UTC · commit e57592e · workflow run

Resolve conflicts between the sample-index rewrite and main's
no-truncation change:

- GalleryFetcher.cs: deleted (replaced by SampleIndexFetcher/GalleryProvider);
  main's truncation removal there is moot.
- ControlSnippetText.cs: take main's CloseUnbalancedTags; drop the
  GalleryFetcher cref now that the gallery path is GalleryProvider.
- CacheVersion: main shipped `23` for the no-truncation bake, so the
  sample-index entry becomes `24`.
- Re-baked the embedded corpus at cache version 24.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟡 Changes recommended

Gallery output still exposes private namespaces and asset paths that break pasted samples.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Replaces Gallery scraping with the shared published-index pipeline while preserving searchable, pasteable find-ui results.

Changes:

  • Adds shared Gallery/Reactor index fetching and removes GalleryFetcher.
  • Adds Gallery normalization, namespace rendering, and corpus validation.
  • Rebakes the Gallery snapshot and increments cache version.
File Description
SearchEngine.cs Renders Gallery XAML namespace setup.
SampleIndexFetcher.cs Adds shared index downloading.
ReactorFetcher.cs Uses the shared fetcher.
GalleryProvider.cs Parses, enriches, and normalizes Gallery samples.
GalleryFetcher.cs Removes the legacy scraper.
snapshot-gallery.json.br Rebakes Gallery corpus data.
snapshot-manifest.json Updates corpus counts and version.
ControlSnippetText.cs Updates provider references.
CacheVersion.cs Invalidates pre-index caches.
GalleryFetcherCleanContentTests.cs Removes obsolete scraper tests.
FindUiSearchTests.cs Removes scraper-specific normalization tests.
EmbeddedSnapshotTests.cs Adds Gallery corpus safeguards.
find-ui-corpus-check.yml Watches shared index components.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/winapp-CLI/WinApp.Cli/Services/Controls/GalleryProvider.cs
Comment thread src/winapp-CLI/WinApp.Cli/Services/Controls/GalleryProvider.cs
Address two review findings on the sample-index port.

The index publishes Gallery's source verbatim, and NormalizeForPaste only
covered part of what that carries:

- 20 scenarios still named a Gallery CLR namespace. 16 of them in the index's
  xmlnsImports field, which SearchEngine renders as the "Setup:" line -- so we
  printed `xmlns:local="using:WinUIGallery.ControlPages"` as an instruction to
  declare a prefix that cannot resolve. tabview-2 was inconsistent with itself:
  the type was already rewritten to <samplepages:YourPage />, but the prefix it
  used still mapped to WinUIGallery.SamplePages.
- 41 scenarios pointed at assets that exist only in Gallery's package -- 32
  under Assets/SampleMedia, 9 under Assets/Tiles. Those compile and then render
  nothing: a silently blank Image, an AppWindow.SetIcon that quietly does not
  take. The scraper rewrote SampleMedia (one URI form of three, so 17 of the
  32); dropping it was a regression, and Tiles was never covered at all.

Rewrites are environment only -- identifiers and paths that resolve against
Gallery's own assembly and package. The sample still teaches what upstream
wrote. Asset rewrites preserve the URI form, because AppWindow.SetIcon takes a
package-relative path rather than a ms-appx URI, and preserve the extension,
because a MediaPlayerElement pointed at a .png is a different kind of broken.

Guards: the corpus check now covers xmlnsImports and Gallery-only asset paths,
and GalleryProviderNormalizeTests pins the transform hermetically -- a corpus
guard alone passes vacuously the day upstream stops shipping the thing being
rewritten.

Cache version 24 is unreleased, so its history entry is amended rather than
superseded. Corpus re-baked.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 883032eb-8c56-4340-b3d7-4c38bb1916b8

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.

Copilot review overview

🟡 Changes recommended

Gallery output still contains unbacked event attributes that make several emitted XAML samples fail when pasted.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Comment thread src/winapp-CLI/WinApp.Cli/Services/Controls/GalleryProvider.cs
@Jaylyn-Barbee
Jaylyn Barbee (Jaylyn-Barbee) marked this pull request as ready for review September 22, 2026 16:58
@nmetulev
Nikola Metulev (nmetulev) merged commit e61b931 into main Sep 22, 2026
12 checks passed
@nmetulev
Nikola Metulev (nmetulev) deleted the jay/gallery-index branch September 22, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phase 1: WinUI-Gallery publishes a sample index (and we delete GalleryFetcher)

3 participants