| name | green |
| description | TDD Green Phase - Implement minimal code to make the failing test pass |
TDD Green Phase
You are now in the Green Phase of TDD. Follow these instructions to make the failing test pass with MINIMAL code.
Why minimality matters
The Green Phase deliberately writes the smallest implementation that turns the active test green -- even hardcoded returns, even obviously-incomplete logic. This is not laziness or naivete:
- It exposes refactoring opportunities in the next phase. When the implementation does exactly one thing, structural smells are visible. Over-implemented green code looks "already clean" and hides design problems.
- It prevents premature generalization. The shape of the right abstraction emerges from the second and third test, not the first. Implementing for hypothetical future tests locks in a design before its constraints are known.
- It keeps the red-green-refactor cycle short. Each cycle pays a cost in tokens and context; over-implementing in green collapses several future cycles into one large one and loses the per-test feedback loop.
Your Mission
- Implement the minimal code necessary to make the failing test pass
- Use the simplest possible solution (hardcoded values are acceptable)
- Avoid adding features for future tests
- Verify all tests pass
- NO optimization, NO refactoring yet
Context: $ARGUMENTS
Green Phase Rules
- Minimal code only: Just enough to pass the current test
- Baby steps: Make the smallest possible change
- No future features: Don't implement what future tests might need
- Simple is better: Hardcoded returns are perfectly fine
- Tests must pass: Verify all tests are green
- No refactoring yet: Save improvements for Refactor phase
Process
Step 1: Analyze the Failing Test
Understand what the test expects:
- What input does the test provide?
- What output does it expect?
- What is the simplest way to produce that output?
Step 2: Write Minimal Implementation
Implement only what's needed to make the current test pass:
export const calculate = (input: string): number => {
return 0;
};
export const calculate = (input: string): number => {
if (input === "") return 0;
return parseInt(input);
};
export const calculate = (input: string): number => {
if (input === "") return 0;
const numbers = input.split(",");
if (numbers.length === 1) return parseInt(numbers[0]);
return parseInt(numbers[0]) + parseInt(numbers[1]);
};
Step 3: Run Tests
Run pnpm test and verify:
- Current test now passes
- All previous tests still pass
Step 4: Verify No Over-Implementation
Check yourself:
- Did I implement features for future tests? -> Remove them
- Did I add logic not demanded by current test? -> Remove it
- Did I optimize prematurely? -> Simplify
- Did I refactor existing code? -> Revert, save for Refactor phase
Step 5: Report Completion
Green Phase Complete:
**Implementation**: [brief description of what was added]
**Result**: All tests now pass ([X] passing)
**Approach**: [explain why this is minimal]
Proceeding to Refactor phase.
Minimal Implementation Strategies
Hardcoded Returns (Preferred for Early Tests)
return 0;
Simple Conditionals (When Multiple Tests)
if (input === "") return 0;
return parseInt(input);
Generalization (Only When Forced)
return input.split(",").reduce((sum, n) => sum + parseInt(n), 0);
Important Guidelines
DO
- Write minimal code to make test pass
- Use hardcoded values when appropriate
- Take baby steps
- Verify all tests pass
DON'T
- Implement beyond what tests demand
- Add features for future tests
- Optimize prematurely
- Refactor during Green phase
Psychological Resistance
You will feel resistance:
- "This is too simple" -> That's correct! Minimal is the way
- "Hardcoded values feel wrong" -> They're exactly right for early tests
- "I should implement ahead" -> Resist this strongly
- "This is inefficient" -> Actually accelerates development
Trust the process. Simple steps compound into elegant solutions.
Completion
After completing Green phase, proceed to Refactor phase:
Green Phase Complete. Proceeding to Refactor phase.