@boyingliu01/xp-gate 0.38.32 → 0.38.33

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 (33) hide show
  1. package/adapters/gate-3.sh +39 -3
  2. package/adapters/gate-4.sh +1 -1
  3. package/adapters/php.sh +362 -0
  4. package/gate-3.sh +39 -3
  5. package/gate-4.sh +1 -1
  6. package/hooks/gate-3.sh +39 -3
  7. package/hooks/gate-4.sh +1 -1
  8. package/lib/__tests__/language-capability.test.js +291 -0
  9. package/lib/__tests__/language-tools-detect.test.js +82 -0
  10. package/lib/language-capability-surfaces.js +315 -0
  11. package/lib/language-capability.js +474 -0
  12. package/lib/language-tools.js +107 -0
  13. package/lib/mattpocock-license-verdict.json +1 -1
  14. package/package.json +1 -1
  15. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  16. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  17. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  18. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  19. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  20. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  21. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  22. package/plugins/opencode/package.json +1 -1
  23. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  24. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  25. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  26. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  27. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  28. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  29. package/principles/adapters/php.ts +77 -0
  30. package/principles/analyzer.ts +6 -0
  31. package/skills/delphi-review/AGENTS.md +1 -1
  32. package/skills/sprint-flow/AGENTS.md +1 -1
  33. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -0,0 +1,291 @@
