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.
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
@@ -1178,6 +1182,19 @@ timestamp, a path the test took, an outcome, is kept beside the others, so
1178
1182
  nothing any run recorded is lost. Jobs that each measured the whole suite
1179
1183
  record each test with times of their own, and keep a copy each.
1180
1184
 
1185
+ Runs made from one run without measuring whose archives are alike byte for
1186
+ byte (the jobs of a continuation round, each made from the same baseline)
1187
+ are read, merged and kept once, from the first of them: the merged run lists
1188
+ that one among its runs, keeps it alone under `parts/`, and says which runs
1189
+ were its copies (`7 run(s) hold run r1's evidence byte for byte, made from one
1190
+ run without measuring (r2; r3; r4; and 4 more): their evidence is kept once,
1191
+ from it, and their strong verdicts each`). Each copy's strong verdicts are
1192
+ kept as any run's. Eight such runs of a large e2e suite, each 232 MB with its
1193
+ baseline's archive and parts, merged in 12 s instead of 100 s and half the
1194
+ memory (a peak footprint of 12.5 GB, from 24.7 GB), into a run of 244 MB
1195
+ instead of 1 GB, which the next round's jobs each carry; its coverage and
1196
+ strong verdicts are the same.
1197
+
1181
1198
  The runs may differ in their tests, the helpers beside them, and the test
1182
1199
  runners' settings, as long as nothing that changed reaches what an earlier
1183
1200
  run's tests did. Measuring a new test alone and adding it to the runs before it
package/docs/mutation.md CHANGED
@@ -60,6 +60,7 @@ switched on and records what the established tools record:
60
60
  | `survived` | Every test that could kill it passed |
61
61
  | `timeout` | A test ran past its time limit with the mutant in place |
62
62
  | `no-coverage` | No test ran the mutated code |
63
+ | `equivalent` | No test can tell it from the original, proven before running it; left out of the score |
63
64
  | `unviable` | The mutant does not compile (Rust and Go); counted apart and left out of the score |
64
65
  | `error` | The pass could not give it a verdict, with the reason; left out of the score |
65
66
 
@@ -78,9 +79,64 @@ first pass of their own:
78
79
  reached or infected it, the likeliest killer first, and stops at the first
79
80
  failure.
80
81
 
82
+ - a JavaScript or TypeScript mutant whose file compiles to the same code as
83
+ the original is `equivalent`, and is not run; mutants whose files compile
84
+ to the same code as each other run once, and each takes that run's verdict
85
+ (see Equivalent mutants, below).
86
+
81
87
  Each of these shortcuts is exact. Where the run cannot prove a test is
82
88
  irrelevant, the test runs.
83
89
 
90
+ ### Equivalent mutants
91
+
92
+ Some mutants change the source without changing the program: a branch that
93
+ can never run emptied, `if (false)` made `if (false)` again, `"a".trim()`
94
+ made `"a"`. No test can kill them, yet each one used to run every test
95
+ that reached it and then waited in the survivors for someone to dismiss it.
96
+
97
+ Before a strong pass runs a JavaScript or TypeScript mutant, Supercov
98
+ compiles its file twice -- once as written, once with the mutant -- with the
99
+ same optimising compiler and the same options (oxc's minifier, built into
100
+ Supercov, with every assumption that could change behaviour turned off),
101
+ and compares the two outputs. Where they are identical the mutant is the
102
+ original program, so it is `equivalent`: not run, not a survivor, and out of
103
+ the score. This is Trivial Compiler Equivalence (Papadakis et al., ICSE
104
+ 2015). It only ever says `equivalent` on an exact match; anything else, a
105
+ file it cannot compile included, runs as before. Two mutants of one file
106
+ that compile to the same code are one program: the pass runs one of them and
107
+ gives the other the same verdict.
108
+
109
+ There is nothing to set up or turn on. The pass says what it spared:
110
+
111
+ ```text
112
+ [supercov] 10 mutant(s) proven equivalent: each compiles to the same code as the original, so no test can tell it apart; 10 of them would have run and did not
113
+ [supercov] 6 mutant(s) compile to the same code as another mutant, which runs once and gives them its verdict
114
+ [supercov] about 1 s of test time saved by not running them
115
+ ```
116
+
117
+ Its summary says the same, and each one says why where it is listed:
118
+
119
+ ```text
120
+ $ supercov runs latest mutants src/shapes.ts:13
121
+ 13:7 ConditionalExpression infected strong: equivalent
122
+ empty → true
123
+ why: `empty` was false at least once (opposite-value)
124
+ strong: equivalent: compiles to the same code as the original: no test can tell it apart, so it was not run
125
+ id: src/shapes.ts:13:7-13:12:ConditionalExpression:true
126
+ ```
127
+
128
+ Here `if (empty) { return "none"; } return "none";` returns `"none"` whichever
129
+ way the test goes, so making it `true` changes nothing. A mutant that takes
130
+ another's verdict says whose: `compiles to the same code as <id>, which ran
131
+ for both`.
132
+
133
+ The markdown and HTML reports fold them into a section of their own, apart
134
+ from the survivors. A file that does not compile (a syntax Supercov's parser
135
+ does not take) is named, and its mutants run as before:
136
+ `could not compile 1 file(s) to compare their mutants' code, so their mutants run as before: src/legacy.js`. So is a file
137
+ whose mutants would take longer to compile than to run, such as a
138
+ generated file with thousands of mutants.
139
+
84
140
  ### How this differs from coverage
