@boyingliu01/xp-gate 0.38.78 → 0.38.80
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/adapters/gate-10.sh +16 -1
- package/adapters/gate-3.sh +20 -1
- package/adapters/gate-4.sh +16 -1
- package/gate-10.sh +16 -1
- package/gate-3.sh +20 -1
- package/gate-4.sh +16 -1
- package/gates/common.ts +18 -3
- package/gates/pbt-detect.ts +110 -30
- package/hooks/deploy-manifest.sh +1 -0
- package/hooks/gate-10.sh +16 -1
- package/hooks/gate-3.sh +20 -1
- package/hooks/gate-4.sh +16 -1
- package/hooks/lib/file-classifier.sh +77 -0
- package/lib/__tests__/crap.test.js +184 -0
- package/lib/__tests__/mirror-sync.test.js +83 -1
- package/lib/crap-cli.js +38 -3
- package/lib/crap.js +98 -7
- package/lib/deploy-manifest.js +1 -0
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/mirror-sync.js +93 -12
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
joinCoverage,
|
|
15
15
|
buildCrapReport,
|
|
16
16
|
isMirrorPath,
|
|
17
|
+
readFileCoverage,
|
|
17
18
|
} = require('../crap.js');
|
|
18
19
|
|
|
19
20
|
describe('crap.js - CRAP formula', () => {
|
|
@@ -135,3 +136,186 @@ describe('crap.js - mirror exclusion', () => {
|
|
|
135
136
|
expect(report.hotspots.map((h) => h.name)).toEqual(['mirrorFn', 'realFn']);
|
|
136
137
|
});
|
|
137
138
|
});
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @test REQ-CRAP-858 `xp-gate crap` must accept the coverage Node itself produces
|
|
142
|
+
* @intent #858: handleCrap only looked for istanbul's `coverage/coverage-final.json`.
|
|
143
|
+
* A project using Node's built-in runner —
|
|
144
|
+
*
|
|
145
|
+
* node --test --experimental-test-coverage
|
|
146
|
+
*
|
|
147
|
+
* — gets `coverage/coverage-summary.json` and NEVER a coverage-final.json,
|
|
148
|
+
* so `xp-gate crap` was permanently unavailable there, not merely
|
|
149
|
+
* "coverage not generated yet". Measured on a real repo whose Gate 5
|
|
150
|
+
* accepted the same artifact at 86.82% lines while CRAP said
|
|
151
|
+
* "No coverage artifact".
|
|
152
|
+
*
|
|
153
|
+
* Two artifacts, two shapes:
|
|
154
|
+
*
|
|
155
|
+
* istanbul coverage-final.json { "<abs path>": { s: { "<id>": count } } }
|
|
156
|
+
* node coverage-summary.json { "total": {...}, "<path>": { lines: {pct}, ... } }
|
|
157
|
+
*
|
|
158
|
+
* readFileCoverage knew only the first. Given the second it found no
|
|
159
|
+
* `entry.s` anywhere and returned an empty map — which surfaces as "every
|
|
160
|
+
* function unmeasured", indistinguishable from having no coverage at all.
|
|
161
|
+
*
|
|
162
|
+
* CRAP is the tool that finds "which function most needs a test", so the
|
|
163
|
+
* cost of this gap is the ranking itself: the repo's worst file
|
|
164
|
+
* (functions 25%) was diluted by an 86.82% overall figure that Gate 5
|
|
165
|
+
* passes, and CRAP was the only thing positioned to surface it.
|
|
166
|
+
*
|
|
167
|
+
* @covers AC-858-01 the Node summary format is read into per-file ratios
|
|
168
|
+
* @covers AC-858-02 istanbul output still reads exactly as before
|
|
169
|
+
* @covers AC-858-03 a file with no function data does not become a fabricated 0
|
|
170
|
+
* @covers AC-858-04 an unrecognised JSON shape yields no coverage, not bogus values
|
|
171
|
+
*/
|
|
172
|
+
describe('#858 readFileCoverage accepts Node coverage-summary.json', () => {
|
|
173
|
+
const fs = require('fs');
|
|
174
|
+
const os = require('os');
|
|
175
|
+
const path = require('path');
|
|
176
|
+
|
|
177
|
+
let dir;
|
|
178
|
+
beforeEach(() => {
|
|
179
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'crap858-'));
|
|
180
|
+
});
|
|
181
|
+
afterEach(() => {
|
|
182
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
function writeCoverage(name, payload) {
|
|
186
|
+
const p = path.join(dir, name);
|
|
187
|
+
fs.writeFileSync(p, JSON.stringify(payload));
|
|
188
|
+
return p;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
it('AC-858-01: reads node coverage-summary.json into per-file ratios', () => {
|
|
192
|
+
const file = writeCoverage('coverage-summary.json', {
|
|
193
|
+
total: { lines: { total: 100, covered: 80, pct: 80 } },
|
|
194
|
+
[`${dir}/tools.mjs`]: {
|
|
195
|
+
lines: { total: 100, covered: 52, pct: 52.26 },
|
|
196
|
+
branches: { total: 10, covered: 10, pct: 100 },
|
|
197
|
+
functions: { total: 4, covered: 1, pct: 25 },
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const coverage = readFileCoverage(file);
|
|
202
|
+
// The per-file ratio is keyed repo-relative, like the istanbul reader.
|
|
203
|
+
const key = [...coverage.keys()].find((k) => k.endsWith('tools.mjs'));
|
|
204
|
+
expect(key).toBeDefined();
|
|
205
|
+
// Node reports functions 25%; that is the factor CRAP needs.
|
|
206
|
+
expect(coverage.get(key)).toBeCloseTo(0.25, 2);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('AC-858-02: istanbul coverage-final.json still reads as before', () => {
|
|
210
|
+
const file = writeCoverage('coverage-final.json', {
|
|
211
|
+
[`${dir}/alpha.js`]: { s: { '0': 1, '1': 0, '2': 1, '3': 1 } },
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const coverage = readFileCoverage(file);
|
|
215
|
+
const key = [...coverage.keys()].find((k) => k.endsWith('alpha.js'));
|
|
216
|
+
expect(key).toBeDefined();
|
|
217
|
+
expect(coverage.get(key)).toBeCloseTo(0.75, 5);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('AC-858-03: an entry with no measurable data is skipped, not scored 0', () => {
|
|
221
|
+
// `total` carries no filename; a file entry with no functions/lines data
|
|
222
|
+
// must not be recorded as 0% -- that would push every such file to the top
|
|
223
|
+
// of the ranking on evidence that does not exist. Unmeasured is not zero.
|
|
224
|
+
const file = writeCoverage('coverage-summary.json', {
|
|
225
|
+
total: { lines: { total: 10, covered: 10, pct: 100 } },
|
|
226
|
+
[`${dir}/measured.mjs`]: { functions: { total: 2, covered: 1, pct: 50 } },
|
|
227
|
+
[`${dir}/empty.mjs`]: {},
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
const coverage = readFileCoverage(file);
|
|
231
|
+
expect([...coverage.keys()].some((k) => k.endsWith('measured.mjs'))).toBe(true);
|
|
232
|
+
expect([...coverage.keys()].some((k) => k.endsWith('empty.mjs'))).toBe(false);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('AC-858-03b: the "total" aggregate is not recorded as a file', () => {
|
|
236
|
+
// Node writes a "total" entry holding the whole-project ratio. It has no
|
|
237
|
+
// filename, and recording it put a phantom path in the map that no source
|
|
238
|
+
// file could ever match -- while reading, to a human, like a real measurement.
|
|
239
|
+
const file = writeCoverage('coverage-summary.json', {
|
|
240
|
+
total: { lines: { total: 100, covered: 80, pct: 80 } },
|
|
241
|
+
[`${dir}/real.mjs`]: { functions: { total: 4, covered: 1, pct: 25 } },
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const coverage = readFileCoverage(file);
|
|
245
|
+
expect(coverage.has('total')).toBe(false);
|
|
246
|
+
expect([...coverage.keys()].some((k) => k === 'total')).toBe(false);
|
|
247
|
+
expect(coverage.size).toBe(1);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('AC-858-03c: a POSIX-spelled absolute path is joinable, not ../../d/...', () => {
|
|
251
|
+
// Node on Windows writes "/d/projects/repo/src/x.mjs" while process.cwd() is
|
|
252
|
+
// "D:\projects\repo". Both pass path.isAbsolute, so path.relative compared two
|
|
253
|
+
// drive spellings and returned "../../d/projects/.../x.mjs" -- a key that
|
|
254
|
+
// matched no source file, making every function look unmeasured (#858).
|
|
255
|
+
// The fixture is derived from the real cwd so the assertion holds on any drive.
|
|
256
|
+
const cwd = process.cwd();
|
|
257
|
+
const drive = /^([A-Za-z]):/.exec(cwd);
|
|
258
|
+
if (!drive) {
|
|
259
|
+
// POSIX: no drive-letter mismatch to reproduce.
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const posixPath = `/${drive[1].toLowerCase()}${cwd.slice(2).split(path.sep).join('/')}/src/posixy.mjs`;
|
|
263
|
+
const file = writeCoverage('coverage-summary.json', {
|
|
264
|
+
total: { lines: { total: 1, covered: 1, pct: 100 } },
|
|
265
|
+
[posixPath]: { functions: { total: 4, covered: 1, pct: 25 } },
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const coverage = readFileCoverage(file);
|
|
269
|
+
const keys = [...coverage.keys()];
|
|
270
|
+
expect(keys).toEqual(['src/posixy.mjs']);
|
|
271
|
+
expect(coverage.get('src/posixy.mjs')).toBeCloseTo(0.25, 5);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('AC-858-04: an unrecognised JSON shape yields an empty map, never a guess', () => {
|
|
275
|
+
const file = writeCoverage('weird.json', { foo: 'bar', baz: [1, 2, 3] });
|
|
276
|
+
const coverage = readFileCoverage(file);
|
|
277
|
+
expect(coverage.size).toBe(0);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @test REQ-CRAP-858-B the CLI finds a Node coverage artifact without being told
|
|
283
|
+
* @intent Reading coverage-summary.json (above) is useless if handleCrap never
|
|
284
|
+
* looks for it. The default path was hardcoded to istanbul's
|
|
285
|
+
* coverage-final.json, so a project producing only the Node summary was
|
|
286
|
+
* told "No coverage artifact" while the file sat right there.
|
|
287
|
+
* Pinned separately because the reader and the discovery are two
|
|
288
|
+
* different failures with the same symptom.
|
|
289
|
+
* @covers AC-858-05 an existing coverage-summary.json is discovered
|
|
290
|
+
* @covers AC-858-06 istanbul still wins when both exist, and --coverage overrides
|
|
291
|
+
*/
|
|
292
|
+
describe('#858 discoverCoverageFile', () => {
|
|
293
|
+
const fs = require('fs');
|
|
294
|
+
const os = require('os');
|
|
295
|
+
const path = require('path');
|
|
296
|
+
const { discoverCoverageFile } = require('../crap-cli.js');
|
|
297
|
+
|
|
298
|
+
// vitest workers forbid process.chdir(), so the root is passed in. The
|
|
299
|
+
// production default is process.cwd(); that is exercised end-to-end below.
|
|
300
|
+
let dir;
|
|
301
|
+
beforeEach(() => {
|
|
302
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'crap858b-'));
|
|
303
|
+
fs.mkdirSync(path.join(dir, 'coverage'));
|
|
304
|
+
});
|
|
305
|
+
afterEach(() => {
|
|
306
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('AC-858-05: discovers coverage-summary.json when it is the only artifact', () => {
|
|
310
|
+
fs.writeFileSync(path.join(dir, 'coverage', 'coverage-summary.json'), '{}');
|
|
311
|
+
expect(discoverCoverageFile(null, dir)).toBe(path.join(dir, 'coverage', 'coverage-summary.json'));
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('AC-858-06: prefers istanbul when both exist, and --coverage always wins', () => {
|
|
315
|
+
fs.writeFileSync(path.join(dir, 'coverage', 'coverage-summary.json'), '{}');
|
|
316
|
+
fs.writeFileSync(path.join(dir, 'coverage', 'coverage-final.json'), '{}');
|
|
317
|
+
expect(discoverCoverageFile(null, dir)).toBe(path.join(dir, 'coverage', 'coverage-final.json'));
|
|
318
|
+
|
|
319
|
+
expect(discoverCoverageFile('/tmp/explicit.json')).toBe('/tmp/explicit.json');
|
|
320
|
+
});
|
|
321
|
+
});
|
|
@@ -20,7 +20,13 @@
|
|
|
20
20
|
const fs = require('fs');
|
|
21
21
|
const os = require('os');
|
|
22
22
|
const path = require('path');
|
|
23
|
-
const { execFileSync } =
|
|
23
|
+
// Deliberately the MODULE, not `const { execFileSync } = ...`: the spy in the
|
|
24
|
+
// "git invocations per pair" block has to replace `childProcess.execFileSync`,
|
|
25
|
+
// and a load-time destructure would keep calling the pre-spy binding. That is
|
|
26
|
+
// the same trap `init.test.js` documents — but there it was the SUBJECT holding
|
|
27
|
+
// the stale reference; here it is the test.
|
|
28
|
+
const childProcess = require('child_process');
|
|
29
|
+
const { execFileSync } = childProcess;
|
|
24
30
|
|
|
25
31
|
const {
|
|
26
32
|
collectMirrorPairs,
|
|
@@ -148,6 +154,82 @@ function trackCanonicalOnly(root, canonical) {
|
|
|
148
154
|
execFileSync('git', ['add', '--', '.gitignore', canonical], { cwd: root });
|
|
149
155
|
}
|
|
150
156
|
|
|
157
|
+
describe('diffTrees — git invocations per pair', () => {
|
|
158
|
+
/**
|
|
159
|
+
* Each `git` launch costs ~120ms on Windows (measured: 10 launches averaged
|
|
160
|
+
* 120ms). `diffTrees` used to launch one process per side, so every pair paid
|
|
161
|
+
* twice, and a test asserting three pairs paid six times. The count is the
|
|
162
|
+
* contract this block pins: it is the difference between a suite that finishes
|
|
163
|
+
* and one that does not, and it is invisible to any assertion about *results*.
|
|
164
|
+
*
|
|
165
|
+
* Counted by spying on the real module, not by timing: timing on this machine
|
|
166
|
+
* is noise-dominated (load 80-100%), the count is deterministic.
|
|
167
|
+
*/
|
|
168
|
+
let spawnCount;
|
|
169
|
+
|
|
170
|
+
beforeEach(() => {
|
|
171
|
+
spawnCount = 0;
|
|
172
|
+
const real = childProcess.execFileSync;
|
|
173
|
+
vi.spyOn(childProcess, 'execFileSync').mockImplementation((cmd, args, opts) => {
|
|
174
|
+
if (cmd === 'git') spawnCount += 1;
|
|
175
|
+
return real(cmd, args, opts);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
afterEach(() => {
|
|
180
|
+
vi.restoreAllMocks();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('reads both sides of one pair in a single git call', () => {
|
|
184
|
+
write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
|
|
185
|
+
write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
|
|
186
|
+
trackAll(TMP_REPO);
|
|
187
|
+
|
|
188
|
+
const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
|
|
189
|
+
expect(diff.inSync).toBe(true);
|
|
190
|
+
// One query for both sides. Two would still be correct, and that is exactly
|
|
191
|
+
// why this needs a test: nothing about the RESULT changes when it regresses.
|
|
192
|
+
expect(spawnCount).toBe(1);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('falls back to a disk walk when the directory is not a checkout', () => {
|
|
196
|
+
// The merged read added this branch: one failed `git ls-files` now has to
|
|
197
|
+
// answer for BOTH sides. If the fallback returned early for only one of them,
|
|
198
|
+
// the other side would compare a disk walk against an empty set and report
|
|
199
|
+
// every file as missing -- a crash-shaped bug dressed as drift.
|
|
200
|
+
const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'mirror-sync-nogit-'));
|
|
201
|
+
try {
|
|
202
|
+
fs.mkdirSync(path.join(outside, 'a'), { recursive: true });
|
|
203
|
+
fs.mkdirSync(path.join(outside, 'b'), { recursive: true });
|
|
204
|
+
fs.writeFileSync(path.join(outside, 'a', 'x.sh'), 'echo x\n');
|
|
205
|
+
fs.writeFileSync(path.join(outside, 'b', 'x.sh'), 'echo x\n');
|
|
206
|
+
|
|
207
|
+
expect(diffTrees(outside, 'a', 'b').inSync).toBe(true);
|
|
208
|
+
|
|
209
|
+
fs.writeFileSync(path.join(outside, 'b', 'x.sh'), 'echo DIFFERENT\n');
|
|
210
|
+
const bad = diffTrees(outside, 'a', 'b');
|
|
211
|
+
expect(bad.inSync).toBe(false);
|
|
212
|
+
expect(bad.differing).toEqual(['x.sh']);
|
|
213
|
+
expect(bad.missing).toEqual([]);
|
|
214
|
+
} finally {
|
|
215
|
+
fs.rmSync(outside, { recursive: true, force: true });
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('does not grow linearly when the caller asks about several pairs', () => {
|
|
220
|
+
write(TMP_REPO, 'c1/a.sh', 'echo a\n');
|
|
221
|
+
write(TMP_REPO, 'm1/a.sh', 'echo a\n');
|
|
222
|
+
write(TMP_REPO, 'c2/b.sh', 'echo b\n');
|
|
223
|
+
write(TMP_REPO, 'm2/b.sh', 'echo b\n');
|
|
224
|
+
trackAll(TMP_REPO);
|
|
225
|
+
|
|
226
|
+
expect(diffTrees(TMP_REPO, 'c1', 'm1').inSync).toBe(true);
|
|
227
|
+
expect(spawnCount).toBe(1);
|
|
228
|
+
expect(diffTrees(TMP_REPO, 'c2', 'm2').inSync).toBe(true);
|
|
229
|
+
expect(spawnCount).toBe(2);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
151
233
|
describe('diffTrees — AC-713-01 untracked artifacts are not drift', () => {
|
|
152
234
|
it('ignores an untracked build artifact in the canonical tree', () => {
|
|
153
235
|
write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
|
package/lib/crap-cli.js
CHANGED
|
@@ -41,12 +41,37 @@ every untested file at the top of the ranking; treating them as 100% would hide
|
|
|
41
41
|
them.
|
|
42
42
|
`;
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Pick the coverage artifact to read when --coverage was not given.
|
|
46
|
+
*
|
|
47
|
+
* #858: this used to be hardcoded to coverage/coverage-final.json, which only
|
|
48
|
+
* istanbul-shaped tools (vitest, jest, nyc) write. Node's built-in
|
|
49
|
+
* `--experimental-test-coverage` writes coverage/coverage-summary.json and never
|
|
50
|
+
* the other file, so on such a project CRAP was permanently unavailable rather
|
|
51
|
+
* than merely waiting for coverage to be generated.
|
|
52
|
+
*
|
|
53
|
+
* Order: an explicit --coverage, then istanbul (richer, per-statement), then the
|
|
54
|
+
* Node summary. Returning the istanbul path when NEITHER exists is deliberate --
|
|
55
|
+
* that is the path the error message names, and it is the more common layout.
|
|
56
|
+
*/
|
|
57
|
+
function discoverCoverageFile(explicit, cwd) {
|
|
58
|
+
if (explicit) return explicit;
|
|
59
|
+
const coverageDir = path.join(cwd || process.cwd(), 'coverage');
|
|
60
|
+
const candidates = ['coverage-final.json', 'coverage-summary.json'];
|
|
61
|
+
for (const name of candidates) {
|
|
62
|
+
const candidate = path.join(coverageDir, name);
|
|
63
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
64
|
+
}
|
|
65
|
+
return path.join(coverageDir, candidates[0]);
|
|
66
|
+
}
|
|
67
|
+
|
|
44
68
|
function parseArgs(argv) {
|
|
45
69
|
const opts = {
|
|
46
70
|
top: 20,
|
|
47
71
|
threshold: 6,
|
|
48
72
|
json: false,
|
|
49
|
-
|
|
73
|
+
// #858: discovered after parsing, not fixed here. `--coverage` still wins.
|
|
74
|
+
coverage: null,
|
|
50
75
|
paths: ['src'],
|
|
51
76
|
includeMirrors: false,
|
|
52
77
|
help: false,
|
|
@@ -161,9 +186,19 @@ async function handleCrap(argv) {
|
|
|
161
186
|
return 1;
|
|
162
187
|
}
|
|
163
188
|
|
|
189
|
+
opts.coverage = discoverCoverageFile(opts.coverage);
|
|
190
|
+
|
|
164
191
|
if (!fs.existsSync(opts.coverage)) {
|
|
192
|
+
// #858: name the artifact that WOULD have been accepted. A user on Node's own
|
|
193
|
+
// runner is told "npx vitest run --coverage" and reasonably concludes CRAP
|
|
194
|
+
// needs vitest — but the file `node --test --experimental-test-coverage`
|
|
195
|
+
// writes is one this tool now reads. Only suggesting vitest turned a format
|
|
196
|
+
// gap into a "you picked the wrong test runner" answer.
|
|
165
197
|
console.error(`✗ No coverage artifact at ${opts.coverage}`);
|
|
166
|
-
console.error('
|
|
198
|
+
console.error(' Generate one with either runner:');
|
|
199
|
+
console.error(' npx vitest run --coverage -> coverage/coverage-final.json');
|
|
200
|
+
console.error(' node --test --experimental-test-coverage -> coverage/coverage-summary.json');
|
|
201
|
+
console.error(' Both formats are read; pass either one with --coverage <file>.');
|
|
167
202
|
console.error(' (Without it every function is unmeasured, which is not a ranking.)');
|
|
168
203
|
return 1;
|
|
169
204
|
}
|
|
@@ -188,4 +223,4 @@ async function handleCrap(argv) {
|
|
|
188
223
|
return 0;
|
|
189
224
|
}
|
|
190
225
|
|
|
191
|
-
module.exports = { handleCrap, parseArgs, render, runLizard };
|
|
226
|
+
module.exports = { handleCrap, parseArgs, render, runLizard, discoverCoverageFile };
|
package/lib/crap.js
CHANGED
|
@@ -66,6 +66,33 @@ function toRepoRelative(filePath) {
|
|
|
66
66
|
return String(filePath).split('\\').join('/').replace(/^\.\//, '');
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Make a coverage artifact's absolute path comparable to `root`.
|
|
71
|
+
*
|
|
72
|
+
* Node writes POSIX-style absolute paths even on Windows:
|
|
73
|
+
*
|
|
74
|
+
* "/d/projects/repo/src/x.mjs" (what coverage-summary.json holds)
|
|
75
|
+
* "D:\\projects\\repo\\src\\x.mjs" (what process.cwd() holds)
|
|
76
|
+
*
|
|
77
|
+
* `path.isAbsolute` accepts the first form on win32, so the artifact path took
|
|
78
|
+
* the "is absolute" branch — and `path.relative` then compared two different
|
|
79
|
+
* drive spellings and produced `../../d/projects/repo/src/x.mjs`, a key that
|
|
80
|
+
* matches no source file. Measured: `xp-gate crap` read the coverage map and
|
|
81
|
+
* still reported every function unmeasured.
|
|
82
|
+
*
|
|
83
|
+
* Converting `/x/...` to `x:\...` before relativising is what makes the two forms
|
|
84
|
+
* agree. On POSIX this is a no-op, because the root and the artifact are then
|
|
85
|
+
* spelled the same way already.
|
|
86
|
+
*/
|
|
87
|
+
function relativiseArtifactPath(absPath, root) {
|
|
88
|
+
const asPosixDrive = /^\/([A-Za-z])\//.exec(absPath);
|
|
89
|
+
if (process.platform === 'win32' && asPosixDrive) {
|
|
90
|
+
const drivePath = `${asPosixDrive[1].toUpperCase()}:${absPath.slice(2).split('/').join('\\')}`;
|
|
91
|
+
return path.relative(root, drivePath);
|
|
92
|
+
}
|
|
93
|
+
return path.relative(root, absPath);
|
|
94
|
+
}
|
|
95
|
+
|
|
69
96
|
/**
|
|
70
97
|
* Attach each function's file coverage and CRAP score.
|
|
71
98
|
*
|
|
@@ -127,7 +154,54 @@ function buildCrapReport(functions, options = {}) {
|
|
|
127
154
|
}
|
|
128
155
|
|
|
129
156
|
/**
|
|
130
|
-
*
|
|
157
|
+
* Per-file coverage ratio read out of ONE Node `coverage-summary.json` entry.
|
|
158
|
+
*
|
|
159
|
+
* Node reports several metrics per file; the function ratio is the one CRAP
|
|
160
|
+
* needs, because CRAP ranks functions. Falling back through functions -> lines ->
|
|
161
|
+
* branches is deliberate: a file with no function data but real line data is
|
|
162
|
+
* still partly measured, while a file with none of the three is not measured at
|
|
163
|
+
* all and must stay absent (see AC-858-03 — recording it as 0 would put every
|
|
164
|
+
* such file at the top of a ranking built on no evidence).
|
|
165
|
+
*
|
|
166
|
+
* @returns {number|null} ratio in [0,1], or null when the entry holds no metric
|
|
167
|
+
*/
|
|
168
|
+
function ratioFromNodeSummary(entry) {
|
|
169
|
+
if (!entry || typeof entry !== 'object') return null;
|
|
170
|
+
for (const metric of ['functions', 'lines', 'branches', 'statements']) {
|
|
171
|
+
const m = entry[metric];
|
|
172
|
+
if (!m || typeof m !== 'object') continue;
|
|
173
|
+
// `pct` is a percentage; `total`/`covered` are the raw counts the percentage
|
|
174
|
+
// was derived from. Prefer the counts (no rounding), fall back to pct.
|
|
175
|
+
if (typeof m.covered === 'number' && typeof m.total === 'number' && m.total > 0) {
|
|
176
|
+
return m.covered / m.total;
|
|
177
|
+
}
|
|
178
|
+
if (typeof m.pct === 'number' && Number.isFinite(m.pct)) {
|
|
179
|
+
// Node writes 100 for "nothing to measure" as well as for full coverage.
|
|
180
|
+
// A zero total is not full coverage; it is no measurement.
|
|
181
|
+
if (m.total === 0) return null;
|
|
182
|
+
return m.pct / 100;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Read per-file coverage ratios out of a coverage artifact.
|
|
190
|
+
*
|
|
191
|
+
* Two shapes are accepted, because two tools produce them and both are normal:
|
|
192
|
+
*
|
|
193
|
+
* istanbul / vitest coverage/coverage-final.json
|
|
194
|
+
* { "<abs path>": { s: { "<stmt id>": count } } }
|
|
195
|
+
*
|
|
196
|
+
* Node built-in coverage/coverage-summary.json
|
|
197
|
+
* { "total": {...}, "<path>": { lines: {pct}, functions: {pct}, ... } }
|
|
198
|
+
* produced by `node --test --experimental-test-coverage`
|
|
199
|
+
*
|
|
200
|
+
* #858: only the first was understood. A project on Node's own runner therefore
|
|
201
|
+
* got "No coverage artifact" forever — its Gate 5 could accept the very same file
|
|
202
|
+
* at 86.82% while CRAP called coverage absent. case 2 is the one this function
|
|
203
|
+
* exists for.
|
|
204
|
+
*
|
|
131
205
|
* Missing or unreadable input yields an empty map, which surfaces as "every
|
|
132
206
|
* function unmeasured" rather than as a silently perfect score.
|
|
133
207
|
*/
|
|
@@ -149,14 +223,31 @@ function readFileCoverage(coverageFile) {
|
|
|
149
223
|
|
|
150
224
|
const root = process.cwd();
|
|
151
225
|
for (const [absPath, entry] of Object.entries(parsed)) {
|
|
152
|
-
if (!entry ||
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
226
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
227
|
+
|
|
228
|
+
// `total` is Node's aggregate across every file, not a file. Recording it
|
|
229
|
+
// would put a phantom entry in the map under a key no source path can match,
|
|
230
|
+
// and worse, it reads as a real measurement (#858).
|
|
231
|
+
if (absPath === 'total') continue;
|
|
232
|
+
|
|
233
|
+
let ratio;
|
|
234
|
+
if (entry.s) {
|
|
235
|
+
// istanbul: statement hit counts. Unchanged behaviour (#858 AC-02).
|
|
236
|
+
const counts = Object.values(entry.s);
|
|
237
|
+
if (!counts.length) continue;
|
|
238
|
+
const covered = counts.filter((c) => c > 0).length;
|
|
239
|
+
ratio = covered / counts.length;
|
|
240
|
+
} else {
|
|
241
|
+
// Node summary. A file entry with no metric stays absent rather than
|
|
242
|
+
// becoming a fabricated 0.
|
|
243
|
+
ratio = ratioFromNodeSummary(entry);
|
|
244
|
+
}
|
|
245
|
+
if (ratio === null || ratio === undefined) continue;
|
|
246
|
+
|
|
156
247
|
const rel = path.isAbsolute(absPath)
|
|
157
|
-
? toRepoRelative(
|
|
248
|
+
? toRepoRelative(relativiseArtifactPath(absPath, root))
|
|
158
249
|
: toRepoRelative(absPath);
|
|
159
|
-
coverage.set(rel,
|
|
250
|
+
coverage.set(rel, ratio);
|
|
160
251
|
}
|
|
161
252
|
return coverage;
|
|
162
253
|
}
|
package/lib/deploy-manifest.js
CHANGED
package/lib/mirror-sync.js
CHANGED
|
@@ -28,7 +28,11 @@
|
|
|
28
28
|
|
|
29
29
|
const fs = require('fs');
|
|
30
30
|
const path = require('path');
|
|
31
|
-
|
|
31
|
+
// Module reference, not a destructure. A load-time copy binds the function once,
|
|
32
|
+
// so a later spy on the module property never reaches it -- which is exactly how
|
|
33
|
+
// the git-invocation count is measured here. A test that cannot observe the call
|
|
34
|
+
// cannot pin it, and an unpinned call count drifts back to one-per-side unnoticed.
|
|
35
|
+
const childProcess = require('child_process');
|
|
32
36
|
|
|
33
37
|
/**
|
|
34
38
|
* The checkout root, derived from this file's location rather than from the
|
|
@@ -237,7 +241,7 @@ function listFiles(root, dir) {
|
|
|
237
241
|
function isIgnored(root, dir) {
|
|
238
242
|
const normalised = dir.replace(/\\/g, '/');
|
|
239
243
|
try {
|
|
240
|
-
execFileSync('git', ['check-ignore', '--no-index', '-q', '--', normalised], {
|
|
244
|
+
childProcess.execFileSync('git', ['check-ignore', '--no-index', '-q', '--', normalised], {
|
|
241
245
|
cwd: root,
|
|
242
246
|
stdio: 'ignore',
|
|
243
247
|
});
|
|
@@ -272,22 +276,49 @@ function isIgnored(root, dir) {
|
|
|
272
276
|
* @param {string} dir directory relative to root
|
|
273
277
|
* @returns {string[]}
|
|
274
278
|
*/
|
|
279
|
+
/**
|
|
280
|
+
* Split raw `git ls-files -z` output into repo-relative path names.
|
|
281
|
+
*
|
|
282
|
+
* `-z` terminates every record with NUL and escapes nothing, so the only parsing
|
|
283
|
+
* is the split. Kept separate from the process call so the merging path below can
|
|
284
|
+
* reuse it on one query covering several directories.
|
|
285
|
+
*
|
|
286
|
+
* @param {string} out stdout from `git ls-files -z`
|
|
287
|
+
* @returns {string[]}
|
|
288
|
+
*/
|
|
289
|
+
function parseLsFiles(out) {
|
|
290
|
+
return out
|
|
291
|
+
.split('\0')
|
|
292
|
+
.filter(Boolean)
|
|
293
|
+
.map((p) => p.replace(/\\/g, '/'));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Keep the entries under `dir` as paths relative to it, minus excluded segments.
|
|
298
|
+
*
|
|
299
|
+
* @param {string[]} repoPaths repo-relative paths
|
|
300
|
+
* @param {string} dir directory whose subtree to extract
|
|
301
|
+
* @returns {string[]}
|
|
302
|
+
*/
|
|
303
|
+
function underDir(repoPaths, dir) {
|
|
304
|
+
const normalised = dir.replace(/\\/g, '/');
|
|
305
|
+
return repoPaths
|
|
306
|
+
.filter((p) => p.startsWith(`${normalised}/`))
|
|
307
|
+
.map((p) => p.slice(normalised.length + 1))
|
|
308
|
+
.filter((p) => !p.split('/').some((seg) => MIRROR_EXCLUDES.includes(seg)));
|
|
309
|
+
}
|
|
310
|
+
|
|
275
311
|
function listTrackedFiles(root, dir) {
|
|
276
312
|
const normalised = dir.replace(/\\/g, '/');
|
|
313
|
+
void normalised;
|
|
277
314
|
let tracked;
|
|
278
315
|
try {
|
|
279
|
-
const out = execFileSync('git', ['ls-files', '-z', '--', dir], {
|
|
316
|
+
const out = childProcess.execFileSync('git', ['ls-files', '-z', '--', dir], {
|
|
280
317
|
cwd: root,
|
|
281
318
|
encoding: 'utf8',
|
|
282
319
|
maxBuffer: 64 * 1024 * 1024,
|
|
283
320
|
});
|
|
284
|
-
tracked = out
|
|
285
|
-
.split('\0')
|
|
286
|
-
.filter(Boolean)
|
|
287
|
-
.map((p) => p.replace(/\\/g, '/'))
|
|
288
|
-
.filter((p) => p.startsWith(`${normalised}/`))
|
|
289
|
-
.map((p) => p.slice(normalised.length + 1))
|
|
290
|
-
.filter((p) => !p.split('/').some((seg) => MIRROR_EXCLUDES.includes(seg)));
|
|
321
|
+
tracked = underDir(parseLsFiles(out), dir);
|
|
291
322
|
} catch {
|
|
292
323
|
return listFiles(root, dir);
|
|
293
324
|
}
|
|
@@ -309,6 +340,55 @@ function listTrackedFiles(root, dir) {
|
|
|
309
340
|
.sort();
|
|
310
341
|
}
|
|
311
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Read the tracked file set of BOTH sides of a pair in one `git` launch.
|
|
345
|
+
*
|
|
346
|
+
* `git ls-files -- <a> <b>` answers for both paths at once, so a pair costs one
|
|
347
|
+
* process instead of two. On Windows a launch is ~120ms (measured: ten averaged
|
|
348
|
+
* 120ms), and a suite comparing seven pairs paid it fourteen times per run
|
|
349
|
+
* (twenty-eight when the ignored-tree fallback fired). Nothing about the RESULT
|
|
350
|
+
* changes, which is why `diffTrees`' own tests would never notice the regression
|
|
351
|
+
* -- the count is pinned separately.
|
|
352
|
+
*
|
|
353
|
+
* Falls back to the per-side function when git is unavailable, so a non-repo
|
|
354
|
+
* caller degrades exactly as before.
|
|
355
|
+
*
|
|
356
|
+
* @param {string} root repository root
|
|
357
|
+
* @param {string} canonical canonical dir (relative)
|
|
358
|
+
* @param {string} mirror mirror dir (relative)
|
|
359
|
+
* @returns {{canonical: string[], mirror: string[]}}
|
|
360
|
+
*/
|
|
361
|
+
function readBothSides(root, canonical, mirror) {
|
|
362
|
+
let repoPaths;
|
|
363
|
+
try {
|
|
364
|
+
const out = childProcess.execFileSync('git', ['ls-files', '-z', '--', canonical, mirror], {
|
|
365
|
+
cwd: root,
|
|
366
|
+
encoding: 'utf8',
|
|
367
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
368
|
+
});
|
|
369
|
+
repoPaths = parseLsFiles(out);
|
|
370
|
+
} catch {
|
|
371
|
+
return {
|
|
372
|
+
canonical: listTrackedFiles(root, canonical),
|
|
373
|
+
mirror: listTrackedFiles(root, mirror),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const collect = (dir) => {
|
|
378
|
+
const tracked = underDir(repoPaths, dir);
|
|
379
|
+
// An ignored tree has nothing tracked by design; asking git again would only
|
|
380
|
+
// repeat "no answer" at the cost of another process. See listTrackedFiles.
|
|
381
|
+
if (tracked.length === 0 && isIgnored(root, dir)) {
|
|
382
|
+
return listFiles(root, dir).filter(
|
|
383
|
+
(p) => !p.split('/').some((seg) => MIRROR_EXCLUDES.includes(seg))
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
return tracked.filter((p) => fs.existsSync(path.join(root, dir, p))).sort();
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
return { canonical: collect(canonical), mirror: collect(mirror) };
|
|
390
|
+
}
|
|
391
|
+
|
|
312
392
|
/**
|
|
313
393
|
* Compare a canonical tree against its mirror.
|
|
314
394
|
*
|
|
@@ -329,8 +409,9 @@ function diffTrees(root, canonical, mirror, options = {}) {
|
|
|
329
409
|
// passing `exclude: ['dist']` must not silently re-enable `__tests__`.
|
|
330
410
|
const exclude = [...MIRROR_EXCLUDES, ...(options.exclude || [])];
|
|
331
411
|
const keep = (rel) => !rel.split('/').some((seg) => exclude.includes(seg));
|
|
332
|
-
const
|
|
333
|
-
const
|
|
412
|
+
const both = readBothSides(root, canonical, mirror);
|
|
413
|
+
const canonicalFiles = both.canonical.filter(keep);
|
|
414
|
+
const mirrorFiles = both.mirror.filter(keep);
|
|
334
415
|
const mirrorSet = new Set(mirrorFiles);
|
|
335
416
|
const canonicalSet = new Set(canonicalFiles);
|
|
336
417
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xp-gate",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.80",
|
|
4
4
|
"displayName": "XP-Gate",
|
|
5
5
|
"description": "Extreme Programming quality gates + AI workflow skills for Claude Code. Includes 12 pre-commit gates (Gate 0-11), 8 pre-push gates, Sprint Flow (6 phases), and Delphi multi-expert review (>=90% consensus).",
|
|
6
6
|
"author": {
|