@boyingliu01/xp-gate 0.38.124 → 0.38.126

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.
Files changed (58) hide show
  1. package/adapters/gate-3.sh +34 -1
  2. package/adapters/gate-7.sh +15 -6
  3. package/bin/xp-gate.js +24 -0
  4. package/build-integrity/gate-10.ts +33 -8
  5. package/gate-3.sh +34 -1
  6. package/gate-registry.sh +3 -1
  7. package/hooks/deploy-manifest.sh +1 -0
  8. package/hooks/gate-3.sh +34 -1
  9. package/hooks/gate-entries/gate-1-entry.sh +35 -24
  10. package/hooks/gate-entries/gate-5-entry.sh +55 -19
  11. package/hooks/gate-entries/gate-6-entry.sh +15 -6
  12. package/hooks/gate-registry.sh +3 -1
  13. package/hooks/lib/gate-status.sh +164 -0
  14. package/hooks/lib/jscpd-run.sh +9 -1
  15. package/hooks/lib/native-path.sh +54 -0
  16. package/hooks/lib/toolchain-path.sh +38 -0
  17. package/hooks/pre-push +13 -4
  18. package/lib/__tests__/arch.test.js +7 -1
  19. package/lib/__tests__/audit-skip-reasons.test.ts +143 -0
  20. package/lib/__tests__/check-tools-list.test.js +155 -0
  21. package/lib/__tests__/doctor-tool-delegation.test.js +156 -0
  22. package/lib/__tests__/install-tools-repair.test.js +263 -0
  23. package/lib/__tests__/language-capability.test.js +27 -0
  24. package/lib/__tests__/tool-audit-collect.test.js +184 -0
  25. package/lib/__tests__/tool-audit-fixtures.js +87 -0
  26. package/lib/__tests__/tool-audit-latest.test.js +84 -0
  27. package/lib/__tests__/tool-audit.test.js +428 -0
  28. package/lib/deploy-manifest.js +1 -0
  29. package/lib/doctor-tool-checks.js +129 -0
  30. package/lib/doctor.js +15 -46
  31. package/lib/gate-audit.ts +80 -0
  32. package/lib/gate-runner.js +5 -0
  33. package/lib/language-capability-surfaces.js +70 -6
  34. package/lib/language-capability.js +3 -0
  35. package/lib/language-tools.js +409 -93
  36. package/lib/mattpocock-license-verdict.json +1 -1
  37. package/lib/tool-audit.js +729 -0
  38. package/package.json +1 -1
  39. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  40. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  41. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  42. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  43. package/plugins/dsh/package.json +1 -1
  44. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  45. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  46. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  47. package/plugins/dsh/src/skills.test.ts +9 -0
  48. package/plugins/opencode/package.json +1 -1
  49. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  50. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  51. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  52. package/plugins/qoder/plugin.json +1 -1
  53. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  54. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  55. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  56. package/skills/delphi-review/AGENTS.md +1 -1
  57. package/skills/sprint-flow/AGENTS.md +1 -1
  58. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -0,0 +1,184 @@
