agentleFS
jazzpujols34jazzpujols34/claude-skills/skills/tdd-discipline/SKILL.md

tdd-discipline

Skill0 starsChanged 5 months agoMITView on GitHub

Enforce test-first development. Trigger on "write a feature", "add functionality", "implement", or any code task that touches business logic. Auto-activate when writing code without tests. Pairs with debug-loop-breaker (prevention vs cure).

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. joeldevz/skynex-pi★ 2same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository13 other files it gives its agents.

The file

Show its rules and text

We split this skill into the rules it gives an agent

17 rules. About 0 are common, 14 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the relevant source files.

    line 30
  2. Distinctive:

    Write a test that:

    line 44
  3. Distinctive:

    If the test passes already → your test is wrong (it's not testing new behavior).

    line 60
  4. Distinctive:

    If it errors on import/setup → fix the test infrastructure, not the source code.

    line 62
  5. Distinctive:

    Write ONLY enough production code to make the failing test pass.

    line 66
  6. Distinctive:

    Don't add error handling for cases you haven't tested

    line 68
  7. Distinctive:

    Don't refactor while implementing

    line 69
  8. Distinctive:

    Don't add features beyond what the test covers

    line 70
  9. Distinctive:

    If it fails → fix the production code (not the test, unless the test had a typo).

    line 80
  10. Distinctive:

    If other tests broke → you introduced a regression.

    line 91
  11. Distinctive:

    When fixing a bug, the order is strict:

    line 99
  12. Distinctive:

    Never fix a bug without a test that proves it was broken.

    line 105
  13. Distinctive:

    Before committing any code change, verify:

    line 109
  14. Distinctive:

    If any check fails, do not commit.

    line 120
  15. Very specific:

    Vitest watch mode can mask failures: Run with --run flag for a clean single pass before committing.

    line 135
  16. Very specific:

    React component tests: use @testing-library/react, test user interactions not component internals.

    line 138
  17. Very specific:

    FastAPI tests: use TestClient from starlette.testclient.

    line 139

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 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

TDD Discipline

Adapted from tdd-guard by nizos; renamed to avoid clashing with that project (see README Credits).

No production code without a failing test first. This is the prevention layer — debug-loop-breaker is the cure.

Detection — When to Activate

Activate this skill when:

  • The user asks to build a new feature or add functionality
  • You're about to write business logic, API endpoints, or data transformations
  • You're fixing a bug (write a test that reproduces it FIRST)
  • Any code change that could break existing behavior

Do NOT activate for:

  • Config files, env vars, styling-only changes
  • Documentation, comments, type-only changes
  • One-off scripts, migrations, or prototyping (unless the user asks)

The Protocol

1. UNDERSTAND before you code

Read the relevant source files. Identify:

  • What function/component will change?
  • What are the inputs and expected outputs?
  • What are the edge cases?

State this in one sentence: "I'm going to [change X] so that [Y happens]. The test should verify [Z]."

2. WRITE the failing test first

# Create or open the test file adjacent to the source
# __tests__/thing.test.ts  or  test_thing.py

Write a test that:

  • Describes the DESIRED behavior (not current behavior)
  • Is specific: exact inputs → exact expected outputs
  • Covers the happy path AND at least one edge case
  • Will fail right now because the feature doesn't exist yet

3. RUN the test — confirm it fails

# JS/TS
npx vitest run path/to/test --reporter=verbose

# Python
pytest path/to/test -v

If the test passes already → your test is wrong (it's not testing new behavior). Rewrite it.

If it errors on import/setup → fix the test infrastructure, not the source code.

4. WRITE the minimum code to pass

Write ONLY enough production code to make the failing test pass. No more.

  • Don't add error handling for cases you haven't tested
  • Don't refactor while implementing
  • Don't add features beyond what the test covers

5. RUN the test — confirm it passes

npx vitest run path/to/test --reporter=verbose
# or
pytest path/to/test -v

If it fails → fix the production code (not the test, unless the test had a typo).

6. RUN all related tests

# Run the full test suite for the module/project
npx vitest run
# or
pytest

If other tests broke → you introduced a regression. Fix it before moving on.

7. REFACTOR (optional, only after green)

Now you can clean up — but only with all tests passing. Run tests after every refactor step.

Bug Fix Protocol

When fixing a bug, the order is strict:

  1. Reproduce — Write a test that triggers the bug (test should FAIL)
  2. Fix — Change the minimum code to make the test pass
  3. Verify — Run all tests to confirm no regressions

Never fix a bug without a test that proves it was broken.

Enforcement Checkpoints

Before committing any code change, verify:

CheckPass?
New behavior has a corresponding test
Test was written BEFORE the implementation
Test fails without the implementation (confirmed)
Test passes with the implementation
Full test suite passes (no regressions)
No test is skipped or .only'd

If any check fails, do not commit. Fix it first.

Anti-Patterns

PatternProblemInstead
Writing implementation first, tests afterTests become "confirmation tests" that just verify what you wrote, not what's correctTest first — always
Testing implementation detailsBrittle tests that break on refactorTest behavior: inputs → outputs
test.skip() or @pytest.mark.skipHiding failuresFix or delete the test
Mocking everythingTests pass but prod breaksMock boundaries only (DB, APIs), not internal functions
One giant test per featureCan't tell what brokeOne assertion per test case, descriptive names
"I'll add tests later"You won'tNow or never

Gotchas

  • Vitest watch mode can mask failures. Run with --run flag for a clean single pass before committing.
  • Python test discovery needs __init__.py in test directories sometimes. If pytest can't find tests, check this.
  • Don't mock the database in integration tests. Mocked tests can pass while a real migration or query fails in production. Use a real test DB.
  • React component tests: use @testing-library/react, test user interactions not component internals. screen.getByRole > wrapper.find('.class-name').
  • FastAPI tests: use TestClient from starlette.testclient. It runs synchronously, no need for async test setup.
  • Edge runtime (e.g. Cloudflare Workers): some Node.js test utilities don't work. Use a local edge emulator (such as Miniflare) for testing edge functions.

Upgrade Path: Hook-Based Enforcement

This skill is a behavioral guide — it relies on the agent following the protocol. For hard enforcement that blocks non-TDD file writes, install the nizos/tdd-guard Claude Code plugin:

# Installs hooks that intercept Write/Edit operations
# Uses a second model to validate TDD compliance
# Blocks file writes that don't follow Red-Green-Refactor
/plugin marketplace add nizos/tdd-guard
/plugin install tdd-guard@tdd-guard
/tdd-guard:setup

The plugin intercepts every file write via PreToolUse hooks, validates against TDD rules using a second model call, and blocks non-compliant operations. Adds latency per write but guarantees compliance. Worth it for critical codebases.

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.