Fix inline snapshot corruption with multiple snapshots in with_settings!#858
Merged
max-sixty merged 1 commit intomitsuhiko:masterfrom Jan 8, 2026
Merged
Fix inline snapshot corruption with multiple snapshots in with_settings!#858max-sixty merged 1 commit intomitsuhiko:masterfrom
max-sixty merged 1 commit intomitsuhiko:masterfrom
Conversation
Fixes mitsuhiko#857 When `find_snapshot_macro(line)` was called for a line inside a macro like `with_settings!`, the `scan_nested_macros` function would scan all nested tokens and find all `@"..."` patterns. Since `try_extract_snapshot` always overwrote the result, the last snapshot found would win regardless of which line we were searching for. This caused: 1. All searches for lines inside `with_settings!` returned the same (last) snapshot position 2. The duplicate detection logic discarded all but the first pending snapshot 3. The first pending snapshot's content got written to the last snapshot's position The fix collects all found snapshots with their macro boundaries (start/end line), then filters at the end to find the one whose macro span contains the target line. This is more general than filtering during scanning because: - The scanning logic collects everything uniformly - The line-matching logic is centralized in one place - It works at any nesting depth Co-Authored-By: Claude <noreply@anthropic.com>
max-sixty
added a commit
that referenced
this pull request
Jan 15, 2026
## Summary - Fix inline snapshot corruption when multiple snapshots appear inside `with_settings!` macro #858 ## Test plan - [x] All tests pass - [x] Pre-commit passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude <noreply@anthropic.com>
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.
Summary
Fixes #857
When
find_snapshot_macro(line)was called for a line inside a macro likewith_settings!, thescan_nested_macrosfunction would scan all nested tokens and find all@"..."patterns. Sincetry_extract_snapshotalways overwrote the result, the last snapshot found would win regardless of which line we were searching for.This caused:
with_settings!returned the same (last) snapshot positionExample from the issue:
The Fix
Instead of filtering during scanning, we now:
This approach is more general because:
Test plan
test_find_snapshot_macro_multiple_in_with_settings🤖 Generated with Claude Code