Coding and Software-Engineering Agents › Test-driven changes

Michael BrenndoerferDecember 1, 20262 min read
Language AI HandbookAll chapters
Part 49 of 67Long-Horizon Agents and Interoperability
Chapter 374Coding and Software-Engineering Agents › Test-driven changes
Reading section 4 of 12 · Test-driven changes · 2 minSection 4 of 12 · 2 min

Section 4 of 12 · 2 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

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-green loop
  1. 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.
  2. Green: Make the smallest change that turns the failing test green, using execution feedback from the test runner to guide the edits.
  3. 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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy