@boyingliu01/xp-gate 0.37.2 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapter-common.sh +12 -2
- package/adapters/csharp.sh +73 -2
- package/adapters/dart.sh +13 -0
- package/adapters/go.sh +5 -0
- package/adapters/iac.sh +46 -3
- package/adapters/java.sh +6 -0
- package/adapters/kotlin.sh +6 -0
- package/adapters/shell.sh +119 -34
- package/adapters/swift.sh +6 -0
- package/adapters/typescript.sh +98 -34
- package/bin/xp-gate.js +48 -2
- package/gate-10.sh +99 -26
- package/gate-12-file-hygiene.sh +13 -1
- package/gate-registry.sh +197 -0
- package/gates/common-process.ts +36 -7
- package/gates/gate-9.ts +17 -8
- package/gates/python-health.ts +215 -24
- package/hooks/adapter-common.sh +12 -2
- package/hooks/deploy-manifest.sh +100 -0
- package/hooks/gate-10.sh +99 -26
- package/hooks/gate-12-file-hygiene.sh +13 -1
- package/hooks/gate-driver.sh +120 -0
- package/hooks/gate-entries/gate-0-entry.sh +825 -0
- package/hooks/gate-entries/gate-1-entry.sh +767 -0
- package/hooks/gate-entries/gate-10-entry.sh +52 -0
- package/hooks/gate-entries/gate-11-entry.sh +120 -0
- package/hooks/gate-entries/gate-12-entry.sh +44 -0
- package/hooks/gate-entries/gate-12b-entry.sh +178 -0
- package/hooks/gate-entries/gate-12c-entry.sh +80 -0
- package/hooks/gate-entries/gate-13-entry.sh +584 -0
- package/hooks/gate-entries/gate-2-entry.sh +199 -0
- package/hooks/gate-entries/gate-3-entry.sh +53 -0
- package/hooks/gate-entries/gate-4-entry.sh +46 -0
- package/hooks/gate-entries/gate-5-entry.sh +1729 -0
- package/hooks/gate-entries/gate-6-entry.sh +658 -0
- package/hooks/gate-entries/gate-7-entry.sh +41 -0
- package/hooks/gate-entries/gate-8-entry.sh +33 -0
- package/hooks/gate-entries/gate-9-entry.sh +307 -0
- package/hooks/gate-entries/subdir-restore.sh +27 -0
- package/hooks/gate-registry.sh +51 -15
- package/hooks/hook-module-resolution.sh +73 -0
- package/hooks/install.sh +135 -0
- package/hooks/lib/now-ms.sh +55 -19
- package/hooks/lib/toolchain-path.sh +50 -6
- package/hooks/pre-commit +256 -5091
- package/hooks/pre-push +212 -25
- package/lib/__tests__/arch-config-template.test.js +190 -0
- package/lib/__tests__/baseline-shell-scope.test.js +60 -0
- package/lib/__tests__/crap-cli.test.js +14 -3
- package/lib/__tests__/deploy-manifest-check-wired.test.js +138 -0
- package/lib/__tests__/deploy-manifest-completeness.test.js +151 -0
- package/lib/__tests__/deploy-manifest-consumers-adapter-uninstall.test.js +40 -0
- package/lib/__tests__/deploy-manifest-consumers-no-private-lists.test.js +74 -0
- package/lib/__tests__/deploy-manifest-projection.test.js +66 -0
- package/lib/__tests__/deploy-manifest-shell-parity.test.js +108 -0
- package/lib/__tests__/deploy-manifest.test.js +97 -0
- package/lib/__tests__/doctor.test.js +51 -7
- package/lib/__tests__/gate-coverage.test.js +79 -12
- package/lib/__tests__/gate-numbering.test.js +28 -1
- package/lib/__tests__/install-sh-deploy-manifest.test.js +80 -0
- package/lib/__tests__/mirror-sync.test.js +45 -3
- package/lib/__tests__/npm-package.test.js +10 -7
- package/lib/__tests__/sastd-client.test.js +452 -0
- package/lib/__tests__/shared-utils-copyHooks-manifest.test.js +69 -0
- package/lib/__tests__/sprint-status-rework.test.js +1 -0
- package/lib/arch-config-template.js +87 -0
- package/lib/baseline.js +54 -2
- package/lib/deploy-manifest.js +174 -0
- package/lib/doctor.js +46 -14
- package/lib/gate-capability.js +291 -0
- package/lib/gate-coverage.js +194 -74
- package/lib/gate-identity.js +349 -0
- package/lib/gate-runner.js +11 -1
- package/lib/hook-module-resolution.js +27 -0
- package/lib/init.js +72 -5
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/sastd-client.js +534 -0
- package/lib/shared-utils.js +31 -9
- package/lib/uninstall.js +10 -7
- package/lib/update-hooks.js +27 -18
- package/mock-policy/AGENTS.md +1 -1
- package/mutation/AGENTS.md +1 -1
- package/package.json +3 -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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- package/principles/AGENTS.md +1 -1
- package/principles/__tests__/analyzer.test.ts +2 -1
- package/principles/__tests__/config-enforcement.test.ts +1 -0
- package/principles/__tests__/types.test.ts +1 -0
- package/principles/adapters/base.ts +14 -1
- package/principles/adapters/duplication.ts +134 -0
- package/principles/rules/__tests__/clean-code/large-file.test.ts +2 -1
- package/principles/rules/clean-code/code-duplication.ts +75 -9
- package/principles/types.ts +39 -0
- package/scripts/__tests__/check-mattpocock-license.test.js +36 -3
- package/scripts/__tests__/sync-package-content.test.js +12 -2
- package/scripts/generate-mirrors.cjs +125 -0
- package/scripts/sync-package-content.js +64 -20
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +2 -2
- package/adapters/gate-9.sh +0 -245
- package/gate-9.sh +0 -245
- package/hooks/gate-9.sh +0 -245
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-DEPLOY-001 deploy-manifest 单一事实源
|
|
3
|
+
* @intent 验证 deploy-manifest.js 是"包内部署文件→安装目标"清单的唯一事实源,
|
|
4
|
+
* 防漏改断言遍历 canonical githooks/ 比对清单,拦截新增 hook/gate 脚本时漏改
|
|
5
|
+
* 清单(#783 建议②:回归测试断言「包内该部署的每个文件都在清单里」)。
|
|
6
|
+
* @covers AC-DEPLOY-01, AC-DEPLOY-02, AC-DEPLOY-03
|
|
7
|
+
*/
|
|
8
|
+
const fs = require('node:fs');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
|
|
11
|
+
// TDD RED:deploy-manifest.js 尚未创建(本测试先提交,实现下一步)。
|
|
12
|
+
// require 抛 MODULE_NOT_FOUND → 整个套件红,是 RED 的合法起点。
|
|
13
|
+
const { HOOK_FILES, GATE_FILES, MODULE_FILES, ADAPTER_COMMON, HOOKS_LIB } = require('../deploy-manifest.js');
|
|
14
|
+
|
|
15
|
+
const REPO_ROOT = path.resolve(__dirname, '..', '..', '..', '..');
|
|
16
|
+
const GITHOOKS_DIR = path.join(REPO_ROOT, 'githooks');
|
|
17
|
+
|
|
18
|
+
describe('deploy-manifest (REQ-DEPLOY-001)', () => {
|
|
19
|
+
describe('AC-DEPLOY-01 清单覆盖 canonical githooks/ 全集(防漏改)', () => {
|
|
20
|
+
it('HOOK_FILES 覆盖 githooks/ 顶层每个普通 hook + hook-module-resolution.sh', () => {
|
|
21
|
+
const topLevel = fs.readdirSync(GITHOOKS_DIR);
|
|
22
|
+
// 普通 hook = 顶层无扩展名普通文件(pre-commit/pre-push/post-commit/post-merge)。
|
|
23
|
+
// .sh 脚本单独分类(gate-*/sprint-gate/adapter-common/hook-module-resolution);
|
|
24
|
+
// install.sh/verify.sh 是安装器与开发工具,非部署到用户 hooks 的 hook,排除。
|
|
25
|
+
const plainHooks = topLevel.filter(f => {
|
|
26
|
+
const p = path.join(GITHOOKS_DIR, f);
|
|
27
|
+
if (!fs.statSync(p).isFile()) return false;
|
|
28
|
+
// 普通 hook 无扩展名(pre-commit/pre-push/post-commit/post-merge)。
|
|
29
|
+
// 带扩展名的全部排除:.sh(gate-*/sprint-gate/adapter-common/
|
|
30
|
+
// hook-module-resolution/install/verify 单独分类)、.md(文档)。
|
|
31
|
+
if (f.includes('.')) return false;
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
expect(plainHooks.sort()).toEqual(
|
|
35
|
+
['post-commit', 'post-merge', 'pre-commit', 'pre-push'],
|
|
36
|
+
);
|
|
37
|
+
for (const h of plainHooks) {
|
|
38
|
+
expect(HOOK_FILES).toContain(h);
|
|
39
|
+
}
|
|
40
|
+
// hook-module-resolution.sh 是 #505 生成的解析表,随 hook 一起部署
|
|
41
|
+
// (pre-commit 顶部 source 它,缺失则 fail-closed FATAL)。
|
|
42
|
+
expect(HOOK_FILES).toContain('hook-module-resolution.sh');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('GATE_FILES 覆盖 githooks/ 每个 gate-*.sh + sprint-gate.sh(11 个)', () => {
|
|
46
|
+
const topLevel = fs.readdirSync(GITHOOKS_DIR);
|
|
47
|
+
const gateFiles = topLevel.filter(f =>
|
|
48
|
+
f.startsWith('gate-') && f.endsWith('.sh') &&
|
|
49
|
+
fs.statSync(path.join(GITHOOKS_DIR, f)).isFile(),
|
|
50
|
+
);
|
|
51
|
+
// #798: `gate-driver.sh` matches the gate-*.sh NAME pattern but is not a
|
|
52
|
+
// gate -- it is the driver that loads gate-entries/ and runs them in
|
|
53
|
+
// XP_GATE_ORDER. It ships from MODULE_FILES. The assertion below still
|
|
54
|
+
// requires it to be deployed SOMEWHERE, so a new file cannot slip through
|
|
55
|
+
// by simply not matching the gate category: it must be in one of the two
|
|
56
|
+
// lists, or this test fails.
|
|
57
|
+
const DRIVER = 'gate-driver.sh';
|
|
58
|
+
for (const g of gateFiles) {
|
|
59
|
+
if (g === DRIVER) {
|
|
60
|
+
expect(GATE_FILES).not.toContain(DRIVER);
|
|
61
|
+
expect(MODULE_FILES).toContain(DRIVER);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
expect(GATE_FILES).toContain(g);
|
|
65
|
+
}
|
|
66
|
+
// ...and the driver must actually exist in the package, or the exemption
|
|
67
|
+
// above would silently cover a file that was never shipped.
|
|
68
|
+
expect(topLevel).toContain(DRIVER);
|
|
69
|
+
// sprint-gate.sh(Gate S)与 gate 套件一起部署(copyAdapters/update-hooks 都拷它)
|
|
70
|
+
expect(GATE_FILES).toContain('sprint-gate.sh');
|
|
71
|
+
// v1 手抄漏 gate-12-file-hygiene.sh 的教训:显式钉死最易漏的成员
|
|
72
|
+
expect(GATE_FILES).toContain('gate-12-file-hygiene.sh');
|
|
73
|
+
expect(GATE_FILES).toContain('gate-registry.sh');
|
|
74
|
+
expect(GATE_FILES).toContain('gate-6-layers.sh');
|
|
75
|
+
// 11 -> 10 after githooks/gate-9.sh was deleted (#738/#717). That file was
|
|
76
|
+
// never sourced by any hook: the SAST gate is gate-10.sh. Shipping it to
|
|
77
|
+
// consumer repos advertised a gate script that could not run, and it let
|
|
78
|
+
// a SAST fix be written into a file nothing executes. If this count grows
|
|
79
|
+
// again, the new member must be a script some hook actually sources.
|
|
80
|
+
expect(GATE_FILES).toHaveLength(10);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('AC-DEPLOY-02 hooks 与 gates 无交集(两类部署目标)', () => {
|
|
85
|
+
it('HOOK_FILES ∩ GATE_FILES = ∅', () => {
|
|
86
|
+
const overlap = HOOK_FILES.filter(f => GATE_FILES.includes(f));
|
|
87
|
+
expect(overlap).toEqual([]);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('AC-DEPLOY-03 adapter-common 与 lib 独立字段', () => {
|
|
92
|
+
it('ADAPTER_COMMON=adapter-common.sh,HOOKS_LIB=lib', () => {
|
|
93
|
+
expect(ADAPTER_COMMON).toBe('adapter-common.sh');
|
|
94
|
+
expect(HOOKS_LIB).toBe('lib');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -85,11 +85,42 @@ describe('doctor', () => {
|
|
|
85
85
|
// and reloading it would restore the full tool list, breaking the test mock setup.
|
|
86
86
|
const modulesToInvalidate = [
|
|
87
87
|
'../doctor', '../uninstall', '../init', '../shared-paths',
|
|
88
|
-
'../check-version.js', '../doctor-tui',
|
|
88
|
+
'../check-version.js', '../doctor-tui', '../language-tools.js',
|
|
89
89
|
];
|
|
90
90
|
for (const mod of modulesToInvalidate) {
|
|
91
91
|
try { delete require.cache[require.resolve(mod)]; } catch { /* first load */ }
|
|
92
92
|
}
|
|
93
|
+
// Language-tool and registry probing are not what this file tests, but
|
|
94
|
+
// doctor() reaches both on every call:
|
|
95
|
+
//
|
|
96
|
+
// 1. diagnoseLanguageTools() scans process.cwd() -- and a vitest worker
|
|
97
|
+
// cannot be chdir'd ("process.chdir() is not supported in workers"), so
|
|
98
|
+
// cwd is always the real xp-gate checkout. That tree is recognised as a
|
|
99
|
+
// TypeScript/Shell/... project, so `checkTool()` runs real subprocesses
|
|
100
|
+
// (`eslint --version`, `npx --no-install archlint --version`,
|
|
101
|
+
// `shellcheck --version`, `pwsh --version`, `terraform --version`, ...).
|
|
102
|
+
// 2. diagnoseUpgrade() -> checkUpgrade() issues a real HTTPS request to
|
|
103
|
+
// https://registry.npmjs.org/-/package/<pkg>/dist-tags and waits on it.
|
|
104
|
+
// Seeding version-cache.json does not prevent the fetch, so every case
|
|
105
|
+
// paid the network round trip -- this was the larger half of the cost.
|
|
106
|
+
//
|
|
107
|
+
// Measured 2026-11-11 on one doctor() call with a config present (i.e. the
|
|
108
|
+
// full check suite): 2140 ms / 1064 ms unstubbed versus 239 ms / 248 ms with
|
|
109
|
+
// both stubbed (ABBA). XP_GATE_REPO_ROOT already redirects the hook-drift
|
|
110
|
+
// check to an empty dir for the same reason; this closes the remaining paths.
|
|
111
|
+
//
|
|
112
|
+
// Why it is safe: no case in this file asserts anything about language-tool
|
|
113
|
+
// detection or upgrade advice -- neither the "Language-Specific Tools"
|
|
114
|
+
// section nor the upgrade message is matched in any expectation. Both stubs
|
|
115
|
+
// are re-applied on every test because vi.resetModules() above discards
|
|
116
|
+
// them, and they must be installed BEFORE require('../doctor') captures its
|
|
117
|
+
// destructured imports.
|
|
118
|
+
const languageTools = require('../language-tools.js');
|
|
119
|
+
languageTools.getToolsForLanguages = () => ({});
|
|
120
|
+
languageTools.detectProjectLanguages = () => ({ detected: [], configFiles: {} });
|
|
121
|
+
const checkVersion = require('../check-version.js');
|
|
122
|
+
checkVersion.checkUpgrade = async () => ({ status: 'current' });
|
|
123
|
+
checkVersion.formatUpgradeMsg = () => '';
|
|
93
124
|
logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
94
125
|
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
95
126
|
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
@@ -192,7 +223,7 @@ describe('doctor', () => {
|
|
|
192
223
|
path.join(dir, 'adapters', 'python.sh'),
|
|
193
224
|
'#!/usr/bin/env bash\necho "py adapter"\n'
|
|
194
225
|
);
|
|
195
|
-
const gateScripts =
|
|
226
|
+
const gateScripts = require('../deploy-manifest.js').GATE_FILES.filter(g => g !== 'gate-registry.sh');
|
|
196
227
|
for (const script of gateScripts) {
|
|
197
228
|
fs.writeFileSync(path.join(dir, 'adapters', script), `#!/bin/bash\n# ${script}\n`);
|
|
198
229
|
}
|
|
@@ -233,7 +264,7 @@ describe('doctor', () => {
|
|
|
233
264
|
fs.mkdirSync(globalAdaptersDir(), { recursive: true });
|
|
234
265
|
fs.writeFileSync(path.join(globalAdaptersDir(), 'typescript.sh'), '#!/usr/bin/env bash\necho "ts adapter"\n');
|
|
235
266
|
fs.writeFileSync(path.join(globalAdaptersDir(), 'python.sh'), '#!/usr/bin/env bash\necho "py adapter"\n');
|
|
236
|
-
const gateScripts =
|
|
267
|
+
const gateScripts = require('../deploy-manifest.js').GATE_FILES.filter(g => g !== 'gate-registry.sh');
|
|
237
268
|
for (const script of gateScripts) {
|
|
238
269
|
fs.writeFileSync(path.join(globalAdaptersDir(), script), `#!/bin/bash\n# ${script}\n`);
|
|
239
270
|
}
|
|
@@ -637,8 +668,17 @@ describe('doctor', () => {
|
|
|
637
668
|
it('AC-488: doctor still accepts its documented flags', async () => {
|
|
638
669
|
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
639
670
|
const { doctor } = require('../doctor');
|
|
640
|
-
await doctor(['--fix', '--sync-hooks']);
|
|
671
|
+
const result = await doctor(['--fix', '--sync-hooks']);
|
|
672
|
+
// Asserted on the RETURN VALUE as well as the absence of flag errors. "No
|
|
673
|
+
// error was printed" alone cannot tell "the flags were understood" from "the
|
|
674
|
+
// function never got far enough to print anything", which is exactly the
|
|
675
|
+
// regression this case exists for: an unrecognised flag makes doctor bail out
|
|
676
|
+
// before it reports anything, and silence reads as success.
|
|
641
677
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
678
|
+
// AC-488 is about flag PARSING, not about this machine being healthy: the exit
|
|
679
|
+
// code legitimately varies with the install state, so the assertion is that it
|
|
680
|
+
// is a doctor verdict (0/1) rather than a crash or an undefined return.
|
|
681
|
+
expect([0, 1]).toContain(result);
|
|
642
682
|
errorSpy.mockRestore();
|
|
643
683
|
});
|
|
644
684
|
|
|
@@ -1038,7 +1078,7 @@ describe('doctor', () => {
|
|
|
1038
1078
|
|
|
1039
1079
|
function createGateScripts(dir) {
|
|
1040
1080
|
fs.mkdirSync(dir, { recursive: true });
|
|
1041
|
-
const gateScripts =
|
|
1081
|
+
const gateScripts = require('../deploy-manifest.js').GATE_FILES.filter(g => g !== 'gate-registry.sh');
|
|
1042
1082
|
for (const script of gateScripts) {
|
|
1043
1083
|
fs.writeFileSync(path.join(dir, script), `#!/bin/bash\n# ${script}\n`);
|
|
1044
1084
|
}
|
|
@@ -1059,7 +1099,7 @@ describe('doctor', () => {
|
|
|
1059
1099
|
expect.stringContaining('Gate scripts')
|
|
1060
1100
|
);
|
|
1061
1101
|
expect(logSpy).toHaveBeenCalledWith(
|
|
1062
|
-
expect.stringContaining('
|
|
1102
|
+
expect.stringContaining('gate script(s) present')
|
|
1063
1103
|
);
|
|
1064
1104
|
});
|
|
1065
1105
|
|
|
@@ -1101,7 +1141,11 @@ describe('doctor', () => {
|
|
|
1101
1141
|
expect(fs.existsSync(path.join(projectAdaptersDir(), 'gate-4.sh'))).toBe(true);
|
|
1102
1142
|
expect(fs.existsSync(path.join(projectAdaptersDir(), 'gate-7.sh'))).toBe(true);
|
|
1103
1143
|
expect(fs.existsSync(path.join(projectAdaptersDir(), 'gate-8.sh'))).toBe(true);
|
|
1104
|
-
|
|
1144
|
+
// gate-9.sh was deleted (#738/#717). It carried a "DEAD CODE — NOT
|
|
1145
|
+
// EXECUTED" banner and no hook sourced it; the SAST gate is gate-10.sh.
|
|
1146
|
+
// Restoring it would re-ship a script that cannot run into every consumer
|
|
1147
|
+
// repo — which is how a C# SAST fix once landed in a file nothing executes.
|
|
1148
|
+
expect(fs.existsSync(path.join(projectAdaptersDir(), 'gate-9.sh'))).toBe(false);
|
|
1105
1149
|
expect(fs.existsSync(path.join(projectAdaptersDir(), 'gate-10.sh'))).toBe(true);
|
|
1106
1150
|
expect(logSpy).toHaveBeenCalledWith(
|
|
1107
1151
|
expect.stringContaining('Restored')
|
|
@@ -20,12 +20,14 @@
|
|
|
20
20
|
*
|
|
21
21
|
* Two data hazards drive the rest of the design:
|
|
22
22
|
*
|
|
23
|
-
* - The
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
23
|
+
* - The artifact emits `gate9_build_integrity` and `gate10_sast`. An
|
|
24
|
+
* earlier version of this comment claimed the CLI numbered those the
|
|
25
|
+
* other way round and that the two were SWAPPED. That was false: the
|
|
26
|
+
* registry, gate-runner.js and the artifact all say 9=Build Integrity,
|
|
27
|
+
* 10=SAST. gate-coverage alone disagreed, via a swap table written for
|
|
28
|
+
* an inversion that never existed (#738). The table is deleted; the
|
|
29
|
+
* table and report keys are now DERIVED from githooks/gate-registry.sh
|
|
30
|
+
* so a fresh copy of the mapping cannot reappear here.
|
|
29
31
|
*
|
|
30
32
|
* - `quality-status/<branch>.json` records the commit it was generated
|
|
31
33
|
* from. Rendering it for a different HEAD silently presents stale
|
|
@@ -81,17 +83,28 @@ describe('gate coverage — four states, never a false green (#636)', () => {
|
|
|
81
83
|
expect(version.reason).toMatch(/hook|git commit|not run/i);
|
|
82
84
|
});
|
|
83
85
|
|
|
84
|
-
it('AC-636-02:
|
|
85
|
-
//
|
|
86
|
-
// Integrity
|
|
86
|
+
it('AC-636-02: gate 9 is Build Integrity and gate 10 is SAST, matching the artifact keys', () => {
|
|
87
|
+
// This assertion replaces an earlier one that pinned 9=SAST / 10=Build
|
|
88
|
+
// Integrity and called it "the CLI's numbering, not the artifact's". That
|
|
89
|
+
// claim was false: githooks/pre-commit emits `gate9_build_integrity` and
|
|
90
|
+
// `gate10_sast`, exactly like gate-registry.sh and gate-runner.js. Only
|
|
91
|
+
// gate-coverage disagreed, via a swap table asserting the producer numbered
|
|
92
|
+
// them "the other way round" (#738).
|
|
93
|
+
//
|
|
94
|
+
// The old assertion is DELETED rather than inverted in place: an inverted
|
|
95
|
+
// assertion would still be a hand-written number->name mapping — a second
|
|
96
|
+
// copy of the fact, which is the defect class itself. The expectation now
|
|
97
|
+
// comes from the registry through the derived table, and
|
|
98
|
+
// scripts/__tests__/gate-identity-cross-surface.test.cjs compares every
|
|
99
|
+
// surface so a fresh copy fails a test instead of misleading a reader.
|
|
87
100
|
const rows = buildCoverageRows(artifact(), { headCommit: 'a0bceb9c0000000000000000000000000000000' });
|
|
88
101
|
const build = rows.find((r) => r.name === 'Build Integrity');
|
|
89
102
|
const sast = rows.find((r) => r.name === 'SAST Security');
|
|
90
103
|
expect(build, 'Build Integrity row must exist').toBeDefined();
|
|
91
104
|
expect(sast, 'SAST row must exist').toBeDefined();
|
|
92
|
-
//
|
|
93
|
-
expect(build.gate).toBe(
|
|
94
|
-
expect(sast.gate).toBe(
|
|
105
|
+
// Evidence: the real artifact keys (hooked at pre-commit:6158/6163).
|
|
106
|
+
expect(build.gate).toBe(9);
|
|
107
|
+
expect(sast.gate).toBe(10);
|
|
95
108
|
});
|
|
96
109
|
|
|
97
110
|
it('AC-636-03: a stale artifact is marked STALE instead of presented as current', () => {
|
|
@@ -135,3 +148,57 @@ describe('gate coverage — four states, never a false green (#636)', () => {
|
|
|
135
148
|
}
|
|
136
149
|
});
|
|
137
150
|
});
|
|
151
|
+
|
|
152
|
+
describe('REQ-GATEID-007 — artifact selection is deterministic or fails', () => {
|
|
153
|
+
const fs = require('node:fs');
|
|
154
|
+
const os = require('node:os');
|
|
155
|
+
const pathMod = require('node:path');
|
|
156
|
+
const { readQualityStatus } = require('../gate-coverage.js');
|
|
157
|
+
|
|
158
|
+
function makeRepo(artifacts) {
|
|
159
|
+
const root = fs.mkdtempSync(pathMod.join(os.tmpdir(), 'xp-gate-coverage-'));
|
|
160
|
+
const dir = pathMod.join(root, '.xp-gate', 'quality-status');
|
|
161
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
162
|
+
for (const [name, body] of Object.entries(artifacts)) {
|
|
163
|
+
fs.writeFileSync(pathMod.join(dir, `${name}.json`), JSON.stringify(body));
|
|
164
|
+
}
|
|
165
|
+
return root;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
it('AC-GATEID-007-01/04: several artifacts refuse to pick by directory order', () => {
|
|
169
|
+
// This is the second cause of the wrong output this sprint fixes: bare
|
|
170
|
+
// `xp-gate gate-coverage` used to read whichever file readdirSync returned
|
|
171
|
+
// first -- here `land-pr438.json` (commit 33672f6d) rather than the branch's
|
|
172
|
+
// own `main.json`. Reading the wrong object beats reading a stale one for
|
|
173
|
+
// danger, and the `stale: true` notice masked it.
|
|
174
|
+
const root = makeRepo({ 'cam-a': { commit: 'aaa' }, 'cam-b': { commit: 'bbb' } });
|
|
175
|
+
const status = readQualityStatus(root);
|
|
176
|
+
expect(status.artifact).toBeNull();
|
|
177
|
+
expect(status.error).toBeTruthy();
|
|
178
|
+
// The migration path must be discoverable from the message itself.
|
|
179
|
+
expect(status.error).toMatch(/--branch/);
|
|
180
|
+
expect(status.candidates.sort()).toEqual(['cam-a', 'cam-b']);
|
|
181
|
+
// Every candidate must be named, not merely "there are several".
|
|
182
|
+
expect(status.error).toMatch(/cam-a/);
|
|
183
|
+
expect(status.error).toMatch(/cam-b/);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('AC-GATEID-007-02: a single artifact still works', () => {
|
|
187
|
+
const root = makeRepo({ only: { commit: 'ccc', gates: {} } });
|
|
188
|
+
const status = readQualityStatus(root);
|
|
189
|
+
expect(status.error).toBeUndefined();
|
|
190
|
+
expect(status.artifact.commit).toBe('ccc');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('AC-GATEID-007-03: an explicit --branch that does not exist errors instead of falling back', () => {
|
|
194
|
+
const root = makeRepo({ other: { commit: 'ddd', gates: {} } });
|
|
195
|
+
const status = readQualityStatus(root, 'missing');
|
|
196
|
+
expect(status.artifact).toBeNull();
|
|
197
|
+
expect(status.error).toMatch(/missing/);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('AC-GATEID-007-03: an explicit --branch reads exactly that artifact', () => {
|
|
201
|
+
const root = makeRepo({ 'cam-a': { commit: 'aaa' }, 'cam-b': { commit: 'bbb' } });
|
|
202
|
+
expect(readQualityStatus(root, 'cam-b').artifact.commit).toBe('bbb');
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -17,6 +17,28 @@ const { GATE_REGISTRY, resolveAlias } = require('../gate-runner');
|
|
|
17
17
|
|
|
18
18
|
const REPO_ROOT = path.join(__dirname, '../../../..');
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Concatenate every file that participates in the pre-commit gate chain: the
|
|
22
|
+
* entry point, the ordered driver, and one body per gate.
|
|
23
|
+
*
|
|
24
|
+
* #798 moved each gate's banner and logic out of pre-commit into
|
|
25
|
+
* gate-entries/. Assertions about gate NAMES must therefore read the whole
|
|
26
|
+
* chain, or they pass while the names moved to a file nothing sources.
|
|
27
|
+
* @returns {string} the chain's source text, newline-joined
|
|
28
|
+
*/
|
|
29
|
+
function readGateChain() {
|
|
30
|
+
const parts = [fs.readFileSync(path.join(REPO_ROOT, 'githooks/pre-commit'), 'utf8')];
|
|
31
|
+
const driver = path.join(REPO_ROOT, 'githooks/gate-driver.sh');
|
|
32
|
+
if (fs.existsSync(driver)) parts.push(fs.readFileSync(driver, 'utf8'));
|
|
33
|
+
const entriesDir = path.join(REPO_ROOT, 'githooks/gate-entries');
|
|
34
|
+
if (fs.existsSync(entriesDir)) {
|
|
35
|
+
for (const f of fs.readdirSync(entriesDir).sort()) {
|
|
36
|
+
if (f.endsWith('.sh')) parts.push(fs.readFileSync(path.join(entriesDir, f), 'utf8'));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return parts.join('\n');
|
|
40
|
+
}
|
|
41
|
+
|
|
20
42
|
describe('gate numbering matches the hook (#677)', () => {
|
|
21
43
|
it('AC-686-01: gate 9 is Build Integrity and gate 10 is SAST Security', () => {
|
|
22
44
|
expect(GATE_REGISTRY['9'].name).toBe('Build Integrity');
|
|
@@ -26,7 +48,12 @@ describe('gate numbering matches the hook (#677)', () => {
|
|
|
26
48
|
it('AC-686-02: the hook agrees — its own output names 9 as Build integrity', () => {
|
|
27
49
|
// Reads the hook rather than restating the constant: if the hook ever
|
|
28
50
|
// renumbers again, this fails and points at which side moved.
|
|
29
|
-
|
|
51
|
+
//
|
|
52
|
+
// #798 moved each gate's banner into its own gate-entries/ file, so the
|
|
53
|
+
// assertion reads the whole chain. It deliberately does NOT assert on
|
|
54
|
+
// pre-commit alone: that would pass while every banner sat in a file no
|
|
55
|
+
// hook sources -- the exact failure #677 was filed about.
|
|
56
|
+
const hook = readGateChain();
|
|
30
57
|
expect(hook).toMatch(/→ Gate 9: Build integrity/);
|
|
31
58
|
expect(hook).toMatch(/GATE 10: Semgrep SAST/);
|
|
32
59
|
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-DEPLOY-001/002 install.sh 读生成的部署清单投影(AC-DEPLOY-06)
|
|
3
|
+
* @intent install.sh 曾把 hook/gate 清单各写一份字面量,且与真实磁盘内容不符:
|
|
4
|
+
* HOOKS_LIST 只有 3 个(漏 post-commit 与 hook-module-resolution.sh),
|
|
5
|
+
* GATE_SCRIPTS 只有 7 个(漏 gate-6-layers.sh / gate-12-file-hygiene.sh /
|
|
6
|
+
* gate-registry.sh)。清单漏项的表现不是报错,而是「装完了但那个 gate 从不
|
|
7
|
+
* 运行」—— 静默失效比崩溃更难发现。这里断言 install.sh 改读
|
|
8
|
+
* githooks/deploy-manifest.sh 投影,并且删掉了那两份字面量。
|
|
9
|
+
* 同时断言 bash 上下文守卫:清单以数组形式展开,POSIX sh 下数组静默变成
|
|
10
|
+
* 空字符串 → 一个 hook 都不装却报成功,因此必须 fail-closed 提示用 bash。
|
|
11
|
+
* @covers AC-DEPLOY-06
|
|
12
|
+
*/
|
|
13
|
+
const fs = require('node:fs');
|
|
14
|
+
const os = require('node:os');
|
|
15
|
+
const path = require('node:path');
|
|
16
|
+
const { spawnSync } = require('node:child_process');
|
|
17
|
+
|
|
18
|
+
const REPO_ROOT = path.resolve(__dirname, '..', '..', '..', '..');
|
|
19
|
+
const INSTALL_SH = path.join(REPO_ROOT, 'githooks', 'install.sh');
|
|
20
|
+
const MANIFEST_SH = path.join(REPO_ROOT, 'githooks', 'deploy-manifest.sh');
|
|
21
|
+
|
|
22
|
+
const manifest = require('../deploy-manifest.js');
|
|
23
|
+
|
|
24
|
+
const BASH = process.env.XP_GATE_BASH_BIN || (process.platform === 'win32' ? 'bash' : '/bin/bash');
|
|
25
|
+
|
|
26
|
+
describe('install.sh sources the generated deploy manifest (AC-DEPLOY-06)', () => {
|
|
27
|
+
const src = fs.readFileSync(INSTALL_SH, 'utf8');
|
|
28
|
+
|
|
29
|
+
it('AC-DEPLOY-06a: source 生成的投影而非自持清单', () => {
|
|
30
|
+
expect(src).toMatch(/(?:source|\.)\s+"\$[A-Z_]*DEPLOY_MANIFEST"/);
|
|
31
|
+
// 反空缺:两份字面量清单必须消失,否则「读投影」只是多了一行没人用的 source。
|
|
32
|
+
expect(src).not.toMatch(/^GATE_SCRIPTS="gate-3\.sh/m);
|
|
33
|
+
expect(src).not.toMatch(/^HOOKS_LIST="pre-commit/m);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('AC-DEPLOY-06b: 非 bash 环境 fail-closed(数组在 POSIX sh 下静默为空)', () => {
|
|
37
|
+
expect(src).toMatch(/BASH_VERSION/);
|
|
38
|
+
const guard = src.slice(src.indexOf('BASH_VERSION'), src.indexOf('BASH_VERSION') + 400);
|
|
39
|
+
expect(guard).toMatch(/exit\s+1/);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('AC-DEPLOY-06c: 投影里的清单覆盖磁盘真实的 gate 文件(防漏项)', () => {
|
|
43
|
+
// 这条是 AC-DEPLOY-02 的思想在 shell 侧的复用:清单必须覆盖磁盘,而不是反过来。
|
|
44
|
+
for (const gate of manifest.GATE_FILES) {
|
|
45
|
+
expect(fs.existsSync(path.join(REPO_ROOT, 'githooks', gate)), `githooks/${gate} 不存在`).toBe(true);
|
|
46
|
+
}
|
|
47
|
+
for (const hook of manifest.HOOK_FILES) {
|
|
48
|
+
expect(fs.existsSync(path.join(REPO_ROOT, 'githooks', hook)), `githooks/${hook} 不存在`).toBe(true);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('AC-DEPLOY-06d: 在临时 git 仓库里实跑 install.sh,装出的 hook 与 gate 齐全', () => {
|
|
53
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-gate-ac06-'));
|
|
54
|
+
try {
|
|
55
|
+
const run = (cmd, args, cwd) => spawnSync(cmd, args, { cwd, encoding: 'utf8', shell: false });
|
|
56
|
+
const git = (args) => run('git', args, tmp);
|
|
57
|
+
const init = git(['init', '-q']);
|
|
58
|
+
if (init.status !== 0) {
|
|
59
|
+
// git 不可用时不做假绿:跳过改由 c 断言覆盖的存在性检查兜底。
|
|
60
|
+
expect(init.error || init.stderr).toBeTruthy();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
git(['config', 'user.email', 't@example.com']);
|
|
64
|
+
git(['config', 'user.name', 't']);
|
|
65
|
+
// install.sh 从自己的目录定位源文件,因此直接执行仓库里的那份。
|
|
66
|
+
const res = spawnSync(BASH, [INSTALL_SH], { cwd: tmp, encoding: 'utf8', shell: false });
|
|
67
|
+
expect(res.status, `install.sh 退出码非 0:${res.stdout}${res.stderr}`).toBe(0);
|
|
68
|
+
|
|
69
|
+
const hooksDir = path.join(tmp, '.git', 'hooks');
|
|
70
|
+
for (const hook of manifest.HOOK_FILES) {
|
|
71
|
+
expect(fs.existsSync(path.join(hooksDir, hook)), `install.sh 未安装 ${hook}`).toBe(true);
|
|
72
|
+
}
|
|
73
|
+
for (const gate of manifest.GATE_FILES) {
|
|
74
|
+
expect(fs.existsSync(path.join(hooksDir, gate)), `install.sh 未安装 ${gate}`).toBe(true);
|
|
75
|
+
}
|
|
76
|
+
} finally {
|
|
77
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -32,11 +32,40 @@ const {
|
|
|
32
32
|
|
|
33
33
|
let TMP_REPO;
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Build the empty git repository ONCE, then copy it per case.
|
|
37
|
+
*
|
|
38
|
+
* Every case writes its own fixture into a pristine repo (and `afterEach`
|
|
39
|
+
* deletes the tree), so each one genuinely needs a fresh repo -- but building
|
|
40
|
+
* that repo means three git processes (`init` + two `config`), measured at
|
|
41
|
+
* 1.4-5.0 s per case here (median ~2.6 s). Across 17 cases that was most of this
|
|
42
|
+
* file's runtime.
|
|
43
|
+
*
|
|
44
|
+
* Copying a prepared `.git` measured 1.1 s/case less (median 1.5 s vs 2.6 s) and
|
|
45
|
+
* keeps everything the cases rely on: verified after `fs.cpSync` that `git add
|
|
46
|
+
* -A -f` succeeds and `git config user.email` still reports the template
|
|
47
|
+
* identity. It also narrows the spread -- copying varied 0.9-2.2 s against
|
|
48
|
+
* `git init`'s 1.4-5.0 s.
|
|
49
|
+
*
|
|
50
|
+
* No `core.hooksPath` override is needed: this file never runs `git commit`, so
|
|
51
|
+
* this machine's global hooks cannot fire (the only `commit` occurrence is prose).
|
|
52
|
+
*/
|
|
53
|
+
let repoTemplate;
|
|
54
|
+
|
|
55
|
+
beforeAll(() => {
|
|
56
|
+
repoTemplate = fs.mkdtempSync(path.join(os.tmpdir(), 'mirror-sync-tpl-'));
|
|
57
|
+
execFileSync('git', ['init', '-q'], { cwd: repoTemplate });
|
|
58
|
+
execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: repoTemplate });
|
|
59
|
+
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: repoTemplate });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
afterAll(() => {
|
|
63
|
+
if (repoTemplate) fs.rmSync(repoTemplate, { recursive: true, force: true });
|
|
64
|
+
});
|
|
65
|
+
|
|
35
66
|
beforeEach(() => {
|
|
36
67
|
TMP_REPO = fs.mkdtempSync(path.join(os.tmpdir(), 'mirror-sync-'));
|
|
37
|
-
|
|
38
|
-
execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: TMP_REPO });
|
|
39
|
-
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: TMP_REPO });
|
|
68
|
+
fs.cpSync(repoTemplate, TMP_REPO, { recursive: true });
|
|
40
69
|
});
|
|
41
70
|
|
|
42
71
|
afterEach(() => {
|
|
@@ -146,7 +175,14 @@ describe('collectMirrorPairs — AC-713-02 pair discovery', () => {
|
|
|
146
175
|
|
|
147
176
|
const pairs = collectMirrorPairs(TMP_REPO);
|
|
148
177
|
const found = pairs.find((p) => p.canonical === 'githooks/lib' && p.mirror === 'src/npm-package/hooks/lib');
|
|
178
|
+
// Asserted on the pair's own fields, not only on its existence: "a pair object
|
|
179
|
+
// was returned" is satisfied by a pair whose mirror path is wrong, which is the
|
|
180
|
+
// bug this case is named after -- the pair must be the CORRECT one.
|
|
149
181
|
expect(found).toBeDefined();
|
|
182
|
+
expect({ canonical: found.canonical, mirror: found.mirror }).toEqual({
|
|
183
|
+
canonical: 'githooks/lib',
|
|
184
|
+
mirror: 'src/npm-package/hooks/lib',
|
|
185
|
+
});
|
|
150
186
|
});
|
|
151
187
|
|
|
152
188
|
it('does not invent a pair for a canonical tree with no mirror', () => {
|
|
@@ -155,6 +191,12 @@ describe('collectMirrorPairs — AC-713-02 pair discovery', () => {
|
|
|
155
191
|
|
|
156
192
|
const pairs = collectMirrorPairs(TMP_REPO);
|
|
157
193
|
const found = pairs.find((p) => p.canonical === 'githooks/lib');
|
|
194
|
+
// Asserted on the collection, not only on `found`: the bug this guards against
|
|
195
|
+
// is "a canonical tree with no mirror gets paired with something", and a bare
|
|
196
|
+
// `toBeUndefined()` cannot distinguish that from the whole function returning
|
|
197
|
+
// nothing. Naming the discovered canonical set makes the empty result mean
|
|
198
|
+
// "this pair was not invented" rather than "no pairs were found at all".
|
|
199
|
+
expect(pairs.map((p) => p.canonical)).toEqual([]);
|
|
158
200
|
expect(found).toBeUndefined();
|
|
159
201
|
});
|
|
160
202
|
});
|
|
@@ -124,14 +124,17 @@ describe('Issue #411: every gate-*.sh at package root is listed in "files"', ()
|
|
|
124
124
|
expect(missing).toEqual([]);
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
it('files array covers
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
it('files array covers every GATE_FILES entry (REQ-DEPLOY-001)', () => {
|
|
128
|
+
// Was: a regex over doctor.js's EXPECTED_GATE_SCRIPTS literal. That list is
|
|
129
|
+
// now derived from the deploy manifest, so the source of truth is read
|
|
130
|
+
// directly — and asserting on the manifest instead of one consumer's copy
|
|
131
|
+
// makes this cover every gate the package is supposed to ship. It caught a
|
|
132
|
+
// real gap on first run: gate-registry.sh, the routing table the hooks
|
|
133
|
+
// source, was absent from "files", so a published tarball would not have it.
|
|
134
|
+
const { GATE_FILES } = require('../deploy-manifest.js');
|
|
135
|
+
expect(GATE_FILES.length).toBeGreaterThan(0);
|
|
133
136
|
const files = pkg.files || [];
|
|
134
|
-
const missing =
|
|
137
|
+
const missing = GATE_FILES.filter(f => !files.includes(f));
|
|
135
138
|
expect(missing).toEqual([]);
|
|
136
139
|
});
|
|
137
140
|
});
|