supercov 4.29.2 → 4.29.4
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.
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
// Strong mutation's reporter for Playwright (playwrightStrong.mjs explains the
|
|
2
|
-
// pass). In
|
|
3
|
-
// the plan names,
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// mutant
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
// pass). In each invocation's runner process it maps each copy of a test to
|
|
3
|
+
// the test the plan names, settles an attempt whose worker ended before its
|
|
4
|
+
// fixture could, says what the invocation is doing (a status file the engine
|
|
5
|
+
// reads for its progress line, and a line on the command's output for each
|
|
6
|
+
// mutant attempt), and keeps the first error outside any test.
|
|
7
|
+
// Once the command has ended, with every invocation it started (a harness may
|
|
8
|
+
// start several at once, each with a share of the tests), the engine runs
|
|
9
|
+
// this module (`judge`), which gives each mutant the round left without a
|
|
10
|
+
// verdict its verdict, or the round that runs it next: one verdict a mutant,
|
|
11
|
+
// from whichever invocations ran it, and what was cut short is unfinished.
|
|
12
|
+
import { appendFileSync, existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
13
|
+
import { pathToFileURL } from "node:url";
|
|
14
|
+
import { attemptPath, baselineOf, entries, invocation, EVERYWHERE, firstWords, giveVerdict, key, loadPass, outcomeOf, placeOf, readJson, reasonOf, settleAttempt, strongPass, withoutCopy, writeJson } from "./playwrightStrong.mjs";
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
// How often, at most, the status file is written.
|
|
17
|
+
const STATUS_MS = 1_000;
|
|
18
|
+
|
|
19
|
+
/** Each JSON file in a directory of the pass, or none. */
|
|
20
|
+
function readAll(directory) {
|
|
21
|
+
return entries(directory).flatMap((name) => {
|
|
22
|
+
try {
|
|
23
|
+
return [readJson(`${directory}/${name}`)];
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function readJsonOr(path) {
|
|
32
|
+
try {
|
|
33
|
+
return readJson(path);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
24
39
|
|
|
25
40
|
function readLines(path) {
|
|
26
41
|
if (!existsSync(path))
|
|
@@ -38,103 +53,183 @@ function readLines(path) {
|
|
|
38
53
|
});
|
|
39
54
|
}
|
|
40
55
|
|
|
56
|
+
function seconds(ms) {
|
|
57
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
58
|
+
}
|
|
59
|
+
|
|
41
60
|
export default class SupercovPlaywrightStrongReporter {
|
|
42
61
|
constructor() {
|
|
43
62
|
this.pass = strongPass();
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.byOriginal = new Map();
|
|
63
|
+
this.running = new Map();
|
|
64
|
+
this.counts = { baselines: 0, controls: 0, failedControls: 0, attempts: 0, killed: 0, passed: 0 };
|
|
65
|
+
this.writtenAt = 0;
|
|
48
66
|
}
|
|
49
|
-
// It prints
|
|
50
|
-
// its own where none does
|
|
67
|
+
// It prints its own lines, and says it prints: Playwright adds a reporter
|
|
68
|
+
// of its own where none does. The command's output is a log beside the
|
|
69
|
+
// pass's results, not `mutants test`'s stdout.
|
|
51
70
|
printsToStdio() {
|
|
52
71
|
return true;
|
|
53
72
|
}
|
|
54
73
|
onBegin(_config, suite) {
|
|
55
74
|
if (!this.pass)
|
|
56
75
|
return;
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
for (const test of
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
for (const test of all) {
|
|
68
|
-
const original = test.repeatEachIndex ? firsts.get(where(test)) : test.id;
|
|
69
|
-
if (!original)
|
|
76
|
+
this.work = loadPass(this.pass);
|
|
77
|
+
this.startedAt = Date.now();
|
|
78
|
+
// A copy of a test has an id of its own; the plan names the test as
|
|
79
|
+
// declared. Copies share its project, file and titles: a worker finds
|
|
80
|
+
// the test's id by them, one small file a test.
|
|
81
|
+
let copies = 0;
|
|
82
|
+
for (const test of suite.allTests()) {
|
|
83
|
+
copies += 1;
|
|
84
|
+
if (withoutCopy(test.titlePath()).copy)
|
|
70
85
|
continue;
|
|
71
|
-
this.
|
|
72
|
-
this.byOriginal.set(`${original}\0${test.repeatEachIndex}`, test.id);
|
|
86
|
+
writeJson(`${this.pass.round}/originals/${key(placeOf(test))}`, test.id);
|
|
73
87
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
this.copies = copies;
|
|
89
|
+
const mutants = Object.keys(this.work.entries).length;
|
|
90
|
+
const tests = Object.values(this.work.tests).filter((test) => test.jobs).length;
|
|
91
|
+
console.log(`[supercov] strong pass, ${describeRound(this.work)}: ${mutants} mutant(s) over ${tests} test(s), ${copies} test case(s) in this invocation`);
|
|
92
|
+
this.writeStatus(true);
|
|
93
|
+
// Said while a long test runs, too.
|
|
94
|
+
this.timer = setInterval(() => this.writeStatus(true), 5_000);
|
|
95
|
+
this.timer.unref?.();
|
|
81
96
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
catch {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
97
|
+
onTestBegin(test) {
|
|
98
|
+
if (!this.pass)
|
|
99
|
+
return;
|
|
100
|
+
this.running.set(test.id, { title: test.title, begunAt: Date.now() });
|
|
101
|
+
this.writeStatus(false);
|
|
90
102
|
}
|
|
91
103
|
onError(error) {
|
|
92
104
|
// Outside any test: a web server that exited, a global setup that
|
|
93
|
-
// threw.
|
|
94
|
-
this.
|
|
105
|
+
// threw. Each invocation's first one's time and words.
|
|
106
|
+
if (!this.pass || this.erred)
|
|
107
|
+
return;
|
|
108
|
+
this.erred = true;
|
|
109
|
+
writeJson(`${this.pass.round}/errors/${process.pid}.json`, { pid: process.pid, at: Date.now(), message: firstWords(error?.message ?? error) });
|
|
95
110
|
}
|
|
96
111
|
onTestEnd(test, result) {
|
|
97
112
|
if (!this.pass)
|
|
98
113
|
return;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const found = this.rowOf(test);
|
|
111
|
-
if (!found)
|
|
114
|
+
this.running.delete(test.id);
|
|
115
|
+
const path = attemptPath(this.pass, invocation(), test.id);
|
|
116
|
+
let attempt;
|
|
117
|
+
try {
|
|
118
|
+
attempt = readJson(path);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
attempt = undefined;
|
|
122
|
+
}
|
|
123
|
+
if (!attempt) {
|
|
124
|
+
this.writeStatus(false);
|
|
112
125
|
return;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
}
|
|
127
|
+
// Its worker ended before its fixture did (a mutant that crashed it):
|
|
128
|
+
// the reporter settles it.
|
|
129
|
+
if (attempt.endedAt === undefined) {
|
|
130
|
+
const { outcome, message } = outcomeOf(result.status, result.errors ?? []);
|
|
131
|
+
attempt = settleAttempt(this.pass, { ...attempt, outcome, message });
|
|
132
|
+
}
|
|
133
|
+
this.lastEndedAt = Date.now();
|
|
134
|
+
this.say(attempt);
|
|
135
|
+
this.writeStatus(false);
|
|
136
|
+
}
|
|
137
|
+
/** A line on the command's output for each attempt with a mutant, and each control that failed. */
|
|
138
|
+
say(attempt) {
|
|
139
|
+
const took = seconds((attempt.endedAt ?? Date.now()) - attempt.startedAt);
|
|
140
|
+
if (attempt.kind !== "mutant") {
|
|
141
|
+
this.counts[attempt.kind === "baseline" ? "baselines" : "controls"] += 1;
|
|
142
|
+
if (attempt.outcome === "failed" || attempt.outcome === "timed-out") {
|
|
143
|
+
this.counts.failedControls += 1;
|
|
144
|
+
console.log(`[supercov] ${attempt.kind} failed, with no mutant: ${JSON.stringify(attempt.title)} (${took}): ${attempt.message ?? attempt.outcome}`);
|
|
145
|
+
}
|
|
116
146
|
return;
|
|
117
147
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
148
|
+
this.counts.attempts += 1;
|
|
149
|
+
this.firstMutantAt ??= attempt.startedAt;
|
|
150
|
+
if (attempt.outcome === "passed")
|
|
151
|
+
this.counts.passed += 1;
|
|
152
|
+
else if (attempt.outcome === "failed")
|
|
153
|
+
this.counts.killed += 1;
|
|
154
|
+
const said = attempt.outcome === "passed" ? "lives" : attempt.outcome === "failed" ? "fails" : attempt.outcome;
|
|
155
|
+
console.log(`[supercov] ${attempt.id}: ${JSON.stringify(attempt.title)} ${said} (${took})`);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* What this invocation is doing, for the engine's progress line: the
|
|
159
|
+
* tests running and since when, what ended so far, and when the last
|
|
160
|
+
* one did. Written at most once a second, unless `now`.
|
|
161
|
+
*/
|
|
162
|
+
writeStatus(now) {
|
|
163
|
+
if (!this.pass || (!now && Date.now() - this.writtenAt < STATUS_MS))
|
|
164
|
+
return;
|
|
165
|
+
this.writtenAt = Date.now();
|
|
166
|
+
const running = [...this.running].map(([id, { title, begunAt }]) => {
|
|
167
|
+
let attempt;
|
|
168
|
+
try {
|
|
169
|
+
attempt = readJson(attemptPath(this.pass, invocation(), id));
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
attempt = undefined;
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
title,
|
|
176
|
+
begunAt,
|
|
177
|
+
kind: attempt?.kind,
|
|
178
|
+
mutant: attempt?.id ?? undefined,
|
|
179
|
+
startedAt: attempt?.startedAt,
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
try {
|
|
183
|
+
writeJson(`${this.pass.shared}/status/${process.pid}.json`, {
|
|
184
|
+
round: this.pass.name,
|
|
185
|
+
kind: this.work?.kind,
|
|
186
|
+
pid: process.pid,
|
|
187
|
+
startedAt: this.startedAt,
|
|
188
|
+
updatedAt: Date.now(),
|
|
189
|
+
copies: this.copies,
|
|
190
|
+
counts: this.counts,
|
|
191
|
+
firstMutantAt: this.firstMutantAt,
|
|
192
|
+
lastEndedAt: this.lastEndedAt,
|
|
193
|
+
running,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// The status is for the progress line; the pass goes on without it.
|
|
198
|
+
}
|
|
121
199
|
}
|
|
122
200
|
onEnd() {
|
|
123
201
|
if (!this.pass)
|
|
124
202
|
return;
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
|
|
203
|
+
clearInterval(this.timer);
|
|
204
|
+
this.running.clear();
|
|
205
|
+
this.writeStatus(true);
|
|
206
|
+
// A killed mutant fails a test, and that is the point: the command's
|
|
207
|
+
// outcome is the pass's, not the tests'. The verdicts are the
|
|
208
|
+
// judge's, once every invocation has ended.
|
|
128
209
|
return { status: "passed" };
|
|
129
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* The round's verdicts left, from what its invocations left on disk:
|
|
213
|
+
* each attempt, the baselines, the kills not yet confirmed, and the
|
|
214
|
+
* errors outside any test; and the rounds to run next.
|
|
215
|
+
*/
|
|
130
216
|
finish() {
|
|
131
|
-
const { pass
|
|
132
|
-
const
|
|
217
|
+
const { pass } = this;
|
|
218
|
+
const work = (this.work = loadPass(pass));
|
|
219
|
+
const kind = work.kind;
|
|
220
|
+
const round = pass.round;
|
|
221
|
+
const attempts = readAll(`${round}/attempts`);
|
|
222
|
+
const errors = readAll(`${round}/errors`).sort((a, b) => a.at - b.at);
|
|
223
|
+
const globalError = errors[0];
|
|
224
|
+
const started = Math.min(statSync(`${round}/pass.json`).mtimeMs, ...attempts.map((attempt) => attempt.startedAt));
|
|
133
225
|
const write = (record) => appendFileSync(pass.resultsPath, `${JSON.stringify(record)}\n`);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
226
|
+
let decided = 0;
|
|
227
|
+
for (const record of work.immediate) {
|
|
228
|
+
if (giveVerdict(pass, record))
|
|
229
|
+
decided += 1;
|
|
230
|
+
}
|
|
231
|
+
// Where a mutant ran past its hit limit in a server, by attempt; and
|
|
232
|
+
// in a process that had it on everywhere, by mutant alone.
|
|
138
233
|
const timedOut = new Set();
|
|
139
234
|
const timedOutAnywhere = new Set();
|
|
140
235
|
for (const line of readLines(`${pass.resultsPath}.timeouts.jsonl`)) {
|
|
@@ -145,233 +240,212 @@ export default class SupercovPlaywrightStrongReporter {
|
|
|
145
240
|
else
|
|
146
241
|
timedOutAnywhere.add(line.mutant);
|
|
147
242
|
}
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
243
|
+
const byMutant = new Map();
|
|
244
|
+
const controls = { ran: 0, failed: [] };
|
|
245
|
+
for (const attempt of attempts) {
|
|
246
|
+
if (attempt.kind !== "mutant") {
|
|
247
|
+
if (attempt.kind === "control" && attempt.endedAt !== undefined) {
|
|
248
|
+
controls.ran += 1;
|
|
249
|
+
if (attempt.outcome === "failed" || attempt.outcome === "timed-out")
|
|
250
|
+
controls.failed.push(attempt.original);
|
|
154
251
|
}
|
|
252
|
+
continue;
|
|
155
253
|
}
|
|
254
|
+
if (!byMutant.has(attempt.id))
|
|
255
|
+
byMutant.set(attempt.id, []);
|
|
256
|
+
byMutant.get(attempt.id).push(attempt);
|
|
156
257
|
}
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const attempt = this.attempt(repetition);
|
|
162
|
-
if (attempt && attempt.mutant !== "-")
|
|
163
|
-
mutated.push({ ...attempt, repetition, endedAt: attempt.endedAt ?? Date.now() });
|
|
164
|
-
}
|
|
165
|
-
const beside = (repetition, attempt) => mutated.some((other) => other.repetition !== repetition &&
|
|
166
|
-
other.mutant !== attempt.mutant &&
|
|
167
|
-
other.startedAt < (attempt.endedAt ?? Date.now()) &&
|
|
168
|
-
attempt.startedAt < other.endedAt);
|
|
169
|
-
// Each repetition's outcome.
|
|
170
|
-
const outcomeOf = (original, index, mutant) => {
|
|
171
|
-
const repetition = this.byOriginal.get(`${original}\0${index}`);
|
|
172
|
-
const ended = repetition && this.statuses.get(repetition);
|
|
173
|
-
const attempt = repetition && this.attempt(repetition);
|
|
174
|
-
if (!attempt) {
|
|
175
|
-
if (baselineFailed.has(original))
|
|
176
|
-
return { kind: "baseline-failed" };
|
|
177
|
-
return { kind: "unrun" };
|
|
178
|
-
}
|
|
179
|
-
const ranAway = attempt.pageTimeout === true ||
|
|
180
|
-
(attempt.attemptId && timedOut.has(attempt.attemptId)) ||
|
|
181
|
-
(mutant && timedOutAnywhere.has(mutant));
|
|
182
|
-
const base = {
|
|
183
|
-
startedAt: attempt.startedAt,
|
|
184
|
-
endedAt: attempt.endedAt ?? Date.now(),
|
|
185
|
-
message: ended?.message,
|
|
186
|
-
beside: beside(repetition, attempt),
|
|
187
|
-
};
|
|
188
|
-
if (ranAway)
|
|
189
|
-
return { ...base, kind: "hit-limit" };
|
|
190
|
-
if (ended?.status === "passed")
|
|
191
|
-
return { ...base, kind: "passed" };
|
|
192
|
-
if (ended?.status === "timedOut" && ended.timeoutOnly)
|
|
193
|
-
return { ...base, kind: "timed-out" };
|
|
194
|
-
if (ended?.status === "failed" || ended?.status === "interrupted" || ended?.status === "timedOut")
|
|
195
|
-
return { ...base, kind: "failed" };
|
|
196
|
-
return { kind: "unrun" };
|
|
197
|
-
};
|
|
198
|
-
// Each mutant's repetitions, in every file it has a row in, and the
|
|
199
|
-
// canaries'.
|
|
200
|
-
const outcomes = new Map();
|
|
201
|
-
const canaries = [];
|
|
202
|
-
for (const fileRows of Object.values(rows.files)) {
|
|
203
|
-
fileRows.forEach((row, index) => {
|
|
204
|
-
if (row.kind === "baseline")
|
|
205
|
-
return;
|
|
206
|
-
for (const original of row.tests) {
|
|
207
|
-
const outcome = { test: original, ...outcomeOf(original, index, row.mutant) };
|
|
208
|
-
if (row.kind === "canary") {
|
|
209
|
-
canaries.push(outcome);
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
if (!outcomes.has(row.id))
|
|
213
|
-
outcomes.set(row.id, []);
|
|
214
|
-
outcomes.get(row.id).push(outcome);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
// What runs next: one mutant alone (with the server started with
|
|
219
|
-
// it, where a server ran its code outside any request), a further
|
|
220
|
-
// pass of survivors' other candidates, and a serial pass, one test
|
|
221
|
-
// at a time, for kills to confirm, timeouts' second tries and what
|
|
222
|
-
// did not finish.
|
|
258
|
+
// What runs next: one mutant alone (with the server started with it,
|
|
259
|
+
// where a server ran its code outside any request), and one test at
|
|
260
|
+
// a time for kills to confirm and timeouts' second tries; the rest of
|
|
261
|
+
// what did not finish, as this round ran it.
|
|
223
262
|
const alone = [];
|
|
224
|
-
const stage = [];
|
|
225
263
|
const serial = [];
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
264
|
+
const rest = [];
|
|
265
|
+
const aloneAgain = [];
|
|
266
|
+
const aloneEach = [];
|
|
267
|
+
const next = (entry, reason, tests, budgetFactor = 1) => {
|
|
268
|
+
const runnable = tests.filter((test) => baselineOf(pass, test) !== "failed");
|
|
269
|
+
if (!runnable.length) {
|
|
230
270
|
write({ id: entry.id, status: "error", reason: "its candidate tests fail without any mutant", tests: 0, durationMs: 0 });
|
|
231
271
|
return;
|
|
232
272
|
}
|
|
233
|
-
const job = runnable
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
273
|
+
const job = { id: entry.id, mutant: entry.mutant, tests: runnable, reason, budgetFactor };
|
|
274
|
+
// What an alone round left runs alone again, as it was.
|
|
275
|
+
if (kind === "alone")
|
|
276
|
+
aloneEach.push({ ...job, reason: entry.reason });
|
|
277
|
+
else if (EVERYWHERE.includes(reason))
|
|
237
278
|
alone.push(job);
|
|
238
|
-
else if (reason === "
|
|
239
|
-
|
|
279
|
+
else if (reason === "unfinished")
|
|
280
|
+
rest.push(job);
|
|
240
281
|
else
|
|
241
282
|
serial.push(job);
|
|
242
283
|
};
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
next(entry, "canary", all);
|
|
284
|
+
const trustedUntil = globalError ? globalError.at : Infinity;
|
|
285
|
+
// One mutant an invocation: which invocation took each, and where a
|
|
286
|
+
// server of that invocation ran it (an invocation whose server was
|
|
287
|
+
// started before it, outside it, never ran its mutant there).
|
|
288
|
+
const claimedBy = new Map();
|
|
289
|
+
for (const name of entries(`${round}/invocations`)) {
|
|
290
|
+
const taken = readJsonOr(`${round}/invocations/${name}`);
|
|
291
|
+
if (taken?.id)
|
|
292
|
+
claimedBy.set(taken.id, name.replace(/\.json$/, ""));
|
|
293
|
+
}
|
|
294
|
+
const ranInServer = new Set(readLines(`${pass.resultsPath}.everywhere.jsonl`).map((line) => `${line.invocation}\0${line.mutant}`));
|
|
295
|
+
for (const [id, entry] of Object.entries(work.entries)) {
|
|
296
|
+
if (existsSync(`${pass.shared}/verdicts/${key(id)}`)) {
|
|
297
|
+
decided += 1;
|
|
258
298
|
continue;
|
|
259
299
|
}
|
|
260
|
-
const
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
if (!verdict || verdict === "confirm")
|
|
300
|
+
const invocation = claimedBy.get(id);
|
|
301
|
+
if (work.batch && invocation === undefined) {
|
|
302
|
+
aloneAgain.push(entry);
|
|
264
303
|
continue;
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
304
|
+
}
|
|
305
|
+
const own = byMutant.get(id) ?? [];
|
|
306
|
+
const ended = own.filter((attempt) => attempt.endedAt !== undefined);
|
|
307
|
+
const ranAway = own.find((attempt) => timedOut.has(attempt.attemptId) || timedOutAnywhere.has(entry.mutant));
|
|
308
|
+
const failed = ended.filter((attempt) => attempt.outcome === "failed");
|
|
309
|
+
const after = reasonOf(kind, entry.reason);
|
|
310
|
+
const suffix = after ? `; ${after}` : "";
|
|
311
|
+
const durationMs = ended.length
|
|
312
|
+
? Math.max(...ended.map((attempt) => attempt.endedAt)) - Math.min(...ended.map((attempt) => attempt.startedAt))
|
|
268
313
|
: 0;
|
|
269
|
-
|
|
314
|
+
const verdict = (record) => {
|
|
315
|
+
if (giveVerdict(pass, { id, ...record, tests: ended.length, durationMs }))
|
|
316
|
+
decided += 1;
|
|
317
|
+
};
|
|
318
|
+
// A kill beside another mutant's attempt, or whose control failed
|
|
319
|
+
// without the mutant: its killing test first, alone, then the rest.
|
|
320
|
+
const doubted = existsSync(`${round}/confirm/${key(id)}`) ? "confirm" : existsSync(`${round}/doubt/${key(id)}`) ? "doubt" : undefined;
|
|
321
|
+
if (doubted && failed.length) {
|
|
322
|
+
const first = failed[0].original;
|
|
323
|
+
next(entry, doubted, [first, ...entry.tests.filter((test) => test !== first)]);
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
// A kill no control came after (the round ended first): as sure as a
|
|
327
|
+
// kill on a server no other mutant's attempt shared.
|
|
328
|
+
const killer = failed.find((attempt) => !attempt.beside && attempt.endedAt < trustedUntil);
|
|
329
|
+
if (killer) {
|
|
330
|
+
verdict({ status: "killed", killedBy: killer.original, reason: `${killer.message ?? "the test failed"}${suffix}` });
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (ranAway) {
|
|
334
|
+
verdict({ status: "timeout", killedBy: ranAway.original, reason: `evaluated past its hit limit${suffix}` });
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (existsSync(`${round}/held/${key(id)}`)) {
|
|
338
|
+
next(entry, "timeout-retry", entry.tests, 2 * (entry.budgetFactor ?? 1));
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
// Alone, the command failed outside any test: the mutant broke the
|
|
342
|
+
// app (a server that would not start with it).
|
|
343
|
+
// (Where one invocation of several failed so, it runs alone with
|
|
344
|
+
// the whole command started with it, which says whether it was the
|
|
345
|
+
// mutant's doing.)
|
|
346
|
+
if (kind === "alone" && !work.batch && globalError && !ended.length) {
|
|
347
|
+
verdict({ status: "killed", reason: `the command failed with it switched on (${globalError.message})${suffix}` });
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
// Its invocation's server never ran it: alone, the whole command
|
|
351
|
+
// started with it.
|
|
352
|
+
if (work.batch && !ranInServer.has(`${invocation}\0${entry.mutant}`)) {
|
|
353
|
+
aloneEach.push(entry);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const passed = new Set(ended.filter((attempt) => attempt.outcome === "passed" && attempt.endedAt < trustedUntil).map((attempt) => attempt.original));
|
|
357
|
+
const runnable = entry.tests.filter((test) => baselineOf(pass, test) !== "failed");
|
|
358
|
+
const left = runnable.filter((test) => !passed.has(test));
|
|
359
|
+
if (!runnable.length) {
|
|
360
|
+
verdict({ status: "error", reason: "its candidate tests fail without any mutant" });
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (left.length) {
|
|
364
|
+
next(entry, "unfinished", left);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const others = work.otherRunners[id];
|
|
368
|
+
verdict(others
|
|
369
|
+
? { status: "error", reason: `no Playwright test killed it, and its other candidates ran under ${others.join(", ")}, which this pass does not run` }
|
|
370
|
+
: { status: "survived", ...(after ? { reason: after } : {}) });
|
|
270
371
|
}
|
|
271
|
-
for (const job of
|
|
372
|
+
for (const job of work.restarts)
|
|
272
373
|
next(job, job.reason, job.tests);
|
|
273
|
-
// A
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
374
|
+
// A round of what an earlier one left that ran to its end and decided
|
|
375
|
+
// nothing would only ask for the same again. One the budget or a
|
|
376
|
+
// signal stopped leaves its mutants without a verdict, for the next
|
|
377
|
+
// pass (a confirmation round stopped before its first test made two
|
|
378
|
+
// mutants of a 60 s pass `error`s).
|
|
379
|
+
const stopped = process.env["SUPERCOV_STRONG_STOPPED"] === "1";
|
|
380
|
+
if (kind !== "main" && !decided && !stopped) {
|
|
381
|
+
for (const job of rest)
|
|
382
|
+
write({ id: job.id, status: "error", reason: "its tests did not finish, in two rounds", tests: 0, durationMs: 0 });
|
|
383
|
+
rest.splice(0, rest.length);
|
|
384
|
+
}
|
|
385
|
+
// A mutant run alone with the whole command started with it, whose
|
|
386
|
+
// tests did not finish: there is no way left to run it.
|
|
387
|
+
if (kind === "alone" && !work.batch && !stopped) {
|
|
388
|
+
for (const job of aloneEach)
|
|
389
|
+
write({ id: job.id, status: "error", reason: "its tests did not finish, run alone", tests: 0, durationMs: 0 });
|
|
390
|
+
aloneEach.splice(0, aloneEach.length);
|
|
279
391
|
}
|
|
280
|
-
for
|
|
281
|
-
|
|
282
|
-
if (
|
|
283
|
-
write({ restart: { kind: "
|
|
392
|
+
// What this invocation had no room for runs in the next, as this
|
|
393
|
+
// one would have run it.
|
|
394
|
+
if (work.deferred.length)
|
|
395
|
+
write({ restart: { kind: "main", reason: "more copies than one invocation holds", mutants: work.deferred } });
|
|
396
|
+
// The mutants a server must start with: one round of them, each
|
|
397
|
+
// invocation of the command taking one; those no invocation took
|
|
398
|
+
// again so, unless none took any; and each one its server did not run
|
|
399
|
+
// (or every one, where no invocation took one) alone with the whole
|
|
400
|
+
// command started with it.
|
|
401
|
+
const takenAny = claimedBy.size > 0;
|
|
402
|
+
for (const entry of aloneAgain)
|
|
403
|
+
(takenAny ? alone : aloneEach).push({ ...entry, budgetFactor: entry.budgetFactor ?? 1 });
|
|
404
|
+
if (alone.length)
|
|
405
|
+
write({ restart: { kind: "alone", everywhere: true, batch: true, reason: "server-wide", mutants: alone, otherRunners: work.otherRunners } });
|
|
406
|
+
for (const job of aloneEach)
|
|
407
|
+
write({ restart: { kind: "alone", everywhere: true, reason: job.reason, mutants: [job], otherRunners: work.otherRunners } });
|
|
408
|
+
if (rest.length)
|
|
409
|
+
write({ restart: { kind: "rest", reason: "unfinished", mutants: rest, otherRunners: work.otherRunners } });
|
|
284
410
|
if (serial.length)
|
|
285
|
-
write({ restart: { kind: "serial", reason: [...new Set(serial.map((job) => job.reason))].join(", "), mutants: serial, otherRunners:
|
|
411
|
+
write({ restart: { kind: "serial", reason: [...new Set(serial.map((job) => job.reason))].join(", "), mutants: serial, otherRunners: work.otherRunners } });
|
|
412
|
+
const mutated = attempts.filter((attempt) => attempt.kind === "mutant");
|
|
286
413
|
write({
|
|
287
414
|
summary: true,
|
|
288
415
|
runner: "playwright",
|
|
289
416
|
pass: pass.name,
|
|
290
417
|
kind,
|
|
291
|
-
...(
|
|
292
|
-
serialFiles:
|
|
293
|
-
...(
|
|
294
|
-
|
|
418
|
+
...(work.concurrency.workers ? { workers: work.concurrency.workers } : {}),
|
|
419
|
+
serialFiles: work.concurrency.serialFiles.length,
|
|
420
|
+
...(globalError ? { error: globalError.message } : {}),
|
|
421
|
+
invocations: new Set(attempts.map((attempt) => attempt.invocation)).size,
|
|
422
|
+
workerProcesses: new Set(attempts.map((attempt) => attempt.worker)).size,
|
|
423
|
+
durationMs: Date.now() - started,
|
|
424
|
+
attempts: mutated.length,
|
|
425
|
+
baselines: attempts.filter((attempt) => attempt.kind === "baseline").length,
|
|
295
426
|
decided,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
canaries: {
|
|
299
|
-
ran: canaries.filter((canary) => canary.startedAt !== undefined).length,
|
|
300
|
-
failed: failedCanaries.map((canary) => canary.test),
|
|
301
|
-
},
|
|
427
|
+
next: { alone: alone.length, rest: rest.length, serial: serial.length },
|
|
428
|
+
controls,
|
|
302
429
|
});
|
|
303
430
|
}
|
|
304
|
-
/**
|
|
305
|
-
* A mutant's verdict from its repetitions in this pass; `undefined` when
|
|
306
|
-
* it was sent on to another pass, `"confirm"` when a kill beside other
|
|
307
|
-
* mutants' attempts is to be confirmed one test at a time.
|
|
308
|
-
*/
|
|
309
|
-
verdict(entry, outcomes, all, trustedUntil, next) {
|
|
310
|
-
const { rows } = this;
|
|
311
|
-
const kind = rows.kind;
|
|
312
|
-
const shared = kind === "main" || kind === "stage";
|
|
313
|
-
const reason = entry.reason ?? (kind === "main" ? undefined : rows.job?.reason);
|
|
314
|
-
const after = kind === "alone"
|
|
315
|
-
? `; ran alone${EVERYWHERE.includes(reason) ? ", with the server started with it switched on" : ""}: ${WHY[reason] ?? reason}`
|
|
316
|
-
: kind === "serial"
|
|
317
|
-
? `; ran one test at a time: ${WHY[reason] ?? reason}`
|
|
318
|
-
: "";
|
|
319
|
-
const trusted = (outcome) => !shared || (!outcome.beside && outcome.endedAt < trustedUntil);
|
|
320
|
-
const failed = outcomes.filter((outcome) => outcome.kind === "failed");
|
|
321
|
-
const killer = failed.find(trusted);
|
|
322
|
-
if (killer)
|
|
323
|
-
return { status: "killed", killedBy: killer.test, reason: `${killer.message ?? "the test failed"}${after}` };
|
|
324
|
-
const ranAway = outcomes.find((outcome) => outcome.kind === "hit-limit");
|
|
325
|
-
if (ranAway)
|
|
326
|
-
return { status: "timeout", killedBy: ranAway.test, reason: `evaluated past its hit limit${after}` };
|
|
327
|
-
if (failed.length) {
|
|
328
|
-
// Its killing test ran beside other mutants' attempts (or after
|
|
329
|
-
// the shared server failed): that test first, alone, then the rest.
|
|
330
|
-
const first = failed[0].test;
|
|
331
|
-
next(entry, failed.some((outcome) => outcome.beside) ? "confirm" : "unfinished", [first], 1, all.filter((test) => test !== first));
|
|
332
|
-
return "confirm";
|
|
333
|
-
}
|
|
334
|
-
const slow = outcomes.find((outcome) => outcome.kind === "timed-out");
|
|
335
|
-
if (slow) {
|
|
336
|
-
if (shared) {
|
|
337
|
-
next(entry, "timeout-retry", all, 2);
|
|
338
|
-
return undefined;
|
|
339
|
-
}
|
|
340
|
-
return { status: "timeout", killedBy: slow.test, reason: `ran out of time${after}` };
|
|
341
|
-
}
|
|
342
|
-
const unrun = outcomes.filter((outcome) => outcome.kind === "unrun" || (shared && outcome.endedAt !== undefined && outcome.endedAt >= trustedUntil));
|
|
343
|
-
if (unrun.length) {
|
|
344
|
-
// Alone, the command failed outside any test: the mutant broke the
|
|
345
|
-
// app (a server that would not start with it).
|
|
346
|
-
if (kind === "alone" && this.globalError)
|
|
347
|
-
return { status: "killed", reason: `the command failed with it switched on (${this.globalError.message})${after}` };
|
|
348
|
-
next(entry, "unfinished", all);
|
|
349
|
-
return undefined;
|
|
350
|
-
}
|
|
351
|
-
if (outcomes.length && outcomes.every((outcome) => outcome.kind === "baseline-failed"))
|
|
352
|
-
return { status: "error", reason: "its candidate tests fail without any mutant" };
|
|
353
|
-
// Its likeliest killer let it live: its other candidates next, side
|
|
354
|
-
// by side after the main pass, one at a time after a serial one.
|
|
355
|
-
if (entry.rest?.length && kind !== "stage") {
|
|
356
|
-
next(entry, kind === "main" ? "stage" : "rest", entry.rest);
|
|
357
|
-
return undefined;
|
|
358
|
-
}
|
|
359
|
-
const others = rows.otherRunners[entry.id];
|
|
360
|
-
if (others)
|
|
361
|
-
return { status: "error", reason: `no Playwright test killed it, and its other candidates ran under ${others.join(", ")}, which this pass does not run` };
|
|
362
|
-
return { status: "survived", ...(after ? { reason: after.slice(2) } : {}) };
|
|
363
|
-
}
|
|
364
431
|
}
|
|
365
432
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
433
|
+
/** A round as its first line says it. */
|
|
434
|
+
function describeRound(work) {
|
|
435
|
+
if (work.kind === "main")
|
|
436
|
+
return work.job ? "the main round's rest" : "main round";
|
|
437
|
+
if (work.kind === "alone")
|
|
438
|
+
return `alone (${EVERYWHERE.includes(work.job?.reason) ? "the server started with the mutant" : work.job?.reason})`;
|
|
439
|
+
return `${work.kind} round (${work.job?.reason})`;
|
|
371
440
|
}
|
|
372
441
|
|
|
373
|
-
/**
|
|
374
|
-
function
|
|
375
|
-
const
|
|
376
|
-
|
|
442
|
+
/** Decides the round's verdicts: run by the engine once the command has ended. */
|
|
443
|
+
export function judge() {
|
|
444
|
+
const reporter = new SupercovPlaywrightStrongReporter();
|
|
445
|
+
if (!reporter.pass || !existsSync(`${reporter.pass.round}/pass.json`))
|
|
446
|
+
return;
|
|
447
|
+
reporter.finish();
|
|
377
448
|
}
|
|
449
|
+
|
|
450
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href)
|
|
451
|
+
judge();
|