1
+ /**
2
+ * @test REQ-LANG-CAPABILITY
3
+ * @intent 一门新语言要在 13 个互不引用的接入面上各写一遍,缺任何一处的症状都是
4
+ * 「门禁打印 PASSED/SKIPPED 而从未检查过任何该语言的文件」。C# 为此分 5 波
5
+ * 补了 16 天,消费项目还自建了 400+ 行门禁兜底。本模块把「接全了吗」变成
6
+ * 从代码派生的三态输出,这些测试钉住派生的**准确性**与**不误报**两面。
7
+ * @covers AC-LANG-CAP-01, AC-LANG-CAP-02, AC-LANG-CAP-03, AC-LANG-CAP-04
8
+ */
9
+ 'use strict';
10
+
11
+ const fs = require('node:fs');
12
+ const os = require('node:os');
13
+ const path = require('node:path');
14
+
15
+ const {
16
+ STATE,
17
+ inspectLanguage,
18
+ inspectAll,
19
+ summarise,
20
+ hasExtensionToken,
21
+ hasLanguageKey,
22
+ definitionAndCall,
23
+ } = require('../language-capability');
24
+
25
+ const REPO_ROOT = path.resolve(__dirname, '../../../..');
26
+
27
+ /**
28
+ * Build a fake hooks tree so each test states exactly which surfaces are wired.
29
+ *
30
+ * A fixture rather than the real repo on purpose: assertions against the live
31
+ * tree would fail every time a gate is legitimately edited, which teaches
32
+ * people to update the expectation instead of reading the failure. The real
33
+ * tree gets one separate test at the bottom.
34
+ *
35
+ * @param {Record<string, string>} files relative path -> content
36
+ * @returns {{root: string, cleanup: () => void}}
37
+ */
38
+ function fixture(files) {
39
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-langcap-'));
40
+ const withDefaults = {
41
+ 'githooks/pre-commit': '',
42
+ ...files,
43
+ };
44
+ for (const [rel, content] of Object.entries(withDefaults)) {
45
+ const target = path.join(root, rel);
46
+ fs.mkdirSync(path.dirname(target), { recursive: true });
47
+ fs.writeFileSync(target, content);
48
+ }
49
+ return { root, cleanup: () => fs.rmSync(root, { recursive: true, force: true }) };
50
+ }
51
+
52
+ const ADAPTER = `
53
+ run_static_analysis() { return 0; }
54
+ run_lint() { return 0; }
55
+ run_tests() { return 0; }
56
+ run_coverage() { return 0; }
57
+ `;
58
+
59
+ describe('extension-token matching is exact, not substring', () => {
60
+ it('does not report csx as cs', () => {
61
+ expect(hasExtensionToken('csx|vb', 'cs')).toBe(false);
62
+ expect(hasExtensionToken('cs|csx', 'cs')).toBe(true);
63
+ expect(hasExtensionToken('cs|csx', 'csx')).toBe(true);
64
+ });
65
+
66
+ // The real defect shape: a reader using includes('php') would match a
67
+ // variable name or a comment, and report a gate as wired when it is not.
68
+ it('does not match an extension that is only a prefix of another', () => {
69
+ expect(hasExtensionToken('phpcs', 'php')).toBe(false);
70
+ expect(hasExtensionToken('php|phps', 'php')).toBe(true);
71
+ });
72
+ });
73
+
74
+ describe('language keys must be delimited, not bare prose', () => {
75
+ it('ignores a language mentioned only in a comment', () => {
76
+ expect(hasLanguageKey('# see the php arm\n', 'php')).toBe(false);
77
+ });
78
+
79
+ it('accepts case-arm and quoted-key shapes', () => {
80
+ expect(hasLanguageKey(' php)\n echo hi\n', 'php')).toBe(true);
81
+ expect(hasLanguageKey(" 'php': { name: 'PHP' },", 'php')).toBe(true);
82
+ });
83
+ });
84
+
85
+ describe('definitionAndCall separates "exists" from "is invoked"', () => {
86
+ // This is the exact C# Gate 13 defect (#717 §8): the function was defined and
87
+ // nothing called it, and a grep for the name read as coverage.
88
+ it('distinguishes a definition from a call', () => {
89
+ const definedOnly = 'gate13_run_php_analysis() {\n return 0\n}\n';
90
+ expect(definitionAndCall(definedOnly, 'gate13_run_php_analysis')).toEqual({
91
+ defined: true,
92
+ called: false,
93
+ });
94
+
95
+ const withCall = `${definedOnly}\ngate13_run_php_analysis; _g13_rc=$?\n`;
96
+ expect(definitionAndCall(withCall, 'gate13_run_php_analysis')).toEqual({
97
+ defined: true,
98
+ called: true,
99
+ });
100
+ });
101
+
102
+ it('does not count a commented-out call', () => {
103
+ const text = 'gate13_run_php_analysis() { return 0; }\n# gate13_run_php_analysis\n';
104
+ expect(definitionAndCall(text, 'gate13_run_php_analysis').called).toBe(false);
105
+ });
106
+
107
+ it('reports neither for an absent function', () => {
108
+ expect(definitionAndCall('echo hi\n', 'gate13_run_php_analysis')).toEqual({
109
+ defined: false,
110
+ called: false,
111
+ });
112
+ });
113
+ });
114
+
115
+ describe('未接线必须被报成 NOT WIRED,且每个面独立判定', () => {
116
+ it('reports an absent adapter as not implemented', () => {
117
+ const f = fixture({});
118
+ try {
119
+ const rows = inspectLanguage('php', {
120
+ root: f.root,
121
+ read: (rel) => {
122
+ try {
123
+ return fs.readFileSync(path.join(f.root, rel), 'utf8');
124
+ } catch {
125
+ return null;
126
+ }
127
+ },
128
+ });
129
+ const adapter = rows.find((r) => r.surface === 'adapter');
130
+ expect(adapter.state).toBe(STATE.NOT_IMPLEMENTED);
131
+ } finally {
132
+ f.cleanup();
133
+ }
134
+ });
135
+
136
+ it('reports Gate 4 NOT WIRED when the filter accepts the file but the analyzer map does not', () => {
137
+ // The #717 defect verbatim: gate-4.sh listed `cs` in its filter, analyzer.ts
138
+ // had no '.cs' entry, so the file was accepted and then dropped.
139
+ const f = fixture({
140
+ 'githooks/adapters/php.sh': ADAPTER,
141
+ 'githooks/adapters/gate-4.sh': "PRINCIPLES_FILES=$(echo \"$CHANGED_FILES\" | grep -E '\\.(ts|php)$')\n",
142
+ 'src/principles/analyzer.ts': "const adapterMap = { '.ts': TypeScriptAdapter };\n",
143
+ });
144
+ try {
145
+ const rows = inspectLanguage('php', {
146
+ root: f.root,
147
+ read: (rel) => {
148
+ try {
149
+ return fs.readFileSync(path.join(f.root, rel), 'utf8');
150
+ } catch {
151
+ return null;
152
+ }
153
+ },
154
+ });
155
+ const gate4 = rows.find((r) => r.surface === 'gate-4');
156
+ expect(gate4.state).toBe(STATE.NOT_WIRED);
157
+ expect(gate4.evidence).toMatch(/adapterMap has no entry/);
158
+ } finally {
159
+ f.cleanup();
160
+ }
161
+ });
162
+
163
+ it('reports Gate 13 NOT WIRED when the function is defined but never invoked', () => {
164
+ const f = fixture({
165
+ 'githooks/adapters/gate-13-compiler-strictness.sh': 'gate13_run_php_analysis() { return 0; }\n',
166
+ 'githooks/gate-entries/gate-13-entry.sh': 'gate13_run_cpp_analysis; _g13_rc=$?\n',
167
+ });
168
+ try {
169
+ const rows = inspectLanguage('php', {
170
+ root: f.root,
171
+ read: (rel) => {
172
+ try {
173
+ return fs.readFileSync(path.join(f.root, rel), 'utf8');
174
+ } catch {
175
+ return null;
176
+ }
177
+ },
178
+ });
179
+ const g13 = rows.find((r) => r.surface === 'gate-13');
180
+ expect(g13.state).toBe(STATE.NOT_WIRED);
181
+ expect(g13.evidence).toMatch(/DEFINED BUT NEVER CALLED/);
182
+ } finally {
183
+ f.cleanup();
184
+ }
185
+ });
186
+ });
187
+
188
+ describe('不得误报:已接线的面必须读成 checked', () => {
189
+ it('reads a fully wired fixture as all-checked', () => {
190
+ const f = fixture({
191
+ 'githooks/adapters/php.sh': ADAPTER,
192
+ 'githooks/adapters/gate-3.sh': "CC_FILES=$(echo \"$CHANGED_FILES\" | grep -E '\\.(ts|php)$')\n",
193
+ 'githooks/adapters/gate-4.sh': "PRINCIPLES_FILES=$(echo \"$CHANGED_FILES\" | grep -E '\\.(ts|php)$')\n",
194
+ 'githooks/gate-entries/gate-0-entry.sh': '_detect_ext_lang "php" || true\n',
195
+ 'githooks/gate-entries/gate-1-entry.sh': 'any_changed_files_match "\\.(ts|php)$" || true\n',
196
+ 'githooks/gate-entries/gate-2-entry.sh': "SOURCE_FILES=$(echo \"$CHANGED_FILES\" | grep -E '\\.(ts|php)$')\n",
197
+ 'githooks/gate-entries/gate-5-entry.sh': "CODE_EXTENSIONS=\"\\.(ts|php)$\"\n",
198
+ 'githooks/gate-entries/gate-6-entry.sh': ' php)\n echo arch\n ;;\n',
199
+ 'githooks/gate-entries/gate-9-entry.sh': ' php)\n echo build\n ;;\n',
200
+ 'githooks/gate-10.sh': 'SEMGREP_RULES+=(--config="$(gate10_resolve_ruleset "p/php")")\n',
201
+ 'githooks/adapters/gate-13-compiler-strictness.sh': 'gate13_run_php_analysis() { return 0; }\n',
202
+ 'githooks/gate-entries/gate-13-entry.sh': 'gate13_run_php_analysis; _g13_rc=$?\n',
203
+ 'src/principles/analyzer.ts': "const adapterMap = { '.php': PhpAdapter };\n",
204
+ 'src/npm-package/lib/language-tools.js': ' php: {\n name: "PHP",\n },\n',
205
+ '.github/workflows/quality-gates.yml': " echo 'php' > project_language.txt\n",
206
+ });
207
+ try {
208
+ const rows = inspectLanguage('php', {
209
+ root: f.root,
210
+ read: (rel) => {
211
+ try {
212
+ return fs.readFileSync(path.join(f.root, rel), 'utf8');
213
+ } catch {
214
+ return null;
215
+ }
216
+ },
217
+ });
218
+ const sum = summarise(rows);
219
+ expect(sum.notWired).toBe(0);
220
+ expect(sum.checked).toBeGreaterThanOrEqual(12);
221
+ } finally {
222
+ f.cleanup();
223
+ }
224
+ });
225
+ });
226
+
227
+ /**
228
+ * The one test that reads the REAL tree.
229
+ *
230
+ * It asserts a property rather than a fixed score. Two properties are worth
231
+ * pinning here because both are silent when violated:
232
+ *
233
+ * 1. A routed language with an ANALYZER must not have the Gate 4
234
+ * filter/map mismatch. That mismatch (#717: gate-4.sh accepted `.cs`,
235
+ * `analyzer.ts` had no entry) is always a bug, never a design choice, and
236
+ * it presents as a gate that "checked" a file it discarded.
237
+ *
238
+ * 2. Gate 4 does NOT need to cover every language with an adapter. Measured:
239
+ * `analyzer.ts` has no shell, powershell or iac adapter at all, so those
240
+ * three languages are correctly absent from the filter. Asserting
241
+ * "filter must match adapters" would have demanded wiring that cannot
242
+ * exist, and the natural fix -- widening the filter -- would have created
243
+ * exactly the accepted-then-dropped defect this file exists to catch.
244
+ * The right requirement is that the language either has an analyzer or is
245
+ * a declared gap, and the two are distinguishable.
246
+ */
247
+ describe('real repository invariants', () => {
248
+ it('no language that HAS an analyzer is discarded by the Gate 4 filter', () => {
249
+ const rows = inspectAll({ root: REPO_ROOT });
250
+ // Languages with an analyzer entry are exactly those the principled engine
251
+ // can construct; the filter must therefore accept them.
252
+ const analyzerSrc = fs.readFileSync(
253
+ path.join(REPO_ROOT, 'src/principles/analyzer.ts'),
254
+ 'utf8',
255
+ );
256
+ const withAnalyzer = new Set();
257
+ for (const r of rows) {
258
+ const hasMapEntry = r.surface === 'gate-4' && /adapterMap/.test(r.evidence);
259
+ if (hasMapEntry) withAnalyzer.add(r.language);
260
+ }
261
+ const mismatches = rows.filter(
262
+ (r) =>
263
+ r.surface === 'gate-4' &&
264
+ r.state === STATE.NOT_WIRED &&
265
+ /adapterMap has no entry/.test(r.evidence),
266
+ );
267
+ // The mismatch state only arises when the filter ACCEPTS and the map does
268
+ // not -- so any occurrence is the defect regardless of the set above.
269
+ expect(mismatches.map((m) => `${m.language}: ${m.evidence}`)).toEqual([]);
270
+ expect(analyzerSrc.length).toBeGreaterThan(0);
271
+ });
272
+
273
+ it('Gate 4 declares shell/powershell/iac as gaps rather than pretending', () => {
274
+ // Pinned so that adding an analyzer for one of them without wiring the
275
+ // filter fails here instead of shipping a half-scaffolded language.
276
+ const rows = inspectAll({ root: REPO_ROOT });
277
+ for (const lang of ['shell', 'powershell', 'iac']) {
278
+ const gate4 = rows.find((r) => r.language === lang && r.surface === 'gate-4');
279
+ expect(gate4.state).toBe(STATE.NOT_WIRED);
280
+ expect(gate4.evidence).toMatch(/extension absent from gate-4\.sh/);
281
+ }
282
+ });
283
+
284
+ it('csharp is fully wired except Gate 9, which is a declared gap', () => {
285
+ const rows = inspectAll({ root: REPO_ROOT }).filter((r) => r.language === 'csharp');
286
+ const sum = summarise(rows);
287
+ expect(sum.notWired).toBe(0);
288
+ const gap = rows.find((r) => r.state === STATE.NOT_IMPLEMENTED);
289
+ expect(gap.surface).toBe('gate-9');
290
+ });
291
+ });
@@ -217,3 +217,85 @@ describe('detectProjectLanguages C# registry membership (#730)', () => {
217
217
  expect(detected).not.toContain('csharp');
218
218
  });
