agentleFS
axiomanticaxiomantic/spellbook/skills/fixing-tests/SKILL.md

fixing-tests

Skill11 starsChanged 3 months agoMITView on GitHub

Use when tests themselves are broken, test quality is poor, or user wants to fix/improve tests. Triggers: 'test is broken', 'test is wrong', 'test is flaky', 'make tests pass', 'tests need updating', 'green mirage', 'tests pass but shouldn't', 'audit report findings', 'run and fix tests'. NOT for: bugs in production code caught by correct tests (use debugging).

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test Reliability Engineer.

    line 11
  2. Distinctive:

    Tests catch bugs, not checkmarks: Every fix must detect real failures, not just achieve green status.

    line 20
  3. Distinctive:

    Read before fixing: Read the test file AND the production file under test.

    line 22
  4. Distinctive:

    If unclear: ask user to clarify target.

    line 45
  5. Distinctive:

    Before each phase, identify: inputs available, gaps in understanding, classification decisions needed (input mode, error type, production …

    line 70
  6. Distinctive:

    Not verifying fixes actually catch failures </FORBIDDEN>

    line 201
  7. Distinctive:

    After fixing tests, verify:

    line 225
  8. Distinctive:

    No production bugs were silently "fixed" as test issues

    line 227

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Fixing Tests

<ROLE> Test Reliability Engineer. Reputation depends on fixes that catch real bugs, not cosmetic changes that turn red to green. Work fast but carefully. Tests exist to catch failures, not achieve green checkmarks. </ROLE><CRITICAL> This skill fixes tests. NOT features. NOT infrastructure. Direct path: Understand problem -> Fix it -> Verify fix -> Move on. </CRITICAL>

Invariant Principles

  1. Tests catch bugs, not checkmarks. Every fix must detect real failures, not just achieve green status.
  2. Production bugs are not test issues. Flag and escalate; never silently fix broken behavior.
  3. Read before fixing. Read the test file AND the production file under test. Never guess.
  4. Verify proves value. Unverified fixes are unfinished fixes.
  5. Scope discipline. Fix tests, not features.

Inputs

InputRequiredDescription
test_outputNoTest failure output to analyze (for run_and_fix mode)
audit_reportNoGreen mirage audit findings with patterns and YAML block
target_testsNoSpecific test files or functions to fix (for general_instructions mode)
test_commandNoCommand to run tests; defaults to project standard

Input Modes

Detect mode from user input, build work items accordingly.

ModeDetectionAction
audit_reportStructured findings with patterns 1-10, "GREEN MIRAGE" verdicts, YAML blockParse YAML, extract findings. Read patterns/assertion-quality-standard.md for assertion quality gate and Full Assertion Principle.
general_instructions"Fix tests in X", "test_foo is broken", specific test referencesExtract target tests/files
run_and_fix"Run tests and fix failures", "get suite green"Run tests, parse failures

If unclear: ask user to clarify target.

WorkItem Schema

interface WorkItem {
  id: string;                           // "finding-1", "failure-1", etc.
  priority: "critical" | "important" | "minor" | "unknown";
  test_file: string;
  test_function?: string;
  line_number?: number;
  pattern?: number;                     // 1-10 from green mirage
  pattern_name?: string;
  current_code?: string;                // Problematic test code
  blind_spot?: string;                  // What broken code would pass
  suggested_fix?: string;               // From audit report
  production_file?: string;             // Related production code
  error_type?: "assertion" | "exception" | "timeout" | "skip";
  error_message?: string;
  expected?: string;
  actual?: string;
}
<analysis> Before each phase, identify: inputs available, gaps in understanding, classification decisions needed (input mode, error type, production bug vs test issue). </analysis>

Phase 0: Input Processing

Dispatch subagent (Task tool) with /fix-tests-parse command. Subagent parses input (audit YAML, fallback headers, or general instructions) into WorkItems and determines commit strategy.

Phase 1: Discovery (run_and_fix only)

Skip for audit_report/general_instructions modes.

pytest --tb=short 2>&1 || npm test 2>&1 || cargo test 2>&1

Parse failures into WorkItems with error_type, message, stack trace, expected/actual. If suite passes completely: report "no failures found" and confirm with user before exiting.

Phase 2: Fix Execution

Dispatch subagent (Task tool) with the /fix-tests-execute command. The subagent MUST read, before writing any fix:

  • The fix-tests-execute command file — the fix execution protocol, the assertion quality gate, the production bug protocol, the banned-pattern list, and the special-case playbooks
  • patterns/assertion-quality-standard.md — the complete Assertion Strength Ladder and Full Assertion Principle

Pass the work items for this batch, and copy in the full Test Writer Template from skills/dispatching-parallel-agents/SKILL.md.

The assertion quality gate applies in ALL input modes, not only audit_report. A production bug found during a fix is escalated to the user, never silently fixed as a "test fix." Both protocols are specified in the fix-tests-execute command.

Phase 3: Batch Processing

FOR priority IN [critical, important, minor]:
    FOR item IN work_items[priority]:
        Execute Phase 2
        IF stuck after 2 attempts:
            Add to stuck_items[]
            Continue to next item

Stuck Items Report

## Stuck Items

### [item.id]: [test_function]
**Attempted:** [what was tried]
**Blocked by:** [why it didn't work]
**Recommendation:** [manual intervention / more context / etc.]

Phase 3.5: Post-Fix Adversarial Review (MANDATORY)

<CRITICAL> This phase is NOT optional. After ALL fixes are applied, dispatch a Test Adversary subagent (Task tool) to verify every new or modified assertion meets quality standards. This catches Pattern 10 violations (partial-to-partial upgrades that look like improvements but are not). </CRITICAL>

Dispatch a Test Adversary subagent (Task tool). The fix-tests-execute command carries the adversary dispatch prompt and its mandatory checks; pass the modified test files, the diff of the fix phase, and the production files under test.

If verdict is FAIL: Re-execute Phase 2 for the failed items with explicit instructions about what went wrong. Do NOT skip re-review.

Phase 4: Final Verification

pytest -v  # or appropriate test command

Summary Report

## Fix Tests Summary

### Input Mode
[audit_report / general_instructions / run_and_fix]

### Metrics
| Metric | Value |
|--------|-------|
| Total items | N |
| Fixed | X |
| Stuck | Y |
| Production bugs | Z |

### Fixes Applied
| Test | File | Issue | Fix | Commit |
|------|------|-------|-----|--------|
| test_foo | test_auth.py | Pattern 2 | Strengthened to full object match | abc123 |

### Test Suite Status
- Before: X passing, Y failing
- After: X passing, Y failing

### Stuck Items (if any)
[List with recommendations]

### Production Bugs Found (if any)
[List with recommended actions]

Re-audit Option (if from audit_report)

Fixes complete. Re-run audit-green-mirage to verify no new mirages?
A) Yes, audit fixed files
B) No, satisfied with fixes

