agentleFS
ThibautBaissacThibautBaissac/rails_ai_agents/.claude/skills/mutation-testing/SKILL.md

mutation-testing

Skill665 starsChanged 6 months agoMITView on GitHub

Run mutant, read mutation reports, fix alive mutations, and verify coverage. Use when running mutation testing, responding to alive mutations, or improving test quality. Triggers: "mutation testing", "mutant", "alive mutation", "mutation coverage". WHEN NOT: Writing tests from scratch (use rspec-agent), fixing failing tests, or general code review.

34 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use domain-modeling and grilling.

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.
  • GoogleSkill

    domain-modeling

    Build and sharpen a project's domain model. Use when the user wants to pin down domain terminology or a ubiquitous language, record an architectural decision, or when another skill needs to maintain the domain model.

    Also in 3 projects that use this

  • GoogleSkill

    grilling

    Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 31 edited versions we read keep these.

  • 19

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always present both options so the user can choose.

    line 83
  2. Distinctive:

    When the subject is known, scope the run to avoid testing unrelated subjects:

    line 97
  3. Very specific:

    If the command succeeds, coverage is 100% — done.

    line 103
  4. Very specific:

    If it fails, find the evil: line in the output — it has the subject name, file path, and line number.

    line 104
  5. Distinctive:

    Read the source file and existing spec file for the subject.

    line 110
  6. Distinctive:

    Ask: "Is the mutated code acceptable for all valid inputs?"

    line 111
  7. Distinctive:

    Add a test: when the mutated code is wrong but tests do not prove it.

    line 115
  8. Distinctive:

    Simplify the code: when the mutated code is correct for all valid inputs.

    line 116
  9. Distinctive:

    Do not change both code and tests in the same commit.

    line 118
  10. Distinctive:

    Follow the project's conventional commits format.

    line 132
  11. Distinctive:

    Add a test when the mutated code is wrong but the existing tests do not prove it.

    line 142
  12. Distinctive:

    Only one value of a boolean/flag is tested — add the other.

    line 146
  13. Distinctive:

    Before accepting a simplification, verify the mutation preserves behavior across the method's full input domain and all call sites.

    line 166
  14. Distinctive:

    Do not rewrite code to eliminate a mutation axis without first ensuring the expression has test coverage.

    line 171
  15. Distinctive:

    Add test coverage for the expression.

    line 175
  16. Distinctive:

    Verify 100% mutation coverage on the subject.

    line 177
  17. Distinctive:

    When the original and mutated code produce the same result for all inputs, the mutation is equivalent.

    line 181
  18. Distinctive:

    Ask: does the mutated form use a more constrained primitive?

    line 183
  19. Very specific:

    Add the subject to the ignore list in config/mutant.yml with an inline comment explaining why it is unkillable.

    line 194
  20. Distinctive:

    Do not commit code or test changes for this subject.

    line 196
  21. Distinctive:

    Every ignored subject must have a comment.

    line 200
  22. Distinctive:

    When adding mutant to a project with no ignore list, run mutant once to find all alive subjects, then seed the ignore list so burn-down can …

    line 206
  23. Very specific:

    Add each subject to the ignore list in config/mutant.yml with # legacy baseline.

    line 217

“Common” is measured: kept by at least 6 in 10 of the 31 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 Testing with Mutant

When to Activate

  • The user asks to run mutation testing.
  • The user has alive mutations to fix.
  • The user asks to verify mutation coverage on a subject.

When Not to Use

  • The task does not involve mutation testing.

Inputs

  • Alive mutation output to act on (paste the evil: block).
  • Optional: subject expression to scope the run.

Outputs (Fixed Order)

  1. Mutation results (alive count, coverage percentage).
  2. Clear action for each alive mutation: add test or simplify code.

Reading Mutation Output

An alive mutation looks like:

evil:YourClass#method:YourClass#method:lib/your_class.rb:42:abc12
@@ -1,3 +1,3 @@
 def method
-  @value >= threshold
+  @value > threshold
 end
  • evil means no test killed this mutation.
  • The diff shows original (-) and mutated (+) code.

Reporting Format (BLUF)

Lead with the verdict — bottom line up front:

If unkillable:

Unkillable. Both forms are equivalent because [reason]. Add to ignore list.

If killable:

Killable.

Option A — add test:

(test diff)

