supercov 4.30.0 → 4.30.2
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.2",
|
|
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.2",
|
|
130
|
+
"@supercov/cli-darwin-x64": "4.30.2",
|
|
131
|
+
"@supercov/cli-linux-arm64-gnu": "4.30.2",
|
|
132
|
+
"@supercov/cli-linux-arm64-musl": "4.30.2",
|
|
133
|
+
"@supercov/cli-linux-x64-gnu": "4.30.2",
|
|
134
|
+
"@supercov/cli-linux-x64-musl": "4.30.2",
|
|
135
|
+
"@supercov/cli-win32-arm64": "4.30.2",
|
|
136
|
+
"@supercov/cli-win32-x64": "4.30.2"
|
|
137
137
|
},
|
|
138
138
|
"peerDependencies": {
|
|
139
139
|
"@playwright/test": ">=1.55.0",
|
|
@@ -25,6 +25,16 @@ if ((process.env.NODE_OPTIONS ?? "").split(/\s+/).filter((option) => option ===
|
|
|
25
25
|
!process.execArgv.includes("--enable-source-maps") &&
|
|
26
26
|
typeof Module.setSourceMapsSupport === "function")
|
|
27
27
|
Module.setSourceMapsSupport(true, { nodeModules: false, generatedCode: true });
|
|
28
|
+
// `node --check` with source maps on fails on any file with an inline map
|
|
29
|
+
// ("TypeError: WeakRef: invalid target", Node 24), and every instrumented
|
|
30
|
+
// copy has one: a site's `node --check assets/scripts/landing.js` failed its
|
|
31
|
+
// test command. A syntax check runs nothing that a stack trace could name.
|
|
32
|
+
if (process.execArgv.includes("--check") || process.execArgv.includes("-c")) {
|
|
33
|
+
if (typeof Module.setSourceMapsSupport === "function")
|
|
34
|
+
Module.setSourceMapsSupport(false);
|
|
35
|
+
else
|
|
36
|
+
process.setSourceMapsEnabled?.(false);
|
|
37
|
+
}
|
|
28
38
|
// Before anything else loads: every module after this compiles from the
|
|
29
39
|
// code the run's earlier processes left (atomic.mjs says why). Not in npm's
|
|
30
40
|
// own process (`npm run`, `npx`, `npm exec`), which runs none of the
|
|
@@ -155,6 +165,182 @@ virtualMachine.createContext = function createContextWithRuntime(...parameters)
|
|
|
155
165
|
}
|
|
156
166
|
return context;
|
|
157
167
|
};
|
|
168
|
+
// A test can read a measured file as text instead of importing it: to check
|
|
169
|
+
// what it says, or to run it in a `vm` sandbox of its own, as a browser
|
|
170
|
+
// script's test does without a browser. The instrumented copy then changed
|
|
171
|
+
// the test's result: a test that parsed the script's first line failed on
|
|
172
|
+
// the runtime loader there, and a script run in a fresh context failed on
|
|
173
|
+
// "Cannot read properties of undefined (reading 'mcdcBegin')". A test file
|
|
174
|
+
// (`*.test.*`, `*.spec.*`, or one under test/, tests/, __tests__/, spec/ or
|
|
175
|
+
// e2e/) reads a measured file as its author wrote it. Everything else reads
|
|
176
|
+
// the copy: a server of the project's own, a bundler, a helper, so a browser
|
|
177
|
+
// is served what Supercov measures. Supercov's own browser fixtures serve
|
|
178
|
+
// public/app.js from a server.mjs that reads it with fs. Code run in a `vm`
|
|
179
|
+
// context that is a measured file, as written or as the copy, runs as the
|
|
180
|
+
// copy with the process's runtime there, so a sandboxed script is measured.
|
|
181
|
+
installProjectSourceText();
|
|
182
|
+
function installProjectSourceText() {
|
|
183
|
+
const workspace = fileURLToPath(new URL("../../", import.meta.url));
|
|
184
|
+
let authored;
|
|
185
|
+
try {
|
|
186
|
+
authored = new Set(JSON.parse(readFileSync(new URL("./authored-sources.json", import.meta.url), "utf8")));
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (authored.size === 0)
|
|
192
|
+
return;
|
|
193
|
+
const authoredRoot = fileURLToPath(new URL("./.authored/", import.meta.url));
|
|
194
|
+
const changedRoot = fileURLToPath(new URL("./.changed/", import.meta.url));
|
|
195
|
+
const roots = [...new Set([workspace, (() => {
|
|
196
|
+
try {
|
|
197
|
+
return realpathSync(workspace);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return workspace;
|
|
201
|
+
}
|
|
202
|
+
})()])];
|
|
203
|
+
const local = (file) => {
|
|
204
|
+
let absolute;
|
|
205
|
+
try {
|
|
206
|
+
absolute = resolve(file instanceof URL ? fileURLToPath(file) : file);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
for (const root of roots) {
|
|
212
|
+
const inside = relative(root, absolute);
|
|
213
|
+
if (inside !== ".." && !inside.startsWith(`..${sep}`) && !isAbsolute(inside))
|
|
214
|
+
return inside.split(sep).join("/");
|
|
215
|
+
}
|
|
216
|
+
return undefined;
|
|
217
|
+
};
|
|
218
|
+
const { readFileSync: readSync, readFile: readCallback, existsSync: exists } = fs;
|
|
219
|
+
const { readFile: readPromise } = fs.promises;
|
|
220
|
+
// The text a tool of the command wrote to the file, or what its author wrote.
|
|
221
|
+
const authoredText = (file) => {
|
|
222
|
+
const changed = resolve(changedRoot, file);
|
|
223
|
+
return exists(changed) ? changed : resolve(authoredRoot, file);
|
|
224
|
+
};
|
|
225
|
+
const testFile = (file) => /(?:^|\/)(?:tests?|__tests__|specs?|e2e)\//.test(file) ||
|
|
226
|
+
/[._-](?:test|spec)\.[cm]?[jt]sx?$/.test(file);
|
|
227
|
+
// Whether the first project frame above `above` is a test file's.
|
|
228
|
+
const readByTest = (above) => {
|
|
229
|
+
const holder = {};
|
|
230
|
+
const limit = Error.stackTraceLimit;
|
|
231
|
+
try {
|
|
232
|
+
Error.stackTraceLimit = 8;
|
|
233
|
+
Error.captureStackTrace(holder, above);
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
Error.stackTraceLimit = limit;
|
|
237
|
+
}
|
|
238
|
+
for (const line of String(holder.stack).split("\n").slice(1)) {
|
|
239
|
+
const frame = /\(?((?:file:\/\/)?[^\s()]+?):\d+:\d+\)?$/.exec(line.trim())?.[1];
|
|
240
|
+
if (frame === undefined || frame.startsWith("node:"))
|
|
241
|
+
continue;
|
|
242
|
+
const caller = frame.startsWith("file:") ? fileURLToPath(frame) : frame;
|
|
243
|
+
const inside = local(caller);
|
|
244
|
+
// Supercov's own wrappers of the same read sit in between.
|
|
245
|
+
if (inside?.split("/").includes(".supercov"))
|
|
246
|
+
continue;
|
|
247
|
+
if (inside === undefined || inside.split("/").includes("node_modules"))
|
|
248
|
+
return false;
|
|
249
|
+
return testFile(inside);
|
|
250
|
+
}
|
|
251
|
+
return false;
|
|
252
|
+
};
|
|
253
|
+
const asAuthored = (target, above) => {
|
|
254
|
+
if (typeof target !== "string" && !(target instanceof URL))
|
|
255
|
+
return target;
|
|
256
|
+
const inside = local(target);
|
|
257
|
+
return inside !== undefined && authored.has(inside) && readByTest(above)
|
|
258
|
+
? authoredText(inside)
|
|
259
|
+
: target;
|
|
260
|
+
};
|
|
261
|
+
fs.readFileSync = function readFileSync(target, ...rest) {
|
|
262
|
+
return Reflect.apply(readSync, this, [asAuthored(target, readFileSync), ...rest]);
|
|
263
|
+
};
|
|
264
|
+
fs.readFile = function readFile(target, ...rest) {
|
|
265
|
+
return Reflect.apply(readCallback, this, [asAuthored(target, readFile), ...rest]);
|
|
266
|
+
};
|
|
267
|
+
fs.promises.readFile = function readFile(target, ...rest) {
|
|
268
|
+
return Reflect.apply(readPromise, this, [asAuthored(target, readFile), ...rest]);
|
|
269
|
+
};
|
|
270
|
+
// Measured files by their authored text, read the first time a `vm` call
|
|
271
|
+
// is given text as long as one of them.
|
|
272
|
+
let byText;
|
|
273
|
+
const lengths = new Set();
|
|
274
|
+
for (const file of authored) {
|
|
275
|
+
try {
|
|
276
|
+
lengths.add(fs.statSync(authoredText(file)).size);
|
|
277
|
+
}
|
|
278
|
+
catch { }
|
|
279
|
+
}
|
|
280
|
+
// The copy to run for `code`: itself when it is already instrumented.
|
|
281
|
+
const copyOf = (code) => {
|
|
282
|
+
if (typeof code !== "string")
|
|
283
|
+
return undefined;
|
|
284
|
+
if (code.includes("__SUPERCOV_DIRECT_RUNTIME__"))
|
|
285
|
+
return code;
|
|
286
|
+
if (!lengths.has(Buffer.byteLength(code)))
|
|
287
|
+
return undefined;
|
|
288
|
+
if (byText === undefined) {
|
|
289
|
+
byText = new Map();
|
|
290
|
+
for (const file of authored) {
|
|
291
|
+
try {
|
|
292
|
+
byText.set(String(Reflect.apply(readSync, fs, [authoredText(file), "utf8"])), resolve(roots[0], file));
|
|
293
|
+
}
|
|
294
|
+
catch { }
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const copy = byText.get(code);
|
|
298
|
+
if (copy === undefined)
|
|
299
|
+
return undefined;
|
|
300
|
+
try {
|
|
301
|
+
const instrumented = String(Reflect.apply(readSync, fs, [copy, "utf8"]));
|
|
302
|
+
return instrumented.includes("__SUPERCOV_DIRECT_RUNTIME__") ? instrumented : undefined;
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
const withRuntime = (context) => {
|
|
309
|
+
if (context === null || (typeof context !== "object" && typeof context !== "function"))
|
|
310
|
+
return;
|
|
311
|
+
if (Object.prototype.hasOwnProperty.call(context, "__SUPERCOV_DIRECT_RUNTIME__"))
|
|
312
|
+
return;
|
|
313
|
+
try {
|
|
314
|
+
Object.defineProperty(context, "__SUPERCOV_DIRECT_RUNTIME__", {
|
|
315
|
+
configurable: true,
|
|
316
|
+
enumerable: false,
|
|
317
|
+
get: () => globalThis.__SUPERCOV_DIRECT_RUNTIME__ ?? process.__SUPERCOV_DIRECT_RUNTIME__,
|
|
318
|
+
set(value) {
|
|
319
|
+
Object.defineProperty(context, "__SUPERCOV_DIRECT_RUNTIME__", {
|
|
320
|
+
configurable: true, enumerable: false, writable: true, value,
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
catch { }
|
|
326
|
+
};
|
|
327
|
+
const { runInContext, runInNewContext } = virtualMachine;
|
|
328
|
+
virtualMachine.runInContext = function runInContextMeasured(code, context, ...rest) {
|
|
329
|
+
const copy = copyOf(code);
|
|
330
|
+
if (copy === undefined)
|
|
331
|
+
return Reflect.apply(runInContext, this, [code, context, ...rest]);
|
|
332
|
+
withRuntime(context);
|
|
333
|
+
return Reflect.apply(runInContext, this, [copy, context, ...rest]);
|
|
334
|
+
};
|
|
335
|
+
virtualMachine.runInNewContext = function runInNewContextMeasured(code, context, ...rest) {
|
|
336
|
+
const copy = copyOf(code);
|
|
337
|
+
if (copy === undefined)
|
|
338
|
+
return Reflect.apply(runInNewContext, this, [code, context, ...rest]);
|
|
339
|
+
const sandbox = context ?? {};
|
|
340
|
+
withRuntime(sandbox);
|
|
341
|
+
return Reflect.apply(runInNewContext, this, [copy, sandbox, ...rest]);
|
|
342
|
+
};
|
|
343
|
+
}
|
|
158
344
|
// Workers are independent Node processes and an explicit `execArgv: []`
|
|
159
345
|
// otherwise strips the preload that supplies the isolated runtime. Preserve
|
|
160
346
|
// every user option while adding exactly one Supercov import.
|
|
@@ -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
|
}
|