peaks-loop-mut 0.1.75 → 0.1.76
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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/services/mut/assert-scanner.d.ts.map +1 -1
- package/dist/services/mut/assert-scanner.js +62 -47
- package/dist/services/mut/production-stryker.d.ts.map +1 -1
- package/dist/services/mut/production-stryker.js +15 -0
- package/dist/services/mut/stryker-errors.d.ts +21 -1
- package/dist/services/mut/stryker-errors.d.ts.map +1 -1
- package/dist/services/mut/stryker-errors.js +22 -2
- package/dist/services/mut/stryker-options.d.ts.map +1 -1
- package/dist/services/mut/stryker-options.js +23 -5
- package/dist/services/mut/test-files.d.ts +45 -0
- package/dist/services/mut/test-files.d.ts.map +1 -0
- package/dist/services/mut/test-files.js +245 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,7 @@
|
|
|
11
11
|
* import { installEccAgents } from 'peaks-loop-mut/services/agent/ecc-package-service';
|
|
12
12
|
*/
|
|
13
13
|
export * from './services/mut/index.js';
|
|
14
|
+
export { MUT_ERROR_CODES, MutToolchainError } from './services/mut/stryker-errors.js';
|
|
15
|
+
export { assertTestFilesUsable, buildTestFileMessage, collectTestFileProblems, isTestFilePattern, MAX_TEST_FILE_CANDIDATES, type TestFileProblem, type TestFilesInput } from './services/mut/test-files.js';
|
|
14
16
|
export { installEccAgents, materializeEccAgents, readEccMaterializeManifest, listMaterializedAgents, hasMaterializedEccAgents, resolveMaterializedAgentName, readMaterializedAgent, listEccAgents, ECC_PACKAGE_NAME, ECC_MATERIALIZE_VERSION, EccSourceError, isSafeAgentName, resolveEccAgentsDir, resolveEccMaterializedDir, resolveEccMaterializedManifestPath, resolveEccPackageRoot, type EccInstallResult, type EccMaterializeManifest, type EccSourceFailure } from './services/agent/ecc-package-service.js';
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,yBAAyB,CAAC;AAExC,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,EAC5B,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,kCAAkC,EAClC,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACtB,MAAM,yCAAyC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,yBAAyB,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACtF,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,wBAAwB,EACxB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,EAC5B,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,kCAAkC,EAClC,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACtB,MAAM,yCAAyC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,4 +11,6 @@
|
|
|
11
11
|
* import { installEccAgents } from 'peaks-loop-mut/services/agent/ecc-package-service';
|
|
12
12
|
*/
|
|
13
13
|
export * from './services/mut/index.js';
|
|
14
|
+
export { MUT_ERROR_CODES, MutToolchainError } from './services/mut/stryker-errors.js';
|
|
15
|
+
export { assertTestFilesUsable, buildTestFileMessage, collectTestFileProblems, isTestFilePattern, MAX_TEST_FILE_CANDIDATES } from './services/mut/test-files.js';
|
|
14
16
|
export { installEccAgents, materializeEccAgents, readEccMaterializeManifest, listMaterializedAgents, hasMaterializedEccAgents, resolveMaterializedAgentName, readMaterializedAgent, listEccAgents, ECC_PACKAGE_NAME, ECC_MATERIALIZE_VERSION, EccSourceError, isSafeAgentName, resolveEccAgentsDir, resolveEccMaterializedDir, resolveEccMaterializedManifestPath, resolveEccPackageRoot } from './services/agent/ecc-package-service.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert-scanner.d.ts","sourceRoot":"","sources":["../../../src/services/mut/assert-scanner.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,gBAAgB,EAA8C,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"assert-scanner.d.ts","sourceRoot":"","sources":["../../../src/services/mut/assert-scanner.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,gBAAgB,EAA8C,MAAM,YAAY,CAAC;AAgB/F,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC3C;AA0ED,wBAAsB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAmDhF"}
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* - toBe(x) where arg === receiver (toBe-self)
|
|
15
15
|
*/
|
|
16
16
|
import { readFile } from 'node:fs/promises';
|
|
17
|
-
import {
|
|
17
|
+
import { resolve } from 'node:path';
|
|
18
|
+
import { assertTestFilesUsable } from './test-files.js';
|
|
18
19
|
const WEAK_PATTERNS = [
|
|
19
20
|
{ pattern: 'toBeDefined', regex: /\.toBeDefined\s*\(\s*\)/g },
|
|
20
21
|
{ pattern: 'toBeTruthy', regex: /\.toBeTruthy\s*\(\s*\)/g },
|
|
@@ -50,61 +51,75 @@ async function countAssertions(content) {
|
|
|
50
51
|
function lineOf(content, offset) {
|
|
51
52
|
return content.slice(0, offset).split('\n').length;
|
|
52
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* The self-equality examples in one file: `expect(x).toEqual(x)` and
|
|
56
|
+
* `expect(x).toBe(x)` both need the RECEIVER extracted, so they share this.
|
|
57
|
+
* Extracted so `scanAssertions` stays inside the per-function line cap.
|
|
58
|
+
*/
|
|
59
|
+
function collectSelfExamples(content, file, regex) {
|
|
60
|
+
const examples = [];
|
|
61
|
+
for (const match of content.matchAll(regex)) {
|
|
62
|
+
const receivers = content
|
|
63
|
+
.slice(0, match.index ?? 0)
|
|
64
|
+
.match(/expect\s*\(\s*([a-zA-Z_$][\w$]*)\s*\)/g);
|
|
65
|
+
const lastReceiver = receivers?.[receivers.length - 1];
|
|
66
|
+
const receiverName = lastReceiver?.match(/expect\s*\(\s*([a-zA-Z_$][\w$]*)\s*\)/)?.[1];
|
|
67
|
+
if (receiverName && receiverName === match[1]) {
|
|
68
|
+
examples.push({ file, line: lineOf(content, match.index ?? 0), code: match[0] });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return examples;
|
|
72
|
+
}
|
|
73
|
+
/** The self-equality patterns, in the order they are reported. */
|
|
74
|
+
const SELF_PATTERNS = [
|
|
75
|
+
{ pattern: 'toEqual-self', regex: TO_EQUAL_SELF },
|
|
76
|
+
{ pattern: 'toBe-self', regex: TO_BE_SELF }
|
|
77
|
+
];
|
|
78
|
+
/** The weak-pattern examples of one file, grouped by pattern. */
|
|
79
|
+
function collectWeakPatternExamples(content, file) {
|
|
80
|
+
const found = new Map();
|
|
81
|
+
for (const { pattern, regex } of WEAK_PATTERNS) {
|
|
82
|
+
const matches = [...content.matchAll(regex)];
|
|
83
|
+
if (matches.length === 0) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
found.set(pattern, matches.map((m) => ({ file, line: lineOf(content, m.index ?? 0), code: m[0] })));
|
|
87
|
+
}
|
|
88
|
+
return found;
|
|
89
|
+
}
|
|
53
90
|
export async function scanAssertions(input) {
|
|
91
|
+
// BEFORE anything is read: a missing file must fail with a NAMED code
|
|
92
|
+
// (`MUT_TEST_FILE_NOT_FOUND`), not with whatever `readFile` throws, and a
|
|
93
|
+
// PATTERN must fail with its own code — this scanner reads literal files.
|
|
94
|
+
assertTestFilesUsable({
|
|
95
|
+
project: input.project,
|
|
96
|
+
testFiles: input.testFiles,
|
|
97
|
+
allowPatterns: false
|
|
98
|
+
});
|
|
54
99
|
let total = 0;
|
|
55
100
|
let weak = 0;
|
|
56
101
|
const byPattern = new Map();
|
|
57
102
|
for (const file of input.testFiles) {
|
|
58
|
-
|
|
103
|
+
// `resolve`, not `join`: an absolute `--test-files` entry must stay
|
|
104
|
+
// absolute instead of being appended to the project root.
|
|
105
|
+
const fullPath = resolve(input.project, file);
|
|
59
106
|
const content = await readFile(fullPath, 'utf8');
|
|
60
107
|
total += await countAssertions(content);
|
|
61
|
-
for (const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
for (const m of matches) {
|
|
67
|
-
const idx = m.index ?? 0;
|
|
68
|
-
list.push({ file, line: lineOf(content, idx), code: m[0] });
|
|
69
|
-
}
|
|
70
|
-
byPattern.set(pattern, list);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// toEqual-self: needs receiver extraction.
|
|
74
|
-
const eqSelf = [...content.matchAll(TO_EQUAL_SELF)];
|
|
75
|
-
for (const m of eqSelf) {
|
|
76
|
-
const receiverMatch = content
|
|
77
|
-
.slice(0, m.index ?? 0)
|
|
78
|
-
.match(/expect\s*\(\s*([a-zA-Z_$][\w$]*)\s*\)/g);
|
|
79
|
-
if (receiverMatch && receiverMatch.length > 0) {
|
|
80
|
-
const lastReceiver = receiverMatch[receiverMatch.length - 1];
|
|
81
|
-
const receiverName = lastReceiver?.match(/expect\s*\(\s*([a-zA-Z_$][\w$]*)\s*\)/)?.[1];
|
|
82
|
-
if (receiverName && receiverName === m[1]) {
|
|
83
|
-
weak += 1;
|
|
84
|
-
const idx = m.index ?? 0;
|
|
85
|
-
const list = byPattern.get('toEqual-self') ?? [];
|
|
86
|
-
list.push({ file, line: lineOf(content, idx), code: m[0] });
|
|
87
|
-
byPattern.set('toEqual-self', list);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
108
|
+
for (const [pattern, examples] of collectWeakPatternExamples(content, file)) {
|
|
109
|
+
weak += examples.length;
|
|
110
|
+
const list = byPattern.get(pattern) ?? [];
|
|
111
|
+
list.push(...examples);
|
|
112
|
+
byPattern.set(pattern, list);
|
|
90
113
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.slice(0, m.index ?? 0)
|
|
96
|
-
.match(/expect\s*\(\s*([a-zA-Z_$][\w$]*)\s*\)/g);
|
|
97
|
-
if (receiverMatch && receiverMatch.length > 0) {
|
|
98
|
-
const lastReceiver = receiverMatch[receiverMatch.length - 1];
|
|
99
|
-
const receiverName = lastReceiver?.match(/expect\s*\(\s*([a-zA-Z_$][\w$]*)\s*\)/)?.[1];
|
|
100
|
-
if (receiverName && receiverName === m[1]) {
|
|
101
|
-
weak += 1;
|
|
102
|
-
const idx = m.index ?? 0;
|
|
103
|
-
const list = byPattern.get('toBe-self') ?? [];
|
|
104
|
-
list.push({ file, line: lineOf(content, idx), code: m[0] });
|
|
105
|
-
byPattern.set('toBe-self', list);
|
|
106
|
-
}
|
|
114
|
+
for (const { pattern, regex } of SELF_PATTERNS) {
|
|
115
|
+
const examples = collectSelfExamples(content, file, regex);
|
|
116
|
+
if (examples.length === 0) {
|
|
117
|
+
continue;
|
|
107
118
|
}
|
|
119
|
+
weak += examples.length;
|
|
120
|
+
const list = byPattern.get(pattern) ?? [];
|
|
121
|
+
list.push(...examples);
|
|
122
|
+
byPattern.set(pattern, list);
|
|
108
123
|
}
|
|
109
124
|
}
|
|
110
125
|
const weakPatterns = [];
|
|
@@ -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":"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,CA6C/D"}
|
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
* process-global, so runs are serialised through `runExclusive()`.
|
|
16
16
|
* - PLUGIN LOADING. The vitest runner is resolved from THIS package's own
|
|
17
17
|
* installation — see `stryker-plugin.ts`.
|
|
18
|
+
* - TEST FILES ARE CHECKED BEFORE STRYKER. A `--test-files` entry that does
|
|
19
|
+
* not exist used to reach Stryker, whose own file matcher dropped it
|
|
20
|
+
* silently and let the run fall back to the project's default test
|
|
21
|
+
* discovery. The options builder is pure and cannot see the file system,
|
|
22
|
+
* so the check lives HERE — the layer that owns the Stryker call. That is
|
|
23
|
+
* what protects the PUBLISHED package: a programmatic caller of this
|
|
24
|
+
* package never goes through the CLI, and it still cannot hand a missing
|
|
25
|
+
* test file to Stryker.
|
|
18
26
|
*
|
|
19
27
|
* NO FAKE GREEN. A run that produces zero mutants, or that cannot load
|
|
20
28
|
* its test runner, fails with a named error code — it never reports
|
|
@@ -33,6 +41,7 @@ import { MUT_ERROR_CODES, MutToolchainError } from './stryker-errors.js';
|
|
|
33
41
|
import { buildStrykerOptions, STRYKER_DEFAULTS } from './stryker-options.js';
|
|
34
42
|
import { resolveVitestRunnerPlugin } from './stryker-plugin.js';
|
|
35
43
|
import { normalizeMutants } from './stryker-result.js';
|
|
44
|
+
import { assertTestFilesUsable } from './test-files.js';
|
|
36
45
|
export { MUT_ERROR_CODES, MutToolchainError };
|
|
37
46
|
/** The config file names Stryker looks for (SUPPORTED_CONFIG_FILE_NAMES, core 9.6.1). */
|
|
38
47
|
const STRYKER_CONFIG_FILE_NAMES = ['', '.'].flatMap((prefix) => ['.conf', '.config'].flatMap((suffix) => ['json', 'js', 'mjs', 'cjs'].map((ext) => `${prefix}stryker${suffix}.${ext}`)));
|
|
@@ -56,6 +65,12 @@ export function createProductionStrykerInvoker() {
|
|
|
56
65
|
concurrency: STRYKER_DEFAULTS.concurrency,
|
|
57
66
|
coverageAnalysis: STRYKER_DEFAULTS.coverageAnalysis
|
|
58
67
|
};
|
|
68
|
+
// The `--test-files` list is validated HERE, immediately before the
|
|
69
|
+
// options are built — the exact position the builder's own check used to
|
|
70
|
+
// occupy, so the error a programmatic caller sees is unchanged. A missing
|
|
71
|
+
// literal path must never reach Stryker; a PATTERN is never checked,
|
|
72
|
+
// because Stryker expands patterns.
|
|
73
|
+
assertTestFilesUsable({ project, testFiles: input.testFiles, allowPatterns: true });
|
|
59
74
|
const { options } = buildStrykerOptions({
|
|
60
75
|
project,
|
|
61
76
|
mutate: input.mutate,
|
|
@@ -10,19 +10,39 @@
|
|
|
10
10
|
* `production-stryker.ts` re-exports these names, so the names this package
|
|
11
11
|
* exports are unchanged by the split.
|
|
12
12
|
*/
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Named error codes surfaced by the production invoker (see R7).
|
|
15
|
+
*
|
|
16
|
+
* THE TEST-FILE CODES. `--test-files` answers three different questions and
|
|
17
|
+
* each gets its OWN name, because one name cannot tell a caller which of the
|
|
18
|
+
* three happened:
|
|
19
|
+
* - `MUT_TEST_FILE_NOT_FOUND` — a LITERAL path that does not exist.
|
|
20
|
+
* - `MUT_TEST_FILE_NOT_A_FILE` — the path exists but is a directory.
|
|
21
|
+
* - `MUT_TEST_FILE_PATTERN_UNSUPPORTED` — the value is a PATTERN and the
|
|
22
|
+
* caller needs literal files (the assertion scanner reads files).
|
|
23
|
+
*/
|
|
14
24
|
export declare const MUT_ERROR_CODES: {
|
|
15
25
|
readonly toolchainUnavailable: "MUT_TOOLCHAIN_UNAVAILABLE";
|
|
16
26
|
readonly projectNotFound: "MUT_PROJECT_NOT_FOUND";
|
|
17
27
|
readonly mutatePatternRequired: "MUT_MUTATE_PATTERN_REQUIRED";
|
|
18
28
|
readonly noMutants: "MUT_NO_MUTANTS";
|
|
19
29
|
readonly failed: "MUT_FAILED";
|
|
30
|
+
readonly testFileNotFound: "MUT_TEST_FILE_NOT_FOUND";
|
|
31
|
+
readonly testFileNotAFile: "MUT_TEST_FILE_NOT_A_FILE";
|
|
32
|
+
readonly testFilePatternUnsupported: "MUT_TEST_FILE_PATTERN_UNSUPPORTED";
|
|
20
33
|
};
|
|
21
34
|
/** An error carrying a machine-readable `code` for the CLI envelope. */
|
|
22
35
|
export declare class MutToolchainError extends Error {
|
|
23
36
|
readonly code: string;
|
|
37
|
+
/**
|
|
38
|
+
* Machine-readable detail for the CLI envelope's `data` field — the place
|
|
39
|
+
* an ABSOLUTE path belongs. The human-facing `message` names paths relative
|
|
40
|
+
* to the project root instead, so the prose never leaks a machine path.
|
|
41
|
+
*/
|
|
42
|
+
readonly details: Record<string, unknown>;
|
|
24
43
|
constructor(code: string, message: string, options?: {
|
|
25
44
|
cause?: unknown;
|
|
45
|
+
details?: Record<string, unknown>;
|
|
26
46
|
});
|
|
27
47
|
}
|
|
28
48
|
//# sourceMappingURL=stryker-errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stryker-errors.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH
|
|
1
|
+
{"version":3,"file":"stryker-errors.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe;;;;;;;;;CASlB,CAAC;AAEX,wEAAwE;AACxE,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAGxC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE;CAOnE"}
|
|
@@ -10,20 +10,40 @@
|
|
|
10
10
|
* `production-stryker.ts` re-exports these names, so the names this package
|
|
11
11
|
* exports are unchanged by the split.
|
|
12
12
|
*/
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Named error codes surfaced by the production invoker (see R7).
|
|
15
|
+
*
|
|
16
|
+
* THE TEST-FILE CODES. `--test-files` answers three different questions and
|
|
17
|
+
* each gets its OWN name, because one name cannot tell a caller which of the
|
|
18
|
+
* three happened:
|
|
19
|
+
* - `MUT_TEST_FILE_NOT_FOUND` — a LITERAL path that does not exist.
|
|
20
|
+
* - `MUT_TEST_FILE_NOT_A_FILE` — the path exists but is a directory.
|
|
21
|
+
* - `MUT_TEST_FILE_PATTERN_UNSUPPORTED` — the value is a PATTERN and the
|
|
22
|
+
* caller needs literal files (the assertion scanner reads files).
|
|
23
|
+
*/
|
|
14
24
|
export const MUT_ERROR_CODES = {
|
|
15
25
|
toolchainUnavailable: 'MUT_TOOLCHAIN_UNAVAILABLE',
|
|
16
26
|
projectNotFound: 'MUT_PROJECT_NOT_FOUND',
|
|
17
27
|
mutatePatternRequired: 'MUT_MUTATE_PATTERN_REQUIRED',
|
|
18
28
|
noMutants: 'MUT_NO_MUTANTS',
|
|
19
|
-
failed: 'MUT_FAILED'
|
|
29
|
+
failed: 'MUT_FAILED',
|
|
30
|
+
testFileNotFound: 'MUT_TEST_FILE_NOT_FOUND',
|
|
31
|
+
testFileNotAFile: 'MUT_TEST_FILE_NOT_A_FILE',
|
|
32
|
+
testFilePatternUnsupported: 'MUT_TEST_FILE_PATTERN_UNSUPPORTED'
|
|
20
33
|
};
|
|
21
34
|
/** An error carrying a machine-readable `code` for the CLI envelope. */
|
|
22
35
|
export class MutToolchainError extends Error {
|
|
23
36
|
code;
|
|
37
|
+
/**
|
|
38
|
+
* Machine-readable detail for the CLI envelope's `data` field — the place
|
|
39
|
+
* an ABSOLUTE path belongs. The human-facing `message` names paths relative
|
|
40
|
+
* to the project root instead, so the prose never leaks a machine path.
|
|
41
|
+
*/
|
|
42
|
+
details;
|
|
24
43
|
constructor(code, message, options) {
|
|
25
44
|
super(message, options);
|
|
26
45
|
this.name = 'MutToolchainError';
|
|
27
46
|
this.code = code;
|
|
47
|
+
this.details = options?.details ?? {};
|
|
28
48
|
}
|
|
29
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stryker-options.d.ts","sourceRoot":"","sources":["../../../src/services/mut/stryker-options.ts"],"names":[],"mappings":"
|
|
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;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"}
|
|
@@ -21,11 +21,25 @@
|
|
|
21
21
|
*
|
|
22
22
|
* DESIGN
|
|
23
23
|
* ------
|
|
24
|
-
* This module is PURE
|
|
25
|
-
*
|
|
26
|
-
* installed at all. The single source of truth for every
|
|
27
|
-
* `STRYKER_DEFAULTS` below — nothing else in the package may
|
|
28
|
-
* default value.
|
|
24
|
+
* This module is PURE in everything it SETS: no clock, no process state, and
|
|
25
|
+
* every default it applies arrives as input, so it can be unit-tested without
|
|
26
|
+
* Stryker being installed at all. The single source of truth for every
|
|
27
|
+
* default lives in `STRYKER_DEFAULTS` below — nothing else in the package may
|
|
28
|
+
* hard-code a default value.
|
|
29
|
+
*
|
|
30
|
+
* NO EXCEPTION TO THAT PURITY. This module never reads the file system, so it
|
|
31
|
+
* cannot know whether a `--test-files` entry exists — and it must not try: a
|
|
32
|
+
* builder that throws on a missing path is not a builder any more, it is half
|
|
33
|
+
* of the validator. The existence check therefore lives where the file system
|
|
34
|
+
* is legitimately read, and it is ONE check with THREE callers (see
|
|
35
|
+
* `test-files.ts`): the CLI boundary (`assertMutTestFiles()`), the assertion
|
|
36
|
+
* scanner (`assert-scanner.ts`) and the production Stryker invoker
|
|
37
|
+
* (`production-stryker.ts`). The invoker is the one that protects the
|
|
38
|
+
* PUBLISHED package: a programmatic caller that never goes through the CLI
|
|
39
|
+
* still cannot hand a missing test file to Stryker, whose own file matcher
|
|
40
|
+
* drops it silently and lets the run fall back to the project's default test
|
|
41
|
+
* discovery. A PATTERN is never checked anywhere: Stryker expands patterns,
|
|
42
|
+
* so a pattern is not a file and cannot be "missing".
|
|
29
43
|
*
|
|
30
44
|
* MEASURED BEHAVIOURS THIS ENCODES
|
|
31
45
|
* --------------------------------
|
|
@@ -142,6 +156,10 @@ export function toStrykerCliOptions(options) {
|
|
|
142
156
|
/**
|
|
143
157
|
* Resolve test-file patterns against the project root so the result does
|
|
144
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.
|
|
145
163
|
*/
|
|
146
164
|
function resolveTestFiles(project, patterns) {
|
|
147
165
|
if (!patterns || patterns.length === 0) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** How many near-miss candidates a message may list. */
|
|
2
|
+
export declare const MAX_TEST_FILE_CANDIDATES = 5;
|
|
3
|
+
/** One unusable `--test-files` entry. */
|
|
4
|
+
export interface TestFileProblem {
|
|
5
|
+
/** The named code this entry's failure carries. */
|
|
6
|
+
readonly code: string;
|
|
7
|
+
/** The value the caller passed, verbatim. */
|
|
8
|
+
readonly input: string;
|
|
9
|
+
/** The path relative to the project root, `/`-separated. */
|
|
10
|
+
readonly display: string;
|
|
11
|
+
/** True when the path resolves outside the project root. */
|
|
12
|
+
readonly outsideProject: boolean;
|
|
13
|
+
/** Near-miss candidates, relative to the project root. */
|
|
14
|
+
readonly candidates: ReadonlyArray<string>;
|
|
15
|
+
}
|
|
16
|
+
export interface TestFilesInput {
|
|
17
|
+
/** The project root — the scope of the run. */
|
|
18
|
+
readonly project: string;
|
|
19
|
+
/** The `--test-files` values, as the caller passed them. */
|
|
20
|
+
readonly testFiles: ReadonlyArray<string>;
|
|
21
|
+
/**
|
|
22
|
+
* True when the caller can expand a PATTERN itself (the CLI and the
|
|
23
|
+
* Stryker options builder can; the assertion scanner cannot — it reads
|
|
24
|
+
* files).
|
|
25
|
+
*/
|
|
26
|
+
readonly allowPatterns: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** True when the value is a PATTERN rather than a literal path. */
|
|
29
|
+
export declare function isTestFilePattern(value: string): boolean;
|
|
30
|
+
/** The unusable entries of a `--test-files` list, in a deterministic order. */
|
|
31
|
+
export declare function collectTestFileProblems(input: TestFilesInput): TestFileProblem[];
|
|
32
|
+
/**
|
|
33
|
+
* The message the envelope carries. Every missing path is named — a list of
|
|
34
|
+
* two missing files names BOTH — and the near-miss candidates follow, capped
|
|
35
|
+
* and deterministically ordered. No plausible near-miss means no candidate
|
|
36
|
+
* line at all.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildTestFileMessage(problems: ReadonlyArray<TestFileProblem>): string;
|
|
39
|
+
/**
|
|
40
|
+
* Validate a `--test-files` list. Throws a `MutToolchainError` carrying a
|
|
41
|
+
* NAMED code when an entry cannot be used; returns normally when every
|
|
42
|
+
* literal entry exists and every pattern is acceptable to the caller.
|
|
43
|
+
*/
|
|
44
|
+
export declare function assertTestFilesUsable(input: TestFilesInput): void;
|
|
45
|
+
//# sourceMappingURL=test-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-files.d.ts","sourceRoot":"","sources":["../../../src/services/mut/test-files.ts"],"names":[],"mappings":"AA8BA,wDAAwD;AACxD,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAgB1C,yCAAyC;AACzC,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAExD;AAqGD,+EAA+E;AAC/E,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,EAAE,CAuChF;AAgBD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,MAAM,CAmCrF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAgBjE"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared validation for the `--test-files` list.
|
|
3
|
+
*
|
|
4
|
+
* `--test-files` was RESOLVED but never CHECKED: `resolveTestFiles()` mapped
|
|
5
|
+
* a pattern to an absolute path and stopped, and `scanAssertions()` read the
|
|
6
|
+
* path literally. A missing path therefore surfaced as whatever the layer
|
|
7
|
+
* BELOW it happened to throw, and the three `peaks mut` subcommands disagreed:
|
|
8
|
+
* `run` / `mutants` reported the generic `MUT_FAILED`, `asserts` had no
|
|
9
|
+
* `try`/`catch` and fell through to `UNHANDLED_ERROR` — both a bare `ENOENT`
|
|
10
|
+
* carrying a machine absolute path.
|
|
11
|
+
*
|
|
12
|
+
* ONE RULE, THREE CALLERS. The same validator runs in the CLI (before any
|
|
13
|
+
* Stryker run, assertion scan or report write), in the Stryker options
|
|
14
|
+
* builder and in the assertion scanner, so the three subcommands answer the
|
|
15
|
+
* same question the same way — same code, same exit code, same message shape.
|
|
16
|
+
*
|
|
17
|
+
* A PATTERN IS NEVER A MISSING FILE. `--test-files` accepts patterns and
|
|
18
|
+
* Stryker expands them; reporting a pattern as missing would turn a working
|
|
19
|
+
* glob into "file not found". Only a LITERAL path can be missing; the one
|
|
20
|
+
* caller that needs literal files (the assertion scanner) rejects a pattern
|
|
21
|
+
* with its own named code.
|
|
22
|
+
*
|
|
23
|
+
* THE MESSAGE NAMES PATHS RELATIVE TO THE PROJECT ROOT; the absolute path
|
|
24
|
+
* travels in the error's `details`, which the CLI envelope carries in its
|
|
25
|
+
* machine-readable `data` field.
|
|
26
|
+
*/
|
|
27
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
28
|
+
import { basename, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
29
|
+
import { MUT_ERROR_CODES, MutToolchainError } from './stryker-errors.js';
|
|
30
|
+
/** How many near-miss candidates a message may list. */
|
|
31
|
+
export const MAX_TEST_FILE_CANDIDATES = 5;
|
|
32
|
+
/**
|
|
33
|
+
* The characters that make a `--test-files` value a PATTERN rather than a
|
|
34
|
+
* literal path. A value carrying any of them is never resolved against the
|
|
35
|
+
* file system as a single file.
|
|
36
|
+
*/
|
|
37
|
+
const PATTERN_METACHARACTERS = /[*?[\]{}]/;
|
|
38
|
+
/** Directories the near-miss search never descends into. */
|
|
39
|
+
const SKIPPED_DIRECTORIES = new Set(['node_modules', 'dist', 'coverage', 'build', 'out']);
|
|
40
|
+
/** The near-miss search is bounded: it must never turn an error into a hang. */
|
|
41
|
+
const MAX_WALK_DEPTH = 8;
|
|
42
|
+
const MAX_COLLECTED_FILES = 20_000;
|
|
43
|
+
/** True when the value is a PATTERN rather than a literal path. */
|
|
44
|
+
export function isTestFilePattern(value) {
|
|
45
|
+
return PATTERN_METACHARACTERS.test(value);
|
|
46
|
+
}
|
|
47
|
+
/** The absolute path a `--test-files` value denotes. */
|
|
48
|
+
function absoluteTestFilePath(project, value) {
|
|
49
|
+
return isAbsolute(value) ? resolve(value) : resolve(project, value);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The project-relative, `/`-separated name of an absolute path, plus whether
|
|
53
|
+
* the path escapes the project root. A path OUTSIDE the root is reported as
|
|
54
|
+
* `../…` — never as a machine absolute path.
|
|
55
|
+
*/
|
|
56
|
+
function displayTestFilePath(project, absolutePath) {
|
|
57
|
+
const rel = relative(project, absolutePath);
|
|
58
|
+
const outsideProject = rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel);
|
|
59
|
+
const trimmed = rel === '' ? basename(absolutePath) : rel;
|
|
60
|
+
return { display: trimmed.split(sep).join('/'), outsideProject };
|
|
61
|
+
}
|
|
62
|
+
/** The entries of one directory, or none when it cannot be read. */
|
|
63
|
+
function readEntries(dir) {
|
|
64
|
+
try {
|
|
65
|
+
return readdirSync(dir, { withFileTypes: true });
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Directories the near-miss search never descends into. */
|
|
72
|
+
function isSkippedDirectory(name) {
|
|
73
|
+
return name.startsWith('.') || SKIPPED_DIRECTORIES.has(name);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Every file under the project root, relative and `/`-separated. Bounded by
|
|
77
|
+
* `MAX_WALK_DEPTH` and `MAX_COLLECTED_FILES`; symlinked directories are not
|
|
78
|
+
* followed.
|
|
79
|
+
*/
|
|
80
|
+
function collectProjectFiles(root) {
|
|
81
|
+
const files = [];
|
|
82
|
+
const walk = (dir, depth) => {
|
|
83
|
+
if (depth > MAX_WALK_DEPTH || files.length >= MAX_COLLECTED_FILES) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (const entry of readEntries(dir)) {
|
|
87
|
+
const absolute = join(dir, entry.name);
|
|
88
|
+
if (entry.isDirectory()) {
|
|
89
|
+
if (!isSkippedDirectory(entry.name)) {
|
|
90
|
+
walk(absolute, depth + 1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (entry.isFile()) {
|
|
94
|
+
files.push(relative(root, absolute).split(sep).join('/'));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
walk(root, 0);
|
|
99
|
+
return files;
|
|
100
|
+
}
|
|
101
|
+
/** The file name without its extension. */
|
|
102
|
+
function baseNameOf(fileName) {
|
|
103
|
+
return fileName.slice(0, fileName.length - extname(fileName).length);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The near-miss candidates for one missing path: files in the SAME DIRECTORY
|
|
107
|
+
* with the SAME extension (rank 0), then files with the SAME BASE NAME
|
|
108
|
+
* anywhere under the project (rank 1). Deterministic order, capped by the
|
|
109
|
+
* caller.
|
|
110
|
+
*/
|
|
111
|
+
function findNearMissCandidates(project, missingAbsolute) {
|
|
112
|
+
const missingDir = displayTestFilePath(project, missingAbsolute).display;
|
|
113
|
+
const missingDirName = missingDir.includes('/')
|
|
114
|
+
? missingDir.slice(0, missingDir.lastIndexOf('/'))
|
|
115
|
+
: '';
|
|
116
|
+
const missingName = basename(missingAbsolute);
|
|
117
|
+
const missingExt = extname(missingName);
|
|
118
|
+
const missingBase = baseNameOf(missingName);
|
|
119
|
+
const ranked = [];
|
|
120
|
+
for (const file of collectProjectFiles(project)) {
|
|
121
|
+
const fileDir = file.includes('/') ? file.slice(0, file.lastIndexOf('/')) : '';
|
|
122
|
+
const fileName = file.slice(fileDir.length + (fileDir === '' ? 0 : 1));
|
|
123
|
+
if (fileDir === missingDirName && extname(fileName) === missingExt) {
|
|
124
|
+
ranked.push({ rank: 0, path: file });
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (baseNameOf(fileName) === missingBase) {
|
|
128
|
+
ranked.push({ rank: 1, path: file });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
ranked.sort((a, b) => (a.rank === b.rank ? (a.path < b.path ? -1 : 1) : a.rank - b.rank));
|
|
132
|
+
return ranked.map((entry) => entry.path);
|
|
133
|
+
}
|
|
134
|
+
/** The unusable entries of a `--test-files` list, in a deterministic order. */
|
|
135
|
+
export function collectTestFileProblems(input) {
|
|
136
|
+
const project = resolve(input.project);
|
|
137
|
+
const problems = [];
|
|
138
|
+
for (const value of input.testFiles) {
|
|
139
|
+
if (isTestFilePattern(value)) {
|
|
140
|
+
if (!input.allowPatterns) {
|
|
141
|
+
problems.push({
|
|
142
|
+
code: MUT_ERROR_CODES.testFilePatternUnsupported,
|
|
143
|
+
input: value,
|
|
144
|
+
display: value,
|
|
145
|
+
outsideProject: false,
|
|
146
|
+
candidates: []
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const absolute = absoluteTestFilePath(project, value);
|
|
152
|
+
const { display, outsideProject } = displayTestFilePath(project, absolute);
|
|
153
|
+
if (!existsSync(absolute)) {
|
|
154
|
+
problems.push({
|
|
155
|
+
code: MUT_ERROR_CODES.testFileNotFound,
|
|
156
|
+
input: value,
|
|
157
|
+
display,
|
|
158
|
+
outsideProject,
|
|
159
|
+
candidates: findNearMissCandidates(project, absolute)
|
|
160
|
+
});
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (!statSync(absolute).isFile()) {
|
|
164
|
+
problems.push({
|
|
165
|
+
code: MUT_ERROR_CODES.testFileNotAFile,
|
|
166
|
+
input: value,
|
|
167
|
+
display,
|
|
168
|
+
outsideProject,
|
|
169
|
+
candidates: findNearMissCandidates(project, absolute)
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return problems;
|
|
174
|
+
}
|
|
175
|
+
/** The code the envelope carries for a list of problems. */
|
|
176
|
+
function envelopeCode(problems) {
|
|
177
|
+
const missing = problems.find((p) => p.code === MUT_ERROR_CODES.testFileNotFound);
|
|
178
|
+
if (missing !== undefined) {
|
|
179
|
+
return missing.code;
|
|
180
|
+
}
|
|
181
|
+
return problems[0]?.code ?? MUT_ERROR_CODES.testFileNotFound;
|
|
182
|
+
}
|
|
183
|
+
/** The human-readable name of one problem, with the outside-project marker. */
|
|
184
|
+
function describeProblem(problem) {
|
|
185
|
+
return problem.outsideProject ? `${problem.display} (outside the project root)` : problem.display;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The message the envelope carries. Every missing path is named — a list of
|
|
189
|
+
* two missing files names BOTH — and the near-miss candidates follow, capped
|
|
190
|
+
* and deterministically ordered. No plausible near-miss means no candidate
|
|
191
|
+
* line at all.
|
|
192
|
+
*/
|
|
193
|
+
export function buildTestFileMessage(problems) {
|
|
194
|
+
const lines = [];
|
|
195
|
+
const missing = problems.filter((p) => p.code === MUT_ERROR_CODES.testFileNotFound);
|
|
196
|
+
const notAFile = problems.filter((p) => p.code === MUT_ERROR_CODES.testFileNotAFile);
|
|
197
|
+
const patterns = problems.filter((p) => p.code === MUT_ERROR_CODES.testFilePatternUnsupported);
|
|
198
|
+
if (missing.length > 0) {
|
|
199
|
+
lines.push(`Test file not found: ${missing.map(describeProblem).join(', ')}`);
|
|
200
|
+
}
|
|
201
|
+
if (notAFile.length > 0) {
|
|
202
|
+
lines.push(`Test file is a directory, not a test file: ${notAFile.map(describeProblem).join(', ')}`);
|
|
203
|
+
}
|
|
204
|
+
if (patterns.length > 0) {
|
|
205
|
+
lines.push(`Test file is a pattern, not a literal file: ${patterns.map(describeProblem).join(', ')}. ` +
|
|
206
|
+
'The assertion scan reads literal files, so it cannot scan a pattern. ' +
|
|
207
|
+
'List the files explicitly, or use `peaks mut mutants` for a pattern-based mutation run.');
|
|
208
|
+
}
|
|
209
|
+
const candidates = [];
|
|
210
|
+
for (const problem of problems) {
|
|
211
|
+
for (const candidate of problem.candidates) {
|
|
212
|
+
if (!candidates.includes(candidate)) {
|
|
213
|
+
candidates.push(candidate);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (candidates.length > 0) {
|
|
218
|
+
lines.push('Near-miss candidates:');
|
|
219
|
+
for (const candidate of candidates.slice(0, MAX_TEST_FILE_CANDIDATES)) {
|
|
220
|
+
lines.push(`- ${candidate}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return lines.join('\n');
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Validate a `--test-files` list. Throws a `MutToolchainError` carrying a
|
|
227
|
+
* NAMED code when an entry cannot be used; returns normally when every
|
|
228
|
+
* literal entry exists and every pattern is acceptable to the caller.
|
|
229
|
+
*/
|
|
230
|
+
export function assertTestFilesUsable(input) {
|
|
231
|
+
const problems = collectTestFileProblems(input);
|
|
232
|
+
if (problems.length === 0) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const byCode = (code) => problems.filter((p) => p.code === code).map((p) => p.display);
|
|
236
|
+
throw new MutToolchainError(envelopeCode(problems), buildTestFileMessage(problems), {
|
|
237
|
+
details: {
|
|
238
|
+
project: resolve(input.project),
|
|
239
|
+
missing: byCode(MUT_ERROR_CODES.testFileNotFound),
|
|
240
|
+
notAFile: byCode(MUT_ERROR_CODES.testFileNotAFile),
|
|
241
|
+
patterns: byCode(MUT_ERROR_CODES.testFilePatternUnsupported),
|
|
242
|
+
candidates: problems.flatMap((p) => p.candidates).slice(0, MAX_TEST_FILE_CANDIDATES)
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|