supercov 4.29.3 → 4.29.5

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 repetition of a
3
- // test to the test the plan names, marks each test's baseline and each killed
4
- // mutant as results come (the fixture reads them: a repetition after a failed
5
- // baseline or a kill skips), and keeps each repetition's outcome on disk.
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 turns the outcomes into each mutant's verdict,
9
- // in the results file `mutants test` reads: one verdict a mutant, from
10
- // whichever invocations ran its rows, and what was cut short is unfinished.
11
- import { appendFileSync, existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
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, loadRows, placeOf, readJson, strongPass, writeJson } from "./playwrightStrong.mjs";
14
+ import { attemptPath, baselineOf, entries, invocation, EVERYWHERE, firstWords, giveVerdict, key, loadPass, outcomeOf, placeOf, readJson, reasonOf, settleAttempt, strongPass, verdictOf, withoutCopy, writeJson } from "./playwrightStrong.mjs";
14
15
 
15
- const WHY = {
16
- "background": "its code ran in server work no request named",
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
- let names;
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.originals = new Map();
63
+ this.running = new Map();
64
+ this.counts = { baselines: 0, controls: 0, failedControls: 0, attempts: 0, killed: 0, timedOut: 0, passed: 0 };
65
+ this.writtenAt = 0;
69
66
  }
70
- // It prints nothing, and says it prints: Playwright adds a reporter of
71
- // its own where none does, and `mutants test --json` owns stdout.
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.rows = loadRows(this.pass);
79
- // A repetition of a test has an id of its own; the plan names the
80
- // first. Repetitions share the test's project, file and titles: a
81
- // worker finds the first's id by them, one small file a test.
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
- if (test.repeatEachIndex)
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
- rowOf(test) {
90
- const original = test.repeatEachIndex ? this.originals.get(placeOf(test)) : test.id;
91
- const file = original && this.rows.tests[original]?.file;
92
- const row = file && this.rows.files[file]?.[test.repeatEachIndex];
93
- return row && row.tests.includes(original) ? { row, original } : undefined;
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,137 @@ 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
- // Why it failed, and whether only the test's time ran out: a test
107
- // that timed out while an assertion or an action was failing failed
108
- // on its own.
109
- const errors = result.errors ?? [];
110
- const timeoutOnly = errors.length > 0 && errors.every((error) => TEST_TIMEOUT.test(stripAnsi(error?.message ?? "")));
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
- if (!found)
120
+ catch {
121
+ attempt = undefined;
122
+ }
123
+ if (!attempt) {
124
+ this.writeStatus(false);
121
125
  return;
122
- const { row, original } = found;
123
- if (row.kind === "baseline" && !this.rows.job) {
124
- // A test stopped (the command was) or skipped did not fail: its
125
- // rows skip, and their mutants are unfinished, not decided.
126
- const said = result.status === "passed" ? "passed" : result.status === "failed" || result.status === "timedOut" ? "failed" : "unfinished";
127
- writeJson(`${this.pass.round}/baseline/${key(original)}`, said);
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
+ }
128
146
  return;
129
147
  }
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);
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
+ else if (attempt.outcome === "timed-out")
155
+ this.counts.timedOut += 1;
156
+ const said = {
157
+ "passed": "lives",
158
+ "failed": "fails",
159
+ "timed-out": `ran out of its ${seconds(attempt.limitMs)} limit (its baseline ${seconds(attempt.baselineMs)})`,
160
+ }[attempt.outcome] ?? attempt.outcome;
161
+ console.log(`[supercov] ${attempt.id}: ${JSON.stringify(attempt.title)} ${said} (${took})`);
162
+ }
163
+ /**
164
+ * What this invocation is doing, for the engine's progress line: the
165
+ * tests running and since when, what ended so far, and when the last
166
+ * one did. Written at most once a second, unless `now`.
167
+ */
168
+ writeStatus(now) {
169
+ if (!this.pass || (!now && Date.now() - this.writtenAt < STATUS_MS))
170
+ return;
171
+ this.writtenAt = Date.now();
172
+ const running = [...this.running].map(([id, { title, begunAt }]) => {
173
+ let attempt;
174
+ try {
175
+ attempt = readJson(attemptPath(this.pass, invocation(), id));
176
+ }
177
+ catch {
178
+ attempt = undefined;
179
+ }
180
+ return {
181
+ title,
182
+ begunAt,
183
+ kind: attempt?.kind,
184
+ mutant: attempt?.id ?? undefined,
185
+ startedAt: attempt?.startedAt,
186
+ limitMs: attempt?.limitMs,
187
+ };
188
+ });
189
+ try {
190
+ writeJson(`${this.pass.shared}/status/${process.pid}.json`, {
191
+ round: this.pass.name,
192
+ kind: this.work?.kind,
193
+ pid: process.pid,
194
+ startedAt: this.startedAt,
195
+ updatedAt: Date.now(),
196
+ copies: this.copies,
197
+ counts: this.counts,
198
+ firstMutantAt: this.firstMutantAt,
199
+ lastEndedAt: this.lastEndedAt,
200
+ running,
201
+ });
202
+ }
203
+ catch {
204
+ // The status is for the progress line; the pass goes on without it.
205
+ }
133
206
  }
