supercov 4.29.2 → 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/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();
|