supercov 4.29.14 → 4.29.16

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.
@@ -9,10 +9,11 @@
9
9
  // disk that every worker and every invocation of the pass share. A mutant
10
10
  // goes from candidate to candidate as copies take it, and stops at its first
11
11
  // kill; nothing waits for a stage to end, and no worker restarts for a
12
- // mutant. A test's first run in each invocation is a control, with no
13
- // mutant: the pass's baseline the first time; and after a kill, the test's
14
- // next run is one too, the check that it still passes without the mutant on
15
- // the same server, which confirms the kill. A harness may start several
12
+ // mutant, nor after one fails its test (`keepsWorker`). A test's first run
13
+ // in each invocation is a control, with no mutant: the pass's baseline the
14
+ // first time; and after a kill, the test's next run is one too, the check
15
+ // that it still passes without the mutant on the same server, which
16
+ // confirms the kill. A harness may start several
16
17
  // invocations at once, each with a share of the tests; they share the pass's
17
18
  // files and decide the same way.
18
19
  //
@@ -46,6 +47,19 @@
46
47
  // mutant broke ends there; an attempt that ran out of it is a `timeout`,
47
48
  // confirmed as a kill is.
48
49
  //
50
+ // Such an attempt ends sooner where it has stalled (`watchStall`): past every
51
+ // time a run of its test that passed took (its baseline × the factor + 1 s),
52
+ // waiting on a Playwright call that cannot end by its own timeout before the
53
+ // limit (a click with no timeout, an `expect` given 15 s), with its pages
54
+ // quiet (no request sent or answered for a second) and nothing left in them
55
+ // that could end the wait before the limit (`pendingBefore`): no timer,
56
+ // animation frame or ending animation due before it, no request unanswered,
57
+ // no open WebSocket, no worker. Nothing it waits on can make it fail before
58
+ // the limit, nothing the page has yet to do can make it pass, and no passing
59
+ // run took that long: the limit would end it as a `timeout` all the same,
60
+ // later. Where the page could still end the wait (it polls on a timer), the
61
+ // attempt runs to its limit: its verdict is whatever that run gives.
62
+ //
49
63
  // This module holds what the config, the fixture (playwright.mjs) and the
50
64
  // reporter (playwrightStrongReporter.mjs) share.
51
65
  import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
@@ -54,6 +68,24 @@ import { basename, dirname, resolve, sep } from "node:path";
54
68
 
55
69
  const TIMEOUT_FACTOR = 1.5;
56
70
  const TIMEOUT_CONSTANT_MS = 5_000;
71
+ // Past its baseline × the factor + this, an attempt has outlasted every run
72
+ // of its test that passed: on a large app's suite, 5,831 attempts that passed
73
+ // took at most 0.5 s past their baseline.
74
+ const STALL_CONSTANT_MS = 1_000;
75
+ // How long an attempt's pages must have sent and answered no request.
76
+ const QUIET_MS = 1_000;
77
+ // How often a stalled attempt is looked for.
78
+ const STALL_POLL_MS = 100;
79
+ // How long a page has to say what it has yet to do; one that cannot answer is
80
+ // busy.
81
+ export const PAGE_ANSWER_MS = 1_000;
82
+ // How soon a stall the page could still end, with nothing due at a known
83
+ // time (a request unanswered, a socket open), is looked at again.
84
+ const DOUBT_RETRY_MS = 500;
85
+ // Playwright's calls that wait for a navigation, under its navigation timeout.
86
+ const NAVIGATIONS = new Set(["goto", "reload", "goBack", "goForward", "waitForURL", "waitForNavigation", "waitForLoadState"]);
87
+ // An API request's own timeout where nothing sets one (Playwright's default).
88
+ const REQUEST_TIMEOUT_MS = 30_000;
57
89
  const DEFAULT_DURATION_MS = 1_000;
58
90
  // How much likelier to kill a mutant a test is taken to be where its own
59
91
  // evidence infected it than where it only reached it: what orders a mutant's
@@ -187,13 +219,312 @@ export function limitOf(baselineMs, factor) {
187
219
  return Math.ceil(baselineMs * factor + TIMEOUT_CONSTANT_MS);
188
220
  }
189
221
 
