supercov 4.29.15 → 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.
package/docs/cli.md CHANGED
@@ -585,11 +585,15 @@ phpunit`). See `docs/design/strong-mutation.md`,
585
585
  mutant is a `timeout`. `SUPERCOV_STRONG_TIMEOUT_FACTOR` sets it where the
586
586
  option is not given.
587
587
  - After an edit, `supercov mutants` measures the checkout again and keeps an
588
- earlier run's verdict for each mutant whose file is as it was and whose
589
- candidate tests, and their test files, nothing changed could reach (as
590
- `tests affected` reads a change: a test file's edit reaches its tests, a
591
- source's edit the tests that ran the changed code). The rest run; the
592
- summary says how many verdicts were kept, and from which run.
588
+ earlier run's verdict for each mutant nothing changed could move: found by
589
+ its code, not its line; a kill where the test that killed it still reaches
590
+ it and runs as it did, a survival where every candidate now ran with it
591
+ then and runs as it did, a test running as it did where nothing it could
592
+ run with the mutant switched on changed (`docs/design/strong-mutation.md`,
593
+ "After an edit"). Timeouts and errors run again. The rest run; the summary
594
+ says how many verdicts were kept, from which runs and commits, and why the
595
+ others run, and `runs <id> mutants` says where each kept verdict was
596
+ reached (`carried from run r5 (commit 1a2b3c4)`).
593
597
  - `--diff` and `--file` answer about the mutants they ask for: the summary's
594
598
  counts and score are theirs, and its first line says how many of the run's
595
599
  mutants that is. `--format markdown` (with `--output <file>`) writes the
package/docs/mutation.md CHANGED
@@ -194,20 +194,36 @@ mutants the tests let survive.
194
194
  code, which those are. A test that failed in the baseline is no candidate.
195
195
  It needs a merged run made by this release, which keeps what its runs
196
196
  answer with.
197
- - **After an edit.** It measures the checkout again and keeps an earlier
198
- verdict for each mutant whose file is as it was and whose candidate tests,
199
- and their test files, nothing changed could reach, as `runs latest tests
200
- affected` reads a change: a test file's edit reaches its tests, a source's
201
- edit the tests that ran the changed code. Each mutant's verdict comes from
202
- the newest earlier run of the same command, dependencies and configuration
203
- that holds one it can keep, so a pass split across jobs, each holding part
204
- of the verdicts in its own run, is kept whole. A test that failed in the
205
- earlier run counts as reached only where the change reaches code that run
206
- covered. The rest run, and the summary says how many verdicts were kept and
207
- from which runs (`193 verdict(s) kept from runs r2, r1: nothing they depend
208
- on changed`), and how many were not, by why (`6 earlier verdict(s) not kept,
209
- so run again: 4 their file changed, 2 a test that could kill them could
210
- reach a change`). An error is never kept: it runs again.
197
+ - **After an edit.** A new commit runs only the mutants whose verdict could
198
+ have changed. `supercov mutants` measures the checkout again and keeps an
199
+ earlier run's verdict for each mutant where nothing it depends on changed;
200
+ the earlier runs are those of the same command, dependencies and
201
+ configuration in `.supercov/runs` (a baseline restored there among them),
202
+ newest first, so a pass split across jobs, each holding part of the
203
+ verdicts in its own run, is kept whole. A verdict is found by its mutant's
204
+ code, not its line: a line added above a function keeps its mutants'
205
+ verdicts. A kill is kept where the test that killed it still reaches the
206
+ mutated code and runs as it did; a survival where every candidate test it
207
+ has now ran with it then and runs as it did; a timeout, an error, a kill
208
+ no record names a test for, and a mutant whose own declaration changed run
209
+ again. A test runs as it did where nothing changed that it could run with
210
+ the mutant switched on, which may be code it never ran without (a function
211
+ no test calls that a mutant sends a test into counts): for a JavaScript or
212
+ TypeScript test run in its runner's process (Jest, Vitest, Mocha, ...),
213
+ nothing its imports load and its code can name; for a Python or Ruby test,
214
+ no code its imports load; for any other (a Playwright test, a mutant a
215
+ server starts with), `runs latest tests affected` finds it unaffected and
216
+ no code but tests' changed. The summary says how many verdicts were kept,
217
+ from which runs and commits (`26 verdict(s) kept from run r5 (commit
218
+ 1a2b3c4), which took 25 test run(s) to reach: nothing they depend on
219
+ changed`), and
220
+ how many were not, by why (`13 earlier verdict(s) not kept, so run again:
221
+ 13 a test that could kill them loads code that changed, which they could
222
+ lead it into`); `runs <id> mutants` says where each kept verdict was
223
+ reached (`carried from run r5 (commit 1a2b3c4)`). On a fixture's eight
224
+ commits it ran 72 mutants where passes from nothing ran 201, every verdict
225
+ the same; `docs/design/strong-mutation.md` ("After an edit") has the rules
226
+ and why they hold.
211
227
  - **Interrupted.** Each verdict is saved as it is made. A pass stopped by
212
228
  Ctrl-C, a killed job or a test worker that never ended keeps what it
213
229
  decided, and the next pass runs only the rest. Sent SIGINT or SIGTERM, the
@@ -560,9 +576,14 @@ no mutants shows none of this.
560
576
  ends sooner, a `timeout` too, once it has stalled: its test's own code has
561
577
  run for longer than any run of the test that passed (baseline × 1.5 + 1 s)
562
578
  and waits on a Playwright call that cannot end by its own timeout before the
563
- limit, its pages quiet for a second. An `expect` that gives up before the
564
- limit still fails the test, a kill, and a page still sending requests runs
565
- on. Nothing needs setting. Each timeout's verdict says what it waited on and
579
+ limit, its pages quiet for a second with nothing left in them that could
580
+ end the wait before the limit: no timer, animation frame or ending
581
+ animation due before it, no request unanswered, no WebSocket open, no
582
+ worker. An `expect` that gives up before the limit still fails the test, a
583
+ kill; a page still sending requests runs on; and so does one that would
584
+ poll again on a timer before the limit, to its limit, where a later poll
585
+ may answer the wait (a timeout there says it `ran to its limit to
586
+ confirm`, and the summary counts those). Nothing needs setting. Each timeout's verdict says what it waited on and
566
587
  where, for example `stopped at 2.5 s of its 6.5 s time limit, ..., waiting
