@holmes-lab/holmes-kit 0.40.0 → 0.40.1
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/CHANGELOG.md +234 -0
- package/README.md +70 -4
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/index.js +25 -19
- package/dist/holmes/cli/interactive-prompt.d.ts +39 -2
- package/dist/holmes/cli/interactive-prompt.js +98 -16
- package/dist/holmes/config/config.d.ts +17 -0
- package/dist/holmes/config/config.js +13 -1
- package/dist/holmes/governance/autonomy.d.ts +7 -0
- package/dist/holmes/governance/autonomy.js +36 -5
- package/dist/holmes/governance/push-gate-runner.d.ts +2 -0
- package/dist/holmes/governance/push-gate-runner.js +40 -3
- package/dist/holmes/governance/push-gate.d.ts +13 -2
- package/dist/holmes/governance/push-gate.js +106 -14
- package/dist/holmes/guardrail/advisory-line.d.ts +102 -0
- package/dist/holmes/guardrail/advisory-line.js +718 -0
- package/dist/holmes/guardrail/impact-gate.d.ts +6 -0
- package/dist/holmes/guardrail/impact-gate.js +32 -5
- package/dist/holmes/hooks/pre-tool-use.d.ts +11 -0
- package/dist/holmes/hooks/pre-tool-use.js +44 -5
- package/dist/holmes/hooks/session-start.js +17 -1
- package/dist/holmes/mcp/handlers/maintenance-analysis.d.ts +13 -0
- package/dist/holmes/mcp/handlers/maintenance-analysis.js +59 -2
- package/dist/holmes/mcp/handlers/test-execution.d.ts +470 -3
- package/dist/holmes/mcp/handlers/test-execution.js +199 -21
- package/dist/holmes/mcp/handlers.d.ts +468 -3
- package/dist/holmes/mcp/handlers.js +5 -1
- package/dist/holmes/mcp/maintenance-analyze.d.ts +5 -0
- package/dist/holmes/mcp/maintenance-analyze.js +4 -2
- package/dist/holmes/mcp/maintenance-evidence.d.ts +9 -0
- package/dist/holmes/mcp/maintenance-evidence.js +4 -1
- package/dist/holmes/mcp/tool-schemas.js +13 -7
- package/dist/holmes/project/baseline.d.ts +15 -2
- package/dist/holmes/project/baseline.js +11 -6
- package/dist/holmes/project/bounded-io.d.ts +1 -0
- package/dist/holmes/project/bounded-io.js +4 -2
- package/dist/holmes/project/change-source.d.ts +4 -0
- package/dist/holmes/project/change-source.js +13 -5
- package/dist/holmes/project/root.js +3 -1
- package/dist/holmes/review/evidence-mode.d.ts +21 -0
- package/dist/holmes/review/evidence-mode.js +33 -0
- package/dist/holmes/review/head-worktree.d.ts +55 -0
- package/dist/holmes/review/head-worktree.js +329 -0
- package/dist/holmes/review/mrp.js +13 -3
- package/dist/holmes/review/run-provenance.d.ts +45 -0
- package/dist/holmes/review/run-provenance.js +314 -0
- package/dist/holmes/review/test-evidence.d.ts +174 -0
- package/dist/holmes/review/test-evidence.js +330 -2
- package/dist/holmes/review/test-reports.d.ts +94 -0
- package/dist/holmes/review/test-reports.js +382 -0
- package/dist/holmes/review/test-runner.d.ts +176 -65
- package/dist/holmes/review/test-runner.js +531 -316
- package/dist/holmes/review/test-units.d.ts +159 -0
- package/dist/holmes/review/test-units.js +814 -0
- package/package.json +1 -1
- package/playbooks/publish/PLAYBOOK.md +2 -1
|
@@ -33,18 +33,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.TAIL_MAX_CHARS = exports.RUNNER_TIMEOUT_MS = void 0;
|
|
36
|
+
exports.TAIL_MAX_CHARS = exports.UNSUPPORTED = exports.readJestReport = exports.wellShapedJson = exports.parseJUnitXmlFiles = exports.parseJUnitXmlOutcomes = exports.parseJUnitXmlCounts = exports.classifyJestOutcomes = exports.parseExecutedCounts = exports.goPackagesWithTestEvents = exports.parseGoTestJson = exports.projectFiles = exports.pytestRules = exports.BUILD_ROOTS = exports.normaliseExcludeDirs = exports.excludedDir = exports.scanEcosystems = exports.RUNNER_TIMEOUT_MS = void 0;
|
|
37
37
|
exports.runBounded = runBounded;
|
|
38
38
|
exports.runnerStopNote = runnerStopNote;
|
|
39
39
|
exports.planTestRun = planTestRun;
|
|
40
40
|
exports.ecosystemOf = ecosystemOf;
|
|
41
|
-
exports.parseGoTestJson = parseGoTestJson;
|
|
42
|
-
exports.parseExecutedCounts = parseExecutedCounts;
|
|
43
|
-
exports.classifyJestOutcomes = classifyJestOutcomes;
|
|
44
|
-
exports.parseJUnitXmlCounts = parseJUnitXmlCounts;
|
|
45
41
|
exports.jestEntry = jestEntry;
|
|
42
|
+
exports.testRunTimeoutMinutes = testRunTimeoutMinutes;
|
|
43
|
+
exports.testRunWorkers = testRunWorkers;
|
|
46
44
|
exports.runJestOutcomes = runJestOutcomes;
|
|
47
|
-
exports.parseJUnitXmlOutcomes = parseJUnitXmlOutcomes;
|
|
48
45
|
exports.detectProjectEcosystems = detectProjectEcosystems;
|
|
49
46
|
exports.runPytest = runPytest;
|
|
50
47
|
exports.parseCargoTest = parseCargoTest;
|
|
@@ -53,12 +50,16 @@ exports.runGradle = runGradle;
|
|
|
53
50
|
exports.runDotnet = runDotnet;
|
|
54
51
|
exports.runGo = runGo;
|
|
55
52
|
exports.runTestScope = runTestScope;
|
|
53
|
+
exports.runEcosystems = runEcosystems;
|
|
54
|
+
exports.coverageAfterRun = coverageAfterRun;
|
|
55
|
+
exports.environmentReason = environmentReason;
|
|
56
56
|
exports.tailOf = tailOf;
|
|
57
57
|
exports.failedTestSummary = failedTestSummary;
|
|
58
|
+
exports.redJestTail = redJestTail;
|
|
58
59
|
exports.summarizeJestJson = summarizeJestJson;
|
|
59
|
-
// @implements A-SPEC-102.1
|
|
60
|
+
// @implements A-SPEC-102.1, A-SPEC-128.4, A-SPEC-128.5, A-SPEC-128.6, A-SPEC-128.7, A-SPEC-128.8, A-SPEC-128.9, A-SPEC-128.10, A-SPEC-128.11, A-SPEC-128.12, A-SPEC-128.13
|
|
60
61
|
// @implements A-SPEC-647
|
|
61
|
-
// @implements A-SPEC-734
|
|
62
|
+
// @implements A-SPEC-734, A-SPEC-466.1, A-SPEC-466.2, A-SPEC-466.3, A-SPEC-466.4, A-SPEC-466.5, A-SPEC-466.6
|
|
62
63
|
const node_child_process_1 = require("node:child_process");
|
|
63
64
|
const bounded_group_1 = require("../project/bounded-group");
|
|
64
65
|
const fs = __importStar(require("node:fs"));
|
|
@@ -68,6 +69,10 @@ const path = __importStar(require("node:path"));
|
|
|
68
69
|
// `--version` probes above stay as they are: they do not judge anything.
|
|
69
70
|
const root_1 = require("../project/root");
|
|
70
71
|
const python_env_1 = require("./python-env");
|
|
72
|
+
const test_units_1 = require("./test-units");
|
|
73
|
+
const test_reports_1 = require("./test-reports");
|
|
74
|
+
const test_units_2 = require("./test-units");
|
|
75
|
+
const run_provenance_1 = require("./run-provenance");
|
|
71
76
|
// Runner stdout ceiling. Measured 2026-09-01 on this repo: a full `jest --json` for 289 suites /
|
|
72
77
|
// 4568 tests emits >2MB, and execFileSync's DEFAULT maxBuffer (1MB) kills the child with ENOBUFS —
|
|
73
78
|
// so a GREEN suite reported `passed: false`, twice, with no failing test named (the baseline never
|
|
@@ -90,7 +95,9 @@ let STOPPED = null;
|
|
|
90
95
|
* no groups; there the child alone is stopped, as before. Otherwise execFileSync's contract: stdout on exit 0, else a
|
|
91
96
|
* throw carrying stdout, stderr, status and code.
|
|
92
97
|
*/
|
|
93
|
-
|
|
98
|
+
/** @implements A-SPEC-466.6 — the bound of the run in progress; `runTestScope` sets it from timeoutMinutes. */
|
|
99
|
+
let RUN_BUDGET_MS = exports.RUNNER_TIMEOUT_MS;
|
|
100
|
+
function runBounded(cmd, args, opts, timeoutMs = RUN_BUDGET_MS) {
|
|
94
101
|
// @implements A-SPEC-734.4 — the group's whole lifetime lives in bounded-group: a watch shim ends it when this process
|
|
95
102
|
// goes, and the call ends it on the bound, an overflow or a signal, or when members outlive a normal exit
|
|
96
103
|
const { result: r, stopped, leftovers } = (0, bounded_group_1.boundedGroupSpawnSync)(cmd, args, opts, timeoutMs);
|
|
@@ -123,6 +130,13 @@ function planTestRun(scope) {
|
|
|
123
130
|
reason: `${scope.tier} scope — run ${scope.impactedTestFiles.length} impacted test file(s)`,
|
|
124
131
|
};
|
|
125
132
|
}
|
|
133
|
+
var test_units_3 = require("./test-units");
|
|
134
|
+
Object.defineProperty(exports, "scanEcosystems", { enumerable: true, get: function () { return test_units_3.scanEcosystems; } });
|
|
135
|
+
Object.defineProperty(exports, "excludedDir", { enumerable: true, get: function () { return test_units_3.excludedDir; } });
|
|
136
|
+
Object.defineProperty(exports, "normaliseExcludeDirs", { enumerable: true, get: function () { return test_units_3.normaliseExcludeDirs; } });
|
|
137
|
+
Object.defineProperty(exports, "BUILD_ROOTS", { enumerable: true, get: function () { return test_units_3.BUILD_ROOTS; } });
|
|
138
|
+
Object.defineProperty(exports, "pytestRules", { enumerable: true, get: function () { return test_units_3.pytestRules; } });
|
|
139
|
+
Object.defineProperty(exports, "projectFiles", { enumerable: true, get: function () { return test_units_3.projectFiles; } });
|
|
126
140
|
/** Ecosystem of a test file, by extension/convention. `null` when no runner adapter exists for it. */
|
|
127
141
|
function ecosystemOf(file) {
|
|
128
142
|
if (/\.(ts|mts|cts|tsx|jsx|js|mjs|cjs)$/i.test(file))
|
|
@@ -150,150 +164,18 @@ function ecosystemOf(file) {
|
|
|
150
164
|
return 'dotnet';
|
|
151
165
|
return null; // cpp and non-test files — counted syntactically, not yet executable here
|
|
152
166
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
function
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
continue;
|
|
166
|
-
let evt;
|
|
167
|
-
try {
|
|
168
|
-
evt = JSON.parse(s);
|
|
169
|
-
}
|
|
170
|
-
catch {
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
if (!evt.Test || !evt.Package)
|
|
174
|
-
continue; // package-level result is not a test case
|
|
175
|
-
if (evt.Action === 'pass' || evt.Action === 'fail') { // skip is excluded; pass/fail both executed
|
|
176
|
-
counts[evt.Package] = (counts[evt.Package] ?? 0) + 1;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return counts;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Parse jest --json output into per-file EXECUTED case counts. This is the execution-proof upgrade
|
|
183
|
-
* over the syntactic countTestCases lower bound: a case only appears here if jest actually ran it
|
|
184
|
-
* (pending/skipped assertions are excluded), so `if(false){it(…)}`, aliasing, and other syntactic
|
|
185
|
-
* fabrications cannot produce evidence. Returns {} for unparseable output (caller falls back).
|
|
186
|
-
*/
|
|
187
|
-
function parseExecutedCounts(stdout, cwd) {
|
|
188
|
-
const start = stdout.indexOf('{');
|
|
189
|
-
if (start < 0)
|
|
190
|
-
return {};
|
|
191
|
-
let data;
|
|
192
|
-
try {
|
|
193
|
-
data = JSON.parse(stdout.slice(start));
|
|
194
|
-
}
|
|
195
|
-
catch {
|
|
196
|
-
return {};
|
|
197
|
-
}
|
|
198
|
-
const out = {};
|
|
199
|
-
for (const tr of data?.testResults ?? []) {
|
|
200
|
-
const abs = tr.name ?? tr.testFilePath ?? '';
|
|
201
|
-
if (!abs)
|
|
202
|
-
continue;
|
|
203
|
-
const ran = (tr.assertionResults ?? []).filter((a) => a.status === 'passed' || a.status === 'failed').length;
|
|
204
|
-
out[relTestPath(abs, cwd)] = ran;
|
|
205
|
-
}
|
|
206
|
-
return out;
|
|
207
|
-
}
|
|
208
|
-
/** Repo-relative, forward-slashed key for a jest test-file path — shared by the parsers below. */
|
|
209
|
-
function relTestPath(abs, cwd) {
|
|
210
|
-
const rel = abs.startsWith(cwd) ? abs.slice(cwd.length).replace(/^[/\\]/, '') : abs;
|
|
211
|
-
return rel.split('\\').join('/');
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* @implements A-SPEC-534.1
|
|
215
|
-
* Classify each jest-executed file into red-assertion | red-error | green from `jest --json` stdout.
|
|
216
|
-
* Pure; unparseable/empty input → {} (same fail-soft convention as parseExecutedCounts).
|
|
217
|
-
*
|
|
218
|
-
* A failed assertion anywhere in a file wins (`red-assertion`) — that is a real red. A file that ran
|
|
219
|
-
* NO assertions but errored (testExecError, or status 'failed' with an empty assertion list — a
|
|
220
|
-
* load/collection/import failure) is `red-error`, which ART-8 must not accept as a valid RED. A file
|
|
221
|
-
* that executed ≥1 assertion with none failing is `green`. A file that only pended/skipped carries no
|
|
222
|
-
* evidence and is omitted entirely.
|
|
223
|
-
*/
|
|
224
|
-
function classifyJestOutcomes(stdout, cwd) {
|
|
225
|
-
const start = stdout.indexOf('{');
|
|
226
|
-
if (start < 0)
|
|
227
|
-
return {};
|
|
228
|
-
let data;
|
|
229
|
-
try {
|
|
230
|
-
data = JSON.parse(stdout.slice(start));
|
|
231
|
-
}
|
|
232
|
-
catch {
|
|
233
|
-
return {};
|
|
234
|
-
}
|
|
235
|
-
const out = {};
|
|
236
|
-
for (const tr of data?.testResults ?? []) {
|
|
237
|
-
const abs = tr.name ?? tr.testFilePath ?? '';
|
|
238
|
-
if (!abs)
|
|
239
|
-
continue;
|
|
240
|
-
const rel = relTestPath(abs, cwd);
|
|
241
|
-
const assertions = tr.assertionResults ?? [];
|
|
242
|
-
if (assertions.some((a) => a.status === 'failed')) {
|
|
243
|
-
out[rel] = 'red-assertion';
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
const executed = assertions.filter((a) => a.status === 'passed' || a.status === 'failed').length;
|
|
247
|
-
const errored = !!tr.testExecError || tr.status === 'failed';
|
|
248
|
-
if (executed === 0) {
|
|
249
|
-
if (errored)
|
|
250
|
-
out[rel] = 'red-error'; // ran nothing AND failed → could not execute its cases
|
|
251
|
-
continue; // otherwise all pending/skipped → no evidence, omit
|
|
252
|
-
}
|
|
253
|
-
out[rel] = errored ? 'red-error' : 'green';
|
|
254
|
-
}
|
|
255
|
-
return out;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Parse pytest's built-in JUnit XML into per-file EXECUTED case counts — the pytest analogue of
|
|
259
|
-
* parseExecutedCounts. `--junit-xml` ships with pytest core, so this needs no plugin, and it is the
|
|
260
|
-
* only pytest output that is both machine-readable and per-file.
|
|
261
|
-
*
|
|
262
|
-
* A `<testcase>` counts as executed unless it carries `<skipped>`, matching the jest rule where
|
|
263
|
-
* pending/skipped assertions are excluded. Errors and failures DO count: they executed.
|
|
264
|
-
*/
|
|
265
|
-
function parseJUnitXmlCounts(xml, ext = 'py') {
|
|
266
|
-
const out = {};
|
|
267
|
-
for (const m of xml.matchAll(/<testcase\b([^>]*?)(\/>|>([\s\S]*?)<\/testcase>)/g)) {
|
|
268
|
-
const attrs = m[1] ?? '';
|
|
269
|
-
const body = m[3] ?? '';
|
|
270
|
-
// `file` (xunit1 / dotnet loggers) is used verbatim when present. Otherwise the `classname`
|
|
271
|
-
// fallback maps to a source path — but the class↔file relationship is language-specific:
|
|
272
|
-
// @implements A-SPEC-137.3
|
|
273
|
-
// py : the MODULE names the file, the class is a nested segment. `tests.test_calc.TestThing`
|
|
274
|
-
// -> `tests/test_calc.py` (drop trailing Capitalized class segments).
|
|
275
|
-
// java/cs : the CLASS names the file. `com.x.FooTest` -> `com/x/FooTest.java` (keep all).
|
|
276
|
-
let file = /\bfile="([^"]*)"/.exec(attrs)?.[1];
|
|
277
|
-
if (!file) {
|
|
278
|
-
const cls = /\bclassname="([^"]*)"/.exec(attrs)?.[1];
|
|
279
|
-
if (!cls)
|
|
280
|
-
continue;
|
|
281
|
-
const parts = cls.split('.').filter(Boolean);
|
|
282
|
-
if (ext === 'py') {
|
|
283
|
-
while (parts.length > 1 && /^[A-Z]/.test(parts[parts.length - 1]))
|
|
284
|
-
parts.pop();
|
|
285
|
-
}
|
|
286
|
-
if (parts.length === 0)
|
|
287
|
-
continue;
|
|
288
|
-
file = `${parts.join('/')}.${ext}`;
|
|
289
|
-
}
|
|
290
|
-
if (/<skipped\b/.test(body))
|
|
291
|
-
continue;
|
|
292
|
-
const key = file.split('\\').join('/');
|
|
293
|
-
out[key] = (out[key] ?? 0) + 1;
|
|
294
|
-
}
|
|
295
|
-
return out;
|
|
296
|
-
}
|
|
167
|
+
// @implements A-SPEC-128.12 — the report readers live in review/test-reports (SRP); these names stay importable from here
|
|
168
|
+
// @implements A-SPEC-137.1, A-SPEC-137.3, A-SPEC-534.1 — the go, JUnit and jest-outcome readers they specify, re-exported
|
|
169
|
+
var test_reports_2 = require("./test-reports");
|
|
170
|
+
Object.defineProperty(exports, "parseGoTestJson", { enumerable: true, get: function () { return test_reports_2.parseGoTestJson; } });
|
|
171
|
+
Object.defineProperty(exports, "goPackagesWithTestEvents", { enumerable: true, get: function () { return test_reports_2.goPackagesWithTestEvents; } });
|
|
172
|
+
Object.defineProperty(exports, "parseExecutedCounts", { enumerable: true, get: function () { return test_reports_2.parseExecutedCounts; } });
|
|
173
|
+
Object.defineProperty(exports, "classifyJestOutcomes", { enumerable: true, get: function () { return test_reports_2.classifyJestOutcomes; } });
|
|
174
|
+
Object.defineProperty(exports, "parseJUnitXmlCounts", { enumerable: true, get: function () { return test_reports_2.parseJUnitXmlCounts; } });
|
|
175
|
+
Object.defineProperty(exports, "parseJUnitXmlOutcomes", { enumerable: true, get: function () { return test_reports_2.parseJUnitXmlOutcomes; } });
|
|
176
|
+
Object.defineProperty(exports, "parseJUnitXmlFiles", { enumerable: true, get: function () { return test_reports_2.parseJUnitXmlFiles; } });
|
|
177
|
+
Object.defineProperty(exports, "wellShapedJson", { enumerable: true, get: function () { return test_reports_2.wellShapedJson; } });
|
|
178
|
+
Object.defineProperty(exports, "readJestReport", { enumerable: true, get: function () { return test_reports_2.readJestReport; } });
|
|
297
179
|
/**
|
|
298
180
|
* @implements A-SPEC-466 — W-4. The TARGET repo's own jest entry, as its package declares it.
|
|
299
181
|
*
|
|
@@ -322,8 +204,75 @@ function jestEntry(cwd) {
|
|
|
322
204
|
return null;
|
|
323
205
|
}
|
|
324
206
|
}
|
|
207
|
+
/** @implements A-SPEC-128.6 — passed and failed cases only (skipped ones are not counted by the parsers). */
|
|
208
|
+
const casesRan = (executed) => Object.values(executed).reduce((a, b) => a + b, 0);
|
|
209
|
+
/**
|
|
210
|
+
* @implements A-SPEC-466.6 — test_run's `timeoutMinutes`, the run's time budget: absent or null is 30; an integer
|
|
211
|
+
* 1..180 is kept; anything else throws (never clamped). It is not a judgement input.
|
|
212
|
+
*/
|
|
213
|
+
function testRunTimeoutMinutes(value) {
|
|
214
|
+
if (value === undefined || value === null)
|
|
215
|
+
return exports.RUNNER_TIMEOUT_MS / 60_000;
|
|
216
|
+
if (typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= 180)
|
|
217
|
+
return value;
|
|
218
|
+
throw new Error(`timeoutMinutes must be an integer from 1 to 180 (got ${typeof value === 'string' ? JSON.stringify(value) : String(value)})`);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* @implements A-SPEC-466.1 — test_run's `workers`: absent stays absent; an integer 1..64 is kept; anything else
|
|
222
|
+
* throws, so a bad count is refused before any change set is derived or any runner starts.
|
|
223
|
+
*/
|
|
224
|
+
function testRunWorkers(value) {
|
|
225
|
+
if (value === undefined || value === null)
|
|
226
|
+
return undefined; // @implements A-SPEC-466.3 — null reads as omitted
|
|
227
|
+
if (typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= 64)
|
|
228
|
+
return value;
|
|
229
|
+
throw new Error(`workers must be an integer from 1 to 64 (got ${typeof value === 'string' ? JSON.stringify(value) : String(value)})`);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* @implements A-SPEC-128.12 — the one message for a configuration outside the 0.40.x supported surface (jest with one
|
|
233
|
+
* project and one unit, pytest under default naming, go). It leads every such environment reason.
|
|
234
|
+
*/
|
|
235
|
+
exports.UNSUPPORTED = '이 구성은 0.40.x가 증빙하지 않습니다 — 0.41 / 오너 결정';
|
|
236
|
+
/** @implements A-SPEC-128.12 — S7: a runner output that could not be read is a value (the unit's environment), never a throw. */
|
|
237
|
+
const unreadable = (what, out, workers) => ({ passed: false, tail: `runner output could not be read (${what}): ${firstLine(out) || '(empty)'}`, executed: {}, outcomes: {}, workers, testsRun: 0, environment: true });
|
|
238
|
+
/**
|
|
239
|
+
* @implements A-SPEC-128.12 — S2/S7: what `jest --showConfig` resolved for this unit, judged by test-units'
|
|
240
|
+
* `jestConfigSurface` (A-SPEC-128.13: one place) — the reason it is outside the surface or cannot be read, else null.
|
|
241
|
+
* No pattern is taken from it.
|
|
242
|
+
*/
|
|
243
|
+
function jestConfigReason(cmd, pre, cwd) {
|
|
244
|
+
let out;
|
|
245
|
+
try {
|
|
246
|
+
out = runBounded(cmd, [...pre, '--showConfig'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: (0, root_1.cleanTestEnv)() });
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
const err = e;
|
|
250
|
+
out = `${err.stderr ?? ''}\n${err.stdout ?? ''}\n${err.message ?? ''}`;
|
|
251
|
+
}
|
|
252
|
+
const cfg = (0, test_reports_1.wellShapedJson)(out, test_reports_1.isJestConfig);
|
|
253
|
+
if (cfg === null || cfg.configs.length === 0)
|
|
254
|
+
return `runner output could not be read (jest --showConfig): ${firstLine(out) || '(empty)'}`;
|
|
255
|
+
const outside = (0, test_units_2.jestConfigSurface)(cfg);
|
|
256
|
+
return outside === null ? null : `${exports.UNSUPPORTED}: ${outside}`;
|
|
257
|
+
}
|
|
325
258
|
/** Run the jest half of a plan. */
|
|
326
|
-
function runJest(files, mode, cwd) {
|
|
259
|
+
function runJest(files, mode, cwd, opts = {}) {
|
|
260
|
+
// @implements A-SPEC-128.11 — P3: a full run's report is read from a file jest writes, so the user's console output
|
|
261
|
+
// on stdout cannot break it; a scoped run keeps its 466.1 argv
|
|
262
|
+
const reportDir = mode === 'full' ? fs.mkdtempSync(path.join(os.tmpdir(), 'holmes-jest-')) : null;
|
|
263
|
+
try {
|
|
264
|
+
return runJestWith(files, mode, cwd, opts, reportDir === null ? null : path.join(reportDir, 'report.json'));
|
|
265
|
+
}
|
|
266
|
+
finally {
|
|
267
|
+
if (reportDir !== null) {
|
|
268
|
+
try {
|
|
269
|
+
fs.rmSync(reportDir, { recursive: true, force: true });
|
|
270
|
+
}
|
|
271
|
+
catch { /* best effort */ }
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function runJestWith(files, mode, cwd, opts, reportFile) {
|
|
327
276
|
// --runTestsByPath treats args as EXACT files (not testPathPattern REGEXes, which would over/mis-match
|
|
328
277
|
// or throw on a metachar); `--` + a leading-`./` guard so a path can never be read as a flag. NO
|
|
329
278
|
// --passWithNoTests on a scoped run (verification H5): if the resolved paths match ZERO tests
|
|
@@ -335,15 +284,36 @@ function runJest(files, mode, cwd) {
|
|
|
335
284
|
// (structurally no .cmd shim to ENOENT on); the npx spelling only as the fallback.
|
|
336
285
|
const entry = jestEntry(cwd);
|
|
337
286
|
const [cmd, ...pre] = entry !== null ? [process.execPath, entry] : ['npx', 'jest'];
|
|
287
|
+
// @implements A-SPEC-466.1 — absent, jest keeps the project's own maxWorkers
|
|
288
|
+
// @implements A-SPEC-466.2 — `applied` is the one value both the argv and the report are built from
|
|
289
|
+
const applied = opts.workers ?? null;
|
|
290
|
+
const workers = applied === null ? [] : [`--maxWorkers=${applied}`];
|
|
291
|
+
// @implements A-SPEC-128.12 — S2: holmes passes jest no ignore argument, so the user's configuration is never replaced
|
|
292
|
+
// (a CLI pattern applies to every project and hid one project's red, R1); exclusions are judged after the run
|
|
338
293
|
const args = mode === 'scoped'
|
|
339
|
-
? [...pre, '--silent', '--json', '--forceExit', '--runTestsByPath', '--', ...safeFiles]
|
|
340
|
-
: [...pre, '--silent', '--json', '--forceExit']; // round 13: an open handle after the last test must not hold the run
|
|
294
|
+
? [...pre, '--silent', '--json', '--forceExit', ...workers, '--runTestsByPath', '--', ...safeFiles]
|
|
295
|
+
: [...pre, '--silent', '--json', '--forceExit', ...workers, `--outputFile=${reportFile}`]; // round 13: an open handle after the last test must not hold the run
|
|
296
|
+
const ran = jestRun(cmd, args, cwd, mode, reportFile, applied);
|
|
297
|
+
if (mode !== 'full' || ran.environment === true)
|
|
298
|
+
return ran;
|
|
299
|
+
// @implements A-SPEC-128.12 — S2/S7: one project only; a configuration jest cannot print is environment
|
|
300
|
+
// @implements A-SPEC-128.13 — and no configured testNamePattern (a selection below the file)
|
|
301
|
+
const reason = jestConfigReason(cmd, pre, cwd);
|
|
302
|
+
return reason === null ? ran : { ...ran, passed: false, environment: true, tail: `${reason}\n${ran.tail}` };
|
|
303
|
+
}
|
|
304
|
+
function jestRun(cmd, args, cwd, mode, reportFile, applied) {
|
|
341
305
|
try {
|
|
342
|
-
const
|
|
306
|
+
const raw = runBounded(cmd, args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: (0, root_1.cleanTestEnv)() });
|
|
307
|
+
const out = mode === 'full' ? (0, test_reports_1.readJestReport)(reportFile, raw) : raw;
|
|
308
|
+
if (out === null)
|
|
309
|
+
return unreadable('jest --json', raw, applied);
|
|
343
310
|
// @implements A-SPEC-515.1 — the green path says what happened instead of handing back the
|
|
344
311
|
// whole `--json` document. `tailOf` wraps the result too, so an unexpectedly long summary is
|
|
345
312
|
// still bounded: a cap that any one path can escape is not a cap.
|
|
346
|
-
|
|
313
|
+
const executed = (0, test_reports_1.parseExecutedCounts)(out, cwd);
|
|
314
|
+
// @implements A-SPEC-128.13 — T1: exit 0 is not green when the report holds a failure (testFailureExitCode: 0)
|
|
315
|
+
const failed = (0, test_reports_1.jestReportFailed)(out);
|
|
316
|
+
return { passed: !failed, tail: tailOf(`${failed ? 'jest exited 0 but its report holds failures\n' : ''}${summarizeJestJson(out) ?? out}`), executed, outcomes: (0, test_reports_1.classifyJestOutcomes)(out, cwd), workers: applied, testsRun: casesRan(executed) };
|
|
347
317
|
}
|
|
348
318
|
catch (e) {
|
|
349
319
|
const err = e;
|
|
@@ -351,9 +321,19 @@ function runJest(files, mode, cwd) {
|
|
|
351
321
|
// classification (A-SPEC-534.1) — survives a red run.
|
|
352
322
|
// @implements A-SPEC-577.1 — the names first, then jest's own summary from stderr. Without the
|
|
353
323
|
// first half this tail was the tail of a JSON document: it said how many failed and never which.
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
324
|
+
// @implements A-SPEC-466.3 — the names and the stderr are bounded apart, so a long stderr cannot push the names out
|
|
325
|
+
// @implements A-SPEC-128.11 — P3: a red full run is read from its report file too; with no report at all the unit
|
|
326
|
+
// ran nothing readable and is environment (a jest that could not start: a configuration error, a missing preset)
|
|
327
|
+
const report = mode === 'full' ? (0, test_reports_1.readJestReport)(reportFile, err.stdout ?? '') : (err.stdout ?? '');
|
|
328
|
+
// jest's own answer for a unit with no test writes no report: it ran nothing, read as such (the tests, not environment)
|
|
329
|
+
if (report === null && /^No tests found, exiting with code 1/m.test(err.stderr ?? '')) {
|
|
330
|
+
return { passed: false, tail: tailOf(err.stderr ?? '', 3), executed: {}, outcomes: {}, workers: applied, testsRun: 0 };
|
|
331
|
+
}
|
|
332
|
+
if (report === null)
|
|
333
|
+
return unreadable('jest --json', `${err.stderr ?? ''}\n${err.stdout ?? ''}\n${err.message ?? ''}`, applied);
|
|
334
|
+
const tail = redJestTail(report, err.stderr ?? err.message ?? '');
|
|
335
|
+
const executed = (0, test_reports_1.parseExecutedCounts)(report, cwd);
|
|
336
|
+
return { passed: false, tail, executed, outcomes: (0, test_reports_1.classifyJestOutcomes)(report, cwd), workers: applied, testsRun: casesRan(executed) };
|
|
357
337
|
}
|
|
358
338
|
}
|
|
359
339
|
/**
|
|
@@ -361,113 +341,28 @@ function runJest(files, mode, cwd) {
|
|
|
361
341
|
* Run specific jest files and return only their RED-first outcomes — the runner `test_run --mutate`
|
|
362
342
|
* injects into runKillsOnFile. Scoped, jest only (the classifier is jest-only), fail-soft to {}.
|
|
363
343
|
*/
|
|
364
|
-
function runJestOutcomes(files, cwd) {
|
|
344
|
+
function runJestOutcomes(files, cwd, timeoutMinutes) {
|
|
365
345
|
if (files.length === 0)
|
|
366
346
|
return {};
|
|
367
|
-
|
|
347
|
+
// @implements A-SPEC-466.6 — a mutation's jest child is a runner child of the run too
|
|
348
|
+
return withRunBudget(timeoutMinutes, () => runJest(files, 'scoped', cwd).outcomes);
|
|
368
349
|
}
|
|
369
350
|
/** Run the pytest half of a plan, taking execution evidence from pytest's built-in JUnit XML. */
|
|
370
351
|
// @implements A-SPEC-502.1 — exported for the wiring test (a fake venv python capturing argv).
|
|
371
|
-
|
|
372
|
-
* @implements A-SPEC-647
|
|
373
|
-
* Per-file RED-first outcome from the same JUnit XML `parseJUnitXmlCounts` reads. Measured 2026-09-14
|
|
374
|
-
* in an external pytest project: a ranged test_run executed the anchored case and recorded NOTHING,
|
|
375
|
-
* because classification was jest-only — a Python project could never produce the red-assertion→green
|
|
376
|
-
* sequence ART-8 reads. `<error>` (collection/import/setup) is a red-error, `<failure>` (an assertion)
|
|
377
|
-
* a red-assertion, executed cases without either are green; a file with only skipped cases says nothing.
|
|
378
|
-
*/
|
|
379
|
-
function parseJUnitXmlOutcomes(xml, ext = 'py') {
|
|
380
|
-
const flags = new Map();
|
|
381
|
-
for (const m of xml.matchAll(/<testcase\b([^>]*?)(\/>|>([\s\S]*?)<\/testcase>)/g)) {
|
|
382
|
-
const attrs = m[1] ?? '';
|
|
383
|
-
const body = m[3] ?? '';
|
|
384
|
-
let file = /\bfile="([^"]*)"/.exec(attrs)?.[1];
|
|
385
|
-
if (!file) {
|
|
386
|
-
const cls = /\bclassname="([^"]*)"/.exec(attrs)?.[1];
|
|
387
|
-
if (!cls)
|
|
388
|
-
continue;
|
|
389
|
-
const parts = cls.split('.').filter(Boolean);
|
|
390
|
-
if (ext === 'py') {
|
|
391
|
-
while (parts.length > 1 && /^[A-Z]/.test(parts[parts.length - 1]))
|
|
392
|
-
parts.pop();
|
|
393
|
-
}
|
|
394
|
-
if (parts.length === 0)
|
|
395
|
-
continue;
|
|
396
|
-
file = `${parts.join('/')}.${ext}`;
|
|
397
|
-
}
|
|
398
|
-
const key = file.split('\\').join('/');
|
|
399
|
-
const f = flags.get(key) ?? { error: false, failure: false, executed: false };
|
|
400
|
-
if (/<error\b/.test(body))
|
|
401
|
-
f.error = true;
|
|
402
|
-
else if (/<failure\b/.test(body))
|
|
403
|
-
f.failure = true;
|
|
404
|
-
if (!/<skipped\b/.test(body))
|
|
405
|
-
f.executed = true;
|
|
406
|
-
flags.set(key, f);
|
|
407
|
-
}
|
|
408
|
-
const out = {};
|
|
409
|
-
for (const [file, f] of flags) {
|
|
410
|
-
if (f.error)
|
|
411
|
-
out[file] = 'red-error';
|
|
412
|
-
else if (f.failure)
|
|
413
|
-
out[file] = 'red-assertion';
|
|
414
|
-
else if (f.executed)
|
|
415
|
-
out[file] = 'green';
|
|
416
|
-
}
|
|
417
|
-
return out;
|
|
418
|
-
}
|
|
352
|
+
// @implements A-SPEC-647 — its per-file outcome reader (parseJUnitXmlOutcomes) lives in review/test-reports
|
|
419
353
|
/**
|
|
420
354
|
* @implements A-SPEC-647
|
|
421
355
|
* The ecosystems a project's OWN test files belong to, by file-name convention, under a bounded walk
|
|
422
356
|
* that skips vendored trees and virtualenvs. Measured: a full-tier run with no impacted list assumed
|
|
423
|
-
* the jest suite on a pytest-only project, ran nothing and reported passed:false.
|
|
424
|
-
*
|
|
357
|
+
* the jest suite on a pytest-only project, ran nothing and reported passed:false.
|
|
358
|
+
* @implements A-SPEC-128.5 — configuration files name an ecosystem too (a pytest.ini, a go.mod), the root's are read
|
|
359
|
+
* even where the walk stops early, and the skipped trees a project vendors are its own declaration
|
|
360
|
+
* (`ax.config.json` testRun.excludeDirs), not a name built in here. This repository lists `reference`.
|
|
425
361
|
*/
|
|
426
|
-
function detectProjectEcosystems(cwd) {
|
|
427
|
-
|
|
428
|
-
const found = new Set();
|
|
429
|
-
const walk = (dir, depth) => {
|
|
430
|
-
if (depth > 6)
|
|
431
|
-
return;
|
|
432
|
-
let entries;
|
|
433
|
-
try {
|
|
434
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
435
|
-
}
|
|
436
|
-
catch {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
if (entries.some((e) => e.isFile() && e.name === 'pyvenv.cfg'))
|
|
440
|
-
return; // a virtualenv is not the project
|
|
441
|
-
for (const e of entries) {
|
|
442
|
-
const name = e.name;
|
|
443
|
-
if (e.isDirectory()) {
|
|
444
|
-
if (SKIP_DIRS.has(name) || (name.startsWith('.') && name !== '.'))
|
|
445
|
-
continue;
|
|
446
|
-
if (name === '__tests__')
|
|
447
|
-
found.add('jest');
|
|
448
|
-
walk(path.join(dir, name), depth + 1);
|
|
449
|
-
continue;
|
|
450
|
-
}
|
|
451
|
-
if (!e.isFile())
|
|
452
|
-
continue;
|
|
453
|
-
if (/\.(test|spec)\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/.test(name))
|
|
454
|
-
found.add('jest');
|
|
455
|
-
else if (/^(test_[^/]*|[^/]*_test)\.py$/.test(name) || name === 'conftest.py')
|
|
456
|
-
found.add('pytest');
|
|
457
|
-
else if (/_test\.go$/.test(name))
|
|
458
|
-
found.add('go');
|
|
459
|
-
else if (name === 'Cargo.toml')
|
|
460
|
-
found.add('rust');
|
|
461
|
-
else if (name === 'build.gradle' || name === 'build.gradle.kts')
|
|
462
|
-
found.add('java');
|
|
463
|
-
else if (/\.csproj$/.test(name))
|
|
464
|
-
found.add('dotnet');
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
walk(cwd, 0);
|
|
468
|
-
return [...found].sort();
|
|
362
|
+
function detectProjectEcosystems(cwd, opts = {}) {
|
|
363
|
+
return (0, test_units_1.scanEcosystems)(cwd, opts).detected;
|
|
469
364
|
}
|
|
470
|
-
function runPytest(files, mode, cwd) {
|
|
365
|
+
function runPytest(files, mode, cwd, ignore = [], pythonFrom, run) {
|
|
471
366
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'holmes-pytest-'));
|
|
472
367
|
const report = path.join(dir, 'report.xml');
|
|
473
368
|
// `python3 -m pytest` rather than a bare `pytest`, so the interpreter on PATH decides which
|
|
@@ -482,24 +377,48 @@ function runPytest(files, mode, cwd) {
|
|
|
482
377
|
// @implements A-SPEC-502.1 — BUG-2, both halves: the interpreter resolves from pyvenv.cfg
|
|
483
378
|
// evidence (HOLMES_PYTHON above all, python3 fallback byte-identical to the old path), and a
|
|
484
379
|
// conftest.py argument widens to its directory instead of collection-ERRORing the whole run.
|
|
485
|
-
|
|
380
|
+
// @implements A-SPEC-128.9 — `-p no:cacheprovider`: a test run leaves no .pytest_cache in the project; E3: an excluded
|
|
381
|
+
// or ignored tree is not collected
|
|
382
|
+
// @implements A-SPEC-128.11 — P3: `--rootdir` is the unit, so a pytest.ini above the repository cannot move the
|
|
383
|
+
// report's file keys out of it (pt-rootdir-above)
|
|
384
|
+
const rootdir = fs.existsSync(cwd) ? (0, root_1.canonicalPath)(cwd) : cwd;
|
|
385
|
+
// @implements A-SPEC-128.13 — W2: the work tree's interpreter (a .venv is not in HEAD)
|
|
386
|
+
const python = (0, python_env_1.pythonFor)(pythonFrom && fs.existsSync(pythonFrom) ? pythonFrom : cwd, { env: process.env, exists: fs.existsSync, platform: process.platform });
|
|
387
|
+
// @implements A-SPEC-128.14, A-SPEC-128.15, A-SPEC-128.16 — in HEAD's worktree: the pinned configuration and its confcutdir,
|
|
388
|
+
// the environment asked where HEAD's names resolve (refused before any test), and the loaded-module record
|
|
389
|
+
const prov = run ? (0, run_provenance_1.pytestRunProvenance)(dir, run, rootdir, python, (0, root_1.cleanTestEnv)(), (c, a, o) => runBounded(c, a, { ...o, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER })) : null;
|
|
390
|
+
if (prov?.refused) {
|
|
391
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
392
|
+
return { passed: false, tail: prov.refused, executed: {}, outcomes: {}, testsRun: 0, environment: true };
|
|
393
|
+
}
|
|
394
|
+
const args = ['-m', 'pytest', '-q', '-p', 'no:cacheprovider', '-o', 'junit_family=xunit1', `--junit-xml=${report}`, `--rootdir=${rootdir}`, ...(prov?.args ?? []),
|
|
395
|
+
...(mode === 'full' ? [`--confcutdir=${prov?.confcutdir ?? rootdir}`, ...ignore.map((d) => `--ignore=${d.replace(/\/+$/, '')}`)] : []),
|
|
486
396
|
...(mode === 'scoped' ? ['--', ...(0, python_env_1.pytestTargets)(files)] : [])];
|
|
487
|
-
const
|
|
397
|
+
const judged = (r) => { const why = prov?.judge(r.passed) ?? null; return why === null ? r : { passed: false, tail: why, executed: {}, outcomes: {}, testsRun: 0, environment: true }; };
|
|
488
398
|
const read = () => {
|
|
489
399
|
try {
|
|
490
|
-
return parseJUnitXmlCounts(fs.readFileSync(report, 'utf8'));
|
|
400
|
+
return (0, test_reports_1.parseJUnitXmlCounts)(fs.readFileSync(report, 'utf8'));
|
|
491
401
|
}
|
|
492
402
|
catch {
|
|
493
403
|
return {};
|
|
494
404
|
}
|
|
495
405
|
};
|
|
406
|
+
// @implements A-SPEC-128.10 — I3: every file pytest collected, skipped ones included
|
|
407
|
+
const reported = () => {
|
|
408
|
+
try {
|
|
409
|
+
return (0, test_reports_1.parseJUnitXmlFiles)(fs.readFileSync(report, 'utf8'));
|
|
410
|
+
}
|
|
411
|
+
catch {
|
|
412
|
+
return [];
|
|
413
|
+
}
|
|
414
|
+
};
|
|
496
415
|
// @implements A-SPEC-647 — per-file outcomes from the same report; in a scoped run a planned file the
|
|
497
416
|
// failed run never reached (no case at all — a collection error before its cases) is a red-error, so a
|
|
498
417
|
// RED that never ran is not mistaken for evidence of nothing.
|
|
499
418
|
const readOutcomes = (passed) => {
|
|
500
419
|
let outcomes = {};
|
|
501
420
|
try {
|
|
502
|
-
outcomes = parseJUnitXmlOutcomes(fs.readFileSync(report, 'utf8'));
|
|
421
|
+
outcomes = (0, test_reports_1.parseJUnitXmlOutcomes)(fs.readFileSync(report, 'utf8'));
|
|
503
422
|
}
|
|
504
423
|
catch {
|
|
505
424
|
outcomes = {};
|
|
@@ -518,13 +437,18 @@ function runPytest(files, mode, cwd) {
|
|
|
518
437
|
// @implements A-SPEC-651.1 — launch from the canonical spelling: pytest keys its JUnit `file`
|
|
519
438
|
// attribute relative to its rootdir, and an 8.3 invocation dir made that key climb out of the
|
|
520
439
|
// project (`../../…/tests/test_calc.py`, measured 2026-09-14 on Windows).
|
|
521
|
-
const out = runBounded(python, args, { cwd: fs.existsSync(cwd) ? (0, root_1.canonicalPath)(cwd) : cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: (0, root_1.cleanTestEnv)() });
|
|
522
|
-
|
|
440
|
+
const out = runBounded(python, args, { cwd: fs.existsSync(cwd) ? (0, root_1.canonicalPath)(cwd) : cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: prov ? prov.env((0, root_1.cleanTestEnv)()) : (0, root_1.cleanTestEnv)() });
|
|
441
|
+
const executed = read();
|
|
442
|
+
// @implements A-SPEC-128.13 — T1: exit 0 is not green when the JUnit report holds a failure or an error
|
|
443
|
+
const outcomes = readOutcomes(true);
|
|
444
|
+
const red = Object.values(outcomes).some((o) => o !== 'green');
|
|
445
|
+
return judged({ passed: !red, tail: tailOf(`${red ? 'pytest exited 0 but its report holds failures\n' : ''}${out}`), executed, outcomes, testsRun: casesRan(executed), reported: reported() });
|
|
523
446
|
}
|
|
524
447
|
catch (e) {
|
|
525
448
|
const err = e;
|
|
526
449
|
// A red pytest run still writes the XML, so execution evidence survives — same property as jest.
|
|
527
|
-
|
|
450
|
+
const executed = read();
|
|
451
|
+
return judged({ passed: false, tail: tailOf(`${err.stdout ?? ''}\n${err.stderr ?? err.message ?? ''}`), executed, outcomes: readOutcomes(false), testsRun: casesRan(executed), reported: reported() });
|
|
528
452
|
}
|
|
529
453
|
finally {
|
|
530
454
|
try {
|
|
@@ -586,7 +510,8 @@ function runCargo(files, _mode, cwd, opts) {
|
|
|
586
510
|
executed[f] = count; // crate-granular
|
|
587
511
|
// Executing nothing is not a pass, mirroring no-passWithNoTests.
|
|
588
512
|
const passed = ok && count > 0;
|
|
589
|
-
|
|
513
|
+
// @implements A-SPEC-128.5 — the crate's count once, whatever the per-file credit (a full run credits no file)
|
|
514
|
+
return { passed, tail: `[rust] cargo test: ${count} executed`, executed, testsRun: count };
|
|
590
515
|
}
|
|
591
516
|
/** Read every JUnit XML report under a directory (recursively) and sum their counts for `ext`. */
|
|
592
517
|
function readJUnitReports(dir, ext) {
|
|
@@ -605,7 +530,7 @@ function readJUnitReports(dir, ext) {
|
|
|
605
530
|
walk(p);
|
|
606
531
|
else if (e.name.endsWith('.xml')) {
|
|
607
532
|
try {
|
|
608
|
-
const counts = parseJUnitXmlCounts(fs.readFileSync(p, 'utf8'), ext);
|
|
533
|
+
const counts = (0, test_reports_1.parseJUnitXmlCounts)(fs.readFileSync(p, 'utf8'), ext);
|
|
609
534
|
for (const [k, v] of Object.entries(counts))
|
|
610
535
|
acc[k] = (acc[k] ?? 0) + v;
|
|
611
536
|
}
|
|
@@ -668,12 +593,15 @@ function runGradle(files, _mode, cwd, opts) {
|
|
|
668
593
|
try {
|
|
669
594
|
runBounded(cmd, args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: (0, root_1.cleanTestEnv)() });
|
|
670
595
|
}
|
|
671
|
-
catch {
|
|
672
|
-
|
|
673
|
-
|
|
596
|
+
catch (e) {
|
|
597
|
+
// @implements A-SPEC-128.10 — R4: the build tool itself missing is the environment, not the tests
|
|
598
|
+
if (e.code === 'ENOENT')
|
|
599
|
+
return { passed: false, tail: `${cmd} not found on PATH — cannot execute Java tests`, executed: {}, unsupported: files };
|
|
600
|
+
ok = false; // a failing test run still wrote the JUnit XML
|
|
601
|
+
}
|
|
674
602
|
const executed = readJUnitReports(path.join(cwd, reportDir), 'java');
|
|
675
603
|
const total = Object.values(executed).reduce((a, b) => a + b, 0);
|
|
676
|
-
return { passed: ok && total > 0, tail: `[java] ${cmd} ${args.join(' ')}: ${total} executed`, executed };
|
|
604
|
+
return { passed: ok && total > 0, tail: `[java] ${cmd} ${args.join(' ')}: ${total} executed`, executed, testsRun: total };
|
|
677
605
|
}
|
|
678
606
|
/**
|
|
679
607
|
* @implements A-SPEC-137.3
|
|
@@ -705,7 +633,7 @@ function runDotnet(files, _mode, cwd, opts) {
|
|
|
705
633
|
}
|
|
706
634
|
let executed = {};
|
|
707
635
|
try {
|
|
708
|
-
executed = parseJUnitXmlCounts(fs.readFileSync(report, 'utf8'), 'cs');
|
|
636
|
+
executed = (0, test_reports_1.parseJUnitXmlCounts)(fs.readFileSync(report, 'utf8'), 'cs');
|
|
709
637
|
}
|
|
710
638
|
catch { /* no report */ }
|
|
711
639
|
try {
|
|
@@ -713,7 +641,7 @@ function runDotnet(files, _mode, cwd, opts) {
|
|
|
713
641
|
}
|
|
714
642
|
catch { /* best effort */ }
|
|
715
643
|
const total = Object.values(executed).reduce((a, b) => a + b, 0);
|
|
716
|
-
return { passed: ok && total > 0, tail: `[dotnet] dotnet test: ${total} executed`, executed };
|
|
644
|
+
return { passed: ok && total > 0, tail: `[dotnet] dotnet test: ${total} executed`, executed, testsRun: total };
|
|
717
645
|
}
|
|
718
646
|
/**
|
|
719
647
|
* @implements A-SPEC-137.1
|
|
@@ -723,6 +651,7 @@ function runDotnet(files, _mode, cwd, opts) {
|
|
|
723
651
|
* `unsupported`, never a pass. `opts.goPresent` overrides the probe for testing.
|
|
724
652
|
*/
|
|
725
653
|
function runGo(files, mode, cwd, opts) {
|
|
654
|
+
const goEnv = { ...(0, root_1.cleanTestEnv)(), ...(opts?.env ?? {}) };
|
|
726
655
|
const present = opts?.goPresent ?? (() => {
|
|
727
656
|
try {
|
|
728
657
|
(0, node_child_process_1.execFileSync)('go', ['version'], { cwd, stdio: 'ignore', timeout: PROBE_TIMEOUT_MS });
|
|
@@ -742,10 +671,10 @@ function runGo(files, mode, cwd, opts) {
|
|
|
742
671
|
const tails = [];
|
|
743
672
|
let passed = true;
|
|
744
673
|
let anyExecuted = 0;
|
|
745
|
-
const runDir = (dirArg, creditFiles) => {
|
|
674
|
+
const runDir = (dirArg, creditFiles, onOutput) => {
|
|
746
675
|
let out = '';
|
|
747
676
|
try {
|
|
748
|
-
out = runBounded('go', ['test', '-json', dirArg], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env:
|
|
677
|
+
out = runBounded('go', ['test', '-json', dirArg], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: goEnv });
|
|
749
678
|
}
|
|
750
679
|
catch (e) {
|
|
751
680
|
const err = e;
|
|
@@ -753,15 +682,63 @@ function runGo(files, mode, cwd, opts) {
|
|
|
753
682
|
tails.push(err.stderr ? tailOf(err.stderr, 2) : (err.message ?? 'go test failed'));
|
|
754
683
|
passed = false;
|
|
755
684
|
}
|
|
756
|
-
|
|
685
|
+
// @implements A-SPEC-128.13 — T1: a named test's fail event is red whatever the exit code (TestMain's os.Exit(0))
|
|
686
|
+
const failedTests = (0, test_reports_1.goFailedTests)(out);
|
|
687
|
+
if (failedTests.length > 0) {
|
|
688
|
+
passed = false;
|
|
689
|
+
tails.push(`[go] failed: ${failedTests.slice(0, 5).join(', ')}`);
|
|
690
|
+
}
|
|
691
|
+
const perPkg = (0, test_reports_1.parseGoTestJson)(out);
|
|
757
692
|
const dirCount = Object.values(perPkg).reduce((a, b) => a + b, 0);
|
|
758
693
|
anyExecuted += dirCount;
|
|
759
694
|
for (const f of creditFiles)
|
|
760
695
|
executed[f] = (executed[f] ?? 0) + dirCount; // package-granular
|
|
696
|
+
if (onOutput)
|
|
697
|
+
onOutput(out);
|
|
761
698
|
tails.push(`[go] ${dirArg}: ${dirCount} executed`);
|
|
762
699
|
};
|
|
763
700
|
if (mode === 'full') {
|
|
764
|
-
|
|
701
|
+
// @implements A-SPEC-128.9 — E3: the module's packages minus the excluded or ignored trees
|
|
702
|
+
// @implements A-SPEC-128.10 — I3 at package granularity: each package's count is credited to its _test.go files, so a
|
|
703
|
+
// package whose tests did not run leaves its files unreported
|
|
704
|
+
let pkgs = [];
|
|
705
|
+
const base = fs.existsSync(cwd) ? (0, root_1.canonicalPath)(cwd) : cwd;
|
|
706
|
+
try {
|
|
707
|
+
pkgs = runBounded('go', ['list', '-f', '{{.ImportPath}}\t{{.Dir}}', './...'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: goEnv })
|
|
708
|
+
.split('\n').map((l) => l.trim()).filter(Boolean)
|
|
709
|
+
.map((l) => { const [importPath, dir] = l.split('\t'); return { importPath, rel: path.relative(base, (0, root_1.canonicalPath)(dir ?? base)).split(path.sep).join('/') }; });
|
|
710
|
+
}
|
|
711
|
+
catch {
|
|
712
|
+
pkgs = [];
|
|
713
|
+
}
|
|
714
|
+
const skip = (opts?.ignore ?? []).map((x) => x.replace(/\/+$/, ''));
|
|
715
|
+
const kept = pkgs.filter((p) => !skip.some((x) => p.rel === x || p.rel.startsWith(`${x}/`)));
|
|
716
|
+
const before = new Map();
|
|
717
|
+
const credit = (out) => {
|
|
718
|
+
const perPkg = (0, test_reports_1.parseGoTestJson)(out);
|
|
719
|
+
const seen = (0, test_reports_1.goPackagesWithTestEvents)(out);
|
|
720
|
+
for (const p of kept) {
|
|
721
|
+
const n = perPkg[p.importPath] ?? 0;
|
|
722
|
+
// @implements A-SPEC-128.11 — P5: a package whose tests all skipped ran them (go-skip); the count stays pass/fail
|
|
723
|
+
if (!seen.has(p.importPath) || before.has(p.importPath))
|
|
724
|
+
continue;
|
|
725
|
+
before.set(p.importPath, n);
|
|
726
|
+
let names = [];
|
|
727
|
+
try {
|
|
728
|
+
names = fs.readdirSync(path.join(base, p.rel)).filter((f) => f.endsWith('_test.go'));
|
|
729
|
+
}
|
|
730
|
+
catch {
|
|
731
|
+
names = [];
|
|
732
|
+
}
|
|
733
|
+
for (const f of names)
|
|
734
|
+
executed[p.rel === '' ? f : `${p.rel}/${f}`] = n;
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
if (skip.length === 0)
|
|
738
|
+
runDir('./...', [], credit);
|
|
739
|
+
else
|
|
740
|
+
for (const k of kept)
|
|
741
|
+
runDir(k.rel === '' ? '.' : `./${k.rel}`, [], credit);
|
|
765
742
|
}
|
|
766
743
|
else {
|
|
767
744
|
const byDir = new Map();
|
|
@@ -778,7 +755,8 @@ function runGo(files, mode, cwd, opts) {
|
|
|
778
755
|
// A run that executed NOTHING is not a pass — the same no-passWithNoTests rule jest/pytest hold.
|
|
779
756
|
if (anyExecuted === 0)
|
|
780
757
|
passed = false;
|
|
781
|
-
|
|
758
|
+
// @implements A-SPEC-128.5 — a full module run credits no file but its tests ran: the count rides apart from the credit
|
|
759
|
+
return { passed, tail: tails.join('\n'), executed, testsRun: anyExecuted };
|
|
782
760
|
}
|
|
783
761
|
/**
|
|
784
762
|
* Execute a plan (I/O). Deterministic inputs → deterministic command; the pass/fail is the suite's.
|
|
@@ -789,59 +767,234 @@ function runGo(files, mode, cwd, opts) {
|
|
|
789
767
|
* ecosystem has no adapter are returned in `unsupported` — never dropped quietly, because a scoped
|
|
790
768
|
* gate that ran part of its scope has verified less than it reports.
|
|
791
769
|
*/
|
|
792
|
-
function runTestScope(scope, cwd) {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
770
|
+
function runTestScope(scope, cwd, opts = {}) {
|
|
771
|
+
return withRunBudget(opts.timeoutMinutes, () => runScopeWithinBudget(scope, cwd, opts));
|
|
772
|
+
}
|
|
773
|
+
/** @implements A-SPEC-466.6 — each runner child started inside `fn` takes the budget; the default comes back after. */
|
|
774
|
+
function withRunBudget(timeoutMinutes, fn) {
|
|
775
|
+
RUN_BUDGET_MS = (timeoutMinutes ?? exports.RUNNER_TIMEOUT_MS / 60_000) * 60_000;
|
|
776
|
+
try {
|
|
777
|
+
return fn();
|
|
778
|
+
}
|
|
779
|
+
finally {
|
|
780
|
+
RUN_BUDGET_MS = exports.RUNNER_TIMEOUT_MS;
|
|
796
781
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* @implements A-SPEC-128.4 — which ecosystem groups a plan runs. A scoped plan groups its own files. A full plan runs
|
|
785
|
+
* every ecosystem the PROJECT has, together with those of the impacted test files: detecting from the impacted files
|
|
786
|
+
* alone let a full run of a jest+pytest project skip pytest and still record `mode: full` (review 2026-11-05, A H1).
|
|
787
|
+
* Jest is assumed only when the project shows no ecosystem at all, and the run says so.
|
|
788
|
+
*/
|
|
789
|
+
function runEcosystems(scope, plan, cwd, opts = {}) {
|
|
802
790
|
const groups = new Map();
|
|
803
791
|
const unsupported = [];
|
|
804
|
-
|
|
792
|
+
const notRun = [];
|
|
793
|
+
if (plan.mode !== 'full') {
|
|
794
|
+
for (const f of plan.testFiles) {
|
|
795
|
+
const eco = ecosystemOf(f);
|
|
796
|
+
if (!eco) {
|
|
797
|
+
unsupported.push(f);
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
groups.set(eco, [...(groups.get(eco) ?? []), f]);
|
|
801
|
+
}
|
|
802
|
+
const units = [...groups.entries()].map(([ecosystem, files]) => ({ ecosystem, dir: '', ignore: [], files }));
|
|
803
|
+
return { groups, units, unsupported, assumedJest: false, detected: [], detectedBy: {}, notRun, notDetected: [],
|
|
804
|
+
implementationCount: 0, implementationSample: [], notTests: [], expected: {}, codeRoots: [], buildRoots: [], sparseTests: [], outsideSurface: [], testFiles: [], notBuilt: [] };
|
|
805
|
+
}
|
|
806
|
+
// @implements A-SPEC-647 — run what the project HAS; @implements A-SPEC-128.4 — always, not only with no impacted file
|
|
807
|
+
// @implements A-SPEC-128.7 — I1: an impacted test file of an ecosystem with no unit is named in notRun, never run
|
|
808
|
+
// @implements A-SPEC-128.9 — E1: what runs is the project's execution units, each where its build root is
|
|
809
|
+
const scan = (0, test_units_1.scanEcosystems)(cwd, opts);
|
|
810
|
+
// @implements A-SPEC-128.12 — S1: only jest, pytest and go units run; the others are named outside the surface
|
|
811
|
+
const units = scan.units.filter((u) => SUPPORTED.has(u.ecosystem)).map((u) => ({ ...u, files: [] }));
|
|
812
|
+
let assumedJest = false;
|
|
813
|
+
// @implements A-SPEC-128.8 — jest is assumed only beside a root package.json (A M1);
|
|
814
|
+
// @implements A-SPEC-128.9 — and only where there is code to test (E2): nothing testable runs nothing
|
|
815
|
+
if (units.length === 0 && scan.implementationCount > 0 && fs.existsSync(path.join(cwd, 'package.json'))) {
|
|
816
|
+
units.push({ ecosystem: 'jest', dir: '', ignore: scan.excluded, files: [] });
|
|
817
|
+
assumedJest = true;
|
|
818
|
+
}
|
|
819
|
+
for (const u of units)
|
|
820
|
+
groups.set(u.ecosystem, []);
|
|
821
|
+
for (const f of scope.impactedTestFiles) {
|
|
805
822
|
const eco = ecosystemOf(f);
|
|
806
823
|
if (!eco) {
|
|
807
824
|
unsupported.push(f);
|
|
808
825
|
continue;
|
|
809
826
|
}
|
|
810
|
-
|
|
811
|
-
|
|
827
|
+
if (groups.has(eco) || notRun.some((n) => n.ecosystem === eco))
|
|
828
|
+
continue;
|
|
829
|
+
notRun.push({ ecosystem: eco, reason: `impacted ${eco} test files, but no ${eco} unit holds them — a full run runs the project's units only` });
|
|
812
830
|
}
|
|
813
|
-
// A
|
|
814
|
-
//
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
831
|
+
// @implements A-SPEC-128.13 — T4: a go unit expects only the _test.go files go builds here (go list, no tags); the rest
|
|
832
|
+
// are named in notBuilt and never refused (a red behind a build tag is a named limit)
|
|
833
|
+
const expected = { ...scan.expected };
|
|
834
|
+
const notBuilt = [];
|
|
835
|
+
for (const u of units.filter((x) => x.ecosystem === 'go')) {
|
|
836
|
+
const key = `go@${u.dir}`;
|
|
837
|
+
const listed = (0, test_units_2.goListTests)(cwd, u.dir);
|
|
838
|
+
if (listed === null || !expected[key])
|
|
839
|
+
continue;
|
|
840
|
+
for (const f of expected[key])
|
|
841
|
+
if (!listed.built.has(f))
|
|
842
|
+
notBuilt.push(f);
|
|
843
|
+
expected[key] = expected[key].filter((f) => listed.built.has(f));
|
|
844
|
+
}
|
|
845
|
+
return { groups, units, unsupported, assumedJest, detected: scan.detected, detectedBy: scan.detectedBy, notRun, notDetected: scan.notDetected,
|
|
846
|
+
implementationCount: scan.implementationCount, implementationSample: scan.implementationSample, notTests: scan.notTests,
|
|
847
|
+
expected, codeRoots: scan.codeRoots, buildRoots: scan.buildRoots, sparseTests: scan.sparseTests,
|
|
848
|
+
outsideSurface: scan.outsideSurface, testFiles: scan.testFiles, notBuilt: notBuilt.sort() };
|
|
849
|
+
}
|
|
850
|
+
const SUPPORTED = new Set(['jest', 'pytest', 'go']);
|
|
851
|
+
/**
|
|
852
|
+
* @implements A-SPEC-128.10 — I3 and R2, judged AFTER the run from what the runners reported: the expected test files
|
|
853
|
+
* a unit did not report (a runner configuration, a root narrower than the tree, a package that ran nothing), and the
|
|
854
|
+
* build roots whose code saw no executed test. Units that could not run (environment, stop) are judged elsewhere.
|
|
855
|
+
*/
|
|
856
|
+
function coverageAfterRun(expected, codeRoots, reported, executedByFile, skipUnits, buildRoots = [], testFiles) {
|
|
857
|
+
const notExecuted = [];
|
|
858
|
+
for (const [unit, files] of Object.entries(expected)) {
|
|
859
|
+
if (skipUnits.has(unit))
|
|
860
|
+
continue;
|
|
861
|
+
for (const f of files)
|
|
862
|
+
if (!reported.has(f))
|
|
863
|
+
notExecuted.push(f);
|
|
864
|
+
}
|
|
865
|
+
// @implements A-SPEC-128.12 — S5 (repairs 128.11 P2): a root's code is tested only by an executed test file whose OWN
|
|
866
|
+
// nearest build root is that root; that a unit ran is not evidence (root-unit-credit, ws-root-credit)
|
|
867
|
+
const roots = new Set(buildRoots);
|
|
868
|
+
const nearestRoot = (rel) => {
|
|
869
|
+
const parts = rel.split('/').slice(0, -1);
|
|
870
|
+
for (let i = parts.length; i > 0; i--) {
|
|
871
|
+
const d = parts.slice(0, i).join('/');
|
|
872
|
+
if (roots.has(d))
|
|
873
|
+
return d;
|
|
825
874
|
}
|
|
875
|
+
return '';
|
|
876
|
+
};
|
|
877
|
+
// @implements A-SPEC-128.13 — T3: only an executed test file of the scanned universe credits code (a test outside the
|
|
878
|
+
// repository or outside the scan credits nothing); when no universe is given, every executed file counts (scoped)
|
|
879
|
+
const universe = testFiles ? new Set(testFiles) : null;
|
|
880
|
+
const testedRoots = new Set();
|
|
881
|
+
for (const [f, n] of Object.entries(executedByFile))
|
|
882
|
+
if (n > 0 && (universe === null || universe.has(f)))
|
|
883
|
+
testedRoots.add(nearestRoot(f));
|
|
884
|
+
const tested = (root) => testedRoots.has(root);
|
|
885
|
+
const testsAt = (root) => (testFiles ?? []).filter((f) => nearestRoot(f) === root).length;
|
|
886
|
+
const untestedCode = codeRoots.filter((g) => !tested(g.root))
|
|
887
|
+
.map((g) => ({ root: g.root, sample: g.sample, ...(g.missingBuildFile ? { missingBuildFile: g.missingBuildFile } : {}), ...(testsAt(g.root) > 0 ? { testFiles: testsAt(g.root) } : {}) }));
|
|
888
|
+
return { notExecuted: notExecuted.sort(), untestedCode };
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* @implements A-SPEC-128.9 — E4: why a unit that ran nothing failed, when the cause is its environment, not its tests: a
|
|
892
|
+
* missing runner. Null when the unit executed a test or failed for any other reason (then it is the tests).
|
|
893
|
+
*/
|
|
894
|
+
function environmentReason(r, counted) {
|
|
895
|
+
// @implements A-SPEC-128.12 — an adapter that says environment is believed even when tests ran (jest projects, a
|
|
896
|
+
// configuration jest cannot print: the run executed, but it is not 0.40.x evidence)
|
|
897
|
+
if (r.environment === true)
|
|
898
|
+
return firstLine(r.tail);
|
|
899
|
+
if (r.passed || counted > 0)
|
|
900
|
+
return null;
|
|
901
|
+
if ((r.unsupported?.length ?? 0) > 0)
|
|
902
|
+
return firstLine(r.tail);
|
|
903
|
+
// @implements A-SPEC-128.10 — R4: only the RUNNER being absent; an ENOENT inside a test, or a module a test imports,
|
|
904
|
+
// is the tests (review 10:51, A H4 / A M4)
|
|
905
|
+
const m = /No module named '?pytest'?(?![\w.])|toolchain not found on PATH|java runtime not found|dotnet not found on PATH|not found on PATH — cannot execute|no gradle\/maven build file found/.exec(r.tail);
|
|
906
|
+
return m ? m[0] : null;
|
|
907
|
+
}
|
|
908
|
+
// @implements A-SPEC-128.12 — S2/S6: withoutExcluded (a unit's report without its excluded trees) lives in test-reports
|
|
909
|
+
function firstLine(s) {
|
|
910
|
+
return (s.split('\n').find((l) => l.trim() !== '') ?? s).trim().slice(0, 200);
|
|
911
|
+
}
|
|
912
|
+
function runScopeWithinBudget(scope, cwd, opts) {
|
|
913
|
+
const plan = planTestRun(scope);
|
|
914
|
+
if (plan.mode === 'noop') {
|
|
915
|
+
return { tier: scope.tier, mode: 'noop', ranFiles: [], passed: true, skipped: true, tail: plan.reason, workers: null };
|
|
826
916
|
}
|
|
827
|
-
|
|
828
|
-
|
|
917
|
+
const { units, unsupported, assumedJest, detected, detectedBy, notRun, notDetected, implementationCount, implementationSample, notTests, expected, codeRoots, buildRoots, sparseTests, outsideSurface, testFiles, notBuilt } = runEcosystems(scope, plan, cwd, { excludeDirs: opts.excludeDirs, isIgnored: opts.isIgnored });
|
|
918
|
+
// @implements A-SPEC-128.7 — what a full plan detected, left out and did not run travels with the result
|
|
919
|
+
// @implements A-SPEC-128.9 — with the implementation count E2 reads and the test-named files that hold no test
|
|
920
|
+
// @implements A-SPEC-128.13 — and the test-file count E2 also needs, and the go files this platform does not build
|
|
921
|
+
const named = plan.mode === 'full'
|
|
922
|
+
? { detectedBy, implementationCount, implementationSample, testFileCount: testFiles.length, ...(notRun.length ? { notRun } : {}),
|
|
923
|
+
...(notDetected.length ? { notDetected } : {}), ...(notTests.length ? { notTests } : {}), ...(notBuilt.length ? { notBuilt } : {}) } : {};
|
|
924
|
+
// @implements A-SPEC-128.12 — S1, S2, S3: outside the surface, one message, environment
|
|
925
|
+
// @implements A-SPEC-128.13 — W3: the work-tree rule is gone (a full run is HEAD's worktree); a configuration known to
|
|
926
|
+
// be outside the surface before the run starts no unit (B M2)
|
|
927
|
+
const surface = plan.mode !== 'full' ? [] : outsideSurface.map((o) => ({ ecosystem: o.ecosystem, dir: o.dir, reason: `${exports.UNSUPPORTED}: ${o.reason}` }));
|
|
928
|
+
if (units.length > 0 && surface.length === 0) {
|
|
929
|
+
const reported = new Set(); // @implements A-SPEC-128.10 — I3: every file a runner said it ran or collected
|
|
930
|
+
const skipUnits = new Set(); // units that could not run: their coverage is not the comparison's to judge
|
|
931
|
+
const runners = {
|
|
932
|
+
jest: (f, m, c) => (m === 'full' && jestEntry(c) === null
|
|
933
|
+
? { passed: false, tail: `jest is not installed for this unit (no local node_modules/jest from ${c})`, executed: {}, workers: null, environment: true }
|
|
934
|
+
: runJest(f, m, c, opts)),
|
|
935
|
+
pytest: (f, m, c, ignore) => runPytest(f, m, c, ignore, opts.sourceRoot ? path.join(opts.sourceRoot, path.relative(cwd, c)) : undefined, opts.sourceRoot && m === 'full' ? { root: cwd, sourceRoot: opts.sourceRoot } : undefined),
|
|
936
|
+
go: (f, m, c, ignore) => runGo(f, m, c, { ignore, env: (0, test_units_2.goWorkEnv)(cwd) }),
|
|
937
|
+
rust: (f, m, c) => runCargo(f, m, c), java: (f, m, c) => runGradle(f, m, c), dotnet: (f, m, c) => runDotnet(f, m, c),
|
|
938
|
+
};
|
|
829
939
|
const ran = [];
|
|
830
940
|
let passed = true;
|
|
831
941
|
const tails = [];
|
|
832
942
|
const executedByFile = {};
|
|
833
943
|
const outcomeByFile = {}; // @implements A-SPEC-534.5 — jest only
|
|
834
|
-
|
|
944
|
+
let workers = null; // @implements A-SPEC-466.2 — what the jest adapter placed on its argv
|
|
945
|
+
let testsRun = 0; // @implements A-SPEC-128.5
|
|
946
|
+
const testsRunBy = {}; // @implements A-SPEC-128.6 — per ecosystem, so none hides behind another
|
|
947
|
+
let stopped = false;
|
|
948
|
+
const failedBy = []; // @implements A-SPEC-128.7 — which runner was red, so a refusal can name its tree
|
|
949
|
+
const unitResults = []; // @implements A-SPEC-128.9 — per unit: every unit must run a test
|
|
950
|
+
const environment = [];
|
|
951
|
+
const keyed = (dir, rec) => (dir === '' ? rec : Object.fromEntries(Object.entries(rec).map(([k, v]) => [`${dir}/${k}`, v])));
|
|
952
|
+
for (const u of [...units].sort((a, b) => (a.ecosystem === b.ecosystem ? a.dir.localeCompare(b.dir) : a.ecosystem.localeCompare(b.ecosystem)))) {
|
|
953
|
+
const eco = u.ecosystem;
|
|
835
954
|
STOPPED = null;
|
|
836
955
|
LEFTOVER = null;
|
|
837
|
-
const
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
956
|
+
const unitCwd = u.dir === '' ? cwd : path.join(cwd, u.dir);
|
|
957
|
+
const raw = runners[eco](u.files, plan.mode, unitCwd, u.ignore);
|
|
958
|
+
// @implements A-SPEC-128.12 — S2/S6: exclusions judged after the run. A reported test under an excluded tree leaves
|
|
959
|
+
// the judgement and the counts; one that ran red is environment, named — never hidden
|
|
960
|
+
const { r, excludedRed } = plan.mode === 'full' ? (0, test_reports_1.withoutExcluded)(raw, u.ignore, u.dir) : { r: raw, excludedRed: [] };
|
|
961
|
+
if (eco === 'jest' && workers === null)
|
|
962
|
+
workers = r.workers ?? null;
|
|
963
|
+
if (!ran.includes(eco))
|
|
964
|
+
ran.push(eco);
|
|
965
|
+
passed = passed && r.passed && STOPPED === null && excludedRed.length === 0;
|
|
966
|
+
stopped = stopped || STOPPED !== null;
|
|
967
|
+
if ((!r.passed || STOPPED !== null) && !failedBy.includes(eco))
|
|
968
|
+
failedBy.push(eco);
|
|
969
|
+
// @implements A-SPEC-128.5 — an adapter that counts apart from its credit says so; jest and pytest credit every test
|
|
970
|
+
const own = r.testsRun;
|
|
971
|
+
// @implements A-SPEC-128.6 — every adapter counts for itself; one that does not reports 0, never a guess
|
|
972
|
+
const counted = typeof own === 'number' ? own : 0;
|
|
973
|
+
testsRunBy[eco] = (testsRunBy[eco] ?? 0) + counted;
|
|
974
|
+
testsRun += counted;
|
|
975
|
+
// @implements A-SPEC-128.13 — T3: a test the runner reported from outside the repository (roots or testpaths that
|
|
976
|
+
// leave it) is named, never credited; A-SPEC-128.14 — judged from the repository root (`../shared` from backend is inside)
|
|
977
|
+
const outside = Object.keys(r.executed).filter((k) => path.isAbsolute(k) || path.posix.normalize(u.dir === '' ? k : `${u.dir}/${k}`).startsWith('../'));
|
|
978
|
+
// every reason is kept: a jest projects configuration whose excluded tree also ran red names both
|
|
979
|
+
const reasons = STOPPED !== null ? [] : [environmentReason(r, counted),
|
|
980
|
+
excludedRed.length > 0 ? `제외한 트리의 시험이 실행됨 — 러너 설정에서도 빼야 함: ${excludedRed.slice(0, 5).join(', ')}` : null,
|
|
981
|
+
outside.length > 0 ? `tests outside the repository ran (${outside.slice(0, 3).join(', ')}) — they are not this commit's evidence` : null].filter((x) => x !== null);
|
|
982
|
+
if (outside.length > 0)
|
|
983
|
+
passed = false;
|
|
984
|
+
for (const reason of reasons)
|
|
985
|
+
environment.push({ ecosystem: eco, dir: u.dir, reason });
|
|
986
|
+
const env = reasons.length > 0 ? reasons.join(' | ') : null;
|
|
987
|
+
unitResults.push({ ecosystem: eco, dir: u.dir, testsRun: counted, passed: r.passed && STOPPED === null, ...(env !== null ? { environment: env } : {}) });
|
|
988
|
+
const label = u.dir === '' ? eco : `${eco} @ ${u.dir}`;
|
|
989
|
+
tails.push(`[${label}] ${r.tail}${STOPPED !== null ? `\n${STOPPED}` : ''}${LEFTOVER !== null ? `\n${LEFTOVER}` : ''}`);
|
|
990
|
+
Object.assign(executedByFile, keyed(u.dir, r.executed));
|
|
991
|
+
for (const f of [...Object.keys(r.executed), ...(r.reported ?? [])])
|
|
992
|
+
reported.add(u.dir === '' ? f : `${u.dir}/${f}`);
|
|
993
|
+
if (env !== null || STOPPED !== null)
|
|
994
|
+
skipUnits.add(`${eco}@${u.dir}`);
|
|
842
995
|
const adapterOutcomes = r.outcomes;
|
|
843
996
|
if (adapterOutcomes)
|
|
844
|
-
Object.assign(outcomeByFile, adapterOutcomes);
|
|
997
|
+
Object.assign(outcomeByFile, keyed(u.dir, adapterOutcomes));
|
|
845
998
|
// @implements A-SPEC-137.1 — an adapter whose toolchain is absent reports its files as
|
|
846
999
|
// unsupported; merge them so a scope that could not run them never reads as fully covered.
|
|
847
1000
|
const adapterUnsupported = r.unsupported;
|
|
@@ -849,14 +1002,30 @@ function runTestScope(scope, cwd) {
|
|
|
849
1002
|
unsupported.push(...adapterUnsupported);
|
|
850
1003
|
}
|
|
851
1004
|
if (assumedJest) {
|
|
852
|
-
tails.push('[assumption] full run
|
|
1005
|
+
tails.push('[assumption] full run found no test ecosystem in the project — defaulted to the jest suite');
|
|
853
1006
|
}
|
|
854
1007
|
if (unsupported.length) {
|
|
855
1008
|
tails.push(`[unsupported] ${unsupported.length} test file(s) have no runner adapter: ${unsupported.slice(0, 5).join(', ')}`);
|
|
856
1009
|
}
|
|
1010
|
+
// @implements A-SPEC-128.11 — P6: tests a sparse checkout left out of the work tree cannot run here
|
|
1011
|
+
if (plan.mode === 'full' && sparseTests.length > 0) {
|
|
1012
|
+
passed = false;
|
|
1013
|
+
environment.push({ ecosystem: 'git', dir: '', reason: `sparse checkout — 증빙할 수 없음: ${sparseTests.length} test file(s) outside the work tree, e.g. ${sparseTests.slice(0, 3).join(', ')}` });
|
|
1014
|
+
tails.push(`[sparse] ${sparseTests.length} test file(s) are not in the work tree (skip-worktree): ${sparseTests.slice(0, 5).join(', ')}`);
|
|
1015
|
+
}
|
|
1016
|
+
// @implements A-SPEC-128.10 — I3 and R2, after the run
|
|
1017
|
+
const coverage = plan.mode === 'full' ? coverageAfterRun(expected, codeRoots, reported, executedByFile, skipUnits, buildRoots, testFiles) : null;
|
|
1018
|
+
if (coverage?.notExecuted.length)
|
|
1019
|
+
tails.push(`[not run] ${coverage.notExecuted.length} detected test file(s) did not run: ${coverage.notExecuted.slice(0, 5).join(', ')}`);
|
|
1020
|
+
if (coverage?.untestedCode.length)
|
|
1021
|
+
tails.push(`[untested] code with no executed test under: ${coverage.untestedCode.map((g) => g.root || '(root)').join(', ')}`);
|
|
857
1022
|
return {
|
|
858
1023
|
tier: scope.tier, mode: plan.mode, ranFiles: plan.testFiles, passed, skipped: false,
|
|
859
|
-
tail: tails.join('\n'), executedByFile, ranWith: ran,
|
|
1024
|
+
tail: tails.join('\n'), executedByFile, ranWith: ran, workers, testsRun, testsRunBy, stopped, detected, failedBy, ...named,
|
|
1025
|
+
...(plan.mode === 'full' ? { units: unitResults } : {}), ...(environment.length ? { environment } : {}),
|
|
1026
|
+
...(coverage?.notExecuted.length ? { notExecuted: coverage.notExecuted.slice(0, 200) } : {}),
|
|
1027
|
+
...(coverage?.untestedCode.length ? { untestedCode: coverage.untestedCode } : {}),
|
|
1028
|
+
workersIgnoredBy: opts.workers === undefined ? [] : ran.filter((eco) => eco !== 'jest'),
|
|
860
1029
|
...(Object.keys(outcomeByFile).length ? { outcomeByFile } : {}),
|
|
861
1030
|
...(unsupported.length ? { unsupported } : {}),
|
|
862
1031
|
};
|
|
@@ -866,8 +1035,15 @@ function runTestScope(scope, cwd) {
|
|
|
866
1035
|
// the no-passWithNoTests rule exists to prevent.
|
|
867
1036
|
return {
|
|
868
1037
|
tier: scope.tier, mode: plan.mode, ranFiles: plan.testFiles, passed: false, skipped: false,
|
|
869
|
-
|
|
870
|
-
|
|
1038
|
+
// @implements A-SPEC-128.8 — a full plan with nothing detected at the root says so, not "no adapter for 0 files"
|
|
1039
|
+
tail: surface.length > 0 ? `no unit started — outside the 0.40.x surface:\n${surface.map((s) => s.reason).join('\n')}`
|
|
1040
|
+
: plan.mode === 'full' && unsupported.length === 0
|
|
1041
|
+
? `no test unit in the project — nothing ran${implementationCount > 0 ? ` (implementation code without tests, e.g. ${implementationSample.join(', ')})` : ''}`
|
|
1042
|
+
: `no runner adapter for ${unsupported.length} test file(s): ${unsupported.slice(0, 5).join(', ')}`,
|
|
1043
|
+
executedByFile: {}, unsupported, ranWith: [], workers: null, testsRun: 0, testsRunBy: {}, stopped: false, detected, ...named,
|
|
1044
|
+
...(plan.mode === 'full' ? { units: [] } : {}), ...(surface.length ? { environment: surface } : {}),
|
|
1045
|
+
// @implements A-SPEC-128.10 — R2: with no unit, every build root's code is untested (and names a missing build file)
|
|
1046
|
+
...(plan.mode === 'full' && surface.length === 0 && codeRoots.length ? { untestedCode: codeRoots.map((g) => ({ root: g.root, sample: g.sample, ...(g.missingBuildFile ? { missingBuildFile: g.missingBuildFile } : {}) })) } : {}),
|
|
871
1047
|
};
|
|
872
1048
|
}
|
|
873
1049
|
// @implements A-SPEC-515.1
|
|
@@ -933,18 +1109,32 @@ function failedTestSummary(stdout, limit = 5) {
|
|
|
933
1109
|
if (j === null || typeof j !== 'object' || !Array.isArray(j.testResults))
|
|
934
1110
|
return null;
|
|
935
1111
|
const failures = [];
|
|
1112
|
+
const broken = [];
|
|
936
1113
|
for (const file of j.testResults) {
|
|
937
1114
|
const base = typeof file?.name === 'string' ? file.name.split(/[\\/]/).pop() ?? file.name : '(unknown file)';
|
|
1115
|
+
const before = failures.length;
|
|
938
1116
|
for (const a of Array.isArray(file?.assertionResults) ? file.assertionResults : []) {
|
|
939
1117
|
if (a?.status !== 'failed')
|
|
940
1118
|
continue;
|
|
941
1119
|
const msg = Array.isArray(a.failureMessages) ? a.failureMessages.find((m) => typeof m === 'string' && m.trim() !== '') : undefined;
|
|
1120
|
+
// @implements A-SPEC-466.4 \u2014 one line per name, each part bounded on its own, so one long message pushes no name out
|
|
942
1121
|
failures.push({
|
|
943
|
-
where: `${base} \u203a ${String(a.title ?? '(untitled)')}`,
|
|
944
|
-
first: typeof msg === 'string' ? (msg.trim().split('\n')[0] ?? '') : '',
|
|
1122
|
+
where: clip(`${base} \u203a ${String(a.title ?? '(untitled)').replace(/\s+/g, ' ').trim()}`, WHERE_MAX),
|
|
1123
|
+
first: clip(typeof msg === 'string' ? (msg.trim().split('\n')[0] ?? '') : '', FIRST_MAX),
|
|
945
1124
|
});
|
|
946
1125
|
}
|
|
1126
|
+
// @implements A-SPEC-466.3 \u2014 a suite that failed with no failing assertion (it did not compile, its teardown threw)
|
|
1127
|
+
// is named too, with the first line of its message
|
|
1128
|
+
// @implements A-SPEC-466.4 \u2014 the cause line: jest opens the message with a `\u25cf Test suite failed to run` header
|
|
1129
|
+
if (file?.status === 'failed' && failures.length === before) {
|
|
1130
|
+
const message = typeof file.message === 'string' ? file.message.replace(/\u001b\[[0-9;]*m/g, '') : '';
|
|
1131
|
+
const cause = message.split('\n').map((l) => l.trim()).find((l) => l !== '' && !l.startsWith('\u25cf')) ?? '';
|
|
1132
|
+
broken.push({ where: clip(`${base} \u203a (suite failed to run)`, WHERE_MAX), first: clip(cause, FIRST_MAX) });
|
|
1133
|
+
}
|
|
947
1134
|
}
|
|
1135
|
+
// @implements A-SPEC-466.5 \u2014 suites that failed to run come first: in a real mixed run (24 failing assertions, 2
|
|
1136
|
+
// broken suites) the five-name bound was spent on assertions and no broken suite was named
|
|
1137
|
+
failures.unshift(...broken);
|
|
948
1138
|
if (failures.length === 0)
|
|
949
1139
|
return null;
|
|
950
1140
|
const shown = failures.slice(0, Math.max(0, limit));
|
|
@@ -954,6 +1144,31 @@ function failedTestSummary(stdout, limit = 5) {
|
|
|
954
1144
|
lines.push(` \u2026 \uc678 ${rest}\uac74`);
|
|
955
1145
|
return lines.join('\n');
|
|
956
1146
|
}
|
|
1147
|
+
/** @implements A-SPEC-466.4 \u2014 each failure line's own bound: `file \u203a title` and its first message line. */
|
|
1148
|
+
const WHERE_MAX = 200;
|
|
1149
|
+
const FIRST_MAX = 300;
|
|
1150
|
+
/** @implements A-SPEC-466.4 \u2014 `text` cut to at most `max` characters, marked `\u2026`, never inside a surrogate pair. */
|
|
1151
|
+
function clip(text, max) {
|
|
1152
|
+
if (text.length <= max)
|
|
1153
|
+
return text;
|
|
1154
|
+
let end = max - 1;
|
|
1155
|
+
if (/[\uD800-\uDBFF]/.test(text[end - 1] ?? ''))
|
|
1156
|
+
end -= 1;
|
|
1157
|
+
return `${text.slice(0, end)}\u2026`;
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* @implements A-SPEC-466.3, A-SPEC-466.4 \u2014 the tail of a red jest run. The failing names come first; jest's stderr
|
|
1161
|
+
* follows with a bound of its own. One `tailOf` over both kept the last lines and cut the front, so a long stderr pushed
|
|
1162
|
+
* every name out (2026-11-04, `27bc0c40`: five failures, none named). The name block is bounded by its parts: five names
|
|
1163
|
+
* of at most WHERE_MAX and FIRST_MAX characters and one count line, so the whole tail stays under 7,000 characters.
|
|
1164
|
+
* Without readable jest JSON the tail is what it always was.
|
|
1165
|
+
*/
|
|
1166
|
+
function redJestTail(stdout, stderr) {
|
|
1167
|
+
const named = failedTestSummary(stdout);
|
|
1168
|
+
if (named === null)
|
|
1169
|
+
return tailOf(`${stdout}\n${stderr}`, { lines: 6 });
|
|
1170
|
+
return `${named}\n${tailOf(stderr, { lines: 30 })}`;
|
|
1171
|
+
}
|
|
957
1172
|
function summarizeJestJson(stdout) {
|
|
958
1173
|
// The payload is not the whole of stdout. A suite that logs anything prints it BEFORE the JSON,
|
|
959
1174
|
// and this repository's own suite does: measured, the first live run after this function landed
|