mutation-test

Validates test assertions by mutating source code and confirming the test suite fails.

1|Updated Jul 16, 2026
One-click install
npx skills add https://github.com/LunarCommand/claude-skills --skill mutation-test-lunarcommand
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mutation-test
Source: https://github.com/LunarCommand/claude-skills/tree/main/skills/mutation-test
Command: npx skills add https://github.com/LunarCommand/claude-skills --skill mutation-test-lunarcommand

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? A green test run proves nothing: a dead assertion and a live one produce identical output. This Skill establishes real evidence that a test checks something by deliberately breaking the behaviour it claims to cover and confirming the suite goes red, and it scopes that work to a PR or diff by shortlisting the changed lines. ## Core Features & Use Cases - Manual mutation procedure: A disciplined seven-step workflow — name the claim, back up the file, confirm a green baseline, apply and verify the mutation, read the failure, restore by content, and report both findings separately. - PR and diff scoping: mutation_test_changed_lines.sh parses a unified diff (e.g. from gh pr diff) into a list of added or modified lines worth mutating, and mutation_test_worktree.sh provides a throwaway git worktree with a verified green baseline to work in. - Dead code verification: Answers claims that code is unused or unreachable by deleting it from a copy and observing which tests break. - Use Case: After writing a fixture that passes immediately, use this Skill to mutate the boundary condition it asserts on, confirm the test fails for the right reason, and restore the file — proving the assertion is live rather than vacuous. ## Quick Start Ask the AI to mutation-test the assertion in your newly written test by breaking the behaviour it covers and confirming the test goes red.

Frequently Asked Questions about mutation-test

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I verify a test actually asserts something?

Use mutation testing: deliberately break the behaviour the test claims to cover, then confirm the test fails. First confirm the test is green unmodified, apply the smallest mutation that violates the claim, verify the edit landed, and read the failure message to ensure it failed for the right reason.

How do I mutation test only the lines changed in a PR?

Pipe the PR diff through mutation_test_changed_lines.sh, for example `gh pr diff 277 | mutation_test_changed_lines.sh --suffix .py`, to get every added or modified line as path and line number. Then run mutations in a throwaway checkout created by mutation_test_worktree.sh at the PR head ref.

Why do all my mutants survive even though coverage exists?

The usual cause is the tests importing the file from somewhere other than where you mutated it, such as a Python editable install recording an absolute path to the original source. Mutate the file in place where the tests load it, and if every mutant still survives, suspect the environment before believing the coverage.

Can mutation testing check whether code is dead or unused?

Yes. Delete the code in question from a backup copy, run the tests that plausibly touch it, and report what breaks. A claim that survives deletion is probably right; one that kills tests is answered with evidence rather than assertion.

Does this skill apply mutations automatically?

No. Choosing the mutation and judging the result are manual in both workflows; there is deliberately no batch runner. The scripts only shortlist changed lines from a diff and provide a disposable worktree with a verified green baseline.

Why restore mutated files with cmp instead of git checkout?

Files targeted by mutation testing usually hold uncommitted work, so git checkout or git restore destroys that work rather than restoring it. Copy the file to a .mtbak backup first, mutate, then restore from the copy and verify with cmp before deleting the backup.