agentleFS
Reef123Reef123/OpenVera/.claude/skills/tdd/SKILL.md

tdd

Skill9 starsChanged 5 months agoMITView on GitHub

Red-green-refactor cycle for /build full Phase 5. Internal skill — invoked by phases.md, not by the user. Governs HOW each test gets written, not WHICH tests to write (that's phase-plan.md).

193 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use make-bot-ui, Poteto Mode and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • eryzerzSkill

    make-bot-ui

    Use when building a custom UI (page, dashboard, buttons) that should wake a Grok Bot over a webhook, when the user must provide a webhook sender key, or when exposing that UI on Tailscale.

    Also in 8 projects that use this

  • jtarorehSkill

    Poteto Mode

    poteto's agent style for concise, detailed responses, deliberate subagents, unslopped prose, simple code, and verified work. Use for poteto, /poteto-mode, or requests to work in this style.

    Also in 5 projects that use this

  • risadamsSkill

    which-skill

    Router over this pack's skills and flows. Ask it "which skill fits X" when you don't remember what's available.

    Also in 7 projects that use this

  • TheOnlyFusionCubeSkill

    principle-attack-the-premise

    Inventory who actually owns or exhibits the imbalance, then challenge the shared premise before writing another patch. Use when two or more fixes that share one premise have failed the same gate.

    Also in 11 projects that use this

  • TheOnlyFusionCubeSkill

    principle-test-behavior-not-implementation

    Call the system the way its consumer does and assert meaningful observable output; avoid mocks or assertions that only mirror internal calls. Use when when writing or evaluating tests.

    Also in 11 projects that use this

  • shreyT19Skill

    principle-laziness-protocol

    Apply when refactoring, evaluating diff size, or tempted to add abstractions, layers, or signal threading. Bias toward deletion and the smallest change that solves the problem.

    Also in 22 projects that use this

The file

We split this skill into the rules it gives an agent

11 rules. 0 are common, 9 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 177 edited versions we read keep these.

  • 9

    Distinctive

    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. Very specific:

    Write the test file (or append to an existing one).

    line 31
  2. Distinctive:

    Run the test. See it fail.

    line 32
  3. Distinctive:

    Write the smallest possible implementation that makes the test pass.

    line 37
  4. Distinctive:

    Run the test. See it pass.

    line 38
  5. Distinctive:

    Run the rest of the suite.

    line 39
  6. Distinctive:

    Tripwire: if green required more than ~10 lines, the test was probably too coarse.

    line 40
  7. Distinctive:

    After each refactor edit, re-run the test.

    line 46
  8. Distinctive:

    Tripwire: if a refactor turns the test red, you changed behavior, not structure.

    line 47
  9. Very specific:

    EARS-compatible when the acceptance criterion is EARS: If the criterion in handoff.md ## Invariants is When <event>, the system shall …

    line 59
  10. Distinctive:

    If a test would need to read multiple files, mock multiple services, or set up half the system — the unit is wrong.

    line 62
  11. Distinctive:

    After every green, before the next red.

    line 82

“Common” is measured: kept by at least 6 in 10 of the 177 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

Phase 5 already prescribes test-first; this skill enforces the loop.


When this fires

/build full Phase 5 entry. The phase-plan.md test spec for the current phase is already written — it names WHICH behaviors to test. This skill governs how each one gets implemented.

Skip this skill for:

  • V0 builds (/build new) — validation is browser/command/validator-agent, not red-green-refactor.
  • Targeted Fix path of /build full — no Phase 5, no test spec, fast change.
  • Phases 1-4 (PRD / Tech Design / Arch Review / Phase Plan) — no code written.

The cycle

For each behavior in the phase's test spec, complete one full RED → GREEN → REFACTOR loop before starting the next.

RED — Write the failing test

  1. Pick ONE behavior from the test spec. Not the easiest, not the hardest — the next in the spec's order.
  2. Write the test file (or append to an existing one). Test name reads as the expected outcome: returns_normalized_path_when_given_relative_input over test_one.
  3. Run the test. See it fail. Read the failure message.
  4. Tripwire: failure says "module not found," "no such function," or "import error" — you haven't actually tested the behavior, you've tested that code doesn't exist yet. Fix that: add the minimum scaffolding so the failure becomes an assertion failure (function exists, returns wrong thing). The first real RED is an assertion failure.

GREEN — Smallest code that passes

  1. Write the smallest possible implementation that makes the test pass. Hard-coded return values are allowed when only one case is tested.
  2. Run the test. See it pass.
  3. Run the rest of the suite. Confirm nothing else broke.
  4. Tripwire: if green required more than ~10 lines, the test was probably too coarse. Note this — the next test will refine, but flag it in the build-spec output so reviewers can see why.

REFACTOR — Improve structure on green

  1. Tests are green. Now improve the code without changing behavior.
  2. Rename misleading identifiers. Extract duplication. Simplify conditionals.
  3. After each refactor edit, re-run the test. Stay green.
  4. Tripwire: if a refactor turns the test red, you changed behavior, not structure. Revert and try again.
  5. Skip refactor only when the next test in the spec will obviously restructure this code (e.g., next test forces extraction into a function). Note "deferred to next cycle" in the build-spec.

Then return to RED with the next behavior.


What makes a good failing test

  • One observable behavior per test. Not "the whole feature works" — one input → one expected output, or one event → one expected state change.
  • Names the outcome, not the mechanism. rejects_when_path_escapes_root over test_path_validation.
  • Fails for the right reason. Assertion failure on the value being tested. Not ImportError, not syntax error, not test-runner config drift.
  • EARS-compatible when the acceptance criterion is EARS. If the criterion in handoff.md ## Invariants is When <event>, the system shall <response>, the test name and assertion mirror that: when_<event>_shall_<response>. EARS notation reference lives in .claude/skills/build/v0-stages.md.
  • Independent. Doesn't depend on test execution order. Setup and teardown are explicit.

If a test would need to read multiple files, mock multiple services, or set up half the system — the unit is wrong. Move it to integration tests or shrink the unit.


Smallest code that passes

The point of "smallest" is to force the next test to do the generalization work, not your imagination.

  • One test covers one input → return that value hard-coded.
  • Two tests cover two inputs → add an if.
  • Three tests with the same shape → extract the pattern.

This is sometimes called "fake it 'til you make it" or "triangulation." Either is fine. What's not fine: writing the full generalized implementation when only one test exists. That's speculative abstraction — the next test might force a different shape and the abstraction wastes effort.

Exception: if the implementation is genuinely one line (return x + y), write it. Don't ceremoniously hard-code return 5 first when the real implementation is obvious and equally short.


When to refactor

After every green, before the next red. The green test is the safety net — refactor while it's there.

Refactor when:

  • A name reads wrong on second look.
  • Two blocks of code do the same thing.
  • A function has grown past one screen.
  • A conditional has more than two branches and the branches share structure.

Skip refactor when:

  • The next test in the spec will obviously restructure this code anyway. Refactoring now means refactoring again in 5 minutes. Note "deferred" and move on.
  • The structure is already clean. Don't refactor for the sake of it. Tripwire: "what specifically am I improving?" If you can't name it, skip.

Anti-patterns

Anti-patternFix
Writing all tests first, then all codeWaterfall in TDD clothing. One test, one implementation, one refactor — then the next test.
Testing implementation, not behaviorTests asserting "function X called function Y" instead of "given input X, output is Y" couple tests to refactors and break on every cleanup.
Refactoring while redThe safety net is gone. Get to green first, then refactor.
Modifying tests after they pass to match what the code actually doesThis is weakening tests. Covered by .claude/rules/test-integrity.md — don't do it, fix the code instead.
Skipping the "see it fail" stepIf you didn't watch the test fail, you don't know it can fail. Run it once on no implementation.
Tests that pass without the implementation existingThe test isn't actually exercising the unit under test. Verify by deleting the implementation — the test must now fail.

What this skill does NOT cover

  • Test selection — which behaviors to test. That's .claude/skills/build/templates/phase-plan.md test specs, written in Phase 4.
  • Test infrastructure setup — which runner, which assertion library, which fixtures pattern. That's Phase 2 Tech Design, decided per-project.
  • EARS criteria writing — while/when/shall notation. Reference: .claude/skills/build/v0-stages.md § handoff.md Invariants.
  • Integration tests across multiple components — TDD applies, but the cycle is slower and the "smallest code that passes" rule loosens. This skill is calibrated to unit tests. For integration, use the same loop but expect each red→green to take longer.
  • Test integrity (don't weaken tests) — .claude/rules/test-integrity.md covers this. Skill references, doesn't duplicate.

Author: Shareef Ellis · @shareefatwork

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.