134
207
  onEnd() {
135
208
  if (!this.pass)
136
209
  return;
137
- // A killed mutant fails its test, and that is the point: the
138
- // command's outcome is the pass's, not the tests'. The verdicts are
139
- // the judge's, once every invocation has ended.
210
+ clearInterval(this.timer);
211
+ this.running.clear();
212
+ this.writeStatus(true);
213
+ // A killed mutant fails a test, and that is the point: the command's
214
+ // outcome is the pass's, not the tests'. The verdicts are the
215
+ // judge's, once every invocation has ended.
140
216
  return { status: "passed" };
141
217
  }
142
218
  /**
143
- * The pass's verdicts, from what its invocations left on disk: each
144
- * repetition's attempt (the fixture's) and outcome (the reporter's), the
145
- * baselines, and the errors outside any test.
219
+ * The round's verdicts left, from what its invocations left on disk:
220
+ * each attempt, the baselines, the kills not yet confirmed, and the
221
+ * errors outside any test; and the rounds to run next.
146
222
  */
147
223
  finish() {
148
224
  const { pass } = this;
149
- const rows = (this.rows = loadRows(pass));
150
- const kind = rows.kind;
151
- const attempts = readAll(`${pass.round}/attempts`);
152
- const byOriginal = new Map(attempts.map((attempt) => [`${attempt.original}\0${attempt.index}`, attempt]));
153
- const outcomeFile = (attempt) => {
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);
225
+ const work = (this.work = loadPass(pass));
226
+ const kind = work.kind;
227
+ const round = pass.round;
228
+ const attempts = readAll(`${round}/attempts`);
229
+ const errors = readAll(`${round}/errors`).sort((a, b) => a.at - b.at);
162
230
  const globalError = errors[0];
163
- const started = Math.min(statSync(`${pass.round}/rows.json`).mtimeMs, ...attempts.map((attempt) => attempt.startedAt));
231
+ const started = Math.min(statSync(`${round}/pass.json`).mtimeMs, ...attempts.map((attempt) => attempt.startedAt));
164
232
  const write = (record) => appendFileSync(pass.resultsPath, `${JSON.stringify(record)}\n`);
165
- for (const record of rows.immediate)
166
- write(record);
167
- // Where a mutant ran past its hit limit, by attempt; and in a process
168
- // that had it on everywhere, by mutant alone.
233
+ let decided = 0;
234
+ for (const record of work.immediate) {
235
+ if (giveVerdict(pass, record))
236
+ decided += 1;
237
+ }
238
+ // Where a mutant ran past its hit limit in a server, by attempt; and
239
+ // in a process that had it on everywhere, by mutant alone.
169
240
  const timedOut = new Set();
170
241
  const timedOutAnywhere = new Set();
171
242
  for (const line of readLines(`${pass.resultsPath}.timeouts.jsonl`)) {
@@ -176,251 +247,209 @@ export default class SupercovPlaywrightStrongReporter {
176
247
  else
177
248
  timedOutAnywhere.add(line.mutant);
178
249
  }
179
- const baselineFailed = new Set();
180
- if (!rows.job) {
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 = [];
250
+ const byMutant = new Map();
251
+ const controls = { ran: 0, failed: [] };
194
252
  for (const attempt of attempts) {
195
- if (attempt.mutant !== "-")
196
- mutated.push({ ...attempt, repetition: attempt.testId, endedAt: attempt.endedAt ?? Date.now() });
197
- }
198
- const beside = (repetition, attempt) => mutated.some((other) => other.repetition !== repetition &&
199
- other.mutant !== attempt.mutant &&
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);
253
+ if (attempt.kind !== "mutant") {
254
+ if (attempt.kind === "control" && attempt.endedAt !== undefined) {
255
+ controls.ran += 1;
256
+ if (attempt.outcome === "failed" || attempt.outcome === "timed-out")
257
+ controls.failed.push(attempt.original);
248
258
  }
249
- });
259
+ continue;
260
+ }
261
+ if (!byMutant.has(attempt.id))
262
+ byMutant.set(attempt.id, []);
263
+ byMutant.get(attempt.id).push(attempt);
250
264
  }
