@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
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.isJestConfig = void 0;
|
|
37
|
+
exports.parseGoTestJson = parseGoTestJson;
|
|
38
|
+
exports.withoutExcluded = withoutExcluded;
|
|
39
|
+
exports.goFailedTests = goFailedTests;
|
|
40
|
+
exports.jestReportFailed = jestReportFailed;
|
|
41
|
+
exports.goPackagesWithTestEvents = goPackagesWithTestEvents;
|
|
42
|
+
exports.parseExecutedCounts = parseExecutedCounts;
|
|
43
|
+
exports.classifyJestOutcomes = classifyJestOutcomes;
|
|
44
|
+
exports.parseJUnitXmlCounts = parseJUnitXmlCounts;
|
|
45
|
+
exports.parseJUnitXmlOutcomes = parseJUnitXmlOutcomes;
|
|
46
|
+
exports.parseJUnitXmlFiles = parseJUnitXmlFiles;
|
|
47
|
+
exports.wellShapedJson = wellShapedJson;
|
|
48
|
+
exports.readJestReport = readJestReport;
|
|
49
|
+
// @implements A-SPEC-128.12
|
|
50
|
+
/**
|
|
51
|
+
* Runner report readers (A-SPEC-128.12, SRP): jest `--json`, pytest/JUnit XML and `go test -json`. Each reader is pure
|
|
52
|
+
* and returns a parsed value, an empty value or null — never a throw. test-runner.ts runs the runners and re-exports
|
|
53
|
+
* these names, so their callers keep importing them from there. The specs each reader was written under are named in
|
|
54
|
+
* its comment (moved here unchanged from test-runner.ts).
|
|
55
|
+
*/
|
|
56
|
+
const fs = __importStar(require("node:fs"));
|
|
57
|
+
/**
|
|
58
|
+
* Written under A-SPEC-137.1.
|
|
59
|
+
* Executed-test counts per Go package from `go test -json` output. A test is EXECUTED when a NAMED
|
|
60
|
+
* test (`Test` present) reaches `Action: 'pass'` or `'fail'` — a skip does not count (matching the
|
|
61
|
+
* jest/pytest rule), and a package-level result (no `Test`) is not a test case. Non-JSON lines (go
|
|
62
|
+
* interleaves build output) are ignored. Pure; empty/garbage input yields `{}` rather than throwing.
|
|
63
|
+
*/
|
|
64
|
+
function parseGoTestJson(out) {
|
|
65
|
+
const counts = {};
|
|
66
|
+
for (const line of out.split('\n')) {
|
|
67
|
+
const s = line.trim();
|
|
68
|
+
if (!s.startsWith('{'))
|
|
69
|
+
continue;
|
|
70
|
+
let evt;
|
|
71
|
+
try {
|
|
72
|
+
evt = JSON.parse(s);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (!evt.Test || !evt.Package)
|
|
78
|
+
continue; // package-level result is not a test case
|
|
79
|
+
if (evt.Action === 'pass' || evt.Action === 'fail') { // skip is excluded; pass/fail both executed
|
|
80
|
+
counts[evt.Package] = (counts[evt.Package] ?? 0) + 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return counts;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Written under A-SPEC-128.12 (S2/S6), moved here by A-SPEC-128.13 (SRP): a unit's report without the tests it reported
|
|
87
|
+
* under its excluded trees (`ignore`, unit-relative; a tree ends in `/`), and the root-relative names of those that ran
|
|
88
|
+
* red. Counts are recomputed from what is kept, so an excluded green neither counts nor credits code.
|
|
89
|
+
*/
|
|
90
|
+
function withoutExcluded(raw, ignore, dir) {
|
|
91
|
+
const excluded = (rel) => ignore.some((x) => (x.endsWith('/') ? rel.startsWith(x) : rel === x));
|
|
92
|
+
const hit = [...Object.keys(raw.executed), ...Object.keys(raw.outcomes ?? {}), ...(raw.reported ?? [])].some(excluded);
|
|
93
|
+
if (!hit)
|
|
94
|
+
return { r: raw, excludedRed: [] };
|
|
95
|
+
const executed = Object.fromEntries(Object.entries(raw.executed).filter(([f]) => !excluded(f)));
|
|
96
|
+
const outcomes = raw.outcomes ? Object.fromEntries(Object.entries(raw.outcomes).filter(([f]) => !excluded(f))) : undefined;
|
|
97
|
+
const excludedRed = Object.entries(raw.outcomes ?? {}).filter(([f, o]) => excluded(f) && o !== 'green').map(([f]) => (dir === '' ? f : `${dir}/${f}`)).sort();
|
|
98
|
+
const keptRed = Object.values(outcomes ?? {}).some((o) => o !== 'green');
|
|
99
|
+
return {
|
|
100
|
+
r: { ...raw, executed, ...(outcomes ? { outcomes } : {}), ...(raw.reported ? { reported: raw.reported.filter((f) => !excluded(f)) } : {}),
|
|
101
|
+
testsRun: Object.values(executed).reduce((a, b) => a + b, 0), passed: raw.passed || (excludedRed.length > 0 && !keptRed) },
|
|
102
|
+
excludedRed,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** A-SPEC-128.13 T1: the named tests `go test -json` reported as failed, whatever the process's exit code. */
|
|
106
|
+
function goFailedTests(out) {
|
|
107
|
+
const failed = [];
|
|
108
|
+
for (const line of out.split('\n')) {
|
|
109
|
+
const s = line.trim();
|
|
110
|
+
if (!s.startsWith('{'))
|
|
111
|
+
continue;
|
|
112
|
+
let evt;
|
|
113
|
+
try {
|
|
114
|
+
evt = JSON.parse(s);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (evt.Action === 'fail' && evt.Test && evt.Package)
|
|
120
|
+
failed.push(`${evt.Package}.${evt.Test}`);
|
|
121
|
+
}
|
|
122
|
+
return failed;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A-SPEC-128.13 T1: whether a jest `--json` report holds a failure — a failed test, a suite that could not run, or a
|
|
126
|
+
* failed result — whatever the process's exit code (`testFailureExitCode: 0` exits 0 over a red).
|
|
127
|
+
*/
|
|
128
|
+
function jestReportFailed(report) {
|
|
129
|
+
let data;
|
|
130
|
+
try {
|
|
131
|
+
data = JSON.parse(report.slice(Math.max(0, report.indexOf('{'))));
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
const n = (v) => (typeof v === 'number' ? v : 0);
|
|
137
|
+
return n(data.numFailedTests) > 0 || n(data.numRuntimeErrorTestSuites) > 0 || (data.testResults ?? []).some((t) => t?.status === 'failed');
|
|
138
|
+
}
|
|
139
|
+
/** Written under A-SPEC-128.11 (P5): the packages in `go test -json` output where a named test passed, failed or skipped. */
|
|
140
|
+
function goPackagesWithTestEvents(out) {
|
|
141
|
+
const seen = new Set();
|
|
142
|
+
for (const line of out.split('\n')) {
|
|
143
|
+
const s = line.trim();
|
|
144
|
+
if (!s.startsWith('{'))
|
|
145
|
+
continue;
|
|
146
|
+
let evt;
|
|
147
|
+
try {
|
|
148
|
+
evt = JSON.parse(s);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (evt.Test && evt.Package && (evt.Action === 'pass' || evt.Action === 'fail' || evt.Action === 'skip'))
|
|
154
|
+
seen.add(evt.Package);
|
|
155
|
+
}
|
|
156
|
+
return seen;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Parse jest --json output into per-file EXECUTED case counts. This is the execution-proof upgrade
|
|
160
|
+
* over the syntactic countTestCases lower bound: a case only appears here if jest actually ran it
|
|
161
|
+
* (pending/skipped assertions are excluded), so `if(false){it(…)}`, aliasing, and other syntactic
|
|
162
|
+
* fabrications cannot produce evidence. Returns {} for unparseable output (caller falls back).
|
|
163
|
+
*/
|
|
164
|
+
function parseExecutedCounts(stdout, cwd) {
|
|
165
|
+
const start = stdout.indexOf('{');
|
|
166
|
+
if (start < 0)
|
|
167
|
+
return {};
|
|
168
|
+
let data;
|
|
169
|
+
try {
|
|
170
|
+
data = JSON.parse(stdout.slice(start));
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return {};
|
|
174
|
+
}
|
|
175
|
+
const out = {};
|
|
176
|
+
for (const tr of data?.testResults ?? []) {
|
|
177
|
+
const abs = tr.name ?? tr.testFilePath ?? '';
|
|
178
|
+
if (!abs)
|
|
179
|
+
continue;
|
|
180
|
+
const ran = (tr.assertionResults ?? []).filter((a) => a.status === 'passed' || a.status === 'failed').length;
|
|
181
|
+
out[relTestPath(abs, cwd)] = ran;
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
/** Repo-relative, forward-slashed key for a jest test-file path — shared by the parsers below. */
|
|
186
|
+
function relTestPath(abs, cwd) {
|
|
187
|
+
const rel = abs.startsWith(cwd) ? abs.slice(cwd.length).replace(/^[/\\]/, '') : abs;
|
|
188
|
+
return rel.split('\\').join('/');
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Written under A-SPEC-534.1.
|
|
192
|
+
* Classify each jest-executed file into red-assertion | red-error | green from `jest --json` stdout.
|
|
193
|
+
* Pure; unparseable/empty input → {} (same fail-soft convention as parseExecutedCounts).
|
|
194
|
+
*
|
|
195
|
+
* A failed assertion anywhere in a file wins (`red-assertion`) — that is a real red. A file that ran
|
|
196
|
+
* NO assertions but errored (testExecError, or status 'failed' with an empty assertion list — a
|
|
197
|
+
* load/collection/import failure) is `red-error`, which ART-8 must not accept as a valid RED. A file
|
|
198
|
+
* that executed ≥1 assertion with none failing is `green`. A file that only pended/skipped carries no
|
|
199
|
+
* evidence and is omitted entirely.
|
|
200
|
+
*/
|
|
201
|
+
function classifyJestOutcomes(stdout, cwd) {
|
|
202
|
+
const start = stdout.indexOf('{');
|
|
203
|
+
if (start < 0)
|
|
204
|
+
return {};
|
|
205
|
+
let data;
|
|
206
|
+
try {
|
|
207
|
+
data = JSON.parse(stdout.slice(start));
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return {};
|
|
211
|
+
}
|
|
212
|
+
const out = {};
|
|
213
|
+
for (const tr of data?.testResults ?? []) {
|
|
214
|
+
const abs = tr.name ?? tr.testFilePath ?? '';
|
|
215
|
+
if (!abs)
|
|
216
|
+
continue;
|
|
217
|
+
const rel = relTestPath(abs, cwd);
|
|
218
|
+
const assertions = tr.assertionResults ?? [];
|
|
219
|
+
if (assertions.some((a) => a.status === 'failed')) {
|
|
220
|
+
out[rel] = 'red-assertion';
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const executed = assertions.filter((a) => a.status === 'passed' || a.status === 'failed').length;
|
|
224
|
+
const errored = !!tr.testExecError || tr.status === 'failed';
|
|
225
|
+
if (executed === 0) {
|
|
226
|
+
if (errored)
|
|
227
|
+
out[rel] = 'red-error'; // ran nothing AND failed → could not execute its cases
|
|
228
|
+
continue; // otherwise all pending/skipped → no evidence, omit
|
|
229
|
+
}
|
|
230
|
+
out[rel] = errored ? 'red-error' : 'green';
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Parse pytest's built-in JUnit XML into per-file EXECUTED case counts — the pytest analogue of
|
|
236
|
+
* parseExecutedCounts. `--junit-xml` ships with pytest core, so this needs no plugin, and it is the
|
|
237
|
+
* only pytest output that is both machine-readable and per-file.
|
|
238
|
+
*
|
|
239
|
+
* A `<testcase>` counts as executed unless it carries `<skipped>`, matching the jest rule where
|
|
240
|
+
* pending/skipped assertions are excluded. Errors and failures DO count: they executed.
|
|
241
|
+
*/
|
|
242
|
+
function parseJUnitXmlCounts(xml, ext = 'py') {
|
|
243
|
+
const out = {};
|
|
244
|
+
for (const m of xml.matchAll(/<testcase\b([^>]*?)(\/>|>([\s\S]*?)<\/testcase>)/g)) {
|
|
245
|
+
const attrs = m[1] ?? '';
|
|
246
|
+
const body = m[3] ?? '';
|
|
247
|
+
// `file` (xunit1 / dotnet loggers) is used verbatim when present. Otherwise the `classname`
|
|
248
|
+
// fallback maps to a source path — but the class↔file relationship is language-specific
|
|
249
|
+
// (written under A-SPEC-137.3):
|
|
250
|
+
// py : the MODULE names the file, the class is a nested segment. `tests.test_calc.TestThing`
|
|
251
|
+
// -> `tests/test_calc.py` (drop trailing Capitalized class segments).
|
|
252
|
+
// java/cs : the CLASS names the file. `com.x.FooTest` -> `com/x/FooTest.java` (keep all).
|
|
253
|
+
let file = /\bfile="([^"]*)"/.exec(attrs)?.[1];
|
|
254
|
+
if (!file) {
|
|
255
|
+
const cls = /\bclassname="([^"]*)"/.exec(attrs)?.[1];
|
|
256
|
+
if (!cls)
|
|
257
|
+
continue;
|
|
258
|
+
const parts = cls.split('.').filter(Boolean);
|
|
259
|
+
if (ext === 'py') {
|
|
260
|
+
while (parts.length > 1 && /^[A-Z]/.test(parts[parts.length - 1]))
|
|
261
|
+
parts.pop();
|
|
262
|
+
}
|
|
263
|
+
if (parts.length === 0)
|
|
264
|
+
continue;
|
|
265
|
+
file = `${parts.join('/')}.${ext}`;
|
|
266
|
+
}
|
|
267
|
+
if (/<skipped\b/.test(body))
|
|
268
|
+
continue;
|
|
269
|
+
const key = file.split('\\').join('/');
|
|
270
|
+
out[key] = (out[key] ?? 0) + 1;
|
|
271
|
+
}
|
|
272
|
+
return out;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Written under A-SPEC-647.
|
|
276
|
+
* Per-file RED-first outcome from the same JUnit XML `parseJUnitXmlCounts` reads. Measured 2026-09-14
|
|
277
|
+
* in an external pytest project: a ranged test_run executed the anchored case and recorded NOTHING,
|
|
278
|
+
* because classification was jest-only — a Python project could never produce the red-assertion→green
|
|
279
|
+
* sequence ART-8 reads. `<error>` (collection/import/setup) is a red-error, `<failure>` (an assertion)
|
|
280
|
+
* a red-assertion, executed cases without either are green; a file with only skipped cases says nothing.
|
|
281
|
+
*/
|
|
282
|
+
function parseJUnitXmlOutcomes(xml, ext = 'py') {
|
|
283
|
+
const flags = new Map();
|
|
284
|
+
for (const m of xml.matchAll(/<testcase\b([^>]*?)(\/>|>([\s\S]*?)<\/testcase>)/g)) {
|
|
285
|
+
const attrs = m[1] ?? '';
|
|
286
|
+
const body = m[3] ?? '';
|
|
287
|
+
let file = /\bfile="([^"]*)"/.exec(attrs)?.[1];
|
|
288
|
+
if (!file) {
|
|
289
|
+
const cls = /\bclassname="([^"]*)"/.exec(attrs)?.[1];
|
|
290
|
+
if (!cls)
|
|
291
|
+
continue;
|
|
292
|
+
const parts = cls.split('.').filter(Boolean);
|
|
293
|
+
if (ext === 'py') {
|
|
294
|
+
while (parts.length > 1 && /^[A-Z]/.test(parts[parts.length - 1]))
|
|
295
|
+
parts.pop();
|
|
296
|
+
}
|
|
297
|
+
if (parts.length === 0)
|
|
298
|
+
continue;
|
|
299
|
+
file = `${parts.join('/')}.${ext}`;
|
|
300
|
+
}
|
|
301
|
+
const key = file.split('\\').join('/');
|
|
302
|
+
const f = flags.get(key) ?? { error: false, failure: false, executed: false };
|
|
303
|
+
if (/<error\b/.test(body))
|
|
304
|
+
f.error = true;
|
|
305
|
+
else if (/<failure\b/.test(body))
|
|
306
|
+
f.failure = true;
|
|
307
|
+
if (!/<skipped\b/.test(body))
|
|
308
|
+
f.executed = true;
|
|
309
|
+
flags.set(key, f);
|
|
310
|
+
}
|
|
311
|
+
const out = {};
|
|
312
|
+
for (const [file, f] of flags) {
|
|
313
|
+
if (f.error)
|
|
314
|
+
out[file] = 'red-error';
|
|
315
|
+
else if (f.failure)
|
|
316
|
+
out[file] = 'red-assertion';
|
|
317
|
+
else if (f.executed)
|
|
318
|
+
out[file] = 'green';
|
|
319
|
+
}
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
322
|
+
/** Written under A-SPEC-128.10: the files a JUnit report names, skipped cases included (what the runner collected). */
|
|
323
|
+
function parseJUnitXmlFiles(xml) {
|
|
324
|
+
const out = new Set();
|
|
325
|
+
for (const m of xml.matchAll(/<testcase\b([^>]*?)(\/>|>)/g)) {
|
|
326
|
+
const file = /\bfile="([^"]*)"/.exec(m[1] ?? '')?.[1];
|
|
327
|
+
if (file)
|
|
328
|
+
out.add(file.split('\\').join('/'));
|
|
329
|
+
}
|
|
330
|
+
return [...out];
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Written under A-SPEC-128.11 (P3): the first well-shaped JSON block in a runner's output, or null. A block starts on a
|
|
334
|
+
* line beginning with `{` or `[` and ends on a line ending with `}` or `]`; it counts only when `accept` holds. The
|
|
335
|
+
* user's own console output (a config logging `[dotenv] …` or `{…}`) is never mistaken for the runner's, and nothing is
|
|
336
|
+
* defaulted.
|
|
337
|
+
*/
|
|
338
|
+
function wellShapedJson(out, accept) {
|
|
339
|
+
const lines = out.split('\n');
|
|
340
|
+
const starts = [];
|
|
341
|
+
const ends = [];
|
|
342
|
+
lines.forEach((l, i) => {
|
|
343
|
+
if (/^\s*[[{]/.test(l))
|
|
344
|
+
starts.push(i);
|
|
345
|
+
if (/[\]}]\s*$/.test(l))
|
|
346
|
+
ends.push(i);
|
|
347
|
+
});
|
|
348
|
+
let tries = 0;
|
|
349
|
+
for (const s of starts) {
|
|
350
|
+
for (let k = ends.length - 1; k >= 0 && ends[k] >= s; k--) {
|
|
351
|
+
if (++tries > 4000)
|
|
352
|
+
return null; // a bound: output with thousands of bracket lines is not read by trial
|
|
353
|
+
try {
|
|
354
|
+
const v = JSON.parse(lines.slice(s, ends[k] + 1).join('\n'));
|
|
355
|
+
if (accept(v))
|
|
356
|
+
return v;
|
|
357
|
+
}
|
|
358
|
+
catch { /* not this block */ }
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
/** S2/S7: `jest --showConfig`'s document — an object with a `configs` array. */
|
|
364
|
+
const isJestConfig = (v) => !!v && typeof v === 'object' && Array.isArray(v.configs);
|
|
365
|
+
exports.isJestConfig = isJestConfig;
|
|
366
|
+
const isJestReport = (v) => !!v && typeof v === 'object' && Array.isArray(v.testResults);
|
|
367
|
+
/**
|
|
368
|
+
* Written under A-SPEC-128.11 (P3): jest's `--json` report, from its `--outputFile` when jest wrote one, else from a
|
|
369
|
+
* well-shaped document on stdout (an object with a `testResults` array). Null when neither reads.
|
|
370
|
+
*/
|
|
371
|
+
function readJestReport(file, stdout) {
|
|
372
|
+
if (file !== null) {
|
|
373
|
+
try {
|
|
374
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
375
|
+
if (isJestReport(JSON.parse(text)))
|
|
376
|
+
return text;
|
|
377
|
+
}
|
|
378
|
+
catch { /* not written: stdout below */ }
|
|
379
|
+
}
|
|
380
|
+
const doc = wellShapedJson(stdout, isJestReport);
|
|
381
|
+
return doc === null ? null : JSON.stringify(doc);
|
|
382
|
+
}
|