@boyingliu01/xp-gate 0.38.76 → 0.38.77

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 (104) hide show
  1. package/lib/__tests__/mirror-sync.test.js +387 -5
  2. package/lib/mattpocock-license-verdict.json +1 -1
  3. package/lib/mirror-sync.js +202 -15
  4. package/package.json +1 -1
  5. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  6. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  7. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  8. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  9. package/plugins/dsh/package.json +1 -1
  10. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  11. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  12. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  13. package/plugins/opencode/package.json +1 -1
  14. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  15. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  16. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  17. package/plugins/qoder/plugin.json +1 -1
  18. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  19. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  20. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  21. package/scripts/generate-mirrors.cjs +10 -0
  22. package/skills/delphi-review/AGENTS.md +1 -1
  23. package/skills/sprint-flow/AGENTS.md +1 -1
  24. package/skills/test-specification-alignment/AGENTS.md +1 -1
  25. package/mock-policy/__tests__/config.test.ts +0 -292
  26. package/mock-policy/__tests__/gate-m3.test.ts +0 -379
  27. package/mock-policy/__tests__/integration.test.ts +0 -600
  28. package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
  29. package/mock-policy/__tests__/schema.test.ts +0 -239
  30. package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
  31. package/mutation/__tests__/detect-ai-test.test.ts +0 -152
  32. package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
  33. package/mutation/__tests__/gate-m.test.ts +0 -246
  34. package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
  35. package/mutation/__tests__/gremlins-runner.test.ts +0 -167
  36. package/mutation/__tests__/init-baseline.test.ts +0 -347
  37. package/mutation/__tests__/mutation-mirror.test.ts +0 -49
  38. package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
  39. package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
  40. package/mutation/__tests__/pitest-runner.test.ts +0 -574
  41. package/mutation/__tests__/runners-index.test.ts +0 -162
  42. package/mutation/__tests__/stryker-runner.test.ts +0 -455
  43. package/mutation/__tests__/test-filter-parity.test.ts +0 -40
  44. package/mutation/__tests__/update-baseline.test.ts +0 -395
  45. package/principles/__tests__/adapter-metrics.test.ts +0 -292
  46. package/principles/__tests__/analyze-read-failure.test.ts +0 -70
  47. package/principles/__tests__/analyzer.test.ts +0 -367
  48. package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
  49. package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
  50. package/principles/__tests__/baseline-prune.test.ts +0 -399
  51. package/principles/__tests__/baseline-storage.test.ts +0 -188
  52. package/principles/__tests__/baseline.test.ts +0 -330
  53. package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
  54. package/principles/__tests__/boy-scout-integration.test.ts +0 -355
  55. package/principles/__tests__/boy-scout.test.ts +0 -893
  56. package/principles/__tests__/cli-files-separators.test.ts +0 -69
  57. package/principles/__tests__/config-arch-group.test.ts +0 -106
  58. package/principles/__tests__/config-enforcement.test.ts +0 -470
  59. package/principles/__tests__/config-git-timeout.test.ts +0 -66
  60. package/principles/__tests__/config-merge-warnings.test.ts +0 -148
  61. package/principles/__tests__/config.test.ts +0 -78
  62. package/principles/__tests__/direct-execution.test.ts +0 -187
  63. package/principles/__tests__/index.test.ts +0 -94
  64. package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
  65. package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
  66. package/principles/__tests__/lint-baseline.test.ts +0 -314
  67. package/principles/__tests__/many-exports-reexport.test.ts +0 -40
  68. package/principles/__tests__/reporter.test.ts +0 -660
  69. package/principles/__tests__/types.test.ts +0 -103
  70. package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
  71. package/principles/adapters/__tests__/base.test.ts +0 -95
  72. package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
  73. package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
  74. package/principles/adapters/__tests__/cpp.test.ts +0 -290
  75. package/principles/adapters/__tests__/dart.test.ts +0 -84
  76. package/principles/adapters/__tests__/go.test.ts +0 -68
  77. package/principles/adapters/__tests__/java.test.ts +0 -385
  78. package/principles/adapters/__tests__/kotlin.test.ts +0 -76
  79. package/principles/adapters/__tests__/objectivec.test.ts +0 -453
  80. package/principles/adapters/__tests__/python.test.ts +0 -84
  81. package/principles/adapters/__tests__/swift.test.ts +0 -68
  82. package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
  83. package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
  84. package/principles/adapters/__tests__/typescript.test.ts +0 -116
  85. package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
  86. package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
  87. package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
  88. package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
  89. package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
  90. package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
  91. package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
  92. package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
  93. package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
  94. package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
  95. package/principles/rules/__tests__/index.test.ts +0 -49
  96. package/principles/rules/__tests__/solid/dip.test.ts +0 -119
  97. package/principles/rules/__tests__/solid/isp.test.ts +0 -58
  98. package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
  99. package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
  100. package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
  101. package/principles/rules/__tests__/solid/srp.test.ts +0 -87
  102. package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
  103. package/principles/rules/arch/__tests__/naming.test.ts +0 -133
  104. package/principles/rules/arch/__tests__/shared.test.ts +0 -113