Option B — simplify code:

(source diff)

Always present both options so the user can choose. Include evidence: if you cannot think of a test that would kill the mutation, say so — that is valuable signal toward unkillable.


Usage

1. Run Mutant

bundle exec mutant run --fail-fast

When the subject is known, scope the run to avoid testing unrelated subjects:

bundle exec mutant run --fail-fast 'Entities::CreateService#call'

If the command succeeds, coverage is 100% — done. If it fails, find the evil: line in the output — it has the subject name, file path, and line number. The diff block immediately after shows the original and mutated code.

2. Investigate

Read the source file and existing spec file for the subject. Ask: "Is the mutated code acceptable for all valid inputs?"

3. Decide and Act

  • Add a test when the mutated code is wrong but tests do not prove it.
  • Simplify the code when the mutated code is correct for all valid inputs.

Do not change both code and tests in the same commit. If both need changing, commit the test first, then simplify the code in a second commit.

4. Re-run and Verify

Re-run mutant (step 1) until 100%. If the same mutation survives after 2 attempts, evaluate whether it is unkillable.

bundle exec rspec  # full suite must pass

5. Commit

Follow the project's conventional commits format. The commit body must explain which mutation survived, why the test kills it or why the simplification is correct.


Fixing Alive Mutations

When to Add a Test

Add a test when the mutated code is wrong but the existing tests do not prove it. The test must pass with the original code and fail with the mutated code. Common reasons a test is missing:

  • Only one value of a boolean/flag is tested — add the other.
  • A collection has one element, so next and break behave the same — add a test with multiple elements.
  • Two objects return the same value in test data, hiding which one the code actually uses — add test data where they differ.
  • A method has a default parameter, and all tests pass the argument explicitly — add a test that omits the argument.

When to Simplify Code

Simplify when the mutated code is correct for all valid inputs. Apply the mutation's change directly to the source code — do not restructure or rewrite, just accept the mutated form.

Mutant encodes the principle of least power: use the most constrained primitive that satisfies the requirement. When Ruby offers multiple methods that overlap in behavior but differ in power, mutant replaces the more powerful one with the less powerful one. If tests still pass, you did not need the extra power — accept the simpler form.

Before accepting a simplification, verify the mutation preserves behavior across the method's full input domain and all call sites.

Simplification Trap: Syntax Rewriting

Do not rewrite code to eliminate a mutation axis without first ensuring the expression has test coverage. Changing syntax may make the mutation disappear without proving the code is correct. The correct sequence:

  1. Add test coverage for the expression.
  2. Apply the simplification mutant suggests.
  3. Verify 100% mutation coverage on the subject.

When a Mutation Is Equivalent

When the original and mutated code produce the same result for all inputs, the mutation is equivalent. Equivalent does NOT mean unkillable. Ask: does the mutated form use a more constrained primitive? If yes, it IS the simplification — apply it to the source.

Examples: method → public_method (restricts to public API), kind_of? → instance_of? (restricts to exact class).

A mutation is only unkillable when you cannot add a test AND you cannot apply the mutation to the source.

When a Mutation Is Unkillable

  1. Add the subject to the ignore list in config/mutant.yml with an inline comment explaining why it is unkillable.
  2. Do not commit code or test changes for this subject.
  3. Report: which mutation survived, why it is equivalent, and what you tried before concluding it is unkillable.

Every ignored subject must have a comment. No uncommented entries.


Prepare a Legacy Project (First-Time Setup)

When adding mutant to a project with no ignore list, run mutant once to find all alive subjects, then seed the ignore list so burn-down can start from a passing baseline:

bundle exec mutant run 2>&1 \
  | sed -n 's/^evil:\([A-Za-z][A-Za-z0-9_:]*[#.][^:]*\):.*/\1/p' \
  | LC_ALL=C sort -u \
  || true

Add each subject to the ignore list in config/mutant.yml with # legacy baseline. Then remove one subject at a time and work through its alive mutations. Commit each fix with the ignore list removal included.


Checklist

  • Each alive mutation has a clear action: add test or simplify code.
  • New tests fail against the mutated code, not just pass against the original.
  • Full RSpec suite passes after each change (bundle exec rspec).
  • Each commit touches one subject only.
  • Unkillable mutations are in the ignore list with a comment.
  • Report: which mutation survived, which option was chosen, and why.

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.