Mutation testing for an application's test suite — measures whether the tests actually catch bugs, not just whether they execute lines. Detects the stack and runs the native mutation tool (Stryker, mutmut, PIT, cargo-mutants, Infection, Stryker.NET, gremlins…) or, when none is available, runs a curated manual mutation campaign in an isolated copy. Returns a report with the mutation score, the surviving mutants ranked by risk (each with file:line, the exact mutation, why the tests missed it, a...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of X Men Tester?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/faelwar-x-men-tester)
---
name: x-men-tester
description: Mutation testing for an application's test suite — measures whether the tests actually catch bugs, not just whether they execute lines. Detects the stack and runs the native mutation tool (Stryker, mutmut, PIT, cargo-mutants, Infection, Stryker.NET, gremlins…) or, when none is available, runs a curated manual mutation campaign in an isolated copy. Returns a report with the mutation score, the surviving mutants ranked by risk (each with file:line, the exact mutation, why the tests missed it, and a concrete test to kill it), and likely-equivalent mutants called out separately. Never leaves the user's source modified. Use whenever the user asks for "mutation testing", a "mutation score", "x-men", "mutants", whether their tests are "actually any good", "would catch a bug", "assert anything", or wants test-suite effectiveness measured beyond line coverage — in any language or repo.
---
# X-Men Tester
Line coverage says a test *ran* the code; mutation testing says whether a test would *notice* if the code were wrong. The method: inject one small, plausible bug (a **mutant**) into the production code, run the tests, and see whether any test fails. If a test fails, the mutant is **killed** — good. If every test still passes, the mutant **survived** — the suite has a blind spot exactly there.
The deliverable is a report of those blind spots and the tests that would close them. The question behind every survivor is **"what real bug would ship today because of this gap, and what single test would catch it?"**
## Ground rules
- **Never leave the user's code mutated.** Snapshot `git status --porcelain` and `git stash list` before starting and confirm both are identical at the end. If git is unavailable (not a repo, or the binary can't run), record SHA-256 checksums of every file in scope instead (`shasum -a 256`, `sha256sum`, or a short script) and compare them at the end. Native tools that sandbox themselves may run in place; any mutation you apply by hand happens only in an isolated copy (§4).
- **Do not change project manifests or lockfiles without asking.** Prefer ephemeral runs (`npx -p`, `uvx`, `pipx run`, a throwaway venv in the scratchpad). If the only path is adding a dev dependency, ask first and offer the manual fallback as the alternative.
- **Do not edit the user's tests or source** to "fix" survivors. Suggest the tests in the report; write them only if the user asks afterwards.
- **A green baseline is mandatory.** Mutation results on a failing or flaky suite are meaningless.
## 1. Resolve the scope
Mutation testing is expensive (≈ mutants × test-suite time), so scope deliberately.
| User says | Code to mutate |
|---|---|
| a file, folder, module or class | exactly that |
| "my changes" / a PR / a branch | production files changed vs. the base (`git diff --name-only $(git merge-base HEAD <base>)`), excluding tests |
| nothing specific | ask, or propose the highest-value module: core domain / business rules, then code with heavy branching. Never default to "the whole repo" on a non-trivial project |
Always exclude from mutation: tests, generated code, migrations, vendored code, pure config/constants files, and logging-only code.
## 2. Reconnoitre
1. **Detect the stack and test runner** from manifests (`package.json`, `pyproject.toml`/`setup.cfg`/`pytest.ini`, `pom.xml`/`build.gradle*`, `Cargo.toml`, `go.mod`, `composer.json`, `*.csproj`, `Gemfile`…) and the project's own docs (`CLAUDE.md`, `README`, `CONTRIBUTING.md`, CI config) for the canonical test command.
2. **Check for existing mutation config** (`stryker.config.*`, `[tool.mutmut]`, pitest plugin, `infection.json5`, `.cargo/mutants.toml`, etc.). If the project already configured a tool, use it and respect its settings.
3. **Map tests to the target**: find which test files exercise the target code (imports, naming conventions). This is what lets you run only the relevant tests per mutant.
4. **Run the baseline**: run the relevant tests once, unmodified. Record pass/fail and wall time.
- Failing → stop. Report the failing tests and ask whether to exclude them or fix first.
- Suspected flakiness (pass/fail differs across two runs) → stop and report it; flaky tests make survivors and kills unreliable.
5. **Estimate cost**: expected mutants × baseline time. If the estimate exceeds ~15 minutes, tell the user the estimate and propose narrowing the scope (fewer files, changed files only, incremental mode) before running.
## 3. Run the native tool (preferred)
Read `references/tools.md` for per-ecosystem commands, how to scope them to the target, how to run them ephemerally, and where each writes its results. Use the machine-readable output (JSON / text lists) to build the report — never eyeball a progress bar.
Native tools are preferred because they mutate systematically, run in parallel, use per-test coverage to skip pointless runs, and sandbox the code. Fall back to §4 when no tool exists for the stack, it cannot be run without unapproved installs, or it fails to work with the project after a reasonable attempt (say which and why in the report).
## 4. Manual fallback campaign
When running mutants by hand, quality beats quantity: 20–40 well-chosen mutants on high-value code tell more than 500 random ones.
1. **Isolate.** Create a copy that is not the user's working tree:
```bash
git worktree add --detach "<scratchpad>/xmen-worktree" HEAD
```
Then bring over uncommitted changes to the target files if the scope includes them (copy the files in), and symlink heavy dependency dirs instead of reinstalling (`node_modules`, `.venv`, `vendor`) when the toolchain tolerates it. Without git, `cp -R` the project (excluding dependency and build dirs) into the scratchpad. Re-run the baseline **in the copy** and confirm it is green there.
2. **Choose mutation sites.** Read the target code and pick lines where a bug would matter: branch conditions, boundaries and comparisons, arithmetic in business rules, return values, error/guard paths, state updates, calls with side effects. Skip logging, trivial getters, and dead code (note dead code as a finding instead).
3. **Generate mutants** from `references/operators.md`. One change per mutant, syntactically valid, and plausible — the kind of bug a human would actually write.
4. **Execute each mutant**: apply the edit in the copy → run only the tests mapped to that file, with a timeout of ~3× baseline (minimum 10 s) → record the outcome → restore the file (`git checkout -- <file>` in the worktree, or re-copy) → verify it is restored before the next mutant.
5. **Tear down**: `git worktree remove --force "<scratchpad>/xmen-worktree"` (or delete the copy), then compare the user's tree against the snapshot (git status or checksums).
## 5. Classify outcomes
| Outcome | Meaning | Counts toward score as |
|---|---|---|
| **Killed** | at least one test failed | detected |
| **Timeout** | tests hung (e.g. mutated loop never ends) | detected |
| **Survived** | all tests passed | undetected |
| **No coverage** | no test executes the mutated line | undetected (report separately — it is a coverage gap, not an assertion gap) |
| **Unviable / compile error** | mutant does not build | excluded |
| **Equivalent** | mutation cannot change observable behavior | excluded — only after you have argued why (see below) |
**Mutation score** = detected ÷ (detected + undetected). Report it overall and per file. Also report the score over covered code only (excluding No coverage) — it separates "tests are missing" from "tests are weak".
**Triage every survivor before reporting it.** Read the mutated code and the tests that cover it, then decide:
- **Real gap** — a test runs this code but does not assert the behavior that changed (weak assertion, assertion on the wrong thing, missing boundary case, exception type/message not checked, side effect not verified).
- **Missing test** — nothing meaningfully exercises this path.
- **Likely equivalent** — the mutant cannot change observable behavior (e.g. `i < len` → `i != len` in a loop that only increments; mutating a value immediately overwritten). Say *why* in one line. When unsure, treat it as a real gap and mark it "Possibly equivalent".
## 6. Rank survivors
| Risk | Meaning | Typical examples |
|---|---|---|
| **Critical** | The undetected bug would corrupt data, money, security or authorization decisions | survivor in auth/permission check, price/tax/balance computation, input validation at a trust boundary |
| **High** | Core business rule or contract can silently change | boundary of a domain rule (`>=` → `>`), removed guard clause, swapped branch in domain logic, return value of a public API |
| **Medium** | Local behavior can change unnoticed | error message/path not asserted, secondary branch, default value |
| **Low** | Minor or cosmetic behavior | formatting, ordering where order is not part of the contract |
Group survivors that share one root cause (e.g. five mutants in a function whose only test asserts `is not None`) into a single finding listing all of them — the fix is one better test.
**Account for every survivor.** Each surviving and no-coverage mutant appears exactly once in the report: in a numbered finding (whose heading or Mutation line states how many mutants it groups, e.g. "(4 mutants)"), under *Not covered at all*, or under *Likely equivalent*. Before writing the report, check that the per-finding counts plus the listed equivalent mutants add up to the totals in the outcome table, and fix whichever side is wrong. A reader must be able to verify that no survivor was silently dropped.
## 7. Report format
```markdown
# X-Men Tester — Mutation Report: <target>
**Verdict:** <one line, e.g. "Tests catch 68% of injected bugs; 3 High-risk blind spots in pricing rules">
**Mutation score:** <n>% (<detected>/<total valid>) · **Covered-code score:** <n>%
**Engine:** <tool + version | manual campaign (<n> mutants) — and why> · **Scope:** <files mutated> · **Test command:** `<cmd>` · **Runtime:** <m>m<s>s
| Outcome | Count |
|---|---|
| Killed | n |
| Timeout | n |
| Survived | n |
| No coverage | n |
| Equivalent / unviable (excluded) | n |
## Per-file score
| File | Score | Killed | Survived | No cov. |
|---|---|---|---|---|
## Surviving mutants
(ordered Critical → Low; number them so the user can say "write the test for #2")
### 1. [HIGH] <short title naming the blind spot>
- **Where:** `src/pricing.py:14` in `apply_discount`
- **Mutations (n):** `if total >= 100:` → `if total > 100:` (list every grouped sibling; n is the count)
- **Why it survived:** <the covering tests and what they fail to assert, e.g. "tests use 50 and 200; nothing checks exactly 100">
- **Real bug it stands for:** <the production failure this gap would let through>
- **Kill it with:** <a concrete, runnable test in the project's framework and style — a complete test function, even for Low findings. Never prose ("add a test for rounding"), a bare expression, or "covered by the test in #1"; if one test kills several findings, repeat it or name it and show it once in full in the first finding that uses it>
```python
def test_discount_applies_at_exactly_100():
assert apply_discount(100) == 90
```
## Not covered at all
- `path:line-range` — <what is untested; one line each>
## Likely equivalent mutants (excluded)
- `path:line` `<mutation>` — <why it cannot change behavior>
## Suite health notes
- <patterns seen across survivors: assertion-free tests, snapshot-only tests, mocks asserting nothing, over-mocking that hides logic, flaky tests found during baseline>
## Housekeeping
- Working tree restored: <yes — git status (or file checksums) identical to the pre-run snapshot>
- Full tool report: <path to HTML/JSON report, if any>
- Not run / limitations: <excluded files, sampling, timeouts, anything partial>
```
Omit empty sections. If the score is high and no meaningful survivor remains, say so plainly — do not manufacture findings. A score is context, not a grade: 100% is rarely worth chasing; the survivors in critical code are what matter.