251
- // What runs next: one mutant alone (with the server started with
252
- // it, where a server ran its code outside any request), a further
253
- // pass of survivors' other candidates, and a serial pass, one test
254
- // at a time, for kills to confirm, timeouts' second tries and what
255
- // did not finish.
265
+ // What runs next: one mutant alone (with the server started with it,
266
+ // where a server ran its code outside any request), and one test at
267
+ // a time for kills to confirm and timeouts' second tries; the rest of
268
+ // what did not finish, as this round ran it.
256
269
  const alone = [];
257
- const stage = [];
258
270
  const serial = [];
259
- const next = (entry, reason, tests, budgetFactor = 1, later = []) => {
260
- const runnable = tests.filter((test) => !baselineFailed.has(test));
261
- const rest = later.filter((test) => !baselineFailed.has(test));
262
- if (!runnable.length && !rest.length) {
271
+ const rest = [];
272
+ const aloneAgain = [];
273
+ const aloneEach = [];
274
+ const next = (entry, reason, tests) => {
275
+ const runnable = tests.filter((test) => baselineOf(pass, test) !== "failed");
276
+ if (!runnable.length) {
263
277
  write({ id: entry.id, status: "error", reason: "its candidate tests fail without any mutant", tests: 0, durationMs: 0 });
264
278
  return;
265
279
  }
266
- const job = runnable.length
267
- ? { id: entry.id, mutant: entry.mutant, tests: runnable, rest, reason, budgetFactor }
268
- : { id: entry.id, mutant: entry.mutant, tests: rest, rest: [], reason, budgetFactor };
269
- if (EVERYWHERE.includes(reason) || reason === "canary")
280
+ const job = { id: entry.id, mutant: entry.mutant, tests: runnable, reason };
281
+ // What an alone round left runs alone again, as it was.
282
+ if (kind === "alone")
283
+ aloneEach.push({ ...job, reason: entry.reason });
284
+ else if (EVERYWHERE.includes(reason))
270
285
  alone.push(job);
271
- else if (reason === "stage")
272
- stage.push(job);
286
+ else if (reason === "unfinished")
287
+ rest.push(job);
273
288
  else
274
289
  serial.push(job);
275
290
  };
276
- const failedCanaries = canaries.filter((canary) => ["failed", "timed-out", "hit-limit"].includes(canary.kind));
277
- const doubtUntil = failedCanaries.length
278
- ? Math.max(...failedCanaries.map((canary) => canary.endedAt))
279
- : -Infinity;
280
- // After an error outside any test (the shared server exited), what
281
- // ended later may be its doing.
282
- const trustedUntil = globalError ? globalError.at - ERROR_MARGIN_MS : Infinity;
283
- this.globalError = globalError;
284
- let decided = 0;
285
- let confirming = 0;
286
- for (const [id, entry] of Object.entries(rows.entries)) {
287
- const own = outcomes.get(id) ?? [];
288
- const ran = own.filter((outcome) => outcome.startedAt !== undefined);
289
- const all = [...entry.tests, ...(entry.rest ?? [])];
290
- if (kind === "main" && ran.some((outcome) => outcome.startedAt <= doubtUntil)) {
291
- next(entry, "canary", all);
291
+ const trustedUntil = globalError ? globalError.at : Infinity;
292
+ // One mutant an invocation: which invocation took each, and where a
293
+ // server of that invocation ran it (an invocation whose server was
294
+ // started before it, outside it, never ran its mutant there).
295
+ const claimedBy = new Map();
296
+ for (const name of entries(`${round}/invocations`)) {
297
+ const taken = readJsonOr(`${round}/invocations/${name}`);
298
+ if (taken?.id)
299
+ claimedBy.set(taken.id, name.replace(/\.json$/, ""));
300
+ }
301
+ const ranInServer = new Set(readLines(`${pass.resultsPath}.everywhere.jsonl`).map((line) => `${line.invocation}\0${line.mutant}`));
302
+ for (const [id, entry] of Object.entries(work.entries)) {
303
+ if (existsSync(`${pass.shared}/verdicts/${key(id)}`)) {
304
+ decided += 1;
292
305
  continue;
293
306
  }
294
- const verdict = this.verdict(rows, entry, own, all, trustedUntil, next);
295
- if (verdict === "confirm")
296
- confirming += 1;
297
- if (!verdict || verdict === "confirm")
307
+ const invocation = claimedBy.get(id);
308
+ if (work.batch && invocation === undefined) {
309
+ aloneAgain.push(entry);
298
310
  continue;
299
- decided += 1;
300
- const durationMs = ran.length
301
- ? Math.max(...ran.map((outcome) => outcome.endedAt)) - Math.min(...ran.map((outcome) => outcome.startedAt))
311
+ }
312
+ const own = byMutant.get(id) ?? [];
313
+ const ended = own.filter((attempt) => attempt.endedAt !== undefined);
314
+ const ranAway = own.find((attempt) => timedOut.has(attempt.attemptId) || timedOutAnywhere.has(entry.mutant));
315
+ // Kills, and attempts that ran out of their time limit.
316
+ const failed = ended.filter((attempt) => attempt.outcome === "failed" || attempt.outcome === "timed-out");
317
+ const after = reasonOf(kind, entry.reason);
318
+ const suffix = after ? `; ${after}` : "";
319
+ const durationMs = ended.length
320
+ ? Math.max(...ended.map((attempt) => attempt.endedAt)) - Math.min(...ended.map((attempt) => attempt.startedAt))
302
321
  : 0;
303
- write({ id, ...verdict, tests: ran.length, durationMs });
322
+ const verdict = (record) => {
323
+ if (giveVerdict(pass, { id, ...record, tests: ended.length, durationMs }))
324
+ decided += 1;
325
+ };
326
+ // A kill beside another mutant's attempt, or whose control failed
327
+ // without the mutant: its killing test first, alone, then the rest.
328
+ const doubted = existsSync(`${round}/confirm/${key(id)}`) ? "confirm" : existsSync(`${round}/doubt/${key(id)}`) ? "doubt" : undefined;
329
+ if (doubted && failed.length) {
330
+ const first = failed[0].original;
331
+ next(entry, doubted, [first, ...entry.tests.filter((test) => test !== first)]);
332
+ continue;
333
+ }
334
+ // A kill no control came after (the round ended first): as sure as a
335
+ // kill on a server no other mutant's attempt shared.
336
+ const killer = failed.find((attempt) => !attempt.beside && attempt.endedAt < trustedUntil);
337
+ if (killer) {
338
+ const { status, reason } = verdictOf(killer);
339
+ verdict({ status, killedBy: killer.original, reason: `${reason}${suffix}` });
340
+ continue;
341
+ }
342
+ if (ranAway) {
343
+ verdict({ status: "timeout", killedBy: ranAway.original, reason: `evaluated past its hit limit${suffix}` });
344
+ continue;
345
+ }
346
+ // Alone, the command failed outside any test: the mutant broke the
347
+ // app (a server that would not start with it).
348
+ // (Where one invocation of several failed so, it runs alone with
349
+ // the whole command started with it, which says whether it was the
350
+ // mutant's doing.)
351
+ if (kind === "alone" && !work.batch && globalError && !ended.length) {
352
+ verdict({ status: "killed", reason: `the command failed with it switched on (${globalError.message})${suffix}` });
353
+ continue;
354
+ }
355
+ // Its invocation's server never ran it: alone, the whole command
356
+ // started with it.
357
+ if (work.batch && !ranInServer.has(`${invocation}\0${entry.mutant}`)) {
358
+ aloneEach.push(entry);
359
+ continue;
360
+ }
361
+ const passed = new Set(ended.filter((attempt) => attempt.outcome === "passed" && attempt.endedAt < trustedUntil).map((attempt) => attempt.original));
362
+ const runnable = entry.tests.filter((test) => baselineOf(pass, test) !== "failed");
363
+ const left = runnable.filter((test) => !passed.has(test));
364
+ if (!runnable.length) {
365
+ verdict({ status: "error", reason: "its candidate tests fail without any mutant" });
366
+ continue;
367
+ }
368
+ if (left.length) {
369
+ next(entry, "unfinished", left);
370
+ continue;
371
+ }
372
+ const others = work.otherRunners[id];
373
+ verdict(others
374
+ ? { status: "error", reason: `no Playwright test killed it, and its other candidates ran under ${others.join(", ")}, which this pass does not run` }
375
+ : { status: "survived", ...(after ? { reason: after } : {}) });
304
376
  }
305
- for (const job of rows.restarts)
377
+ for (const job of work.restarts)
306
378
  next(job, job.reason, job.tests);
307
- // A serial pass that decided nothing would only ask for its
308
- // unfinished mutants again.
309
- if (kind === "serial" && !decided) {
310
- for (const job of serial.filter((job) => job.reason === "unfinished"))
311
- write({ id: job.id, status: "error", reason: "its tests did not finish, run one at a time", tests: 0, durationMs: 0 });
312
- serial.splice(0, serial.length, ...serial.filter((job) => job.reason !== "unfinished"));
379
+ // A round of what an earlier one left that ran to its end and decided
380
+ // nothing would only ask for the same again. One the budget or a
381
+ // signal stopped leaves its mutants without a verdict, for the next
382
+ // pass (a confirmation round stopped before its first test made two
383
+ // mutants of a 60 s pass `error`s).
384
+ const stopped = process.env["SUPERCOV_STRONG_STOPPED"] === "1";
385
+ if (kind !== "main" && !decided && !stopped) {
386
+ for (const job of rest)
387
+ write({ id: job.id, status: "error", reason: "its tests did not finish, in two rounds", tests: 0, durationMs: 0 });
388
+ rest.splice(0, rest.length);
389
+ }
390
+ // A mutant run alone with the whole command started with it, whose
391
+ // tests did not finish: there is no way left to run it.
392
+ if (kind === "alone" && !work.batch && !stopped) {
393
+ for (const job of aloneEach)
394
+ write({ id: job.id, status: "error", reason: "its tests did not finish, run alone", tests: 0, durationMs: 0 });
395
+ aloneEach.splice(0, aloneEach.length);
313
396
  }
314
397
  // What this invocation had no room for runs in the next, as this
315
398
  // one would have run it.
316
- if (rows.deferred.length) {
317
- write({ restart: rows.job
318
- ? { ...rows.job, mutants: rows.deferred }
319
- : { kind: "main", reason: "more rows than one invocation holds", mutants: rows.deferred } });
320
- }
321
- for (const job of alone)
322
- write({ restart: { kind: "alone", everywhere: EVERYWHERE.includes(job.reason), reason: job.reason, mutants: [job], otherRunners: rows.otherRunners } });
323
- if (stage.length)
324
- write({ restart: { kind: "stage", reason: "stage", mutants: stage, otherRunners: rows.otherRunners } });
399
+ if (work.deferred.length)
400
+ write({ restart: { kind: "main", reason: "more copies than one invocation holds", mutants: work.deferred } });
401
+ // The mutants a server must start with: one round of them, each
402
+ // invocation of the command taking one; those no invocation took
403
+ // again so, unless none took any; and each one its server did not run
404
+ // (or every one, where no invocation took one) alone with the whole
405
+ // command started with it.
406
+ const takenAny = claimedBy.size > 0;
407
+ for (const entry of aloneAgain)
408
+ (takenAny ? alone : aloneEach).push(entry);
409
+ if (alone.length)
410
+ write({ restart: { kind: "alone", everywhere: true, batch: true, reason: "server-wide", mutants: alone, otherRunners: work.otherRunners } });
411
+ for (const job of aloneEach)
412
+ write({ restart: { kind: "alone", everywhere: true, reason: job.reason, mutants: [job], otherRunners: work.otherRunners } });
413
+ if (rest.length)
414
+ write({ restart: { kind: "rest", reason: "unfinished", mutants: rest, otherRunners: work.otherRunners } });
325
415
  if (serial.length)
326
- write({ restart: { kind: "serial", reason: [...new Set(serial.map((job) => job.reason))].join(", "), mutants: serial, otherRunners: rows.otherRunners } });
416
+ write({ restart: { kind: "serial", reason: [...new Set(serial.map((job) => job.reason))].join(", "), mutants: serial, otherRunners: work.otherRunners } });
417
+ const mutated = attempts.filter((attempt) => attempt.kind === "mutant");
327
418
  write({
328
419
  summary: true,
329
420
  runner: "playwright",
330
421
  pass: pass.name,
331
422
  kind,
332
- ...(rows.concurrency.workers ? { workers: rows.concurrency.workers } : {}),
333
- serialFiles: rows.concurrency.serialFiles.length,
423
+ ...(work.concurrency.workers ? { workers: work.concurrency.workers } : {}),
424
+ serialFiles: work.concurrency.serialFiles.length,
334
425
  ...(globalError ? { error: globalError.message } : {}),
335
426
  invocations: new Set(attempts.map((attempt) => attempt.invocation)).size,
427
+ workerProcesses: new Set(attempts.map((attempt) => attempt.worker)).size,
336
428
  durationMs: Date.now() - started,
429
+ attempts: mutated.length,
430
+ timedOut: mutated.filter((attempt) => attempt.outcome === "timed-out").length,
431
+ timeoutFactor: work.timeoutFactor,
432
+ baselines: attempts.filter((attempt) => attempt.kind === "baseline").length,
337
433
  decided,
338
- confirming,
339
- next: { alone: alone.length, stage: stage.length, serial: serial.length },
340
- canaries: {
341
- ran: canaries.filter((canary) => canary.startedAt !== undefined).length,
342
- failed: failedCanaries.map((canary) => canary.test),
343
- },
434
+ next: { alone: alone.length, rest: rest.length, serial: serial.length },
435
+ controls,
344
436
  });
345
437
  }
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
438
  }
413
439
 
414
- /** An error's message, on one line, short enough to keep. */
415
- function firstWords(message) {
416
- const text = stripAnsi(message ?? "").replace(/\s+/g, " ").trim();
417
- return text.length > 300 ? `${text.slice(0, 299)}…` : text;
440
+ /** A round as its first line says it. */
441
+ function describeRound(work) {
442
+ if (work.kind === "main")
443
+ return work.job ? "the main round's rest" : "main round";
444
+ if (work.kind === "alone")
445
+ return `alone (${EVERYWHERE.includes(work.job?.reason) ? "the server started with the mutant" : work.job?.reason})`;
446
+ return `${work.kind} round (${work.job?.reason})`;
418
447
  }
419
448
 
420
- /** Decides the pass's verdicts: run by the engine once the command has ended. */
449
+ /** Decides the round's verdicts: run by the engine once the command has ended. */
421
450
  export function judge() {
422
451
  const reporter = new SupercovPlaywrightStrongReporter();
423
- if (!reporter.pass || !existsSync(`${reporter.pass.round}/rows.json`))
452
+ if (!reporter.pass || !existsSync(`${reporter.pass.round}/pass.json`))
424
453
  return;
425
454
  reporter.finish();
426
455
  }