wiki / concepts / tdd-with-agents
TDD With Agents
Machine ingest — raw context
loading…
~… tokensappend .md to any wiki URL for this view
TDD With Agents
Test-driven development as the control mechanism for agent-produced code. Write the test first (RED), make it pass (GREEN), then refactor. With agents, the test is the verifiable success criteria that lets the agent loop independently.
Why it matters now
matt pocock: “Bad code is now the most expensive it has ever been.” Agents ship volume. Without tests as the gate, the volume is slop. TDD turns karpathy four guidelines #4 (goal-driven execution) from principle into practice: “fix the bug” → “write a test that reproduces it, then make it pass.” See also red green tdd and simon willison’s agentic engineering patterns.
The loop
- RED — write a failing test that encodes the requirement.
- GREEN — write minimum code to pass the test. Nothing speculative.
- REFACTOR — improve structure without changing behavior. karpathy four guidelines #3 (surgical changes) governs this step.
How agents change it
- The test IS the spec for the agent. A good test lets the agent loop autonomously because it knows when it’s done.
- Each tracer bullet ticket should ship with its test — the slice is verifiable because the test exists.
- The agent can run the test and report real results — no “I think it works.”
Apply it (Agent Recipe)
- Role: Test-driven implementation specialist.
- When to trigger: Writing new functionality or fixing a reported defect.
- Instruction:
- Write an isolated test case asserting target behavior.
- Run the test suite and verify the test fails for the expected reason (RED).
- Write the minimal implementation required to pass the test (GREEN).
- Refactor code structure while keeping the test suite green (REFACTOR).
- Verification:
npm test - Pitfalls to avoid: Writing tests after implementation; mocking out the actual unit under test.
Related
karpathy four guidelines, tracer bullets, idea to ship flow, grilling doctrine, red green tdd.
Evidence — verified primary sources
| karpathy-guidelines-skill-2026 | https://github.com/multica-ai/andrej-karpathy-skills/blob/main/skills/karpathy-guidelines/SKILL.md | ingested 2026-08-22 sha256:3dbba31cbdb8… |
| aihero-dev-homepage-2026 | https://www.aihero.dev/ | ingested 2026-08-22 sha256:231157fed45f… |
| simon-willison-red-green-tdd-2026 | https://simonwillison.net/guides/agentic-engineering-patterns/red-green-tdd/ | ingested 2026-08-22 sha256:a578765f0bee… |
Graph context
References (4)
Matt Pocock: "Bad code is now the most expensive it has ever been." Agents ship volume.Karpathy's Four GuidelinesRed/Green TDDand simon-willison's agentic-engineering-patterns.Tracer Bulletsticket should ship with its test — the slice is Referenced by (9)
Agent Harness EngineeringAgentic Manual TestingAutomated Eval EngineeringConformance Suites as Fitness FunctionsDesigning for VerifiabilityIdea-to-Ship FlowKarpathy's Four Guidelinesin miniature and powers tracer-bullets. #1 isRed/Green TDDbroader agent TDD workflowTracer Bullets. See idea-to-ship-flow.