ref(snapshotting): Centralize preview filename resolution#255
Merged
Conversation
Move snapshot export filename generation behind a single resolver so the naming policy is derived once and reused consistently at runtime. This also changes filename behavior to prefer display names when available, use display-name ordinals for duplicate named previews, and keep line numbers as a fallback for unnamed macro previews instead of part of the default identity. Co-Authored-By: OpenAI Codex <noreply@openai.com>
NicoHinderling
approved these changes
Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Centralize snapshot export filename resolution behind a single resolver and simplify the filename policy used by
SnapshotTest.The previous logic was split across discovery-time metadata maps, runtime assembly in
testPreview, and several fallback branches. That made the code harder to reason about and also produced unstable filenames in cases where a display name was already enough to identify the preview.This change moves filename generation into
SnapshotTest.FileNameResolver, computes names once during preview discovery, and makes the runtime path a simple lookup.Behavior changes:
#Previews now preferfileId + displayNamedisplayName_ordinalline-<line>previewIndexBefore / after examples:
Before:
HackerNews_CommentRow.swift_152_HTML_case_1.pngAfter:
HackerNews_CommentRow.swift_HTML_case_1.pngBefore:
Feature_LoginView.swift_42_line-42.pngAfter:
Feature_LoginView.swift_line-42.pngBefore: duplicate named provider previews could fall back to raw indexes such as
Test_View_3After: they resolve to display-name ordinals such as
Test_View_Dark_Mode_1I also renamed the internal count from
duplicateDisplayNameCounttodisplayNameOccurrenceCountand added typealiases for the resolver's string-backed grouping concepts so the code reads closer to what it is actually modeling.Validated with
swift test --filter SnapshottingTestsTestsandswift test.