@boyingliu01/xp-gate 0.15.4 → 0.15.5

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 (72) hide show
  1. package/adapter-common.sh +0 -0
  2. package/adapters/cpp.sh +0 -0
  3. package/adapters/dart.sh +0 -0
  4. package/adapters/flutter.sh +0 -0
  5. package/adapters/gate-3.sh +68 -0
  6. package/adapters/gate-4.sh +80 -0
  7. package/adapters/gate-7.sh +45 -0
  8. package/adapters/gate-8.sh +56 -0
  9. package/adapters/gate-9.sh +104 -0
  10. package/adapters/go.sh +0 -0
  11. package/adapters/iac.sh +0 -0
  12. package/adapters/java.sh +0 -0
  13. package/adapters/kotlin.sh +0 -0
  14. package/adapters/objectivec.sh +0 -0
  15. package/adapters/plugins/book299-20132-python/scripts/install-gradle.sh +0 -0
  16. package/adapters/plugins/book299-20132-python/scripts/install-maven.sh +0 -0
  17. package/adapters/plugins/book299-4081-c/scripts/install-gradle.sh +0 -0
  18. package/adapters/plugins/book299-4081-c/scripts/install-maven.sh +0 -0
  19. package/adapters/plugins/book299-4083-javascriptes5/scripts/install-gradle.sh +0 -0
  20. package/adapters/plugins/book299-4083-javascriptes5/scripts/install-maven.sh +0 -0
  21. package/adapters/powershell.sh +0 -0
  22. package/adapters/python.sh +0 -0
  23. package/adapters/shell.sh +0 -0
  24. package/adapters/swift.sh +0 -0
  25. package/adapters/typescript.sh +0 -0
  26. package/bin/xp-gate.js +0 -0
  27. package/gate-3.sh +0 -0
  28. package/gate-4.sh +0 -0
  29. package/gate-7.sh +0 -0
  30. package/gate-8.sh +0 -0
  31. package/gate-9.sh +0 -0
  32. package/hooks/adapter-common.sh +0 -0
  33. package/hooks/gate-3.sh +0 -0
  34. package/hooks/gate-4.sh +0 -0
  35. package/hooks/gate-7.sh +0 -0
  36. package/hooks/gate-8.sh +0 -0
  37. package/hooks/gate-9.sh +0 -0
  38. package/hooks/pre-commit +0 -0
  39. package/hooks/pre-push +0 -0
  40. package/lib/__tests__/phase-transition.test.js +272 -272
  41. package/lib/__tests__/sprint-audit.test.js +207 -207
  42. package/lib/doctor-tui.js +198 -198
  43. package/lib/language-tools.js +833 -833
  44. package/lib/phase-transition.js +249 -249
  45. package/lib/sprint-audit.js +235 -235
  46. package/mock-policy/AGENTS.md +2 -2
  47. package/mutation/AGENTS.md +2 -2
  48. package/package.json +1 -1
  49. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  50. package/plugins/claude-code/bin/delphi-review-guard.sh +0 -0
  51. package/plugins/claude-code/bin/xp-gate-check +0 -0
  52. package/plugins/claude-code/skills/delphi-review/AGENTS.md +2 -2
  53. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +2 -2
  54. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +2 -2
  55. package/plugins/opencode/package.json +1 -1
  56. package/plugins/opencode/skills/delphi-review/AGENTS.md +2 -2
  57. package/plugins/opencode/skills/sprint-flow/AGENTS.md +2 -2
  58. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +2 -2
  59. package/plugins/qoder/agents/delphi-architecture.md +48 -48
  60. package/plugins/qoder/agents/delphi-feasibility.md +48 -48
  61. package/plugins/qoder/agents/delphi-technical.md +48 -48
  62. package/plugins/qoder/bin/sprint-flow-guard.sh +0 -0
  63. package/plugins/qoder/bin/xp-gate-check +0 -0
  64. package/plugins/qoder/plugin.json +1 -1
  65. package/plugins/qoder/skills/delphi-review/AGENTS.md +2 -2
  66. package/plugins/qoder/skills/sprint-flow/AGENTS.md +2 -2
  67. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +2 -2
  68. package/principles/AGENTS.md +2 -2
  69. package/scripts/delphi-external-review.cjs +432 -432
  70. package/skills/delphi-review/AGENTS.md +2 -2
  71. package/skills/sprint-flow/AGENTS.md +2 -2
  72. package/skills/test-specification-alignment/AGENTS.md +2 -2
