@holmes-lab/holmes-kit 0.33.0 → 0.35.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.
@@ -33,8 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.RELEASE_TEST_LANE_SCHEMA = exports.RELEASE_TEST_LANE_FILE = exports.OUTCOMES_FILE = void 0;
36
+ exports.REQUIRED_DOCS_TESTS = exports.RELEASE_TEST_LANE_FULL_FILE = exports.RELEASE_TEST_LANE_SCHEMA = exports.RELEASE_TEST_LANE_FILE = exports.OUTCOMES_FILE = void 0;
37
37
  exports.writeReleaseTestLaneReceipt = writeReleaseTestLaneReceipt;
38
+ exports.inheritablePaths = inheritablePaths;
39
+ exports.laneGit = laneGit;
40
+ exports.inheritReleaseTestLane = inheritReleaseTestLane;
38
41
  exports.validateReleaseTestLaneReceipt = validateReleaseTestLaneReceipt;
39
42
  exports.outcomesFilename = outcomesFilename;
40
43
  exports.isOutcomesFilename = isOutcomesFilename;
@@ -42,10 +45,11 @@ exports.appendOutcomes = appendOutcomes;
42
45
  exports.readOutcomes = readOutcomes;
43
46
  exports.buildOutcomeRecords = buildOutcomeRecords;
44
47
  exports.groupOutcomesByAspec = groupOutcomesByAspec;
45
- // @implements A-SPEC-724.1, A-SPEC-714, A-SPEC-734
48
+ // @implements A-SPEC-724.1, A-SPEC-714, A-SPEC-734, A-SPEC-748
46
49
  // @implements A-SPEC-534.3, A-SPEC-625
47
50
  // @implements A-SPEC-645
48
51
  const node_crypto_1 = require("node:crypto");
52
+ const node_child_process_1 = require("node:child_process");
49
53
  const execution_context_1 = require("../project/execution-context");
50
54
  const fs = __importStar(require("node:fs"));
51
55
  const path = __importStar(require("node:path"));
@@ -55,10 +59,12 @@ exports.OUTCOMES_FILE = path.join('.ax', 'ledger', 'test-outcomes.jsonl');
55
59
  exports.RELEASE_TEST_LANE_FILE = path.join('.ax', 'evidence', 'release-test-lane.json');
56
60
  exports.RELEASE_TEST_LANE_SCHEMA = 'release-test-lane/1';
57
61
  const RELEASE_TEST_LANE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
62
+ // A full receipt signs exactly what it always signed; `inheritedFrom` is signed only where it exists.
58
63
  const stableReceipt = (receipt) => JSON.stringify({
59
64
  schema: receipt.schema, root: receipt.root, head: receipt.head, completedAt: receipt.completedAt,
60
65
  passed: receipt.passed, externalAccess: receipt.externalAccess, command: receipt.command,
61
66
  include: receipt.include, exclusions: receipt.exclusions,
67
+ ...(receipt.inheritedFrom ? { inheritedFrom: receipt.inheritedFrom } : {}),
62
68
  });
63
69
  const releaseReceiptDigest = (receipt) => `sha256:${(0, node_crypto_1.createHash)('sha256').update(stableReceipt(receipt)).digest('hex')}`;
64
70
  /** Persist only evidence whose scope is explicit and bounded; callers cannot choose its path. */
@@ -68,24 +74,142 @@ function writeReleaseTestLaneReceipt(root, input) {
68
74
  const receipt = normalizeReleaseTestLaneReceipt(root, { ...input, schema: exports.RELEASE_TEST_LANE_SCHEMA });
69
75
  if (receipt === null)
70
76
  return null;
71
- const file = path.join(path.resolve(root), exports.RELEASE_TEST_LANE_FILE);
77
+ if (!writeAtomic(path.join(path.resolve(root), exports.RELEASE_TEST_LANE_FILE), receipt))
78
+ return null;
79
+ // @implements A-SPEC-748 — a FULL lane is also kept as the base later docs-only commits inherit from.
80
+ if (!receipt.inheritedFrom && !writeAtomic(path.join(path.resolve(root), exports.RELEASE_TEST_LANE_FULL_FILE), receipt))
81
+ return null;
82
+ return receipt;
83
+ }
84
+ function writeAtomic(file, receipt) {
72
85
  const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
73
86
  try {
74
87
  fs.mkdirSync(path.dirname(file), { recursive: true });
75
88
  fs.writeFileSync(tmp, `${JSON.stringify(receipt)}\n`, { encoding: 'utf8', mode: 0o600 });
76
89
  fs.renameSync(tmp, file);
77
- return receipt;
90
+ return true;
78
91
  }
79
92
  catch {
80
93
  try {
81
94
  fs.unlinkSync(tmp);
82
95
  }
83
96
  catch { /* no partial receipt is valid */ }
84
- return null;
97
+ return false;
85
98
  }
86
99
  }
