用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/andrem-sec/psc-comet --skill tdd命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | tdd |
| description | Test-driven development — Red, Green, Refactor with explicit phase gates |
| version | 0.2.0 |
| level | 2 |
| triggers | ["tdd","test driven","write tests first","TDD mode","/tdd"] |
| context_files | ["context/user.md"] |
| steps | [{"name":"Red","description":"Write a failing test describing the desired behavior. Run it. Confirm it fails for the right reason."},{"name":"Green","description":"Write minimum code to pass. Nothing more."},{"name":"Verify","description":"Run the full test suite. All tests must pass, not just the new one."},{"name":"Refactor","description":"Improve the implementation without changing behavior. Tests stay green."},{"name":"Repeat","description":"Next behavior increment — return to Red."}] |
Enforce the Red → Green → Refactor cycle.
Without TDD enforcement, Claude writes implementation first and tests after. The tests then verify what the code does rather than what it should do — producing tests that pass by construction. The feedback loop is inverted: Claude discovers problems at the end of implementation rather than at the start.
Write the test first. Run it. If it passes, the test is wrong — either it is testing something that already exists or it is not actually asserting anything.
The test must fail for the right reason:
AssertionError: expected 401, got 200 — the behavior is not implemented yetImportError: cannot import name 'login' — the function doesn't exist yet, fix the import structure firstDo not proceed to Green until the test fails for the right reason.
Write the minimum code to make the test pass. Not the cleanest code. Not the most extensible code. The minimum.
If you cannot make the test pass in under 15 minutes, the test scope is too large. Split it.
One refactor at a time. Rename, extract function, remove duplication — one change. Run tests. Green. Next change.
Do not batch multiple structural changes in one refactor pass. If tests go red mid-refactor, you have changed too much to know which change broke it.
Coverage targets are differentiated by code criticality:
100% coverage required:
90% coverage required:
80% coverage required:
Why differentiated: Not all code has the same cost-of-failure. A bug in auth can leak all user data. A bug in a UI tooltip is cosmetic. Invest test effort proportional to risk.
Check coverage before declaring Green complete. Do not regress existing coverage.
For non-deterministic code (LLM calls, external API integration, complex business rules), measure reliability with pass@k metrics:
pass@1: Test passes on first attempt
pass@3: Test passes at least once in 3 attempts
pass^3: Test passes on all 3 attempts
Use these metrics when:
Run 3 times, record pass@1, pass@3, pass^3. Only use for non-deterministic code — deterministic tests should be pass@1 = 100%.
test_[unit]_[scenario]_[expected_outcome]
Examples:
test_auth_with_expired_token_returns_401test_order_when_stock_zero_raises_OutOfStockDo not write implementation and then write a test that matches it. That is not TDD — it is documentation.
Do not test implementation details. Tests should not break when internal structure changes without behavior changing.
Do not mock the database in integration tests. Use a real test database. Mocked tests that pass while real behavior is broken are worse than no tests.