Skip to content

Conversation

@max-sixty
Copy link
Collaborator

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

From Claude

Summary

Enhance cargo-insta for use in non-TTY environments (LLMs, CI pipelines, scripts) by adding non-interactive modes for snapshot review and management.

Changes

Non-Interactive Review Mode

  • cargo insta review --snapshot <path> now works without a TTY
  • Shows the snapshot diff in a read-only mode
  • Provides instructions for accepting/rejecting

Non-Interactive Reject Mode

  • cargo insta reject --snapshot <path> now works without a TTY
  • Shows the diff before rejecting (so users can verify what they're rejecting)
  • Actually performs the rejection

Enhanced pending-snapshots Output

  • Now shows helpful usage instructions instead of just paths
  • Provides example commands with actual snapshot paths
  • Uses workspace-relative paths for better readability

Helper Function

  • Extracted format_snapshot_key() to eliminate code duplication
  • Consistently uses workspace-relative paths throughout

Improved Error Messages

  • Updated TTY error message to guide users to non-interactive alternatives
  • Mentions all available non-interactive commands

Examples

Before (without TTY):

$ cargo insta review
error: Interactive review requires a terminal. Use `cargo insta accept` or `cargo insta reject`...

After (without TTY):

$ cargo insta pending-snapshots
Pending snapshots:
  src/lib.rs:42
  src/snapshots/test__example.snap

To review a snapshot: cargo insta review --snapshot 'src/lib.rs:42'
To accept a snapshot: cargo insta accept --snapshot 'src/lib.rs:42'
To reject a snapshot: cargo insta reject --snapshot 'src/lib.rs:42'

$ cargo insta review --snapshot 'src/lib.rs:42'
Snapshot: src/lib.rs:42 (inline):
  Package: example@0.1.0

[... shows full diff ...]

To accept: cargo insta accept --snapshot 'src/lib.rs:42'
To reject: cargo insta reject --snapshot 'src/lib.rs:42'

$ cargo insta accept --snapshot 'src/lib.rs:42'
insta review finished
accepted:
  src/lib.rs:42 (inline)

Use Cases

This is particularly useful for:

  • LLM/AI coding assistants - Can now review and manage snapshots programmatically
  • CI/CD pipelines - Scripts can review specific snapshots without interactive prompts
  • Automated workflows - Tools can inspect snapshot diffs before deciding to accept/reject

Testing

  • ✅ All existing tests pass (62 tests)
  • ✅ All lints pass (pre-commit run --all-files)
  • ✅ Manually tested non-interactive review/reject workflows
  • ✅ Verified workspace-relative paths work correctly

Backward Compatibility

  • All changes are additive - existing behavior unchanged
  • Interactive mode still works as before
  • JSON output from pending-snapshots --as-json maintains absolute paths for machine consumption
  • Human-readable output uses relative paths for better UX

Maximilian Roos and others added 3 commits November 2, 2025 12:08
Enhance cargo-insta for use in non-TTY environments (LLMs, CI):

- Add non-interactive review mode: `cargo insta review --snapshot <path>`
  shows diffs without requiring a TTY
- Add non-interactive reject mode: `cargo insta reject --snapshot <path>`
  shows diffs and rejects the snapshot
- Enhance `pending-snapshots` output with usage instructions and
  workspace-relative paths
- Extract `format_snapshot_key()` helper to eliminate code duplication
- Update error messages to guide users on non-interactive options

All paths are now workspace-relative for better readability and
copy-paste workflows. JSON output maintains absolute paths for
backward compatibility.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Adjusts the conditions for displaying diffs in non-interactive mode.
Now, `accept` operations do not display diffs, while `review` and `reject` operations do, ensuring relevant information is shown.

Co-authored-by: Claude <no-reply@anthropic.com>
@max-sixty max-sixty merged commit d8deb2f into mitsuhiko:master Nov 20, 2025
11 checks passed
@max-sixty max-sixty deleted the llm-friendly branch November 20, 2025 04:19
@max-sixty max-sixty mentioned this pull request Nov 20, 2025
max-sixty added a commit that referenced this pull request Nov 20, 2025
## Summary

Prepare for the 1.44.0 release:

- Bump version to 1.44.0 in `insta/Cargo.toml` and
`cargo-insta/Cargo.toml`
- Update CHANGELOG.md with all changes since 1.43.2

## Changes in 1.44.0

- Added non-interactive snapshot review and reject modes for use in
non-TTY environments (LLMs, CI pipelines, scripts) #815
- Add `--disable-nextest-doctest` flag with deprecation warning #803
- Add ergonomic `--test-runner-fallback` / `--no-test-runner-fallback`
flags #811
- Apply redactions to snapshot metadata #813
- Remove confusing 'previously unseen snapshot' message #812
- Speed up JSON float rendering #806 (@nyurik)
- Allow globset version up to 0.4.16 #810 (@g0hl1n)
- Improve documentation #814 (@tshepang)
- Enforce starting newlines in assertions #563

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <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.

1 participant