190
- /** What a verdict says of an attempt that ran out of its time limit. */
222
+ /** What a timeout's reason says where the attempt ran to its limit past a stall its pages could have ended. */
223
+ export const CONFIRMED_AT_LIMIT = "it ran to its limit to confirm";
224
+
225
+ /** What a verdict says of an attempt that ran out of its time limit, or stalled before it. */
191
226
  function limitReason(attempt) {
192
227
  const seconds = (ms) => `${(ms / 1000).toFixed(1)} s`;
228
+ const waiting = attempt.waitingOn ? `, waiting on ${attempt.waitingOn}` : "";
229
+ if (attempt.stalledAtMs !== undefined)
230
+ return `stopped at ${seconds(attempt.stalledAtMs)} of its ${seconds(attempt.limitMs)} time limit, past every run of the test that passed (${attempt.timeoutFactor} × its ${seconds(attempt.baselineMs)} baseline + ${STALL_CONSTANT_MS / 1000} s), its pages quiet with nothing due before the limit${waiting}, which cannot end before the limit`;
193
231
  const why = attempt.limitMs < limitOf(attempt.baselineMs, attempt.timeoutFactor)
194
232
  ? "the test's own timeout"
195
233
  : `${attempt.timeoutFactor} × its ${seconds(attempt.baselineMs)} baseline + ${TIMEOUT_CONSTANT_MS / 1000} s`;
196
- return `ran past its time limit of ${seconds(attempt.limitMs)} (${why})`;
234
+ // It stalled where its pages could still end the wait: the limit, not
235
+ // the stall, decided it.
236
+ const confirmed = attempt.doubtedAtMs !== undefined
237
+ ? `; it stalled at ${seconds(attempt.doubtedAtMs)}, with ${attempt.doubtedBy} that could still end the wait, so ${CONFIRMED_AT_LIMIT}`
238
+ : "";
239
+ return `ran past its time limit of ${seconds(attempt.limitMs)} (${why})${waiting}${confirmed}`;
240
+ }
241
+
242
+ /**
243
+ * When a Playwright call the test made ends by its own timeout, from when it
244
+ * began: `Infinity` where it has none. `method` is the call, `args` what it
245
+ * was given; `request` says it is an API request's; `timeouts` are the test's
246
+ * defaults (`action`, `navigation`; 0 for none). An `expect` on a locator
247
+ * reaches Playwright as `_expect`, with the timeout it runs under.
248
+ */
249
+ export function ownDeadline({ method, args, startedAt, request, timeouts }) {
250
+ const after = (ms) => (ms > 0 ? startedAt + ms : Infinity);
251
+ if (method === "waitForTimeout")
252
+ return startedAt + (Number(args[0]) || 0);
253
+ const options = [...args].reverse().find((arg) => arg !== null && typeof arg === "object" && typeof arg.timeout === "number");
254
+ if (options)
255
+ return after(options.timeout);
256
+ if (request)
257
+ return after(timeouts.action > 0 ? Math.min(timeouts.action, REQUEST_TIMEOUT_MS) : REQUEST_TIMEOUT_MS);
258
+ if (NAVIGATIONS.has(method))
259
+ return after(timeouts.navigation || timeouts.action);
260
+ return after(timeouts.action);
261
+ }
262
+
263
+ /**
264
+ * A Playwright call as a timeout's reason names it (a bundled
265
+ * Playwright's `_Locator` is a `Locator`): `Locator.click (#save)`, `expect(#save) to.be.visible`, `expect to.have.url`,
266
+ * `Page.waitForURL`.
267
+ */
268
+ export function describeCall(object, method, args) {
269
+ const selector = typeof object?._selector === "string" ? object._selector : undefined;
270
+ const said = method === "_expect"
271
+ ? `expect${selector ? `(${selector})` : ""} ${args[0]}`
272
+ : `${(object?.constructor?.name ?? "Playwright").replace(/^_+/, "")}.${method}${selector ? ` (${selector})` : ""}`;
273
+ return said.length > 160 ? `${said.slice(0, 159)}…` : said;
274
+ }
275
+
276
+ /**
277
+ * The call a stalled attempt waits on, or `undefined`: the newest Playwright
278
+ * call, one the test's own code made, has not returned, no call still running can end by its
279
+ * own timeout before `limitAt`, and its pages have been quiet since
280
+ * `quietSince` for a second.
281
+ */
282
+ export function stalledOn({ waits, newest, limitAt, quietSince, now }) {
283
+ // The newest call is the test's own (a fixture's setup, such as a new
284
+ // page, is no wait of the test's).
285
+ if (!newest || !waits.has(newest) || !newest.fromTest)
286
+ return undefined;
287
+ if (now - quietSince < QUIET_MS)
288
+ return undefined;
289
+ for (const wait of waits) {
290
+ if (wait.deadline < limitAt)
291
+ return undefined;
292
+ }
293
+ return newest;
294
+ }
295
+
296
+ /**
297
+ * What a page could still do that may end a wait before `limitAt`, as one
298
+ * phrase, and when to ask again (`retryAt`); `undefined` where nothing can.
299
+ * `frames` is each frame's answer to `watchPageWork`'s query: its earliest
300
+ * due timer, animation frame or ending animation (`due`, ms since the epoch,
301
+ * or null) and its open sockets; `null` where the frame has no watch (an
302
+ * empty one, `about:blank`, has nothing to run), `PAGE_BUSY` where it did not
303
+ * answer in time, `PAGE_GONE` where its document went away meanwhile.
304
+ * `requests` are those sent and not yet answered, `workers` the page workers
305
+ * running.
306
+ */
307
+ export function pendingBefore({ frames, requests, workers, limitAt, now }) {
308
+ const again = { retryAt: now + DOUBT_RETRY_MS };
309
+ if (requests > 0)
310
+ return { because: `${requests} unanswered request(s)`, ...again };
311
+ if (workers > 0)
312
+ return { because: `${workers} worker(s) running in its pages`, ...again };
313
+ let due = Infinity;
314
+ for (const { url, answer } of frames) {
315
+ if (answer === PAGE_BUSY)
316
+ return { because: "a page that did not answer", ...again };
317
+ if (answer === PAGE_GONE)
318
+ return { because: "a page loading a new document", ...again };
319
+ if (answer === null || answer === undefined) {
320
+ if (url === "about:blank" || url === "")
321
+ continue;
322
+ return { because: `a frame with no watch on its timers (${url})`, ...again };
323
+ }
324
+ if (answer.sockets > 0)
325
+ return { because: `${answer.sockets} open WebSocket(s)`, ...again };
326
+ if (typeof answer.due === "number")
327
+ due = Math.min(due, answer.due);
328
+ }
329
+ if (due < limitAt)
330
+ return { because: `a timer due in ${(Math.max(0, due - now) / 1000).toFixed(1)} s`, retryAt: Math.max(due, now) + STALL_POLL_MS };
331
+ return undefined;
332
+ }
333
+ /** A frame that did not answer in time. */
334
+ export const PAGE_BUSY = "busy";
335
+ /** A frame whose document went away while it was asked. */
336
+ export const PAGE_GONE = "gone";
337
+
338
+ /**
339
+ * Keeps what a document has yet to do that could change it: its timers,
340
+ * animation frames and idle callbacks, its WebSockets; an init script,
341
+ * before the page's own scripts. `globalThis[Symbol.for("supercov.pageWork")]()`
342
+ * answers with the earliest of them due (a running animation that ends
343
+ * counts at its end; media that plays, now) and the sockets open. The page's
344
+ * functions keep their behaviour: each call goes to the browser's own, with
345
+ * what it was given.
346
+ */
347
+ export function watchPageWork() {
348
+ const watchKey = Symbol.for("supercov.pageWork");
349
+ if (globalThis[watchKey])
350
+ return;
351
+ const timers = new Map();
352
+ const frames = new Set();
353
+ const sockets = new Set();
354
+ const own = {};
355
+ for (const name of ["setTimeout", "setInterval", "clearTimeout", "clearInterval", "requestAnimationFrame", "cancelAnimationFrame", "requestIdleCallback", "cancelIdleCallback"])
356
+ own[name] = globalThis[name];
357
+ const forget = (id) => timers.delete(id);
358
+ const timer = (kind) => function (handler, delay, ...rest) {
359
+ const ms = Math.max(0, Number(delay) || 0);
360
+ const entry = { at: Date.now() + ms, every: kind === "setInterval" ? ms : undefined, loose: typeof handler !== "function" };
361
+ let id;
362
+ const run = entry.loose || entry.every !== undefined
363
+ ? handler
364
+ : function (...args) {
365
+ forget(id);
366
+ return handler.apply(this, args);
367
+ };
368
+ id = own[kind].call(globalThis, run, delay, ...rest);
369
+ timers.set(id, entry);
370
+ return id;
371
+ };
372
+ globalThis.setTimeout = timer("setTimeout");
373
+ globalThis.setInterval = timer("setInterval");
374
+ // The browser's ids are one pool: either clears either.
375
+ for (const name of ["clearTimeout", "clearInterval"]) {
376
+ globalThis[name] = function (id) {
377
+ forget(id);
378
+ return own[name].call(globalThis, id);
379
+ };
380
+ }
381
+ const callback = (request, cancel, kind) => {
382
+ if (typeof own[request] !== "function")
383
+ return;
384
+ globalThis[request] = function (handler, ...rest) {
385
+ let id;
386
+ const run = typeof handler === "function"
387
+ ? function (...args) {
388
+ frames.delete(`${kind}${id}`);
389
+ return handler.apply(this, args);
390
+ }
391
+ : handler;
392
+ id = own[request].call(globalThis, run, ...rest);
393
+ frames.add(`${kind}${id}`);
394
+ return id;
395
+ };
396
+ globalThis[cancel] = function (id) {
397
+ frames.delete(`${kind}${id}`);
398
+ return own[cancel].call(globalThis, id);
399
+ };
400
+ };
401
+ callback("requestAnimationFrame", "cancelAnimationFrame", "frame");
402
+ callback("requestIdleCallback", "cancelIdleCallback", "idle");
403
+ if (typeof globalThis.WebSocket === "function") {
404
+ globalThis.WebSocket = new Proxy(globalThis.WebSocket, {
405
+ construct(target, args, newTarget) {
406
+ const socket = Reflect.construct(target, args, newTarget);
407
+ sockets.add(socket);
408
+ socket.addEventListener("close", () => sockets.delete(socket));
409
+ return socket;
410
+ },
411
+ });
412
+ }
413
+ Object.defineProperty(globalThis, watchKey, {
414
+ configurable: true,
415
+ value: () => {
416
+ const now = Date.now();
417
+ let due = frames.size > 0 ? now : Infinity;
418
+ for (const [id, entry] of timers) {
419
+ if (entry.every !== undefined)
420
+ due = Math.min(due, entry.at > now || entry.every === 0 ? Math.max(entry.at, now) : entry.at + Math.ceil((now - entry.at) / entry.every) * entry.every);
421
+ // A string's timer is not seen to run: past its time by a
422
+ // second, it ran.
423
+ else if (entry.loose && entry.at < now - 1_000)
424
+ timers.delete(id);
425
+ else
426
+ due = Math.min(due, Math.max(entry.at, now));
427
+ }
428
+ const document = globalThis.document;
429
+ for (const animation of document?.getAnimations?.() ?? []) {
430
+ const timing = animation.playState === "running" ? animation.effect?.getComputedTiming?.() : undefined;
431
+ if (timing && Number.isFinite(timing.endTime))
432
+ due = Math.min(due, now + Math.max(0, timing.endTime - (Number(timing.localTime) || 0)) / (Math.abs(animation.playbackRate) || 1));
433
+ }
434
+ for (const media of document?.querySelectorAll?.("video, audio") ?? []) {
435
+ if (!media.paused && !media.ended)
436
+ due = now;
437
+ }
438
+ let open = 0;
439
+ for (const socket of sockets) {
440
+ if (socket.readyState === 3)
441
+ sockets.delete(socket);
442
+ else
443
+ open += 1;
444
+ }
445
+ return { due: Number.isFinite(due) ? due : null, sockets: open };
446
+ },
447
+ });
448
+ }
449
+
450
+ /** When, from its start, a mutant attempt has outlasted every passing run of its test. */
451
+ export function stallWindowOf(baselineMs, factor) {
452
+ return Math.ceil(baselineMs * factor + STALL_CONSTANT_MS);
453
+ }
454
+
455
+ /**
456
+ * Ends a mutant attempt as a timeout once it has stalled (`stalledOn`, asked
457
+ * of `look(limitAt)` every tenth of a second from the end of its window, which
458
+ * counts from the first call the test's own code made, `since`), and nothing
459
+ * its pages have yet to do could end the wait before the limit (`doubt(limitAt)`,
460
+ * `pendingBefore`'s answer): its test's timeout is set to what it has already
461
+ * run. A stall its pages could still end is looked at again when that is due,
462
+ * and meanwhile the attempt goes on. The watch says when it stopped and on
463
+ * what (`stalled`), when it first stalled where its pages could still end the
464
+ * wait and why (`doubted`), and, where it went on to its limit, what it last
465
+ * waited on (`waiting`). `stop()` ends the watch.
466
+ */
467
+ export function watchStall(testInfo, claimed, look, doubt) {
468
+ if (claimed?.kind !== "mutant")
469
+ return undefined;
470
+ const from = claimed.startedAt + stallWindowOf(claimed.baselineMs, claimed.timeoutFactor);
471
+ if (from >= claimed.limitAt)
472
+ return undefined;
473
+ const windowMs = stallWindowOf(claimed.baselineMs, claimed.timeoutFactor);
474
+ const watch = { stalled: undefined, doubted: undefined, waiting: undefined, timer: undefined, stopped: false };
475
+ // A test whose body has ended (it failed, ran out of time, or its
476
+ // fixtures are being torn down: Playwright sets its duration then) waits
477
+ // on nothing of its own: what its teardown closes is not what it waited
478
+ // on.
479
+ const ended = () => watch.stopped || testInfo.status !== "passed" || testInfo.duration > 0;
480
+ const later = (ms) => {
481
+ watch.timer = setTimeout(check, Math.max(STALL_POLL_MS, ms));
482
+ };
483
+ const check = () => {
484
+ if (ended())
485
+ return;
486
+ const { stalled, waiting, since } = look(claimed.limitAt);
487
+ watch.waiting = waiting;
488
+ // The window counts from the test's first call of its own, not from
489
+ // its claim: setting up its page in a new worker on a loaded machine
490
+ // took seconds, which no baseline holds.
491
+ const pastWindow = Date.now() >= since + windowMs;
492
+ if (!stalled || !pastWindow) {
493
+ later(STALL_POLL_MS);
494
+ return;
495
+ }
496
+ doubt(claimed.limitAt).then((pending) => {
497
+ if (ended())
498
+ return;
499
+ if (pending) {
500
+ watch.doubted ??= { atMs: Date.now() - claimed.startedAt, waitingOn: stalled };
501
+ watch.doubted.because = pending.because;
502
+ later(pending.retryAt - Date.now());
503
+ return;
504
+ }
505
+ // Still stalled on the same call, once its pages answered.
506
+ if (look(claimed.limitAt).stalled !== stalled) {
507
+ later(STALL_POLL_MS);
508
+ return;
509
+ }
510
+ watch.stalled = { atMs: Date.now() - claimed.startedAt, waitingOn: stalled };
511
+ testInfo.setTimeout(Math.max(1, Date.now() - claimed.claimedAt));
512
+ }, () => later(STALL_POLL_MS));
513
+ };
514
+ watch.timer = setTimeout(check, Math.max(0, from - Date.now()));
515
+ watch.stop = () => {
516
+ watch.stopped = true;
517
+ clearTimeout(watch.timer);
518
+ };
519
+ return watch;
520
+ }
521
+
522
+ /** What a stall watch adds to its attempt's end. */
523
+ export function stallDetails(watch) {
524
+ if (watch?.stalled)
525
+ return { stalledAtMs: watch.stalled.atMs, waitingOn: watch.stalled.waitingOn };
526
+ const doubted = watch?.doubted ? { doubtedAtMs: watch.doubted.atMs, doubtedBy: watch.doubted.because } : {};
527
+ return { ...(watch?.waiting ? { waitingOn: watch.waiting } : {}), ...doubted };
197
528
  }
