agentleFS
dork-labsdork-labs/dorkos/.claude/skills/test-driven-development/SKILL.md

test-driven-development

Skill11 starsChanged 48 days agoMITView on GitHub

Use when implementing any feature or bugfix, before writing implementation code

190 other projects use a version of this, 118 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use chinese-code-review, chinese-commit-conventions 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.
  • Leodorareluctant259Skill

    chinese-code-review

    中文代码审查规范——在保持专业严谨的同时,用符合国内团队文化的方式给出有效反馈

    Also in 8 projects that use this

  • Leodorareluctant259Skill

    chinese-commit-conventions

    中文 Git 提交规范 — 适配国内团队的 commit message 规范和 changelog 自动化

    Also in 8 projects that use this

  • obraSkill

    diagnosing-superpowers

    Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

    Also in 19 projects that use this

  • LLl0k0laDSkill

    using-agent-skills

    Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.

    Also in 39 projects that use this

  • LLl0k0laDSkill

    git-workflow-and-versioning

    Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.

    Also in 47 projects that use this

  • MrCipherSmithSkill

    constraint-driven-development

    Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.

    Also in 15 projects that use this

  • +3 more from Leodorareluctant259
  • +3 more from LLl0k0laD

The file

We split this skill into the rules it gives an agent

12 rules. 4 are common, 5 are distinctive, and 3 are very specific to this project.

  • 4

    Common

    Most of the 178 edited versions we read keep these.

  • 5

    Distinctive

    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. Common:

    Write the test first. Watch it fail.

    line 10
  2. Common:

    Core principle: If you didn't watch the test fail, you don't know if it tests the right thing.

    line 12
  3. Distinctive:

    Write code before the test?

    line 30
  4. Common:

    Test fails (not errors)

    line 48
  5. Distinctive:

    Write the simplest code that passes the test.

    line 57
  6. Distinctive:

    After green only: remove duplication, improve names, extract helpers.

    line 73
  7. Very specific:

    Server session routes: use FakeAgentRuntime from @dorkos/test-utils, never hand-rolled runtime mocks

    line 101
  8. Very specific:

    SSE streams: use collectDurableEvents from @dorkos/test-utils (trigger the turn first — message POSTs are trigger-only 202s)

    line 102
  9. Very specific:

    Gotcha: never run bare pnpm vitest run for a full run — in the dev environment it falsely fails 2 tests.

    line 111
  10. Common:

    Before marking work complete:

    line 115
  11. Distinctive:

    When adding mocks or test utilities, read @testing-anti-patterns.md to avoid common pitfalls: testing mock behavior instead of real …

    line 142
  12. Distinctive:

    No exceptions without the user's permission.

    line 151

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

Test-Driven Development (TDD)

Overview

Write the test first. Watch it fail. Write minimal code to pass.

Core principle: If you didn't watch the test fail, you don't know if it tests the right thing.

Violating the letter of the rules is violating the spirit of the rules.

When to Use

Always: new features, bug fixes, refactoring, behavior changes.

Exceptions (ask the user): throwaway prototypes, generated code, configuration files.

Thinking "skip TDD just this once"? Stop. That's rationalization.

The Iron Law

NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST

Write code before the test? Delete it. Start over. Don't keep it as "reference", don't "adapt" it while writing tests — delete means delete. Implement fresh from tests.

Red-Green-Refactor

RED — Write Failing Test

One minimal test showing what should happen: one behavior, a name that describes it, real code under test (mocks only if unavoidable — a test that only exercises vi.fn() chains tests the mock, not the code).

Verify RED — Watch It Fail

MANDATORY. Never skip.

pnpm vitest run path/to/test.test.ts

Confirm:

  • Test fails (not errors)
  • Failure message is the one you expected
  • It fails because the feature is missing (not a typo or bad import)

Test passes? You're testing existing behavior — fix the test. Test errors? Fix the error and re-run until it fails correctly.

