Contracts with a ladder of checks, an end-of-turn gate, retrospectives and shared lessons, time-to-delivery measurement, a library of 140 verification techniques and 20 recipes, personal data kept outside the clone, and releases with rollback. Standard library only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
3.1 KiB
id, title, answers, rung, section, languages, kinds, cost, detect, ran_here, verified
| id | title | answers | rung | section | languages | kinds | cost | detect | ran_here | verified |
|---|---|---|---|---|---|---|---|---|---|---|
| red-before-green | Prove a new test can fail by seeing it fail before the fix | Does this new test actually fail without my change, so its passing means something? | 3 | test-quality | any | general, money, parsing, state-machine | low | git --version | yes | ran |
Use when
- You fixed a bug and wrote a regression test.
- You added a feature and a test for it.
- Any time a test is the evidence for done: a test that cannot fail is not evidence.
This is a check on another check. The test itself is rung 3 (an example test). Seeing it fail on the old code adds confidence that the test is sensitive to the bug, but it does not raise the claim above rung 3; a property test or mutation run is what reaches rung 2.
Do not use when
- The change is a pure refactor with no behaviour change; there is no red to see. Use existing tests and
mutation-on-diff. - The failure would only be a compile error because the new API does not exist yet. Stub the API first so the test compiles and fails on behaviour.
Set up
Two ways to get the red run. Either write the test first and run it before editing the code, or after the fix revert only the fix and rerun. With git:
git stash push -- src/ # park the fix, keep the new tests
# or: git checkout HEAD~1 -- src/file # restore the old source
Minimal example
Bug: price(10, 100) returned 1000 instead of 900. Add the test in a separate file, tests/threshold.rs: #[test] fn threshold_discount() { assert_eq!(mycrate::price(10, 100), 900); }. If it lives in the same file as the fix, stashing the fix stashes the test too.
git stash push -- src/
cargo test threshold_discount # red
git stash pop
cargo test threshold_discount # green
Run
Run the exact new test by name on the old code, then on the new code.
Passing looks like: the first run fails with an assertion about the behaviour you fixed (left: 1000, right: 900), the second passes with 1 passed. Failure of the check: the test passes on the old code (it tests nothing about the bug), or fails for a different reason (a compile error, a missing file, a typo). Read the failure message, not just the exit status. Also confirm the test ran: 0 passed or no tests to run is not red.
As a contract check
{"id": "red-green", "claim": "The regression test fails on the pre-fix source and passes on the fixed source", "kind": "general", "rung": 3, "cmd": "git stash push -q -- src/ && ! cargo test threshold_discount; r=$?; git stash pop -q; test $r -eq 0 && cargo test threshold_discount", "expect": {"exit": 0}, "tier": "deep", "timeout_s": 600}
What a pass does not prove
- That the test fails for the right reason. Inspect the red failure output yourself.
- That the test is strong: it may fail on one input and miss nearby ones. Pair with
cargo-mutantsor a property test. - If the fix and the test touch the same files, stashing the wrong paths removes the test too; check that the red run still contains the test.
- Always restore the fix afterwards (
git stash pop) and rerun the green run.