@boyingliu01/xp-gate 0.38.5 → 0.38.6

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 (43) hide show
  1. package/build-integrity/gate-10.ts +45 -27
  2. package/hooks/gate-entries/gate-10-entry.sh +7 -0
  3. package/hooks/gate-entries/gate-11-entry.sh +7 -0
  4. package/hooks/gate-entries/gate-12-entry.sh +7 -0
  5. package/hooks/gate-entries/gate-12b-entry.sh +7 -0
  6. package/hooks/gate-entries/gate-12c-entry.sh +7 -0
  7. package/hooks/gate-entries/gate-13-entry.sh +7 -0
  8. package/hooks/gate-entries/gate-5-entry.sh +48 -2
  9. package/hooks/gate-entries/gate-6-entry.sh +93 -2
  10. package/hooks/gate-entries/gate-7-entry.sh +7 -0
  11. package/hooks/gate-entries/gate-8-entry.sh +7 -0
  12. package/hooks/gate-entries/gate-9-entry.sh +7 -0
  13. package/lib/mattpocock-license-verdict.json +1 -1
  14. package/mock-policy/AGENTS.md +1 -1
  15. package/mutation/AGENTS.md +1 -1
  16. package/package.json +1 -1
  17. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  18. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  19. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  20. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  21. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  22. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  23. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  24. package/plugins/opencode/package.json +1 -1
  25. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  26. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  27. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  28. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  29. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  30. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  31. package/principles/AGENTS.md +1 -1
  32. package/scripts/generate-mirrors.cjs +85 -28
  33. package/scripts/sync-package-content.js +5 -0
  34. package/skills/delphi-review/AGENTS.md +1 -1
  35. package/skills/sprint-flow/AGENTS.md +1 -1
  36. package/skills/test-specification-alignment/AGENTS.md +1 -1
  37. package/build-integrity/__tests__/ccn-refactor-gate10.test.ts +0 -133
  38. package/build-integrity/__tests__/gate-10.test.ts +0 -340
  39. package/build-integrity/__tests__/import-resolver.test.ts +0 -747
  40. package/build-integrity/__tests__/orchestrator.test.ts +0 -302
  41. package/build-integrity/__tests__/quote-masker.test.ts +0 -177
  42. package/skills/sprint-flow/__tests__/sprint-flow.test.cjs +0 -457
  43. package/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +0 -70
