| name | test-driven-development |
| type | workflow |
| description | Forces the strict Red-Green-Refactor development cycle. Requires writing a failing test and running it in the terminal before writing any implementation code. |
| argument-hint | [task-description-or-file] |
| user-invocable | true |
| allowed-tools | Read, Glob, Grep, RunCommand |
| context | fork |
| effort | 3 |
| agent | lead-programmer |
| when_to_use | When implementing ANY approved feature, bug fix, algorithmic logic, or when executing atomic tasks generated by the planning phase. |
Test-Driven Development (TDD)
Purpose
TDD acts as the ultimate truth verifier. It prevents Agents from blindly inserting implementation code based on assumptions. By strictly enforcing the RED-GREEN-REFACTOR cycle, we guarantee that all code changes are demonstrably functional and logically sound before moving on to the next task.
Workflow (Strict Process)
ABSOLUTE DIRECTIVE: Under NO circumstances are you allowed to write the final implementation logic before a test has explicitly failed in the terminal environment.
1. RED Phase (Write the Failing Test)
- Read the specification for the current atomic task.
- Create or modify the appropriate test file (e.g.,
*.test.ts, *_test.go, test_*.py) to assert the expected behavior.
- EXECUTE: Use the terminal to run the test suite.
- GATE: Capture the terminal output. You MUST see the test FAIL. If the test passes immediately, your test is flawed or asserting the wrong state.
2. GREEN Phase (Make it Pass)
- Write the absolute minimum amount of source code necessary to fulfill the test requirement. Do not over-engineer or add "nice-to-have" features yet.
- EXECUTE: Use the terminal to run the test suite again.
- GATE: Capture the terminal output. You MUST see the test PASS.
3. REFACTOR Phase (Clean it Up)
- Optimize your implementation code (clean up naming, extract duplicate logic, improve types/interfaces) without altering behavior.
- EXECUTE: Run the test suite a final time to ensure your refactoring did not break the green state.
Output Format
Your final response to the user MUST contain the evidence of your execution in the following format:
# 🧪 TDD Execution: [Feature/Task Name]
## 🔴 RED Phase Evidence
- **Test added**: `[test_function_name]`
- **Terminal Output**:
```bash
[Insert the failing test output trace here - do not fake this]
🟢 GREEN Phase Evidence