Special Cases

Playbooks for flaky tests, implementation-coupled tests, missing tests, and slow or bloated tests live in the fix-tests-execute command, alongside the fix type classification they belong to.

<FORBIDDEN> ## Anti-Patterns

Over-Engineering

  • Creating elaborate test infrastructure for simple fixes
  • Adding abstraction layers "for future flexibility"
  • Refactoring unrelated code while fixing tests

Under-Testing

  • Weakening assertions to make tests pass
  • Removing tests instead of fixing them
  • Marking tests as skip without fixing

Scope Creep

  • Fixing production bugs without flagging them
  • Refactoring production code to make tests easier
  • Adding features while fixing tests

Blind Fixes

  • Applying suggested fixes without reading context
  • Copy-pasting fixes without understanding them
  • Not verifying fixes actually catch failures</FORBIDDEN>

Self-Check

<RULE>Before completing, ALL boxes must be checked. If ANY unchecked: STOP and fix.</RULE>

  • All work items processed or explicitly marked stuck
  • Each fix verified to pass
  • Each fix verified to catch the failure it should catch
  • Each fix verified to be Level 4+ on the Assertion Strength Ladder (patterns/assertion-quality-standard.md)
  • Each new assertion has a named mutation that would cause it to fail
  • No bare substring checks introduced (assert "X" in result is BANNED on all output)
  • No partial assertions on dynamic output (full expected constructed, not membership checked)
  • All mock calls fully asserted: every call, all args, call count verified
  • No mock.ANY introduced
  • No Pattern 10 violations (partial-to-partial upgrades)
  • Phase 3.5 adversarial review completed with PASS verdict
  • Full test suite ran at end
  • Production bugs flagged, not silently fixed
  • Commits follow agreed strategy
  • Summary report provided
<reflection> After fixing tests, verify: - Each fix actually catches the failure it should - No production bugs were silently "fixed" as test issues - Tests detect real bugs, not just achieve green status </reflection>

<FINAL_EMPHASIS> Tests exist to catch bugs. Every fix you make must result in tests that actually catch failures, not tests that achieve green checkmarks.

Fix it. Prove it works. Move on. No over-engineering. No under-testing. </FINAL_EMPHASIS>

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.