@hughescr/stryker-bun-runner 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -13
- package/dist/index.d.ts +137 -20
- package/dist/index.js +1051 -142
- package/dist/templates/coverage-preload.js +483 -0
- package/package.json +4 -2
- package/dist/coverage/preload-logic.js +0 -255
- package/dist/templates/coverage-preload.ts +0 -440
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { PluginKind, declareClassPlugin } from "@stryker-mutator/api/plugin";
|
|
|
5
5
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
6
6
|
import * as fsPromises2 from "node:fs/promises";
|
|
7
7
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8
|
-
import
|
|
8
|
+
import path9 from "node:path";
|
|
9
9
|
import { tokens, commonTokens } from "@stryker-mutator/api/plugin";
|
|
10
10
|
import {
|
|
11
11
|
DryRunStatus,
|
|
@@ -23,6 +23,7 @@ import { glob } from "tinyglobby";
|
|
|
23
23
|
|
|
24
24
|
// src/utils/private-temp-dir.ts
|
|
25
25
|
import { createHash } from "node:crypto";
|
|
26
|
+
import { lstatSync, readdirSync, readFileSync, readlinkSync, realpathSync, rmSync, utimesSync } from "node:fs";
|
|
26
27
|
import { lstat, mkdir, realpath, rm, writeFile } from "node:fs/promises";
|
|
27
28
|
import { tmpdir } from "node:os";
|
|
28
29
|
import path from "node:path";
|
|
@@ -33,6 +34,28 @@ class UnsafeTempDirError extends Error {
|
|
|
33
34
|
this.name = "UnsafeTempDirError";
|
|
34
35
|
}
|
|
35
36
|
}
|
|
37
|
+
function readLinuxPidSpaceIds() {
|
|
38
|
+
const bootId = readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
|
|
39
|
+
return `${bootId}:${readlinkSync("/proc/self/ns/pid")}`;
|
|
40
|
+
}
|
|
41
|
+
function computePidSpace(platform = process.platform, readIds = readLinuxPidSpaceIds) {
|
|
42
|
+
if (platform !== "linux") {
|
|
43
|
+
return { tag: tagOf(""), known: true };
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
return { tag: tagOf(readIds()), known: true };
|
|
47
|
+
} catch {
|
|
48
|
+
return { tag: tagOf("stryker-bun-runner: unknown Linux pid space"), known: false };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function tagOf(ids) {
|
|
52
|
+
return createHash("sha256").update(ids).digest("hex").slice(0, 8);
|
|
53
|
+
}
|
|
54
|
+
var currentPidSpace;
|
|
55
|
+
function pidSpace() {
|
|
56
|
+
currentPidSpace ??= computePidSpace();
|
|
57
|
+
return currentPidSpace;
|
|
58
|
+
}
|
|
36
59
|
var RUN_TEMP_DIR_SLOTS = 16;
|
|
37
60
|
function currentUid() {
|
|
38
61
|
const uid = process.getuid?.();
|
|
@@ -45,7 +68,8 @@ function runTempDirPrefix(key = {}) {
|
|
|
45
68
|
const cwd = key.cwd ?? process.cwd();
|
|
46
69
|
const ppid = key.ppid ?? process.ppid;
|
|
47
70
|
const hash = createHash("sha256").update(`${cwd}:${ppid}`).digest("hex").slice(0, 16);
|
|
48
|
-
|
|
71
|
+
const space = key.pidSpace ?? pidSpace().tag;
|
|
72
|
+
return path.join(key.baseDir ?? tmpdir(), `stryker-bun-runner-${key.uid ?? currentUid()}-${space}-${ppid}-${hash}`);
|
|
49
73
|
}
|
|
50
74
|
function octal(mode) {
|
|
51
75
|
return (mode & 4095).toString(8).padStart(4, "0");
|
|
@@ -143,6 +167,107 @@ async function writePrivateFile(file, data) {
|
|
|
143
167
|
await rm(file, { force: true });
|
|
144
168
|
await writeFile(file, data, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
145
169
|
}
|
|
170
|
+
var RUN_DIR_NAME_RE = /^stryker-bun-runner-(0|[1-9]\d*)-([0-9a-f]{8})-([1-9]\d*)-[0-9a-f]{16}-(?:0|[1-9]\d*)$/;
|
|
171
|
+
var STALE_RUN_DIR_AGE_MS = 60 * 60 * 1000;
|
|
172
|
+
var RUN_DIR_TOUCH_INTERVAL_MS = 10 * 60 * 1000;
|
|
173
|
+
var MAX_RUN_DIRS_EXAMINED = 1000;
|
|
174
|
+
function touchRunTempDir(dir, now = Date.now()) {
|
|
175
|
+
try {
|
|
176
|
+
utimesSync(dir, now / 1000, now / 1000);
|
|
177
|
+
} catch {}
|
|
178
|
+
}
|
|
179
|
+
function processExists(pid) {
|
|
180
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
process.kill(pid, 0);
|
|
185
|
+
return true;
|
|
186
|
+
} catch (err) {
|
|
187
|
+
return err.code !== "ESRCH";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function ancestorsSafe(top, uid, lstatFn) {
|
|
191
|
+
for (let component = top;; component = path.dirname(component)) {
|
|
192
|
+
if (ancestorProblem(lstatFn(component), uid) !== undefined) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
if (component === path.dirname(component)) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function listSafeBaseDir(baseDir, uid, lstatFn, readdirFn = listDir) {
|
|
201
|
+
try {
|
|
202
|
+
const base = realpathSync(baseDir ?? tmpdir());
|
|
203
|
+
return ancestorsSafe(base, uid, lstatFn) ? { base, names: readdirFn(base) } : undefined;
|
|
204
|
+
} catch {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function runDirOwner(name, uid, space) {
|
|
209
|
+
const match = RUN_DIR_NAME_RE.exec(name);
|
|
210
|
+
return match !== null && Number(match[1]) === uid && match[2] === space ? Number(match[3]) : undefined;
|
|
211
|
+
}
|
|
212
|
+
function listDir(dir) {
|
|
213
|
+
return readdirSync(dir);
|
|
214
|
+
}
|
|
215
|
+
function removeTree(dir) {
|
|
216
|
+
rmSync(dir, { recursive: true });
|
|
217
|
+
}
|
|
218
|
+
function runIsOver({ dir, owner }, judge) {
|
|
219
|
+
const st = judge.lstatFn(dir);
|
|
220
|
+
if (dirProblem(st, judge.uid) !== undefined) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
if (owner === judge.exitingPid) {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
return judge.now - st.mtimeMs >= judge.minAgeMs && !judge.isAlive(owner);
|
|
227
|
+
}
|
|
228
|
+
function removeFinishedRunTempDirs(options = {}) {
|
|
229
|
+
const uid = options.uid ?? process.getuid?.();
|
|
230
|
+
const space = options.pidSpace ?? pidSpace();
|
|
231
|
+
const lstatFn = options.lstat ?? lstatSync;
|
|
232
|
+
const listing = uid === undefined || !space.known ? undefined : listSafeBaseDir(options.baseDir, uid, lstatFn, options.readdir);
|
|
233
|
+
if (uid === undefined || listing === undefined) {
|
|
234
|
+
return [];
|
|
235
|
+
}
|
|
236
|
+
const { exitingPid } = options;
|
|
237
|
+
const candidates = listing.names.map((name) => ({ dir: path.join(listing.base, name), owner: runDirOwner(name, uid, space.tag) })).filter((candidate) => candidate.owner !== undefined).toSorted((a, b) => Number(b.owner === exitingPid) - Number(a.owner === exitingPid)).slice(0, options.maxExamined ?? MAX_RUN_DIRS_EXAMINED);
|
|
238
|
+
const judge = {
|
|
239
|
+
uid,
|
|
240
|
+
lstatFn,
|
|
241
|
+
exitingPid,
|
|
242
|
+
isAlive: options.isAlive ?? processExists,
|
|
243
|
+
minAgeMs: options.minAgeMs ?? STALE_RUN_DIR_AGE_MS,
|
|
244
|
+
now: options.now ?? Date.now()
|
|
245
|
+
};
|
|
246
|
+
const remove = options.remove ?? removeTree;
|
|
247
|
+
return candidates.filter((candidate) => {
|
|
248
|
+
try {
|
|
249
|
+
if (!runIsOver(candidate, judge)) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
remove(candidate.dir);
|
|
253
|
+
return true;
|
|
254
|
+
} catch {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
}).map((candidate) => candidate.dir);
|
|
258
|
+
}
|
|
259
|
+
var exitCleanupRegistered = new WeakSet;
|
|
260
|
+
function removeRunTempDirsOnExit(proc = process) {
|
|
261
|
+
if (exitCleanupRegistered.has(proc)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
exitCleanupRegistered.add(proc);
|
|
265
|
+
proc.once("exit", () => {
|
|
266
|
+
try {
|
|
267
|
+
removeFinishedRunTempDirs({ exitingPid: process.pid });
|
|
268
|
+
} catch {}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
146
271
|
|
|
147
272
|
// src/utils/test-name-pattern.ts
|
|
148
273
|
var MAX_TEST_NAME_PATTERN_LENGTH = 1e5;
|
|
@@ -213,23 +338,45 @@ async function resolveEagerModulesFromGlobs(mutateGlobs, cwd = process.cwd()) {
|
|
|
213
338
|
resolved.sort((a, b) => a.localeCompare(b));
|
|
214
339
|
return resolved;
|
|
215
340
|
}
|
|
216
|
-
|
|
217
|
-
const
|
|
341
|
+
function resolvePreloadTemplate(moduleDir) {
|
|
342
|
+
const isBundled = moduleDir.endsWith("dist") || moduleDir.includes("dist/");
|
|
343
|
+
if (isBundled) {
|
|
344
|
+
return {
|
|
345
|
+
templatePath: path2.join(moduleDir, "templates/coverage-preload.js"),
|
|
346
|
+
preloadLogicPath: undefined,
|
|
347
|
+
extension: "js"
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
templatePath: path2.join(moduleDir, "../templates/coverage-preload.ts"),
|
|
352
|
+
preloadLogicPath: path2.join(moduleDir, "preload-logic.ts"),
|
|
353
|
+
extension: "ts"
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
async function generatePreloadScript(options, moduleDir = path2.dirname(fileURLToPath(import.meta.url))) {
|
|
218
357
|
await ensurePrivateDir(options.tempDir);
|
|
219
|
-
const
|
|
220
|
-
const
|
|
221
|
-
const templatePath = isBundled ? path2.join(__dirname2, "templates/coverage-preload.ts") : path2.join(__dirname2, "../templates/coverage-preload.ts");
|
|
358
|
+
const { templatePath, preloadLogicPath, extension } = resolvePreloadTemplate(moduleDir);
|
|
359
|
+
const preloadPath = path2.join(options.tempDir, `stryker-coverage-preload-${process.pid}.${extension}`);
|
|
222
360
|
const template = await readFile(templatePath, "utf8");
|
|
223
|
-
const preloadLogicPath = isBundled ? path2.join(__dirname2, "coverage/preload-logic.js") : path2.join(__dirname2, "preload-logic.ts");
|
|
224
361
|
const eagerModules = options.eagerModules ?? [];
|
|
225
|
-
const
|
|
362
|
+
const eagerModulesFile = eagerModules.length > 0 ? eagerModulesFileFor(preloadPath) : null;
|
|
363
|
+
const withLogic = preloadLogicPath === undefined ? template : template.replace("__PRELOAD_LOGIC_PATH__", () => preloadLogicPath);
|
|
364
|
+
const content = withLogic.replace("__EAGER_MODULES_FILE__", () => JSON.stringify(eagerModulesFile));
|
|
226
365
|
await writePrivateFile(preloadPath, content);
|
|
366
|
+
if (eagerModulesFile !== null) {
|
|
367
|
+
await writePrivateFile(eagerModulesFile, JSON.stringify(eagerModules));
|
|
368
|
+
}
|
|
227
369
|
return preloadPath;
|
|
228
370
|
}
|
|
371
|
+
function eagerModulesFileFor(preloadPath) {
|
|
372
|
+
return `${preloadPath.replace(/\.[jt]s$/, "")}.eager-modules.json`;
|
|
373
|
+
}
|
|
229
374
|
async function cleanupPreloadScript(preloadPath) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
375
|
+
for (const file of [preloadPath, eagerModulesFileFor(preloadPath)]) {
|
|
376
|
+
try {
|
|
377
|
+
await unlink(file);
|
|
378
|
+
} catch {}
|
|
379
|
+
}
|
|
233
380
|
}
|
|
234
381
|
// src/coverage/collector.ts
|
|
235
382
|
import { readFile as readFile2, unlink as unlink2 } from "node:fs/promises";
|
|
@@ -238,7 +385,24 @@ function addHitCounts(into, from) {
|
|
|
238
385
|
into[mutantId] = (into[mutantId] ?? 0) + count;
|
|
239
386
|
}
|
|
240
387
|
}
|
|
388
|
+
function isRecordObject(value) {
|
|
389
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
390
|
+
}
|
|
391
|
+
function isWellFormedLine(data) {
|
|
392
|
+
if (!isRecordObject(data.perTest) || !isRecordObject(data.static)) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
for (const counts of Object.values(data.perTest)) {
|
|
396
|
+
if (!isRecordObject(counts)) {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
241
402
|
function mergeCoverageData(dataList) {
|
|
403
|
+
if (dataList.length === 1 && isWellFormedLine(dataList[0])) {
|
|
404
|
+
return { perTest: dataList[0].perTest, static: dataList[0].static };
|
|
405
|
+
}
|
|
242
406
|
const merged = { perTest: {}, static: {} };
|
|
243
407
|
for (const data of dataList) {
|
|
244
408
|
for (const [testId, counts] of Object.entries(data.perTest)) {
|
|
@@ -249,6 +413,20 @@ function mergeCoverageData(dataList) {
|
|
|
249
413
|
}
|
|
250
414
|
return merged;
|
|
251
415
|
}
|
|
416
|
+
var readsInFlight = new Map;
|
|
417
|
+
async function readCoverageFileDataShared(coverageFile, logger) {
|
|
418
|
+
const inFlight = readsInFlight.get(coverageFile);
|
|
419
|
+
if (inFlight) {
|
|
420
|
+
return inFlight;
|
|
421
|
+
}
|
|
422
|
+
const read = readCoverageFileData(coverageFile, logger);
|
|
423
|
+
readsInFlight.set(coverageFile, read);
|
|
424
|
+
try {
|
|
425
|
+
return await read;
|
|
426
|
+
} finally {
|
|
427
|
+
readsInFlight.delete(coverageFile);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
252
430
|
async function readCoverageFileData(coverageFile, logger) {
|
|
253
431
|
try {
|
|
254
432
|
const content = await readFile2(coverageFile, "utf8");
|
|
@@ -272,7 +450,7 @@ async function readCoverageFileData(coverageFile, logger) {
|
|
|
272
450
|
}
|
|
273
451
|
async function collectCoverage(coverageFile, logger) {
|
|
274
452
|
try {
|
|
275
|
-
const dataList = await
|
|
453
|
+
const dataList = await readCoverageFileDataShared(coverageFile, logger);
|
|
276
454
|
if (dataList.length === 0) {
|
|
277
455
|
return;
|
|
278
456
|
}
|
|
@@ -282,7 +460,7 @@ async function collectCoverage(coverageFile, logger) {
|
|
|
282
460
|
}
|
|
283
461
|
}
|
|
284
462
|
async function collectLateHits(coverageFile, logger) {
|
|
285
|
-
const dataList = await
|
|
463
|
+
const dataList = await readCoverageFileDataShared(coverageFile, logger);
|
|
286
464
|
return dataList.flatMap((data) => data.lateHits ?? []);
|
|
287
465
|
}
|
|
288
466
|
async function cleanupCoverageFile(coverageFile) {
|
|
@@ -503,27 +681,80 @@ function resolveEachTestName(baseName, inspectorId, nameInspectorIds, duplicateN
|
|
|
503
681
|
const index = duplicateNameIndex.get(key_) ?? 0;
|
|
504
682
|
return `${baseName} [${index}]`;
|
|
505
683
|
}
|
|
506
|
-
function
|
|
684
|
+
function buildMappedCoverage(counterIds, resolved, rawCoverage, testHierarchy) {
|
|
507
685
|
const nameInspectorIds = buildNameInspectorIds(resolved);
|
|
508
686
|
const duplicateNameIndex = buildDuplicateNameIndex(nameInspectorIds, testHierarchy);
|
|
509
|
-
const
|
|
687
|
+
const staticCounts = { ...rawCoverage.static };
|
|
688
|
+
const staticIds = new Set(Object.keys(staticCounts));
|
|
689
|
+
const creditedByName = new Map;
|
|
690
|
+
const orphaned = [];
|
|
510
691
|
for (const [i, key] of counterIds.entries()) {
|
|
692
|
+
const incoming = rawCoverage.perTest[key] ?? {};
|
|
511
693
|
const { name: baseName, testInfo, inspectorId } = resolved[i];
|
|
512
694
|
if (!testInfo) {
|
|
695
|
+
orphaned.push(incoming);
|
|
513
696
|
continue;
|
|
514
697
|
}
|
|
515
698
|
const finalName = resolveEachTestName(baseName, inspectorId, nameInspectorIds, duplicateNameIndex);
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
699
|
+
const credited = creditedByName.get(finalName);
|
|
700
|
+
if (!credited && !holdsAny(incoming, staticIds)) {
|
|
701
|
+
creditedByName.set(finalName, incoming);
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
const writable = { ...credited };
|
|
705
|
+
creditedByName.set(finalName, writable);
|
|
706
|
+
creditHits(incoming, writable, staticIds, staticCounts);
|
|
707
|
+
}
|
|
708
|
+
const perTest = nonEmptyTests(creditedByName, orphaned.length > 0);
|
|
709
|
+
if (orphaned.length > 0) {
|
|
710
|
+
creditOrphanedHits(orphaned, staticCounts, perTest);
|
|
711
|
+
}
|
|
712
|
+
return { static: staticCounts, perTest };
|
|
713
|
+
}
|
|
714
|
+
function creditHits(incoming, credited, staticIds, staticCounts) {
|
|
715
|
+
for (const mutantId of Object.keys(incoming)) {
|
|
716
|
+
const hits = incoming[mutantId];
|
|
717
|
+
if (staticIds.has(mutantId)) {
|
|
718
|
+
staticCounts[mutantId] += hits;
|
|
522
719
|
} else {
|
|
523
|
-
|
|
720
|
+
credited[mutantId] = (credited[mutantId] ?? 0) + hits;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
function nonEmptyTests(creditedByName, copy) {
|
|
725
|
+
const perTest = {};
|
|
726
|
+
for (const [name, counts] of creditedByName) {
|
|
727
|
+
if (Object.keys(counts).length > 0) {
|
|
728
|
+
perTest[name] = copy ? { ...counts } : counts;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return perTest;
|
|
732
|
+
}
|
|
733
|
+
function holdsAny(counts, mutantIds) {
|
|
734
|
+
for (const mutantId of Object.keys(counts)) {
|
|
735
|
+
if (mutantIds.has(mutantId)) {
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
function creditOrphanedHits(orphaned, staticCounts, perTest) {
|
|
742
|
+
const firstHolder = new Map;
|
|
743
|
+
for (const counts of [staticCounts, ...Object.values(perTest)]) {
|
|
744
|
+
for (const mutantId of Object.keys(counts)) {
|
|
745
|
+
if (!firstHolder.has(mutantId)) {
|
|
746
|
+
firstHolder.set(mutantId, counts);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
for (const counts of orphaned) {
|
|
751
|
+
for (const mutantId of Object.keys(counts)) {
|
|
752
|
+
const holder = firstHolder.get(mutantId);
|
|
753
|
+
if (holder) {
|
|
754
|
+
holder[mutantId] += counts[mutantId];
|
|
755
|
+
}
|
|
524
756
|
}
|
|
525
757
|
}
|
|
526
|
-
return remappedPerTest;
|
|
527
758
|
}
|
|
528
759
|
function warnInteriorGapIfPresent(pairs, testHierarchy, logger) {
|
|
529
760
|
const warnedFiles = new Set;
|
|
@@ -578,7 +809,6 @@ function mapFilePrefixedCounterKeys(rawCoverage, executionOrder, testHierarchy,
|
|
|
578
809
|
}
|
|
579
810
|
const counterIds = globallyOrderedKeys.toSorted((a, b) => splitCounterKey(a).position - splitCounterKey(b).position);
|
|
580
811
|
const resolved = resolveCounterKeys(counterIds, fileToInspectorIds, testHierarchy, logger);
|
|
581
|
-
const remappedPerTest = buildRemappedPerTest(counterIds, resolved, rawCoverage.perTest, testHierarchy);
|
|
582
812
|
const counterKeyToTestName = new Map;
|
|
583
813
|
for (const [i, key] of counterIds.entries()) {
|
|
584
814
|
if (resolved[i].testInfo) {
|
|
@@ -586,10 +816,7 @@ function mapFilePrefixedCounterKeys(rawCoverage, executionOrder, testHierarchy,
|
|
|
586
816
|
}
|
|
587
817
|
}
|
|
588
818
|
const orphanedKeyCount = reportOrphanedKeys(resolved, counterIds, logger);
|
|
589
|
-
const coverage =
|
|
590
|
-
static: rawCoverage.static,
|
|
591
|
-
perTest: remappedPerTest
|
|
592
|
-
}));
|
|
819
|
+
const coverage = buildMappedCoverage(counterIds, resolved, rawCoverage, testHierarchy);
|
|
593
820
|
return {
|
|
594
821
|
coverage,
|
|
595
822
|
inspectorIdToProjectFile,
|
|
@@ -647,8 +874,29 @@ function mapLegacyCounterKeys(rawCoverage, executionOrder, testHierarchy, logger
|
|
|
647
874
|
};
|
|
648
875
|
}
|
|
649
876
|
// src/coverage/preload-logic.ts
|
|
650
|
-
import { appendFileSync, closeSync, constants,
|
|
877
|
+
import { appendFileSync, closeSync, constants, openSync, writeSync } from "node:fs";
|
|
651
878
|
var SYNC_TOKEN_ENV = "__STRYKER_SYNC_TOKEN__";
|
|
879
|
+
var PRELOAD_TIMINGS_ENV = "__STRYKER_PRELOAD_TIMINGS__";
|
|
880
|
+
var PRELOAD_TIMINGS_PREFIX = "[Stryker Timings] ";
|
|
881
|
+
function readPreloadTimings(stderr) {
|
|
882
|
+
const start = stderr.lastIndexOf(`
|
|
883
|
+
${PRELOAD_TIMINGS_PREFIX}`);
|
|
884
|
+
if (start === -1) {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
const jsonStart = start + 1 + PRELOAD_TIMINGS_PREFIX.length;
|
|
888
|
+
const end = stderr.indexOf(`
|
|
889
|
+
`, jsonStart);
|
|
890
|
+
try {
|
|
891
|
+
const parsed = JSON.parse(stderr.slice(jsonStart, end === -1 ? stderr.length : end));
|
|
892
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => typeof entry[1] === "number"));
|
|
896
|
+
} catch {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
652
900
|
var HIT_LIMIT_SENTINEL = "__STRYKER_HIT_LIMIT_REACHED__";
|
|
653
901
|
var COVERAGE_APPEND_FLAGS = constants.O_WRONLY | constants.O_APPEND | constants.O_CREAT | constants.O_NOFOLLOW;
|
|
654
902
|
var LIFELINE_FD_ENV = "__STRYKER_LIFELINE_FD__";
|
|
@@ -1178,7 +1426,7 @@ function shortestSpelling(absolute, cwd) {
|
|
|
1178
1426
|
const spelled = relative.startsWith(`..${path3.sep}`) ? relative : `.${path3.sep}${relative}`;
|
|
1179
1427
|
return spelled.length < absolute.length ? spelled : absolute;
|
|
1180
1428
|
}
|
|
1181
|
-
function
|
|
1429
|
+
function computeTestFileArgs(files, cwd, budget) {
|
|
1182
1430
|
const absolute = files.map((file) => path3.resolve(cwd, file));
|
|
1183
1431
|
const absoluteBytes = bytesOf(absolute);
|
|
1184
1432
|
if (absoluteBytes <= budget) {
|
|
@@ -1188,6 +1436,22 @@ function buildTestFileArgs(files, cwd = process.cwd(), budget = MAX_TEST_FILE_AR
|
|
|
1188
1436
|
const relativeBytes = bytesOf(relative);
|
|
1189
1437
|
return { args: relative, form: "relative", bytes: relativeBytes, fits: relativeBytes <= budget };
|
|
1190
1438
|
}
|
|
1439
|
+
function sameEntries(a, b) {
|
|
1440
|
+
return a.length === b.length && a.every((entry, index) => entry === b[index]);
|
|
1441
|
+
}
|
|
1442
|
+
var lastBuild;
|
|
1443
|
+
function buildTestFileArgs(files, cwd = process.cwd(), budget = MAX_TEST_FILE_ARGS_BYTES) {
|
|
1444
|
+
if (!path3.isAbsolute(cwd)) {
|
|
1445
|
+
return computeTestFileArgs(files, cwd, budget);
|
|
1446
|
+
}
|
|
1447
|
+
const cached = lastBuild;
|
|
1448
|
+
if (cached?.cwd === cwd && cached.budget === budget && sameEntries(cached.files, files)) {
|
|
1449
|
+
return { ...cached.result, args: [...cached.result.args] };
|
|
1450
|
+
}
|
|
1451
|
+
const result = computeTestFileArgs(files, cwd, budget);
|
|
1452
|
+
lastBuild = { files: [...files], cwd, budget, result: { ...result, args: [...result.args] } };
|
|
1453
|
+
return result;
|
|
1454
|
+
}
|
|
1191
1455
|
|
|
1192
1456
|
// src/process-runner.ts
|
|
1193
1457
|
var KILL_GRACE_PERIOD_MS = 500;
|
|
@@ -1195,6 +1459,7 @@ var STDIO_CLOSE_GRACE_MS = 4 * KILL_GRACE_PERIOD_MS;
|
|
|
1195
1459
|
var LIFELINE_FD = 3;
|
|
1196
1460
|
var SPAWN_DEPTH_ENV = "__STRYKER_BUN_RUNNER_DEPTH__";
|
|
1197
1461
|
var DEFAULT_MAX_SPAWN_DEPTH = 1;
|
|
1462
|
+
var PROFILE_ENV = "STRYKER_BUN_PROFILE";
|
|
1198
1463
|
function stripAnsi(text) {
|
|
1199
1464
|
return text.replaceAll(/\u001B\[[0-9;?]*[\u0020-\u002F]*[\u0040-\u007E]|\u001B\][^\u0007\u001B]*(?:\u0007|\u001B\\)/g, "");
|
|
1200
1465
|
}
|
|
@@ -1316,9 +1581,19 @@ function buildChildEnv(options, spawnDepth) {
|
|
|
1316
1581
|
}
|
|
1317
1582
|
}
|
|
1318
1583
|
env[SPAWN_DEPTH_ENV] = String(spawnDepth + 1);
|
|
1584
|
+
if (options.profile) {
|
|
1585
|
+
delete env[PROFILE_ENV];
|
|
1586
|
+
}
|
|
1587
|
+
if (options.profile && options.syncPort) {
|
|
1588
|
+
env[PRELOAD_TIMINGS_ENV] = "1";
|
|
1589
|
+
} else {
|
|
1590
|
+
delete env[PRELOAD_TIMINGS_ENV];
|
|
1591
|
+
}
|
|
1319
1592
|
return env;
|
|
1320
1593
|
}
|
|
1321
1594
|
async function spawnBunTests(options, spawnDepth) {
|
|
1595
|
+
const profile = options.profile;
|
|
1596
|
+
profile?.beginSpawn(options.bail === true, options.testFiles, options.testNamePattern);
|
|
1322
1597
|
const args = ["test"];
|
|
1323
1598
|
if (options.inspect) {
|
|
1324
1599
|
args.push("--inspect=127.0.0.1:0");
|
|
@@ -1370,6 +1645,7 @@ async function spawnBunTests(options, spawnDepth) {
|
|
|
1370
1645
|
detached: true
|
|
1371
1646
|
};
|
|
1372
1647
|
const childProcess = spawn2(options.bunPath, args, spawnOpts);
|
|
1648
|
+
profile?.mark("spawned");
|
|
1373
1649
|
liveChildren.add(childProcess);
|
|
1374
1650
|
ensureSignalCleanup();
|
|
1375
1651
|
const beginTermination = () => {
|
|
@@ -1429,6 +1705,7 @@ async function spawnBunTests(options, spawnDepth) {
|
|
|
1429
1705
|
if (childProcess.stderr) {
|
|
1430
1706
|
childProcess.stderr.on("data", (data) => {
|
|
1431
1707
|
stderrChunks.push(data);
|
|
1708
|
+
profile?.onStderr(data);
|
|
1432
1709
|
if (options.inspect && !inspectorUrlExtracted && options.onInspectorReady) {
|
|
1433
1710
|
const text = Buffer.concat(stderrChunks).toString();
|
|
1434
1711
|
const match = /Listening:[\t\v\f\r \u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*\n\s*(ws:\/\/\S+)/.exec(stripAnsi(text));
|
|
@@ -1451,6 +1728,7 @@ async function spawnBunTests(options, spawnDepth) {
|
|
|
1451
1728
|
}
|
|
1452
1729
|
};
|
|
1453
1730
|
childProcess.on("exit", (code, signal) => {
|
|
1731
|
+
profile?.mark("exit");
|
|
1454
1732
|
onLeaderExitDuringTermination?.();
|
|
1455
1733
|
stdioCloseHandle = setTimeout(() => {
|
|
1456
1734
|
release();
|
|
@@ -1466,6 +1744,7 @@ async function spawnBunTests(options, spawnDepth) {
|
|
|
1466
1744
|
}, STDIO_CLOSE_GRACE_MS);
|
|
1467
1745
|
});
|
|
1468
1746
|
childProcess.on("close", (code, signal) => {
|
|
1747
|
+
profile?.mark("close");
|
|
1469
1748
|
hasClosed = true;
|
|
1470
1749
|
onLeaderExitDuringTermination?.();
|
|
1471
1750
|
release();
|
|
@@ -1479,6 +1758,7 @@ async function spawnBunTests(options, spawnDepth) {
|
|
|
1479
1758
|
});
|
|
1480
1759
|
});
|
|
1481
1760
|
childProcess.on("error", (error) => {
|
|
1761
|
+
profile?.mark("close");
|
|
1482
1762
|
hasClosed = true;
|
|
1483
1763
|
onLeaderExitDuringTermination?.();
|
|
1484
1764
|
release();
|
|
@@ -1508,13 +1788,17 @@ function headerFilter(lines, testFiles) {
|
|
|
1508
1788
|
if (testFiles === undefined) {
|
|
1509
1789
|
return () => true;
|
|
1510
1790
|
}
|
|
1511
|
-
const roots = testFiles.map((file) => path4.resolve(file));
|
|
1791
|
+
const roots = new Set(testFiles.map((file) => path4.resolve(file)));
|
|
1512
1792
|
const isRunFile = (file) => {
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1517
|
-
|
|
1793
|
+
let candidate = path4.resolve(file);
|
|
1794
|
+
while (!roots.has(candidate)) {
|
|
1795
|
+
const parent = path4.dirname(candidate);
|
|
1796
|
+
if (parent === candidate) {
|
|
1797
|
+
return false;
|
|
1798
|
+
}
|
|
1799
|
+
candidate = parent;
|
|
1800
|
+
}
|
|
1801
|
+
return true;
|
|
1518
1802
|
};
|
|
1519
1803
|
const namesRunFile = lines.some((line) => {
|
|
1520
1804
|
const file = parseFilePath(line);
|
|
@@ -1525,6 +1809,7 @@ function headerFilter(lines, testFiles) {
|
|
|
1525
1809
|
function isWorkflowCommandLine(line) {
|
|
1526
1810
|
return workflowCommandRe.test(line);
|
|
1527
1811
|
}
|
|
1812
|
+
var MAX_FAILURE_MESSAGE_LENGTH = 4000;
|
|
1528
1813
|
function buildTestName(testName, currentFile) {
|
|
1529
1814
|
return currentFile ? `${currentFile} > ${testName}` : testName;
|
|
1530
1815
|
}
|
|
@@ -1548,8 +1833,7 @@ function parseTestLine(line, currentFile) {
|
|
|
1548
1833
|
file: currentFile,
|
|
1549
1834
|
status: "failed",
|
|
1550
1835
|
duration: failMatch[2] ? Number.parseFloat(failMatch[2]) : undefined
|
|
1551
|
-
}
|
|
1552
|
-
startedCollectingError: true
|
|
1836
|
+
}
|
|
1553
1837
|
};
|
|
1554
1838
|
}
|
|
1555
1839
|
const bailFailMatch = /^\(fail\) +(\S.*?)(?: \[([0-9.]+)ms\])?$/.exec(line);
|
|
@@ -1560,8 +1844,7 @@ function parseTestLine(line, currentFile) {
|
|
|
1560
1844
|
file: currentFile,
|
|
1561
1845
|
status: "failed",
|
|
1562
1846
|
duration: bailFailMatch[2] ? Number.parseFloat(bailFailMatch[2]) : undefined
|
|
1563
|
-
}
|
|
1564
|
-
startedCollectingError: true
|
|
1847
|
+
}
|
|
1565
1848
|
};
|
|
1566
1849
|
}
|
|
1567
1850
|
const skipMatch = /^⏭ +(\S.*)$/.exec(line);
|
|
@@ -1576,28 +1859,69 @@ function parseTestLine(line, currentFile) {
|
|
|
1576
1859
|
}
|
|
1577
1860
|
return {};
|
|
1578
1861
|
}
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1862
|
+
var NON_FAILING_RESULT_LINE = /^(?:\((?:pass|skip|todo)\)|[✓»✎⏭]) +\S/;
|
|
1863
|
+
var CODE_FRAME_LINE = /^\s*\d+ \|(?: |$)/;
|
|
1864
|
+
var ERROR_HEADING_LINE = /^(?:error|\w*Error)(?: \[[^\]]*\])?: /;
|
|
1865
|
+
var AFTER_FAIL_NOTE_LINE = /^\s+\^ \S/;
|
|
1866
|
+
function capFailureMessage(message) {
|
|
1867
|
+
return message.length > MAX_FAILURE_MESSAGE_LENGTH ? `${message.slice(0, MAX_FAILURE_MESSAGE_LENGTH)}
|
|
1868
|
+
… (${message.length - MAX_FAILURE_MESSAGE_LENGTH} more characters)` : message;
|
|
1869
|
+
}
|
|
1870
|
+
function readFailureBlock(block) {
|
|
1871
|
+
const lines = block.filter((line) => !isWorkflowCommandLine(line));
|
|
1872
|
+
const frameStart = lines.findIndex((line) => CODE_FRAME_LINE.test(line));
|
|
1873
|
+
const start = frameStart === -1 ? lines.findIndex((line) => ERROR_HEADING_LINE.test(line)) : frameStart;
|
|
1874
|
+
const text = lines.slice(Math.max(start, 0)).join(`
|
|
1582
1875
|
`).trim();
|
|
1583
|
-
}
|
|
1876
|
+
return { text: text === "" ? undefined : text, reported: start !== -1 };
|
|
1584
1877
|
}
|
|
1585
|
-
function
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1878
|
+
function failureMessageFrom(block, notes) {
|
|
1879
|
+
const report = block.text !== undefined && (block.reported || notes.length === 0) ? capFailureMessage(block.text) : undefined;
|
|
1880
|
+
const parts = report === undefined ? notes : [report, ...notes];
|
|
1881
|
+
return parts.length === 0 ? undefined : parts.join(`
|
|
1882
|
+
`);
|
|
1590
1883
|
}
|
|
1591
|
-
function
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1884
|
+
function setFailureMessage(test, block, notes) {
|
|
1885
|
+
const failureMessage = failureMessageFrom(block, notes);
|
|
1886
|
+
if (failureMessage !== undefined) {
|
|
1887
|
+
test.failureMessage = failureMessage;
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
function recordTest(reader, test, index) {
|
|
1891
|
+
if (test.status === "failed") {
|
|
1892
|
+
const block = readFailureBlock(reader.lines.slice(reader.blockStart, index));
|
|
1893
|
+
setFailureMessage(test, block, []);
|
|
1894
|
+
reader.lastFailed = { test, block, notes: [] };
|
|
1895
|
+
}
|
|
1896
|
+
reader.tests.push(test);
|
|
1897
|
+
reader.counters[test.status]++;
|
|
1898
|
+
reader.blockStart = index + 1;
|
|
1899
|
+
}
|
|
1900
|
+
function readLine(reader, index) {
|
|
1901
|
+
const line = reader.lines[index];
|
|
1902
|
+
const filePath = parseFilePath(line);
|
|
1903
|
+
if (filePath && reader.isHeaderFile(filePath)) {
|
|
1904
|
+
reader.currentFile = filePath;
|
|
1905
|
+
reader.blockStart = index + 1;
|
|
1906
|
+
reader.lastFailed = undefined;
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
if (isWorkflowCommandLine(line)) {
|
|
1910
|
+
return;
|
|
1911
|
+
}
|
|
1912
|
+
if (reader.lastFailed && AFTER_FAIL_NOTE_LINE.test(line)) {
|
|
1913
|
+
const { test, block, notes } = reader.lastFailed;
|
|
1914
|
+
notes.push(line.trim());
|
|
1915
|
+
setFailureMessage(test, block, notes);
|
|
1916
|
+
reader.blockStart = index + 1;
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
reader.lastFailed = undefined;
|
|
1920
|
+
const { test } = parseTestLine(line, reader.currentFile);
|
|
1921
|
+
if (test) {
|
|
1922
|
+
recordTest(reader, test, index);
|
|
1923
|
+
} else if (NON_FAILING_RESULT_LINE.test(line)) {
|
|
1924
|
+
reader.blockStart = index + 1;
|
|
1601
1925
|
}
|
|
1602
1926
|
}
|
|
1603
1927
|
var RAN_LINE = /^\s*Ran\s+(\d+)\s+tests?\b/;
|
|
@@ -1670,37 +1994,19 @@ function parseBunTestOutput(stdout, stderr, testFiles) {
|
|
|
1670
1994
|
const output = `${stdout}
|
|
1671
1995
|
${stderr}`;
|
|
1672
1996
|
const lines = output.split(`
|
|
1673
|
-
`);
|
|
1674
|
-
const
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
if (isWorkflowCommandLine(line)) {
|
|
1686
|
-
continue;
|
|
1687
|
-
}
|
|
1688
|
-
const parseResult = parseTestLine(line, currentFile);
|
|
1689
|
-
if (parseResult.test) {
|
|
1690
|
-
if (currentTest && collectingError) {
|
|
1691
|
-
finalizeErrorMessage(currentTest, errorLines);
|
|
1692
|
-
errorLines = [];
|
|
1693
|
-
}
|
|
1694
|
-
currentTest = parseResult.test;
|
|
1695
|
-
tests.push(currentTest);
|
|
1696
|
-
collectingError = updateCounters(currentTest, counters, parseResult);
|
|
1697
|
-
continue;
|
|
1698
|
-
}
|
|
1699
|
-
if (collectingError && currentTest && shouldCollectErrorLine(line)) {
|
|
1700
|
-
errorLines.push(line);
|
|
1701
|
-
}
|
|
1997
|
+
`).map((line) => stripAnsi(line));
|
|
1998
|
+
const reader = {
|
|
1999
|
+
lines,
|
|
2000
|
+
isHeaderFile: headerFilter(lines, testFiles),
|
|
2001
|
+
tests,
|
|
2002
|
+
counters,
|
|
2003
|
+
currentFile: undefined,
|
|
2004
|
+
blockStart: 0,
|
|
2005
|
+
lastFailed: undefined
|
|
2006
|
+
};
|
|
2007
|
+
for (let index = 0;index < lines.length; index++) {
|
|
2008
|
+
readLine(reader, index);
|
|
1702
2009
|
}
|
|
1703
|
-
finalizeErrorMessage(currentTest, errorLines);
|
|
1704
2010
|
const summaryCounts = parseSummaryLines(output);
|
|
1705
2011
|
counters.passed = Math.max(counters.passed, summaryCounts.passed);
|
|
1706
2012
|
counters.failed = Math.max(counters.failed, summaryCounts.failed);
|
|
@@ -1720,6 +2026,363 @@ ${stderr}`;
|
|
|
1720
2026
|
};
|
|
1721
2027
|
}
|
|
1722
2028
|
|
|
2029
|
+
// src/run-profile.ts
|
|
2030
|
+
import { appendFileSync as appendFileSync2 } from "node:fs";
|
|
2031
|
+
import path5 from "node:path";
|
|
2032
|
+
import { StringDecoder } from "node:string_decoder";
|
|
2033
|
+
var PROFILE_FORMAT_VERSION = 1;
|
|
2034
|
+
var SPAWN_MARKS = ["spawnStart", "spawned", "firstStderr", "inspector", "firstFile", "decisive", "exit", "close"];
|
|
2035
|
+
var PHASES = ["prep", "spawn", "startup", "inspector", "load", "tests", "teardown", "stdio", "finish"];
|
|
2036
|
+
var PHASE_FROM = {
|
|
2037
|
+
requested: "prep",
|
|
2038
|
+
spawnStart: "spawn",
|
|
2039
|
+
spawned: "startup",
|
|
2040
|
+
firstStderr: "load",
|
|
2041
|
+
inspector: "load",
|
|
2042
|
+
firstFile: "tests",
|
|
2043
|
+
decisive: "teardown",
|
|
2044
|
+
exit: "stdio",
|
|
2045
|
+
close: "finish"
|
|
2046
|
+
};
|
|
2047
|
+
function mutantRunScope(fileScoped, testNamePattern, coveringTestCount) {
|
|
2048
|
+
if (fileScoped) {
|
|
2049
|
+
return "files";
|
|
2050
|
+
}
|
|
2051
|
+
if (testNamePattern !== undefined) {
|
|
2052
|
+
return "targeted";
|
|
2053
|
+
}
|
|
2054
|
+
return coveringTestCount > 0 ? "fallback" : "static";
|
|
2055
|
+
}
|
|
2056
|
+
var systemClock = { now: () => performance.now(), origin: performance.timeOrigin };
|
|
2057
|
+
function round3(value) {
|
|
2058
|
+
return Math.round(value * 1000) / 1000;
|
|
2059
|
+
}
|
|
2060
|
+
function share(part, whole) {
|
|
2061
|
+
return whole > 0 ? Math.round(part / whole * 1e4) / 1e4 : 0;
|
|
2062
|
+
}
|
|
2063
|
+
function computePhases(sequence) {
|
|
2064
|
+
const phases = {};
|
|
2065
|
+
if (sequence.length === 0) {
|
|
2066
|
+
return phases;
|
|
2067
|
+
}
|
|
2068
|
+
const end = sequence.at(-1)[1];
|
|
2069
|
+
let [previousMark, previousAt] = sequence[0];
|
|
2070
|
+
for (const [mark, at] of sequence.slice(1)) {
|
|
2071
|
+
if (at < previousAt || at > end) {
|
|
2072
|
+
continue;
|
|
2073
|
+
}
|
|
2074
|
+
const phase = mark === "inspector" ? "inspector" : PHASE_FROM[previousMark];
|
|
2075
|
+
phases[phase] = (phases[phase] ?? 0) + (at - previousAt);
|
|
2076
|
+
previousMark = mark;
|
|
2077
|
+
previousAt = at;
|
|
2078
|
+
}
|
|
2079
|
+
return phases;
|
|
2080
|
+
}
|
|
2081
|
+
function percentile(sorted, q) {
|
|
2082
|
+
return sorted[Math.max(0, Math.ceil(q * sorted.length) - 1)];
|
|
2083
|
+
}
|
|
2084
|
+
function summarize(values) {
|
|
2085
|
+
const sorted = values.toSorted((a, b) => a - b);
|
|
2086
|
+
const sum = sorted.reduce((total, value) => total + value, 0);
|
|
2087
|
+
return {
|
|
2088
|
+
count: sorted.length,
|
|
2089
|
+
sum: round3(sum),
|
|
2090
|
+
mean: round3(sum / sorted.length),
|
|
2091
|
+
p50: round3(percentile(sorted, 0.5)),
|
|
2092
|
+
p95: round3(percentile(sorted, 0.95))
|
|
2093
|
+
};
|
|
2094
|
+
}
|
|
2095
|
+
function groupKeys(record) {
|
|
2096
|
+
if (record.kind === "dry") {
|
|
2097
|
+
return ["all", "dry", `dry/${record.status}`];
|
|
2098
|
+
}
|
|
2099
|
+
const scope = record.scope ?? "unknown";
|
|
2100
|
+
return ["all", "mutant", `mutant/${record.status}`, `mutant/*/${scope}`, `mutant/${record.status}/${scope}`];
|
|
2101
|
+
}
|
|
2102
|
+
function optionalStats(values) {
|
|
2103
|
+
return values.length > 0 ? summarize(values) : undefined;
|
|
2104
|
+
}
|
|
2105
|
+
function groupStats(records) {
|
|
2106
|
+
const totalMs = summarize(records.map((record) => record.totalMs));
|
|
2107
|
+
const phases = {};
|
|
2108
|
+
const phaseShare = {};
|
|
2109
|
+
for (const phase of PHASES) {
|
|
2110
|
+
const stats = optionalStats(records.flatMap((record) => record.phases[phase] ?? []));
|
|
2111
|
+
if (stats) {
|
|
2112
|
+
phases[phase] = stats;
|
|
2113
|
+
phaseShare[phase] = share(stats.sum, totalMs.sum);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
return {
|
|
2117
|
+
runs: records.length,
|
|
2118
|
+
totalMs,
|
|
2119
|
+
files: optionalStats(records.flatMap((record) => record.files ?? [])),
|
|
2120
|
+
fileHeaders: optionalStats(records.flatMap((record) => record.fileHeaders ?? [])),
|
|
2121
|
+
phases,
|
|
2122
|
+
phaseShare
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2125
|
+
function aggregateRuns(records) {
|
|
2126
|
+
const groups = new Map;
|
|
2127
|
+
for (const record of records) {
|
|
2128
|
+
for (const key of groupKeys(record)) {
|
|
2129
|
+
const members = groups.get(key);
|
|
2130
|
+
if (members) {
|
|
2131
|
+
members.push(record);
|
|
2132
|
+
} else {
|
|
2133
|
+
groups.set(key, [record]);
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
return Object.fromEntries([...groups.keys()].toSorted((a, b) => a.localeCompare(b)).map((key) => [key, groupStats(groups.get(key))]));
|
|
2138
|
+
}
|
|
2139
|
+
var FAIL_LINE_RE = /^(?:\(fail\)|✗) /;
|
|
2140
|
+
var MAX_PENDING_LINE = 4096;
|
|
2141
|
+
function classifyStderrLine(line, bail) {
|
|
2142
|
+
if (fileHeaderRe.test(line)) {
|
|
2143
|
+
return "file";
|
|
2144
|
+
}
|
|
2145
|
+
if (line.startsWith(HIT_LIMIT_SENTINEL)) {
|
|
2146
|
+
return "hitLimit";
|
|
2147
|
+
}
|
|
2148
|
+
if (bail && FAIL_LINE_RE.test(line)) {
|
|
2149
|
+
return "fail";
|
|
2150
|
+
}
|
|
2151
|
+
return RAN_LINE.test(line) ? "summary" : undefined;
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
class RunProfile {
|
|
2155
|
+
owner;
|
|
2156
|
+
kind;
|
|
2157
|
+
mutantId;
|
|
2158
|
+
clock;
|
|
2159
|
+
requestedAt;
|
|
2160
|
+
spawnStates = [];
|
|
2161
|
+
details = {};
|
|
2162
|
+
scope;
|
|
2163
|
+
files;
|
|
2164
|
+
patternBytes;
|
|
2165
|
+
constructor(owner, kind, mutantId, clock) {
|
|
2166
|
+
this.owner = owner;
|
|
2167
|
+
this.kind = kind;
|
|
2168
|
+
this.mutantId = mutantId;
|
|
2169
|
+
this.clock = clock;
|
|
2170
|
+
this.requestedAt = clock.now();
|
|
2171
|
+
this.scope = kind === "dry" ? "dry" : undefined;
|
|
2172
|
+
}
|
|
2173
|
+
setScope(scope) {
|
|
2174
|
+
this.scope = scope;
|
|
2175
|
+
}
|
|
2176
|
+
beginSpawn(bail, testFiles, testNamePattern) {
|
|
2177
|
+
this.files = testFiles?.length;
|
|
2178
|
+
this.patternBytes = testNamePattern === undefined ? undefined : Buffer.byteLength(testNamePattern);
|
|
2179
|
+
this.spawnStates.push({
|
|
2180
|
+
bail,
|
|
2181
|
+
marks: { spawnStart: this.clock.now() },
|
|
2182
|
+
fileHeaders: 0,
|
|
2183
|
+
scanning: true,
|
|
2184
|
+
decoder: new StringDecoder("utf8"),
|
|
2185
|
+
pending: "",
|
|
2186
|
+
skippingLine: false
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
mark(name) {
|
|
2190
|
+
const state = this.spawnStates.at(-1);
|
|
2191
|
+
if (state && state.marks[name] === undefined) {
|
|
2192
|
+
state.marks[name] = this.clock.now();
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
onStderr(chunk) {
|
|
2196
|
+
const state = this.spawnStates.at(-1);
|
|
2197
|
+
if (!state) {
|
|
2198
|
+
return;
|
|
2199
|
+
}
|
|
2200
|
+
const at = this.clock.now();
|
|
2201
|
+
state.marks.firstStderr ??= at;
|
|
2202
|
+
if (!state.scanning) {
|
|
2203
|
+
return;
|
|
2204
|
+
}
|
|
2205
|
+
let text = state.decoder.write(chunk);
|
|
2206
|
+
if (state.skippingLine) {
|
|
2207
|
+
const newline = text.indexOf(`
|
|
2208
|
+
`);
|
|
2209
|
+
if (newline === -1) {
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
text = text.slice(newline + 1);
|
|
2213
|
+
state.skippingLine = false;
|
|
2214
|
+
}
|
|
2215
|
+
const lines = (state.pending + text).split(`
|
|
2216
|
+
`);
|
|
2217
|
+
state.pending = lines.pop();
|
|
2218
|
+
for (const line of lines) {
|
|
2219
|
+
if (!this.readLine(state, stripAnsi(line).replace(/\r$/, ""), at)) {
|
|
2220
|
+
return;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
if (state.pending.length > MAX_PENDING_LINE) {
|
|
2224
|
+
state.pending = "";
|
|
2225
|
+
state.skippingLine = true;
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
readLine(state, line, at) {
|
|
2229
|
+
const kind = classifyStderrLine(line, state.bail);
|
|
2230
|
+
if (kind === "file") {
|
|
2231
|
+
state.fileHeaders++;
|
|
2232
|
+
state.marks.firstFile ??= at;
|
|
2233
|
+
} else if (kind !== undefined) {
|
|
2234
|
+
state.decisive = kind;
|
|
2235
|
+
state.marks.decisive = at;
|
|
2236
|
+
state.scanning = false;
|
|
2237
|
+
}
|
|
2238
|
+
return state.scanning;
|
|
2239
|
+
}
|
|
2240
|
+
at(name) {
|
|
2241
|
+
this.details[`at.${name}`] ??= round3(this.clock.now() - this.requestedAt);
|
|
2242
|
+
}
|
|
2243
|
+
atEpoch(name, epochMs) {
|
|
2244
|
+
this.details[`at.${name}`] ??= round3(epochMs - (this.clock.origin + this.requestedAt));
|
|
2245
|
+
}
|
|
2246
|
+
preloadTimings(timings) {
|
|
2247
|
+
for (const [name, value] of Object.entries(timings ?? {})) {
|
|
2248
|
+
if (name.startsWith("at.")) {
|
|
2249
|
+
this.atEpoch(`preload.${name.slice(3)}`, value);
|
|
2250
|
+
} else {
|
|
2251
|
+
this.detail(`preload.${name}`, value);
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
detail(name, value) {
|
|
2256
|
+
this.details[name] = round3(value);
|
|
2257
|
+
}
|
|
2258
|
+
finish(status) {
|
|
2259
|
+
this.owner.record(this.toRecord(status, this.clock.now()));
|
|
2260
|
+
}
|
|
2261
|
+
toRecord(status, returnedAt) {
|
|
2262
|
+
const sequence = [["requested", this.requestedAt]];
|
|
2263
|
+
for (const state of this.spawnStates) {
|
|
2264
|
+
for (const mark of SPAWN_MARKS) {
|
|
2265
|
+
const at = state.marks[mark];
|
|
2266
|
+
if (at !== undefined) {
|
|
2267
|
+
sequence.push([mark, at]);
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
sequence.push(["returned", returnedAt]);
|
|
2272
|
+
const phases = computePhases(sequence);
|
|
2273
|
+
const last = this.spawnStates.at(-1);
|
|
2274
|
+
return {
|
|
2275
|
+
type: "run",
|
|
2276
|
+
v: PROFILE_FORMAT_VERSION,
|
|
2277
|
+
pid: this.owner.pid,
|
|
2278
|
+
kind: this.kind,
|
|
2279
|
+
mutant: this.mutantId,
|
|
2280
|
+
status,
|
|
2281
|
+
scope: this.scope,
|
|
2282
|
+
files: this.files,
|
|
2283
|
+
patternBytes: this.patternBytes,
|
|
2284
|
+
spawns: this.spawnStates.length,
|
|
2285
|
+
bail: last?.bail,
|
|
2286
|
+
decisive: last?.decisive,
|
|
2287
|
+
fileHeaders: last?.fileHeaders,
|
|
2288
|
+
startEpochMs: round3(this.clock.origin + this.requestedAt),
|
|
2289
|
+
totalMs: round3(returnedAt - this.requestedAt),
|
|
2290
|
+
detail: Object.keys(this.details).length > 0 ? { ...this.details } : undefined,
|
|
2291
|
+
marks: this.spawnStates.map((state) => Object.fromEntries(SPAWN_MARKS.flatMap((mark) => state.marks[mark] === undefined ? [] : [[mark, round3(state.marks[mark] - this.requestedAt)]]))),
|
|
2292
|
+
phases: Object.fromEntries(Object.entries(phases).map(([phase, ms]) => [phase, round3(ms)]))
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
var NO_HANDLERS = Object.freeze({});
|
|
2297
|
+
function profileInspectorHandlers(profile) {
|
|
2298
|
+
if (profile === undefined) {
|
|
2299
|
+
return NO_HANDLERS;
|
|
2300
|
+
}
|
|
2301
|
+
return {
|
|
2302
|
+
onTestFound: () => {
|
|
2303
|
+
profile.mark("firstFile");
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
class WorkerProfiler {
|
|
2309
|
+
file;
|
|
2310
|
+
logger;
|
|
2311
|
+
clock;
|
|
2312
|
+
pid;
|
|
2313
|
+
records = [];
|
|
2314
|
+
createdAt;
|
|
2315
|
+
failed = false;
|
|
2316
|
+
constructor(file, logger, clock = systemClock, pid = process.pid) {
|
|
2317
|
+
this.file = file;
|
|
2318
|
+
this.logger = logger;
|
|
2319
|
+
this.clock = clock;
|
|
2320
|
+
this.pid = pid;
|
|
2321
|
+
this.createdAt = clock.now();
|
|
2322
|
+
}
|
|
2323
|
+
startRun(kind, mutantId) {
|
|
2324
|
+
return new RunProfile(this, kind, mutantId, this.clock);
|
|
2325
|
+
}
|
|
2326
|
+
record(record) {
|
|
2327
|
+
this.records.push(record);
|
|
2328
|
+
this.append(record);
|
|
2329
|
+
}
|
|
2330
|
+
writeSummary() {
|
|
2331
|
+
if (this.records.length === 0) {
|
|
2332
|
+
return;
|
|
2333
|
+
}
|
|
2334
|
+
const end = round3(this.clock.origin + this.clock.now());
|
|
2335
|
+
let firstRun = Number.POSITIVE_INFINITY;
|
|
2336
|
+
for (const record of this.records) {
|
|
2337
|
+
firstRun = Math.min(firstRun, record.startEpochMs);
|
|
2338
|
+
}
|
|
2339
|
+
const busyMs = this.records.reduce((total, record) => total + record.totalMs, 0);
|
|
2340
|
+
const dryRunMs = this.records.reduce((total, record) => total + (record.kind === "dry" ? record.totalMs : 0), 0);
|
|
2341
|
+
const wallMs = end - firstRun;
|
|
2342
|
+
const summary = {
|
|
2343
|
+
type: "summary",
|
|
2344
|
+
v: PROFILE_FORMAT_VERSION,
|
|
2345
|
+
pid: this.pid,
|
|
2346
|
+
runs: this.records.length,
|
|
2347
|
+
createdEpochMs: round3(this.clock.origin + this.createdAt),
|
|
2348
|
+
firstRunEpochMs: firstRun,
|
|
2349
|
+
endEpochMs: end,
|
|
2350
|
+
wallMs: round3(wallMs),
|
|
2351
|
+
busyMs: round3(busyMs),
|
|
2352
|
+
dryRunMs: round3(dryRunMs),
|
|
2353
|
+
dryRunShareOfBusy: share(dryRunMs, busyMs),
|
|
2354
|
+
dryRunShareOfWall: share(dryRunMs, wallMs),
|
|
2355
|
+
groups: aggregateRuns(this.records)
|
|
2356
|
+
};
|
|
2357
|
+
this.records.length = 0;
|
|
2358
|
+
this.append(summary);
|
|
2359
|
+
}
|
|
2360
|
+
append(line) {
|
|
2361
|
+
if (this.failed) {
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
try {
|
|
2365
|
+
appendFileSync2(this.file, `${JSON.stringify(line)}
|
|
2366
|
+
`);
|
|
2367
|
+
} catch (error) {
|
|
2368
|
+
this.failed = true;
|
|
2369
|
+
this.logger.warn("%s: cannot append to %s (%s); profiling is off for this worker", PROFILE_ENV, this.file, error instanceof Error ? error.message : String(error));
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
function createWorkerProfiler(logger, env = process.env) {
|
|
2374
|
+
const value = env[PROFILE_ENV];
|
|
2375
|
+
if (value === undefined || value === "" || value === "0" || value === "false") {
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
if (!path5.isAbsolute(value)) {
|
|
2379
|
+
logger.warn("%s must be the absolute path of a JSONL file to append to (got %s); profiling is off", PROFILE_ENV, value);
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
2382
|
+
logger.debug("Profiling every run to %s", value);
|
|
2383
|
+
return new WorkerProfiler(value, logger);
|
|
2384
|
+
}
|
|
2385
|
+
|
|
1723
2386
|
// src/utils/bun-args.ts
|
|
1724
2387
|
var BREAKS_ATTRIBUTION = "breaks per-test coverage attribution";
|
|
1725
2388
|
var RETRY_REASON = "re-runs failing tests, which repeats test names (so a killedBy test cannot be resolved to one test, and incremental mode re-runs them) and cannot improve mutation scores";
|
|
@@ -1878,8 +2541,9 @@ async function checkBunVersion(bunPath, env, timeoutMs = VERSION_CHECK_TIMEOUT_M
|
|
|
1878
2541
|
}
|
|
1879
2542
|
// src/utils/sync-server.ts
|
|
1880
2543
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
1881
|
-
import {
|
|
2544
|
+
import { createRequire } from "node:module";
|
|
1882
2545
|
import { WebSocketServer, WebSocket as WebSocket3 } from "ws";
|
|
2546
|
+
var { createServer } = createRequire(import.meta.url)("node:http");
|
|
1883
2547
|
function isExpectedPath(url, expected) {
|
|
1884
2548
|
if (url === undefined) {
|
|
1885
2549
|
return false;
|
|
@@ -2033,7 +2697,7 @@ class SyncServer {
|
|
|
2033
2697
|
}
|
|
2034
2698
|
// src/utils/bunfig-sanitizer.ts
|
|
2035
2699
|
import { readFile as readFile4, unlink as unlink3 } from "node:fs/promises";
|
|
2036
|
-
import
|
|
2700
|
+
import path6 from "node:path";
|
|
2037
2701
|
import { parse, stringify } from "smol-toml";
|
|
2038
2702
|
var SAFE_TEST_KEYS = new Set([
|
|
2039
2703
|
"preload",
|
|
@@ -2050,7 +2714,7 @@ var IGNORED_TEST_KEY_REASONS = new Map([
|
|
|
2050
2714
|
]);
|
|
2051
2715
|
var FORCED_FALSE_TEST_KEY_REASONS = new Map([
|
|
2052
2716
|
["coverage", "forced to false for mutation runs: a coverageThreshold miss makes bun exit 1 even when no test fails, which would be mistaken for a mutant kill"],
|
|
2053
|
-
["onlyFailures", "forced to false for
|
|
2717
|
+
["onlyFailures", "forced to false for the dry run, which reads every test's result; mutant runs hide passing tests themselves"]
|
|
2054
2718
|
]);
|
|
2055
2719
|
var COVERAGE_DROP_REASON = "dropped: coverage is disabled for mutation runs (the runner collects its own per-test coverage)";
|
|
2056
2720
|
var GENERIC_DROP_REASON = "dropped: not on the runner's allowlist of [test] settings that are safe for mutation runs";
|
|
@@ -2067,7 +2731,7 @@ function absolutizePath(value, projectCwd) {
|
|
|
2067
2731
|
if (typeof value !== "string") {
|
|
2068
2732
|
return value;
|
|
2069
2733
|
}
|
|
2070
|
-
return
|
|
2734
|
+
return path6.isAbsolute(value) ? value : path6.resolve(projectCwd, value);
|
|
2071
2735
|
}
|
|
2072
2736
|
function absolutizePathValue(value, projectCwd) {
|
|
2073
2737
|
if (Array.isArray(value)) {
|
|
@@ -2076,7 +2740,7 @@ function absolutizePathValue(value, projectCwd) {
|
|
|
2076
2740
|
return absolutizePath(value, projectCwd);
|
|
2077
2741
|
}
|
|
2078
2742
|
async function readSourceBunfig(projectCwd, sourceBunfig) {
|
|
2079
|
-
const bunfigPath = sourceBunfig === undefined ?
|
|
2743
|
+
const bunfigPath = sourceBunfig === undefined ? path6.join(projectCwd, "bunfig.toml") : path6.resolve(projectCwd, sourceBunfig);
|
|
2080
2744
|
try {
|
|
2081
2745
|
const content = await readFile4(bunfigPath, "utf8");
|
|
2082
2746
|
return parse(content);
|
|
@@ -2091,12 +2755,12 @@ async function readSourceBunfig(projectCwd, sourceBunfig) {
|
|
|
2091
2755
|
async function readBunfigTestRoot(projectCwd, sourceBunfig) {
|
|
2092
2756
|
const rawConfig = await readSourceBunfig(projectCwd, sourceBunfig);
|
|
2093
2757
|
const root = rawConfig.test?.root;
|
|
2094
|
-
return typeof root === "string" ?
|
|
2758
|
+
return typeof root === "string" ? path6.resolve(projectCwd, root) : undefined;
|
|
2095
2759
|
}
|
|
2096
2760
|
async function readBunfigTestPreloads(projectCwd, sourceBunfig) {
|
|
2097
2761
|
const rawConfig = await readSourceBunfig(projectCwd, sourceBunfig);
|
|
2098
2762
|
const preload = rawConfig.test?.preload;
|
|
2099
|
-
return [preload].flat().filter((entry) => typeof entry === "string").map((entry) =>
|
|
2763
|
+
return [preload].flat().filter((entry) => typeof entry === "string").map((entry) => path6.resolve(projectCwd, entry));
|
|
2100
2764
|
}
|
|
2101
2765
|
function sanitizeTestSection(sourceTest, projectCwd, dropped) {
|
|
2102
2766
|
const sanitizedTest = {};
|
|
@@ -2132,13 +2796,14 @@ async function generateSanitizedBunfig(projectCwd, tmpDir, sourceBunfig, onDropp
|
|
|
2132
2796
|
dropped.push({ key: `test.${key}`, reason: RANDOM_ORDER_REASON, warn: false, mutantRunsOnly: true });
|
|
2133
2797
|
}
|
|
2134
2798
|
onDropped?.(dropped);
|
|
2135
|
-
const outPath =
|
|
2799
|
+
const outPath = path6.join(tmpDir, `stryker-bun-runner-bunfig-${process.pid}-${Date.now()}.toml`);
|
|
2136
2800
|
await writePrivateFile(outPath, stringify(sanitized));
|
|
2801
|
+
const mutantRunTest = { ...sanitizedTest, onlyFailures: true };
|
|
2137
2802
|
if (randomOrderKeys.length > 0) {
|
|
2138
|
-
|
|
2803
|
+
delete mutantRunTest.seed;
|
|
2139
2804
|
mutantRunTest.randomize = false;
|
|
2140
|
-
await writePrivateFile(mutantRunBunfigPath(outPath), stringify({ ...sanitized, test: mutantRunTest }));
|
|
2141
2805
|
}
|
|
2806
|
+
await writePrivateFile(mutantRunBunfigPath(outPath), stringify({ ...sanitized, test: mutantRunTest }));
|
|
2142
2807
|
return outPath;
|
|
2143
2808
|
}
|
|
2144
2809
|
async function unlinkIfPresent(filePath) {
|
|
@@ -2156,7 +2821,7 @@ async function cleanupSanitizedBunfig(filePath) {
|
|
|
2156
2821
|
}
|
|
2157
2822
|
// src/utils/test-file-discovery.ts
|
|
2158
2823
|
import * as fsPromises from "node:fs/promises";
|
|
2159
|
-
import
|
|
2824
|
+
import path7 from "node:path";
|
|
2160
2825
|
function isExcludedDirName(name) {
|
|
2161
2826
|
return name.startsWith(".") || name.toLowerCase() === "node_modules";
|
|
2162
2827
|
}
|
|
@@ -2202,7 +2867,7 @@ async function handleSymlinkFile(fullPath, entryName, ctx) {
|
|
|
2202
2867
|
}
|
|
2203
2868
|
const resolvedTarget = await tryRealpath(fullPath);
|
|
2204
2869
|
if (resolvedTarget && !hasExcludedAncestor(resolvedTarget)) {
|
|
2205
|
-
ctx.results.push(
|
|
2870
|
+
ctx.results.push(path7.relative(ctx.cwd, fullPath));
|
|
2206
2871
|
}
|
|
2207
2872
|
}
|
|
2208
2873
|
async function handleSymlink(fullPath, entryName, ctx) {
|
|
@@ -2218,7 +2883,7 @@ async function handleSymlink(fullPath, entryName, ctx) {
|
|
|
2218
2883
|
}
|
|
2219
2884
|
}
|
|
2220
2885
|
async function processEntry(entry, dir, ctx) {
|
|
2221
|
-
const fullPath =
|
|
2886
|
+
const fullPath = path7.join(dir, entry.name);
|
|
2222
2887
|
if (entry.isDirectory()) {
|
|
2223
2888
|
if (!isExcludedDirName(entry.name)) {
|
|
2224
2889
|
await ctx.walk(fullPath);
|
|
@@ -2226,7 +2891,7 @@ async function processEntry(entry, dir, ctx) {
|
|
|
2226
2891
|
} else if (entry.isSymbolicLink()) {
|
|
2227
2892
|
await handleSymlink(fullPath, entry.name, ctx);
|
|
2228
2893
|
} else if (entry.isFile() && TEST_FILE_SUFFIX_RE.test(entry.name)) {
|
|
2229
|
-
ctx.results.push(
|
|
2894
|
+
ctx.results.push(path7.relative(ctx.cwd, fullPath));
|
|
2230
2895
|
}
|
|
2231
2896
|
}
|
|
2232
2897
|
async function discoverTestFiles(cwd = process.cwd(), logger, sourceBunfig) {
|
|
@@ -2292,6 +2957,92 @@ class MutantWarnAggregator {
|
|
|
2292
2957
|
this.affected.clear();
|
|
2293
2958
|
}
|
|
2294
2959
|
}
|
|
2960
|
+
// src/utils/likely-killer-order.ts
|
|
2961
|
+
import path8 from "node:path";
|
|
2962
|
+
var MUTANT_SWITCH_RE = /stryMutAct_9fa48\("([^"\\]+)"\)/g;
|
|
2963
|
+
function mutantIdsInInstrumentedSource(code) {
|
|
2964
|
+
return new Set(Array.from(code.matchAll(MUTANT_SWITCH_RE), (match) => match[1]));
|
|
2965
|
+
}
|
|
2966
|
+
|
|
2967
|
+
class TestFileCoverage {
|
|
2968
|
+
files;
|
|
2969
|
+
byMutant;
|
|
2970
|
+
constructor(files, byMutant) {
|
|
2971
|
+
this.files = files;
|
|
2972
|
+
this.byMutant = byMutant;
|
|
2973
|
+
}
|
|
2974
|
+
static fromPerTest(perTest) {
|
|
2975
|
+
const files = [];
|
|
2976
|
+
const fileIndex = new Map;
|
|
2977
|
+
const byMutant = new Map;
|
|
2978
|
+
for (const [key, counts] of Object.entries(perTest)) {
|
|
2979
|
+
const sepIdx = key.lastIndexOf("@@");
|
|
2980
|
+
if (sepIdx === -1) {
|
|
2981
|
+
continue;
|
|
2982
|
+
}
|
|
2983
|
+
const file = key.slice(0, sepIdx);
|
|
2984
|
+
let index = fileIndex.get(file);
|
|
2985
|
+
if (index === undefined) {
|
|
2986
|
+
index = files.push(file) - 1;
|
|
2987
|
+
fileIndex.set(file, index);
|
|
2988
|
+
}
|
|
2989
|
+
for (const mutantId of Object.keys(counts)) {
|
|
2990
|
+
let indices = byMutant.get(mutantId);
|
|
2991
|
+
if (indices === undefined) {
|
|
2992
|
+
indices = new Set;
|
|
2993
|
+
byMutant.set(mutantId, indices);
|
|
2994
|
+
}
|
|
2995
|
+
indices.add(index);
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
return files.length === 0 ? undefined : new TestFileCoverage(files, new Map([...byMutant].map(([mutantId, indices]) => [mutantId, [...indices]])));
|
|
2999
|
+
}
|
|
3000
|
+
static fromJson(value) {
|
|
3001
|
+
if (typeof value !== "object" || value === null) {
|
|
3002
|
+
return;
|
|
3003
|
+
}
|
|
3004
|
+
const { files, mutants } = value;
|
|
3005
|
+
if (!Array.isArray(files) || !files.every((file) => typeof file === "string") || typeof mutants !== "object" || mutants === null || Array.isArray(mutants)) {
|
|
3006
|
+
return;
|
|
3007
|
+
}
|
|
3008
|
+
const isFileIndex = (index) => Number.isInteger(index) && index >= 0 && index < files.length;
|
|
3009
|
+
const entries = Object.entries(mutants);
|
|
3010
|
+
if (!entries.every(([, indices]) => Array.isArray(indices) && indices.every((index) => isFileIndex(index)))) {
|
|
3011
|
+
return;
|
|
3012
|
+
}
|
|
3013
|
+
return new TestFileCoverage(files, new Map(entries));
|
|
3014
|
+
}
|
|
3015
|
+
toJSON() {
|
|
3016
|
+
return { files: [...this.files], mutants: Object.fromEntries([...this.byMutant].map(([mutantId, indices]) => [mutantId, [...indices]])) };
|
|
3017
|
+
}
|
|
3018
|
+
filesCovering(mutantId) {
|
|
3019
|
+
return new Set((this.byMutant.get(mutantId) ?? []).map((index) => this.files[index]));
|
|
3020
|
+
}
|
|
3021
|
+
coverageCounts(mutantIds) {
|
|
3022
|
+
const counts = new Map;
|
|
3023
|
+
for (const mutantId of mutantIds) {
|
|
3024
|
+
for (const index of this.byMutant.get(mutantId) ?? []) {
|
|
3025
|
+
const file = this.files[index];
|
|
3026
|
+
counts.set(file, (counts.get(file) ?? 0) + 1);
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
return counts;
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
function namedAfter(sourceFile) {
|
|
3033
|
+
if (sourceFile === undefined) {
|
|
3034
|
+
return () => false;
|
|
3035
|
+
}
|
|
3036
|
+
const sourceStem = path8.parse(sourceFile).name.toLowerCase();
|
|
3037
|
+
return (testFile) => path8.basename(testFile).replace(TEST_FILE_SUFFIX_RE, "").toLowerCase() === sourceStem;
|
|
3038
|
+
}
|
|
3039
|
+
function compareKillerRanks(a, b) {
|
|
3040
|
+
return a.coverage - b.coverage || b.sourceMutants - a.sourceMutants || Number(b.namedAfter) - Number(a.namedAfter);
|
|
3041
|
+
}
|
|
3042
|
+
function orderLikelyKillersFirst(files, rankOf) {
|
|
3043
|
+
const ranks = new Map(files.map((file) => [file, rankOf(file)]));
|
|
3044
|
+
return files.toSorted((a, b) => compareKillerRanks(ranks.get(a), ranks.get(b)));
|
|
3045
|
+
}
|
|
2295
3046
|
// src/bun-test-runner.ts
|
|
2296
3047
|
function createInspectorUrlWaiter() {
|
|
2297
3048
|
let url = null;
|
|
@@ -2468,6 +3219,7 @@ var MUTANT_WARN_KIND = {
|
|
|
2468
3219
|
spawnError: "could not start bun test, scoring as Error rather than Killed",
|
|
2469
3220
|
signalError: "bun test terminated by a signal, scoring as Error rather than Killed",
|
|
2470
3221
|
noEvidence: "bun test exited non-zero with no failing test and no fail/error count, scoring as Error rather than Killed",
|
|
3222
|
+
earlyExit: "bun test exited 0 before printing its summary, scoring as Error rather than Survived",
|
|
2471
3223
|
inconclusiveTimeout: "inconclusive timeout, scoring as Error rather than Timeout",
|
|
2472
3224
|
registryVersion: "dryRun registry file has an unexpected version (skipped)",
|
|
2473
3225
|
registryMalformed: "dryRun registry file is malformed (treated as absent)",
|
|
@@ -2490,6 +3242,16 @@ function readReportedHitCount(stderr, token) {
|
|
|
2490
3242
|
const match = new RegExp(String.raw`^${HIT_LIMIT_SENTINEL} ${token} (\d+)$`, "m").exec(stderr);
|
|
2491
3243
|
return match ? Number(match[1]) : undefined;
|
|
2492
3244
|
}
|
|
3245
|
+
function ignoreStep() {}
|
|
3246
|
+
function dryRunStepMarker(profile, stderr) {
|
|
3247
|
+
if (profile === undefined) {
|
|
3248
|
+
return ignoreStep;
|
|
3249
|
+
}
|
|
3250
|
+
profile.preloadTimings(readPreloadTimings(stderr));
|
|
3251
|
+
return (step) => {
|
|
3252
|
+
profile.at(step);
|
|
3253
|
+
};
|
|
3254
|
+
}
|
|
2493
3255
|
|
|
2494
3256
|
class BunTestRunner {
|
|
2495
3257
|
logger;
|
|
@@ -2505,6 +3267,8 @@ class BunTestRunner {
|
|
|
2505
3267
|
loggedRandomizeOff = false;
|
|
2506
3268
|
loggedFileArgNotes = new Set;
|
|
2507
3269
|
testFileDurations;
|
|
3270
|
+
testFileCoverage;
|
|
3271
|
+
sourceCoverageCounts = new Map;
|
|
2508
3272
|
sourceBunfig;
|
|
2509
3273
|
testFilesOverride;
|
|
2510
3274
|
mutateGlobs;
|
|
@@ -2518,6 +3282,8 @@ class BunTestRunner {
|
|
|
2518
3282
|
sanitizedBunfigPath;
|
|
2519
3283
|
sanitizedBunfigCwd;
|
|
2520
3284
|
tempDir;
|
|
3285
|
+
tempDirTouchedAt = 0;
|
|
3286
|
+
runOwnerPid;
|
|
2521
3287
|
cachedTestNames;
|
|
2522
3288
|
baseNameIndex;
|
|
2523
3289
|
testNameIndex;
|
|
@@ -2538,6 +3304,7 @@ class BunTestRunner {
|
|
|
2538
3304
|
mutantWarnings;
|
|
2539
3305
|
mutantRunsByStatus = emptyMutantRunCounts();
|
|
2540
3306
|
fullSuiteFallbacks = 0;
|
|
3307
|
+
profiler;
|
|
2541
3308
|
currentAbortController;
|
|
2542
3309
|
constructor(logger, options) {
|
|
2543
3310
|
this.logger = logger;
|
|
@@ -2565,6 +3332,7 @@ class BunTestRunner {
|
|
|
2565
3332
|
this.coverageAnalysis = options.coverageAnalysis;
|
|
2566
3333
|
this.disableBail = options.disableBail;
|
|
2567
3334
|
this.mutantWarnings = new MutantWarnAggregator(logger);
|
|
3335
|
+
this.profiler = createWorkerProfiler(logger);
|
|
2568
3336
|
this.logger.debug("BunTestRunner initialized with options: %o", {
|
|
2569
3337
|
bunPath: this.bunPath,
|
|
2570
3338
|
timeout: this.timeout,
|
|
@@ -2576,7 +3344,7 @@ class BunTestRunner {
|
|
|
2576
3344
|
rssCheckIntervalMs: this.rssCheckIntervalMs,
|
|
2577
3345
|
maxSpawnDepth: this.maxSpawnDepth
|
|
2578
3346
|
});
|
|
2579
|
-
if (this.testFilesOverride?.some((p) =>
|
|
3347
|
+
if (this.testFilesOverride?.some((p) => path9.isAbsolute(p))) {
|
|
2580
3348
|
const isSandbox = process.cwd().includes(".stryker-tmp/sandbox-");
|
|
2581
3349
|
if (isSandbox) {
|
|
2582
3350
|
this.logger.warn("bun.testFiles contains absolute path(s) and the current working directory appears to be a Stryker sandbox (%s). " + "Absolute paths point at the ORIGINAL (unmutated) source files — mutations will be silently bypassed. " + "Use relative paths so that Bun resolves them against the sandbox copy.", process.cwd());
|
|
@@ -2584,7 +3352,20 @@ class BunTestRunner {
|
|
|
2584
3352
|
}
|
|
2585
3353
|
}
|
|
2586
3354
|
async resolveRegistryPath() {
|
|
2587
|
-
|
|
3355
|
+
this.assertRunOwnerIsParent();
|
|
3356
|
+
return path9.join(await resolveRunTempDir(), "registry.json");
|
|
3357
|
+
}
|
|
3358
|
+
assertRunOwnerIsParent() {
|
|
3359
|
+
if (this.runOwnerPid !== undefined && process.ppid !== this.runOwnerPid) {
|
|
3360
|
+
throw new Error(`stryker-bun-runner: the Stryker main process (pid ${this.runOwnerPid}) that owns this run has exited ` + `(this worker's parent is now pid ${process.ppid}); not recreating the run's temporary directory`);
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
keepRunTempDirFresh(now) {
|
|
3364
|
+
if (this.tempDir === undefined || now - this.tempDirTouchedAt < RUN_DIR_TOUCH_INTERVAL_MS || process.ppid !== this.runOwnerPid) {
|
|
3365
|
+
return;
|
|
3366
|
+
}
|
|
3367
|
+
this.tempDirTouchedAt = now;
|
|
3368
|
+
touchRunTempDir(this.tempDir, now);
|
|
2588
3369
|
}
|
|
2589
3370
|
resolveCoveringTestFiles(filterIds) {
|
|
2590
3371
|
if (filterIds.length === 0) {
|
|
@@ -2613,9 +3394,64 @@ class BunTestRunner {
|
|
|
2613
3394
|
}
|
|
2614
3395
|
return [...files].toSorted((a, b) => a.localeCompare(b));
|
|
2615
3396
|
}
|
|
2616
|
-
orderCheapestFirst(files) {
|
|
2617
|
-
const
|
|
2618
|
-
return
|
|
3397
|
+
orderCheapestFirst(files, projectFiles) {
|
|
3398
|
+
const costed = files.map((file) => ({ file, cost: this.testFileDurations?.get(projectFiles.get(file)) ?? Number.POSITIVE_INFINITY }));
|
|
3399
|
+
return costed.toSorted((a, b) => a.cost - b.cost).map((entry) => entry.file);
|
|
3400
|
+
}
|
|
3401
|
+
projectFilesOf(files) {
|
|
3402
|
+
return new Map(files.map((file) => [file, normalizeTestFilePath(file) ?? file]));
|
|
3403
|
+
}
|
|
3404
|
+
ordersLikelyKillersFirst(options, coveringTestCount) {
|
|
3405
|
+
return coveringTestCount === 0 && !options.disableBail;
|
|
3406
|
+
}
|
|
3407
|
+
orderForMutantRun(files, ctx) {
|
|
3408
|
+
if (files === undefined) {
|
|
3409
|
+
return;
|
|
3410
|
+
}
|
|
3411
|
+
const projectFiles = this.projectFilesOf(files);
|
|
3412
|
+
const cheapest = this.orderCheapestFirst(files, projectFiles);
|
|
3413
|
+
if (!this.ordersLikelyKillersFirst(ctx.options, ctx.coveringTestCount)) {
|
|
3414
|
+
return cheapest;
|
|
3415
|
+
}
|
|
3416
|
+
const { id: mutantId, fileName } = ctx.options.activeMutant;
|
|
3417
|
+
const mutantFiles = this.testFileCoverage?.filesCovering(mutantId);
|
|
3418
|
+
const isNamedAfterSource = namedAfter(fileName);
|
|
3419
|
+
const rankOf = (file) => {
|
|
3420
|
+
const projectFile = projectFiles.get(file);
|
|
3421
|
+
return {
|
|
3422
|
+
coverage: mutantFiles?.has(projectFile) ? 0 : 1,
|
|
3423
|
+
sourceMutants: ctx.sourceCoverage?.get(projectFile) ?? 0,
|
|
3424
|
+
namedAfter: isNamedAfterSource(file)
|
|
3425
|
+
};
|
|
3426
|
+
};
|
|
3427
|
+
const ordered = orderLikelyKillersFirst(cheapest, rankOf);
|
|
3428
|
+
if (ordered[0] !== cheapest[0]) {
|
|
3429
|
+
this.logger.debug("Mutant %s: running %s first as its likeliest killer (cheapest first would start with %s)", mutantId, ordered[0], cheapest[0]);
|
|
3430
|
+
}
|
|
3431
|
+
return ordered;
|
|
3432
|
+
}
|
|
3433
|
+
setTestFileCoverage(testFileCoverage) {
|
|
3434
|
+
this.testFileCoverage = testFileCoverage;
|
|
3435
|
+
this.sourceCoverageCounts.clear();
|
|
3436
|
+
}
|
|
3437
|
+
async sourceCoverageFor(sandboxFileName) {
|
|
3438
|
+
const coverage = this.testFileCoverage;
|
|
3439
|
+
if (coverage === undefined) {
|
|
3440
|
+
return;
|
|
3441
|
+
}
|
|
3442
|
+
const cached = this.sourceCoverageCounts.get(sandboxFileName);
|
|
3443
|
+
if (cached !== undefined) {
|
|
3444
|
+
return cached;
|
|
3445
|
+
}
|
|
3446
|
+
let mutantIds = new Set;
|
|
3447
|
+
try {
|
|
3448
|
+
mutantIds = mutantIdsInInstrumentedSource(await fsPromises2.readFile(sandboxFileName, "utf8"));
|
|
3449
|
+
} catch (error) {
|
|
3450
|
+
this.logger.debug("Could not read %s for its mutant ids (%s); its full-suite runs rank test files without same-file coverage", sandboxFileName, error instanceof Error ? error.message : String(error));
|
|
3451
|
+
}
|
|
3452
|
+
const counts = coverage.coverageCounts(mutantIds);
|
|
3453
|
+
this.sourceCoverageCounts.set(sandboxFileName, counts);
|
|
3454
|
+
return counts;
|
|
2619
3455
|
}
|
|
2620
3456
|
logRandomizeOffOnce() {
|
|
2621
3457
|
const sources = [];
|
|
@@ -2648,7 +3484,7 @@ class BunTestRunner {
|
|
|
2648
3484
|
this.logger.debug("Stryker passed an empty testFiles array; ignoring it");
|
|
2649
3485
|
}
|
|
2650
3486
|
} else {
|
|
2651
|
-
const files = [...new Set(requested.map((file) =>
|
|
3487
|
+
const files = [...new Set(requested.map((file) => path9.resolve(cwd, file)))].toSorted((a, b) => a.localeCompare(b));
|
|
2652
3488
|
this.strykerTestFiles = { cwd, files };
|
|
2653
3489
|
this.warnIfTestFilesOverridden(files, cwd);
|
|
2654
3490
|
}
|
|
@@ -2710,7 +3546,7 @@ class BunTestRunner {
|
|
|
2710
3546
|
if (this.warnedTestFilesConflict || this.testFilesOverride === undefined) {
|
|
2711
3547
|
return;
|
|
2712
3548
|
}
|
|
2713
|
-
const configured = [...new Set(this.testFilesOverride.map((file) =>
|
|
3549
|
+
const configured = [...new Set(this.testFilesOverride.map((file) => path9.resolve(cwd, file)))];
|
|
2714
3550
|
const selectedSet = new Set(selected);
|
|
2715
3551
|
if (configured.length === selectedSet.size && configured.every((file) => selectedSet.has(file))) {
|
|
2716
3552
|
return;
|
|
@@ -2780,10 +3616,16 @@ class BunTestRunner {
|
|
|
2780
3616
|
}
|
|
2781
3617
|
this.coverageFilePath = undefined;
|
|
2782
3618
|
}
|
|
3619
|
+
this.runOwnerPid ??= process.ppid;
|
|
2783
3620
|
const tempDir = await this.ensureRunTempDir();
|
|
2784
|
-
this.
|
|
3621
|
+
this.tempDirTouchedAt = Date.now();
|
|
3622
|
+
this.coverageFilePath = path9.join(tempDir, `coverage-${Date.now()}.json`);
|
|
2785
3623
|
this.logger.debug("Generating coverage preload script...");
|
|
2786
3624
|
const eagerCwd = process.cwd();
|
|
3625
|
+
const testFilesPending = this.getOrDiscoverTestFiles();
|
|
3626
|
+
testFilesPending.catch(() => {
|
|
3627
|
+
return;
|
|
3628
|
+
});
|
|
2787
3629
|
if (this.cachedEagerModules === undefined || this.cachedEagerModulesCwd !== eagerCwd) {
|
|
2788
3630
|
this.cachedEagerModules = await resolveEagerModulesFromGlobs(this.mutateGlobs);
|
|
2789
3631
|
this.cachedEagerModulesCwd = eagerCwd;
|
|
@@ -2796,10 +3638,11 @@ class BunTestRunner {
|
|
|
2796
3638
|
});
|
|
2797
3639
|
this.logger.debug("Preload script generated at: %s", this.preloadScriptPath);
|
|
2798
3640
|
await this.ensureSanitizedBunfig();
|
|
2799
|
-
const testFiles = await
|
|
3641
|
+
const testFiles = await testFilesPending;
|
|
2800
3642
|
this.logStartSummary(testFiles);
|
|
2801
3643
|
}
|
|
2802
3644
|
async ensureRunTempDir() {
|
|
3645
|
+
this.assertRunOwnerIsParent();
|
|
2803
3646
|
this.tempDir = await resolveRunTempDir();
|
|
2804
3647
|
return this.tempDir;
|
|
2805
3648
|
}
|
|
@@ -2861,6 +3704,7 @@ ${lines}`, ...ignored.flatMap((d) => [d.key.replace(/^test\./, "[test]."), d.rea
|
|
|
2861
3704
|
this.strykerTestFiles = { cwd: process.cwd(), files: selectedFiles };
|
|
2862
3705
|
}
|
|
2863
3706
|
this.testFileDurations = parseTestFileDurations(parsed.testFileDurations);
|
|
3707
|
+
this.setTestFileCoverage(TestFileCoverage.fromJson(parsed.mutantTestFiles));
|
|
2864
3708
|
this.logger.debug("Loaded dryRun registry from %s (%d entries)", registryPath, this.cachedTestNames.size);
|
|
2865
3709
|
} catch (err) {
|
|
2866
3710
|
const code = err.code;
|
|
@@ -2872,7 +3716,7 @@ ${lines}`, ...ignored.flatMap((d) => [d.key.replace(/^test\./, "[test]."), d.rea
|
|
|
2872
3716
|
}
|
|
2873
3717
|
}
|
|
2874
3718
|
buildFailureMessage(testInfo, parsed) {
|
|
2875
|
-
const parsedTest = parsed.tests.find((t) => t.name.includes(testInfo.name));
|
|
3719
|
+
const parsedTest = parsed.tests.find((t) => t.status === "failed" && t.name.includes(testInfo.name));
|
|
2876
3720
|
const baseFailureMessage = parsedTest?.failureMessage ?? testInfo.error?.message ?? defaultFailureMessage(testInfo);
|
|
2877
3721
|
const stack = testInfo.error?.stack;
|
|
2878
3722
|
return stack && !baseFailureMessage.includes(stack) ? `${baseFailureMessage}
|
|
@@ -2988,6 +3832,12 @@ ${stack}` : baseFailureMessage;
|
|
|
2988
3832
|
return { tests, testNameIndex: buildTestNameIndex(tests, bunNames) };
|
|
2989
3833
|
}
|
|
2990
3834
|
async dryRun(options) {
|
|
3835
|
+
const profile = this.profiler?.startRun("dry");
|
|
3836
|
+
const result = await this.executeDryRun(options, profile);
|
|
3837
|
+
profile?.finish(result.status);
|
|
3838
|
+
return result;
|
|
3839
|
+
}
|
|
3840
|
+
async executeDryRun(options, profile) {
|
|
2991
3841
|
const coverageAnalysis = this.resolveCoverageAnalysis(options);
|
|
2992
3842
|
this.applyDryRunTestFiles(options);
|
|
2993
3843
|
this.logger.debug("Running dry run with inspector-based coverage collection...");
|
|
@@ -3037,7 +3887,8 @@ ${stack}` : baseFailureMessage;
|
|
|
3037
3887
|
onMemoryLimitExceeded: (rssBytes) => {
|
|
3038
3888
|
this.logger.warn("bun test child exceeded maxChildRss (%d bytes observed) during dryRun — killing and reporting as a timeout for this run", rssBytes);
|
|
3039
3889
|
},
|
|
3040
|
-
onInspectorReady: inspectorUrlWaiter.onReady
|
|
3890
|
+
onInspectorReady: inspectorUrlWaiter.onReady,
|
|
3891
|
+
profile
|
|
3041
3892
|
});
|
|
3042
3893
|
const inspectorUrl = await inspectorUrlWaiter.wait(testProcess, this.inspectorTimeout);
|
|
3043
3894
|
if (!inspectorUrl) {
|
|
@@ -3070,12 +3921,14 @@ exit=%s timedOut=%s
|
|
|
3070
3921
|
},
|
|
3071
3922
|
onRequestStall: (info) => {
|
|
3072
3923
|
this.logger.warn("Inspector request unanswered after %dms even though other frames are still arriving (last frame %dms ago): %s (id=%d) — possible protocol-level stall distinct from total silence", info.msUnanswered, info.msSinceLastFrame, info.method, info.id);
|
|
3073
|
-
}
|
|
3924
|
+
},
|
|
3925
|
+
...profileInspectorHandlers(profile)
|
|
3074
3926
|
}
|
|
3075
3927
|
});
|
|
3076
3928
|
try {
|
|
3077
3929
|
await inspector.connect();
|
|
3078
3930
|
await inspector.send("TestReporter.enable", {});
|
|
3931
|
+
profile?.mark("inspector");
|
|
3079
3932
|
this.logger.debug("Inspector connected and TestReporter enabled");
|
|
3080
3933
|
} catch (error) {
|
|
3081
3934
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
@@ -3092,6 +3945,7 @@ exit=%s timedOut=%s
|
|
|
3092
3945
|
let drainRejection;
|
|
3093
3946
|
syncServer.setDrainHandler(async () => {
|
|
3094
3947
|
const drainRequestReceivedAt = Date.now();
|
|
3948
|
+
profile?.at("drainRequest");
|
|
3095
3949
|
const countsAtRequest = inspector.getEventCounts();
|
|
3096
3950
|
const gapsAtRequest = inspector.getFoundIdGaps();
|
|
3097
3951
|
this.logger.debug("Drain-request received: %d/%d/%d found/start/end events received so far; %d found-id gap(s)%s", countsAtRequest.found, countsAtRequest.start, countsAtRequest.end, gapsAtRequest.length, formatGapIdList(gapsAtRequest));
|
|
@@ -3112,6 +3966,7 @@ exit=%s timedOut=%s
|
|
|
3112
3966
|
this.logger.debug("Inspector drain round-trip rejected before any wait bound was hit: %s", drainRejection);
|
|
3113
3967
|
}
|
|
3114
3968
|
} finally {
|
|
3969
|
+
profile?.at("drainSettled");
|
|
3115
3970
|
cancelSilence();
|
|
3116
3971
|
const elapsedMs = Date.now() - drainRequestReceivedAt;
|
|
3117
3972
|
const countsAtSettle = inspector.getEventCounts();
|
|
@@ -3123,11 +3978,13 @@ exit=%s timedOut=%s
|
|
|
3123
3978
|
this.logger.debug("Signaled preload script to proceed");
|
|
3124
3979
|
const result = await testProcess;
|
|
3125
3980
|
const totalElapsedMs = Date.now() - startTime;
|
|
3981
|
+
const markStep = dryRunStepMarker(profile, result.stderr);
|
|
3126
3982
|
if (result.outputIncomplete) {
|
|
3127
3983
|
this.logger.warn("%s; the dry run may report fewer tests than ran", formatOutputIncomplete());
|
|
3128
3984
|
}
|
|
3129
3985
|
inspector.expectClose();
|
|
3130
3986
|
await inspector.waitForClose(INSPECTOR_DRAIN_TIMEOUT_MS);
|
|
3987
|
+
markStep("inspectorClosed");
|
|
3131
3988
|
const testHierarchy = inspector.getTests();
|
|
3132
3989
|
const executionOrder = inspector.getExecutionOrder();
|
|
3133
3990
|
const wasClosedUnexpectedly = inspector.wasClosedUnexpectedly;
|
|
@@ -3145,11 +4002,12 @@ exit=%s timedOut=%s
|
|
|
3145
4002
|
duplicateFoundIdCount: collisionStats.duplicateFoundIdCount
|
|
3146
4003
|
});
|
|
3147
4004
|
const parsed = parseBunTestOutput(result.stdout, result.stderr);
|
|
4005
|
+
markStep("outputParsed");
|
|
3148
4006
|
const earlyResult = this.checkDryRunProcessResult(result, parsed, testHierarchy);
|
|
3149
4007
|
if (earlyResult) {
|
|
3150
4008
|
return earlyResult;
|
|
3151
4009
|
}
|
|
3152
|
-
return await this.buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, { wasClosedUnexpectedly, closeInfo, duplicateFoundIdCount: collisionStats.duplicateFoundIdCount }, coverageAnalysis);
|
|
4010
|
+
return await this.buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, { wasClosedUnexpectedly, closeInfo, duplicateFoundIdCount: collisionStats.duplicateFoundIdCount }, coverageAnalysis, profile);
|
|
3153
4011
|
} finally {
|
|
3154
4012
|
abortController.abort();
|
|
3155
4013
|
if (this.currentAbortController === abortController) {
|
|
@@ -3167,10 +4025,12 @@ exit=%s timedOut=%s
|
|
|
3167
4025
|
this.logger.warn("Inspector data looks abnormal after the dry run: %s — test results may be incomplete; enable debug logging for the full drain/close/collision diagnostics", problems.join("; "));
|
|
3168
4026
|
}
|
|
3169
4027
|
}
|
|
3170
|
-
async buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, inspectorState, coverageAnalysis) {
|
|
3171
|
-
const { coverage: mutantCoverage, inspectorIdToProjectFile, coverageKeys } = await this.collectAndRemapCoverage(testHierarchy, executionOrder);
|
|
4028
|
+
async buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, inspectorState, coverageAnalysis, profile) {
|
|
4029
|
+
const { coverage: mutantCoverage, inspectorIdToProjectFile, coverageKeys, testFileCoverage } = await this.collectAndRemapCoverage(testHierarchy, executionOrder, profile);
|
|
4030
|
+
profile?.at("coverageMapped");
|
|
3172
4031
|
const { tests, testNameIndex } = this.buildTestsFromInspector(testHierarchy, [...new Set(executionOrder)], parsed, totalElapsedMs, inspectorIdToProjectFile);
|
|
3173
4032
|
tests.sort((a, b) => a.name.localeCompare(b.name));
|
|
4033
|
+
profile?.at("testsBuilt");
|
|
3174
4034
|
const facts = {
|
|
3175
4035
|
executionOrder,
|
|
3176
4036
|
testHierarchy,
|
|
@@ -3181,6 +4041,7 @@ exit=%s timedOut=%s
|
|
|
3181
4041
|
duplicateFoundIdCount: inspectorState.duplicateFoundIdCount
|
|
3182
4042
|
};
|
|
3183
4043
|
const gateResult = this.checkCompletenessGate(facts, parsed.summaryFailed, inspectorState.wasClosedUnexpectedly, tests, inspectorState.closeInfo, result.stderr);
|
|
4044
|
+
profile?.at("gateChecked");
|
|
3184
4045
|
if (gateResult) {
|
|
3185
4046
|
return gateResult;
|
|
3186
4047
|
}
|
|
@@ -3188,7 +4049,9 @@ exit=%s timedOut=%s
|
|
|
3188
4049
|
if (coverageResult) {
|
|
3189
4050
|
return coverageResult;
|
|
3190
4051
|
}
|
|
3191
|
-
|
|
4052
|
+
profile?.at("coverageChecked");
|
|
4053
|
+
await this.buildAndPersistTestRegistry(tests, testNameIndex, testFileCoverage);
|
|
4054
|
+
profile?.at("registryWritten");
|
|
3192
4055
|
this.warnOnUnidentifiedDryRunFailure(result, parsed, tests);
|
|
3193
4056
|
this.warnOnTightDryRunTimeout(totalElapsedMs);
|
|
3194
4057
|
return {
|
|
@@ -3211,7 +4074,7 @@ exit=%s timedOut=%s
|
|
|
3211
4074
|
}
|
|
3212
4075
|
return null;
|
|
3213
4076
|
}
|
|
3214
|
-
const coverageDir = this.coverageFilePath === undefined ? tmpdir2() :
|
|
4077
|
+
const coverageDir = this.coverageFilePath === undefined ? tmpdir2() : path9.dirname(this.coverageFilePath);
|
|
3215
4078
|
const parts = [
|
|
3216
4079
|
`stryker-bun-runner: the dry run produced no mutant coverage data — the coverage file ${this.coverageFilePath ?? "(none configured)"} was missing, unreadable or empty. ` + "Without it Stryker runs the full test suite for every mutant, which is far slower than running each mutant's covering tests. " + "Likely causes: the coverage preload never ran (check for a [test].preload in bunfig.toml or bun.bunArgs that replaces or bypasses it), " + `${coverageDir} is not writable, or the bun test child exited before its final afterAll hook wrote the file (e.g. a test calls process.exit).`
|
|
3217
4080
|
];
|
|
@@ -3236,7 +4099,7 @@ ${preloadLines.join(`
|
|
|
3236
4099
|
this.logger.warn("The dry run took %dms, more than 80%% of bun.timeout (%dms). bun.timeout bounds the dry run (mutant runs use Stryker's per-mutant timeout instead); a dry run that outgrows bun.timeout plus the drain-handshake allowance is killed — raise bun.timeout", elapsedMs, this.timeout);
|
|
3237
4100
|
}
|
|
3238
4101
|
}
|
|
3239
|
-
async buildAndPersistTestRegistry(tests, testNameIndex) {
|
|
4102
|
+
async buildAndPersistTestRegistry(tests, testNameIndex, testFileCoverage) {
|
|
3240
4103
|
this.cachedTestNames = new Set(tests.map((t) => t.name));
|
|
3241
4104
|
if (tests.length !== this.cachedTestNames.size) {
|
|
3242
4105
|
const nameCount = new Map;
|
|
@@ -3261,6 +4124,7 @@ ${preloadLines.join(`
|
|
|
3261
4124
|
this.testNameIndex = testNameIndex;
|
|
3262
4125
|
this.testFileDurations = sumDurationsByFile(tests);
|
|
3263
4126
|
this.logger.debug("Recorded dry-run durations for %d test file(s) to order mutant runs cheapest-first", this.testFileDurations.size);
|
|
4127
|
+
this.setTestFileCoverage(testFileCoverage);
|
|
3264
4128
|
try {
|
|
3265
4129
|
const registryPath = await this.resolveRegistryPath();
|
|
3266
4130
|
const tmpPath = `${registryPath}.tmp`;
|
|
@@ -3271,7 +4135,8 @@ ${preloadLines.join(`
|
|
|
3271
4135
|
baseNameIndex: [...this.baseNameIndex.entries()],
|
|
3272
4136
|
testNameIndex: [...testNameIndex.entries()],
|
|
3273
4137
|
testFiles: this.selectedTestFilesFor(process.cwd()),
|
|
3274
|
-
testFileDurations: [...this.testFileDurations.entries()]
|
|
4138
|
+
testFileDurations: [...this.testFileDurations.entries()],
|
|
4139
|
+
mutantTestFiles: testFileCoverage?.toJSON()
|
|
3275
4140
|
});
|
|
3276
4141
|
await writePrivateFile(tmpPath, registryData);
|
|
3277
4142
|
this.lastRegistryTmpPath = tmpPath;
|
|
@@ -3305,7 +4170,9 @@ ${preloadLines.join(`
|
|
|
3305
4170
|
}
|
|
3306
4171
|
async mutantRun(options) {
|
|
3307
4172
|
const startedAt = Date.now();
|
|
4173
|
+
const profile = this.profiler?.startRun("mutant", options.activeMutant.id);
|
|
3308
4174
|
this.logger.debug("Running mutant run for mutant %s", options.activeMutant.id);
|
|
4175
|
+
this.keepRunTempDirFresh(startedAt);
|
|
3309
4176
|
const requestedFilter = options.testFilter ?? [];
|
|
3310
4177
|
if (!this.cachedTestNames) {
|
|
3311
4178
|
await this.loadRegistryFile(options.activeMutant.id);
|
|
@@ -3320,11 +4187,12 @@ ${preloadLines.join(`
|
|
|
3320
4187
|
const { localRegistry, localBaseIndex } = this.buildLocalTestFilterIndex(filterIds);
|
|
3321
4188
|
const mutantCwd = process.cwd();
|
|
3322
4189
|
const sanitizedBunfig = this.sanitizedBunfigPath && this.sanitizedBunfigCwd === mutantCwd ? this.sanitizedBunfigPath : await this.ensureSanitizedBunfig();
|
|
3323
|
-
const bunfigPath =
|
|
4190
|
+
const bunfigPath = mutantRunBunfigPath(sanitizedBunfig);
|
|
3324
4191
|
this.logRandomizeOffOnce();
|
|
3325
4192
|
this.effectiveTestFiles = await this.getOrDiscoverTestFiles();
|
|
3326
4193
|
const strykerTimeoutMs = isUsableTimeout(options.timeout) ? options.timeout : undefined;
|
|
3327
4194
|
const limitMs = strykerTimeoutMs === undefined ? this.timeout : limitFromStrykerTimeout(strykerTimeoutMs);
|
|
4195
|
+
const sourceCoverage = this.ordersLikelyKillersFirst(options, filterIds.length) ? await this.sourceCoverageFor(options.sandboxFileName) : undefined;
|
|
3328
4196
|
const result = await this.executeMutantRun({
|
|
3329
4197
|
options,
|
|
3330
4198
|
bunfigPath,
|
|
@@ -3333,9 +4201,12 @@ ${preloadLines.join(`
|
|
|
3333
4201
|
coveringTestCount: filterIds.length,
|
|
3334
4202
|
deadline: startedAt + limitMs,
|
|
3335
4203
|
strykerTimeoutMs,
|
|
3336
|
-
testFileScope
|
|
4204
|
+
testFileScope,
|
|
4205
|
+
sourceCoverage,
|
|
4206
|
+
profile
|
|
3337
4207
|
}, testNamePattern, this.resolveCoveringTestFiles(filterIds));
|
|
3338
4208
|
this.mutantRunsByStatus[result.status]++;
|
|
4209
|
+
profile?.finish(result.status);
|
|
3339
4210
|
return result;
|
|
3340
4211
|
}
|
|
3341
4212
|
async resolveTestFileFilter(filter) {
|
|
@@ -3350,7 +4221,7 @@ ${preloadLines.join(`
|
|
|
3350
4221
|
const cwd = process.cwd();
|
|
3351
4222
|
const exist = await Promise.all(entries.map(async (entry) => {
|
|
3352
4223
|
try {
|
|
3353
|
-
const stat = await fsPromises2.stat(
|
|
4224
|
+
const stat = await fsPromises2.stat(path9.resolve(cwd, entry));
|
|
3354
4225
|
return stat.isFile();
|
|
3355
4226
|
} catch {
|
|
3356
4227
|
return false;
|
|
@@ -3364,8 +4235,9 @@ ${preloadLines.join(`
|
|
|
3364
4235
|
const abortController = new AbortController;
|
|
3365
4236
|
this.currentAbortController = abortController;
|
|
3366
4237
|
const hitLimitToken = newHitLimitToken();
|
|
3367
|
-
const ordered = this.
|
|
4238
|
+
const ordered = this.orderForMutantRun(ctx.testFileScope ?? (testNamePattern === undefined ? this.effectiveTestFiles : coveringTestFiles ?? this.effectiveTestFiles), ctx);
|
|
3368
4239
|
const testFiles = this.fitTestFiles(ordered, ctx.testFileScope === undefined ? this.explicitTestFilesSource(process.cwd()) : "Stryker's testFiles option");
|
|
4240
|
+
ctx.profile?.setScope(mutantRunScope(ctx.testFileScope !== undefined, testNamePattern, ctx.coveringTestCount));
|
|
3369
4241
|
let result;
|
|
3370
4242
|
try {
|
|
3371
4243
|
result = await runBunTests({
|
|
@@ -3389,7 +4261,8 @@ ${preloadLines.join(`
|
|
|
3389
4261
|
maxSpawnDepth: this.maxSpawnDepth,
|
|
3390
4262
|
onMemoryLimitExceeded: (rssBytes) => {
|
|
3391
4263
|
this.mutantWarnings.warn(MUTANT_WARN_KIND.memoryLimit, options.activeMutant.id, "bun test child exceeded maxChildRss (%d bytes observed) during mutant run %s — killing and reporting as a timeout for this mutant", rssBytes, options.activeMutant.id);
|
|
3392
|
-
}
|
|
4264
|
+
},
|
|
4265
|
+
profile: ctx.profile
|
|
3393
4266
|
});
|
|
3394
4267
|
} finally {
|
|
3395
4268
|
if (this.currentAbortController === abortController) {
|
|
@@ -3419,6 +4292,9 @@ ${preloadLines.join(`
|
|
|
3419
4292
|
}
|
|
3420
4293
|
return this.buildMutantKilledResult(result, parsed, localRegistry, localBaseIndex, options.activeMutant.id);
|
|
3421
4294
|
}
|
|
4295
|
+
if (!parsed.summaryPrinted) {
|
|
4296
|
+
return this.classifyEarlyCleanExit(result, parsed, localRegistry, localBaseIndex, options.activeMutant.id);
|
|
4297
|
+
}
|
|
3422
4298
|
return {
|
|
3423
4299
|
status: MutantRunStatus.Survived,
|
|
3424
4300
|
nrOfTests: parsed.totalTests
|
|
@@ -3451,7 +4327,7 @@ ${preloadLines.join(`
|
|
|
3451
4327
|
this.mutantWarnings.warn(MUTANT_WARN_KIND.inconclusiveTimeout, mutantId, "Mutant %s: inconclusive timeout, scoring as Error rather than Timeout: %s", mutantId, errorMessage);
|
|
3452
4328
|
return { status: MutantRunStatus.Error, errorMessage };
|
|
3453
4329
|
}
|
|
3454
|
-
buildMutantKilledResult(result, parsed, localRegistry, localBaseIndex, mutantId) {
|
|
4330
|
+
buildMutantKilledResult(result, parsed, localRegistry, localBaseIndex, mutantId, earlyExit = false) {
|
|
3455
4331
|
const rawFailedNames = parsed.tests.filter((test) => test.status === "failed").map((test) => normalizeTestName(test.name));
|
|
3456
4332
|
if (result.signal && rawFailedNames.length === 0) {
|
|
3457
4333
|
return this.buildSignalErrorResult(result, mutantId, `bun test terminated by ${result.signal} before any test reported a failure`);
|
|
@@ -3466,6 +4342,9 @@ ${preloadLines.join(`
|
|
|
3466
4342
|
if (result.signal && killedBy.length === 0) {
|
|
3467
4343
|
return this.buildSignalErrorResult(result, mutantId, `bun test terminated by ${result.signal}; the ${rawFailedNames.length} failing test(s) reported could not be attributed to a known test`);
|
|
3468
4344
|
}
|
|
4345
|
+
if (earlyExit && killedBy.length === 0) {
|
|
4346
|
+
return this.buildEarlyExitErrorResult(result, mutantId, `the ${rawFailedNames.length} failing test(s) it reported could not be attributed to a known test`);
|
|
4347
|
+
}
|
|
3469
4348
|
if (killedBy.length === 0) {
|
|
3470
4349
|
this.mutantWarnings.warn(MUTANT_WARN_KIND.noKillerIdentified, mutantId, "Mutant %s: no killing test identifiable — emitting empty killedBy; " + `this mutant will re-run on every incremental run
|
|
3471
4350
|
` + `exit=%s
|
|
@@ -3511,6 +4390,20 @@ ${preloadLines.join(`
|
|
|
3511
4390
|
errorMessage: `bun test exited with code ${result.exitCode} but reported no failing test and no fail/error count, so there is no evidence a test detected this mutant: ${output}`
|
|
3512
4391
|
};
|
|
3513
4392
|
}
|
|
4393
|
+
classifyEarlyCleanExit(result, parsed, localRegistry, localBaseIndex, mutantId) {
|
|
4394
|
+
if (parsed.tests.some((test) => test.status === "failed")) {
|
|
4395
|
+
return this.buildMutantKilledResult(result, parsed, localRegistry, localBaseIndex, mutantId, true);
|
|
4396
|
+
}
|
|
4397
|
+
return this.buildEarlyExitErrorResult(result, mutantId, "no test reported a failure");
|
|
4398
|
+
}
|
|
4399
|
+
buildEarlyExitErrorResult(result, mutantId, evidence) {
|
|
4400
|
+
const output = stripAnsi(`${result.stdout}
|
|
4401
|
+
${result.stderr}`).trim().slice(-500) || "(no output)";
|
|
4402
|
+
const incomplete = result.outputIncomplete ? " (its output was still held open by a process it started, so the summary may also have been cut off)" : "";
|
|
4403
|
+
const errorMessage = `bun exited 0 before running every selected test: it printed no test summary${incomplete}, so a test, hook or module most likely called process.exit(0) and the tests after it never ran; the mutant changed what the suite does, but ${evidence}: ${output}`;
|
|
4404
|
+
this.mutantWarnings.warn(MUTANT_WARN_KIND.earlyExit, mutantId, "Mutant %s: %s — scoring as Error rather than Survived", mutantId, errorMessage);
|
|
4405
|
+
return { status: MutantRunStatus.Error, errorMessage };
|
|
4406
|
+
}
|
|
3514
4407
|
checkDryRunProcessResult(result, parsed, testHierarchy) {
|
|
3515
4408
|
if (result.timedOut) {
|
|
3516
4409
|
if (result.memoryLimitExceeded !== true) {
|
|
@@ -3595,7 +4488,7 @@ ${stderr.slice(-500)}`);
|
|
|
3595
4488
|
errorMessage
|
|
3596
4489
|
};
|
|
3597
4490
|
}
|
|
3598
|
-
async collectAndRemapCoverage(testHierarchy, executionOrder) {
|
|
4491
|
+
async collectAndRemapCoverage(testHierarchy, executionOrder, profile) {
|
|
3599
4492
|
const testMap = new Map(testHierarchy.map((t) => [t.id, t]));
|
|
3600
4493
|
if (!this.coverageFilePath) {
|
|
3601
4494
|
return { coverage: undefined, inspectorIdToProjectFile: new Map, coverageKeys: undefined };
|
|
@@ -3604,13 +4497,20 @@ ${stderr.slice(-500)}`);
|
|
|
3604
4497
|
collectCoverage(this.coverageFilePath, this.logger),
|
|
3605
4498
|
collectLateHits(this.coverageFilePath, this.logger)
|
|
3606
4499
|
]);
|
|
4500
|
+
profile?.at("coverageRead");
|
|
3607
4501
|
await cleanupCoverageFile(this.coverageFilePath);
|
|
3608
4502
|
if (!rawCoverage) {
|
|
3609
4503
|
return { coverage: undefined, inspectorIdToProjectFile: new Map, coverageKeys: undefined };
|
|
3610
4504
|
}
|
|
4505
|
+
const testFileCoverage = TestFileCoverage.fromPerTest(rawCoverage.perTest);
|
|
3611
4506
|
const { coverage, inspectorIdToProjectFile, counterKeyToTestName, rawKeyCount, orphanedKeyCount } = mapCoverageToInspectorIds(rawCoverage, executionOrder, testMap, this.logger);
|
|
3612
4507
|
this.emitCoverageBleedWarnings(lateHits, counterKeyToTestName);
|
|
3613
|
-
return {
|
|
4508
|
+
return {
|
|
4509
|
+
coverage,
|
|
4510
|
+
inspectorIdToProjectFile,
|
|
4511
|
+
coverageKeys: { keyCount: rawKeyCount, unmatchedKeyCount: orphanedKeyCount },
|
|
4512
|
+
testFileCoverage
|
|
4513
|
+
};
|
|
3614
4514
|
}
|
|
3615
4515
|
emitCoverageBleedWarnings(lateHits, counterKeyToTestName) {
|
|
3616
4516
|
const listed = lateHits.slice(0, MAX_COVERAGE_BLEED_WARNINGS);
|
|
@@ -3691,10 +4591,18 @@ ${stderr.slice(-500)}`);
|
|
|
3691
4591
|
this.mutantRunsByStatus = emptyMutantRunCounts();
|
|
3692
4592
|
this.fullSuiteFallbacks = 0;
|
|
3693
4593
|
}
|
|
4594
|
+
writeProfileSummary() {
|
|
4595
|
+
try {
|
|
4596
|
+
this.profiler?.writeSummary();
|
|
4597
|
+
} catch (error) {
|
|
4598
|
+
this.logger.warn("Could not write the run profile's summary: %s", error instanceof Error ? error.message : String(error));
|
|
4599
|
+
}
|
|
4600
|
+
}
|
|
3694
4601
|
async dispose() {
|
|
3695
4602
|
this.logger.debug("Disposing BunTestRunner");
|
|
3696
4603
|
this.logMutantRunSummary();
|
|
3697
4604
|
this.mutantWarnings.flush();
|
|
4605
|
+
this.writeProfileSummary();
|
|
3698
4606
|
if (this.currentAbortController) {
|
|
3699
4607
|
this.logger.debug("Aborting in-flight bun test child during dispose");
|
|
3700
4608
|
this.currentAbortController.abort();
|
|
@@ -3725,8 +4633,8 @@ ${stderr.slice(-500)}`);
|
|
|
3725
4633
|
}
|
|
3726
4634
|
// src/checker-tsconfig.ts
|
|
3727
4635
|
import { readFile as readFile6, rename as rename2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
3728
|
-
import { createRequire } from "node:module";
|
|
3729
|
-
import
|
|
4636
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
4637
|
+
import path10 from "node:path";
|
|
3730
4638
|
import { glob as glob2 } from "tinyglobby";
|
|
3731
4639
|
var DEFAULT_MUTATE_PATTERNS = ["{src,lib}/**"];
|
|
3732
4640
|
var MUTATION_RANGE_RE = /:\d+(?::\d+)?-\d+(?::\d+)?$/;
|
|
@@ -3736,7 +4644,7 @@ var LOG_PREFIX = "[Stryker] withTestFilesExcludedFromTypeCheck: ";
|
|
|
3736
4644
|
var MAX_QUOTED_ERRORS = 3;
|
|
3737
4645
|
function loadTypeScript(cwd) {
|
|
3738
4646
|
try {
|
|
3739
|
-
return
|
|
4647
|
+
return createRequire2(path10.join(cwd, "package.json"))("typescript");
|
|
3740
4648
|
} catch {
|
|
3741
4649
|
return;
|
|
3742
4650
|
}
|
|
@@ -3763,7 +4671,7 @@ async function findTestFiles(config, cwd) {
|
|
|
3763
4671
|
for (const relativeFiles of [await discoverTestFiles(cwd, undefined, sourceBunfig), bun.testFiles]) {
|
|
3764
4672
|
if (relativeFiles) {
|
|
3765
4673
|
for (const file of relativeFiles) {
|
|
3766
|
-
testFiles.add(
|
|
4674
|
+
testFiles.add(path10.resolve(cwd, file));
|
|
3767
4675
|
}
|
|
3768
4676
|
}
|
|
3769
4677
|
}
|
|
@@ -3841,12 +4749,12 @@ function derivedHeader(source) {
|
|
|
3841
4749
|
`);
|
|
3842
4750
|
}
|
|
3843
4751
|
function renderDerivedTsconfig(sourcePath, derivedPath, project, entryPoints) {
|
|
3844
|
-
const source =
|
|
4752
|
+
const source = path10.basename(sourcePath);
|
|
3845
4753
|
const body = {
|
|
3846
4754
|
extends: `./${source}`,
|
|
3847
4755
|
...project.options.declarationDir !== undefined && { compilerOptions: { declarationDir: null } },
|
|
3848
4756
|
include: [],
|
|
3849
|
-
files: entryPoints.map((file) =>
|
|
4757
|
+
files: entryPoints.map((file) => path10.relative(path10.dirname(derivedPath), file))
|
|
3850
4758
|
};
|
|
3851
4759
|
return `${derivedHeader(source)}${JSON.stringify(body, null, 2)}
|
|
3852
4760
|
`;
|
|
@@ -3860,8 +4768,8 @@ async function withTestFilesExcludedFromTypeCheck(config, { cwd = process.cwd()
|
|
|
3860
4768
|
if (!ts) {
|
|
3861
4769
|
return leaveUnchanged(config, `typescript cannot be loaded from ${cwd}; install it there`);
|
|
3862
4770
|
}
|
|
3863
|
-
const sourcePath =
|
|
3864
|
-
const shownSource =
|
|
4771
|
+
const sourcePath = path10.resolve(cwd, config.tsconfigFile ?? "tsconfig.json");
|
|
4772
|
+
const shownSource = path10.relative(cwd, sourcePath);
|
|
3865
4773
|
const read = readProject(ts, sourcePath, shownSource);
|
|
3866
4774
|
if ("problem" in read) {
|
|
3867
4775
|
return leaveUnchanged(config, read.problem);
|
|
@@ -3878,10 +4786,10 @@ async function withTestFilesExcludedFromTypeCheck(config, { cwd = process.cwd()
|
|
|
3878
4786
|
if (entryPoints.length === 0) {
|
|
3879
4787
|
return leaveUnchanged(config, `${shownSource} would have no files left once test files are excluded`);
|
|
3880
4788
|
}
|
|
3881
|
-
const derivedPath =
|
|
3882
|
-
const shownDerived =
|
|
4789
|
+
const derivedPath = path10.join(path10.dirname(sourcePath), `${path10.basename(sourcePath, ".json")}${DERIVED_SUFFIX}`);
|
|
4790
|
+
const shownDerived = path10.relative(cwd, derivedPath);
|
|
3883
4791
|
const text = renderDerivedTsconfig(sourcePath, derivedPath, project, entryPoints);
|
|
3884
|
-
const derivedProject = ts.parseJsonSourceFileConfigFileContent(ts.parseJsonText(derivedPath, text), ts.sys,
|
|
4792
|
+
const derivedProject = ts.parseJsonSourceFileConfigFileContent(ts.parseJsonText(derivedPath, text), ts.sys, path10.dirname(derivedPath), undefined, derivedPath);
|
|
3885
4793
|
const derived = createProgram(ts, derivedProject, original);
|
|
3886
4794
|
const newErrors = findNewErrors(derived, original, testFiles);
|
|
3887
4795
|
if (newErrors.length > 0) {
|
|
@@ -3903,6 +4811,7 @@ async function withTestFilesExcludedFromTypeCheck(config, { cwd = process.cwd()
|
|
|
3903
4811
|
}
|
|
3904
4812
|
|
|
3905
4813
|
// src/index.ts
|
|
4814
|
+
removeRunTempDirsOnExit();
|
|
3906
4815
|
var strykerPlugins = [
|
|
3907
4816
|
declareClassPlugin(PluginKind.TestRunner, "bun", BunTestRunner)
|
|
3908
4817
|
];
|