@@ -1,355 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { exec } from 'child_process';
3
- import { promisify } from 'util';
4
- import * as path from 'path';
5
- import { tmpdir } from 'os';
6
- import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
7
-
8
- const execAsync = promisify(exec);
9
-
10
- vi.mock('fs/promises', async (importOriginal) => {
11
- const actual = await importOriginal<typeof import('fs/promises')>();
12
- return {
13
- ...actual,
14
- readFile: vi.fn(),
15
- access: vi.fn(),
16
- writeFile: vi.fn(),
17
- };
18
- });
19
-
20
- vi.mock('../analyzer', () => ({
21
- analyze: vi.fn(),
22
- getAdapterForFile: vi.fn(),
23
- }));
24
-
25
- vi.mock('../index', () => ({
26
- getAllRules: vi.fn(() => []),
27
- }));
28
-
29
- import { readFile, access, writeFile } from 'fs/promises';
30
- import {
31
- classifyFiles,
32
- calculateDelta,
33
- runEnforcement,
34
- } from '../boy-scout';
35
- import { analyze } from '../analyzer';
36
-
37
- const mockAnalyze = vi.mocked(analyze);
38
- const mockReadFile = vi.mocked(readFile);
39
- const mockAccess = vi.mocked(access);
40
- const mockWriteFile = vi.mocked(writeFile);
41
-
42
- interface BaselineEntry {
43
- totalWarnings: number;
44
- lastAnalyzed: string;
45
- }
46
-
47
- type AnalysisResult = Awaited<ReturnType<typeof analyze>>;
48
-
49
- const emptyAnalysis = (): AnalysisResult => ({ violations: [] } as unknown as AnalysisResult);
50
-
51
- function fakeAnalysis(violations: Partial<AnalysisResult['violations']>[number][]): AnalysisResult {
52
- return { violations: violations as unknown as AnalysisResult['violations'] } as unknown as AnalysisResult;
53
- }
54
-
55
- beforeEach(() => {
56
- vi.clearAllMocks();
57
- });
58
-
59
- /**
60
- * @test REQ-59 Boy Scout Rule integration tests
61
- * @intent Verify runEnforcement, CLI integration, and edge cases for Boy Scout Rule
62
- * @covers AC-59-01
63
- */
64
- describe('Boy Scout Rule - runEnforcement', () => {
65
- it('passes when new files have zero warnings and modified files are clean', async () => {
66
- mockAnalyze.mockResolvedValue(emptyAnalysis());
67
- mockAccess.mockResolvedValue(undefined);
68
- mockReadFile.mockResolvedValue(
69
- JSON.stringify({ 'src/modified.ts': { totalWarnings: 3, lastAnalyzed: '2024-01-01' } })
70
- );
71
- mockWriteFile.mockResolvedValue(undefined);
72
-
73
- const result = await runEnforcement(['src/new.ts'], ['src/modified.ts'], '/tmp/test-baseline.json');
74
-
75
- expect(result.overallStatus).toBe('PASS');
76
- expect(result.summary.totalFiles).toBe(2);
77
- });
78
-
79
- it('blocks when new files have warnings', async () => {
80
- mockAnalyze.mockResolvedValue(
81
- fakeAnalysis([{ file: 'src/new.ts', line: 1, ruleId: 'test', severity: 'warning' as const, message: 'm' }])
82
- );
83
- mockAccess.mockRejectedValue(new Error('ENOENT'));
84
- mockWriteFile.mockResolvedValue(undefined);
85
-
86
- const result = await runEnforcement(['src/new.ts'], [], '/tmp/test-baseline.json');
87
-
88
- expect(result.overallStatus).toBe('BLOCK');
89
- expect(result.summary.blockedFiles).toBe(1);
90
- });
91
-
92
- it('blocks when modified files increase warnings', async () => {
93
- mockAnalyze.mockResolvedValue(
94
- fakeAnalysis([
95
- { file: 'src/modified.ts', line: 1, ruleId: 'test', severity: 'warning' as const, message: 'm' },
96
- { file: 'src/modified.ts', line: 2, ruleId: 'test', severity: 'warning' as const, message: 'm' },
97
- { file: 'src/modified.ts', line: 3, ruleId: 'test', severity: 'warning' as const, message: 'm' },
98
- ])
99
- );
100
- mockAccess.mockResolvedValue(undefined);
101
- mockReadFile.mockResolvedValue(
102
- JSON.stringify({ 'src/modified.ts': { totalWarnings: 1, lastAnalyzed: '2024-01-01' } })
103
- );
104
- mockWriteFile.mockResolvedValue(undefined);
105
-
106
- const result = await runEnforcement([], ['src/modified.ts'], '/tmp/test-baseline.json');
107
- expect(result.overallStatus).toBe('BLOCK');
108
- expect(result.violations[0].reason).toContain('cannot increase warnings');
109
- });
110
-
111
- it('auto-initializes missing baseline entries for modified files', async () => {
112
- mockAnalyze.mockResolvedValue(emptyAnalysis());
113
- mockAccess.mockResolvedValue(undefined);
114
- mockReadFile.mockResolvedValue('{}');
115
- mockWriteFile.mockResolvedValue(undefined);
116
-
117
- const result = await runEnforcement([], ['src/modified.ts'], '/tmp/test-baseline.json');
118
- expect(mockWriteFile).toHaveBeenCalled();
119
- expect(result.overallStatus).toBe('PASS');
120
- });
121
-
122
- it('handles empty newFiles and modifiedFiles arrays', async () => {
123
- mockAnalyze.mockResolvedValue(emptyAnalysis());
124
- mockAccess.mockRejectedValue(new Error('ENOENT'));
125
-
126
- const result = await runEnforcement([], [], '/tmp/test-baseline.json');
127
- expect(result.overallStatus).toBe('PASS');
128
- expect(result.summary.totalFiles).toBe(0);
129
- });
130
-
131
- it('filters out empty strings from file arrays', async () => {
132
- mockAnalyze.mockResolvedValue(emptyAnalysis());
133
- mockAccess.mockRejectedValue(new Error('ENOENT'));
134
-
135
- const result = await runEnforcement(['', ' ', ''], ['', ' '], '/tmp/test.json');
136
- expect(result.overallStatus).toBe('PASS');
137
- });
138
-
139
- it('auto-init saves updated baseline when missing entries exist', async () => {
140
- mockAnalyze.mockResolvedValue(
141
- fakeAnalysis([{ file: 'src/a.ts', line: 1, ruleId: 'test', severity: 'warning' as const, message: 'm' }])
142
- );
143
- mockAccess.mockResolvedValue(undefined);
144
- mockReadFile.mockResolvedValue(JSON.stringify({}));
145
- mockWriteFile.mockResolvedValue(undefined);
146
-
147
- await runEnforcement([], ['src/a.ts'], '/tmp/test-baseline.json');
148
- expect(mockWriteFile).toHaveBeenCalled();
149
- expect(vi.mocked(mockWriteFile).mock.calls[0][0]).toBe('/tmp/test-baseline.json');
150
- });
151
-
152
- // #452: the auto-init path inside runEnforcement once wrote only the current
153
- // commit's files, silently dropping entries for untouched files -- which then
154
- // made Gate 6 BLOCK files the commit never touched. The explicit
155
- // init-baseline command got merge semantics (#445); these tests pin the same
156
- // guarantee on the automatic path.
157
- it('REQ-452: auto-init preserves entries for files not in the current commit', async () => {
158
- // 6 warnings so the entry survives the "small baselines must clear" rule;
159
- // a clean file gains no entry by design (nothing to budget).
160
- const warnings = Array.from({ length: 6 }, (_, i) => ({
161
- file: 'plugins/dsh/src/command.ts', line: i + 1, ruleId: 'test', severity: 'warning' as const, message: 'm',
162
- }));
163
- mockAnalyze.mockResolvedValue(fakeAnalysis(warnings));
164
- mockAccess.mockResolvedValue(undefined);
165
- mockReadFile.mockResolvedValue(
166
- JSON.stringify({ 'src/npm-package/lib/test-alignment.ts': { totalWarnings: 1, lastAnalyzed: '2024-01-01' } })
167
- );
168
- mockWriteFile.mockResolvedValue(undefined);
169
-
170
- const result = await runEnforcement([], ['plugins/dsh/src/command.ts'], '/tmp/test-baseline.json');
171
-
172
- expect(result.overallStatus).toBe('PASS');
173
- expect(mockWriteFile).toHaveBeenCalled();
174
- const saved = JSON.parse(vi.mocked(mockWriteFile).mock.calls[0][1] as string) as Record<string, BaselineEntry>;
175
- expect(saved['src/npm-package/lib/test-alignment.ts']).toEqual({ totalWarnings: 1, lastAnalyzed: '2024-01-01' });
176
- expect(saved['plugins/dsh/src/command.ts']?.totalWarnings).toBe(6);
177
- });
178
-
179
- it('REQ-452: auto-init is idempotent -- a second run over the same files writes the same entries', async () => {
180
- mockAnalyze.mockResolvedValue(emptyAnalysis());
181
- mockAccess.mockResolvedValue(undefined);
182
- mockWriteFile.mockResolvedValue(undefined);
183
- const first = JSON.stringify({});
184
-
185
- mockReadFile.mockResolvedValue(first);
186
- await runEnforcement([], ['src/a.ts'], '/tmp/test-baseline.json');
187
- const savedOnce = vi.mocked(mockWriteFile).mock.calls.at(-1)![1] as string;
188
-
189
- mockReadFile.mockResolvedValue(savedOnce);
190
- mockWriteFile.mockClear();
191
- await runEnforcement([], ['src/a.ts'], '/tmp/test-baseline.json');
192
- const savedTwice = vi.mocked(mockWriteFile).mock.calls.at(-1)![1] as string;
193
-
194
- expect(JSON.parse(savedOnce)).toEqual(JSON.parse(savedTwice));
195
- });
196
-
197
- it('blocks modified file with <=5 baseline warnings that are not cleared', async () => {
198
- mockAnalyze.mockResolvedValue(
199
- fakeAnalysis([{ file: 'src/mod.ts', line: 1, ruleId: 'test', severity: 'warning' as const, message: 'm' }])
200
- );
201
- mockAccess.mockResolvedValue(undefined);
202
- mockReadFile.mockResolvedValue(
203
- JSON.stringify({ 'src/mod.ts': { totalWarnings: 3, lastAnalyzed: '2024-01-01' } })
204
- );
205
- mockWriteFile.mockResolvedValue(undefined);
206
-
207
- const result = await runEnforcement([], ['src/mod.ts'], '/tmp/test-baseline.json');
208
- expect(result.overallStatus).toBe('BLOCK');
209
- expect(result.violations[0].reason).toContain('must clear to zero');
210
- });
211
-
212
- it('enforcement passes when modified file clears all warnings', async () => {
213
- mockAnalyze.mockResolvedValue(emptyAnalysis());
214
- mockAccess.mockResolvedValue(undefined);
215
- mockReadFile.mockResolvedValue(
216
- JSON.stringify({ 'src/mod.ts': { totalWarnings: 3, lastAnalyzed: '2024-01-01' } })
217
- );
218
- mockWriteFile.mockResolvedValue(undefined);
219
-
220
- const result = await runEnforcement([], ['src/mod.ts'], '/tmp/test-baseline.json');
221
- expect(result.overallStatus).toBe('PASS');
222
- });
223
- });
224
-
225
- describe('calculateDelta reason messages', () => {
226
- it('returns "Warnings decreased" reason on decrease', () => {
227
- const result = calculateDelta({ totalWarnings: 10 } as BaselineEntry, 7, 'MODIFIED');
228
- expect(result.delta).toBe(-3);
229
- expect(result.enforcement).toBe('PASS');
230
- expect(result.reason).toContain('Warnings decreased by 3');
231
- });
232
-
233
- it('returns "All warnings cleared" reason when current is zero', () => {
234
- const result = calculateDelta({ totalWarnings: 0 } as BaselineEntry, 0, 'MODIFIED');
235
- expect(result.delta).toBe(0);
236
- expect(result.enforcement).toBe('PASS');
237
- expect(result.reason).toContain('All warnings cleared');
238
- });
239
-
240
- it('returns "No new warnings introduced" when same count and >5', () => {
241
- const result = calculateDelta({ totalWarnings: 8, lastAnalyzed: new Date().toISOString() } as BaselineEntry, 8, 'MODIFIED');
242
- expect(result.delta).toBe(0);
243
- expect(result.enforcement).toBe('PASS');
244
- expect(result.reason).toContain('No new warnings introduced');
245
- });
246
-
247
- it('sets correct file field in delta result', () => {
248
- const result = calculateDelta(null, 5, 'MODIFIED');
249
- result.file = 'src/test.ts';
250
- expect(result.file).toBe('src/test.ts');
251
- expect(result.status).toBe('MODIFIED');
252
- });
253
- });
254
-
255
- describe('classifyFiles edge cases', () => {
256
- it('ignores rename lines with insufficient parts', () => {
257
- const classified = classifyFiles(['R095']);
258
- expect(classified.renamed).toEqual([]);
259
- });
260
-
261
- it('ignores lines with less than 2 parts', () => {
262
- const classified = classifyFiles(['A']);
263
- expect(classified.new).toEqual([]);
264
- });
265
-
266
- it('handles unknown status codes gracefully', () => {
267
- const classified = classifyFiles(['X src/unknown.ts']);
268
- expect(classified.new).toEqual([]);
269
- expect(classified.renamed).toEqual([]);
270
- });
271
-
272
- it('handles files with spaces in paths for new files', () => {
273
- const classified = classifyFiles(['A src/my file.ts']);
274
- expect(classified.new).toEqual(['src/my file.ts']);
275
- });
276
- });
277
-
278
- describe('CLI integration', () => {
279
- const BOY_SCOUT_PATH = path.resolve(__dirname, '../boy-scout.ts');
280
- const CLI_TEST_TIMEOUT = 60000;
281
-
282
- it('shows help and exits with --help flag', async () => {
283
- const { stdout } = await execAsync(`npx tsx ${BOY_SCOUT_PATH} --help`, { timeout: 30000 });
284
- expect(stdout).toContain('Usage: boy-scout');
285
- expect(stdout).toContain('--new-files');
286
- }, CLI_TEST_TIMEOUT);
287
-
288
- it('shows help and exits with -h flag', async () => {
289
- const { stdout } = await execAsync(`npx tsx ${BOY_SCOUT_PATH} -h`, { timeout: 30000 });
290
- expect(stdout).toContain('Usage: boy-scout');
291
- }, CLI_TEST_TIMEOUT);
292
-
293
- it('shows help and exits with help command', async () => {
294
- const { stdout } = await execAsync(`npx tsx ${BOY_SCOUT_PATH} help`, { timeout: 30000 });
295
- expect(stdout).toContain('Usage: boy-scout');
296
- }, CLI_TEST_TIMEOUT);
297
-
298
- it('runs init-baseline via CLI against an isolated baseline', async () => {
299
- try {
300
- // Never point --baseline at the repo's tracked .warnings-baseline.json: this
301
- // test must not mutate tracked state. Use a throwaway path instead (#445).
302
- // NOTE: this file mocks 'fs/promises' (which also covers 'node:fs/promises'),
303
- // so use node:fs sync APIs -- they are not intercepted.
304
- const tmpBaseline = path.join(mkdtempSync(path.join(tmpdir(), 'bs-init-')), 'baseline.json');
305
- const { stdout } = await execAsync(
306
- `npx tsx ${BOY_SCOUT_PATH} --init-baseline src/principles/boy-scout.ts --baseline "${tmpBaseline}"`,
307
- { timeout: 30000 }
308
- );
309
- // The command now reports a merge summary instead of the old (misleading)
310
- // "Baseline initialized successfully" — it updates rather than replaces.
311
- expect(stdout).toContain('Baseline updated');
312
- expect(stdout).toContain(tmpBaseline);
313
- expect(typeof readFileSync(tmpBaseline, 'utf-8')).toBe('string');
314
- } catch (error) {
315
- throw error instanceof Error ? error : new Error(String(error));
316
- }
317
- }, CLI_TEST_TIMEOUT);
318
-
319
- /**
320
- * @test REQ-DSH-014
321
- * @intent 验证 CLI 的 --init-baseline 是合并语义:既有条目不因初始化无关文件而丢失
322
- * (#445 实测会把已跟踪基线摧毁成 {})
323
- * @covers AC-DSH-014-01
324
- */
325
- it('init-baseline preserves pre-existing entries (merge, not replace)', async () => {
326
- try {
327
- const dir = mkdtempSync(path.join(tmpdir(), 'bs-merge-'));
328
- const tmpBaseline = path.join(dir, 'baseline.json');
329
- writeFileSync(
330
- tmpBaseline,
331
- JSON.stringify({
332
- 'src/legacy.ts': { totalWarnings: 3, lastAnalyzed: '2026-01-01T00:00:00.000Z' },
333
- }),
334
- 'utf-8'
335
- );
336
-
337
- await execAsync(
338
- `npx tsx ${BOY_SCOUT_PATH} --init-baseline src/principles/boy-scout.ts --baseline "${tmpBaseline}"`,
339
- { timeout: 30000 }
340
- );
341
-
342
- const written = JSON.parse(readFileSync(tmpBaseline, 'utf-8'));
343
- expect(written['src/legacy.ts']).toBeDefined();
344
- expect(written['src/legacy.ts'].totalWarnings).toBe(3);
345
- } catch (error) {
346
- throw error instanceof Error ? error : new Error(String(error));
347
- }
348
- }, CLI_TEST_TIMEOUT);
349
-
350
- it('runs enforcement via CLI with empty files', async () => {
351
- await expect(
352
- execAsync(`npx tsx ${BOY_SCOUT_PATH} --new-files "" --modified-files ""`, { timeout: 30000 })
353
- ).resolves.toMatchObject({ stdout: expect.stringContaining('"overallStatus"') });
354
- }, CLI_TEST_TIMEOUT);
355
- });