-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit d8deb2f
max-sixtyMaximilian RoosclaudeClaude
authoredAdd LLM-friendly non-interactive snapshot management (#815)
> 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):**
```bash
$ cargo insta review
error: Interactive review requires a terminal. Use `cargo insta accept` or `cargo insta reject`...
```
**After (without TTY):**
```bash
$ 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
---------
Co-authored-by: Maximilian Roos <maximilian@Maximilians-MacBook-Pro.local>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <no-reply@anthropic.com>1 parent 783ebc2 commit d8deb2f
1 file changed
+100
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | - | ||
303 | - | ||
302 | + | ||
303 | + | ||
304 | + | ||
305 | + | ||
306 | + | ||
307 | + | ||
308 | + | ||
304 | 309 | | |
305 | 310 | | |
306 | 311 | | |
| |||
563 | 568 | | |
564 | 569 | | |
565 | 570 | | |
571 | + | ||
572 | + | ||
573 | + | ||
574 | + | ||
575 | + | ||
576 | + | ||
577 | + | ||
578 | + | ||
579 | + | ||
580 | + | ||
581 | + | ||
582 | + | ||
583 | + | ||
584 | + | ||
585 | + | ||
566 | 586 | | |
567 | 587 | | |
568 | 588 | | |
| |||
602 | 622 | | |
603 | 623 | | |
604 | 624 | | |
625 | + | ||
626 | + | ||
627 | + | ||
628 | + | ||
629 | + | ||
630 | + | ||
605 | 631 | | |
606 | 632 | | |
607 | 633 | | |
608 | 634 | | |
609 | 635 | | |
610 | 636 | | |
611 | - | ||
612 | - | ||
613 | - | ||
614 | - | ||
615 | - | ||
637 | + | ||
616 | 638 | | |
617 | 639 | | |
618 | 640 | | |
| |||
621 | 643 | | |
622 | 644 | | |
623 | 645 | | |
646 | + | ||
647 | + | ||
648 | + | ||
649 | + | ||
650 | + | ||
651 | + | ||
652 | + | ||
653 | + | ||
654 | + | ||
655 | + | ||
656 | + | ||
657 | + | ||
658 | + | ||
659 | + | ||
660 | + | ||
661 | + | ||
662 | + | ||
663 | + | ||
664 | + | ||
665 | + | ||
666 | + | ||
667 | + | ||
668 | + | ||
669 | + | ||
670 | + | ||
671 | + | ||
672 | + | ||
673 | + | ||
674 | + | ||
675 | + | ||
676 | + | ||
677 | + | ||
678 | + | ||
679 | + | ||
680 | + | ||
681 | + | ||
682 | + | ||
683 | + | ||
624 | 684 | | |
625 | 685 | | |
626 | 686 | | |
| |||
1265 | 1325 | | |
1266 | 1326 | | |
1267 | 1327 | | |
1328 | + | ||
1329 | + | ||
1268 | 1330 | | |
1269 | 1331 | | |
1270 | 1332 | | |
1271 | 1333 | | |
1334 | + | ||
1335 | + | ||
1272 | 1336 | | |
1273 | 1337 | | |
1274 | 1338 | | |
| |||
1291 | 1355 | | |
1292 | 1356 | | |
1293 | 1357 | | |
1294 | - | ||
1295 | - | ||
1296 | 1358 | | |
1297 | - | ||
1359 | + | ||
1298 | 1360 | | |
1299 | 1361 | | |
1300 | 1362 | | |
1301 | 1363 | | |
1364 | + | ||
1365 | + | ||
1366 | + | ||
1367 | + | ||
1368 | + | ||
1369 | + | ||
1370 | + | ||
1371 | + | ||
1372 | + | ||
1373 | + | ||
1374 | + | ||
1375 | + | ||
1376 | + | ||
1377 | + | ||
1378 | + | ||
1379 | + | ||
1380 | + | ||
1381 | + | ||
1382 | + | ||
1383 | + | ||
1384 | + | ||
1385 | + | ||
1386 | + | ||
1387 | + | ||
1388 | + | ||
1389 | + | ||
1390 | + | ||
1391 | + | ||
1302 | 1392 | | |
1303 | 1393 | | |
1304 | 1394 | | |
| |||
0 commit comments