198
529
 
199
530
  /**
@@ -316,7 +647,7 @@ function buildPass(pass, root, config) {
316
647
  if (job && job.kind !== "main") {
317
648
  for (const entry of job.mutants) {
318
649
  const all = [...entry.tests, ...(entry.rest ?? [])].filter((id) => tests[id]);
319
- mutants.push({ id: entry.id, mutant: entry.mutant, tests: [...new Set(all)], reason: entry.reason });
650
+ mutants.push({ id: entry.id, mutant: entry.mutant, tests: [...new Set(all)], reason: entry.reason, ...(entry.serverRan ? { serverRan: true } : {}) });
320
651
  }
321
652
  // A serial round runs one test at a time: what it kills, nothing
322
653
  // beside it did.
@@ -397,7 +728,7 @@ function buildPass(pass, root, config) {
397
728
  restarts.push({ id: mutant.id, mutant: switched, tests: ordered, reason: serverWide });
398
729
  continue;
399
730
  }
400
- mutants.push({ id: mutant.id, mutant: switched, tests: ordered, infected, ...(mutant.passedBefore ? { passedBefore: mutant.passedBefore } : {}) });
731
+ mutants.push({ id: mutant.id, mutant: switched, tests: ordered, infected, ...(mutant.passedBefore ? { passedBefore: mutant.passedBefore } : {}), ...(mutant.serverRan ? { serverRan: true } : {}) });
401
732
  }
402
733
  }
403
734
  // What a survivor's verdict says of the candidates it was not run with.
@@ -1412,6 +1743,7 @@ export async function strongClaim(testInfo) {
1412
1743
  else if (configured > 0)
1413
1744
  testInfo.setTimeout(Date.now() - started + configured);
1414
1745
  const { running, beside } = startRunning(pass, testInfo.testId, attempt.mutant);
1746
+ const startedAt = Date.now();
1415
1747
  const claimed = {
1416
1748
  original,
1417
1749
  title: test.title,
@@ -1421,8 +1753,10 @@ export async function strongClaim(testInfo) {
1421
1753
  kind: attempt.kind,
1422
1754
  id: attempt.id,
1423
1755
  mutant: attempt.mutant,
1424
- ...(attempt.kind === "mutant" ? { baselineMs: attempt.baselineMs, limitMs: attempt.limitMs, timeoutFactor: attempt.timeoutFactor, ...(attempt.cold ? { cold: true } : {}) } : {}),
1425
- startedAt: Date.now(),
1756
+ // A mutant's: when its limit ends it, and when its claim began,
1757
+ // which the test's timeout counts from (`watchStall`).
1758
+ ...(attempt.kind === "mutant" ? { baselineMs: attempt.baselineMs, limitMs: attempt.limitMs, timeoutFactor: attempt.timeoutFactor, limitAt: startedAt + attempt.limitMs, claimedAt: started, ...(attempt.cold ? { cold: true } : {}) } : {}),
1759
+ startedAt,
1426
1760
  lock,
1427
1761
  running,
1428
1762
  besideAtStart: beside,
@@ -1480,11 +1814,44 @@ function passedWith(pass, id) {
1480
1814
  return new Set(entries(`${pass.round}/passed/${key(id)}`));
1481
1815
  }
1482
1816
 
1817
+ /**
1818
+ * The mutants an attempt ran on its server, in work one of its requests set
1819
+ * off (`noteRequestHit` in runtime.mjs): their switches, `file#index`.
1820
+ */
1821
+ export function ranByRequests(pass) {
1822
+ const ran = new Set();
1823
+ const path = `${pass.resultsPath}.reached.jsonl`;
1824
+ if (!existsSync(path))
1825
+ return ran;
1826
+ for (const line of readFileSync(path, "utf8").split("\n")) {
1827
+ try {
1828
+ ran.add(JSON.parse(line).mutant);
1829
+ }
1830
+ catch {
1831
+ // A line a process was still writing, or none.
1832
+ }
1833
+ }
1834
+ return ran;
1835
+ }
1836
+
1837
+ /**
1838
+ * Whether a survivor of a shared server is in doubt: its candidates' servers
1839
+ * ran its code when measured, and no attempt of it ran it here. The request
1840
+ * that reached its code did not carry the attempt's mutant (`unreached`): its
1841
+ * verdict is the one it gets alone, with the server started with it.
1842
+ */
1843
+ export function unreached(kind, entry, ran) {
1844
+ return kind !== "alone" && entry.serverRan === true && !ran.has(entry.mutant);
1845
+ }
1846
+
1483
1847
  /** A mutant every candidate test lets live, now that one more passed with it: its verdict. */
