Use during the implementation step of any requirement — after the spec exists and before declaring done. Defines the red/green/refactor loop, the Three Laws adapted for agents, the mandatory refactor step with its quality gates (Four Rules of Simple Design, CRAP threshold), and the backtracking protocol for when you get stuck.
78%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./.claude/skills/tdd-cycle/SKILL.mdSource discipline: Robert C. Martin's Three Laws of TDD and his Cycles of TDD. Rationale: a mind (or model) cannot pursue correct behavior and correct structure simultaneously. So the loop separates them: make it work (red→green), then make it right (refactor), never both in one move.
For an agent, Law 3 is the anti-speculation rule and it is the one you will
be most tempted to break: no "while I'm here" helpers, no handling of inputs
no test demands, no config options nobody asked for, no pub that nothing
external calls. Speculative generality is unverified code by construction —
nothing forces it, so cargo-mutants will flag it, and the traceability audit
has no REQ to hang it on. If you think the code will be needed: that is a
requirement; invoke spec-authoring first.
Step size: you may take larger green steps than a human keystroke-level cycle — one anchor scenario or one property at a time is the right grain — but never more than ONE failing test in existence at once, and never production code that no failing test forced.
Work from the spec's anchor scenarios and candidate laws as your test list, simplest first.
When the new test references production code that doesn't exist yet, the
honest red is blocked by a compile error — which is not a red, it's a
build failure. The discipline: write the production signature as a
compiling stub that returns a wrong-but-valid value (is_merge -> false
always, title -> String::new(), parse -> None). Run the suite → clean
assertion failures you can count and read. Then fill in the real body →
green.
Do NOT stub with unimplemented!()/todo!(): panicking stubs abort the
run at the first failure instead of giving you the full red picture. The
red count is itself a check on your spec partitioning — N scenarios should
produce N comprehensible failures, and zero failures against a stubbed
region tells you that region carries no behavior worth a spec (it's a data
carrier, not a rule — see testing-strategy on what doesn't get tests).
pricing: extract bracket lookup from compute_tax), so the history
replays as red→green→refactor and a reviewer can reject the refactor
without rejecting the behavior.As the tests get more specific, the production code should get more generic.
If you find yourself adding an if/match arm per test case, you are
hard-coding answers, not generalizing — the discount table grows a branch per
scenario instead of becoming arithmetic. Prefer the simplest transformation
that generalizes (constant → variable → conditional → iteration/recursion —
the Transformation Priority Premise ordering). A pile of special cases is
exactly the shape cargo-mutants shreds.
Symptom: the next test cannot be made green without a large rewrite — you need to change a lot of production code at once, outside the loop. This means an earlier green step generalized in the wrong direction.
Per Martin: the only honest fix is to backtrack — revert to an earlier green state, reorder the remaining tests (usually: you took a too-specific test too early), and take a different fork. For an agent the protocol is:
git stash / revert to the last green commit.Commit on green, every cycle, so this protocol is always cheap.
igouss/gitweb-rs
9ef2429
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.