Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@max-sixty
Copy link
Collaborator

@max-sixty max-sixty commented Nov 27, 2025

Summary

This fixes a regression introduced in 1.44.0 where existing inline snapshots using the legacy multiline format would fail to match.

The problem: PR #563 changed how inline snapshots handle leading newlines. This caused snapshots like:

insta::assert_snapshot!(value, @r"
    Unconflicted Mode(FILE) 0839b2e9412b
    ");

to fail when the actual value is "Unconflicted Mode(FILE) 0839b2e9412b".

The legacy format stored single-line content in a multiline raw string with source code indentation. After from_inline_literal processing, this becomes " Unconflicted...\n " β€” the leading spaces from code indentation weren't being stripped in the legacy comparison path.

The fix: In matches_legacy, detect the legacy single-line-in-multiline pattern:

let is_legacy_single_line_in_multiline =
    sc.contents.contains('\n') && sc.contents.trim_end().lines().count() <= 1;

When this pattern is detected, apply trim_start() to strip the source code indentation artifacts.

This ensures:

  • βœ… Legacy snapshots continue to pass (with a warning to update)
  • βœ… Modern single-line snapshots with intentional leading spaces are preserved
  • βœ… True multiline snapshots are unaffected

Test plan

  • Added 8 comprehensive functional tests covering:
    • Single-line content in multiline format (the jj bug)
    • Raw string multiline variant
    • Force update reformatting works
    • True multiline content unaffected
    • Multiline with relative indentation preserved
    • Intentional leading spaces correctly fail (no false positives)
    • Trailing whitespace line edge case
    • Empty snapshot edge case
  • All 72 functional tests pass
  • Full test suite passes

Reported-by: jj-vcs/jj
See: #819 (comment)

πŸ€– Generated with Claude Code

This fixes a regression introduced in 1.44.0 where existing inline
snapshots using the legacy multiline format would fail to match.

The problem: In 1.44.0, we changed how inline snapshots handle leading
newlines (PR mitsuhiko#563). This caused snapshots like:

    insta::assert_snapshot!(value, @r"
    Unconflicted Mode(FILE) 0839b2e9412b
    ");

to fail when the actual value is "Unconflicted Mode(FILE) 0839b2e9412b".
The legacy format stored single-line content in a multiline raw string
with source code indentation, which after processing becomes
"    Unconflicted...\n    " - the leading spaces from indentation
weren't being stripped in the comparison.

The fix: In `matches_legacy`, detect the legacy single-line-in-multiline
pattern by checking if the raw contents contain a newline but collapse
to a single line after trimming. When this pattern is detected, apply
`trim_start()` to strip the source code indentation artifacts.

This ensures:
- Legacy snapshots continue to pass (with a warning to update)
- Modern single-line snapshots with intentional spaces are preserved
- True multiline snapshots are unaffected

We take backward compatibility seriously - upgrading insta should not
cause existing valid tests to fail.

Reported-by: jj-vcs/jj
See: mitsuhiko#819 (comment)

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@max-sixty
Copy link
Collaborator Author

summary done by Claude, as is some of the code...

this fixes the small regression with leading white space on in a multiline snapshots with a single line of text

@max-sixty max-sixty merged commit e55ce99 into mitsuhiko:master Nov 27, 2025
15 checks passed
@max-sixty max-sixty deleted the back-compat branch November 27, 2025 05:42
max-sixty added a commit to max-sixty/insta that referenced this pull request Nov 27, 2025
## Changes

- Fix backward compatibility for legacy inline snapshot format. Snapshots
  using single-line content in multiline raw strings now correctly match
  again. (mitsuhiko#830)
- Handle merge conflicts in snapshot files gracefully. When a snapshot file
  contains git merge conflict markers, insta now detects them and treats
  the snapshot as missing, allowing tests to continue and create a new
  pending snapshot for review. (mitsuhiko#829)
- Skip nextest_doctest tests when cargo-nextest is not installed. (mitsuhiko#826)
- Fix functional tests failing under nextest due to inherited
  `NEXTEST_RUN_ID` environment variable. (mitsuhiko#824)

## Version Updates

- Bump version to 1.44.2 in `insta/Cargo.toml` and `cargo-insta/Cargo.toml`
- Update CHANGELOG.md with release notes
- Update Cargo.lock

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
@max-sixty max-sixty mentioned this pull request Nov 27, 2025
2 tasks
max-sixty added a commit to max-sixty/insta that referenced this pull request Nov 27, 2025
## Changes

- Fix backward compatibility for legacy inline snapshot format. Snapshots
  using single-line content in multiline raw strings now correctly match
  again. (mitsuhiko#830)
- Handle merge conflicts in snapshot files gracefully. When a snapshot file
  contains git merge conflict markers, insta now detects them and treats
  the snapshot as missing, allowing tests to continue and create a new
  pending snapshot for review. (mitsuhiko#829)
- Skip nextest_doctest tests when cargo-nextest is not installed. (mitsuhiko#826)
- Fix functional tests failing under nextest due to inherited
  `NEXTEST_RUN_ID` environment variable. (mitsuhiko#824)

## Version Updates

- Bump version to 1.44.2 in `insta/Cargo.toml` and `cargo-insta/Cargo.toml`
- Update CHANGELOG.md with release notes
- Update Cargo.lock

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
max-sixty added a commit that referenced this pull request Nov 27, 2025
## Summary

Prepare for the 1.44.2 patch release with four changes since 1.44.1.

## Changes

- Fix backward compatibility for legacy inline snapshot format.
Snapshots using single-line content in multiline raw strings now
correctly match again. (#830)
- Handle merge conflicts in snapshot files gracefully. When a snapshot
file contains git merge conflict markers, insta now detects them and
treats the snapshot as missing, allowing tests to continue and create a
new pending snapshot for review. (#829)
- Skip nextest_doctest tests when cargo-nextest is not installed. (#826)
- Fix functional tests failing under nextest due to inherited
`NEXTEST_RUN_ID` environment variable. (#824)

## Version Updates

- Bump version to 1.44.2 in `insta/Cargo.toml` and
`cargo-insta/Cargo.toml`
- Update CHANGELOG.md with release notes
- Update Cargo.lock

## Test plan

- [x] All tests pass
- [x] Pre-commit lints pass

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
max-sixty added a commit to max-sixty/insta that referenced this pull request Nov 27, 2025
…ko#830)

## Summary

This fixes a regression introduced in 1.44.0 where existing inline
snapshots using the legacy multiline format would fail to match.

**The problem:** PR mitsuhiko#563 changed how inline snapshots handle leading
newlines. This caused snapshots like:

```rust
insta::assert_snapshot!(value, @r"
    Unconflicted Mode(FILE) 0839b2e9412b
    ");
```

to fail when the actual value is `"Unconflicted Mode(FILE)
0839b2e9412b"`.

The legacy format stored single-line content in a multiline raw string
with source code indentation. After `from_inline_literal` processing,
this becomes `" Unconflicted...\n "` β€” the leading spaces from code
indentation weren't being stripped in the legacy comparison path.

**The fix:** In `matches_legacy`, detect the legacy
single-line-in-multiline pattern:

```rust
let is_legacy_single_line_in_multiline =
    sc.contents.contains('\n') && sc.contents.trim_end().lines().count() <= 1;
```

When this pattern is detected, apply `trim_start()` to strip the source
code indentation artifacts.

This ensures:
- βœ… Legacy snapshots continue to pass (with a warning to update)
- βœ… Modern single-line snapshots with intentional leading spaces are
preserved
- βœ… True multiline snapshots are unaffected

## Test plan

- [x] Added 8 comprehensive functional tests covering:
  - Single-line content in multiline format (the jj bug)
  - Raw string multiline variant
  - Force update reformatting works
  - True multiline content unaffected
  - Multiline with relative indentation preserved
  - Intentional leading spaces correctly fail (no false positives)
  - Trailing whitespace line edge case
  - Empty snapshot edge case
- [x] All 72 functional tests pass
- [x] Full test suite passes

Reported-by: jj-vcs/jj  
See: mitsuhiko#819 (comment)

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
max-sixty added a commit to max-sixty/insta that referenced this pull request Nov 27, 2025
## Summary

Prepare for the 1.44.2 patch release with four changes since 1.44.1.

## Changes

- Fix backward compatibility for legacy inline snapshot format.
Snapshots using single-line content in multiline raw strings now
correctly match again. (mitsuhiko#830)
- Handle merge conflicts in snapshot files gracefully. When a snapshot
file contains git merge conflict markers, insta now detects them and
treats the snapshot as missing, allowing tests to continue and create a
new pending snapshot for review. (mitsuhiko#829)
- Skip nextest_doctest tests when cargo-nextest is not installed. (mitsuhiko#826)
- Fix functional tests failing under nextest due to inherited
`NEXTEST_RUN_ID` environment variable. (mitsuhiko#824)

## Version Updates

- Bump version to 1.44.2 in `insta/Cargo.toml` and
`cargo-insta/Cargo.toml`
- Update CHANGELOG.md with release notes
- Update Cargo.lock

## Test plan

- [x] All tests pass
- [x] Pre-commit lints pass

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
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.

1 participant