@@ -1,302 +0,0 @@
1
- /**
2
- * @test Gate 10 runGate10 orchestrator + main CLI
3
- * @intent Verify that runGate10 combines tsc/pack/import checks correctly,
4
- * and that main() parses CLI args and returns correct exit codes.
5
- * @covers runGate10, main
6
- */
7
-
8
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
9
- import fs from 'fs/promises';
10
- import path from 'path';
11
- import os from 'os';
12
-
13
- import { runGate10, main } from '../gate-10';
14
-
15
- vi.setConfig({ testTimeout: 90000 });
16
-
17
- describe('runGate10', () => {
18
- let tmpDir: string;
19
-
20
- beforeEach(async () => {
21
- tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'gate10-orch-'));
22
- const projectNodeModules = path.join(process.cwd(), 'node_modules');
23
- const testNodeModules = path.join(tmpDir, 'node_modules');
24
- try {
25
- await fs.symlink(projectNodeModules, testNodeModules, 'dir');
26
- } catch { /* may already exist */ }
27
- });
28
-
29
- afterEach(async () => {
30
- for (let attempt = 0; attempt < 5; attempt++) {
31
- try {
32
- await fs.rm(tmpDir, { recursive: true, force: true });
33
- break;
34
- } catch {
35
- if (attempt < 4) await new Promise(r => setTimeout(r, 500 * (attempt + 1)));
36
- }
37
- }
38
- });
39
-
40
- it('returns skip status when no package.json exists', async () => {
41
- const result = await runGate10({
42
- changedFiles: [],
43
- projectRoot: tmpDir,
44
- timeoutMs: 30000,
45
- });
46
-
47
- expect(result.exitCode).toBe(0);
48
- expect(result.checks.tsc.status).toBe('skip');
49
- expect(result.checks.pack.status).toBe('skip');
50
- expect(result.checks.imports.status).toBe('pass');
51
- expect(result.errors).toHaveLength(0);
52
- });
53
-
54
- it('returns skip when no changed TS/JS files and no tsconfig', async () => {
55
- await fs.writeFile(
56
- path.join(tmpDir, 'package.json'),
57
- JSON.stringify({ name: 'test', version: '1.0.0' })
58
- );
59
-
60
- const result = await runGate10({
61
- changedFiles: [],
62
- projectRoot: tmpDir,
63
- timeoutMs: 30000,
64
- });
65
-
66
- expect(result.exitCode).toBe(0);
67
- expect(result.checks.tsc.status).toBe('skip');
68
- expect(result.checks.imports.status).toBe('pass');
69
- });
70
-
71
- it('returns pass when all checks pass', async () => {
72
- // Create a minimal valid project
73
- await fs.writeFile(
74
- path.join(tmpDir, 'tsconfig.json'),
75
- JSON.stringify({
76
- compilerOptions: { target: 'ES2020', module: 'commonjs', strict: true, noEmit: true },
77
- include: ['*.ts'],
78
- })
79
- );
80
- await fs.writeFile(path.join(tmpDir, 'valid.ts'), 'const x: number = 42;\n');
81
- await fs.writeFile(
82
- path.join(tmpDir, 'package.json'),
83
- JSON.stringify({ name: 'test-pkg', version: '1.0.0' })
84
- );
85
-
86
- const validFile = path.join(tmpDir, 'valid.ts');
87
- const result = await runGate10({
88
- changedFiles: [validFile],
89
- projectRoot: tmpDir,
90
- timeoutMs: 60000,
91
- });
92
-
93
- expect(result.exitCode).toBe(0);
94
- expect(result.status).toBe('pass');
95
- expect(result.checks.tsc.status).toBe('pass');
96
- expect(result.checks.imports.status).toBe('pass');
97
- expect(result.errors).toHaveLength(0);
98
- });
99
-
100
- it('returns block (exitCode 1) when tsc check fails', async () => {
101
- // Create a project with type errors
102
- await fs.writeFile(
103
- path.join(tmpDir, 'tsconfig.json'),
104
- JSON.stringify({
105
- compilerOptions: { target: 'ES2020', module: 'commonjs', strict: true, noEmit: true },
106
- include: ['*.ts'],
107
- })
108
- );
109
- await fs.writeFile(path.join(tmpDir, 'bad.ts'), 'const x: number = "string";\n');
110
- await fs.writeFile(
111
- path.join(tmpDir, 'package.json'),
112
- JSON.stringify({ name: 'test-pkg', version: '1.0.0' })
113
- );
114
-
115
- const badFile = path.join(tmpDir, 'bad.ts');
116
- const result = await runGate10({
117
- changedFiles: [badFile],
118
- projectRoot: tmpDir,
119
- timeoutMs: 60000,
120
- });
121
-
122
- expect(result.exitCode).toBe(1);
123
- expect(result.status).toBe('block');
124
- expect(result.checks.tsc.status).toBe('fail');
125
- expect(result.errors.length).toBeGreaterThan(0);
126
- });
127
-
128
- it('returns block when import check fails', async () => {
129
- // Create a project with a broken import
130
- const srcDir = path.join(tmpDir, 'src');
131
- await fs.mkdir(srcDir);
132
- await fs.writeFile(
133
- path.join(tmpDir, 'tsconfig.json'),
134
- JSON.stringify({
135
- compilerOptions: { target: 'ES2020', module: 'commonjs', strict: true, noEmit: true },
136
- include: ['src/*.ts'],
137
- })
138
- );
139
- await fs.writeFile(
140
- path.join(srcDir, 'bad-import.ts'),
141
- `import { x } from './nonexistent';\n`
142
- );
143
- await fs.writeFile(
144
- path.join(tmpDir, 'package.json'),
145
- JSON.stringify({ name: 'test-pkg', version: '1.0.0' })
146
- );
147
-
148
- const badFile = path.join(srcDir, 'bad-import.ts');
149
- const result = await runGate10({
150
- changedFiles: [badFile],
151
- projectRoot: tmpDir,
152
- timeoutMs: 60000,
153
- });
154
-
155
- expect(result.exitCode).toBe(1);
156
- expect(result.status).toBe('block');
157
- expect(result.checks.imports.status).toBe('fail');
158
- expect(result.checks.imports.violations.length).toBeGreaterThan(0);
159
- });
160
-
161
- it('includes warnings array in result', async () => {
162
- const result = await runGate10({
163
- changedFiles: [],
164
- projectRoot: tmpDir,
165
- timeoutMs: 30000,
166
- });
167
-
168
- expect(Array.isArray(result.warnings)).toBe(true);
169
- });
170
-
171
- it('includes errors array in result', async () => {
172
- const result = await runGate10({
173
- changedFiles: [],
174
- projectRoot: tmpDir,
175
- timeoutMs: 30000,
176
- });
177
-
178
- expect(Array.isArray(result.errors)).toBe(true);
179
- });
180
-
181
- it('runs all checks in parallel (total time < sum of individual times)', async () => {
182
- // This is a soft check — we just verify the result has all three check results
183
- await fs.writeFile(
184
- path.join(tmpDir, 'tsconfig.json'),
185
- JSON.stringify({
186
- compilerOptions: { target: 'ES2020', module: 'commonjs', strict: true, noEmit: true },
187
- include: ['*.ts'],
188
- })
189
- );
190
- await fs.writeFile(path.join(tmpDir, 'valid.ts'), 'const x: number = 42;\n');
191
- await fs.writeFile(
192
- path.join(tmpDir, 'package.json'),
193
- JSON.stringify({ name: 'test-pkg', version: '1.0.0' })
194
- );
195
-
196
- const result = await runGate10({
197
- changedFiles: [path.join(tmpDir, 'valid.ts')],
198
- projectRoot: tmpDir,
199
- timeoutMs: 60000,
200
- });
201
-
202
- // All three checks should have been run
203
- expect(result.checks.tsc).toBeDefined();
204
- expect(result.checks.pack).toBeDefined();
205
- expect(result.checks.imports).toBeDefined();
206
- // All should have non-negative duration
207
- expect(result.checks.tsc.durationMs).toBeGreaterThanOrEqual(0);
208
- expect(result.checks.pack.durationMs).toBeGreaterThanOrEqual(0);
209
- expect(result.checks.imports.durationMs).toBeGreaterThanOrEqual(0);
210
- });
211
- });
212
-
213
- /**
214
- * ─── main CLI ─────────────────────────────────────────────────────────────────
215
- */
216
- describe('main', () => {
217
- let tmpDir: string;
218
- let consoleSpy: any;
219
-
220
- beforeEach(async () => {
221
- tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'gate10-cli-'));
222
- consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => { /* intentional no-op for spy */ });
223
- const projectNodeModules = path.join(process.cwd(), 'node_modules');
224
- const testNodeModules = path.join(tmpDir, 'node_modules');
225
- try {
226
- await fs.symlink(projectNodeModules, testNodeModules, 'dir');
227
- } catch { /* may already exist */ }
228
- });
229
-
230
- afterEach(async () => {
231
- consoleSpy.mockRestore();
232
- for (let attempt = 0; attempt < 5; attempt++) {
233
- try {
234
- await fs.rm(tmpDir, { recursive: true, force: true });
235
- break;
236
- } catch {
237
- if (attempt < 4) await new Promise(r => setTimeout(r, 500 * (attempt + 1)));
238
- }
239
- }
240
- });
241
-
242
- it('returns 0 when no changed files provided', async () => {
243
- const exitCode = await main([
244
- '--changed-files', '',
245
- '--project-root', tmpDir,
246
- ]);
247
- expect(exitCode).toBe(0);
248
- });
249
-
250
- it('parses comma-separated changed files', async () => {
251
- const file1 = path.join(tmpDir, 'a.ts');
252
- const file2 = path.join(tmpDir, 'b.ts');
253
- await fs.writeFile(file1, 'const a = 1;\n');
254
- await fs.writeFile(file2, 'const b = 2;\n');
255
-
256
- const exitCode = await main([
257
- '--changed-files', `${file1},${file2}`,
258
- '--project-root', tmpDir,
259
- ]);
260
-
261
- expect(exitCode).toBe(0);
262
- });
263
-
264
- it('returns 1 when a check fails', async () => {
265
- // Create a project with type errors
266
- await fs.writeFile(
267
- path.join(tmpDir, 'tsconfig.json'),
268
- JSON.stringify({
269
- compilerOptions: { target: 'ES2020', module: 'commonjs', strict: true, noEmit: true },
270
- include: ['*.ts'],
271
- })
272
- );
273
- const badFile = path.join(tmpDir, 'bad.ts');
274
- await fs.writeFile(badFile, 'const x: number = "string";\n');
275
-
276
- const exitCode = await main([
277
- '--changed-files', badFile,
278
- '--project-root', tmpDir,
279
- ]);
280
-
281
- expect(exitCode).toBe(1);
282
- });
283
-
284
- it('prints formatted results table', async () => {
285
- const exitCode = await main([
286
- '--changed-files', '',
287
- '--project-root', tmpDir,
288
- ]);
289
-
290
- // Check that console.log was called with table-like output
291
- expect(exitCode).toBe(0);
292
- const output = consoleSpy.mock.calls.map((c: unknown[]) => c[0]).join('\n');
293
- expect(output).toMatch(/tsc|pack|import/i);
294
- });
295
-
296
- it('returns 0 for --help flag', async () => {
297
- const exitCode = await main(['--help']);
298
- expect(exitCode).toBe(0);
299
- const output = consoleSpy.mock.calls.map((c: unknown[]) => c[0]).join('\n');
300
- expect(output).toMatch(/usage|help|changed-files/i);
301
- });
302
- });
@@ -1,177 +0,0 @@
1
- /**
2
- * @test The quote/comment masker's own contract (#759)
3
- * @intent Assert the masker's three positional invariants directly instead of
4
- * inferring them from extractImports' output. A shorter result shifts
5
- * every later line number, a lost newline collapses lines, and a
6
- * surviving quote re-opens the exact hole #759 closed — each is a
7
- * silent failure, so each is pinned here.
8
- * @covers maskTextQuotes, maskTextQuotesForTest
9
- */
10
-
11
- import { describe, it, expect } from 'vitest';
12
- import { maskTextQuotesForTest } from '../quote-masker';
13
-
14
- /**
15
- * Every other test drives `extractImports` and infers the masker's
16
- * behaviour from the paths that come out. These assert the three properties the
17
- * masker promises directly, because each is a silent-failure class on its own:
18
- * a shorter output shifts every later line number, a lost newline collapses
19
- * lines, and a surviving quote re-opens the exact bug #759 fixed.
20
- */
21
- describe('maskTextQuotes contract', () => {
22
- const BS = String.fromCharCode(92);
23
- const BT = String.fromCharCode(96);
24
- const SQ = String.fromCharCode(39);
25
- const SAMPLES: Array<[string, string]> = [
26
- ['plain code', "import x from './x';"],
27
- ['single-quoted string', "const a = 'hello';"],
28
- ['double-quoted string', 'const b = "hello";'],
29
- ['template literal', 'const c = ' + BT + 'hello' + BT + ';'],
30
- ['nested interpolation', 'const d = ' + BT + '${' + BT + '${v}' + BT + '}' + BT + ';'],
31
- ['line comment', "// import x from './x'"],
32
- ['block comment', "/* import x from './x' */"],
33
- ['escaped quote', 'const e = ' + BS + '"'],
34
- ['line continuation', "const f = 'a" + BS + "\nb';"],
35
- ['regex literal', 'const g = /ab+c/;'],
36
- ['trailing backslash', 'const h = ' + BS],
37
- // Unbalanced delimiters: the masker must never throw and never grow or
38
- // shrink the text, even when the file simply ends mid-literal. Every one of
39
- // these is a shape a truncated or generated file really contains.
40
- ['unterminated single quote', "const i = 'abc"],
41
- ['unterminated double quote', 'const j = "abc'],
42
- ['unterminated template', 'const k = ' + BT + 'abc'],
43
- ['unterminated block comment', 'const l = 1; /* abc'],
44
- ['unterminated interpolation', 'const m = ' + BT + '${'],
45
- ['regex holding a quote', 'const n = /' + SQ + '/;'],
46
- ['empty input', ''],
47
- ];
48
-
49
- it.each(SAMPLES)('preserves length for %s', (_label, sample) => {
50
- expect(maskTextQuotesForTest(sample).length).toBe(sample.length);
51
- });
52
-
53
- it.each(SAMPLES)('preserves the newline count for %s', (_label, sample) => {
54
- const countNewlines = (s: string): number => s.split(String.fromCharCode(10)).length;
55
- expect(countNewlines(maskTextQuotesForTest(sample))).toBe(countNewlines(sample));
56
- });
57
-
58
- it('leaves no raw quote inside masked text', () => {
59
- // The DELIMITERS survive (they are real code); what must not survive is a
60
- // quote INSIDE a literal or comment, which is what would let the import
61
- // regexes see pseudo-code. Asserting "no quote anywhere" would be wrong —
62
- // the opening quote is code.
63
- const content = "const a = 'it\"s \"x\"'; // 'another'";
64
- const masked = maskTextQuotesForTest(content);
65
- // Everything from the opening delimiter to the end of the line is either
66
- // the delimiter itself, a sentinel, or a space.
67
- const open = masked.indexOf("'");
68
- expect(open).toBeGreaterThan(-1);
69
- // The doubled-quote body keeps ONE extra delimiter; every other quote inside
70
- // the literal must be a sentinel.
71
- const seen = new Set(masked.slice(open + 1));
72
- expect(seen.has('"')).toBe(false);
73
- // The comment's quote must not survive either.
74
- expect(masked.split("'").length - 1).toBe(2);
75
- });
76
-
77
- it('is idempotent in length when applied twice', () => {
78
- // The masker is not a fixed point of itself (masking a masked string masks
79
- // its sentinels), but it must never grow or shrink the text.
80
- const content = "const a = 'x'; import y from './y';";
81
- const once = maskTextQuotesForTest(content);
82
- expect(maskTextQuotesForTest(once).length).toBe(content.length);
83
- });
84
-
85
- it('never throws on any sample, including unbalanced delimiters', () => {
86
- // `extractImports` runs over arbitrary real files, and a truncated file or a
87
- // generated artefact can end mid-literal. A throw here would abort Gate 10
88
- // for the whole file rather than mis-report one line, so this is checked
89
- // across every sample rather than one representative case.
90
- for (const [label, sample] of SAMPLES) {
91
- expect(() => maskTextQuotesForTest(sample), label).not.toThrow();
92
- }
93
- });
94
-
95
- it('never throws on a lone sentinel byte in the input', () => {
96
- // QUOTE_SENTINEL is a NUL character. Source containing a literal NUL is
97
- // unusual but legal in a string, and the masker must not treat it as
98
- // anything special.
99
- const NUL = String.fromCharCode(0);
100
- const content = "const a = '" + NUL + "'; import y from './y';";
101
- expect(() => maskTextQuotesForTest(content)).not.toThrow();
102
- expect(maskTextQuotesForTest(content).length).toBe(content.length);
103
- });
104
-
105
- it('preserves CR bytes on a CRLF-terminated file', () => {
106
- // Windows-authored sources are everywhere in this repo. A masker that
107
- // stripped or normalised `\r` would shift nothing on its own, but the
108
- // length/newline invariants are what line numbers are derived from, so the
109
- // CR bytes are pinned explicitly rather than assumed to survive.
110
- const CR = String.fromCharCode(13);
111
- const NL = String.fromCharCode(10);
112
- const content =
113
- "import a from './a';" + CR + NL +
114
- "const s = 'x';" + CR + NL +
115
- "import b from './b';" + CR + NL;
116
- const masked = maskTextQuotesForTest(content);
117
- expect(masked.length).toBe(content.length);
118
- expect(masked.split(CR).length).toBe(content.split(CR).length);
119
- expect(masked.split(NL).length).toBe(content.split(NL).length);
120
- });
121
-
122
- it('treats a division operator as code, not the start of a regex', () => {
123
- // The masker has no regex support, so `a / b` must not be mistaken for the
124
- // start of a literal. If it were, the quote in the following comment would
125
- // open a phantom string and mask the rest of the file.
126
- const content = "const r = a / b; // it's a comment\nimport real from './real';\n";
127
- const masked = maskTextQuotesForTest(content);
128
- expect(masked.length).toBe(content.length);
129
- // The real import's delimiters survive: they are code, not text.
130
- expect(masked).toContain("'./real'");
131
- });
132
-
133
- it('keeps length when a file ends on an escape INSIDE a literal', () => {
134
- // Regression: `stepEscape` pushed two characters but advanced past a
135
- // one-character remainder, so this input came out LONGER than it went in
136
- // (13 -> 14) and every line number after it would have been wrong. The
137
- // unrelated `trailing backslash` sample above missed it because that
138
- // backslash sits in code mode and never reaches stepEscape.
139
- const content = "const e = 'a" + BS;
140
- expect(maskTextQuotesForTest(content).length).toBe(content.length);
141
- });
142
-
143
- it('keeps length for EVERY truncation point of a tricky file', () => {
144
- // Exhaustive rather than representative: a fixpoint over every prefix of
145
- // several shapes is what actually proves the length invariant, because the
146
- // escape bug above lived at exactly ONE truncation point out of many.
147
- const DQ = String.fromCharCode(34);
148
- const NL = String.fromCharCode(10);
149
- const seeds = [
150
- "const a = 'x' + " + DQ + 'y' + DQ + ';',
151
- 'const t = ' + BT + '${a + ' + BT + '${b}' + BT + '}' + BT + ';',
152
- '/* c */ const z = 1; // tail',
153
- "const e = 'a" + BS + "'b';",
154
- "const l = 'a" + BS + NL + " b';",
155
- 'const m = ' + BT + '${' + BT + '${v}' + BT + '}' + BT + ';',
156
- ];
157
- for (const seed of seeds) {
158
- for (let n = 0; n <= seed.length; n++) {
159
- const prefix = seed.slice(0, n);
160
- expect(
161
- maskTextQuotesForTest(prefix).length,
162
- 'prefix ' + n + ' of ' + JSON.stringify(seed),
163
- ).toBe(prefix.length);
164
- }
165
- }
166
- });
167
-
168
- it('terminates on an unterminated literal instead of spinning', () => {
169
- // A truncated file leaves `mode` non-code for the rest of the input. Each
170
- // handler advances the cursor, so the loop is bounded by the input length —
171
- // this test fails (by timing out) if a future handler ever forgets to.
172
- for (const sample of ["const i = 'abc", '/* x', 'const k = ' + BT + 'abc']) {
173
- const out = maskTextQuotesForTest(sample);
174
- expect(out.length).toBe(sample.length);
175
- }
176
- });
177
- });