.claude/skills/openspec-sp-tdd/SKILL.md
TDD 红/绿/重构循环。铁律:先失败测试后实现。Use when implementing any new functionality.
npx skillsauth add cenmiao/openspec-pro openspec-sp-tddInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
铁律:NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
任何生产代码编写前,必须先有失败的测试。
编写一个测试,然后运行并确认失败。
测试标准:
验证失败:
编写刚好让测试通过的代码。
实现标准:
验证通过:
改进代码结构,保持测试通过。
重构标准:
在标记任何实现为"完成"前,必须验证:
禁止的词汇:
// 错误:测试 mock 的返回值
test('mock returns value', () => {
mock.fn.mockReturnValue(42);
expect(mock.fn()).toBe(42);
});
// 正确:测试真实功能
test('calculate total', () => {
const result = calculateTotal([10, 20, 12]);
expect(result).toBe(42);
});
// 错误:为了测试添加方法
class UserService {
// 只为测试添加
getInternalState() { ... }
}
// 错误:一个测试做太多
test('user flow', () => {
createUser();
login();
updateProfile();
logout();
deleteAccount();
});
// 正确:每个行为独立测试
test('create user', () => { ... });
test('login with valid credentials', () => { ... });
test('update profile', () => { ... });
实现新功能时:
用户:添加一个函数计算购物车总价
助手:我使用 openspec-sp-tdd 技能来实现。
**Step 1: Red - 写失败测试**
[编写测试代码,运行,显示失败]
✓ 测试失败,符合预期
**Step 2: Green - 写最小实现**
[编写实现代码,运行测试,显示通过]
✓ 测试通过
**Step 3: Refactor - 重构**
[改进代码结构]
✓ 所有测试保持通过
**验证清单:**
- [x] 测试先失败
- [x] 实现有对应测试
- [x] 所有测试通过
testing
Verify implementation matches change artifacts. Use when the user wants to validate that implementation is complete, correct, and coherent before archiving.
data-ai
Sync delta specs from a change to main specs. Use when the user wants to update main specs with changes from a delta spec, without archiving the change.
testing
完成前必须有验证证据。Proof precedes assertion. Use before reporting any task completion.
development
子代理驱动开发 + 两阶段审查(规格合规→代码质量)。Use when implementing tasks that require high code quality.