TDD Enforcement Algorithm
FreeNo executable scriptsNot checkedAlgorithmic decision tree enforcing test-first development via boolean conditions instead of imperatives
About this skill
TDD Enforcement Algorithm
Overview
Agents follow algorithmic decision trees (100% compliance) better than imperative instructions (0-33% compliance) for enforcing test-first development. Boolean conditions remove interpretation: "Does failing test exist? NO → STOP" vs "You MUST write tests first" (agent: "for complex code, mine is simple").
Core principle: Binary checks before implementation. Recovery mandates deleting untested code (no sunk cost exceptions).
When to Use
Use this algorithm when:
- About to write implementation code (functions, methods, classes)
- Code exists without tests (recovery path)
- Under pressure (time, sunk cost, authority) where TDD bypass tempting
- Need deterministic enforcement (no acceptable exceptions)
Use upstream TDD skill when:
- This algorithm says proceed (test exists, now implement)
- Learning RED-GREEN-REFACTOR methodology
- Understanding why TDD matters
Relationship:
- This skill: WHEN to use TDD (decision algorithm)
- Upstream skill: HOW to use TDD (implementation details)
Decision Algorithm: When to Write Tests First
1. Check for implementation code
Are you about to write implementation code?
- PASS: CONTINUE
- FAIL: GOTO 6
2. Check for prototype exception
Does throwaway prototype exception apply (user approved)?
- PASS: GOTO 6
- FAIL: CONTINUE
3. Check for failing test
Does a failing test exist for this code?
- PASS: GOTO 6
- FAIL: CONTINUE
4. Write failing test first
STOP writing implementation code. Write failing test first.
5. Verify test fails
Run project test command
- PASS (test runs and fails as expected): GOTO 6
- FAIL (test passes or doesn't run): GOTO 4 (fix test)
6. Proceed with implementation
Test exists OR not writing code OR approved exception - proceed
Recovery Algorithm: Already Wrote Code Without Tests?
7. Check for implementation code
Have you written ANY implementation code?
- PASS: CONTINUE
- FAIL: GOTO 10
8. Check for tests
Does that code have tests that failed first?
- PASS: GOTO 10
- FAIL: CONTINUE
9. Delete untested code
Delete the untested code. Execute: git reset --hard OR rm [files]. Do not keep as "reference".
- PASS: STOP
- FAIL: STOP
10. Continue
Tests exist OR no code written - continue
INVALID Conditions (NOT in algorithm, do NOT use)
These rationalizations are NOT VALID ALGORITHM CONDITIONS:
- "Is code too simple to test?" → NOT A VALID CONDITION
- "Is there time pressure?" → NOT A VALID CONDITION
- "Did I manually test it?" → NOT A VALID CONDITION
- "Will I add tests after?" → NOT A VALID CONDITION
- "Is deleting X hours wasteful?" → NOT A VALID CONDITION
- "Am I being pragmatic?" → NOT A VALID CONDITION
- "Can I keep as reference?" → NOT A VALID CONDITION
- "Is this exploratory code?" → NOT A VALID CONDITION (ask for throwaway prototype exception)
- "Tests after achieve same goal?" → NOT A VALID CONDITION
- "I already know it works?" → NOT A VALID CONDITION
All of these mean: Run the algorithm. Follow what it says.
Self-Test
Q1: You're about to write function calculateTotal(). What does Step 3 ask?
Answer: "Does a failing test exist?" If NO → Go to Step 4 (STOP, write test first)
Q2: I wrote 100 lines without tests. What does Recovery Step 3 say?
Answer: Delete the untested code. Execute: git reset --hard OR rm [files]
Q3: "This code is too simple to need tests" - is this a valid algorithm condition?
Answer: NO. Listed under INVALID conditions
Q4: Can I keep untested code as "reference" while writing tests?
Answer: NO. Recovery Step 3 says "Delete... Do not keep as 'reference'"
Five Mechanisms That Work
1. Boolean Conditions (No Interpretation)
Imperative: "You MUST write tests first" Agent rationalization: "For complex code. Mine is simple."
Algorithmic: "Does a failing test exist? → YES/NO" Agent: Binary check. Either test exists or it doesn't. No interpretation.
2. Explicit Invalid Conditions List
Imperative: "Regardless of simplicity or time pressure..." Agent: Still debates what "simple" means
Algorithmic: "Is code too simple to test?" → NOT A VALID CONDITION Agent: Sees rationalization explicitly invalidated. Can't use it.
3. Deterministic Execution Path with STOP
Imperative: Multiple MUST statements → agent balances priorities
Algorithmic:
Step 4: STOP writing implementation code
Write failing test first
Result: Single path. No choices. STOP prevents continuing.
4. Self-Test Forcing Comprehension
Quiz with correct answers:
Q1: About to write function. Step 3 asks?
Answer: Does a failing test exist?
Agents demonstrate understanding before proceeding. Catches comprehension failures early.
5. Unreachable Steps Proving Determinism
Step 5: [UNREACHABLE - if you reach here, you violated Step 4]
Demonstrates algorithm is deterministic. Reaching Step 5 = violat
Install TDD Enforcement Algorithm in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the TDD Enforcement Algorithm skill do?
Algorithmic decision tree enforcing test-first development via boolean conditions instead of imperatives
How do I install the TDD Enforcement Algorithm skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the TDD Enforcement Algorithm skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
by Anthropic