@@ -1,207 +1,207 @@
1
- /**
2
- * Tests for sprint-audit CLI command (Layer 2)
3
- * @test REQ-338 Sprint audit — final completeness check
4
- * @intent Verify sprint-audit correctly checks phase coverage, artifacts, consistency
5
- * @covers AC-AUDIT-01 (SKIP when no sprint-state.json)
6
- * @covers AC-AUDIT-02 (PASS when 6/6 completed)
7
- * @covers AC-AUDIT-03 (PASS_WITH_WARNINGS when 4-5/6 completed)
8
- * @covers AC-AUDIT-04 (FAIL when <4/6 completed)
9
- * @covers AC-AUDIT-05 (FAIL on state inconsistency)
10
- * @covers AC-AUDIT-06 (--json flag outputs JSON)
11
- * @covers AC-AUDIT-07 (report persisted to audit-report.json)
12
- */
13
-
14
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
15
- import fs from 'node:fs';
16
- import path from 'node:path';
17
- import os from 'node:os';
18
- import { handleSprintAudit } from '../sprint-audit.js';
19
-
20
- describe('sprint-audit', () => {
21
- let tmpDir;
22
-
23
- beforeEach(() => {
24
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sprint-audit-test-'));
25
- });
26
-
27
- afterEach(() => {
28
- fs.rmSync(tmpDir, { recursive: true, force: true });
29
- });
30
-
31
- function writeState(state) {
32
- const stateDir = path.join(tmpDir, '.sprint-state');
33
- fs.mkdirSync(stateDir, { recursive: true });
34
- fs.writeFileSync(path.join(stateDir, 'sprint-state.json'), JSON.stringify(state));
35
- }
36
-
37
- function makeState(overrides = {}) {
38
- return {
39
- _schema_version: 1,
40
- id: 'sprint-test-audit',
41
- task_description: 'Test audit feature',
42
- phase: 6,
43
- status: 'completed',
44
- started_at: '2026-07-22T10:00:00Z',
45
- phase_history: [],
46
- isolation: { branch: 'sprint/test-audit', worktree_path: null },
47
- outputs: {},
48
- ...overrides,
49
- };
50
- }
51
-
52
- function makePhaseHistory(completedPhases) {
53
- const phaseNames = ['PREP', 'DESIGN', 'BUILD', 'VERIFY', 'SHIP', 'CLOSE'];
54
- return completedPhases.map((p, i) => ({
55
- phase: p,
56
- phase_name: phaseNames[p - 1],
57
- status: 'completed',
58
- started_at: `2026-07-22T10:${String(i).padStart(2, '0')}:00Z`,
59
- completed_at: `2026-07-22T10:${String(i).padStart(2, '0')}:30Z`,
60
- duration_seconds: 30,
61
- }));
62
- }
63
-
64
- describe('handleSprintAudit()', () => {
65
- it('returns 0 and shows help with --help', async () => {
66
- const code = await handleSprintAudit(['--help']);
67
- expect(code).toBe(0);
68
- });
69
-
70
- it('returns SKIP (exit 0) when no sprint-state.json exists', async () => {
71
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
72
- const code = await handleSprintAudit(['--dir', tmpDir]);
73
- expect(code).toBe(0);
74
- expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('No sprint-state.json'));
75
- logSpy.mockRestore();
76
- });
77
-
78
- it('returns PASS when 6/6 phases completed', async () => {
79
- writeState(makeState({ phase_history: makePhaseHistory([1, 2, 3, 4, 5, 6]) }));
80
-
81
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
82
- const code = await handleSprintAudit(['--dir', tmpDir]);
83
- expect(code).toBe(0);
84
- // Check output contains PASS
85
- const output = logSpy.mock.calls.map(c => c[0]).join('\n');
86
- expect(output).toContain('PASS');
87
- expect(output).toContain('6/6');
88
- logSpy.mockRestore();
89
- });
90
-
91
- it('returns PASS_WITH_WARNINGS when 5/6 completed', async () => {
92
- writeState(makeState({ phase: 5, phase_history: makePhaseHistory([1, 2, 3, 4, 5]) }));
93
-
94
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
95
- const code = await handleSprintAudit(['--dir', tmpDir]);
96
- expect(code).toBe(0);
97
- const output = logSpy.mock.calls.map(c => c[0]).join('\n');
98
- expect(output).toContain('PASS_WITH_WARNINGS');
99
- logSpy.mockRestore();
100
- });
101
-
102
- it('returns PASS_WITH_WARNINGS when 4/6 completed', async () => {
103
- writeState(makeState({ phase: 4, phase_history: makePhaseHistory([1, 2, 3, 4]) }));
104
-
105
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
106
- const code = await handleSprintAudit(['--dir', tmpDir]);
107
- expect(code).toBe(0);
108
- const output = logSpy.mock.calls.map(c => c[0]).join('\n');
109
- expect(output).toContain('PASS_WITH_WARNINGS');
110
- logSpy.mockRestore();
111
- });
112
-
113
- it('returns FAIL when <4/6 completed', async () => {
114
- writeState(makeState({ phase: 3, phase_history: makePhaseHistory([1, 2, 3]) }));
115
-
116
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
117
- const code = await handleSprintAudit(['--dir', tmpDir]);
118
- expect(code).toBe(1);
119
- const output = logSpy.mock.calls.map(c => c[0]).join('\n');
120
- expect(output).toContain('FAIL');
121
- logSpy.mockRestore();
122
- });
123
-
124
- it('returns FAIL on state inconsistency (phase vs phase_history)', async () => {
125
- const history = makePhaseHistory([1, 2, 3, 4, 5, 6]);
126
- writeState(makeState({ phase: 3, phase_history: history })); // phase=3 but last entry is 6
127
-
128
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
129
- const code = await handleSprintAudit(['--dir', tmpDir]);
130
- expect(code).toBe(1);
131
- const output = logSpy.mock.calls.map(c => c[0]).join('\n');
132
- expect(output).toContain('State inconsistency');
133
- logSpy.mockRestore();
134
- });
135
-
136
- it('outputs JSON when --json flag is set', async () => {
137
- writeState(makeState({ phase_history: makePhaseHistory([1, 2, 3, 4, 5, 6]) }));
138
-
139
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
140
- const code = await handleSprintAudit(['--dir', tmpDir, '--json']);
141
- expect(code).toBe(0);
142
- const output = logSpy.mock.calls.map(c => c[0]).join('\n');
143
- const result = JSON.parse(output);
144
- expect(result.verdict).toBe('PASS');
145
- expect(result.coverage.completed).toBe(6);
146
- logSpy.mockRestore();
147
- });
148
-
149
- it('counts skipped phases as completed in coverage', async () => {
150
- const history = makePhaseHistory([1, 2, 3, 4, 5]);
151
- history.push({
152
- phase: 6, phase_name: 'CLOSE', status: 'skipped',
153
- started_at: '2026-07-22T10:05:00Z', completed_at: '2026-07-22T10:05:00Z', duration_seconds: 0,
154
- });
155
- writeState(makeState({ phase: 6, phase_history: history }));
156
-
157
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
158
- const code = await handleSprintAudit(['--dir', tmpDir, '--json']);
159
- expect(code).toBe(0);
160
- const output = logSpy.mock.calls.map(c => c[0]).join('\n');
161
- const result = JSON.parse(output);
162
- expect(result.coverage.completed).toBe(6);
163
- expect(result.verdict).toBe('PASS');
164
- logSpy.mockRestore();
165
- });
166
-
167
- it('warns about missing summary files for completed phases', async () => {
168
- writeState(makeState({ phase_history: makePhaseHistory([1, 2, 3, 4, 5, 6]) }));
169
- // No phase-outputs directory → all summaries missing
170
-
171
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
172
- const code = await handleSprintAudit(['--dir', tmpDir, '--json']);
173
- expect(code).toBe(0);
174
- const output = logSpy.mock.calls.map(c => c[0]).join('\n');
175
- const result = JSON.parse(output);
176
- expect(result.warnings.length).toBeGreaterThan(0);
177
- expect(result.warnings.some(w => w.includes('summary missing'))).toBe(true);
178
- logSpy.mockRestore();
179
- });
180
-
181
- it('persists audit report to audit-report.json', async () => {
182
- writeState(makeState({ phase_history: makePhaseHistory([1, 2, 3, 4, 5, 6]) }));
183
-
184
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
185
- await handleSprintAudit(['--dir', tmpDir]);
186
- logSpy.mockRestore();
187
-
188
- const reportPath = path.join(tmpDir, '.sprint-state', 'audit-report.json');
189
- expect(fs.existsSync(reportPath)).toBe(true);
190
- const report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
191
- expect(report.verdict).toBe('PASS');
192
- expect(report.sprint_id).toBe('sprint-test-audit');
193
- });
194
-
195
- it('handles corrupted sprint-state.json gracefully', async () => {
196
- const stateDir = path.join(tmpDir, '.sprint-state');
197
- fs.mkdirSync(stateDir, { recursive: true });
198
- fs.writeFileSync(path.join(stateDir, 'sprint-state.json'), 'not-valid-json');
199
-
200
- const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
201
- const code = await handleSprintAudit(['--dir', tmpDir]);
202
- expect(code).toBe(1);
203
- expect(errSpy).toHaveBeenCalledWith(expect.stringContaining('Failed to parse'));
204
- errSpy.mockRestore();
205
- });
206
- });
207
- });
1
+ /**
2
+ * Tests for sprint-audit CLI command (Layer 2)
3
+ * @test REQ-338 Sprint audit — final completeness check
4
+ * @intent Verify sprint-audit correctly checks phase coverage, artifacts, consistency
5
+ * @covers AC-AUDIT-01 (SKIP when no sprint-state.json)
6
+ * @covers AC-AUDIT-02 (PASS when 6/6 completed)
7
+ * @covers AC-AUDIT-03 (PASS_WITH_WARNINGS when 4-5/6 completed)
8
+ * @covers AC-AUDIT-04 (FAIL when <4/6 completed)
9
+ * @covers AC-AUDIT-05 (FAIL on state inconsistency)
10
+ * @covers AC-AUDIT-06 (--json flag outputs JSON)
11
+ * @covers AC-AUDIT-07 (report persisted to audit-report.json)
12
+ */
13
+
14
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
15
+ import fs from 'node:fs';
16
+ import path from 'node:path';
17
+ import os from 'node:os';
18
+ import { handleSprintAudit } from '../sprint-audit.js';
19
+
20
+ describe('sprint-audit', () => {
21
+ let tmpDir;
22
+
23
+ beforeEach(() => {
24
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sprint-audit-test-'));
25
+ });
26
+
27
+ afterEach(() => {
28
+ fs.rmSync(tmpDir, { recursive: true, force: true });
29
+ });
30
+
31
+ function writeState(state) {
32
+ const stateDir = path.join(tmpDir, '.sprint-state');
33
+ fs.mkdirSync(stateDir, { recursive: true });
34
+ fs.writeFileSync(path.join(stateDir, 'sprint-state.json'), JSON.stringify(state));
35
+ }
36
+
37
+ function makeState(overrides = {}) {
38
+ return {
39
+ _schema_version: 1,
40
+ id: 'sprint-test-audit',
41
+ task_description: 'Test audit feature',
42
+ phase: 6,
43
+ status: 'completed',
44
+ started_at: '2026-07-22T10:00:00Z',
45
+ phase_history: [],
46
+ isolation: { branch: 'sprint/test-audit', worktree_path: null },
47
+ outputs: {},
48
+ ...overrides,
49
+ };
50
+ }
51
+
52
+ function makePhaseHistory(completedPhases) {
53
+ const phaseNames = ['PREP', 'DESIGN', 'BUILD', 'VERIFY', 'SHIP', 'CLOSE'];
54
+ return completedPhases.map((p, i) => ({
55
+ phase: p,
56
+ phase_name: phaseNames[p - 1],
57
+ status: 'completed',
58
+ started_at: `2026-07-22T10:${String(i).padStart(2, '0')}:00Z`,
59
+ completed_at: `2026-07-22T10:${String(i).padStart(2, '0')}:30Z`,
60
+ duration_seconds: 30,
61
+ }));
62
+ }
63
+
64
+ describe('handleSprintAudit()', () => {
65
+ it('returns 0 and shows help with --help', async () => {
66
+ const code = await handleSprintAudit(['--help']);
67
+ expect(code).toBe(0);
68
+ });
69
+
70
+ it('returns SKIP (exit 0) when no sprint-state.json exists', async () => {
71
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
72
+ const code = await handleSprintAudit(['--dir', tmpDir]);
73
+ expect(code).toBe(0);
74
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('No sprint-state.json'));
75
+ logSpy.mockRestore();
76
+ });
77
+
78
+ it('returns PASS when 6/6 phases completed', async () => {
79
+ writeState(makeState({ phase_history: makePhaseHistory([1, 2, 3, 4, 5, 6]) }));
80
+
81
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
82
+ const code = await handleSprintAudit(['--dir', tmpDir]);
83
+ expect(code).toBe(0);
84
+ // Check output contains PASS
85
+ const output = logSpy.mock.calls.map(c => c[0]).join('\n');
86
+ expect(output).toContain('PASS');
87
+ expect(output).toContain('6/6');
88
+ logSpy.mockRestore();
89
+ });
90
+
91
+ it('returns PASS_WITH_WARNINGS when 5/6 completed', async () => {
92
+ writeState(makeState({ phase: 5, phase_history: makePhaseHistory([1, 2, 3, 4, 5]) }));
93
+
94
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
95
+ const code = await handleSprintAudit(['--dir', tmpDir]);
96
+ expect(code).toBe(0);
97
+ const output = logSpy.mock.calls.map(c => c[0]).join('\n');
98
+ expect(output).toContain('PASS_WITH_WARNINGS');
99
+ logSpy.mockRestore();
100
+ });
101
+
102
+ it('returns PASS_WITH_WARNINGS when 4/6 completed', async () => {
103
+ writeState(makeState({ phase: 4, phase_history: makePhaseHistory([1, 2, 3, 4]) }));
104
+
105
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
106
+ const code = await handleSprintAudit(['--dir', tmpDir]);
107
+ expect(code).toBe(0);
108
+ const output = logSpy.mock.calls.map(c => c[0]).join('\n');
109
+ expect(output).toContain('PASS_WITH_WARNINGS');
110
+ logSpy.mockRestore();
111
+ });
112
+
113
+ it('returns FAIL when <4/6 completed', async () => {
114
+ writeState(makeState({ phase: 3, phase_history: makePhaseHistory([1, 2, 3]) }));
115
+
116
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
117
+ const code = await handleSprintAudit(['--dir', tmpDir]);
118
+ expect(code).toBe(1);
119
+ const output = logSpy.mock.calls.map(c => c[0]).join('\n');
120
+ expect(output).toContain('FAIL');
121
+ logSpy.mockRestore();
122
+ });
123
+
124
+ it('returns FAIL on state inconsistency (phase vs phase_history)', async () => {
125
+ const history = makePhaseHistory([1, 2, 3, 4, 5, 6]);
126
+ writeState(makeState({ phase: 3, phase_history: history })); // phase=3 but last entry is 6
127
+
128
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
129
+ const code = await handleSprintAudit(['--dir', tmpDir]);
130
+ expect(code).toBe(1);
131
+ const output = logSpy.mock.calls.map(c => c[0]).join('\n');
132
+ expect(output).toContain('State inconsistency');
133
+ logSpy.mockRestore();
134
+ });
135
+
136
+ it('outputs JSON when --json flag is set', async () => {
137
+ writeState(makeState({ phase_history: makePhaseHistory([1, 2, 3, 4, 5, 6]) }));
138
+
139
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
140
+ const code = await handleSprintAudit(['--dir', tmpDir, '--json']);
141
+ expect(code).toBe(0);
142
+ const output = logSpy.mock.calls.map(c => c[0]).join('\n');
143
+ const result = JSON.parse(output);
144
+ expect(result.verdict).toBe('PASS');
145
+ expect(result.coverage.completed).toBe(6);
146
+ logSpy.mockRestore();
147
+ });
148
+
149
+ it('counts skipped phases as completed in coverage', async () => {
150
+ const history = makePhaseHistory([1, 2, 3, 4, 5]);
151
+ history.push({
152
+ phase: 6, phase_name: 'CLOSE', status: 'skipped',
153
+ started_at: '2026-07-22T10:05:00Z', completed_at: '2026-07-22T10:05:00Z', duration_seconds: 0,
154
+ });
155
+ writeState(makeState({ phase: 6, phase_history: history }));
156
+
157
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
158
+ const code = await handleSprintAudit(['--dir', tmpDir, '--json']);
159
+ expect(code).toBe(0);
160
+ const output = logSpy.mock.calls.map(c => c[0]).join('\n');
161
+ const result = JSON.parse(output);
162
+ expect(result.coverage.completed).toBe(6);
163
+ expect(result.verdict).toBe('PASS');
164
+ logSpy.mockRestore();
165
+ });
166
+
167
+ it('warns about missing summary files for completed phases', async () => {
168
+ writeState(makeState({ phase_history: makePhaseHistory([1, 2, 3, 4, 5, 6]) }));
169
+ // No phase-outputs directory → all summaries missing
170
+
171
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
172
+ const code = await handleSprintAudit(['--dir', tmpDir, '--json']);
173
+ expect(code).toBe(0);
174
+ const output = logSpy.mock.calls.map(c => c[0]).join('\n');
175
+ const result = JSON.parse(output);
176
+ expect(result.warnings.length).toBeGreaterThan(0);
177
+ expect(result.warnings.some(w => w.includes('summary missing'))).toBe(true);
178
+ logSpy.mockRestore();
179
+ });
180
+
181
+ it('persists audit report to audit-report.json', async () => {
182
+ writeState(makeState({ phase_history: makePhaseHistory([1, 2, 3, 4, 5, 6]) }));
183
+
184
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
185
+ await handleSprintAudit(['--dir', tmpDir]);
186
+ logSpy.mockRestore();
187
+
188
+ const reportPath = path.join(tmpDir, '.sprint-state', 'audit-report.json');
189
+ expect(fs.existsSync(reportPath)).toBe(true);
190
+ const report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
191
+ expect(report.verdict).toBe('PASS');
192
+ expect(report.sprint_id).toBe('sprint-test-audit');
193
+ });
194
+
195
+ it('handles corrupted sprint-state.json gracefully', async () => {
196
+ const stateDir = path.join(tmpDir, '.sprint-state');
197
+ fs.mkdirSync(stateDir, { recursive: true });
198
+ fs.writeFileSync(path.join(stateDir, 'sprint-state.json'), 'not-valid-json');
199
+
200
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
201
+ const code = await handleSprintAudit(['--dir', tmpDir]);
202
+ expect(code).toBe(1);
203
+ expect(errSpy).toHaveBeenCalledWith(expect.stringContaining('Failed to parse'));
204
+ errSpy.mockRestore();
205
+ });
206
+ });
207
+ });