tdd-cycle-runner
Use when executing the complete TDD red-green-refactor cycle as an atomic skill, bridging L4 test specifications to L5 implementation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when executing the complete TDD red-green-refactor cycle as an atomic skill, bridging L4 test specifications to L5 implementation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when auditing the overall architecture for completeness, consistency, principle compliance, derivation chain integrity, and proposing/validating adjustments. This skill unifies the meta-verification layer and replaces architecture-self-auditor, derivation-chain-validator, adjustment-proposer, and adjustment-validator.
Use when designing system architecture, recording decisions, selecting patterns and tech stack, analyzing data flow, designing interface contracts, and applying the Strangler pattern. This skill unifies D2 Architecture Derivation Domain and replaces architecture-decision-recorder, architecture-pattern-selector, tech-stack-selector, data-flow-analyzer, interface-contract-designer, and strangler-pattern-suite.
Use when generating implementation code from interface contracts for backend (Go) and frontend (Vue/React) in any language. This skill unifies D5 Implementation Derivation Domain (L4.5→L5) and replaces contract-driven-code-generator, backend-code-generator, frontend-code-generator, and generic-code-generator.
Use when validating code and specifications against all 15 Aether constitutional principles (P0-P14), detecting principle conflicts, resolving via dynamic weighting, and enforcing mechanized constraints. This skill unifies the constitution enforcement layer and replaces constitution-validator, principle-consistency-checker, and constraint-check-runner.
Use when orchestrating complex deployments (canary, blue-green, rolling), managing releases, handling rollbacks, and enforcing change management. This skill unifies deployment operations and replaces deployment-orchestrator, rollback-manager, release-manager, and change-management.
Use when evaluating task determinism, dispatching to traditional code generators vs AI generation, enforcing contract consistency gates, and routing for confidence-based human review. This skill unifies D4.5 Generation Dispatch Domain and replaces deterministic-evaluator, code-generator-dispatcher, contract-consistency-gate, and confidence-based-reviewer.
| name | tdd-cycle-runner |
| description | Use when executing the complete TDD red-green-refactor cycle as an atomic skill, bridging L4 test specifications to L5 implementation |
Execute the complete Test-Driven Development (TDD) red-green-refactor cycle as an atomic skill. Bridges L4 test specifications to L5 implementation in the Aether five-layer derivation model, ensuring strict adherence to P6: Test-First Principle.
Unit tests defined? ─────────────────────┐
│
Need to implement code to pass tests? ───┤
├─► Use tdd-cycle-runner
L4 -> L5 derivation needed? ─────────────┤
│
Following P6 Test-First Principle? ──────┘
Use when:
Don't use when:
L4: Unit Test Specifications (Component Contract Layer)
├── UT-001: Test user registration with valid email
├── UT-002: Test user registration with invalid email
└── UT-003: Test user registration with duplicate email
|
v
TDD Cycle Runner
|
v
L5: Implementation Code (Unit Implementation Layer)
├── RED: Write failing test
├── GREEN: Write minimal code to pass
└── REFACTOR: Improve design
Write Failing Test (RED) → Write Minimal Code (GREEN) → Improve Design (REFACTOR)
↑ |
└──────────────────────←───────────────────────────────────┘
// Writing production code first, testing later
function registerUser(email, password) {
// ... implementation without tests
return user;
}
// Tests written after code is "done"
test('registerUser', () => {
expect(registerUser('test@example.com', 'password')).toBeDefined();
});
// RED: Write failing test first
test('registerUser with valid email creates user', () => {
const user = registerUser('test@example.com', 'SecurePass123!');
expect(user.email).toBe('test@example.com');
expect(user.id).toBeDefined();
});
test('registerUser with invalid email throws error', () => {
expect(() => registerUser('invalid-email', 'password'))
.toThrow('Invalid email format');
});
test('registerUser with duplicate email throws error', () => {
registerUser('test@example.com', 'password');
expect(() => registerUser('test@example.com', 'password'))
.toThrow('Email already registered');
});
// GREEN: Write minimal code to pass tests
function registerUser(email, password) {
if (!isValidEmail(email)) {
throw new Error('Invalid email format');
}
if (userExists(email)) {
throw new Error('Email already registered');
}
return createUser(email, password);
}
// REFACTOR: Improve design
class UserService {
constructor(userRepository, emailValidator) {
this.userRepository = userRepository;
this.emailValidator = emailValidator;
}
register(email, password) {
this.validateEmail(email);
this.ensureUnique(email);
return this.userRepository.create({ email, password });
}
validateEmail(email) {
if (!this.emailValidator.isValid(email)) {
throw new ValidationError('Invalid email format');
}
}
ensureUnique(email) {
if (this.userRepository.exists(email)) {
throw new DuplicateError('Email already registered');
}
}
}
| Phase | Action | Goal | Success Criteria |
|---|---|---|---|
| RED | Write failing test | Define behavior | Test fails with expected error |
| GREEN | Write minimal code | Make test pass | All tests pass |
| REFACTOR | Improve design | Clean up code | Tests still pass, code is better |
class TDDCycleRunner:
def __init__(self, test_specifications, code_template):
self.tests = test_specifications
self.code = code_template
self.cycle_count = 0
def execute_cycle(self):
"""Execute one complete TDD cycle."""
# RED Phase
self.red_phase()
# GREEN Phase
self.green_phase()
# REFACTOR Phase
self.refactor_phase()
self.cycle_count += 1
def red_phase(self):
"""Write failing test."""
test = self.tests.next()
self.write_test(test)
assert self.run_tests() == 'fail', "Test should fail in RED phase"
def green_phase(self):
"""Write minimal code to pass."""
self.write_minimal_code()
assert self.run_tests() == 'pass', "All tests should pass in GREEN phase"
def refactor_phase(self):
"""Improve design while keeping tests green."""
initial_tests = self.run_tests()
self.improve_design()
assert self.run_tests() == initial_tests, "Tests must stay green after refactor"
tdd_cycle_report:
cycle_id: "tdd-20250424-001"
target: "UserService.register"
cycles_completed: 3
red_phase:
- test_id: "ut-001"
description: "Valid email creates user"
status: "passed"
error_message: "registerUser is not defined"
green_phase:
- test_id: "ut-001"
implementation: "Minimal registerUser function"
status: "passed"
refactor_phase:
- changes: ["Extracted UserService class", "Added dependency injection"]
tests_status: "all_passing"
final_state:
tests_passing: 3
tests_failing: 0
code_quality_score: 0.92
coverage: 100%