tdd · git:20261102.bc6f8af · 2026-11-02 · sha256 ac50dd365526473a

tdd git:20261102.bc6f8afA

Immutable. This exact content never changes and is served at /api/v1/blob/ac50dd365526473a.

No tool to install first
claude plugin marketplace add https://markdownregistry.com/mp/a/art_xaclspx3unk7i34e/ac50dd365526473a0f7fd74a7f11840659510c5f8db76c6db65d4b28a659d329.json

Then /plugin install tdd@markdownregistry-xaclspx3unk7i34e in Claude Code. It installs this exact version, the one graded A here, pinned to the commit it was graded at, and leaves it there.

---
name: tdd
description: Drives code changes through the Red-Green-Refactor test-driven development loop at public module seams. Use when building features test-first, writing unit or integration tests, or practicing red-green-refactor.
---

# Test-Driven Development (TDD)

Follow the strict **Red → Green → Refactor** loop on every behavioral increment, testing exclusively through public module seams.

## Decision tree

1. **Does the test reach into private functions, internal state variables, or internal helper call counts?**
   - **Yes** → Rewrite the test to invoke only the module's **public seam** and assert on observable outputs or returned errors.
   - **No** → Proceed to step 2.
2. **Does the module mix pure domain calculations with external I/O (DB, HTTP, filesystem)?**
   - **Yes** → Extract the pure calculation so 80%+ of boundary cases run in zero-mock unit tests; test the I/O adapter separately with one focused integration test.
   - **No** → Run the Red-Green-Refactor cycle below.

## The Red → Green → Refactor cycle

1. **RED (Write one failing test)**:
   - Write a single test named after the observable capability (`calculates prorated refund when subscription cancels mid-cycle`).
   - Run the test via `run_command` and verify it **fails for the expected behavioral reason** (not a syntax or import error).
2. **GREEN (Minimal production code)**:
   - Write the minimum genuine production code needed to make the failing test pass.
   - **Zero Test Tampering**: Never weaken, skip (`.skip`), or alter the test during the Green phase to manufacture a pass—production logic must satisfy the test contract.
   - Re-run the test and confirm it turns green.
3. **REFACTOR (Clean while green)**:
   - Eliminate duplication, flatten nested conditionals into guard clauses, and sharpen identifier names while keeping all tests green.
   - Never add new behavior during the Refactor phase.