Overview
The preferred implementation pattern is red, green, refactor:
- Red: write one test that expresses the next behavior and confirm that it fails for the
expected reason.
- Green: make the implementation change required for the test to pass.
- Refactor: improve the code while preserving the passing behavior.
This ordering matters. Agents often produce weak tests when they implement an entire feature first and add tests afterward. They may test their own chosen structure rather than the required behavior, mirror the implementation too closely, or create tests that pass without proving much.
Writing the failing test first instruments the desired behavior before the implementation exists. The agent must then satisfy an external signal rather than retroactively justify code it already wrote. The test becomes part of the task definition.
After the focused test passes, the agent should run the broader feedback loops required by the repository. In the demonstrated workflow, these include the test suite and the type checker. A type error or failing test becomes a concrete next action. The agent fixes the error, reruns the checks, and commits only after the feedback is green.
Feedback loops are not limited to unit tests. The principle is that the repository must be able to tell the agent whether a change is acceptable. A deep service with a clear interface can be tested as a meaningful unit. A fragmented collection of tiny functions provides weaker signals because tests may cover isolated pieces while missing the behavior that emerges from their interaction.