supercov 4.29.15 → 4.29.17
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 +9 -5
- package/docs/mutation.md +41 -18
- package/package.json +9 -9
- package/runtime/javascript/playwright.mjs +36 -6
- package/runtime/javascript/playwrightStrong.mjs +224 -22
- package/runtime/javascript/playwrightStrongReporter.mjs +52 -9
- package/runtime/javascript/strongJobs.mjs +26 -11
- package/runtime/javascript/vitestStrongReporter.mjs +13 -2
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
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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.**
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
|
@@ -217,7 +233,9 @@ mutants the tests let survive.
|
|
|
217
233
|
of the tests each runs against, so a pass cut short has decided as many as
|
|
218
234
|
it could. `--budget <seconds>` is the whole command's, measuring and
|
|
219
235
|
planning included: once it is spent the pass stops and ends as a finished
|
|
220
|
-
one, its verdicts saved, so a job ends when its budget says.
|
|
236
|
+
one, its verdicts saved, so a job ends when its budget says. Nothing is
|
|
237
|
+
judged once the pass begins to stop: a test the stop cut short says nothing
|
|
238
|
+
of its mutant, which is left for the next pass. The summary
|
|
221
239
|
says how many mutants it left for the next pass (`budget of 2400 s spent:
|
|
222
240
|
812 mutant(s) left without a verdict, for the next pass`), and, where
|
|
223
241
|
measuring took half the budget or more, what it took (`measuring took 310 s
|
|
@@ -560,9 +578,14 @@ no mutants shows none of this.
|
|
|
560
578
|
ends sooner, a `timeout` too, once it has stalled: its test's own code has
|
|
561
579
|
run for longer than any run of the test that passed (baseline × 1.5 + 1 s)
|
|
562
580
|
and waits on a Playwright call that cannot end by its own timeout before the
|
|
563
|
-
limit, its pages quiet for a second
|
|
564
|
-
|
|
565
|
-
|
|
581
|
+
limit, its pages quiet for a second with nothing left in them that could
|
|
582
|
+
end the wait before the limit: no timer, animation frame or ending
|
|
583
|
+
animation due before it, no request unanswered, no WebSocket open, no
|
|
584
|
+
worker. An `expect` that gives up before the limit still fails the test, a
|
|
585
|
+
kill; a page still sending requests runs on; and so does one that would
|
|
586
|
+
poll again on a timer before the limit, to its limit, where a later poll
|
|
587
|
+
may answer the wait (a timeout there says it `ran to its limit to
|
|
588
|
+
confirm`, and the summary counts those). Nothing needs setting. Each timeout's verdict says what it waited on and
|
|
566
589
|
where, for example `stopped at 2.5 s of its 6.5 s time limit, ..., waiting
|
|
567
590
|
on Locator.click (#save) at tests/save.spec.ts:12:20`, and the summary says
|
|
568
591
|
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.
|
|
3
|
+
"version": "4.29.17",
|
|
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.
|
|
129
|
-
"@supercov/cli-darwin-x64": "4.29.
|
|
130
|
-
"@supercov/cli-linux-arm64-gnu": "4.29.
|
|
131
|
-
"@supercov/cli-linux-arm64-musl": "4.29.
|
|
132
|
-
"@supercov/cli-linux-x64-gnu": "4.29.
|
|
133
|
-
"@supercov/cli-linux-x64-musl": "4.29.
|
|
134
|
-
"@supercov/cli-win32-arm64": "4.29.
|
|
135
|
-
"@supercov/cli-win32-x64": "4.29.
|
|
128
|
+
"@supercov/cli-darwin-arm64": "4.29.17",
|
|
129
|
+
"@supercov/cli-darwin-x64": "4.29.17",
|
|
130
|
+
"@supercov/cli-linux-arm64-gnu": "4.29.17",
|
|
131
|
+
"@supercov/cli-linux-arm64-musl": "4.29.17",
|
|
132
|
+
"@supercov/cli-linux-x64-gnu": "4.29.17",
|
|
133
|
+
"@supercov/cli-linux-x64-musl": "4.29.17",
|
|
134
|
+
"@supercov/cli-win32-arm64": "4.29.17",
|
|
135
|
+
"@supercov/cli-win32-x64": "4.29.17"
|
|
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,
|
|
308
|
-
//
|
|
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
|
|
695
|
+
const sent = (request) => {
|
|
689
696
|
this.quietSince = Date.now();
|
|
697
|
+
this.unanswered.add(request);
|
|
690
698
|
};
|
|
691
|
-
|
|
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)
|
|
55
|
-
//
|
|
56
|
-
//
|
|
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
|
-
|
|
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
|
|
287
|
-
*
|
|
288
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
491
|
+
const pastWindow = Date.now() >= since + windowMs;
|
|
492
|
+
if (!stalled || !pastWindow) {
|
|
493
|
+
later(STALL_POLL_MS);
|
|
313
494
|
return;
|
|
314
495
|
}
|
|
315
|
-
|
|
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 = () =>
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -1667,6 +1868,7 @@ export const WHY = {
|
|
|
1667
1868
|
"module-level": "it is a server module's top-level code",
|
|
1668
1869
|
"by-time": "its code ran for a request that named no test",
|
|
1669
1870
|
"unfinished": "not every candidate test ran in the shared pass",
|
|
1871
|
+
"unfinished-twice": "not every candidate test ran in two rounds of tests side by side",
|
|
1670
1872
|
"confirm": "a test killed it beside other mutants' attempts",
|
|
1671
1873
|
"doubt": "the test that killed it failed without it too, on the same server",
|
|
1672
1874
|
"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",
|
|
@@ -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
|
-
|
|
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 (
|
|
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)
|
|
@@ -474,9 +498,20 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
474
498
|
// signal stopped leaves its mutants without a verdict, for the next
|
|
475
499
|
// pass (a confirmation round stopped before its first test made two
|
|
476
500
|
// mutants of a 60 s pass `error`s).
|
|
501
|
+
// A `rest` round's mutant runs one test at a time first: beside one
|
|
502
|
+
// another, a worker with nothing it could take yet ran through a
|
|
503
|
+
// test's copies while another worker's attempt ran, and the round
|
|
504
|
+
// ended with mutants still waiting for that test. One whose every
|
|
505
|
+
// candidate kills it (a test that fails without it is left out)
|
|
506
|
+
// was an `error` on a loaded runner. One at a time, no copy is spent
|
|
507
|
+
// so; what a serial round leaves is the `error`.
|
|
477
508
|
if (kind !== "main" && !decided && !stopped) {
|
|
478
|
-
for (const job of rest)
|
|
479
|
-
|
|
509
|
+
for (const job of rest) {
|
|
510
|
+
if (kind === "rest")
|
|
511
|
+
serial.push({ ...job, reason: "unfinished-twice" });
|
|
512
|
+
else
|
|
513
|
+
write({ id: job.id, status: "error", reason: "its tests did not finish, in two rounds", tests: 0, durationMs: 0 });
|
|
514
|
+
}
|
|
480
515
|
rest.splice(0, rest.length);
|
|
481
516
|
}
|
|
482
517
|
// A mutant run alone with the whole command started with it, whose
|
|
@@ -520,6 +555,14 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
520
555
|
durationMs: Date.now() - started,
|
|
521
556
|
attempts: mutated.length,
|
|
522
557
|
timedOut: mutated.filter((attempt) => attempt.outcome === "timed-out").length,
|
|
558
|
+
// Attempts ended where they stalled, and those that stalled where
|
|
559
|
+
// their pages could still end the wait, ran on, and timed out
|
|
560
|
+
// all the same.
|
|
561
|
+
stalls: {
|
|
562
|
+
stopped: mutated.filter((attempt) => attempt.stalledAtMs !== undefined).length,
|
|
563
|
+
ranOn: mutated.filter((attempt) => attempt.doubtedAtMs !== undefined).length,
|
|
564
|
+
ranOnTimedOut: mutated.filter((attempt) => attempt.doubtedAtMs !== undefined && attempt.outcome === "timed-out").length,
|
|
565
|
+
},
|
|
523
566
|
timeoutFactor: work.timeoutFactor,
|
|
524
567
|
baselines: attempts.filter((attempt) => attempt.kind === "baseline").length,
|
|
525
568
|
decided,
|
|
@@ -20,15 +20,17 @@
|
|
|
20
20
|
// whose parent was not chosen) runs whole from then on. A kill by a job that
|
|
21
21
|
// ran other tests than its baseline did is confirmed by running the job's
|
|
22
22
|
// tests again without the mutant. A job past 3x its baseline and 10 s is
|
|
23
|
-
// stopped: a timeout, unless a test had already failed. A
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
23
|
+
// stopped: a timeout, unless a test had already failed. A stopped job may
|
|
24
|
+
// only have waited: on the jobs beside it (the CPU; Cargo's lock on a build
|
|
25
|
+
// directory, where each job builds Rust compiled to wasm), or on a machine
|
|
26
|
+
// busier than when its baseline ran (other work on it, beyond the pass's
|
|
27
|
+
// own). So it runs again alone, after its tests ran alone without the
|
|
28
|
+
// mutant, and its limit there is 3x the slower of that run and its
|
|
29
|
+
// baseline, and 10 s: only a job past that is a timeout.
|
|
28
30
|
import { fork, spawn } from "node:child_process";
|
|
29
31
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
30
32
|
import { availableParallelism, constants, cpus } from "node:os";
|
|
31
|
-
import { basename, delimiter, join, resolve } from "node:path";
|
|
33
|
+
import { basename, delimiter, dirname, join, resolve } from "node:path";
|
|
32
34
|
import { fileURLToPath } from "node:url";
|
|
33
35
|
|
|
34
36
|
// A file whose baseline job took at most this long, the start of the command
|
|
@@ -386,7 +388,15 @@ function stop(child) {
|
|
|
386
388
|
|
|
387
389
|
export async function drive({ command, plan, resultsPath, root = process.cwd(), workers = parallelism(), environment = process.env, graceMs = 10_000, baselineGraceMs = 60_000 }) {
|
|
388
390
|
const started = Date.now();
|
|
389
|
-
|
|
391
|
+
// Once the pass is told to stop (`stopped-at` beside the results), its
|
|
392
|
+
// jobs are stopped under their tests: one that ends then says nothing of
|
|
393
|
+
// its mutant, and no verdict is written (vitestStrongReporter.mjs).
|
|
394
|
+
const stopping = join(dirname(resultsPath), "stopped-at");
|
|
395
|
+
const write = (record) => {
|
|
396
|
+
if (record.status !== undefined && existsSync(stopping))
|
|
397
|
+
return;
|
|
398
|
+
appendFileSync(resultsPath, `${JSON.stringify(record)}\n`);
|
|
399
|
+
};
|
|
390
400
|
const work = `${resultsPath}.jobs`;
|
|
391
401
|
mkdirSync(work, { recursive: true });
|
|
392
402
|
const tests = plan.tests;
|
|
@@ -685,11 +695,16 @@ export async function drive({ command, plan, resultsPath, root = process.cwd(),
|
|
|
685
695
|
const bail = !whole || [...baseline.statuses.values()].every((status) => status === "passed");
|
|
686
696
|
let result = await job({ mutant, file: group.file, tests: chosen, bail, limitMs, priority });
|
|
687
697
|
const killerIn = (outcome) => [...outcome.statuses].find(([id, status]) => status === "failed" && (chosen === null || chosen.has(id)) && !excluded(id))?.[0];
|
|
688
|
-
// Past its limit
|
|
689
|
-
//
|
|
690
|
-
|
|
698
|
+
// Past its limit with nothing failed: it may only have waited, on
|
|
699
|
+
// the jobs beside it or on a machine busier than when its
|
|
700
|
+
// baseline ran. It runs again alone, its limit from the same
|
|
701
|
+
// tests without the mutant run alone just before it, at the
|
|
702
|
+
// machine's speed now.
|
|
703
|
+
if (result.timedOut && !result.mutantTimedOut && killerIn(result) === undefined) {
|
|
691
704
|
profile.alone += 1;
|
|
692
|
-
|
|
705
|
+
const now = await job({ mutant: null, file: group.file, tests: chosen, bail: false, limitMs: baselineLimit(group.file, chosen), alone: true });
|
|
706
|
+
const slowest = Math.max(baseline.durationMs, now.durationMs);
|
|
707
|
+
result = await job({ mutant, file: group.file, tests: chosen, bail, limitMs: 3 * slowest + graceMs, alone: true });
|
|
693
708
|
}
|
|
694
709
|
const ran = [...result.statuses].filter(([id, status]) => status !== "skipped" && (chosen === null || chosen.has(id)));
|
|
695
710
|
const killer = killerIn(result);
|
|
@@ -21,7 +21,7 @@ import { syncBuiltinESMExports } from "node:module";
|
|
|
21
21
|
import { PassThrough } from "node:stream";
|
|
22
22
|
import { fileURLToPath } from "node:url";
|
|
23
23
|
import { availableParallelism } from "node:os";
|
|
24
|
-
import { relative, sep } from "node:path";
|
|
24
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
25
25
|
|
|
26
26
|
// A mutant's test, and its copy, get twice StrykerJS's limit: 1.5× the
|
|
27
27
|
// measured time and 5 s, doubled.
|
|
@@ -719,7 +719,18 @@ async function drive(vitest, runFiles, specs, plan, resultsPath) {
|
|
|
719
719
|
// Vitest 2 and later pass specifications; Vitest 1, [project, file].
|
|
720
720
|
const fileOf = (spec) => spec.moduleId ?? (Array.isArray(spec) ? spec[1] : spec);
|
|
721
721
|
const specOf = new Map(specs.map((spec) => [toRelative(root, fileOf(spec)), spec]));
|
|
722
|
-
|
|
722
|
+
// Once the pass is told to stop (Supercov notes when, `stopped-at`
|
|
723
|
+
// beside the results, before it signals the command), its copies are
|
|
724
|
+
// stopped under their tests: a copy that ends then says nothing of its
|
|
725
|
+
// mutant, and no verdict is written. The mutant is left for the next
|
|
726
|
+
// pass. One judged from a copy the budget stopped on a macOS runner was a
|
|
727
|
+
// `killed` for a mutant whose test waits five minutes.
|
|
728
|
+
const stopping = join(dirname(resultsPath), "stopped-at");
|
|
729
|
+
const write = (record) => {
|
|
730
|
+
if (record.status !== undefined && existsSync(stopping))
|
|
731
|
+
return;
|
|
732
|
+
appendFileSync(resultsPath, `${JSON.stringify(record)}\n`);
|
|
733
|
+
};
|
|
723
734
|
const tests = plan.tests;
|
|
724
735
|
const started = Date.now();
|
|
725
736
|
const passCpu = machineCpu();
|