mutant-cafe 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -6
- package/dist/bin.js +932 -290
- package/dist/bin.js.map +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Other mutants, all chosen from the checker's view of the return type:
|
|
|
15
15
|
- `Effect.succeed(value)` for plausible values of `A`, `Effect.fail` of each tag, `Effect.die`, and `Effect.never` behind a measured timeout
|
|
16
16
|
- `Option.none()` and `Option.some(value)`
|
|
17
17
|
- `Stream.empty`, a one-element stream, and a failing stream
|
|
18
|
-
- a `Layer` that
|
|
18
|
+
- a `Layer` that dies at build, even when its error type is `never`, plus one failing build per error tag
|
|
19
19
|
- flipped booleans and cycled literal unions
|
|
20
20
|
|
|
21
21
|
## Use it
|
|
@@ -28,12 +28,23 @@ npx mutant-cafe --list # preview the mutants
|
|
|
28
28
|
npx mutant-cafe --jobs 4 # test them
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
It mutates internal functions by default, including `Effect.fn` and `Effect.fnUntraced`, object-literal arrows, service methods inside Layers, and the inner function of a curried export. Layer values and static Layer properties are targets too. Names follow their path, such as `Greeter.layer.greet`, `policy.canEdit`, and `guardFor.<inner>`. With `--exported-only`, targets must be reachable through an exported binding path: exported top-level functions, methods and functions in exported values, returned curried functions, and exported Layers with their returned service methods. Local declarations and arrows inside other function bodies are internal, even if their owner is exported. This keeps local helpers out without dropping exported object or service APIs.
|
|
32
|
+
|
|
33
|
+
Value synthesis includes branded strings and numbers, empty sets and maps, anonymous objects with cycled literal fields, and same-typed parameters as identity replacements. Naked type-parameter returns get no fabricated values, but a same-typed parameter can still supply an identity mutant. Context-only generic types that cannot be named in the body are skipped with a reason. Literal leaves keep their type without making mutable arrays readonly. Generator mutants use the body's type before `Effect.fn` pipeables such as `Effect.scoped` or `Effect.map`.
|
|
34
|
+
|
|
31
35
|
Run it from the package whose tests you want to check. In a monorepo that resolves workspace packages through built output, build the package's dependencies first.
|
|
32
36
|
|
|
33
37
|
| Flag | Meaning |
|
|
34
38
|
| --- | --- |
|
|
35
|
-
| `--list` | print
|
|
39
|
+
| `--list` | print mutants, per-file counts, the total and the not-mutated count, then exit |
|
|
40
|
+
| `--exported-only` | only exported binding paths, curried returns and Layer service methods; exclude local helpers |
|
|
36
41
|
| `--in-diff <file>` | only mutants on lines a unified diff adds or changes |
|
|
42
|
+
| `--in-diff-range <A...B or A..B>` | select from `git diff` run at the repository root; exclusive with `--in-diff` |
|
|
43
|
+
| `--max-mutants <n>` | keep the first n selected mutants in repository path, line, column, id order |
|
|
44
|
+
| `--format <text or json or github>` | text by default; JSON for `--list`; Markdown for GitHub |
|
|
45
|
+
| `--summary-md <file>` | write the Markdown summary to a file |
|
|
46
|
+
| `--summary-marker <text>` | override the first-line `<!-- mutant.cafe -->` marker |
|
|
47
|
+
| `--advisory` | exit 0 for outcomes and baseline failure; usage and internal errors still fail |
|
|
37
48
|
| `--file <glob>`, `--exclude <glob>` | choose source files (repeatable) |
|
|
38
49
|
| `--jobs <n>` | scratch copies tested in parallel |
|
|
39
50
|
| `--timeout <s>` | per-mutant test timeout; default 5× the baseline run, at least 20 s |
|
|
@@ -41,11 +52,89 @@ Run it from the package whose tests you want to check. In a monorepo that resolv
|
|
|
41
52
|
| `--output <dir>` | results directory, default `mutants.out` |
|
|
42
53
|
| `--tsconfig <path>` | default `tsconfig.json` |
|
|
43
54
|
|
|
44
|
-
|
|
55
|
+
## CI
|
|
56
|
+
|
|
57
|
+
Use a git range to check changed bodies and a mutant budget to cap the work. The budget applies after file, diff and function selection. Ordering uses repository-relative file path (lexical, not locale-dependent), start line, column, then id. `--max-mutants 0` keeps none. Budget-skipped mutants are not outcomes.
|
|
58
|
+
|
|
59
|
+
This advisory GitHub Actions job writes a step summary and updates one sticky PR comment. Install mutant-cafe as a dev dependency first. Replace `npm ci` with your package manager's install command if needed; run the mutation command from the package you want to test.
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
name: Mutation advisory
|
|
63
|
+
on: pull_request
|
|
64
|
+
permissions:
|
|
65
|
+
contents: read
|
|
66
|
+
pull-requests: write
|
|
67
|
+
jobs:
|
|
68
|
+
mutants:
|
|
69
|
+
runs-on: ubuntu-latest
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/checkout@v4
|
|
72
|
+
with:
|
|
73
|
+
fetch-depth: 0
|
|
74
|
+
- uses: actions/setup-node@v4
|
|
75
|
+
with:
|
|
76
|
+
node-version: 24
|
|
77
|
+
- run: npm ci
|
|
78
|
+
- name: Check changed bodies
|
|
79
|
+
run: >-
|
|
80
|
+
npx --no-install mutant-cafe
|
|
81
|
+
--in-diff-range "origin/${{ github.base_ref }}...HEAD"
|
|
82
|
+
--max-mutants 40 --format github --advisory
|
|
83
|
+
--summary-md mutant-summary.md
|
|
84
|
+
- name: Update sticky comment
|
|
85
|
+
if: github.event.pull_request.head.repo.full_name == github.repository
|
|
86
|
+
uses: actions/github-script@v7
|
|
87
|
+
with:
|
|
88
|
+
script: |
|
|
89
|
+
const fs = require('node:fs');
|
|
90
|
+
const body = fs.readFileSync('mutant-summary.md', 'utf8');
|
|
91
|
+
const marker = '<!-- mutant.cafe -->';
|
|
92
|
+
const { owner, repo } = context.repo;
|
|
93
|
+
const issue_number = context.issue.number;
|
|
94
|
+
const comments = await github.paginate(github.rest.issues.listComments, {
|
|
95
|
+
owner, repo, issue_number
|
|
96
|
+
});
|
|
97
|
+
const previous = comments.find(comment =>
|
|
98
|
+
comment.user.type === 'Bot' && comment.body?.startsWith(marker)
|
|
99
|
+
);
|
|
100
|
+
if (previous) {
|
|
101
|
+
await github.rest.issues.updateComment({
|
|
102
|
+
owner, repo, comment_id: previous.id, body
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
await github.rest.issues.createComment({ owner, repo, issue_number, body });
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Fork PRs still get the step summary; the example only posts comments on same-repository PRs. Do not switch this job to `pull_request_target` to grant untrusted PR code a write token. If a job or matrix tests multiple packages, give each summary a distinct `--summary-marker` and match that marker in the comment step.
|
|
110
|
+
|
|
111
|
+
`--format github` prints Markdown and writes the same content to `GITHUB_STEP_SUMMARY` when set. `--summary-md` also works with the default text output. The first line is `<!-- mutant.cafe -->` unless overridden. The summary counts all outcomes, lists up to 50 missed, timeout, untested and unreliable mutants with repository-root-relative paths, and says what would have failed without `--advisory`. Advisory mode does not hide bad arguments, bad refs, source errors or internal errors.
|
|
112
|
+
|
|
113
|
+
For automation without running tests, `--list --format json` prints one JSON document: `schemaVersion`, `tool`, `mutants` (the same `Mutant` shape used by report results), `notMutated`, and `counts` with `selected`, `run` and `budgetSkipped`. `selected` is the count before the budget; `run` is zero for a list and the number of recorded outcomes for an execution. The published `MutantList` and `RunReport` schemas are exported by `@mutant-cafe/core` in this workspace. Reports keep schema version 2: `selected`, `run` and `budgetSkipped` are additive optional fields, so older v2 reports still decode.
|
|
114
|
+
|
|
115
|
+
## Outputs
|
|
116
|
+
|
|
117
|
+
Mutant ids are stable within a version and may change between versions before 1.0. An import-adding mutant hashes its logical edit, not the retained file prefix, so edits above its binding do not change its id.
|
|
118
|
+
|
|
119
|
+
Results land in `mutants.out/`: `missed.txt`, `caught.txt`, `timeout.txt`, `unviable.txt`, `untested.txt`, `unreliable.txt`, `not-mutated.txt`, a context diff and a log per mutant, and `outcomes.json`. Every result line includes the mutant id used by `diff/<id>.diff` and `logs/<id>.log`. Lines show the declared return type when available, or an abbreviated inferred type; JSON keeps full types and uses report `schemaVersion: 2`. Add `mutants.out*` to `.gitignore`. Your source tree is never edited: each mutant runs in a scratch copy. Workspace dependency links back into the copied source tree, including package self-links, point at the scratch packages rather than the originals. Mutation imports are added when the file has no usable value import for an Effect API.
|
|
120
|
+
|
|
121
|
+
`not-mutated.txt` lists considered functions with no mutants and their reasons: unsupported return values or required fields, generic returns, and explicit exclusions. The summary includes that count. With `--in-diff`, only skips from files touched by the diff are reported. The baseline command prints before execution. A failed baseline still writes `outcomes.json`, including its command and output tail; TypeScript load errors print the tsconfig path and diagnostics.
|
|
45
122
|
|
|
46
123
|
An include glob that matches no source file is a usage error, including a path outside the package root. Diff paths resolve from the Git toplevel, with support for `git diff --relative`; outside Git they resolve from the working directory.
|
|
47
124
|
|
|
48
|
-
Exit
|
|
125
|
+
| Exit code | Meaning |
|
|
126
|
+
| --- | --- |
|
|
127
|
+
| 0 | no missed, unreliable, untested or timed-out mutants |
|
|
128
|
+
| 1 | usage, source or tsconfig error |
|
|
129
|
+
| 2 | some mutants were missed, or untested with no unreliable results |
|
|
130
|
+
| 3 | some timed out, with no missed, unreliable or untested results |
|
|
131
|
+
| 4 | baseline tests fail |
|
|
132
|
+
| 5 | the `--in-diff` diff does not match the tree |
|
|
133
|
+
| 6 | the diff cannot be parsed |
|
|
134
|
+
| 7 | some results are unreliable, with none missed |
|
|
135
|
+
| 70 | internal error |
|
|
136
|
+
|
|
137
|
+
Precedence is **missed (2), unreliable (7), untested (2), then timeout (3)**. A real miss wins over unreliable results; unreliable wins over an empty selection or timeout.
|
|
49
138
|
|
|
50
139
|
## Outcomes
|
|
51
140
|
|
|
@@ -55,9 +144,20 @@ Exit codes: 0 no missed, untested or timed-out mutants, 1 usage error, 2 some mu
|
|
|
55
144
|
| missed | the selected tests passed |
|
|
56
145
|
| unviable | the mutant does not type-check |
|
|
57
146
|
| timeout | the tests ran past the per-mutant budget without a reported failure or evidence of a caught `Effect.never` |
|
|
58
|
-
| untested |
|
|
147
|
+
| untested | related selection found no test files and the full-suite fallback did not fail |
|
|
148
|
+
| unreliable | an unsupported runner, an omitted importing test, or a selected test reading a built self-entry instead of the affected source |
|
|
149
|
+
|
|
150
|
+
Vitest first runs tests related to the mutated file. When that selects no test files, mutant.cafe reruns the package's full suite within the remaining budget. A failing fallback counts as caught, including dynamic-import consumers. A passing fallback is untested, not missed: unrelated passing tests do not prove they reached the mutant.
|
|
151
|
+
|
|
152
|
+
Before the baseline, mutant.cafe checks `package.json`'s test script and asks the installed Vitest for its resolved test files. It warns when another runner owns the test script or a test importing a target is omitted. Test support imported by selected tests is not an omitted suite. Affected viable mutants are unreliable and are not scored as missed; their diagnostics name the script or omitted test. Common wrappers (`pnpm exec vitest`, `npx vitest`, `cross-env … vitest`, chained commands and `vitest --project`) count as Vitest scripts. Delegated scripts such as `turbo run test` or `pnpm -r test` are unverified, not declared non-Vitest.
|
|
153
|
+
|
|
154
|
+
Only an explicit non-Vitest runner skips the baseline and makes all results unreliable. Delegated or unknown scripts and failed selection probes warn but do not disable the Vitest baseline.
|
|
155
|
+
|
|
156
|
+
Self-imports that resolve to built JavaScript are scoped: the export's `types` condition or explicit tsconfig `rootDir`/`outDir` maps the entry back to source and its import closure. A mutant in that closure is unreliable only if its actual selected tests include a test that imports the built entry. If mapping is unavailable, only that selected-test condition applies. Selection comes from the running Vitest reporter, including a full-suite fallback. Other mutants run normally; a built self-import never disables the baseline. Remapping a package link cannot rebuild its output.
|
|
157
|
+
|
|
158
|
+
This does not add `node:test` support. Literal relative imports are traced transitively; computed imports remain subject to the full-suite fallback.
|
|
59
159
|
|
|
60
|
-
|
|
160
|
+
Selection and partial failures come from Vitest's reporter hooks, not its human-readable messages. A reported failure still counts as caught if another test file hangs.
|
|
61
161
|
|
|
62
162
|
Ordinary mutants use the configured timeout. For `Effect.never`, mutant.cafe measures the unmutated related run once per file, including any full-suite fallback. Its budget is that duration × the timeout multiplier, with a 1 s floor. Slow tests that never call the function can finish normally; a process killed before test collection is not credited as caught. Each mutant run also sets Vitest's per-test timeout to half its budget, overriding a package's `testTimeout: 0`, and stops after the first reported failure.
|
|
63
163
|
|