100
+ /** @implements A-SPEC-748 — the last FULL lane receipt, kept beside the current one (git-ignored like it). */
101
+ exports.RELEASE_TEST_LANE_FULL_FILE = path.join('.ax', 'evidence', 'release-test-lane.full.json');
102
+ /**
103
+ * @implements A-SPEC-748 — the tests an inherited receipt runs: every test that reads the repository's own README or
104
+ * docs/, plus the docs-currency, publish-docs-gate and packaging tests. A ratchet test fails when a new reader is missing.
105
+ */
106
+ exports.REQUIRED_DOCS_TESTS = [
107
+ 'src/holmes/project/docs-currency.test.ts',
108
+ 'src/holmes/playbooks/publish-docs-gate.test.ts',
109
+ 'src/holmes/playbooks/packaging.test.ts',
110
+ 'src/holmes/cpg/foundation/language-matrix.test.ts',
111
+ 'src/holmes/project/dependency-overrides.test.ts',
112
+ ];
113
+ /**
114
+ * @implements A-SPEC-748 — every path of every change (both sides of a rename or copy) must be `README.md` or under
115
+ * `docs/`, and none may be shipped (equal to, or under a directory entry of, package.json `files`).
116
+ */
117
+ function inheritablePaths(changes, shipped) {
118
+ const isShipped = (p) => shipped.some((raw) => {
119
+ const e = raw.replace(/\\/g, '/').replace(/^\.\//, '');
120
+ return e.endsWith('/') ? p.startsWith(e) : p === e || p.startsWith(`${e}/`);
121
+ });
122
+ for (const change of changes) {
123
+ for (const raw of change.paths) {
124
+ const p = raw.replace(/\\/g, '/');
125
+ if (!(p === 'README.md' || p.startsWith('docs/')) || isShipped(p))
126
+ return { ok: false, path: p };
127
+ }
128
+ }
129
+ return { ok: true };
130
+ }
131
+ /** @implements A-SPEC-748 — the two git questions inheritance asks, answered by git in `root`; `null`/false when git cannot. */
132
+ function laneGit(root) {
133
+ const run = (args) => {
134
+ const r = (0, node_child_process_1.spawnSync)('git', ['-C', root, ...args], { encoding: 'utf8', timeout: 30_000, maxBuffer: 64 * 1024 * 1024 });
135
+ return { status: r.status, stdout: typeof r.stdout === 'string' ? r.stdout : '' };
136
+ };
137
+ return {
138
+ isAncestor: (base, head) => run(['merge-base', '--is-ancestor', base, head]).status === 0,
139
+ changes: (base, head) => {
140
+ const r = run(['diff', '--name-status', '-M', '-z', base, head]);
141
+ if (r.status !== 0)
142
+ return null;
143
+ const parts = r.stdout.split('\0').filter((s) => s !== '');
144
+ const out = [];
145
+ for (let i = 0; i < parts.length;) {
146
+ const status = parts[i++];
147
+ const n = /^[RC]/.test(status) ? 2 : 1;
148
+ out.push({ status, paths: parts.slice(i, i + n) });
149
+ i += n;
150
+ }
151
+ return out;
152
+ },
153
+ };
154
+ }
155
+ /** @implements A-SPEC-748 — the kept FULL receipt, valid for its own head and not older than the lane's limit. */
156
+ function readFullReceipt(root, now) {
157
+ let parsed;
158
+ try {
159
+ parsed = JSON.parse(fs.readFileSync(path.join(path.resolve(root), exports.RELEASE_TEST_LANE_FULL_FILE), 'utf8'));
160
+ }
161
+ catch {
162
+ return { ok: false, reason: 'no full release test-lane receipt to inherit from — run the full lane (--record-release-test-lane)' };
163
+ }
164
+ const receipt = normalizeReleaseTestLaneReceipt(root, parsed);
165
+ if (receipt === null || receipt.digest !== parsed.digest) {
166
+ return { ok: false, reason: 'the kept full release test-lane receipt is malformed or its digest is invalid' };
167
+ }
168
+ if (receipt.inheritedFrom)
169
+ return { ok: false, reason: 'the kept full receipt is itself inherited — only a full lane can be inherited from' };
170
+ const completedMs = Date.parse(receipt.completedAt);
171
+ if (completedMs > now || now - completedMs > RELEASE_TEST_LANE_MAX_AGE_MS) {
172
+ return { ok: false, reason: 'the kept full release test-lane receipt is older than 24 hours (or in the future)' };
173
+ }
174
+ return { ok: true, receipt };
175
+ }
176
+ /** @implements A-SPEC-748 — whether HEAD may stand on the full receipt: an ancestor, and only inheritable changes since it. */
177
+ function inheritableSince(full, head, git, shipped) {
178
+ if (!git.isAncestor(full.head, head))
179
+ return `the full lane's HEAD ${full.head.slice(0, 12)} is not an ancestor of ${head.slice(0, 12)}`;
180
+ const changes = git.changes(full.head, head);
181
+ if (changes === null)
182
+ return 'git could not list the changes since the full lane';
183
+ const verdict = inheritablePaths(changes, shipped);
184
+ return verdict.ok ? null : `${verdict.path} changed since the full lane — only README.md and unshipped docs/ files may be inherited; run the full lane`;
185
+ }
186
+ /**
187
+ * @implements A-SPEC-748 — record a receipt for HEAD by inheriting the kept full lane receipt: refused unless the full
188
+ * receipt is valid, fresh and an ancestor, every change since it is inheritable, and the required docs tests pass.
189
+ */
190
+ function inheritReleaseTestLane(root, head, opts) {
191
+ const now = opts.now ?? Date.now();
192
+ const full = readFullReceipt(root, now);
193
+ if (!full.ok)
194
+ return full;
195
+ if (full.receipt.head === head)
196
+ return { ok: false, reason: 'HEAD already has the full release test-lane receipt — nothing to inherit' };
197
+ const blocked = inheritableSince(full.receipt, head, opts.git, opts.shipped);
198
+ if (blocked !== null)
199
+ return { ok: false, reason: blocked };
200
+ if (!opts.runDocsTests(exports.REQUIRED_DOCS_TESTS))
201
+ return { ok: false, reason: 'the required docs tests failed — this commit is not published on an inherited receipt' };
202
+ const receipt = writeReleaseTestLaneReceipt(root, {
203
+ root: path.resolve(root), head, completedAt: new Date(now).toISOString(), passed: true, externalAccess: 'forbidden',
204
+ command: ['npm', 'test', '--', '--runInBand', ...exports.REQUIRED_DOCS_TESTS],
205
+ include: ['required docs tests on a docs-only commit, inheriting the full lane'],
206
+ exclusions: full.receipt.exclusions,
207
+ inheritedFrom: { head: full.receipt.head, completedAt: full.receipt.completedAt, digest: full.receipt.digest },
208
+ });
209
+ return receipt === null ? { ok: false, reason: 'the inherited release test-lane receipt could not be written' } : { ok: true, receipt };
210
+ }
87
211
  /** Read the sole project-local receipt and fail closed for every missing or unprovable condition. */
88
- function validateReleaseTestLaneReceipt(root, head, now = Date.now()) {
212
+ function validateReleaseTestLaneReceipt(root, head, now = Date.now(), inherit) {
89
213
  const expectedRoot = path.resolve(root);
90
214
  if (typeof head !== 'string' || head === '' || head.includes('/') || head.includes('\\'))
91
215
  return { valid: false, reason: 'invalid current HEAD' };
@@ -105,6 +229,22 @@ function validateReleaseTestLaneReceipt(root, head, now = Date.now()) {
105
229
  return { valid: false, reason: 'release test-lane receipt belongs to a different root' };
106
230
  if (receipt.head !== head)
107
231
  return { valid: false, reason: 'release test-lane receipt HEAD does not match' };
232
+ // @implements A-SPEC-748 — an inherited receipt stands only on the kept full receipt it names, and on a diff
233
+ // recomputed now: a path list written into the receipt is never trusted.
234
+ if (receipt.inheritedFrom) {
235
+ if (!inherit)
236
+ return { valid: false, reason: 'an inherited release test-lane receipt needs the publish-time diff to be checked' };
237
+ const full = readFullReceipt(root, now);
238
+ if (!full.ok)
239
+ return { valid: false, reason: full.reason };
240
+ const f = full.receipt;
241
+ if (f.head !== receipt.inheritedFrom.head || f.completedAt !== receipt.inheritedFrom.completedAt || f.digest !== receipt.inheritedFrom.digest) {
242
+ return { valid: false, reason: 'the inherited receipt does not name the kept full release test-lane receipt' };
243
+ }
244
+ const blocked = inheritableSince(f, head, inherit.git, inherit.shipped);
245
+ if (blocked !== null)
246
+ return { valid: false, reason: blocked };
247
+ }
108
248
  const completedMs = Date.parse(receipt.completedAt);
109
249
  if (!Number.isFinite(completedMs) || completedMs > now || now - completedMs > RELEASE_TEST_LANE_MAX_AGE_MS) {
110
250
  return { valid: false, reason: 'release test-lane receipt is stale or has an invalid timestamp' };
@@ -122,10 +262,17 @@ function normalizeReleaseTestLaneReceipt(root, input) {
122
262
  || typeof value.completedAt !== 'string' || !Number.isFinite(Date.parse(value.completedAt))
123
263
  || value.passed !== true || value.externalAccess !== 'forbidden')
124
264
  return null;
265
+ // @implements A-SPEC-748 — an inherited receipt names its full receipt and ran named docs tests; a full one keeps
266
+ // today's command requirements.
267
+ const from = value.inheritedFrom;
268
+ if (from !== undefined && (!from || typeof from.head !== 'string' || from.head === '' || /[\\/]/.test(from.head)
269
+ || typeof from.completedAt !== 'string' || !Number.isFinite(Date.parse(from.completedAt))
270
+ || typeof from.digest !== 'string' || !/^sha256:[0-9a-f]{64}$/.test(from.digest)))
271
+ return null;
125
272
  if (!Array.isArray(value.command) || value.command.some((part) => typeof part !== 'string' || part === '')
126
273
  || value.command.length < 5 || value.command[0] !== 'npm' || value.command[1] !== 'test'
127
274
  || value.command[2] !== '--' || !value.command.includes('--runInBand')
128
- || !value.command.some((part) => part.startsWith('--testPathIgnorePatterns=')))
275
+ || (from === undefined && !value.command.some((part) => part.startsWith('--testPathIgnorePatterns='))))
129
276
  return null;
130
277
  if (!Array.isArray(value.include) || value.include.length === 0 || value.include.some((part) => typeof part !== 'string' || part.trim() === ''))
131
278
  return null;
@@ -134,7 +281,8 @@ function normalizeReleaseTestLaneReceipt(root, input) {
134
281
  return null;
135
282
  const unsigned = { schema: exports.RELEASE_TEST_LANE_SCHEMA, root: rootPath, head: value.head, completedAt: value.completedAt,
136
283
  passed: true, externalAccess: 'forbidden', command: [...value.command], include: [...value.include],
137
- exclusions: value.exclusions.map((entry) => ({ pattern: entry.pattern, reason: entry.reason })) };
284
+ exclusions: value.exclusions.map((entry) => ({ pattern: entry.pattern, reason: entry.reason })),
285
+ ...(from !== undefined ? { inheritedFrom: { head: from.head, completedAt: from.completedAt, digest: from.digest } } : {}) };
138
286
  return { ...unsigned, digest: releaseReceiptDigest(unsigned) };
139
287
  }
140
288
  // @implements A-SPEC-562.1 — outcomes join the ledger's REPLICA convention (A-SPEC-148): one file per
@@ -115,6 +115,15 @@ export declare function accountChangedFiles(changedFiles: string[], scanEntry: (
115
115
  implementsSpecs: string[];
116
116
  symbolCount: number;
117
117
  } | undefined): ChangedFileAccount;
118
+ /**
119
+ * @implements A-SPEC-750 — one left-to-right pass over source, replacing the regex passes that stripped comments, then
120
+ * strings, in sequence (a `/*`, `//` or backtick inside a literal began a comment or a template there and swallowed the
121
+ * real case heads up to the next closer — measured 2026-10-01: 72 test files counted fewer cases than Jest ran).
122
+ * Strings become `""`, a template keeps only its `${…}` code, comments become a space, and (when `js`) a regex literal
123
+ * becomes `/x/`. A failed regex attempt disables attempts until the end of that line, so a long line costs one pass.
124
+ * Without `js`, a backtick string is a raw string with no interpolation and `/` is never a regex.
125
+ */
126
+ export declare function stripCode(src: string, js: boolean): string;
118
127
  /** Frameworks this counter understands, for diagnostics and tests. */
119
128
  export declare const SUPPORTED_TEST_FRAMEWORKS: string[];
120
129
  export declare function countTestCases(source: string, filePath?: string): number;
@@ -36,11 +36,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.SUPPORTED_TEST_FRAMEWORKS = void 0;
37
37
  exports.architectureGoverningFiles = architectureGoverningFiles;
38
38
  exports.accountChangedFiles = accountChangedFiles;
39
+ exports.stripCode = stripCode;
39
40
  exports.countTestCases = countTestCases;
40
41
  exports.extractAnchors = extractAnchors;
41
42
  exports.scanTestAnchors = scanTestAnchors;
42
43
  exports.computeTestScope = computeTestScope;
43
- // @implements A-SPEC-121.2, A-SPEC-734
44
+ // @implements A-SPEC-121.2, A-SPEC-734, A-SPEC-750
44
45
  const anchor_ids_1 = require("./anchor-ids");
45
46
  const fs = __importStar(require("node:fs"));
46
47
  const path = __importStar(require("node:path"));
@@ -143,11 +144,282 @@ function accountChangedFiles(changedFiles, scanEntry) {
143
144
  * wrappers or aliasing can still fabricate heads. Execution proof is the test RUNNER's job
144
145
  * (planTestRun/runTestScope); this counter only stops declared coverage over an absent/empty suite.
145
146
  */
146
- /** Strip block/line comments and string literals from C-family source. */
147
- const stripCFamily = (src) => src
148
- .replace(/\/\*[\s\S]*?\*\//g, ' ') // block comments
149
- .replace(/(^|[^:])\/\/[^\n]*/g, '$1 ') // line comments (not ://)
150
- .replace(/'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"|`(?:\\.|[^`\\])*`/g, '""');
147
+ /** Keywords after which a `/` starts a regex literal rather than a division. */
148
+ const REGEX_AFTER_KEYWORD = new Set(['return', 'typeof', 'instanceof', 'in', 'of', 'new', 'delete', 'void', 'throw', 'case', 'do',
149
+ 'else', 'yield', 'await']);
150
+ // Character classes by code: a regex test per character made the lexer seven times slower than the regex counter it
151
+ // replaces (measured 2026-10-02: 170 ms against 25 ms over the 648-file tree).
152
+ const isIdentStart = (cc) => (cc >= 97 && cc <= 122) || (cc >= 65 && cc <= 90) || cc === 95 || cc === 36 || cc > 127;
153
+ const isIdentPart = (cc) => isIdentStart(cc) || (cc >= 48 && cc <= 57);
154
+ const isSpace = (cc) => cc === 32 || cc === 10 || cc === 9 || cc === 13 || cc === 11 || cc === 12 || cc === 160;
155
+ const PLAIN_RUN = /[^/'"`{}]+/y;
156
+ /** Whether a `/` after the run src[from, to) may start a regex: by the run's last significant token, else `prev`. */
157
+ function regexOkAfterRun(src, from, to, prev) {
158
+ let k = to - 1;
159
+ while (k >= from && isSpace(src.charCodeAt(k)))
160
+ k--;
161
+ if (k < from)
162
+ return prev;
163
+ const cc = src.charCodeAt(k);
164
+ if (cc === 41 || cc === 93)
165
+ return false;
166
+ if (!isIdentPart(cc))
167
+ return true;
168
+ let w = k;
169
+ while (w > from && isIdentPart(src.charCodeAt(w - 1)))
170
+ w--;
171
+ const first = src.charCodeAt(w);
172
+ if (first >= 48 && first <= 57)
173
+ return false;
174
+ // Only a short word can be a keyword: slicing every identifier would cost more than the whole lexer.
175
+ return k - w < 10 && REGEX_AFTER_KEYWORD.has(src.slice(w, k + 1));
176
+ }
177
+ /** Index just past a quoted string starting at `i`; a string ends at its quote or at a newline. */
178
+ function endOfQuoted(src, i, quote) {
179
+ for (let j = i + 1; j < src.length; j++) {
180
+ const ch = src[j];
181
+ if (ch === '\\') {
182
+ j++;
183
+ continue;
184
+ }
185
+ if (ch === quote)
186
+ return j + 1;
187
+ if (ch === '\n')
188
+ return j;
189
+ }
190
+ return src.length;
191
+ }
192
+ /** From inside a template, the index after its closing backtick, or after the next `${` (interp = true). */
193
+ function scanTemplate(src, j) {
194
+ for (; j < src.length; j++) {
195
+ const ch = src[j];
196
+ if (ch === '\\') {
197
+ j++;
198
+ continue;
199
+ }
200
+ if (ch === '`')
201
+ return { next: j + 1, interp: false };
202
+ if (ch === '$' && src[j + 1] === '{')
203
+ return { next: j + 2, interp: true };
204
+ }
205
+ return { next: src.length, interp: false };
206
+ }
207
+ /** Index just past a regex literal starting at `i`, or -1 when none closes before the line ends. */
208
+ function endOfRegex(src, i) {
209
+ let inClass = false;
210
+ for (let j = i + 1; j < src.length; j++) {
211
+ const ch = src[j];
212
+ if (ch === '\n' || ch === '\r')
213
+ return -1;
214
+ if (ch === '\\') {
215
+ j++;
216
+ continue;
217
+ }
218
+ if (ch === '[')
219
+ inClass = true;
220
+ else if (ch === ']')
221
+ inClass = false;
222
+ else if (ch === '/' && !inClass) {
223
+ let k = j + 1;
224
+ while (k < src.length && /[A-Za-z]/.test(src[k]))
225
+ k++;
226
+ return k;
227
+ }
228
+ }
229
+ return -1;
230
+ }
231
+ /**
232
+ * @implements A-SPEC-750 — one left-to-right pass over source, replacing the regex passes that stripped comments, then
233
+ * strings, in sequence (a `/*`, `//` or backtick inside a literal began a comment or a template there and swallowed the
234
+ * real case heads up to the next closer — measured 2026-10-01: 72 test files counted fewer cases than Jest ran).
235
+ * Strings become `""`, a template keeps only its `${…}` code, comments become a space, and (when `js`) a regex literal
236
+ * becomes `/x/`. A failed regex attempt disables attempts until the end of that line, so a long line costs one pass.
237
+ * Without `js`, a backtick string is a raw string with no interpolation and `/` is never a regex.
238
+ */
239
+ function stripCode(src, js) {
240
+ const out = [];
241
+ const n = src.length;
242
+ let i = 0;
243
+ let start = 0;
244
+ let regexOk = true;
245
+ let regexOffUntil = -1;
246
+ const interp = [];
247
+ const emit = (text, next) => { out.push(src.slice(start, i), text); i = next; start = next; };
248
+ const template = (from, lead) => {
249
+ const t = scanTemplate(src, from);
250
+ if (t.interp) {
251
+ emit(lead + '${', t.next);
252
+ interp.push(0);
253
+ regexOk = true;
254
+ }
255
+ else {
256
+ emit(lead + '`', t.next);
257
+ regexOk = false;
258
+ }
259
+ };
260
+ while (i < n) {
261
+ const c = src[i];
262
+ if (c === '/' && src[i + 1] === '/') {
263
+ const e = src.indexOf('\n', i);
264
+ emit(' ', e < 0 ? n : e);
265
+ continue;
266
+ }
267
+ if (c === '/' && src[i + 1] === '*') {
268
+ const e = src.indexOf('*/', i + 2);
269
+ emit(' ', e < 0 ? n : e + 2);
270
+ continue;
271
+ }
272
+ if (c === '"' || c === "'") {
273
+ emit('""', endOfQuoted(src, i, c));
274
+ regexOk = false;
275
+ continue;
276
+ }
277
+ if (c === '`') {
278
+ if (js) {
279
+ template(i + 1, '`');
280
+ continue;
281
+ }
282
+ let j = i + 1;
283
+ while (j < n && src[j] !== '`')
284
+ j += src[j] === '\\' ? 2 : 1;
285
+ emit('""', Math.min(n, j + 1));
286
+ regexOk = false;
287
+ continue;
288
+ }
289
+ if (js && c === '}' && interp.length > 0 && interp[interp.length - 1] === 0) {
290
+ interp.pop();
291
+ template(i + 1, '}');
292
+ continue;
293
+ }
294
+ if (js && c === '/' && regexOk && i >= regexOffUntil) {
295
+ const e = endOfRegex(src, i);
296
+ if (e > 0) {
297
+ emit('/x/', e);
298
+ regexOk = false;
299
+ continue;
300
+ }
301
+ const nl = src.indexOf('\n', i);
302
+ regexOffUntil = nl < 0 ? n : nl;
303
+ i++;
304
+ regexOk = true;
305
+ continue;
306
+ }
307
+ // Everything but the six characters that open or close a literal, a comment or a brace is copied as one run; only
308
+ // its last significant token matters, for whether a following `/` may start a regex.
309
+ PLAIN_RUN.lastIndex = i;
310
+ if (PLAIN_RUN.test(src)) {
311
+ const j = PLAIN_RUN.lastIndex;
312
+ regexOk = regexOkAfterRun(src, i, j, regexOk);
313
+ i = j;
314
+ continue;
315
+ }
316
+ if (c === '{' && interp.length > 0)
317
+ interp[interp.length - 1]++;
318
+ else if (c === '}' && interp.length > 0)
319
+ interp[interp.length - 1]--;
320
+ regexOk = true;
321
+ i++;
322
+ }
323
+ out.push(src.slice(start, n));
324
+ return out.join('');
325
+ }
326
+ /** Index after spaces, tabs and newlines. */
327
+ function skipSpace(code, j) {
328
+ while (j < code.length && /\s/.test(code[j]))
329
+ j++;
330
+ return j;
331
+ }
332
+ /** Index just past the group opened at `j` (`(`, `[`, `{` or a stripped template), or the end of the code. */
333
+ function skipGroup(code, j) {
334
+ if (code[j] === '`') {
335
+ for (j++; j < code.length; j++) {
336
+ if (code[j] === '`')
337
+ return j + 1;
338
+ if (code[j] === '$' && code[j + 1] === '{')
339
+ j = skipGroup(code, j + 1) - 1;
340
+ }
341
+ return code.length;
342
+ }
343
+ let depth = 0;
344
+ for (; j < code.length; j++) {
345
+ const ch = code[j];
346
+ if (ch === '`') {
347
+ j = skipGroup(code, j) - 1;
348
+ continue;
349
+ }
350
+ if (ch === '(' || ch === '[' || ch === '{')
351
+ depth++;
352
+ else if (ch === ')' || ch === ']' || ch === '}') {
353
+ if (--depth === 0)
354
+ return j + 1;
355
+ }
356
+ }
357
+ return code.length;
358
+ }
359
+ const JEST_HEADS = ['it', 'test', 'fit'];
360
+ // @implements A-SPEC-653 — the platform helpers of A-SPEC-220.3 (`posixOnly('why')(…)`) are heads too: a POSIX-only suite
361
+ // written with the REPORTING skip must not read as "no real cases". `.skip` on a helper is still not a head.
362
+ const JEST_HELPERS = new Set(['posixOnly', 'posixOnlyNonRoot', 'posixOnlyWithCommand', 'win32Only']);
363
+ // @implements A-SPEC-750 — searched in the stripped CODE: a skip token inside a string or a comment (this counter's own tests
364
+ // hold several) no longer forfeits the file; one in code, including an alias line or any computed access, still does.
365
+ const JEST_SUITE_SKIP = /(?<![\w$.])describe\s*(?:\.\s*skip(?![\w$])|\[)|(?<![\w$])xdescribe(?![\w$])/;
366
+ const JEST_ALIAS_HINT = /=\s*(?:it|test|fit|posixOnly|posixOnlyNonRoot|posixOnlyWithCommand|win32Only)(?![\w$])/;
367
+ const JEST_ALIAS = /(?<![\w$.])(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=;]*)?=\s*(it|test|fit|posixOnly|posixOnlyNonRoot|posixOnlyWithCommand|win32Only)(?![\w$])/g;
368
+ /**
369
+ * Jest cases in stripped code: a standalone `it|test|fit` (or a same-file alias of one, or of a platform helper call)
370
+ * followed by `(`, or by `.each(…)(` / `.each` + template + `(`. Method calls (`re.test(`) never match: the head must not
371
+ * follow a `.`. `it.skip(`/`it.todo(`/`xit(` never match, so nothing is subtracted.
372
+ */
373
+ function jestCount(code) {
374
+ if (JEST_SUITE_SKIP.test(code))
375
+ return 0;
376
+ const direct = new Set(JEST_HEADS);
377
+ // Most files bind no alias; the declaration scan below visits every `const`, so it runs only when an alias can exist.
378
+ if (JEST_ALIAS_HINT.test(code))
379
+ for (const m of code.matchAll(JEST_ALIAS)) {
380
+ let j = m.index + m[0].length;
381
+ if (JEST_HELPERS.has(m[2])) {
382
+ j = skipSpace(code, j);
383
+ if (code[j] !== '(')
384
+ continue;
385
+ j = skipGroup(code, j);
386
+ }
387
+ while (j < code.length && (code[j] === ' ' || code[j] === '\t'))
388
+ j++;
389
+ if (j >= code.length || ';,\n\r}'.includes(code[j]))
390
+ direct.add(m[1]);
391
+ }
392
+ const names = [...direct, ...[...JEST_HELPERS].filter((h) => !direct.has(h))].map((s) => s.replace(/\$/g, '\\$'));
393
+ let cases = 0;
394
+ for (const m of code.matchAll(new RegExp(`(?<![\\w$.])(?:${names.join('|')})(?![\\w$])`, 'g'))) {
395
+ let j = m.index + m[0].length;
396
+ if (!direct.has(m[0])) {
397
+ j = skipSpace(code, j);
398
+ if (code[j] !== '(')
399
+ continue;
400
+ j = skipGroup(code, j);
401
+ }
402
+ j = skipSpace(code, j);
403
+ if (code[j] === '(') {
404
+ cases++;
405
+ continue;
406
+ }
407
+ if (code[j] !== '.')
408
+ continue;
409
+ let k = skipSpace(code, j + 1);
410
+ if (!code.startsWith('each', k) || /[\w$]/.test(code[k + 4] ?? ''))
411
+ continue;
412
+ k = skipSpace(code, k + 4);
413
+ if (code[k] !== '(' && code[k] !== '`')
414
+ continue;
415
+ k = skipSpace(code, skipGroup(code, k));
416
+ if (code[k] === '(')
417
+ cases++;
418
+ }
419
+ return cases;
420
+ }
421
+ /** Strip block/line comments and string literals from C-family source (no regex literals, no interpolation). */
422
+ const stripCFamily = (src) => stripCode(src, false);
151
423
  /** Strip `#` comments, docstrings and string literals from Python source. */
152
424
  const stripPython = (src) => src
153
425
  .replace(/'''[\s\S]*?'''|"""[\s\S]*?"""/g, '""') // docstrings first — they may contain #
@@ -168,14 +440,10 @@ const FRAMEWORKS = [
168
440
  {
169
441
  id: 'jest',
170
442
  ext: /\.(ts|mts|cts|tsx|jsx|js|mjs|cjs)$/i,
171
- strip: stripCFamily,
172
- suiteSkip: /\bdescribe\s*(?:\.\s*skip|\[\s*['"]skip['"]\s*\])|\bxdescribe\b/,
173
- // Head must be a STANDALONE identifier (not `.test(`/`.it(` method calls) followed directly by
174
- // `(` or by `.each(...)(`: `it.skip(`/`it.todo(`/`xit(` never match — no subtraction needed.
175
- // @implements A-SPEC-653 — the platform helpers of A-SPEC-220.3 (`posixOnly('why')(…)`) are heads too:
176
- // a POSIX-only suite written with the REPORTING skip must not read as "no real cases" (measured: that
177
- // is why two suites had used a bare early return instead). `.skip` on a helper is still not a head.
178
- head: /(?<![.\w])(?:it|test|fit|(?:posixOnly|posixOnlyNonRoot|posixOnlyWithCommand|win32Only)\s*\([^)]*\))(?:\s*\.\s*each\s*\([^)]*\)\s*)?\s*\(/g,
443
+ strip: (src) => stripCode(src, true),
444
+ suiteSkip: JEST_SUITE_SKIP,
445
+ head: /(?!)/g,
446
+ count: (src) => jestCount(stripCode(src, true)),
179
447
  },
180
448
  {
181
449
  id: 'pytest',
@@ -246,6 +514,8 @@ const ruleFor = (filePath) => (filePath && FRAMEWORKS.find((f) => f.ext.test(fil
246
514
  exports.SUPPORTED_TEST_FRAMEWORKS = FRAMEWORKS.map((f) => f.id);
247
515
  function countTestCases(source, filePath) {
248
516
  const rule = ruleFor(filePath);
517
+ if (rule.count)
518
+ return rule.count(source);
249
519
  const stripped = rule.strip(source);
250
520
  // Suite-skip detection runs on the ORIGINAL source: string-stripping turns `describe['skip'](`
251
521
  // into `describe[""](`, hiding the marker (round-2 test caught this). Comments are already
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "//": "@implements A-SPEC-209",
3
3
  "name": "@holmes-lab/holmes-kit",
4
- "version": "0.33.0",
4
+ "version": "0.35.0",
5
5
  "description": "Holmes-Kit — deterministic Agentic Software Engineering (ASE) harness with causal traceability (spec chain + D-CPG + RTM + phase guardrail)",
6
6
  "main": "dist/holmes/mcp/server.js",
7
7
  "types": "dist/holmes/mcp/server.d.ts",