@holmes-lab/holmes-kit 0.40.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +312 -0
- package/README.md +79 -5
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/approve-context.js +4 -3
- package/dist/holmes/cli/approve.js +22 -12
- package/dist/holmes/cli/autonomy.d.ts +21 -0
- package/dist/holmes/cli/autonomy.js +35 -5
- package/dist/holmes/cli/doctor.js +58 -6
- package/dist/holmes/cli/index.js +394 -267
- package/dist/holmes/cli/init.js +17 -6
- package/dist/holmes/cli/interactive-prompt.d.ts +39 -2
- package/dist/holmes/cli/interactive-prompt.js +98 -16
- package/dist/holmes/cli/ledger-witness.d.ts +61 -0
- package/dist/holmes/cli/ledger-witness.js +212 -0
- package/dist/holmes/cli/playbook-skills.d.ts +3 -56
- package/dist/holmes/cli/playbook-skills.js +26 -349
- package/dist/holmes/config/config.d.ts +21 -0
- package/dist/holmes/config/config.js +22 -3
- package/dist/holmes/governance/approval-queue.d.ts +65 -1
- package/dist/holmes/governance/approval-queue.js +279 -9
- package/dist/holmes/governance/autonomous-shell.d.ts +13 -1
- package/dist/holmes/governance/autonomous-shell.js +157 -4
- package/dist/holmes/governance/autonomy.d.ts +216 -0
- package/dist/holmes/governance/autonomy.js +1162 -10
- package/dist/holmes/governance/install-manifest.d.ts +7 -4
- package/dist/holmes/governance/install-manifest.js +144 -14
- package/dist/holmes/governance/ledger-witness.d.ts +63 -0
- package/dist/holmes/governance/ledger-witness.js +296 -0
- package/dist/holmes/governance/provenance-chain.d.ts +8 -1
- package/dist/holmes/governance/provenance-chain.js +23 -4
- 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/governance/recorded-pairs.d.ts +4 -0
- package/dist/holmes/governance/recorded-pairs.js +25 -1
- package/dist/holmes/governance/session-context.d.ts +7 -0
- package/dist/holmes/governance/session-context.js +34 -6
- package/dist/holmes/guardrail/advisory-line.d.ts +102 -0
- package/dist/holmes/guardrail/advisory-line.js +718 -0
- package/dist/holmes/guardrail/anchor-scope-text.d.ts +9 -0
- package/dist/holmes/guardrail/anchor-scope-text.js +7 -0
- package/dist/holmes/guardrail/command-traits.d.ts +102 -0
- package/dist/holmes/guardrail/command-traits.js +379 -0
- package/dist/holmes/guardrail/fixtures/manager-builtins.json +23 -0
- package/dist/holmes/guardrail/fixtures/npm-commands.json +7 -0
- package/dist/holmes/guardrail/impact-gate.d.ts +6 -0
- package/dist/holmes/guardrail/impact-gate.js +32 -5
- package/dist/holmes/guardrail/outward-acts.d.ts +47 -0
- package/dist/holmes/guardrail/outward-acts.js +1102 -0
- package/dist/holmes/guardrail/refusal-codes.js +8 -1
- package/dist/holmes/guardrail/refusal-templates.d.ts +15 -0
- package/dist/holmes/guardrail/refusal-templates.js +71 -0
- package/dist/holmes/guardrail/risk-classifier.d.ts +22 -6
- package/dist/holmes/guardrail/risk-classifier.js +12 -118
- package/dist/holmes/guardrail/shell-lexer.d.ts +69 -0
- package/dist/holmes/guardrail/shell-lexer.js +567 -0
- package/dist/holmes/guardrail/write-target.js +7 -1
- package/dist/holmes/hooks/pre-tool-use.d.ts +71 -0
- package/dist/holmes/hooks/pre-tool-use.js +1466 -14
- package/dist/holmes/hooks/session-start.js +27 -1
- package/dist/holmes/hooks/stop.d.ts +7 -0
- package/dist/holmes/hooks/stop.js +39 -2
- package/dist/holmes/mcp/elicit-approval.d.ts +0 -21
- package/dist/holmes/mcp/elicit-approval.js +5 -2
- package/dist/holmes/mcp/handlers/approval-ask.js +3 -2
- package/dist/holmes/mcp/handlers/entity-integration.d.ts +1 -1
- package/dist/holmes/mcp/handlers/entity-integration.js +9 -6
- package/dist/holmes/mcp/handlers/entity-renumber.js +2 -1
- package/dist/holmes/mcp/handlers/entity-store.js +7 -2
- 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/operator-inspection.d.ts +2 -0
- package/dist/holmes/mcp/handlers/operator-inspection.js +25 -4
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +3 -1
- package/dist/holmes/mcp/handlers/spec-approval.js +28 -10
- package/dist/holmes/mcp/handlers/spec-lifecycle.js +10 -7
- package/dist/holmes/mcp/handlers/test-execution.d.ts +470 -3
- package/dist/holmes/mcp/handlers/test-execution.js +201 -21
- package/dist/holmes/mcp/handlers.d.ts +473 -8
- package/dist/holmes/mcp/handlers.js +6 -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 +16 -10
- 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/playbook-reference.d.ts +50 -0
- package/dist/holmes/project/playbook-reference.js +259 -0
- package/dist/holmes/project/playbook-skill-states.d.ts +94 -0
- package/dist/holmes/project/playbook-skill-states.js +396 -0
- package/dist/holmes/project/root.d.ts +9 -1
- package/dist/holmes/project/root.js +26 -3
- package/dist/holmes/project/running-package.d.ts +15 -0
- package/dist/holmes/project/running-package.js +87 -0
- 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 +178 -65
- package/dist/holmes/review/test-runner.js +551 -319
- package/dist/holmes/review/test-units.d.ts +159 -0
- package/dist/holmes/review/test-units.js +814 -0
- package/dist/holmes/spec/entity-integration-transaction.d.ts +19 -2
- package/dist/holmes/spec/entity-integration-transaction.js +68 -7
- package/package.json +5 -2
- 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, A-SPEC-794.119
|
|
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,18 @@ 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
|
+
/**
|
|
101
|
+
* @implements A-SPEC-794.119 — the tree the run in progress executes in, held for the run as its budget is (`runTestScope`
|
|
102
|
+
* sets it from `projectRoot`). Every test child takes `testEnv()`: CLAUDE_PROJECT_DIR, where the server carries it, names
|
|
103
|
+
* this tree. Undefined: the environment is cleaned as before.
|
|
104
|
+
*/
|
|
105
|
+
let RUN_PROJECT_ROOT;
|
|
106
|
+
function testEnv() {
|
|
107
|
+
return (0, root_1.cleanTestEnv)(process.env, RUN_PROJECT_ROOT === undefined ? {} : { projectDir: RUN_PROJECT_ROOT });
|
|
108
|
+
}
|
|
109
|
+
function runBounded(cmd, args, opts, timeoutMs = RUN_BUDGET_MS) {
|
|
94
110
|
// @implements A-SPEC-734.4 — the group's whole lifetime lives in bounded-group: a watch shim ends it when this process
|
|
95
111
|
// goes, and the call ends it on the bound, an overflow or a signal, or when members outlive a normal exit
|
|
96
112
|
const { result: r, stopped, leftovers } = (0, bounded_group_1.boundedGroupSpawnSync)(cmd, args, opts, timeoutMs);
|
|
@@ -123,6 +139,13 @@ function planTestRun(scope) {
|
|
|
123
139
|
reason: `${scope.tier} scope — run ${scope.impactedTestFiles.length} impacted test file(s)`,
|
|
124
140
|
};
|
|
125
141
|
}
|
|
142
|
+
var test_units_3 = require("./test-units");
|
|
143
|
+
Object.defineProperty(exports, "scanEcosystems", { enumerable: true, get: function () { return test_units_3.scanEcosystems; } });
|
|
144
|
+
Object.defineProperty(exports, "excludedDir", { enumerable: true, get: function () { return test_units_3.excludedDir; } });
|
|
145
|
+
Object.defineProperty(exports, "normaliseExcludeDirs", { enumerable: true, get: function () { return test_units_3.normaliseExcludeDirs; } });
|
|
146
|
+
Object.defineProperty(exports, "BUILD_ROOTS", { enumerable: true, get: function () { return test_units_3.BUILD_ROOTS; } });
|
|
147
|
+
Object.defineProperty(exports, "pytestRules", { enumerable: true, get: function () { return test_units_3.pytestRules; } });
|
|
148
|
+
Object.defineProperty(exports, "projectFiles", { enumerable: true, get: function () { return test_units_3.projectFiles; } });
|
|
126
149
|
/** Ecosystem of a test file, by extension/convention. `null` when no runner adapter exists for it. */
|
|
127
150
|
function ecosystemOf(file) {
|
|
128
151
|
if (/\.(ts|mts|cts|tsx|jsx|js|mjs|cjs)$/i.test(file))
|
|
@@ -150,150 +173,18 @@ function ecosystemOf(file) {
|
|
|
150
173
|
return 'dotnet';
|
|
151
174
|
return null; // cpp and non-test files — counted syntactically, not yet executable here
|
|
152
175
|
}
|
|
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
|
-
}
|
|
176
|
+
// @implements A-SPEC-128.12 — the report readers live in review/test-reports (SRP); these names stay importable from here
|
|
177
|
+
// @implements A-SPEC-137.1, A-SPEC-137.3, A-SPEC-534.1 — the go, JUnit and jest-outcome readers they specify, re-exported
|
|
178
|
+
var test_reports_2 = require("./test-reports");
|
|
179
|
+
Object.defineProperty(exports, "parseGoTestJson", { enumerable: true, get: function () { return test_reports_2.parseGoTestJson; } });
|
|
180
|
+
Object.defineProperty(exports, "goPackagesWithTestEvents", { enumerable: true, get: function () { return test_reports_2.goPackagesWithTestEvents; } });
|
|
181
|
+
Object.defineProperty(exports, "parseExecutedCounts", { enumerable: true, get: function () { return test_reports_2.parseExecutedCounts; } });
|
|
182
|
+
Object.defineProperty(exports, "classifyJestOutcomes", { enumerable: true, get: function () { return test_reports_2.classifyJestOutcomes; } });
|
|
183
|
+
Object.defineProperty(exports, "parseJUnitXmlCounts", { enumerable: true, get: function () { return test_reports_2.parseJUnitXmlCounts; } });
|
|
184
|
+
Object.defineProperty(exports, "parseJUnitXmlOutcomes", { enumerable: true, get: function () { return test_reports_2.parseJUnitXmlOutcomes; } });
|
|
185
|
+
Object.defineProperty(exports, "parseJUnitXmlFiles", { enumerable: true, get: function () { return test_reports_2.parseJUnitXmlFiles; } });
|
|
186
|
+
Object.defineProperty(exports, "wellShapedJson", { enumerable: true, get: function () { return test_reports_2.wellShapedJson; } });
|
|
187
|
+
Object.defineProperty(exports, "readJestReport", { enumerable: true, get: function () { return test_reports_2.readJestReport; } });
|
|
297
188
|
/**
|
|
298
189
|
* @implements A-SPEC-466 — W-4. The TARGET repo's own jest entry, as its package declares it.
|
|
299
190
|
*
|
|
@@ -322,8 +213,75 @@ function jestEntry(cwd) {
|
|
|
322
213
|
return null;
|
|
323
214
|
}
|
|
324
215
|
}
|
|
216
|
+
/** @implements A-SPEC-128.6 — passed and failed cases only (skipped ones are not counted by the parsers). */
|
|
217
|
+
const casesRan = (executed) => Object.values(executed).reduce((a, b) => a + b, 0);
|
|
218
|
+
/**
|
|
219
|
+
* @implements A-SPEC-466.6 — test_run's `timeoutMinutes`, the run's time budget: absent or null is 30; an integer
|
|
220
|
+
* 1..180 is kept; anything else throws (never clamped). It is not a judgement input.
|
|
221
|
+
*/
|
|
222
|
+
function testRunTimeoutMinutes(value) {
|
|
223
|
+
if (value === undefined || value === null)
|
|
224
|
+
return exports.RUNNER_TIMEOUT_MS / 60_000;
|
|
225
|
+
if (typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= 180)
|
|
226
|
+
return value;
|
|
227
|
+
throw new Error(`timeoutMinutes must be an integer from 1 to 180 (got ${typeof value === 'string' ? JSON.stringify(value) : String(value)})`);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* @implements A-SPEC-466.1 — test_run's `workers`: absent stays absent; an integer 1..64 is kept; anything else
|
|
231
|
+
* throws, so a bad count is refused before any change set is derived or any runner starts.
|
|
232
|
+
*/
|
|
233
|
+
function testRunWorkers(value) {
|
|
234
|
+
if (value === undefined || value === null)
|
|
235
|
+
return undefined; // @implements A-SPEC-466.3 — null reads as omitted
|
|
236
|
+
if (typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= 64)
|
|
237
|
+
return value;
|
|
238
|
+
throw new Error(`workers must be an integer from 1 to 64 (got ${typeof value === 'string' ? JSON.stringify(value) : String(value)})`);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* @implements A-SPEC-128.12 — the one message for a configuration outside the 0.40.x supported surface (jest with one
|
|
242
|
+
* project and one unit, pytest under default naming, go). It leads every such environment reason.
|
|
243
|
+
*/
|
|
244
|
+
exports.UNSUPPORTED = '이 구성은 0.40.x가 증빙하지 않습니다 — 0.41 / 오너 결정';
|
|
245
|
+
/** @implements A-SPEC-128.12 — S7: a runner output that could not be read is a value (the unit's environment), never a throw. */
|
|
246
|
+
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 });
|
|
247
|
+
/**
|
|
248
|
+
* @implements A-SPEC-128.12 — S2/S7: what `jest --showConfig` resolved for this unit, judged by test-units'
|
|
249
|
+
* `jestConfigSurface` (A-SPEC-128.13: one place) — the reason it is outside the surface or cannot be read, else null.
|
|
250
|
+
* No pattern is taken from it.
|
|
251
|
+
*/
|
|
252
|
+
function jestConfigReason(cmd, pre, cwd) {
|
|
253
|
+
let out;
|
|
254
|
+
try {
|
|
255
|
+
out = runBounded(cmd, [...pre, '--showConfig'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: testEnv() });
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
const err = e;
|
|
259
|
+
out = `${err.stderr ?? ''}\n${err.stdout ?? ''}\n${err.message ?? ''}`;
|
|
260
|
+
}
|
|
261
|
+
const cfg = (0, test_reports_1.wellShapedJson)(out, test_reports_1.isJestConfig);
|
|
262
|
+
if (cfg === null || cfg.configs.length === 0)
|
|
263
|
+
return `runner output could not be read (jest --showConfig): ${firstLine(out) || '(empty)'}`;
|
|
264
|
+
const outside = (0, test_units_2.jestConfigSurface)(cfg);
|
|
265
|
+
return outside === null ? null : `${exports.UNSUPPORTED}: ${outside}`;
|
|
266
|
+
}
|
|
325
267
|
/** Run the jest half of a plan. */
|
|
326
|
-
function runJest(files, mode, cwd) {
|
|
268
|
+
function runJest(files, mode, cwd, opts = {}) {
|
|
269
|
+
// @implements A-SPEC-128.11 — P3: a full run's report is read from a file jest writes, so the user's console output
|
|
270
|
+
// on stdout cannot break it; a scoped run keeps its 466.1 argv
|
|
271
|
+
const reportDir = mode === 'full' ? fs.mkdtempSync(path.join(os.tmpdir(), 'holmes-jest-')) : null;
|
|
272
|
+
try {
|
|
273
|
+
return runJestWith(files, mode, cwd, opts, reportDir === null ? null : path.join(reportDir, 'report.json'));
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
if (reportDir !== null) {
|
|
277
|
+
try {
|
|
278
|
+
fs.rmSync(reportDir, { recursive: true, force: true });
|
|
279
|
+
}
|
|
280
|
+
catch { /* best effort */ }
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function runJestWith(files, mode, cwd, opts, reportFile) {
|
|
327
285
|
// --runTestsByPath treats args as EXACT files (not testPathPattern REGEXes, which would over/mis-match
|
|
328
286
|
// or throw on a metachar); `--` + a leading-`./` guard so a path can never be read as a flag. NO
|
|
329
287
|
// --passWithNoTests on a scoped run (verification H5): if the resolved paths match ZERO tests
|
|
@@ -335,15 +293,36 @@ function runJest(files, mode, cwd) {
|
|
|
335
293
|
// (structurally no .cmd shim to ENOENT on); the npx spelling only as the fallback.
|
|
336
294
|
const entry = jestEntry(cwd);
|
|
337
295
|
const [cmd, ...pre] = entry !== null ? [process.execPath, entry] : ['npx', 'jest'];
|
|
296
|
+
// @implements A-SPEC-466.1 — absent, jest keeps the project's own maxWorkers
|
|
297
|
+
// @implements A-SPEC-466.2 — `applied` is the one value both the argv and the report are built from
|
|
298
|
+
const applied = opts.workers ?? null;
|
|
299
|
+
const workers = applied === null ? [] : [`--maxWorkers=${applied}`];
|
|
300
|
+
// @implements A-SPEC-128.12 — S2: holmes passes jest no ignore argument, so the user's configuration is never replaced
|
|
301
|
+
// (a CLI pattern applies to every project and hid one project's red, R1); exclusions are judged after the run
|
|
338
302
|
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
|
|
303
|
+
? [...pre, '--silent', '--json', '--forceExit', ...workers, '--runTestsByPath', '--', ...safeFiles]
|
|
304
|
+
: [...pre, '--silent', '--json', '--forceExit', ...workers, `--outputFile=${reportFile}`]; // round 13: an open handle after the last test must not hold the run
|
|
305
|
+
const ran = jestRun(cmd, args, cwd, mode, reportFile, applied);
|
|
306
|
+
if (mode !== 'full' || ran.environment === true)
|
|
307
|
+
return ran;
|
|
308
|
+
// @implements A-SPEC-128.12 — S2/S7: one project only; a configuration jest cannot print is environment
|
|
309
|
+
// @implements A-SPEC-128.13 — and no configured testNamePattern (a selection below the file)
|
|
310
|
+
const reason = jestConfigReason(cmd, pre, cwd);
|
|
311
|
+
return reason === null ? ran : { ...ran, passed: false, environment: true, tail: `${reason}\n${ran.tail}` };
|
|
312
|
+
}
|
|
313
|
+
function jestRun(cmd, args, cwd, mode, reportFile, applied) {
|
|
341
314
|
try {
|
|
342
|
-
const
|
|
315
|
+
const raw = runBounded(cmd, args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: testEnv() });
|
|
316
|
+
const out = mode === 'full' ? (0, test_reports_1.readJestReport)(reportFile, raw) : raw;
|
|
317
|
+
if (out === null)
|
|
318
|
+
return unreadable('jest --json', raw, applied);
|
|
343
319
|
// @implements A-SPEC-515.1 — the green path says what happened instead of handing back the
|
|
344
320
|
// whole `--json` document. `tailOf` wraps the result too, so an unexpectedly long summary is
|
|
345
321
|
// still bounded: a cap that any one path can escape is not a cap.
|
|
346
|
-
|
|
322
|
+
const executed = (0, test_reports_1.parseExecutedCounts)(out, cwd);
|
|
323
|
+
// @implements A-SPEC-128.13 — T1: exit 0 is not green when the report holds a failure (testFailureExitCode: 0)
|
|
324
|
+
const failed = (0, test_reports_1.jestReportFailed)(out);
|
|
325
|
+
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
326
|
}
|
|
348
327
|
catch (e) {
|
|
349
328
|
const err = e;
|
|
@@ -351,9 +330,19 @@ function runJest(files, mode, cwd) {
|
|
|
351
330
|
// classification (A-SPEC-534.1) — survives a red run.
|
|
352
331
|
// @implements A-SPEC-577.1 — the names first, then jest's own summary from stderr. Without the
|
|
353
332
|
// first half this tail was the tail of a JSON document: it said how many failed and never which.
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
333
|
+
// @implements A-SPEC-466.3 — the names and the stderr are bounded apart, so a long stderr cannot push the names out
|
|
334
|
+
// @implements A-SPEC-128.11 — P3: a red full run is read from its report file too; with no report at all the unit
|
|
335
|
+
// ran nothing readable and is environment (a jest that could not start: a configuration error, a missing preset)
|
|
336
|
+
const report = mode === 'full' ? (0, test_reports_1.readJestReport)(reportFile, err.stdout ?? '') : (err.stdout ?? '');
|
|
337
|
+
// jest's own answer for a unit with no test writes no report: it ran nothing, read as such (the tests, not environment)
|
|
338
|
+
if (report === null && /^No tests found, exiting with code 1/m.test(err.stderr ?? '')) {
|
|
339
|
+
return { passed: false, tail: tailOf(err.stderr ?? '', 3), executed: {}, outcomes: {}, workers: applied, testsRun: 0 };
|
|
340
|
+
}
|
|
341
|
+
if (report === null)
|
|
342
|
+
return unreadable('jest --json', `${err.stderr ?? ''}\n${err.stdout ?? ''}\n${err.message ?? ''}`, applied);
|
|
343
|
+
const tail = redJestTail(report, err.stderr ?? err.message ?? '');
|
|
344
|
+
const executed = (0, test_reports_1.parseExecutedCounts)(report, cwd);
|
|
345
|
+
return { passed: false, tail, executed, outcomes: (0, test_reports_1.classifyJestOutcomes)(report, cwd), workers: applied, testsRun: casesRan(executed) };
|
|
357
346
|
}
|
|
358
347
|
}
|
|
359
348
|
/**
|
|
@@ -361,113 +350,28 @@ function runJest(files, mode, cwd) {
|
|
|
361
350
|
* Run specific jest files and return only their RED-first outcomes — the runner `test_run --mutate`
|
|
362
351
|
* injects into runKillsOnFile. Scoped, jest only (the classifier is jest-only), fail-soft to {}.
|
|
363
352
|
*/
|
|
364
|
-
function runJestOutcomes(files, cwd) {
|
|
353
|
+
function runJestOutcomes(files, cwd, timeoutMinutes) {
|
|
365
354
|
if (files.length === 0)
|
|
366
355
|
return {};
|
|
367
|
-
|
|
356
|
+
// @implements A-SPEC-466.6 — a mutation's jest child is a runner child of the run too
|
|
357
|
+
return withRunBudget(timeoutMinutes, () => runJest(files, 'scoped', cwd).outcomes);
|
|
368
358
|
}
|
|
369
359
|
/** Run the pytest half of a plan, taking execution evidence from pytest's built-in JUnit XML. */
|
|
370
360
|
// @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
|
-
}
|
|
361
|
+
// @implements A-SPEC-647 — its per-file outcome reader (parseJUnitXmlOutcomes) lives in review/test-reports
|
|
419
362
|
/**
|
|
420
363
|
* @implements A-SPEC-647
|
|
421
364
|
* The ecosystems a project's OWN test files belong to, by file-name convention, under a bounded walk
|
|
422
365
|
* 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
|
-
*
|
|
366
|
+
* the jest suite on a pytest-only project, ran nothing and reported passed:false.
|
|
367
|
+
* @implements A-SPEC-128.5 — configuration files name an ecosystem too (a pytest.ini, a go.mod), the root's are read
|
|
368
|
+
* even where the walk stops early, and the skipped trees a project vendors are its own declaration
|
|
369
|
+
* (`ax.config.json` testRun.excludeDirs), not a name built in here. This repository lists `reference`.
|
|
425
370
|
*/
|
|
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();
|
|
371
|
+
function detectProjectEcosystems(cwd, opts = {}) {
|
|
372
|
+
return (0, test_units_1.scanEcosystems)(cwd, opts).detected;
|
|
469
373
|
}
|
|
470
|
-
function runPytest(files, mode, cwd) {
|
|
374
|
+
function runPytest(files, mode, cwd, ignore = [], pythonFrom, run) {
|
|
471
375
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'holmes-pytest-'));
|
|
472
376
|
const report = path.join(dir, 'report.xml');
|
|
473
377
|
// `python3 -m pytest` rather than a bare `pytest`, so the interpreter on PATH decides which
|
|
@@ -482,24 +386,48 @@ function runPytest(files, mode, cwd) {
|
|
|
482
386
|
// @implements A-SPEC-502.1 — BUG-2, both halves: the interpreter resolves from pyvenv.cfg
|
|
483
387
|
// evidence (HOLMES_PYTHON above all, python3 fallback byte-identical to the old path), and a
|
|
484
388
|
// conftest.py argument widens to its directory instead of collection-ERRORing the whole run.
|
|
485
|
-
|
|
389
|
+
// @implements A-SPEC-128.9 — `-p no:cacheprovider`: a test run leaves no .pytest_cache in the project; E3: an excluded
|
|
390
|
+
// or ignored tree is not collected
|
|
391
|
+
// @implements A-SPEC-128.11 — P3: `--rootdir` is the unit, so a pytest.ini above the repository cannot move the
|
|
392
|
+
// report's file keys out of it (pt-rootdir-above)
|
|
393
|
+
const rootdir = fs.existsSync(cwd) ? (0, root_1.canonicalPath)(cwd) : cwd;
|
|
394
|
+
// @implements A-SPEC-128.13 — W2: the work tree's interpreter (a .venv is not in HEAD)
|
|
395
|
+
const python = (0, python_env_1.pythonFor)(pythonFrom && fs.existsSync(pythonFrom) ? pythonFrom : cwd, { env: process.env, exists: fs.existsSync, platform: process.platform });
|
|
396
|
+
// @implements A-SPEC-128.14, A-SPEC-128.15, A-SPEC-128.16 — in HEAD's worktree: the pinned configuration and its confcutdir,
|
|
397
|
+
// the environment asked where HEAD's names resolve (refused before any test), and the loaded-module record
|
|
398
|
+
const prov = run ? (0, run_provenance_1.pytestRunProvenance)(dir, run, rootdir, python, testEnv(), (c, a, o) => runBounded(c, a, { ...o, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER })) : null;
|
|
399
|
+
if (prov?.refused) {
|
|
400
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
401
|
+
return { passed: false, tail: prov.refused, executed: {}, outcomes: {}, testsRun: 0, environment: true };
|
|
402
|
+
}
|
|
403
|
+
const args = ['-m', 'pytest', '-q', '-p', 'no:cacheprovider', '-o', 'junit_family=xunit1', `--junit-xml=${report}`, `--rootdir=${rootdir}`, ...(prov?.args ?? []),
|
|
404
|
+
...(mode === 'full' ? [`--confcutdir=${prov?.confcutdir ?? rootdir}`, ...ignore.map((d) => `--ignore=${d.replace(/\/+$/, '')}`)] : []),
|
|
486
405
|
...(mode === 'scoped' ? ['--', ...(0, python_env_1.pytestTargets)(files)] : [])];
|
|
487
|
-
const
|
|
406
|
+
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
407
|
const read = () => {
|
|
489
408
|
try {
|
|
490
|
-
return parseJUnitXmlCounts(fs.readFileSync(report, 'utf8'));
|
|
409
|
+
return (0, test_reports_1.parseJUnitXmlCounts)(fs.readFileSync(report, 'utf8'));
|
|
491
410
|
}
|
|
492
411
|
catch {
|
|
493
412
|
return {};
|
|
494
413
|
}
|
|
495
414
|
};
|
|
415
|
+
// @implements A-SPEC-128.10 — I3: every file pytest collected, skipped ones included
|
|
416
|
+
const reported = () => {
|
|
417
|
+
try {
|
|
418
|
+
return (0, test_reports_1.parseJUnitXmlFiles)(fs.readFileSync(report, 'utf8'));
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
return [];
|
|
422
|
+
}
|
|
423
|
+
};
|
|
496
424
|
// @implements A-SPEC-647 — per-file outcomes from the same report; in a scoped run a planned file the
|
|
497
425
|
// failed run never reached (no case at all — a collection error before its cases) is a red-error, so a
|
|
498
426
|
// RED that never ran is not mistaken for evidence of nothing.
|
|
499
427
|
const readOutcomes = (passed) => {
|
|
500
428
|
let outcomes = {};
|
|
501
429
|
try {
|
|
502
|
-
outcomes = parseJUnitXmlOutcomes(fs.readFileSync(report, 'utf8'));
|
|
430
|
+
outcomes = (0, test_reports_1.parseJUnitXmlOutcomes)(fs.readFileSync(report, 'utf8'));
|
|
503
431
|
}
|
|
504
432
|
catch {
|
|
505
433
|
outcomes = {};
|
|
@@ -518,13 +446,18 @@ function runPytest(files, mode, cwd) {
|
|
|
518
446
|
// @implements A-SPEC-651.1 — launch from the canonical spelling: pytest keys its JUnit `file`
|
|
519
447
|
// attribute relative to its rootdir, and an 8.3 invocation dir made that key climb out of the
|
|
520
448
|
// 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:
|
|
522
|
-
|
|
449
|
+
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(testEnv()) : testEnv() });
|
|
450
|
+
const executed = read();
|
|
451
|
+
// @implements A-SPEC-128.13 — T1: exit 0 is not green when the JUnit report holds a failure or an error
|
|
452
|
+
const outcomes = readOutcomes(true);
|
|
453
|
+
const red = Object.values(outcomes).some((o) => o !== 'green');
|
|
454
|
+
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
455
|
}
|
|
524
456
|
catch (e) {
|
|
525
457
|
const err = e;
|
|
526
458
|
// A red pytest run still writes the XML, so execution evidence survives — same property as jest.
|
|
527
|
-
|
|
459
|
+
const executed = read();
|
|
460
|
+
return judged({ passed: false, tail: tailOf(`${err.stdout ?? ''}\n${err.stderr ?? err.message ?? ''}`), executed, outcomes: readOutcomes(false), testsRun: casesRan(executed), reported: reported() });
|
|
528
461
|
}
|
|
529
462
|
finally {
|
|
530
463
|
try {
|
|
@@ -573,7 +506,7 @@ function runCargo(files, _mode, cwd, opts) {
|
|
|
573
506
|
let out = '';
|
|
574
507
|
let ok = true;
|
|
575
508
|
try {
|
|
576
|
-
out = runBounded('cargo', ['test'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: (
|
|
509
|
+
out = runBounded('cargo', ['test'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: testEnv() });
|
|
577
510
|
}
|
|
578
511
|
catch (e) {
|
|
579
512
|
const err = e;
|
|
@@ -586,7 +519,8 @@ function runCargo(files, _mode, cwd, opts) {
|
|
|
586
519
|
executed[f] = count; // crate-granular
|
|
587
520
|
// Executing nothing is not a pass, mirroring no-passWithNoTests.
|
|
588
521
|
const passed = ok && count > 0;
|
|
589
|
-
|
|
522
|
+
// @implements A-SPEC-128.5 — the crate's count once, whatever the per-file credit (a full run credits no file)
|
|
523
|
+
return { passed, tail: `[rust] cargo test: ${count} executed`, executed, testsRun: count };
|
|
590
524
|
}
|
|
591
525
|
/** Read every JUnit XML report under a directory (recursively) and sum their counts for `ext`. */
|
|
592
526
|
function readJUnitReports(dir, ext) {
|
|
@@ -605,7 +539,7 @@ function readJUnitReports(dir, ext) {
|
|
|
605
539
|
walk(p);
|
|
606
540
|
else if (e.name.endsWith('.xml')) {
|
|
607
541
|
try {
|
|
608
|
-
const counts = parseJUnitXmlCounts(fs.readFileSync(p, 'utf8'), ext);
|
|
542
|
+
const counts = (0, test_reports_1.parseJUnitXmlCounts)(fs.readFileSync(p, 'utf8'), ext);
|
|
609
543
|
for (const [k, v] of Object.entries(counts))
|
|
610
544
|
acc[k] = (acc[k] ?? 0) + v;
|
|
611
545
|
}
|
|
@@ -666,14 +600,17 @@ function runGradle(files, _mode, cwd, opts) {
|
|
|
666
600
|
}
|
|
667
601
|
let ok = true;
|
|
668
602
|
try {
|
|
669
|
-
runBounded(cmd, args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: (
|
|
603
|
+
runBounded(cmd, args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: testEnv() });
|
|
604
|
+
}
|
|
605
|
+
catch (e) {
|
|
606
|
+
// @implements A-SPEC-128.10 — R4: the build tool itself missing is the environment, not the tests
|
|
607
|
+
if (e.code === 'ENOENT')
|
|
608
|
+
return { passed: false, tail: `${cmd} not found on PATH — cannot execute Java tests`, executed: {}, unsupported: files };
|
|
609
|
+
ok = false; // a failing test run still wrote the JUnit XML
|
|
670
610
|
}
|
|
671
|
-
catch {
|
|
672
|
-
ok = false;
|
|
673
|
-
} // a failing test run still wrote the JUnit XML
|
|
674
611
|
const executed = readJUnitReports(path.join(cwd, reportDir), 'java');
|
|
675
612
|
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 };
|
|
613
|
+
return { passed: ok && total > 0, tail: `[java] ${cmd} ${args.join(' ')}: ${total} executed`, executed, testsRun: total };
|
|
677
614
|
}
|
|
678
615
|
/**
|
|
679
616
|
* @implements A-SPEC-137.3
|
|
@@ -698,14 +635,14 @@ function runDotnet(files, _mode, cwd, opts) {
|
|
|
698
635
|
const report = path.join(dir, 'junit.xml');
|
|
699
636
|
let ok = true;
|
|
700
637
|
try {
|
|
701
|
-
runBounded('dotnet', ['test', '--logger', `junit;LogFilePath=${report}`], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: (
|
|
638
|
+
runBounded('dotnet', ['test', '--logger', `junit;LogFilePath=${report}`], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: testEnv() });
|
|
702
639
|
}
|
|
703
640
|
catch {
|
|
704
641
|
ok = false;
|
|
705
642
|
}
|
|
706
643
|
let executed = {};
|
|
707
644
|
try {
|
|
708
|
-
executed = parseJUnitXmlCounts(fs.readFileSync(report, 'utf8'), 'cs');
|
|
645
|
+
executed = (0, test_reports_1.parseJUnitXmlCounts)(fs.readFileSync(report, 'utf8'), 'cs');
|
|
709
646
|
}
|
|
710
647
|
catch { /* no report */ }
|
|
711
648
|
try {
|
|
@@ -713,7 +650,7 @@ function runDotnet(files, _mode, cwd, opts) {
|
|
|
713
650
|
}
|
|
714
651
|
catch { /* best effort */ }
|
|
715
652
|
const total = Object.values(executed).reduce((a, b) => a + b, 0);
|
|
716
|
-
return { passed: ok && total > 0, tail: `[dotnet] dotnet test: ${total} executed`, executed };
|
|
653
|
+
return { passed: ok && total > 0, tail: `[dotnet] dotnet test: ${total} executed`, executed, testsRun: total };
|
|
717
654
|
}
|
|
718
655
|
/**
|
|
719
656
|
* @implements A-SPEC-137.1
|
|
@@ -723,6 +660,7 @@ function runDotnet(files, _mode, cwd, opts) {
|
|
|
723
660
|
* `unsupported`, never a pass. `opts.goPresent` overrides the probe for testing.
|
|
724
661
|
*/
|
|
725
662
|
function runGo(files, mode, cwd, opts) {
|
|
663
|
+
const goEnv = { ...testEnv(), ...(opts?.env ?? {}) };
|
|
726
664
|
const present = opts?.goPresent ?? (() => {
|
|
727
665
|
try {
|
|
728
666
|
(0, node_child_process_1.execFileSync)('go', ['version'], { cwd, stdio: 'ignore', timeout: PROBE_TIMEOUT_MS });
|
|
@@ -742,10 +680,10 @@ function runGo(files, mode, cwd, opts) {
|
|
|
742
680
|
const tails = [];
|
|
743
681
|
let passed = true;
|
|
744
682
|
let anyExecuted = 0;
|
|
745
|
-
const runDir = (dirArg, creditFiles) => {
|
|
683
|
+
const runDir = (dirArg, creditFiles, onOutput) => {
|
|
746
684
|
let out = '';
|
|
747
685
|
try {
|
|
748
|
-
out = runBounded('go', ['test', '-json', dirArg], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env:
|
|
686
|
+
out = runBounded('go', ['test', '-json', dirArg], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: goEnv });
|
|
749
687
|
}
|
|
750
688
|
catch (e) {
|
|
751
689
|
const err = e;
|
|
@@ -753,15 +691,63 @@ function runGo(files, mode, cwd, opts) {
|
|
|
753
691
|
tails.push(err.stderr ? tailOf(err.stderr, 2) : (err.message ?? 'go test failed'));
|
|
754
692
|
passed = false;
|
|
755
693
|
}
|
|
756
|
-
|
|
694
|
+
// @implements A-SPEC-128.13 — T1: a named test's fail event is red whatever the exit code (TestMain's os.Exit(0))
|
|
695
|
+
const failedTests = (0, test_reports_1.goFailedTests)(out);
|
|
696
|
+
if (failedTests.length > 0) {
|
|
697
|
+
passed = false;
|
|
698
|
+
tails.push(`[go] failed: ${failedTests.slice(0, 5).join(', ')}`);
|
|
699
|
+
}
|
|
700
|
+
const perPkg = (0, test_reports_1.parseGoTestJson)(out);
|
|
757
701
|
const dirCount = Object.values(perPkg).reduce((a, b) => a + b, 0);
|
|
758
702
|
anyExecuted += dirCount;
|
|
759
703
|
for (const f of creditFiles)
|
|
760
704
|
executed[f] = (executed[f] ?? 0) + dirCount; // package-granular
|
|
705
|
+
if (onOutput)
|
|
706
|
+
onOutput(out);
|
|
761
707
|
tails.push(`[go] ${dirArg}: ${dirCount} executed`);
|
|
762
708
|
};
|
|
763
709
|
if (mode === 'full') {
|
|
764
|
-
|
|
710
|
+
// @implements A-SPEC-128.9 — E3: the module's packages minus the excluded or ignored trees
|
|
711
|
+
// @implements A-SPEC-128.10 — I3 at package granularity: each package's count is credited to its _test.go files, so a
|
|
712
|
+
// package whose tests did not run leaves its files unreported
|
|
713
|
+
let pkgs = [];
|
|
714
|
+
const base = fs.existsSync(cwd) ? (0, root_1.canonicalPath)(cwd) : cwd;
|
|
715
|
+
try {
|
|
716
|
+
pkgs = runBounded('go', ['list', '-f', '{{.ImportPath}}\t{{.Dir}}', './...'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: RUNNER_MAX_BUFFER, env: goEnv })
|
|
717
|
+
.split('\n').map((l) => l.trim()).filter(Boolean)
|
|
718
|
+
.map((l) => { const [importPath, dir] = l.split('\t'); return { importPath, rel: path.relative(base, (0, root_1.canonicalPath)(dir ?? base)).split(path.sep).join('/') }; });
|
|
719
|
+
}
|
|
720
|
+
catch {
|
|
721
|
+
pkgs = [];
|
|
722
|
+
}
|
|
723
|
+
const skip = (opts?.ignore ?? []).map((x) => x.replace(/\/+$/, ''));
|
|
724
|
+
const kept = pkgs.filter((p) => !skip.some((x) => p.rel === x || p.rel.startsWith(`${x}/`)));
|
|
725
|
+
const before = new Map();
|
|
726
|
+
const credit = (out) => {
|
|
727
|
+
const perPkg = (0, test_reports_1.parseGoTestJson)(out);
|
|
728
|
+
const seen = (0, test_reports_1.goPackagesWithTestEvents)(out);
|
|
729
|
+
for (const p of kept) {
|
|
730
|
+
const n = perPkg[p.importPath] ?? 0;
|
|
731
|
+
// @implements A-SPEC-128.11 — P5: a package whose tests all skipped ran them (go-skip); the count stays pass/fail
|
|
732
|
+
if (!seen.has(p.importPath) || before.has(p.importPath))
|
|
733
|
+
continue;
|
|
734
|
+
before.set(p.importPath, n);
|
|
735
|
+
let names = [];
|
|
736
|
+
try {
|
|
737
|
+
names = fs.readdirSync(path.join(base, p.rel)).filter((f) => f.endsWith('_test.go'));
|
|
738
|
+
}
|
|
739
|
+
catch {
|
|
740
|
+
names = [];
|
|
741
|
+
}
|
|
742
|
+
for (const f of names)
|
|
743
|
+
executed[p.rel === '' ? f : `${p.rel}/${f}`] = n;
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
if (skip.length === 0)
|
|
747
|
+
runDir('./...', [], credit);
|
|
748
|
+
else
|
|
749
|
+
for (const k of kept)
|
|
750
|
+
runDir(k.rel === '' ? '.' : `./${k.rel}`, [], credit);
|
|
765
751
|
}
|
|
766
752
|
else {
|
|
767
753
|
const byDir = new Map();
|
|
@@ -778,7 +764,8 @@ function runGo(files, mode, cwd, opts) {
|
|
|
778
764
|
// A run that executed NOTHING is not a pass — the same no-passWithNoTests rule jest/pytest hold.
|
|
779
765
|
if (anyExecuted === 0)
|
|
780
766
|
passed = false;
|
|
781
|
-
|
|
767
|
+
// @implements A-SPEC-128.5 — a full module run credits no file but its tests ran: the count rides apart from the credit
|
|
768
|
+
return { passed, tail: tails.join('\n'), executed, testsRun: anyExecuted };
|
|
782
769
|
}
|
|
783
770
|
/**
|
|
784
771
|
* Execute a plan (I/O). Deterministic inputs → deterministic command; the pass/fail is the suite's.
|
|
@@ -789,59 +776,242 @@ function runGo(files, mode, cwd, opts) {
|
|
|
789
776
|
* ecosystem has no adapter are returned in `unsupported` — never dropped quietly, because a scoped
|
|
790
777
|
* gate that ran part of its scope has verified less than it reports.
|
|
791
778
|
*/
|
|
792
|
-
function runTestScope(scope, cwd) {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
779
|
+
function runTestScope(scope, cwd, opts = {}) {
|
|
780
|
+
// @implements A-SPEC-794.119 — held for this run only, put back after (a nested or later run is not given this tree)
|
|
781
|
+
const prevRoot = RUN_PROJECT_ROOT;
|
|
782
|
+
RUN_PROJECT_ROOT = opts.projectRoot;
|
|
783
|
+
try {
|
|
784
|
+
return withRunBudget(opts.timeoutMinutes, () => runScopeWithinBudget(scope, cwd, opts));
|
|
796
785
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
786
|
+
finally {
|
|
787
|
+
RUN_PROJECT_ROOT = prevRoot;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
/** @implements A-SPEC-466.6 — each runner child started inside `fn` takes the budget; the default comes back after. */
|
|
791
|
+
function withRunBudget(timeoutMinutes, fn) {
|
|
792
|
+
RUN_BUDGET_MS = (timeoutMinutes ?? exports.RUNNER_TIMEOUT_MS / 60_000) * 60_000;
|
|
793
|
+
try {
|
|
794
|
+
return fn();
|
|
795
|
+
}
|
|
796
|
+
finally {
|
|
797
|
+
RUN_BUDGET_MS = exports.RUNNER_TIMEOUT_MS;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* @implements A-SPEC-128.4 — which ecosystem groups a plan runs. A scoped plan groups its own files. A full plan runs
|
|
802
|
+
* every ecosystem the PROJECT has, together with those of the impacted test files: detecting from the impacted files
|
|
803
|
+
* alone let a full run of a jest+pytest project skip pytest and still record `mode: full` (review 2026-11-05, A H1).
|
|
804
|
+
* Jest is assumed only when the project shows no ecosystem at all, and the run says so.
|
|
805
|
+
*/
|
|
806
|
+
function runEcosystems(scope, plan, cwd, opts = {}) {
|
|
802
807
|
const groups = new Map();
|
|
803
808
|
const unsupported = [];
|
|
804
|
-
|
|
809
|
+
const notRun = [];
|
|
810
|
+
if (plan.mode !== 'full') {
|
|
811
|
+
for (const f of plan.testFiles) {
|
|
812
|
+
const eco = ecosystemOf(f);
|
|
813
|
+
if (!eco) {
|
|
814
|
+
unsupported.push(f);
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
groups.set(eco, [...(groups.get(eco) ?? []), f]);
|
|
818
|
+
}
|
|
819
|
+
const units = [...groups.entries()].map(([ecosystem, files]) => ({ ecosystem, dir: '', ignore: [], files }));
|
|
820
|
+
return { groups, units, unsupported, assumedJest: false, detected: [], detectedBy: {}, notRun, notDetected: [],
|
|
821
|
+
implementationCount: 0, implementationSample: [], notTests: [], expected: {}, codeRoots: [], buildRoots: [], sparseTests: [], outsideSurface: [], testFiles: [], notBuilt: [] };
|
|
822
|
+
}
|
|
823
|
+
// @implements A-SPEC-647 — run what the project HAS; @implements A-SPEC-128.4 — always, not only with no impacted file
|
|
824
|
+
// @implements A-SPEC-128.7 — I1: an impacted test file of an ecosystem with no unit is named in notRun, never run
|
|
825
|
+
// @implements A-SPEC-128.9 — E1: what runs is the project's execution units, each where its build root is
|
|
826
|
+
const scan = (0, test_units_1.scanEcosystems)(cwd, opts);
|
|
827
|
+
// @implements A-SPEC-128.12 — S1: only jest, pytest and go units run; the others are named outside the surface
|
|
828
|
+
const units = scan.units.filter((u) => SUPPORTED.has(u.ecosystem)).map((u) => ({ ...u, files: [] }));
|
|
829
|
+
let assumedJest = false;
|
|
830
|
+
// @implements A-SPEC-128.8 — jest is assumed only beside a root package.json (A M1);
|
|
831
|
+
// @implements A-SPEC-128.9 — and only where there is code to test (E2): nothing testable runs nothing
|
|
832
|
+
if (units.length === 0 && scan.implementationCount > 0 && fs.existsSync(path.join(cwd, 'package.json'))) {
|
|
833
|
+
units.push({ ecosystem: 'jest', dir: '', ignore: scan.excluded, files: [] });
|
|
834
|
+
assumedJest = true;
|
|
835
|
+
}
|
|
836
|
+
for (const u of units)
|
|
837
|
+
groups.set(u.ecosystem, []);
|
|
838
|
+
for (const f of scope.impactedTestFiles) {
|
|
805
839
|
const eco = ecosystemOf(f);
|
|
806
840
|
if (!eco) {
|
|
807
841
|
unsupported.push(f);
|
|
808
842
|
continue;
|
|
809
843
|
}
|
|
810
|
-
|
|
811
|
-
|
|
844
|
+
if (groups.has(eco) || notRun.some((n) => n.ecosystem === eco))
|
|
845
|
+
continue;
|
|
846
|
+
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
847
|
}
|
|
813
|
-
// A
|
|
814
|
-
//
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
848
|
+
// @implements A-SPEC-128.13 — T4: a go unit expects only the _test.go files go builds here (go list, no tags); the rest
|
|
849
|
+
// are named in notBuilt and never refused (a red behind a build tag is a named limit)
|
|
850
|
+
const expected = { ...scan.expected };
|
|
851
|
+
const notBuilt = [];
|
|
852
|
+
for (const u of units.filter((x) => x.ecosystem === 'go')) {
|
|
853
|
+
const key = `go@${u.dir}`;
|
|
854
|
+
const listed = (0, test_units_2.goListTests)(cwd, u.dir);
|
|
855
|
+
if (listed === null || !expected[key])
|
|
856
|
+
continue;
|
|
857
|
+
for (const f of expected[key])
|
|
858
|
+
if (!listed.built.has(f))
|
|
859
|
+
notBuilt.push(f);
|
|
860
|
+
expected[key] = expected[key].filter((f) => listed.built.has(f));
|
|
861
|
+
}
|
|
862
|
+
return { groups, units, unsupported, assumedJest, detected: scan.detected, detectedBy: scan.detectedBy, notRun, notDetected: scan.notDetected,
|
|
863
|
+
implementationCount: scan.implementationCount, implementationSample: scan.implementationSample, notTests: scan.notTests,
|
|
864
|
+
expected, codeRoots: scan.codeRoots, buildRoots: scan.buildRoots, sparseTests: scan.sparseTests,
|
|
865
|
+
outsideSurface: scan.outsideSurface, testFiles: scan.testFiles, notBuilt: notBuilt.sort() };
|
|
866
|
+
}
|
|
867
|
+
const SUPPORTED = new Set(['jest', 'pytest', 'go']);
|
|
868
|
+
/**
|
|
869
|
+
* @implements A-SPEC-128.10 — I3 and R2, judged AFTER the run from what the runners reported: the expected test files
|
|
870
|
+
* a unit did not report (a runner configuration, a root narrower than the tree, a package that ran nothing), and the
|
|
871
|
+
* build roots whose code saw no executed test. Units that could not run (environment, stop) are judged elsewhere.
|
|
872
|
+
*/
|
|
873
|
+
function coverageAfterRun(expected, codeRoots, reported, executedByFile, skipUnits, buildRoots = [], testFiles) {
|
|
874
|
+
const notExecuted = [];
|
|
875
|
+
for (const [unit, files] of Object.entries(expected)) {
|
|
876
|
+
if (skipUnits.has(unit))
|
|
877
|
+
continue;
|
|
878
|
+
for (const f of files)
|
|
879
|
+
if (!reported.has(f))
|
|
880
|
+
notExecuted.push(f);
|
|
881
|
+
}
|
|
882
|
+
// @implements A-SPEC-128.12 — S5 (repairs 128.11 P2): a root's code is tested only by an executed test file whose OWN
|
|
883
|
+
// nearest build root is that root; that a unit ran is not evidence (root-unit-credit, ws-root-credit)
|
|
884
|
+
const roots = new Set(buildRoots);
|
|
885
|
+
const nearestRoot = (rel) => {
|
|
886
|
+
const parts = rel.split('/').slice(0, -1);
|
|
887
|
+
for (let i = parts.length; i > 0; i--) {
|
|
888
|
+
const d = parts.slice(0, i).join('/');
|
|
889
|
+
if (roots.has(d))
|
|
890
|
+
return d;
|
|
825
891
|
}
|
|
892
|
+
return '';
|
|
893
|
+
};
|
|
894
|
+
// @implements A-SPEC-128.13 — T3: only an executed test file of the scanned universe credits code (a test outside the
|
|
895
|
+
// repository or outside the scan credits nothing); when no universe is given, every executed file counts (scoped)
|
|
896
|
+
const universe = testFiles ? new Set(testFiles) : null;
|
|
897
|
+
const testedRoots = new Set();
|
|
898
|
+
for (const [f, n] of Object.entries(executedByFile))
|
|
899
|
+
if (n > 0 && (universe === null || universe.has(f)))
|
|
900
|
+
testedRoots.add(nearestRoot(f));
|
|
901
|
+
const tested = (root) => testedRoots.has(root);
|
|
902
|
+
const testsAt = (root) => (testFiles ?? []).filter((f) => nearestRoot(f) === root).length;
|
|
903
|
+
const untestedCode = codeRoots.filter((g) => !tested(g.root))
|
|
904
|
+
.map((g) => ({ root: g.root, sample: g.sample, ...(g.missingBuildFile ? { missingBuildFile: g.missingBuildFile } : {}), ...(testsAt(g.root) > 0 ? { testFiles: testsAt(g.root) } : {}) }));
|
|
905
|
+
return { notExecuted: notExecuted.sort(), untestedCode };
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* @implements A-SPEC-128.9 — E4: why a unit that ran nothing failed, when the cause is its environment, not its tests: a
|
|
909
|
+
* missing runner. Null when the unit executed a test or failed for any other reason (then it is the tests).
|
|
910
|
+
*/
|
|
911
|
+
function environmentReason(r, counted) {
|
|
912
|
+
// @implements A-SPEC-128.12 — an adapter that says environment is believed even when tests ran (jest projects, a
|
|
913
|
+
// configuration jest cannot print: the run executed, but it is not 0.40.x evidence)
|
|
914
|
+
if (r.environment === true)
|
|
915
|
+
return firstLine(r.tail);
|
|
916
|
+
if (r.passed || counted > 0)
|
|
917
|
+
return null;
|
|
918
|
+
if ((r.unsupported?.length ?? 0) > 0)
|
|
919
|
+
return firstLine(r.tail);
|
|
920
|
+
// @implements A-SPEC-128.10 — R4: only the RUNNER being absent; an ENOENT inside a test, or a module a test imports,
|
|
921
|
+
// is the tests (review 10:51, A H4 / A M4)
|
|
922
|
+
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);
|
|
923
|
+
return m ? m[0] : null;
|
|
924
|
+
}
|
|
925
|
+
// @implements A-SPEC-128.12 — S2/S6: withoutExcluded (a unit's report without its excluded trees) lives in test-reports
|
|
926
|
+
function firstLine(s) {
|
|
927
|
+
return (s.split('\n').find((l) => l.trim() !== '') ?? s).trim().slice(0, 200);
|
|
928
|
+
}
|
|
929
|
+
function runScopeWithinBudget(scope, cwd, opts) {
|
|
930
|
+
const plan = planTestRun(scope);
|
|
931
|
+
if (plan.mode === 'noop') {
|
|
932
|
+
return { tier: scope.tier, mode: 'noop', ranFiles: [], passed: true, skipped: true, tail: plan.reason, workers: null };
|
|
826
933
|
}
|
|
827
|
-
|
|
828
|
-
|
|
934
|
+
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 });
|
|
935
|
+
// @implements A-SPEC-128.7 — what a full plan detected, left out and did not run travels with the result
|
|
936
|
+
// @implements A-SPEC-128.9 — with the implementation count E2 reads and the test-named files that hold no test
|
|
937
|
+
// @implements A-SPEC-128.13 — and the test-file count E2 also needs, and the go files this platform does not build
|
|
938
|
+
const named = plan.mode === 'full'
|
|
939
|
+
? { detectedBy, implementationCount, implementationSample, testFileCount: testFiles.length, ...(notRun.length ? { notRun } : {}),
|
|
940
|
+
...(notDetected.length ? { notDetected } : {}), ...(notTests.length ? { notTests } : {}), ...(notBuilt.length ? { notBuilt } : {}) } : {};
|
|
941
|
+
// @implements A-SPEC-128.12 — S1, S2, S3: outside the surface, one message, environment
|
|
942
|
+
// @implements A-SPEC-128.13 — W3: the work-tree rule is gone (a full run is HEAD's worktree); a configuration known to
|
|
943
|
+
// be outside the surface before the run starts no unit (B M2)
|
|
944
|
+
const surface = plan.mode !== 'full' ? [] : outsideSurface.map((o) => ({ ecosystem: o.ecosystem, dir: o.dir, reason: `${exports.UNSUPPORTED}: ${o.reason}` }));
|
|
945
|
+
if (units.length > 0 && surface.length === 0) {
|
|
946
|
+
const reported = new Set(); // @implements A-SPEC-128.10 — I3: every file a runner said it ran or collected
|
|
947
|
+
const skipUnits = new Set(); // units that could not run: their coverage is not the comparison's to judge
|
|
948
|
+
const runners = {
|
|
949
|
+
jest: (f, m, c) => (m === 'full' && jestEntry(c) === null
|
|
950
|
+
? { passed: false, tail: `jest is not installed for this unit (no local node_modules/jest from ${c})`, executed: {}, workers: null, environment: true }
|
|
951
|
+
: runJest(f, m, c, opts)),
|
|
952
|
+
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),
|
|
953
|
+
go: (f, m, c, ignore) => runGo(f, m, c, { ignore, env: (0, test_units_2.goWorkEnv)(cwd) }),
|
|
954
|
+
rust: (f, m, c) => runCargo(f, m, c), java: (f, m, c) => runGradle(f, m, c), dotnet: (f, m, c) => runDotnet(f, m, c),
|
|
955
|
+
};
|
|
829
956
|
const ran = [];
|
|
830
957
|
let passed = true;
|
|
831
958
|
const tails = [];
|
|
832
959
|
const executedByFile = {};
|
|
833
960
|
const outcomeByFile = {}; // @implements A-SPEC-534.5 — jest only
|
|
834
|
-
|
|
961
|
+
let workers = null; // @implements A-SPEC-466.2 — what the jest adapter placed on its argv
|
|
962
|
+
let testsRun = 0; // @implements A-SPEC-128.5
|
|
963
|
+
const testsRunBy = {}; // @implements A-SPEC-128.6 — per ecosystem, so none hides behind another
|
|
964
|
+
let stopped = false;
|
|
965
|
+
const failedBy = []; // @implements A-SPEC-128.7 — which runner was red, so a refusal can name its tree
|
|
966
|
+
const unitResults = []; // @implements A-SPEC-128.9 — per unit: every unit must run a test
|
|
967
|
+
const environment = [];
|
|
968
|
+
const keyed = (dir, rec) => (dir === '' ? rec : Object.fromEntries(Object.entries(rec).map(([k, v]) => [`${dir}/${k}`, v])));
|
|
969
|
+
for (const u of [...units].sort((a, b) => (a.ecosystem === b.ecosystem ? a.dir.localeCompare(b.dir) : a.ecosystem.localeCompare(b.ecosystem)))) {
|
|
970
|
+
const eco = u.ecosystem;
|
|
835
971
|
STOPPED = null;
|
|
836
972
|
LEFTOVER = null;
|
|
837
|
-
const
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
973
|
+
const unitCwd = u.dir === '' ? cwd : path.join(cwd, u.dir);
|
|
974
|
+
const raw = runners[eco](u.files, plan.mode, unitCwd, u.ignore);
|
|
975
|
+
// @implements A-SPEC-128.12 — S2/S6: exclusions judged after the run. A reported test under an excluded tree leaves
|
|
976
|
+
// the judgement and the counts; one that ran red is environment, named — never hidden
|
|
977
|
+
const { r, excludedRed } = plan.mode === 'full' ? (0, test_reports_1.withoutExcluded)(raw, u.ignore, u.dir) : { r: raw, excludedRed: [] };
|
|
978
|
+
if (eco === 'jest' && workers === null)
|
|
979
|
+
workers = r.workers ?? null;
|
|
980
|
+
if (!ran.includes(eco))
|
|
981
|
+
ran.push(eco);
|
|
982
|
+
passed = passed && r.passed && STOPPED === null && excludedRed.length === 0;
|
|
983
|
+
stopped = stopped || STOPPED !== null;
|
|
984
|
+
if ((!r.passed || STOPPED !== null) && !failedBy.includes(eco))
|
|
985
|
+
failedBy.push(eco);
|
|
986
|
+
// @implements A-SPEC-128.5 — an adapter that counts apart from its credit says so; jest and pytest credit every test
|
|
987
|
+
const own = r.testsRun;
|
|
988
|
+
// @implements A-SPEC-128.6 — every adapter counts for itself; one that does not reports 0, never a guess
|
|
989
|
+
const counted = typeof own === 'number' ? own : 0;
|
|
990
|
+
testsRunBy[eco] = (testsRunBy[eco] ?? 0) + counted;
|
|
991
|
+
testsRun += counted;
|
|
992
|
+
// @implements A-SPEC-128.13 — T3: a test the runner reported from outside the repository (roots or testpaths that
|
|
993
|
+
// leave it) is named, never credited; A-SPEC-128.14 — judged from the repository root (`../shared` from backend is inside)
|
|
994
|
+
const outside = Object.keys(r.executed).filter((k) => path.isAbsolute(k) || path.posix.normalize(u.dir === '' ? k : `${u.dir}/${k}`).startsWith('../'));
|
|
995
|
+
// every reason is kept: a jest projects configuration whose excluded tree also ran red names both
|
|
996
|
+
const reasons = STOPPED !== null ? [] : [environmentReason(r, counted),
|
|
997
|
+
excludedRed.length > 0 ? `제외한 트리의 시험이 실행됨 — 러너 설정에서도 빼야 함: ${excludedRed.slice(0, 5).join(', ')}` : null,
|
|
998
|
+
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);
|
|
999
|
+
if (outside.length > 0)
|
|
1000
|
+
passed = false;
|
|
1001
|
+
for (const reason of reasons)
|
|
1002
|
+
environment.push({ ecosystem: eco, dir: u.dir, reason });
|
|
1003
|
+
const env = reasons.length > 0 ? reasons.join(' | ') : null;
|
|
1004
|
+
unitResults.push({ ecosystem: eco, dir: u.dir, testsRun: counted, passed: r.passed && STOPPED === null, ...(env !== null ? { environment: env } : {}) });
|
|
1005
|
+
const label = u.dir === '' ? eco : `${eco} @ ${u.dir}`;
|
|
1006
|
+
tails.push(`[${label}] ${r.tail}${STOPPED !== null ? `\n${STOPPED}` : ''}${LEFTOVER !== null ? `\n${LEFTOVER}` : ''}`);
|
|
1007
|
+
Object.assign(executedByFile, keyed(u.dir, r.executed));
|
|
1008
|
+
for (const f of [...Object.keys(r.executed), ...(r.reported ?? [])])
|
|
1009
|
+
reported.add(u.dir === '' ? f : `${u.dir}/${f}`);
|
|
1010
|
+
if (env !== null || STOPPED !== null)
|
|
1011
|
+
skipUnits.add(`${eco}@${u.dir}`);
|
|
842
1012
|
const adapterOutcomes = r.outcomes;
|
|
843
1013
|
if (adapterOutcomes)
|
|
844
|
-
Object.assign(outcomeByFile, adapterOutcomes);
|
|
1014
|
+
Object.assign(outcomeByFile, keyed(u.dir, adapterOutcomes));
|
|
845
1015
|
// @implements A-SPEC-137.1 — an adapter whose toolchain is absent reports its files as
|
|
846
1016
|
// unsupported; merge them so a scope that could not run them never reads as fully covered.
|
|
847
1017
|
const adapterUnsupported = r.unsupported;
|
|
@@ -849,14 +1019,30 @@ function runTestScope(scope, cwd) {
|
|
|
849
1019
|
unsupported.push(...adapterUnsupported);
|
|
850
1020
|
}
|
|
851
1021
|
if (assumedJest) {
|
|
852
|
-
tails.push('[assumption] full run
|
|
1022
|
+
tails.push('[assumption] full run found no test ecosystem in the project — defaulted to the jest suite');
|
|
853
1023
|
}
|
|
854
1024
|
if (unsupported.length) {
|
|
855
1025
|
tails.push(`[unsupported] ${unsupported.length} test file(s) have no runner adapter: ${unsupported.slice(0, 5).join(', ')}`);
|
|
856
1026
|
}
|
|
1027
|
+
// @implements A-SPEC-128.11 — P6: tests a sparse checkout left out of the work tree cannot run here
|
|
1028
|
+
if (plan.mode === 'full' && sparseTests.length > 0) {
|
|
1029
|
+
passed = false;
|
|
1030
|
+
environment.push({ ecosystem: 'git', dir: '', reason: `sparse checkout — 증빙할 수 없음: ${sparseTests.length} test file(s) outside the work tree, e.g. ${sparseTests.slice(0, 3).join(', ')}` });
|
|
1031
|
+
tails.push(`[sparse] ${sparseTests.length} test file(s) are not in the work tree (skip-worktree): ${sparseTests.slice(0, 5).join(', ')}`);
|
|
1032
|
+
}
|
|
1033
|
+
// @implements A-SPEC-128.10 — I3 and R2, after the run
|
|
1034
|
+
const coverage = plan.mode === 'full' ? coverageAfterRun(expected, codeRoots, reported, executedByFile, skipUnits, buildRoots, testFiles) : null;
|
|
1035
|
+
if (coverage?.notExecuted.length)
|
|
1036
|
+
tails.push(`[not run] ${coverage.notExecuted.length} detected test file(s) did not run: ${coverage.notExecuted.slice(0, 5).join(', ')}`);
|
|
1037
|
+
if (coverage?.untestedCode.length)
|
|
1038
|
+
tails.push(`[untested] code with no executed test under: ${coverage.untestedCode.map((g) => g.root || '(root)').join(', ')}`);
|
|
857
1039
|
return {
|
|
858
1040
|
tier: scope.tier, mode: plan.mode, ranFiles: plan.testFiles, passed, skipped: false,
|
|
859
|
-
tail: tails.join('\n'), executedByFile, ranWith: ran,
|
|
1041
|
+
tail: tails.join('\n'), executedByFile, ranWith: ran, workers, testsRun, testsRunBy, stopped, detected, failedBy, ...named,
|
|
1042
|
+
...(plan.mode === 'full' ? { units: unitResults } : {}), ...(environment.length ? { environment } : {}),
|
|
1043
|
+
...(coverage?.notExecuted.length ? { notExecuted: coverage.notExecuted.slice(0, 200) } : {}),
|
|
1044
|
+
...(coverage?.untestedCode.length ? { untestedCode: coverage.untestedCode } : {}),
|
|
1045
|
+
workersIgnoredBy: opts.workers === undefined ? [] : ran.filter((eco) => eco !== 'jest'),
|
|
860
1046
|
...(Object.keys(outcomeByFile).length ? { outcomeByFile } : {}),
|
|
861
1047
|
...(unsupported.length ? { unsupported } : {}),
|
|
862
1048
|
};
|
|
@@ -866,8 +1052,15 @@ function runTestScope(scope, cwd) {
|
|
|
866
1052
|
// the no-passWithNoTests rule exists to prevent.
|
|
867
1053
|
return {
|
|
868
1054
|
tier: scope.tier, mode: plan.mode, ranFiles: plan.testFiles, passed: false, skipped: false,
|
|
869
|
-
|
|
870
|
-
|
|
1055
|
+
// @implements A-SPEC-128.8 — a full plan with nothing detected at the root says so, not "no adapter for 0 files"
|
|
1056
|
+
tail: surface.length > 0 ? `no unit started — outside the 0.40.x surface:\n${surface.map((s) => s.reason).join('\n')}`
|
|
1057
|
+
: plan.mode === 'full' && unsupported.length === 0
|
|
1058
|
+
? `no test unit in the project — nothing ran${implementationCount > 0 ? ` (implementation code without tests, e.g. ${implementationSample.join(', ')})` : ''}`
|
|
1059
|
+
: `no runner adapter for ${unsupported.length} test file(s): ${unsupported.slice(0, 5).join(', ')}`,
|
|
1060
|
+
executedByFile: {}, unsupported, ranWith: [], workers: null, testsRun: 0, testsRunBy: {}, stopped: false, detected, ...named,
|
|
1061
|
+
...(plan.mode === 'full' ? { units: [] } : {}), ...(surface.length ? { environment: surface } : {}),
|
|
1062
|
+
// @implements A-SPEC-128.10 — R2: with no unit, every build root's code is untested (and names a missing build file)
|
|
1063
|
+
...(plan.mode === 'full' && surface.length === 0 && codeRoots.length ? { untestedCode: codeRoots.map((g) => ({ root: g.root, sample: g.sample, ...(g.missingBuildFile ? { missingBuildFile: g.missingBuildFile } : {}) })) } : {}),
|
|
871
1064
|
};
|
|
872
1065
|
}
|
|
873
1066
|
// @implements A-SPEC-515.1
|
|
@@ -933,18 +1126,32 @@ function failedTestSummary(stdout, limit = 5) {
|
|
|
933
1126
|
if (j === null || typeof j !== 'object' || !Array.isArray(j.testResults))
|
|
934
1127
|
return null;
|
|
935
1128
|
const failures = [];
|
|
1129
|
+
const broken = [];
|
|
936
1130
|
for (const file of j.testResults) {
|
|
937
1131
|
const base = typeof file?.name === 'string' ? file.name.split(/[\\/]/).pop() ?? file.name : '(unknown file)';
|
|
1132
|
+
const before = failures.length;
|
|
938
1133
|
for (const a of Array.isArray(file?.assertionResults) ? file.assertionResults : []) {
|
|
939
1134
|
if (a?.status !== 'failed')
|
|
940
1135
|
continue;
|
|
941
1136
|
const msg = Array.isArray(a.failureMessages) ? a.failureMessages.find((m) => typeof m === 'string' && m.trim() !== '') : undefined;
|
|
1137
|
+
// @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
1138
|
failures.push({
|
|
943
|
-
where: `${base} \u203a ${String(a.title ?? '(untitled)')}`,
|
|
944
|
-
first: typeof msg === 'string' ? (msg.trim().split('\n')[0] ?? '') : '',
|
|
1139
|
+
where: clip(`${base} \u203a ${String(a.title ?? '(untitled)').replace(/\s+/g, ' ').trim()}`, WHERE_MAX),
|
|
1140
|
+
first: clip(typeof msg === 'string' ? (msg.trim().split('\n')[0] ?? '') : '', FIRST_MAX),
|
|
945
1141
|
});
|
|
946
1142
|
}
|
|
1143
|
+
// @implements A-SPEC-466.3 \u2014 a suite that failed with no failing assertion (it did not compile, its teardown threw)
|
|
1144
|
+
// is named too, with the first line of its message
|
|
1145
|
+
// @implements A-SPEC-466.4 \u2014 the cause line: jest opens the message with a `\u25cf Test suite failed to run` header
|
|
1146
|
+
if (file?.status === 'failed' && failures.length === before) {
|
|
1147
|
+
const message = typeof file.message === 'string' ? file.message.replace(/\u001b\[[0-9;]*m/g, '') : '';
|
|
1148
|
+
const cause = message.split('\n').map((l) => l.trim()).find((l) => l !== '' && !l.startsWith('\u25cf')) ?? '';
|
|
1149
|
+
broken.push({ where: clip(`${base} \u203a (suite failed to run)`, WHERE_MAX), first: clip(cause, FIRST_MAX) });
|
|
1150
|
+
}
|
|
947
1151
|
}
|
|
1152
|
+
// @implements A-SPEC-466.5 \u2014 suites that failed to run come first: in a real mixed run (24 failing assertions, 2
|
|
1153
|
+
// broken suites) the five-name bound was spent on assertions and no broken suite was named
|
|
1154
|
+
failures.unshift(...broken);
|
|
948
1155
|
if (failures.length === 0)
|
|
949
1156
|
return null;
|
|
950
1157
|
const shown = failures.slice(0, Math.max(0, limit));
|
|
@@ -954,6 +1161,31 @@ function failedTestSummary(stdout, limit = 5) {
|
|
|
954
1161
|
lines.push(` \u2026 \uc678 ${rest}\uac74`);
|
|
955
1162
|
return lines.join('\n');
|
|
956
1163
|
}
|
|
1164
|
+
/** @implements A-SPEC-466.4 \u2014 each failure line's own bound: `file \u203a title` and its first message line. */
|
|
1165
|
+
const WHERE_MAX = 200;
|
|
1166
|
+
const FIRST_MAX = 300;
|
|
1167
|
+
/** @implements A-SPEC-466.4 \u2014 `text` cut to at most `max` characters, marked `\u2026`, never inside a surrogate pair. */
|
|
1168
|
+
function clip(text, max) {
|
|
1169
|
+
if (text.length <= max)
|
|
1170
|
+
return text;
|
|
1171
|
+
let end = max - 1;
|
|
1172
|
+
if (/[\uD800-\uDBFF]/.test(text[end - 1] ?? ''))
|
|
1173
|
+
end -= 1;
|
|
1174
|
+
return `${text.slice(0, end)}\u2026`;
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* @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
|
|
1178
|
+
* follows with a bound of its own. One `tailOf` over both kept the last lines and cut the front, so a long stderr pushed
|
|
1179
|
+
* every name out (2026-11-04, `27bc0c40`: five failures, none named). The name block is bounded by its parts: five names
|
|
1180
|
+
* of at most WHERE_MAX and FIRST_MAX characters and one count line, so the whole tail stays under 7,000 characters.
|
|
1181
|
+
* Without readable jest JSON the tail is what it always was.
|
|
1182
|
+
*/
|
|
1183
|
+
function redJestTail(stdout, stderr) {
|
|
1184
|
+
const named = failedTestSummary(stdout);
|
|
1185
|
+
if (named === null)
|
|
1186
|
+
return tailOf(`${stdout}\n${stderr}`, { lines: 6 });
|
|
1187
|
+
return `${named}\n${tailOf(stderr, { lines: 30 })}`;
|
|
1188
|
+
}
|
|
957
1189
|
function summarizeJestJson(stdout) {
|
|
958
1190
|
// The payload is not the whole of stdout. A suite that logs anything prints it BEFORE the JSON,
|
|
959
1191
|
// and this repository's own suite does: measured, the first live run after this function landed
|