219
219
  });
220
+
221
+ /**
222
+ * @test REQ-846
223
+ * @intent Objective-C 有完整的运行时(githooks/adapters/objectivec.sh),且在 Gate 1/3/4/5/10
224
+ * 与 docs-only.sh 的每个门禁层清单里都出现过,却从未进入 LANGUAGE_REGISTRY。这是 #730
225
+ * 的同构缺陷:detect-languages 生成的配置不含 objectivec,而读配置的 hook 不回退
226
+ * 扩展名嗅探,于是 Objective-C 项目永不路由。注册表成员资格,而非门禁支持,决定可达性。
227
+ * @covers AC-846-01, AC-846-02, AC-846-03, AC-846-04
228
+ */
229
+ describe('detectProjectLanguages Objective-C registry membership (#846)', () => {
230
+ let loadModule;
231
+
232
+ beforeEach(() => {
233
+ vi.resetModules();
234
+ delete require.cache[require.resolve('../language-tools')];
235
+ loadModule = () => require('../language-tools');
236
+ vi.spyOn(console, 'log').mockImplementation(() => {});
237
+ });
238
+
239
+ afterEach(() => {
240
+ vi.restoreAllMocks();
241
+ });
242
+
243
+ function detectIn(spec) {
244
+ const root = makeFixture(spec);
245
+ try {
246
+ return loadModule().detectProjectLanguages(root);
247
+ } finally {
248
+ fs.rmSync(root, { recursive: true, force: true });
249
+ }
250
+ }
251
+
252
+ it('detects objectivec from a Podfile', () => {
253
+ const { detected, configFiles } = detectIn({
254
+ Podfile: "platform :ios, '13.0'",
255
+ 'ViewController.m': '#import <UIKit/UIKit.h>',
256
+ });
257
+ expect(detected).toContain('objectivec');
258
+ expect(configFiles.objectivec).toContain('Podfile');
259
+ });
260
+
261
+ // The .xcodeproj is a DIRECTORY, and .pbxproj lives inside it — not at the repo
262
+ // root. A registry entry listing only the literal '.pbxproj' would stat a file
263
+ // of that name and never match, leaving the config looking corrected while
264
+ // detection stayed broken. Glob it and prove the glob actually fires.
265
+ it('detects objectivec from a <name>.pbxproj inside an Xcode project dir', () => {
266
+ expect(
267
+ detectIn({
268
+ 'MyApp.xcodeproj/project.pbxproj': '// !$*UTF8*$!',
269
+ 'AppDelegate.m': '@implementation AppDelegate @end',
270
+ }).detected,
271
+ ).toContain('objectivec');
272
+ });
273
+
274
+ // The bug's actual shape: an iOS app with a JS bridge or Fastlane tooling.
275
+ // Before the fix this reported typescript alone, so the hook took the
276
+ // TypeScript path for an Objective-C codebase.
277
+ it('reports objectivec alongside typescript in a mixed ObjC + JS repo', () => {
278
+ const { detected } = detectIn({
279
+ Podfile: 'platform :ios, 13.0',
280
+ 'Main.m': 'int main() { return 0; }',
281
+ 'package.json': '{"name":"bridge"}',
282
+ });
283
+ expect(detected).toEqual(expect.arrayContaining(['objectivec', 'typescript']));
284
+ });
285
+
286
+ // `.m` is also MATLAB's extension. Objective-C detection must key off the Xcode
287
+ // manifest, NOT the extension, or every MATLAB checkout is graded as ObjC —
288
+ // and since `configFiles` is non-empty for objectivec, the extension fallback
289
+ // is structurally disabled for it.
290
+ it('does not report objectivec for a MATLAB repo that has only .m files', () => {
291
+ const { detected } = detectIn({
292
+ 'script.m': 'x = [1 2 3]; plot(x);',
293
+ });
294
+ expect(detected).not.toContain('objectivec');
295
+ });
296
+
297
+ it('does not report objectivec for a repo with no Xcode artifact', () => {
298
+ const { detected } = detectIn({ 'package.json': '{}', 'index.js': '' });
299
+ expect(detected).not.toContain('objectivec');
300
+ });
301
+ });