feat(snapshot-diff): supercharge — envelope, counts, --only, --path-prefix, fix _obj bug
Fixes - Fix _obj helper in test_cmd_snapshot_diff.py: was calling write_object with bare hex OIDs (without sha256: prefix), causing validate_object_id to raise ValueError on all 20 tests that called _obj. Fix: use blob_id(). - Fix test_raw_has_no_effect_on_json_output: compared full JSON objects including elapsed_ms, which differ between two invocations. Now compares only the stable structural fields.
Source (snapshot_diff.py) - Add elapsed_ms and exit_code to _DiffResult TypedDict and all JSON outputs (single-pair and batch --stdin modes). - Add added_count, modified_count, deleted_count fields — agents no longer need to len() the arrays to read change counts. - Add --only / -o flag (choices: added|modified|deleted) — restricts output to one change category; suppressed lists are emitted as empty arrays in JSON mode; only matching status letters appear in text mode. - Add --path-prefix flag — filters diff to paths starting with PREFIX before applying --only; counts and total_changes reflect the filtered view. - Rewrite module docstring: agent quickstart, full JSON schema with new fields, --only and --path-prefix sections. - Improve docstrings on _AddedEntry, _ModifiedEntry, _DeletedEntry, _DiffResult, _resolve_to_snapshot_id, _compute_diff, _emit_text, run. - _compute_diff now accepts only and path_prefix kwargs and passes them through.
Tests (53 new in test_cmd_snapshot_diff_supercharge.py) - TestJsonEnvelope: elapsed_ms, exit_code, per-category counts match list lengths - TestJsonSchema: all fields present, sha256: prefix on IDs, entry schemas - TestOnlyFilter: all three categories, text mode, short -o flag, invalid value - TestPathPrefixFilter: src/ scoping, docs/ exclusion, nonmatching prefix, --only + --path-prefix combined - TestStdinEnvelope: elapsed_ms, count fields, --only and --path-prefix in batch - TestSecurity: ANSI in paths (text sanitized, JSON preserved), path-prefix traversal is safe (startswith filter cannot escape manifest key space) - TestDiffProperties: self-diff, symmetric add/delete, all-modified, empty snaps - TestResolution: HEAD, commit ID, branch vs snapshot ID - TestResolveToSnapshotId: direct snap, branch, HEAD, case insensitive, None cases - TestComputeDiff: unit tests for only/path_prefix kwargs - TestLargeManifestStress: 500-file diff, exact add/modify counts verified - TestConcurrentStress: 10 threads diffing same pair, all succeed
0 comments
muse hub commit comment sha256:f185c5803852a6d625db5941bc684d5524cb28543dcd02cd68b780f8e912eb7d --body "your comment"
No comments yet. Be the first to start the discussion.