muharmutation harness
Pages

Mutation testing that proves each fault landed

muhar plants named faults in your source, one exact text edit each, proves on disk that every edit landed, runs your test suite, and records whether the suite went red. If the harness itself cannot be trusted — the suite was already red, or a fault it must catch went unnoticed — the whole run is discarded with exit status 2. It is never reported as a clean result.

Install muharRun the worked example

This is a real run against the small Go package in the worked example. Two guards have tests that notice when the guard is removed. One does not.

Commandmuhar -spec mutations.json
Exit0
Harness healthy: baseline GREEN, positive control CAUGHT.
  CAUGHT         zero is accepted as an amount
  CAUGHT         the limit ignores what was already spent today
  NOT_CAUGHT       a withdrawal that lands exactly on the limit is refused
Totals: 2 caught, 1 NOT CAUGHT, 0 could-not-mutate.

A passing test is not a test that can fail

A green suite tells you the code did what the tests checked. It does not tell you whether the tests check the thing you care about. Line coverage does not either: a line can execute under a test that asserts nothing about it.

Mutation testing asks the direct question. Change the code the way a bug would — flip a comparison, drop a check, return early — and run the suite. If the suite goes red, a test is guarding that behaviour. If it stays green, nothing is: the bug you just planted would ship.

Tools such as PIT, Stryker, cargo-mutants, Gremlins and mutmut generate hundreds of such changes automatically and report a mutation score. muhar takes a narrower job and does it with stricter evidence. The comparison covers where each of them is the better choice.

What muhar does differently

Named guards, not a score

You write each mutation yourself, as the specific guard you need proven: the daily-limit check, the authorisation check, the refusal that stops a bad merge. Each one has a name, and the report gives a verdict per name. There is no generated mutant list to triage and no percentage to argue about. The question each line answers is the one you asked: does the suite notice when this guard is gone?

Proof that each fault landed

A mutation is an exact text edit: replace this string with that one, in this file. muhar refuses an edit that cannot change anything — an empty or missing old string, old equal to new — writes the result, then reads the file back from disk and compares the bytes. Only a mutation proven in place is handed to the suite. One that cannot be proven is reported as COULD_NOT_MUTATE, its own state, and never as NOT_CAUGHT.

A broken harness never reads as clean

Before any verdict, muhar runs your suite on pristine source (it must pass) and then plants a positive control — a mutation the suite must catch. If either check fails, nothing after it can be believed, so muhar prints HARNESS BROKEN — run discarded., gives the reason, prints no per-guard verdicts and no Totals: line, and exits 2.

Three verdicts, never two

VerdictMeaningWhat to do
CAUGHTThe suite failed with the mutation in place. A test guards this behaviour.Nothing.
NOT_CAUGHTThe suite passed with the mutation proven in place. No test notices this guard is gone.Write the missing test, then rerun.
COULD_NOT_MUTATEThe edit could not be planted or proven, so the suite never ran against it.Fix the spec: the old text drifted, or the file moved. Never read this as clean.

The output reference has the exact format of every line, and the exit codes.

Any file, any suite

The suite is any shell command, and a mutation is a text edit, so muhar is not limited to Go source. The same spec can plant a fault in a JSON policy file, a shell script or a YAML config, and run whatever command proves it: go test, make check, bats. Writing good mutants has examples for each.

{
  "test": "go test ./... -count=1 -timeout 60s",
  "control": {
    "name": "CONTROL: never refuse an over-limit withdrawal",
    "file": "limits.go",
    "old": "\t\treturn ErrOverLimit",
    "new": "\t\treturn nil"
  },
  "mutations": [
    {
      "name": "zero is accepted as an amount",
      "file": "limits.go",
      "old": "if amount <= 0 {",
      "new": "if amount < 0 {"
    }
  ]
}

When muhar is the wrong tool

If you want broad, automatic coverage of a codebase you do not know well, use a generator: it will find weak spots you did not think to name. muhar has no mutation operators, no score, and no coverage-guided test selection yet, and it runs your whole suite once per mutation. It earns its place on the short list of guards that must never silently lose their test, and in CI where a broken harness must fail the build rather than pass it. The roadmap lists the cost and selection work in progress.

Where to go next

  • Install: a release binary or a build from source.
  • Worked example: from an empty directory to a NOT_CAUGHT you then fix, in five minutes.
  • Spec reference and CLI reference: every field and flag.
  • CI integration: sharded legs and the Totals: line as a gate.
  • muhar ships with Assay, a delivery workflow for coding agents, whose release pipeline uses it to prove that the desk tools' refusals are tested.