probatio 0.1.2 → 0.2.0
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 +109 -17
- package/dist/cli.js +122 -55
- package/dist/contract.js +7 -5
- package/dist/ledger/build.js +14 -0
- package/dist/mcp.js +98 -26
- package/dist/mutate/child-lines.mjs +23 -18
- package/dist/mutate/coverage-map.js +75 -18
- package/dist/mutate/fail-reporter.mjs +21 -0
- package/dist/mutate/generate.js +25 -4
- package/dist/mutate/load-failure.mjs +40 -0
- package/dist/mutate/mocha-coverage.cjs +7 -1
- package/dist/mutate/node-batch-loader.mjs +15 -1
- package/dist/mutate/node-batch.mjs +40 -3
- package/dist/mutate/node-coverage.mjs +7 -32
- package/dist/mutate/patch.js +2 -1
- package/dist/mutate/precise-lines.mjs +147 -31
- package/dist/mutate/probatio-jacoco-run.java +2 -2
- package/dist/mutate/project-config.js +58 -0
- package/dist/mutate/run.js +192 -32
- package/dist/mutate/rust-coverage.js +4 -19
- package/dist/mutate/sealed.js +94 -1
- package/dist/mutate/suite-decision.js +2 -1
- package/dist/mutate/suites.js +136 -163
- package/dist/mutate/tally.js +85 -20
- package/dist/node-version.js +13 -0
- package/dist/swarm/check-kill.js +14 -7
- package/dist/swarm/queue.js +13 -7
- package/dist/verify/change.js +5 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,21 +1,76 @@
|
|
|
1
1
|
# Probatio
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
(Claude, Grok, ChatGPT, others), working alone or as swarms. Every claim it makes is checkable.
|
|
5
|
-
It remembers what was fixed so agents with small context do not redo or undo work, and it shows
|
|
6
|
-
which tests already touch a change.
|
|
3
|
+
[](https://www.npmjs.com/package/probatio)
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
Probatio scores a test suite by the bugs it already catches. A kill is an assertion the suite had. The kill count is not a merge gate.
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
Node 22.6 or newer:
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install probatio
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx probatio mutate generate --package . --out .probatio/generate
|
|
15
|
+
npx probatio mutate run --package . --patches .probatio/generate/mutants --out .probatio/runs
|
|
16
|
+
npx probatio mutate tally --out .probatio/runs
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Each command prints one JSON object and exits 0 only when `ok` is true.
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"schemaVersion": 1,
|
|
24
|
+
"ok": true,
|
|
25
|
+
"summary": "0 no coverage, 0 survived, 1 killed, 0 flaky, 0 timed out, 0 errored, of 1 finished.",
|
|
26
|
+
"next": "No survivor in this batch.",
|
|
27
|
+
"nextCall": null
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Agents changing this repo should read [AGENTS.md](AGENTS.md). The MCP server is `probatio mcp`. Snippets are in the MCP section below. People building Probatio should read [docs/builders.md](docs/builders.md). Small suites live in [examples/](examples/).
|
|
32
|
+
|
|
33
|
+
## Status
|
|
34
|
+
|
|
35
|
+
What a result means:
|
|
36
|
+
|
|
37
|
+
- **killed**: a test the suite already had failed an assertion on the mutant. It is not proof the change is safe, and the count is not a merge gate.
|
|
38
|
+
- **survived**: a test ran the line and did not notice. That is a gap. Add a test that fails on the mutant, then rerun.
|
|
39
|
+
- **no coverage**: no test executed that line, so the suite was not started. It is not a pass and not a gap.
|
|
40
|
+
- **did not build** (`unviable`): the compiler rejected the mutant, or on Node a test file no longer links (a removed export, a missing module, a file that does not parse). No test code ran, so it is not a kill and not a gap. Java, Rust, Go, and C# reject the same change at compile time, so every language gets the same verdict. For a ledger fix it means the reverted commit cannot be a regression check as it stands: write a hand-made mutant (`source=hand`) that keeps the API and puts the old behaviour back.
|
|
41
|
+
- **timed out**: the baseline clock ran out. It is not a kill.
|
|
42
|
+
- A red baseline, or a baseline with no test report, stops before the first mutant.
|
|
43
|
+
|
|
44
|
+
What runs today:
|
|
45
|
+
|
|
46
|
+
- Discovery finds the project's own suite: `run_tests.sh`, Cargo, Go, Swift, Maven, dotnet, pytest, unittest, node:test, Mocha, and `make test` for COBOL. An unknown layout asks for `--suite-command`.
|
|
47
|
+
- Node, pytest, Go, Maven/Java, Rust, C#, Mocha, and C with LLVM coverage collect a line map on the baseline. A mutant runs only the tests that hit its line.
|
|
48
|
+
- A Node child process started by a test is mapped under that test, with no import in the child and even when it ends with `process.exit`. A child started with a cleared environment cannot be seen and stays `no coverage`.
|
|
49
|
+
- A slow suite with no line map (baseline 5 seconds or more, more than 30 mutants pending) stops before the first mutant.
|
|
50
|
+
- A project that needs its own environment or test-line format says so in `.probatio.json` (below). Probatio does not patch a project's files or environment to make one repository pass.
|
|
51
|
+
|
|
52
|
+
Sealed runs. A sealed run hides the test that came with a fix, puts the bug back, and asks whether the rest of the suite notices. Seven subjects are recorded (2026-10-05 and 10-06):
|
|
16
53
|
|
|
17
|
-
|
|
18
|
-
|
|
54
|
+
| Subject | Result |
|
|
55
|
+
|---|---|
|
|
56
|
+
| QuixBugs, Python program | no coverage: the planted line was not executed |
|
|
57
|
+
| QuixBugs, Java program | survived |
|
|
58
|
+
| Commons CSV, one bug | survived |
|
|
59
|
+
| tqdm, one bug | survived |
|
|
60
|
+
| First one-command `mutate sealed` run | survived, both runs |
|
|
61
|
+
| Commons CSV `c15a06ee` (CSV-288) | the suite stayed green with the test hidden |
|
|
62
|
+
| Commons CSV `2c83a308` (CSV-271) | killed on 10-06 with no line map; survived on 10-08 with the map; see below |
|
|
63
|
+
|
|
64
|
+
The CSV-271 kill came from `CSVFormatTest.testFormatThrowsNullPointerException`. The fix commit itself edited that test: it changed the asserted stack-frame class from `CSVFormat` to `java.util.Objects`. With the test as it was before the fix, all 92 `CSVFormatTest` tests pass on the reverted code, and no other test fails because of the bug. So no older test caught it. The honest record is that these suites did not notice a hidden real bug, which is what a sealed run is for. A kill that pins an internal detail, such as which class threw, is not the same as a test that checks behaviour.
|
|
65
|
+
|
|
66
|
+
Known limits:
|
|
67
|
+
|
|
68
|
+
- The sealed list (`seal`) is a plain id list in the state dir. An agent that can read that directory can see it. Keep the state dir and every `mutate sealed` label file outside the workspace of the agents being scored.
|
|
69
|
+
- `mutate sealed` checks whether the fix commit edited the killing test (`fixEdited`, `olderTestCatch`). It matches a kill to a file by path, class name, or a test name written in that file. A test renamed by the fix can slip past that match.
|
|
70
|
+
- The Java line map comes from JaCoCo, which does not count a line as executed when a call on that line throws. A test that reaches a line only through an exception is not selected for it, so a mutant there can survive a test that would fail. On Commons CSV-271 the map leaves out `testFormatThrowsNullPointerException` at `CSVPrinter.java:284`, and the sealed run reports survived.
|
|
71
|
+
- The operator set is small: condition swaps, relational swaps, booleans, a dropped `!`. No arithmetic, statement deletion, or constants.
|
|
72
|
+
|
|
73
|
+
The package version in this repository is in `package.json`. The npm badge above is the published version.
|
|
19
74
|
|
|
20
75
|
## mutate
|
|
21
76
|
|
|
@@ -31,11 +86,29 @@ npx probatio mutate tally --out .probatio/runs
|
|
|
31
86
|
|
|
32
87
|
`run` discovers the suite: `run_tests.sh`, Cargo, Go, Swift, Maven, dotnet, pytest, unittest, node:test, Mocha, then `make test` when COBOL tests sit under that Makefile. An unknown layout stops and asks for `--suite-command`. It does not compile one file and call that the suite. `make test` that would curl or wget a missing file stops, and nothing is fetched. A worktree that has no `node_modules` uses the main checkout's. Omitting `--build` runs no build. Pass `--build` with a command when the suite needs one first.
|
|
33
88
|
|
|
34
|
-
|
|
89
|
+
Discovery reads the package root. An example project inside it, such as a directory with its own `go.mod` or `pytest.ini`, is a different project and is not collected. Go needs a `go.mod` at or above the package.
|
|
90
|
+
|
|
91
|
+
Node, pytest, Go, Maven/Java, Rust, C#, and Mocha collect a line map on the baseline. C collects one when LLVM coverage was instrumented. Mocha writes its own `{ files }` record from root hooks, keyed by the Mocha title. The node:test collector is a different file and does not name Mocha tests. The map stores the file, the line, and the test names that hit that line. A later mutant runs only those tests (`go test -run`, Maven `-Dtest`, `cargo test`, `dotnet test --filter`, Mocha `--grep`). A line no test executed is `no coverage`, and the suite is not started. A Node child process started by a mapped test loads a small collector through `NODE_OPTIONS`. It writes the lines it ran when it exits, including after `process.exit`, and the parent test stores them under its own name. Each test process has its own dump directory, so parallel test files do not take each other's children. A child started with a cleared environment stays `no coverage`. On Node, a test filter that matches nothing is an error, not a survivor, and only the requested tests can be credited with a kill. A test file that fails before any test runs is one of two things. If it does not link or parse (a removed export, a missing module), no code ran, and the mutant is `unviable` unless some other test failed. If its own top-level code ran the mutated program and threw, that is a kill by that file, and confirm reruns the whole file. Covered mutants of one Node file are applied one after another in the suite process already running, and the line map is reset between them. `--workers` stays 1. A crash or a process left dirty ends that process. The next mutant starts clean. A baseline of 5 seconds or more, with no line map and more than 30 mutants still pending, stops before the first mutant. `next` names that baseline and tells you to narrow `--src` or pass a smaller patch directory. A one-file C, C++, Java, COBOL, or assembly launcher is not a suite discovery returns.
|
|
35
92
|
|
|
36
|
-
The mutant timeout is the baseline duration times 5, and at least 20 seconds, capped by `--suite-timeout-ms`. A timeout is not a kill. `--budget-ms` stops mutant work after the baseline. The first mutant still runs, except for that no-line-map stop. A kill is the test that failed
|
|
93
|
+
The mutant timeout is the baseline duration times 5, and at least 20 seconds, capped by `--suite-timeout-ms`. A timeout is not a kill. `--budget-ms` stops mutant work after the baseline. The first mutant still runs, except for that no-line-map stop. A kill is the test that failed. A mutant the compiler rejects is `unviable`: the summary says `N did not build`, `unviable` and `unviableIds` list them, and they are neither kills nor gaps. Confirm is on by default and reruns the failing names. Pytest names that `-k` cannot express are passed as node ids. A usage error, including pytest exit 4, is not a kill. `verify-change` does not confirm a second time. Add `--affected` to limit the file list to tests that can see the change. The default, once a line map exists, runs the tests on the changed line.
|
|
37
94
|
|
|
38
|
-
`tally` reads that run directory. The summary leads with the no-coverage count, then the survivors.
|
|
95
|
+
`tally` reads that run directory. The summary leads with the no-coverage count, then the survivors. `keep` names each test that killed a mutant, once, as an id `--only-test` can run. `noKillsYet` names tests that saw no mutant die in this batch. That is not a reason to delete them: one batch is not evidence, and the Auspex experiment caught 10 of 18 sealed bugs after pruning by kill evidence. `pruning.advice` stays empty and `deletedTests` is 0. A gap is a survivor. An unseen line is not a gap and not a pass. A timeout is neither a kill nor a gap.
|
|
96
|
+
|
|
97
|
+
`nextCall` writes to a fresh out dir next to the old one, because the old out dir would skip every finished mutant and repeat the old result. With a gap, it reruns the batch on `HEAD` (`<out>.after-gaps`) once the new test is committed. With no gap, it rescores the keep ids at the same commit with `--only-test` (`<out>.rescore`).
|
|
98
|
+
|
|
99
|
+
## .probatio.json
|
|
100
|
+
|
|
101
|
+
A project can say how its suite runs. The file sits at the package root and is read even when it is not committed.
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"env": { "ARCH_NATIVE": "1" },
|
|
106
|
+
"testLine": "^(Testing .+|Running .+)$",
|
|
107
|
+
"passLine": "All done, tests as expected"
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`env` is added to the suite's environment, for a flag the project's own CI sets. `testLine` names the tests of a `run_tests.sh` suite: each matching line is a test, and the first capture group is the name when there is one. When the suite exits non-zero, the last test line is the one that failed, unless `passLine` was printed. Without `testLine`, a shell suite that prints TAP (`ok 1 - name`, `not ok 2 - name`) is read as TAP. Otherwise it is one command: exit 0 passes, and a failure is `::command`, not an invented test name. An invalid file stops the run and names the field.
|
|
39
112
|
|
|
40
113
|
## ledger
|
|
41
114
|
|
|
@@ -43,7 +116,7 @@ The mutant timeout is the baseline duration times 5, and at least 20 seconds, ca
|
|
|
43
116
|
npx probatio ledger build --package . --commit HEAD --out .probatio/ledger
|
|
44
117
|
```
|
|
45
118
|
|
|
46
|
-
A fix commit has a `Fixes-bug:` trailer, or it changes both `src` and a test. `ledger build` reverts that commit's src diff onto the tree you name. A diff that applies is written as a forward patch (`source=history`): apply it to put the bug back. A diff that does not apply is reported, and left for a hand-made patch in the same directory (`source=hand`, `fix=<commit>`). A rebuild keeps those hand-made files. Nothing is fuzzy-applied. A src diff over `--max-lines` (default 300) is skipped. `--max-commits N` reads only the newest N non-merge commits and says when older history was not scanned. The default reads the whole history. A tree is checked out only when a fix inside that cap has to be applied.
|
|
119
|
+
A fix commit has a `Fixes-bug:` trailer, or it changes both `src` and a test. A commit that changes the version in `package.json`, `Cargo.toml`, `pyproject.toml`, or `setup.cfg` is a release, and it is not a fix unless it has the trailer: reverting it would put back several changes, not one bug. `ledger build` reverts that commit's src diff onto the tree you name. A diff that applies is written as a forward patch (`source=history`): apply it to put the bug back. A diff that does not apply is reported, and left for a hand-made patch in the same directory (`source=hand`, `fix=<commit>`). A rebuild keeps those hand-made files. Nothing is fuzzy-applied. A src diff over `--max-lines` (default 300) is skipped. `--max-commits N` reads only the newest N non-merge commits and says when older history was not scanned. The default reads the whole history. A tree is checked out only when a fix inside that cap has to be applied.
|
|
47
120
|
|
|
48
121
|
## matrix
|
|
49
122
|
|
|
@@ -81,4 +154,23 @@ Lists the tests that can see the diff, runs mutants on the changed lines, and re
|
|
|
81
154
|
|
|
82
155
|
An item is `.probatio/queue/<id>.json`. `queue claim` renames it to `claimed/<agent>-<id>.json` with a lease. `queue reap` moves an expired lease back. `check-kill <id>` runs the tests that directly import the mutated file and confirms the killing test again. It is done only when that mutant dies and that suite is still green. `verify-change` is the edit-sized run: it uses the line map and does not confirm a second time.
|
|
83
156
|
|
|
84
|
-
|
|
157
|
+
## MCP
|
|
158
|
+
|
|
159
|
+
`probatio mcp` and the `probatio-mcp` bin speak stdio JSON-RPC, one JSON object per line. The tool name is `probatio`. `argv` is the CLI words. `ping` returns `{}`. An unknown method returns JSON-RPC `-32601` with the same id. A tool call runs in the background, so `ping` and other calls are answered while a long `mutate run` works. `notifications/cancelled` with that call's `requestId` stops the command and its suite, removes its worktrees, and sends no reply. The server answers with the client's `protocolVersion` when it is `2024-11-05`, `2025-03-26`, or `2025-06-18`.
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"mcpServers": {
|
|
164
|
+
"probatio": {
|
|
165
|
+
"command": "probatio",
|
|
166
|
+
"args": ["mcp"]
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
That block is the Claude, Cursor, and Grok shape. The tool runs the CLI and returns that command's JSON. `nextCall.argv` keeps absolute paths so a later spawn does not have to expand `~`.
|
|
173
|
+
|
|
174
|
+
`mutate generate` reads the commit (`HEAD` unless you pass `--commit`). `--working-tree` reads the checkout on disk and says so. `mutate run` scores the commit either way.
|
|
175
|
+
|
|
176
|
+
`verify-change` does not score uncommitted edits when `--base` and `--commit` are the same. A clean empty diff says `No diff-scoped mutant.`
|
package/dist/cli.js
CHANGED
|
@@ -10,65 +10,82 @@ import { appendFinding, chooseSealed, fixGap, guardAllows, lineHash, loadState,
|
|
|
10
10
|
import { git } from "./mutate/patch.js";
|
|
11
11
|
import { generateMutants } from "./mutate/generate.js";
|
|
12
12
|
import { runMutants } from "./mutate/run.js";
|
|
13
|
-
import { LABEL_LEAK_SUMMARY, labelLeaked, readSealedLabel } from "./mutate/sealed.js";
|
|
13
|
+
import { fixEditedKillers, LABEL_LEAK_SUMMARY, labelLeaked, readSealedLabel, sealedTreeLeaked } from "./mutate/sealed.js";
|
|
14
14
|
import { generateNext } from "./mutate/suite-decision.js";
|
|
15
15
|
import { discoverSuite } from "./mutate/suites.js";
|
|
16
16
|
import { tallyRun } from "./mutate/tally.js";
|
|
17
17
|
import { checkKill } from "./swarm/check-kill.js";
|
|
18
18
|
import { claimItem, reapClaims, seedQueue } from "./swarm/queue.js";
|
|
19
19
|
import { verifyChange } from "./verify/change.js";
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
finish(await generateCommand(parsed.flags), parsed.human);
|
|
25
|
-
if (group === "mutate" && action === "run")
|
|
26
|
-
finish(await runCommand(parsed.flags), parsed.human);
|
|
27
|
-
if (group === "mutate" && action === "sealed")
|
|
28
|
-
finish(await sealedCommand(parsed.flags), parsed.human);
|
|
29
|
-
if (group === "mutate" && action === "tally")
|
|
30
|
-
finish(tallyCommand(parsed.flags), parsed.human);
|
|
31
|
-
if (group === "ledger" && action === "build")
|
|
32
|
-
finish(await ledgerCommand(parsed.flags), parsed.human);
|
|
33
|
-
if (group === "matrix" && action === "report")
|
|
34
|
-
finish(matrixCommand(parsed.flags), parsed.human);
|
|
35
|
-
if (group === "golden" && action === "check")
|
|
36
|
-
finish(goldenCommand(parsed.flags), parsed.human);
|
|
37
|
-
if (group === "gap" && action === "fix")
|
|
38
|
-
finish(gapFixCommand(parsed.flags), parsed.human);
|
|
39
|
-
if (group === "gap" && action === "revert")
|
|
40
|
-
finish(gapRevertCommand(parsed.flags), parsed.human);
|
|
41
|
-
if (group === "guard" && action === "check")
|
|
42
|
-
finish(guardCommand(parsed.flags), parsed.human);
|
|
43
|
-
if (group === "findings" && action === "add")
|
|
44
|
-
finish(findingsCommand(parsed.flags), parsed.human);
|
|
45
|
-
if (group === "status")
|
|
46
|
-
finish(statusCommand(parsed.flags), parsed.human);
|
|
47
|
-
if (group === "seal")
|
|
48
|
-
finish(sealCommand(parsed.flags), parsed.human);
|
|
49
|
-
if (group === "queue" && action === "seed")
|
|
50
|
-
finish(queueSeedCommand(parsed.flags), parsed.human);
|
|
51
|
-
if (group === "queue" && action === "claim")
|
|
52
|
-
finish(queueClaimCommand(parsed.flags), parsed.human);
|
|
53
|
-
if (group === "queue" && action === "reap")
|
|
54
|
-
finish(queueReapCommand(parsed.flags), parsed.human);
|
|
55
|
-
if (group === "check-kill")
|
|
56
|
-
finish(await checkKillCommand(parsed.flags, action), parsed.human);
|
|
57
|
-
if (group === "verify-change")
|
|
58
|
-
finish(await verifyCommand(parsed.flags), parsed.human);
|
|
59
|
-
finish(usage(false, "Use mutate, ledger, matrix, golden, gap, guard, findings, status, queue, check-kill, or verify-change."), parsed.human);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
63
|
-
finish({
|
|
20
|
+
import { nodeTooOld } from "./node-version.js";
|
|
21
|
+
const tooOld = nodeTooOld(process.versions.node);
|
|
22
|
+
if (tooOld) {
|
|
23
|
+
process.stdout.write(`${JSON.stringify({
|
|
64
24
|
schemaVersion: SCHEMA_VERSION,
|
|
65
25
|
ok: false,
|
|
66
|
-
command:
|
|
67
|
-
summary:
|
|
68
|
-
next: "
|
|
26
|
+
command: "mutate.help",
|
|
27
|
+
summary: tooOld,
|
|
28
|
+
next: "Install Node 22.6 or newer and run the command again.",
|
|
69
29
|
nextCall: null,
|
|
70
|
-
}
|
|
30
|
+
})}\n`);
|
|
31
|
+
process.exit(1);
|
|
71
32
|
}
|
|
33
|
+
const parsed = parseArgs(process.argv.slice(2));
|
|
34
|
+
const [group, action] = parsed.command;
|
|
35
|
+
if (group === "mcp" && !action) {
|
|
36
|
+
await import("./mcp.js");
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
try {
|
|
40
|
+
if (group === "mutate" && action === "generate")
|
|
41
|
+
finish(await generateCommand(parsed.flags), parsed.human);
|
|
42
|
+
if (group === "mutate" && action === "run")
|
|
43
|
+
finish(await runCommand(parsed.flags), parsed.human);
|
|
44
|
+
if (group === "mutate" && action === "sealed")
|
|
45
|
+
finish(await sealedCommand(parsed.flags), parsed.human);
|
|
46
|
+
if (group === "mutate" && action === "tally")
|
|
47
|
+
finish(tallyCommand(parsed.flags), parsed.human);
|
|
48
|
+
if (group === "ledger" && action === "build")
|
|
49
|
+
finish(await ledgerCommand(parsed.flags), parsed.human);
|
|
50
|
+
if (group === "matrix" && action === "report")
|
|
51
|
+
finish(matrixCommand(parsed.flags), parsed.human);
|
|
52
|
+
if (group === "golden" && action === "check")
|
|
53
|
+
finish(goldenCommand(parsed.flags), parsed.human);
|
|
54
|
+
if (group === "gap" && action === "fix")
|
|
55
|
+
finish(gapFixCommand(parsed.flags), parsed.human);
|
|
56
|
+
if (group === "gap" && action === "revert")
|
|
57
|
+
finish(gapRevertCommand(parsed.flags), parsed.human);
|
|
58
|
+
if (group === "guard" && action === "check")
|
|
59
|
+
finish(guardCommand(parsed.flags), parsed.human);
|
|
60
|
+
if (group === "findings" && action === "add")
|
|
61
|
+
finish(findingsCommand(parsed.flags), parsed.human);
|
|
62
|
+
if (group === "status")
|
|
63
|
+
finish(statusCommand(parsed.flags), parsed.human);
|
|
64
|
+
if (group === "seal")
|
|
65
|
+
finish(sealCommand(parsed.flags), parsed.human);
|
|
66
|
+
if (group === "queue" && action === "seed")
|
|
67
|
+
finish(queueSeedCommand(parsed.flags), parsed.human);
|
|
68
|
+
if (group === "queue" && action === "claim")
|
|
69
|
+
finish(queueClaimCommand(parsed.flags), parsed.human);
|
|
70
|
+
if (group === "queue" && action === "reap")
|
|
71
|
+
finish(queueReapCommand(parsed.flags), parsed.human);
|
|
72
|
+
if (group === "check-kill")
|
|
73
|
+
finish(await checkKillCommand(parsed.flags, action), parsed.human);
|
|
74
|
+
if (group === "verify-change")
|
|
75
|
+
finish(await verifyCommand(parsed.flags), parsed.human);
|
|
76
|
+
finish(usage(false, "Use mutate, ledger, matrix, golden, gap, guard, findings, status, queue, check-kill, or verify-change."), parsed.human);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
80
|
+
finish({
|
|
81
|
+
schemaVersion: SCHEMA_VERSION,
|
|
82
|
+
ok: false,
|
|
83
|
+
command: `${group ?? "mutate"}.${action ?? "help"}`,
|
|
84
|
+
summary: message,
|
|
85
|
+
next: "Fix the command and run it again.",
|
|
86
|
+
nextCall: null,
|
|
87
|
+
}, parsed.human);
|
|
88
|
+
}
|
|
72
89
|
function usage(ok, summary) {
|
|
73
90
|
return {
|
|
74
91
|
schemaVersion: SCHEMA_VERSION,
|
|
@@ -93,7 +110,19 @@ async function generateCommand(flags) {
|
|
|
93
110
|
maxMutants: int(flags, "max-mutants") ?? null,
|
|
94
111
|
maxMinutes: int(flags, "max-minutes") ?? null,
|
|
95
112
|
skipFiles: texts(flags, "skip-file"),
|
|
113
|
+
commit: text(flags, "commit") ?? "HEAD",
|
|
114
|
+
workingTree: bool(flags, "working-tree", false),
|
|
96
115
|
});
|
|
116
|
+
if (result.error) {
|
|
117
|
+
return {
|
|
118
|
+
schemaVersion: SCHEMA_VERSION,
|
|
119
|
+
ok: false,
|
|
120
|
+
command: "mutate.generate",
|
|
121
|
+
summary: result.error,
|
|
122
|
+
next: "Commit the file, or pass --working-tree to mutate the checkout on disk. mutate run scores the commit.",
|
|
123
|
+
nextCall: null,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
97
126
|
if (result.violations.length > 0) {
|
|
98
127
|
const first = result.violations[0];
|
|
99
128
|
return {
|
|
@@ -117,9 +146,14 @@ async function generateCommand(flags) {
|
|
|
117
146
|
summary: stopped
|
|
118
147
|
? `Stopped by the time budget after ${result.filesVisited} files. ${result.mutants.length} mutants written.`
|
|
119
148
|
: `${result.mutants.length} mutants in ${result.filesVisited} files. No string-literal mutant.`,
|
|
120
|
-
next:
|
|
121
|
-
|
|
122
|
-
|
|
149
|
+
next: [
|
|
150
|
+
stopped
|
|
151
|
+
? "Narrow --src or raise --max-minutes, then run the same command."
|
|
152
|
+
: generateNext(result.mutants.length, suite ? { kind: suite.kind, command: suite.command } : null),
|
|
153
|
+
result.source === "working-tree"
|
|
154
|
+
? "These patches match the working tree. mutate run scores the commit, so commit the files before mutate run."
|
|
155
|
+
: "",
|
|
156
|
+
].filter((line) => line.length > 0).join(" "),
|
|
123
157
|
nextCall: result.mutants.length === 0
|
|
124
158
|
? null
|
|
125
159
|
: { argv: ["mutate", "run", "--package", packageDir, "--patches", patches, "--out", path.join(outDir, "runs")] },
|
|
@@ -133,6 +167,19 @@ async function generateCommand(flags) {
|
|
|
133
167
|
};
|
|
134
168
|
}
|
|
135
169
|
async function runCommand(flags, hide = null) {
|
|
170
|
+
const hidden = hide ?? texts(flags, "hide");
|
|
171
|
+
const escaped = hidden.find((rel) => rel.split(/[\\/]/).includes(".."));
|
|
172
|
+
if (escaped) {
|
|
173
|
+
return {
|
|
174
|
+
schemaVersion: SCHEMA_VERSION,
|
|
175
|
+
ok: false,
|
|
176
|
+
command: "mutate.run",
|
|
177
|
+
summary: `--hide stays inside the package. Refused ${escaped}.`,
|
|
178
|
+
next: "Pass a relative path with no .. segment.",
|
|
179
|
+
nextCall: null,
|
|
180
|
+
killed: 0,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
136
183
|
const onlyNames = texts(flags, "only-test");
|
|
137
184
|
if (onlyNames.some((id) => id === "::command" || id.endsWith("::command"))) {
|
|
138
185
|
return {
|
|
@@ -209,6 +256,8 @@ async function runCommand(flags, hide = null) {
|
|
|
209
256
|
next: report.next,
|
|
210
257
|
nextCall: report.ok ? resume : null,
|
|
211
258
|
killed: report.killed,
|
|
259
|
+
unviable: report.unviable,
|
|
260
|
+
unviableIds: report.unviableIds,
|
|
212
261
|
survived: report.survived,
|
|
213
262
|
flaky: report.flaky,
|
|
214
263
|
timeouts: report.timeouts,
|
|
@@ -234,10 +283,28 @@ function tallyCommand(flags) {
|
|
|
234
283
|
async function sealedCommand(flags) {
|
|
235
284
|
const label = readSealedLabel(path.resolve(requireText(flags, "label")));
|
|
236
285
|
const hide = texts(flags, "hide");
|
|
286
|
+
const outDir = path.resolve(requireText(flags, "out"));
|
|
237
287
|
const report = await runCommand(flags, hide);
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
288
|
+
const packageDir = path.resolve(requireText(flags, "package"));
|
|
289
|
+
const repoDir = path.resolve(text(flags, "repo") ?? gitRoot(packageDir));
|
|
290
|
+
const kills = Array.isArray(report.kills) ? report.kills : [];
|
|
291
|
+
const commit = typeof report.commit === "string" ? report.commit : "";
|
|
292
|
+
const edited = report.ok && commit ? fixEditedKillers(repoDir, packageDir, commit, hide, kills) : { files: [], olderTestCatch: false };
|
|
293
|
+
const fromFix = kills.length > 0 && !edited.olderTestCatch;
|
|
294
|
+
const judged = {
|
|
295
|
+
...report,
|
|
296
|
+
...(fromFix
|
|
297
|
+
? {
|
|
298
|
+
summary: `${report.summary} Every kill came from a test edited by the fix commit (${edited.files.join(", ")}). That is the fix's own test, so no older test caught the bug.`,
|
|
299
|
+
next: "Record this as a miss. Do not restore the hidden test.",
|
|
300
|
+
}
|
|
301
|
+
: {}),
|
|
302
|
+
fixEdited: edited.files,
|
|
303
|
+
olderTestCatch: edited.olderTestCatch,
|
|
304
|
+
};
|
|
305
|
+
const body = JSON.stringify(judged);
|
|
306
|
+
if (!labelLeaked(body, label) && !sealedTreeLeaked(outDir, label))
|
|
307
|
+
return judged;
|
|
241
308
|
return {
|
|
242
309
|
schemaVersion: SCHEMA_VERSION,
|
|
243
310
|
ok: false,
|
package/dist/contract.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
export const SCHEMA_VERSION = 1;
|
|
3
3
|
/** Replace the home directory so a result never carries a user's name or home path. */
|
|
4
|
-
export function scrub(value, home = homedir()) {
|
|
4
|
+
export function scrub(value, home = homedir(), keepPaths = false) {
|
|
5
5
|
if (typeof value === "string") {
|
|
6
|
-
if (!home || !value.includes(home))
|
|
6
|
+
if (keepPaths || !home || !value.includes(home))
|
|
7
7
|
return value;
|
|
8
8
|
return value.split(home).join("~");
|
|
9
9
|
}
|
|
10
10
|
if (Array.isArray(value))
|
|
11
|
-
return value.map((item) => scrub(item, home));
|
|
11
|
+
return value.map((item) => scrub(item, home, keepPaths));
|
|
12
12
|
if (value && typeof value === "object") {
|
|
13
13
|
const out = {};
|
|
14
|
-
for (const [key, item] of Object.entries(value))
|
|
15
|
-
|
|
14
|
+
for (const [key, item] of Object.entries(value)) {
|
|
15
|
+
// nextCall.argv is executed. A tilde is not expanded by spawn or by MCP.
|
|
16
|
+
out[key] = scrub(item, home, keepPaths || key === "nextCall");
|
|
17
|
+
}
|
|
16
18
|
return out;
|
|
17
19
|
}
|
|
18
20
|
return value;
|
package/dist/ledger/build.js
CHANGED
|
@@ -106,6 +106,9 @@ function collect(repo, commit, srcPrefix, testsPrefix, maxCommits) {
|
|
|
106
106
|
continue;
|
|
107
107
|
if (!hasTrailer && lines === 0)
|
|
108
108
|
continue;
|
|
109
|
+
// A version bump ships whatever was finished. Reverting it puts back several changes, not one bug.
|
|
110
|
+
if (!hasTrailer && bumpsVersion(repo, sha))
|
|
111
|
+
continue;
|
|
109
112
|
found.push({
|
|
110
113
|
commit: sha,
|
|
111
114
|
date: date ?? "",
|
|
@@ -116,6 +119,17 @@ function collect(repo, commit, srcPrefix, testsPrefix, maxCommits) {
|
|
|
116
119
|
}
|
|
117
120
|
return { found, scanned: limited.length, budgetHit };
|
|
118
121
|
}
|
|
122
|
+
const MANIFESTS = ["package.json", "Cargo.toml", "pyproject.toml", "setup.cfg"].map((name) => `:(glob)**/${name}`);
|
|
123
|
+
/** True when the commit changes a project version line in a manifest. */
|
|
124
|
+
function bumpsVersion(repo, sha) {
|
|
125
|
+
const diff = git(repo, ["show", "--format=", "-U0", sha, "--", ...MANIFESTS]);
|
|
126
|
+
if (diff.status !== 0)
|
|
127
|
+
return false;
|
|
128
|
+
return diff.stdout
|
|
129
|
+
.split("\n")
|
|
130
|
+
.filter((line) => /^[-+]/.test(line) && !line.startsWith("+++") && !line.startsWith("---"))
|
|
131
|
+
.some((line) => /"version"\s*:/.test(line) || /^[-+]\s*version\s*=/.test(line));
|
|
132
|
+
}
|
|
119
133
|
function entry(candidate, id, status, files, reason) {
|
|
120
134
|
return {
|
|
121
135
|
id,
|
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { nodeTooOld } from "./node-version.js";
|
|
7
|
+
const tooOld = nodeTooOld(process.versions.node);
|
|
8
|
+
if (tooOld) {
|
|
9
|
+
process.stdout.write(`${JSON.stringify({
|
|
10
|
+
schemaVersion: 1,
|
|
11
|
+
ok: false,
|
|
12
|
+
command: "mcp",
|
|
13
|
+
summary: tooOld,
|
|
14
|
+
next: "Install Node 22.6 or newer and run the command again.",
|
|
15
|
+
nextCall: null,
|
|
16
|
+
})}\n`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
/** Protocol versions this server speaks. The client's choice wins when it is one of these. */
|
|
20
|
+
const PROTOCOLS = ["2024-11-05", "2025-03-26", "2025-06-18"];
|
|
6
21
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
7
22
|
const version = readVersion();
|
|
8
23
|
const tool = {
|
|
@@ -15,6 +30,9 @@ const tool = {
|
|
|
15
30
|
},
|
|
16
31
|
};
|
|
17
32
|
let buffer = "";
|
|
33
|
+
let closing = false;
|
|
34
|
+
/** Tool calls still running, by request id. A cancel kills the child and drops the reply. */
|
|
35
|
+
const running = new Map();
|
|
18
36
|
process.stdin.setEncoding("utf8");
|
|
19
37
|
process.stdin.on("data", (chunk) => {
|
|
20
38
|
buffer += chunk;
|
|
@@ -22,7 +40,10 @@ process.stdin.on("data", (chunk) => {
|
|
|
22
40
|
});
|
|
23
41
|
process.stdin.on("end", () => {
|
|
24
42
|
drain(true);
|
|
25
|
-
|
|
43
|
+
closing = true;
|
|
44
|
+
// A call already running still gets its reply before the server exits.
|
|
45
|
+
if (running.size === 0)
|
|
46
|
+
process.exit(0);
|
|
26
47
|
});
|
|
27
48
|
function drain(flush = false) {
|
|
28
49
|
const lines = buffer.split("\n");
|
|
@@ -44,6 +65,22 @@ function drain(flush = false) {
|
|
|
44
65
|
function handle(message) {
|
|
45
66
|
if (!message.method)
|
|
46
67
|
return;
|
|
68
|
+
if (message.method === "notifications/cancelled") {
|
|
69
|
+
const key = message.params?.requestId;
|
|
70
|
+
if (key === undefined)
|
|
71
|
+
return;
|
|
72
|
+
const child = running.get(String(key));
|
|
73
|
+
running.delete(String(key));
|
|
74
|
+
if (child?.pid) {
|
|
75
|
+
try {
|
|
76
|
+
process.kill(-child.pid, "SIGTERM");
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
child.kill("SIGTERM");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
47
84
|
if (message.id === undefined || message.id === null)
|
|
48
85
|
return;
|
|
49
86
|
if (message.method === "initialize") {
|
|
@@ -51,7 +88,7 @@ function handle(message) {
|
|
|
51
88
|
jsonrpc: "2.0",
|
|
52
89
|
id: message.id,
|
|
53
90
|
result: {
|
|
54
|
-
protocolVersion: "
|
|
91
|
+
protocolVersion: PROTOCOLS.includes(message.params?.protocolVersion ?? "") ? message.params?.protocolVersion : PROTOCOLS[0],
|
|
55
92
|
capabilities: { tools: {} },
|
|
56
93
|
serverInfo: { name: "probatio", version },
|
|
57
94
|
tools: [tool],
|
|
@@ -63,36 +100,71 @@ function handle(message) {
|
|
|
63
100
|
send({ jsonrpc: "2.0", id: message.id, result: { tools: [tool] } });
|
|
64
101
|
return;
|
|
65
102
|
}
|
|
103
|
+
if (message.method === "ping") {
|
|
104
|
+
send({ jsonrpc: "2.0", id: message.id, result: {} });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
66
107
|
if (message.method === "tools/call") {
|
|
67
108
|
const argv = message.params?.arguments?.argv;
|
|
68
109
|
if (!Array.isArray(argv) || argv.some((item) => typeof item !== "string")) {
|
|
69
110
|
send({ jsonrpc: "2.0", id: message.id, error: { code: -32602, message: "argv must be an array of strings" } });
|
|
70
111
|
return;
|
|
71
112
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
113
|
+
call(message.id, argv);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
send({
|
|
117
|
+
jsonrpc: "2.0",
|
|
118
|
+
id: message.id,
|
|
119
|
+
error: { code: -32601, message: `method not found: ${message.method}` },
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/** One CLI command per call. It runs beside other calls, so ping and cancel are answered meanwhile. */
|
|
123
|
+
function call(id, argv) {
|
|
124
|
+
const key = String(id);
|
|
125
|
+
const cli = cliCommand();
|
|
126
|
+
// Its own process group, so a cancel also stops the suite the command started.
|
|
127
|
+
const child = spawn(cli.bin, [...cli.args, ...argv], { stdio: ["ignore", "pipe", "ignore"], detached: true });
|
|
128
|
+
running.set(key, child);
|
|
129
|
+
let text = "";
|
|
130
|
+
child.stdout?.setEncoding("utf8");
|
|
131
|
+
child.stdout?.on("data", (chunk) => {
|
|
132
|
+
text += chunk;
|
|
133
|
+
});
|
|
134
|
+
const settle = (failure) => {
|
|
135
|
+
// A cancelled call is no longer in the map. Its reply is dropped.
|
|
136
|
+
const live = running.get(key) === child;
|
|
137
|
+
running.delete(key);
|
|
138
|
+
if (live)
|
|
139
|
+
reply(id, text, failure);
|
|
140
|
+
if (closing && running.size === 0)
|
|
141
|
+
process.exit(0);
|
|
142
|
+
};
|
|
143
|
+
child.on("error", (error) => settle(error.message));
|
|
144
|
+
child.on("close", () => settle(null));
|
|
145
|
+
}
|
|
146
|
+
function reply(id, text, failure) {
|
|
147
|
+
let envelope = null;
|
|
148
|
+
try {
|
|
149
|
+
envelope = JSON.parse(text);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
envelope = null;
|
|
153
|
+
}
|
|
154
|
+
if (!envelope || typeof envelope !== "object") {
|
|
155
|
+
const message = failure ? `the command did not start: ${failure}` : "the command did not return one JSON object";
|
|
156
|
+
send({ jsonrpc: "2.0", id, error: { code: -32000, message } });
|
|
157
|
+
return;
|
|
95
158
|
}
|
|
159
|
+
send({
|
|
160
|
+
jsonrpc: "2.0",
|
|
161
|
+
id,
|
|
162
|
+
result: {
|
|
163
|
+
content: [{ type: "text", text: text.trim() }],
|
|
164
|
+
structuredContent: envelope,
|
|
165
|
+
isError: envelope.ok !== true,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
96
168
|
}
|
|
97
169
|
function cliCommand() {
|
|
98
170
|
const compiled = path.join(here, "cli.js");
|