@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
@@ -13,6 +13,16 @@
13
13
  * mirror-only fix that the next publish rolled back, and #717 sent a C#
14
14
  * SAST fix into a file no hook sourced.
15
15
  *
16
+ * P1-E step 2 adds the three trees that were still committed twice and are
17
+ * already byte-identical mirrors: `hooks/lib/` (21), `build-integrity/`
18
+ * (9) and `skills/` (67). Same argument, same contract, 97 more files that
19
+ * stop having an editorial second copy.
20
+ *
21
+ * `src/principles/` is NOT here yet, and the omission is deliberate: it is
22
+ * still being edited in place by another workstream, and two producers
23
+ * writing one tree means the content depends on which process ran last.
24
+ * It joins once that work lands.
25
+ *
16
26
  * P1-E step 1 moves the largest tree (`adapters/`, 199 files) out of
17
27
  * version control. Once it is generated, "edit the wrong copy" stops being
18
28
  * detectable-but-possible and becomes physically impossible: there is no
@@ -48,7 +58,10 @@ const REPO_ROOT = path.resolve(PKG_ROOT, '..', '..');
48
58
 
49
59
  /** Mirrors generated here, each with the canonical tree it comes from. */
50
60
  const GENERATED_TREES = Object.freeze([
51
- { mirror: 'adapters', canonical: path.join(REPO_ROOT, 'githooks', 'adapters') },
61
+ { mirror: 'adapters', canonical: path.join(REPO_ROOT, 'githooks', 'adapters'), sync: 'adapters' },
62
+ { mirror: 'hooks/lib', canonical: path.join(REPO_ROOT, 'githooks', 'lib'), sync: 'hooks' },
63
+ { mirror: 'build-integrity', canonical: path.join(REPO_ROOT, 'src', 'build-integrity'), sync: 'module' },
64
+ { mirror: 'skills', canonical: path.join(REPO_ROOT, 'skills'), sync: 'skills' },
52
65
  ]);
53
66
 