85
141
 
86
142
  A line can be covered, its branch taken both ways, and still have no test that
@@ -138,20 +194,36 @@ mutants the tests let survive.
138
194
  code, which those are. A test that failed in the baseline is no candidate.
139
195
  It needs a merged run made by this release, which keeps what its runs
140
196
  answer with.
141
- - **After an edit.** It measures the checkout again and keeps an earlier
142
- verdict for each mutant whose file is as it was and whose candidate tests,
143
- and their test files, nothing changed could reach, as `runs latest tests
144
- affected` reads a change: a test file's edit reaches its tests, a source's
145
- edit the tests that ran the changed code. Each mutant's verdict comes from
146
- the newest earlier run of the same command, dependencies and configuration
147
- that holds one it can keep, so a pass split across jobs, each holding part
148
- of the verdicts in its own run, is kept whole. A test that failed in the
149
- earlier run counts as reached only where the change reaches code that run
150
- covered. The rest run, and the summary says how many verdicts were kept and
151
- from which runs (`193 verdict(s) kept from runs r2, r1: nothing they depend
152
- on changed`), and how many were not, by why (`6 earlier verdict(s) not kept,
153
- so run again: 4 their file changed, 2 a test that could kill them could
154
- 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.
155
227
  - **Interrupted.** Each verdict is saved as it is made. A pass stopped by
156
228
  Ctrl-C, a killed job or a test worker that never ended keeps what it
157
229
  decided, and the next pass runs only the rest. Sent SIGINT or SIGTERM, the
@@ -485,7 +557,11 @@ no mutants shows none of this.
485
557
  (`docs/design/strong-mutation.md`, Module-level values). A mutant whose
486
558
  code ran only for requests that named no test (a webhook a mock server
487
559
  sends while tests run) runs against the tests that were running then, not
488
- every test. A test runs without a mutant only after a failure, to confirm
560
+ every test. A survivor whose code its candidates' servers ran, but which no
561
+ test's request ran with its mutant in the pass (work in a route's
562
+ `after()`, a worker process the first request started), is not trusted: it
563
+ runs again alone, with the server started with it switched on, and the pass
564
+ warns about it. A test runs without a mutant only after a failure, to confirm
489
565
  it; a failure before any such run passed on its server (a cold server)
490
566
  runs the mutant again once one has. StrykerJS has no
491
567
  Playwright runner, so Playwright's verdicts are checked by hand (see below).
@@ -496,7 +572,23 @@ no mutants shows none of this.
496
572
  test may shorten it but not lengthen it, so a click or an `expect` that
497
573
  waits for an element the mutant broke ends there, not at its own 30 s. A
498
574
  test that runs out of its limit makes its mutant a `timeout`, which counts
499
- as detected; the summary says how many, and against what limit.
575
+ as detected; the summary says how many, and against what limit. An attempt
576
+ ends sooner, a `timeout` too, once it has stalled: its test's own code has
577
+ run for longer than any run of the test that passed (baseline × 1.5 + 1 s)
578
+ and waits on a Playwright call that cannot end by its own timeout before the
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
587
+ where, for example `stopped at 2.5 s of its 6.5 s time limit, ..., waiting
588
+ on Locator.click (#save) at tests/save.spec.ts:12:20`, and the summary says
589
+ how much time ending them early saved. A worker is kept after a mutant
590
+ fails its test, so the next test does not wait for a new worker and
591
+ browser; a test that fails without any mutant still gets a new one.
500
592
  `--timeout-factor <x>` (or `SUPERCOV_STRONG_TIMEOUT_FACTOR`) changes the
501
593
  1.5: a suite whose tests' times vary widely between runs may want 2 or 3.
502
594
  A mutant tries its candidates cheapest to a kill first (a test's time over
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supercov",
3
- "version": "4.29.14",
3
+ "version": "4.29.16",
4
4
  "description": "Coverage, security and code quality for coding agents",
5
5
  "keywords": [
6
6
  "coverage",
@@ -83,7 +83,7 @@
83
83
  "eval:skill": "claude plugin eval plugins/supercov --scaffold --trust-plugin --no-publish --model claude-sonnet-5 --judge-model claude-haiku-4-5 --threshold 0.66 --tag behavior trigger --allow-tools Bash Edit Write --max-cost-usd 15",
84
84
  "eval:skill-triggers": "claude plugin eval plugins/supercov --scaffold --trust-plugin --no-publish --model claude-sonnet-5 --judge-model claude-haiku-4-5 --threshold 0.66 --tag trigger --ablation none --max-cost-usd 5",
85
85
  "test:engine": "cargo fmt --all -- --check && cargo clippy --workspace --all-targets -- -D warnings && cargo test --workspace && npm run test:runtime && npm run test:rust-assets && npm run test:engine-integrations",
86
- "test:engine-integrations": "cargo build -p supercov && node scripts/html-report-integration.mjs && node scripts/mutation-report-formats.mjs && node scripts/rust-process-supervision.mjs && node scripts/rust-direct-node-integration.mjs && node scripts/rust-public-run-integration.mjs && node scripts/rust-embedded-runtime-integration.mjs && node scripts/rust-direct-vitest-integration.mjs && node scripts/rust-nested-vitest-integration.mjs && node scripts/rust-direct-jest-integration.mjs && node scripts/mocha-failure-output.mjs && node scripts/failure-output.mjs node ava tap && node scripts/side-by-side.mjs node && node scripts/merge-across.mjs && node scripts/import-line-evidence.mjs && node scripts/mock-reach.mjs && node scripts/generated-inputs.mjs && node scripts/baseline-continuation.mjs && node scripts/rust-direct-playwright-integration.mjs && node scripts/rust-custom-browser-playwright-integration.mjs && node scripts/cross-origin-requests.mjs && node scripts/leaving-page.mjs && node scripts/shared-page.mjs && node scripts/context-script-copies.mjs && node scripts/context-headers.mjs && node scripts/context-cookies.mjs && node scripts/hidden-request-emit.mjs && node scripts/js-syntax-zoo.mjs && node scripts/ruby-syntax-zoo.mjs && node scripts/rust-syntax-zoo.mjs && node scripts/python-syntax-zoo.mjs && node scripts/go-syntax-zoo.mjs && node scripts/java-syntax-zoo.mjs && node scripts/background-by-time.mjs && node scripts/python-server-playwright.mjs && node scripts/ruby-server-playwright.mjs && node scripts/go-server-playwright.mjs && node scripts/jvm-server-playwright.mjs && node scripts/docker-server-playwright.mjs && node scripts/docker-clients-playwright.mjs && node scripts/docker-exec-playwright.mjs && node scripts/rust-classic-browser-integration.mjs && node scripts/exec-handover.mjs && node scripts/rust-region-container.mjs && node scripts/rust-top-packages-integration.mjs && node scripts/rust-generic-esbuild-integration.mjs && node scripts/rust-generic-tsc-integration.mjs && node scripts/rust-generic-build-matrix.mjs && node scripts/rust-vite-playwright-integration.mjs && node scripts/workspace-crash-integration.mjs",
86
+ "test:engine-integrations": "cargo build -p supercov && node scripts/html-report-integration.mjs && node scripts/mutation-report-formats.mjs && node scripts/rust-process-supervision.mjs && node scripts/rust-direct-node-integration.mjs && node scripts/rust-public-run-integration.mjs && node scripts/rust-embedded-runtime-integration.mjs && node scripts/rust-direct-vitest-integration.mjs && node scripts/rust-nested-vitest-integration.mjs && node scripts/rust-direct-jest-integration.mjs && node scripts/mocha-failure-output.mjs && node scripts/failure-output.mjs node ava tap && node scripts/side-by-side.mjs node && node scripts/merge-across.mjs && node scripts/import-line-evidence.mjs && node scripts/mock-reach.mjs && node scripts/generated-inputs.mjs && node scripts/baseline-continuation.mjs && node scripts/rust-direct-playwright-integration.mjs && node scripts/rust-custom-browser-playwright-integration.mjs && node scripts/cross-origin-requests.mjs && node scripts/leaving-page.mjs && node scripts/shared-page.mjs && node scripts/context-script-copies.mjs && node scripts/context-headers.mjs && node scripts/context-cookies.mjs && node scripts/hidden-request-emit.mjs && node scripts/js-syntax-zoo.mjs && node scripts/ruby-syntax-zoo.mjs && node scripts/rust-syntax-zoo.mjs && node scripts/python-syntax-zoo.mjs && node scripts/go-syntax-zoo.mjs && node scripts/java-syntax-zoo.mjs && node scripts/background-by-time.mjs && node scripts/next-after-webhook.mjs && node scripts/python-server-playwright.mjs && node scripts/ruby-server-playwright.mjs && node scripts/go-server-playwright.mjs && node scripts/jvm-server-playwright.mjs && node scripts/docker-server-playwright.mjs && node scripts/docker-clients-playwright.mjs && node scripts/docker-exec-playwright.mjs && node scripts/rust-classic-browser-integration.mjs && node scripts/exec-handover.mjs && node scripts/rust-region-container.mjs && node scripts/rust-top-packages-integration.mjs && node scripts/rust-generic-esbuild-integration.mjs && node scripts/rust-generic-tsc-integration.mjs && node scripts/rust-generic-build-matrix.mjs && node scripts/rust-vite-playwright-integration.mjs && node scripts/workspace-crash-integration.mjs",
87
87
  "test:platform": "cargo test --workspace && cargo build -p supercov && node scripts/rust-process-supervision.mjs && node scripts/workspace-crash-integration.mjs",
88
88
  "test:native-package": "cargo build --release -p supercov && node scripts/native-package-integration.mjs && node scripts/native-release-set-integration.mjs",
89
89
  "test:pypi-wheel": "node scripts/pypi-wheel-integration.mjs",
@@ -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.14",
129
- "@supercov/cli-darwin-x64": "4.29.14",
130
- "@supercov/cli-linux-arm64-gnu": "4.29.14",
131
- "@supercov/cli-linux-arm64-musl": "4.29.14",
132
- "@supercov/cli-linux-x64-gnu": "4.29.14",
133
- "@supercov/cli-linux-x64-musl": "4.29.14",
134
- "@supercov/cli-win32-arm64": "4.29.14",
135
- "@supercov/cli-win32-x64": "4.29.14"
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, installCopies, ranInWorker, strongClaim, strongFinish } 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"] ??
@@ -189,6 +189,10 @@ const ACTION_METHODS = new Set([
189
189
  "type",
190
190
  "uncheck",
191
191
  ]);
192
+ // The calls that open and close a test's browser contexts and pages, as
193
+ // Playwright's own fixtures make them while setting a test up and tearing
194
+ // it down: no wait of the test's, and not where its own time starts.
195
+ const LIFECYCLE = new Set(["Browser.newContext", "Browser.newPage", "BrowserContext.newPage", "BrowserContext.close", "Page.close"]);
192
196
  const REQUEST_METHODS = new Set([
193
197
  "delete",
194
198
  "fetch",
@@ -204,6 +208,26 @@ function isApiRequestContext(value) {
204
208
  typeof candidate["get"] === "function" &&
205
209
  typeof candidate["post"] === "function");
206
210
  }
211
+ /**
212
+ * Where in the test's own code a call was made, for a timeout's reason: the
213
+ * stack through these proxies runs past V8's usual ten frames.
214
+ */
215
+ function testSite() {
216
+ const limit = Error.stackTraceLimit;
217
+ Error.stackTraceLimit = 50;
218
+ const stack = new Error().stack?.split("\n").slice(2) ?? [];
219
+ Error.stackTraceLimit = limit;
220
+ // A strong pass runs the suite in its isolated copy of the project, under
221
+ // `.supercov/`: the test's frame is any outside `node_modules`, said
222
+ // relative to where the suite runs.
223
+ const frame = stack.find((line) => /[/\\]tests?[/\\]|\.(spec|test)\.[cm]?[jt]sx?:/.test(line) && !line.includes("node_modules"));
224
+ if (!frame)
225
+ return undefined;
226
+ const root = process.cwd().replaceAll("\\", "/");
227
+ const place = frame.trim().replace(/^at\s+/, "").replaceAll("\\", "/").replace(`${pathToFileURL(root).href}/`, "").replace(`${root}/`, "");
228
+ // `name (file:line:column)`: the place alone.
229
+ return /\(([^()]+)\)$/.exec(place)?.[1] ?? place;
230
+ }
207
231
  function callerSource() {
208
232
  const stack = new Error().stack?.split("\n").slice(2) ?? [];
209
233
  const candidate = stack.find((line) => /[/\\]tests[/\\]/.test(line) &&
@@ -241,6 +265,8 @@ class CoveragePhaseController {
241
265
  pageRegistrations = new WeakMap();
242
266
  scriptUpdate = Promise.resolve();
243
267
  proxyCache = new WeakMap();
268
+ // Each proxy's Playwright object: calls made on it are not the test's.
269
+ proxyTargets = new WeakMap();
244
270
  runtimeSnapshots;
245
271
  // Contexts whose creation the collector did not observe: it does not know
246
272
  // what `extraHTTPHeaders` their owner configured, so it must not rewrite
@@ -278,6 +304,18 @@ class CoveragePhaseController {
278
304
  // Set when a worker's evidence could not be read: the test's coverage is
279
305
  // then a lower bound.
280
306
  workerEvidenceMissing = false;
307
+ // A strong attempt's: the test's default timeouts (`watchWaits`), the
308
+ // calls it made on Playwright's objects that have not settled, each with
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`).
312
+ waitTimeouts;
313
+ waits = new Set();
314
+ newestWait;
315
+ testCalledAt;
316
+ matcherSite;
317
+ quietSince = Date.now();
318
+ unanswered = new Set();
281
319
  disposed = false;
282
320
  // Parameter properties are stateful despite the base ESLint rule treating
283
321
  // this as an empty constructor.
@@ -609,6 +647,9 @@ class CoveragePhaseController {
609
647
  parts.push(`(${activatePageMutant})(${JSON.stringify(mutant === "-"
610
648
  ? { file: null, index: -1, marker: PAGE_TIMEOUT_MARKER }
611
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})();`);
612
653
  }
613
654
  parts.push(`(${announceAttempt})(${JSON.stringify({
614
655
  attemptId: this.scope.attemptId,
@@ -647,10 +688,23 @@ class CoveragePhaseController {
647
688
  void this.registerWorker(worker);
648
689
  };
649
690
  const closed = () => this.closedContexts.add(context);
650
- context.on("page", register);
651
- context.on("serviceworker", registerServiceWorker);
652
- context.on("close", closed);
653
- this.contextListeners.set(context, [["page", register], ["serviceworker", registerServiceWorker], ["close", closed]]);
691
+ const listeners = [["page", register], ["serviceworker", registerServiceWorker], ["close", closed]];
692
+ // A strong attempt's pages are busy while they send or have
693
+ // answered a request: not stalled.
694
+ if (this.waitTimeouts) {
695
+ const sent = (request) => {
696
+ this.quietSince = Date.now();
697
+ this.unanswered.add(request);
698
+ };
699
+ const answered = (request) => {
700
+ this.quietSince = Date.now();
701
+ this.unanswered.delete(request);
702
+ };
703
+ listeners.push(["request", sent], ["requestfinished", answered], ["requestfailed", answered]);
704
+ }
705
+ for (const [event, listener] of listeners)
706
+ context.on(event, listener);
707
+ this.contextListeners.set(context, listeners);
654
708
  for (const worker of context.serviceWorkers())
655
709
  void this.registerWorker(worker);
656
710
  for (const page of context.pages())
@@ -761,6 +815,73 @@ class CoveragePhaseController {
761
815
  requestPhaseId() {
762
816
  return this.activePhaseId;
763
817
  }
818
+ /** Keeps the calls a strong attempt makes, under its test's default timeouts. */
819
+ watchWaits(timeouts) {
820
+ this.waitTimeouts = timeouts;
821
+ }
822
+ /** A call the test made on one of Playwright's objects, until it settles. */
823
+ trackWait(object, method, args, pending, site) {
824
+ if (!this.waitTimeouts || !(pending instanceof Promise))
825
+ return;
826
+ // A locator assertion's `_expect` comes from Playwright's matcher:
827
+ // where the test called the matcher.
828
+ this.keepWait(describeCall(object, method, args), ownDeadline({ method, args, startedAt: Date.now(), request: isApiRequestContext(object), timeouts: this.waitTimeouts }), pending, site ?? this.matcherSite);
829
+ }
830
+ /**
831
+ * An `expect.poll` or a `toPass`, until it settles: it ends by its own
832
+ * timeout, `timeout` where the test gave one, else its config's.
833
+ */
834
+ keepRetries(operation, timeout, polls, pending) {
835
+ if (!this.waitTimeouts || !(pending instanceof Promise))
836
+ return;
837
+ const ms = timeout ?? (polls ? this.waitTimeouts.expect : this.waitTimeouts.toPass);
838
+ this.keepWait(operation, ms > 0 ? Date.now() + ms : Infinity, pending, this.matcherSite);
839
+ }
840
+ keepWait(operation, deadline, pending, at) {
841
+ // Whether it is the test's own (not opening or closing a context or
842
+ // a page, as Playwright's fixtures do); the first such call is where
843
+ // the test's own time starts.
844
+ // Where in the test it was called (`at`), for a timeout's reason.
845
+ const wait = { operation: at ? `${operation} at ${at}` : operation, deadline, fromTest: !LIFECYCLE.has(operation.split(" ")[0]) };
846
+ if (wait.fromTest)
847
+ this.testCalledAt ??= Date.now();
848
+ this.waits.add(wait);
849
+ this.newestWait = wait;
850
+ const settled = () => this.waits.delete(wait);
851
+ pending.then(settled, settled);
852
+ }
853
+ /** A default timeout the test set on a page or a context: the shortest counts. */
854
+ lowerTimeout(method, args) {
855
+ const ms = Number(args[0]);
856
+ if (!this.waitTimeouts || !(ms > 0))
857
+ return;
858
+ const kind = method === "setDefaultTimeout" ? "action" : "navigation";
859
+ const now = this.waitTimeouts[kind];
860
+ this.waitTimeouts[kind] = now > 0 ? Math.min(now, ms) : ms;
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
+ }
879
+ /** What a strong attempt is stalled on before `limitAt`, if it is, and what it waits on now. */
880
+ stall(limitAt) {
881
+ const newest = this.newestWait;
882
+ const stalled = stalledOn({ waits: this.waits, newest, limitAt, quietSince: this.quietSince, now: Date.now() });
883
+ return { stalled: stalled?.operation, waiting: this.waits.has(newest) ? newest.operation : undefined, since: this.testCalledAt };
884
+ }
764
885
  async dispose() {
765
886
  this.disposed = true;
766
887
  await Promise.all([...this.pendingRegistrations]);
@@ -815,6 +936,9 @@ class CoveragePhaseController {
815
936
  const method = String(property);
816
937
  return (...args) => {
817
938
  this.promotePendingAssertion();
939
+ // Where the test made the call, while its frame is
940
+ // still on the stack.
941
+ const site = this.waitTimeouts ? testSite() : undefined;
818
942
  const isRequest = REQUEST_METHODS.has(method) &&
819
943
  isApiRequestContext(object);
820
944
  if (ACTION_METHODS.has(method) || isRequest) {
@@ -822,7 +946,9 @@ class CoveragePhaseController {
822
946
  const operation = `${object.constructor?.name ?? "Playwright"}.${method}`;
823
947
  const phase = await this.beginAction(operation);
824
948
  try {
825
- const result = await Reflect.apply(value, object, isRequest ? this.scopeApiRequest(args) : args);
949
+ const pending = Reflect.apply(value, object, isRequest ? this.scopeApiRequest(args) : args);
950
+ this.trackWait(object, method, args, pending, site);
951
+ const result = await pending;
826
952
  this.finish(phase);
827
953
  return this.prepareResult(result);
828
954
  }
@@ -836,11 +962,15 @@ class CoveragePhaseController {
836
962
  ? this.scopeBrowserContext(args)
837
963
  : args;
838
964
  const result = Reflect.apply(value, object, invokedArgs);
965
+ if (method === "setDefaultTimeout" || method === "setDefaultNavigationTimeout")
966
+ this.lowerTimeout(method, invokedArgs);
967
+ this.trackWait(object, method, invokedArgs, result, site);
839
968
  return this.wrapResult(result, method === "newContext" ? invokedArgs : undefined);
840
969
  };
841
970
  },
842
971
  });
843
972
  this.proxyCache.set(target, proxy);
973
+ this.proxyTargets.set(proxy, target);
844
974
  // Playwright's built-in `page` fixture is created through the wrapped
845
975
  // worker-scoped browser. The test-scoped fixture sees that proxy again;
846
976
  // treating our own proxy as a fresh target would nest wrappers, emit two
@@ -1664,7 +1794,12 @@ function isPlaywrightValue(value) {
1664
1794
  return true;
1665
1795
  }
1666
1796
  }
1667
- function wrapMatchers(matchers, path = "expect", settles = false) {
1797
+ /**
1798
+ * The matchers of an `expect`. `retries` is what an `expect.poll` or a
1799
+ * `toPass` retries under: whether it polls, and the timeout its `expect` was
1800
+ * given (`expect.poll(fn, { timeout })`, `expect.configure({ timeout })`).
1801
+ */
1802
+ function wrapMatchers(matchers, path = "expect", settles = false, retries = { polls: false, timeout: undefined }) {
1668
1803
  return new Proxy(matchers, {
1669
1804
  get(target, property) {
1670
1805
  // Matcher objects and built-ins can expose getters whose internal slots
@@ -1675,11 +1810,15 @@ function wrapMatchers(matchers, path = "expect", settles = false) {
1675
1810
  if (value &&
1676
1811
  typeof value === "object" &&
1677
1812
  (name === "not" || name === "resolves" || name === "rejects"))
1678
- return wrapMatchers(value, `${path}.${name}`, settles && name === "not");
1813
+ return wrapMatchers(value, `${path}.${name}`, settles && name === "not", retries);
1679
1814
  if (typeof value !== "function")
1680
1815
  return value;
1681
1816
  return (...args) => {
1682
1817
  const controller = activeController;
1818
+ // Where the test called the matcher: the calls it makes of
1819
+ // Playwright's objects are named by it.
1820
+ if (controller?.waitTimeouts)
1821
+ controller.matcherSite = testSite();
1683
1822
  const settled = settles && SETTLED_MATCHERS.has(name);
1684
1823
  const phase = bridgedAssertionDepth === 0
1685
1824
  ? controller?.beginAssertion(`${path}.${name}`, undefined, !settled)
@@ -1690,6 +1829,10 @@ function wrapMatchers(matchers, path = "expect", settles = false) {
1690
1829
  controller?.promotePendingAssertion();
1691
1830
  try {
1692
1831
  const result = Reflect.apply(value, target, args);
1832
+ // A poll, or `toPass`, retries until its own timeout,
1833
+ // whatever the calls in it wait on.
1834
+ if (retries.polls || name === "toPass")
1835
+ controller?.keepRetries(`${path}.${name}`, retries.polls ? retries.timeout : args[0]?.timeout ?? retries.timeout, retries.polls, result);
1693
1836
  if (result instanceof Promise) {
1694
1837
  return result.then((resolved) => {
1695
1838
  if (phase && controller)
@@ -1714,21 +1857,22 @@ function wrapMatchers(matchers, path = "expect", settles = false) {
1714
1857
  },
1715
1858
  });
1716
1859
  }
1717
- function wrapExpectCallable(callable, polls = false) {
1860
+ function wrapExpectCallable(callable, polls = false, timeout = undefined) {
1718
1861
  return new Proxy(callable, {
1719
1862
  apply(target, thisArg, argumentsList) {
1720
1863
  const result = Reflect.apply(target, thisArg, argumentsList);
1864
+ // `expect.configure(options)`: an `expect` under its timeout.
1721
1865
  if (typeof result === "function")
1722
- return wrapExpectCallable(result, polls);
1866
+ return wrapExpectCallable(result, polls, argumentsList[0]?.timeout ?? timeout);
1723
1867
  if (result && typeof result === "object")
1724
- return wrapMatchers(result, "expect", !polls && !isPlaywrightValue(argumentsList[0]));
1868
+ return wrapMatchers(result, "expect", !polls && !isPlaywrightValue(argumentsList[0]), { polls, timeout: polls ? argumentsList[1]?.timeout ?? timeout : timeout });
1725
1869
  return result;
1726
1870
  },
1727
1871
  get(target, property, receiver) {
1728
1872
  const value = Reflect.get(target, property, receiver);
1729
1873
  if (typeof value !== "function")
1730
1874
  return value;
1731
- return wrapExpectCallable(value.bind(target), polls || property === "poll");
1875
+ return wrapExpectCallable(value.bind(target), polls || property === "poll", timeout);
1732
1876
  },
1733
1877
  });
1734
1878
  }
@@ -1870,6 +2014,13 @@ const instrumentedFixtures = {
1870
2014
  const configuredHeaders = Object.fromEntries(Object.entries(testInfo.project.use.extraHTTPHeaders ?? {}).map(([name, value]) => [name, String(value)]));
1871
2015
  const setupStarted = performance.now();
1872
2016
  const controller = new CoveragePhaseController(scope, configuredHeaders, testInfo.project.use.baseURL);
2017
+ if (strong?.kind === "mutant")
2018
+ controller.watchWaits({
2019
+ action: testInfo.project.use.actionTimeout ?? 0,
2020
+ navigation: testInfo.project.use.navigationTimeout ?? 0,
2021
+ expect: testInfo.project.expect?.timeout ?? 5_000,
2022
+ toPass: testInfo.project.expect?.toPass?.timeout ?? 0,
2023
+ });
1873
2024
  controllers.set(scope.attemptId, controller);
1874
2025
  activeController = controller;
1875
2026
  directRuntime()?.activateCoverageScope(scope);
@@ -1908,10 +2059,13 @@ const instrumentedFixtures = {
1908
2059
  // A mutant that ran in this worker's own process may have left
1909
2060
  // state in it: the next test gets a new worker.
1910
2061
  let restartWorker = false;
2062
+ // A mutant attempt that stalls ends there, a timeout.
2063
+ const stall = watchStall(testInfo, strong, (limitAt) => controller.stall(limitAt), (limitAt) => controller.pageWork(limitAt));
1911
2064
  try {
1912
2065
  await use();
1913
2066
  }
1914
2067
  finally {
2068
+ stall?.stop();
1915
2069
  const teardownStarted = performance.now();
1916
2070
  const endedAtMs = Date.now();
1917
2071
  try {
@@ -1946,8 +2100,11 @@ const instrumentedFixtures = {
1946
2100
  appendEvidenceLine(`${JSON.stringify(payload)}\n`);
1947
2101
  }
1948
2102
  finally {
1949
- strongFinish(testInfo, strong, { attemptId: scope.attemptId, pageTimeout: controller.mutantRanAway === true });
1950
- restartWorker = ranInWorker(strong, scope.attemptId) && testInfo.status === "passed";
2103
+ strongFinish(testInfo, strong, { attemptId: scope.attemptId, pageTimeout: controller.mutantRanAway === true, ...stallDetails(stall) });
2104
+ const ranHere = ranInWorker(strong, scope.attemptId);
2105
+ restartWorker = ranHere && testInfo.status === "passed";
2106
+ if (keepsWorker(strong, ranHere, testInfo.status))
2107
+ testInfo.expectedStatus = testInfo.status;
1951
2108
  await timed("controller.dispose", () => controller.dispose());
1952
2109
  timingCount("fixture.testTeardown", performance.now() - teardownStarted);
1953
2110
  timingReport(testInfo.title);