Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Golden Tests

tests/golden.rs is the end-to-end lock on the score stability contract: it re-scores the local corpus in tests/assets/raw/ through the exact code path of the binary (blurdetector::run with the CLI defaults) and byte-compares the resulting CSV report with the golden references in tests/assets/golden/. Any difference — a score, a rounding, a column, a line ending — fails the test.

Two configurations are locked:

Golden fileConfiguration
tests/assets/golden/default.csvCLI defaults (--pre-blur 0)
tests/assets/golden/preblur.csvCLI defaults with --pre-blur 0.8

Running

cargo test --release --test golden -- --ignored

The tests are #[ignore]d by default because they need the gitignored CR3 corpus (absent in CI and on fresh clones) and a release build to run in reasonable time. Run the guard on any machine holding the corpus before merging a change that touches the pipeline — especially an optimization.

When it fails

The failure message pinpoints the first differing CSV line, keeps the candidate report in the temp directory for inspection, and prints the drift command ready to paste:

scores diverged from tests/assets/golden/default.csv
first difference at line 42:
  golden   : tests\assets\raw\IMG_6545.CR3,sharp,251.6,73.9,
  candidate: tests\assets\raw\IMG_6545.CR3,sharp,251.7,73.9,
candidate kept at /tmp/blurdetector-candidate-default-1234.csv

An unintended difference means the change broke parity: fix the code, not the goldens.

Measuring drift

If the difference is intended (exceptional — see the procedure), quantify it first:

cargo run --release --example drift_report -- tests/assets/golden/default.csv candidate.csv [threshold]

The report prints:

  • how many files were compared, and how many exist on only one side;
  • the median and maximum relative score deltas;
  • the Spearman rank correlation — 1.0 means the new scores order photos exactly like the old ones, which is what threshold-based culling actually depends on;
  • the verdict flips at the given threshold (default 100), listed file by file;
  • the median new/old score ratio and the equivalent threshold it suggests for existing calibrations.

Regenerating

Only once a scoring change is measured and announced:

# POSIX shell
BLURDETECTOR_UPDATE_GOLDEN=1 cargo test --release --test golden -- --ignored
# PowerShell
$env:BLURDETECTOR_UPDATE_GOLDEN = "1"; cargo test --release --test golden -- --ignored

The regenerated CSVs in tests/assets/golden/ are committed with the change; from that point on they are the contract every future refactor is held to.