TDD Bugfix
Test-first bug fix. Failing test proves the bug, fix makes it pass, runtime evidence confirms.
Do NOT use when
- No local test path exists (manual browser testing, production-only bugs)
- Building features (use
architect-firstthenplan-slice) - Refactoring (use
deep-code-quality-review)
Workflow
- Reproduce: Trace the code path to the defect. Write a minimal test that fails. Run it to confirm failure.
- Root-cause: Follow root-cause checklist. Record root cause via
ck_memory_record(type:finding). - Failing test: Write a test that demonstrates the bug. Must be: minimal, deterministic, clearly named. Confirm it fails.
- Validate test: Run
ck_validateon the test code. Fix findings. - Minimal fix: Smallest change to make the test pass. No refactoring, no improvements. Record improvement ideas via
ck_memory_recordfor later. - Verify: Failing test passes. Full suite passes (
mix test). Zero new failures. - Validate fix: Run
ck_validateon the diff. Record findings. - Commit:
ck_git_commitwith message referencing the bug and test.
Rules
- Test first, fix second — no exceptions
- Minimal fix only — refactoring is a separate commit
- No
Process.sleep/1in tests — use monitors or:sys.get_state/1 - Root-cause, not symptom — fix the cause or record deeper issue as
ck_finding
Output
- Failing test proving the bug
- Minimal fix making test pass
- Full suite passing
- Root cause recorded in memory