tdd
tdd — Red-Green-Refactor for AI-coded features
Trigger
Fire when:
- User says "TDD this", "red-green-refactor", "test-first"
- New-feature task under [[afk-vs-hitl-tasks]] AFK mode + test infra present
Precondition
Test loop <60s per [[feedback-loops-are-the-ceiling]]. Slow loop? Fix loop FIRST. Never skip TDD to dodge slow tests.
Process — strict order
| Step | Action | Verify |
|---|---|---|
| 1. RED | Write ONE failing test. Smallest observable behavior. | Run. MUST see FAIL with expected error. |
| 2. GREEN | Minimum code to pass. No extras. No untested error handling. | Run. MUST see PASS. |
| 3. REFACTOR | Clean impl + test. Tests stay green. Extract deep modules per [[deep-modules-over-shallow]]. Rename for clarity. | Run. Stays green. |
| 4. LOOP | Next behavior. Back to RED. | — |
Anti-cheat — hard rules
- MUST see failing test output before writing production code
- MUST NOT write multiple tests before first passes
- MUST NOT skip refactor — design emerges there
- MUST NOT rewrite test to match implementation after the fact
Test written AFTER code = code-shaped test, not spec-shaped. Rejects the point.
Output shape per cycle
RED: <test name> → <expected fail message>
GREEN: <files changed, LOC delta>
REFACTOR: <what got extracted/renamed>
Source
Kent Beck, Test-Driven Development: By Example (1999). AI-coding context: Matt Pocock workshop, 2026-07-03.