peaks-loop-mut 0.1.72 → 0.1.74
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 +21 -4
- package/dist/services/mut/mut-runner.d.ts.map +1 -1
- package/dist/services/mut/mut-runner.js +23 -3
- package/dist/services/mut/production-stryker.d.ts +2 -0
- package/dist/services/mut/production-stryker.d.ts.map +1 -1
- package/dist/services/mut/production-stryker.js +125 -68
- package/dist/services/mut/stryker-errors.d.ts +28 -0
- package/dist/services/mut/stryker-errors.d.ts.map +1 -0
- package/dist/services/mut/stryker-errors.js +29 -0
- package/dist/services/mut/stryker-options.d.ts +80 -0
- package/dist/services/mut/stryker-options.d.ts.map +1 -0
- package/dist/services/mut/stryker-options.js +151 -0
- package/dist/services/mut/stryker-plugin.d.ts +6 -0
- package/dist/services/mut/stryker-plugin.d.ts.map +1 -0
- package/dist/services/mut/stryker-plugin.js +61 -0
- package/dist/services/mut/stryker-result.d.ts +22 -0
- package/dist/services/mut/stryker-result.d.ts.map +1 -0
- package/dist/services/mut/stryker-result.js +77 -0
- package/package.json +3 -1
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* DRY: production implementation lives in this file; tests mock the
|
|
8
8
|
* invokeStryker injection point.
|
|
9
9
|
* KISS: keep the public surface narrow — input, invoker, output.
|
|
10
|
+
*
|
|
11
|
+
* The invoker input shape carries the mutation scope (`mutate`) so the
|
|
12
|
+
* CLI can drive it (R4). Every field is optional except `project` and
|
|
13
|
+
* `testFiles`, so the injected-invoker seam keeps working unchanged.
|
|
10
14
|
*/
|
|
11
15
|
import type { MutationReport } from './types.js';
|
|
12
16
|
export interface StrykerRawResult {
|
|
@@ -24,13 +28,26 @@ export interface StrykerRawResult {
|
|
|
24
28
|
}>;
|
|
25
29
|
}>;
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
/** The input an invoker receives. */
|
|
32
|
+
export interface StrykerInvokerInput {
|
|
33
|
+
/** Project root — the scope of the mutation run. */
|
|
34
|
+
readonly project: string;
|
|
35
|
+
/** Test files the mutation run must execute. */
|
|
36
|
+
readonly testFiles: ReadonlyArray<string>;
|
|
37
|
+
/** Source patterns to mutate. Empty means "let the project config decide". */
|
|
38
|
+
readonly mutate?: ReadonlyArray<string>;
|
|
39
|
+
readonly tsconfigFile?: string;
|
|
40
|
+
readonly timeoutMs?: number;
|
|
41
|
+
readonly concurrency?: number;
|
|
42
|
+
}
|
|
43
|
+
export type StrykerInvoker = (opts: StrykerInvokerInput) => Promise<StrykerRawResult>;
|
|
31
44
|
export interface RunMutationInput {
|
|
32
45
|
readonly project: string;
|
|
33
46
|
readonly testFiles: ReadonlyArray<string>;
|
|
47
|
+
readonly mutate?: ReadonlyArray<string>;
|
|
48
|
+
readonly tsconfigFile?: string;
|
|
49
|
+
readonly timeoutMs?: number;
|
|
50
|
+
readonly concurrency?: number;
|
|
34
51
|
readonly invokeStryker: StrykerInvoker;
|
|
35
52
|
}
|
|
36
53
|
export interface RunMutationOutput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mut-runner.d.ts","sourceRoot":"","sources":["../../../src/services/mut/mut-runner.ts"],"names":[],"mappings":"AAAA
|
|
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;CAC/B;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,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,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,CA8BrF"}
|
|
@@ -3,12 +3,15 @@ export async function runMutation(input) {
|
|
|
3
3
|
try {
|
|
4
4
|
raw = await input.invokeStryker({
|
|
5
5
|
project: input.project,
|
|
6
|
-
testFiles: input.testFiles
|
|
6
|
+
testFiles: input.testFiles,
|
|
7
|
+
mutate: input.mutate,
|
|
8
|
+
tsconfigFile: input.tsconfigFile,
|
|
9
|
+
timeoutMs: input.timeoutMs,
|
|
10
|
+
concurrency: input.concurrency
|
|
7
11
|
});
|
|
8
12
|
}
|
|
9
13
|
catch (err) {
|
|
10
|
-
|
|
11
|
-
throw new Error(`Stryker invocation failed: ${message}`);
|
|
14
|
+
throw wrapInvocationError(err);
|
|
12
15
|
}
|
|
13
16
|
const killRate = raw.mutantsTotal === 0 ? 0 : raw.mutantsKilled / raw.mutantsTotal;
|
|
14
17
|
return {
|
|
@@ -27,3 +30,20 @@ export async function runMutation(input) {
|
|
|
27
30
|
}
|
|
28
31
|
};
|
|
29
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Wrap an invoker failure while KEEPING its machine-readable `code`.
|
|
35
|
+
* The production invoker raises named codes (`MUT_TOOLCHAIN_UNAVAILABLE`,
|
|
36
|
+
* `MUT_NO_MUTANTS`, …) and the CLI envelope must surface them instead of
|
|
37
|
+
* collapsing every failure into one anonymous message.
|
|
38
|
+
*/
|
|
39
|
+
function wrapInvocationError(err) {
|
|
40
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41
|
+
const wrapped = new Error(`Stryker invocation failed: ${message}`);
|
|
42
|
+
if (err && typeof err === 'object' && 'code' in err) {
|
|
43
|
+
const code = err.code;
|
|
44
|
+
if (typeof code === 'string') {
|
|
45
|
+
wrapped.code = code;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return wrapped;
|
|
49
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { StrykerInvoker } from './mut-runner.js';
|
|
2
|
+
import { MUT_ERROR_CODES, MutToolchainError } from './stryker-errors.js';
|
|
3
|
+
export { MUT_ERROR_CODES, MutToolchainError };
|
|
2
4
|
export declare function createProductionStrykerInvoker(): StrykerInvoker;
|
|
3
5
|
//# sourceMappingURL=production-stryker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"production-stryker.d.ts","sourceRoot":"","sources":["../../../src/services/mut/production-stryker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"production-stryker.d.ts","sourceRoot":"","sources":["../../../src/services/mut/production-stryker.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AASzE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,CAAC;AAY9C,wBAAgB,8BAA8B,IAAI,cAAc,CAuC/D"}
|
|
@@ -1,79 +1,136 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Production Stryker invoker
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Production Stryker invoker — runs a REAL mutation test through
|
|
3
|
+
* `@stryker-mutator/core`'s programmatic API.
|
|
4
|
+
*
|
|
5
|
+
* MEASURED against the installed toolchain (@stryker-mutator/core 9.6.1,
|
|
6
|
+
* @stryker-mutator/vitest-runner 9.6.1):
|
|
7
|
+
*
|
|
8
|
+
* - PROJECT SCOPE. `Stryker.runMutationTest()` hands its cliOptions to
|
|
9
|
+
* `PrepareExecutor`, whose `ConfigReader` looks for a config file and
|
|
10
|
+
* whose `ProjectReader` resolves every `mutate` / `testFiles` pattern
|
|
11
|
+
* against `process.cwd()` (`config/file-matcher.js` →
|
|
12
|
+
* `path.resolve(pattern)`). The project of a run is therefore decided
|
|
13
|
+
* by the CWD, so this invoker chdirs into `--project` for the run and
|
|
14
|
+
* restores the previous CWD in a `finally`. The chdir is
|
|
15
|
+
* process-global, so runs are serialised through `runExclusive()`.
|
|
16
|
+
* - PLUGIN LOADING. The vitest runner is resolved from THIS package's own
|
|
17
|
+
* installation — see `stryker-plugin.ts`.
|
|
18
|
+
*
|
|
19
|
+
* NO FAKE GREEN. A run that produces zero mutants, or that cannot load
|
|
20
|
+
* its test runner, fails with a named error code — it never reports
|
|
21
|
+
* `mutantsTotal: 0` as if it were a measurement.
|
|
22
|
+
*
|
|
23
|
+
* THE SPLIT. This module used to carry the plugin resolution and the
|
|
24
|
+
* mutant-result normalisation as well, and grew past the repository's
|
|
25
|
+
* raw-line cap (`src/services/scan/file-size-policy.ts` → 300 for
|
|
26
|
+
* `packages/**`). Those halves now live in `stryker-errors.ts` (the named
|
|
27
|
+
* codes), `stryker-plugin.ts` (the plugin path) and `stryker-result.ts`
|
|
28
|
+
* (the report shaping). The names THIS module exports are unchanged.
|
|
5
29
|
*/
|
|
6
|
-
import {
|
|
30
|
+
import { existsSync } from 'node:fs';
|
|
31
|
+
import { resolve } from 'node:path';
|
|
32
|
+
import { MUT_ERROR_CODES, MutToolchainError } from './stryker-errors.js';
|
|
33
|
+
import { buildStrykerOptions, STRYKER_DEFAULTS } from './stryker-options.js';
|
|
34
|
+
import { resolveVitestRunnerPlugin } from './stryker-plugin.js';
|
|
35
|
+
import { normalizeMutants } from './stryker-result.js';
|
|
36
|
+
export { MUT_ERROR_CODES, MutToolchainError };
|
|
37
|
+
/** The config file names Stryker looks for (SUPPORTED_CONFIG_FILE_NAMES, core 9.6.1). */
|
|
38
|
+
const STRYKER_CONFIG_FILE_NAMES = ['', '.'].flatMap((prefix) => ['.conf', '.config'].flatMap((suffix) => ['json', 'js', 'mjs', 'cjs'].map((ext) => `${prefix}stryker${suffix}.${ext}`)));
|
|
39
|
+
/** Serialises the process-global CWD window (see the module header). */
|
|
40
|
+
let runQueue = Promise.resolve();
|
|
7
41
|
export function createProductionStrykerInvoker() {
|
|
8
|
-
return async (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
42
|
+
return async (input) => {
|
|
43
|
+
const project = resolve(input.project);
|
|
44
|
+
if (!existsSync(project)) {
|
|
45
|
+
throw new MutToolchainError(MUT_ERROR_CODES.projectNotFound, `The project directory "${project}" does not exist.`);
|
|
46
|
+
}
|
|
47
|
+
assertMutateScope(project, input.mutate);
|
|
48
|
+
const pluginDescriptors = [resolveVitestRunnerPlugin()];
|
|
49
|
+
// A project `stryker.conf.js` owns the runner, the timing and the
|
|
50
|
+
// coverage settings; a project without one gets the CLI's defaults.
|
|
51
|
+
const projectOwned = hasProjectStrykerConfig(project)
|
|
52
|
+
? {}
|
|
53
|
+
: {
|
|
54
|
+
testRunner: STRYKER_DEFAULTS.testRunner,
|
|
55
|
+
timeoutMs: STRYKER_DEFAULTS.timeoutMS,
|
|
56
|
+
concurrency: STRYKER_DEFAULTS.concurrency,
|
|
57
|
+
coverageAnalysis: STRYKER_DEFAULTS.coverageAnalysis
|
|
58
|
+
};
|
|
59
|
+
const { options } = buildStrykerOptions({
|
|
60
|
+
project,
|
|
61
|
+
mutate: input.mutate,
|
|
62
|
+
testFiles: input.testFiles,
|
|
63
|
+
pluginDescriptors,
|
|
64
|
+
tsconfigFile: input.tsconfigFile,
|
|
65
|
+
...projectOwned
|
|
66
|
+
});
|
|
67
|
+
const mutants = await runInProject(project, options);
|
|
68
|
+
if (mutants.length === 0) {
|
|
69
|
+
throw new MutToolchainError(MUT_ERROR_CODES.noMutants, 'The mutation run produced 0 mutants. Check the --mutate patterns against the project root ' +
|
|
70
|
+
`("${project}") — a pattern that matches no file is a configuration error, not a passing measurement.`);
|
|
71
|
+
}
|
|
72
|
+
return normalizeMutants(mutants, project);
|
|
18
73
|
};
|
|
19
74
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
75
|
+
/**
|
|
76
|
+
* R4: the mutation scope must come from `--mutate`, or from a Stryker
|
|
77
|
+
* config file at the project root (backwards compatibility).
|
|
78
|
+
*/
|
|
79
|
+
function assertMutateScope(project, mutate) {
|
|
80
|
+
if (mutate && mutate.length > 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (hasProjectStrykerConfig(project)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
throw new MutToolchainError(MUT_ERROR_CODES.mutatePatternRequired, `No mutation scope was given and no Stryker config file was found in "${project}". ` +
|
|
87
|
+
'Pass --mutate <patterns...> (for example --mutate "src/**/*.ts") or add a stryker.conf.js at the project root.');
|
|
88
|
+
}
|
|
89
|
+
/** True when the project root carries a config file Stryker would read. */
|
|
90
|
+
function hasProjectStrykerConfig(project) {
|
|
91
|
+
return STRYKER_CONFIG_FILE_NAMES.some((name) => existsSync(resolve(project, name)));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Run Stryker with the project as the CWD, restoring the previous CWD
|
|
95
|
+
* afterwards. Serialised so concurrent invocations cannot interleave.
|
|
96
|
+
*/
|
|
97
|
+
async function runInProject(project, options) {
|
|
98
|
+
return runExclusive(async () => {
|
|
99
|
+
const previousCwd = process.cwd();
|
|
100
|
+
try {
|
|
101
|
+
process.chdir(project);
|
|
102
|
+
const Stryker = (await import('@stryker-mutator/core')).Stryker;
|
|
103
|
+
return await new Stryker(options).runMutationTest();
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
throw toMutError(err);
|
|
38
107
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
else if (m.status === 'Survived') {
|
|
42
|
-
bucket.survived++;
|
|
43
|
-
bucket.survivedEntries.push({
|
|
44
|
-
line: m.location.start.line + 1, // Stryker is 0-based; reports are 1-based.
|
|
45
|
-
mutation: m.replacement,
|
|
46
|
-
survivedBecause: m.statusReason ?? ''
|
|
47
|
-
});
|
|
108
|
+
finally {
|
|
109
|
+
process.chdir(previousCwd);
|
|
48
110
|
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** Queue a unit of work so only one Stryker run owns the CWD at a time. */
|
|
114
|
+
function runExclusive(fn) {
|
|
115
|
+
const result = runQueue.then(fn, fn);
|
|
116
|
+
runQueue = result.then(() => undefined, () => undefined);
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
/** Map a Stryker failure onto a named error code. */
|
|
120
|
+
function toMutError(err) {
|
|
121
|
+
if (err instanceof MutToolchainError) {
|
|
122
|
+
return err;
|
|
49
123
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const total = b.killed + b.survived;
|
|
53
|
-
const killRate = total === 0 ? 0 : b.killed / total;
|
|
54
|
-
return { file, killRate, survived: b.survivedEntries };
|
|
55
|
-
})
|
|
56
|
-
// Stable order for MUT.sig / reports.
|
|
57
|
-
.sort((a, b) => a.file.localeCompare(b.file));
|
|
58
|
-
return {
|
|
59
|
-
mutantsTotal: mutants.length,
|
|
60
|
-
mutantsKilled,
|
|
61
|
-
mutantsSurvived,
|
|
62
|
-
mutantsTimeout,
|
|
63
|
-
perFile
|
|
64
|
-
};
|
|
124
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
125
|
+
return new MutToolchainError(classifyStrykerFailure(message), message, { cause: err });
|
|
65
126
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
else if (m.status === 'Survived')
|
|
74
|
-
mutantsSurvived++;
|
|
75
|
-
else if (m.status === 'Timeout')
|
|
76
|
-
mutantsTimeout++;
|
|
127
|
+
/** A missing plugin / package / runner is a toolchain problem, not a generic failure. */
|
|
128
|
+
function classifyStrykerFailure(message) {
|
|
129
|
+
if (/cannot find .*plugin/i.test(message) ||
|
|
130
|
+
/does not support the --testfiles option/i.test(message) ||
|
|
131
|
+
/cannot find (?:package|module)/i.test(message) ||
|
|
132
|
+
/ERR_MODULE_NOT_FOUND/.test(message)) {
|
|
133
|
+
return MUT_ERROR_CODES.toolchainUnavailable;
|
|
77
134
|
}
|
|
78
|
-
return
|
|
135
|
+
return MUT_ERROR_CODES.failed;
|
|
79
136
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The named error codes of the mutation pipeline, and the error type that
|
|
3
|
+
* carries them.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS IS ITS OWN MODULE
|
|
6
|
+
* ---------------------------
|
|
7
|
+
* The production invoker raises these codes from three places, and the plugin
|
|
8
|
+
* resolver raises one of them from a module of its own. Keeping the codes
|
|
9
|
+
* here lets both raise the SAME error type without an import cycle;
|
|
10
|
+
* `production-stryker.ts` re-exports these names, so the names this package
|
|
11
|
+
* exports are unchanged by the split.
|
|
12
|
+
*/
|
|
13
|
+
/** Named error codes surfaced by the production invoker (see R7). */
|
|
14
|
+
export declare const MUT_ERROR_CODES: {
|
|
15
|
+
readonly toolchainUnavailable: "MUT_TOOLCHAIN_UNAVAILABLE";
|
|
16
|
+
readonly projectNotFound: "MUT_PROJECT_NOT_FOUND";
|
|
17
|
+
readonly mutatePatternRequired: "MUT_MUTATE_PATTERN_REQUIRED";
|
|
18
|
+
readonly noMutants: "MUT_NO_MUTANTS";
|
|
19
|
+
readonly failed: "MUT_FAILED";
|
|
20
|
+
};
|
|
21
|
+
/** An error carrying a machine-readable `code` for the CLI envelope. */
|
|
22
|
+
export declare class MutToolchainError extends Error {
|
|
23
|
+
readonly code: string;
|
|
24
|
+
constructor(code: string, message: string, options?: {
|
|
25
|
+
cause?: unknown;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=stryker-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stryker-errors.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,qEAAqE;AACrE,eAAO,MAAM,eAAe;;;;;;CAMlB,CAAC;AAEX,wEAAwE;AACxE,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAKzE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The named error codes of the mutation pipeline, and the error type that
|
|
3
|
+
* carries them.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS IS ITS OWN MODULE
|
|
6
|
+
* ---------------------------
|
|
7
|
+
* The production invoker raises these codes from three places, and the plugin
|
|
8
|
+
* resolver raises one of them from a module of its own. Keeping the codes
|
|
9
|
+
* here lets both raise the SAME error type without an import cycle;
|
|
10
|
+
* `production-stryker.ts` re-exports these names, so the names this package
|
|
11
|
+
* exports are unchanged by the split.
|
|
12
|
+
*/
|
|
13
|
+
/** Named error codes surfaced by the production invoker (see R7). */
|
|
14
|
+
export const MUT_ERROR_CODES = {
|
|
15
|
+
toolchainUnavailable: 'MUT_TOOLCHAIN_UNAVAILABLE',
|
|
16
|
+
projectNotFound: 'MUT_PROJECT_NOT_FOUND',
|
|
17
|
+
mutatePatternRequired: 'MUT_MUTATE_PATTERN_REQUIRED',
|
|
18
|
+
noMutants: 'MUT_NO_MUTANTS',
|
|
19
|
+
failed: 'MUT_FAILED'
|
|
20
|
+
};
|
|
21
|
+
/** An error carrying a machine-readable `code` for the CLI envelope. */
|
|
22
|
+
export class MutToolchainError extends Error {
|
|
23
|
+
code;
|
|
24
|
+
constructor(code, message, options) {
|
|
25
|
+
super(message, options);
|
|
26
|
+
this.name = 'MutToolchainError';
|
|
27
|
+
this.code = code;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Stryker } from '@stryker-mutator/core';
|
|
2
|
+
/**
|
|
3
|
+
* The exact option type `new Stryker(...)` accepts, derived from the
|
|
4
|
+
* installed `@stryker-mutator/core` (9.6.1) instead of re-declared by
|
|
5
|
+
* hand — so `tsc` checks every option name against the real API.
|
|
6
|
+
*/
|
|
7
|
+
export type StrykerCliOptions = ConstructorParameters<typeof Stryker>[0];
|
|
8
|
+
/**
|
|
9
|
+
* The options this package actually sets.
|
|
10
|
+
*
|
|
11
|
+
* Two deviations from `StrykerCliOptions`, both deliberate:
|
|
12
|
+
*
|
|
13
|
+
* - `logLevel` / `fileLogLevel` are typed as plain strings. In
|
|
14
|
+
* `@stryker-mutator/api` 9.6.1 they are the `LogLevel` const enum,
|
|
15
|
+
* and that package is NOT a declared dependency of peaks-loop-mut
|
|
16
|
+
* (pnpm's strict layout does not expose it here), so the enum type
|
|
17
|
+
* cannot be named. `production-stryker.ts` restores the narrow type at
|
|
18
|
+
* the single `new Stryker(...)` boundary.
|
|
19
|
+
* - `vitest` is a real Stryker option (it is in the core JSON schema and
|
|
20
|
+
* the vitest-runner plugin contributes it too), but the GENERATED
|
|
21
|
+
* TypeScript type for `StrykerOptions` does not declare it — measured
|
|
22
|
+
* in `@stryker-mutator/api` 9.6.1 → `src-generated/stryker-core.d.ts`.
|
|
23
|
+
* The option therefore travels in an intersection type: the extra key
|
|
24
|
+
* is accepted at runtime (the core schema validates it) and ignored by
|
|
25
|
+
* the type system.
|
|
26
|
+
*/
|
|
27
|
+
export type StrykerOptionsShape = Omit<StrykerCliOptions, 'logLevel' | 'fileLogLevel'> & {
|
|
28
|
+
logLevel?: string;
|
|
29
|
+
fileLogLevel?: string;
|
|
30
|
+
vitest?: {
|
|
31
|
+
related?: boolean;
|
|
32
|
+
configFile?: string;
|
|
33
|
+
dir?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** Every default the builder applies lives here — nowhere else. */
|
|
37
|
+
export declare const STRYKER_DEFAULTS: {
|
|
38
|
+
readonly testRunner: "vitest";
|
|
39
|
+
readonly coverageAnalysis: "off";
|
|
40
|
+
readonly timeoutMS: 30000;
|
|
41
|
+
readonly concurrency: 1;
|
|
42
|
+
readonly reporters: ReadonlyArray<string>;
|
|
43
|
+
readonly logLevel: "off";
|
|
44
|
+
readonly fileLogLevel: "off";
|
|
45
|
+
readonly allowConsoleColors: false;
|
|
46
|
+
};
|
|
47
|
+
export interface StrykerOptionsInput {
|
|
48
|
+
/** Project root — the scope of the mutation run. */
|
|
49
|
+
readonly project: string;
|
|
50
|
+
/** Source patterns to mutate. Empty means "let the project config decide". */
|
|
51
|
+
readonly mutate?: ReadonlyArray<string>;
|
|
52
|
+
/** Test files to run. Empty means "let the runner discover them". */
|
|
53
|
+
readonly testFiles?: ReadonlyArray<string>;
|
|
54
|
+
/** Absolute paths (or file URLs) of Stryker plugins to load. */
|
|
55
|
+
readonly pluginDescriptors?: ReadonlyArray<string>;
|
|
56
|
+
readonly tsconfigFile?: string;
|
|
57
|
+
readonly timeoutMs?: number;
|
|
58
|
+
readonly concurrency?: number;
|
|
59
|
+
readonly testRunner?: string;
|
|
60
|
+
readonly coverageAnalysis?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface BuiltStrykerOptions {
|
|
63
|
+
readonly options: StrykerCliOptions;
|
|
64
|
+
readonly pluginDescriptors: ReadonlyArray<string>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Build the Stryker options for one mutation run.
|
|
68
|
+
*
|
|
69
|
+
* Pure: the same input always yields the same output.
|
|
70
|
+
*/
|
|
71
|
+
export declare function buildStrykerOptions(input: StrykerOptionsInput): BuiltStrykerOptions;
|
|
72
|
+
/**
|
|
73
|
+
* Narrow the built options back to the type `new Stryker(...)` accepts.
|
|
74
|
+
* `StrykerCliOptions` is assignable to `StrykerOptionsShape`, so this
|
|
75
|
+
* assertion is a widening of two `logLevel` fields and never a cast that
|
|
76
|
+
* hides a wrong option name — every other option was already checked
|
|
77
|
+
* against the real API by `Omit<StrykerCliOptions, ...>`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function toStrykerCliOptions(options: StrykerOptionsShape): StrykerCliOptions;
|
|
80
|
+
//# sourceMappingURL=stryker-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stryker-options.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-options.ts"],"names":[],"mappings":"AAwDA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD;;;;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;;;;CAI9B,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,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;CACpC;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,CA+BnF;AAkCD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,GAAG,iBAAiB,CAEnF"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure Stryker configuration builder for `peaks mut`.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS
|
|
5
|
+
* ---------------
|
|
6
|
+
* Measured against the installed Stryker 9.6.1
|
|
7
|
+
* (`node_modules/@stryker-mutator/core/package.json` → 9.6.1,
|
|
8
|
+
* `@stryker-mutator/vitest-runner/package.json` → 9.6.1):
|
|
9
|
+
*
|
|
10
|
+
* - `new Stryker(cliOptions)` merges the cliOptions OVER whatever
|
|
11
|
+
* `stryker.conf.js` the ConfigReader found in the CWD
|
|
12
|
+
* (`config/config-reader.js` → `deepMerge(options, cliOptions)`).
|
|
13
|
+
* So the whole mutation surface can be expressed in code and the
|
|
14
|
+
* project no longer has to hand-author a Stryker config file.
|
|
15
|
+
* - `ConfigReader.findConfigFile()` looks the config file up relative
|
|
16
|
+
* to `process.cwd()`, and `ProjectReader` resolves every `mutate` /
|
|
17
|
+
* `testFiles` pattern against `process.cwd()` as well
|
|
18
|
+
* (`config/file-matcher.js` → `path.resolve(pattern)`). So the
|
|
19
|
+
* project scope of a run is decided by the CWD — the invoker owns
|
|
20
|
+
* that (see `production-stryker.ts`).
|
|
21
|
+
*
|
|
22
|
+
* DESIGN
|
|
23
|
+
* ------
|
|
24
|
+
* This module is PURE: no IO, no clock, no process state. Everything it
|
|
25
|
+
* needs arrives as input, so it can be unit-tested without Stryker being
|
|
26
|
+
* installed at all. The single source of truth for every default lives in
|
|
27
|
+
* `STRYKER_DEFAULTS` below — nothing else in the package may hard-code a
|
|
28
|
+
* default value.
|
|
29
|
+
*
|
|
30
|
+
* MEASURED BEHAVIOURS THIS ENCODES
|
|
31
|
+
* --------------------------------
|
|
32
|
+
* - `mutate` patterns are passed through VERBATIM. Stryker supports
|
|
33
|
+
* `!`-negation and `:line-range` suffixes (`!src/foo.ts`,
|
|
34
|
+
* `src/foo.ts:1-11`); `path.resolve()` would mangle both, so the
|
|
35
|
+
* patterns stay relative to the project root (the invoker chdirs
|
|
36
|
+
* there before the run).
|
|
37
|
+
* - `testFiles` patterns ARE resolved against the project root. Stryker
|
|
38
|
+
* resolves them with `path.resolve(pattern)` too, but relative to
|
|
39
|
+
* whatever the CWD happens to be; resolving them here makes the
|
|
40
|
+
* result independent of the caller's CWD.
|
|
41
|
+
* - `vitest.related` is forced OFF whenever explicit test files are
|
|
42
|
+
* given. With `related: true` (the Stryker default) the vitest
|
|
43
|
+
* runner narrows the dry run to test files that IMPORT the mutated
|
|
44
|
+
* source (`@stryker-mutator/vitest-runner` 9.6.1 →
|
|
45
|
+
* `vitest-test-runner.js` → `this.ctx.config.related = ...`). A
|
|
46
|
+
* mutated file that no test imports then yields "No tests were
|
|
47
|
+
* executed" and Stryker aborts BEFORE the mutation stage. That is
|
|
48
|
+
* the degradation this switch removes: with an explicit `--test-files`
|
|
49
|
+
* list, the list is authoritative. Measured — see the RD artifact.
|
|
50
|
+
* - `reporters: []` + `logLevel: 'off'` are what keep stdout free for
|
|
51
|
+
* the `--json` envelope: Stryker's logging backend writes to
|
|
52
|
+
* `process.stdout` (`core/stryker.js` → `provideLoggingBackend(
|
|
53
|
+
* rootInjector, process.stdout)`) and the built-in reporters write
|
|
54
|
+
* there too. Measured: stdout length 0 for a real run.
|
|
55
|
+
*/
|
|
56
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
57
|
+
/** Every default the builder applies lives here — nowhere else. */
|
|
58
|
+
export const STRYKER_DEFAULTS = {
|
|
59
|
+
testRunner: 'vitest',
|
|
60
|
+
coverageAnalysis: 'off',
|
|
61
|
+
timeoutMS: 30_000,
|
|
62
|
+
concurrency: 1,
|
|
63
|
+
reporters: [],
|
|
64
|
+
logLevel: 'off',
|
|
65
|
+
fileLogLevel: 'off',
|
|
66
|
+
allowConsoleColors: false
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Build the Stryker options for one mutation run.
|
|
70
|
+
*
|
|
71
|
+
* Pure: the same input always yields the same output.
|
|
72
|
+
*/
|
|
73
|
+
export function buildStrykerOptions(input) {
|
|
74
|
+
const project = resolve(input.project);
|
|
75
|
+
const pluginDescriptors = [...(input.pluginDescriptors ?? [])];
|
|
76
|
+
const options = {
|
|
77
|
+
reporters: [...STRYKER_DEFAULTS.reporters],
|
|
78
|
+
logLevel: STRYKER_DEFAULTS.logLevel,
|
|
79
|
+
fileLogLevel: STRYKER_DEFAULTS.fileLogLevel,
|
|
80
|
+
allowConsoleColors: STRYKER_DEFAULTS.allowConsoleColors
|
|
81
|
+
};
|
|
82
|
+
applyCallerOwnedOptions(options, input);
|
|
83
|
+
if (input.mutate && input.mutate.length > 0) {
|
|
84
|
+
// Verbatim: `!` negation and `:line-range` suffixes must survive.
|
|
85
|
+
options.mutate = [...input.mutate];
|
|
86
|
+
}
|
|
87
|
+
const testFiles = resolveTestFiles(project, input.testFiles);
|
|
88
|
+
if (testFiles.length > 0) {
|
|
89
|
+
options.testFiles = testFiles;
|
|
90
|
+
// An explicit test list is authoritative — do not let vitest's
|
|
91
|
+
// related-mode narrowing discard it. See the module header.
|
|
92
|
+
options.vitest = { related: false };
|
|
93
|
+
}
|
|
94
|
+
if (pluginDescriptors.length > 0) {
|
|
95
|
+
// `appendPlugins` (not `plugins`) so a project `stryker.conf.js` keeps
|
|
96
|
+
// its own plugin list; ours is added on top.
|
|
97
|
+
options.appendPlugins = pluginDescriptors;
|
|
98
|
+
}
|
|
99
|
+
return { options: toStrykerCliOptions(options), pluginDescriptors };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Apply the options the caller owns. Everything here is a PROJECT-owned
|
|
103
|
+
* setting: it is written only when the caller asked for it, so a project
|
|
104
|
+
* `stryker.conf.js` keeps its own value.
|
|
105
|
+
*
|
|
106
|
+
* - the test runner: the CLI names one only for a project without a
|
|
107
|
+
* config file. The vitest runner is the one that implements Stryker's
|
|
108
|
+
* `--testFiles` contract (the built-in `command` runner throws "The
|
|
109
|
+
* command test runner does not support the --testFiles option" —
|
|
110
|
+
* measured on @stryker-mutator/core 9.6.1), so a project that names
|
|
111
|
+
* another runner and is handed `--test-files` fails LOUDLY rather
|
|
112
|
+
* than silently running something else.
|
|
113
|
+
* - the timing and coverage settings: a project config file owns them.
|
|
114
|
+
*/
|
|
115
|
+
function applyCallerOwnedOptions(options, input) {
|
|
116
|
+
if (input.testRunner) {
|
|
117
|
+
options.testRunner = input.testRunner;
|
|
118
|
+
}
|
|
119
|
+
if (input.coverageAnalysis) {
|
|
120
|
+
options.coverageAnalysis = input.coverageAnalysis;
|
|
121
|
+
}
|
|
122
|
+
if (input.timeoutMs !== undefined) {
|
|
123
|
+
options.timeoutMS = input.timeoutMs;
|
|
124
|
+
}
|
|
125
|
+
if (input.concurrency !== undefined) {
|
|
126
|
+
options.concurrency = input.concurrency;
|
|
127
|
+
}
|
|
128
|
+
if (input.tsconfigFile) {
|
|
129
|
+
options.tsconfigFile = input.tsconfigFile;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Narrow the built options back to the type `new Stryker(...)` accepts.
|
|
134
|
+
* `StrykerCliOptions` is assignable to `StrykerOptionsShape`, so this
|
|
135
|
+
* assertion is a widening of two `logLevel` fields and never a cast that
|
|
136
|
+
* hides a wrong option name — every other option was already checked
|
|
137
|
+
* against the real API by `Omit<StrykerCliOptions, ...>`.
|
|
138
|
+
*/
|
|
139
|
+
export function toStrykerCliOptions(options) {
|
|
140
|
+
return options;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Resolve test-file patterns against the project root so the result does
|
|
144
|
+
* not depend on the caller's CWD. Absolute patterns are kept as-is.
|
|
145
|
+
*/
|
|
146
|
+
function resolveTestFiles(project, patterns) {
|
|
147
|
+
if (!patterns || patterns.length === 0) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
return patterns.map((pattern) => (isAbsolute(pattern) ? pattern : resolve(project, pattern)));
|
|
151
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stryker-plugin.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-plugin.ts"],"names":[],"mappings":"AA0BA;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAclD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolution of the vitest-runner plugin for the production Stryker invoker.
|
|
3
|
+
*
|
|
4
|
+
* MEASURED against @stryker-mutator/core 9.6.1 and
|
|
5
|
+
* @stryker-mutator/vitest-runner 9.6.1:
|
|
6
|
+
*
|
|
7
|
+
* `PluginLoader.resolvePluginModules()` accepts an absolute path and turns
|
|
8
|
+
* it into a `file://` URL, and the child worker re-imports that same
|
|
9
|
+
* descriptor. So the vitest runner is loaded from THIS package's own
|
|
10
|
+
* installation, never from the target project. Measured: a fixture with NO
|
|
11
|
+
* node_modules still ran it.
|
|
12
|
+
*
|
|
13
|
+
* WHY THE ABSOLUTE PATH AND NOT THE BARE SPECIFIER. The bare specifier would
|
|
14
|
+
* only work when the runner happens to sit next to `@stryker-mutator/core` in
|
|
15
|
+
* the same `node_modules`. Measured in this repository's pnpm layout, the
|
|
16
|
+
* glob Stryker uses for its default plugin list resolves to core's pnpm
|
|
17
|
+
* sibling directory, which contains only api, core, instrumenter and util —
|
|
18
|
+
* all four are in Stryker's `IGNORED_PACKAGES` list, so the default glob
|
|
19
|
+
* finds NO vitest runner.
|
|
20
|
+
*/
|
|
21
|
+
import { readFileSync } from 'node:fs';
|
|
22
|
+
import { createRequire } from 'node:module';
|
|
23
|
+
import { dirname, resolve } from 'node:path';
|
|
24
|
+
import { MUT_ERROR_CODES, MutToolchainError } from './stryker-errors.js';
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the vitest runner plugin from THIS package's own installation
|
|
27
|
+
* so the target project does not need a node_modules of its own.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveVitestRunnerPlugin() {
|
|
30
|
+
try {
|
|
31
|
+
const require = createRequire(import.meta.url);
|
|
32
|
+
const pkgPath = require.resolve('@stryker-mutator/vitest-runner/package.json');
|
|
33
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
34
|
+
return resolve(dirname(pkgPath), resolvePackageEntry(pkg.exports?.['.']));
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
throw new MutToolchainError(MUT_ERROR_CODES.toolchainUnavailable, 'The mutation toolchain is not available: @stryker-mutator/vitest-runner could not be resolved ' +
|
|
38
|
+
`from the peaks-loop-mut installation. ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Read a package `exports` entry that may be a string or a nested object. */
|
|
42
|
+
function resolvePackageEntry(entry) {
|
|
43
|
+
if (typeof entry === 'string') {
|
|
44
|
+
return entry;
|
|
45
|
+
}
|
|
46
|
+
if (entry && typeof entry === 'object') {
|
|
47
|
+
const record = entry;
|
|
48
|
+
for (const candidate of [record['default'], record['import']]) {
|
|
49
|
+
if (typeof candidate === 'string') {
|
|
50
|
+
return candidate;
|
|
51
|
+
}
|
|
52
|
+
if (candidate && typeof candidate === 'object') {
|
|
53
|
+
const nested = candidate['default'];
|
|
54
|
+
if (typeof nested === 'string') {
|
|
55
|
+
return nested;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw new Error('the package does not declare a resolvable "exports" entry');
|
|
61
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StrykerRawResult } from './mut-runner.js';
|
|
2
|
+
/** Stryker 9 MutantResult, re-declared locally so this package does not
|
|
3
|
+
* depend on @stryker-mutator/api (the house convention, see types.ts). */
|
|
4
|
+
export interface StrykerMutant {
|
|
5
|
+
readonly fileName: string;
|
|
6
|
+
readonly status: 'Killed' | 'Survived' | 'Timeout' | 'NoCoverage' | 'CompileError' | 'RuntimeError' | 'Ignored' | 'Pending';
|
|
7
|
+
readonly replacement: string;
|
|
8
|
+
readonly location: {
|
|
9
|
+
readonly start: {
|
|
10
|
+
readonly line: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
readonly statusReason?: string;
|
|
14
|
+
}
|
|
15
|
+
/** The mutants Stryker produced, as this module reads them. */
|
|
16
|
+
type Mutants = ReadonlyArray<StrykerMutant>;
|
|
17
|
+
/**
|
|
18
|
+
* Normalize the mutants Stryker produced into the invoker's result shape.
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeMutants(mutants: Mutants, project: string): StrykerRawResult;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=stryker-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stryker-result.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-result.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD;0EAC0E;AAC1E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EACX,QAAQ,GACR,UAAU,GACV,SAAS,GACT,YAAY,GACZ,cAAc,GACd,cAAc,GACd,SAAS,GACT,SAAS,CAAC;IACd,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IACjE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,+DAA+D;AAC/D,KAAK,OAAO,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAE5C;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAyDpF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shaping of a Stryker mutation result into the report's own shape.
|
|
3
|
+
*
|
|
4
|
+
* Two things happen here and nowhere else:
|
|
5
|
+
*
|
|
6
|
+
* - the per-file buckets (`byFile`) are built, with the per-file kill rate
|
|
7
|
+
* and the surviving mutants' locations;
|
|
8
|
+
* - the file names are made PROJECT-RELATIVE and their separators are
|
|
9
|
+
* normalized to `/`, so the report — and therefore `MUT.sig`, which is a
|
|
10
|
+
* digest of the report — is identical on Windows and on POSIX.
|
|
11
|
+
*/
|
|
12
|
+
import { isAbsolute, relative, sep } from 'node:path';
|
|
13
|
+
/**
|
|
14
|
+
* Normalize the mutants Stryker produced into the invoker's result shape.
|
|
15
|
+
*/
|
|
16
|
+
export function normalizeMutants(mutants, project) {
|
|
17
|
+
const { mutantsKilled, mutantsSurvived, mutantsTimeout } = countStatuses(mutants);
|
|
18
|
+
// Bucket mutants by fileName to populate perFile. deriveFollowups iterates
|
|
19
|
+
// m.byFile to emit per-file followups (e.g. low_kill_rate) — leaving this
|
|
20
|
+
// empty (as v0 did) silently swallowed those followups in production.
|
|
21
|
+
const byFile = new Map();
|
|
22
|
+
for (const m of mutants) {
|
|
23
|
+
// Stryker returns absolute paths in MutantResult.fileName. Strip the
|
|
24
|
+
// project root so byFile[].file is repo-relative (e.g. "src/services/loop/...").
|
|
25
|
+
// path.relative falls back to the absolute path when input is outside
|
|
26
|
+
// project, which is the safest failure mode. The separators are
|
|
27
|
+
// normalized to "/" so the report — and therefore MUT.sig, which is a
|
|
28
|
+
// digest of the report — is identical on Windows and on POSIX.
|
|
29
|
+
const file = isAbsolute(m.fileName) && m.fileName.startsWith(project)
|
|
30
|
+
? relative(project, m.fileName).split(sep).join('/')
|
|
31
|
+
: m.fileName;
|
|
32
|
+
let bucket = byFile.get(file);
|
|
33
|
+
if (!bucket) {
|
|
34
|
+
bucket = { killed: 0, survived: 0, survivedEntries: [] };
|
|
35
|
+
byFile.set(file, bucket);
|
|
36
|
+
}
|
|
37
|
+
if (m.status === 'Killed')
|
|
38
|
+
bucket.killed++;
|
|
39
|
+
else if (m.status === 'Survived') {
|
|
40
|
+
bucket.survived++;
|
|
41
|
+
bucket.survivedEntries.push({
|
|
42
|
+
line: m.location.start.line + 1, // Stryker is 0-based; reports are 1-based.
|
|
43
|
+
mutation: m.replacement,
|
|
44
|
+
survivedBecause: m.statusReason ?? ''
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const perFile = [...byFile.entries()]
|
|
49
|
+
.map(([file, b]) => {
|
|
50
|
+
const total = b.killed + b.survived;
|
|
51
|
+
const killRate = total === 0 ? 0 : b.killed / total;
|
|
52
|
+
return { file, killRate, survived: b.survivedEntries };
|
|
53
|
+
})
|
|
54
|
+
// Stable order for MUT.sig / reports.
|
|
55
|
+
.sort((a, b) => a.file.localeCompare(b.file));
|
|
56
|
+
return {
|
|
57
|
+
mutantsTotal: mutants.length,
|
|
58
|
+
mutantsKilled,
|
|
59
|
+
mutantsSurvived,
|
|
60
|
+
mutantsTimeout,
|
|
61
|
+
perFile
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function countStatuses(mutants) {
|
|
65
|
+
let mutantsKilled = 0;
|
|
66
|
+
let mutantsSurvived = 0;
|
|
67
|
+
let mutantsTimeout = 0;
|
|
68
|
+
for (const m of mutants) {
|
|
69
|
+
if (m.status === 'Killed')
|
|
70
|
+
mutantsKilled++;
|
|
71
|
+
else if (m.status === 'Survived')
|
|
72
|
+
mutantsSurvived++;
|
|
73
|
+
else if (m.status === 'Timeout')
|
|
74
|
+
mutantsTimeout++;
|
|
75
|
+
}
|
|
76
|
+
return { mutantsKilled, mutantsSurvived, mutantsTimeout };
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peaks-loop-mut",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.74",
|
|
4
4
|
"description": "Mutation testing + assertion scanning + ECC cache for peaks-loop (workspace-internal)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"peaks-loop",
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
"node": ">=20.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@stryker-mutator/core": "^9.6.1",
|
|
32
|
+
"@stryker-mutator/vitest-runner": "^9.6.1",
|
|
31
33
|
"ecc-universal": "^2.2.3",
|
|
32
34
|
"zod": "^4.6.7"
|
|
33
35
|
},
|