一键导入
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code. Red-Green-Refactor cycle ensures tests pass.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when implementing any feature or bugfix, before writing implementation code. Red-Green-Refactor cycle ensures tests pass.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Coordinate specialized teammates in Agent Teams for execution, review, and planning. Delegate mode mandatory with TaskCompleted/TeammateIdle hooks.
Plan completion workflow - archive plan, verify todos, create git commit, push with retry. Use for finalizing completed plans.
Plan confirmation workflow - extract plan from conversation, create file, auto-review with Interactive Recovery. Use for confirming plans after /00_plan.
Plan execution workflow - parallel SC implementation, worktree mode, verification patterns, GPT delegation. Use for executing plans with TDD + Ralph Loop.
Use when blocked, stuck, or needing fresh perspective. Consults GPT experts via Codex CLI with graceful fallback.
Coordinate independent teammates concurrently in Agent Teams for 50-70% speedup. Launch multiple teammates simultaneously.
| name | test-driven-development |
| description | Use when implementing any feature or bugfix, before writing implementation code. Red-Green-Refactor cycle ensures tests pass. |
Purpose: Red-Green-Refactor cycle for reliable code with tests Target: Coder agent implementing features or bugfixes
| Phase | Action | Verify |
|---|---|---|
| RED | Write failing test | npm test → FAIL |
| GREEN | Minimal implementation | npm test → PASS |
| REFACTOR | Clean up code | npm test && npm run lint → PASS |
| REPEAT | Until criteria met | All quality gates pass |
Step 1: RED - Write a failing test
// src/auth.service.test.ts
describe('AuthService', () => {
it('should authenticate valid user', async () => {
const service = new AuthService();
const result = await service.authenticate('user@example.com', 'password');
expect(result).toBe(true);
});
});
Verify test fails: npm test → FAIL: AuthService is not defined
Step 2: GREEN - Write minimal code to pass
// src/auth.service.ts
export class AuthService {
async authenticate(email: string, password: string): Promise<boolean> {
return true; // Minimal implementation
}
}
Verify test passes: npm test → PASS
Step 3: REFACTOR - Clean up
// src/auth.service.ts
export class AuthService {
constructor(private users: UserRepository) {}
async authenticate(email: string, password: string): Promise<boolean> {
const user = await this.users.findByEmail(email);
if (!user) return false;
return await user.verifyPassword(password);
}
}
Verify tests still pass: npm test && npm run lint → PASS
it('should calculate total with discount', () => {
const cart = new Cart(); // Arrange
cart.applyDiscount('SUMMER20'); // Act
expect(cart.total).toBe(80); // Assert
});
it('should reject invalid card', () => {
const payment = new PaymentService(); // Given
const result = payment.process({ number: 'invalid' }, 100); // When
expect(result.success).toBe(false); // Then
});
npm test -- --coverage # Generate report
open coverage/lcov-report/index.html # View in browser
// Promise-based
it('should fetch user', async () => {
const user = await service.getUser(1);
expect(user.name).toBe('Alice');
});
// Callback-based
it('should emit event', (done) => {
service.on('event', (data) => {
expect(data).toBe('expected');
done();
});
service.trigger();
});
// Timer-based
jest.useFakeTimers();
it('should timeout after 5s', () => {
service.start();
jest.advanceTimersByTime(5000);
expect(service.timedOut).toBe(true);
});
const mockRepository = {
findByEmail: jest.fn().mockResolvedValue({ id: 1, email: 'test@example.com' })
};
const service = new AuthService(mockRepository);
await service.authenticate('test@example.com', 'password');
expect(mockRepository.findByEmail).toHaveBeenCalledWith('test@example.com');
it('should throw on invalid input', () => {
expect(() => service.validate(null)).toThrow('Invalid input');
expect(() => service.validate('')).toThrow('Email required');
});
Autonomous iteration until all tests pass:
See: @.claude/skills/ralph-loop/SKILL.md
After implementation:
npm test)npm test -- --coverage)npm run type-check)npm run lint)Version: claude-pilot 4.2.0