Skip to content

fix: tolerate a missing binary snapshot data file#914

Merged
max-sixty merged 2 commits into
mitsuhiko:masterfrom
max-sixty:911-optional-binary
May 30, 2026
Merged

fix: tolerate a missing binary snapshot data file#914
max-sixty merged 2 commits into
mitsuhiko:masterfrom
max-sixty:911-optional-binary

Conversation

@max-sixty

@max-sixty max-sixty commented May 30, 2026

Copy link
Copy Markdown
Collaborator

cargo insta accept (and cargo insta test --accept) fails with a nonspecific No such file or directory (os error 2) and refuses to accept whenever a tracked .snap binary snapshot's data file is absent, even with --include-ignored. That absence is the normal state after checking out a project that gitignores its binary data files: the .snap metadata is committed but the data files are not, so they're missing on any fresh clone, on CI, or after git clean. This is the setup reported in #911.

The cause isn't the ignore walker, which is why --include-ignored doesn't help. When a snapshot is loaded, Snapshot::from_file eagerly fs::reads the binary sidecar, and a missing sidecar makes that ? abort the whole load. But cargo-insta only needs the old snapshot's metadata here (it never reads the old binary's bytes, only the extension, to clean up a stale file), and insta's own runtime already tolerates a missing old snapshot during cargo insta test. So the abort was an inconsistency, and one you couldn't recover from with the obvious accept.

This makes an absent payload a first-class state. SnapshotContents::Binary now holds Option<Rc<Vec<u8>>>; from_file maps a NotFound data file to None instead of erroring (a present-but-unreadable file still errors). A freshly produced snapshot always carries Some. This fixes both the accept crash and the misleading Failed to parse snapshot file warning the runtime printed in the same scenario.

Note: this changes the shape of the public SnapshotContents::Binary variant. No call site in either crate binds the payload directly (all match via _, { .. }, or unreachable!()), so nothing else needed touching, but it's a public-type change worth a semver note.

Includes a functional test (test_binary_accept_missing_old_binary) that reproduces the failure (tracked .snap, absent data file, then accept) and passes with the fix.

Closes #911. Thanks to @Kinrany for the report.

This was written by Claude Code on behalf of max

max-sixty and others added 2 commits May 28, 2026 18:04
…iko#911)

End-to-end functional test: a binary snapshot whose data file is gitignored
by extension is absent on a fresh checkout while its `.snap` metadata stays
tracked. Accepting a new value then fails with `No such file or directory
(os error 2)`. Fails on master; the accompanying fix makes it pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tsuhiko#911)

SnapshotContents::Binary now holds Option<Rc<Vec<u8>>>; a missing data
file loads as None instead of aborting, fixing the accept crash and the
misleading runtime warning when binary data files are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@max-sixty max-sixty merged commit a436836 into mitsuhiko:master May 30, 2026
15 checks passed
@max-sixty max-sixty deleted the 911-optional-binary branch May 30, 2026 22:42
@Kinrany

Kinrany commented Jun 1, 2026

Copy link
Copy Markdown

Thank you!

@max-sixty max-sixty mentioned this pull request Jun 11, 2026
max-sixty added a commit that referenced this pull request Jun 11, 2026
Minor release. Highlights since 1.47.2:

- `strip_ansi_escape_codes` setting (#899, @pierluigilenoci)
- Opt-in YAML literal blocks for multiline metadata strings via
`INSTA_YAML_BLOCK_STYLE=1` (#851, @ivov)
- An explicit `--accept` now overrides `CI=true` (#924)
- `cargo insta test --profile` now translates to nextest's
`--cargo-profile`; new `--nextest-profile` flag (#910)
- Windows `--snapshot` path fix and partial-path filter matching (#904)
- Accepting a binary snapshot tolerates a missing data file (#914)

> _This was written by Claude Code on behalf of @max-sixty_

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

Binary snapshot in .gitignore not seen even with --include-ignored

2 participants