Coding and Software-Engineering Agents › Test-driven changes
Language AI HandbookAll chapters The loop that makes coding agents reliable is the classic red-green-refactor rhythm, adapted so the agent can drive it. It has a specific structure you should internalize because every design decision in the implementation follows from it.
- Red: Establish a failing test that captures the desired behavior. If the test suite already has one, start here. If not, write a new test that fails for the right reason, and confirm it fails before touching the implementation.
- Green: Make the smallest change that turns the failing test green, using execution feedback from the test runner to guide the edits.
- Regress. Run the original suite after the change. Compare the named earlier passes with their new outcomes.
Check that the target fails because of the reported behavior. A missing dependency or a skipped case tells you little about whether the proposed edit is justified.
In the date fixture, the visible exception identifies the rejected leap day. Keep that exception in the run record so the green result can be related to the original failure.
Keep the edit close to the required behavior. This example constrains the changed path and verifies the final diff. Apply separate review to additional behavior changes.
Behavior under test is not behavior under use
Tests cover the cases they exercise. Run the existing suite because a changed function can affect callers other than the one in the issue. Passing that suite leaves unexercised behavior for review and further tests.
The general leap-year rule and a special case for 2000-02-29 can both pass the target test. The other visible tests and held-out cases check additional behavior. The reviewer can inspect whether the patch implements the rule and consider inputs the tests leave out.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!