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