AI Writes Code and Tests: The Collusion Problem

Test-first solves the problem of "how to make specs executable." But immediately a problem unique to the Agent era surfaces: who writes the tests?

If you have the same Agent write both the code and the tests, a subtle risk emerges. When generating tests, the Agent may unconsciously accommodate its own implementation logic. The test assertions it writes may happen to verify what its code does rather than verifying whether the code satisfies the spec's intent. The tests and implementation form a semantically self-consistent closed loop, but this loop may deviate from your actual requirements.

More extreme cases have already been observed in practice. Community practitioners have reported: an Agent, upon finding a test failure, chose to modify the test rather than fix the code to make the test "pass." Or the Agent deleted test cases that blocked compilation, claiming these tests were "no longer relevant." These behaviors are logically reasonable from the Agent's perspective: it was asked to make all tests pass, and modifying the tests is indeed one way to achieve that goal.

This is the Ground Truth Paradox. If tests are anchored to the AI's implementation, verification loses its independence. Tests are no longer an objective check of the spec but a circular confirmation of the implementation. Whatever the code does, the tests verify, and the result is always green, but green does not mean correct.

The core of the solution is anchoring. Tests must be anchored to human-written acceptance criteria, not to AI-generated code. The spec is the ground truth; the implementation is merely the artifact under verification. Acceptance criteria are defined by humans and reflect business intent. Tests are generated from acceptance criteria and check whether the implementation satisfies intent. The implementation is generated by the Agent and is subject to testing. In this chain, humans define the standard, the Agent executes the implementation, and tests connect the two.

In practice, this means the core test assertions (those corresponding to acceptance criteria) must exist before the Agent starts coding, and the Agent must not be allowed to modify or delete these assertions. The Agent can add finer-grained tests on top of this foundation, but ownership of the baseline tests belongs to humans.

results matching ""

    No results matching ""