Skip to content

ref(snapshotting): Centralize preview filename resolution#255

Merged
cameroncooke merged 1 commit into
mainfrom
cameroncooke/ref/simplify-snapshot-filenames
Apr 21, 2026
Merged

ref(snapshotting): Centralize preview filename resolution#255
cameroncooke merged 1 commit into
mainfrom
cameroncooke/ref/simplify-snapshot-filenames

Conversation

@cameroncooke
Copy link
Copy Markdown
Contributor

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:

  • Named #Previews now prefer fileId + displayName
  • Duplicate named previews now use displayName_ordinal
  • Anonymous macro previews fall back to line-<line>
  • Anonymous provider previews still fall back to previewIndex
  • Duplicate line information is no longer emitted in filenames

Before / after examples:

  • Before: HackerNews_CommentRow.swift_152_HTML_case_1.png

  • After: HackerNews_CommentRow.swift_HTML_case_1.png

  • Before: Feature_LoginView.swift_42_line-42.png

  • After: Feature_LoginView.swift_line-42.png

  • Before: duplicate named provider previews could fall back to raw indexes such as Test_View_3

  • After: they resolve to display-name ordinals such as Test_View_Dark_Mode_1

I also renamed the internal count from duplicateDisplayNameCount to displayNameOccurrenceCount and 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 SnapshottingTestsTests and swift test.

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>
@cameroncooke cameroncooke marked this pull request as ready for review April 20, 2026 11:12
@cameroncooke cameroncooke merged commit 4912f5d into main Apr 21, 2026
7 checks passed
@cameroncooke cameroncooke deleted the cameroncooke/ref/simplify-snapshot-filenames branch April 21, 2026 09:16
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.

2 participants