@boyingliu01/xp-gate 0.38.5 → 0.38.7

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 (52) hide show
  1. package/adapters/gate-7.sh +7 -2
  2. package/build-integrity/gate-10.ts +45 -27
  3. package/gate-7.sh +7 -2
  4. package/hooks/gate-7.sh +7 -2
  5. package/hooks/gate-entries/gate-0-entry.sh +249 -28
  6. package/hooks/gate-entries/gate-1-entry.sh +81 -3
  7. package/hooks/gate-entries/gate-10-entry.sh +7 -0
  8. package/hooks/gate-entries/gate-11-entry.sh +7 -0
  9. package/hooks/gate-entries/gate-12-entry.sh +7 -0
  10. package/hooks/gate-entries/gate-12b-entry.sh +7 -0
  11. package/hooks/gate-entries/gate-12c-entry.sh +7 -0
  12. package/hooks/gate-entries/gate-13-entry.sh +7 -0
  13. package/hooks/gate-entries/gate-5-entry.sh +48 -2
  14. package/hooks/gate-entries/gate-6-entry.sh +93 -2
  15. package/hooks/gate-entries/gate-7-entry.sh +7 -0
  16. package/hooks/gate-entries/gate-8-entry.sh +7 -0
  17. package/hooks/gate-entries/gate-9-entry.sh +7 -0
  18. package/lib/mattpocock-license-verdict.json +1 -1
  19. package/mock-policy/AGENTS.md +1 -1
  20. package/mutation/AGENTS.md +1 -1
  21. package/package.json +1 -1
  22. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  23. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  24. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  25. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  26. package/plugins/dsh/package.json +1 -1
  27. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  28. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  29. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  30. package/plugins/opencode/package.json +1 -1
  31. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  32. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  33. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  34. package/plugins/qoder/plugin.json +1 -1
  35. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  36. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  37. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  38. package/principles/AGENTS.md +1 -1
  39. package/principles/analyzer.ts +12 -1
  40. package/principles/config.ts +179 -0
  41. package/scripts/generate-mirrors.cjs +85 -28
  42. package/scripts/sync-package-content.js +5 -0
  43. package/skills/delphi-review/AGENTS.md +1 -1
  44. package/skills/sprint-flow/AGENTS.md +1 -1
  45. package/skills/test-specification-alignment/AGENTS.md +1 -1
  46. package/build-integrity/__tests__/ccn-refactor-gate10.test.ts +0 -133
  47. package/build-integrity/__tests__/gate-10.test.ts +0 -340
  48. package/build-integrity/__tests__/import-resolver.test.ts +0 -747
  49. package/build-integrity/__tests__/orchestrator.test.ts +0 -302
  50. package/build-integrity/__tests__/quote-masker.test.ts +0 -177
  51. package/skills/sprint-flow/__tests__/sprint-flow.test.cjs +0 -457
  52. package/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +0 -70
