agentleFS
oopsla5xxoopsla5xx/oops-skills/.claude/skills/implement-tdd/SKILL.md

implement-tdd

Skill4 starsChanged 3 months agoMITView on GitHub

Implement each step from the plan using TDD — write failing test first, then minimal code to pass, then refactor. Run for each unchecked step in the Plan section of .ai/tasks/<name>.md.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

29 rules. About 0 are common, 27 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈27

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Hard rule: Do not write implementation before having a failing test.

    line 10
  2. Distinctive:

    Before the first step, run the full test suite to confirm the baseline is green:

    line 16
  3. Distinctive:

    If the baseline is red → stop, report to user, do not implement on a red baseline.

    line 23
  4. Distinctive:

    Read the step's "Done when:" to know what the test needs to assert

    line 33
  5. Distinctive:

    Write the test — only test the behavior of this step, nothing more

    line 34
  6. Distinctive:

    Run the test: it must be red

    line 35
  7. Distinctive:

    If the test is red for the wrong reason → fix the test, do not write implementation.

    line 50
  8. Distinctive:

    Write the smallest implementation that can make the test green

    line 54
  9. Distinctive:

    Run the test: it must be green

    line 55
  10. Distinctive:

    Run full suite: must not introduce any new red

    line 56
  11. Distinctive:

    Do not add logic for cases that don't have a test yet

    line 59
  12. Distinctive:

    Do not add abstractions that aren't needed yet

    line 60
  13. Distinctive:

    Do not refactor related code outside the scope of this step

    line 61
  14. Distinctive:

    If the full suite has new red → find the regression, fix it before continuing.

    line 63
  15. Distinctive:

    Only refactor if the code just written has clear issues: bad names, duplicate logic, magic numbers

    line 67
  16. Distinctive:

    After each refactor change → run tests again

    line 68
  17. Distinctive:

    If tests go red during refactor → revert immediately, don't carry the debt

    line 69
  18. Distinctive:

    Commit with a clear message:

    line 82
  19. Very specific:

    Run the migration up: <migrate-command>

    line 101
  20. Distinctive:

    Verify schema is correct (query or inspect)

    line 102
  21. Distinctive:

    Run migration again → confirm idempotent Done when: both directions run cleanly.

    line 104
  22. Distinctive:

    If the project has component tests (Storybook, Testing Library) → use them.

    line 108
  23. Distinctive:

    Write a simple render test (snapshot or "renders without crash")

    line 109
  24. Distinctive:

    If possible — test interaction (click, input) Do not skip tests entirely for UI — a minimal render test still has value.

    line 111
  25. Distinctive:

    Do not skip tests entirely for UI — a minimal render test still has value.

    line 112
  26. Distinctive:

    Test at the integration layer, not unit.

    line 115
  27. Distinctive:

    Stop, ask the user, do not assume.

    line 118
  28. Distinctive:

    Run the full suite one final time

    line 132
  29. Very specific:

    Run lint and typecheck (get commands from .ai/commands.md)

    line 133

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Implement TDD

Implement each step in the ## Plan of the spec file following the TDD cycle.

Hard rule: Do not write implementation before having a failing test. No exceptions.


Setup

Before the first step, run the full test suite to confirm the baseline is green:

# Get the command from .ai/commands.md
<test-command>

If the baseline is red → stop, report to user, do not implement on a red baseline.


Cycle for each step in the Plan

Take the next unchecked - [ ] step from ## Plan in the spec file. Execute:

🔴 Red — Write the test first

  1. Read the step's "Done when:" to know what the test needs to assert
  2. Write the test — only test the behavior of this step, nothing more
  3. Run the test: it must be red

Correctly red test:

FAIL: expected X but got undefined   ← correct, function doesn't exist yet
FAIL: expected true but got false    ← correct, logic not yet implemented

Incorrectly red test (must fix before continuing):

SyntaxError / TypeError              ← test has a syntax error
Cannot find module                   ← wrong import path
Expected 2 arguments but got 1      ← test itself is written incorrectly

If the test is red for the wrong reason → fix the test, do not write implementation.

🟢 Green — Minimal code to pass

  1. Write the smallest implementation that can make the test green
  2. Run the test: it must be green
  3. Run full suite: must not introduce any new red

"Minimal" means:

  • Do not add logic for cases that don't have a test yet
  • Do not add abstractions that aren't needed yet
  • Do not refactor related code outside the scope of this step

If the full suite has new red → find the regression, fix it before continuing.

🔵 Refactor — Clean up while green

  1. Only refactor if the code just written has clear issues: bad names, duplicate logic, magic numbers
  2. After each refactor change → run tests again
  3. If tests go red during refactor → revert immediately, don't carry the debt

Do not refactor in this step:

  • Code belonging to other steps in the plan
  • Code unrelated to the current step
  • "Improvements" that are speculative (YAGNI)

✅ Tick and commit

  1. Mark the step as done in the spec file:
    - [x] 1. Create `src/auth/reset-token.ts` ...
  2. Commit with a clear message:
    test: <step just completed>
    feat: <step just completed>
    Or combine if small:
    feat: <step just completed> (with tests)

Then take the next step and repeat.


Special cases

Step is a DB migration: Tests don't follow the normal Red/Green cycle. Instead:

  1. Write the migration
  2. Run the migration up: <migrate-command>
  3. Verify schema is correct (query or inspect)
  4. Run rollback: <rollback-command>
  5. Run migration again → confirm idempotent Done when: both directions run cleanly.

Step is a UI component: If the project has component tests (Storybook, Testing Library) → use them. If not:

  1. Write a simple render test (snapshot or "renders without crash")
  2. Implement the component
  3. If possible — test interaction (click, input) Do not skip tests entirely for UI — a minimal render test still has value.

Step is wiring/integration: Test at the integration layer, not unit. Mock external services (email, payment) if needed. Do not mock your own internal code.

Step has an Open question [BLOCKING]: Stop, ask the user, do not assume. Do not implement a step with a blocking question.


Stop and report when

  • Full suite is red after implementation and the cause is unknown → report immediately, do not continue implementing
  • Scope has expanded beyond the spec → stop, update spec/plan, confirm with user
  • You discover the plan has the wrong order (step N needs code from step N+2) → report it, do not reorder on your own

After all steps are done

  1. Run the full suite one final time
  2. Run lint and typecheck (get commands from .ai/commands.md)
  3. Move on to /self-check (Phase 3 of task-flow)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.