agentleFS
DanaResearchGroupDanaResearchGroup/agent-skills/mutation-test/SKILL.md

mutation-test

Skill1 starsChanged 3 months agoMITView on GitHub

Mutation-test the Python lines a diff touched with cosmic-ray, and fail on any surviving mutant — a line the tests execute but never check. Use when hardening agent-written code before a PR, when a contract Verifier needs proof the tests actually assert something, when asked whether tests are meaningful rather than just covering, or when running a "hardener" stage.

  • Installs packages

9 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use skill-eval and brainstorm.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SaluteYBSkill

    skill-eval

    Evaluate, tune, and regression-check AgentSkills. Use when creating a new skill or improving an existing one and you need structured should-trigger, should-not-trigger, boundary-case, and execution-quality examples. Also use when auditing overlapping skills and sharpening trigger descriptions before release.

    Also in 3 projects that use this

  • nicolasestremSkill

    brainstorm

    Structured idea generation and solution exploration with systematic analysis.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Run it. For each SURVIVED row, read the diff: it is a behavior change the tests accepted.

    line 61
  2. Distinctive:

    Write the assertion that would have failed on it — usually a specific expected value, a boundary case, or a check on the branch not taken.

    line 62
  3. Distinctive:

    Never pass the gate by:

    line 66
  4. Very specific:

    Compiled modules are refused: When a .so/.pyd for the same module sits beside the .py (Cython builds of plain .py files do this), Python …

    line 84

“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “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

Mutation test

Coverage says a line ran. A mutation test says whether any test would notice if the line were wrong. The tool flips one thing at a time (+ to -, > to >=, True to False, a constant), reruns the tests, and records whether they fail ("killed") or still pass ("survived"). A survivor is a line whose behavior no assertion pins down.

This skill wraps cosmic-ray and mutates only the lines a diff changed. Each mutant costs one full run of the test command, so whole-module runs are a survey, not a gate: one 540-line module in a mid-size repo yields 575 mutants against 26 for a small diff.

Run it

From inside the repo, in the environment the tests run in (cosmic-ray must be importable there; pip install 'cosmic-ray>=8.7,<9'):

python ~/.claude/skills/mutation-test/bin/mutation-test --diff <base> \
  --test-command 'pytest path/to/the_tests.py -x -q -p no:cacheprovider'
  • --diff <base> compares the working tree against <base>, usually the branch's merge-base with main. Untracked new files count as changed in full. Test files are never mutated.
  • --test-command is a shell command. Give it only the tests that cover the changed files: every mutant reruns it. Turn off parallel runners for it (-n 0 under pytest-xdist): startup dominates a single file's run.
  • The tool mutates files in place and restores them, so run it in your own worktree with no other process editing it. It checks every target byte-for-byte afterwards and restores any it finds changed.
ExitMeaning
0every mutant killed (or nothing in scope)
1at least one survived: each printed as SURVIVED file:line operator plus its diff
2cannot judge: red baseline, compiled module shadowing a target, more than --max-mutants, a mutant run that crashed, another run already mutating the same tree, or cosmic-ray missing

Other flags: --timeout S per test run (a timeout counts as killed), --max-mutants N (default 200), --json, --exclude GLOB (added to the test-file exclusions, which always apply), and trailing paths to narrow the scope (or, without --diff, to mutate whole files).

Before the first run: a green baseline

The tool runs the test command once, unmutated, and refuses (exit 2) if it fails: on a red baseline every mutant would count as killed. Tests that fail for environmental reasons (a missing binary, local settings) must be deselected in the command, not fixed by the gate:

--test-command 'pytest pkg/level_test.py -x -q -n 0 --deselect pkg/level_test.py::TestLevel::test_needs_onedmin'

The hardener loop

As a contract Verifier, the command plus exits 0 is the whole check. The loop:

  1. Run it. For each SURVIVED row, read the diff: it is a behavior change the tests accepted.
  2. Write the assertion that would have failed on it — usually a specific expected value, a boundary case, or a check on the branch not taken.
  3. Rerun until it exits 0.

Never pass the gate by:

  • deleting the code the survivor lives in only to make it disappear,
  • weakening the test command to fewer tests than cover the change,
  • raising --timeout so slow mutants count as killed, or lowering it so all of them do,
  • deselecting tests that fail because of the mutant rather than the environment.

Some survivors are equivalent mutants: a change with no observable effect (x * 1 vs x, a reordered independent assignment). If no test could ever tell them apart, stop and report the row with why it is equivalent rather than contort a test around it.

Because a deterministic check decides acceptance, the loop does not need a strong model: a free-tier one can run it.

Limits

  • Python only, one process (cosmic-ray's local distributor). Cost is roughly mutants × one test run; on a repo whose single test file takes 8 s, 26 mutants took under 4 minutes.
  • Compiled modules are refused. When a .so/.pyd for the same module sits beside the .py (Cython builds of plain .py files do this), Python imports the compiled one and mutating the source changes nothing: every mutant would survive. The tool exits 2 naming the file. Narrow the paths to the pure-Python modules.
  • Any non-zero exit of the test command counts as a kill — including an import error. The green baseline guards the common case; a mutant that breaks imports is still killed, which is correct.
  • A pure deletion (lines removed, none added) scopes the line just before the cut.
  • One run per tree. Mutants are written into the source in place, so a second run started mid-run would snapshot a mutant as the original and write it back afterwards. A surviving mutant left that way is a bug the suite cannot see. The second run exits 2. Agent harnesses that background long commands (codex does) make this easy to hit: wait for the first run.

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.