1
+ /**
2
+ * check-tools must report the COMPLETE tool set, not just the languages the
3
+ * current project happens to use.
4
+ *
5
+ * The gap this pins (2026-11-23): `check-tools` in this repo printed 8 entries —
6
+ * the tools of the four detected languages — while doctor probed a different set
7
+ * of 8 cross-language CLI tools (jscpd, checkov, ...). Neither command could see
8
+ * the union, so a broken jscpd was invisible to `check-tools` and a broken
9
+ * eslint invisible to `doctor`. "Complete" has to mean the union, deduplicated,
10
+ * because the same tool can appear in both lists (semgrep: Gate 10 and Python).
11
+ */
12
+ const os = require('os');
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+
16
+ const { collectGateTools, auditAllTools } = require('../tool-audit.js');
17
+
18
+ /** Minimal LANGUAGE_REGISTRY-shaped fixture. */
19
+ const REGISTRY = {
20
+ typescript: {
21
+ name: 'TypeScript/JavaScript',
22
+ tools: [{ name: 'eslint', checkCmd: 'eslint --version', optional: false, gates: ['Gate 1'] }],
23
+ },
24
+ python: {
25
+ name: 'Python',
26
+ tools: [
27
+ // Same tool as the cross-language list, listed per-language too.
28
+ { name: 'semgrep', checkCmd: 'semgrep --version', optional: false, gates: ['Gate 10'] },
29
+ { name: 'mypy', checkCmd: 'mypy --version', optional: false, gates: ['Gate 1'] },
30
+ ],
31
+ },
32
+ };
33
+
34
+ const CLI_TOOLS = [
35
+ { tool: 'semgrep', checkCmd: 'semgrep --version', gates: ['Gate 10 (SAST)'] },
36
+ { tool: 'jscpd', checkCmd: 'jscpd --version', gates: ['Gate 2 (Duplicate Code)'] },
37
+ ];
38
+
39
+ describe('collectGateTools: completeness', () => {
40
+ /**
41
+ * @test REQ-TOOLS-005
42
+ * @intent 清单必须同时包含跨语言 CLI 工具与语言工具,不能只取其一
43
+ * @covers AC-TOOLS-005-01
44
+ */
45
+ it('includes both the cross-language CLI tools and the language tools', () => {
46
+ const tools = collectGateTools({
47
+ registry: REGISTRY,
48
+ cliTools: CLI_TOOLS,
49
+ languages: ['typescript', 'python'],
50
+ });
51
+ const names = tools.map((t) => t.name);
52
+ expect(names).toContain('jscpd'); // cross-language only
53
+ expect(names).toContain('eslint'); // language only
54
+ expect(names).toContain('mypy'); // language only
55
+ });
56
+
57
+ /**
58
+ * @test REQ-TOOLS-005
59
+ * @intent 同一工具在两处出现只能算一个,且门禁标签合并
60
+ * @covers AC-TOOLS-005-02
61
+ */
62
+ it('deduplicates a tool that appears in both lists and merges its gates', () => {
63
+ const tools = collectGateTools({
64
+ registry: REGISTRY,
65
+ cliTools: CLI_TOOLS,
66
+ languages: ['typescript', 'python'],
67
+ });
68
+ const semgrep = tools.filter((t) => t.name === 'semgrep');
69
+ expect(semgrep).toHaveLength(1);
70
+ expect(semgrep[0].gates.join(' ')).toContain('Gate 10');
71
+ });
72
+
73
+ /**
74
+ * @test REQ-TOOLS-005
75
+ * @intent 指定语言时只取该语言工具,但跨语言 CLI 工具仍必须包含
76
+ * @covers AC-TOOLS-005-03
77
+ */
78
+ it('filters by language but never drops the cross-language tools', () => {
79
+ const tools = collectGateTools({
80
+ registry: REGISTRY,
81
+ cliTools: CLI_TOOLS,
82
+ languages: ['typescript'],
83
+ });
84
+ const names = tools.map((t) => t.name);
85
+ expect(names).toContain('eslint');
86
+ expect(names).not.toContain('mypy');
87
+ expect(names).toContain('jscpd');
88
+ });
89
+
90
+ /**
91
+ * @test REQ-TOOLS-005
92
+ * @intent 必须能取全量(不受项目语言限制),否则"完备性"无从判起
93
+ * @covers AC-TOOLS-005-04
94
+ */
95
+ it('can list every registered tool when no language filter is given', () => {
96
+ const tools = collectGateTools({ registry: REGISTRY, cliTools: CLI_TOOLS, languages: null });
97
+ const names = tools.map((t) => t.name);
98
+ expect(names).toEqual(expect.arrayContaining(['eslint', 'mypy', 'semgrep', 'jscpd']));
99
+ });
100
+ });
101
+
102
+ describe('auditAllTools: produces a list, never throws', () => {
103
+ /**
104
+ * @test REQ-TOOLS-006
105
+ * @intent 每个工具都产出一条审计记录;单个探针失败不能中断整份清单
106
+ * @covers AC-TOOLS-006-01
107
+ */
108
+ it('returns one row per tool even when one probe throws', () => {
109
+ const rows = auditAllTools(
110
+ [
111
+ { name: 'ok-tool', checkCmd: 'ok-tool --version' },
112
+ { name: 'boom', checkCmd: 'boom --version' },
113
+ ],
114
+ {
115
+ runProbe: (cmd) => {
116
+ if (String(cmd).startsWith('boom')) throw new Error('kaboom');
117
+ return { status: 0, stdout: '1.2.3', stderr: '' };
118
+ },
119
+ locate: () => ['/usr/bin/x'],
120
+ realpath: (p) => p,
121
+ resolveLatest: () => null,
122
+ },
123
+ );
124
+ expect(rows).toHaveLength(2);
125
+ expect(rows.find((r) => r.name === 'boom').validityReason).toContain('kaboom');
126
+ });
127
+
128
+ /**
129
+ * @test REQ-TOOLS-006
130
+ * @intent resolveLatest 抛异常时该工具记为 unknown,不能让整份报告失败
131
+ * @covers AC-TOOLS-006-02
132
+ */
133
+ it('treats a failing version lookup as unknown, not as an exception', () => {
134
+ const rows = auditAllTools([{ name: 'x', checkCmd: 'x --version' }], {
135
+ runProbe: () => ({ status: 0, stdout: '1.0.0', stderr: '' }),
136
+ locate: () => ['/usr/bin/x'],
137
+ realpath: (p) => p,
138
+ resolveLatest: () => {
139
+ throw new Error('registry unreachable');
140
+ },
141
+ });
142
+ expect(rows).toHaveLength(1);
143
+ expect(rows[0].currency).toBe('unknown');
144
+ });
145
+ });
146
+
147
+ describe('collectGateTools: installer travels with the tool', () => {
148
+ /**
149
+ * @test REQ-TOOLS-009
150
+ * @intent 收集器必须保留 install 字段,否则 install-tools 会对有安装命令的工具报
151
+ * "no installer known"(shellcheck 实况)
152
+ * @covers AC-TOOLS-009-01
153
+ */
154
+ it('keeps the install command from the registry entry', () => {
155
+ const registry = {
156
+ shell: {
157
+ name: 'Shell',
158
+ tools: [{
159
+ name: 'shellcheck',
160
+ checkCmd: 'shellcheck --version',
161
+ optional: true,
162
+ gates: ['Gate 1'],
163
+ install: { linux: 'apt-get install shellcheck' },
164
+ }],
165
+ },
166
+ };
167
+ const tools = collectGateTools({ registry, cliTools: [], languages: ['shell'] });
168
+ expect(tools[0].install).toEqual({ linux: 'apt-get install shellcheck' });
169
+ });
170
+
171
+ /**
172
+ * @test REQ-TOOLS-009
173
+ * @intent 跨语言 CLI 工具的安装命令也要保留(doctor 用同一份表)
174
+ * @covers AC-TOOLS-009-02
175
+ */
176
+ it('keeps the install command from a cross-language CLI entry', () => {
177
+ const tools = collectGateTools({
178
+ registry: {},
179
+ cliTools: [{ tool: 'jscpd', checkCmd: 'jscpd --version', gates: [], install: { linux: 'npm install -g jscpd' } }],
180
+ languages: null,
181
+ });
182
+ expect(tools.find((t) => t.name === 'jscpd').install).toEqual({ linux: 'npm install -g jscpd' });
183
+ });
184
+ });
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Shared fixtures for the tool-audit / check-tools / install-tools tests.
3
+ *
4
+ * Kept in one place because three suites assert against the same shapes: a
5
+ * duplicated `row()` builder drifted 16% of a file the first time it was copied,
6
+ * and a fixture that disagrees with its sibling produces tests that pass for
7
+ * different reasons.
8
+ */
9
+
10
+ /** Capture console output from an async handler. */
11
+ async function capture(fn) {
12
+ const lines = [];
13
+ const origLog = console.log;
14
+ const origErr = console.error;
15
+ console.log = (...a) => lines.push(a.join(' '));
16
+ console.error = (...a) => lines.push(a.join(' '));
17
+ try {
18
+ const code = await fn();
19
+ return { code, out: lines.join('\n') };
20
+ } finally {
21
+ console.log = origLog;
22
+ console.error = origErr;
23
+ }
24
+ }
25
+
26
+ /**
27
+ * One audit row, defaulting to a healthy single-copy current tool so each test
28
+ * only states the property it cares about.
29
+ */
30
+ function auditRow(name, over = {}) {
31
+ return {
32
+ name,
33
+ available: true,
34
+ validityReason: '',
35
+ npxInvoked: false,
36
+ paths: [`/home/u/.local/bin/${name}`],
37
+ distinctRealPaths: [`/home/u/.local/bin/${name}`],
38
+ duplicated: false,
39
+ version: '1.0.0',
40
+ installedVersion: '1.0.0',
41
+ latestVersion: '1.0.0',
42
+ outdated: false,
43
+ currency: 'current',
44
+ gates: [],
45
+ optional: false,
46
+ languages: ['shell'],
47
+ ...over,
48
+ };
49
+ }
50
+
51
+ /** A registry tool definition carrying an installer command. */
52
+ function toolDefinition(name, over = {}) {
53
+ return {
54
+ name,
55
+ checkCmd: `${name} --version`,
56
+ optional: false,
57
+ gates: [],
58
+ install: { linux: `npm install -g ${name}` },
59
+ ...over,
60
+ };
61
+ }
62
+
63
+ /** A throwaway project directory for language detection. */
64
+ function tmpProject() {
65
+ const fs = require('fs');
66
+ const os = require('os');
67
+ const path = require('path');
68
+ return fs.mkdtempSync(path.join(os.tmpdir(), 'xp-gate-tools-'));
69
+ }
70
+
71
+ /**
72
+ * Write a fixture file, failing loudly with the path when it cannot be written:
73
+ * a silent failure would make "language not detected" look like a pass.
74
+ */
75
+ function writeFixture(dir, name, content) {
76
+ const fs = require('fs');
77
+ const path = require('path');
78
+ const target = path.join(dir, name);
79
+ try {
80
+ fs.writeFileSync(target, content);
81
+ } catch (err) {
82
+ throw new Error(`cannot write fixture ${target}: ${err instanceof Error ? err.message : String(err)}`);
83
+ }
84
+ return target;
85
+ }
86
+
87
+ module.exports = { capture, auditRow, toolDefinition, tmpProject, writeFixture };
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Latest-version resolution — the input to every "is this outdated" verdict.
3
+ *
4
+ * DESIGN CONSTRAINT (measured on this machine): every lookup here may hit the
5
+ * network, and the network is unreliable here (GitHub API returned an empty body
6
+ * twice while writing this). So the resolver must:
7
+ *
8
+ * - never hang a report (bounded timeout),
9
+ * - never turn a lookup failure into "up to date" (unknown ≠ current),
10
+ * - be injectable so the audit tests never touch the network.
11
+ *
12
+ * The registry is chosen per tool NAME, not per language: `jscpd` is an npm
13
+ * package whether the project is TypeScript or Shell, and `shellcheck` is never
14
+ * an npm package at all.
15
+ */
16
+ const { resolveLatestVersion, registryFor } = require('../tool-audit.js');
17
+
18
+ describe('tool-audit: latest version resolution', () => {
19
+ /**
20
+ * @test REQ-TOOLS-008
21
+ * @intent 按工具名决定查询渠道:npm 包走 npm,其余走已知版本表
22
+ * @covers AC-TOOLS-008-01
23
+ */
24
+ it('routes npm-distributed tools to the npm registry and others to the table', () => {
25
+ expect(registryFor('jscpd')).toBe('npm');
26
+ expect(registryFor('eslint')).toBe('npm');
27
+ expect(registryFor('@archlinter/cli')).toBe('npm');
28
+ expect(registryFor('shellcheck')).toBe('table');
29
+ expect(registryFor('hadolint')).toBe('table');
30
+ expect(registryFor('gitleaks')).toBe('table');
31
+ });
32
+
33
+ /**
34
+ * @test REQ-TOOLS-008
35
+ * @intent 查询失败必须返回 null(→ unknown),不能回落成"当前版本"显得已是最新
36
+ * @covers AC-TOOLS-008-02
37
+ */
38
+ it('returns null when the lookup fails instead of assuming current', () => {
39
+ const v = resolveLatestVersion('jscpd', {
40
+ runNpmView: () => {
41
+ throw new Error('ETIMEDOUT');
42
+ },
43
+ table: {},
44
+ });
45
+ expect(v).toBeNull();
46
+ });
47
+
48
+ /**
49
+ * @test REQ-TOOLS-008
50
+ * @intent npm 查询成功时返回净版本号
51
+ * @covers AC-TOOLS-008-03
52
+ */
53
+ it('returns the bare version from npm', () => {
54
+ const v = resolveLatestVersion('jscpd', { runNpmView: () => '5.4.3\n', table: {} });
55
+ expect(v).toBe('5.4.3');
56
+ });
57
+
58
+ /**
59
+ * @test REQ-TOOLS-008
60
+ * @intent 表中没有的工具返回 null,而不是猜测
61
+ * @covers AC-TOOLS-008-04
62
+ */
63
+ it('returns null for a tool with no known channel', () => {
64
+ expect(resolveLatestVersion('mystery-tool', { runNpmView: () => null, table: {} })).toBeNull();
65
+ });
66
+
67
+ /**
68
+ * @test REQ-TOOLS-008
69
+ * @intent 表中有的工具直接取表值(离线可用)
70
+ * @covers AC-TOOLS-008-05
71
+ */
72
+ it('reads a pinned version from the offline table without any network call', () => {
73
+ let called = false;
74
+ const v = resolveLatestVersion('shellcheck', {
75
+ runNpmView: () => {
76
+ called = true;
77
+ return null;
78
+ },
79
+ table: { shellcheck: '0.11.0' },
80
+ });
81
+ expect(v).toBe('0.11.0');
82
+ expect(called).toBe(false);
83
+ });
84
+ });