supercov 4.29.7 → 4.29.8

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/mutation.md CHANGED
@@ -144,6 +144,14 @@ mutants the tests let survive.
144
144
  of the 450 s budget, which leaves the pass 140 s`). A measurement is never
145
145
  cut short, since one stopped halfway records nothing: one that outlasts the
146
146
  budget leaves the pass nothing, and the pass runs nothing.
147
+ - **Partial progress.** A mutant a pass left open keeps the candidate tests
148
+ that already passed with it, saved with the run's verdicts, and the next
149
+ pass runs it only against the rest (`37 mutant(s) resume where earlier
150
+ passes left them, with 4 of 15 candidates left (the median)`): a kill needs
151
+ one failing candidate, a survivor every candidate passing, and the ones
152
+ that passed did. The candidates are kept as verdicts are, after an edit, a
153
+ merge and in a later round: a candidate a change could reach runs again.
154
+ The Playwright driver records them.
147
155
  - **Exit codes.** `0` with an answer; `1` when `--fail-on` or `--critical`
148
156
  finds a mutant; `2`, after the answer, when the measured command failed (a
149
157
  failing test kills nothing, so the verdicts cannot gate) or no mutant could
@@ -449,6 +457,19 @@ no mutants shows none of this.
449
457
  has left. A candidate in a project others start from (a login `setup`)
450
458
  never runs with a mutant: a mutant no other test kills is an `error` that
451
459
  says so.
460
+ - **A harness with slots.** A harness may run several `playwright test`
461
+ processes at once (slots, each with its own server and database) and keep
462
+ a spec file with a serial describe whole, in one slot. In a strong pass
463
+ such a file runs in every slot whose command names spec files, and each
464
+ slot takes its own mutants of it from a queue the pass's slots share, so one
465
+ slot no longer runs all of them. Nothing in the harness or the command
466
+ changes: Supercov's preload adds the file to each invocation's file filters
467
+ before Playwright reads them, and leaves `--list` as it is. Each slot runs
468
+ the file's tests once without a mutant before its first mutant there. A
469
+ file it cannot spread (one that sets its serial mode in a helper of its
470
+ own) is named in the progress lines, with what it costs (`"e2e/buy.spec.ts"
471
+ has a serial describe, and 1 of the 6 invocations runs it: its 37 mutant(s)
472
+ wait about 12m00s there, the others about 1m00s`).
452
473
  - **Jest and Mocha** run in resident runners, as StrykerJS's do; `node:test`,
453
474
  AVA, node-tap, `bun:test` and Vitest Browser Mode run one test file per
454
475
  start of the command, with the mutant on from its start.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supercov",
3
- "version": "4.29.7",
3
+ "version": "4.29.8",
4
4
  "description": "Coverage, security and code quality for coding agents",
5
5
  "keywords": [
6
6
  "coverage",
@@ -125,14 +125,14 @@
125
125
  "test:windows-tls": "node scripts/windows-tls-test.mjs"
126
126
  },
127
127
  "optionalDependencies": {
128
- "@supercov/cli-darwin-arm64": "4.29.7",
129
- "@supercov/cli-darwin-x64": "4.29.7",
130
- "@supercov/cli-linux-arm64-gnu": "4.29.7",
131
- "@supercov/cli-linux-arm64-musl": "4.29.7",
132
- "@supercov/cli-linux-x64-gnu": "4.29.7",
133
- "@supercov/cli-linux-x64-musl": "4.29.7",
134
- "@supercov/cli-win32-arm64": "4.29.7",
135
- "@supercov/cli-win32-x64": "4.29.7"
128
+ "@supercov/cli-darwin-arm64": "4.29.8",
129
+ "@supercov/cli-darwin-x64": "4.29.8",
130
+ "@supercov/cli-linux-arm64-gnu": "4.29.8",
131
+ "@supercov/cli-linux-arm64-musl": "4.29.8",
132
+ "@supercov/cli-linux-x64-gnu": "4.29.8",
133
+ "@supercov/cli-linux-x64-musl": "4.29.8",
134
+ "@supercov/cli-win32-arm64": "4.29.8",
135
+ "@supercov/cli-win32-x64": "4.29.8"
136
136
  },
137
137
  "peerDependencies": {
138
138
  "@playwright/test": ">=1.55.0",
@@ -296,7 +296,7 @@ function buildPass(pass, root, config) {
296
296
  const tests = {};
297
297
  plan.tests.forEach((test) => {
298
298
  if (test.runner === "playwright" && test.file)
299
- tests[playwrightId(test)] = { file: test.file, title: test.title ?? null, durationMs: test.durationMs ?? null, jobs: 0 };
299
+ tests[playwrightId(test)] = { file: test.file, title: test.title ?? null, durationMs: test.durationMs ?? null, jobs: 0, planId: test.id };
300
300
  });
301
301
  // `workers` set only where the round runs one test at a time.
302
302
  const concurrency = { workers: undefined, serialFiles: serialFilesOf(plan, tests, fullyParallelOf(config)) };
@@ -536,6 +536,108 @@ function mutantOf(pass, id) {
536
536
  return mutantCache.get(id);
537
537
  }
538
538
 
539
+ // `playwright test`'s options that take a value, one that may (it takes the
540
+ // next argument unless that is an option), and the one that takes every
541
+ // argument up to the next option: what tells a file filter from an option's
542
+ // value.
543
+ const VALUED_OPTIONS = new Set(["--browser", "-c", "--config", "-g", "--grep", "-G", "--grep-invert", "--global-timeout", "-j", "--workers", "--last-failed-file", "--max-failures", "--output", "--repeat-each", "--reporter", "--retries", "--run-agents", "--shard", "--test-list", "--test-list-invert", "--timeout", "--trace", "--tsconfig", "--ui-host", "--ui-port", "--update-source-method"]);
544
+ const OPTIONAL_VALUE_OPTIONS = new Set(["--debug", "--only-changed", "-u", "--update-snapshots"]);
545
+ const VARIADIC_OPTIONS = new Set(["--project"]);
546
+
547
+ /** The file filters a `playwright test` command line names (the arguments after `test`). */
548
+ export function fileFilters(args) {
549
+ const filters = [];
550
+ for (let at = 0; at < args.length; at++) {
551
+ const argument = args[at];
552
+ if (argument === "--")
553
+ break;
554
+ if (!argument.startsWith("-")) {
555
+ filters.push(argument);
556
+ continue;
557
+ }
558
+ if (argument.includes("="))
559
+ continue;
560
+ if (VALUED_OPTIONS.has(argument))
561
+ at += 1;
562
+ else if (OPTIONAL_VALUE_OPTIONS.has(argument) || VARIADIC_OPTIONS.has(argument)) {
563
+ while (at + 1 < args.length && !args[at + 1].startsWith("-")) {
564
+ at += 1;
565
+ if (!VARIADIC_OPTIONS.has(argument))
566
+ break;
567
+ }
568
+ }
569
+ }
570
+ return filters;
571
+ }
572
+
573
+ /** A filter that matches one spec file, by its path from the project root, whatever the separator. */
574
+ export function specFilter(file) {
575
+ const parts = file.split(/[\\/]/).map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
576
+ return `/(?:^|[\\\\/])${parts.join("[\\\\/]")}$/`;
577
+ }
578
+
579
+ /** A spec file's text declares a serial describe. */
580
+ const SERIAL_DECLARATION = /\.describe\.serial\b|\bmode\s*:\s*["'`]serial["'`]/;
581
+
582
+ /**
583
+ * The spec files the pass spreads over its invocations: those with a serial
584
+ * describe whose tests some mutant still to run is a candidate of. Worked
585
+ * out once a pass, from its plan and the files' text, by the first
586
+ * invocation to start; the rest read it.
587
+ */
588
+ function spreadFiles(pass, root) {
589
+ const saved = `${pass.shared}/spread-files.json`;
590
+ const known = readJsonOr(saved, undefined);
591
+ if (known)
592
+ return known;
593
+ const plan = readJson(pass.planPath);
594
+ const candidates = new Set();
595
+ for (const mutant of plan.mutants) {
596
+ if (mutant.decided || mutant.serverWide)
597
+ continue;
598
+ for (const candidate of mutant.candidates) {
599
+ const test = plan.tests[candidate.test];
600
+ if (test?.runner === "playwright" && test.file)
601
+ candidates.add(test.file);
602
+ }
603
+ }
604
+ const files = [...candidates].filter((file) => {
605
+ try {
606
+ return SERIAL_DECLARATION.test(readFileSync(resolve(root, file), "utf8"));
607
+ }
608
+ catch {
609
+ return false;
610
+ }
611
+ }).sort();
612
+ writeJson(saved, files);
613
+ return files;
614
+ }
615
+
616
+ /**
617
+ * Spreads a pass's serial spec files over every invocation that names spec
618
+ * files: a harness that shares tests out to several `playwright test`
619
+ * processes (slots, each with a server and a database of its own) keeps a
620
+ * file with a serial describe whole, in one of them, and that one slot ran
621
+ * every mutant of the file while the others ended early. The strong pass runs
622
+ * a serial describe as a default one and takes a mutant's claim on a test
623
+ * pass-wide, so the file runs in each slot, which takes its own mutants of it
624
+ * from the shared queue. Playwright reads its file filters from the command
625
+ * line before it loads any config, so the preload adds them to `argv`
626
+ * (`argv[2]` is `test`), before Playwright parses it. A command that names
627
+ * no file runs every file already; `--list` is left as it is (a harness
628
+ * shares its tests out from it). The files added, or none.
629
+ */
630
+ export function spreadSerialFiles(argv, root) {
631
+ const pass = strongPass();
632
+ if (!pass || argv[2] !== "test" || argv.includes("--list"))
633
+ return [];
634
+ if (!fileFilters(argv.slice(3)).length)
635
+ return [];
636
+ const files = spreadFiles(pass, root);
637
+ argv.splice(3, 0, ...files.map(specFilter));
638
+ return files;
639
+ }
640
+
539
641
  /**
540
642
  * Whether this process lists the tests (`playwright test --list`) rather
541
643
  * than run them: it reads no plan and writes nothing, and lists the
@@ -685,15 +787,37 @@ export function installCopies(baseTest) {
685
787
  }
686
788
  arrange(suite);
687
789
  };
688
- prototype._describe = function (type, ...rest) {
689
- return describe.call(this, type === "serial" ? "default" : type === "serial.only" ? "only" : type, ...rest);
790
+ prototype._describe = function (type, location, ...rest) {
791
+ if (type === "serial" || type === "serial.only")
792
+ declaredSerial(location);
793
+ return describe.call(this, type === "serial" ? "default" : type === "serial.only" ? "only" : type, location, ...rest);
690
794
  };
691
795
  prototype._configure = function (location, options) {
796
+ if (options?.mode === "serial")
797
+ declaredSerial(location);
692
798
  return configure.call(this, location, options?.mode === "serial" ? { ...options, mode: "default" } : options);
693
799
  };
694
800
  return true;
695
801
  }
696
802
 
803
+ /**
804
+ * The spec files that declare a serial describe, as this process loaded
805
+ * them (the runner loads every file before its first test): a harness that
806
+ * keeps such a file's tests together gives it to one invocation, and the
807
+ * progress lines say what that costs.
808
+ */
809
+ const SERIAL_FILES = Symbol.for("supercov.serialFiles");
810
+ function declaredSerial(location) {
811
+ globalThis[SERIAL_FILES] ??= new Set();
812
+ if (location?.file)
813
+ globalThis[SERIAL_FILES].add(realFile(location.file));
814
+ }
815
+
816
+ /** Whether this process loaded `file` (a real path) with a serial describe in it. */
817
+ export function serialFile(file) {
818
+ return Boolean(globalThis[SERIAL_FILES]?.has(realFile(file)));
819
+ }
820
+
697
821
  let declaredCopies;
698
822
  function copiesOf(file, title) {
699
823
  if (!file)
@@ -984,11 +1108,20 @@ function workLeft(pass, test) {
984
1108
  * few tests, those whose runs left take longest. `held` are the tests the
985
1109
  * invocation runs.
986
1110
  */
987
- export function queuedWork(pass, work, held) {
1111
+ export function queuedWork(pass, work, held, serial = new Set()) {
988
1112
  const settledNow = new Set([...entries(`${pass.shared}/verdicts`), ...entries(`${pass.round}/killed`)]);
989
1113
  const claimed = new Map();
990
1114
  const tests = [];
1115
+ // Each serial file's mutants waiting for any of its tests.
1116
+ const serialWaiting = new Map();
991
1117
  let ms = 0;
1118
+ // Every serial file this invocation runs, whether or not a mutant waits
1119
+ // for it here now: which invocations run a file is what says it is
1120
+ // confined to one.
1121
+ for (const id of held) {
1122
+ if (serial.has(id) && work.tests[id] && !serialWaiting.has(work.tests[id].file))
1123
+ serialWaiting.set(work.tests[id].file, new Set());
1124
+ }
992
1125
  for (const id of held) {
993
1126
  const test = work.tests[id];
994
1127
  let waiting = 0;
@@ -998,8 +1131,11 @@ export function queuedWork(pass, work, held) {
998
1131
  continue;
999
1132
  if (!claimed.has(at))
1000
1133
  claimed.set(at, new Set(entries(`${pass.round}/claims/${at}`)));
1001
- if (!claimed.get(at).has(key(id)))
1002
- waiting += 1;
1134
+ if (claimed.get(at).has(key(id)))
1135
+ continue;
1136
+ waiting += 1;
1137
+ if (serial.has(id))
1138
+ serialWaiting.get(test.file).add(at);
1003
1139
  }
1004
1140
  if (!waiting)
1005
1141
  continue;
@@ -1008,7 +1144,8 @@ export function queuedWork(pass, work, held) {
1008
1144
  tests.push({ title: test.title ?? id, waiting, baselineMs, limitMs: limitOf(baselineMs, work.timeoutFactor) });
1009
1145
  }
1010
1146
  tests.sort((a, b) => b.waiting * b.baselineMs - a.waiting * a.baselineMs || a.title.localeCompare(b.title));
1011
- return { ms, tests: tests.slice(0, COSTLY_SHOWN) };
1147
+ const serialFiles = [...serialWaiting].map(([file, mutants]) => ({ file, mutants: mutants.size })).sort((a, b) => a.file.localeCompare(b.file));
1148
+ return { ms, tests: tests.slice(0, COSTLY_SHOWN), ...(serialFiles.length ? { serial: serialFiles } : {}) };
1012
1149
  }
1013
1150
 
1014
1151
  /**
@@ -1170,6 +1307,10 @@ export function outcomeOf(status, errors) {
1170
1307
  return { outcome: "passed" };
1171
1308
  if (status === "skipped")
1172
1309
  return { outcome: "skipped" };
1310
+ // Stopped from outside (the budget, a signal): it neither passed nor
1311
+ // failed, and settles nothing.
1312
+ if (status === "interrupted")
1313
+ return { outcome: "interrupted" };
1173
1314
  if (errors.length > 0 && timeout(errors[0]))
1174
1315
  return { outcome: "timed-out", message };
1175
1316
  return { outcome: "failed", message };
@@ -10,8 +10,9 @@
10
10
  // verdict its verdict, or the round that runs it next: one verdict a mutant,
11
11
  // from whichever invocations ran it, and what was cut short is unfinished.
12
12
  import { appendFileSync, existsSync, readFileSync, realpathSync, statSync } from "node:fs";
13
+ import { dirname, join } from "node:path";
13
14
  import { pathToFileURL } from "node:url";
14
- import { attemptPath, baselineOf, entries, invocation, EVERYWHERE, firstWords, giveVerdict, key, loadPass, outcomeOf, placeOf, queuedWork, readJson, reasonOf, settleAttempt, strongPass, verdictOf, withoutCopy, writeJson } from "./playwrightStrong.mjs";
15
+ import { attemptPath, baselineOf, entries, invocation, EVERYWHERE, firstWords, giveVerdict, key, loadPass, outcomeOf, placeOf, queuedWork, readJson, reasonOf, serialFile, settleAttempt, strongPass, verdictOf, withoutCopy, writeJson } from "./playwrightStrong.mjs";
15
16
 
16
17
  // How often, at most, the status file is written.
17
18
  const STATUS_MS = 1_000;
@@ -68,6 +69,8 @@ export default class SupercovPlaywrightStrongReporter {
68
69
  // The tests this invocation runs, and the baseline time of the runs
69
70
  // it ended: its pace, for the time its work left takes.
70
71
  this.held = [];
72
+ // Those of them in a file with a serial describe.
73
+ this.serial = new Set();
71
74
  this.doneMs = 0;
72
75
  this.queuedAt = 0;
73
76
  }
@@ -91,8 +94,11 @@ export default class SupercovPlaywrightStrongReporter {
91
94
  if (withoutCopy(test.titlePath()).copy)
92
95
  continue;
93
96
  writeJson(`${this.pass.round}/originals/${key(placeOf(test))}`, test.id);
94
- if (this.work.tests[test.id]?.jobs)
97
+ if (this.work.tests[test.id]?.jobs) {
95
98
  this.held.push(test.id);
99
+ if (serialFile(test.location.file))
100
+ this.serial.add(test.id);
101
+ }
96
102
  }
97
103
  this.copies = copies;
98
104
  const mutants = Object.keys(this.work.entries).length;
@@ -227,7 +233,7 @@ export default class SupercovPlaywrightStrongReporter {
227
233
  countQueued() {
228
234
  this.queuedAt = Date.now();
229
235
  try {
230
- const queued = queuedWork(this.pass, this.work, this.held);
236
+ const queued = queuedWork(this.pass, this.work, this.held, this.serial);
231
237
  const spent = (this.lastEndedAt ?? 0) - (this.firstStartedAt ?? 0);
232
238
  if (this.doneMs > 0 && spent > 0)
233
239
  queued.leftMs = Math.round((queued.ms * spent) / this.doneMs);
@@ -321,7 +327,13 @@ export default class SupercovPlaywrightStrongReporter {
321
327
  else
322
328
  serial.push(job);
323
329
  };
324
- const trustedUntil = globalError ? globalError.at : Infinity;
330
+ // A round the budget or a signal stopped: from the moment it began
331
+ // to stop (`stopped-at`, beside the results), its servers went down
332
+ // under the tests still running, and a test that ended after it
333
+ // says nothing of its mutant. So, from an error outside any test.
334
+ const stopped = process.env["SUPERCOV_STRONG_STOPPED"] === "1";
335
+ const stoppedAt = Number(readJsonOr(join(dirname(pass.resultsPath), "stopped-at"))) || Infinity;
336
+ const trustedUntil = Math.min(globalError ? globalError.at : Infinity, stoppedAt);
325
337
  // One mutant an invocation: which invocation took each, and where a
326
338
  // server of that invocation ran it (an invocation whose server was
327
339
  // started before it, outside it, never ran its mutant there).
@@ -365,7 +377,8 @@ export default class SupercovPlaywrightStrongReporter {
365
377
  continue;
366
378
  }
367
379
  // A kill no control came after (the round ended first): as sure as a
368
- // kill on a server no other mutant's attempt shared.
380
+ // kill on a server no other mutant's attempt shared, where it ended
381
+ // before the round began to stop.
369
382
  const killer = failed.find((attempt) => !attempt.beside && attempt.endedAt < trustedUntil);
370
383
  if (killer) {
371
384
  const { status, reason } = verdictOf(killer);
@@ -408,12 +421,26 @@ export default class SupercovPlaywrightStrongReporter {
408
421
  }
409
422
  for (const job of work.restarts)
410
423
  next(job, job.reason, job.tests);
424
+ // What each mutant left open passed: its candidates that ran with it
425
+ // and passed (before any error outside a test), by the plan's ids. A
426
+ // later pass, or a later round, resumes there. A round of mutants a
427
+ // server ran from its start lends nothing to a request's own switch.
428
+ if (kind !== "alone") {
429
+ for (const id of Object.keys(work.entries)) {
430
+ if (existsSync(`${pass.shared}/verdicts/${key(id)}`))
431
+ continue;
432
+ const passed = (byMutant.get(id) ?? [])
433
+ .filter((attempt) => attempt.outcome === "passed" && attempt.endedAt < trustedUntil)
434
+ .map((attempt) => work.tests[attempt.original]?.planId ?? attempt.original);
435
+ if (passed.length)
436
+ write({ progress: true, id, passed: [...new Set(passed)].sort() });
437
+ }
438
+ }
411
439
  // A round of what an earlier one left that ran to its end and decided
412
440
  // nothing would only ask for the same again. One the budget or a
413
441
  // signal stopped leaves its mutants without a verdict, for the next
414
442
  // pass (a confirmation round stopped before its first test made two
415
443
  // mutants of a 60 s pass `error`s).
416
- const stopped = process.env["SUPERCOV_STRONG_STOPPED"] === "1";
417
444
  if (kind !== "main" && !decided && !stopped) {
418
445
  for (const job of rest)
419
446
  write({ id: job.id, status: "error", reason: "its tests did not finish, in two rounds", tests: 0, durationMs: 0 });
@@ -1086,6 +1086,14 @@ if (generatedPlaywrightConfig &&
1086
1086
  }
1087
1087
  }
1088
1088
  process.argv.push("--config", generatedPlaywrightConfig);
1089
+ // A strong pass spreads its serial spec files over every invocation of
1090
+ // Playwright that names spec files (playwrightStrong.mjs).
1091
+ if (process.env.SUPERCOV_STRONG_PLAN) {
1092
+ const strong = await import(__rewriteRelativeImportExtension(new URL("./playwrightStrong.mjs", import.meta.url)));
1093
+ const spread = strong.spreadSerialFiles(process.argv, projectRoot ?? process.cwd());
1094
+ if (spread.length)
1095
+ console.log(`[supercov] strong pass: ${spread.length} spec file(s) with a serial describe run in this invocation too, each taking its own mutants of them: ${spread.join(", ")}`);
1096
+ }
1089
1097
  }
1090
1098
  // A process the runner marked as not a test worker skips the wrapper, unless
1091
1099
  // it was started from Playwright's own files: a worker Playwright starts some