supercov 4.30.1 → 4.30.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/cli.md CHANGED
@@ -1302,11 +1302,12 @@ The merged run keeps the strong verdicts the runs saved (`mutants test`,
1302
1302
  from each run, and how many the merged run's plan decides without running
1303
1303
  them (`1265 strong verdict(s) kept from runs r8, r7: 1103 from r8, 150 from
1304
1304
  r7, 12 the merged run's plan decides`). A verdict two runs hold alike counts
1305
- for the first run named. A kill in any run is a kill. A survival stands only where the run that
1306
- let the mutant survive measured every test of the merged suite that could
1307
- kill it; where another run's tests could, and it has no verdict, the mutant is
1308
- left for a pass over the merged run to run. An error stands only where no run
1309
- holds anything else. A run whose verdicts are of another mutant set than the
1305
+ for the first run named. A kill in any run is a kill. A survival stands only
1306
+ where every test of the merged suite that could kill it ran with the mutant in
1307
+ a run that let it survive, or in one whose tests passed without running the
1308
+ mutated code; where another run's tests could, and it has no verdict, the
1309
+ mutant is left for a pass over the merged run to run. An error stands only
1310
+ where no run holds anything else. A run whose verdicts are of another mutant set than the
1310
1311
  merged run lists lends none, and `merge` names it; a run some of whose tests
1311
1312
  another measured again lends none either. Split a strong pass across jobs this
1312
1313
  way: each job measures and runs `supercov mutants --shard k/n -- <command>`,
package/docs/mutation.md CHANGED
@@ -643,6 +643,20 @@ no mutants shows none of this.
643
643
  - **Jest and Mocha** run in resident runners, as StrykerJS's do; `node:test`,
644
644
  AVA, node-tap, `bun:test` and Vitest Browser Mode run one test file per
645
645
  start of the command, with the mutant on from its start.
646
+ Jobs run side by side, several of one test file at once. A test file that
647
+ does not run beside a copy of itself as it does alone (a server on a fixed
648
+ port, a fixed temporary path) would let one job's tests reach another's
649
+ server, with another mutant or none. Its first baseline runs as two copies
650
+ at once, and where they end differently its jobs run one at a time, and
651
+ the pass names it (`[supercov] tests/api.test.ts does not run beside a copy
652
+ of itself ...`). Giving such a test a free port makes it fast again. Two
653
+ copies without a mutant that share a server can both pass, as either
654
+ server answers alike; such a file is not caught, and only its own free
655
+ port makes its verdicts sound.
656
+ A job past its limit runs again beside its tests without the mutant (a
657
+ control), under the same load, its limit 3× the slower of the control and
658
+ its baseline, and 10 s; the pass no longer waits for the machine to empty
659
+ first, which kept it half idle where some jobs take minutes.
646
660
  - Rust compiled to wasm and loaded by these tests is mutated too:
647
661
  the command builds the wasm with the mutants switched in, and each wasm
648
662
  instance, in Node or in a Playwright page, runs the test's mutant.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supercov",
3
- "version": "4.30.1",
3
+ "version": "4.30.3",
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.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"
129
+ "@supercov/cli-darwin-arm64": "4.30.3",
130
+ "@supercov/cli-darwin-x64": "4.30.3",
131
+ "@supercov/cli-linux-arm64-gnu": "4.30.3",
132
+ "@supercov/cli-linux-arm64-musl": "4.30.3",
133
+ "@supercov/cli-linux-x64-gnu": "4.30.3",
134
+ "@supercov/cli-linux-x64-musl": "4.30.3",
135
+ "@supercov/cli-win32-arm64": "4.30.3",
136
+ "@supercov/cli-win32-x64": "4.30.3"
137
137
  },
