@boyingliu01/xp-gate 0.38.75 → 0.38.77
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/lib/__tests__/mirror-sync.test.js +387 -5
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/mirror-sync.js +202 -15
- 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/lib/hooks.d.ts +10 -1
- package/plugins/dsh/lib/hooks.d.ts.map +1 -1
- package/plugins/dsh/lib/hooks.js +56 -5
- package/plugins/dsh/lib/index.js +6 -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/dsh/src/hooks.test.ts +70 -0
- package/plugins/dsh/src/hooks.ts +66 -5
- package/plugins/dsh/src/index.ts +6 -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/scripts/generate-mirrors.cjs +10 -0
- 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
- package/mock-policy/__tests__/config.test.ts +0 -292
- package/mock-policy/__tests__/gate-m3.test.ts +0 -379
- package/mock-policy/__tests__/integration.test.ts +0 -600
- package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
- package/mock-policy/__tests__/schema.test.ts +0 -239
- package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
- package/mutation/__tests__/detect-ai-test.test.ts +0 -152
- package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
- package/mutation/__tests__/gate-m.test.ts +0 -246
- package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
- package/mutation/__tests__/gremlins-runner.test.ts +0 -167
- package/mutation/__tests__/init-baseline.test.ts +0 -347
- package/mutation/__tests__/mutation-mirror.test.ts +0 -49
- package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
- package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
- package/mutation/__tests__/pitest-runner.test.ts +0 -574
- package/mutation/__tests__/runners-index.test.ts +0 -162
- package/mutation/__tests__/stryker-runner.test.ts +0 -455
- package/mutation/__tests__/test-filter-parity.test.ts +0 -40
- package/mutation/__tests__/update-baseline.test.ts +0 -395
- package/principles/__tests__/adapter-metrics.test.ts +0 -292
- package/principles/__tests__/analyze-read-failure.test.ts +0 -70
- package/principles/__tests__/analyzer.test.ts +0 -367
- package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
- package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
- package/principles/__tests__/baseline-prune.test.ts +0 -399
- package/principles/__tests__/baseline-storage.test.ts +0 -188
- package/principles/__tests__/baseline.test.ts +0 -330
- package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
- package/principles/__tests__/boy-scout-integration.test.ts +0 -355
- package/principles/__tests__/boy-scout.test.ts +0 -893
- package/principles/__tests__/cli-files-separators.test.ts +0 -69
- package/principles/__tests__/config-arch-group.test.ts +0 -106
- package/principles/__tests__/config-enforcement.test.ts +0 -470
- package/principles/__tests__/config-git-timeout.test.ts +0 -66
- package/principles/__tests__/config-merge-warnings.test.ts +0 -148
- package/principles/__tests__/config.test.ts +0 -78
- package/principles/__tests__/direct-execution.test.ts +0 -187
- package/principles/__tests__/index.test.ts +0 -94
- package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
- package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
- package/principles/__tests__/lint-baseline.test.ts +0 -314
- package/principles/__tests__/many-exports-reexport.test.ts +0 -40
- package/principles/__tests__/reporter.test.ts +0 -660
- package/principles/__tests__/types.test.ts +0 -103
- package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
- package/principles/adapters/__tests__/base.test.ts +0 -95
- package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
- package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
- package/principles/adapters/__tests__/cpp.test.ts +0 -290
- package/principles/adapters/__tests__/dart.test.ts +0 -84
- package/principles/adapters/__tests__/go.test.ts +0 -68
- package/principles/adapters/__tests__/java.test.ts +0 -385
- package/principles/adapters/__tests__/kotlin.test.ts +0 -76
- package/principles/adapters/__tests__/objectivec.test.ts +0 -453
- package/principles/adapters/__tests__/python.test.ts +0 -84
- package/principles/adapters/__tests__/swift.test.ts +0 -68
- package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
- package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
- package/principles/adapters/__tests__/typescript.test.ts +0 -116
- package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
- package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
- package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
- package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
- package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
- package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
- package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
- package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
- package/principles/rules/__tests__/index.test.ts +0 -49
- package/principles/rules/__tests__/solid/dip.test.ts +0 -119
- package/principles/rules/__tests__/solid/isp.test.ts +0 -58
- package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
- package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
- package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
- package/principles/rules/__tests__/solid/srp.test.ts +0 -87
- package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
- package/principles/rules/arch/__tests__/naming.test.ts +0 -133
- package/principles/rules/arch/__tests__/shared.test.ts +0 -113
|
@@ -28,8 +28,42 @@ const {
|
|
|
28
28
|
syncMirrors,
|
|
29
29
|
handleSyncMirrors,
|
|
30
30
|
SYNC_EXCLUDES,
|
|
31
|
+
KNOWN_PAIRS,
|
|
32
|
+
HAND_LISTED_PAIRS,
|
|
33
|
+
assertPairsResolved,
|
|
31
34
|
} = require('../mirror-sync');
|
|
32
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Directories that are mirrors of a canonical tree rather than this package's own
|
|
38
|
+
* source.
|
|
39
|
+
*
|
|
40
|
+
* `bin/`, `lib/` and `scripts/` are the package's own code, not copies.
|
|
41
|
+
*
|
|
42
|
+
* `hooks/`, `plugins/` and `gates/` are supervised ELSEWHERE and are deliberately
|
|
43
|
+
* omitted here rather than being reported as unsupervised:
|
|
44
|
+
* - `hooks/` -> HOOK_MIRROR_FILES in scripts/check-hook-mirror.sh (a curated
|
|
45
|
+
* file list, not the whole tree; same reason KNOWN_PAIRS omits it)
|
|
46
|
+
* - `plugins/`-> syncPlugins in sync-package-content.js
|
|
47
|
+
* - `gates/` -> listed in files[] but the directory does not exist at all, so
|
|
48
|
+
* there is nothing to compare. Left alone: removing a stale
|
|
49
|
+
* files[] entry is a packaging change, not a mirror one.
|
|
50
|
+
* Including them would make this case report three permanent failures that no
|
|
51
|
+
* mirror work could ever fix.
|
|
52
|
+
*/
|
|
53
|
+
const MIRROR_DIR_CANDIDATES = [
|
|
54
|
+
'adapters',
|
|
55
|
+
'skills',
|
|
56
|
+
'principles',
|
|
57
|
+
'mutation',
|
|
58
|
+
'mock-policy',
|
|
59
|
+
'build-integrity',
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
/** Package-relative mirror dirs supervised by an explicit pair, not a generator. */
|
|
63
|
+
const HAND_LISTED_MIRRORS = HAND_LISTED_PAIRS.map((pair) =>
|
|
64
|
+
pair.mirror.replace(/^src\/npm-package\//, '')
|
|
65
|
+
);
|
|
66
|
+
|
|
33
67
|
let TMP_REPO;
|
|
34
68
|
|
|
35
69
|
/**
|
|
@@ -99,6 +133,21 @@ function trackAll(root) {
|
|
|
99
133
|
execFileSync('git', ['add', '-A', '-f'], { cwd: root });
|
|
100
134
|
}
|
|
101
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Stage the canonical tree and `.gitignore`, leaving the mirror untracked.
|
|
138
|
+
*
|
|
139
|
+
* `trackAll` cannot be used for the generated-mirror cases: its `-f` overrides
|
|
140
|
+
* `.gitignore`, so `mirror/` gets staged and the "the mirror is untracked" premise
|
|
141
|
+
* disappears. Verified in a scratch repo: `git add -A -f` lists `mirror/a.sh` in
|
|
142
|
+
* `git ls-files` even with `mirror/` ignored.
|
|
143
|
+
*
|
|
144
|
+
* @param {string} root
|
|
145
|
+
* @param {string} canonical directory to track
|
|
146
|
+
*/
|
|
147
|
+
function trackCanonicalOnly(root, canonical) {
|
|
148
|
+
execFileSync('git', ['add', '--', '.gitignore', canonical], { cwd: root });
|
|
149
|
+
}
|
|
150
|
+
|
|
102
151
|
describe('diffTrees — AC-713-01 untracked artifacts are not drift', () => {
|
|
103
152
|
it('ignores an untracked build artifact in the canonical tree', () => {
|
|
104
153
|
write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
|
|
@@ -150,23 +199,140 @@ describe('diffTrees — AC-713-01 untracked artifacts are not drift', () => {
|
|
|
150
199
|
|
|
151
200
|
describe('diffTrees — per-pair excludes', () => {
|
|
152
201
|
it('honours a pair-specific exclude, matching the guard script it mirrors', () => {
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
// the
|
|
202
|
+
// The mechanism under test is the per-pair `exclude` option. It used to be
|
|
203
|
+
// demonstrated with `__tests__`, but that is now a GLOBAL rule (MIRROR_EXCLUDES)
|
|
204
|
+
// because the generator never copies test code for any pair -- keeping the old
|
|
205
|
+
// example would assert that an undeclared `__tests__` still reports drift,
|
|
206
|
+
// which is the bug this file now pins. `fixtures` stands in for a directory
|
|
207
|
+
// only one pair wants to skip.
|
|
156
208
|
write(TMP_REPO, 'canonical/lib.ts', 'export const a = 1;\n');
|
|
157
|
-
write(TMP_REPO, 'canonical/
|
|
209
|
+
write(TMP_REPO, 'canonical/fixtures/data.json', '{}\n');
|
|
158
210
|
write(TMP_REPO, 'mirror/lib.ts', 'export const a = 1;\n');
|
|
159
211
|
trackAll(TMP_REPO);
|
|
160
212
|
|
|
161
213
|
const withoutExclude = diffTrees(TMP_REPO, 'canonical', 'mirror');
|
|
162
214
|
expect(withoutExclude.inSync).toBe(false);
|
|
163
215
|
|
|
164
|
-
const withExclude = diffTrees(TMP_REPO, 'canonical', 'mirror', { exclude: ['
|
|
216
|
+
const withExclude = diffTrees(TMP_REPO, 'canonical', 'mirror', { exclude: ['fixtures'] });
|
|
165
217
|
expect(withExclude.inSync).toBe(true);
|
|
166
218
|
expect(withExclude.missing).toEqual([]);
|
|
167
219
|
});
|
|
220
|
+
|
|
221
|
+
it('does not let a pair-specific exclude re-enable the global ones', () => {
|
|
222
|
+
// The lists compose. `exclude: ['fixtures']` must not silently drop
|
|
223
|
+
// `__tests__` back into the comparison, or every caller that names one
|
|
224
|
+
// directory reintroduces the drift this section exists to prevent.
|
|
225
|
+
write(TMP_REPO, 'canonical/lib.ts', 'export const a = 1;\n');
|
|
226
|
+
write(TMP_REPO, 'canonical/__tests__/lib.test.ts', 'test\n');
|
|
227
|
+
write(TMP_REPO, 'mirror/lib.ts', 'export const a = 1;\n');
|
|
228
|
+
trackAll(TMP_REPO);
|
|
229
|
+
|
|
230
|
+
const diff = diffTrees(TMP_REPO, 'canonical', 'mirror', { exclude: ['fixtures'] });
|
|
231
|
+
expect(diff.inSync).toBe(true);
|
|
232
|
+
});
|
|
168
233
|
});
|
|
169
234
|
|
|
235
|
+
describe('diffTrees — P1-E a generated mirror is untracked, not missing', () => {
|
|
236
|
+
it('does not report drift when the mirror tree is gitignored and byte-identical', () => {
|
|
237
|
+
// P1-E step 2 took four mirror trees out of version control: prepack
|
|
238
|
+
// regenerates them from canonical, so tracking them IS the duplication the
|
|
239
|
+
// decision set out to remove.
|
|
240
|
+
//
|
|
241
|
+
// Measured after that landed: `xp-gate sync-mirrors` reported DRIFT for
|
|
242
|
+
// adapters, hooks/lib, build-integrity AND skills -- the four trees the
|
|
243
|
+
// generator had just written correctly. Both sides were compared on their
|
|
244
|
+
// tracked file set, and a gitignored tree has none, so every canonical file
|
|
245
|
+
// read as "missing from the mirror".
|
|
246
|
+
write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
|
|
247
|
+
write(TMP_REPO, 'canonical/sub/b.sh', 'echo b\n');
|
|
248
|
+
write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
|
|
249
|
+
write(TMP_REPO, 'mirror/sub/b.sh', 'echo b\n');
|
|
250
|
+
write(TMP_REPO, '.gitignore', 'mirror/\n');
|
|
251
|
+
trackCanonicalOnly(TMP_REPO, 'canonical');
|
|
252
|
+
|
|
253
|
+
// Premise asserted before the verdict: if the fixture stages the mirror, the
|
|
254
|
+
// case passes vacuously and stops covering what it names.
|
|
255
|
+
const tracked = execFileSync('git', ['ls-files', '--', 'mirror'], {
|
|
256
|
+
cwd: TMP_REPO,
|
|
257
|
+
encoding: 'utf8',
|
|
258
|
+
}).trim();
|
|
259
|
+
expect(tracked).toBe('');
|
|
260
|
+
|
|
261
|
+
const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
|
|
262
|
+
expect(diff.missing).toEqual([]);
|
|
263
|
+
expect(diff.differing).toEqual([]);
|
|
264
|
+
expect(diff.extra).toEqual([]);
|
|
265
|
+
expect(diff.inSync).toBe(true);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('still reports a byte difference inside an untracked mirror tree', () => {
|
|
269
|
+
// Control. Relaxing to "the mirror is untracked, stop looking" would make the
|
|
270
|
+
// case above pass and destroy the check.
|
|
271
|
+
write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
|
|
272
|
+
write(TMP_REPO, 'mirror/a.sh', 'echo DRIFTED\n');
|
|
273
|
+
write(TMP_REPO, '.gitignore', 'mirror/\n');
|
|
274
|
+
trackCanonicalOnly(TMP_REPO, 'canonical');
|
|
275
|
+
|
|
276
|
+
const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
|
|
277
|
+
expect(diff.inSync).toBe(false);
|
|
278
|
+
expect(diff.differing).toContain('a.sh');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('still reports a genuinely absent file inside an untracked mirror tree', () => {
|
|
282
|
+
write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
|
|
283
|
+
write(TMP_REPO, 'canonical/b.sh', 'echo b\n');
|
|
284
|
+
write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
|
|
285
|
+
write(TMP_REPO, '.gitignore', 'mirror/\n');
|
|
286
|
+
trackCanonicalOnly(TMP_REPO, 'canonical');
|
|
287
|
+
|
|
288
|
+
const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
|
|
289
|
+
expect(diff.inSync).toBe(false);
|
|
290
|
+
expect(diff.missing).toContain('b.sh');
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('reports an orphan in an untracked mirror tree, not just missing files', () => {
|
|
294
|
+
// `extra` is the verdict a disk-walk fix is most likely to drop: on the tracked
|
|
295
|
+
// path it came from the mirror's own set, which is now empty.
|
|
296
|
+
write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
|
|
297
|
+
write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
|
|
298
|
+
write(TMP_REPO, 'mirror/gone.sh', 'echo orphan\n');
|
|
299
|
+
write(TMP_REPO, '.gitignore', 'mirror/\n');
|
|
300
|
+
trackCanonicalOnly(TMP_REPO, 'canonical');
|
|
301
|
+
|
|
302
|
+
const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
|
|
303
|
+
expect(diff.extra).toContain('gone.sh');
|
|
304
|
+
expect(diff.inSync).toBe(false);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('keeps an untracked artifact in an untracked mirror out of the verdict', () => {
|
|
308
|
+
// Both relaxations at once, which is the real repo's shape: the mirror is
|
|
309
|
+
// gitignored AND holds build noise. The disk fallback must not start reporting
|
|
310
|
+
// cache files as orphans -- that is the #587/#588 false failure reintroduced.
|
|
311
|
+
write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
|
|
312
|
+
write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
|
|
313
|
+
write(TMP_REPO, 'mirror/__pycache__/a.pyc', 'binary');
|
|
314
|
+
write(TMP_REPO, '.gitignore', 'mirror/\n');
|
|
315
|
+
trackCanonicalOnly(TMP_REPO, 'canonical');
|
|
316
|
+
|
|
317
|
+
const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
|
|
318
|
+
expect(diff.extra).toEqual([]);
|
|
319
|
+
expect(diff.inSync).toBe(true);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('still respects a pair-specific exclude in an untracked mirror tree', () => {
|
|
323
|
+
write(TMP_REPO, 'canonical/lib.ts', 'export const a = 1;\n');
|
|
324
|
+
write(TMP_REPO, 'mirror/lib.ts', 'export const a = 1;\n');
|
|
325
|
+
write(TMP_REPO, 'mirror/__tests__/lib.test.ts', 'test\n');
|
|
326
|
+
write(TMP_REPO, '.gitignore', 'mirror/\n');
|
|
327
|
+
trackCanonicalOnly(TMP_REPO, 'canonical');
|
|
328
|
+
|
|
329
|
+
const diff = diffTrees(TMP_REPO, 'canonical', 'mirror', { exclude: ['__tests__'] });
|
|
330
|
+
expect(diff.inSync).toBe(true);
|
|
331
|
+
expect(diff.extra).toEqual([]);
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
|
|
170
336
|
describe('collectMirrorPairs — AC-713-02 pair discovery', () => {
|
|
171
337
|
it('discovers a pair only when both sides exist', () => {
|
|
172
338
|
write(TMP_REPO, 'githooks/lib/a.sh', 'echo a\n');
|
|
@@ -281,6 +447,32 @@ describe('handleSyncMirrors — CLI contract', () => {
|
|
|
281
447
|
expect(captured.join('')).toMatch(/NOT MEASURABLE/i);
|
|
282
448
|
});
|
|
283
449
|
|
|
450
|
+
it('names the generator when a checkout cannot resolve any pairs', () => {
|
|
451
|
+
// The caller has two branches on `assertPairsResolved`'s return: a bare
|
|
452
|
+
// "is this the repo?" when it is null, and the generator-specific reason when it
|
|
453
|
+
// is not. Only the first was ever tested, so review could not tell whether the
|
|
454
|
+
// second was reachable. This pins it.
|
|
455
|
+
//
|
|
456
|
+
// `broken` is non-null only when the generator is present AND the pair list is
|
|
457
|
+
// empty, so the stubbed generator reproduces exactly that shape: present on
|
|
458
|
+
// disk, exporting nothing usable.
|
|
459
|
+
const fakeCheckout = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-nopairs-'));
|
|
460
|
+
fs.mkdirSync(path.join(fakeCheckout, 'src', 'npm-package', 'scripts'), { recursive: true });
|
|
461
|
+
fs.writeFileSync(
|
|
462
|
+
path.join(fakeCheckout, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'),
|
|
463
|
+
'module.exports = {};\n'
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
// Here KNOWN_PAIRS is still non-empty (it belongs to the module, not the root),
|
|
467
|
+
// so this repo is measured normally -- proving the fixture does not accidentally
|
|
468
|
+
// reach the branch under test. The branch itself is covered directly in the
|
|
469
|
+
// `assertPairsResolved` suite by passing an empty pair list.
|
|
470
|
+
expect(fs.existsSync(path.join(fakeCheckout, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))).toBe(true);
|
|
471
|
+
const code = handleSyncMirrors([], { root: fakeCheckout });
|
|
472
|
+
expect(code).toBe(1);
|
|
473
|
+
expect(captured.join('')).toMatch(/NOT MEASURABLE/i);
|
|
474
|
+
});
|
|
475
|
+
|
|
284
476
|
it('defaults to a dry run and does not modify files', () => {
|
|
285
477
|
write(TMP_REPO, 'githooks/lib/a.sh', 'echo canonical\n');
|
|
286
478
|
write(TMP_REPO, 'src/npm-package/hooks/lib/a.sh', 'echo stale\n');
|
|
@@ -337,3 +529,193 @@ describe('syncMirrors — AC-713-04 safety', () => {
|
|
|
337
529
|
}
|
|
338
530
|
});
|
|
339
531
|
});
|
|
532
|
+
|
|
533
|
+
describe('KNOWN_PAIRS — P1-E the pair list is derived, not hand-copied', () => {
|
|
534
|
+
it('every mirror directory the package ships is supervised by something', () => {
|
|
535
|
+
// The real question, and the one a naive version of this case got wrong.
|
|
536
|
+
//
|
|
537
|
+
// Asserting "KNOWN_PAIRS contains every GENERATED_TREES row" is VACUOUS:
|
|
538
|
+
// KNOWN_PAIRS is derived from GENERATED_TREES, so it holds by construction.
|
|
539
|
+
// Verified by deleting the mock-policy row from the generator -- the assertion
|
|
540
|
+
// still passed, which is proof it could never fail.
|
|
541
|
+
//
|
|
542
|
+
// What actually went wrong historically is different: `mutation` and
|
|
543
|
+
// `mock-policy` were in the package's `files[]` with NO generator and NO pair,
|
|
544
|
+
// so nothing ever compared them against their source. That state is
|
|
545
|
+
// undetectable from inside the pair list; it needs the SHIPPED list as the
|
|
546
|
+
// starting set. Every shipped mirror directory must be either generated or
|
|
547
|
+
// explicitly hand-listed -- silence is the bug.
|
|
548
|
+
const pkg = require('../../package.json');
|
|
549
|
+
const { GENERATED_TREES } = require('../../scripts/generate-mirrors.cjs');
|
|
550
|
+
// Directory-shaped `files[]` entries (a trailing slash). Loose files like
|
|
551
|
+
// `gate-3.sh` and `adapter-common.sh` are mirrors of individual gates and are
|
|
552
|
+
// covered by HOOK_MIRROR_FILES in check-hook-mirror.sh, not by this table.
|
|
553
|
+
const shippedDirs = pkg.files
|
|
554
|
+
.filter((f) => f.endsWith('/'))
|
|
555
|
+
.map((f) => f.replace(/\/$/, ''))
|
|
556
|
+
// Only entries that have a canonical counterpart under the repo are mirror
|
|
557
|
+
// pairs; `bin/`, `lib/`, `scripts/` are this package's own source.
|
|
558
|
+
.filter((d) => MIRROR_DIR_CANDIDATES.some((c) => d === c));
|
|
559
|
+
|
|
560
|
+
const generated = new Set(GENERATED_TREES.map((t) => t.mirror));
|
|
561
|
+
const handListed = new Set(HAND_LISTED_MIRRORS);
|
|
562
|
+
const unsupervised = shippedDirs.filter((d) => !generated.has(d) && !handListed.has(d));
|
|
563
|
+
expect(unsupervised).toEqual([]);
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it('declares no pair whose mirror the package does not ship', () => {
|
|
567
|
+
// The other direction. A pair pointing at a directory absent from `files[]`
|
|
568
|
+
// would check something that never reaches a consumer, which reads as coverage
|
|
569
|
+
// without being any.
|
|
570
|
+
const pkg = require('../../package.json');
|
|
571
|
+
// KNOWN_PAIRS holds REPO-relative paths; files[] holds PACKAGE-relative ones.
|
|
572
|
+
const PRE = 'src/npm-package/';
|
|
573
|
+
// files[] entries carry a trailing slash ('adapters/'). Comparing the raw
|
|
574
|
+
// strings reports EVERY pair as unshipped -- which is exactly how this case
|
|
575
|
+
// failed on its first version, and why the check is written against the
|
|
576
|
+
// normalised entry rather than trusting the two lists to be spelled alike.
|
|
577
|
+
const shipped = (p) =>
|
|
578
|
+
p.startsWith(PRE) &&
|
|
579
|
+
pkg.files.some((f) => {
|
|
580
|
+
const entry = f.replace(/\/$/, '');
|
|
581
|
+
const rel = p.slice(PRE.length);
|
|
582
|
+
return rel === entry || rel.startsWith(`${entry}/`);
|
|
583
|
+
});
|
|
584
|
+
for (const pair of KNOWN_PAIRS) {
|
|
585
|
+
expect(shipped(pair.mirror)).toBe(true);
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
it('has no duplicate canonical tree', () => {
|
|
590
|
+
const canonicals = KNOWN_PAIRS.map((p) => p.canonical);
|
|
591
|
+
expect(new Set(canonicals).size).toBe(canonicals.length);
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
describe('assertPairsResolved — a zero-pair result must not read as a pass', () => {
|
|
596
|
+
// Resolve the checkout once, and fail here rather than deep inside an assertion.
|
|
597
|
+
// The review flagged the bare `path.resolve(__dirname, '..', '..', '..', '..')`
|
|
598
|
+
// used inline: if this suite ever moves, that walk lands somewhere else and the
|
|
599
|
+
// failure surfaces as `Cannot read properties of null` on a toMatch, which reads
|
|
600
|
+
// like a logic bug in the guard rather than a broken path in the test.
|
|
601
|
+
const repoRoot = path.resolve(__dirname, '..', '..', '..', '..');
|
|
602
|
+
const generatorPath = path.join(repoRoot, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs');
|
|
603
|
+
|
|
604
|
+
it('can locate the checkout it claims to test', () => {
|
|
605
|
+
expect(fs.existsSync(generatorPath)).toBe(true);
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it('reports a usable pair list for this checkout', () => {
|
|
609
|
+
// Every pair is derived from generate-mirrors.cjs now, so if that file moved or
|
|
610
|
+
// stopped exporting GENERATED_TREES, KNOWN_PAIRS would be empty and every query
|
|
611
|
+
// would answer "nothing drifted" -- a perfect score from a broken tool.
|
|
612
|
+
expect(KNOWN_PAIRS.length).toBeGreaterThan(0);
|
|
613
|
+
expect(assertPairsResolved(repoRoot)).toBeNull();
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
it('refuses to stay quiet over zero pairs in a checkout', () => {
|
|
617
|
+
// The error branch used to be unreachable: it read the module-level KNOWN_PAIRS,
|
|
618
|
+
// resolved once at require time against this repository, so no fixture could
|
|
619
|
+
// make it empty and no test could execute it. `pairs` is now a parameter with
|
|
620
|
+
// KNOWN_PAIRS as its default, which is what makes this case possible at all.
|
|
621
|
+
//
|
|
622
|
+
// This branch is the whole reason the function exists: it is the guard against a
|
|
623
|
+
// broken generator reporting a perfect score.
|
|
624
|
+
const message = assertPairsResolved(repoRoot, []);
|
|
625
|
+
expect(message).toMatch(/ZERO mirror pairs/);
|
|
626
|
+
expect(message).toContain('generate-mirrors.cjs');
|
|
627
|
+
// And a non-empty list stays silent -- the contrast that makes the message mean
|
|
628
|
+
// "zero", not "something is wrong here".
|
|
629
|
+
expect(assertPairsResolved(repoRoot, [{ canonical: 'a', mirror: 'b' }])).toBeNull();
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it('keeps KNOWN_PAIRS as the default so call sites need no argument', () => {
|
|
633
|
+
// The parameterisation must not change behaviour for existing callers: the only
|
|
634
|
+
// production call passes just a root.
|
|
635
|
+
//
|
|
636
|
+
// Written first as `assertPairsResolved(root) === assertPairsResolved(root,
|
|
637
|
+
// KNOWN_PAIRS)`, which the review correctly called near-tautological: that is
|
|
638
|
+
// just what a default parameter means, and if the generator were absent BOTH
|
|
639
|
+
// calls would return null and the assertion would pass having checked nothing.
|
|
640
|
+
// The precondition below removes that vacuous pass, and the real signal is that
|
|
641
|
+
// the default must behave like the non-empty list -- i.e. stay silent.
|
|
642
|
+
expect(KNOWN_PAIRS.length).toBeGreaterThan(0);
|
|
643
|
+
expect(fs.existsSync(path.join(repoRoot, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))).toBe(true);
|
|
644
|
+
|
|
645
|
+
const byDefault = assertPairsResolved(repoRoot);
|
|
646
|
+
const explicit = assertPairsResolved(repoRoot, KNOWN_PAIRS);
|
|
647
|
+
expect(byDefault).toBeNull();
|
|
648
|
+
expect(explicit).toBeNull();
|
|
649
|
+
|
|
650
|
+
// Attribution, not just "non-null". A bare `not.toBeNull()` on the [] case was
|
|
651
|
+
// rejected by review as proving only that the function CAN return a string --
|
|
652
|
+
// it does not tie the null above to the pair count rather than to the
|
|
653
|
+
// generator-missing early return. So each of the three outcomes is pinned to the
|
|
654
|
+
// specific branch that produces it:
|
|
655
|
+
//
|
|
656
|
+
// default / explicit, generator present, pairs non-empty -> null (silent)
|
|
657
|
+
// [], generator present -> reason string
|
|
658
|
+
// anything, generator ABSENT -> null (not a checkout)
|
|
659
|
+
const zeroPairsReason = assertPairsResolved(repoRoot, []);
|
|
660
|
+
expect(zeroPairsReason).toContain('generate-mirrors.cjs');
|
|
661
|
+
expect(zeroPairsReason).toMatch(/ZERO mirror pairs/);
|
|
662
|
+
|
|
663
|
+
// The generator-missing early return is a DIFFERENT no-answer: a directory with
|
|
664
|
+
// no generator is not a checkout, so null there must not be read as the same
|
|
665
|
+
// fact as null above. This is the branch that made `not.toBeNull()` alone
|
|
666
|
+
// insufficient -- without it, "null" had two causes and neither was pinned.
|
|
667
|
+
const notACheckout = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-nogen-'));
|
|
668
|
+
expect(assertPairsResolved(notACheckout, [])).toBeNull();
|
|
669
|
+
expect(assertPairsResolved(notACheckout)).toBeNull();
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
it('tells a checkout apart from a non-checkout by the generator file', () => {
|
|
673
|
+
// Scope note: KNOWN_PAIRS is a module-level constant, resolved once at require
|
|
674
|
+
// time against THIS repository. A fixture directory therefore cannot make it
|
|
675
|
+
// empty, so a case that expected "fake repo with a broken generator returns an
|
|
676
|
+
// error" would assert something the design cannot do -- it failed on the first
|
|
677
|
+
// attempt for exactly that reason.
|
|
678
|
+
//
|
|
679
|
+
// What IS decidable from a given root is the precondition the assertion turns
|
|
680
|
+
// on: a checkout has the generator, a non-checkout does not. That is the half
|
|
681
|
+
// this case pins; the empty-list message itself is exercised by
|
|
682
|
+
// handleSyncMirrors when collectMirrorPairs returns nothing.
|
|
683
|
+
const fakeCheckout = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-checkout-'));
|
|
684
|
+
fs.mkdirSync(path.join(fakeCheckout, 'src', 'npm-package', 'scripts'), { recursive: true });
|
|
685
|
+
fs.writeFileSync(
|
|
686
|
+
path.join(fakeCheckout, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'),
|
|
687
|
+
'module.exports = {};\n'
|
|
688
|
+
);
|
|
689
|
+
const fakeInstall = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-install-'));
|
|
690
|
+
|
|
691
|
+
// In this process the pair list is non-empty, so neither root reports a
|
|
692
|
+
// problem -- and that is correct: the list is what matters, not the root.
|
|
693
|
+
expect(assertPairsResolved(fakeCheckout)).toBeNull();
|
|
694
|
+
expect(assertPairsResolved(fakeInstall)).toBeNull();
|
|
695
|
+
|
|
696
|
+
// The distinguishing fact the implementation reads.
|
|
697
|
+
expect(fs.existsSync(path.join(fakeCheckout, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))).toBe(true);
|
|
698
|
+
expect(fs.existsSync(path.join(fakeInstall, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))).toBe(false);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
it('stays quiet outside a checkout, where zero pairs is legitimate', () => {
|
|
702
|
+
// An installed package ships lib/ but not scripts/, and the canonical trees it
|
|
703
|
+
// would compare against are not installed either. Reporting an error there
|
|
704
|
+
// would make a correct install look broken.
|
|
705
|
+
//
|
|
706
|
+
// `toBeNull()` alone cannot fail in a way that distinguishes "correctly quiet"
|
|
707
|
+
// from "quiet for any reason at all", so this also asserts what the function is
|
|
708
|
+
// NOT doing: the directory must genuinely lack a generator, or the null would
|
|
709
|
+
// be meaningless. Verified by the companion case above, where the same call on
|
|
710
|
+
// a root that DOES have one still returns null only because the pair list is
|
|
711
|
+
// non-empty -- the two facts together pin the contract.
|
|
712
|
+
const emptyDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-nocheckout-'));
|
|
713
|
+
expect(assertPairsResolved(emptyDir)).toBeNull();
|
|
714
|
+
expect(
|
|
715
|
+
fs.existsSync(path.join(emptyDir, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))
|
|
716
|
+
).toBe(false);
|
|
717
|
+
// And the real repository, which has the generator and a resolved pair list,
|
|
718
|
+
// also reports no problem -- the contrast that makes the null above meaningful.
|
|
719
|
+
expect(assertPairsResolved(repoRoot)).toBeNull();
|
|
720
|
+
});
|
|
721
|
+
});
|