agentleFS
Luis85Luis85/agentic-workflow/.claude/skills/tdd-cycle/SKILL.md

tdd-cycle

Skill0 starsChanged 6 months agoMITView on GitHub

Implement one slice via strict red -> green -> refactor. Failing test first, smallest passing code, refactor only on green. Use in stage 7 (Implementation). Triggers "TDD", "red-green-refactor", "test-first".

4 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

22 rules. 0 are common, 14 are distinctive, and 8 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 14

    Distinctive

    This author's own choices. Worth a look.

  • 8

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    After Beck's TDD and Pocock's tdd.

    line 9
  2. Distinctive:

    Read the task's acceptance criteria.

    line 19
  3. Distinctive:

    Write a single failing test that asserts that behavior through the public interface the spec defines.

    line 21
  4. Distinctive:

    Run the test. It must fail with a meaningful message — "expected X, got Y", not "ReferenceError: foo is not defined".

    line 22
  5. Very specific:

    Commit (or mark as ready to commit if the user hasn't authorized commits) using the canonical task-ID format from …

    line 23
  6. Distinctive:

    Write the smallest code change that makes the failing test pass.

    line 27
  7. Distinctive:

    Run the whole test suite — not just this test.

    line 28
  8. Distinctive:

    If something else turned red, you broke an invariant.

    line 29
  9. Very specific:

    Commit with the task-ID format: feat(<area>): <T-AREA-NNN> green — <same behavior phrasing>.

    line 30
  10. Distinctive:

    Look at the code you just wrote and the surrounding code.

    line 34
  11. Distinctive:

    If no refactor needed, say so explicitly and move on.

    line 41
  12. Very specific:

    Commit with the task-ID format: refactor(<area>): <T-AREA-NNN> <what you changed> (use refactor type rather than feat since no new behavior …

    line 42
  13. Very specific:

    When the dispatched task is fully green and refactored, append an entry to specs/<slug>/implementation-log.md: task ID, behaviors covered, …

    line 48
  14. Distinctive:

    Test after: If the test was written after the production code, it's not TDD.

    line 54
  15. Distinctive:

    Horizontal slicing: Don't write all the tests then all the code.

    line 55
  16. Distinctive:

    Refactor on red: Never. Refactoring without a green safety net is just changing code.

    line 57
  17. Distinctive:

    Refactor without a refactor: Don't ship code that you yourself would have flagged in review.

    line 58
  18. Very specific:

    Stop. Write a note in implementation-log.md describing what you tried, what you observed, and what you suspect is the root cause.

    line 62
  19. Very specific:

    Prefer SDK-style fakes over generic mocks (a fake UserStore over a generic mock of a method).

    line 67
  20. Distinctive:

    Never mock the system under test.

    line 68
  21. Distinctive:

    All acceptance criteria have at least one passing test asserting the observable behavior.

    line 73
  22. Very specific:

    No artifacts in specs/<slug>/ other than the log append — the design and spec are upstream-owned.

    line 84

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “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

TDD cycle

After Beck's TDD and Pocock's tdd. The cycle is the contract; if you skip a step, you've drifted from TDD into "tests after."

The cycle

This skill executes the currently dispatched task, not the whole backlog. /spec:implement is scoped to a single task per invocation (.claude/commands/spec/implement.md step 1); when this task is complete, return control to the orchestrator, which will dispatch the next ready task in a fresh /spec:implement call.

For the dispatched task <T-AREA-NNN>:

🔴 RED

  1. Read the task's acceptance criteria.
  2. Pick one observable behavior from the criteria — the smallest meaningful one.
  3. Write a single failing test that asserts that behavior through the public interface the spec defines. No private-method tests, no implementation peeking.
  4. Run the test. It must fail with a meaningful message — "expected X, got Y", not "ReferenceError: foo is not defined". If the failure is about missing scaffolding, write the minimum stubs to get a real assertion failure, then re-run.
  5. Commit (or mark as ready to commit if the user hasn't authorized commits) using the canonical task-ID format from .claude/commands/spec/implement.md: feat(<area>): <T-AREA-NNN> red — <behavior in plain English>. Always include the task ID so the commit traces back to its task per docs/traceability.md.

🟢 GREEN

  1. Write the smallest code change that makes the failing test pass. Resist generality. "The simplest thing that could possibly work."
  2. Run the whole test suite — not just this test. A green local with a red suite is a regression.
  3. If something else turned red, you broke an invariant. Revert and find a smaller change.
  4. Commit with the task-ID format: feat(<area>): <T-AREA-NNN> green — <same behavior phrasing>.

🔵 REFACTOR

  1. Look at the code you just wrote and the surrounding code. Ask:
    • Is there duplication? (extract)
    • Is a method too long? (split)
    • Is a module too shallow? (deepen — push more behavior behind a smaller interface)
    • Is naming honest? (rename to match the canonical term in docs/glossary/<slug>.md)
    • Is there feature envy / primitive obsession?
  2. Make at most one refactor per cycle. Run the suite after each change.
  3. If no refactor needed, say so explicitly and move on. Don't manufacture refactors.
  4. Commit with the task-ID format: refactor(<area>): <T-AREA-NNN> <what you changed> (use refactor type rather than feat since no new behavior is added).

Loop within the dispatched task only

Pick the next observable behavior from the same task's acceptance criteria. RED again. Continue until this task's acceptance criteria all pass.

When the dispatched task is fully green and refactored, append an entry to specs/<slug>/implementation-log.md: task ID, behaviors covered, tests added (count + names), files touched, commit SHAs (or "uncommitted").

Then return control to the orchestrator with a one-line summary. Do not pick up the next task — that's the orchestrator's job (it will dispatch a new /spec:implement for the next ready task per .claude/skills/orchestrate/PHASES.md Stage 7 loop).

Anti-patterns to refuse

  • Test after. If the test was written after the production code, it's not TDD; rewrite the test first or delete the production code.
  • Horizontal slicing. Don't write all the tests then all the code. Strict one-cycle-at-a-time.
  • Mock the unit under test. Mocks belong at system boundaries (network, filesystem, time, randomness). Mocking the thing you're testing means the test is meaningless.
  • Refactor on red. Never. Refactoring without a green safety net is just changing code.
  • Refactor without a refactor. Don't ship code that you yourself would have flagged in review.

When you can't make the test pass within two attempts

Stop. Write a note in implementation-log.md describing what you tried, what you observed, and what you suspect is the root cause. Return control to the orchestrator with a blocked summary. Don't keep grinding — the spec or design probably has a gap.

Mocking guidance

  • Mock at system boundaries: HTTP clients, database drivers, filesystem, clock, random.
  • Prefer SDK-style fakes over generic mocks (a fake UserStore over a generic mock of a method).
  • Never mock the system under test. Never mock value objects.
  • Inject dependencies; don't reach for globals to swap out.

Definition of done for a task

  • All acceptance criteria have at least one passing test asserting the observable behavior.
  • The whole test suite is green.
  • Lint and type-check pass.
  • An implementation-log.md entry was appended.
  • No TODO left in the code that wasn't already there.

Outputs

  • Source code changes.
  • Test additions.
  • One implementation-log.md append per task.
  • No artifacts in specs/<slug>/ other than the log append — the design and spec are upstream-owned.

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.