peaks-loop-mut 0.1.80 → 0.1.82
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/dist/services/mut/mut-runner.d.ts +10 -0
- package/dist/services/mut/mut-runner.d.ts.map +1 -1
- package/dist/services/mut/mut-runner.js +19 -10
- package/dist/services/mut/production-stryker.d.ts.map +1 -1
- package/dist/services/mut/production-stryker.js +45 -4
- package/dist/services/mut/stryker-options.d.ts +55 -0
- package/dist/services/mut/stryker-options.d.ts.map +1 -1
- package/dist/services/mut/stryker-options.js +58 -19
- package/dist/services/mut/stryker-run-config.d.ts +91 -0
- package/dist/services/mut/stryker-run-config.d.ts.map +1 -0
- package/dist/services/mut/stryker-run-config.js +153 -0
- package/package.json +1 -1
|
@@ -36,18 +36,28 @@ export interface StrykerInvokerInput {
|
|
|
36
36
|
readonly testFiles: ReadonlyArray<string>;
|
|
37
37
|
/** Source patterns to mutate. Empty means "let the project config decide". */
|
|
38
38
|
readonly mutate?: ReadonlyArray<string>;
|
|
39
|
+
/** Patterns NOT to copy into the Stryker sandbox. Empty means "copy all". */
|
|
40
|
+
readonly ignorePatterns?: ReadonlyArray<string>;
|
|
39
41
|
readonly tsconfigFile?: string;
|
|
40
42
|
readonly timeoutMs?: number;
|
|
41
43
|
readonly concurrency?: number;
|
|
44
|
+
/** Session id — scopes the generated per-run vitest config. Optional at this
|
|
45
|
+
* layer: an invoker that receives no test files has nothing to scope. */
|
|
46
|
+
readonly sessionId?: string;
|
|
42
47
|
}
|
|
43
48
|
export type StrykerInvoker = (opts: StrykerInvokerInput) => Promise<StrykerRawResult>;
|
|
44
49
|
export interface RunMutationInput {
|
|
45
50
|
readonly project: string;
|
|
46
51
|
readonly testFiles: ReadonlyArray<string>;
|
|
47
52
|
readonly mutate?: ReadonlyArray<string>;
|
|
53
|
+
readonly ignorePatterns?: ReadonlyArray<string>;
|
|
48
54
|
readonly tsconfigFile?: string;
|
|
49
55
|
readonly timeoutMs?: number;
|
|
50
56
|
readonly concurrency?: number;
|
|
57
|
+
/** Session id — scopes the generated per-run vitest config. Optional here so a
|
|
58
|
+
* caller that fails earlier (a missing test file, say) still gets THAT named
|
|
59
|
+
* error; the options builder refuses a test-file run without one. */
|
|
60
|
+
readonly sessionId?: string;
|
|
51
61
|
readonly invokeStryker: StrykerInvoker;
|
|
52
62
|
}
|
|
53
63
|
export interface RunMutationOutput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mut-runner.d.ts","sourceRoot":"","sources":["../../../src/services/mut/mut-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;QAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAC;YAAC,eAAe,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC/F,CAAC,CAAC;CACJ;AAED,qCAAqC;AACrC,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"mut-runner.d.ts","sourceRoot":"","sources":["../../../src/services/mut/mut-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;QAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAC;YAAC,eAAe,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC/F,CAAC,CAAC;CACJ;AAED,qCAAqC;AACrC,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,6EAA6E;IAC7E,QAAQ,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;8EAC0E;IAC1E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,mBAAmB,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAEtF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;0EAEsE;IACtE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,cAAc,CAAC;CACxC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;CACnC;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAgCrF"}
|
|
@@ -5,9 +5,11 @@ export async function runMutation(input) {
|
|
|
5
5
|
project: input.project,
|
|
6
6
|
testFiles: input.testFiles,
|
|
7
7
|
mutate: input.mutate,
|
|
8
|
+
ignorePatterns: input.ignorePatterns,
|
|
8
9
|
tsconfigFile: input.tsconfigFile,
|
|
9
10
|
timeoutMs: input.timeoutMs,
|
|
10
|
-
concurrency: input.concurrency
|
|
11
|
+
concurrency: input.concurrency,
|
|
12
|
+
sessionId: input.sessionId
|
|
11
13
|
});
|
|
12
14
|
}
|
|
13
15
|
catch (err) {
|
|
@@ -31,18 +33,25 @@ export async function runMutation(input) {
|
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
|
-
* Wrap an invoker failure while KEEPING its machine-readable `code
|
|
35
|
-
* The production invoker raises named codes
|
|
36
|
-
* `MUT_NO_MUTANTS`, …) and the
|
|
37
|
-
*
|
|
36
|
+
* Wrap an invoker failure while KEEPING its machine-readable `code` and its
|
|
37
|
+
* `details`. The production invoker raises named codes
|
|
38
|
+
* (`MUT_TOOLCHAIN_UNAVAILABLE`, `MUT_NO_MUTANTS`, …) and attaches the
|
|
39
|
+
* captured Stryker log as `details.strykerLog`; the CLI envelope must surface
|
|
40
|
+
* both instead of collapsing every failure into one anonymous message.
|
|
38
41
|
*/
|
|
39
42
|
function wrapInvocationError(err) {
|
|
40
43
|
const message = err instanceof Error ? err.message : String(err);
|
|
41
|
-
const wrapped = new Error(`Stryker invocation failed: ${message}
|
|
42
|
-
if (err && typeof err === 'object'
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const wrapped = new Error(`Stryker invocation failed: ${message}`, { cause: err });
|
|
45
|
+
if (err && typeof err === 'object') {
|
|
46
|
+
if ('code' in err) {
|
|
47
|
+
const code = err.code;
|
|
48
|
+
if (typeof code === 'string') {
|
|
49
|
+
wrapped.code = code;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const details = err.details;
|
|
53
|
+
if (details && typeof details === 'object') {
|
|
54
|
+
wrapped.details = details;
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
57
|
return wrapped;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"production-stryker.d.ts","sourceRoot":"","sources":["../../../src/services/mut/production-stryker.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAUzE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,CAAC;AAY9C,wBAAgB,8BAA8B,IAAI,cAAc,
|
|
1
|
+
{"version":3,"file":"production-stryker.d.ts","sourceRoot":"","sources":["../../../src/services/mut/production-stryker.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAUzE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,CAAC;AAY9C,wBAAgB,8BAA8B,IAAI,cAAc,CAqD/D"}
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
* codes), `stryker-plugin.ts` (the plugin path) and `stryker-result.ts`
|
|
36
36
|
* (the report shaping). The names THIS module exports are unchanged.
|
|
37
37
|
*/
|
|
38
|
-
import { existsSync } from 'node:fs';
|
|
38
|
+
import { existsSync, readFileSync, rmSync, statSync } from 'node:fs';
|
|
39
39
|
import { resolve } from 'node:path';
|
|
40
40
|
import { MUT_ERROR_CODES, MutToolchainError } from './stryker-errors.js';
|
|
41
41
|
import { buildStrykerOptions, STRYKER_DEFAULTS } from './stryker-options.js';
|
|
@@ -75,8 +75,16 @@ export function createProductionStrykerInvoker() {
|
|
|
75
75
|
project,
|
|
76
76
|
mutate: input.mutate,
|
|
77
77
|
testFiles: input.testFiles,
|
|
78
|
+
ignorePatterns: input.ignorePatterns,
|
|
78
79
|
pluginDescriptors,
|
|
79
80
|
tsconfigFile: input.tsconfigFile,
|
|
81
|
+
// Scopes the per-run vitest config whose `include` IS `--test-files`.
|
|
82
|
+
// Without it the project's own config filters the list to zero tests.
|
|
83
|
+
...(input.sessionId !== undefined ? { sessionId: input.sessionId } : {}),
|
|
84
|
+
// The console log stays 'off' (stdout belongs to --json), so this is
|
|
85
|
+
// the ONLY channel that records WHY Stryker failed. `runInProject`
|
|
86
|
+
// removes the file again unless the project already had one.
|
|
87
|
+
fileLogLevel: STRYKER_DEFAULTS.diagnosticFileLogLevel,
|
|
80
88
|
...projectOwned
|
|
81
89
|
});
|
|
82
90
|
const mutants = await runInProject(project, options);
|
|
@@ -108,23 +116,51 @@ function hasProjectStrykerConfig(project) {
|
|
|
108
116
|
/**
|
|
109
117
|
* Run Stryker with the project as the CWD, restoring the previous CWD
|
|
110
118
|
* afterwards. Serialised so concurrent invocations cannot interleave.
|
|
119
|
+
*
|
|
120
|
+
* THE FILE LOG. Stryker writes its file log to `stryker.log` in the CWD,
|
|
121
|
+
* which is the project root for the duration of the run (the path is fixed
|
|
122
|
+
* in `core/logging/logging-backend.js`). The console level is `off`, so that
|
|
123
|
+
* file is the only record of the real failure reason — `Something went wrong
|
|
124
|
+
* in the initial test run` is thrown bare. So on failure the bytes this run
|
|
125
|
+
* appended are read into the error's `details`, and unless the project
|
|
126
|
+
* ALREADY had a `stryker.log` (a developer's own), the file is removed
|
|
127
|
+
* afterwards so the working tree is left as it was found.
|
|
111
128
|
*/
|
|
112
129
|
async function runInProject(project, options) {
|
|
113
130
|
return runExclusive(async () => {
|
|
114
131
|
const previousCwd = process.cwd();
|
|
132
|
+
const logPath = resolve(project, 'stryker.log');
|
|
133
|
+
const logExistedBefore = existsSync(logPath);
|
|
134
|
+
const logBytesBefore = logExistedBefore ? statSync(logPath).size : 0;
|
|
115
135
|
try {
|
|
116
136
|
process.chdir(project);
|
|
117
137
|
const Stryker = (await import('@stryker-mutator/core')).Stryker;
|
|
118
138
|
return await new Stryker(options).runMutationTest();
|
|
119
139
|
}
|
|
120
140
|
catch (err) {
|
|
121
|
-
throw toMutError(err);
|
|
141
|
+
throw toMutError(err, readLogSince(logPath, logBytesBefore));
|
|
122
142
|
}
|
|
123
143
|
finally {
|
|
124
144
|
process.chdir(previousCwd);
|
|
145
|
+
if (!logExistedBefore) {
|
|
146
|
+
rmSync(logPath, { force: true });
|
|
147
|
+
}
|
|
125
148
|
}
|
|
126
149
|
});
|
|
127
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* The part of `stryker.log` this run wrote. The file is APPENDED to, so a
|
|
153
|
+
* project that already had one keeps its older lines out of the diagnostic.
|
|
154
|
+
* A missing file is not an error — it only means nothing was logged.
|
|
155
|
+
*/
|
|
156
|
+
function readLogSince(logPath, offset) {
|
|
157
|
+
try {
|
|
158
|
+
return readFileSync(logPath).subarray(offset).toString('utf8');
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return '';
|
|
162
|
+
}
|
|
163
|
+
}
|
|
128
164
|
/** Queue a unit of work so only one Stryker run owns the CWD at a time. */
|
|
129
165
|
function runExclusive(fn) {
|
|
130
166
|
const result = runQueue.then(fn, fn);
|
|
@@ -132,12 +168,17 @@ function runExclusive(fn) {
|
|
|
132
168
|
return result;
|
|
133
169
|
}
|
|
134
170
|
/** Map a Stryker failure onto a named error code. */
|
|
135
|
-
function toMutError(err) {
|
|
171
|
+
function toMutError(err, strykerLog) {
|
|
136
172
|
if (err instanceof MutToolchainError) {
|
|
137
173
|
return err;
|
|
138
174
|
}
|
|
139
175
|
const message = err instanceof Error ? err.message : String(err);
|
|
140
|
-
return new MutToolchainError(classifyStrykerFailure(message), message, {
|
|
176
|
+
return new MutToolchainError(classifyStrykerFailure(message), message, {
|
|
177
|
+
cause: err,
|
|
178
|
+
// Only present when Stryker wrote something — an empty entry would make
|
|
179
|
+
// the caller think a log exists when it does not.
|
|
180
|
+
...(strykerLog.trim().length > 0 ? { details: { strykerLog } } : {})
|
|
181
|
+
});
|
|
141
182
|
}
|
|
142
183
|
/** A missing plugin / package / runner is a toolchain problem, not a generic failure. */
|
|
143
184
|
function classifyStrykerFailure(message) {
|
|
@@ -43,6 +43,36 @@ export declare const STRYKER_DEFAULTS: {
|
|
|
43
43
|
readonly logLevel: "off";
|
|
44
44
|
readonly fileLogLevel: "off";
|
|
45
45
|
readonly allowConsoleColors: false;
|
|
46
|
+
/** The caller's sandbox-ignore list is opt-in, so the default is empty. */
|
|
47
|
+
readonly ignorePatterns: ReadonlyArray<string>;
|
|
48
|
+
/**
|
|
49
|
+
* ALWAYS ignored, whatever the caller asked for.
|
|
50
|
+
*
|
|
51
|
+
* `.stryker-tmp`: Stryker copies the project into `.stryker-tmp/sandbox-*`, so
|
|
52
|
+
* a sandbox directory that is itself copied is a copy of the sandbox into
|
|
53
|
+
* itself.
|
|
54
|
+
*
|
|
55
|
+
* `.peaks`: the runtime artifact tree. Two measured reasons (2026-11-17):
|
|
56
|
+
* - it holds past sessions whose scratch fixtures contain Windows junctions
|
|
57
|
+
* and symlinks, and Stryker's copier dies on them with `EPERM: operation
|
|
58
|
+
* not permitted, copyfile` — the run never started, on a tree that has
|
|
59
|
+
* nothing to do with the code under mutation;
|
|
60
|
+
* - it is large and grows with every session, so copying it per mutant is
|
|
61
|
+
* pure cost. A mutation run needs the source, the tests and the toolchain,
|
|
62
|
+
* never the session archive.
|
|
63
|
+
*
|
|
64
|
+
* No mutation target or test lives under `.peaks/**`: that tree is gitignored
|
|
65
|
+
* runtime state, and `git ls-files` — which every gate scope is built from —
|
|
66
|
+
* never lists it.
|
|
67
|
+
*/
|
|
68
|
+
readonly alwaysIgnoredPatterns: ReadonlyArray<string>;
|
|
69
|
+
/**
|
|
70
|
+
* The file-log level the PRODUCTION invoker turns on while a run is in
|
|
71
|
+
* flight (`production-stryker.ts` reads it). The console level stays
|
|
72
|
+
* `off` — stdout is reserved for the `--json` envelope — so the file log
|
|
73
|
+
* is the only place Stryker's real failure reason is written down.
|
|
74
|
+
*/
|
|
75
|
+
readonly diagnosticFileLogLevel: "debug";
|
|
46
76
|
};
|
|
47
77
|
export interface StrykerOptionsInput {
|
|
48
78
|
/** Project root — the scope of the mutation run. */
|
|
@@ -51,6 +81,30 @@ export interface StrykerOptionsInput {
|
|
|
51
81
|
readonly mutate?: ReadonlyArray<string>;
|
|
52
82
|
/** Test files to run. Empty means "let the runner discover them". */
|
|
53
83
|
readonly testFiles?: ReadonlyArray<string>;
|
|
84
|
+
/**
|
|
85
|
+
* Session id, used to place the per-run generated vitest config under
|
|
86
|
+
* `.peaks/_runtime/<sessionId>/mut/`. When given, that config's `include` is
|
|
87
|
+
* what makes `--test-files` select anything (see `stryker-run-config.ts`).
|
|
88
|
+
*
|
|
89
|
+
* OPTIONAL here: this builder produces OPTIONS and does not own the run's
|
|
90
|
+
* preconditions. `peaks mut run` makes `--session-id` a required option, so
|
|
91
|
+
* the CLI cannot reach Stryker unscoped; a programmatic caller that omits it
|
|
92
|
+
* gets the project's own `include` and the loud "No tests were executed"
|
|
93
|
+
* abort instead of an error from a pure builder.
|
|
94
|
+
*/
|
|
95
|
+
readonly sessionId?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Setup files the generated per-run config should carry. A suite that depends
|
|
98
|
+
* on global setup fails without it, and a setup failure reports mutants as
|
|
99
|
+
* killed when nothing actually ran.
|
|
100
|
+
*/
|
|
101
|
+
readonly setupFiles?: ReadonlyArray<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Patterns NOT to copy into the Stryker sandbox. Empty by default.
|
|
104
|
+
* Passed through verbatim (Stryker's own glob semantics) and always
|
|
105
|
+
* extended with the patterns in `STRYKER_DEFAULTS.alwaysIgnoredPatterns`.
|
|
106
|
+
*/
|
|
107
|
+
readonly ignorePatterns?: ReadonlyArray<string>;
|
|
54
108
|
/** Absolute paths (or file URLs) of Stryker plugins to load. */
|
|
55
109
|
readonly pluginDescriptors?: ReadonlyArray<string>;
|
|
56
110
|
readonly tsconfigFile?: string;
|
|
@@ -58,6 +112,7 @@ export interface StrykerOptionsInput {
|
|
|
58
112
|
readonly concurrency?: number;
|
|
59
113
|
readonly testRunner?: string;
|
|
60
114
|
readonly coverageAnalysis?: string;
|
|
115
|
+
readonly fileLogLevel?: string;
|
|
61
116
|
}
|
|
62
117
|
export interface BuiltStrykerOptions {
|
|
63
118
|
readonly options: StrykerCliOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stryker-options.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-options.ts"],"names":[],"mappings":"AAsEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"stryker-options.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-options.ts"],"names":[],"mappings":"AAsEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGrD;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,qBAAqB,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,cAAc,CAAC,GAAG;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACnE,CAAC;AAEF,mEAAmE;AACnE,eAAO,MAAM,gBAAgB;;;;;wBAKV,aAAa,CAAC,MAAM,CAAC;;;;IAItC,2EAA2E;6BACrD,aAAa,CAAC,MAAM,CAAC;IAC3C;;;;;;;;;;;;;;;;;;;OAmBG;oCACkD,aAAa,CAAC,MAAM,CAAC;IAC1E;;;;;OAKG;;CAEK,CAAC;AAEX,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,qEAAqE;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3C;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAChD,gEAAgE;IAChE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACnD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,QAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACnD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,GAAG,mBAAmB,CAgDnF;AAwCD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,GAAG,iBAAiB,CAEnF"}
|
|
@@ -67,7 +67,8 @@
|
|
|
67
67
|
* rootInjector, process.stdout)`) and the built-in reporters write
|
|
68
68
|
* there too. Measured: stdout length 0 for a real run.
|
|
69
69
|
*/
|
|
70
|
-
import {
|
|
70
|
+
import { resolve } from 'node:path';
|
|
71
|
+
import { resolveTestFiles, scopedVitestOptions } from './stryker-run-config.js';
|
|
71
72
|
/** Every default the builder applies lives here — nowhere else. */
|
|
72
73
|
export const STRYKER_DEFAULTS = {
|
|
73
74
|
testRunner: 'vitest',
|
|
@@ -77,7 +78,37 @@ export const STRYKER_DEFAULTS = {
|
|
|
77
78
|
reporters: [],
|
|
78
79
|
logLevel: 'off',
|
|
79
80
|
fileLogLevel: 'off',
|
|
80
|
-
allowConsoleColors: false
|
|
81
|
+
allowConsoleColors: false,
|
|
82
|
+
/** The caller's sandbox-ignore list is opt-in, so the default is empty. */
|
|
83
|
+
ignorePatterns: [],
|
|
84
|
+
/**
|
|
85
|
+
* ALWAYS ignored, whatever the caller asked for.
|
|
86
|
+
*
|
|
87
|
+
* `.stryker-tmp`: Stryker copies the project into `.stryker-tmp/sandbox-*`, so
|
|
88
|
+
* a sandbox directory that is itself copied is a copy of the sandbox into
|
|
89
|
+
* itself.
|
|
90
|
+
*
|
|
91
|
+
* `.peaks`: the runtime artifact tree. Two measured reasons (2026-11-17):
|
|
92
|
+
* - it holds past sessions whose scratch fixtures contain Windows junctions
|
|
93
|
+
* and symlinks, and Stryker's copier dies on them with `EPERM: operation
|
|
94
|
+
* not permitted, copyfile` — the run never started, on a tree that has
|
|
95
|
+
* nothing to do with the code under mutation;
|
|
96
|
+
* - it is large and grows with every session, so copying it per mutant is
|
|
97
|
+
* pure cost. A mutation run needs the source, the tests and the toolchain,
|
|
98
|
+
* never the session archive.
|
|
99
|
+
*
|
|
100
|
+
* No mutation target or test lives under `.peaks/**`: that tree is gitignored
|
|
101
|
+
* runtime state, and `git ls-files` — which every gate scope is built from —
|
|
102
|
+
* never lists it.
|
|
103
|
+
*/
|
|
104
|
+
alwaysIgnoredPatterns: ['.stryker-tmp', '.peaks'],
|
|
105
|
+
/**
|
|
106
|
+
* The file-log level the PRODUCTION invoker turns on while a run is in
|
|
107
|
+
* flight (`production-stryker.ts` reads it). The console level stays
|
|
108
|
+
* `off` — stdout is reserved for the `--json` envelope — so the file log
|
|
109
|
+
* is the only place Stryker's real failure reason is written down.
|
|
110
|
+
*/
|
|
111
|
+
diagnosticFileLogLevel: 'debug'
|
|
81
112
|
};
|
|
82
113
|
/**
|
|
83
114
|
* Build the Stryker options for one mutation run.
|
|
@@ -101,10 +132,26 @@ export function buildStrykerOptions(input) {
|
|
|
101
132
|
const testFiles = resolveTestFiles(project, input.testFiles);
|
|
102
133
|
if (testFiles.length > 0) {
|
|
103
134
|
options.testFiles = testFiles;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
135
|
+
options.vitest = scopedVitestOptions({
|
|
136
|
+
project,
|
|
137
|
+
testFiles,
|
|
138
|
+
sessionId: input.sessionId,
|
|
139
|
+
...(input.setupFiles !== undefined ? { setupFiles: input.setupFiles } : {})
|
|
140
|
+
});
|
|
107
141
|
}
|
|
142
|
+
// Verbatim, like `mutate`: these are Stryker globs, not file paths.
|
|
143
|
+
// `.stryker-tmp` is appended unconditionally (see STRYKER_DEFAULTS).
|
|
144
|
+
// Deduplicated: the always-ignored list is the caller's to repeat (a caller
|
|
145
|
+
// that already passes `.peaks` should not get it twice), and a duplicated
|
|
146
|
+
// glob is not harmless — it makes the resolved options harder to read and
|
|
147
|
+
// would double any future per-pattern warning.
|
|
148
|
+
options.ignorePatterns = [
|
|
149
|
+
...new Set([
|
|
150
|
+
...STRYKER_DEFAULTS.ignorePatterns,
|
|
151
|
+
...(input.ignorePatterns ?? []),
|
|
152
|
+
...STRYKER_DEFAULTS.alwaysIgnoredPatterns
|
|
153
|
+
])
|
|
154
|
+
];
|
|
108
155
|
if (pluginDescriptors.length > 0) {
|
|
109
156
|
// `appendPlugins` (not `plugins`) so a project `stryker.conf.js` keeps
|
|
110
157
|
// its own plugin list; ours is added on top.
|
|
@@ -114,6 +161,7 @@ export function buildStrykerOptions(input) {
|
|
|
114
161
|
}
|
|
115
162
|
/**
|
|
116
163
|
* Apply the options the caller owns. Everything here is a PROJECT-owned
|
|
164
|
+
|
|
117
165
|
* setting: it is written only when the caller asked for it, so a project
|
|
118
166
|
* `stryker.conf.js` keeps its own value.
|
|
119
167
|
*
|
|
@@ -142,6 +190,11 @@ function applyCallerOwnedOptions(options, input) {
|
|
|
142
190
|
if (input.tsconfigFile) {
|
|
143
191
|
options.tsconfigFile = input.tsconfigFile;
|
|
144
192
|
}
|
|
193
|
+
if (input.fileLogLevel) {
|
|
194
|
+
// The production invoker raises this to capture Stryker's own reason
|
|
195
|
+
// when a run fails; the console level stays untouched.
|
|
196
|
+
options.fileLogLevel = input.fileLogLevel;
|
|
197
|
+
}
|
|
145
198
|
}
|
|
146
199
|
/**
|
|
147
200
|
* Narrow the built options back to the type `new Stryker(...)` accepts.
|
|
@@ -153,17 +206,3 @@ function applyCallerOwnedOptions(options, input) {
|
|
|
153
206
|
export function toStrykerCliOptions(options) {
|
|
154
207
|
return options;
|
|
155
208
|
}
|
|
156
|
-
/**
|
|
157
|
-
* Resolve test-file patterns against the project root so the result does
|
|
158
|
-
* not depend on the caller's CWD. Absolute patterns are kept as-is.
|
|
159
|
-
*
|
|
160
|
-
* PURE: a path that does not exist is resolved anyway. Rejecting it is the
|
|
161
|
-
* validator's job (`test-files.ts`), and the validator runs at the boundary
|
|
162
|
-
* that owns the file system — see the module header.
|
|
163
|
-
*/
|
|
164
|
-
function resolveTestFiles(project, patterns) {
|
|
165
|
-
if (!patterns || patterns.length === 0) {
|
|
166
|
-
return [];
|
|
167
|
-
}
|
|
168
|
-
return patterns.map((pattern) => (isAbsolute(pattern) ? pattern : resolve(project, pattern)));
|
|
169
|
-
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A throwaway vitest config whose `include` is exactly the caller's test files.
|
|
3
|
+
*
|
|
4
|
+
* THE DEFECT THIS EXISTS FOR. `peaks mut run --test-files <a> <b>` passed the
|
|
5
|
+
* files to Stryker, but Stryker loads the project's `stryker.conf.js`, which
|
|
6
|
+
* points `vitest.configFile` at `stryker.vitest.config.mjs` — a config whose
|
|
7
|
+
* `include` names TWO hard-coded test files. Vitest filters `--test-files`
|
|
8
|
+
* through that `include`, so any other file selected ZERO tests and the dry run
|
|
9
|
+
* aborted with "No tests were executed". Measured 2026-11-17: a brand-new test
|
|
10
|
+
* file for a brand-new module could not be mutation-tested at all. The
|
|
11
|
+
* `--test-files` option was effectively decorative for every file outside those
|
|
12
|
+
* two.
|
|
13
|
+
*
|
|
14
|
+
* WHY NOT JUST WIDEN THE PROJECT CONFIG'S `include`. `stryker.vitest.config.mjs`
|
|
15
|
+
* is also what a direct `npx stryker run` uses, and its narrow list is deliberate
|
|
16
|
+
* there: the main suite contains CLI tests that call `process.chdir()`, which
|
|
17
|
+
* Stryker's forced-threaded vitest workers reject. Widening it would break that
|
|
18
|
+
* path. A per-run generated config leaves the project's own file exactly as its
|
|
19
|
+
* author intended and gives `peaks mut` the selection the caller asked for.
|
|
20
|
+
*
|
|
21
|
+
* WHERE IT LIVES. Under the project's `.peaks/_runtime/<sid>/mut/`, which is
|
|
22
|
+
* gitignored runtime state and is already in `alwaysIgnoredPatterns`, so the file
|
|
23
|
+
* neither pollutes the tree nor gets copied into the Stryker sandbox.
|
|
24
|
+
*/
|
|
25
|
+
export type GeneratedVitestConfig = {
|
|
26
|
+
/** Absolute path of the config file that was written. */
|
|
27
|
+
readonly configPath: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Write a vitest config under `<project>/.peaks/_runtime/<sid>/mut/` whose
|
|
31
|
+
* `include` is exactly `testFiles`, and whose aliases match the project's own
|
|
32
|
+
* `~/src/*` mapping so tests load exactly as they do normally.
|
|
33
|
+
*
|
|
34
|
+
* `setupFiles` is carried over from the project's config when the caller names
|
|
35
|
+
* one: a suite that depends on global setup (the workspace build, for instance)
|
|
36
|
+
* fails without it, and a mutation run that fails for a setup reason reports
|
|
37
|
+
* mutants as killed when nothing ran.
|
|
38
|
+
*/
|
|
39
|
+
export declare function writeRunScopedVitestConfig(input: {
|
|
40
|
+
readonly project: string;
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
readonly testFiles: ReadonlyArray<string>;
|
|
43
|
+
readonly setupFiles?: ReadonlyArray<string>;
|
|
44
|
+
}): GeneratedVitestConfig;
|
|
45
|
+
/** Display path for a generated config, relative to the project when possible. */
|
|
46
|
+
export declare function displayConfigPath(project: string, configPath: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* The `vitest` options for a run that names its test files.
|
|
49
|
+
*
|
|
50
|
+
* TWO THINGS, both required:
|
|
51
|
+
* - `related: false` — an explicit test list is authoritative, so vitest's
|
|
52
|
+
* related-mode narrowing must not discard it;
|
|
53
|
+
* - `configFile` — the generated config below, whose `include` IS the list.
|
|
54
|
+
* A project `stryker.conf.js` normally points at a config with a fixed
|
|
55
|
+
* short `include`, and vitest filters `--test-files` through it, so any
|
|
56
|
+
* other file selects ZERO tests and the dry run aborts with "No tests were
|
|
57
|
+
* executed". Measured 2026-11-17: a new test file could not be
|
|
58
|
+
* mutation-tested at all.
|
|
59
|
+
*
|
|
60
|
+
* WITHOUT A SESSION ID, `configFile` is OMITTED and only `related` is returned.
|
|
61
|
+
* This function builds OPTIONS; it does not own the run's preconditions. An
|
|
62
|
+
* earlier version threw here, which made every caller that only inspects the
|
|
63
|
+
* built options — the package's own `stryker-options.test.ts` does exactly that
|
|
64
|
+
* — supply a session id it has no use for. The requirement belongs where the
|
|
65
|
+
* run is started: `peaks mut run` declares `--session-id` a REQUIRED option, so
|
|
66
|
+
* an unscoped run cannot reach Stryker through the CLI. A programmatic caller
|
|
67
|
+
* that omits it falls back to the project's own `include` and sees the
|
|
68
|
+
* zero-tests abort, which is loud and names its own cause.
|
|
69
|
+
*/
|
|
70
|
+
export declare function scopedVitestOptions(input: {
|
|
71
|
+
readonly project: string;
|
|
72
|
+
readonly testFiles: ReadonlyArray<string>;
|
|
73
|
+
readonly sessionId: string | undefined;
|
|
74
|
+
readonly setupFiles?: ReadonlyArray<string>;
|
|
75
|
+
}): {
|
|
76
|
+
related: boolean;
|
|
77
|
+
configFile?: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Resolve test-file patterns against the project root so the result does
|
|
81
|
+
* not depend on the caller's CWD. Absolute patterns are kept as-is.
|
|
82
|
+
*
|
|
83
|
+
* PURE: a path that does not exist is resolved anyway. Rejecting it is this
|
|
84
|
+
* module's own `assertTestFilesUsable`, which runs at the boundary that owns
|
|
85
|
+
* the file system — see the module header.
|
|
86
|
+
*
|
|
87
|
+
* Lives here rather than in `stryker-options.ts` because it is about test
|
|
88
|
+
* files, not about Stryker options; the options builder imports it.
|
|
89
|
+
*/
|
|
90
|
+
export declare function resolveTestFiles(project: string, patterns: ReadonlyArray<string> | undefined): string[];
|
|
91
|
+
//# sourceMappingURL=stryker-run-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stryker-run-config.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-run-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,MAAM,MAAM,qBAAqB,GAAG;IAClC,yDAAyD;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAAC;AAQF;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IAChD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC7C,GAAG,qBAAqB,CAgBxB;AA2CD,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAG7E;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC7C,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAW5C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,GAC1C,MAAM,EAAE,CAKV"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A throwaway vitest config whose `include` is exactly the caller's test files.
|
|
3
|
+
*
|
|
4
|
+
* THE DEFECT THIS EXISTS FOR. `peaks mut run --test-files <a> <b>` passed the
|
|
5
|
+
* files to Stryker, but Stryker loads the project's `stryker.conf.js`, which
|
|
6
|
+
* points `vitest.configFile` at `stryker.vitest.config.mjs` — a config whose
|
|
7
|
+
* `include` names TWO hard-coded test files. Vitest filters `--test-files`
|
|
8
|
+
* through that `include`, so any other file selected ZERO tests and the dry run
|
|
9
|
+
* aborted with "No tests were executed". Measured 2026-11-17: a brand-new test
|
|
10
|
+
* file for a brand-new module could not be mutation-tested at all. The
|
|
11
|
+
* `--test-files` option was effectively decorative for every file outside those
|
|
12
|
+
* two.
|
|
13
|
+
*
|
|
14
|
+
* WHY NOT JUST WIDEN THE PROJECT CONFIG'S `include`. `stryker.vitest.config.mjs`
|
|
15
|
+
* is also what a direct `npx stryker run` uses, and its narrow list is deliberate
|
|
16
|
+
* there: the main suite contains CLI tests that call `process.chdir()`, which
|
|
17
|
+
* Stryker's forced-threaded vitest workers reject. Widening it would break that
|
|
18
|
+
* path. A per-run generated config leaves the project's own file exactly as its
|
|
19
|
+
* author intended and gives `peaks mut` the selection the caller asked for.
|
|
20
|
+
*
|
|
21
|
+
* WHERE IT LIVES. Under the project's `.peaks/_runtime/<sid>/mut/`, which is
|
|
22
|
+
* gitignored runtime state and is already in `alwaysIgnoredPatterns`, so the file
|
|
23
|
+
* neither pollutes the tree nor gets copied into the Stryker sandbox.
|
|
24
|
+
*/
|
|
25
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
26
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
27
|
+
/** One `'<path>',` line for an array literal in the generated module. */
|
|
28
|
+
function includeLine(projectRoot, file) {
|
|
29
|
+
const rel = relative(projectRoot, resolve(projectRoot, file)).split(sep).join('/');
|
|
30
|
+
return ` '${rel.replace(/'/g, "\\'")}',`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Write a vitest config under `<project>/.peaks/_runtime/<sid>/mut/` whose
|
|
34
|
+
* `include` is exactly `testFiles`, and whose aliases match the project's own
|
|
35
|
+
* `~/src/*` mapping so tests load exactly as they do normally.
|
|
36
|
+
*
|
|
37
|
+
* `setupFiles` is carried over from the project's config when the caller names
|
|
38
|
+
* one: a suite that depends on global setup (the workspace build, for instance)
|
|
39
|
+
* fails without it, and a mutation run that fails for a setup reason reports
|
|
40
|
+
* mutants as killed when nothing ran.
|
|
41
|
+
*/
|
|
42
|
+
export function writeRunScopedVitestConfig(input) {
|
|
43
|
+
const projectRoot = resolve(input.project);
|
|
44
|
+
const outDir = join(projectRoot, '.peaks', '_runtime', input.sessionId, 'mut');
|
|
45
|
+
mkdirSync(outDir, { recursive: true });
|
|
46
|
+
const configPath = join(outDir, 'vitest.run-scoped.config.mjs');
|
|
47
|
+
// PROJECT-RELATIVE, never absolute. Stryker copies the project into
|
|
48
|
+
// `.stryker-tmp/sandbox-*` and evaluates this config THERE, so an absolute
|
|
49
|
+
// path baked at generation time names the ORIGINAL tree — outside the
|
|
50
|
+
// sandbox's `root`, which vitest then filters away, reporting zero tests.
|
|
51
|
+
// Measured 2026-11-17: absolute includes produced exactly that.
|
|
52
|
+
const includes = input.testFiles.map((f) => includeLine(projectRoot, f)).join('\n');
|
|
53
|
+
const setup = (input.setupFiles ?? []).map((f) => includeLine(projectRoot, f)).join('\n');
|
|
54
|
+
writeFileSync(configPath, renderConfigSource(includes, setup), 'utf8');
|
|
55
|
+
return { configPath };
|
|
56
|
+
}
|
|
57
|
+
/** The module text a run-scoped config is made of. Separate from the file write
|
|
58
|
+
* so the template stays readable (and under the function-length cap). */
|
|
59
|
+
function renderConfigSource(includes, setup) {
|
|
60
|
+
return [
|
|
61
|
+
'// GENERATED PER MUTATION RUN — do not edit, do not commit.',
|
|
62
|
+
'//',
|
|
63
|
+
'// Its `include` is exactly the test files this run was asked for, which is',
|
|
64
|
+
"// what `--test-files` means. See writeRunScopedVitestConfig's header.",
|
|
65
|
+
'',
|
|
66
|
+
'// NO `vitest/config` IMPORT, and a PLAIN OBJECT export. A target project may',
|
|
67
|
+
'// have no node_modules at all — the integration fixture deliberately has',
|
|
68
|
+
'// none, to prove the runner is loaded from peaks-loop own installation — so',
|
|
69
|
+
'// `import { defineConfig } from "vitest/config"` would fail to resolve and',
|
|
70
|
+
'// the run would die before Stryker started. `defineConfig` is a typing',
|
|
71
|
+
'// helper, not a requirement: vitest accepts an exported plain object.',
|
|
72
|
+
'',
|
|
73
|
+
'// NO `root`, AND RELATIVE `include`/`alias` BASE. Stryker evaluates this',
|
|
74
|
+
'// config inside a copy of the project at `.stryker-tmp/sandbox-*`, so any',
|
|
75
|
+
'// absolute path baked at generation time would name the ORIGINAL tree —',
|
|
76
|
+
'// outside the sandbox — and vitest would filter every include away',
|
|
77
|
+
'// (measured 2026-11-17: exactly zero tests selected that way). Omitting',
|
|
78
|
+
'// `root` lets vitest use its own cwd, which is the sandbox.',
|
|
79
|
+
'const projectRoot = process.cwd();',
|
|
80
|
+
'',
|
|
81
|
+
'export default {',
|
|
82
|
+
' resolve: {',
|
|
83
|
+
' alias: [',
|
|
84
|
+
" { find: /^~\\/src\\/(.*)$/, replacement: projectRoot + '/src/' + '$1' },",
|
|
85
|
+
" { find: /^~\\/src\\/(.*)\\.js$/, replacement: projectRoot + '/src/' + '$1' + '.ts' }",
|
|
86
|
+
' ]',
|
|
87
|
+
' },',
|
|
88
|
+
' test: {',
|
|
89
|
+
' include: [\n' + includes + '\n ],',
|
|
90
|
+
...(setup === '' ? [] : [' setupFiles: [\n' + setup + '\n ],']),
|
|
91
|
+
' passWithNoTests: false',
|
|
92
|
+
' }',
|
|
93
|
+
'};',
|
|
94
|
+
''
|
|
95
|
+
].join('\n');
|
|
96
|
+
}
|
|
97
|
+
/** Display path for a generated config, relative to the project when possible. */
|
|
98
|
+
export function displayConfigPath(project, configPath) {
|
|
99
|
+
const rel = relative(resolve(project), configPath);
|
|
100
|
+
return rel === '' ? configPath : rel.split(sep).join('/');
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The `vitest` options for a run that names its test files.
|
|
104
|
+
*
|
|
105
|
+
* TWO THINGS, both required:
|
|
106
|
+
* - `related: false` — an explicit test list is authoritative, so vitest's
|
|
107
|
+
* related-mode narrowing must not discard it;
|
|
108
|
+
* - `configFile` — the generated config below, whose `include` IS the list.
|
|
109
|
+
* A project `stryker.conf.js` normally points at a config with a fixed
|
|
110
|
+
* short `include`, and vitest filters `--test-files` through it, so any
|
|
111
|
+
* other file selects ZERO tests and the dry run aborts with "No tests were
|
|
112
|
+
* executed". Measured 2026-11-17: a new test file could not be
|
|
113
|
+
* mutation-tested at all.
|
|
114
|
+
*
|
|
115
|
+
* WITHOUT A SESSION ID, `configFile` is OMITTED and only `related` is returned.
|
|
116
|
+
* This function builds OPTIONS; it does not own the run's preconditions. An
|
|
117
|
+
* earlier version threw here, which made every caller that only inspects the
|
|
118
|
+
* built options — the package's own `stryker-options.test.ts` does exactly that
|
|
119
|
+
* — supply a session id it has no use for. The requirement belongs where the
|
|
120
|
+
* run is started: `peaks mut run` declares `--session-id` a REQUIRED option, so
|
|
121
|
+
* an unscoped run cannot reach Stryker through the CLI. A programmatic caller
|
|
122
|
+
* that omits it falls back to the project's own `include` and sees the
|
|
123
|
+
* zero-tests abort, which is loud and names its own cause.
|
|
124
|
+
*/
|
|
125
|
+
export function scopedVitestOptions(input) {
|
|
126
|
+
if (input.sessionId === undefined) {
|
|
127
|
+
return { related: false };
|
|
128
|
+
}
|
|
129
|
+
const generated = writeRunScopedVitestConfig({
|
|
130
|
+
project: input.project,
|
|
131
|
+
sessionId: input.sessionId,
|
|
132
|
+
testFiles: input.testFiles,
|
|
133
|
+
...(input.setupFiles !== undefined ? { setupFiles: input.setupFiles } : {})
|
|
134
|
+
});
|
|
135
|
+
return { related: false, configFile: generated.configPath };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Resolve test-file patterns against the project root so the result does
|
|
139
|
+
* not depend on the caller's CWD. Absolute patterns are kept as-is.
|
|
140
|
+
*
|
|
141
|
+
* PURE: a path that does not exist is resolved anyway. Rejecting it is this
|
|
142
|
+
* module's own `assertTestFilesUsable`, which runs at the boundary that owns
|
|
143
|
+
* the file system — see the module header.
|
|
144
|
+
*
|
|
145
|
+
* Lives here rather than in `stryker-options.ts` because it is about test
|
|
146
|
+
* files, not about Stryker options; the options builder imports it.
|
|
147
|
+
*/
|
|
148
|
+
export function resolveTestFiles(project, patterns) {
|
|
149
|
+
if (!patterns || patterns.length === 0) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
return patterns.map((pattern) => (isAbsolute(pattern) ? pattern : resolve(project, pattern)));
|
|
153
|
+
}
|