Activate When
/godmode:test, "write tests", "test coverage"
The Loop
# Measure current coverage
npx vitest --coverage 2>&1 | tail -5
# Or: pytest --cov=src --cov-report=term | grep TOTAL
# Or: go test -cover ./...
coverage = measure_coverage()
target = user_target OR 80
current_iteration = 0
WHILE coverage < target:
current_iteration += 1
# 1. FIND — coverage report, untested lines
# Priority: happy > error > edge > integration
# 2. RED — write ONE test. It MUST fail.
# IF passes immediately: wrong test, delete
# 3. GREEN — write minimum code -> PASS
# 4. REFACTOR — remove test duplication
# Run ALL tests. IF unrelated breaks -> revert
# 5. COMMIT: git add {file} && git commit
# 6. MEASURE: coverage = measure_coverage()
# 7. LOG to .godmode/test-results.tsv
IF current_iteration % 5 == 0:
print "Iter {N}: {coverage}% (target: {target}%)"
Print: "Coverage: {start}% -> {final}% in {N} iters"
Quality Targets
- Coverage target: >=80% line coverage (configurable)
- Test execution: <30s for unit suite, <120s for integration
- Flaky tests: 0 tolerated (quarantine immediately)
- Test-to-code ratio: >=1.5 test lines per code line
- Max test file size: <300 lines (split if larger)
- Assertion density: >=2 assertions per test average
Output Format
Print: Test: coverage {start}% -> {final}% (target: {target}%). {N} tests added in {iters} iterations. Status: {DONE|PARTIAL}.
Workflow Detail
- Detect framework: read package.json, pytest.ini, Cargo.toml, go.mod to find test runner.
- Baseline coverage: run coverage command, parse report, record starting percentage.
- Identify gaps: read coverage report line-by-line, list uncovered functions sorted by importance.
- RED: write one failing test targeting the highest-priority uncovered path.
- GREEN: write minimum production code (or confirm existing code) to make the test pass.
- REFACTOR: clean up duplication in test and source, re-run full suite to confirm no regressions.
- COMMIT: stage test file and any changed source, commit with message
test: cover {function/path}.
- MEASURE: re-run coverage, compute delta, log to TSV.
- REPEAT: go to step 3 until coverage target met or stop condition triggers.
- FINAL REPORT: print summary with start coverage, final coverage, iterations, tests added, and status.
Hard Rules
- Inherits Default Activations per
SKILL.md §14. Principles prelude, pre-commit audit (agents/tester.md step 11a), terse/stdio/tokens, DispatchContext validation, Progressive Disclosure routing, discard cost hierarchy all fire by default.
- RED first -- test must fail before implementation.
If passes immediately: wrong test, delete.
- One test per iteration -- atomic, revertable.
- No mocking unless external I/O (network, fs, clock).
Test names:
should_{verb}_when_{condition}.
- Min 1 assertion per test; 3+ recommended.
- Priority: happy_path > error_path > edge_case.
- Never keep a test that does not increase coverage.
- Never ask to continue. Loop autonomously.
Keep/Discard Discipline
KEEP if: coverage increased AND all existing tests pass
DISCARD if: coverage unchanged OR existing test broke
On discard: git reset --hard HEAD~1
Log reason. Move to next uncovered path.
Overfitting Prevention
Tests must cover behavior, not implementation. If a test breaks when internals change but behavior is preserved → test is overfitted. Rewrite it.
Stop Conditions
STOP when FIRST of:
- coverage >= target (default 80%)
- 50 iterations reached (safety limit)
- 3 consecutive iterations with <0.5% gain
- >5 consecutive discards on different paths
Error Recovery
| Failure |
Action |
| Test passes immediately |
Delete. Rewrite to test specific uncovered behavior. |
| Coverage unchanged |
Check coverage report line-by-line. May hit covered paths. |
| Unrelated test breaks |
Revert. Check shared state or import side effects. Fix isolation. |
| Coverage plateaus |
Switch to integration tests. Check for dead code inflating denominator. |
TSV Logging
Append to .godmode/test-results.tsv:
iteration\ttest_file\tlines_covered\tcoverage_before\tcoverage_after\tdelta\tstatus
Status: kept, discarded, plateau.
1---2name: test3description: TDD loop. RED-GREEN-REFACTOR until coverage target met.4---56## Activate When7- `/godmode:test`, "write tests", "test coverage"89## The Loop10```bash11# Measure current coverage12npx vitest --coverage 2>&1 | tail -513# Or: pytest --cov=src --cov-report=term | grep TOTAL14# Or: go test -cover ./...15```16```17coverage = measure_coverage()18target = user_target OR 8019current_iteration = 02021WHILE coverage < target:22 current_iteration += 123 # 1. FIND — coverage report, untested lines24 # Priority: happy > error > edge > integration25 # 2. RED — write ONE test. It MUST fail.26 # IF passes immediately: wrong test, delete27 # 3. GREEN — write minimum code -> PASS28 # 4. REFACTOR — remove test duplication29 # Run ALL tests. IF unrelated breaks -> revert30 # 5. COMMIT: git add {file} && git commit31 # 6. MEASURE: coverage = measure_coverage()32 # 7. LOG to .godmode/test-results.tsv33 IF current_iteration % 5 == 0:34 print "Iter {N}: {coverage}% (target: {target}%)"3536Print: "Coverage: {start}% -> {final}% in {N} iters"37```3839<!-- tier-3 -->4041## Quality Targets42- Coverage target: >=80% line coverage (configurable)43- Test execution: <30s for unit suite, <120s for integration44- Flaky tests: 0 tolerated (quarantine immediately)45- Test-to-code ratio: >=1.5 test lines per code line46- Max test file size: <300 lines (split if larger)47- Assertion density: >=2 assertions per test average4849## Output Format50Print: `Test: coverage {start}% -> {final}% (target: {target}%). {N} tests added in {iters} iterations.51Status: {DONE|PARTIAL}.`5253## Workflow Detail541. **Detect framework**: read package.json, pytest.ini, Cargo.toml, go.mod to find test runner.552. **Baseline coverage**: run coverage command, parse report, record starting percentage.563. **Identify gaps**: read coverage report line-by-line, list uncovered functions sorted by importance.574. **RED**: write one failing test targeting the highest-priority uncovered path.585. **GREEN**: write minimum production code (or confirm existing code) to make the test pass.596. **REFACTOR**: clean up duplication in test and source, re-run full suite to confirm no regressions.607. **COMMIT**: stage test file and any changed source, commit with message `test: cover {function/path}`.618. **MEASURE**: re-run coverage, compute delta, log to TSV.629. **REPEAT**: go to step 3 until coverage target met or stop condition triggers.6310. **FINAL REPORT**: print summary with start coverage, final coverage, iterations, tests added, and status.6465## Hard Rules660. **Inherits Default Activations per `SKILL.md §14`.** Principles prelude, pre-commit audit (agents/tester.md step 11a), terse/stdio/tokens, DispatchContext validation, Progressive Disclosure routing, discard cost hierarchy all fire by default.671. RED first -- test must fail before implementation.68 If passes immediately: wrong test, delete.692. One test per iteration -- atomic, revertable.703. No mocking unless external I/O (network, fs, clock).71 Test names: `should_{verb}_when_{condition}`.724. Min 1 assertion per test; 3+ recommended.735. Priority: happy_path > error_path > edge_case.746. Never keep a test that does not increase coverage.757. Never ask to continue. Loop autonomously.7677## Keep/Discard Discipline78```79KEEP if: coverage increased AND all existing tests pass80DISCARD if: coverage unchanged OR existing test broke81 On discard: git reset --hard HEAD~182 Log reason. Move to next uncovered path.83```8485### Overfitting Prevention86Tests must cover behavior, not implementation. If a test breaks when internals change but behavior is preserved → test is overfitted. Rewrite it.8788## Stop Conditions89```90STOP when FIRST of:91 - coverage >= target (default 80%)92 - 50 iterations reached (safety limit)93 - 3 consecutive iterations with <0.5% gain94 - >5 consecutive discards on different paths95```9697## Error Recovery98| Failure | Action |99|---------|--------|100| Test passes immediately | Delete. Rewrite to test specific uncovered behavior. |101| Coverage unchanged | Check coverage report line-by-line. May hit covered paths. |102| Unrelated test breaks | Revert. Check shared state or import side effects. Fix isolation. |103| Coverage plateaus | Switch to integration tests. Check for dead code inflating denominator. |104105## TSV Logging106Append to `.godmode/test-results.tsv`:107`iteration\ttest_file\tlines_covered\tcoverage_before\tcoverage_after\tdelta\tstatus`108Status: kept, discarded, plateau.