supercov 4.30.0 → 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supercov",
|
|
3
|
-
"version": "4.30.
|
|
3
|
+
"version": "4.30.1",
|
|
4
4
|
"description": "Coverage, security and code quality for coding agents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"coverage",
|
|
@@ -126,14 +126,14 @@
|
|
|
126
126
|
"test:windows-tls": "node scripts/windows-tls-test.mjs"
|
|
127
127
|
},
|
|
128
128
|
"optionalDependencies": {
|
|
129
|
-
"@supercov/cli-darwin-arm64": "4.30.
|
|
130
|
-
"@supercov/cli-darwin-x64": "4.30.
|
|
131
|
-
"@supercov/cli-linux-arm64-gnu": "4.30.
|
|
132
|
-
"@supercov/cli-linux-arm64-musl": "4.30.
|
|
133
|
-
"@supercov/cli-linux-x64-gnu": "4.30.
|
|
134
|
-
"@supercov/cli-linux-x64-musl": "4.30.
|
|
135
|
-
"@supercov/cli-win32-arm64": "4.30.
|
|
136
|
-
"@supercov/cli-win32-x64": "4.30.
|
|
129
|
+
"@supercov/cli-darwin-arm64": "4.30.1",
|
|
130
|
+
"@supercov/cli-darwin-x64": "4.30.1",
|
|
131
|
+
"@supercov/cli-linux-arm64-gnu": "4.30.1",
|
|
132
|
+
"@supercov/cli-linux-arm64-musl": "4.30.1",
|
|
133
|
+
"@supercov/cli-linux-x64-gnu": "4.30.1",
|
|
134
|
+
"@supercov/cli-linux-x64-musl": "4.30.1",
|
|
135
|
+
"@supercov/cli-win32-arm64": "4.30.1",
|
|
136
|
+
"@supercov/cli-win32-x64": "4.30.1"
|
|
137
137
|
},
|
|
138
138
|
"peerDependencies": {
|
|
139
139
|
"@playwright/test": ">=1.55.0",
|
|
@@ -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.
|
|
@@ -408,7 +560,61 @@ function stop(child) {
|
|
|
408
560
|
}
|
|
409
561
|
}
|
|
410
562
|
|
|
411
|
-
|
|
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 }) {
|
|
412
618
|
const started = Date.now();
|
|
413
619
|
// Once the pass is told to stop (`stopped-at` beside the results), its
|
|
414
620
|
// jobs are stopped under their tests: one that ends then says nothing of
|
|
@@ -870,10 +1076,22 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
870
1076
|
write({ id: mutant.id, status: "survived", tests: ran, durationMs: Date.now() - begun });
|
|
871
1077
|
}
|
|
872
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
|
+
}
|
|
873
1087
|
const pending = [];
|
|
874
1088
|
for (const planned of plan.mutants) {
|
|
875
1089
|
if (planned.decided)
|
|
876
1090
|
continue;
|
|
1091
|
+
if (unbuilt !== undefined) {
|
|
1092
|
+
write({ id: planned.id, status: "error", reason: unbuilt, tests: 0, durationMs: 0 });
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
877
1095
|
// A Rust mutant (Rust compiled to wasm) is switched by its index in
|
|
878
1096
|
// its file's list, as the pass's build placed it.
|
|
879
1097
|
const found = planned.language === "rust" ? { index: planned.index, entry: {} } : indexes.get(planned.id);
|
|
@@ -940,11 +1158,17 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
940
1158
|
return 0;
|
|
941
1159
|
}
|
|
942
1160
|
|
|
943
|
-
// `node strongJobs.mjs -- <command>`
|
|
1161
|
+
// `node strongJobs.mjs [--build=<words as JSON>] -- <command>`
|
|
944
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
|
+
}
|
|
945
1169
|
// Bun leaves the `--` out of process.argv.
|
|
946
|
-
const at = process.argv.indexOf("--",
|
|
947
|
-
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);
|
|
948
1172
|
const planPath = process.env.SUPERCOV_STRONG_PLAN;
|
|
949
1173
|
const resultsPath = process.env.SUPERCOV_STRONG_RESULTS;
|
|
950
1174
|
if (!command.length || !planPath || !resultsPath) {
|
|
@@ -961,5 +1185,5 @@ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.ur
|
|
|
961
1185
|
}
|
|
962
1186
|
process.on("exit", stopStarted);
|
|
963
1187
|
const plan = JSON.parse(readFileSync(planPath, "utf8"));
|
|
964
|
-
process.exitCode = await drive({ command, plan, resultsPath });
|
|
1188
|
+
process.exitCode = await drive({ command, build, plan, resultsPath });
|
|
965
1189
|
}
|