567
588
  on Locator.click (#save) at tests/save.spec.ts:12:20`, and the summary says
568
589
  how much time ending them early saved. A worker is kept after a mutant
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supercov",
3
- "version": "4.29.15",
3
+ "version": "4.29.16",
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.15",
129
- "@supercov/cli-darwin-x64": "4.29.15",
130
- "@supercov/cli-linux-arm64-gnu": "4.29.15",
131
- "@supercov/cli-linux-arm64-musl": "4.29.15",
132
- "@supercov/cli-linux-x64-gnu": "4.29.15",
133
- "@supercov/cli-linux-x64-musl": "4.29.15",
134
- "@supercov/cli-win32-arm64": "4.29.15",
135
- "@supercov/cli-win32-x64": "4.29.15"
128
+ "@supercov/cli-darwin-arm64": "4.29.16",
129
+ "@supercov/cli-darwin-x64": "4.29.16",
130
+ "@supercov/cli-linux-arm64-gnu": "4.29.16",
131
+ "@supercov/cli-linux-arm64-musl": "4.29.16",
132
+ "@supercov/cli-linux-x64-gnu": "4.29.16",
133
+ "@supercov/cli-linux-x64-musl": "4.29.16",
134
+ "@supercov/cli-win32-arm64": "4.29.16",
135
+ "@supercov/cli-win32-x64": "4.29.16"
136
136
  },