GREEN — Minimal Code

Write the simplest code that passes the test. No extra options, no speculative parameters, no refactoring other code, no "improvements" beyond what the test demands (YAGNI).

Verify GREEN — Watch It Pass

MANDATORY.

pnpm vitest run path/to/test.test.ts

Confirm: the test passes, other tests still pass, output is pristine (no errors or warnings).

Test fails? Fix the code, not the test. Other tests fail? Fix now.

REFACTOR — Clean Up

After green only: remove duplication, improve names, extract helpers. Keep tests green. Don't add behavior. Then repeat with the next failing test.

Why Test-First (Not Test-After)

Tests written after code pass immediately — and passing immediately proves nothing: they're biased by your implementation, test what you built rather than what's required, and you never saw them catch anything. Test-first forces you to see the failure, which is the proof the test works. Manual testing doesn't substitute: no record, can't re-run, edge cases forgotten under pressure.

Common Rationalizations

ExcuseReality
"Too simple to test"Simple code breaks. Test takes 30 seconds.
"I'll test after"Tests passing immediately prove nothing.
"Already manually tested"Ad-hoc does not equal systematic. No record, can't re-run.
"Deleting X hours is wasteful"Sunk cost fallacy. Keeping unverified code is technical debt.
"Keep as reference, write tests first"You'll adapt it. That's testing after. Delete means delete.
"Need to explore first"Fine. Throw away exploration, start with TDD.
"Test hard = design unclear"Listen to the test. Hard to test = hard to use.
"TDD will slow me down"TDD is faster than debugging. Pragmatic = test-first.
"Existing code has no tests"You're improving it. Add tests for existing code.

Red flags — stop and start over: code before test, test passes immediately, can't explain why the test failed, "just this once", "it's about spirit not ritual", "this is different because...".

DorkOS-Specific Patterns

Full conventions: .claude/rules/testing.md. The essentials:

  • Location: tests live in __tests__/ directories alongside source (e.g. apps/server/src/services/__tests__/foo.test.ts)
  • Client components: need the @vitest-environment jsdom directive and a mock Transport via TransportProvider + createMockTransport() from @dorkos/test-utils
  • Server session routes: use FakeAgentRuntime from @dorkos/test-utils, never hand-rolled runtime mocks
  • SSE streams: use collectDurableEvents from @dorkos/test-utils (trigger the turn first — message POSTs are trigger-only 202s)

Commands

pnpm vitest run path/to/test.test.ts   # one file — the TDD inner loop
pnpm test -- --run                     # full suite (via turbo)

Gotcha: never run bare pnpm vitest run for a full run — in the dev environment it falsely fails 2 tests. Full runs go through pnpm test -- --run; bare pnpm vitest run is only for scoped paths.

Verification Checklist

Before marking work complete:

  • Every new function/method has a test
  • Watched each test fail before implementing
  • Each test failed for the expected reason (feature missing, not typo)
  • Wrote minimal code to pass each test
  • All tests pass, output pristine
  • Tests use real code (mocks only if unavoidable)
  • Edge cases and errors covered

Can't check all boxes? You skipped TDD. Start over.

When Stuck

ProblemSolution
Don't know how to testWrite wished-for API. Write assertion first. Ask the user.
Test too complicatedDesign too complicated. Simplify interface.
Must mock everythingCode too coupled. Use dependency injection.
Test setup hugeExtract helpers. Still complex? Simplify design.

Debugging Integration

Bug found? Write a failing test reproducing it, then follow the TDD cycle. The test proves the fix and prevents regression. Never fix bugs without a test.

Testing Anti-Patterns

When adding mocks or test utilities, read @testing-anti-patterns.md to avoid common pitfalls: testing mock behavior instead of real behavior, adding test-only methods to production classes, mocking without understanding dependencies.

Final Rule

Production code -> test exists and failed first
Otherwise -> not TDD

No exceptions without the user's permission.

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.