The Test Passed. Would It Catch the Broken Implementation?
A pull request includes a retry helper and a passing test. The test checks that a refund response says succeeded. The implementation can still refund twice.
The quickest way to find out what that test establishes is to give it an implementation you know is wrong. If it stays green, the test is measuring something other than the property you intended.
This article uses the synthetic refund scenario in AFL’s When the Agent Acts Twice workbook. The records are invented, the provider is a local simulation, and no money moves. The exercise is useful for reviewing agent-written changes because a plausible test can make a plausible implementation look more complete than it is.
Start with the consequence
The requirement is one committed effect for one approved operation, including when the provider commits but its response is lost.
Notice what the requirement does not say. It does not demand one HTTP request. It does not demand a particular helper function. It does not say that every timeout must end with success. An unresolved outcome may need to remain pending until it can be reconciled.
Three tempting assertions miss different parts of that requirement:
| Assertion | Why a green result is insufficient |
|---|---|
| The retry helper ran twice | Two attempts can create two effects. |
The final response says succeeded |
Success on the second request says nothing about the first effect. |
| The provider was called once | A legitimate recovery request may be necessary to obtain the original result. |
A mock-call assertion can still be useful. It might catch a wrong amount or an unauthorized destination. Its value depends on what was invoked and which arguments were checked. Calling a mock directly and asserting that it was called does not exercise the application at all.
Keep a known-bad implementation
The workbook includes both implementations behind the same regression. From the extracted issue directory, run:
LAB_IMPLEMENTATION=faulty node --test test/regression.test.mjsThe faulty client sends a new provider key for every attempt. The injected failure happens after the first effect commits but before the client receives a response. That location matters: a failure before commit would not expose this particular duplicate-effect defect.
The intended result is exit status 1 with actual effect count 2 and expected 1. Record the assertion output. A test runner that crashes before reaching the assertion has not demonstrated the check.
Now run the same regression against the repaired default:
node --test test/regression.test.mjsIt passes because retries retain the same approved operation identity and payload, and the simulated provider deduplicates that identity under its stated contract.
These two runs provide specific evidence: the check distinguishes this faulty implementation from this repair at this injected failure point. They do not prove the repaired implementation is free of other defects.
Ask which implementation the test could tolerate
During review, make a small table before adding more tests:
| Deliberate defect | Observable consequence | Check that should fail |
|---|---|---|
| New key on every retry | Multiple effects for one approved operation | Authoritative effect count |
| Amount changed after approval | Executed intent differs from approval | Rejection before external effect |
| New key after restart | Recovered delivery becomes a second operation | Identity and effect count across processes |
| Same key for every refund on an order | A second valid refund is suppressed | Two distinct approvals can create two effects |
The last row is easy to miss. Preventing duplicates by blocking all later work can satisfy a narrow safety assertion while breaking the product. Include the valid second operation in your coverage.
You do not need a large mutation-testing setup to use this reasoning. A retained faulty implementation and a controlled fixture make the first check reviewable. Keep them clearly separated from deployable code.
Test the assumption below the application
The workbook’s provider promises atomic key-and-effect recording and indefinite retention. Those promises make the repaired retry mechanism work. A mock that implements those promises is evidence about application behavior under them; it is not evidence that a real provider offers them.
For an integration, attach the provider contract or observed sandbox evidence. Test parameter mismatch, concurrent requests and the oldest retry your system permits. If the documented key lifetime is shorter than the retry horizon, a passing local test leaves a material question open.
The agent eval worksheet uses the same discipline for instruction changes: declare the evidence and decision rule before inspecting the result. Keep unknown or unevaluated properties visible.
Make the review note precise
Use this format:
Invariant:
Known-bad implementation:
Injected failure point:
Expected failing assertion:
Repaired result:
Provider or storage assumptions:
Cases still untested:A note saying “all tests pass” hides those boundaries. A note naming the defect caught, its consequence and the assumptions gives the next reviewer something they can challenge and reproduce.
The workbook includes the regression, additional restart and concurrency cases, and a separate answer key. Start with the faulty test run, then explain why it failed before opening the repair.