mutant-cafe 0.1.3 → 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 CHANGED
@@ -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,6 +52,66 @@ 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.