@boyingliu01/xp-gate 0.38.125 → 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.
- package/adapters/gate-3.sh +34 -1
- package/adapters/gate-7.sh +15 -6
- package/bin/xp-gate.js +24 -0
- package/build-integrity/gate-10.ts +33 -8
- package/gate-3.sh +34 -1
- package/gate-registry.sh +3 -1
- package/hooks/deploy-manifest.sh +1 -0
- package/hooks/gate-3.sh +34 -1
- package/hooks/gate-entries/gate-1-entry.sh +35 -24
- package/hooks/gate-entries/gate-5-entry.sh +55 -19
- package/hooks/gate-entries/gate-6-entry.sh +15 -6
- package/hooks/gate-registry.sh +3 -1
- package/hooks/lib/gate-status.sh +164 -0
- package/hooks/lib/jscpd-run.sh +9 -1
- package/hooks/lib/native-path.sh +54 -0
- package/hooks/lib/toolchain-path.sh +38 -0
- package/hooks/pre-push +13 -4
- package/lib/__tests__/arch.test.js +7 -1
- package/lib/__tests__/audit-skip-reasons.test.ts +143 -0
- package/lib/__tests__/check-tools-list.test.js +155 -0
- package/lib/__tests__/doctor-tool-delegation.test.js +156 -0
- package/lib/__tests__/install-tools-repair.test.js +263 -0
- package/lib/__tests__/language-capability.test.js +27 -0
- package/lib/__tests__/tool-audit-collect.test.js +184 -0
- package/lib/__tests__/tool-audit-fixtures.js +87 -0
- package/lib/__tests__/tool-audit-latest.test.js +84 -0
- package/lib/__tests__/tool-audit.test.js +428 -0
- package/lib/deploy-manifest.js +1 -0
- package/lib/doctor-tool-checks.js +129 -0
- package/lib/doctor.js +15 -46
- package/lib/gate-audit.ts +80 -0
- package/lib/gate-runner.js +5 -0
- package/lib/language-capability-surfaces.js +70 -6
- package/lib/language-capability.js +3 -0
- package/lib/language-tools.js +409 -93
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/tool-audit.js +729 -0
- 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/dsh/src/skills.test.ts +9 -0
- 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
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `xp-gate check-tools` must answer three questions in ONE list:
|
|
3
|
+
* completeness (is anything missing), validity (does it actually run) and
|
|
4
|
+
* uniqueness (is there exactly one copy), plus currency (is it the latest).
|
|
5
|
+
*
|
|
6
|
+
* Before this change the command answered none of them reliably:
|
|
7
|
+
* - it only walked languages detected in the current project, so a cross-
|
|
8
|
+
* language tool (jscpd, checkov) that was broken never appeared;
|
|
9
|
+
* - validity was an exit-code check, which reported `psscriptanalyzer` as
|
|
10
|
+
* available while `Invoke-ScriptAnalyzer` did not exist (measured);
|
|
11
|
+
* - duplicates were invisible: two byte-identical hadolint binaries and an
|
|
12
|
+
* old archlint shadowing a newer npm install both passed unnoticed.
|
|
13
|
+
*
|
|
14
|
+
* These tests drive the command through its handler with an injected audit so
|
|
15
|
+
* they never touch the network or the real toolchain.
|
|
16
|
+
*/
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const os = require('os');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
|
|
21
|
+
const { handleCheckTools } = require('../language-tools.js');
|
|
22
|
+
const { capture, auditRow: row, tmpProject, writeFixture } = require('./tool-audit-fixtures.js');
|
|
23
|
+
|
|
24
|
+
describe('check-tools: the list itself', () => {
|
|
25
|
+
/**
|
|
26
|
+
* @test REQ-TOOLS-010
|
|
27
|
+
* @intent 清单必须包含跨语言 CLI 工具,不能只看项目语言
|
|
28
|
+
* @covers AC-TOOLS-010-01
|
|
29
|
+
*/
|
|
30
|
+
it('lists cross-language CLI tools even when no language uses them', async () => {
|
|
31
|
+
const dir = tmpProject();
|
|
32
|
+
writeFixture(dir, 'package.json', '{}');
|
|
33
|
+
const rows = [row('eslint'), row('jscpd'), row('checkov')];
|
|
34
|
+
const { code, out } = await capture(() =>
|
|
35
|
+
handleCheckTools(['--json', '--flat'], { projectRoot: dir, audit: () => rows }),
|
|
36
|
+
);
|
|
37
|
+
expect(code).toBe(0);
|
|
38
|
+
const parsed = JSON.parse(out);
|
|
39
|
+
const names = parsed.tools.map((t) => t.name);
|
|
40
|
+
expect(names).toEqual(expect.arrayContaining(['jscpd', 'checkov']));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @test REQ-TOOLS-010
|
|
45
|
+
* @intent 有效性:探针无输出判为不可用并给出原因(psscriptanalyzer 实况)
|
|
46
|
+
* @covers AC-TOOLS-010-02
|
|
47
|
+
*/
|
|
48
|
+
it('reports an empty-output probe as unavailable WITH a reason', async () => {
|
|
49
|
+
const dir = tmpProject();
|
|
50
|
+
const rows = [
|
|
51
|
+
row('psscriptanalyzer', {
|
|
52
|
+
available: false,
|
|
53
|
+
version: null,
|
|
54
|
+
installedVersion: null,
|
|
55
|
+
currency: 'missing',
|
|
56
|
+
validityReason: 'probe printed no output (empty output cannot prove availability)',
|
|
57
|
+
optional: true,
|
|
58
|
+
}),
|
|
59
|
+
];
|
|
60
|
+
const { out } = await capture(() =>
|
|
61
|
+
handleCheckTools(['--json', '--flat'], { projectRoot: dir, audit: () => rows, languages: [] }),
|
|
62
|
+
);
|
|
63
|
+
const t = JSON.parse(out).tools.find((x) => x.name === 'psscriptanalyzer');
|
|
64
|
+
expect(t.status).toBe('missing');
|
|
65
|
+
expect(t.reason).toMatch(/no output/i);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @test REQ-TOOLS-010
|
|
70
|
+
* @intent 唯一性:重复安装必须在清单里显式标出,并列出全部副本
|
|
71
|
+
* @covers AC-TOOLS-010-03
|
|
72
|
+
*/
|
|
73
|
+
it('marks a tool installed twice and lists every copy', async () => {
|
|
74
|
+
const dir = tmpProject();
|
|
75
|
+
const rows = [
|
|
76
|
+
row('hadolint', {
|
|
77
|
+
duplicated: true,
|
|
78
|
+
paths: ['/home/u/.local/bin/hadolint', '/home/u/.npm-global/bin/hadolint'],
|
|
79
|
+
distinctRealPaths: ['/home/u/.local/bin/hadolint', '/home/u/.npm-global/bin/hadolint'],
|
|
80
|
+
}),
|
|
81
|
+
];
|
|
82
|
+
const { out } = await capture(() =>
|
|
83
|
+
handleCheckTools(['--json', '--flat'], { projectRoot: dir, audit: () => rows, languages: [] }),
|
|
84
|
+
);
|
|
85
|
+
const t = JSON.parse(out).tools.find((x) => x.name === 'hadolint');
|
|
86
|
+
expect(t.duplicated).toBe(true);
|
|
87
|
+
expect(t.paths).toHaveLength(2);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @test REQ-TOOLS-010
|
|
92
|
+
* @intent 汇总必须同时给出缺失/重复/过期/未知四类计数,且 complete 只在全清时为真
|
|
93
|
+
* @covers AC-TOOLS-010-04
|
|
94
|
+
*/
|
|
95
|
+
it('summarizes every problem category and withholds complete until all are clear', async () => {
|
|
96
|
+
const dir = tmpProject();
|
|
97
|
+
const rows = [
|
|
98
|
+
row('ok1'),
|
|
99
|
+
row('dup1', { duplicated: true }),
|
|
100
|
+
row('old1', { outdated: true, currency: 'outdated', latestVersion: '2.0.0' }),
|
|
101
|
+
row('gone1', { available: false, currency: 'missing', installedVersion: null }),
|
|
102
|
+
row('unk1', { currency: 'unknown', outdated: null, latestVersion: null }),
|
|
103
|
+
];
|
|
104
|
+
const { out } = await capture(() =>
|
|
105
|
+
handleCheckTools(['--json', '--flat'], { projectRoot: dir, audit: () => rows, languages: [] }),
|
|
106
|
+
);
|
|
107
|
+
const s = JSON.parse(out).summary;
|
|
108
|
+
expect(s.missing).toBe(1);
|
|
109
|
+
expect(s.duplicated).toBe(1);
|
|
110
|
+
expect(s.outdated).toBe(1);
|
|
111
|
+
expect(s.unknown).toBe(1);
|
|
112
|
+
expect(s.complete).toBe(false);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @test REQ-TOOLS-010
|
|
117
|
+
* @intent 非 JSON 输出也要能同时看出三类问题,不能只打"available/missing"
|
|
118
|
+
* @covers AC-TOOLS-010-05
|
|
119
|
+
*/
|
|
120
|
+
it('prints duplicates and outdated versions in human output too', async () => {
|
|
121
|
+
const dir = tmpProject();
|
|
122
|
+
const rows = [
|
|
123
|
+
row('hadolint', {
|
|
124
|
+
outdated: true,
|
|
125
|
+
currency: 'outdated',
|
|
126
|
+
installedVersion: '2.14.0',
|
|
127
|
+
latestVersion: '2.15.1',
|
|
128
|
+
duplicated: true,
|
|
129
|
+
paths: ['/a/hadolint', '/b/hadolint'],
|
|
130
|
+
distinctRealPaths: ['/a/hadolint', '/b/hadolint'],
|
|
131
|
+
}),
|
|
132
|
+
];
|
|
133
|
+
const { out } = await capture(() =>
|
|
134
|
+
handleCheckTools([], { projectRoot: dir, audit: () => rows, languages: [] }),
|
|
135
|
+
);
|
|
136
|
+
expect(out).toMatch(/2\.14\.0/);
|
|
137
|
+
expect(out).toMatch(/2\.15\.1/);
|
|
138
|
+
expect(out.toLowerCase()).toMatch(/duplicate|重复/);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @test REQ-TOOLS-010
|
|
143
|
+
* @intent 可选的缺失工具不应让命令以失败退出,但必须仍然列出
|
|
144
|
+
* @covers AC-TOOLS-010-06
|
|
145
|
+
*/
|
|
146
|
+
it('does not fail the command for a missing OPTIONAL tool, but still lists it', async () => {
|
|
147
|
+
const dir = tmpProject();
|
|
148
|
+
const rows = [row('terraform', { available: false, currency: 'missing', installedVersion: null, optional: true })];
|
|
149
|
+
const { code, out } = await capture(() =>
|
|
150
|
+
handleCheckTools(['--json', '--flat'], { projectRoot: dir, audit: () => rows, languages: [] }),
|
|
151
|
+
);
|
|
152
|
+
expect(code).toBe(0);
|
|
153
|
+
expect(JSON.parse(out).tools).toHaveLength(1);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* doctor must DELEGATE its tool checks to the audit instead of re-implementing
|
|
3
|
+
* them.
|
|
4
|
+
*
|
|
5
|
+
* Why this matters (2026-11-23): doctor carried its own probe loop while
|
|
6
|
+
* check-tools carried another. They disagreed in three measurable ways —
|
|
7
|
+
* doctor reported `psscriptanalyzer` as available (empty-output probe read as
|
|
8
|
+
* success), doctor could not see duplicate copies, and doctor knew nothing about
|
|
9
|
+
* outdated versions. Two implementations of one rule is how they drift; the
|
|
10
|
+
* single-source fix is for doctor to consume the audit's rows.
|
|
11
|
+
*
|
|
12
|
+
* The CONTRACT doctor exposes must not change: entries are named
|
|
13
|
+
* `CLI tool: <tool> (<gates>)` with status PASS/WARN, because existing tests and
|
|
14
|
+
* consumers read exactly that.
|
|
15
|
+
*/
|
|
16
|
+
const { mapAuditRowsToDoctorChecks } = require('../doctor-tool-checks.js');
|
|
17
|
+
|
|
18
|
+
describe('doctor tool checks: delegation', () => {
|
|
19
|
+
/**
|
|
20
|
+
* @test REQ-TOOLS-013
|
|
21
|
+
* @intent 保持既有报告契约:名称形如 "CLI tool: <tool> (<gates>)",状态 PASS/WARN
|
|
22
|
+
* @covers AC-TOOLS-013-01
|
|
23
|
+
*/
|
|
24
|
+
it('keeps the existing check name and status contract', () => {
|
|
25
|
+
const checks = mapAuditRowsToDoctorChecks([
|
|
26
|
+
{
|
|
27
|
+
name: 'jscpd', available: true, version: '5.4.3', installedVersion: '5.4.3',
|
|
28
|
+
gates: ['Gate 2 (Duplicate Code)'], optional: false, duplicated: false,
|
|
29
|
+
outdated: false, currency: 'current', paths: ['/x/jscpd'], distinctRealPaths: ['/x/jscpd'],
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
expect(checks).toHaveLength(1);
|
|
33
|
+
expect(checks[0].name).toBe('CLI tool: jscpd (Gate 2 (Duplicate Code))');
|
|
34
|
+
expect(checks[0].status).toBe('PASS');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @test REQ-TOOLS-013
|
|
39
|
+
* @intent 不可用判 WARN,并在 detail 里给出原因与安装提示
|
|
40
|
+
* @covers AC-TOOLS-013-02
|
|
41
|
+
*/
|
|
42
|
+
it('reports an unavailable tool as WARN with its reason and an install command', () => {
|
|
43
|
+
const checks = mapAuditRowsToDoctorChecks([
|
|
44
|
+
{
|
|
45
|
+
name: 'psscriptanalyzer', available: false, version: null, installedVersion: null,
|
|
46
|
+
validityReason: 'probe printed no output (empty output cannot prove availability)',
|
|
47
|
+
gates: ['Gate 1 (Code Quality)'], optional: true, duplicated: false,
|
|
48
|
+
outdated: null, currency: 'missing', paths: [], distinctRealPaths: [],
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
expect(checks[0].status).toBe('WARN');
|
|
52
|
+
expect(checks[0].detail).toMatch(/no output/i);
|
|
53
|
+
expect(checks[0].detail).toMatch(/install-tools/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @test REQ-TOOLS-013
|
|
58
|
+
* @intent 重复安装必须在 doctor 里可见(旧实现完全看不到)
|
|
59
|
+
* @covers AC-TOOLS-013-03
|
|
60
|
+
*/
|
|
61
|
+
it('surfaces duplicate copies that the old doctor could not see', () => {
|
|
62
|
+
const checks = mapAuditRowsToDoctorChecks([
|
|
63
|
+
{
|
|
64
|
+
name: 'hadolint', available: true, version: '2.14.0', installedVersion: '2.14.0',
|
|
65
|
+
gates: ['Gate 7'], optional: false, duplicated: true, outdated: false,
|
|
66
|
+
currency: 'current',
|
|
67
|
+
paths: ['/a/hadolint', '/b/hadolint'],
|
|
68
|
+
distinctRealPaths: ['/a/hadolint', '/b/hadolint'],
|
|
69
|
+
},
|
|
70
|
+
]);
|
|
71
|
+
expect(checks[0].detail).toMatch(/duplicate/i);
|
|
72
|
+
expect(checks[0].detail).toContain('/b/hadolint');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @test REQ-TOOLS-013
|
|
77
|
+
* @intent 过期版本也要可见,并给出目标版本
|
|
78
|
+
* @covers AC-TOOLS-013-04
|
|
79
|
+
*/
|
|
80
|
+
it('surfaces an outdated version with the target', () => {
|
|
81
|
+
const checks = mapAuditRowsToDoctorChecks([
|
|
82
|
+
{
|
|
83
|
+
name: 'shellcheck', available: true, version: '0.10.0', installedVersion: '0.10.0',
|
|
84
|
+
gates: ['Gate 1'], optional: true, duplicated: false, outdated: true,
|
|
85
|
+
currency: 'outdated', latestVersion: '0.11.0',
|
|
86
|
+
paths: ['/x/shellcheck'], distinctRealPaths: ['/x/shellcheck'],
|
|
87
|
+
},
|
|
88
|
+
]);
|
|
89
|
+
expect(checks[0].detail).toMatch(/0\.10\.0/);
|
|
90
|
+
expect(checks[0].detail).toMatch(/0\.11\.0/);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @test REQ-TOOLS-013
|
|
95
|
+
* @intent 全部正常时 detail 就是版本号,保持旧输出可读
|
|
96
|
+
* @covers AC-TOOLS-013-05
|
|
97
|
+
*/
|
|
98
|
+
it('keeps a plain version string for a perfectly healthy tool', () => {
|
|
99
|
+
const checks = mapAuditRowsToDoctorChecks([
|
|
100
|
+
{
|
|
101
|
+
name: 'lizard', available: true, version: '1.26.1', installedVersion: '1.26.1',
|
|
102
|
+
gates: ['Gate 3'], optional: false, duplicated: false, outdated: false,
|
|
103
|
+
currency: 'current', paths: ['/x/lizard'], distinctRealPaths: ['/x/lizard'],
|
|
104
|
+
},
|
|
105
|
+
]);
|
|
106
|
+
expect(checks[0].detail).toBe('1.26.1');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('doctor tool checks: no blocking network work', () => {
|
|
111
|
+
/**
|
|
112
|
+
* @test REQ-TOOLS-016
|
|
113
|
+
* @intent doctor 的工具检查默认不做版本查询:实测同步 `npm view` 每次阻塞事件循环
|
|
114
|
+
* 约 5 秒,令同轮 checkEnv 的 `node --version`(正常 5ms)超时被误判
|
|
115
|
+
* Not found。doctor 只回答"能不能用",最新版由 check-tools 负责。
|
|
116
|
+
* @covers AC-TOOLS-016-01
|
|
117
|
+
*/
|
|
118
|
+
it('defaults to no version lookup at all', async () => {
|
|
119
|
+
const { auditGateCliTools } = require('../doctor-tool-checks.js');
|
|
120
|
+
const rows = await auditGateCliTools({
|
|
121
|
+
tools: [{ name: 'jscpd', checkCmd: 'jscpd --version', gates: [], optional: false }],
|
|
122
|
+
runProbe: () => ({ status: 0, stdout: '5.4.3', stderr: '' }),
|
|
123
|
+
locate: () => ['/x/jscpd'],
|
|
124
|
+
realpath: (p) => p,
|
|
125
|
+
});
|
|
126
|
+
// With no resolver supplied, currency must be unknown — never "current".
|
|
127
|
+
expect(rows[0].currency).toBe('unknown');
|
|
128
|
+
expect(rows[0].outdated).toBeNull();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @test REQ-TOOLS-016
|
|
133
|
+
* @intent 审计本身必须并行探测:慢工具(checkov 1.9s / semgrep 1.4s)不得串行阻塞
|
|
134
|
+
* @covers AC-TOOLS-016-02
|
|
135
|
+
*/
|
|
136
|
+
it('probes tools concurrently rather than one after another', async () => {
|
|
137
|
+
const { auditGateCliTools } = require('../doctor-tool-checks.js');
|
|
138
|
+
const started = [];
|
|
139
|
+
const rows = await auditGateCliTools({
|
|
140
|
+
tools: [
|
|
141
|
+
{ name: 'slow1', checkCmd: 'slow1', gates: [] },
|
|
142
|
+
{ name: 'slow2', checkCmd: 'slow2', gates: [] },
|
|
143
|
+
],
|
|
144
|
+
runProbe: async (cmd) => {
|
|
145
|
+
started.push(cmd);
|
|
146
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
147
|
+
return { status: 0, stdout: '1.0.0', stderr: '' };
|
|
148
|
+
},
|
|
149
|
+
locate: () => [],
|
|
150
|
+
realpath: (p) => p,
|
|
151
|
+
});
|
|
152
|
+
expect(rows).toHaveLength(2);
|
|
153
|
+
// Both probes are in flight before either resolves.
|
|
154
|
+
expect(started).toEqual(['slow1', 'slow2']);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `xp-gate install-tools` must make the toolchain converge to "one valid,
|
|
3
|
+
* current copy of every tool" — and it must be safe to run.
|
|
4
|
+
*
|
|
5
|
+
* The rules encoded here were decided explicitly for this machine (2026-11-23):
|
|
6
|
+
*
|
|
7
|
+
* - Remove a duplicate only when the SAME tool has more than one real entity
|
|
8
|
+
* (two byte-identical hadolint binaries, an old archlint shadowing a new
|
|
9
|
+
* one). Never uninstall a distro package: `jq` from apt is not a duplicate,
|
|
10
|
+
* it is the system's copy, and removing it can take other software with it.
|
|
11
|
+
* - Prefer the copy the PATH resolves FIRST: that is the one gates actually
|
|
12
|
+
* execute, so keeping it means the repair does not change gate behaviour.
|
|
13
|
+
* - Dry-run is the default outcome for anything destructive: without `--yes`
|
|
14
|
+
* the command only reports.
|
|
15
|
+
*
|
|
16
|
+
* Every test injects its own filesystem/command layer; none touches the real
|
|
17
|
+
* toolchain or the network.
|
|
18
|
+
*/
|
|
19
|
+
const path = require('path');
|
|
20
|
+
|
|
21
|
+
const { planToolRepairs, handleInstallTools } = require('../language-tools.js');
|
|
22
|
+
const { capture, auditRow: row, toolDefinition: def } = require('./tool-audit-fixtures.js');
|
|
23
|
+
|
|
24
|
+
describe('install-tools: repair planning', () => {
|
|
25
|
+
/**
|
|
26
|
+
* @test REQ-TOOLS-011
|
|
27
|
+
* @intent 重复实体必须产出"删除多余副本"动作,且保留 PATH 首个(门禁实际执行的)那份
|
|
28
|
+
* @covers AC-TOOLS-011-01
|
|
29
|
+
*/
|
|
30
|
+
it('plans removal of every duplicate entity except the first-resolved one', () => {
|
|
31
|
+
const dup = row('hadolint', {
|
|
32
|
+
duplicated: true,
|
|
33
|
+
paths: ['/home/u/.local/bin/hadolint', '/home/u/.npm-global/bin/hadolint'],
|
|
34
|
+
distinctRealPaths: ['/home/u/.local/bin/hadolint', '/home/u/.npm-global/bin/hadolint'],
|
|
35
|
+
});
|
|
36
|
+
const plan = planToolRepairs([dup]);
|
|
37
|
+
const removals = plan.actions.filter((a) => a.kind === 'remove-duplicate');
|
|
38
|
+
expect(removals).toHaveLength(1);
|
|
39
|
+
// The FIRST path is what gates execute; keep it.
|
|
40
|
+
expect(removals[0].path).toBe('/home/u/.npm-global/bin/hadolint');
|
|
41
|
+
expect(plan.actions.some((a) => a.kind === 'keep' && a.path === '/home/u/.local/bin/hadolint')).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @test REQ-TOOLS-011
|
|
46
|
+
* @intent 缺失的必需工具产出安装动作
|
|
47
|
+
* @covers AC-TOOLS-011-02
|
|
48
|
+
*/
|
|
49
|
+
it('plans an install for a missing required tool', () => {
|
|
50
|
+
const plan = planToolRepairs(
|
|
51
|
+
[row('mypy', { available: false, currency: 'missing', installedVersion: null })],
|
|
52
|
+
{ definitions: [def('mypy', { install: { linux: 'pip install mypy' } })] },
|
|
53
|
+
);
|
|
54
|
+
const installs = plan.actions.filter((a) => a.kind === 'install');
|
|
55
|
+
expect(installs).toHaveLength(1);
|
|
56
|
+
expect(installs[0].command).toContain('pip install mypy');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @test REQ-TOOLS-011
|
|
61
|
+
* @intent 可选的缺失工具不应被自动安装(避免装一堆用不上的东西)
|
|
62
|
+
* @covers AC-TOOLS-011-03
|
|
63
|
+
*/
|
|
64
|
+
it('does not auto-install a missing OPTIONAL tool', () => {
|
|
65
|
+
const plan = planToolRepairs(
|
|
66
|
+
[row('terraform', { available: false, currency: 'missing', installedVersion: null, optional: true })],
|
|
67
|
+
{ definitions: [def('terraform', { optional: true })] },
|
|
68
|
+
);
|
|
69
|
+
expect(plan.actions.filter((a) => a.kind === 'install')).toHaveLength(0);
|
|
70
|
+
expect(plan.actions.some((a) => a.kind === 'skip-optional')).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @test REQ-TOOLS-011
|
|
75
|
+
* @intent 过期的必需工具产出升级动作
|
|
76
|
+
* @covers AC-TOOLS-011-04
|
|
77
|
+
*/
|
|
78
|
+
it('plans an upgrade for an outdated required tool', () => {
|
|
79
|
+
const plan = planToolRepairs(
|
|
80
|
+
[row('hadolint', { outdated: true, currency: 'outdated', installedVersion: '2.14.0', latestVersion: '2.15.1' })],
|
|
81
|
+
{ definitions: [def('hadolint', { install: { linux: 'brew upgrade hadolint' } })] },
|
|
82
|
+
);
|
|
83
|
+
const upgrades = plan.actions.filter((a) => a.kind === 'upgrade');
|
|
84
|
+
expect(upgrades).toHaveLength(1);
|
|
85
|
+
expect(upgrades[0].command).toContain('brew upgrade hadolint');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @test REQ-TOOLS-011
|
|
90
|
+
* @intent 系统包(apt 装的 jq)不得被当作可删除的重复
|
|
91
|
+
* @covers AC-TOOLS-011-05
|
|
92
|
+
*/
|
|
93
|
+
it('never plans removal of a distro-owned copy', () => {
|
|
94
|
+
const dup = row('jq', {
|
|
95
|
+
duplicated: true,
|
|
96
|
+
paths: ['/usr/bin/jq', '/home/u/.local/bin/jq'],
|
|
97
|
+
distinctRealPaths: ['/usr/bin/jq', '/home/u/.local/bin/jq'],
|
|
98
|
+
});
|
|
99
|
+
const plan = planToolRepairs([dup], { systemPrefixes: ['/usr/bin/', '/bin/'] });
|
|
100
|
+
// Nothing to do: a distro copy beside a user copy is coexistence, not a
|
|
101
|
+
// duplicate install, so the plan is empty rather than "keep the system one".
|
|
102
|
+
expect(plan.actions.filter((a) => a.kind === 'remove-duplicate')).toHaveLength(0);
|
|
103
|
+
expect(plan.actions).toHaveLength(0);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @test REQ-TOOLS-011
|
|
108
|
+
* @intent 通过 npx 调用的工具没有 PATH 实体,不得产生删除动作
|
|
109
|
+
* @covers AC-TOOLS-011-06
|
|
110
|
+
*/
|
|
111
|
+
it('never plans removal for an npx-invoked tool', () => {
|
|
112
|
+
const plan = planToolRepairs([
|
|
113
|
+
row('@archlinter/cli', { npxInvoked: true, paths: [], distinctRealPaths: [] }),
|
|
114
|
+
]);
|
|
115
|
+
expect(plan.actions).toHaveLength(0);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @test REQ-TOOLS-011
|
|
120
|
+
* @intent 一切正常的工具不产生任何动作
|
|
121
|
+
* @covers AC-TOOLS-011-07
|
|
122
|
+
*/
|
|
123
|
+
it('plans nothing when the toolchain is already clean', () => {
|
|
124
|
+
const plan = planToolRepairs([row('eslint')]);
|
|
125
|
+
expect(plan.actions).toHaveLength(0);
|
|
126
|
+
expect(plan.clean).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('install-tools: command behaviour', () => {
|
|
131
|
+
/**
|
|
132
|
+
* @test REQ-TOOLS-012
|
|
133
|
+
* @intent 默认(无 --yes)只报告不修改,且必须明确说明未做任何改动
|
|
134
|
+
* @covers AC-TOOLS-012-01
|
|
135
|
+
*/
|
|
136
|
+
it('does not execute anything without --yes, and says so', async () => {
|
|
137
|
+
const executed = [];
|
|
138
|
+
const { code, out } = await capture(() =>
|
|
139
|
+
handleInstallTools([], {
|
|
140
|
+
projectRoot: '/tmp',
|
|
141
|
+
languages: ['shell'],
|
|
142
|
+
audit: () => [row('hadolint', { outdated: true, currency: 'outdated', latestVersion: '2.0.0' })],
|
|
143
|
+
definitions: [def('hadolint')],
|
|
144
|
+
run: (cmd) => {
|
|
145
|
+
executed.push(cmd);
|
|
146
|
+
return { status: 0 };
|
|
147
|
+
},
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
expect(code).toBe(0);
|
|
151
|
+
expect(executed).toHaveLength(0);
|
|
152
|
+
expect(out.toLowerCase()).toMatch(/no changes|dry|--yes/);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @test REQ-TOOLS-012
|
|
157
|
+
* @intent 带 --yes 时执行计划中的动作
|
|
158
|
+
* @covers AC-TOOLS-012-02
|
|
159
|
+
*/
|
|
160
|
+
it('executes the planned actions with --yes', async () => {
|
|
161
|
+
const executed = [];
|
|
162
|
+
const { code } = await capture(() =>
|
|
163
|
+
handleInstallTools(['--yes'], {
|
|
164
|
+
projectRoot: '/tmp',
|
|
165
|
+
languages: ['shell'],
|
|
166
|
+
audit: () => [row('mypy', { available: false, currency: 'missing', installedVersion: null })],
|
|
167
|
+
definitions: [def('mypy', { install: { linux: 'pip install mypy' } })],
|
|
168
|
+
run: (cmd) => {
|
|
169
|
+
executed.push(cmd);
|
|
170
|
+
return { status: 0 };
|
|
171
|
+
},
|
|
172
|
+
removeFile: () => true,
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
expect(code).toBe(0);
|
|
176
|
+
expect(executed.some((c) => c.includes('pip install mypy'))).toBe(true);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @test REQ-TOOLS-012
|
|
181
|
+
* @intent 单个动作失败不能中断其余动作;最后如实报告失败数
|
|
182
|
+
* @covers AC-TOOLS-012-03
|
|
183
|
+
*/
|
|
184
|
+
it('continues after a failing action and reports the failure', async () => {
|
|
185
|
+
const executed = [];
|
|
186
|
+
const { code, out } = await capture(() =>
|
|
187
|
+
handleInstallTools(['--yes'], {
|
|
188
|
+
projectRoot: '/tmp',
|
|
189
|
+
languages: ['shell'],
|
|
190
|
+
audit: () => [
|
|
191
|
+
row('a', { available: false, currency: 'missing', installedVersion: null }),
|
|
192
|
+
row('b', { available: false, currency: 'missing', installedVersion: null }),
|
|
193
|
+
],
|
|
194
|
+
definitions: [def('a'), def('b')],
|
|
195
|
+
run: (cmd) => {
|
|
196
|
+
executed.push(cmd);
|
|
197
|
+
return { status: cmd.includes(' a') ? 1 : 0 };
|
|
198
|
+
},
|
|
199
|
+
}),
|
|
200
|
+
);
|
|
201
|
+
expect(executed.length).toBe(2);
|
|
202
|
+
// A failed repair is a non-zero exit: silence would read as success.
|
|
203
|
+
expect(code).not.toBe(0);
|
|
204
|
+
expect(out).toMatch(/fail/i);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @test REQ-TOOLS-012
|
|
209
|
+
* @intent 工具链已干净时直接说明,不做任何事
|
|
210
|
+
* @covers AC-TOOLS-012-04
|
|
211
|
+
*/
|
|
212
|
+
it('reports an already-clean toolchain without side effects', async () => {
|
|
213
|
+
const executed = [];
|
|
214
|
+
const { code, out } = await capture(() =>
|
|
215
|
+
handleInstallTools(['--yes'], {
|
|
216
|
+
projectRoot: '/tmp',
|
|
217
|
+
languages: ['shell'],
|
|
218
|
+
audit: () => [row('eslint')],
|
|
219
|
+
definitions: [def('eslint')],
|
|
220
|
+
run: (cmd) => {
|
|
221
|
+
executed.push(cmd);
|
|
222
|
+
return { status: 0 };
|
|
223
|
+
},
|
|
224
|
+
}),
|
|
225
|
+
);
|
|
226
|
+
expect(code).toBe(0);
|
|
227
|
+
expect(executed).toHaveLength(0);
|
|
228
|
+
expect(out).toMatch(/nothing|up to date|already|无需|已是最新/i);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe('install-tools: action ordering', () => {
|
|
233
|
+
/**
|
|
234
|
+
* @test REQ-TOOLS-014
|
|
235
|
+
* @intent 同一工具既重复又过期时,升级必须作用于"保留的那份",不能把新版本写到
|
|
236
|
+
* 刚被删掉的路径上 —— 否则去重与升级互相抵消,重复原样回来
|
|
237
|
+
* (2026-11-23 实况:hadolint 去重后又出现两份)
|
|
238
|
+
* @covers AC-TOOLS-014-01
|
|
239
|
+
*/
|
|
240
|
+
it('flags an upgrade command that writes into the path it also removes', () => {
|
|
241
|
+
const dupOutdated = row('hadolint', {
|
|
242
|
+
outdated: true,
|
|
243
|
+
currency: 'outdated',
|
|
244
|
+
installedVersion: '2.14.0',
|
|
245
|
+
latestVersion: '2.15.1',
|
|
246
|
+
duplicated: true,
|
|
247
|
+
// Second copy is the one the plan removes; the installer writes there.
|
|
248
|
+
paths: ['/home/u/.npm-global/bin/hadolint', '/home/u/.local/bin/hadolint'],
|
|
249
|
+
distinctRealPaths: ['/home/u/.npm-global/bin/hadolint', '/home/u/.local/bin/hadolint'],
|
|
250
|
+
});
|
|
251
|
+
const plan = planToolRepairs([dupOutdated], {
|
|
252
|
+
definitions: [def('hadolint', { install: { linux: 'curl -sL x -o /home/u/.local/bin/hadolint' } })],
|
|
253
|
+
});
|
|
254
|
+
const removal = plan.actions.find((a) => a.kind === 'remove-duplicate');
|
|
255
|
+
const upgrade = plan.actions.find((a) => a.kind === 'upgrade');
|
|
256
|
+
expect(removal).toBeTruthy();
|
|
257
|
+
expect(upgrade).toBeTruthy();
|
|
258
|
+
// The installer writes to ~/.local/bin, which is exactly the copy marked for
|
|
259
|
+
// removal: applying both puts a second hadolint back and the duplicate
|
|
260
|
+
// survives the repair. It must be surfaced, not executed blindly.
|
|
261
|
+
expect(upgrade.writesToRemovedPath).toBe(true);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
@@ -281,6 +281,33 @@ describe('real repository invariants', () => {
|
|
|
281
281
|
}
|
|
282
282
|
});
|
|
283
283
|
|
|
284
|
+
/**
|
|
285
|
+
* @test REQ-LANG-CAPABILITY
|
|
286
|
+
* @intent gate-3/gate-4 的扩展名白名单不是字面量,而是从
|
|
287
|
+
* githooks/lib/file-classifier.sh 的 XP_GATE_CCN_EXTS /
|
|
288
|
+
* XP_GATE_PRINCIPLES_EXTS 变量展开的。只在 gate-*.sh 里 grep 字面量
|
|
289
|
+
* 会把一处真实的接线读成"未接线"——csharp 因此在 gate-3/gate-4 上
|
|
290
|
+
* 永久红着,而 `cs` 明明已在两个变量里,`\.(…)$` filter 也确实收 .cs。
|
|
291
|
+
* @covers AC-LANG-CAP-05
|
|
292
|
+
*/
|
|
293
|
+
it('derives gate-3/gate-4 extension sets from the classifier, not just literals', () => {
|
|
294
|
+
const { readFileSync } = require('node:fs');
|
|
295
|
+
const classifier = readFileSync(
|
|
296
|
+
path.join(REPO_ROOT, 'githooks/lib/file-classifier.sh'),
|
|
297
|
+
'utf8',
|
|
298
|
+
);
|
|
299
|
+
// Precondition: the authority really does declare cs, so the assertion
|
|
300
|
+
// below cannot pass by accident when the classifier is later edited.
|
|
301
|
+
expect(classifier).toMatch(/XP_GATE_CCN_EXTS=.*\bcs\b/);
|
|
302
|
+
expect(classifier).toMatch(/XP_GATE_PRINCIPLES_EXTS=.*\bcs\b/);
|
|
303
|
+
|
|
304
|
+
const rows = inspectAll({ root: REPO_ROOT }).filter((r) => r.language === 'csharp');
|
|
305
|
+
for (const surface of ['gate-3', 'gate-4']) {
|
|
306
|
+
const row = rows.find((r) => r.surface === surface);
|
|
307
|
+
expect(row.state, `${surface} should see cs via the classifier`).toBe(STATE.CHECKED);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
284
311
|
it('csharp is fully wired except Gate 9, which is a declared gap', () => {
|
|
285
312
|
const rows = inspectAll({ root: REPO_ROOT }).filter((r) => r.language === 'csharp');
|
|
286
313
|
const sum = summarise(rows);
|