supercov 4.29.19 → 4.30.1
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 +331 -23
- package/runtime/javascript/strongVitestHost.mjs +212 -0
- package/runtime/javascript/vitestStrongReporter.mjs +33 -9
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
// copy, with the plan (SUPERCOV_STRONG_PLAN) and where the verdicts go
|
|
6
6
|
// (SUPERCOV_STRONG_RESULTS).
|
|
7
7
|
//
|
|
8
|
+
// A command that builds and then tests (`sh -c "<build> && <tests>"`) is
|
|
9
|
+
// split by the engine: the driver runs the build once, before any job, and
|
|
10
|
+
// each job starts the tests' steps (`buildOnce`).
|
|
11
|
+
//
|
|
8
12
|
// Each job is one start of the command for one test file: the mutant on in
|
|
9
13
|
// every process from its start (SUPERCOV_ACTIVE_MUTANT), only the job's tests
|
|
10
14
|
// run (SUPERCOV_STRONG_JOB, read by the runner's adapter through
|
|
@@ -28,7 +32,7 @@
|
|
|
28
32
|
// mutant, and its limit there is 3x the slower of that run and its
|
|
29
33
|
// baseline, and 10 s: only a job past that is a timeout.
|
|
30
34
|
import { fork, spawn } from "node:child_process";
|
|
31
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
35
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
32
36
|
import { availableParallelism, constants, cpus } from "node:os";
|
|
33
37
|
import { basename, delimiter, dirname, join, resolve } from "node:path";
|
|
34
38
|
import { fileURLToPath } from "node:url";
|
|
@@ -215,9 +219,157 @@ export function commandFor(command, file, root = process.cwd(), runner = undefin
|
|
|
215
219
|
return [process.execPath, file];
|
|
216
220
|
if (program && /^bun(?:\.exe)?$/.test(basename(program)) && first === "test")
|
|
217
221
|
return [...command, `./${file}`];
|
|
222
|
+
if (runner === "node:test") {
|
|
223
|
+
const narrowed = nodeTestFor(command, file, root);
|
|
224
|
+
if (narrowed)
|
|
225
|
+
return narrowed;
|
|
226
|
+
}
|
|
218
227
|
return withoutNpx(command, root);
|
|
219
228
|
}
|
|
220
229
|
|
|
230
|
+
// Node's options that take a value as the next word (`--import tsx`); one
|
|
231
|
+
// written `--name=value` takes none.
|
|
232
|
+
const NODE_VALUE_OPTIONS = new Set([
|
|
233
|
+
"--import", "--require", "-r", "--loader", "--experimental-loader", "--conditions", "-C",
|
|
234
|
+
"--env-file", "--env-file-if-exists", "--input-type", "--title", "--inspect-port",
|
|
235
|
+
"--test-reporter", "--test-reporter-destination", "--test-concurrency", "--test-timeout",
|
|
236
|
+
"--test-name-pattern", "--test-skip-pattern", "--test-shard", "--test-isolation",
|
|
237
|
+
"--test-coverage-include", "--test-coverage-exclude", "--test-coverage-branches",
|
|
238
|
+
"--test-coverage-functions", "--test-coverage-lines", "--test-global-setup", "--watch-path",
|
|
239
|
+
]);
|
|
240
|
+
|
|
241
|
+
// `node [options] --test [patterns]` with the patterns replaced by the job's
|
|
242
|
+
// file, as words, or undefined where `words` is not such a command. Node
|
|
243
|
+
// starts a process for each test file its patterns name, and a file the job
|
|
244
|
+
// does not run still costs that process its start and its loaders: a job
|
|
245
|
+
// on supergateway, whose 227 files each load tsx, took 45 s to run one
|
|
246
|
+
// file's tests, and its baseline passed its limit beside the jobs next to it.
|
|
247
|
+
// A word that may be the value of an option this does not know (one that is
|
|
248
|
+
// no test file, directory or glob) leaves the command as it is.
|
|
249
|
+
export function nodeTestWords(words, file, root) {
|
|
250
|
+
let at = 0;
|
|
251
|
+
while (at < words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[at]))
|
|
252
|
+
at += 1;
|
|
253
|
+
if (!/^node(?:\.exe)?$/.test(basename(words[at] ?? "")))
|
|
254
|
+
return undefined;
|
|
255
|
+
const kept = words.slice(0, at + 1);
|
|
256
|
+
let test = false;
|
|
257
|
+
for (let index = at + 1; index < words.length; index += 1) {
|
|
258
|
+
const word = words[index];
|
|
259
|
+
if (word === "--")
|
|
260
|
+
return undefined;
|
|
261
|
+
if (word === "--test") {
|
|
262
|
+
test = true;
|
|
263
|
+
kept.push(word);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (word.startsWith("-")) {
|
|
267
|
+
kept.push(word);
|
|
268
|
+
if (!word.includes("=") && NODE_VALUE_OPTIONS.has(word)) {
|
|
269
|
+
if (index + 1 >= words.length)
|
|
270
|
+
return undefined;
|
|
271
|
+
kept.push(words[++index]);
|
|
272
|
+
}
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const names = /[*?[{]/.test(word) || /\.[cm]?[jt]sx?$/.test(word) || isDirectory(join(root, word));
|
|
276
|
+
if (!names)
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
return test ? [...kept, `./${file}`] : undefined;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function isDirectory(path) {
|
|
283
|
+
try {
|
|
284
|
+
return statSync(path).isDirectory();
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// The command for a node:test job: `node ... --test` with only the job's
|
|
292
|
+
// file (`nodeTestWords`), itself or as the one command of a shell's `-c`
|
|
293
|
+
// script (the tests' steps of a command that builds first).
|
|
294
|
+
function nodeTestFor(command, file, root) {
|
|
295
|
+
const [program, flag, script, ...rest] = command;
|
|
296
|
+
if (/^(?:sh|bash|dash|zsh)$/.test(basename(program ?? "")) && flag === "-c" && typeof script === "string" && rest.length === 0) {
|
|
297
|
+
const words = shellWords(script);
|
|
298
|
+
const narrowed = words && nodeTestWords(words, file, root);
|
|
299
|
+
return narrowed && [program, flag, narrowed.map(shellQuoted).join(" ")];
|
|
300
|
+
}
|
|
301
|
+
return nodeTestWords(command, file, root);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// A shell script's words, unquoted, where it is one simple command: no
|
|
305
|
+
// operator, substitution, expansion, redirection or line break outside
|
|
306
|
+
// single quotes. Undefined for any other script.
|
|
307
|
+
export function shellWords(script) {
|
|
308
|
+
const words = [];
|
|
309
|
+
let word;
|
|
310
|
+
let single = false;
|
|
311
|
+
let double = false;
|
|
312
|
+
for (let index = 0; index < script.length; index += 1) {
|
|
313
|
+
const c = script[index];
|
|
314
|
+
if (single) {
|
|
315
|
+
if (c === "'")
|
|
316
|
+
single = false;
|
|
317
|
+
else
|
|
318
|
+
word += c;
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (c === "\\") {
|
|
322
|
+
const next = script[index + 1];
|
|
323
|
+
if (next === undefined || next === "\n")
|
|
324
|
+
return undefined;
|
|
325
|
+
if (double && !"$`\"\\".includes(next))
|
|
326
|
+
word = (word ?? "") + c;
|
|
327
|
+
word = (word ?? "") + next;
|
|
328
|
+
index += 1;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (double) {
|
|
332
|
+
if (c === "\"")
|
|
333
|
+
double = false;
|
|
334
|
+
else if (c === "$" || c === "`")
|
|
335
|
+
return undefined;
|
|
336
|
+
else
|
|
337
|
+
word += c;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (c === "'") {
|
|
341
|
+
single = true;
|
|
342
|
+
word ??= "";
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (c === "\"") {
|
|
346
|
+
double = true;
|
|
347
|
+
word ??= "";
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (c === " " || c === "\t") {
|
|
351
|
+
if (word !== undefined)
|
|
352
|
+
words.push(word);
|
|
353
|
+
word = undefined;
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if ("|&;()<>$`\n\r#~".includes(c))
|
|
357
|
+
return undefined;
|
|
358
|
+
word = (word ?? "") + c;
|
|
359
|
+
}
|
|
360
|
+
if (single || double)
|
|
361
|
+
return undefined;
|
|
362
|
+
if (word !== undefined)
|
|
363
|
+
words.push(word);
|
|
364
|
+
return words.length ? words : undefined;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// A word as a POSIX shell reads it back: as it is where nothing in it is
|
|
368
|
+
// special, else in single quotes.
|
|
369
|
+
export function shellQuoted(word) {
|
|
370
|
+
return /^[A-Za-z0-9_@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
371
|
+
}
|
|
372
|
+
|
|
221
373
|
// `npx <tool> ...` where the project has the tool: the tool itself. npx
|
|
222
374
|
// costs a start of npm's CLI before each job's, a third of a small suite's
|
|
223
375
|
// job.
|
|
@@ -247,6 +399,20 @@ export function mochaArguments(command) {
|
|
|
247
399
|
return at < 0 ? undefined : command.slice(at + 1);
|
|
248
400
|
}
|
|
249
401
|
|
|
402
|
+
// The arguments a command gives AVA, where it starts AVA itself (`ava`,
|
|
403
|
+
// `npx ava`, `node_modules/.bin/ava`, AVA's `entrypoints/cli.mjs`).
|
|
404
|
+
export function avaArguments(command) {
|
|
405
|
+
const at = command.findIndex((word) => /(?:^|[\\/])ava$/.test(word) || /ava[\\/]entrypoints[\\/]cli\.mjs$/.test(word));
|
|
406
|
+
return at < 0 ? undefined : command.slice(at + 1);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// The arguments a command gives Vitest, where it starts Vitest itself
|
|
410
|
+
// (`vitest run`, `npx vitest`, `node_modules/.bin/vitest`).
|
|
411
|
+
export function vitestArguments(command) {
|
|
412
|
+
const at = command.findIndex((word) => /(?:^|[\\/])vitest(?:\.m?js)?$/.test(word));
|
|
413
|
+
return at < 0 ? undefined : command.slice(at + 1);
|
|
414
|
+
}
|
|
415
|
+
|
|
250
416
|
// Whether a project's .js files are CommonJS (its package.json has no
|
|
251
417
|
// `"type": "module"`).
|
|
252
418
|
export function packageIsCommonJs(root) {
|
|
@@ -261,7 +427,7 @@ export function packageIsCommonJs(root) {
|
|
|
261
427
|
// Resident runners (strongJestHost.mjs, strongMochaHost.mjs), each running one
|
|
262
428
|
// job at a time. A host whose job passes its limit is stopped, and the next
|
|
263
429
|
// job starts another.
|
|
264
|
-
function residentHosts({ script, args, root, environment, log }) {
|
|
430
|
+
function residentHosts({ script, args, root, environment, log, asCommand = false }) {
|
|
265
431
|
const idle = [];
|
|
266
432
|
const all = new Set();
|
|
267
433
|
const host = () => new Promise((resolveHost, rejectHost) => {
|
|
@@ -330,8 +496,12 @@ function residentHosts({ script, args, root, environment, log }) {
|
|
|
330
496
|
};
|
|
331
497
|
const answered = (message) => {
|
|
332
498
|
if (message?.type === "done" && message.id === id) {
|
|
333
|
-
|
|
334
|
-
|
|
499
|
+
// A host that can run no further job is stopped.
|
|
500
|
+
if (message.tainted)
|
|
501
|
+
stop(child);
|
|
502
|
+
else
|
|
503
|
+
idle.push(child);
|
|
504
|
+
settle({ timedOut: false, error: message.error, fallback: message.fallback, tainted: message.tainted });
|
|
335
505
|
}
|
|
336
506
|
};
|
|
337
507
|
const exited = () => settle({ timedOut: false, error: "the resident runner ended" });
|
|
@@ -348,6 +518,10 @@ function residentHosts({ script, args, root, environment, log }) {
|
|
|
348
518
|
for (const child of all)
|
|
349
519
|
stop(child);
|
|
350
520
|
},
|
|
521
|
+
// Whether a job it stops at its limit, and a baseline that does not
|
|
522
|
+
// pass in it, run again as commands (the runners whose jobs used to
|
|
523
|
+
// start the command, and whose limits came from such a start).
|
|
524
|
+
asCommand,
|
|
351
525
|
};
|
|
352
526
|
}
|
|
353
527
|
|
|
@@ -386,7 +560,61 @@ function stop(child) {
|
|
|
386
560
|
}
|
|
387
561
|
}
|
|
388
562
|
|
|
389
|
-
|
|
563
|
+
// Runs a command's build once, before any job (`--build`, where the engine
|
|
564
|
+
// split `sh -c "<build> && <tests>"`): its output goes to `log`. Whether it
|
|
565
|
+
// passed, and if not, what it said last.
|
|
566
|
+
export function buildOnce(build, { root, environment, log }) {
|
|
567
|
+
return new Promise((resolveBuild) => {
|
|
568
|
+
const [program, ...args] = build;
|
|
569
|
+
let child;
|
|
570
|
+
try {
|
|
571
|
+
child = spawn(program, args, {
|
|
572
|
+
cwd: root,
|
|
573
|
+
// No mutant is on in the build: the switches are read while
|
|
574
|
+
// the tests run, and the build is the same for every one.
|
|
575
|
+
env: { ...environment, SUPERCOV_ACTIVE_MUTANT: "-", SUPERCOV_STRONG_PLAN: "" },
|
|
576
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
577
|
+
detached: process.platform !== "win32",
|
|
578
|
+
shell: process.platform === "win32",
|
|
579
|
+
windowsHide: true,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
resolveBuild({ passed: false, said: String(error?.message ?? error) });
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
track(child);
|
|
587
|
+
const keep = (chunk) => {
|
|
588
|
+
try {
|
|
589
|
+
appendFileSync(log, chunk);
|
|
590
|
+
}
|
|
591
|
+
catch {
|
|
592
|
+
// The log is for reading only.
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
child.stdout.on("data", keep);
|
|
596
|
+
child.stderr.on("data", keep);
|
|
597
|
+
const done = (code, error) => {
|
|
598
|
+
if (code === 0) {
|
|
599
|
+
resolveBuild({ passed: true });
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
let output = "";
|
|
603
|
+
try {
|
|
604
|
+
output = readFileSync(log, "utf8");
|
|
605
|
+
}
|
|
606
|
+
catch {
|
|
607
|
+
// Nothing was written.
|
|
608
|
+
}
|
|
609
|
+
const last = output.trim().split("\n").slice(-5).join("\n");
|
|
610
|
+
resolveBuild({ passed: false, said: error ? String(error.message ?? error) : `exited ${code}${last ? `: ${last}` : ""}` });
|
|
611
|
+
};
|
|
612
|
+
child.once("error", (error) => done(null, error));
|
|
613
|
+
child.once("close", (code) => done(code));
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
export async function drive({ command, build, plan, resultsPath, root = process.cwd(), workers = parallelism(), environment = process.env, graceMs = 10_000, baselineGraceMs = 60_000, aloneGraceMs = graceMs }) {
|
|
390
618
|
const started = Date.now();
|
|
391
619
|
// Once the pass is told to stop (`stopped-at` beside the results), its
|
|
392
620
|
// jobs are stopped under their tests: one that ends then says nothing of
|
|
@@ -442,6 +670,18 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
442
670
|
// (SUPERCOV_STRONG_MOCHA_ESM=process: a process per job instead).
|
|
443
671
|
const esmHosts = residentHosts({ script: "strongMochaHost.mjs", args: mochaArgs, root, environment: { ...environment, SUPERCOV_MOCHA_FRESH_WORKERS: "1" }, log: join(work, "mocha-esm-hosts.log") });
|
|
444
672
|
const esmResident = process.env.SUPERCOV_STRONG_MOCHA_ESM !== "process";
|
|
673
|
+
// Vitest Browser Mode: a resident Vitest, its Vite server and its
|
|
674
|
+
// browser kept for job after job, each job in fresh browser contexts
|
|
675
|
+
// (strongVitestHost.mjs). A file it cannot run as a command would runs
|
|
676
|
+
// as a command from then on (`commandOnly`).
|
|
677
|
+
const vitestArgs = residentAllowed ? vitestArguments(withoutNpx(command, root)) : undefined;
|
|
678
|
+
const vitestHosts = residentHosts({ script: "strongVitestHost.mjs", args: vitestArgs, root, environment: { ...environment, SUPERCOV_STRONG_PLAN: "" }, log: join(work, "vitest-hosts.log"), asCommand: true });
|
|
679
|
+
const commandOnly = new Set();
|
|
680
|
+
// AVA: a resident AVA, its command's options worked out once, each job's
|
|
681
|
+
// test files in fresh workers as the command's own run makes them
|
|
682
|
+
// (strongAvaHost.mjs).
|
|
683
|
+
const avaArgs = residentAllowed ? avaArguments(withoutNpx(command, root)) : undefined;
|
|
684
|
+
const avaHosts = residentHosts({ script: "strongAvaHost.mjs", args: avaArgs, root, environment: { ...environment, SUPERCOV_STRONG_PLAN: "" }, log: join(work, "ava-hosts.log"), asCommand: true });
|
|
445
685
|
const commonJs = packageIsCommonJs(root);
|
|
446
686
|
const broken = new Set();
|
|
447
687
|
const residentFor = (file) => {
|
|
@@ -454,6 +694,10 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
454
694
|
return mochaHosts;
|
|
455
695
|
if (runner === "mocha" && mochaArgs && esmResident)
|
|
456
696
|
return esmHosts;
|
|
697
|
+
if (runner === "vitest-browser" && vitestArgs && !commandOnly.has(file))
|
|
698
|
+
return vitestHosts;
|
|
699
|
+
if (runner === "ava" && avaArgs && !commandOnly.has(file))
|
|
700
|
+
return avaHosts;
|
|
457
701
|
return undefined;
|
|
458
702
|
};
|
|
459
703
|
// Rust compiled to wasm (SUPERCOV_WASM_STRONG): a job that starts the
|
|
@@ -488,7 +732,7 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
488
732
|
});
|
|
489
733
|
return handed ? parallel(work, priority) : result;
|
|
490
734
|
};
|
|
491
|
-
const profile = { jobs: 0, baselines: 0, confirmations: 0, overturned: 0, stopped: 0, alone: 0, jobMs: 0 };
|
|
735
|
+
const profile = { jobs: 0, baselines: 0, confirmations: 0, overturned: 0, stopped: 0, alone: 0, jobMs: 0, residentJobs: 0, residentFallbacks: 0 };
|
|
492
736
|
const machine = turns();
|
|
493
737
|
let jobNumber = 0;
|
|
494
738
|
|
|
@@ -498,7 +742,7 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
498
742
|
// so that the kills most mutants get at once come first, and a
|
|
499
743
|
// survivor's many files fill what is left. One run `alone` waits for no
|
|
500
744
|
// slot: it has the machine to itself.
|
|
501
|
-
function job({ mutant, file, tests: chosen, bail, limitMs, priority = 0, alone = false }) {
|
|
745
|
+
function job({ mutant, file, tests: chosen, bail, limitMs, priority = 0, alone = false, command: asCommand = false }) {
|
|
502
746
|
const start = (work) => (alone ? machine.alone(work) : run(() => machine.shared(work), priority));
|
|
503
747
|
return start((turn) => new Promise((resolveJob) => {
|
|
504
748
|
const number = ++jobNumber;
|
|
@@ -510,7 +754,7 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
510
754
|
writeFileSync(spec, JSON.stringify({ files: { [file]: chosen === null ? null : [...chosen] }, known, bail, mutant: mutant ? `${mutant.file}#${mutant.index}` : null }));
|
|
511
755
|
const results = join(directory, "results.jsonl");
|
|
512
756
|
const begun = Date.now();
|
|
513
|
-
const resident = residentFor(file);
|
|
757
|
+
const resident = asCommand ? undefined : residentFor(file);
|
|
514
758
|
// A job's outcome, read from its evidence; then its directory is
|
|
515
759
|
// removed, as nothing after reads it (a job's evidence ran to
|
|
516
760
|
// 24 MB on nanoid, a gigabyte a pass).
|
|
@@ -603,18 +847,42 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
603
847
|
SUPERCOV_STRONG_RESULTS: results,
|
|
604
848
|
SUPERCOV_STRONG_PLAN: "",
|
|
605
849
|
};
|
|
606
|
-
resident.run({ file: join(root, file), mutant: mutant ? { file: mutant.file, index: mutant.index } : null, environment: environmentOfJob }, limitMs).then(({ timedOut, error, notStarted }) => {
|
|
850
|
+
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
851
|
if (notStarted) {
|
|
608
852
|
broken.add(runnerOf.get(file));
|
|
609
853
|
spawnJob();
|
|
610
854
|
return;
|
|
611
855
|
}
|
|
856
|
+
// The resident runner did not run the job as the command
|
|
857
|
+
// would have: the command runs it, from a clean slate.
|
|
858
|
+
if (fallback !== undefined) {
|
|
859
|
+
profile.residentFallbacks += 1;
|
|
860
|
+
try {
|
|
861
|
+
appendFileSync(join(work, "resident-fallbacks.log"), `${file}: ${fallback}\n`);
|
|
862
|
+
}
|
|
863
|
+
catch {
|
|
864
|
+
// The log is for reading only.
|
|
865
|
+
}
|
|
866
|
+
if (tainted)
|
|
867
|
+
broken.add(runnerOf.get(file));
|
|
868
|
+
else
|
|
869
|
+
commandOnly.add(file);
|
|
870
|
+
rmSync(evidence, { recursive: true, force: true });
|
|
871
|
+
mkdirSync(evidence, { recursive: true });
|
|
872
|
+
rmSync(`${results}.timeouts.jsonl`, { force: true });
|
|
873
|
+
spawnJob();
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
if (tainted)
|
|
877
|
+
broken.add(runnerOf.get(file));
|
|
878
|
+
profile.residentJobs += 1;
|
|
612
879
|
if (timedOut)
|
|
613
880
|
profile.stopped += 1;
|
|
614
881
|
profile.jobMs += Date.now() - begun;
|
|
615
882
|
const mutantKey = mutant ? `${mutant.file}#${mutant.index}` : undefined;
|
|
616
883
|
resolveJob(read({
|
|
617
884
|
timedOut,
|
|
885
|
+
resident: resident.asCommand,
|
|
618
886
|
mutantTimedOut: mutantKey !== undefined && readTimeouts(`${results}.timeouts.jsonl`).includes(mutantKey),
|
|
619
887
|
exitCode: error ? 1 : 0,
|
|
620
888
|
error,
|
|
@@ -640,23 +908,39 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
640
908
|
async function wholeBaseline(file) {
|
|
641
909
|
const state = fileState(file);
|
|
642
910
|
state.whole ??= (async () => {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
911
|
+
const once = async () => {
|
|
912
|
+
profile.baselines += 1;
|
|
913
|
+
const result = await job({ mutant: null, file, tests: null, bail: false, limitMs: baselineLimit(file, null) });
|
|
914
|
+
const passing = new Set([...result.statuses].filter(([, status]) => status === "passed").map(([id]) => id));
|
|
915
|
+
return { ...result, passing, finished: !result.timedOut && passing.size > 0 };
|
|
916
|
+
};
|
|
917
|
+
return commandWhereResidentFails(file, once, (result) => result.finished && [...result.statuses.values()].every((status) => status === "passed" || status === "skipped"));
|
|
647
918
|
})();
|
|
648
919
|
return state.whole;
|
|
649
920
|
}
|
|
921
|
+
// A baseline the resident runner ran that did not pass as it should is
|
|
922
|
+
// run again as a command, and the file's jobs are the command's from
|
|
923
|
+
// then on: what a test does without a mutant is the command's to say.
|
|
924
|
+
async function commandWhereResidentFails(file, once, clean) {
|
|
925
|
+
const result = await once();
|
|
926
|
+
if (!result.resident || clean(result))
|
|
927
|
+
return result;
|
|
928
|
+
commandOnly.add(file);
|
|
929
|
+
return once();
|
|
930
|
+
}
|
|
650
931
|
// The baseline a mutant's job in `file` is judged by: the subset's where
|
|
651
932
|
// it stood for the file, else the whole file's.
|
|
652
933
|
async function baselineFor(file) {
|
|
653
934
|
const state = fileState(file);
|
|
654
935
|
if (!state.wholeNeeded && state.union.size > 0) {
|
|
655
936
|
state.subset ??= (async () => {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
937
|
+
const once = async () => {
|
|
938
|
+
profile.baselines += 1;
|
|
939
|
+
const chosen = new Set(state.union);
|
|
940
|
+
const result = await job({ mutant: null, file, tests: chosen, bail: false, limitMs: baselineLimit(file, chosen) });
|
|
941
|
+
return { ...result, chosen, finished: passedAll(result, chosen) };
|
|
942
|
+
};
|
|
943
|
+
return commandWhereResidentFails(file, once, (result) => result.finished);
|
|
660
944
|
})();
|
|
661
945
|
const subset = await state.subset;
|
|
662
946
|
if (subset.finished)
|
|
@@ -702,9 +986,13 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
702
986
|
// machine's speed now.
|
|
703
987
|
if (result.timedOut && !result.mutantTimedOut && killerIn(result) === undefined) {
|
|
704
988
|
profile.alone += 1;
|
|
705
|
-
|
|
989
|
+
// A resident runner's limit is tighter than a command's, which
|
|
990
|
+
// starts the runner and the browser within it: the job runs
|
|
991
|
+
// again as a command, with a command's limit.
|
|
992
|
+
const asCommand = Boolean(result.resident);
|
|
993
|
+
const now = await job({ mutant: null, file: group.file, tests: chosen, bail: false, limitMs: baselineLimit(group.file, chosen), alone: true, command: asCommand });
|
|
706
994
|
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 });
|
|
995
|
+
result = await job({ mutant, file: group.file, tests: chosen, bail, limitMs: 3 * slowest + aloneGraceMs, alone: true, command: asCommand });
|
|
708
996
|
}
|
|
709
997
|
const ran = [...result.statuses].filter(([id, status]) => status !== "skipped" && (chosen === null || chosen.has(id)));
|
|
710
998
|
const killer = killerIn(result);
|
|
@@ -788,10 +1076,22 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
788
1076
|
write({ id: mutant.id, status: "survived", tests: ran, durationMs: Date.now() - begun });
|
|
789
1077
|
}
|
|
790
1078
|
|
|
1079
|
+
// The command's build, once: every job runs the tests' steps alone. A
|
|
1080
|
+
// build that fails leaves no mutant a job could test.
|
|
1081
|
+
let unbuilt;
|
|
1082
|
+
if (build && plan.mutants.some((planned) => !planned.decided)) {
|
|
1083
|
+
const built = await buildOnce(build, { root, environment, log: join(work, "build.log") });
|
|
1084
|
+
if (!built.passed)
|
|
1085
|
+
unbuilt = `the command's build, \`${build.at(-1)}\`, did not pass without a mutant (${built.said}), so it could not test this one`;
|
|
1086
|
+
}
|
|
791
1087
|
const pending = [];
|
|
792
1088
|
for (const planned of plan.mutants) {
|
|
793
1089
|
if (planned.decided)
|
|
794
1090
|
continue;
|
|
1091
|
+
if (unbuilt !== undefined) {
|
|
1092
|
+
write({ id: planned.id, status: "error", reason: unbuilt, tests: 0, durationMs: 0 });
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
795
1095
|
// A Rust mutant (Rust compiled to wasm) is switched by its index in
|
|
796
1096
|
// its file's list, as the pass's build placed it.
|
|
797
1097
|
const found = planned.language === "rust" ? { index: planned.index, entry: {} } : indexes.get(planned.id);
|
|
@@ -852,15 +1152,23 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
852
1152
|
jestHosts.close();
|
|
853
1153
|
mochaHosts.close();
|
|
854
1154
|
esmHosts.close();
|
|
1155
|
+
vitestHosts.close();
|
|
1156
|
+
avaHosts.close();
|
|
855
1157
|
write({ summary: true, driver: "jobs", workers, ...profile, durationMs: Date.now() - started });
|
|
856
1158
|
return 0;
|
|
857
1159
|
}
|
|
858
1160
|
|
|
859
|
-
// `node strongJobs.mjs -- <command>`
|
|
1161
|
+
// `node strongJobs.mjs [--build=<words as JSON>] -- <command>`
|
|
860
1162
|
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
1163
|
+
let first = 2;
|
|
1164
|
+
let build;
|
|
1165
|
+
if (process.argv[first]?.startsWith("--build=")) {
|
|
1166
|
+
build = JSON.parse(process.argv[first].slice("--build=".length));
|
|
1167
|
+
first += 1;
|
|
1168
|
+
}
|
|
861
1169
|
// Bun leaves the `--` out of process.argv.
|
|
862
|
-
const at = process.argv.indexOf("--",
|
|
863
|
-
const command = process.argv.slice(at < 0 ?
|
|
1170
|
+
const at = process.argv.indexOf("--", first);
|
|
1171
|
+
const command = process.argv.slice(at < 0 ? first : at + 1);
|
|
864
1172
|
const planPath = process.env.SUPERCOV_STRONG_PLAN;
|
|
865
1173
|
const resultsPath = process.env.SUPERCOV_STRONG_RESULTS;
|
|
866
1174
|
if (!command.length || !planPath || !resultsPath) {
|
|
@@ -877,5 +1185,5 @@ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.ur
|
|
|
877
1185
|
}
|
|
878
1186
|
process.on("exit", stopStarted);
|
|
879
1187
|
const plan = JSON.parse(readFileSync(planPath, "utf8"));
|
|
880
|
-
process.exitCode = await drive({ command, plan, resultsPath });
|
|
1188
|
+
process.exitCode = await drive({ command, build, plan, resultsPath });
|
|
881
1189
|
}
|