agentleFS
michaelalbermichaelalber/ai-toolkit/skills/tdd-loop/SKILL.md

tdd-loop

Skill3 starsChanged 3 months agoMITView on GitHub

The canonical RED-GREEN-REFACTOR inner loop. Enforces behavioral, structure-insensitive tests and prohibits horizontal slicing. Use when writing any new code test-first, managing TDD phase transitions, or as the inner loop for qrspi-implement, qraspi-implement, or any other implementation skill. Do NOT use to audit existing test suites — use evaluate-tests instead.

9 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 8

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every test must satisfy both before leaving RED:

    line 18
  2. Distinctive:

    Write ONE failing test for the next smallest observable behavior

    line 53
  3. Distinctive:

    Run the suite — the new test must fail for a semantic reason (not import/syntax)

    line 54
  4. Distinctive:

    All other tests must still pass

    line 55
  5. Distinctive:

    Write the minimum code to pass the failing test — nothing it does not require (no unrequested error handling, config, edge cases, or "while …

    line 58
  6. Distinctive:

    Prefer: Fake It (hardcode) → Obvious Implementation → Triangulation

    line 59
  7. Distinctive:

    Run the suite — all tests must pass

    line 60
  8. Distinctive:

    Run tests after every change — revert immediately if red

    line 65

“Common” is measured: kept by at least 6 in 10 of the 9 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 (Red-Green-Refactor)

"Write tests that are sensitive to behavior changes, insensitive to structure changes." — Kent Beck

Two Critical Properties

Every test must satisfy both before leaving RED:

PropertyA compliant test...A violation looks like
Behavioralfails when the observable outcome breaksassert repo.save.called — verifies a method was called, not what the system produced
Structure-insensitivesurvives a rename-only or extract-method refactorassert order._total == 100 — reads internal state; breaks on any rename

The Failure Mode: Horizontal Slicing

The most common TDD failure in AI-generated code:

# WRONG — horizontal slice
def test_register(): ...
def test_login(): ...
def test_logout(): ...
# ... then all implementation
class Auth: ...
# RIGHT — vertical slice
def test_register(): ...    # one test
class Auth:                 # minimal code to pass it
    def register(): ...
# refactor → commit → next test
def test_login(): ...

Horizontal slicing produces tests that were never red, implementations that were never minimal, and refactoring that was never constrained by a safety net. Never accumulate unimplemented tests.

The Cycle — One test → one implementation → repeat

RED

  1. Write ONE failing test for the next smallest observable behavior
  2. Run the suite — the new test must fail for a semantic reason (not import/syntax)
  3. All other tests must still pass

GREEN

  1. Write the minimum code to pass the failing test — nothing it does not require (no unrequested error handling, config, edge cases, or "while I'm here" features)
  2. Prefer: Fake It (hardcode) → Obvious Implementation → Triangulation
  3. Run the suite — all tests must pass
  4. Strategies & per-language idioms (.NET/Python/PHP/TS): green idioms on demand; for .NET test structure see test-scaffold

REFACTOR

  1. One structural change at a time — behavior must not change (no bug fixes, no new features; those start a new RED)
  2. Run tests after every change — revert immediately if red
  3. Smell→refactoring recipes: code smells · refactoring catalog on demand

Per-Cycle Self-Check

  • This test was red before I wrote any implementation
  • This test asserts an observable outcome, not a method call or internal state
  • A rename-only refactor would NOT break this test
  • My implementation passes this test and no others I have not written yet
  • All tests are green entering REFACTOR

State Block

<tdd-state>
phase: RED | GREEN | REFACTOR
iteration: N
current_test: [test name]
failure_reason: [semantic description — not "syntax error"]
tests_passing: true | false
</tdd-state>

Modes & Companions

The one canonical loop (GREEN/REFACTOR depth in references/ above). Companions are modes and audits, not alternatives:

NeedSkill
AI drives all phases autonomously (defers here for mechanics)tdd-agent
Audit test quality or TDD compliance after the factevaluate-tests
.NET test conventions — xUnit / AAA / mockstest-scaffold
RED before/after examplesBehavioral Examples

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.