Skip to content

Fix gallery search-index placeholder false positives - #1609

Open
PaperHammer (PaperHammer) wants to merge 1 commit into
microsoft:mainfrom
PaperHammer:fix/issue1020-placeholder-detection
Open

PaperHammer (PaperHammer) wants to merge 1 commit into
microsoft:mainfrom
PaperHammer:fix/issue1020-placeholder-detection

Conversation

@PaperHammer

Copy link
Copy Markdown
Contributor

Summary

Complete Gallery samples could be silently omitted from the search index when comments or display text contained ellipses. This change makes placeholder filtering context-aware and adds an independent coverage check that detects missing samples after index regeneration.

  • Mask comments and literal text while checking executable code for omissions.
  • Retain checks for explicit omission comments and direct MapControl token or Uri placeholders.
  • Compare routed source-card headers and order against the index, with explicit exceptions for intentional omissions and editorial replacements.
  • Regenerate the index, restoring only the Pan and OpacityTransition samples.
  • Update regression tests, documentation, and the changelog.

Linked issue / spec

Fixes #1020.

Related design — spec 064 §3.2.

Test plan

  • Search-index suite — 137 passed, including paired regressions and independent coverage checks.
  • Regenerated index and --check — passed.
  • Confirmed the index still contains 106 controls, with samples increasing from 247 to 249. Only Pan and OpacityTransition were added.
  • Rebuilt the index with the original generator. The freshness check passed, while the independent coverage check correctly reported both missing samples.
  • Full Release solution build — passed with 0 errors and 366 warnings, including dependency-version conflicts and Win2D platform warnings.
  • git diff --check — passed.
  • Full unit suite — 16,033 passed, 18 skipped, 3 failed.

Both CS1503 failures also reproduce on the unchanged baseline at 7e3d0254:

  • DidYouMeanAnalyzerParityTests.CS1503_string_for_element_fires_in_both_engines
  • SymbolSuggesterTests.CS1503_Element_expected_string_supplied_proposes_text_factory

LayoutModifiersTests.Fluent_Layout_Updates_Allocate_Only_The_Returned_Records failed during the full run, then passed in focused reruns on both the baseline and the fixed tree. The full-suite result remains recorded as three failures.

Risk / breaking changes

Resource-placeholder checks cover direct string-literal MapControl token arguments and explicit Uri construction. Other resource-call shapes, target-typed construction, and computed placeholders require an explicit omission marker such as // omitted: reason.

The independent coverage check compares sample headers and order. Changes to snippets already listed as intentional omissions require manual review of those exceptions.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice fix. The Roslyn masking is a lot more robust than the old regex, and the coverage manifest is a good safety net. Left a few comments inline.

Comment on lines +69 to +70
var uri = list.Parent is ObjectCreationExpressionSyntax creation
&& creation.Type.ToString() is "Uri" or "System.Uri" or "global::System.Uri";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This narrows the URI check to new Uri(...) only. Every other string literal gets masked before the ... scan, so Image("ms-appx:///Assets/.../photo.png") or MediaPlayerElement("https://<your-host>/clip.mp4") would now get indexed. The old regex rejected both. Nothing in the gallery hits this today, but the Image and Media pages are where it's most likely to show up.

Could we run the path and <your…> checks on any string literal that starts with a URI scheme? If the narrower rule is intended, the CHANGELOG line about URI placeholders should say new Uri(...) to match the README.

Comment on lines +68 to +78
[InlineData("MapControl(\"<your-key>\");")]
[InlineData("MapControl(@\"<your-key>\");")]
[InlineData("MapControl(\"\"\"<your-key>\"\"\");")]
[InlineData("MapControl(\"<yourApiKey>\");")]
[InlineData("MapControl(<yourApiKey>);")]
[InlineData("MapControl(mapServiceToken: \"<your.azure.maps.key>\");")]
[InlineData("MapControl(\"<yourapikey>\");")]
[InlineData("var uri = new Uri(\"ms-appx:///.../image.png\");")]
[InlineData("var uri = new Uri(\"https://example.com/media/(...)\");")]
[InlineData("var uri = new Uri(\"https://example.com/media/( ... )\");")]
[InlineData("var uri = new System.Uri(uriString: \"https://example.com/.../page\");")]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few HasDirectPlaceholder shapes aren't covered here. Factories.MapControl, global::System.Uri, new Uri("https://<your-host>/x") and the first-argument-only rule for MapControl could all be narrowed without anything going red. Maybe add rows for those, plus a kept case like MapControl("configured-key", "<your-note>").

Comment on lines +147 to +161
problems.Add($"{id}: editorial override is missing a manifest entry.");

var actual = indexed[id].EnumerateArray().Select(s => s.GetProperty("header").GetString()!).ToArray();
if (expected.SequenceEqual(actual)) continue;

var missing = expected.Except(actual).ToArray();
var unexpected = actual.Except(expected).ToArray();
problems.Add($"{id}: expected {expected.Count}, got {actual.Length}. "
+ $"Missing: [{string.Join(", ", missing)}]. "
+ $"Unexpected: [{string.Join(", ", unexpected)}]. "
+ "If both lists are empty, check the order or duplicate count.");
}

problems.AddRange(remainingChanges.Select(entry =>
$"{entry.Key.Control} / {entry.Key.Title} ({entry.Key.Occurrence}): stale manifest entry ({entry.Value.Reason})."));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The stale manifest and "override is missing a manifest entry" branches never fire in any test. TESTING.md calls out stale entry detection, so a MiniGallery case for each would be good.

[new("grid", "Basic Grid")] = new(Action.Skip, "Remaining grid cells are elided."),
[new("list-view", "Basic ListView")] = new(Action.Skip, "Additional list items are elided."),
[new("list-view", "Animated edit (spec 042)")] = new(Action.Skip, "The mutation signature and item template are elided."),
[new("map-control", "Interactive map")] = new(Action.Replace, "Editorial code supplies the complete no-token branch."),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit, take it or leave it. The Replace entries duplicate sampleOverride in editorial.json. Deriving them from the override (first non-skipped card gets the override header) would mean one less file to touch next time.


var routes = Routes(gallery);
var pageNames = included.Select(id => routes[id]).ToHashSet(StringComparer.Ordinal);
var pageFiles = Directory.EnumerateFiles(Path.Join(gallery, "ControlPages"), "*.cs", SearchOption.AllDirectories);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit. This is another copy of the page loader that GallerySources is there to avoid, and unlike ReadSources it doesn't skip bin/obj. Could we make GallerySources.ReadSources internal and reuse it here?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants