supercov 4.29.19 → 4.30.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 +6 -4
- package/docs/cli.md +13 -7
- package/docs/mutation.md +184 -15
- package/docs/performance.md +68 -0
- package/docs/supported-suites.md +26 -18
- package/package.json +9 -9
- package/runtime/javascript/playwrightStrongReporter.mjs +58 -4
- package/runtime/javascript/register.mjs +10 -1
- package/runtime/javascript/strongAvaHost.mjs +103 -0
- package/runtime/javascript/strongJobs.mjs +101 -17
- package/runtime/javascript/strongVitestHost.mjs +212 -0
- package/runtime/javascript/vitestStrongReporter.mjs +33 -9
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { appendFileSync, existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
13
13
|
import { dirname, join } from "node:path";
|
|
14
14
|
import { pathToFileURL } from "node:url";
|
|
15
|
-
import { attemptPath, baselineOf, entries, invocation, EVERYWHERE, firstWords, giveVerdict, key, loadPass, outcomeOf, placeOf, queuedWork, ranByRequests, readJson, reasonOf, serialFile, settleAttempt, strongPass, unreached, verdictOf, withoutCopy, writeJson } from "./playwrightStrong.mjs";
|
|
15
|
+
import { attemptPath, baselineOf, entries, invocation, EVERYWHERE, firstWords, stripAnsi, giveVerdict, key, loadPass, outcomeOf, placeOf, queuedWork, ranByRequests, readJson, reasonOf, serialFile, settleAttempt, strongPass, unreached, verdictOf, withoutCopy, writeJson } from "./playwrightStrong.mjs";
|
|
16
16
|
|
|
17
17
|
// How often, at most, the status file is written.
|
|
18
18
|
const STATUS_MS = 1_000;
|
|
@@ -114,16 +114,42 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
114
114
|
this.timer = setInterval(() => this.writeStatus(true), 5_000);
|
|
115
115
|
this.timer.unref?.();
|
|
116
116
|
}
|
|
117
|
+
// What a web server or a global setup prints, outside any test, goes to
|
|
118
|
+
// the reporters: this one stands in for the project's, which would
|
|
119
|
+
// have printed it (Playwright's own prefix it, `[WebServer] `), so it
|
|
120
|
+
// passes it on. A build the server's command runs says why it failed
|
|
121
|
+
// there and nowhere else. What a test prints stays its own.
|
|
122
|
+
onStdOut(chunk, test) {
|
|
123
|
+
if (!test)
|
|
124
|
+
process.stdout.write(chunk);
|
|
125
|
+
}
|
|
126
|
+
onStdErr(chunk, test) {
|
|
127
|
+
if (!test)
|
|
128
|
+
process.stderr.write(chunk);
|
|
129
|
+
}
|
|
117
130
|
onTestBegin(test) {
|
|
118
131
|
if (!this.pass)
|
|
119
132
|
return;
|
|
133
|
+
// A test began, so the command started: where no process of it has
|
|
134
|
+
// a mutant on everywhere (any round but one alone), it starts
|
|
135
|
+
// without one, which an alone round's failure is judged against.
|
|
136
|
+
if (!this.begun && this.work?.kind !== "alone")
|
|
137
|
+
markStartedWithoutMutant(this.pass);
|
|
138
|
+
this.begun = true;
|
|
120
139
|
this.running.set(test.id, { title: test.title, begunAt: Date.now() });
|
|
121
140
|
this.writeStatus(false);
|
|
122
141
|
}
|
|
123
142
|
onError(error) {
|
|
124
143
|
// Outside any test: a web server that exited, a global setup that
|
|
125
|
-
// threw.
|
|
126
|
-
|
|
144
|
+
// threw. Said on the command's output, every one, whole: this
|
|
145
|
+
// reporter stands in for the project's, which would have printed
|
|
146
|
+
// it, and the judge's record below keeps only the first one's words.
|
|
147
|
+
if (!this.pass)
|
|
148
|
+
return;
|
|
149
|
+
const text = stripAnsi(String(error?.stack ?? error?.message ?? error));
|
|
150
|
+
console.error(`[supercov] the command reported an error outside any test: ${text}`);
|
|
151
|
+
// Each invocation's first one's time and words, for the judge.
|
|
152
|
+
if (this.erred)
|
|
127
153
|
return;
|
|
128
154
|
this.erred = true;
|
|
129
155
|
writeJson(`${this.pass.round}/errors/${process.pid}.json`, { pid: process.pid, at: Date.now(), message: firstWords(error?.message ?? error) });
|
|
@@ -266,6 +292,11 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
266
292
|
clearInterval(this.timer);
|
|
267
293
|
this.running.clear();
|
|
268
294
|
this.writeStatus(true);
|
|
295
|
+
// A command that failed before any test began (a web server that
|
|
296
|
+
// would not start, a global setup that threw) failed: it says so by
|
|
297
|
+
// its exit code, and Supercov shows and keeps its output.
|
|
298
|
+
if (this.erred && !this.begun)
|
|
299
|
+
return undefined;
|
|
269
300
|
// A killed mutant fails a test, and that is the point: the command's
|
|
270
301
|
// outcome is the pass's, not the tests'. The verdicts are the
|
|
271
302
|
// judge's, once every invocation has ended.
|
|
@@ -425,8 +456,16 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
425
456
|
// the whole command started with it, which says whether it was the
|
|
426
457
|
// mutant's doing.) An error after the round began to stop is the
|
|
427
458
|
// stop's: its servers went down under it.
|
|
459
|
+
// That is the mutant's doing only where the command starts without
|
|
460
|
+
// it: some round of this pass began a test with no mutant on
|
|
461
|
+
// everywhere. Where none did, the command fails without any
|
|
462
|
+
// mutant too (a build of the pass's copy that fails), and the
|
|
463
|
+
// failure says nothing of this one: no verdict.
|
|
428
464
|
if (kind === "alone" && !work.batch && globalError && globalError.at < stoppedAt && !ended.length) {
|
|
429
|
-
|
|
465
|
+
if (startedWithoutMutant(pass))
|
|
466
|
+
verdict({ status: "killed", reason: `the command failed with it switched on (${globalError.message})${suffix}` });
|
|
467
|
+
else
|
|
468
|
+
verdict({ status: "error", reason: `the command failed with it switched on (${globalError.message}), and no run of it in this pass got as far as a test without a mutant${suffix}` });
|
|
430
469
|
continue;
|
|
431
470
|
}
|
|
432
471
|
// Its invocation's server never ran it: alone, the whole command
|
|
@@ -572,6 +611,21 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
572
611
|
}
|
|
573
612
|
}
|
|
574
613
|
|
|
614
|
+
// Whether some round of the pass began a test in a command with no mutant
|
|
615
|
+
// on everywhere: the command starts without one.
|
|
616
|
+
function markStartedWithoutMutant(pass) {
|
|
617
|
+
try {
|
|
618
|
+
writeJson(`${pass.shared}/started-without-mutant`, Date.now());
|
|
619
|
+
}
|
|
620
|
+
catch {
|
|
621
|
+
// Unmarked, an alone round's failure decides nothing.
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function startedWithoutMutant(pass) {
|
|
626
|
+
return existsSync(`${pass.shared}/started-without-mutant`);
|
|
627
|
+
}
|
|
628
|
+
|
|
575
629
|
/** A round as its first line says it. */
|
|
576
630
|
function describeRound(work) {
|
|
577
631
|
if (work.kind === "main")
|
|
@@ -10,6 +10,7 @@ import Module, { register, syncBuiltinESMExports } from "node:module";
|
|
|
10
10
|
import fs, { closeSync, openSync, readFileSync, realpathSync, unlinkSync } from "node:fs";
|
|
11
11
|
import path, { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { isMainThread } from "node:worker_threads";
|
|
13
14
|
import { installLaunchSupervisor, wrapImportedCapability } from "./launchSupervisor.mjs";
|
|
14
15
|
import { __supercovBindCapabilityWrapper } from "./capability.mjs";
|
|
15
16
|
import { adaptRunnerEntry, noteSkippedCoverageThresholds } from "./runnerEntry.mjs";
|
|
@@ -41,7 +42,15 @@ const isNpmItself = (() => {
|
|
|
41
42
|
return false;
|
|
42
43
|
}
|
|
43
44
|
})();
|
|
44
|
-
|
|
45
|
+
// Nor in a worker thread. Node writes a thread's compiled code as the
|
|
46
|
+
// thread ends, a temporary file and a rename for each module it compiled, and
|
|
47
|
+
// a runner waits for its worker to end: AVA stops a file whose worker sends
|
|
48
|
+
// nothing for 10 s ("Timed out while running tests", "Failed to exit"). On a
|
|
49
|
+
// disk busy with other writes, each rename took 0.2 s, and the two workers
|
|
50
|
+
// of a two-file suite spent most of a minute ending: 20 of 24 runs failed
|
|
51
|
+
// where AVA alone passed. A worker thread compiles as it would without
|
|
52
|
+
// Supercov; a process keeps the cache.
|
|
53
|
+
if (!isNpmItself && isMainThread)
|
|
45
54
|
enableNodeCompileCache(process.env.SUPERCOV_COMPILE_CACHE);
|
|
46
55
|
installLaunchSupervisor();
|
|
47
56
|
// Playwright's compile cache, written whole (atomic.mjs says why).
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// A resident AVA for a strong pass's jobs (strongJobs.mjs): one process that
|
|
2
|
+
// keeps AVA's command loaded, its configuration read and its options worked
|
|
3
|
+
// out, and runs one job after another, where each job started the command.
|
|
4
|
+
//
|
|
5
|
+
// AVA runs every test file in a worker of its own (a worker thread, or a
|
|
6
|
+
// child process under --no-worker-threads), made for the file as the run
|
|
7
|
+
// starts and given the main process's environment as it is then, so each
|
|
8
|
+
// job's file and the code it tests load afresh, with the job's mutant on
|
|
9
|
+
// from the worker's start, as in a command of its own. This process loads
|
|
10
|
+
// none of the project's code: the command's main process does not either. Between runs the main
|
|
11
|
+
// process keeps only what AVA's own watch mode keeps between its reruns:
|
|
12
|
+
// its options and its cache directory.
|
|
13
|
+
//
|
|
14
|
+
// The options are AVA's command's own: the host runs AVA's command
|
|
15
|
+
// (`lib/cli.js`) with the command's arguments and takes the Api it makes as
|
|
16
|
+
// it would start its first run. It refuses (the driver starts the command
|
|
17
|
+
// for each job, as before) where the command watches or debugs, or where
|
|
18
|
+
// AVA's command ends instead (a configuration it rejects).
|
|
19
|
+
//
|
|
20
|
+
// The driver forks it in the project's copy and sends
|
|
21
|
+
// { type: "init", args: [<the command's arguments to ava>] }
|
|
22
|
+
// { type: "job", id, file: <absolute test file>, mutant: { file, index } | null, environment: {...} }
|
|
23
|
+
// and it answers { type: "ready", error? } and { type: "done", id, error?, tainted? }:
|
|
24
|
+
// `tainted` that this process runs no further job.
|
|
25
|
+
import { realpathSync } from "node:fs";
|
|
26
|
+
import { createRequire, syncBuiltinESMExports } from "node:module";
|
|
27
|
+
import { join } from "node:path";
|
|
28
|
+
import { pathToFileURL } from "node:url";
|
|
29
|
+
import threads from "node:worker_threads";
|
|
30
|
+
|
|
31
|
+
const root = process.cwd();
|
|
32
|
+
// A shared worker (AVA's plugin API) lives as long as the main process: in a
|
|
33
|
+
// command, one job's; here, every later job's too. A job that starts one
|
|
34
|
+
// is the host's last.
|
|
35
|
+
let sharedWorker = false;
|
|
36
|
+
{
|
|
37
|
+
const { Worker } = threads;
|
|
38
|
+
threads.Worker = class extends Worker {
|
|
39
|
+
constructor(file, ...rest) {
|
|
40
|
+
if (/shared-worker-loader/.test(String(file)))
|
|
41
|
+
sharedWorker = true;
|
|
42
|
+
super(file, ...rest);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
syncBuiltinESMExports();
|
|
46
|
+
}
|
|
47
|
+
let api;
|
|
48
|
+
let run;
|
|
49
|
+
let runOptions;
|
|
50
|
+
|
|
51
|
+
async function init(args) {
|
|
52
|
+
if (args.some((argument) => /^(?:-w|--watch|debug|reset-cache)$/.test(argument)))
|
|
53
|
+
throw new Error("the command watches, debugs or resets AVA's cache");
|
|
54
|
+
process.env.SUPERCOV_STRONG_PLAN = "";
|
|
55
|
+
process.env.SUPERCOV_ACTIVE_MUTANT = "-";
|
|
56
|
+
// The installed package, by its real path: AVA's command loads its Api
|
|
57
|
+
// from there, and only that module's Api is the one it makes.
|
|
58
|
+
const main = realpathSync(createRequire(join(root, "package.json")).resolve("ava"));
|
|
59
|
+
const at = main.replaceAll("\\", "/").lastIndexOf("/node_modules/ava/");
|
|
60
|
+
if (at < 0)
|
|
61
|
+
throw new Error(`AVA is not where a package is: ${main}`);
|
|
62
|
+
const avaRoot = main.slice(0, at + "/node_modules/ava".length);
|
|
63
|
+
const load = async (name) => import(pathToFileURL(join(avaRoot, "lib", name)).href);
|
|
64
|
+
const { default: Api } = await load("api.js");
|
|
65
|
+
run = Api.prototype.run;
|
|
66
|
+
// AVA's command makes its Api from the command line and the project's
|
|
67
|
+
// configuration, and starts its run: the run is taken here instead, with
|
|
68
|
+
// what the command asked of it (its files, its line numbers).
|
|
69
|
+
const made = new Promise((resolveMade) => {
|
|
70
|
+
Api.prototype.run = function capture(options) {
|
|
71
|
+
resolveMade({ api: this, options });
|
|
72
|
+
return new Promise(() => { });
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
process.argv = [process.execPath, join(avaRoot, "entrypoints", "cli.mjs"), ...args];
|
|
76
|
+
const { default: loadCli } = await load("cli.js");
|
|
77
|
+
const exited = loadCli().then(() => {
|
|
78
|
+
throw new Error("AVA's command ended without starting a run");
|
|
79
|
+
});
|
|
80
|
+
({ api, options: runOptions } = await Promise.race([made, exited]));
|
|
81
|
+
Api.prototype.run = run;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// A job runs what the command runs, as the command's own run would: every
|
|
85
|
+
// test file in a worker of its own, where the adapter runs only the job's
|
|
86
|
+
// tests (strongJob.mjs). The workers take the environment as it is when the
|
|
87
|
+
// run makes them.
|
|
88
|
+
async function runJob({ environment, mutant }) {
|
|
89
|
+
Object.assign(process.env, environment, { SUPERCOV_ACTIVE_MUTANT: mutant ? `${mutant.file}#${mutant.index}` : "-" });
|
|
90
|
+
await run.call(api, runOptions);
|
|
91
|
+
return sharedWorker ? { tainted: true } : {};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
process.on("message", (message) => {
|
|
95
|
+
const reply = (answer) => process.send?.(answer);
|
|
96
|
+
if (message?.type === "init") {
|
|
97
|
+
init(message.args ?? []).then(() => reply({ type: "ready" }), (error) => reply({ type: "ready", error: String(error?.stack ?? error) }));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (message?.type === "job")
|
|
101
|
+
runJob(message).then((outcome) => reply({ type: "done", id: message.id, ...outcome }), (error) => reply({ type: "done", id: message.id, error: String(error?.stack ?? error), tainted: true }));
|
|
102
|
+
});
|
|
103
|
+
process.send?.({ type: "started" });
|
|
@@ -247,6 +247,20 @@ export function mochaArguments(command) {
|
|
|
247
247
|
return at < 0 ? undefined : command.slice(at + 1);
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
// The arguments a command gives AVA, where it starts AVA itself (`ava`,
|
|
251
|
+
// `npx ava`, `node_modules/.bin/ava`, AVA's `entrypoints/cli.mjs`).
|
|
252
|
+
export function avaArguments(command) {
|
|
253
|
+
const at = command.findIndex((word) => /(?:^|[\\/])ava$/.test(word) || /ava[\\/]entrypoints[\\/]cli\.mjs$/.test(word));
|
|
254
|
+
return at < 0 ? undefined : command.slice(at + 1);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// The arguments a command gives Vitest, where it starts Vitest itself
|
|
258
|
+
// (`vitest run`, `npx vitest`, `node_modules/.bin/vitest`).
|
|
259
|
+
export function vitestArguments(command) {
|
|
260
|
+
const at = command.findIndex((word) => /(?:^|[\\/])vitest(?:\.m?js)?$/.test(word));
|
|
261
|
+
return at < 0 ? undefined : command.slice(at + 1);
|
|
262
|
+
}
|
|
263
|
+
|
|
250
264
|
// Whether a project's .js files are CommonJS (its package.json has no
|
|
251
265
|
// `"type": "module"`).
|
|
252
266
|
export function packageIsCommonJs(root) {
|
|
@@ -261,7 +275,7 @@ export function packageIsCommonJs(root) {
|
|
|
261
275
|
// Resident runners (strongJestHost.mjs, strongMochaHost.mjs), each running one
|
|
262
276
|
// job at a time. A host whose job passes its limit is stopped, and the next
|
|
263
277
|
// job starts another.
|
|
264
|
-
function residentHosts({ script, args, root, environment, log }) {
|
|
278
|
+
function residentHosts({ script, args, root, environment, log, asCommand = false }) {
|
|
265
279
|
const idle = [];
|
|
266
280
|
const all = new Set();
|
|
267
281
|
const host = () => new Promise((resolveHost, rejectHost) => {
|
|
@@ -330,8 +344,12 @@ function residentHosts({ script, args, root, environment, log }) {
|
|
|
330
344
|
};
|
|
331
345
|
const answered = (message) => {
|
|
332
346
|
if (message?.type === "done" && message.id === id) {
|
|
333
|
-
|
|
334
|
-
|
|
347
|
+
// A host that can run no further job is stopped.
|
|
348
|
+
if (message.tainted)
|
|
349
|
+
stop(child);
|
|
350
|
+
else
|
|
351
|
+
idle.push(child);
|
|
352
|
+
settle({ timedOut: false, error: message.error, fallback: message.fallback, tainted: message.tainted });
|
|
335
353
|
}
|
|
336
354
|
};
|
|
337
355
|
const exited = () => settle({ timedOut: false, error: "the resident runner ended" });
|
|
@@ -348,6 +366,10 @@ function residentHosts({ script, args, root, environment, log }) {
|
|
|
348
366
|
for (const child of all)
|
|
349
367
|
stop(child);
|
|
350
368
|
},
|
|
369
|
+
// Whether a job it stops at its limit, and a baseline that does not
|
|
370
|
+
// pass in it, run again as commands (the runners whose jobs used to
|
|
371
|
+
// start the command, and whose limits came from such a start).
|
|
372
|
+
asCommand,
|
|
351
373
|
};
|
|
352
374
|
}
|
|
353
375
|
|
|
@@ -442,6 +464,18 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
442
464
|
// (SUPERCOV_STRONG_MOCHA_ESM=process: a process per job instead).
|
|
443
465
|
const esmHosts = residentHosts({ script: "strongMochaHost.mjs", args: mochaArgs, root, environment: { ...environment, SUPERCOV_MOCHA_FRESH_WORKERS: "1" }, log: join(work, "mocha-esm-hosts.log") });
|
|
444
466
|
const esmResident = process.env.SUPERCOV_STRONG_MOCHA_ESM !== "process";
|
|
467
|
+
// Vitest Browser Mode: a resident Vitest, its Vite server and its
|
|
468
|
+
// browser kept for job after job, each job in fresh browser contexts
|
|
469
|
+
// (strongVitestHost.mjs). A file it cannot run as a command would runs
|
|
470
|
+
// as a command from then on (`commandOnly`).
|
|
471
|
+
const vitestArgs = residentAllowed ? vitestArguments(withoutNpx(command, root)) : undefined;
|
|
472
|
+
const vitestHosts = residentHosts({ script: "strongVitestHost.mjs", args: vitestArgs, root, environment: { ...environment, SUPERCOV_STRONG_PLAN: "" }, log: join(work, "vitest-hosts.log"), asCommand: true });
|
|
473
|
+
const commandOnly = new Set();
|
|
474
|
+
// AVA: a resident AVA, its command's options worked out once, each job's
|
|
475
|
+
// test files in fresh workers as the command's own run makes them
|
|
476
|
+
// (strongAvaHost.mjs).
|
|
477
|
+
const avaArgs = residentAllowed ? avaArguments(withoutNpx(command, root)) : undefined;
|
|
478
|
+
const avaHosts = residentHosts({ script: "strongAvaHost.mjs", args: avaArgs, root, environment: { ...environment, SUPERCOV_STRONG_PLAN: "" }, log: join(work, "ava-hosts.log"), asCommand: true });
|
|
445
479
|
const commonJs = packageIsCommonJs(root);
|
|
446
480
|
const broken = new Set();
|
|
447
481
|
const residentFor = (file) => {
|
|
@@ -454,6 +488,10 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
454
488
|
return mochaHosts;
|
|
455
489
|
if (runner === "mocha" && mochaArgs && esmResident)
|
|
456
490
|
return esmHosts;
|
|
491
|
+
if (runner === "vitest-browser" && vitestArgs && !commandOnly.has(file))
|
|
492
|
+
return vitestHosts;
|
|
493
|
+
if (runner === "ava" && avaArgs && !commandOnly.has(file))
|
|
494
|
+
return avaHosts;
|
|
457
495
|
return undefined;
|
|
458
496
|
};
|
|
459
497
|
// Rust compiled to wasm (SUPERCOV_WASM_STRONG): a job that starts the
|
|
@@ -488,7 +526,7 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
488
526
|
});
|
|
489
527
|
return handed ? parallel(work, priority) : result;
|
|
490
528
|
};
|
|
491
|
-
const profile = { jobs: 0, baselines: 0, confirmations: 0, overturned: 0, stopped: 0, alone: 0, jobMs: 0 };
|
|
529
|
+
const profile = { jobs: 0, baselines: 0, confirmations: 0, overturned: 0, stopped: 0, alone: 0, jobMs: 0, residentJobs: 0, residentFallbacks: 0 };
|
|
492
530
|
const machine = turns();
|
|
493
531
|
let jobNumber = 0;
|
|
494
532
|
|
|
@@ -498,7 +536,7 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
498
536
|
// so that the kills most mutants get at once come first, and a
|
|
499
537
|
// survivor's many files fill what is left. One run `alone` waits for no
|
|
500
538
|
// slot: it has the machine to itself.
|
|
501
|
-
function job({ mutant, file, tests: chosen, bail, limitMs, priority = 0, alone = false }) {
|
|
539
|
+
function job({ mutant, file, tests: chosen, bail, limitMs, priority = 0, alone = false, command: asCommand = false }) {
|
|
502
540
|
const start = (work) => (alone ? machine.alone(work) : run(() => machine.shared(work), priority));
|
|
503
541
|
return start((turn) => new Promise((resolveJob) => {
|
|
504
542
|
const number = ++jobNumber;
|
|
@@ -510,7 +548,7 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
510
548
|
writeFileSync(spec, JSON.stringify({ files: { [file]: chosen === null ? null : [...chosen] }, known, bail, mutant: mutant ? `${mutant.file}#${mutant.index}` : null }));
|
|
511
549
|
const results = join(directory, "results.jsonl");
|
|
512
550
|
const begun = Date.now();
|
|
513
|
-
const resident = residentFor(file);
|
|
551
|
+
const resident = asCommand ? undefined : residentFor(file);
|
|
514
552
|
// A job's outcome, read from its evidence; then its directory is
|
|
515
553
|
// removed, as nothing after reads it (a job's evidence ran to
|
|
516
554
|
// 24 MB on nanoid, a gigabyte a pass).
|
|
@@ -603,18 +641,42 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
603
641
|
SUPERCOV_STRONG_RESULTS: results,
|
|
604
642
|
SUPERCOV_STRONG_PLAN: "",
|
|
605
643
|
};
|
|
606
|
-
resident.run({ file: join(root, file), mutant: mutant ? { file: mutant.file, index: mutant.index } : null, environment: environmentOfJob }, limitMs).then(({ timedOut, error, notStarted }) => {
|
|
644
|
+
resident.run({ file: join(root, file), mutant: mutant ? { file: mutant.file, index: mutant.index } : null, environment: environmentOfJob }, limitMs).then(({ timedOut, error, notStarted, fallback, tainted }) => {
|
|
607
645
|
if (notStarted) {
|
|
608
646
|
broken.add(runnerOf.get(file));
|
|
609
647
|
spawnJob();
|
|
610
648
|
return;
|
|
611
649
|
}
|
|
650
|
+
// The resident runner did not run the job as the command
|
|
651
|
+
// would have: the command runs it, from a clean slate.
|
|
652
|
+
if (fallback !== undefined) {
|
|
653
|
+
profile.residentFallbacks += 1;
|
|
654
|
+
try {
|
|
655
|
+
appendFileSync(join(work, "resident-fallbacks.log"), `${file}: ${fallback}\n`);
|
|
656
|
+
}
|
|
657
|
+
catch {
|
|
658
|
+
// The log is for reading only.
|
|
659
|
+
}
|
|
660
|
+
if (tainted)
|
|
661
|
+
broken.add(runnerOf.get(file));
|
|
662
|
+
else
|
|
663
|
+
commandOnly.add(file);
|
|
664
|
+
rmSync(evidence, { recursive: true, force: true });
|
|
665
|
+
mkdirSync(evidence, { recursive: true });
|
|
666
|
+
rmSync(`${results}.timeouts.jsonl`, { force: true });
|
|
667
|
+
spawnJob();
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if (tainted)
|
|
671
|
+
broken.add(runnerOf.get(file));
|
|
672
|
+
profile.residentJobs += 1;
|
|
612
673
|
if (timedOut)
|
|
613
674
|
profile.stopped += 1;
|
|
614
675
|
profile.jobMs += Date.now() - begun;
|
|
615
676
|
const mutantKey = mutant ? `${mutant.file}#${mutant.index}` : undefined;
|
|
616
677
|
resolveJob(read({
|
|
617
678
|
timedOut,
|
|
679
|
+
resident: resident.asCommand,
|
|
618
680
|
mutantTimedOut: mutantKey !== undefined && readTimeouts(`${results}.timeouts.jsonl`).includes(mutantKey),
|
|
619
681
|
exitCode: error ? 1 : 0,
|
|
620
682
|
error,
|
|
@@ -640,23 +702,39 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
640
702
|
async function wholeBaseline(file) {
|
|
641
703
|
const state = fileState(file);
|
|
642
704
|
state.whole ??= (async () => {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
705
|
+
const once = async () => {
|
|
706
|
+
profile.baselines += 1;
|
|
707
|
+
const result = await job({ mutant: null, file, tests: null, bail: false, limitMs: baselineLimit(file, null) });
|
|
708
|
+
const passing = new Set([...result.statuses].filter(([, status]) => status === "passed").map(([id]) => id));
|
|
709
|
+
return { ...result, passing, finished: !result.timedOut && passing.size > 0 };
|
|
710
|
+
};
|
|
711
|
+
return commandWhereResidentFails(file, once, (result) => result.finished && [...result.statuses.values()].every((status) => status === "passed" || status === "skipped"));
|
|
647
712
|
})();
|
|
648
713
|
return state.whole;
|
|
649
714
|
}
|
|
715
|
+
// A baseline the resident runner ran that did not pass as it should is
|
|
716
|
+
// run again as a command, and the file's jobs are the command's from
|
|
717
|
+
// then on: what a test does without a mutant is the command's to say.
|
|
718
|
+
async function commandWhereResidentFails(file, once, clean) {
|
|
719
|
+
const result = await once();
|
|
720
|
+
if (!result.resident || clean(result))
|
|
721
|
+
return result;
|
|
722
|
+
commandOnly.add(file);
|
|
723
|
+
return once();
|
|
724
|
+
}
|
|
650
725
|
// The baseline a mutant's job in `file` is judged by: the subset's where
|
|
651
726
|
// it stood for the file, else the whole file's.
|
|
652
727
|
async function baselineFor(file) {
|
|
653
728
|
const state = fileState(file);
|
|
654
729
|
if (!state.wholeNeeded && state.union.size > 0) {
|
|
655
730
|
state.subset ??= (async () => {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
731
|
+
const once = async () => {
|
|
732
|
+
profile.baselines += 1;
|
|
733
|
+
const chosen = new Set(state.union);
|
|
734
|
+
const result = await job({ mutant: null, file, tests: chosen, bail: false, limitMs: baselineLimit(file, chosen) });
|
|
735
|
+
return { ...result, chosen, finished: passedAll(result, chosen) };
|
|
736
|
+
};
|
|
737
|
+
return commandWhereResidentFails(file, once, (result) => result.finished);
|
|
660
738
|
})();
|
|
661
739
|
const subset = await state.subset;
|
|
662
740
|
if (subset.finished)
|
|
@@ -702,9 +780,13 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
702
780
|
// machine's speed now.
|
|
703
781
|
if (result.timedOut && !result.mutantTimedOut && killerIn(result) === undefined) {
|
|
704
782
|
profile.alone += 1;
|
|
705
|
-
|
|
783
|
+
// A resident runner's limit is tighter than a command's, which
|
|
784
|
+
// starts the runner and the browser within it: the job runs
|
|
785
|
+
// again as a command, with a command's limit.
|
|
786
|
+
const asCommand = Boolean(result.resident);
|
|
787
|
+
const now = await job({ mutant: null, file: group.file, tests: chosen, bail: false, limitMs: baselineLimit(group.file, chosen), alone: true, command: asCommand });
|
|
706
788
|
const slowest = Math.max(baseline.durationMs, now.durationMs);
|
|
707
|
-
result = await job({ mutant, file: group.file, tests: chosen, bail, limitMs: 3 * slowest + aloneGraceMs, alone: true });
|
|
789
|
+
result = await job({ mutant, file: group.file, tests: chosen, bail, limitMs: 3 * slowest + aloneGraceMs, alone: true, command: asCommand });
|
|
708
790
|
}
|
|
709
791
|
const ran = [...result.statuses].filter(([id, status]) => status !== "skipped" && (chosen === null || chosen.has(id)));
|
|
710
792
|
const killer = killerIn(result);
|
|
@@ -852,6 +934,8 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
852
934
|
jestHosts.close();
|
|
853
935
|
mochaHosts.close();
|
|
854
936
|
esmHosts.close();
|
|
937
|
+
vitestHosts.close();
|
|
938
|
+
avaHosts.close();
|
|
855
939
|
write({ summary: true, driver: "jobs", workers, ...profile, durationMs: Date.now() - started });
|
|
856
940
|
return 0;
|
|
857
941
|
}
|