1484
1848
  function surviveIfDone(pass, id) {
1485
1849
  if (settled(pass, id) || existsSync(`${pass.round}/confirm/${key(id)}`) || existsSync(`${pass.round}/doubt/${key(id)}`))
1486
1850
  return;
1487
1851
  const entry = mutantOf(pass, id);
1852
+ // The round's judge sends it to run alone.
1853
+ if (unreached(loadWorker(pass).kind, entry, ranByRequests(pass)))
1854
+ return;
1488
1855
  const passed = passedWith(pass, id);
1489
1856
  // Every candidate passed with it: one that failed without it is left to
1490
1857
  // the round's judge, once its controls are all known.
@@ -1503,8 +1870,9 @@ export const WHY = {
1503
1870
  "unfinished": "not every candidate test ran in the shared pass",
1504
1871
  "confirm": "a test killed it beside other mutants' attempts",
1505
1872
  "doubt": "the test that killed it failed without it too, on the same server",
1873
+ "unreached": "its candidates passed on the shared server, yet no attempt of theirs ran it there: the requests that reached its code did not carry their test's mutant",
1506
1874
  };
1507
- export const EVERYWHERE = ["background", "module-level", "by-time"];
1875
+ export const EVERYWHERE = ["background", "module-level", "by-time", "unreached"];
1508
1876
 
1509
1877
  /** What a verdict from a later round says of it. */
1510
1878
  export function reasonOf(kind, reason) {
@@ -1670,6 +2038,25 @@ export function ranInWorker(claimed, attemptId) {
1670
2038
  return Boolean(strong?.requestHits?.get?.(`${attemptId}\0${claimed.mutant}`));
1671
2039
  }
1672
2040
 
2041
+ /**
2042
+ * Whether a mutant attempt that failed or ran out of time keeps its worker
2043
+ * for the next copy: Playwright ends a worker after a test fails, to start
2044
+ * the next test in a new one with a new browser, and on a large app's e2e
2045
+ * suite a failed attempt was one in seven. The failure is the mutant's, in
2046
+ * the app it was switched on in, and the worker's process ran none of it
2047
+ * (`ranInWorker`), so the worker is as before. The attempt is marked as
2048
+ * expected to end so (`expectedStatus`), which Playwright reads after the
2049
+ * test's fixtures are torn down; its verdict is read from its status, as
2050
+ * before. A control that fails (no mutant) still ends its worker, and so
2051
+ * does an attempt whose mutant ran in the worker's own process. A kill is
2052
+ * confirmed by its test's next control on the same server, as before: a
2053
+ * worker the failure did leave unfit fails that control, and puts the kill
2054
+ * in doubt.
2055
+ */
2056
+ export function keepsWorker(claimed, ranHere, status) {
2057
+ return claimed?.kind === "mutant" && !ranHere && (status === "failed" || status === "timedOut");
2058
+ }
2059
+
1673
2060
  /**
1674
2061
  * Switches a document's mutant on before its scripts run: an init script.
1675
2062
  * Every copy of the runtime in the page reads the state from here.
@@ -12,7 +12,7 @@
12
12
  import { appendFileSync, existsSync, readFileSync, realpathSync, statSync } from "node:fs";
13
13
  import { dirname, join } from "node:path";
14
14
  import { pathToFileURL } from "node:url";
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
+ import { attemptPath, baselineOf, entries, invocation, EVERYWHERE, firstWords, giveVerdict, key, loadPass, outcomeOf, placeOf, queuedWork, ranByRequests, readJson, reasonOf, serialFile, settleAttempt, strongPass, unreached, verdictOf, withoutCopy, writeJson } from "./playwrightStrong.mjs";
16
16
 
17
17
  // How often, at most, the status file is written.
18
18
  const STATUS_MS = 1_000;
@@ -40,6 +40,11 @@ function readJsonOr(path) {
40
40
  }
41
41
  }
42
42
 
43
+ /** Ids for a message: the first few, and how many more. */
44
+ function listed(ids) {
45
+ const shown = ids.slice(0, 5).join(", ");
46
+ return ids.length > 5 ? `${shown} and ${ids.length - 5} more` : shown;
47
+ }
43
48
  function readLines(path) {
44
49
  if (!existsSync(path))
45
50
  return [];
@@ -173,12 +178,21 @@ export default class SupercovPlaywrightStrongReporter {
173
178
  const said = {
174
179
  "passed": "lives",
175
180
  "failed": "fails",
176
- "timed-out": `ran out of its ${seconds(attempt.limitMs)} limit (its baseline ${seconds(attempt.baselineMs)})`,
181
+ "timed-out": attempt.stalledAtMs === undefined
182
+ ? `ran out of its ${seconds(attempt.limitMs)} limit (its baseline ${seconds(attempt.baselineMs)})`
183
+ : `stalled before its ${seconds(attempt.limitMs)} limit (its baseline ${seconds(attempt.baselineMs)})`,
177
184
  }[attempt.outcome] ?? attempt.outcome;
185
+ // What a timeout waited on, where the fixture saw it.
186
+ const waiting = attempt.outcome === "timed-out" && attempt.waitingOn ? `, waiting on ${attempt.waitingOn}` : "";
187
+ // A stall its pages could still have ended: it ran on, and what
188
+ // that run gave is its outcome.
189
+ const doubted = attempt.doubtedAtMs === undefined
190
+ ? ""
191
+ : `, past a stall at ${seconds(attempt.doubtedAtMs)} with ${attempt.doubtedBy} that could still end the wait`;
178
192
  // A cold attempt's failure decides nothing: it runs again once a
179
193
  // control has passed on its server.
180
194
  const cold = attempt.cold && (attempt.outcome === "failed" || attempt.outcome === "timed-out") ? ", before any control here: runs again after one" : "";
181
- console.log(`[supercov] ${attempt.id}: ${JSON.stringify(attempt.title)} ${said} (${took}${cold})`);
195
+ console.log(`[supercov] ${attempt.id}: ${JSON.stringify(attempt.title)} ${said}${waiting}${doubted} (${took}${cold})`);
182
196
  }
183
197
  /**
184
198
  * What this invocation is doing, for the engine's progress line: the
@@ -319,7 +333,7 @@ export default class SupercovPlaywrightStrongReporter {
319
333
  write({ id: entry.id, status: "error", reason: "its candidate tests fail without any mutant", tests: 0, durationMs: 0 });
320
334
  return;
321
335
  }
322
- const job = { id: entry.id, mutant: entry.mutant, tests: runnable, reason };
336
+ const job = { id: entry.id, mutant: entry.mutant, tests: runnable, reason, ...(entry.serverRan ? { serverRan: true } : {}) };
323
337
  // What an alone round left runs alone again, as it was.
324
338
  if (kind === "alone")
325
339
  aloneEach.push({ ...job, reason: entry.reason });
@@ -347,6 +361,17 @@ export default class SupercovPlaywrightStrongReporter {
347
361
  claimedBy.set(taken.id, name.replace(/\.json$/, ""));
348
362
  }
349
363
  const ranInServer = new Set(readLines(`${pass.resultsPath}.everywhere.jsonl`).map((line) => `${line.invocation}\0${line.mutant}`));
364
+ const ranByRequest = ranByRequests(pass);
365
+ // Survivors no attempt ran: they run again alone.
366
+ const notRan = [];
367
+ // The mutants whose passes here do not count: no attempt ran them on
368
+ // their server (those `notRan` names, those whose invocation's server
369
+ // never ran them, and those left unfinished that no attempt has run
370
+ // yet). Their passes are not their progress: a pass that ends before
371
+ // they run again leaves them as open as before, and the next runs
372
+ // every candidate of theirs again, alone where its server does not run
373
+ // them. A survivor is one every candidate let live with it switched on.
374
+ const unproven = new Set();
350
375
  for (const [id, entry] of Object.entries(work.entries)) {
351
376
  if (existsSync(`${pass.shared}/verdicts/${key(id)}`)) {
352
377
  decided += 1;
@@ -398,14 +423,16 @@ export default class SupercovPlaywrightStrongReporter {
398
423
  // app (a server that would not start with it).
399
424
  // (Where one invocation of several failed so, it runs alone with
400
425
  // the whole command started with it, which says whether it was the
401
- // mutant's doing.)
402
- if (kind === "alone" && !work.batch && globalError && !ended.length) {
426
+ // mutant's doing.) An error after the round began to stop is the
427
+ // stop's: its servers went down under it.
428
+ if (kind === "alone" && !work.batch && globalError && globalError.at < stoppedAt && !ended.length) {
403
429
  verdict({ status: "killed", reason: `the command failed with it switched on (${globalError.message})${suffix}` });
404
430
  continue;
405
431
  }
406
432
  // Its invocation's server never ran it: alone, the whole command
407
433
  // started with it.
408
434
  if (work.batch && !ranInServer.has(`${invocation}\0${entry.mutant}`)) {
435
+ unproven.add(id);
409
436
  aloneEach.push(entry);
410
437
  continue;
411
438
  }
@@ -416,8 +443,19 @@ export default class SupercovPlaywrightStrongReporter {
416
443
  verdict({ status: "error", reason: "its candidate tests fail without any mutant" });
417
444
  continue;
418
445
  }
446
+ // What passed of a mutant no attempt has run yet passed without
447
+ // it: its next round runs every candidate again, so that what it
448
+ // sends alone, if no attempt runs it there either, is all of them.
449
+ const notYetRan = unreached(kind, entry, ranByRequest);
450
+ if (notYetRan)
451
+ unproven.add(id);
419
452
  if (left.length) {
420
- next(entry, "unfinished", left);
453
+ next(entry, "unfinished", notYetRan ? runnable : left);
454
+ continue;
455
+ }
456
+ if (notYetRan) {
457
+ notRan.push(id);
458
+ next(entry, "unreached", runnable);
421
459
  continue;
422
460
  }
423
461
  verdict(entry.unrun
@@ -426,13 +464,27 @@ export default class SupercovPlaywrightStrongReporter {
426
464
  }
427
465
  for (const job of work.restarts)
428
466
  next(job, job.reason, job.tests);
467
+ // Said where the pass's output is read: a verdict a server's switch
468
+ // missed is a Supercov fault, and other survivors may share it.
469
+ if (notRan.length)
470
+ console.error(`[supercov] warning: ${notRan.length} mutant(s) lived through every candidate test on the shared server, though no attempt ran them there: the requests that reached their code did not carry their test's mutant. Each runs again alone, with the server started with it switched on: ${listed(notRan)}`);
471
+ if (kind === "alone") {
472
+ const killedAlone = readLines(pass.resultsPath)
473
+ .filter((record) => work.entries[record.id]?.reason === "unreached" && (record.status === "killed" || record.status === "timeout"))
474
+ .map((record) => record.id);
475
+ if (killedAlone.length)
476
+ console.error(`[supercov] warning: ${killedAlone.length} mutant(s) the shared server let live were killed alone, with the server started with them switched on; their verdicts are the kills: ${listed(killedAlone)}`);
477
+ }
429
478
  // What each mutant left open passed: its candidates that ran with it
430
479
  // and passed (before any error outside a test), by the plan's ids. A
431
480
  // later pass, or a later round, resumes there. A round of mutants a
432
- // server ran from its start lends nothing to a request's own switch.
481
+ // server ran from its start lends nothing to a request's own switch,
482
+ // and a mutant no attempt ran here (`unproven`) passed nothing with
483
+ // it: a later pass that took its candidates' passes as its progress
484
+ // would call it `survived` without running it once.
433
485
  if (kind !== "alone") {
434
486
  for (const id of Object.keys(work.entries)) {
435
- if (existsSync(`${pass.shared}/verdicts/${key(id)}`))
487
+ if (unproven.has(id) || existsSync(`${pass.shared}/verdicts/${key(id)}`))
436
488
  continue;
437
489
  const passed = (byMutant.get(id) ?? [])
438
490
  .filter((attempt) => attempt.outcome === "passed" && attempt.endedAt < trustedUntil)
@@ -492,6 +544,14 @@ export default class SupercovPlaywrightStrongReporter {
492
544
  durationMs: Date.now() - started,
493
545
  attempts: mutated.length,
494
546
  timedOut: mutated.filter((attempt) => attempt.outcome === "timed-out").length,
547
+ // Attempts ended where they stalled, and those that stalled where
548
+ // their pages could still end the wait, ran on, and timed out
549
+ // all the same.
550
+ stalls: {
551
+ stopped: mutated.filter((attempt) => attempt.stalledAtMs !== undefined).length,
552
+ ranOn: mutated.filter((attempt) => attempt.doubtedAtMs !== undefined).length,
553
+ ranOnTimedOut: mutated.filter((attempt) => attempt.doubtedAtMs !== undefined && attempt.outcome === "timed-out").length,
554
+ },
495
555
  timeoutFactor: work.timeoutFactor,
496
556
  baselines: attempts.filter((attempt) => attempt.kind === "baseline").length,
497
557
  decided,