tdd
Canon TDD for humans and AI agents. Use for production code changes by writing tests first, proving RED, implementing minimal GREEN, and refactoring safely…
от oimiragieo★ 48 звёзд на GitHub
Установить tdd в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Test-Driven Development (TDD)
Overview
This skill implements Canon TDD with AI-specific guardrails:
- Build or update a scenario list.
- Execute exactly one scenario as a runnable test.
- Prove RED.
- Implement minimum change for GREEN.
- Optionally refactor.
- Repeat until scenario list is empty.
When to Use
Use for:
- New features
- Bug fixes
- Behavior changes
- Repository-scale patching driven by tests
- AI-assisted code generation where tests are executable specifications
Ask human approval before bypassing only for:
- Throwaway prototypes
- Purely declarative config edits with no execution path
- One-off migration scripts that will not be maintained
The Iron Law
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
If code was written first, discard and restart from RED.
Canon Loop
Step 0: Create/refresh scenario backlog
Before building the backlog, query memory for past failure signatures and reusable test templates:
Skill({ skill: 'memory-search' }); // query: "<feature-name> test failure signatures"
Read .claude/context/memory/learnings.md for recurring anti-patterns relevant to this task.
Then:
- Keep a short ordered list of test scenarios for this task.
- Prioritize by design signal and risk, not by implementation convenience.
- Add discovered scenarios during execution.
- Reuse templates from memory — do not repeat failure patterns already documented.
Step 1: Pick exactly one scenario and write one runnable test
- One behavior per cycle.
- Use clear behavior names.
- Favor real collaborators; mock only external boundaries.
Step 2: Prove RED
- Run the narrowest test command.
- Failure must be due to missing behavior, not syntax or setup errors.
- Record red evidence (test file and failing assertion message).
Step 3: Implement minimum GREEN patch
- Implement only what current red test requires.
- No speculative APIs or unrelated cleanup.
- Keep patch bounded to current scenario.
Step 4: Prove GREEN
- Re-run narrow test command.
- Run impacted suite (or package-level test set).
- Confirm no regressions.
Flakiness Gate (mandatory for async, hook, or nondeterministic tests):
For tests that involve async I/O, stop hooks, timers, or file system operations, a single pass is insufficient. Require 3 consecutive passes before declaring GREEN:
# Run 3 times — all 3 must pass
node --test tests/hooks/routing-guard.test.cjs && \
node --test tests/hooks/routing-guard.test.cjs && \
node --test tests/hooks/routing-guard.test.cjs
A test that passes once and fails on the second run is RED, not GREEN. Do not advance to Step 5 until 3 consecutive passes are confirmed.
Mutation Testing Gate (security-critical code only):
For security hooks, routing validators, auth logic, and any code path that controls access or trust decisions, run Stryker mutation testing after achieving GREEN to verify that tests genuinely catch faults and are not vacuously passing.
# Run Stryker mutation testing (threshold: 85%)
npx stryker run
# Require mutationScore >= 85 in stryker.config.json
For fast-check-based property tests on security hooks, the fail-closed property is the mutation-equivalent gate:
// fast-check fail-closed property — must hold for any input
fc.assert(
fc.property(fc.anything(), input => {
const result = securityHook(input);
// Hook must NEVER return allow=true for malformed/unexpected input
expect(result.allow).not.toBe(true);
})
);
Skip this gate for non-security application code (Step 4 → Step 5 directly).
Step 5: Optional refactor
- Refactor only with green tests.
- Re-run the same test set after refactor.
Step 5.5: Property-Based Testing (recommended for utility functions and security hooks)
After refactor (or after Step 4 for security-critical code), consider supplementing example-based tests with property-based tests. PBT achieves 23.1–37.3% pass@1 improvement over example-based TDD alone for LLM code generation (arXiv:2506.18315) by breaking the self-deception cycle.
When to invoke:
- Utility functions (encode/decode, parsers, serializers, calculators)
- Security hooks (input validators, sanitizers, access control logic)
- Any function where invariants, round-trip properties, or mathematical properties can be stated
Invocation:
Skill({ skill: 'property-based-testing' });
Key property patterns to identify:
| Pattern | Example |
|---|---|
| Round-trip | decode(encode(x)) === x |
| Idempotence | normalize(normalize(x)) === normalize(x) |
| Invariant | sort(arr).length === arr.length |
| Fa |
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
- 01
Read - 02
Write - 03
Edit - 04
Bash - 05
Glob - 06
Grep
Вложенные файлы
- benchmarks/scenario-async-error-handling.json
- benchmarks/scenario-bug-fix-with-regression.json
- benchmarks/scenario-red-green-refactor.json
- commands/tdd.md
- hooks/post-execute.cjs
- hooks/pre-execute.cjs
- manifest.json
- observations/.gitkeep
- observations/README.md
- references/research-requirements.md
- references/tdd-memory-profile.md
- rules/tdd.md
- schemas/input.schema.json
- schemas/output.schema.json
- scripts/main.cjs
- templates/implementation-template.md
- testing-anti-patterns.md
FAQ
Что делает скилл tdd?
Canon TDD for humans and AI agents. Use for production code changes by writing tests first, proving RED, implementing minimal GREEN, and refactoring safely. 2026 edition adds TDP, flakiness gate, ralph-loop integration, memory-search in Step 0, PBT as Step 5.5, mutation testing gate in Step 4, and CJS LSP warning.
Как установить скилл tdd?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл tdd запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…