@@ -1,340 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2
- import fs from 'fs/promises';
3
- import fss from 'node:fs';
4
- import path from 'path';
5
- import os from 'os';
6
- import { runTscCheck, runPackCheck, resolveImportPath } from '../gate-10';
7
-
8
- // Increase test timeout for subprocess calls (tsc, npm pack)
9
- vi.setConfig({ testTimeout: 30000 });
10
-
11
- /**
12
- * @test REQ-627
13
- * @intent `resolveImportPath` had ZERO direct tests before this file gained them.
14
- * It decides whether an import in changed code points at a real file, so
15
- * a silent regression here makes Gate 10 pass while imports are broken.
16
- * The `.js -> .ts` fallback is the subtle part: TypeScript's ESM output
17
- * rewrites `./x.ts` to `./x.js`, so a source tree has `x.js` specifiers
18
- * that must resolve to `x.ts`. Removing that arm left every existing test
19
- * green, which is exactly why these cases are needed.
20
- * @covers AC-627-01, AC-627-02, AC-627-03
21
- */
22
-
23
- describe('resolveImportPath (build-integrity)', () => {
24
- let dir: string;
25
-
26
- beforeEach(async () => {
27
- dir = await fs.mkdtemp(path.join(os.tmpdir(), 'gate10-resolve-'));
28
- });
29
-
30
- afterEach(async () => {
31
- await fs.rm(dir, { recursive: true, force: true });
32
- });
33
-
34
- const from = (): string => path.join(dir, 'importer.ts');
35
-
36
- /**
37
- * Create a fixture file. The write is wrapped so a failure is reported with
38
- * the file name instead of surfacing as a bare fs error somewhere later — a
39
- * test whose fixture silently failed to materialise asserts nothing useful.
40
- */
41
- function writeSource(name: string, content: string): void {
42
- try {
43
- fss.writeFileSync(path.join(dir, name), content);
44
- } catch (error) {
45
- throw new Error(`could not create fixture ${name}: ${String(error)}`);
46
- }
47
- }
48
-
49
- /** Create a fixture subdirectory, for the index-file fallback case. */
50
- function makeDir(name: string): void {
51
- try {
52
- fss.mkdirSync(path.join(dir, name));
53
- } catch (error) {
54
- throw new Error(`could not create fixture dir ${name}: ${String(error)}`);
55
- }
56
- }
57
-
58
- it('AC-627-01: resolves an explicit .js specifier to the sibling .ts source', async () => {
59
- writeSource('target.ts', 'export const x = 1;\n');
60
- // The specifier says .js; only target.ts exists. ESM output depends on this.
61
- expect(resolveImportPath('./target.js', from())).toBe(path.join(dir, 'target.ts'));
62
- });
63
-
64
- it('AC-627-01: prefers an existing .js file over the .ts fallback', async () => {
65
- writeSource('both.js', 'module.exports = {};\n');
66
- writeSource('both.ts', 'export const x = 1;\n');
67
- expect(resolveImportPath('./both.js', from())).toBe(path.join(dir, 'both.js'));
68
- });
69
-
70
- it('AC-627-02: an explicit non-.js extension must match exactly (no fallback)', async () => {
71
- writeSource('mod.mjs', 'export {};\n');
72
- // .mjs exists, resolves directly
73
- expect(resolveImportPath('./mod.mjs', from())).toBe(path.join(dir, 'mod.mjs'));
74
- // .cjs does NOT exist, and there is no .cjs -> .ts fallback
75
- expect(resolveImportPath('./missing.cjs', from())).toBeNull();
76
- });
77
-
78
- it('AC-627-03: an extensionless import tries known extensions, then index files', async () => {
79
- writeSource('plain.ts', 'export const y = 2;\n');
80
- expect(resolveImportPath('./plain', from())).toBe(path.join(dir, 'plain.ts'));
81
-
82
- makeDir('pkg');
83
- writeSource('pkg/index.ts', 'export {};\n');
84
- expect(resolveImportPath('./pkg', from())).toBe(path.join(dir, 'pkg', 'index.ts'));
85
- });
86
-
87
- it('AC-627-03: a non-relative specifier is not resolved at all', () => {
88
- expect(resolveImportPath('lodash', from())).toBeNull();
89
- expect(resolveImportPath('@scope/pkg', from())).toBeNull();
90
- });
91
-
92
- it('AC-627-03: a relative import to nothing returns null', async () => {
93
- expect(resolveImportPath('./nope', from())).toBeNull();
94
- });
95
- });
96
-
97
- /**
98
- * @test Gate 10 runTscCheck
99
- * @intent Verify tsc --noEmit check behavior for build integrity gate
100
- * @covers runTscCheck
101
- */
102
-
103
- describe('runTscCheck', () => {
104
- let tmpDir: string;
105
-
106
- beforeEach(async () => {
107
- tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'gate10-test-'));
108
- // Symlink node_modules from project root so tsc is available
109
- const projectNodeModules = path.join(process.cwd(), 'node_modules');
110
- const testNodeModules = path.join(tmpDir, 'node_modules');
111
- try {
112
- await fs.symlink(projectNodeModules, testNodeModules, 'dir');
113
- } catch {
114
- // Ignore if symlink fails (e.g., already exists)
115
- }
116
- });
117
-
118
- afterEach(async () => {
119
- // Windows may hold a file lock from tsc subprocess; retry with backoff
120
- for (let attempt = 0; attempt < 5; attempt++) {
121
- try {
122
- await fs.rm(tmpDir, { recursive: true, force: true });
123
- break;
124
- } catch {
125
- if (attempt < 4) await new Promise(r => setTimeout(r, 500 * (attempt + 1)));
126
- }
127
- }
128
- });
129
-
130
- it('returns skip when no tsconfig.json exists', async () => {
131
- const result = await runTscCheck(tmpDir, 30000);
132
- expect(result.status).toBe('skip');
133
- expect(result.message).toContain('tsconfig.json');
134
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
135
- });
136
-
137
- it('returns skip when tsc is not available on PATH', async () => {
138
- // Create tsconfig.json in an isolated dir with no node_modules
139
- const isolatedDir = await fs.mkdtemp(path.join(os.tmpdir(), 'gate10-notsc-'));
140
- try {
141
- await fs.writeFile(
142
- path.join(isolatedDir, 'tsconfig.json'),
143
- JSON.stringify({ compilerOptions: { strict: true } })
144
- );
145
-
146
- // Override PATH and cwd to exclude all tsc resolution paths
147
- const originalPath = process.env.PATH;
148
- const originalCwd = process.cwd;
149
- process.env.PATH = process.platform === 'win32' ? 'C:\\Windows\\System32' : '/usr/bin:/bin';
150
- process.cwd = () => isolatedDir;
151
-
152
- try {
153
- const result = await runTscCheck(isolatedDir, 30000);
154
- expect(result.status).toBe('skip');
155
- expect(result.message).toContain('tsc');
156
- } finally {
157
- process.env.PATH = originalPath;
158
- process.cwd = originalCwd;
159
- }
160
- } finally {
161
- await fs.rm(isolatedDir, { recursive: true, force: true }).catch(() => { /* ignore cleanup errors */ });
162
- }
163
- });
164
-
165
- it('returns pass when tsc exits 0', async () => {
166
- // Create a minimal valid TypeScript project
167
- await fs.writeFile(
168
- path.join(tmpDir, 'tsconfig.json'),
169
- JSON.stringify({
170
- compilerOptions: {
171
- target: 'ES2020',
172
- module: 'commonjs',
173
- strict: true,
174
- noEmit: true,
175
- },
176
- include: ['*.ts'],
177
- })
178
- );
179
-
180
- await fs.writeFile(
181
- path.join(tmpDir, 'valid.ts'),
182
- 'const x: number = 42;\nconsole.log(x);\n'
183
- );
184
-
185
- const result = await runTscCheck(tmpDir, 60000);
186
- expect(result.status).toBe('pass');
187
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
188
- });
189
-
190
- it('returns fail when tsc exits non-zero', async () => {
191
- // Create a TypeScript project with type errors
192
- await fs.writeFile(
193
- path.join(tmpDir, 'tsconfig.json'),
194
- JSON.stringify({
195
- compilerOptions: {
196
- target: 'ES2020',
197
- module: 'commonjs',
198
- strict: true,
199
- noEmit: true,
200
- },
201
- include: ['*.ts'],
202
- })
203
- );
204
-
205
- await fs.writeFile(
206
- path.join(tmpDir, 'invalid.ts'),
207
- 'const x: number = "string";\n'
208
- );
209
-
210
- const result = await runTscCheck(tmpDir, 60000);
211
- expect(result.status).toBe('fail');
212
- expect(result.message).toMatch(/error|Error/);
213
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
214
- });
215
-
216
- it('returns skip when tsc times out', async () => {
217
- // Create a large TypeScript project that will timeout
218
- await fs.writeFile(
219
- path.join(tmpDir, 'tsconfig.json'),
220
- JSON.stringify({
221
- compilerOptions: {
222
- target: 'ES2020',
223
- module: 'commonjs',
224
- strict: true,
225
- noEmit: true,
226
- },
227
- include: ['*.ts'],
228
- })
229
- );
230
-
231
- // Create many files to slow down tsc
232
- for (let i = 0; i < 100; i++) {
233
- const content = `
234
- export const value${i} = ${i};
235
- export function fn${i}(): number { return ${i}; }
236
- export interface Interface${i} { prop: number; }
237
- `;
238
- await fs.writeFile(path.join(tmpDir, `file${i}.ts`), content);
239
- }
240
-
241
- // Very short timeout to force timeout (or tsc unavailable on slow platforms)
242
- const result = await runTscCheck(tmpDir, 500);
243
- expect(result.status).toBe('skip');
244
- expect(result.message).toMatch(/timeout|Timeout|TIMEOUT|timed out|not available/i);
245
- });
246
- });
247
-
248
- /**
249
- * @test Gate 10 runPackCheck
250
- * @intent Verify npm pack --dry-run check behavior for build integrity gate
251
- * @covers runPackCheck
252
- */
253
- describe('runPackCheck', () => {
254
- let tmpDir: string;
255
-
256
- beforeEach(async () => {
257
- tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'gate10-pack-'));
258
- });
259
-
260
- afterEach(async () => {
261
- for (let attempt = 0; attempt < 5; attempt++) {
262
- try {
263
- await fs.rm(tmpDir, { recursive: true, force: true });
264
- break;
265
- } catch {
266
- if (attempt < 4) await new Promise(r => setTimeout(r, 500 * (attempt + 1)));
267
- }
268
- }
269
- });
270
-
271
- it('returns skip when no package.json exists', async () => {
272
- const result = await runPackCheck(tmpDir, 30000);
273
- expect(result.status).toBe('skip');
274
- expect(result.message).toContain('package.json');
275
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
276
- });
277
-
278
- it('returns skip when package.json has no files field', async () => {
279
- await fs.writeFile(
280
- path.join(tmpDir, 'package.json'),
281
- JSON.stringify({ name: 'test-pkg', version: '1.0.0' })
282
- );
283
-
284
- const result = await runPackCheck(tmpDir, 30000);
285
- expect(result.status).toBe('skip');
286
- expect(result.message).toContain('files');
287
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
288
- });
289
-
290
- it('returns pass when npm pack produces non-empty file list', async () => {
291
- await fs.writeFile(
292
- path.join(tmpDir, 'package.json'),
293
- JSON.stringify({
294
- name: 'test-pkg',
295
- version: '1.0.0',
296
- files: ['index.js'],
297
- })
298
- );
299
- await fs.writeFile(path.join(tmpDir, 'index.js'), 'module.exports = {};\n');
300
-
301
- const result = await runPackCheck(tmpDir, 60000);
302
- expect(result.status).toBe('pass');
303
- expect(result.message).toMatch(/\d+ file/);
304
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
305
- });
306
-
307
- it('returns fail when npm pack exits non-zero', async () => {
308
- await fs.writeFile(
309
- path.join(tmpDir, 'package.json'),
310
- JSON.stringify({
311
- name: 'test-pkg',
312
- version: '1.0.0',
313
- files: ['index.js'],
314
- scripts: { prepack: 'exit 1' },
315
- })
316
- );
317
- await fs.writeFile(path.join(tmpDir, 'index.js'), 'module.exports = {};\n');
318
-
319
- const result = await runPackCheck(tmpDir, 60000);
320
- expect(result.status).toBe('fail');
321
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
322
- });
323
-
324
- it('returns skip when npm pack times out', async () => {
325
- await fs.writeFile(
326
- path.join(tmpDir, 'package.json'),
327
- JSON.stringify({
328
- name: 'test-pkg',
329
- version: '1.0.0',
330
- files: ['index.js'],
331
- })
332
- );
333
- await fs.writeFile(path.join(tmpDir, 'index.js'), 'module.exports = {};\n');
334
-
335
- const result = await runPackCheck(tmpDir, 1);
336
- expect(result.status).toBe('skip');
337
- expect(result.message).toMatch(/timeout|Timeout|TIMEOUT/);
338
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
339
- });
340
- });