54
67
  function quiet(argv) {
@@ -75,46 +88,90 @@ function main(argv = process.argv.slice(2)) {
75
88
  if (!silent) process.stderr.write(`${message}\n`);
76
89
  };
77
90
 
78
- // 1. The tree this step owns. Absence of the canonical source is a defect in the
79
- // checkout, not a normal state, so it fails rather than skipping.
80
- const [{ mirror, canonical }] = GENERATED_TREES;
81
- if (!fs.existsSync(canonical)) {
82
- process.stderr.write(
83
- `[generate-mirrors] CANNOT GENERATE: canonical tree missing: ${canonical}\n`
84
- + ' The package would build without its adapters. Refusing to continue '
85
- + 'silently -- a package missing the files it ships is the failure this\n'
86
- + ' generator exists to prevent.\n',
87
- );
88
- return 1;
89
- }
91
+ // The canonical source of `adapters` is the tree this module was built for, so
92
+ // its absence is a defect in the checkout and fails. The other three are
93
+ // best-effort: `prepare` runs on every `npm install`, including from a sdist-less
94
+ // checkout where a sibling tree may legitimately be absent, and an install must
95
+ // not fail because of that. It must not SILENTLY SKIP either -- a package that
96
+ // ships without the files it promises is worse than a loud warning.
97
+ const REQUIRED = 'adapters';
98
+ const failures = [];
99
+ let syncSkillsHook;
100
+ let syncAdaptersHook;
101
+ let syncModulesHook;
102
+ let syncHooksHook;
90
103
 
91
- let sync;
92
104
  try {
93
105
  // Required lazily: sync-package-content.js runs its own main at require-time
94
106
  // when invoked directly, and the eager import would make every caller pay for
95
107
  // the skills/plugin discovery even when only the adapters mirror is wanted.
96
- // No eslint-disable needed: this file is CommonJS and `global-require` does
97
- // not fire here (the directive that used to sit on this line was itself the
98
- // reported problem -- an unused disable is a warning, and Gate 1 allows zero).
99
- ({ syncAdapters: sync } = require('./sync-package-content.js'));
108
+ const mod = require('./sync-package-content.js');
109
+ syncAdaptersHook = mod.syncAdapters;
110
+ syncModulesHook = mod.syncModules;
111
+ syncSkillsHook = mod.syncSkills;
112
+ syncHooksHook = mod.syncHooks;
100
113
  } catch (error) {
101
114
  process.stderr.write(`[generate-mirrors] cannot load sync-package-content.js: ${error.message}\n`);
102
115
  return 1;
103
116
  }
104
117
 
105
- if (typeof sync !== 'function') {
106
- process.stderr.write('[generate-mirrors] sync-package-content.js does not export syncAdapters\n');
107
- return 1;
108
- }
118
+ for (const tree of GENERATED_TREES) {
119
+ if (!fs.existsSync(tree.canonical)) {
120
+ if (tree.mirror === REQUIRED) {
121
+ process.stderr.write(
122
+ `[generate-mirrors] CANNOT GENERATE: canonical tree missing: ${tree.canonical}\n`
123
+ + ' The package would build without its adapters. Refusing to continue '
124
+ + 'silently -- a package missing the files it ships is the failure this\n'
125
+ + ' generator exists to prevent.\n',
126
+ );
127
+ return 1;
128
+ }
129
+ process.stderr.write(
130
+ `[generate-mirrors] WARNING: canonical tree missing, skipping ${tree.mirror}/: ${tree.canonical}\n`
131
+ + ' The published package would be missing these files. This is tolerated '
132
+ + 'only because `prepare` runs on installs from partial checkouts.\n',
133
+ );
134
+ failures.push(tree.mirror);
135
+ continue;
136
+ }
109
137
 
110
- const entries = sync();
111
- const files = countFiles(path.join(PKG_ROOT, mirror));
112
- if (files === 0) {
113
- process.stderr.write(`[generate-mirrors] ERROR: ${mirror}/ generated 0 files from ${canonical}\n`);
114
- return 1;
138
+ let produced = 0;
139
+ try {
140
+ if (tree.sync === 'adapters') {
141
+ syncAdaptersHook();
142
+ produced = 1;
143
+ } else if (tree.sync === 'hooks') {
144
+ // syncHooks copies githooks/* plus the whole githooks/lib/ subtree.
145
+ syncHooksHook();
146
+ produced = 1;
147
+ } else if (tree.sync === 'module') {
148
+ produced = syncModulesHook(tree.mirror);
149
+ } else if (tree.sync === 'skills') {
150
+ syncSkillsHook();
151
+ produced = 1;
152
+ }
153
+ } catch (error) {
154
+ process.stderr.write(`[generate-mirrors] ERROR generating ${tree.mirror}/: ${error.message}\n`);
155
+ return 1;
156
+ }
157
+
158
+ if (!produced) {
159
+ process.stderr.write(`[generate-mirrors] ERROR: sync for ${tree.mirror}/ reported nothing copied\n`);
160
+ return 1;
161
+ }
162
+
163
+ const mirrorDir = tree.mirror === 'hooks/lib'
164
+ ? path.join(PKG_ROOT, 'hooks', 'lib')
165
+ : path.join(PKG_ROOT, tree.mirror);
166
+ const files = countFiles(mirrorDir);
167
+ if (files === 0) {
168
+ process.stderr.write(`[generate-mirrors] ERROR: ${tree.mirror}/ generated 0 files from ${tree.canonical}\n`);
169
+ return 1;
170
+ }
171
+ say(`[generate-mirrors] ${tree.mirror}/ (${files} files)`);
115
172
  }
116
- say(`[generate-mirrors] ${mirror}/ (${entries} entries, ${files} files)`);
117
173
 
174
+ if (failures.length > 0) say(`[generate-mirrors] best-effort trees skipped: ${failures.join(', ')}`);
118
175
  return 0;
119
176
  }
120
177
 
@@ -609,5 +609,10 @@ if (require.main === module) {
609
609
  checkPreCommitDrift,
610
610
  syncHooks,
611
611
  syncAdapters,
612
+ // P1-E step 2: generate-mirrors.cjs produces these trees too, so the mirror
613
+ // stops being a second committed copy. Exported for that caller only; the
614
+ // require-time guards above stay untouched.
615
+ syncSkills,
616
+ syncModules,
612
617
  };
613
618
  }
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.5.0
6
+ **Version:** 0.38.6.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.5.0
6
+ **Version:** 0.38.6.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration, 40-67% token savings vs parallel). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.5.0
6
+ **Version:** 0.38.6.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,133 +0,0 @@
1
- /**
2
- * @test CCN refactoring for Gate 10 (runGate10, main)
3
- * @intent Verify refactored functions maintain same behavior
4
- * @covers runGate10, main, parseGate10Args, printGate10Result
5
- */
6
-
7
- import { describe, it, expect, vi } from 'vitest';
8
-
9
- import { runGate10, parseGate10Args } from '../gate-10';
10
-
11
- vi.setConfig({ testTimeout: 30000 });
12
-
13
- describe('parseGate10Args', () => {
14
- it('parses --changed-files with comma-separated values', () => {
15
- const result = parseGate10Args([
16
- '--changed-files', 'src/a.ts,src/b.ts',
17
- ]);
18
- expect(result.changedFiles).toEqual(['src/a.ts', 'src/b.ts']);
19
- expect(result.projectRoot).toBe(process.cwd());
20
- expect(result.timeoutMs).toBe(60000);
21
- });
22
-
23
- it('parses --project-root', () => {
24
- const result = parseGate10Args([
25
- '--project-root', '/tmp/test',
26
- ]);
27
- expect(result.projectRoot).toBe('/tmp/test');
28
- });
29
-
30
- it('parses --timeout', () => {
31
- const result = parseGate10Args([
32
- '--timeout', '30000',
33
- ]);
34
- expect(result.timeoutMs).toBe(30000);
35
- });
36
-
37
- it('returns help=true when --help is passed', () => {
38
- const result = parseGate10Args(['--help']);
39
- expect(result.help).toBe(true);
40
- });
41
-
42
- it('trims and filters empty changed files', () => {
43
- const result = parseGate10Args([
44
- '--changed-files', 'a.ts,,,b.ts',
45
- ]);
46
- expect(result.changedFiles).toEqual(['a.ts', 'b.ts']);
47
- });
48
-
49
- it('returns empty array when no --changed-files', () => {
50
- const result = parseGate10Args([]);
51
- expect(result.changedFiles).toEqual([]);
52
- });
53
- });
54
-
55
- describe('runGate10 (status logic tests)', () => {
56
- it('blocks when tsc fails, pack passes, import passes', async () => {
57
- const result = await runGate10({
58
- changedFiles: [],
59
- projectRoot: '/nonexistent',
60
- timeoutMs: 30000,
61
- });
62
-
63
- // No tsconfig → tsc skip, no package.json → pack skip, no files → imports pass
64
- expect(result.exitCode).toBe(0);
65
- expect(result.checks.tsc.status).toBe('skip');
66
- expect(result.checks.pack.status).toBe('skip');
67
- expect(result.checks.imports.status).toBe('pass');
68
- });
69
-
70
- it('status is skip when ALL checks skip', () => {
71
- // Test via static analysis — status = skip when all are skip
72
- const result = {
73
- status: 'skip' as const,
74
- exitCode: 0,
75
- checks: {
76
- tsc: { status: 'skip' as const, message: '', durationMs: 0 },
77
- pack: { status: 'skip' as const, message: '', durationMs: 0 },
78
- imports: { status: 'skip' as const, message: '', durationMs: 0, violations: [] },
79
- },
80
- warnings: [],
81
- errors: [],
82
- };
83
- expect(result.status).toBe('skip');
84
- expect(result.exitCode).toBe(0);
85
- });
86
-
87
- it('status is pass when any check passes and none fail', () => {
88
- const result = {
89
- status: 'pass' as const,
90
- exitCode: 0,
91
- checks: {
92
- tsc: { status: 'pass' as const, message: '', durationMs: 0 },
93
- pack: { status: 'skip' as const, message: '', durationMs: 0 },
94
- imports: { status: 'skip' as const, message: '', durationMs: 0, violations: [] },
95
- },
96
- warnings: [],
97
- errors: [],
98
- };
99
- expect(result.status).toBe('pass');
100
- });
101
- });
102
-
103
- describe('collectErrors', () => {
104
- it('collects errors from failed checks', async () => {
105
- // Import the internal functions via the module
106
- const result = await runGate10({
107
- changedFiles: [],
108
- projectRoot: '/nonexistent',
109
- timeoutMs: 30000,
110
- });
111
- // In this path: no tsconfig (skip), no package.json (skip), no files (pass)
112
- expect(result.errors).toEqual([]);
113
- expect(result.warnings).toEqual([]);
114
- });
115
- });
116
-
117
- describe('resolveGate10Status', () => {
118
- it('returns block when any check fails', () => {
119
- const result = {
120
- status: 'block' as const,
121
- exitCode: 1,
122
- checks: {
123
- tsc: { status: 'fail' as const, message: 'error', durationMs: 0 },
124
- pack: { status: 'pass' as const, message: '', durationMs: 0 },
125
- imports: { status: 'pass' as const, message: '', durationMs: 0, violations: [] },
126
- },
127
- warnings: [],
128
- errors: ['tsc: error'],
129
- };
130
- expect(result.exitCode).toBe(1);
131
- expect(result.status).toBe('block');
132
- });
133
- });
@@ -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
- });