mutant-cafe 0.1.3 → 0.1.5
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 +68 -2
- package/dist/bin.js +681 -257
- package/dist/bin.js.map +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ npx mutant-cafe --jobs 4 # test them
|
|
|
30
30
|
|
|
31
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
32
|
|
|
33
|
-
Value synthesis includes branded strings and numbers, empty sets and maps, anonymous objects with cycled literal fields, and
|
|
33
|
+
Value synthesis includes branded strings and numbers, empty sets and maps, anonymous objects with cycled literal fields, and every assignable parameter as an identity replacement, named by the parameter. Boolean and literal unions with up to eight members are exhaustive, excluding an obvious original constant. Swallow mutants enumerate recoveries only for genuinely finite success types with at most four members, including both booleans. Numbers, strings, structs, Json and larger finite sets use one representative per error tag. Larger or recursive shapes have at most six synthesized representatives per function and genre, plus `undefined` when present. For `Schema.Json`, these are `null`, `""`, `0`, `false`, `[]` and `{}`. Capped tagged unions keep the original body's discriminant first, with fields emptied, then other variants in declaration order. Synthesis stops beyond depth four or 2 KiB of printed value text and records the bound. Assignable-parameter identities are separate from the literal cap. Values differing only by `as const` or redundant parentheses generate one mutant. 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
34
|
|
|
35
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.
|
|
36
36
|
|
|
@@ -39,6 +39,12 @@ Run it from the package whose tests you want to check. In a monorepo that resolv
|
|
|
39
39
|
| `--list` | print mutants, per-file counts, the total and the not-mutated count, then exit |
|
|
40
40
|
| `--exported-only` | only exported binding paths, curried returns and Layer service methods; exclude local helpers |
|
|
41
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 |
|
|
42
48
|
| `--file <glob>`, `--exclude <glob>` | choose source files (repeatable) |
|
|
43
49
|
| `--jobs <n>` | scratch copies tested in parallel |
|
|
44
50
|
| `--timeout <s>` | per-mutant test timeout; default 5× the baseline run, at least 20 s |
|
|
@@ -46,13 +52,73 @@ Run it from the package whose tests you want to check. In a monorepo that resolv
|
|
|
46
52
|
| `--output <dir>` | results directory, default `mutants.out` |
|
|
47
53
|
| `--tsconfig <path>` | default `tsconfig.json` |
|
|
48
54
|
|
|
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
|
+
|
|
49
115
|
## Outputs
|
|
50
116
|
|
|
51
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.
|
|
52
118
|
|
|
53
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.
|
|
54
120
|
|
|
55
|
-
`not-mutated.txt`
|
|
121
|
+
`not-mutated.txt` gives one located line per considered function or Layer value with omitted mutations: `file:line:column`, target path and reason. Layer values use their initializer location; unavailable locations print `?:?`. It reports unsupported return fields, generic returns, explicit exclusions, capped values with an omitted count, and error classes whose constructors are unavailable. A constructor failure does not suppress recoveries or defects. Callbacks in arguments and arrays have their own locations; schema and brand constants are not functions. When a return cannot be synthesized but inner functions are mutated, the reason says so. The summary includes the line count. A target that the compiler cannot analyse gets a located `analysis failed` reason without aborting the remaining targets. Faults discovered during viability checks join the same skip report rather than becoming unviable outcomes. Config and program-load failures still stop the run. With `--in-diff`, only skips from files touched by the diff are reported. An empty selection, including a zero budget or a diff outside function bodies, skips the baseline, prints the selection count and cause to stderr, and writes a report with zero run and no baseline command. An empty actionable summary says “No actionable mutants.” The baseline command prints before execution when there are selected mutants. A failed baseline still writes `outcomes.json`, including its command and output tail; TypeScript load errors print the tsconfig path and diagnostics.
|
|
56
122
|
|
|
57
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.
|
|
58
124
|
|