---
name: tdd-cycle
description: Execute a comprehensive Test-Driven Development (TDD) workflow with strict red-green-refactor discipline:
Execute a comprehensive Test-Driven Development (TDD) workflow with strict red-green-refactor discipline:
[Extended thinking: This workflow enforces test-first development through coordinated agent orchestration. Each phase of the TDD cycle is strictly enforced with fail-first verification, incremental implementation, and continuous refactoring. The workflow supports both single test and test suite approaches with configurable coverage thresholds.]
Configuration
Coverage Thresholds
- Minimum line coverage: 80%
- Minimum branch coverage: 75%
- Critical path coverage: 100%
Refactoring Triggers
- Cyclomatic complexity > 10
- Method length > 20 lines
- Class length > 200 lines
- Duplicate code blocks > 3 lines
Phase 1: Test Specification and Design
1. Requirements Analysis
- Do this step directly in Codex CLI (legacy playbook referenced subagent: comprehensive-review::architect-review).
- Instruction: "Analyze requirements for: (use the user's prompt). Define acceptance criteria, identify edge cases, and create test scenarios. Output a comprehensive test specification."
- Output: Test specification, acceptance criteria, edge case matrix
- Validation: Ensure all requirements have corresponding test scenarios
2. Test Architecture Design
- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).
- Instruction: "Design test architecture for: (use the user's prompt) based on test specification. Define test structure, fixtures, mocks, and test data strategy. Ensure testability and maintainability."
- Output: Test architecture, fixture design, mock strategy
- Validation: Architecture supports isolated, fast, reliable tests
Phase 2: RED - Write Failing Tests
3. Write Unit Tests (Failing)
- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).
- Instruction: "Write FAILING unit tests for: (use the user's prompt). Tests must fail initially. Include edge cases, error scenarios, and happy paths. DO NOT implement production code."
- Output: Failing unit tests, test documentation
- CRITICAL: Verify all tests fail with expected error messages
4. Verify Test Failure
- Do this step directly in Codex CLI (legacy playbook referenced subagent: tdd-workflows::code-reviewer).
- Instruction: "Verify that all tests for: (use the user's prompt) are failing correctly. Ensure failures are for the right reasons (missing implementation, not test errors). Confirm no false positives."
- Output: Test failure verification report
- GATE: Do not proceed until all tests fail appropriately
Phase 3: GREEN - Make Tests Pass
5. Minimal Implementation
- Do this step directly in Codex CLI (legacy playbook referenced subagent: backend-development::backend-architect).
- Instruction: "Implement MINIMAL code to make tests pass for: (use the user's prompt). Focus only on making tests green. Do not add extra features or optimizations. Keep it simple."
- Output: Minimal working implementation
- Constraint: No code beyond what's needed to pass tests
6. Verify Test Success
- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).
- Instruction: "Run all tests for: (use the user's prompt) and verify they pass. Check test coverage metrics. Ensure no tests were accidentally broken."
- Output: Test execution report, coverage metrics
- GATE: All tests must pass before proceeding
Phase 4: REFACTOR - Improve Code Quality
7. Code Refactoring
- Do this step directly in Codex CLI (legacy playbook referenced subagent: tdd-workflows::code-reviewer).
- Instruction: "Refactor implementation for: (use the user's prompt) while keeping tests green. Apply SOLID principles, remove duplication, improve naming, and optimize performance. Run tests after each refactoring."
- Output: Refactored code, refactoring report
- Constraint: Tests must remain green throughout
8. Test Refactoring
- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).
- Instruction: "Refactor tests for: (use the user's prompt). Remove test duplication, improve test names, extract common fixtures, and enhance test readability. Ensure tests still provide same coverage."
- Output: Refactored tests, improved test structure
- Validation: Coverage metrics unchanged or improved
Phase 5: Integration and System Tests
9. Write Integration Tests (Failing First)
- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).
- Instruction: "Write FAILING integration tests for: (use the user's prompt). Test component interactions, API contracts, and data flow. Tests must fail initially."
- Output: Failing integration tests
- Validation: Tests fail due to missing integration logic
10. Implement Integration
- Do this step directly in Codex CLI (legacy playbook referenced subagent: backend-development::backend-architect).
- Instruction: "Implement integration code for: (use the user's prompt) to make integration tests pass. Focus on component interaction and data flow."
- Output: Integration implementation
- Validation: All integration tests pass
Phase 6: Continuous Improvement Cycle
11. Performance and Edge Case Tests
- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).
- Instruction: "Add performance tests and additional edge case tests for: (use the user's prompt). Include stress tests, boundary tests, and error recovery tests."
- Output: Extended test suite
- Metric: Increased test coverage and scenario coverage
12. Final Code Review
- Do this step directly in Codex CLI (legacy playbook referenced subagent: comprehensive-review::architect-review).
- Instruction: "Perform comprehensive review of: (use the user's prompt). Verify TDD process was followed, check code quality, test quality, and coverage. Suggest improvements."
- Output: Review report, improvement suggestions
- Action: Implement critical suggestions while maintaining green tests
Incremental Development Mode
For test-by-test development:
- Write ONE failing test
- Make ONLY that test pass
- Refactor if needed
- Repeat for next test
Use this approach by adding --incremental flag to focus on one test at a time.
Test Suite Mode
For comprehensive test suite development:
- Write ALL tests for a feature/module (failing)
- Implement code to pass ALL tests
- Refactor entire module
- Add integration tests
Use this approach by adding --suite flag for batch test development.
Validation Checkpoints
RED Phase Validation
GREEN Phase Validation
REFACTOR Phase Validation
Coverage Reports
Generate coverage reports after each phase:
- Line coverage
- Branch coverage
- Function coverage
- Statement coverage
Failure Recovery
If TDD discipline is broken:
- STOP immediately
- Identify which phase was violated
- Rollback to last valid state
- Resume from correct phase
- Document lesson learned
TDD Metrics Tracking
Track and report:
- Time in each phase (Red/Green/Refactor)
- Number of test-implementation cycles
- Coverage progression
- Refactoring frequency
- Defect escape rate
Anti-Patterns to Avoid
- Writing implementation before tests
- Writing tests that already pass
- Skipping the refactor phase
- Writing multiple features without tests
- Modifying tests to make them pass
- Ignoring failing tests
- Writing tests after implementation
Success Criteria
- 100% of code written test-first
- All tests pass continuously
- Coverage exceeds thresholds
- Code complexity within limits
- Zero defects in covered code
- Clear test documentation
- Fast test execution (< 5 seconds for unit tests)
Notes
- Enforce strict RED-GREEN-REFACTOR discipline
- Each phase must be completed before moving to next
- Tests are the specification
- If a test is hard to write, the design needs improvement
- Refactoring is NOT optional
- Keep test execution fast
- Tests should be independent and isolated
TDD implementation for: (use the user's prompt)
Output Format
<result>
<analysis>Brief analysis</analysis>
<solution>Implementation</solution>
<considerations>Trade-offs and notes</considerations>
</result>
1---2name: tdd-cycle3description: ---4---5---6name: tdd-cycle7description: Execute a comprehensive Test-Driven Development (TDD) workflow with strict red-green-refactor discipline:8---9Execute a comprehensive Test-Driven Development (TDD) workflow with strict red-green-refactor discipline:1011[Extended thinking: This workflow enforces test-first development through coordinated agent orchestration. Each phase of the TDD cycle is strictly enforced with fail-first verification, incremental implementation, and continuous refactoring. The workflow supports both single test and test suite approaches with configurable coverage thresholds.]1213## Configuration1415### Coverage Thresholds1617- Minimum line coverage: 80%18- Minimum branch coverage: 75%19- Critical path coverage: 100%2021### Refactoring Triggers2223- Cyclomatic complexity > 1024- Method length > 20 lines25- Class length > 200 lines26- Duplicate code blocks > 3 lines2728## Phase 1: Test Specification and Design2930### 1. Requirements Analysis3132- Do this step directly in Codex CLI (legacy playbook referenced subagent: comprehensive-review::architect-review).33- Instruction: "Analyze requirements for: (use the user's prompt). Define acceptance criteria, identify edge cases, and create test scenarios. Output a comprehensive test specification."34- Output: Test specification, acceptance criteria, edge case matrix35- Validation: Ensure all requirements have corresponding test scenarios3637### 2. Test Architecture Design3839- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).40- Instruction: "Design test architecture for: (use the user's prompt) based on test specification. Define test structure, fixtures, mocks, and test data strategy. Ensure testability and maintainability."41- Output: Test architecture, fixture design, mock strategy42- Validation: Architecture supports isolated, fast, reliable tests4344## Phase 2: RED - Write Failing Tests4546### 3. Write Unit Tests (Failing)4748- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).49- Instruction: "Write FAILING unit tests for: (use the user's prompt). Tests must fail initially. Include edge cases, error scenarios, and happy paths. DO NOT implement production code."50- Output: Failing unit tests, test documentation51- **CRITICAL**: Verify all tests fail with expected error messages5253### 4. Verify Test Failure5455- Do this step directly in Codex CLI (legacy playbook referenced subagent: tdd-workflows::code-reviewer).56- Instruction: "Verify that all tests for: (use the user's prompt) are failing correctly. Ensure failures are for the right reasons (missing implementation, not test errors). Confirm no false positives."57- Output: Test failure verification report58- **GATE**: Do not proceed until all tests fail appropriately5960## Phase 3: GREEN - Make Tests Pass6162### 5. Minimal Implementation6364- Do this step directly in Codex CLI (legacy playbook referenced subagent: backend-development::backend-architect).65- Instruction: "Implement MINIMAL code to make tests pass for: (use the user's prompt). Focus only on making tests green. Do not add extra features or optimizations. Keep it simple."66- Output: Minimal working implementation67- Constraint: No code beyond what's needed to pass tests6869### 6. Verify Test Success7071- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).72- Instruction: "Run all tests for: (use the user's prompt) and verify they pass. Check test coverage metrics. Ensure no tests were accidentally broken."73- Output: Test execution report, coverage metrics74- **GATE**: All tests must pass before proceeding7576## Phase 4: REFACTOR - Improve Code Quality7778### 7. Code Refactoring7980- Do this step directly in Codex CLI (legacy playbook referenced subagent: tdd-workflows::code-reviewer).81- Instruction: "Refactor implementation for: (use the user's prompt) while keeping tests green. Apply SOLID principles, remove duplication, improve naming, and optimize performance. Run tests after each refactoring."82- Output: Refactored code, refactoring report83- Constraint: Tests must remain green throughout8485### 8. Test Refactoring8687- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).88- Instruction: "Refactor tests for: (use the user's prompt). Remove test duplication, improve test names, extract common fixtures, and enhance test readability. Ensure tests still provide same coverage."89- Output: Refactored tests, improved test structure90- Validation: Coverage metrics unchanged or improved9192## Phase 5: Integration and System Tests9394### 9. Write Integration Tests (Failing First)9596- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).97- Instruction: "Write FAILING integration tests for: (use the user's prompt). Test component interactions, API contracts, and data flow. Tests must fail initially."98- Output: Failing integration tests99- Validation: Tests fail due to missing integration logic100101### 10. Implement Integration102103- Do this step directly in Codex CLI (legacy playbook referenced subagent: backend-development::backend-architect).104- Instruction: "Implement integration code for: (use the user's prompt) to make integration tests pass. Focus on component interaction and data flow."105- Output: Integration implementation106- Validation: All integration tests pass107108## Phase 6: Continuous Improvement Cycle109110### 11. Performance and Edge Case Tests111112- Do this step directly in Codex CLI (legacy playbook referenced subagent: unit-testing::test-automator).113- Instruction: "Add performance tests and additional edge case tests for: (use the user's prompt). Include stress tests, boundary tests, and error recovery tests."114- Output: Extended test suite115- Metric: Increased test coverage and scenario coverage116117### 12. Final Code Review118119- Do this step directly in Codex CLI (legacy playbook referenced subagent: comprehensive-review::architect-review).120- Instruction: "Perform comprehensive review of: (use the user's prompt). Verify TDD process was followed, check code quality, test quality, and coverage. Suggest improvements."121- Output: Review report, improvement suggestions122- Action: Implement critical suggestions while maintaining green tests123124## Incremental Development Mode125126For test-by-test development:1271281. Write ONE failing test1292. Make ONLY that test pass1303. Refactor if needed1314. Repeat for next test132133Use this approach by adding `--incremental` flag to focus on one test at a time.134135## Test Suite Mode136137For comprehensive test suite development:1381391. Write ALL tests for a feature/module (failing)1402. Implement code to pass ALL tests1413. Refactor entire module1424. Add integration tests143144Use this approach by adding `--suite` flag for batch test development.145146## Validation Checkpoints147148### RED Phase Validation149150- [ ] All tests written before implementation151- [ ] All tests fail with meaningful error messages152- [ ] Test failures are due to missing implementation153- [ ] No test passes accidentally154155### GREEN Phase Validation156157- [ ] All tests pass158- [ ] No extra code beyond test requirements159- [ ] Coverage meets minimum thresholds160- [ ] No test was modified to make it pass161162### REFACTOR Phase Validation163164- [ ] All tests still pass after refactoring165- [ ] Code complexity reduced166- [ ] Duplication eliminated167- [ ] Performance improved or maintained168- [ ] Test readability improved169170## Coverage Reports171172Generate coverage reports after each phase:173174- Line coverage175- Branch coverage176- Function coverage177- Statement coverage178179## Failure Recovery180181If TDD discipline is broken:1821831. **STOP** immediately1842. Identify which phase was violated1853. Rollback to last valid state1864. Resume from correct phase1875. Document lesson learned188189## TDD Metrics Tracking190191Track and report:192193- Time in each phase (Red/Green/Refactor)194- Number of test-implementation cycles195- Coverage progression196- Refactoring frequency197- Defect escape rate198199## Anti-Patterns to Avoid200201- Writing implementation before tests202- Writing tests that already pass203- Skipping the refactor phase204- Writing multiple features without tests205- Modifying tests to make them pass206- Ignoring failing tests207- Writing tests after implementation208209## Success Criteria210211- 100% of code written test-first212- All tests pass continuously213- Coverage exceeds thresholds214- Code complexity within limits215- Zero defects in covered code216- Clear test documentation217- Fast test execution (< 5 seconds for unit tests)218219## Notes220221- Enforce strict RED-GREEN-REFACTOR discipline222- Each phase must be completed before moving to next223- Tests are the specification224- If a test is hard to write, the design needs improvement225- Refactoring is NOT optional226- Keep test execution fast227- Tests should be independent and isolated228229TDD implementation for: (use the user's prompt)230## Output Format231232```xml233<result>234 <analysis>Brief analysis</analysis>235 <solution>Implementation</solution>236 <considerations>Trade-offs and notes</considerations>237</result>238```