138
138
  "peerDependencies": {
139
139
  "@playwright/test": ">=1.55.0",
@@ -196,6 +196,10 @@ function wrappedRegistration(original, parentTestId, forcedStatus) {
196
196
  // environment while testing integrations. Keep this attempt's transport
197
197
  // destination fixed to the value present when the test was registered.
198
198
  beginBufferedServerEvidence(scope);
199
+ // How long the test took, its t.after callbacks included: a
200
+ // strong pass orders a mutant's test files and sets its limits
201
+ // by it, and took every node:test test for 1 s without it.
202
+ const begun = performance.now();
199
203
  // A todo test runs, and stays todo whether its body passes or fails.
200
204
  let status = marked ?? "passed";
201
205
  const job = strongJob();
@@ -234,7 +238,7 @@ function wrappedRegistration(original, parentTestId, forcedStatus) {
234
238
  return;
235
239
  emitted = true;
236
240
  const flushedServerEvidence = flushBufferedServerEvidence(scope);
237
- writeRunnerEvidence(identity, nextStatus, scope, evidenceDirectory, takeNodeAssertionPhases(scope), flushedServerEvidence);
241
+ writeRunnerEvidence(identity, nextStatus, scope, evidenceDirectory, takeNodeAssertionPhases(scope), flushedServerEvidence, false, performance.now() - begun);
238
242
  };
239
243
  const finishBody = () => {
240
244
  // User t.after callbacks run after the body. Register last so
@@ -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.
@@ -125,7 +125,7 @@ export function readScopedServerEvidence(scope, evidencePath = serverEvidencePat
125
125
  return [];
126
126
  }
127
127
  }
128
- export function writeRunnerEvidence(identity, status, scope, evidenceDirectoryOverride, phases = [], serverEvidenceSource, snapshot = false) {
128
+ export function writeRunnerEvidence(identity, status, scope, evidenceDirectoryOverride, phases = [], serverEvidenceSource, snapshot = false, durationMs = undefined) {
129
129
  const evidenceDirectory = evidenceDirectoryOverride ?? process.env["SUPERCOV_EVIDENCE_DIR"];
130
130
  if (!evidenceDirectory)
131
131
  return;
@@ -138,6 +138,7 @@ export function writeRunnerEvidence(identity, status, scope, evidenceDirectoryOv
138
138
  title: identity.name.split(" > ").at(-1) ?? identity.name,
139
139
  retry: identity.retry ?? 0,
140
140
  status,
141
+ ...(typeof durationMs === "number" ? { durationMs: Math.round(durationMs) } : {}),
141
142
  ...(identity.role ? { role: identity.role } : {}),
142
143
  provenance: inferTestProvenance({
143
144
  runner: identity.runner,
@@ -28,9 +28,13 @@
28
28
  // only have waited: on the jobs beside it (the CPU; Cargo's lock on a build
29
29
  // directory, where each job builds Rust compiled to wasm), or on a machine
30
30
  // busier than when its baseline ran (other work on it, beyond the pass's
31
- // own). So it runs again alone, after its tests ran alone without the
32
- // mutant, and its limit there is 3x the slower of that run and its
33
- // baseline, and 10 s: only a job past that is a timeout.
31
+ // own). So its tests run again without the mutant, beside the same jobs
32
+ // (a control), and the mutant again after them, its limit 3x the slower of
33
+ // that run and its baseline, and 10 s: only a job past that is a timeout.
34
+ // Nothing waits for the machine to empty. A test file runs beside a copy of
35
+ // itself, as a pass runs many mutants against one file at once; one whose
36
+ // first baseline does not do there what it does alone (a fixed port, a fixed
37
+ // path) runs one job at a time from then on, and the pass says so.
34
38
  import { fork, spawn } from "node:child_process";
35
39
  import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
36
40
  import { availableParallelism, constants, cpus } from "node:os";
@@ -106,49 +110,6 @@ export function slots(size) {
106
110
  };
107
111
  }
108
112
 
109
- // Turns at the machine: `shared` work runs beside other shared work, and
110
- // `alone` work waits until none runs, while no shared work starts. A shared
111
- // turn learns whether other work ran beside it (`crowded`).
112
- export function turns() {
113
- const running = new Set();
114
- const idle = [];
115
- let alone;
116
- return {
117
- async shared(work) {
118
- while (alone)
119
- await alone;
120
- const turn = { crowded: running.size > 0 };
121
- for (const other of running)
122
- other.crowded = true;
123
- running.add(turn);
124
- try {
125
- return await work(turn);
126
- }
127
- finally {
128
- running.delete(turn);
129
- if (running.size === 0)
130
- for (const wake of idle.splice(0))
131
- wake();
132
- }
133
- },
134
- async alone(work) {
135
- while (alone)
136
- await alone;
137
- let end;
138
- alone = new Promise((done) => { end = done; });
139
- try {
140
- if (running.size > 0)
141
- await new Promise((wake) => idle.push(wake));
142
- return await work({ crowded: false });
143
- }
144
- finally {
145
- alone = undefined;
146
- end();
147
- }
148
- },
149
- };
150
- }
151
-
152
113
  // Every file under `directory`, recursively.
153
114
  function filesUnder(directory) {
154
115
  let entries;
@@ -732,19 +693,28 @@ export async function drive({ command, build, plan, resultsPath, root = process.
732
693
  });
733
694
  return handed ? parallel(work, priority) : result;
734
695
  };
735
- const profile = { jobs: 0, baselines: 0, confirmations: 0, overturned: 0, stopped: 0, alone: 0, jobMs: 0, residentJobs: 0, residentFallbacks: 0 };
736
- const machine = turns();
696
+ const profile = { jobs: 0, baselines: 0, confirmations: 0, overturned: 0, stopped: 0, controls: 0, jobMs: 0, residentJobs: 0, residentFallbacks: 0, oneAtATime: [] };
697
+ // Test files that do not run as they should beside a copy of
698
+ // themselves: one job of each at a time, in turn.
699
+ const oneAtATime = new Map();
737
700
  let jobNumber = 0;
738
701
 
739
702
  // One start of the command: `tests` of `file` (null: all of them), with
740
703
  // `mutant` on (null: none), stopped at `limitMs`. A job of a mutant's
741
704
  // later batch (`priority` 1, 2, ...) waits behind every first file's,
742
705
  // so that the kills most mutants get at once come first, and a
743
- // survivor's many files fill what is left. One run `alone` waits for no
744
- // slot: it has the machine to itself.
745
- function job({ mutant, file, tests: chosen, bail, limitMs, priority = 0, alone = false, command: asCommand = false }) {
746
- const start = (work) => (alone ? machine.alone(work) : run(() => machine.shared(work), priority));
747
- return start((turn) => new Promise((resolveJob) => {
706
+ // survivor's many files fill what is left. A job of a file that runs one
707
+ // at a time waits for the file's job before it, then for a slot.
708
+ function job({ mutant, file, tests: chosen, bail, limitMs, priority = 0, command: asCommand = false, handle }) {
709
+ const start = (work) => {
710
+ const before = oneAtATime.get(file);
711
+ if (before === undefined)
712
+ return run(work, priority);
713
+ const mine = before.then(() => run(work, priority));
714
+ oneAtATime.set(file, mine.catch(() => undefined));
715
+ return mine;
716
+ };
717
+ return start(() => new Promise((resolveJob) => {
748
718
  const number = ++jobNumber;
749
719
  profile.jobs += 1;
750
720
  const directory = join(work, String(number));
@@ -762,7 +732,7 @@ export async function drive({ command, build, plan, resultsPath, root = process.
762
732
  const statuses = outcomes(evidence);
763
733
  if (environment.SUPERCOV_STRONG_KEEP !== "1")
764
734
  rmSync(directory, { recursive: true, force: true });
765
- return { ...outcome, statuses, crowded: turn.crowded };
735
+ return { ...outcome, statuses };
766
736
  };
767
737
  // A runner's own command, started for this job alone.
768
738
  const spawnJob = () => {
@@ -810,11 +780,19 @@ export async function drive({ command, build, plan, resultsPath, root = process.
810
780
  child.stdout.resume();
811
781
  child.stderr.resume();
812
782
  let timedOut = false;
813
- const timer = setTimeout(() => {
783
+ const expire = () => {
814
784
  timedOut = true;
815
785
  profile.stopped += 1;
816
786
  stop(child);
817
- }, limitMs);
787
+ };
788
+ let timer = setTimeout(expire, handle?.limitMs ?? limitMs);
789
+ // A job started beside its control is given its limit
790
+ // once the control ends, or starts with it.
791
+ if (handle)
792
+ handle.setLimit = (ms) => {
793
+ clearTimeout(timer);
794
+ timer = setTimeout(expire, Math.max(0, begun + ms - Date.now()));
795
+ };
818
796
  const finish = (code, error) => {
819
797
  clearTimeout(timer);
820
798
  profile.jobMs += Date.now() - begun;
@@ -905,12 +883,32 @@ export async function drive({ command, build, plan, resultsPath, root = process.
905
883
  .reduce((sum, id) => sum + (byId.get(id)?.durationMs ?? 1_000), 0);
906
884
  const baselineLimit = (file, chosen) => 3 * cost(file, chosen) + baselineGraceMs;
907
885
  const passedAll = (result, chosen) => !result.timedOut && [...chosen].every((id) => result.statuses.get(id) === "passed");
886
+ // A file's first baseline: two copies at once, where the pass runs jobs
887
+ // side by side. Where the copies end alike, the file runs beside itself
888
+ // as it does alone; where they do not, its jobs run one at a time from
889
+ // then on, and its baseline runs again so.
890
+ const probed = new Set();
891
+ const alike = (one, other) => one.timedOut === other.timedOut
892
+ && one.statuses.size === other.statuses.size
893
+ && [...one.statuses].every(([id, status]) => other.statuses.get(id) === status);
894
+ async function baselineJob(spec) {
895
+ if (workers < 2 || probed.has(spec.file) || oneAtATime.has(spec.file))
896
+ return job(spec);
897
+ probed.add(spec.file);
898
+ const [one, other] = await Promise.all([job(spec), job(spec)]);
899
+ if (alike(one, other))
900
+ return one;
901
+ oneAtATime.set(spec.file, Promise.resolve());
902
+ profile.oneAtATime.push(spec.file);
903
+ console.error(`[supercov] ${spec.file} does not run beside a copy of itself as it runs alone (a fixed port or path?): its jobs run one at a time`);
904
+ return job(spec);
905
+ }
908
906
  async function wholeBaseline(file) {
909
907
  const state = fileState(file);
910
908
  state.whole ??= (async () => {
911
909
  const once = async () => {
912
910
  profile.baselines += 1;
913
- const result = await job({ mutant: null, file, tests: null, bail: false, limitMs: baselineLimit(file, null) });
911
+ const result = await baselineJob({ mutant: null, file, tests: null, bail: false, limitMs: baselineLimit(file, null) });
914
912
  const passing = new Set([...result.statuses].filter(([, status]) => status === "passed").map(([id]) => id));
915
913
  return { ...result, passing, finished: !result.timedOut && passing.size > 0 };
916
914
  };
@@ -937,7 +935,7 @@ export async function drive({ command, build, plan, resultsPath, root = process.
937
935
  const once = async () => {
938
936
  profile.baselines += 1;
939
937
  const chosen = new Set(state.union);
940
- const result = await job({ mutant: null, file, tests: chosen, bail: false, limitMs: baselineLimit(file, chosen) });
938
+ const result = await baselineJob({ mutant: null, file, tests: chosen, bail: false, limitMs: baselineLimit(file, chosen) });
941
939
  return { ...result, chosen, finished: passedAll(result, chosen) };
942
940
  };
943
941
  return commandWhereResidentFails(file, once, (result) => result.finished);
@@ -981,18 +979,40 @@ export async function drive({ command, build, plan, resultsPath, root = process.
981
979
  const killerIn = (outcome) => [...outcome.statuses].find(([id, status]) => status === "failed" && (chosen === null || chosen.has(id)) && !excluded(id))?.[0];
982
980
  // Past its limit with nothing failed: it may only have waited, on
983
981
  // the jobs beside it or on a machine busier than when its
984
- // baseline ran. It runs again alone, its limit from the same
985
- // tests without the mutant run alone just before it, at the
986
- // machine's speed now.
982
+ // baseline ran. It runs again beside the same tests without the
983
+ // mutant (a control), under the same load, and its limit is 3x
984
+ // the slower of the control and its baseline, and the grace: at
985
+ // the machine's speed now. Neither waits for the machine to
986
+ // empty, which, with long jobs, kept it half idle.
987
987
  if (result.timedOut && !result.mutantTimedOut && killerIn(result) === undefined) {
988
- profile.alone += 1;
988
+ profile.controls += 1;
989
989
  // A resident runner's limit is tighter than a command's, which
990
990
  // starts the runner and the browser within it: the job runs
991
991
  // again as a command, with a command's limit.
992
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 });
994
- const slowest = Math.max(baseline.durationMs, now.durationMs);
995
- result = await job({ mutant, file: group.file, tests: chosen, bail, limitMs: 3 * slowest + aloneGraceMs, alone: true, command: asCommand });
993
+ const controlLimit = baselineLimit(group.file, chosen);
994
+ const limitAfter = (control) => 3 * Math.max(baseline.durationMs, control.durationMs) + aloneGraceMs;
995
+ const control = { mutant: null, file: group.file, tests: chosen, bail: false, limitMs: controlLimit, priority: -1, command: asCommand };
996
+ // A resident runner cannot change a job's limit once it
997
+ // runs: the control first, then the mutant. (A file that
998
+ // runs one job at a time runs them so anyway, its control
999
+ // queued first.)
1000
+ if (!asCommand && residentFor(group.file)) {
1001
+ const now = await job(control);
1002
+ result = await job({ mutant, file: group.file, tests: chosen, bail, limitMs: limitAfter(now), priority: -1, command: asCommand });
1003
+ }
1004
+ else {
1005
+ // Its limit is the longest the control could set, until
1006
+ // the control ends and sets it. The control is queued
1007
+ // first: with one slot, it runs first.
1008
+ const handle = { limitMs: limitAfter({ durationMs: controlLimit }) };
1009
+ const controlled = job(control);
1010
+ const pending = job({ mutant, file: group.file, tests: chosen, bail, limitMs: handle.limitMs, priority: -1, command: asCommand, handle });
1011
+ const now = await controlled;
1012
+ handle.limitMs = limitAfter(now);
1013
+ handle.setLimit?.(handle.limitMs);
1014
+ result = await pending;
1015
+ }
996
1016
  }
997
1017
  const ran = [...result.statuses].filter(([id, status]) => status !== "skipped" && (chosen === null || chosen.has(id)));
998
1018
  const killer = killerIn(result);