@hughescr/stryker-bun-runner 1.3.8 → 1.4.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 CHANGED
@@ -33,7 +33,9 @@ curl -fsSL https://bun.sh/install | bash -s "bun-v1.3.7"
33
33
 
34
34
  ### Other Requirements
35
35
 
36
- - **@stryker-mutator/core** ^9.0.0
36
+ - **@stryker-mutator/core** ^9.0.0 || ^10.0.0
37
+
38
+ Stryker itself runs on Node (only the test children run on Bun), so the host Node version must satisfy the Stryker major you pick: Stryker 9 needs Node >= 20, Stryker 10 needs Node >= 22.
37
39
 
38
40
  ## Installation
39
41
 
@@ -84,6 +86,7 @@ A second full-suite fallback happens at run time: a `--test-name-pattern` that m
84
86
  | `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). |
85
87
  | `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). |
86
88
  | `bun.rssCheckIntervalMs` | `number` | `1000` | Poll interval in milliseconds for the `maxChildRss` check. |
89
+ | `bun.maxSpawnDepth` | `number` | `1` | Maximum `bun test` spawn nesting depth before the runner refuses to spawn. Guards against runaway recursion — see [Recursion containment](#recursion-containment). Raise to `2` only if your own tests drive this runner. |
87
90
 
88
91
  ### Example with all options
89
92
 
@@ -124,6 +127,29 @@ What this means for memory planning on a mutation-testing machine:
124
127
  - Set `bun.maxChildRss` as a backstop against a single run growing unexpectedly large (see [Memory containment](#memory-containment)).
125
128
  - Use Stryker core's [`maxTestRunnerReuse`](#maxtestrunnerreuse-compatibility) to periodically recycle the *Stryker worker* process itself (see below) — this is orthogonal to the spawned `bun test` child and addresses a different, much smaller source of growth.
126
129
 
130
+ ## Recursion containment
131
+
132
+ ### Kills reach the whole process tree
133
+
134
+ On POSIX systems, every `bun test` child is spawned **detached**, so it leads its own process group, and every kill path (timeout, `AbortSignal`, the `maxChildRss` ceiling) signals that whole group rather than the single child. This matters whenever your test suite itself spawns processes: signalling only the direct child leaves its grandchildren alive and reparented to PID 1, where nothing will ever clean them up. A suite that starts a server, a database, or another `bun` process therefore leaks one of each on every timed-out mutant unless the group is signalled. Platforms without POSIX process-group signalling fall back to terminating the direct child and cannot guarantee descendant cleanup.
135
+
136
+ Spawning detached has a consequence worth stating plainly: a detached child is no longer in the terminal's foreground process group, so it does **not** die on its own when you Ctrl-C a run. The runner therefore traps `SIGINT`/`SIGTERM`/`SIGHUP`, kills every live child's group, and re-raises the signal so the default behaviour is preserved. Without that, interrupting a campaign would strand one full `bun test` process per worker.
137
+
138
+ ### The runner refuses to nest indefinitely
139
+
140
+ Each child carries its spawn depth in `__STRYKER_BUN_RUNNER_DEPTH__`, and a run at or beyond `bun.maxSpawnDepth` fails with a non-zero exit code instead of spawning. The failure mode this prevents is worth spelling out, because it is not hypothetical and it is not survivable:
141
+
142
+ - The runner can spawn `bun test` from inside a `bun test` it spawned.
143
+ - If a nested run falls back to auto-discovery while its cwd is the project root, it picks up the project's **entire** suite — including the very test that spawned it.
144
+ - That test spawns again, and so on. A new generation appears roughly every second.
145
+ - Every generation leads its own process group, so killing any one of them does not stop the chain; the survivors keep replicating and are reparented to PID 1. (Group-per-generation is a consequence of the detached spawn above — which is why the depth ceiling, not the group kill, is what actually terminates this.)
146
+
147
+ Under mutation testing this is reachable through ordinary mutants — anything that defeats the `bun.testFiles` override puts a nested run back on auto-discovery. The depth ceiling turns that from an unbounded runaway into a single loud failure.
148
+
149
+ The default of `1` allows the runner's own `bun test` children and nothing deeper, which is correct for every project whose tests do not themselves drive this runner. If yours do, raise it to `2` — **on the runner instance making the nested call**, since that is where the ceiling is enforced. Setting it in `stryker.conf.mjs` only configures the outer run, which never reaches the ceiling. This plugin's own integration tests are the worked example: they pass `maxSpawnDepth: 2` in their `bun: { … }` literals, because under Stryker the suite is itself a depth-1 run and its own spawns land at depth 2.
150
+
151
+ A refused spawn is reported as a failure for that mutant, with the reason on stderr, rather than silently passing.
152
+
127
153
  ## Memory containment
128
154
 
129
155
  Two independent knobs help bound the memory a single `bun test` child can use, on top of the isolation the [memory model](#memory-model) already provides:
@@ -71,12 +71,12 @@ function startOrphanWatchdog(deps) {
71
71
  };
72
72
  }
73
73
  export {
74
- writeCoverageToFile,
75
- startOrphanWatchdog,
76
- shouldCollectCoverage,
77
- setActiveMutant,
78
- initializeStrykerNamespace,
79
- getPreloadConfig,
74
+ detectGapWindowBleed,
80
75
  formatCoverageData,
81
- detectGapWindowBleed
76
+ getPreloadConfig,
77
+ initializeStrykerNamespace,
78
+ setActiveMutant,
79
+ shouldCollectCoverage,
80
+ startOrphanWatchdog,
81
+ writeCoverageToFile
82
82
  };
package/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export declare class BunTestRunner implements TestRunner {
24
24
  private readonly smol;
25
25
  private readonly maxChildRss?;
26
26
  private readonly rssCheckIntervalMs?;
27
+ private readonly maxSpawnDepth?;
27
28
  private preloadScriptPath?;
28
29
  private coverageFilePath?;
29
30
  private sanitizedBunfigPath?;
@@ -92,6 +93,31 @@ export declare class BunTestRunner implements TestRunner {
92
93
  private get registryPath();
93
94
  private get registryTmpPath();
94
95
  /**
96
+ * Narrow a targeted mutant run to just the test FILES its covering tests live
97
+ * in.
98
+ *
99
+ * `--test-name-pattern` filters at the TEST level, not the file level: bun
100
+ * still loads every test file it was given in order to discover which names
101
+ * match. On a suite of 31 spec files that costs ~330ms per run of which only
102
+ * ~54ms is process startup — and a run that ends up executing two tests pays
103
+ * it in full, on every mutant. Handing bun only the files that can contain a
104
+ * covering test drops the same measurement to ~66ms.
105
+ *
106
+ * Test ids are `<projectFile> > <fullName>` (see buildProjectFileTestName), so
107
+ * the file is already the id's prefix and no extra bookkeeping is needed.
108
+ *
109
+ * Returns undefined — meaning "use the full discovered list" — whenever the
110
+ * narrowing cannot be proven safe:
111
+ * - no filter at all (static mutants, full-suite runs),
112
+ * - any id that carries no parsable file prefix (console-fallback ids), or
113
+ * - any derived file that is not in the discovered list, which would mean the
114
+ * prefix was something other than a real test file.
115
+ *
116
+ * A wrong narrowing would silently skip a covering test and turn a killed
117
+ * mutant into a survivor, so every uncertain case takes the full list.
118
+ */
119
+ private resolveCoveringTestFiles;
120
+ /**
95
121
  * Get test runner capabilities
96
122
  */
97
123
  capabilities(): TestRunnerCapabilities;
@@ -470,6 +496,25 @@ export interface BunTestRunnerOptions {
470
496
  * @default 1000
471
497
  */
472
498
  rssCheckIntervalMs?: number;
499
+ /**
500
+ * Maximum `bun test` spawn nesting depth before the runner refuses to spawn.
501
+ *
502
+ * The runner can spawn `bun test` from inside a `bun test` it already
503
+ * spawned. If a nested run falls back to auto-discovery while its cwd is the
504
+ * project root, it picks up the project's entire suite — including the test
505
+ * that spawned it — and the nesting never terminates. This ceiling makes that
506
+ * finite: a run at or beyond the limit fails with a non-zero exit code
507
+ * instead of spawning. See the README's "Recursion containment" section.
508
+ *
509
+ * The default of 1 allows the runner's own `bun test` children and nothing
510
+ * deeper, which is right for every project whose tests do not themselves
511
+ * drive this runner. Raise it to 2 only if yours do — note that the value
512
+ * must be set on the runner instance making the *nested* call, since that is
513
+ * where the ceiling is enforced.
514
+ *
515
+ * @default 1
516
+ */
517
+ maxSpawnDepth?: number;
473
518
  }
474
519
  /**
475
520
  * Extended Stryker options with Bun-specific configuration
@@ -553,6 +598,12 @@ export declare const strykerValidationSchema: {
553
598
  description: string;
554
599
  default: number;
555
600
  };
601
+ maxSpawnDepth: {
602
+ type: string;
603
+ minimum: number;
604
+ description: string;
605
+ default: number;
606
+ };
556
607
  };
557
608
  additionalProperties: boolean;
558
609
  };