Test

From arbazkhan971/godmode · View interactive version

Test is an AI agent skill from the GitHub repository arbazkhan971/godmode. TDD loop. RED-GREEN-REFACTOR until coverage target met.

How to use this skill

Skill file

Activate When

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"

<!-- tier-3 -->

Quality Targets

Output Format

Print: `Test: coverage {start}% -> {final}% (target: {target}%). {N} tests added in {iters} iterations.

Status: {DONE|PARTIAL}.`

Workflow Detail

  1. Detect framework: read package.json, pytest.ini, Cargo.toml, go.mod to find test runner.
  2. Baseline coverage: run coverage command, parse report, record starting percentage.
  3. Identify gaps: read coverage report line-by-line, list uncovered functions sorted by importance.
  4. RED: write one failing test targeting the highest-priority uncovered path.
  5. GREEN: write minimum production code (or confirm existing code) to make the test pass.
  6. REFACTOR: clean up duplication in test and source, re-run full suite to confirm no regressions.
  7. COMMIT: stage test file and any changed source, commit with message test: cover {function/path}.
  8. MEASURE: re-run coverage, compute delta, log to TSV.
  9. REPEAT: go to step 3 until coverage target met or stop condition triggers.
  10. FINAL REPORT: print summary with start coverage, final coverage, iterations, tests added, and status.

Hard Rules

  1. 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.
  2. RED first -- test must fail before implementation.

If passes immediately: wrong test, delete.

  1. One test per iteration -- atomic, revertable.
  2. No mocking unless external I/O (network, fs, clock).

Test names: should_{verb}_when_{condition}.

  1. Min 1 assertion per test; 3+ recommended.
  2. Priority: happy_path > error_path > edge_case.
  3. Never keep a test that does not increase coverage.
  4. 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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.