supercov 4.29.1 → 4.29.3
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/docs/cli.md +7 -2
- package/docs/mutation.md +26 -4
- package/package.json +9 -9
- package/runtime/javascript/playwrightStrong.mjs +141 -32
- package/runtime/javascript/playwrightStrongReporter.mjs +113 -61
- package/runtime/javascript/vitestStrong.mjs +59 -1
- package/runtime/javascript/vitestStrongReporter.mjs +54 -11
package/docs/cli.md
CHANGED
|
@@ -537,7 +537,8 @@ many in a line per runner (`12 mutant(s) not run: no strong driver for
|
|
|
537
537
|
phpunit`). See `docs/design/strong-mutation.md`,
|
|
538
538
|
`docs/design/python-mutants.md` and `docs/design/mutation-drivers.md`.
|
|
539
539
|
|
|
540
|
-
- `--shard k/n` runs one of n shares of the mutants,
|
|
540
|
+
- `--shard k/n` runs one of n shares of the mutants, of about the same cost
|
|
541
|
+
(the copies and tests each mutant runs), for parallel jobs; each
|
|
541
542
|
job's run holds its share's verdicts, `merge` keeps them all in the merged
|
|
542
543
|
run, and a later `supercov mutants` keeps each verdict nothing changed could
|
|
543
544
|
move from whichever earlier run holds it (see
|
|
@@ -553,7 +554,11 @@ phpunit`). See `docs/design/strong-mutation.md`,
|
|
|
553
554
|
- A second `mutants test` over the same run runs only what has no verdict yet.
|
|
554
555
|
The pass saves each verdict as it comes: one that stops early (a test worker
|
|
555
556
|
that never ended, Ctrl-C, a killed job) keeps what it decided, and the next
|
|
556
|
-
pass runs the rest. Ctrl-C stops every process the pass started
|
|
557
|
+
pass runs the rest. Ctrl-C or SIGTERM stops every process the pass started,
|
|
558
|
+
and the pass ends within seconds: 8 s after the signal at the latest.
|
|
559
|
+
- `--budget <seconds>` stops the pass once it is spent: it ends as a finished
|
|
560
|
+
pass, its verdicts saved, and says how many mutants it left for the next.
|
|
561
|
+
The cheapest mutants run first, by their tests' recorded times.
|
|
557
562
|
- After an edit, `supercov mutants` measures the checkout again and keeps an
|
|
558
563
|
earlier run's verdict for each mutant whose file is as it was and whose
|
|
559
564
|
candidate tests, and their test files, nothing changed could reach (as
|
package/docs/mutation.md
CHANGED
|
@@ -117,8 +117,15 @@ mutants the tests let survive.
|
|
|
117
117
|
from runs r2, r1`).
|
|
118
118
|
- **Interrupted.** Each verdict is saved as it is made. A pass stopped by
|
|
119
119
|
Ctrl-C, a killed job or a test worker that never ended keeps what it
|
|
120
|
-
decided,
|
|
121
|
-
|
|
120
|
+
decided, and the next pass runs only the rest. Sent SIGINT or SIGTERM, the
|
|
121
|
+
pass stops every process it started and ends within seconds: one that has
|
|
122
|
+
not ended 8 s after the signal is ended, what it decided saved first.
|
|
123
|
+
- **Order and budget.** The cheapest mutants run first, by the recorded times
|
|
124
|
+
of the tests each runs against, so a pass cut short has decided as many as
|
|
125
|
+
it could. `--budget <seconds>` stops the pass once it is spent and ends it
|
|
126
|
+
as a finished one, its verdicts saved; the summary says how many mutants it
|
|
127
|
+
left for the next pass (`budget of 2400 s spent: 812 mutant(s) left without
|
|
128
|
+
a verdict, for the next pass`).
|
|
122
129
|
- **Exit codes.** `0` with an answer; `1` when `--fail-on` or `--critical`
|
|
123
130
|
finds a mutant; `2`, after the answer, when the measured command failed (a
|
|
124
131
|
failing test kills nothing, so the verdicts cannot gate) or no mutant could
|
|
@@ -212,8 +219,11 @@ npx supercov runs latest mutants test --plan --json
|
|
|
212
219
|
|
|
213
220
|
- `--critical <glob>` (repeatable): every mutant in those files must be killed
|
|
214
221
|
or accepted, or the command fails.
|
|
215
|
-
- `--shard k/n` runs one of n shares of the mutants,
|
|
222
|
+
- `--shard k/n` runs one of n shares of the mutants, of about the same cost,
|
|
223
|
+
for parallel jobs (see
|
|
216
224
|
[A pass split across jobs](#a-pass-split-across-jobs)).
|
|
225
|
+
- `--budget <seconds>` stops the pass once that time is spent, its verdicts
|
|
226
|
+
saved, and leaves the rest for the next pass.
|
|
217
227
|
- `--plan` prints what would run, and runs nothing.
|
|
218
228
|
|
|
219
229
|
Some mutants no test can tell apart from the original. Accept them in
|
|
@@ -240,7 +250,7 @@ merges the runs, and the merged run holds every job's verdicts:
|
|
|
240
250
|
# Each of four jobs (matrix.shard 1 to 4):
|
|
241
251
|
- uses: actions/cache/restore@v4
|
|
242
252
|
with: { path: .supercov/runs, key: "mutants-${{ github.sha }}", restore-keys: "mutants-" }
|
|
243
|
-
- run: npx supercov mutants --shard ${{ matrix.shard }}/4 -- npm test
|
|
253
|
+
- run: npx supercov mutants --shard ${{ matrix.shard }}/4 --budget 2400 -- npm test
|
|
244
254
|
- uses: actions/upload-artifact@v4
|
|
245
255
|
with: { name: "mutants-${{ matrix.shard }}", path: .supercov/runs, include-hidden-files: true }
|
|
246
256
|
# Then one job:
|
|
@@ -260,6 +270,18 @@ earlier verdicts as after an edit. Name the command after `--`: without it,
|
|
|
260
270
|
Every job must measure the same commit with the same dependencies, as for any
|
|
261
271
|
merge ([CLI reference](cli.md#combine-shards)).
|
|
262
272
|
|
|
273
|
+
- **The shares.** Each job computes the same split from its own run: the
|
|
274
|
+
mutants to run are dealt in turn, back and forth, most costly first, so
|
|
275
|
+
every share gets its part of the costly ones. A mutant's cost there is what
|
|
276
|
+
the plan lists of it, the copies of test files it starts and the tests they
|
|
277
|
+
run, not the tests' times, which differ between jobs.
|
|
278
|
+
- **The budget.** `--budget <seconds>` ends a job's pass in time without a
|
|
279
|
+
`timeout` around it: past the budget the pass stops, saves what it
|
|
280
|
+
decided, and exits as a finished pass. Within a pass the cheapest mutants
|
|
281
|
+
run first, so a job cut short has decided as many as it could, and the
|
|
282
|
+
mutants it left run in the next commit's pass, where the restored runs lend
|
|
283
|
+
the rest of their verdicts.
|
|
284
|
+
|
|
263
285
|
- **The merge.** `supercov merge` keeps the strong verdicts of the runs it
|
|
264
286
|
merges, mutant by mutant, and says how many and from which runs. A kill in
|
|
265
287
|
any run is a kill. A survival stands where the run that let the mutant
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supercov",
|
|
3
|
-
"version": "4.29.
|
|
3
|
+
"version": "4.29.3",
|
|
4
4
|
"description": "Coverage, security and code quality for coding agents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"coverage",
|
|
@@ -125,14 +125,14 @@
|
|
|
125
125
|
"test:windows-tls": "node scripts/windows-tls-test.mjs"
|
|
126
126
|
},
|
|
127
127
|
"optionalDependencies": {
|
|
128
|
-
"@supercov/cli-darwin-arm64": "4.29.
|
|
129
|
-
"@supercov/cli-darwin-x64": "4.29.
|
|
130
|
-
"@supercov/cli-linux-arm64-gnu": "4.29.
|
|
131
|
-
"@supercov/cli-linux-arm64-musl": "4.29.
|
|
132
|
-
"@supercov/cli-linux-x64-gnu": "4.29.
|
|
133
|
-
"@supercov/cli-linux-x64-musl": "4.29.
|
|
134
|
-
"@supercov/cli-win32-arm64": "4.29.
|
|
135
|
-
"@supercov/cli-win32-x64": "4.29.
|
|
128
|
+
"@supercov/cli-darwin-arm64": "4.29.3",
|
|
129
|
+
"@supercov/cli-darwin-x64": "4.29.3",
|
|
130
|
+
"@supercov/cli-linux-arm64-gnu": "4.29.3",
|
|
131
|
+
"@supercov/cli-linux-arm64-musl": "4.29.3",
|
|
132
|
+
"@supercov/cli-linux-x64-gnu": "4.29.3",
|
|
133
|
+
"@supercov/cli-linux-x64-musl": "4.29.3",
|
|
134
|
+
"@supercov/cli-win32-arm64": "4.29.3",
|
|
135
|
+
"@supercov/cli-win32-x64": "4.29.3"
|
|
136
136
|
},
|
|
137
137
|
"peerDependencies": {
|
|
138
138
|
"@playwright/test": ">=1.55.0",
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// Strong mutation for Playwright (docs/design/strong-mutation.md, browser
|
|
2
2
|
// tests against a server).
|
|
3
3
|
//
|
|
4
|
-
//
|
|
4
|
+
// An invocation of Playwright runs the plan, or as many of its rows as one
|
|
5
|
+
// invocation holds (the rest run in further invocations, which the engine
|
|
6
|
+
// starts); a harness may start several invocations at once, each with a
|
|
7
|
+
// share of the tests, and they share the pass's files. The generated config repeats every
|
|
5
8
|
// test (`repeatEach`) as often as the busiest test file has rows: a file's row
|
|
6
9
|
// k is what every test of the file does in its k-th repetition -- run with
|
|
7
10
|
// one mutant, run with none (the baseline, row 0, and canaries), or skip. A
|
|
@@ -31,10 +34,29 @@ const TIMEOUT_CONSTANT_MS = 5_000;
|
|
|
31
34
|
const DEFAULT_DURATION_MS = 1_000;
|
|
32
35
|
const CANARY_FILES = 3;
|
|
33
36
|
const POLL_MS = 50;
|
|
37
|
+
// Playwright makes every repetition of every test of a file it loads before
|
|
38
|
+
// the first test runs, in the runner, whether a row names the test or not:
|
|
39
|
+
// an invocation holds about this many of them, and the main pass's other
|
|
40
|
+
// rows go to further invocations.
|
|
41
|
+
const TEST_CASES_PER_INVOCATION = 20_000;
|
|
42
|
+
// A baseline, two canaries and one mutant's row at least.
|
|
43
|
+
const MIN_REPETITIONS = 4;
|
|
34
44
|
|
|
35
45
|
/** What a page writes to its console when its mutant passed the hit limit. */
|
|
36
46
|
export const PAGE_TIMEOUT_MARKER = "SUPERCOV_MUTANT_TIMEOUT";
|
|
37
47
|
|
|
48
|
+
/**
|
|
49
|
+
* How many repetitions of each test one invocation holds: what fits
|
|
50
|
+
* `TEST_CASES_PER_INVOCATION` for the plan's Playwright tests, or
|
|
51
|
+
* `SUPERCOV_PLAYWRIGHT_REPETITIONS`.
|
|
52
|
+
*/
|
|
53
|
+
export function repetitionsPerInvocation(testCount) {
|
|
54
|
+
const asked = Number(process.env["SUPERCOV_PLAYWRIGHT_REPETITIONS"]);
|
|
55
|
+
if (Number.isInteger(asked) && asked >= MIN_REPETITIONS)
|
|
56
|
+
return asked;
|
|
57
|
+
return Math.max(MIN_REPETITIONS, Math.floor(TEST_CASES_PER_INVOCATION / Math.max(1, testCount)));
|
|
58
|
+
}
|
|
59
|
+
|
|
38
60
|
/** The pass this process belongs to, or `undefined` outside strong mode. */
|
|
39
61
|
export function strongPass() {
|
|
40
62
|
const planPath = process.env["SUPERCOV_STRONG_PLAN"];
|
|
@@ -63,7 +85,7 @@ export function writeJson(path, value) {
|
|
|
63
85
|
renameSync(draft, path);
|
|
64
86
|
}
|
|
65
87
|
|
|
66
|
-
function readJson(path) {
|
|
88
|
+
export function readJson(path) {
|
|
67
89
|
return JSON.parse(readFileSync(path, "utf8"));
|
|
68
90
|
}
|
|
69
91
|
|
|
@@ -151,22 +173,34 @@ function buildRows(pass, root, config) {
|
|
|
151
173
|
});
|
|
152
174
|
// `workers` set only where the pass runs one test at a time.
|
|
153
175
|
const concurrency = { workers: undefined, serialFiles: serialFilesOf(plan, tests, fullyParallelOf(config)) };
|
|
154
|
-
|
|
155
|
-
|
|
176
|
+
const job = pass.restart ? readJson(pass.restart) : null;
|
|
177
|
+
const perInvocation = repetitionsPerInvocation(Object.keys(tests).length);
|
|
178
|
+
if (job && job.kind !== "main") {
|
|
156
179
|
const files = {};
|
|
157
180
|
const entries = {};
|
|
181
|
+
// A mutant with a row in a file this invocation has filled waits
|
|
182
|
+
// for the next invocation, which runs the same job.
|
|
183
|
+
const deferred = [];
|
|
158
184
|
for (const entry of job.mutants) {
|
|
159
185
|
const known = { ...entry, tests: entry.tests.filter((id) => tests[id]) };
|
|
186
|
+
const rows = mutantRows(tests, known);
|
|
187
|
+
if (rows.some(([file]) => (files[file]?.length ?? 0) >= perInvocation)) {
|
|
188
|
+
deferred.push(entry);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
160
191
|
entries[entry.id] = known;
|
|
161
|
-
for (const [file, row] of
|
|
192
|
+
for (const [file, row] of rows)
|
|
162
193
|
(files[file] ??= []).push(row);
|
|
163
194
|
}
|
|
164
195
|
// A serial pass runs one test at a time: what it kills, nothing
|
|
165
196
|
// beside it did.
|
|
166
197
|
if (job.kind === "serial")
|
|
167
198
|
concurrency.workers = 1;
|
|
168
|
-
return { pass: pass.name, kind: job.kind, job, tests, files, entries, concurrency, immediate: [], restarts: [], otherRunners: job.otherRunners ?? {} };
|
|
199
|
+
return { pass: pass.name, kind: job.kind, job, tests, files, entries, concurrency, immediate: [], restarts: [], otherRunners: job.otherRunners ?? {}, deferred };
|
|
169
200
|
}
|
|
201
|
+
// A main pass's later invocation runs the mutants the one before had no
|
|
202
|
+
// room for, as the main pass would.
|
|
203
|
+
const only = job ? new Set(job.mutants.map((mutant) => mutant.id)) : undefined;
|
|
170
204
|
|
|
171
205
|
// The copy's own list: the mutant at each index must be the run's, and
|
|
172
206
|
// one the instrumenter could not place has no switch to turn on.
|
|
@@ -185,6 +219,9 @@ function buildRows(pass, root, config) {
|
|
|
185
219
|
|
|
186
220
|
const immediate = [];
|
|
187
221
|
const restarts = [];
|
|
222
|
+
const deferred = [];
|
|
223
|
+
// A file's mutated rows, beside its baseline and two canaries.
|
|
224
|
+
const rowsPerFile = perInvocation - 3;
|
|
188
225
|
const otherRunners = {};
|
|
189
226
|
const entries = {};
|
|
190
227
|
const byFile = new Map();
|
|
@@ -195,7 +232,7 @@ function buildRows(pass, root, config) {
|
|
|
195
232
|
baseline.get(file).add(id);
|
|
196
233
|
};
|
|
197
234
|
for (const mutant of plan.mutants) {
|
|
198
|
-
if (mutant.decided)
|
|
235
|
+
if (mutant.decided || (only && !only.has(mutant.id)))
|
|
199
236
|
continue;
|
|
200
237
|
// A Rust mutant (Rust compiled to wasm) is switched by its index in
|
|
201
238
|
// its file's list, as the pass's build placed it.
|
|
@@ -231,19 +268,26 @@ function buildRows(pass, root, config) {
|
|
|
231
268
|
}
|
|
232
269
|
const ordered = [...own.filter((test) => test.infected), ...own.filter((test) => !test.infected)].map((test) => test.id);
|
|
233
270
|
const switched = `${mutant.file}#${found.index}`;
|
|
234
|
-
for (const id of ordered)
|
|
235
|
-
needBaseline(tests[id].file, id);
|
|
236
271
|
if (mutant.serverWide) {
|
|
272
|
+
for (const id of ordered)
|
|
273
|
+
needBaseline(tests[id].file, id);
|
|
237
274
|
restarts.push({ id: mutant.id, mutant: switched, tests: ordered, reason: mutant.serverWide, budgetFactor: 1 });
|
|
238
275
|
continue;
|
|
239
276
|
}
|
|
240
277
|
const entry = { id: mutant.id, mutant: switched, tests: [ordered[0]], rest: ordered.slice(1), budgetFactor: 1 };
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
278
|
+
// One row, in its first test's file.
|
|
279
|
+
const [[file, row]] = mutantRows(tests, entry);
|
|
280
|
+
if (!byFile.has(file))
|
|
281
|
+
byFile.set(file, []);
|
|
282
|
+
// A file's rows past what this invocation holds wait for the next.
|
|
283
|
+
if (byFile.get(file).length >= rowsPerFile) {
|
|
284
|
+
deferred.push({ id: mutant.id });
|
|
285
|
+
continue;
|
|
246
286
|
}
|
|
287
|
+
byFile.get(file).push(row);
|
|
288
|
+
entries[mutant.id] = entry;
|
|
289
|
+
for (const id of ordered)
|
|
290
|
+
needBaseline(tests[id].file, id);
|
|
247
291
|
}
|
|
248
292
|
const files = {};
|
|
249
293
|
for (const [file, ids] of baseline) {
|
|
@@ -262,16 +306,52 @@ function buildRows(pass, root, config) {
|
|
|
262
306
|
rows.splice(1 + Math.floor(mutated.length / 2), 0, canary());
|
|
263
307
|
rows.push(canary());
|
|
264
308
|
}
|
|
265
|
-
return { pass: pass.name, kind: "main", job: null, tests, files, entries, concurrency, immediate, restarts, otherRunners };
|
|
309
|
+
return { pass: pass.name, kind: "main", job: null, tests, files, entries, concurrency, immediate, restarts, otherRunners, deferred };
|
|
266
310
|
}
|
|
267
311
|
|
|
268
|
-
/** The rows of this pass: built and written by the runner, read
|
|
312
|
+
/** The rows of this pass: built and written by the runner, read by its reporter. */
|
|
269
313
|
let rowsCache;
|
|
270
314
|
export function loadRows(pass) {
|
|
271
315
|
rowsCache ??= readJson(`${pass.round}/rows.json`);
|
|
272
316
|
return rowsCache;
|
|
273
317
|
}
|
|
274
318
|
|
|
319
|
+
/**
|
|
320
|
+
* What a worker reads: the pass's shape (`worker.json`: the repetitions,
|
|
321
|
+
* the tests and how they run side by side), and the rows of the one
|
|
322
|
+
* repetition index it serves (`rows/<index>.json`), never the plan or the
|
|
323
|
+
* other rows. Each is small and the same size whatever the plan's.
|
|
324
|
+
*/
|
|
325
|
+
function writeWorkerFiles(pass, rows, repeatEach) {
|
|
326
|
+
writeJson(`${pass.round}/worker.json`, { repeatEach, tests: rows.tests, concurrency: rows.concurrency, job: Boolean(rows.job) });
|
|
327
|
+
const byIndex = Array.from({ length: repeatEach }, () => ({}));
|
|
328
|
+
for (const [file, fileRows] of Object.entries(rows.files))
|
|
329
|
+
fileRows.forEach((row, index) => { byIndex[index][file] = row; });
|
|
330
|
+
byIndex.forEach((at, index) => writeJson(`${pass.round}/rows/${index}.json`, at));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
let workerCache;
|
|
334
|
+
function loadWorker(pass) {
|
|
335
|
+
workerCache ??= readJson(`${pass.round}/worker.json`);
|
|
336
|
+
return workerCache;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const indexCache = new Map();
|
|
340
|
+
function rowsAt(pass, index) {
|
|
341
|
+
if (!indexCache.has(index))
|
|
342
|
+
indexCache.set(index, readJson(`${pass.round}/rows/${index}.json`));
|
|
343
|
+
return indexCache.get(index);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Whether this process lists the tests (`playwright test --list`) rather
|
|
348
|
+
* than run them: it reads no plan and writes nothing, and lists the
|
|
349
|
+
* project's tests as they are, once each.
|
|
350
|
+
*/
|
|
351
|
+
function listing() {
|
|
352
|
+
return process.argv.includes("--list");
|
|
353
|
+
}
|
|
354
|
+
|
|
275
355
|
/**
|
|
276
356
|
* The generated config in strong mode: every test repeated once per row,
|
|
277
357
|
* no retries (a retry would be a repetition of its own), no failure limit
|
|
@@ -279,18 +359,28 @@ export function loadRows(pass) {
|
|
|
279
359
|
* serial pass), and the strong reporter alone.
|
|
280
360
|
*/
|
|
281
361
|
export function strongConfig(normalized, root, reporterPath) {
|
|
362
|
+
if (listing())
|
|
363
|
+
return normalized;
|
|
282
364
|
const pass = strongPass();
|
|
283
|
-
let
|
|
365
|
+
let shape;
|
|
284
366
|
if (process.env.TEST_WORKER_INDEX === undefined) {
|
|
285
|
-
|
|
286
|
-
|
|
367
|
+
// Every invocation of the pass (a harness may start several at
|
|
368
|
+
// once, each with a share of the tests) works out the same rows from
|
|
369
|
+
// the same plan and writes them alike; none removes what another
|
|
370
|
+
// wrote. The pass's directory is new with the pass.
|
|
371
|
+
const rows = buildRows(pass, root, normalized);
|
|
372
|
+
const repeatEach = Math.max(1, ...Object.values(rows.files).map((fileRows) => fileRows.length));
|
|
373
|
+
// This invocation, for its workers: they share its server.
|
|
374
|
+
process.env["SUPERCOV_PLAYWRIGHT_INVOCATION"] = String(process.pid);
|
|
287
375
|
writeJson(`${pass.round}/rows.json`, rows);
|
|
376
|
+
writeWorkerFiles(pass, rows, repeatEach);
|
|
288
377
|
rowsCache = rows;
|
|
378
|
+
shape = { repeatEach, concurrency: rows.concurrency };
|
|
289
379
|
}
|
|
290
380
|
else {
|
|
291
|
-
|
|
381
|
+
shape = loadWorker(pass);
|
|
292
382
|
}
|
|
293
|
-
const repeatEach
|
|
383
|
+
const { repeatEach, concurrency } = shape;
|
|
294
384
|
const strongProject = (project) => ({ ...project, repeatEach, retries: 0 });
|
|
295
385
|
return {
|
|
296
386
|
...normalized,
|
|
@@ -298,7 +388,7 @@ export function strongConfig(normalized, root, reporterPath) {
|
|
|
298
388
|
repeatEach,
|
|
299
389
|
retries: 0,
|
|
300
390
|
maxFailures: 0,
|
|
301
|
-
...(
|
|
391
|
+
...(concurrency.workers ? { workers: concurrency.workers } : {}),
|
|
302
392
|
// The strong reporter alone: `mutants test --json` owns stdout.
|
|
303
393
|
reporter: [[reporterPath]],
|
|
304
394
|
};
|
|
@@ -317,15 +407,22 @@ export function baselineOf(pass, original) {
|
|
|
317
407
|
|
|
318
408
|
const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
319
409
|
|
|
320
|
-
|
|
410
|
+
/**
|
|
411
|
+
* Where a test is, the same for each of its repetitions and in every
|
|
412
|
+
* invocation: its project and title path. The reporter, from a test case.
|
|
413
|
+
*/
|
|
414
|
+
export function placeOf(test) {
|
|
415
|
+
return JSON.stringify(test.titlePath().slice(1));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** The test the plan names (its first repetition's id) for a repetition, as its invocation's reporter wrote it. */
|
|
321
419
|
async function originalTestId(pass, testInfo) {
|
|
322
420
|
if (!testInfo.repeatEachIndex)
|
|
323
421
|
return testInfo.testId;
|
|
422
|
+
const path = `${pass.round}/originals/${key(JSON.stringify([testInfo.project.name, ...testInfo.titlePath]))}`;
|
|
324
423
|
for (let waited = 0; waited < 10_000; waited += POLL_MS) {
|
|
325
|
-
if (
|
|
326
|
-
|
|
327
|
-
if (repetitionsCache?.[testInfo.testId])
|
|
328
|
-
return repetitionsCache[testInfo.testId];
|
|
424
|
+
if (existsSync(path))
|
|
425
|
+
return readJson(path);
|
|
329
426
|
await sleep(POLL_MS);
|
|
330
427
|
}
|
|
331
428
|
return undefined;
|
|
@@ -347,8 +444,10 @@ function alive(pid) {
|
|
|
347
444
|
* whose holder died is taken over.
|
|
348
445
|
*/
|
|
349
446
|
async function lockFile(pass, file) {
|
|
350
|
-
|
|
351
|
-
|
|
447
|
+
// Per invocation: another invocation's tests reach a server of their own.
|
|
448
|
+
const locks = `${pass.round}/locks/${process.env["SUPERCOV_PLAYWRIGHT_INVOCATION"]}`;
|
|
449
|
+
const lock = `${locks}/${key(file)}`;
|
|
450
|
+
mkdirSync(locks, { recursive: true });
|
|
352
451
|
for (;;) {
|
|
353
452
|
try {
|
|
354
453
|
mkdirSync(lock);
|
|
@@ -384,10 +483,10 @@ export async function strongClaim(testInfo) {
|
|
|
384
483
|
if (!pass)
|
|
385
484
|
return undefined;
|
|
386
485
|
const started = Date.now();
|
|
387
|
-
const rows =
|
|
486
|
+
const rows = loadWorker(pass);
|
|
388
487
|
const original = await originalTestId(pass, testInfo);
|
|
389
488
|
const test = original && rows.tests[original];
|
|
390
|
-
const row = test &&
|
|
489
|
+
const row = test && rowsAt(pass, testInfo.repeatEachIndex)[test.file];
|
|
391
490
|
if (!row || !row.tests.includes(original))
|
|
392
491
|
return null;
|
|
393
492
|
const configured = testInfo.timeout;
|
|
@@ -427,7 +526,17 @@ export async function strongClaim(testInfo) {
|
|
|
427
526
|
}
|
|
428
527
|
else if (configured > 0)
|
|
429
528
|
testInfo.setTimeout(Date.now() - started + configured);
|
|
430
|
-
const claimed = {
|
|
529
|
+
const claimed = {
|
|
530
|
+
original,
|
|
531
|
+
index: testInfo.repeatEachIndex,
|
|
532
|
+
testId: testInfo.testId,
|
|
533
|
+
invocation: process.env["SUPERCOV_PLAYWRIGHT_INVOCATION"],
|
|
534
|
+
kind: row.kind,
|
|
535
|
+
id: row.id,
|
|
536
|
+
mutant: row.mutant ?? "-",
|
|
537
|
+
startedAt: Date.now(),
|
|
538
|
+
lock,
|
|
539
|
+
};
|
|
431
540
|
writeJson(`${pass.round}/attempts/${key(testInfo.testId)}.json`, claimed);
|
|
432
541
|
return claimed;
|
|
433
542
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
// Strong mutation's reporter for Playwright (playwrightStrong.mjs explains the
|
|
2
|
-
// pass). In
|
|
3
|
-
// the plan names, marks each test's baseline and each killed
|
|
4
|
-
// results come (the fixture reads them: a repetition after a failed
|
|
5
|
-
// or a kill skips), and
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
// pass). In each invocation's runner process it maps each repetition of a
|
|
3
|
+
// test to the test the plan names, marks each test's baseline and each killed
|
|
4
|
+
// mutant as results come (the fixture reads them: a repetition after a failed
|
|
5
|
+
// baseline or a kill skips), and keeps each repetition's outcome on disk.
|
|
6
|
+
// Once the command has ended, with every invocation it started (a harness may
|
|
7
|
+
// start several at once, each with a share of the tests), the engine runs
|
|
8
|
+
// this module (`judge`), which turns the outcomes into each mutant's verdict,
|
|
9
|
+
// in the results file `mutants test` reads: one verdict a mutant, from
|
|
10
|
+
// whichever invocations ran its rows, and what was cut short is unfinished.
|
|
11
|
+
import { appendFileSync, existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
12
|
+
import { pathToFileURL } from "node:url";
|
|
13
|
+
import { baselineOf, key, loadRows, placeOf, readJson, strongPass, writeJson } from "./playwrightStrong.mjs";
|
|
9
14
|
|
|
10
15
|
const WHY = {
|
|
11
16
|
"background": "its code ran in server work no request named",
|
|
@@ -22,6 +27,25 @@ const WHY = {
|
|
|
22
27
|
// test (a server that exited) are trusted; later ones may be its doing.
|
|
23
28
|
const ERROR_MARGIN_MS = 1_000;
|
|
24
29
|
|
|
30
|
+
/** Each JSON file in a directory of the pass, or none. */
|
|
31
|
+
function readAll(directory) {
|
|
32
|
+
let names;
|
|
33
|
+
try {
|
|
34
|
+
names = readdirSync(directory);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return names.sort().flatMap((name) => {
|
|
40
|
+
try {
|
|
41
|
+
return [readJson(`${directory}/${name}`)];
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
25
49
|
function readLines(path) {
|
|
26
50
|
if (!existsSync(path))
|
|
27
51
|
return [];
|
|
@@ -41,10 +65,7 @@ function readLines(path) {
|
|
|
41
65
|
export default class SupercovPlaywrightStrongReporter {
|
|
42
66
|
constructor() {
|
|
43
67
|
this.pass = strongPass();
|
|
44
|
-
this.
|
|
45
|
-
this.statuses = new Map();
|
|
46
|
-
this.repetitions = {};
|
|
47
|
-
this.byOriginal = new Map();
|
|
68
|
+
this.originals = new Map();
|
|
48
69
|
}
|
|
49
70
|
// It prints nothing, and says it prints: Playwright adds a reporter of
|
|
50
71
|
// its own where none does, and `mutants test --json` owns stdout.
|
|
@@ -56,42 +77,28 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
56
77
|
return;
|
|
57
78
|
this.rows = loadRows(this.pass);
|
|
58
79
|
// A repetition of a test has an id of its own; the plan names the
|
|
59
|
-
// first. Repetitions share the test's project, file and titles
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
for (const test of all) {
|
|
64
|
-
if (!test.repeatEachIndex)
|
|
65
|
-
firsts.set(where(test), test.id);
|
|
66
|
-
}
|
|
67
|
-
for (const test of all) {
|
|
68
|
-
const original = test.repeatEachIndex ? firsts.get(where(test)) : test.id;
|
|
69
|
-
if (!original)
|
|
80
|
+
// first. Repetitions share the test's project, file and titles: a
|
|
81
|
+
// worker finds the first's id by them, one small file a test.
|
|
82
|
+
for (const test of suite.allTests()) {
|
|
83
|
+
if (test.repeatEachIndex)
|
|
70
84
|
continue;
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
85
|
+
this.originals.set(placeOf(test), test.id);
|
|
86
|
+
writeJson(`${this.pass.round}/originals/${key(placeOf(test))}`, test.id);
|
|
73
87
|
}
|
|
74
|
-
writeJson(`${this.pass.round}/repetitions.json`, this.repetitions);
|
|
75
88
|
}
|
|
76
89
|
rowOf(test) {
|
|
77
|
-
const original = this.
|
|
90
|
+
const original = test.repeatEachIndex ? this.originals.get(placeOf(test)) : test.id;
|
|
78
91
|
const file = original && this.rows.tests[original]?.file;
|
|
79
92
|
const row = file && this.rows.files[file]?.[test.repeatEachIndex];
|
|
80
93
|
return row && row.tests.includes(original) ? { row, original } : undefined;
|
|
81
94
|
}
|
|
82
|
-
attempt(repetition) {
|
|
83
|
-
const path = `${this.pass.round}/attempts/${key(repetition)}.json`;
|
|
84
|
-
try {
|
|
85
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
95
|
onError(error) {
|
|
92
96
|
// Outside any test: a web server that exited, a global setup that
|
|
93
|
-
// threw.
|
|
94
|
-
this.
|
|
97
|
+
// threw. Each invocation's first one's time and words.
|
|
98
|
+
if (!this.pass || this.erred)
|
|
99
|
+
return;
|
|
100
|
+
this.erred = true;
|
|
101
|
+
writeJson(`${this.pass.round}/errors/${process.pid}.json`, { at: Date.now(), message: firstWords(error?.message ?? error) });
|
|
95
102
|
}
|
|
96
103
|
onTestEnd(test, result) {
|
|
97
104
|
if (!this.pass)
|
|
@@ -102,34 +109,58 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
102
109
|
const errors = result.errors ?? [];
|
|
103
110
|
const timeoutOnly = errors.length > 0 && errors.every((error) => TEST_TIMEOUT.test(stripAnsi(error?.message ?? "")));
|
|
104
111
|
const reported = errors.find((error) => !TEST_TIMEOUT.test(stripAnsi(error?.message ?? ""))) ?? errors[0];
|
|
105
|
-
this.statuses.set(test.id, {
|
|
106
|
-
status: result.status,
|
|
107
|
-
timeoutOnly,
|
|
108
|
-
message: reported ? firstWords(reported.message ?? reported.value) : undefined,
|
|
109
|
-
});
|
|
110
112
|
const found = this.rowOf(test);
|
|
113
|
+
if (found) {
|
|
114
|
+
writeJson(`${this.pass.round}/outcomes/${key(test.id)}.json`, {
|
|
115
|
+
status: result.status,
|
|
116
|
+
timeoutOnly,
|
|
117
|
+
message: reported ? firstWords(reported.message ?? reported.value) : undefined,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
111
120
|
if (!found)
|
|
112
121
|
return;
|
|
113
122
|
const { row, original } = found;
|
|
114
123
|
if (row.kind === "baseline" && !this.rows.job) {
|
|
115
|
-
|
|
124
|
+
// A test stopped (the command was) or skipped did not fail: its
|
|
125
|
+
// rows skip, and their mutants are unfinished, not decided.
|
|
126
|
+
const said = result.status === "passed" ? "passed" : result.status === "failed" || result.status === "timedOut" ? "failed" : "unfinished";
|
|
127
|
+
writeJson(`${this.pass.round}/baseline/${key(original)}`, said);
|
|
116
128
|
return;
|
|
117
129
|
}
|
|
118
130
|
// The rest of the mutant's repetitions skip.
|
|
119
|
-
if (row.kind === "mutant" && result.status === "failed" && this.
|
|
131
|
+
if (row.kind === "mutant" && result.status === "failed" && existsSync(`${this.pass.round}/attempts/${key(test.id)}.json`))
|
|
120
132
|
writeJson(`${this.pass.round}/killed/${key(row.id)}`, original);
|
|
121
133
|
}
|
|
122
134
|
onEnd() {
|
|
123
135
|
if (!this.pass)
|
|
124
136
|
return;
|
|
125
|
-
this.finish();
|
|
126
137
|
// A killed mutant fails its test, and that is the point: the
|
|
127
|
-
// command's outcome is the pass's, not the tests'.
|
|
138
|
+
// command's outcome is the pass's, not the tests'. The verdicts are
|
|
139
|
+
// the judge's, once every invocation has ended.
|
|
128
140
|
return { status: "passed" };
|
|
129
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* The pass's verdicts, from what its invocations left on disk: each
|
|
144
|
+
* repetition's attempt (the fixture's) and outcome (the reporter's), the
|
|
145
|
+
* baselines, and the errors outside any test.
|
|
146
|
+
*/
|
|
130
147
|
finish() {
|
|
131
|
-
const { pass
|
|
148
|
+
const { pass } = this;
|
|
149
|
+
const rows = (this.rows = loadRows(pass));
|
|
132
150
|
const kind = rows.kind;
|
|
151
|
+
const attempts = readAll(`${pass.round}/attempts`);
|
|
152
|
+
const byOriginal = new Map(attempts.map((attempt) => [`${attempt.original}\0${attempt.index}`, attempt]));
|
|
153
|
+
const outcomeFile = (attempt) => {
|
|
154
|
+
try {
|
|
155
|
+
return readJson(`${pass.round}/outcomes/${key(attempt.testId)}.json`);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const errors = readAll(`${pass.round}/errors`).sort((a, b) => a.at - b.at);
|
|
162
|
+
const globalError = errors[0];
|
|
163
|
+
const started = Math.min(statSync(`${pass.round}/rows.json`).mtimeMs, ...attempts.map((attempt) => attempt.startedAt));
|
|
133
164
|
const write = (record) => appendFileSync(pass.resultsPath, `${JSON.stringify(record)}\n`);
|
|
134
165
|
for (const record of rows.immediate)
|
|
135
166
|
write(record);
|
|
@@ -148,8 +179,11 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
148
179
|
const baselineFailed = new Set();
|
|
149
180
|
if (!rows.job) {
|
|
150
181
|
for (const fileRows of Object.values(rows.files)) {
|
|
182
|
+
// A baseline that never ended (the command was stopped, or
|
|
183
|
+
// ran out of time) says nothing of the test: its rows did not
|
|
184
|
+
// run, and the mutants are unfinished.
|
|
151
185
|
for (const original of fileRows[0].tests) {
|
|
152
|
-
if (baselineOf(pass, original)
|
|
186
|
+
if (baselineOf(pass, original) === "failed")
|
|
153
187
|
baselineFailed.add(original);
|
|
154
188
|
}
|
|
155
189
|
}
|
|
@@ -157,10 +191,9 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
157
191
|
// Every attempt that ran with a mutant: a kill beside another's is
|
|
158
192
|
// confirmed alone before it counts.
|
|
159
193
|
const mutated = [];
|
|
160
|
-
for (const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
mutated.push({ ...attempt, repetition, endedAt: attempt.endedAt ?? Date.now() });
|
|
194
|
+
for (const attempt of attempts) {
|
|
195
|
+
if (attempt.mutant !== "-")
|
|
196
|
+
mutated.push({ ...attempt, repetition: attempt.testId, endedAt: attempt.endedAt ?? Date.now() });
|
|
164
197
|
}
|
|
165
198
|
const beside = (repetition, attempt) => mutated.some((other) => other.repetition !== repetition &&
|
|
166
199
|
other.mutant !== attempt.mutant &&
|
|
@@ -168,9 +201,9 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
168
201
|
attempt.startedAt < other.endedAt);
|
|
169
202
|
// Each repetition's outcome.
|
|
170
203
|
const outcomeOf = (original, index, mutant) => {
|
|
171
|
-
const
|
|
172
|
-
const ended =
|
|
173
|
-
const
|
|
204
|
+
const attempt = byOriginal.get(`${original}\0${index}`);
|
|
205
|
+
const ended = attempt && outcomeFile(attempt);
|
|
206
|
+
const repetition = attempt?.testId;
|
|
174
207
|
if (!attempt) {
|
|
175
208
|
if (baselineFailed.has(original))
|
|
176
209
|
return { kind: "baseline-failed" };
|
|
@@ -246,7 +279,8 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
246
279
|
: -Infinity;
|
|
247
280
|
// After an error outside any test (the shared server exited), what
|
|
248
281
|
// ended later may be its doing.
|
|
249
|
-
const trustedUntil =
|
|
282
|
+
const trustedUntil = globalError ? globalError.at - ERROR_MARGIN_MS : Infinity;
|
|
283
|
+
this.globalError = globalError;
|
|
250
284
|
let decided = 0;
|
|
251
285
|
let confirming = 0;
|
|
252
286
|
for (const [id, entry] of Object.entries(rows.entries)) {
|
|
@@ -257,7 +291,7 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
257
291
|
next(entry, "canary", all);
|
|
258
292
|
continue;
|
|
259
293
|
}
|
|
260
|
-
const verdict = this.verdict(entry, own, all, trustedUntil, next);
|
|
294
|
+
const verdict = this.verdict(rows, entry, own, all, trustedUntil, next);
|
|
261
295
|
if (verdict === "confirm")
|
|
262
296
|
confirming += 1;
|
|
263
297
|
if (!verdict || verdict === "confirm")
|
|
@@ -277,6 +311,13 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
277
311
|
write({ id: job.id, status: "error", reason: "its tests did not finish, run one at a time", tests: 0, durationMs: 0 });
|
|
278
312
|
serial.splice(0, serial.length, ...serial.filter((job) => job.reason !== "unfinished"));
|
|
279
313
|
}
|
|
314
|
+
// What this invocation had no room for runs in the next, as this
|
|
315
|
+
// one would have run it.
|
|
316
|
+
if (rows.deferred.length) {
|
|
317
|
+
write({ restart: rows.job
|
|
318
|
+
? { ...rows.job, mutants: rows.deferred }
|
|
319
|
+
: { kind: "main", reason: "more rows than one invocation holds", mutants: rows.deferred } });
|
|
320
|
+
}
|
|
280
321
|
for (const job of alone)
|
|
281
322
|
write({ restart: { kind: "alone", everywhere: EVERYWHERE.includes(job.reason), reason: job.reason, mutants: [job], otherRunners: rows.otherRunners } });
|
|
282
323
|
if (stage.length)
|
|
@@ -290,8 +331,9 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
290
331
|
kind,
|
|
291
332
|
...(rows.concurrency.workers ? { workers: rows.concurrency.workers } : {}),
|
|
292
333
|
serialFiles: rows.concurrency.serialFiles.length,
|
|
293
|
-
...(
|
|
294
|
-
|
|
334
|
+
...(globalError ? { error: globalError.message } : {}),
|
|
335
|
+
invocations: new Set(attempts.map((attempt) => attempt.invocation)).size,
|
|
336
|
+
durationMs: Date.now() - started,
|
|
295
337
|
decided,
|
|
296
338
|
confirming,
|
|
297
339
|
next: { alone: alone.length, stage: stage.length, serial: serial.length },
|
|
@@ -306,8 +348,7 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
306
348
|
* it was sent on to another pass, `"confirm"` when a kill beside other
|
|
307
349
|
* mutants' attempts is to be confirmed one test at a time.
|
|
308
350
|
*/
|
|
309
|
-
verdict(entry, outcomes, all, trustedUntil, next) {
|
|
310
|
-
const { rows } = this;
|
|
351
|
+
verdict(rows, entry, outcomes, all, trustedUntil, next) {
|
|
311
352
|
const kind = rows.kind;
|
|
312
353
|
const shared = kind === "main" || kind === "stage";
|
|
313
354
|
const reason = entry.reason ?? (kind === "main" ? undefined : rows.job?.reason);
|
|
@@ -375,3 +416,14 @@ function firstWords(message) {
|
|
|
375
416
|
const text = stripAnsi(message ?? "").replace(/\s+/g, " ").trim();
|
|
376
417
|
return text.length > 300 ? `${text.slice(0, 299)}…` : text;
|
|
377
418
|
}
|
|
419
|
+
|
|
420
|
+
/** Decides the pass's verdicts: run by the engine once the command has ended. */
|
|
421
|
+
export function judge() {
|
|
422
|
+
const reporter = new SupercovPlaywrightStrongReporter();
|
|
423
|
+
if (!reporter.pass || !existsSync(`${reporter.pass.round}/rows.json`))
|
|
424
|
+
return;
|
|
425
|
+
reporter.finish();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href)
|
|
429
|
+
judge();
|
|
@@ -72,6 +72,10 @@ function claim() {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// What a file before this one in the same worker reported to is not this
|
|
76
|
+
// file's copy.
|
|
77
|
+
if (globalThis.__vitest_worker__)
|
|
78
|
+
globalThis.__vitest_worker__.supercovReport = undefined;
|
|
75
79
|
const claimed = claim();
|
|
76
80
|
// A copy with nothing to run -- beyond its file's assignments, or one whose
|
|
77
81
|
// mutant another copy has decided -- ends here, before its test file loads.
|
|
@@ -117,6 +121,53 @@ function outsideTests(error) {
|
|
|
117
121
|
/SUPERCOV_MUTANT_TIMEOUT|MutantTimeout/.test(`${error?.name} ${error?.code} ${error?.message}`);
|
|
118
122
|
report({ outside: true, timeout, message: `${error?.message ?? error}`.slice(0, 300), hits: hitsNow() });
|
|
119
123
|
}
|
|
124
|
+
// A test file that does not load or set up -- a setup file after this one
|
|
125
|
+
// throws, or one of its imports does -- runs none of its tests and none of
|
|
126
|
+
// its hooks: Vitest tells its collection, and the copy reports what failed
|
|
127
|
+
// with how often its mutant had run by then. Reported once per worker: a
|
|
128
|
+
// worker that runs files one after another reports each to its own copy.
|
|
129
|
+
const workerState = globalThis.__vitest_worker__;
|
|
130
|
+
if (workerState)
|
|
131
|
+
workerState.supercovReport = assignment ? (record) => report({ ...record, hits: hitsNow() }) : undefined;
|
|
132
|
+
if (workerState?.rpc && !workerState.supercovCollected) {
|
|
133
|
+
workerState.supercovCollected = true;
|
|
134
|
+
const rpc = workerState.rpc;
|
|
135
|
+
workerState.rpc = new Proxy(rpc, {
|
|
136
|
+
get(target, name) {
|
|
137
|
+
const value = Reflect.get(target, name);
|
|
138
|
+
if (name !== "onCollected" || typeof value !== "function")
|
|
139
|
+
return value;
|
|
140
|
+
return (files, ...rest) => {
|
|
141
|
+
const error = files?.find?.((file) => file?.result?.state === "fail")?.result?.errors?.[0];
|
|
142
|
+
if (error)
|
|
143
|
+
workerState.supercovReport?.({ loadError: true, message: messageOf(error) });
|
|
144
|
+
return value.call(target, files, ...rest);
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// An error as a verdict's reason says it.
|
|
151
|
+
function messageOf(error) {
|
|
152
|
+
return `${error?.message ?? error}`.slice(0, 300);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// The first hook of `suite` or a suite in it that failed (a `beforeAll`
|
|
156
|
+
// that threw): Vitest records it on its suite and skips the suite's tests.
|
|
157
|
+
function failedHook(suite) {
|
|
158
|
+
if (!suite || suite.type === "test")
|
|
159
|
+
return undefined;
|
|
160
|
+
const own = suite.result?.errors?.[0];
|
|
161
|
+
if (own)
|
|
162
|
+
return own;
|
|
163
|
+
for (const child of suite.tasks ?? []) {
|
|
164
|
+
const error = failedHook(child);
|
|
165
|
+
if (error)
|
|
166
|
+
return error;
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
120
171
|
if (assignment) {
|
|
121
172
|
process.on("uncaughtException", outsideTests);
|
|
122
173
|
process.on("unhandledRejection", outsideTests);
|
|
@@ -206,9 +257,16 @@ const LEFT_RUNNING_PROBE_EVALUATIONS = Math.ceil(LEFT_RUNNING_EVALUATIONS * LEFT
|
|
|
206
257
|
// clock (vi.useFakeTimers) and leaves it faked must not hold the look up.
|
|
207
258
|
const realSetTimeout = globalThis.setTimeout;
|
|
208
259
|
const pause = (ms) => new Promise((resolve) => realSetTimeout(resolve, ms));
|
|
209
|
-
|
|
260
|
+
// No parameter is declared: Vitest 4 reads a suite hook's first one as the
|
|
261
|
+
// fixtures it asks for, and passes the suite second (Vitest 1-3, first).
|
|
262
|
+
afterAll(async function () {
|
|
210
263
|
if (!assignment)
|
|
211
264
|
return;
|
|
265
|
+
// A hook that failed skipped its suite's tests: what failed, and how
|
|
266
|
+
// often the mutant had run by the file's end.
|
|
267
|
+
const hook = failedHook([...arguments].find((value) => value?.type === "suite"));
|
|
268
|
+
if (hook)
|
|
269
|
+
report({ hook: true, message: messageOf(hook), hits: hitsNow() });
|
|
212
270
|
if (assignment.mutant && runtime.mutantHitCount) {
|
|
213
271
|
const before = runtime.mutantHitCount();
|
|
214
272
|
await pause(LEFT_RUNNING_PROBE_MS);
|
|
@@ -148,6 +148,12 @@ function readOutcome(out) {
|
|
|
148
148
|
outcome.doneAt = record.at;
|
|
149
149
|
outcome.channelLost = Boolean(record.channelLost);
|
|
150
150
|
}
|
|
151
|
+
// Its test file did not load or set up, or a hook failed and its
|
|
152
|
+
// suite's tests were skipped: the first such error.
|
|
153
|
+
else if (record.loadError)
|
|
154
|
+
outcome.loadError ??= record;
|
|
155
|
+
else if (record.hook)
|
|
156
|
+
outcome.hook ??= record;
|
|
151
157
|
else if (record.test)
|
|
152
158
|
outcome.tests.push(record);
|
|
153
159
|
else if (record.outside)
|
|
@@ -1138,7 +1144,7 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1138
1144
|
entry.state = "waiting";
|
|
1139
1145
|
if (outcome.cancelled && !outcome.claimed && !stalled && ++entry.tries < 3)
|
|
1140
1146
|
return;
|
|
1141
|
-
const failed = outcome.tests.some((test) => test.failed);
|
|
1147
|
+
const failed = outcome.tests.some((test) => test.failed) || Boolean(outcome.hook);
|
|
1142
1148
|
if ((failed || !outcome.done) && !entry.whole) {
|
|
1143
1149
|
entry.whole = true;
|
|
1144
1150
|
entry.tests = new Set();
|
|
@@ -1166,6 +1172,8 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1166
1172
|
wholeBaseline.add(entry.file);
|
|
1167
1173
|
if (outcome.outside.length)
|
|
1168
1174
|
baselineFailed.add(`${entry.file}#outside`);
|
|
1175
|
+
if (outcome.hook)
|
|
1176
|
+
baselineFailed.add(`${entry.file}#hook`);
|
|
1169
1177
|
if (!outcome.done)
|
|
1170
1178
|
baselineFailed.add(`${entry.file}#file`);
|
|
1171
1179
|
for (const test of outcome.tests)
|
|
@@ -1285,7 +1293,8 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1285
1293
|
job.confirming.splice(job.confirming.indexOf(waiting), 1);
|
|
1286
1294
|
const alsoWithout = evidence.test ? result.failed.has(evidence.test)
|
|
1287
1295
|
: evidence.outside ? result.outside
|
|
1288
|
-
:
|
|
1296
|
+
: evidence.hook ? result.hook
|
|
1297
|
+
: !result.done;
|
|
1289
1298
|
if (!alsoWithout) {
|
|
1290
1299
|
finish(job, verdict);
|
|
1291
1300
|
return;
|
|
@@ -1394,6 +1403,10 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1394
1403
|
// the same way without the mutant.
|
|
1395
1404
|
kill({ unfinished: true }, { status: "timeout", killedBy: group.file, reason: "its test file stopped before its end, past its limit" });
|
|
1396
1405
|
}
|
|
1406
|
+
// Its file did not load or set up before the mutant ran: not the
|
|
1407
|
+
// mutant's doing.
|
|
1408
|
+
else if (outcome.loadError?.hits === 0)
|
|
1409
|
+
finish(job, { status: "error", reason: `its copy of ${group.file} did not load before the mutant ran: ${outcome.loadError.message}` });
|
|
1397
1410
|
else if (!outcome.done) {
|
|
1398
1411
|
// The copy started and its file did not finish: the mutant
|
|
1399
1412
|
// broke it while it loaded or ran.
|
|
@@ -1402,6 +1415,9 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1402
1415
|
else
|
|
1403
1416
|
kill({ unfinished: true }, { status: "killed", killedBy: group.file, reason: "the test file did not finish" });
|
|
1404
1417
|
}
|
|
1418
|
+
// A hook failed with the mutant, as it does not without it.
|
|
1419
|
+
else if (outcome.hook?.hits > 0 && !baselineFailed.has(`${group.file}#hook`))
|
|
1420
|
+
kill({ hook: true }, { status: "killed", killedBy: group.file, reason: `a hook failed: ${outcome.hook.message}` });
|
|
1405
1421
|
else {
|
|
1406
1422
|
const short = ranNone(claim, outcome, { order: baselineOrder.get(group.file) }, group.file);
|
|
1407
1423
|
if (short)
|
|
@@ -1420,6 +1436,7 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1420
1436
|
check.result = {
|
|
1421
1437
|
failed: new Set(outcome.tests.filter((test) => test.failed).map((test) => test.test)),
|
|
1422
1438
|
outside: outcome.outside.length > 0,
|
|
1439
|
+
hook: Boolean(outcome.hook),
|
|
1423
1440
|
// A copy no worker took cannot say the tests fail without the
|
|
1424
1441
|
// mutant: the kill stands.
|
|
1425
1442
|
done: outcome.done || !outcome.claimed,
|
|
@@ -1463,9 +1480,13 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1463
1480
|
const missing = expected.filter((id) => !ran.has(id));
|
|
1464
1481
|
if (!missing.length && (ran.size || !claim.wholeFile))
|
|
1465
1482
|
return undefined;
|
|
1483
|
+
// What kept them from running, where the copy said: a hook that
|
|
1484
|
+
// failed, or its file not loading.
|
|
1485
|
+
const why = outcome.hook ?? outcome.loadError;
|
|
1486
|
+
const said = why ? `: ${why.message}` : "";
|
|
1466
1487
|
if (!ran.size)
|
|
1467
|
-
return `its copy of ${file} ran none of the tests it was to run`;
|
|
1468
|
-
return `its copy of ${file} ran ${expected.length - missing.length} of the ${expected.length} tests it was to run`;
|
|
1488
|
+
return `its copy of ${file} ran none of the tests it was to run${said}`;
|
|
1489
|
+
return `its copy of ${file} ran ${expected.length - missing.length} of the ${expected.length} tests it was to run${said}`;
|
|
1469
1490
|
}
|
|
1470
1491
|
async function runContinuous() {
|
|
1471
1492
|
// Each file's baselines: `union` (its mutants' candidates together)
|
|
@@ -1510,7 +1531,7 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1510
1531
|
entry.state = "waiting";
|
|
1511
1532
|
return;
|
|
1512
1533
|
}
|
|
1513
|
-
if (shape === "union" && (!outcome.done || outcome.tests.some((test) => test.failed))) {
|
|
1534
|
+
if (shape === "union" && (!outcome.done || outcome.hook || outcome.tests.some((test) => test.failed))) {
|
|
1514
1535
|
// Recorded, and the file's copies run whole from now on.
|
|
1515
1536
|
entry.state = "known";
|
|
1516
1537
|
entry.done = false;
|
|
@@ -1523,6 +1544,9 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1523
1544
|
entry.order = outcome.tests.map((test) => test.test);
|
|
1524
1545
|
entry.failed = new Set(outcome.tests.filter((test) => test.failed).map((test) => test.test));
|
|
1525
1546
|
entry.outside = outcome.outside.length > 0;
|
|
1547
|
+
// A hook of the file fails without a mutant too: one that fails
|
|
1548
|
+
// with a mutant says nothing of it.
|
|
1549
|
+
entry.hook = Boolean(outcome.hook);
|
|
1526
1550
|
if (outcome.done) {
|
|
1527
1551
|
entry.copyMs = outcome.doneAt - outcome.claimedAt;
|
|
1528
1552
|
let testsMs = 0;
|
|
@@ -1568,8 +1592,7 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1568
1592
|
provide(vitest, { root, stage: directory });
|
|
1569
1593
|
const fileKeyOf = new Map();
|
|
1570
1594
|
const nextIndex = new Map();
|
|
1571
|
-
// Every mutant's files, in the order it would take them
|
|
1572
|
-
// work left first (long chains do not end the pass).
|
|
1595
|
+
// Every mutant's files, in the order it would take them.
|
|
1573
1596
|
// A copy of the whole file costs what its tests took in the measured
|
|
1574
1597
|
// run (its whole baseline may never run).
|
|
1575
1598
|
const estimateC = (group) => shapeOf(group) === "whole"
|
|
@@ -1584,7 +1607,14 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1584
1607
|
job.confirmingKills = 0;
|
|
1585
1608
|
}
|
|
1586
1609
|
const idle = (job) => !job.done && !job.open && !job.confirmingKills;
|
|
1587
|
-
|
|
1610
|
+
// The cheapest mutants first, the plan's order (its estimate)
|
|
1611
|
+
// between equals: a pass cut short -- a budget, a job's time limit --
|
|
1612
|
+
// has decided as many as it could, where the costliest first spent a
|
|
1613
|
+
// large suite's whole budget on a few dozen of them. A worker with
|
|
1614
|
+
// no mutant waiting takes the next file of the one with the most
|
|
1615
|
+
// work left (`besides`), so that long chains do not end the pass.
|
|
1616
|
+
const order = [...pending].sort((a, b) => remainingOf(a) - remainingOf(b));
|
|
1617
|
+
const besides = [...order].reverse();
|
|
1588
1618
|
const rankOf = new Map(order.map((job, rank) => [job, rank]));
|
|
1589
1619
|
const checks = [];
|
|
1590
1620
|
const waiters = [];
|
|
@@ -1685,7 +1715,7 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1685
1715
|
// next file beside it (the most work left first). Its verdict
|
|
1686
1716
|
// is the same either way; a copy its mutant's kill makes moot is
|
|
1687
1717
|
// stopped.
|
|
1688
|
-
for (const job of
|
|
1718
|
+
for (const job of besides) {
|
|
1689
1719
|
if (job.done || job.confirmingKills || !job.open)
|
|
1690
1720
|
continue;
|
|
1691
1721
|
const group = nextOf(job);
|
|
@@ -1820,7 +1850,10 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1820
1850
|
// once; a failure that repeats counts (the mutant may have run in
|
|
1821
1851
|
// a process the copy started).
|
|
1822
1852
|
const unevaluated = (evidence) => evidence?.hits === 0;
|
|
1823
|
-
|
|
1853
|
+
// A hook that failed (its suite's tests skipped), or a file that
|
|
1854
|
+
// did not load or set up, where the file's baseline had neither.
|
|
1855
|
+
const broke = failed || outside ? undefined : outcome.loadError ?? (entry.hook ? undefined : outcome.hook);
|
|
1856
|
+
if (!group.rerunUnevaluated && (unevaluated(failed) || (!failed && unevaluated(outside)) || unevaluated(broke))) {
|
|
1824
1857
|
group.rerunUnevaluated = true;
|
|
1825
1858
|
profile.unevaluatedReruns += 1;
|
|
1826
1859
|
job.ran -= outcome.tests.length;
|
|
@@ -1836,8 +1869,16 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1836
1869
|
: { status: "killed", killedBy: group.file, reason: `an error outside any test: ${outside.message}` });
|
|
1837
1870
|
else if (outcome.hung)
|
|
1838
1871
|
kill(job, group, claim, outcome, { unfinished: true }, { status: "timeout", killedBy: group.file, reason: "its test file stopped before its end, past its limit" });
|
|
1872
|
+
// It broke again before the mutant ran, as it did the first
|
|
1873
|
+
// time: not the mutant's doing, and its tests did not run.
|
|
1874
|
+
else if (unevaluated(broke))
|
|
1875
|
+
finishC(job, { status: "error", reason: `its copy of ${group.file} ${broke.loadError ? "did not load" : "ran no test: a hook failed"} before the mutant ran, twice: ${broke.message}` });
|
|
1839
1876
|
else if (!outcome.done)
|
|
1840
1877
|
kill(job, group, claim, outcome, { unfinished: true }, { status: "killed", killedBy: group.file, reason: "the test file did not finish" });
|
|
1878
|
+
// A hook failed with the mutant, as it does not without it: the
|
|
1879
|
+
// run fails, as Vitest's own does where a hook fails.
|
|
1880
|
+
else if (broke)
|
|
1881
|
+
kill(job, group, claim, outcome, { hook: true }, { status: "killed", killedBy: group.file, reason: `a hook failed: ${broke.message}` });
|
|
1841
1882
|
else if (ranNone(claim, outcome, entry, group.file))
|
|
1842
1883
|
finishC(job, { status: "error", reason: ranNone(claim, outcome, entry, group.file) });
|
|
1843
1884
|
else
|
|
@@ -1858,7 +1899,8 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1858
1899
|
}
|
|
1859
1900
|
const alsoWithout = evidence.test ? result.failed.has(evidence.test)
|
|
1860
1901
|
: evidence.outside ? result.outside
|
|
1861
|
-
:
|
|
1902
|
+
: evidence.hook ? result.hook
|
|
1903
|
+
: !result.done;
|
|
1862
1904
|
if (!alsoWithout) {
|
|
1863
1905
|
finishC(job, verdict);
|
|
1864
1906
|
return;
|
|
@@ -1879,6 +1921,7 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
1879
1921
|
check.result = {
|
|
1880
1922
|
failed: new Set(outcome.tests.filter((test) => test.failed).map((test) => test.test)),
|
|
1881
1923
|
outside: outcome.outside.length > 0,
|
|
1924
|
+
hook: Boolean(outcome.hook),
|
|
1882
1925
|
done: outcome.done || !outcome.claimed,
|
|
1883
1926
|
};
|
|
1884
1927
|
// A run of the whole file with no mutant is its whole baseline.
|