@boyingliu01/xp-gate 0.36.1 → 0.37.1
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/cpp.sh +78 -10
- package/adapters/csharp.sh +58 -3
- package/adapters/gate-3.sh +15 -5
- package/adapters/gate-8.sh +131 -9
- package/adapters/typescript.sh +32 -8
- package/build-integrity/__tests__/import-resolver.test.ts +257 -0
- package/build-integrity/__tests__/quote-masker.test.ts +177 -0
- package/build-integrity/gate-10.ts +127 -9
- package/build-integrity/quote-masker.ts +266 -0
- package/gate-10.sh +66 -0
- package/gate-12-file-hygiene.sh +15 -7
- package/gate-13-compiler-strictness.sh +81 -1
- package/gate-3.sh +15 -5
- package/gate-6-layers.sh +375 -0
- package/gate-8.sh +131 -9
- package/hooks/gate-10.sh +66 -0
- package/hooks/gate-12-file-hygiene.sh +15 -7
- package/hooks/gate-13-compiler-strictness.sh +81 -1
- package/hooks/gate-3.sh +15 -5
- package/hooks/gate-6-layers.sh +375 -0
- package/hooks/gate-8.sh +131 -9
- package/hooks/gate-registry.sh +2 -2
- package/hooks/hook-module-resolution.sh +1 -1
- package/hooks/lib/assertion-quality.sh +8 -2
- package/hooks/lib/ccn-ratchet.sh +10 -0
- package/hooks/lib/layer-baseline.cjs +88 -0
- package/hooks/lib/typecheck.sh +28 -5
- package/hooks/pre-commit +376 -53
- package/hooks/pre-push +46 -13
- package/lib/__tests__/agent-runtime-journal.test.js +1 -1
- package/lib/__tests__/arch.test.js +9 -0
- package/lib/__tests__/audit-cli-contract.test.ts +1 -1
- package/lib/__tests__/check-alignment-reasons.test.mjs +11 -1
- package/lib/__tests__/check-all-skip-accounting.test.js +1 -1
- package/lib/__tests__/detect-deps-gate-identity.test.js +135 -0
- package/lib/__tests__/detect-deps.test.js +2 -1
- package/lib/__tests__/doctor-469-hook-env.test.js +7 -1
- package/lib/__tests__/doctor-arch-tools.test.js +169 -0
- package/lib/__tests__/doctor-delphi.test.js +1 -1
- package/lib/__tests__/doctor-drift-round2.test.js +4 -1
- package/lib/__tests__/doctor-executed-surface.test.js +45 -24
- package/lib/__tests__/doctor-module-drift.test.js +13 -7
- package/lib/__tests__/doctor-module-resolution-parity.test.js +74 -2
- package/lib/__tests__/doctor-tui-skill-freshness.test.js +21 -6
- package/lib/__tests__/doctor.test.js +17 -0
- package/lib/__tests__/gate-runner-tsx-invocation.test.js +149 -0
- package/lib/__tests__/gate-runner.test.js +23 -7
- package/lib/__tests__/init-gitignore.test.js +204 -0
- package/lib/__tests__/init.test.js +24 -3
- package/lib/__tests__/language-tools-build-file-install.test.js +82 -0
- package/lib/__tests__/language-tools-detect.test.js +61 -0
- package/lib/__tests__/mirror-sync.test.js +2 -0
- package/lib/__tests__/phase-transition.test.js +19 -1
- package/lib/__tests__/sprint-status-rework.test.js +32 -12
- package/lib/__tests__/test-alignment-range-guard.test.ts +82 -0
- package/lib/__tests__/test-alignment.test.ts +13 -3
- package/lib/__tests__/update-skill.test.js +2 -2
- package/lib/detect-deps.js +7 -1
- package/lib/doctor.js +81 -17
- package/lib/gate-runner.js +101 -7
- package/lib/hook-module-resolution.js +18 -6
- package/lib/init.js +136 -1
- package/lib/language-tools.js +217 -1
- package/lib/layer-baseline.cjs +88 -0
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/principles.js +21 -6
- package/lib/test-alignment.ts +452 -55
- package/mock-policy/AGENTS.md +1 -1
- package/mutation/AGENTS.md +1 -1
- package/package.json +2 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +34 -24
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/delphi-review/INSTALL.md +29 -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/.delphi-config.json.example +34 -24
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/delphi-review/INSTALL.md +29 -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/client.test.ts +1 -1
- package/plugins/dsh/src/command.test.ts +1 -1
- package/plugins/dsh/src/contract.test.ts +1 -1
- package/plugins/dsh/src/credentials.test.ts +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +34 -24
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/delphi-review/INSTALL.md +29 -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/.delphi-config.json.example +34 -24
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/delphi-review/INSTALL.md +29 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/principles/AGENTS.md +1 -1
- package/principles/__tests__/config-arch-group.test.ts +106 -0
- package/principles/__tests__/config-enforcement.test.ts +1 -1
- package/principles/adapters/control-nesting.ts +572 -0
- package/principles/adapters/csharp.ts +73 -42
- package/principles/adapters/java.ts +9 -5
- package/principles/adapters/typescript.ts +138 -176
- package/principles/config.ts +37 -2
- package/principles/index.ts +57 -4
- package/principles/reporter.ts +99 -65
- package/principles/rules/arch/__tests__/dependency.test.ts +180 -0
- package/principles/rules/arch/__tests__/naming.test.ts +133 -0
- package/principles/rules/arch/__tests__/shared.test.ts +113 -0
- package/principles/rules/arch/dependency.ts +264 -0
- package/principles/rules/arch/naming.ts +188 -0
- package/principles/rules/arch/shared.ts +169 -0
- package/principles/rules/exports.ts +26 -0
- package/principles/rules/index.ts +11 -18
- package/scripts/__tests__/sync-package-content.test.js +23 -1
- package/scripts/sync-package-content.js +8 -2
- package/skills/delphi-review/.delphi-config.json.example +34 -24
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/delphi-review/INSTALL.md +29 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-726
|
|
3
|
+
* @intent ArchUnit and Konsist are LIBRARIES, not CLIs. `detectBy: 'build-file'`
|
|
4
|
+
* exists precisely because there is no binary to probe -- but the
|
|
5
|
+
* `install` field was still filled with an instruction TO A HUMAN
|
|
6
|
+
* ('add "com.tngtech.archunit:archunit-junit5" to pom.xml / build.gradle').
|
|
7
|
+
* `installTool()` hands that string to execSync with a shell, so every
|
|
8
|
+
* Java project running `xp-gate doctor --fix --install-tools` got
|
|
9
|
+
* `'add' is not recognized as an internal or external command` (or, on
|
|
10
|
+
* POSIX, an attempted `/bin/sh` execution of prose) and a spurious
|
|
11
|
+
* install failure for a library that is installed by editing a build
|
|
12
|
+
* file. A tool with no runnable installer must return an actionable
|
|
13
|
+
* manual instruction and must never spawn a process.
|
|
14
|
+
* @covers AC-726-02
|
|
15
|
+
*/
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
describe('installTool — build-file tools are documented, never executed (#689 review)', () => {
|
|
21
|
+
/**
|
|
22
|
+
* Fresh module each time: installTool reads process.platform at call time,
|
|
23
|
+
* but the tool definitions are module state and a stale cache across cases
|
|
24
|
+
* would hide a change.
|
|
25
|
+
*/
|
|
26
|
+
function loadTools() {
|
|
27
|
+
const modPath = require.resolve('../language-tools.js');
|
|
28
|
+
delete require.cache[modPath];
|
|
29
|
+
return require(modPath);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* getArchitectureTools() groups tools by language (`{ java: [...], kotlin: [...] }`),
|
|
34
|
+
* so flatten before filtering.
|
|
35
|
+
*/
|
|
36
|
+
function buildFileTools(mod) {
|
|
37
|
+
const byLang = mod.getArchitectureTools();
|
|
38
|
+
return Object.values(byLang).flat().filter((tool) => tool.detectBy === 'build-file');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function findTool(mod, name) {
|
|
42
|
+
return buildFileTools(mod).find((tool) => tool.name === name);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
it('finds the build-file tools this contract is about', () => {
|
|
46
|
+
const names = buildFileTools(loadTools()).map((tool) => tool.name);
|
|
47
|
+
expect(names).toContain('archunit');
|
|
48
|
+
expect(names).toContain('konsist');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('refuses to shell-execute a build-file install string and explains why', () => {
|
|
52
|
+
const mod = loadTools();
|
|
53
|
+
const archunit = findTool(mod, 'archunit');
|
|
54
|
+
|
|
55
|
+
const result = mod.installTool(archunit);
|
|
56
|
+
|
|
57
|
+
expect(result.success).toBe(false);
|
|
58
|
+
// The message must tell the reader what to DO -- the whole point of the
|
|
59
|
+
// field was the instruction, so it must survive as guidance.
|
|
60
|
+
expect(result.message).toMatch(/pom\.xml|build\.gradle/i);
|
|
61
|
+
// And it must be explicit that nothing was run, so a caller cannot read a
|
|
62
|
+
// false failure as "the install command failed".
|
|
63
|
+
expect(result.message).toMatch(/manual|not run|no install command is runnable|library/i);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('does not spawn a shell for a build-file tool (the prose never reaches execSync)', () => {
|
|
67
|
+
const mod = loadTools();
|
|
68
|
+
const konsist = findTool(mod, 'konsist');
|
|
69
|
+
const before = console.log;
|
|
70
|
+
const logged = [];
|
|
71
|
+
console.log = (line) => logged.push(String(line));
|
|
72
|
+
try {
|
|
73
|
+
mod.installTool(konsist);
|
|
74
|
+
} finally {
|
|
75
|
+
console.log = before;
|
|
76
|
+
}
|
|
77
|
+
// The old path logged `Installing <name>: <prose>` immediately before
|
|
78
|
+
// execSync. Its absence is the observable proof that no process started.
|
|
79
|
+
const spawning = logged.filter((line) => /^Installing /i.test(line));
|
|
80
|
+
expect(spawning).toEqual([]);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -156,3 +156,64 @@ describe('check-tools language selection (#468)', () => {
|
|
|
156
156
|
expect(Object.keys(reported)).toContain('shell');
|
|
157
157
|
});
|
|
158
158
|
});
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @test REQ-717
|
|
162
|
+
* @intent C# 有完整的门禁支持(adapter、principles 引擎、Gate 4/5/6/10/13),却从未进入
|
|
163
|
+
* LANGUAGE_REGISTRY:detect-languages 生成的配置里没有 csharp,而读配置的 hook
|
|
164
|
+
* 不会回退到扩展名嗅探,于是 C# 在任何混合 .NET+JS 仓库里都不会被路由(#730)
|
|
165
|
+
* @covers AC-717-01, AC-717-02, AC-717-03
|
|
166
|
+
*/
|
|
167
|
+
describe('detectProjectLanguages C# registry membership (#730)', () => {
|
|
168
|
+
let loadModule;
|
|
169
|
+
|
|
170
|
+
beforeEach(() => {
|
|
171
|
+
vi.resetModules();
|
|
172
|
+
delete require.cache[require.resolve('../language-tools')];
|
|
173
|
+
loadModule = () => require('../language-tools');
|
|
174
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
afterEach(() => {
|
|
178
|
+
vi.restoreAllMocks();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
function detectIn(spec) {
|
|
182
|
+
const root = makeFixture(spec);
|
|
183
|
+
try {
|
|
184
|
+
return loadModule().detectProjectLanguages(root);
|
|
185
|
+
} finally {
|
|
186
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// The .csproj name is project-specific, so detection must glob it. A registry
|
|
191
|
+
// entry listing the literal '.csproj' would stat a file of that exact name and
|
|
192
|
+
// never match -- the config would look corrected while detection stayed broken.
|
|
193
|
+
it('detects csharp from a project-specific .csproj filename', () => {
|
|
194
|
+
const { detected, configFiles } = detectIn({ 'DshAotRunner.csproj': '<Project/>' });
|
|
195
|
+
expect(detected).toContain('csharp');
|
|
196
|
+
expect(configFiles.csharp).toContain('DshAotRunner.csproj');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('detects csharp from a .sln in a solution-only repo', () => {
|
|
200
|
+
expect(detectIn({ 'App.sln': 'Microsoft Visual Studio Solution File' }).detected).toContain('csharp');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// The bug's actual shape: a .NET repo that also has package.json for its JS
|
|
204
|
+
// tooling. Before the fix this reported typescript alone, so the hook took the
|
|
205
|
+
// TypeScript path for a C# codebase.
|
|
206
|
+
it('reports csharp alongside typescript in a mixed .NET + JS repo', () => {
|
|
207
|
+
const { detected } = detectIn({
|
|
208
|
+
'Runner.csproj': '<Project/>',
|
|
209
|
+
'Program.cs': 'class P { static void Main() {} }',
|
|
210
|
+
'package.json': '{"name":"runner"}',
|
|
211
|
+
});
|
|
212
|
+
expect(detected).toEqual(expect.arrayContaining(['csharp', 'typescript']));
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('does not report csharp for a repo with no .NET artifact', () => {
|
|
216
|
+
const { detected } = detectIn({ 'package.json': '{}', 'index.js': '' });
|
|
217
|
+
expect(detected).not.toContain('csharp');
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -42,11 +42,29 @@ function git(command, cwd) {
|
|
|
42
42
|
}).trim();
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
// A pre-initialised repository, created once per test FILE rather than once per
|
|
46
|
+
// test. `git init` + three `git config` + `git add` is four process launches that
|
|
47
|
+
// have nothing to do with what these tests assert; on Windows each launch costs
|
|
48
|
+
// ~130 ms, so this fixture was ~0.5 s of pure process overhead per repository and
|
|
49
|
+
// the file builds 20 of them (84 s measured, the single slowest test file in the
|
|
50
|
+
// suite). Copying the prepared tree is one filesystem operation instead.
|
|
51
|
+
let _repoTemplate = null;
|
|
52
|
+
|
|
53
|
+
function repoTemplate() {
|
|
54
|
+
if (_repoTemplate) return _repoTemplate;
|
|
55
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'phase-transition-template-'));
|
|
46
56
|
git('init --quiet --template=', dir);
|
|
47
57
|
git('config core.hooksPath /dev/null', dir);
|
|
48
58
|
git('config user.email "test@test.com"', dir);
|
|
49
59
|
git('config user.name "Test"', dir);
|
|
60
|
+
_repoTemplate = dir;
|
|
61
|
+
return dir;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function createRepository(dir, message) {
|
|
65
|
+
// Copy the prepared template (init + config already done, so no process is
|
|
66
|
+
// launched for either), then make the one commit that encodes `message`.
|
|
67
|
+
fs.cpSync(repoTemplate(), dir, { recursive: true });
|
|
50
68
|
fs.writeFileSync(path.join(dir, 'file.txt'), message);
|
|
51
69
|
git('add file.txt', dir);
|
|
52
70
|
git(`commit --quiet -m "${message}"`, dir);
|
|
@@ -51,6 +51,28 @@ function makeCommit(msg, dir) {
|
|
|
51
51
|
git(`commit --no-verify -m "${msg}"`, d);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
// A repository with identity already configured, built once per test FILE
|
|
55
|
+
// instead of once per test. `git init` plus two `git config` launches cost
|
|
56
|
+
// ~130 ms each on Windows and none of it is what these tests assert; copying the
|
|
57
|
+
// prepared tree is one filesystem operation instead of three process launches.
|
|
58
|
+
let _repoTemplate = null;
|
|
59
|
+
|
|
60
|
+
/** Build the template exactly once. Never copies from itself. */
|
|
61
|
+
function repoTemplate() {
|
|
62
|
+
if (_repoTemplate) return _repoTemplate;
|
|
63
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'rework-template-'));
|
|
64
|
+
git('init', dir);
|
|
65
|
+
git('config user.email "test@test.com"', dir);
|
|
66
|
+
git('config user.name "Test"', dir);
|
|
67
|
+
_repoTemplate = dir;
|
|
68
|
+
return dir;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Create a configured repo at `dir`, replacing the init + 2x config triple. */
|
|
72
|
+
function initRepo(dir) {
|
|
73
|
+
fs.cpSync(repoTemplate(), dir, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
|
|
54
76
|
function daysAgo(n) {
|
|
55
77
|
return new Date(Date.now() - n * 86400000).toISOString();
|
|
56
78
|
}
|
|
@@ -73,6 +95,12 @@ function hoursAgo(n) {
|
|
|
73
95
|
beforeAll(() => {
|
|
74
96
|
TMP_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'rework-test-'));
|
|
75
97
|
cwdSpy = vi.spyOn(process, 'cwd');
|
|
98
|
+
// Build the shared repo template HERE, before any test mocks process.cwd().
|
|
99
|
+
// repoTemplate() calls os.tmpdir(), which resolves through process.cwd(); once
|
|
100
|
+
// cwdSpy is stubbing it to TMP_DIR, a lazily-created template would be made
|
|
101
|
+
// inside TMP_DIR and then copied into itself.
|
|
102
|
+
_repoTemplate = null;
|
|
103
|
+
repoTemplate();
|
|
76
104
|
});
|
|
77
105
|
|
|
78
106
|
beforeEach(() => {
|
|
@@ -113,9 +141,7 @@ describe('sprint-status --rework-check (#369)', () => {
|
|
|
113
141
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'rework-b-'));
|
|
114
142
|
cwdSpy.mockReturnValue(dir);
|
|
115
143
|
|
|
116
|
-
|
|
117
|
-
git('config user.email "test@test.com"', dir);
|
|
118
|
-
git('config user.name "Test"', dir);
|
|
144
|
+
initRepo(dir);
|
|
119
145
|
// 10 commits, 2 of them fixes => 20%, below the 30% threshold.
|
|
120
146
|
// The count has to come from real history: the old fixture made 3 commits
|
|
121
147
|
// and declared 'total_sprint_commits: 10' by hand, so the expected 20%
|
|
@@ -159,9 +185,7 @@ describe('sprint-status --rework-check (#369)', () => {
|
|
|
159
185
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'rework-c-'));
|
|
160
186
|
cwdSpy.mockReturnValue(dir);
|
|
161
187
|
|
|
162
|
-
|
|
163
|
-
git('config user.email "test@test.com"', dir);
|
|
164
|
-
git('config user.name "Test"', dir);
|
|
188
|
+
initRepo(dir);
|
|
165
189
|
// 10 commits, 5 of them fixes => 50%, above the 30% threshold.
|
|
166
190
|
makeCommit('fix: one', dir);
|
|
167
191
|
makeCommit('fix: two', dir);
|
|
@@ -223,9 +247,7 @@ describe('sprint-status --rework-check (#369)', () => {
|
|
|
223
247
|
const outerDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rework-outer-'));
|
|
224
248
|
|
|
225
249
|
for (const dir of [targetDir, outerDir]) {
|
|
226
|
-
|
|
227
|
-
git('config user.email "test@test.com"', dir);
|
|
228
|
-
git('config user.name "Test"', dir);
|
|
250
|
+
initRepo(dir);
|
|
229
251
|
}
|
|
230
252
|
makeCommit('feat: target initial', targetDir);
|
|
231
253
|
makeCommit('fix: target bug', targetDir);
|
|
@@ -279,9 +301,7 @@ describe('sprint-status --rework-check (#369)', () => {
|
|
|
279
301
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'rework-injection-'));
|
|
280
302
|
const markerFile = path.join(dir, 'injection-marker');
|
|
281
303
|
cwdSpy.mockReturnValue(dir);
|
|
282
|
-
|
|
283
|
-
git('config user.email "test@test.com"', dir);
|
|
284
|
-
git('config user.name "Test"', dir);
|
|
304
|
+
initRepo(dir);
|
|
285
305
|
makeCommit('fix: target bug', dir);
|
|
286
306
|
|
|
287
307
|
writeSprintState({
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-670
|
|
3
|
+
* @intent `expandAcCovers()` expands the `the range shorthand` shorthand, but
|
|
4
|
+
* the loop had no ceiling: a typo such as
|
|
5
|
+
* `a range with a wildly mistyped upper bound` produces a billion entries and
|
|
6
|
+
* a module-scope Set that eats memory until the process dies. The guard
|
|
7
|
+
* is not about hostile input -- an alignment run reads whatever
|
|
8
|
+
* annotations a repository happens to contain, and a single wrong digit
|
|
9
|
+
* is enough. Expansion past a sane ceiling must be refused LOUDLY rather
|
|
10
|
+
* than attempted: a silent truncation would drop coverage while still
|
|
11
|
+
* reading as a passing alignment, and a silent "two ids" would be
|
|
12
|
+
* indistinguishable from an annotation that genuinely lists two.
|
|
13
|
+
* @covers AC-670-64
|
|
14
|
+
*/
|
|
15
|
+
import { describe, it, expect } from 'vitest';
|
|
16
|
+
import { mkdtempSync, writeFileSync, rmSync } from 'fs';
|
|
17
|
+
import { tmpdir } from 'os';
|
|
18
|
+
import { join } from 'path';
|
|
19
|
+
|
|
20
|
+
const { parseTestFiles } = await import('../test-alignment');
|
|
21
|
+
|
|
22
|
+
/** One test file whose @covers carries the given range. */
|
|
23
|
+
function writeTestFileWithRange(covers: string): { dir: string; file: string } {
|
|
24
|
+
const dir = mkdtempSync(join(tmpdir(), 'xpgate-range-'));
|
|
25
|
+
const file = join(dir, 'range.test.ts');
|
|
26
|
+
const header = ['/**', ' * @test REQ-670', ' * @intent fixture', ' * @covers ' + covers, ' */'];
|
|
27
|
+
const body = ["it('does a thing', () => { expect(1).toBe(1); });"];
|
|
28
|
+
writeFileSync(file, header.concat(body).join('\n'), 'utf8');
|
|
29
|
+
return { dir, file };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Capture console.warn for the duration of `run`, so a refusal can be asserted. */
|
|
33
|
+
function captureWarnings<T>(run: () => T): { value: T; warnings: string } {
|
|
34
|
+
const warnings: string[] = [];
|
|
35
|
+
const originalWarn = console.warn;
|
|
36
|
+
console.warn = (...args: unknown[]) => {
|
|
37
|
+
warnings.push(args.map(String).join(' '));
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
return { value: run(), warnings: warnings.join('\n') };
|
|
41
|
+
} finally {
|
|
42
|
+
console.warn = originalWarn;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe('expandAcCovers guards an unbounded range', () => {
|
|
47
|
+
it('expands a normal range, so the guard does not break the feature', () => {
|
|
48
|
+
const { dir, file } = writeTestFileWithRange('AC-670-01 through AC-670-04');
|
|
49
|
+
try {
|
|
50
|
+
const map = parseTestFiles([file]);
|
|
51
|
+
expect(map.tests[0].covers).toEqual(['AC-670-01', 'AC-670-02', 'AC-670-03', 'AC-670-04']);
|
|
52
|
+
} finally {
|
|
53
|
+
rmSync(dir, { recursive: true, force: true });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('refuses an absurd range instead of trying to build it', () => {
|
|
58
|
+
// Without a ceiling this allocates ~1e9 strings and dies. The time assertion
|
|
59
|
+
// proves the loop was never entered, which is the only acceptable behaviour.
|
|
60
|
+
const huge = 'AC-' + '670' + '-000000001';
|
|
61
|
+
const hugeEnd = 'AC-' + '670' + '-999999999';
|
|
62
|
+
const { dir, file } = writeTestFileWithRange(huge + ' through ' + hugeEnd);
|
|
63
|
+
const started = Date.now();
|
|
64
|
+
try {
|
|
65
|
+
const { value: map, warnings } = captureWarnings(() => parseTestFiles([file]));
|
|
66
|
+
expect(Date.now() - started).toBeLessThan(5000);
|
|
67
|
+
|
|
68
|
+
const ids = map.tests[0].covers || [];
|
|
69
|
+
// It must NOT have materialised the range.
|
|
70
|
+
expect(ids.length).toBeLessThan(1000);
|
|
71
|
+
// The two literal endpoints are still real references and must survive --
|
|
72
|
+
// dropping them would lose the only genuine signal in the annotation.
|
|
73
|
+
expect(ids).toContain(huge);
|
|
74
|
+
expect(ids).toContain(hugeEnd);
|
|
75
|
+
// ...and the refusal has to be sayable, or the degradation is invisible.
|
|
76
|
+
expect(warnings).toMatch(/refused to expand/);
|
|
77
|
+
expect(warnings).toMatch(/typ/);
|
|
78
|
+
} finally {
|
|
79
|
+
rmSync(dir, { recursive: true, force: true });
|
|
80
|
+
}
|
|
81
|
+
}, 30000);
|
|
82
|
+
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @test REQ-ALIGN-001 Parse specification.yaml into requirement map
|
|
3
3
|
* @intent Verify that parseSpecification() correctly extracts REQ IDs and AC IDs
|
|
4
4
|
* from the canonical specification.yaml format (specification.requirements wrapper)
|
|
5
|
-
* @covers AC-ALIGN-001-01, AC-ALIGN-001-02, AC-ALIGN-001-03, AC-ALIGN-001-04
|
|
5
|
+
* @covers AC-ALIGN-001-01, AC-ALIGN-001-02, AC-ALIGN-001-03, AC-ALIGN-001-04, AC-670-63
|
|
6
6
|
*
|
|
7
7
|
* @test REQ-ALIGN-002 Parse test files for @test/@intent/@covers annotations
|
|
8
8
|
* @intent Verify that parseTestFiles() extracts annotations from TS, Python, and Go
|
|
@@ -57,8 +57,18 @@ afterEach(() => {
|
|
|
57
57
|
function writeTempFile(filename: string, content: string): string {
|
|
58
58
|
const filepath = path.join(tempDir, filename);
|
|
59
59
|
const dir = path.dirname(filepath);
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
try {
|
|
61
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
62
|
+
fs.writeFileSync(filepath, content, 'utf8');
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// A silent failure here would surface as an unrelated assertion error far
|
|
65
|
+
// from the real cause (an unwritable temp dir), so name the file and the
|
|
66
|
+
// underlying reason in the thrown message. `cause` keeps the original error
|
|
67
|
+
// reachable: readers need its code (EACCES/ENOENT) and stack, which a
|
|
68
|
+
// message string alone would discard.
|
|
69
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
70
|
+
throw new Error(`Failed to write temp file ${filepath}: ${reason}`, { cause: error });
|
|
71
|
+
}
|
|
62
72
|
return filepath;
|
|
63
73
|
}
|
|
64
74
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @test
|
|
2
|
+
* @test REQ-719
|
|
3
3
|
* @intent Verify updateSkill() handles check/all/single-name modes, config parsing, and delegates to installSkill correctly
|
|
4
|
-
* @covers AC-416-04
|
|
4
|
+
* @covers AC-416-04, AC-719-01, AC-719-02, AC-719-03
|
|
5
5
|
*/
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const path = require('path');
|
package/lib/detect-deps.js
CHANGED
|
@@ -86,7 +86,13 @@ const GATE_CLI_TOOLS = [
|
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
tool: 'semgrep',
|
|
89
|
-
|
|
89
|
+
// Gate 10, not 9. `githooks/gate-registry.sh` is the single source of truth
|
|
90
|
+
// (`"sast|10|gate-10.sh|YES"`); gate 9 is Build Integrity. This entry said 9,
|
|
91
|
+
// which is the same drift that made #717 write a C# SAST fix into gate-9.sh —
|
|
92
|
+
// a fix applied to a gate that never runs. Anything reporting "which gate does
|
|
93
|
+
// this tool serve" has to agree with the registry or it sends the reader to
|
|
94
|
+
// the wrong file.
|
|
95
|
+
gates: ['Gate 10 (SAST Security)'],
|
|
90
96
|
checkCmd: 'semgrep --version',
|
|
91
97
|
install: {
|
|
92
98
|
darwin: 'brew install semgrep',
|
package/lib/doctor.js
CHANGED
|
@@ -24,7 +24,12 @@ const { checkUpgrade, formatUpgradeMsg } = require('./check-version.js');
|
|
|
24
24
|
const { GATE_CLI_TOOLS, checkCliTool, getToolInstallCmd, checkBash, detectInstalledPlatforms, getSkillsDirs } = require('./detect-deps.js');
|
|
25
25
|
// #505: the single source of truth for module resolution order. The hook reads a
|
|
26
26
|
// generated shell projection of this same module.
|
|
27
|
-
const {
|
|
27
|
+
const {
|
|
28
|
+
RESOLUTION_ORDER,
|
|
29
|
+
GATE_RESOLUTION_ORDER,
|
|
30
|
+
ADAPTER_DIR_ORDER,
|
|
31
|
+
GATE_PROBE,
|
|
32
|
+
} = require('./hook-module-resolution.js');
|
|
28
33
|
const { inspectHookFile } = require('./hook-health.js');
|
|
29
34
|
const { parseQuarantine, findPolicyViolations } = require('./flaky.js');
|
|
30
35
|
|
|
@@ -1165,18 +1170,34 @@ function resolveExecutedModuleDirs(ctx = {}) {
|
|
|
1165
1170
|
const scriptDir = ctx.scriptDir || GLOBAL_HOOKS_DIR();
|
|
1166
1171
|
|
|
1167
1172
|
const has = (dir, file) => fs.existsSync(path.join(dir, file));
|
|
1168
|
-
|
|
1173
|
+
const roots = { adapterDir: scriptDir, globalAdapterDir, projectGithooks, scriptDir };
|
|
1174
|
+
const dirFor = (tier) => dirForTierBase(tier.base, roots);
|
|
1175
|
+
|
|
1176
|
+
// Read the cascade from ADAPTER_DIR_ORDER instead of restating it. The order
|
|
1177
|
+
// used to be typed here a second time, and when the spec moved to
|
|
1178
|
+
// project-first this copy kept answering global-first -- so doctor reported a
|
|
1179
|
+
// module surface the hook had already stopped executing. That is the same
|
|
1180
|
+
// duplication #505 exists to prevent, one level down.
|
|
1169
1181
|
let adapterDir = scriptDir;
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1182
|
+
for (const tier of ADAPTER_DIR_ORDER) {
|
|
1183
|
+
const dir = dirFor(tier);
|
|
1184
|
+
if (dir && has(dir, tier.probe)) {
|
|
1185
|
+
adapterDir = dir;
|
|
1186
|
+
break;
|
|
1187
|
+
}
|
|
1174
1188
|
}
|
|
1175
1189
|
|
|
1190
|
+
// Gate scripts: same tier list, probed for the gate sentinel rather than for
|
|
1191
|
+
// adapter-common.sh (GATE_RESOLUTION_ORDER's bases mirror ADAPTER_DIR_ORDER's).
|
|
1176
1192
|
let gateDir = adapterDir;
|
|
1177
|
-
if (!has(adapterDir,
|
|
1178
|
-
|
|
1179
|
-
|
|
1193
|
+
if (!has(adapterDir, GATE_PROBE)) {
|
|
1194
|
+
for (const tier of ADAPTER_DIR_ORDER) {
|
|
1195
|
+
const dir = dirFor(tier);
|
|
1196
|
+
if (dir && has(dir, GATE_PROBE)) {
|
|
1197
|
+
gateDir = dir;
|
|
1198
|
+
break;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1180
1201
|
}
|
|
1181
1202
|
|
|
1182
1203
|
return { adapterDir, gateDir, globalAdapterDir, projectGithooks, scriptDir };
|
|
@@ -1259,17 +1280,60 @@ function executedModulePath(name, dirs) {
|
|
|
1259
1280
|
const sourced = path.join(dirs.adapterDir, name);
|
|
1260
1281
|
return fs.existsSync(sourced) ? sourced : null;
|
|
1261
1282
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1283
|
+
// The candidate chain is projected from RESOLUTION_ORDER rather than typed out
|
|
1284
|
+
// here. This used to be a second copy of the order, and it went stale the
|
|
1285
|
+
// moment the tiers changed: it began the chain with `adapterDir/<name>.sh`
|
|
1286
|
+
// (the FLAT layout) even when ADAPTER_DIR was the project tier, so a stray file
|
|
1287
|
+
// at the repo root shadowed the repo's own nested adapter.
|
|
1288
|
+
if (isGateModuleFile(name)) {
|
|
1289
|
+
// Gate modules have exactly one executed location: whatever GATE_DIR resolved
|
|
1290
|
+
// to. GATE_DIR already ran the full tier fallback in
|
|
1291
|
+
// resolveExecutedModuleDirs(), so re-walking the tiers here would report a
|
|
1292
|
+
// copy that tier holds but the gate suite does not actually run from.
|
|
1293
|
+
const gatePath = path.join(dirs.gateDir, name);
|
|
1294
|
+
return fs.existsSync(gatePath) ? gatePath : null;
|
|
1295
|
+
}
|
|
1296
|
+
// Adapter templates carry their own extension ('{name}.sh'), so the
|
|
1297
|
+
// substitution needs the bare stem here -- unlike the gate call above, which
|
|
1298
|
+
// takes the filename as-is. Same split as the hook's
|
|
1299
|
+
// resolve_adapter_path ("bare language name") vs _hook_resolve.
|
|
1300
|
+
const stem = name.replace(/\.[^./\\]+$/, '');
|
|
1301
|
+
const candidates = RESOLUTION_ORDER
|
|
1302
|
+
.map((tier) => {
|
|
1303
|
+
const root = dirForTierBase(tier.base, dirs);
|
|
1304
|
+
return root ? path.join(root, tier.template.replace('{name}', stem)) : null;
|
|
1305
|
+
})
|
|
1306
|
+
.filter(Boolean);
|
|
1270
1307
|
return candidates.find((candidate) => fs.existsSync(candidate)) || null;
|
|
1271
1308
|
}
|
|
1272
1309
|
|
|
1310
|
+
/**
|
|
1311
|
+
* The directory a resolution tier's `base` names, from
|
|
1312
|
+
* `resolveExecutedModuleDirs()` output.
|
|
1313
|
+
*
|
|
1314
|
+
* An unknown base returns null rather than ''. A '' base makes `path.join` emit a
|
|
1315
|
+
* relative path, and `existsSync` then probes the CWD -- silently testing a
|
|
1316
|
+
* different tree instead of failing.
|
|
1317
|
+
*
|
|
1318
|
+
* @param {string} base
|
|
1319
|
+
* @param {ReturnType<typeof resolveExecutedModuleDirs>} dirs
|
|
1320
|
+
* @returns {string|null}
|
|
1321
|
+
*/
|
|
1322
|
+
function dirForTierBase(base, dirs) {
|
|
1323
|
+
switch (base) {
|
|
1324
|
+
case 'ADAPTER_DIR':
|
|
1325
|
+
return dirs.adapterDir;
|
|
1326
|
+
case 'GLOBAL_ADAPTER_DIR':
|
|
1327
|
+
return dirs.globalAdapterDir;
|
|
1328
|
+
case 'PROJECT_GITHOOKS':
|
|
1329
|
+
return dirs.projectGithooks;
|
|
1330
|
+
case 'SCRIPT_DIR':
|
|
1331
|
+
return dirs.scriptDir;
|
|
1332
|
+
default:
|
|
1333
|
+
return null;
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1273
1337
|
/**
|
|
1274
1338
|
* Which tier an executed copy came from, so a FAIL says where it ran from.
|
|
1275
1339
|
*/
|