@hughescr/stryker-bun-runner 1.3.0 → 1.3.2
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 +37 -3
- package/dist/index.d.ts +48 -9
- package/dist/index.js +109 -65
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,8 +65,11 @@ The plugin uses Bun's Inspector Protocol (WebSocket) to:
|
|
|
65
65
|
2. **Track execution** - Listens for TestReporter events to correlate test runs with coverage
|
|
66
66
|
3. **Sequential execution** - Uses `--concurrency=1` to ensure reliable coverage correlation
|
|
67
67
|
4. **Build hierarchy** - Reconstructs test names from describe blocks for accurate reporting
|
|
68
|
+
5. **Targeted mutant runs** - Runs only the tests that covered each mutant (via `--test-name-pattern`); bails after the first failure unless Stryker's `disableBail` option is set (dry runs never bail, since the full suite must run for coverage). Any bail flag in `bun.bunArgs` is ignored — bail is decided solely by the runner.
|
|
68
69
|
|
|
69
|
-
This approach provides reliable test-to-mutant correlation, even with multiple test files.
|
|
70
|
+
Oversized covering-test patterns (over 100,000 UTF-8 bytes) fall back to running the full suite, to stay within OS argument-length limits. This approach provides reliable test-to-mutant correlation, even with multiple test files.
|
|
71
|
+
|
|
72
|
+
A second full-suite fallback happens at run time: a `--test-name-pattern` that matches zero tests triggers a one-shot full-suite retry (see [Diagnostic warnings worth grepping for in CI](#diagnostic-warnings-worth-grepping-for-in-ci)).
|
|
70
73
|
|
|
71
74
|
## Options
|
|
72
75
|
|
|
@@ -76,7 +79,7 @@ This approach provides reliable test-to-mutant correlation, even with multiple t
|
|
|
76
79
|
| `bun.timeout` | `number` | `10000` | Timeout per test in milliseconds |
|
|
77
80
|
| `bun.inspectorTimeout` | `number` | `5000` | Timeout for Inspector WebSocket connection in milliseconds |
|
|
78
81
|
| `bun.env` | `object` | `undefined` | Additional environment variables to pass to bun test |
|
|
79
|
-
| `bun.bunArgs` | `string[]` | `undefined` | Additional bun test flags (e.g., `['--
|
|
82
|
+
| `bun.bunArgs` | `string[]` | `undefined` | Additional bun test flags (e.g., `['--only']`). Bail flags (`--bail`, `--bail=<N>`, or a space-separated `--bail <N>`) are ignored here — bail is fully managed by the runner via Stryker's `disableBail` option (see [How It Works](#how-it-works)). |
|
|
80
83
|
| `bun.testFiles` | `string[]` | `undefined` | Explicit list of test file paths (absolute or relative to cwd). When provided, skips auto-discovery and uses this list verbatim. Relative paths resolve against the bun subprocess's cwd. Useful for restricting mutation testing to a subset of test files. |
|
|
81
84
|
| `bun.smol` | `boolean` | `false` | Pass Bun's `--smol` flag to every child: a smaller JavaScriptCore heap at some cost to speed. Recommended on memory-constrained machines — see [Memory model](#memory-model). |
|
|
82
85
|
| `bun.maxChildRss` | `number` | `undefined` | Soft memory ceiling in bytes for each child's RSS. A child that exceeds it is killed and the run reported as a clean timeout for that mutant. See [Memory containment](#memory-containment). |
|
|
@@ -90,7 +93,7 @@ bun: {
|
|
|
90
93
|
timeout: 30000, // 30 second test timeout
|
|
91
94
|
inspectorTimeout: 10000, // 10 second connection timeout
|
|
92
95
|
env: { DEBUG: 'true' }, // Extra environment variables
|
|
93
|
-
bunArgs: ['--
|
|
96
|
+
bunArgs: ['--only'], // Extra bun test flags (bail flags here are ignored — see Options table)
|
|
94
97
|
smol: true, // Smaller JSC heap, some speed cost — see Memory model
|
|
95
98
|
maxChildRss: 1_500_000_000, // Kill+report-timeout a child using more than ~1.5GB RSS
|
|
96
99
|
rssCheckIntervalMs: 1000, // How often to poll RSS when maxChildRss is set
|
|
@@ -167,6 +170,37 @@ export default {
|
|
|
167
170
|
};
|
|
168
171
|
```
|
|
169
172
|
|
|
173
|
+
## Diagnostic warnings worth grepping for in CI
|
|
174
|
+
|
|
175
|
+
The runner logs three warnings that flag when a mutant run's `--test-name-pattern`
|
|
176
|
+
couldn't be built or applied with full fidelity. None of them indicate a wrong
|
|
177
|
+
mutation-testing verdict by themselves, but they're worth grepping your CI logs for
|
|
178
|
+
because they mark where the runner fell back to less-precise behavior:
|
|
179
|
+
|
|
180
|
+
- **`--test-name-pattern matched 0 tests`** — the pattern for a mutant's covering
|
|
181
|
+
tests matched nothing across the whole run (usually because a mutant changed a
|
|
182
|
+
value interpolated into an `it.each` title). The runner retries once with the
|
|
183
|
+
full suite rather than reporting a false kill, so the eventual verdict is still
|
|
184
|
+
genuine — if the retry itself also matches zero tests (or the zero-match came
|
|
185
|
+
from a user-supplied `--test-name-pattern` in `bunArgs`, which is never retried),
|
|
186
|
+
the mutant is classified as an infrastructure `Error`, never a kill. Every
|
|
187
|
+
occurrence is worth spot-checking that it's explained by an interpolated-title
|
|
188
|
+
change, not a real pattern gap.
|
|
189
|
+
- **`no exact-name registry available`** — this worker couldn't load the shared
|
|
190
|
+
dry-run test-name registry, so every alternative in that mutant's pattern used
|
|
191
|
+
the lossy `' > '`-collapsing reconstruction instead of Bun's exact matching
|
|
192
|
+
names. Tests whose titles legitimately contain `" > "` may have been silently
|
|
193
|
+
excluded from that run.
|
|
194
|
+
- **`missing from exact-name registry`** — the registry loaded, but one or more
|
|
195
|
+
`testFilter` ids for this mutant weren't in it (falls back to the same lossy
|
|
196
|
+
reconstruction for just those ids, listing up to 5 of the missing ids).
|
|
197
|
+
|
|
198
|
+
The last two matter because Bun only errors when a pattern matches **zero** tests
|
|
199
|
+
across the whole run; a *partial* miss — some alternatives hit, others silently
|
|
200
|
+
don't — exits 0 with no error text at all. These two warns are the only signal
|
|
201
|
+
that a partial silent drop was possible for a given mutant run, so seeing either
|
|
202
|
+
of them in a clean run's logs is worth investigating before trusting the score.
|
|
203
|
+
|
|
170
204
|
## Known Limitations
|
|
171
205
|
|
|
172
206
|
- **Sequential execution required** - Tests run with `--concurrency=1` to ensure accurate coverage tracking. This is slower than parallel execution but necessary for correct test-to-mutant correlation.
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare class BunTestRunner implements TestRunner {
|
|
|
31
31
|
private tempDir?;
|
|
32
32
|
private cachedTestNames?;
|
|
33
33
|
private baseNameIndex?;
|
|
34
|
+
private testNameIndex?;
|
|
34
35
|
private cachedTestFiles?;
|
|
35
36
|
private cachedTestFilesCwd?;
|
|
36
37
|
private cachedEagerModules?;
|
|
@@ -84,17 +85,26 @@ export declare class BunTestRunner implements TestRunner {
|
|
|
84
85
|
private ensureSanitizedBunfig;
|
|
85
86
|
/**
|
|
86
87
|
* Load the shared dryRun registry written by the one worker that ran dryRun.
|
|
87
|
-
* Populates this.cachedTestNames
|
|
88
|
-
* mutantRun calls on this worker can resolve killedBy names
|
|
89
|
-
*
|
|
88
|
+
* Populates this.cachedTestNames, this.baseNameIndex, and this.testNameIndex
|
|
89
|
+
* so that subsequent mutantRun calls on this worker can resolve killedBy names
|
|
90
|
+
* and build exact --test-name-pattern alternatives, even for static-coverage
|
|
91
|
+
* mutants where testFilter is empty.
|
|
90
92
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
+
* Loading is all-or-nothing: a wrong version or a malformed field rejects the
|
|
94
|
+
* whole file (never a half-initialised registry). Failures are non-fatal — the
|
|
95
|
+
* worker falls back to raw console names and the lossy pattern reconstruction,
|
|
96
|
+
* and a warning is logged so the issue is visible.
|
|
93
97
|
*/
|
|
94
98
|
private loadRegistryFile;
|
|
95
99
|
/**
|
|
96
100
|
* Build test results from inspector data.
|
|
97
101
|
*
|
|
102
|
+
* Also returns a testNameIndex mapping each FINAL test id (dedup ' [N]'
|
|
103
|
+
* suffix included) to Bun's exact internal matching name (TestInfo.bunName)
|
|
104
|
+
* for --test-name-pattern generation. Tests without a bunName — console-
|
|
105
|
+
* fallback results and unknown-inspectorId placeholders — get no index entry
|
|
106
|
+
* and stay on the lossy pattern reconstruction path (never worse than before).
|
|
107
|
+
*
|
|
98
108
|
* @param inspectorIdToProjectFile - Optional mapping from inspector ID to project file path.
|
|
99
109
|
* When provided, the project file is used for TestResult.id, name, and fileName instead of
|
|
100
110
|
* testInfo.url. This is important for tests defined via helpers (e.g. RuleTester.run()) where
|
|
@@ -107,18 +117,41 @@ export declare class BunTestRunner implements TestRunner {
|
|
|
107
117
|
dryRun(): Promise<DryRunResult>;
|
|
108
118
|
/**
|
|
109
119
|
* Build the in-memory test name cache and base-name index, then atomically
|
|
110
|
-
* persist them
|
|
111
|
-
*
|
|
120
|
+
* persist them — together with the exact-name testNameIndex from
|
|
121
|
+
* buildTestsFromInspector — to a well-known file so other worker processes
|
|
122
|
+
* can lazy-load them when handling static-coverage mutants (testFilter is
|
|
123
|
+
* empty for those) and build exact --test-name-pattern alternatives.
|
|
112
124
|
*
|
|
113
125
|
* Writing to a .tmp path then renaming is atomic on POSIX: readers always see
|
|
114
126
|
* either the previous complete file or the new one — never a partial write.
|
|
115
127
|
*/
|
|
116
128
|
private buildAndPersistTestRegistry;
|
|
117
129
|
/**
|
|
130
|
+
* Lossy-visibility warns for a mutant run's --test-name-pattern.
|
|
131
|
+
*
|
|
132
|
+
* Bun exits 0 on a PARTIAL pattern miss (verified live, bun 1.3.14),
|
|
133
|
+
* silently dropping the missed tests — so these warns are the only signal
|
|
134
|
+
* that some covering-test alternatives were built via the lossy
|
|
135
|
+
* ' > '-collapsing reconstruction instead of exact bun names. Must be called
|
|
136
|
+
* AFTER the registry lazy-load so this.testNameIndex reflects reality.
|
|
137
|
+
*/
|
|
138
|
+
private warnLossyPatternAlternatives;
|
|
139
|
+
/**
|
|
118
140
|
* Run tests with an active mutant
|
|
119
141
|
*/
|
|
120
142
|
mutantRun(options: MutantRunOptions): Promise<MutantRunResult>;
|
|
121
143
|
/**
|
|
144
|
+
* Spawn bun for a mutant run and interpret the result. Extracted from
|
|
145
|
+
* mutantRun so that a --test-name-pattern which matched 0 tests can retry
|
|
146
|
+
* once with the full suite (testNamePattern undefined) while reusing the
|
|
147
|
+
* SAME localRegistry/localBaseIndex built from the original testFilter for
|
|
148
|
+
* killedBy resolution — avoiding both a false Killed and redundant setup.
|
|
149
|
+
* The retry always recurses with testNamePattern undefined, so the retry
|
|
150
|
+
* gate's first conjunct is false on that call: recursion is bounded to
|
|
151
|
+
* depth 1 by construction, never a retry-of-a-retry.
|
|
152
|
+
*/
|
|
153
|
+
private executeMutantRun;
|
|
154
|
+
/**
|
|
122
155
|
* Build the MutantRunResult for a killed mutant (non-zero exit code).
|
|
123
156
|
* Handles runtime error detection and killedBy resolution.
|
|
124
157
|
*/
|
|
@@ -196,8 +229,14 @@ export interface BunTestRunnerOptions {
|
|
|
196
229
|
*/
|
|
197
230
|
env?: Record<string, string>;
|
|
198
231
|
/**
|
|
199
|
-
* Additional bun test flags to pass
|
|
200
|
-
*
|
|
232
|
+
* Additional bun test flags to pass.
|
|
233
|
+
*
|
|
234
|
+
* Bail flags (`--bail`, `--bail=<N>`, or a space-separated `--bail <N>`) are
|
|
235
|
+
* stripped if present — bail is fully managed by the runner based on
|
|
236
|
+
* Stryker's `disableBail` option, so a bail flag configured here would
|
|
237
|
+
* otherwise silently override that decision.
|
|
238
|
+
*
|
|
239
|
+
* @example ['--only', '--verbose']
|
|
201
240
|
*/
|
|
202
241
|
bunArgs?: string[];
|
|
203
242
|
/**
|
package/dist/index.js
CHANGED
|
@@ -5618,30 +5618,12 @@ function mapCoverageToInspectorIds(rawCoverage, executionOrder, testHierarchy, l
|
|
|
5618
5618
|
}
|
|
5619
5619
|
return { coverage: rawCoverage, inspectorIdToProjectFile: new Map };
|
|
5620
5620
|
}
|
|
5621
|
-
function
|
|
5622
|
-
const appearances = new Map;
|
|
5623
|
-
for (const [, counts] of perTestEntries) {
|
|
5624
|
-
for (const mutantId of Object.keys(counts)) {
|
|
5625
|
-
appearances.set(mutantId, (appearances.get(mutantId) ?? 0) + 1);
|
|
5626
|
-
}
|
|
5627
|
-
}
|
|
5628
|
-
return appearances;
|
|
5629
|
-
}
|
|
5630
|
-
function buildPromoteToStaticSet(existingStaticKeys, perTestAppearances) {
|
|
5631
|
-
const promoteToStatic = new Set(existingStaticKeys);
|
|
5632
|
-
for (const [mutantId, count] of perTestAppearances) {
|
|
5633
|
-
if (count > 1) {
|
|
5634
|
-
promoteToStatic.add(mutantId);
|
|
5635
|
-
}
|
|
5636
|
-
}
|
|
5637
|
-
return promoteToStatic;
|
|
5638
|
-
}
|
|
5639
|
-
function buildFilteredPerTest(perTestEntries, promoteToStatic) {
|
|
5621
|
+
function buildFilteredPerTest(perTestEntries, staticIds) {
|
|
5640
5622
|
const newPerTest = {};
|
|
5641
5623
|
for (const [testId, counts] of perTestEntries) {
|
|
5642
5624
|
const filteredCounts = {};
|
|
5643
5625
|
for (const [mutantId, hitCount] of Object.entries(counts)) {
|
|
5644
|
-
if (!
|
|
5626
|
+
if (!staticIds.has(mutantId)) {
|
|
5645
5627
|
filteredCounts[mutantId] = hitCount;
|
|
5646
5628
|
}
|
|
5647
5629
|
}
|
|
@@ -5652,27 +5634,11 @@ function buildFilteredPerTest(perTestEntries, promoteToStatic) {
|
|
|
5652
5634
|
return newPerTest;
|
|
5653
5635
|
}
|
|
5654
5636
|
function stabilizeCoverage(coverage) {
|
|
5655
|
-
const
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
const perTestAppearances = countPerTestAppearances(perTestEntries);
|
|
5661
|
-
const promoteToStatic = buildPromoteToStaticSet(existingStaticKeys, perTestAppearances);
|
|
5662
|
-
const existingStatic = new Set(existingStaticKeys);
|
|
5663
|
-
const hasNewPromotions = [...promoteToStatic].some((id) => !existingStatic.has(id));
|
|
5664
|
-
const hasPerTestContamination = perTestEntries.some(([, counts]) => Object.keys(counts).some((id) => promoteToStatic.has(id)));
|
|
5665
|
-
if (!hasNewPromotions && !hasPerTestContamination) {
|
|
5666
|
-
return coverage;
|
|
5667
|
-
}
|
|
5668
|
-
const newStatic = { ...coverage.static };
|
|
5669
|
-
for (const mutantId of promoteToStatic) {
|
|
5670
|
-
if (!(mutantId in newStatic)) {
|
|
5671
|
-
newStatic[mutantId] = 1;
|
|
5672
|
-
}
|
|
5673
|
-
}
|
|
5674
|
-
const newPerTest = buildFilteredPerTest(perTestEntries, promoteToStatic);
|
|
5675
|
-
return { static: newStatic, perTest: newPerTest };
|
|
5637
|
+
const staticIds = new Set(Object.keys(coverage.static));
|
|
5638
|
+
return {
|
|
5639
|
+
static: coverage.static,
|
|
5640
|
+
perTest: buildFilteredPerTest(Object.entries(coverage.perTest), staticIds)
|
|
5641
|
+
};
|
|
5676
5642
|
}
|
|
5677
5643
|
function pairKeysWithInspectorIds(globallyOrderedPerTestKeys, executionOrder, testHierarchy, logger) {
|
|
5678
5644
|
const nonSkipped = executionOrder.filter((id) => {
|
|
@@ -6017,11 +5983,12 @@ class InspectorClient {
|
|
|
6017
5983
|
}
|
|
6018
5984
|
}
|
|
6019
5985
|
handleTestFound(params) {
|
|
6020
|
-
const fullName = this.buildFullName(params.id, params.name, params.parentId);
|
|
5986
|
+
const { fullName, bunName } = this.buildFullName(params.id, params.name, params.parentId);
|
|
6021
5987
|
const testInfo = {
|
|
6022
5988
|
id: params.id,
|
|
6023
5989
|
name: params.name,
|
|
6024
5990
|
fullName,
|
|
5991
|
+
bunName,
|
|
6025
5992
|
type: params.type,
|
|
6026
5993
|
parentId: params.parentId,
|
|
6027
5994
|
url: params.url,
|
|
@@ -6062,7 +6029,7 @@ class InspectorClient {
|
|
|
6062
6029
|
}
|
|
6063
6030
|
buildFullName(id, name, parentId) {
|
|
6064
6031
|
if (parentId === undefined) {
|
|
6065
|
-
return name;
|
|
6032
|
+
return { fullName: name, bunName: name };
|
|
6066
6033
|
}
|
|
6067
6034
|
const parts = [name];
|
|
6068
6035
|
const visited = new Set([id]);
|
|
@@ -6080,7 +6047,7 @@ class InspectorClient {
|
|
|
6080
6047
|
parts.unshift(parent.name);
|
|
6081
6048
|
currentId = parent.parentId;
|
|
6082
6049
|
}
|
|
6083
|
-
return parts.join(" > ");
|
|
6050
|
+
return { fullName: parts.join(" > "), bunName: parts.join(" ") };
|
|
6084
6051
|
}
|
|
6085
6052
|
handleClose() {
|
|
6086
6053
|
if (this.isClosing) {
|
|
@@ -6309,6 +6276,20 @@ async function getPsRss(pid) {
|
|
|
6309
6276
|
|
|
6310
6277
|
// src/process-runner.ts
|
|
6311
6278
|
var KILL_GRACE_PERIOD_MS = 500;
|
|
6279
|
+
function stripBailArgs(bunArgs) {
|
|
6280
|
+
const sanitized = [];
|
|
6281
|
+
for (let i = 0;i < bunArgs.length; i++) {
|
|
6282
|
+
const arg = bunArgs[i];
|
|
6283
|
+
if (arg === "--bail" || arg.startsWith("--bail=")) {
|
|
6284
|
+
if (arg === "--bail" && /^\d+$/.test(bunArgs[i + 1])) {
|
|
6285
|
+
i += 1;
|
|
6286
|
+
}
|
|
6287
|
+
continue;
|
|
6288
|
+
}
|
|
6289
|
+
sanitized.push(arg);
|
|
6290
|
+
}
|
|
6291
|
+
return sanitized;
|
|
6292
|
+
}
|
|
6312
6293
|
function killWithEscalation(childProcess, isClosed, gracePeriodMs) {
|
|
6313
6294
|
childProcess.kill("SIGTERM");
|
|
6314
6295
|
setTimeout(() => {
|
|
@@ -6341,7 +6322,7 @@ async function runBunTests(options) {
|
|
|
6341
6322
|
args.push("--smol");
|
|
6342
6323
|
}
|
|
6343
6324
|
if (options.bunArgs && options.bunArgs.length > 0) {
|
|
6344
|
-
args.push(...options.bunArgs);
|
|
6325
|
+
args.push(...stripBailArgs(options.bunArgs));
|
|
6345
6326
|
}
|
|
6346
6327
|
if (options.testFiles && options.testFiles.length > 0) {
|
|
6347
6328
|
args.push(...options.testFiles);
|
|
@@ -7751,20 +7732,29 @@ async function cleanupSanitizedBunfig(filePath) {
|
|
|
7751
7732
|
}
|
|
7752
7733
|
}
|
|
7753
7734
|
// src/utils/test-name-pattern.ts
|
|
7754
|
-
|
|
7735
|
+
var MAX_TEST_NAME_PATTERN_LENGTH = 1e5;
|
|
7736
|
+
var fileExtRe = /\.(?:test|spec)\.(?:[jt]sx?|m[jt]s)$/;
|
|
7737
|
+
var dedupSuffixRe = / \[\d+\]$/;
|
|
7738
|
+
var metaRe = /[.*+?^${}()|[\]\\/]/g;
|
|
7739
|
+
function escapeRegex(str) {
|
|
7740
|
+
return str.replaceAll(metaRe, String.raw`\$&`);
|
|
7741
|
+
}
|
|
7742
|
+
function buildTestNamePattern(testFilter, testNameIndex) {
|
|
7755
7743
|
if (testFilter.length === 0) {
|
|
7756
7744
|
return;
|
|
7757
7745
|
}
|
|
7758
|
-
const fileExtRe = /\.(?:test|spec)\.(?:[jt]sx?|m[jt]s)$/;
|
|
7759
|
-
const dedupSuffixRe = / \[\d+\]$/;
|
|
7760
|
-
const metaRe = /[.*+?^${}()|[\]\\/]/g;
|
|
7761
7746
|
const alternatives = new Set;
|
|
7762
7747
|
for (const id of testFilter) {
|
|
7748
|
+
const exact = testNameIndex?.get(id);
|
|
7749
|
+
if (exact !== undefined && exact.length > 0 && !exact.includes("\x00")) {
|
|
7750
|
+
alternatives.add(escapeRegex(exact));
|
|
7751
|
+
continue;
|
|
7752
|
+
}
|
|
7763
7753
|
const firstSepIdx = id.indexOf(" > ");
|
|
7764
7754
|
let name = firstSepIdx !== -1 && fileExtRe.test(id.slice(0, firstSepIdx)) ? id.slice(firstSepIdx + 3) : id;
|
|
7765
7755
|
name = name.replace(dedupSuffixRe, "");
|
|
7766
7756
|
name = name.replaceAll(" > ", " ");
|
|
7767
|
-
name = name
|
|
7757
|
+
name = escapeRegex(name);
|
|
7768
7758
|
if (name.length > 0) {
|
|
7769
7759
|
alternatives.add(name);
|
|
7770
7760
|
}
|
|
@@ -7772,7 +7762,11 @@ function buildTestNamePattern(testFilter) {
|
|
|
7772
7762
|
if (alternatives.size === 0) {
|
|
7773
7763
|
return;
|
|
7774
7764
|
}
|
|
7775
|
-
|
|
7765
|
+
const pattern = `^(?:${[...alternatives].join("|")})$`;
|
|
7766
|
+
if (Buffer.byteLength(pattern) > MAX_TEST_NAME_PATTERN_LENGTH) {
|
|
7767
|
+
return;
|
|
7768
|
+
}
|
|
7769
|
+
return pattern;
|
|
7776
7770
|
}
|
|
7777
7771
|
// src/utils/test-file-discovery.ts
|
|
7778
7772
|
import * as fsPromises from "node:fs/promises";
|
|
@@ -7883,6 +7877,17 @@ function sleep(ms) {
|
|
|
7883
7877
|
setTimeout(resolve3, ms);
|
|
7884
7878
|
});
|
|
7885
7879
|
}
|
|
7880
|
+
function buildTestNameIndex(tests, bunNames) {
|
|
7881
|
+
const testNameIndex = new Map;
|
|
7882
|
+
for (const [i, test] of tests.entries()) {
|
|
7883
|
+
const bunName = bunNames[i];
|
|
7884
|
+
if (bunName !== undefined) {
|
|
7885
|
+
testNameIndex.set(test.id, bunName);
|
|
7886
|
+
}
|
|
7887
|
+
}
|
|
7888
|
+
return testNameIndex;
|
|
7889
|
+
}
|
|
7890
|
+
var ZERO_MATCH_TEST_PATTERN_RE = /matched 0 tests\./;
|
|
7886
7891
|
|
|
7887
7892
|
class BunTestRunner {
|
|
7888
7893
|
logger;
|
|
@@ -7904,6 +7909,7 @@ class BunTestRunner {
|
|
|
7904
7909
|
tempDir;
|
|
7905
7910
|
cachedTestNames;
|
|
7906
7911
|
baseNameIndex;
|
|
7912
|
+
testNameIndex;
|
|
7907
7913
|
cachedTestFiles;
|
|
7908
7914
|
cachedTestFilesCwd;
|
|
7909
7915
|
cachedEagerModules;
|
|
@@ -8030,16 +8036,21 @@ class BunTestRunner {
|
|
|
8030
8036
|
try {
|
|
8031
8037
|
const raw = await fsPromises2.readFile(registryPath, "utf8");
|
|
8032
8038
|
const parsed = JSON.parse(raw);
|
|
8033
|
-
if (parsed.version !==
|
|
8039
|
+
if (parsed.version !== 2) {
|
|
8034
8040
|
this.logger.warn("dryRun registry file has unexpected version %s; skipping", String(parsed.version));
|
|
8035
8041
|
return;
|
|
8036
8042
|
}
|
|
8037
|
-
if (!Array.isArray(parsed.cachedTestNames) || !Array.isArray(parsed.baseNameIndex)) {
|
|
8038
|
-
this.logger.warn("dryRun registry file is malformed (cachedTestNames or
|
|
8043
|
+
if (!Array.isArray(parsed.cachedTestNames) || !Array.isArray(parsed.baseNameIndex) || !Array.isArray(parsed.testNameIndex)) {
|
|
8044
|
+
this.logger.warn("dryRun registry file is malformed (cachedTestNames, baseNameIndex, or testNameIndex missing or not an array); treating as absent");
|
|
8045
|
+
return;
|
|
8046
|
+
}
|
|
8047
|
+
if (!parsed.testNameIndex.every((entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && typeof entry[1] === "string")) {
|
|
8048
|
+
this.logger.warn("dryRun registry file is malformed (testNameIndex entry is not a [string, string] pair); treating as absent");
|
|
8039
8049
|
return;
|
|
8040
8050
|
}
|
|
8041
8051
|
this.cachedTestNames = new Set(parsed.cachedTestNames);
|
|
8042
8052
|
this.baseNameIndex = new Map(parsed.baseNameIndex);
|
|
8053
|
+
this.testNameIndex = new Map(parsed.testNameIndex);
|
|
8043
8054
|
this.logger.debug("Loaded dryRun registry from %s (%d entries)", registryPath, this.cachedTestNames.size);
|
|
8044
8055
|
} catch (err) {
|
|
8045
8056
|
const code = err.code;
|
|
@@ -8052,7 +8063,7 @@ class BunTestRunner {
|
|
|
8052
8063
|
}
|
|
8053
8064
|
buildTestsFromInspector(testHierarchy, executionOrder, parsed, totalElapsedMs, inspectorIdToProjectFile) {
|
|
8054
8065
|
if (executionOrder.length === 0) {
|
|
8055
|
-
|
|
8066
|
+
const fallbackTests = parsed.tests.map((t) => {
|
|
8056
8067
|
const normalizedName = normalizeTestName(t.name);
|
|
8057
8068
|
if (t.status === "failed") {
|
|
8058
8069
|
return {
|
|
@@ -8078,12 +8089,14 @@ class BunTestRunner {
|
|
|
8078
8089
|
timeSpentMs: Math.round(t.duration ?? 1)
|
|
8079
8090
|
};
|
|
8080
8091
|
});
|
|
8092
|
+
return { tests: fallbackTests, testNameIndex: new Map };
|
|
8081
8093
|
}
|
|
8082
8094
|
const timePerTest = executionOrder.length > 0 ? Math.max(1, Math.round(totalElapsedMs / executionOrder.length)) : 1;
|
|
8083
8095
|
const testMap = new Map;
|
|
8084
8096
|
for (const test of testHierarchy) {
|
|
8085
8097
|
testMap.set(test.id, test);
|
|
8086
8098
|
}
|
|
8099
|
+
const bunNames = executionOrder.map((inspectorId) => testMap.get(inspectorId)?.bunName);
|
|
8087
8100
|
const tests = executionOrder.map((inspectorId) => {
|
|
8088
8101
|
const testInfo = testMap.get(inspectorId);
|
|
8089
8102
|
if (!testInfo) {
|
|
@@ -8158,7 +8171,7 @@ class BunTestRunner {
|
|
|
8158
8171
|
test.name = uniqueName;
|
|
8159
8172
|
}
|
|
8160
8173
|
}
|
|
8161
|
-
return tests;
|
|
8174
|
+
return { tests, testNameIndex: buildTestNameIndex(tests, bunNames) };
|
|
8162
8175
|
}
|
|
8163
8176
|
async dryRun() {
|
|
8164
8177
|
this.logger.debug("Running dry run with inspector-based coverage collection...");
|
|
@@ -8263,9 +8276,9 @@ exit=%s timedOut=%s
|
|
|
8263
8276
|
return earlyResult;
|
|
8264
8277
|
}
|
|
8265
8278
|
const { coverage: mutantCoverage, inspectorIdToProjectFile } = await this.collectAndRemapCoverage(testHierarchy, executionOrder);
|
|
8266
|
-
const tests = this.buildTestsFromInspector(testHierarchy, executionOrder, parsed, totalElapsedMs, inspectorIdToProjectFile);
|
|
8279
|
+
const { tests, testNameIndex } = this.buildTestsFromInspector(testHierarchy, executionOrder, parsed, totalElapsedMs, inspectorIdToProjectFile);
|
|
8267
8280
|
tests.sort((a, b) => a.name.localeCompare(b.name));
|
|
8268
|
-
await this.buildAndPersistTestRegistry(tests);
|
|
8281
|
+
await this.buildAndPersistTestRegistry(tests, testNameIndex);
|
|
8269
8282
|
return {
|
|
8270
8283
|
status: DryRunStatus.Complete,
|
|
8271
8284
|
tests,
|
|
@@ -8279,7 +8292,7 @@ exit=%s timedOut=%s
|
|
|
8279
8292
|
await syncServer.close();
|
|
8280
8293
|
}
|
|
8281
8294
|
}
|
|
8282
|
-
async buildAndPersistTestRegistry(tests) {
|
|
8295
|
+
async buildAndPersistTestRegistry(tests, testNameIndex) {
|
|
8283
8296
|
this.cachedTestNames = new Set(tests.map((t) => t.name));
|
|
8284
8297
|
if (tests.length !== this.cachedTestNames.size) {
|
|
8285
8298
|
const nameCount = new Map;
|
|
@@ -8304,14 +8317,16 @@ exit=%s timedOut=%s
|
|
|
8304
8317
|
}
|
|
8305
8318
|
}
|
|
8306
8319
|
this.logger.debug("Cached %d test names from dry run for killedBy resolution", this.cachedTestNames.size);
|
|
8320
|
+
this.testNameIndex = testNameIndex;
|
|
8307
8321
|
try {
|
|
8308
8322
|
const registryPath = this.registryPath;
|
|
8309
8323
|
const tmpPath = this.registryTmpPath;
|
|
8310
8324
|
const registryData = JSON.stringify({
|
|
8311
|
-
version:
|
|
8325
|
+
version: 2,
|
|
8312
8326
|
writtenAt: Date.now(),
|
|
8313
8327
|
cachedTestNames: [...this.cachedTestNames],
|
|
8314
|
-
baseNameIndex: [...this.baseNameIndex.entries()]
|
|
8328
|
+
baseNameIndex: [...this.baseNameIndex.entries()],
|
|
8329
|
+
testNameIndex: [...testNameIndex.entries()]
|
|
8315
8330
|
});
|
|
8316
8331
|
await fsPromises2.writeFile(tmpPath, registryData, "utf8");
|
|
8317
8332
|
this.lastRegistryTmpPath = tmpPath;
|
|
@@ -8322,17 +8337,35 @@ exit=%s timedOut=%s
|
|
|
8322
8337
|
this.logger.warn("Failed to write dryRun registry file: %s", error instanceof Error ? error.message : String(error));
|
|
8323
8338
|
}
|
|
8324
8339
|
}
|
|
8340
|
+
warnLossyPatternAlternatives(filterIds, mutantId) {
|
|
8341
|
+
if (filterIds.length === 0) {
|
|
8342
|
+
return;
|
|
8343
|
+
}
|
|
8344
|
+
const exactNameIndex = this.testNameIndex;
|
|
8345
|
+
if (exactNameIndex === undefined) {
|
|
8346
|
+
this.logger.warn('Mutant %s: no exact-name registry available — all %d covering-test pattern alternatives use lossy reconstruction; tests with " > " in their titles may be silently dropped', mutantId, filterIds.length);
|
|
8347
|
+
return;
|
|
8348
|
+
}
|
|
8349
|
+
const missed = filterIds.filter((id) => !exactNameIndex.has(id));
|
|
8350
|
+
if (missed.length > 0) {
|
|
8351
|
+
this.logger.warn('Mutant %s: %d of %d testFilter ids missing from exact-name registry (lossy fallback; " > " titles among them may be silently dropped): %s%s', mutantId, missed.length, filterIds.length, missed.slice(0, 5).join(", "), missed.length > 5 ? ", …" : "");
|
|
8352
|
+
}
|
|
8353
|
+
}
|
|
8325
8354
|
async mutantRun(options) {
|
|
8326
8355
|
this.logger.debug("Running mutant run for mutant %s", options.activeMutant.id);
|
|
8327
|
-
const
|
|
8328
|
-
const localTestFilter = options.testFilter ?? [];
|
|
8329
|
-
const { localRegistry, localBaseIndex } = this.buildLocalTestFilterIndex(localTestFilter);
|
|
8356
|
+
const filterIds = options.testFilter ?? [];
|
|
8330
8357
|
if (!this.cachedTestNames) {
|
|
8331
8358
|
await this.loadRegistryFile();
|
|
8332
8359
|
}
|
|
8360
|
+
this.warnLossyPatternAlternatives(filterIds, options.activeMutant.id);
|
|
8361
|
+
const testNamePattern = buildTestNamePattern(filterIds, this.testNameIndex);
|
|
8362
|
+
const { localRegistry, localBaseIndex } = this.buildLocalTestFilterIndex(filterIds);
|
|
8333
8363
|
const mutantCwd = process.cwd();
|
|
8334
8364
|
const bunfigPath = this.sanitizedBunfigPath && this.sanitizedBunfigCwd === mutantCwd ? this.sanitizedBunfigPath : await this.ensureSanitizedBunfig();
|
|
8335
8365
|
this.cachedTestFiles = await this.getOrDiscoverTestFiles();
|
|
8366
|
+
return this.executeMutantRun(options, bunfigPath, testNamePattern, localRegistry, localBaseIndex);
|
|
8367
|
+
}
|
|
8368
|
+
async executeMutantRun(options, bunfigPath, testNamePattern, localRegistry, localBaseIndex) {
|
|
8336
8369
|
const abortController = new AbortController;
|
|
8337
8370
|
this.currentAbortController = abortController;
|
|
8338
8371
|
let result;
|
|
@@ -8344,7 +8377,7 @@ exit=%s timedOut=%s
|
|
|
8344
8377
|
bunArgs: this.bunArgs,
|
|
8345
8378
|
bunfigPath,
|
|
8346
8379
|
activeMutant: options.activeMutant.id,
|
|
8347
|
-
bail:
|
|
8380
|
+
bail: !options.disableBail,
|
|
8348
8381
|
sequentialMode: true,
|
|
8349
8382
|
preloadScript: this.preloadScriptPath,
|
|
8350
8383
|
testNamePattern,
|
|
@@ -8376,6 +8409,10 @@ exit=%s timedOut=%s
|
|
|
8376
8409
|
exitCode: result.exitCode
|
|
8377
8410
|
});
|
|
8378
8411
|
if (result.exitCode !== 0) {
|
|
8412
|
+
if (testNamePattern !== undefined && parsed.tests.length === 0 && ZERO_MATCH_TEST_PATTERN_RE.test(result.stderr)) {
|
|
8413
|
+
this.logger.warn("Mutant %s: --test-name-pattern matched 0 tests — usually a runner pattern gap or a mutant that changed an interpolated test title (it.each); retrying once with the full suite", options.activeMutant.id);
|
|
8414
|
+
return this.executeMutantRun(options, bunfigPath, undefined, localRegistry, localBaseIndex);
|
|
8415
|
+
}
|
|
8379
8416
|
return this.buildMutantKilledResult(result, parsed, localRegistry, localBaseIndex, options.activeMutant.id);
|
|
8380
8417
|
}
|
|
8381
8418
|
return {
|
|
@@ -8412,6 +8449,13 @@ exit=%s timedOut=%s
|
|
|
8412
8449
|
}
|
|
8413
8450
|
checkRuntimeError(result, mutantId) {
|
|
8414
8451
|
const stderr = result.stderr;
|
|
8452
|
+
if (ZERO_MATCH_TEST_PATTERN_RE.test(stderr)) {
|
|
8453
|
+
this.logger.warn("Mutant %s: --test-name-pattern matched 0 tests with no covering tests left to retry — not a kill: %s", mutantId, stderr.slice(0, 200));
|
|
8454
|
+
return {
|
|
8455
|
+
status: MutantRunStatus.Error,
|
|
8456
|
+
errorMessage: `stryker-bun-runner: bun's --test-name-pattern matched 0 tests for this mutant (runner pattern gap or mutant-changed interpolated title — not a kill): ${stderr.slice(0, 500)}`
|
|
8457
|
+
};
|
|
8458
|
+
}
|
|
8415
8459
|
const isRuntimeError = stderr.includes("Unhandled error") || stderr.includes("Cannot find module") || stderr.includes("SyntaxError") || stderr.includes("TypeError") || stderr.includes("ReferenceError") || stderr.includes("is not defined") || stderr.includes("Unexpected token");
|
|
8416
8460
|
if (isRuntimeError) {
|
|
8417
8461
|
this.logger.debug("Mutant %s caused runtime error (tests could not run): %s", mutantId, stderr.slice(0, 200));
|