Evidence-First Testing
A green test proves only that the current code satisfies that test. To call a test regression
evidence, show the counterfactual: the focused signal rejects the faulty behavior and accepts
the repaired behavior.
Choose the claim and evidence
First classify what the red state means:
- Defect reproduction: the current implementation violates an existing contract.
- Contract test: requested new or changed behavior is not implemented yet; an expected red
state is not proof of a pre-existing defect.
- Flaky or environment-specific failure: logs, inputs, seeds, timing, versions, and
environment details must travel with the result.
Before implementing or repairing the claimed behavior, obtain the smallest reliable signal:
- an existing failing test;
- a new focused test or minimal reproducer;
- a build, type-check, request, trace, or command that exposes the defect;
- for flaky or environment-specific failures, preserved logs, inputs, seeds, timing, and environment details.
Record the exact command or procedure, inputs, expected result, observed result, environment,
and exit status. Confirm that the signal fails for the expected reason. An unrelated setup,
fixture, import, or environment failure is not red-state evidence.
Enforce the gate
For bug fixes, regression tests, and behavior changes with a testable contract, use this order:
- Inspect and diagnose without changing the relevant behavior.
- Run the focused signal against the current code and record the red-state result.
- Make the smallest justified implementation change.
- Re-run the same signal and confirm it turns green.
- Run the smallest broader suite or check that is required by the repository, the user, or
a still-credible failure category. Broaden only when the changed contract, boundary, or
failure mode requires it; do not use a fixed test count or line-count comparison as a
substitute for evidence.
Do not begin the implementation step until a focused signal exists. A bug fix requires
defect-specific red-state evidence; a new behavior may use an expected-red contract test.
If no safe red state or counterfactual can be established, report the evidence as INCOMPLETE
instead of calling the test regression-proof. Reading code, adding diagnostic logging, or
creating a test fixture is allowed when it does not repair or bypass the claim.
When a plan or task-status interface is available, keep implementation pending until the
evidence step is complete.
Validate the test itself
When adding or changing tests:
- Make assertions observable and specific to the claimed behavior.
- Keep the expected result independent from production code, constants, helpers, or generated
answers where practical; a test should not merely restate the implementation.
- Verify that a new regression test fails on the faulty implementation.
- Check that a repaired flaky test is stable across enough repetitions to support the claim.
- Add coverage for distinct acceptance conditions or credible failure modes, not to reach a
preset number of cases.
- A test may be more involved than the implementation when it exercises a real boundary or
independent oracle; explain that evidence need instead of judging by code length.
- Avoid weakening, deleting, skipping, or broadly mocking a failing assertion merely to make the suite green.
- Distinguish product defects, test defects, and environment defects before editing.
Recover when the fix came first
If behavior was already changed, restore the missing counterfactual by running the test against one of:
- the parent or known-bad revision;
- the implementation with the relevant fix temporarily reverted;
- a targeted mutation that recreates the defect.
Preserve unrelated working-tree changes while doing this. If no safe counterfactual is feasible,
state that the post-change pass is real but the regression proof is unverified; a first-run pass
is not sufficient.
Report evidence
Report:
- Focused signal: command or procedure and the input;
- Before change: red result and why it is the expected failure;
- Change: the smallest behavior change made;
- After change: green result from the same signal;
- Broader checks: the relevant suite or check and its result;
- Limitations: missing reproduction, unsafe counterfactual, or environment constraint.
State limitations plainly when the original failure could not be reproduced.
1---2name: evidence-first-testing3description: Preserve failure evidence and prove that tests detect the behavior they claim to cover. Use for bug fixes, regression coverage, test changes, flaky-test investigation, and behavior changes with a concrete acceptance contract; do not use for documentation-only or formatting-only work.4---56# Evidence-First Testing78A green test proves only that the current code satisfies that test. To call a test regression9evidence, show the counterfactual: the focused signal rejects the faulty behavior and accepts10the repaired behavior.1112## Choose the claim and evidence1314First classify what the red state means:1516- **Defect reproduction:** the current implementation violates an existing contract.17- **Contract test:** requested new or changed behavior is not implemented yet; an expected red18 state is not proof of a pre-existing defect.19- **Flaky or environment-specific failure:** logs, inputs, seeds, timing, versions, and20 environment details must travel with the result.2122Before implementing or repairing the claimed behavior, obtain the smallest reliable signal:2324- an existing failing test;25- a new focused test or minimal reproducer;26- a build, type-check, request, trace, or command that exposes the defect;27- for flaky or environment-specific failures, preserved logs, inputs, seeds, timing, and environment details.2829Record the exact command or procedure, inputs, expected result, observed result, environment,30and exit status. Confirm that the signal fails for the expected reason. An unrelated setup,31fixture, import, or environment failure is not red-state evidence.3233## Enforce the gate3435For bug fixes, regression tests, and behavior changes with a testable contract, use this order:36371. Inspect and diagnose without changing the relevant behavior.382. Run the focused signal against the current code and record the red-state result.393. Make the smallest justified implementation change.404. Re-run the same signal and confirm it turns green.415. Run the smallest broader suite or check that is required by the repository, the user, or42 a still-credible failure category. Broaden only when the changed contract, boundary, or43 failure mode requires it; do not use a fixed test count or line-count comparison as a44 substitute for evidence.4546Do not begin the implementation step until a focused signal exists. A bug fix requires47defect-specific red-state evidence; a new behavior may use an expected-red contract test.48If no safe red state or counterfactual can be established, report the evidence as INCOMPLETE49instead of calling the test regression-proof. Reading code, adding diagnostic logging, or50creating a test fixture is allowed when it does not repair or bypass the claim.5152When a plan or task-status interface is available, keep implementation pending until the53evidence step is complete.5455## Validate the test itself5657When adding or changing tests:5859- Make assertions observable and specific to the claimed behavior.60- Keep the expected result independent from production code, constants, helpers, or generated61 answers where practical; a test should not merely restate the implementation.62- Verify that a new regression test fails on the faulty implementation.63- Check that a repaired flaky test is stable across enough repetitions to support the claim.64- Add coverage for distinct acceptance conditions or credible failure modes, not to reach a65 preset number of cases.66- A test may be more involved than the implementation when it exercises a real boundary or67 independent oracle; explain that evidence need instead of judging by code length.68- Avoid weakening, deleting, skipping, or broadly mocking a failing assertion merely to make the suite green.69- Distinguish product defects, test defects, and environment defects before editing.7071## Recover when the fix came first7273If behavior was already changed, restore the missing counterfactual by running the test against one of:7475- the parent or known-bad revision;76- the implementation with the relevant fix temporarily reverted;77- a targeted mutation that recreates the defect.7879Preserve unrelated working-tree changes while doing this. If no safe counterfactual is feasible,80state that the post-change pass is real but the regression proof is unverified; a first-run pass81is not sufficient.8283## Report evidence8485Report:8687- **Focused signal:** command or procedure and the input;88- **Before change:** red result and why it is the expected failure;89- **Change:** the smallest behavior change made;90- **After change:** green result from the same signal;91- **Broader checks:** the relevant suite or check and its result;92- **Limitations:** missing reproduction, unsafe counterfactual, or environment constraint.9394State limitations plainly when the original failure could not be reproduced.