Every detector in sanctifier-core has a golden snapshot of its findings,
powered by insta. This is the safety net that lets us add
and refactor detectors without silently regressing their output: any change to
what a detector reports shows up as a snapshot diff that a human must review.
tests/
├── detector_snapshots.rs # one #[test] per detector
├── gallery_snapshots.rs # full registry over the bug gallery
├── fixtures/detectors/<name>.rs # a focused fixture that trips <name>
├── fixtures/gallery/<bug>_*.rs # canonical vulnerable + fixed corpus
└── snapshots/ # reviewed golden output (committed)
├── detector_snapshots__<name>.snap
└── gallery_snapshots__<bug>_*.snap
detector_snapshots.rs runs a single detector against its fixture and asserts
the resulting Vec<RuleViolation> with insta::assert_yaml_snapshot!. The
fixtures intentionally also contain clean code paths, so the snapshot proves
both what the detector flags and what it correctly leaves alone.
gallery_snapshots.rs runs the full default RuleRegistry over the
canonical vulnerable-contract gallery — ten bug
classes, each as a vulnerable + fixed pair — so the shared corpus is wired into
the snapshot suite. See that gallery README for the bug-class → finding-code map.
# Run the detector snapshots (part of the normal suite too):
cargo test -p sanctifier-core --all-features --test detector_snapshots
# Or, with the insta runner (nicer output, used in CI):
cargo insta test -p sanctifier-core --all-featuresWhen a detector's output changes, the test fails and insta writes a
pending *.snap.new file next to the existing snapshot.
Install the helper once: cargo install cargo-insta.
# Interactively accept/reject each pending change:
cargo insta review
# Accept everything pending (only after eyeballing the diff):
cargo insta accept
# Throw away all pending changes:
cargo insta rejectAlways read the diff. A snapshot change means a detector now reports something
different — make sure that difference is intended before accepting, then commit
the updated .snap file alongside your code change.
- Add a fixture at
fixtures/detectors/<name>.rsthat triggers the detector (and ideally a clean path it must ignore). It only needs to parse as Rust — detectors analyze source withsyn, they do not compile it. - Add a
#[test]indetector_snapshots.rscallingassert_detector_snapshot. - Run
cargo insta test -p sanctifier-core --all-features, thencargo insta reviewto accept the new snapshot. - Commit the fixture, the test, and the generated
.snap.
CI runs cargo insta test -p sanctifier-core --all-features --check --unreferenced reject:
--checkfails the build on any snapshot diff (and never writes files), so unreviewed changes cannot merge.--unreferenced rejectfails if a.snapis left behind with no matching test, keeping the snapshot set tidy.