137
137
  "peerDependencies": {
138
138
  "@playwright/test": ">=1.55.0",
@@ -20,7 +20,7 @@ import { inferTestProvenance, testTags } from "./provenance.mjs";
20
20
  import { appendJsonLineDurableSync, appendJsonLineSync } from "./atomic.mjs";
21
21
  import { expandSnapshot, mergeSnapshots, columnarEvents } from "./snapshots.mjs";
22
22
  import { COVERAGE_DOCUMENT_PHASE_COOKIE, COVERAGE_DOCUMENT_PHASE_SITE_COOKIE, COVERAGE_PHASE_HEADER, COVERAGE_PHASE_COOKIE, COVERAGE_PHASE_SITE_COOKIE, COVERAGE_SCOPE_COOKIE, COVERAGE_SCOPE_HEADER, COVERAGE_SCOPE_SITE_COOKIE, COVERAGE_CARRIER_ENV, encodeCoverageCarrier, encodeCoverageScope, serverEvidenceDirectory, serverEvidencePath, startDocumentInPhase, } from "./transport.mjs";
23
- import { PAGE_TIMEOUT_MARKER, activatePageMutant, describeCall, installCopies, keepsWorker, ownDeadline, ranInWorker, stallDetails, stalledOn, strongClaim, strongFinish, watchStall } from "./playwrightStrong.mjs";
23
+ import { PAGE_ANSWER_MS, PAGE_BUSY, PAGE_GONE, PAGE_TIMEOUT_MARKER, activatePageMutant, describeCall, installCopies, keepsWorker, ownDeadline, pendingBefore, ranInWorker, stallDetails, stalledOn, strongClaim, strongFinish, watchPageWork, watchStall } from "./playwrightStrong.mjs";
24
24
  export * from "@playwright/test";
25
25
  const generatedTargetModule = "__SUPERCOV_PLAYWRIGHT_MODULE__";
26
26
  const targetModule = process.env["SUPERCOV_PLAYWRIGHT_MODULE"] ??
@@ -265,6 +265,8 @@ class CoveragePhaseController {
265
265
  pageRegistrations = new WeakMap();
266
266
  scriptUpdate = Promise.resolve();
267
267
  proxyCache = new WeakMap();
268
+ // Each proxy's Playwright object: calls made on it are not the test's.
269
+ proxyTargets = new WeakMap();
268
270
  runtimeSnapshots;
269
271
  // Contexts whose creation the collector did not observe: it does not know
270
272
  // what `extraHTTPHeaders` their owner configured, so it must not rewrite
@@ -304,14 +306,16 @@ class CoveragePhaseController {
304
306
  workerEvidenceMissing = false;
305
307
  // A strong attempt's: the test's default timeouts (`watchWaits`), the
306
308
  // calls it made on Playwright's objects that have not settled, each with
307
- // when its own timeout ends it, the newest of them, and since when its
308
- // pages have sent and answered no request (`stall`).
309
+ // when its own timeout ends it, the newest of them, since when its pages
310
+ // have sent and answered no request (`stall`), and the requests they sent
311
+ // that are not answered yet (`pageWork`).
309
312
  waitTimeouts;
310
313
  waits = new Set();
311
314
  newestWait;
312
315
  testCalledAt;
313
316
  matcherSite;
314
317
  quietSince = Date.now();
318
+ unanswered = new Set();
315
319
  disposed = false;
316
320
  // Parameter properties are stateful despite the base ESLint rule treating
317
321
  // this as an empty constructor.
@@ -643,6 +647,9 @@ class CoveragePhaseController {
643
647
  parts.push(`(${activatePageMutant})(${JSON.stringify(mutant === "-"
644
648
  ? { file: null, index: -1, marker: PAGE_TIMEOUT_MARKER }
645
649
  : { file: mutant.slice(0, at), index: Number(mutant.slice(at + 1)), marker: PAGE_TIMEOUT_MARKER })});`);
650
+ // What the document has yet to do, for a stalled attempt's
651
+ // watch: before the page's own scripts set a timer.
652
+ parts.push(`(${watchPageWork})();`);
646
653
  }
647
654
  parts.push(`(${announceAttempt})(${JSON.stringify({
648
655
  attemptId: this.scope.attemptId,
@@ -685,10 +692,15 @@ class CoveragePhaseController {
685
692
  // A strong attempt's pages are busy while they send or have
686
693
  // answered a request: not stalled.
687
694
  if (this.waitTimeouts) {
688
- const busy = () => {
695
+ const sent = (request) => {
689
696
  this.quietSince = Date.now();
697
+ this.unanswered.add(request);
690
698
  };
691
- listeners.push(["request", busy], ["requestfinished", busy], ["requestfailed", busy]);
699
+ const answered = (request) => {
700
+ this.quietSince = Date.now();
701
+ this.unanswered.delete(request);
702
+ };
703
+ listeners.push(["request", sent], ["requestfinished", answered], ["requestfailed", answered]);
692
704
  }
693
705
  for (const [event, listener] of listeners)
694
706
  context.on(event, listener);
@@ -847,6 +859,23 @@ class CoveragePhaseController {
847
859
  const now = this.waitTimeouts[kind];
848
860
  this.waitTimeouts[kind] = now > 0 ? Math.min(now, ms) : ms;
849
861
  }
862
+ /**
863
+ * What the test's pages could still do that may end a stalled wait
864
+ * before `limitAt` (`pendingBefore`), asked of every frame of every page
865
+ * at once.
866
+ */
867
+ async pageWork(limitAt) {
868
+ // The pages themselves, not the test's view of them: a question
869
+ // asked through that would be a call of the test's, its newest.
870
+ const pages = this.allPages().map((page) => this.proxyTargets.get(page) ?? page).filter((page) => !page.isClosed());
871
+ const asked = pages.flatMap((page) => page.frames().map(async (frame) => {
872
+ const answer = await bounded(internally(page, () => frame.evaluate(() => globalThis[Symbol.for("supercov.pageWork")]?.() ?? null)).catch(() => PAGE_GONE), PAGE_ANSWER_MS);
873
+ return { url: frame.url(), answer: answer === WORKER_TIMED_OUT ? PAGE_BUSY : answer };
874
+ }));
875
+ const frames = await Promise.all(asked);
876
+ const workers = pages.reduce((sum, page) => sum + page.workers().length, 0);
877
+ return pendingBefore({ frames, requests: this.unanswered.size, workers, limitAt, now: Date.now() });
878
+ }
850
879
  /** What a strong attempt is stalled on before `limitAt`, if it is, and what it waits on now. */
851
880
  stall(limitAt) {
852
881
  const newest = this.newestWait;
@@ -941,6 +970,7 @@ class CoveragePhaseController {
941
970
  },
942
971
  });
943
972
  this.proxyCache.set(target, proxy);
973
+ this.proxyTargets.set(proxy, target);
944
974
  // Playwright's built-in `page` fixture is created through the wrapped
945
975
  // worker-scoped browser. The test-scoped fixture sees that proxy again;
946
976
  // treating our own proxy as a fresh target would nest wrappers, emit two
@@ -2030,7 +2060,7 @@ const instrumentedFixtures = {
2030
2060
  // state in it: the next test gets a new worker.
2031
2061
  let restartWorker = false;
2032
2062
  // A mutant attempt that stalls ends there, a timeout.
2033
- const stall = watchStall(testInfo, strong, (limitAt) => controller.stall(limitAt));
2063
+ const stall = watchStall(testInfo, strong, (limitAt) => controller.stall(limitAt), (limitAt) => controller.pageWork(limitAt));
2034
2064
  try {
2035
2065
  await use();
2036
2066
  }
@@ -51,9 +51,14 @@
51
51
  // time a run of its test that passed took (its baseline × the factor + 1 s),
52
52
  // waiting on a Playwright call that cannot end by its own timeout before the
53
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). Nothing it waits on can
55
- // make it fail before the limit, and no passing run took that long: the limit
56
- // would end it as a `timeout` all the same, later.
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.
57
62
  //
58
63
  // This module holds what the config, the fixture (playwright.mjs) and the
59
64
  // reporter (playwrightStrongReporter.mjs) share.
@@ -71,6 +76,12 @@ const STALL_CONSTANT_MS = 1_000;
71
76
  const QUIET_MS = 1_000;
72
77
  // How often a stalled attempt is looked for.
73
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;
74
85
  // Playwright's calls that wait for a navigation, under its navigation timeout.
75
86
  const NAVIGATIONS = new Set(["goto", "reload", "goBack", "goForward", "waitForURL", "waitForNavigation", "waitForLoadState"]);
76
87
  // An API request's own timeout where nothing sets one (Playwright's default).
@@ -208,16 +219,24 @@ export function limitOf(baselineMs, factor) {
208
219
  return Math.ceil(baselineMs * factor + TIMEOUT_CONSTANT_MS);
209
220
  }
210
221
 
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
+
211
225
  /** What a verdict says of an attempt that ran out of its time limit, or stalled before it. */
212
226
  function limitReason(attempt) {
213
227
  const seconds = (ms) => `${(ms / 1000).toFixed(1)} s`;
214
228
  const waiting = attempt.waitingOn ? `, waiting on ${attempt.waitingOn}` : "";
215
229
  if (attempt.stalledAtMs !== undefined)
216
- 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${waiting}, which cannot end before the limit`;
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`;
217
231
  const why = attempt.limitMs < limitOf(attempt.baselineMs, attempt.timeoutFactor)
218
232
  ? "the test's own timeout"
219
233
  : `${attempt.timeoutFactor} × its ${seconds(attempt.baselineMs)} baseline + ${TIMEOUT_CONSTANT_MS / 1000} s`;
220
- return `ran past its time limit of ${seconds(attempt.limitMs)} (${why})${waiting}`;
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}`;
221
240
  }
222
241
 
223
242
  /**
@@ -274,6 +293,160 @@ export function stalledOn({ waits, newest, limitAt, quietSince, now }) {
274
293
  return newest;
275
294
  }
276
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
+
277
450
  /** When, from its start, a mutant attempt has outlasted every passing run of its test. */
278
451
  export function stallWindowOf(baselineMs, factor) {
279
452
  return Math.ceil(baselineMs * factor + STALL_CONSTANT_MS);
@@ -282,40 +455,67 @@ export function stallWindowOf(baselineMs, factor) {
282
455
  /**
283
456
  * Ends a mutant attempt as a timeout once it has stalled (`stalledOn`, asked
284
457
  * of `look(limitAt)` every tenth of a second from the end of its window, which
285
- * counts from the first call the test's own code made, `since`):
286
- * its test's timeout is set to what it has already run. The watch says when
287
- * it did so and on what (`stalled`), and, where it went on to its limit, what
288
- * it last waited on (`waiting`). `stop()` ends the watch.
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.
289
466
  */
290
- export function watchStall(testInfo, claimed, look) {
467
+ export function watchStall(testInfo, claimed, look, doubt) {
291
468
  if (claimed?.kind !== "mutant")
292
469
  return undefined;
293
470
  const from = claimed.startedAt + stallWindowOf(claimed.baselineMs, claimed.timeoutFactor);
294
471
  if (from >= claimed.limitAt)
295
472
  return undefined;
296
473
  const windowMs = stallWindowOf(claimed.baselineMs, claimed.timeoutFactor);
297
- const watch = { stalled: undefined, waiting: undefined, timer: undefined };
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
+ };
298
483
  const check = () => {
299
- // A test whose body has ended (it failed, ran out of time, or its
300
- // fixtures are being torn down: Playwright sets its duration then)
301
- // waits on nothing of its own: what its teardown closes is not what
302
- // it waited on.
303
- if (testInfo.status !== "passed" || testInfo.duration > 0)
484
+ if (ended())
304
485
  return;
305
486
  const { stalled, waiting, since } = look(claimed.limitAt);
306
487
  watch.waiting = waiting;
307
488
  // The window counts from the test's first call of its own, not from
308
489
  // its claim: setting up its page in a new worker on a loaded machine
309
490
  // took seconds, which no baseline holds.
310
- if (stalled && Date.now() >= since + windowMs) {
311
- watch.stalled = { atMs: Date.now() - claimed.startedAt, waitingOn: stalled };
312
- testInfo.setTimeout(Math.max(1, Date.now() - claimed.claimedAt));
491
+ const pastWindow = Date.now() >= since + windowMs;
492
+ if (!stalled || !pastWindow) {
493
+ later(STALL_POLL_MS);
313
494
  return;
314
495
  }
315
- watch.timer = setTimeout(check, STALL_POLL_MS);
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));
316
513
  };
317
514
  watch.timer = setTimeout(check, Math.max(0, from - Date.now()));
318
- watch.stop = () => clearTimeout(watch.timer);
515
+ watch.stop = () => {
516
+ watch.stopped = true;
517
+ clearTimeout(watch.timer);
518
+ };
319
519
  return watch;
320
520
  }
321
521
 
@@ -323,7 +523,8 @@ export function watchStall(testInfo, claimed, look) {
323
523
  export function stallDetails(watch) {
324
524
  if (watch?.stalled)
325
525
  return { stalledAtMs: watch.stalled.atMs, waitingOn: watch.stalled.waitingOn };
326
- return watch?.waiting ? { waitingOn: watch.waiting } : {};
526
+ const doubted = watch?.doubted ? { doubtedAtMs: watch.doubted.atMs, doubtedBy: watch.doubted.because } : {};
527
+ return { ...(watch?.waiting ? { waitingOn: watch.waiting } : {}), ...doubted };
327
528
  }
328
529
 
329
530
  /**
@@ -184,10 +184,15 @@ export default class SupercovPlaywrightStrongReporter {
184
184
  }[attempt.outcome] ?? attempt.outcome;
185
185
  // What a timeout waited on, where the fixture saw it.
186
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`;
187
192
  // A cold attempt's failure decides nothing: it runs again once a
188
193
  // control has passed on its server.
189
194
  const cold = attempt.cold && (attempt.outcome === "failed" || attempt.outcome === "timed-out") ? ", before any control here: runs again after one" : "";
190
- console.log(`[supercov] ${attempt.id}: ${JSON.stringify(attempt.title)} ${said}${waiting} (${took}${cold})`);
195
+ console.log(`[supercov] ${attempt.id}: ${JSON.stringify(attempt.title)} ${said}${waiting}${doubted} (${took}${cold})`);
191
196
  }
192
197
  /**
193
198
  * What this invocation is doing, for the engine's progress line: the
@@ -359,6 +364,14 @@ export default class SupercovPlaywrightStrongReporter {
359
364
  const ranByRequest = ranByRequests(pass);
360
365
  // Survivors no attempt ran: they run again alone.
361
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();
362
375
  for (const [id, entry] of Object.entries(work.entries)) {
363
376
  if (existsSync(`${pass.shared}/verdicts/${key(id)}`)) {
364
377
  decided += 1;
@@ -410,14 +423,16 @@ export default class SupercovPlaywrightStrongReporter {
410
423
  // app (a server that would not start with it).
411
424
  // (Where one invocation of several failed so, it runs alone with
412
425
  // the whole command started with it, which says whether it was the
413
- // mutant's doing.)
414
- 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) {
415
429
  verdict({ status: "killed", reason: `the command failed with it switched on (${globalError.message})${suffix}` });
416
430
  continue;
417
431
  }
418
432
  // Its invocation's server never ran it: alone, the whole command
419
433
  // started with it.
420
434
  if (work.batch && !ranInServer.has(`${invocation}\0${entry.mutant}`)) {
435
+ unproven.add(id);
421
436
  aloneEach.push(entry);
422
437
  continue;
423
438
  }
@@ -428,11 +443,17 @@ export default class SupercovPlaywrightStrongReporter {
428
443
  verdict({ status: "error", reason: "its candidate tests fail without any mutant" });
429
444
  continue;
430
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);
431
452
  if (left.length) {
432
- next(entry, "unfinished", left);
453
+ next(entry, "unfinished", notYetRan ? runnable : left);
433
454
  continue;
434
455
  }
435
- if (unreached(kind, entry, ranByRequest)) {
456
+ if (notYetRan) {
436
457
  notRan.push(id);
437
458
  next(entry, "unreached", runnable);
438
459
  continue;
@@ -457,10 +478,13 @@ export default class SupercovPlaywrightStrongReporter {
457
478
  // What each mutant left open passed: its candidates that ran with it
458
479
  // and passed (before any error outside a test), by the plan's ids. A
459
480
  // later pass, or a later round, resumes there. A round of mutants a
460
- // 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.
461
485
  if (kind !== "alone") {
462
486
  for (const id of Object.keys(work.entries)) {
463
- if (existsSync(`${pass.shared}/verdicts/${key(id)}`))
487
+ if (unproven.has(id) || existsSync(`${pass.shared}/verdicts/${key(id)}`))
464
488
  continue;
465
489
  const passed = (byMutant.get(id) ?? [])
466
490
  .filter((attempt) => attempt.outcome === "passed" && attempt.endedAt < trustedUntil)
@@ -520,6 +544,14 @@ export default class SupercovPlaywrightStrongReporter {
520
544
  durationMs: Date.now() - started,
521
545
  attempts: mutated.length,
522
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
+ },
523
555
  timeoutFactor: work.timeoutFactor,
524
556
  baselines: attempts.filter((attempt) => attempt.kind === "baseline").length,
525
557
  decided,