# CLI reference
Supercov has one command for measuring a suite and a small set of commands for
reading the result. Text output is designed for people and coding agents. Add
`--json` only when an integration needs a stable machine-readable response.
```sh supercov
npx supercov --help
```
## Quick reference
| Measure a suite | `npx supercov -- <test command>` |
| List recent runs | `npx supercov runs` |
| Read the newest run | `npx supercov runs latest` |
| Find useful gaps | `npx supercov runs latest gaps` |
| Inspect one file | `npx supercov runs latest file <path>` |
| See how much executed code the tests assert | `npx supercov runs latest assertions` |
| Assess it with Jev | `npx supercov runs latest assertions assess` |
| Find what is not asserted in one file | `npx supercov runs latest assertions <path>` |
| See each test's answer for one statement | `npx supercov runs latest assertions <path>:<line>` |
| See what one test is judged to catch | `npx supercov runs latest assertions --test <name>` |
| List what is asserted on a weak answer | `npx supercov runs latest assertions --weak` |
| See how far the tests got toward killing each mutant | `npx supercov runs latest mutants` |
| Run the tests against the mutants they infected | `npx supercov runs latest mutants test` |
| Read matching current source code | `npx supercov runs latest source <path>` |
| Compare two runs | `npx supercov diff <older> <newer>` |
| Open an interactive report | `npx supercov report` |
| Find the tests a change affects | `npx supercov runs latest tests affected` |
| Combine shards | `npx supercov merge <id> <id> [...]` |
| Add coverage measured elsewhere, by line | `npx supercov import lcov.info --test <name>` |
| Remove stored runs | `npx supercov runs clean` |
| Assess code quality with Jev | `npx supercov quality` |
| See only files with findings | `npx supercov quality gaps` |
| Review what a change introduced | `npx supercov quality patch` |
| Remove saved assessments | `npx supercov quality clean` |
| Find security surface with Jev | `npx supercov security` |
| Review what a change introduced, security only | `npx supercov security patch` |
| Read bundled guides | `npx supercov docs` |
## Assess source quality
```sh supercov-example
npx supercov quality # this repository
npx supercov quality src/ # one directory
npx supercov quality gaps # only files something fired on
npx supercov quality file src/a.ts # one file, every check
npx supercov quality scope # which files are assessed, and why
npx supercov quality snapshots # saved assessments
npx supercov quality diff <older> <newer>
npx supercov security # twelve security checks, every file
npx supercov security gaps # only files something fired on
npx supercov security patch --base origin/main
npx supercov security --run latest # flagged files no test exercises
```
With no argument the subject is the repository you are standing in. Every
assessment saves a snapshot, so the reading commands work afterwards with no key
and no network.
Twelve yes/no questions about named code properties go to [Jev](https://typesafe.ai);
the score is arithmetic this command does over the answers. Text reports a band,
`good`, `fair` or `weak`; `--json` carries the number and every check with what
is known about it. `--all` includes test files, generated output and anything
outside a source root, all of which are left out by default. `--dry-run` prints
the exact requests and contacts nothing; how many there are and what they cost
is one line on stderr.
`quality diff` reports what changed between two assessments: which files lost
or gained health, each check that moved in them with its value before and after,
and which files entered or left the scope.
Assessing needs a TypeSafe AI API key in `TYPESAFE_API_KEY`; reading a saved
assessment does not. `TYPESAFE_BASE_URL` and `TYPESAFE_DEFAULT_MODEL` use Jev
through another provider, such as OpenRouter. The command prints a cost estimate before sending anything
and caches answers by content, so a second run pays only for what changed.
See [Understanding quality](https://supercov.com/docs/quality) for what the
number is worth and which files get assessed.
## Review what a change introduced
```sh supercov-example
npx supercov quality patch
npx supercov quality patch --base origin/main
npx supercov quality patch --base origin/main --annotate github --run latest
```
The same twelve properties asked of a change, plus six risk checks that only
apply to one: a credential in source, untrusted input in a query, a change to
who may do what, a test that now checks less, a schema migration, and debugging
left behind.
With no range it reviews uncommitted work when the tree is dirty and everything
since this branch left its default branch when it is clean. `--unstaged`,
`--staged` and `--base <ref>` say so explicitly; `--base` uses the merge base,
like `runs patch`, so commits other people landed after you branched are not
your change.
`--annotate github` prints workflow annotations on stdout, needing no token and
posting no comment. `--run <id>` reads a saved coverage run and marks any file
where a property appeared and the run left lines uncovered.
Output lists only files where something appeared. A change that introduces
nothing prints one line saying so. About $0.0005 per changed file.
## Measure a test command
```sh supercov
npx supercov -- <test command>
```
Everything after `--` is passed to the test command:
```sh supercov
npx supercov -- npm test
npx supercov -- npx playwright test --project=chromium
npx supercov -- cargo test
npx supercov -- cargo nextest run
```
Use the complete command you rely on before merging or deploying. A coverage run
preserves the wrapped command's exit status, so it can remain a CI gate.
Some launchers drop the `--` before Supercov sees it: Bun when it runs the
script (`[run] bun = true`, `bun --bun run`, `bun run supercov`), Yarn 1's
`yarn supercov -- ...`, and PowerShell on its way into a package manager's
`.ps1` shim. A first word that is no Supercov command but a program on `PATH`,
or a path to one, is then still measured as the test command, and Yarn 1's
`--exact-attribution` is restored from what Yarn recorded. Under Yarn 1 in
PowerShell, a `--` of the test command's own is lost before Supercov runs:
put that command in a package script.
A script that queries the run it just recorded can have Supercov write the
run's id to a file. `latest` is the newest run, which is another one when two
commands record runs side by side:
```sh supercov-example
SUPERCOV_RUN_ID_FILE=unit.id npx supercov -- <test command>
npx supercov runs <run-id> check --min-lines 80 # the id in unit.id
```
The file is removed when the run starts and written when it is recorded, so a
run that is not recorded leaves no id behind.
## List and select runs
```sh supercov
npx supercov runs
npx supercov runs --limit 5
npx supercov runs latest
npx supercov runs <run-id>
```
Runs are listed newest first. `latest` is convenient during an interactive
loop. Use the immutable run id in automation, review notes, and work that spans
sessions.
## Query a run
```sh supercov
npx supercov runs <run-id> [query] [options]
```
| no query | Read the overall result, test outcome, completeness, and timings |
| `gaps` | See only files with uncovered behavior or measurement limits |
| `files` | See every included file, including fully covered files; `--group dir` shows coverage by directory, split by test kind |
| `file <path>` | Inspect the open obligations in one file |
| `decision <id \| path:line>` | Understand missing boolean outcomes and MC/DC witnesses |
| `line <path:line>...` | See a line's state, obligations, and covering tests; several lines, or `--from-file` with one per line, in one call |
| `test <id \| name>` | See the coverage attributed to one test |
| `tests without-evidence` | List the tests that made assertions and recorded no coverage, which the summary counts in a warning |
| `kinds` | Group coverage by test level, such as unit or E2E |
| `runners` | Group coverage by test runner |
| `scope` | See what is source and what is not, by directory and reason; `--files` lists every file |
| `assertions` | Read the share of executed statements the tests assert, and the ones they do not; `assertions assess` works it out |
| `mutants [path[:line]]` | See, for each mutant the language's established tool would make (StrykerJS; in preview mutmut, cargo-mutants, Gremlins and mutant), whether a test reached it and changed its value |
| `source <path>` | Read matching current project source with line numbers |
| `minimize` | Find a small test subset that preserves a coverage target |
Common examples:
```sh supercov
npx supercov runs latest gaps --limit 10
npx supercov runs latest file app/routes/checkout.ts
npx supercov runs latest decision app/routes/checkout.ts:42
npx supercov runs latest line app/routes/checkout.ts:57
npx supercov runs latest test "checkout retry"
```
To see where the coverage is, read it by directory. Each row is a directory,
with what it holds and how much of it each kind of test covers; `--depth`
keeps more levels, and `--metric` picks branches, functions, statements or
MC/DC instead of lines:
```sh supercov
npx supercov runs latest files --group dir
npx supercov runs latest files --group dir --depth 2 --metric branches
```
```
Directory Files Lines e2e unit no test All
app 5 23 86.96% 0.00% 8.70% 95.65%
lib 1 10 90.00% 40.00% 0.00% 90.00%
. 2 8 75.00% 0.00% 25.00% 100.00%
components 1 2 100.00% 0.00% 0.00% 100.00%
```
`no test` is what ran only while no test was running, such as a server
starting before the first test. The column is there when a directory has any.
In `--json`, every file of `files` and `gaps` carries `totals` and `covered`
for each metric beside what is missing, so a percentage can be worked out for
any file or set of files.
A page holds at most what fits in one reply, so a `--limit` larger than that
returns fewer entries. Such a page says so: `pageCut` in `--json` gives
`asked`, `returned` and `nextOffset`, and stderr names the `--offset` the rest
start at.
`line` reads the run once for every location it is given, so asking for
twenty lines in one call costs about what one does. `--from-file` takes the
locations from a file, one per line, skipping blank lines and `#` comments.
Each line of several lists its state, its gaps and its first three covering
tests, with `totalTests` and `totalPhases` for the rest; asked alone, a line
lists every test and phase. In `--json` the reply is `coverage.lines`, one
entry per location in order, each location once. Locations that do not fit one
reply are listed in `remaining`, and `pagination.nextOffset` says where the next
reply starts: ask again with `--offset`, as for any page.
A location naming no file of the run, or more than one, is listed under **Not
answered** (`failed` in `--json`, each with its `location`, `code` and
`message`) and the others are still answered; the call fails only when none
is. A line whose file changed since the run is answered from the working tree
with a warning naming that file; a change elsewhere, a test's included, does
not make the answer stale. A line holding no statement, branch or function
start is **NOT MEASURED** and says so.
```sh supercov
npx supercov runs latest line app/routes/checkout.ts:42 app/routes/checkout.ts:57
npx supercov runs latest line --from-file lines.txt --json
```
An MC/DC gap names the value each missing condition never took, in `file`,
`line` and `decision` (`` `sum < 50` was never true; needs `express` false,
`sum < 50` true, decision true ``). In `--json` it is `missingOutcomes`:
`["true"]` or `["false"]`, both when no test evaluated the condition, and
none when it took both values but never decided the result alone.
`file --group decision` lists the missing conditions under each decision.
Run any query with `--help` to see only the options valid for that query:
```sh supercov
npx supercov runs latest --help
npx supercov runs latest file --help
npx supercov runs latest assertions --help
```
`source <path>` reads the matching current file directly. It prints source code
with line numbers, preserving indentation; add `--json` only when you want
structured `{line, text}` items. `--offset` is zero-based and `--limit` controls
the number of source lines. The file must still match the run; rerun the suite
after source changes.
### Assertion coverage
```sh supercov-example
npx supercov runs <run-id> assertions assess --dry-run
npx supercov runs <run-id> assertions assess
npx supercov runs <run-id> assertions assess --refresh # ask again instead of reusing saved answers
npx supercov runs <run-id> assertions assess --tag @e2e --dry-run
npx supercov runs <run-id> assertions
npx supercov runs <run-id> assertions --all --json
```
`assertions assess` asks Jev, test by test, whether each statement the test ran
would make it fail if changed, and saves the result to the run; it needs
`TYPESAFE_API_KEY` for questions not answered before. `assertions` reads the
saved result without the network. The regular run summary shows the same share,
and JSON reports expose it under `data.assertionCoverage`. See
[Assertion coverage](assertions.md) for what counts as asserted and how answers
are reused across runs.
`--kind`, `--runner`, `--tag`, `--title` and `--test-file` assess or read some of
the tests, as they narrow every query. `assess --tag @e2e` asks only those tests
about the statements they ran and saves the result apart from the run's whole
assessment; its answers are kept, so a later `assess` asks only what is left.
`assertions --tag @e2e` reads what those tests assert: a statement that only
other tests catch is not asserted there.
### Mutants
```sh supercov-example
npx supercov runs <run-id> mutants
npx supercov runs <run-id> mutants app/checkout.ts
npx supercov runs <run-id> mutants app/checkout.ts:42
npx supercov runs <run-id> mutants --status not-infected,not-reached
npx supercov runs <run-id> mutants --mutator EqualityOperator --json
npx supercov runs <run-id> mutants --stryker reports/mutation/mutation.json
npx supercov runs <run-id> mutants --format jsonl --output mutants.jsonl
npx supercov runs <run-id> mutants --diff origin/main
npx supercov runs <run-id> mutants --diff origin/main --format markdown --output mutants.md
npx supercov runs <run-id> mutants --diff origin/main --fail-on not-infected,not-reached
```
`mutants` reads weak mutation from the run: for each mutant StrykerJS 10.1.1
(JavaScript, TypeScript) would make, or in preview mutmut 3.8.1 (Python),
cargo-mutants 27.1.0 (Rust), Gremlins 0.6.0 (Go) or mutant 0.17.1 (Ruby) would
make (see [Mutation testing](mutation.md)), whether a test
ran the mutated code and whether the mutant's value would have differed there.
Nothing runs again. A plain run does nothing for mutants and costs nothing
more for them: a run lists its mutants from its sources the first time they are asked for (by `mutants`,
`mutants test` or `supercov mutants`), and keeps them beside the run. A source
changed since the run is left out until the run is measured again.
`supercov mutants` does all of it: it measures a run of the checkout with the
mutants' probes where the latest run is of other sources or is a plain one,
lists the mutants, and runs `mutants test`; while the checkout is unchanged it
reads that run again. Listed this way, a mutant whose verdict
needs the values its expression took is `unknown`, and `mutants test` runs it;
a run measured with `SUPERCOV_MUTANTS=1` records those values (the mutants'
probes) and decides more of them without running anything.
Each mutant has one status:
| `not-reached` | No test ran the mutated code |
| `not-infected` | A test ran it, and every evaluation gave the mutant the original's value: these tests cannot kill it |
| `infected` | Some evaluation gave the mutant another value: a candidate kill, not a kill |
| `unknown` | The run cannot tell, such as code that ran where values are not recorded |
| `equivalent` | No input can make it differ, shown by a static rule from the code alone, whatever the tests did |
The weak score is `infected / (infected + not-infected + not-reached)`, with
unknown and equivalent mutants left out, and beside it the same over reached
mutants alone. They are shown beside coverage and never change it.
A not-infected boundary comparison (`<` and `<=`, `>` and `>=`) with an
operand that is a clock reading (`Date.now()`, `new Date()`,
`performance.now()`, and arithmetic, `.getTime()` or date-fns `add*`/`sub*` of
one, through up to two consts or local functions) or a `Math.random()` reading
is listed with `(clock boundary)` or `(random boundary)`: only one exact
reading would make it differ, so a test can hardly reach it. It stays not
infected, and the summary counts these beside the not-infected ones
(`211 not infected (12 at a clock or random boundary)`).
Without a file, `mutants` shows a table of files, a page at a time, ordered by
how many mutants a test reaches and does not infect, which only this report
shows, then by how many no test reaches, then by name. Files no test ran at all
come last, however many mutants they hold, and a line counts them. With a file
it lists the file's mutants by line, as `line:column Mutator original →
replacement status reason`; with `file:line`, that line's mutants each with its
reason and id. A mutant whose code is on several lines or too long to show is
shown by the part it changes, with `…` for what it shares with the original:
`….slice(0, maxUsers) → …` for a chain without its last call. `--status` and `--mutator` pick mutants, across files when no
file is given. The scores are of the mutants asked about: the run, a file or a
line, and one mutator with `--mutator`. The run summary shows one line,
`Mutants 15 · weak score 53.3% · 1 not infected · 6 not reached · 0 unknown ·
0 equivalent`, and `data.mutants` in its JSON.
`--kind`, `--runner`, `--tag`, `--title` and `--test-file` read the verdicts of
those tests alone: a mutant only other tests infect is not infected there.
`--filter passed` and `--filter failed` are not supported.
In `--json` the reply is `coverage.mutants`: `mutantSet`, `levels`
(`weak: true`, `strong: false`), `summary` with the counts by status,
`untestable` (the not-infected mutants at a clock or random boundary),
`weakScore`, `weakScoreReached` and `mutationScore` (null until tests run
against mutants), and a page of `mutants`, each with its `id`
(`file:line:column-line:column:Mutator:descriptor`), `span`, `original`,
`replacement`, `changed` (`from`, `to`: the part shown, where it is shown
instead), `status`, `weak` (`reach`, `infection`, `code`, `reason`; `rule` for
an equivalent mutant; `untestable` and `untestableReason` for a clock or
random boundary), `strong` (null) and `stryker`. Mutants are listed by file path, and within a
file by position, whatever the table's order.
`--format jsonl` writes every mutant asked about, one JSON object per line,
each as `--json` lists it, with nothing paged; `--output <file>` writes them
to a file instead of standard output. A file, `--status`, `--mutator`,
`--stryker` and the options that narrow the tests apply as they do to the
query.
`--stryker` joins StrykerJS's own reports by mutant id. It takes several
reports, as a glob gives them (`--stryker reports/*.json`), and directories of
them, whose every `.json` file is read, recursively; a file to query goes
before it. Give `--stryker-root <dir>` when a report's paths are relative to
another directory than the project root. The commands the reply suggests repeat
what `--stryker` was given, or `<56 reports>` for more than three. Each mutant
then shows StrykerJS's status, and a `stryker` block counts the mutants
matched, those only Supercov or only StrykerJS made (by mutator), and how many
of StrykerJS's survivors this run says no test infects or reaches. A mutant
this run says is not infected, not reached or equivalent that StrykerJS killed
is a soundness violation: each is listed, and the command exits `1`.
The HTML report (`supercov report`) shows a run's mutants of every language
where it shows its coverage (see [Mutation testing in the HTML
report](reports.md#mutation-testing)): the weak and the strong score side by
side with every status counted, why the mutants without a verdict have none,
each language, the mutants left alive by file, a Mutants column with each
file's score, and each line's mutants with both levels' verdicts and the test
that killed one. `supercov report --diff <base>` shows only a change's
mutants. A run without mutants shows none.
#### Mutants on a pull request
`--diff <base>` keeps the mutants on lines a change added or modified since it
left `<base>`, a git ref such as `origin/main`. The change is the commit the
run measured against its merge base with `<base>`; a run measured with
uncommitted changes, or one that records no commit, is compared as the working
tree, untracked files added whole, and the output says so. Everything else
composes with it: a file or line, `--status`, `--mutator`, the test filters,
`--json`, `--format`, `--stryker`, and the scores, which are of the change's
mutants. A base git does not know (a shallow checkout's) fails with exit `2`.
The output names the base, the merge base and how many changed lines hold a
mutant, then lists the mutants the tests leave alive, not infected first and
then not reached, each with the part it changes and why, and counts the rest
in one line. `--json` lists every mutant of the change, survivors first, with
`diff` (`base`, `mergeBase`, `commit`, `changedLines`, `linesWithMutants`).
`--format markdown` writes a table for a pull request's comment: the counts in
one line, then up to 25 not-infected and not-reached mutants (or those
`--status` names) with where they are (`file:line:column`), what they change,
their status and why, and the command that lists the rest. Once `mutants test`
gave verdicts, a second line has the mutation score, with how many mutants it
is over (or, with none, why there is no score), and every verdict counted
(killed, timed out, survived, no coverage, unviable, error, not run for want
of a driver, and those with none yet), and the table lists the survivors: the
mutants that survived or that no test covers, then those weak mutation shows
no test can kill, each with its weak status, its strong verdict and why.
#### Mutation reports other tools read
```sh supercov-example
npx supercov runs latest mutants --format stryker --output reports/mutation/mutation.json
npx supercov runs latest mutants --format pit --output target/pit-reports/mutations.xml
```
`--format stryker` writes StrykerJS's `mutation.json`: the mutation testing
report schema's version 2, which mutation-testing-elements' HTML report, the
Stryker Dashboard and CI integrations read. Each file carries its language and
its source as the checkout holds it, which the schema requires: a file the
checkout no longer has is left out and named on stderr. `--format pit` writes
PIT's `mutations.xml`, which PIT's report aggregator and Sonar's PIT plugin
read. Both hold the mutants asked about (a file, `--diff`, `--mutator` and the
test filters narrow them), each with its strong verdict where `mutants test`
gave one:
| `killed` | `Killed` | `KILLED` |
| `timeout` | `Timeout` | `TIMED_OUT` |
| `survived` | `Survived` | `SURVIVED` |
| `no-coverage` | `NoCoverage` | `NO_COVERAGE` |
| `unviable` | `CompileError` | `NON_VIABLE` |
| `error` | `RuntimeError` | `NOT_STARTED` |
| not run: no driver for its language | `Pending` | `NOT_STARTED` |
| `equivalent` | `Ignored` | left out |
| no verdict, not reached | `NoCoverage` | `NO_COVERAGE` |
| no verdict, not infected | `Survived` | `SURVIVED` |
| no verdict, infected or unknown | `Pending` | `NOT_STARTED` |
A mutant no test reaches or infects is the one the strong pass itself decides
without running it, as no-coverage or survived, so the two formats say the
same before a pass ran. A StrykerJS mutant's `statusReason` and a PIT
mutant's `description` say why, in the words the HTML report uses; a killed
mutant names its test in `killedBy` and `killingTest`. Supercov mutates
source, not bytecode: a PIT mutant's class is its file's path after a `java`
or `kotlin` source root (`com.shop.Cart`), its method is left empty, and its
index is its place in its file.
`--fail-on <statuses>` exits `1` when any mutant asked about has one of them,
`--diff`'s mutants with it: a gate CI can hold a change to. Without it the exit
codes are as before. In GitHub Actions, after the tests are measured:
```yaml
- uses: actions/checkout@v6
with:
fetch-depth: 0 # the base and the merge base
- run: npx supercov -- npm test
- run: npx supercov runs latest mutants --diff origin/${{ github.base_ref }} --format markdown --output mutants.md
- run: gh pr comment ${{ github.event.number }} --body-file mutants.md --edit-last --create-if-none
env:
GH_TOKEN: ${{ github.token }}
- run: npx supercov runs latest mutants --diff origin/${{ github.base_ref }} --fail-on not-infected
```
### Strong mutation: run the tests against the mutants
```bash
npx supercov runs latest mutants test # every mutant the run's tests infected
npx supercov runs latest mutants test --diff origin/main # only the change's mutants
npx supercov runs latest mutants test --file src/billing.ts
npx supercov runs latest mutants test --plan --json # what would run, nothing run
npx supercov runs latest mutants test --critical "src/auth/**" --fail-on survived
```
`mutants test` reruns the measured run's command (or the one after `--`) with
every mutant behind a switch and saves StrykerJS's verdicts into the run:
`killed`, `survived`, `timeout`, `no-coverage`, and `error` for a mutant that
could not be switched on. The pass's summary ends with the mutants the tests
let survive (`file:line`, the mutator and the change, the first ten and how
many more). `mutants` then shows each mutant's verdict beside its weak status,
and the mutation score with the verdicts' counts; `mutants --status survived`
(or `killed`, `timeout`, `no-coverage`, `error`, `unviable`) lists the mutants
with that verdict, and `--format markdown` lists the survivors under the
mutation score. A Playwright mutant with many candidates that lived through
its first tier, with the rest of its candidates not run yet, is
`survived-so-far`: listed by `--status survived` as such (and alone by
`--status survived-so-far`), counted apart, and not in the score.
It runs far less than StrykerJS: no dry run (the measured run is one), no
mutant no test infected (decided `survived`) or reached (`no-coverage`), and
each mutant only against the tests whose own evidence shows they infected it.
Vitest suites run in rounds through one resident Vitest: each test file can
carry its own mutant, several copies of a file run side by side, a mutant is
switched on before the test file's imports, and it stops at its first failing
test. Playwright suites carry each attempt's mutant with its requests, so one
server serves different mutants to different workers; mutants of a server's
start-up run with the server restarted for them. Jest, node:test, Mocha, AVA,
node-tap, bun:test and Vitest's Browser Mode run one test file per start of the
command, with the mutant switched on in every process from its start (in the
page, under Browser Mode) and only that file's candidate tests, stopping at
the first failure; Jest and Mocha keep resident runners for it. Python, Rust,
Go and Ruby are in preview. Rust mutants
run through cargo's tests, or through the JavaScript tests that load the
crate compiled to wasm. Go mutants run each package's test binary, built once.
Ruby mutants run in a fork of the loaded suite under RSpec, Minitest, test-unit
or Cucumber. Python suites under pytest or unittest (`python -m
unittest`) collect their tests once; each mutant then runs in a fork of that
process, its function switched to mutmut's copy of it, against its candidate
tests in collection order, stopping at the first failure. A mutant whose code
ran while the test modules loaded runs in a fresh interpreter of the command
with the mutant on from its start. A mutant no driver runs the tests of is an
`error`, which the score leaves out as every error, and the summary says how
many in a line per runner (`12 mutant(s) not run: no strong driver for
phpunit`). See `docs/design/strong-mutation.md`,
`docs/design/python-mutants.md` and `docs/design/mutation-drivers.md`.
- `--shard k/n` runs one of n shares of the mutants, of about the same cost
(the copies and tests each mutant runs), for parallel jobs; each
job's run holds its share's verdicts, `merge` keeps them all in the merged
run, and a later `supercov mutants` keeps each verdict nothing changed could
move from whichever earlier run holds it (see
[Combine shards](#combine-shards)). `supercov mutants --shard` saves into a
run of its own even on an unchanged checkout, so a job never saves into a
run it restored, which every job of its round holds a copy of. There it
makes that run from the newest restored run whose command passed, without
measuring again, and keeps every verdict the restored runs hold. A run whose
command failed only because tests failed is made into one too, where none
passed: a failed test is no candidate, and the shard says which it leaves
out. A run whose command failed otherwise (no test failed, or no exit
status) is not, and the shard measures, saying what kept that run out.
- `--critical <glob>` (repeatable): every mutant there must be killed or
accepted, or the command fails.
- `--fail-on survived,timeout,no-coverage,error`: fail on any asked mutant with
one of these.
- Accepted equivalents: `supercov.accepted.json` at the project root, a list of
`{ "id": "<mutant id>", "reason": "<why no test can tell it apart>" }`. An
accepted mutant still runs, shows as accepted, and never fails the command;
an entry whose mutant is killed or gone is listed as stale.
- A second `mutants test` over the same run runs only what has no verdict yet.
The pass saves each verdict as it comes: one that stops early (a test worker
that never ended, Ctrl-C, a killed job) keeps what it decided, and the next
pass runs the rest. Ctrl-C or SIGTERM stops every process the pass started,
and the pass ends within seconds: 8 s after the signal at the latest.
- `--budget <seconds>` stops the pass once it is spent, counted from the
command's start (with `supercov mutants`, measuring included): it ends as a
finished pass, its verdicts saved, and says how many mutants it left for the
next, and what measuring took where that was half the budget or more. The
cheapest mutants run first, by their tests' recorded times.
- `--timeout-factor <x>`: a Playwright test that runs with a mutant is
stopped past x times its baseline + 5 s (default 1.5, StrykerJS's), and the
mutant is a `timeout`. `SUPERCOV_STRONG_TIMEOUT_FACTOR` sets it where the
option is not given.
- After an edit, `supercov mutants` measures the checkout again and keeps an
earlier run's verdict for each mutant whose file is as it was and whose
candidate tests, and their test files, nothing changed could reach (as
`tests affected` reads a change: a test file's edit reaches its tests, a
source's edit the tests that ran the changed code). The rest run; the
summary says how many verdicts were kept, and from which run.
- `--diff` and `--file` answer about the mutants they ask for: the summary's
counts and score are theirs, and its first line says how many of the run's
mutants that is. `--format markdown` (with `--output <file>`) writes the
answer as a pull request's comment, as `mutants --format markdown` does.
- A run that recorded no test is refused with exit `2`; where its command ran
mutants' code (a runner Supercov has no adapter for, such as tape), it says
how many and names the runner. A pass over a run whose command failed
answers, then exits `2`: a failing test kills nothing, so the verdicts are
the passing tests' alone and cannot gate. So does a pass in which no mutant
could be run. A mutant only work outside any test ran is `no-coverage`.
- The command's own output goes to a log beside the pass's results; stdout is
the answer alone. When the pass ends, its directory under `.supercov/strong`
keeps only those logs, and the next pass removes it.
## Fail CI below a coverage floor
```sh supercov-example
npx supercov runs check --min-lines 90 --min-branches 80 --min-mcdc 80
npx supercov runs check --min-lines 100 --per-file --json
```
`check` reads a recorded run; it never runs tests again. Give a floor per metric
with `--min-lines`, `--min-statements`, `--min-functions`, `--min-branches` or
`--min-mcdc`. `--per-file` applies the same floors to every file that has
eligible obligations, in addition to the whole run. Both report the counts
behind the percentage and, for lines, where the gaps are.
`--kind`, `--runner`, `--tag`, `--title` and `--test-file` hold some of the
run's tests to a floor of their own, `--kind e2e --min-lines 60` say, from the
same run.
Floors are compared against the counts, never a rounded percentage: 9,999
covered lines out of 10,000 displays as 99.99% and fails a 100% floor, and a
run that displayed `100.00%` could never pass one while something is uncovered.
A check answers only when the run can answer. These end the command with `2`
rather than a pass or a failure:
- the wrapped test command did not pass, so a gate over it would turn a red CI
run green
- the run no longer matches the current checkout
- a requested metric has nothing eligible, which is not the same as complete
- a requested metric left obligations unmeasured, so no exact judgement exists
- a requested metric is not recorded by the language adapter
## Check the lines a change touches
```sh supercov-example
npx supercov runs patch --base origin/main --min-lines 100
npx supercov runs patch --base origin/main --annotate github
```
`patch` answers whether the lines this change added or modified are tested. It
compares against the **merge base** with `--base`, not that branch's tip, so
commits other people landed after you branched are not counted as your
obligation. A shallow checkout has no merge base; fetch with full history
(`actions/checkout` takes `fetch-depth: 0`).
The denominator is the changed lines the run measured. Comments, blank lines and
declarations fall out because the language adapter already decided they are not
executable, not because `patch` guesses at syntax. Deleted lines are excluded:
there is nothing left to cover. Untracked new source counts as entirely added.
A change with nothing executable in it reports **No executable changes** and
passes, rather than claiming 100% for a patch that changed only comments. A
changed file that looks like product source but is absent from the run is named
separately, because treating it as zero uncovered lines would report success for
code nothing ran.
A run whose suite failed still shows the change's coverage, but `patch` exits 2
and `--json` gives `result: "error"` with the reasons: a gate over a failed
suite cannot pass. A run whose source has changed since is refused, because
its lines no longer map onto the checkout.
`--kind`, `--runner`, `--tag`, `--title` and `--test-file` ask whether some of
the tests reach the change: the E2E tests, or the tests of one file.
`--annotate github` prints workflow-command annotations on stdout, combining
adjacent misses into one range and capping the total (`--max-annotations`). It
needs no token and posts no comment.
## Comment on a pull request
In GitHub Actions, one step runs the tests, says in a comment which changed
lines no test ran, and marks them in the diff:
```yaml
on: pull_request
permissions:
contents: read
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: npm ci
- uses: supercorp-ai/supercov@v4
with:
command: npm test
```
`command` is the test command in any supported language: `pytest`,
`cargo test`, `go test ./...`, `bundle exec rspec`, `mvn test`. The step takes
the place of the one that ran the tests, and fails when they fail. It needs no
account and no server: the comment is written with the workflow's own token,
and everything else stays on the runner.
The comment gives the coverage of the changed lines, the run's line, branch and
MC/DC coverage, and each changed file with the lines no test ran, linked to the
commit. A later push rewrites the same comment. The job summary holds the same
report, which is what a pull request from a fork gets: its token cannot write a
comment.
| `command` | required | The test command. One command; put several in a script. |
| `working-directory` | `.` | Where to run it. |
| `min-changed-lines` | none | Fail below this percentage of changed lines covered. |
| `min-lines`, `min-branches`, `min-mcdc` | none | Fail below this percentage for the whole run. |
| `title` | `Coverage` | The comment's heading. Give each job its own when several comment on one pull request. |
| `base` | the pull request's base | What the change is compared with. |
| `comment`, `annotate` | `true` | Turn the comment or the marks in the diff off. |
| `version` | the action's release | The Supercov release to run. |
| `binary` | none | A `supercov` already on the runner, used instead of downloading one. |
The default checkout fetches one commit; the step fetches the history between
it and the base itself. It puts `supercov` on the `PATH` and sets the outputs
`run-id`, `lines`, `branches` and `changed-lines`, so later steps can read the
same run:
```yaml
- run: supercov runs report --format html --output coverage/report
```
## Export for other tools
Every obligation a run left uncovered, one JSON object per line:
```sh supercov-example
npx supercov runs latest gaps --format jsonl --metric mcdc --output gaps.jsonl
npx supercov runs latest gaps --format jsonl > gaps.jsonl
```
Each line holds the file, the line, the source of that line and what `runs
<id> file` says of the obligation: for an MC/DC condition its decision, the
condition and the vectors observed. `--metric`, `--filter`, `--kind`,
`--runner`, `--tag`, `--title` and `--test-file` narrow it as they narrow
`gaps`, and nothing is paged, so a tool or an agent reads a run's every gap in
one pass instead of a page at a time.
`runs <id> mutants --format jsonl` exports a run's mutants the same way, one
mutant per line, and `--format stryker` and `--format pit` as the mutation
reports StrykerJS's and PIT's tools read (see [Mutation reports other tools
read](#mutation-reports-other-tools-read)).
```sh supercov-example
npx supercov runs report --format lcov --output coverage/lcov.info
npx supercov runs report --format cobertura --output coverage/cobertura.xml
npx supercov runs report --format istanbul --output coverage/coverage-final.json
npx supercov runs report --format istanbul-summary --output coverage/coverage-summary.json
npx supercov runs report --format clover --output coverage/clover.xml
npx supercov runs report --format jacoco --output coverage/jacoco.xml
npx supercov runs report --format sonar --output coverage/sonar.xml
npx supercov runs report --format html --output coverage/report
```
| `lcov` | an LCOV tracefile | Codecov, Coveralls, Qlty, `genhtml`, editors |
| `cobertura` | Cobertura XML | GitLab merge requests, Azure DevOps, ReportGenerator |
| `istanbul` | Istanbul's `coverage-final.json` | tools that read JavaScript coverage by range, such as CRAP gates, and Istanbul's own reporters |
| `istanbul-summary` | Istanbul's `coverage-summary.json` | pull-request comment Actions for Vitest and Jest, badge generators |
| `clover` | Clover XML | Qlty, Codecov, Atlassian tools |
| `jacoco` | JaCoCo XML | GitLab merge requests, SonarQube's Java analysis, Qlty |
| `sonar` | SonarQube's generic coverage XML | SonarQube and SonarCloud, for any language (`sonar.coverageReportPaths`) |
These formats carry coverage only: none has a place for a mutant, so a run's
mutants are in `mutants --format stryker` and `--format pit` instead, and in
the `html` page.
All are written from the same view `check` and `patch` read, so a viewer,
hosted service or CI integration sees the totals Supercov enforced. `--kind`,
`--runner`, `--tag`, `--title` and `--test-file` write the coverage of only
those tests, from the same run:
```sh supercov-example
npx supercov runs report --format lcov --kind e2e --output coverage/e2e.info
```
Paths are
repository-relative with forward slashes, ordering is stable, and the file is
written atomically; an existing file is kept unless you pass `--force`. Without
`--output` the report goes to stdout and diagnostics to stderr, so a redirect
captures only the report; an HTML report asked for in a terminal is written to
`.supercov/reports/coverage-report.html` instead, replaced each time, and its
path said.
Supercov records that a line ran, not how many times, so `DA:`, `hits`,
Istanbul's counts and Clover's `count` state `1` or `0`. They are not execution
frequencies, and Supercov will not invent one to fill a field. JaCoCo counts
bytecode instructions, which Supercov does not measure, so the `jacoco` export
states each measured line as one instruction, missed or covered. Cobertura,
Clover, JaCoCo and SonarQube state branches by line; a branch on a line that is
not itself measured, such as a later line of a statement written across
several, is stated on the measured line its statement starts on, so their
branch totals are Supercov's.
The `istanbul` export places every statement, function and branch by its range
in the source, found in this checkout; its keys are absolute paths, as Istanbul
writes them. A file changed since the run no longer holds what the run recorded
there, and the export stops and names it rather than guess where it moved: run
the tests again. Istanbul records no place for each alternative of a branch, so
each is placed at its branch. The summary states Supercov's own counts, its
lines included.
MC/DC conditions are not exported as ordinary branches. A consumer would then
show condition obligations as branch coverage, which is a different
measurement. The LCOV export writes them as LCOV 2's own records, `MCDC:` for
each condition with `MCF:` and `MCH:` for a file, so `lcov --mcdc-coverage` and
`genhtml --mcdc-coverage` show a per-file MC/DC figure from the export alone.
LCOV counts a condition twice, once for each way it can turn the outcome, and
Supercov's covered condition is both: hit over found is the run's MC/DC. A
reader of the older format passes the records over. The other formats have no
such record; there the evidence stays in the JSON view and the HTML report. A report
from a failed or stale run is still written, with a warning on stderr — only
`check` refuses to pass on one.
### The HTML report
`--format html` writes one self-contained document. It opens from a copied CI
artifact with no server, no network and no login, and nothing is fetched from a
CDN. Because a source path is never used as an output path, a filename cannot
write outside the directory you named, and no directory is ever cleared to
regenerate a report.
It has three levels: the run's metric counts, a filterable and sortable file
table, and a source view marking each line covered or not covered in words and
a glyph as well as colour. Every line links as `#<file>:<line>`, so a CI summary
can point someone at the obligation rather than at the report.
Four states stay distinct, because collapsing them into one score is how a
report starts to mislead: **uncovered** (measured, nothing reached it), **not
applicable** (nothing eligible), **partly measured** (Supercov declined some
obligations, which are excluded from every count) and **stale** (the run no
longer matches the checkout). A failed suite says so beside its numbers.
For a run whose mutants are listed it also shows its mutation testing, as
`supercov report` does (see [Mutation testing](reports.md#mutation-testing)):
a Mutation testing card with the weak and the strong score, every status
counted, why mutants have no verdict, each language, and the survivors by
file, each linking to its line; a sortable Mutants column with each file's
score and survivors; and, under each line of the source, its mutants with
what they change, both levels and the test that killed one, a survivor set
apart. `--diff <base>` keeps the mutants on lines a change added or changed
since its merge base with `<base>`, and the card says so; with another
format `--diff` is refused, as those formats carry no mutants.
```sh supercov-example
npx supercov runs latest report --format html --diff origin/main --output coverage/report
```
Source text is embedded only when the run still matches the checkout; otherwise
the report shows line numbers and explains why. Embedding makes a report
portable and also means it contains your code — worth knowing before uploading
one as a public artifact.
## Narrow a view
| `--filter all \| passed \| failed` | Recalculate the view from all, successful, or failed attempts |
| `--kind <kind>` | Restrict to a test level such as `unit`, `integration`, or `e2e` |
| `--runner <runner>` | Restrict to one runner |
| `--tag <tag>` | Restrict to tests with this tag; repeat it for tests with any of several, and start a value with `!` to leave those tests out |
| `--title <text>` | Restrict to tests whose name contains this text |
| `--test-file <path>` | Restrict to tests in this file, or in this directory |
| `--metric all \| lines \| statements \| functions \| branches \| mcdc` | Choose a metric for `files`, `gaps`, `diff`, or `minimize` |
| `--limit N`, `--offset N` | Page through a collection; `--limit 0` lists every entry |
| `--json` | Return the machine-readable form |
Collection output includes a copyable command for the next page.
### Read some of a run's tests
`--tag`, `--title` and `--test-file` read the coverage of only the tests they
pick, from a run already measured: the API tests of a Playwright suite, the
tests of one spec file, everything named `checkout`. Each takes several values
for tests matching any of them, and when several are given a test must match
each. A value starting with `!` leaves those tests out, so the browser tests of
a suite whose other tests are tagged read as the tests with none of the tags.
```sh supercov
npx supercov runs latest --tag @api
npx supercov runs latest gaps --test-file tests/e2e/checkout.spec.ts
npx supercov runs latest files --title checkout --tag smoke
npx supercov runs latest --tag '!api' --tag '!cron' --tag '!webhook'
```
A tag is what the runner gives a test: a Playwright tag (`{ tag: '@api' }`, or
an `@word` in the title), an `@word` in a Jest, Vitest, Mocha, `node:test`,
AVA or tap title, a pytest marker, an RSpec tag or `type`, a Cucumber tag, a
JUnit `@Tag` or a TestNG group. Tags are written with or without the `@` and in
any case. `runs <id> test <name>` lists a test's tags.
The first query with a filter works out its coverage from the run's evidence
and keeps it beside the run (12 s for a run of about 3,000 tests); asking again
reads it back in a fraction of a second. Nothing is added to the test run
itself.
For a large file, group and rank its decisions:
```sh supercov
npx supercov runs latest file app/routes/checkout.ts \
--group decision --sort missing
```
## Compare runs
```sh supercov
npx supercov diff <older-run> <newer-run>
```
`diff` reports gains and losses. Use it after adding a test to prove that the
expected behavior became covered without an unexplained regression elsewhere.
Neither input run is changed. Under the totals it lists what was lost, marked
`-`, and then what was gained, marked `+`:
```
gained: 1 line, 1 branch, 0 MC/DC conditions
lost: 1 line, 1 branch, 0 MC/DC conditions
- line src/fee.js:5
- branch src/fee.js:2 false
+ line src/fee.js:3
+ branch src/fee.js:2 true
```
When the difference is in more than one file, the files come first, the one
that lost most at the top, so a component that did not render in one run reads
as one row and not as forty:
```
in 2 files, most lost first:
src/panel.js: lost 6 lines, 1 branch
src/fee.js: lost 1 line, 1 branch; gained 1 line, 1 branch
```
The counts are of the whole difference, whatever page of it is shown. In
`--json`, `files` and `byFile`.
Two runs of the same code can differ a little: what an end-to-end suite
reaches depends on timing, on the order of tests, and on state outside the
code. When both runs measured the same source, `diff` says so under the
totals, and a loss it lists is not a change in the code. Run again before
acting on one. In `--json`, `inputs.sourceChanged` and `inputs.testsChanged`
say what differed between the two runs.
The same filters can focus a comparison:
```sh supercov
npx supercov diff <older-run> <newer-run> --kind e2e
```
To see what a new test covered that the suite did not, measure it alone and
compare it with the suite's run, keeping only what it gained:
```sh supercov-example
npx supercov -- <the new test alone>
npx supercov diff <suite-run> latest --gained
```
A test run alone covers far less than the suite, so a plain `diff` of the two
lists nearly everything as lost. `--gained` lists only the lines, branches and
MC/DC conditions the newer run covers and the older does not, which is how to
check that a test reached the conditions it was written for without measuring
the whole suite. In `--json`, `gainedOnly` is `true` and `lost` is empty.
## Generate a portable HTML report
```sh
npx supercov report
npx supercov report <run-id>
npx supercov report latest --compare <older-run-id>
```
`report` turns stored local evidence into one self-contained interactive HTML
file and opens it in the default browser. It does not rerun tests, start a
server, load external assets, or upload anything. The default report includes
up to ten recent runs. Selecting a run compares it with the previous saved run
automatically.
```sh
npx supercov report --runs 10
npx supercov report --output artifacts/supercov-report.html --no-open
```
`--kind`, `--runner`, `--tag`, `--title` and `--test-file` make a report of
only those tests' coverage, in every run it holds; a run with none of them is
left out, and the report names the tests it shows.
`--diff <base>` shows only the mutants on lines a change added or changed
since its merge base with `<base>`, as `runs <id> mutants --diff` reads them,
and the report says so; coverage is not narrowed. See [Mutation
testing](reports.md#mutation-testing) for what the report shows of mutants.
A report includes the five newest runs; `--runs N` includes up to 20. A large
project's report can pass GitHub's 25 MB attachment limit; `--runs 1` makes
the smallest. See [Portable HTML reports](reports.md) for
the privacy and source-integrity rules.
## Find a smaller test set
```sh supercov
npx supercov runs latest minimize
npx supercov runs latest minimize --metric branches --target 90
```
`minimize` finds a small set of tests that preserves the selected coverage
target. Without `--target` it keeps everything the tests together cover, so
it works on a run that is not fully covered; `--target 90` asks for 90% of
each selected metric instead. It does not edit, delete, or skip tests for you. Treat the result as an
analysis aid, not permission to remove tests that protect behavior outside the
selected metric.
## Find the tests a change affects
```sh supercov
npx supercov runs latest tests affected
npx supercov runs latest tests affected --files
npx supercov runs latest tests affected --json
```
`tests affected` names the tests of a run whose recorded execution the changes
since that run could have reached: a change in code the test ran, in its test
file, or in the shape of a file it ran code in -- a declaration added, removed
or renamed. A change confined to code the test never ran does not count, and
neither do comments, blank lines or trailing whitespace. A test that did not
pass in the run is listed regardless.
`--names` prints one affected test name per line and `--files` one test file
per line, for a runner's filter. A Vitest, Playwright or node:test test inside
`describe` blocks is printed as the blocks and the test joined by spaces
(`small charges`), which is what `vitest -t`, `--grep` and
`--test-name-pattern` match. A Rust test is printed as its path in its crate
(`tests::it_works`), which `cargo test -- --exact` and nextest's `test(=...)`
match. `--kind`, `--runner`, `--tag`, `--title` and
`--test-file` list only the affected tests they pick: from a run that merged two
runners' suites, `tests affected --names --runner playwright` gives Playwright
only its own tests. A helper beside the tests, or source outside what is
measured, that changed affects the tests whose files import it (a JavaScript or
TypeScript helper that only gained functions affects none), and every test
where Supercov cannot read the imports. A dependency,
lockfile, configuration or toolchain change affects every test and is reported
as such; a test runner's settings affect only the runs that used that runner.
A source file
added since the run is outside every test's record; the working-tree check
says so, and the suite should run in full.
A Rust test loads what it names by path: a fixture, a data file or a script
named in its own function (or in its entry of a macro that declares a test
per entry), or anywhere in its file outside another test, and what a script it
names imports and names in turn. A path that goes on in a placeholder
(`tests/fixtures/{name}`) names the directory before it. So a change to one
fixture affects the tests that name it, and a file no test names, as before,
affects every test. A file measured Rust source embeds with `include_str!` or
`include_bytes!` is part of the declaration embedding it: a template or a
script compiled into the binary affects the tests that ran that code. Changed
code no probe of the run measured -- code for another platform, a feature the
run's build left off -- is listed under `unmeasured` (`--json`) and named in
the text: no test's record says what it reaches, so run the suite in full
where that code is compiled.
A server the suite starts is recorded too: a mock server `webServer` starts,
or the application's own. Each Node process of a Playwright run notes the
project files it loads and reads, and the tests it serves, by the test a
request names or, for one that names none (a webhook), the test running
then. A change to a file such a process loaded or read, a mock's code, a
helper it imports or the data it reads, affects the tests it served and no
others. A mock keeps its state between tests, so a mock's files count whole,
not route by route; a file the application's server loaded, a preload of its
own, affects every test it served.
### Which affected tests check the change
When the run has an [assertion assessment](assertions.md), `tests affected`
also says, for each affected test, whether it was judged to catch a change to
the statements that changed in code it ran, and lists those tests first. A run
without an assessment answers from coverage alone, as above.
```sh supercov
npx supercov runs latest assertions assess # once, on the run
# ... edit code ...
npx supercov runs latest assertions assess --changed # ask every test that ran the changed code
npx supercov runs latest tests affected --names --ran-changed
```
The assessment stops asking about a statement once one test catches it, so on
its own it knows only some tests' answers. `assess --changed` asks, for the
statements in code changed since the run, every test that ran them: typically
a few requests per commit. After it, `--ran-changed` leaves out the affected
tests that ran the changed declaration but none of the changed statements, and
`--asserting` also those judged to catch no change to them. Tests whose own
file changed or that did not pass stay, and so does any test never asked. With
an assessment or without, `--names` and `--files` list first the tests whose
own file or name shares words with a changed file (`test_receivebuffer.py` for
`_receivebuffer.py`), the verdicts breaking ties.
Measured by applying random changes and running the suite:
| h11 (Python, 78 tests) | 23 (153) | all 153 in 28 tests | all 153 in 23.5 | 141 in 19.9 | 18 of 23 |
| go-version (Go, 31 tests) | 36 (140) | all 140 in 10.1 | all 140 in 9.8 | 133 in 9.4 | 32 of 36 |
`--ran-changed` never dropped a failing test; `--asserting` dropped 5 to 8% of
them. `assess --changed` cost about a tenth of a cent per change.
Measured on real history: at each of a project's recent commits, the source
the commit replaced was put back -- someone reintroducing what it fixed -- and
the commit's own tests run against it:
| h11 (Python) | 60 (13) | 27 | 27 | 27 | 25.2 / 24.9 of 75 |
| go-version (Go) | 24 (2) | 3 | 3 | 3 | 15.2 / 14.1 of 25 |
| dry-inflector (Ruby) | 12 (7) | 26 | 26 | 26 | 813 / 718 of 1,109 |
| uuid (TypeScript, node:test) | 4 (3) | 6 | 6 | 6 | 13.2 / 11.5 of 64 |
| dtolnay/semver (Rust) | 20 (0) | 0 | -- | -- | 27.9 / 25.9 of 38 |
| commons-cli (Java) | 15 (7) | 12 | 12 | 12 | 159 / 143 of 985 |
No failing test was left out of the set to run. On real commits the
assessment narrows little -- Jev judges most tests that ran a changed line to
catch the change -- and its verdicts alone ranked a failing test in the first
three for only 6 of 32 breaking commits. Ranking by name, with the verdicts
breaking ties, put one there for 10 of those 32, and for 15 of 25 breaking
commits in four projects it was not designed on (hashie, Masterminds/semver,
itsdangerous, java-classmate), where file order managed 11; without an
assessment, name alone managed 8 and 12. After a project's first
assessment, each commit cost under a cent.
## Combine shards
```sh supercov
npx supercov merge <shard-a> <shard-b> <shard-c>
npx supercov merge
```
Merge creates a new run. The inputs must describe the same source,
configuration, toolchain, schema, and coverage denominator. Supercov rejects an
incompatible merge rather than publishing a misleading aggregate.
With no run named, `merge` takes the runs recorded on the source as it is now,
leaving out runs that are themselves a merge. It prints the runs it took. This
is what a script uses after measuring its suites, one after another or side by
side, without knowing what each run was called. Asked again with nothing new,
it names the merge already made.
A test that is in two of the runs is one test in the merge. If it failed in
either, it is failed, which is why a command measured again in the same
project replaces its earlier runs there and is not merged with them. Runs of
one command measured on different machines and copied into one
`.supercov/runs` replace none of each other: each is a share of the suite, and
all are merged.
A test whose records two runs hold byte for byte alike, once each run's id is
the merge's, is kept once, from the first run, and so are an entry's records
of no test (a server's background): a run made from another without measuring
(a continuation round's shard) adds nothing to them, and the merge says how
many copies it kept once (`3402 copy(ies) of records that an earlier run held
byte for byte kept once, from that run`). A copy that differs in anything, a
timestamp, a path the test took, an outcome, is kept beside the others, so
nothing any run recorded is lost. Jobs that each measured the whole suite
record each test with times of their own, and keep a copy each.
The runs may differ in their tests, the helpers beside them, and the test
runners' settings, as long as nothing that changed reaches what an earlier
run's tests did. Measuring a new test alone and adding it to the runs before it
is then the whole suite's figure, without the whole suite's time:
```sh supercov-example
npx supercov -- npm test # the suite, once
npx supercov -- <the new test alone> # a test added since
npx supercov merge
```
Each file that differs from what an earlier run was recorded with is judged by
what that run's tests did with it:
- Another run's test file: it was not in this run. A file of the run's own
tests: what it recorded is of other tests, and the run is left out.
- A file the run measured: left out, always.
- A helper, fixture or support file, or source outside what is measured (a
simulator kept out of `SUPERCOV_SOURCE_ROOTS`): left out of a run only when
that run's test files import it, directly or through other files. Supercov
reads the imports of JavaScript, TypeScript, Python and Ruby tests, with
pytest's `conftest.py` files and `pytest_plugins`, and what `.rspec`
requires; a computed import, a glob of support files, a change to
`sys.path` or `$LOAD_PATH`, or tests in another language count every helper
as loaded. A JavaScript, TypeScript or Python helper that only gained
functions, which code written before cannot have called, leaves every run
in. In Python that is a plain `def`: a decorator runs when the module
loads.
- A test runner's settings: `playwright.config.*`, `vitest.config.*`,
`jest.config.*` and `ava.config.*` belong to their runner, and a run that
did not use that runner keeps. Of Playwright's settings, only those that
decide what a test does count: `use`, `testDir`, `webServer`,
`globalSetup`, `globalTeardown`, and a project's `dependencies` and
`teardown`. Timeouts, retries, workers, reporters, which files and names to
run, and projects added since schedule tests and change nothing an earlier
test reached. This needs the newer run to have measured Playwright.
- Any other configuration, such as `tsconfig.json`, `vite.config.*` or a
Babel file, may set how any test runs, and leaves the run out.
A run left out is named with the files and the functions that changed. The
merged run lists what differed and why it does not reach the earlier runs:
`merged across:` in `runs <id>`, and `mergedAcross` in JSON.
A changed file that a server the run's tests reached loaded or read (see
[Find the tests a change affects](#find-the-tests-a-change-affects)) takes
only those tests from the run: measure them again, and the merge keeps the
rest of the run and leaves their old records out:
```sh supercov-example
npx supercov runs <suite-run> tests affected --names # after changing a mock
npx supercov -- <those tests alone>
npx supercov merge
```
Until they are measured again, the merge refuses and names them.
When you know a change Supercov counts does not alter what the earlier tests
ran, say so:
```sh supercov-example
npx supercov merge --allow-changed
```
The product code, the dependencies, and what is measured must still be the
same, and a run whose own test files changed is still left out. What was
accepted is listed in `merged across:` as accepted.
Runs measured on different machines merge the same way. Each machine
measures its part of the suite on the same commit and toolchain, and one job
merges them after copying each run's directory from `.supercov/runs/` into its
own:
```yaml
# Each of two jobs:
- run: npx supercov -- <test command for shard ${{ matrix.shard }}>
- uses: actions/upload-artifact@v4
with: { name: "supercov-${{ matrix.shard }}", path: .supercov/runs, include-hidden-files: true }
# Then one job:
- uses: actions/download-artifact@v4
with: { pattern: "supercov-*", path: .supercov/runs, merge-multiple: true }
- run: npx supercov merge
```
Every machine must install the same dependencies. With a lockfile committed,
install it as it is in each job (`npm ci`, `pnpm install --frozen-lockfile`,
`yarn install --immutable`, `bun install --frozen-lockfile`). A repository
without one resolves its dependencies anew in each job, and `merge` leaves
every run out as `the dependencies have changed`: resolve the lockfile once in
a first job, pass it to the others as an artifact, and `npm ci` it there.
A merged run lists the mutants of every file a run listed (see
[Mutants](#mutants)), once. Runs that listed different mutants of a file
recorded with the same bytes are not merged. A run that listed no mutants
adds none, and where its tests ran a mutant, a verdict that needs values they
did not record is `unknown`.
The merged run keeps the strong verdicts the runs saved (`mutants test`,
`--shard` among them), by mutant, and `merge` prints how many, how many came
from each run, and how many the merged run's plan decides without running
them (`1265 strong verdict(s) kept from runs r8, r7: 1103 from r8, 150 from
r7, 12 the merged run's plan decides`). A verdict two runs hold alike counts
for the first run named. A kill in any run is a kill. A survival stands only where the run that
let the mutant survive measured every test of the merged suite that could
kill it; where another run's tests could, and it has no verdict, the mutant is
left for a pass over the merged run to run. An error stands only where no run
holds anything else. A run whose verdicts are of another mutant set than the
merged run lists lends none, and `merge` names it; a run some of whose tests
another measured again lends none either. Split a strong pass across jobs this
way: each job measures and runs `supercov mutants --shard k/n -- <command>`,
and the last merges (see `docs/mutation.md`, A pass split across jobs). A
second round on the same commit restores the first round's runs and does the
same: each job saves into a run of its own, made from a restored one without
measuring again, which keeps the restored runs' verdicts and replaces them,
and the last job's `merge` takes the new runs.
A run named twice is refused (`Each merged run must be unique: r1 is named
more than once`): copies of one run that several jobs saved verdicts into
share its id, and `.supercov/runs` holds one of them. Up to 4.29.5,
`supercov mutants --shard` on a checkout unchanged since the runs it restored
saved into the latest of them; run such a round again.
`assertions assess` assesses a merged run across every suite merged into it,
reusing the answers saved when its parts were assessed. `tests affected` of a
merged run is answered from the runs it was merged from, which hold the record
of what each test ran; a test in several of them is affected where any says so.
## Add coverage measured elsewhere
Some code runs where Supercov cannot measure it: a deployed worker, a
production container, a binary another tool built. If that environment can
write an LCOV tracefile, add its lines to a run:
```sh
npx supercov import lcov.info --test "edge in production"
npx supercov import lcov.info --background --run <run-id>
```
The import publishes a new run made from the latest one (or the one `--run`
names), and leaves that run as it was. The lines are credited to a test of
their own, of kind `imported` with runner `lines`, or to the run's background.
This evidence is line-only. A line that ran credits every statement on it, and
a function that was entered credits the function. Branches, decisions and MC/DC
come only from Supercov's own measurement. A file the run did not measure joins
it with one statement per recorded line, and is marked as measured only by the
import.
Paths are matched to the project: an absolute path under the project, or the
one measured file a path ends with, such as `/app/src/lib.rs` for
`src/lib.rs`. Files outside the project are left out and listed. If evidence
names a line past the end of a file, it was recorded from other source, and
the import refuses it.
Supercov runs no other coverage tool. A profile another tool recorded is
exported as LCOV by that tool first. For an LLVM profile from a binary built
with `-C instrument-coverage`, with `rustup component add llvm-tools`:
```sh
llvm-profdata merge -sparse default.profraw -o edge.profdata
llvm-cov export -format=lcov -instr-profile edge.profdata target/debug/edge > edge.info
npx supercov import edge.info --test "edge binary"
```
## Clean local data
```sh supercov
npx supercov runs clean --dry-run
npx supercov runs clean --keep 20
npx supercov runs clean
```
By default, `runs clean` removes all stored runs and the isolated build cache.
`--keep N` keeps the newest N runs, by when they started rather than by their
identifiers, which carry no order. Cleanup removes only marker-owned Supercov
storage.
Saved quality assessments live in their own lane and are never removed here: an
assessment costs money and cannot be reproduced from the repository. Remove
those deliberately, with the same options:
```sh supercov
npx supercov quality clean --dry-run
npx supercov quality clean --keep 5
npx supercov quality clean
```
If Supercov itself fails to publish a run the tests already paid for, it keeps
that run's raw evidence in `.supercov/failed-evidence/<run id>` and says so in
the error. Report the failure with that directory: it is what diagnoses it. Only
a full `runs clean` reclaims it -- `--keep N` leaves it alone -- and the summary says
when it goes.
## Read bundled documentation
```sh supercov
npx supercov docs
npx supercov docs getting-started
npx supercov docs troubleshooting
```
The guides are installed with the package, so they remain available in a
terminal or offline environment after the package has been downloaded.
## Environment variables
| `SUPERCOV_SOURCE_ROOTS` | Comma-separated directories or files that hold your own code, in any language; everything else is left out |
| `SUPERCOV_TEST_ROOTS` | For an Ant build whose `<batchtest>` directories cannot be read from its files: comma-separated directories that hold its tests |
| `SUPERCOV_TEST_KIND` | Label the wrapped command as a test level such as `unit` or `e2e` |
| `SUPERCOV_SOURCE_TOOLS` | Comma-separated names of tools the test command runs that read source as text, such as a linter or a spell checker, besides Biome, oxlint, dprint, cspell and knip. Each is run on your source as you wrote it instead of on the instrumented copy |
| `SUPERCOV_RUN_ID` | Set by Supercov, not by you: in every process a measured command starts, the run's id, so a test or harness can tell it is measured |
| `SUPERCOV_RUN_ID_FILE` | A file to write the recorded run's id to, for a script to query that run rather than `latest` |
| `SUPERCOV_KEEP_WORKSPACE` | Set to `1` to leave the instrumented copy of the project in `.supercov/workspaces/` after the run, to inspect what the command ran |
| `SUPERCOV_MUTANTS` | Set to `1` to measure a run with the probes that record the values its mutants' verdicts read, and list its mutants as it runs (see [Mutants](#mutants)); a plain run lists none and places no probe |
| `SUPERCOV_STRONG_WORKERS` | How many test processes a JavaScript or Python strong pass runs at once (default: about one per CPU) |
| `SUPERCOV_STRONG_TIMEOUT_FACTOR` | A Playwright strong pass's time limit for a test run with a mutant: this many times the test's baseline, + 5 s (default `1.5`; `--timeout-factor` overrides it) |
| `SUPERCOV_COMMAND_TIMEOUT_MS` | Stop the test command after this many milliseconds: what is still running is asked to stop, then made to five seconds later, what ran is recorded, and Supercov exits `124`. No deadline by default |
Examples:
```sh supercov
SUPERCOV_SOURCE_ROOTS=src,app npx supercov -- npm test
SUPERCOV_TEST_KIND=e2e npx supercov -- npx playwright test
```
## Exit codes
| `0` | The command or query succeeded |
| Wrapped command's code | The test command failed and Supercov preserved its status |
| `127`, `126` | The test command could not start: no such program, or one that may not be run, as a shell reports it |
| `124` | The test command ran past `SUPERCOV_COMMAND_TIMEOUT_MS` and was stopped |
| `1` | A valid measurement failed a policy you set, such as a coverage floor, or `mutants --stryker` found a soundness violation |
| `2` | Supercov could not complete the request, or the evidence cannot answer it |
`quality` and `security` exit `0` for a complete report in which some files
could not be assessed, such as a file larger than the model accepts; each is
listed in the report with its reason, and stderr says how many. They exit `2`
when no file could be assessed.