Skip to content

Fix xcresult snapshot test file attribution#1094

Merged
trunk-io[bot] merged 1 commit into
mainfrom
dylan/xcresult-use-file_path-instead-of-call_stack
May 19, 2026
Merged

Fix xcresult snapshot test file attribution#1094
trunk-io[bot] merged 1 commit into
mainfrom
dylan/xcresult-use-file_path-instead-of-call_stack

Conversation

@dfrankland
Copy link
Copy Markdown
Member

@dfrankland dfrankland commented May 18, 2026

Summary

  • Prefer structured failure summary file paths before falling back to call-stack inspection.
  • Preserve the existing legacy documentLocationInCreatingWorkspace fallback path.
  • Add a Swift SnapshotTesting xcresult fixture plus parameterized unit and integration coverage.

Rationale

Swift SnapshotTesting trait failures can include framework files later in the call stack, such as SnapshotsTestTrait.swift. The previous experimental failure-summary path selected the last Swift or Obj-C call-stack frame, so the reported JUnit file could point at SnapshotTesting internals instead of the test source that asserted the snapshot.

The xcresult failure summary already contains better structured attribution fields. Although the legacy schema calls the preferred field fileName, the inspected xcresult objects store a full absolute source path there, not just a basename. In the SnapshotTesting fixture, fileName and sourceCodeContext.location.filePath both point to /tmp/xcresult-snapshot-repro.sPh62f/Tests/SnapshotReproTests/SnapshotReproTests.swift; the call stack also includes full paths, but later frames point at SnapshotTesting internals.

This change therefore prefers fileName, then sourceCodeContext.location.filePath, and only falls back to the old call-stack heuristic when those structured fields are absent. The non-experimental legacy path remains available and unchanged in behavior.

Testing

  • cargo test -p xcresult
  • Temporarily reverted the source change and confirmed test_swift_snapshot_testing_trait_failure_uses_assertion_file::case_1_experimental_failure_summary fails by pointing at SnapshotsTestTrait.swift; restored the fix and confirmed it passes.

@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 18, 2026

😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details.

@trunk-staging-io
Copy link
Copy Markdown

trunk-staging-io Bot commented May 18, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.10%. Comparing base (5571a7c) to head (762b693).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1094      +/-   ##
==========================================
+ Coverage   81.77%   82.10%   +0.32%     
==========================================
  Files          69       69              
  Lines       14939    14986      +47     
==========================================
+ Hits        12217    12304      +87     
+ Misses       2722     2682      -40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 18, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

}

fn normalize_file_path(file_path: Option<&String>) -> Option<String> {
file_path.map(|file_path| file_path.replace(' ', "%20"))
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.

Is this necessary?

Copy link
Copy Markdown
Member Author

@dfrankland dfrankland May 19, 2026

Choose a reason for hiding this comment

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

Unfortunately, yes. We didn't correct for this before when parsing XCResult file:// URLS, so for test identity backwards compat, we need to continue percent encoding spaces to ensure we don't create new test cases.

@trunk-io trunk-io Bot merged commit 0e97542 into main May 19, 2026
25 checks passed
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.

3 participants