Skip to content

refactor(xcresult): name the places a test's file can come from - #1158

Merged
trunk-io[bot] merged 1 commit into
mainfrom
claude/xcresult-attribution-types
Aug 19, 2026
Merged

refactor(xcresult): name the places a test's file can come from#1158
trunk-io[bot] merged 1 commit into
mainfrom
claude/xcresult-attribution-types

Conversation

@dfrankland

Copy link
Copy Markdown
Member

Stack 1/3 — no behaviour change.

The file we report for a failed test was assembled by an .or_else chain of Option<String>, where every link meant something different and none of them said so. fileName is the site an assertion fired, which for a helper is the helper's file; the call-stack fallback is whichever frame happened to be outermost. Reading the chain, they are indistinguishable.

This adds the vocabulary:

  • FileSource — one variant per place we look, each documented with what it actually means
  • FileCandidate — carries the source alongside the path, so a candidate can be traced back to where it came from instead of arriving as an anonymous string
  • ReportedPath — normalizes once at construction. It was previously applied by hand at each call site, which is a silent bug the moment one is missed, or two paths are compared having been normalized differently.

Each source's extraction moves into a new file_attribution module as its own named function. The module doc states the thing the code could not: an .xcresult records where a failure was raised, never where a test is declared, so every source here is a proxy for the question we are actually asking — and the answer is what codeowners get resolved from.

xcresult_legacy.rs gets ~100 lines smaller.

Verification

No behaviour change: the sources are offered in the order the chain tried them and the first is taken. All 11 pre-existing integration tests pass unchanged, plus 10 new unit tests covering normalization, candidate ordering and provenance, the stack-frame filter, and document-location cleaning.

🤖 Generated with Claude Code

The file we report for a failed test was assembled by an `.or_else` chain of
`Option<String>`, where every link meant something different and none of them
said so. `fileName` is the site an assertion fired, which for a helper is the
helper's file; the call-stack fallback is whichever frame happened to be
outermost. Reading the chain, they are indistinguishable.

`FileSource` names each place we look and `FileCandidate` carries it alongside
the path, so a candidate can be traced back to where it came from instead of
arriving as an anonymous string. The extraction for each source moves into
`file_attribution` as its own named function, and the module doc says the thing
the code could not: an `.xcresult` records where a failure was *raised*, never
where a test is *declared*, so every source here is a proxy for the question we
are actually asking.

`ReportedPath` normalizes once at construction. It was previously applied by
hand at each call site, which is a silent bug the moment one is missed or two
paths are compared having been normalized differently.

No behaviour change: the sources are offered in the order the chain tried them
and the first is taken.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Aug 18, 2026

Copy link
Copy Markdown

😎 This pull request was merged.

@trunk-staging-io

trunk-staging-io Bot commented Aug 18, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

Failed Test Failure Summary Logs
pending_quarantine_test should be quarantined when run with variant A test marked as pending was expected to fail but unexpectedly passed. Logs ↗︎
variant_quarantine_test should be quarantined when run with variant A test expected the sum of 2 + 2 to be 5, but it was actually 4, indicating a failing assertion. Logs ↗︎

View Full Report ↗︎Docs

@codecov-commenter

codecov-commenter commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.28%. Comparing base (64052e5) to head (8579cd1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1158      +/-   ##
==========================================
+ Coverage   82.97%   83.28%   +0.31%     
==========================================
  Files          71       72       +1     
  Lines       16044    16110      +66     
==========================================
+ Hits        13312    13417     +105     
+ Misses       2732     2693      -39     

☔ View full report in Codecov by Harness.
📢 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

trunk-io Bot commented Aug 18, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@trunk-io
trunk-io Bot merged commit 49dbbce into main Aug 19, 2026
27 checks passed
@trunk-io

trunk-io Bot commented Aug 19, 2026

Copy link
Copy Markdown

This pull request was merged into main as part of stacked PR 1162.

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