Skip to content

Fix inline snapshot corruption on multiline accept + partial accept workflow tests#494

Merged
MatthewMckee4 merged 3 commits intomainfrom
test/inline-snapshot-partial-accept-workflow
Feb 22, 2026
Merged

Fix inline snapshot corruption on multiline accept + partial accept workflow tests#494
MatthewMckee4 merged 3 commits intomainfrom
test/inline-snapshot-partial-accept-workflow

Conversation

@MatthewMckee4
Copy link
Member

@MatthewMckee4 MatthewMckee4 commented Feb 22, 2026

Summary

  • Add 6 integration tests for inline snapshot partial accept workflows (accept/skip/re-review, accept/skip/rerun, multiline line-shift scenarios)
  • Fix bug in find_inline_argument where a multiline inline accept that shifts line numbers could corrupt an intervening function's inline= argument
  • Add containing_function_name helper and function_name parameter to find_inline_argument / rewrite_inline_snapshot to match the correct assert_snapshot call
  • Add 4 unit tests for the new function-name-aware search

Bug

When accepting a multiline inline snapshot, the source file expands (e.g., inline="" becomes a triple-quoted block adding ~4 lines). Subsequent .snap.new files have stale line numbers. find_inline_argument searched forward from the stale line for the first assert_snapshot( call, which could land on an intervening function's inline= argument and silently corrupt it.

Fix

find_inline_argument now accepts an optional function_name parameter. When provided, it uses containing_function_name to verify the found call is inside the correct function, skipping calls in wrong functions.

Test plan

  • All 6 new integration tests pass
  • All 4 new unit tests pass
  • Full test suite passes (651 tests)
  • prek run -a passes clean

Test coverage for partially accepting inline snapshots across multiple
review sessions, including multiline values that shift source line numbers.

- Accept first/skip second, then review again to accept second
- Accept first/skip second, re-run tests, then accept remaining
- Multiline accept shifts line numbers; stale line number still resolves
- Multiline accept + re-run creates duplicate pending snapshots at old/new lines
@MatthewMckee4 MatthewMckee4 added the testing Related to testing Karva label Feb 22, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 22, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 1 untouched benchmark


Comparing test/inline-snapshot-partial-accept-workflow (fbb9e48) with main (45007e8)

Open in CodSpeed

find_inline_argument searched forward from a stale line number for the
first assert_snapshot call, which could land on an intervening function's
inline argument and corrupt it. Now accepts an optional function_name
parameter and skips calls in wrong functions.

Adds containing_function_name helper and 6 new tests (2 integration,
4 unit) that verify the fix.
@MatthewMckee4 MatthewMckee4 changed the title Add inline snapshot partial accept workflow tests Fix inline snapshot corruption on multiline accept + partial accept workflow tests Feb 22, 2026
@MatthewMckee4 MatthewMckee4 added the bug Something isn't working label Feb 22, 2026
Strip inline comments that just narrate what the code does (e.g.,
"// Review: accept first, skip second"). Keep only comments that
explain non-obvious intent. Add CLAUDE.md rule against useless
inline comments in tests.
@MatthewMckee4 MatthewMckee4 removed the testing Related to testing Karva label Feb 22, 2026
@MatthewMckee4 MatthewMckee4 merged commit a0b9745 into main Feb 22, 2026
9 checks passed
@MatthewMckee4 MatthewMckee4 deleted the test/inline-snapshot-partial-accept-workflow branch February 22, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant