@boyingliu01/xp-gate 0.38.76 → 0.38.78
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.
- package/lib/__tests__/gate2-verdict.test.js +58 -1
- package/lib/__tests__/mirror-sync.test.js +387 -5
- package/lib/gate-runner.js +88 -9
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/mirror-sync.js +202 -15
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/references/phase-2-design.md +62 -2
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/references/phase-2-design.md +62 -2
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/references/phase-2-design.md +62 -2
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/references/phase-2-design.md +62 -2
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/scripts/generate-mirrors.cjs +10 -0
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/sprint-flow/references/phase-2-design.md +62 -2
- package/skills/test-specification-alignment/AGENTS.md +1 -1
- package/mock-policy/__tests__/config.test.ts +0 -292
- package/mock-policy/__tests__/gate-m3.test.ts +0 -379
- package/mock-policy/__tests__/integration.test.ts +0 -600
- package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
- package/mock-policy/__tests__/schema.test.ts +0 -239
- package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
- package/mutation/__tests__/detect-ai-test.test.ts +0 -152
- package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
- package/mutation/__tests__/gate-m.test.ts +0 -246
- package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
- package/mutation/__tests__/gremlins-runner.test.ts +0 -167
- package/mutation/__tests__/init-baseline.test.ts +0 -347
- package/mutation/__tests__/mutation-mirror.test.ts +0 -49
- package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
- package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
- package/mutation/__tests__/pitest-runner.test.ts +0 -574
- package/mutation/__tests__/runners-index.test.ts +0 -162
- package/mutation/__tests__/stryker-runner.test.ts +0 -455
- package/mutation/__tests__/test-filter-parity.test.ts +0 -40
- package/mutation/__tests__/update-baseline.test.ts +0 -395
- package/principles/__tests__/adapter-metrics.test.ts +0 -292
- package/principles/__tests__/analyze-read-failure.test.ts +0 -70
- package/principles/__tests__/analyzer.test.ts +0 -367
- package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
- package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
- package/principles/__tests__/baseline-prune.test.ts +0 -399
- package/principles/__tests__/baseline-storage.test.ts +0 -188
- package/principles/__tests__/baseline.test.ts +0 -330
- package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
- package/principles/__tests__/boy-scout-integration.test.ts +0 -355
- package/principles/__tests__/boy-scout.test.ts +0 -893
- package/principles/__tests__/cli-files-separators.test.ts +0 -69
- package/principles/__tests__/config-arch-group.test.ts +0 -106
- package/principles/__tests__/config-enforcement.test.ts +0 -470
- package/principles/__tests__/config-git-timeout.test.ts +0 -66
- package/principles/__tests__/config-merge-warnings.test.ts +0 -148
- package/principles/__tests__/config.test.ts +0 -78
- package/principles/__tests__/direct-execution.test.ts +0 -187
- package/principles/__tests__/index.test.ts +0 -94
- package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
- package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
- package/principles/__tests__/lint-baseline.test.ts +0 -314
- package/principles/__tests__/many-exports-reexport.test.ts +0 -40
- package/principles/__tests__/reporter.test.ts +0 -660
- package/principles/__tests__/types.test.ts +0 -103
- package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
- package/principles/adapters/__tests__/base.test.ts +0 -95
- package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
- package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
- package/principles/adapters/__tests__/cpp.test.ts +0 -290
- package/principles/adapters/__tests__/dart.test.ts +0 -84
- package/principles/adapters/__tests__/go.test.ts +0 -68
- package/principles/adapters/__tests__/java.test.ts +0 -385
- package/principles/adapters/__tests__/kotlin.test.ts +0 -76
- package/principles/adapters/__tests__/objectivec.test.ts +0 -453
- package/principles/adapters/__tests__/python.test.ts +0 -84
- package/principles/adapters/__tests__/swift.test.ts +0 -68
- package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
- package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
- package/principles/adapters/__tests__/typescript.test.ts +0 -116
- package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
- package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
- package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
- package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
- package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
- package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
- package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
- package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
- package/principles/rules/__tests__/index.test.ts +0 -49
- package/principles/rules/__tests__/solid/dip.test.ts +0 -119
- package/principles/rules/__tests__/solid/isp.test.ts +0 -58
- package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
- package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
- package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
- package/principles/rules/__tests__/solid/srp.test.ts +0 -87
- package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
- package/principles/rules/arch/__tests__/naming.test.ts +0 -133
- package/principles/rules/arch/__tests__/shared.test.ts +0 -113
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test REQ-COV-003 BaselineStorage uncovered branches
|
|
3
|
-
* @intent Cover initializeWithAnalyzer (batching, timeout, errors) and ccn statistics
|
|
4
|
-
* @covers AC-COV-003
|
|
5
|
-
*/
|
|
6
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
7
|
-
import fs from 'fs/promises';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import os from 'os';
|
|
10
|
-
import { BaselineStorage } from '../baseline';
|
|
11
|
-
|
|
12
|
-
describe('BaselineEntry - lint tool fields (ruff, golangci, shellcheck)', () => {
|
|
13
|
-
it('accepts ruff field in BaselineEntry', () => {
|
|
14
|
-
const storage = new BaselineStorage();
|
|
15
|
-
const entry: Record<string, unknown> = {
|
|
16
|
-
'src/app.py': {
|
|
17
|
-
ruff: { warnings: 5, errors: 2 },
|
|
18
|
-
totalWarnings: 5,
|
|
19
|
-
lastAnalyzed: new Date().toISOString(),
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
expect(() => storage.validate(entry as unknown as Record<string, import('../baseline').BaselineEntry>)).not.toThrow();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('accepts golangci field in BaselineEntry', () => {
|
|
26
|
-
const storage = new BaselineStorage();
|
|
27
|
-
const entry: Record<string, unknown> = {
|
|
28
|
-
'src/main.go': {
|
|
29
|
-
golangci: { warnings: 3, errors: 1 },
|
|
30
|
-
totalWarnings: 3,
|
|
31
|
-
lastAnalyzed: new Date().toISOString(),
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
expect(() => storage.validate(entry as unknown as Record<string, import('../baseline').BaselineEntry>)).not.toThrow();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('accepts shellcheck field in BaselineEntry', () => {
|
|
38
|
-
const storage = new BaselineStorage();
|
|
39
|
-
const entry: Record<string, unknown> = {
|
|
40
|
-
'deploy.sh': {
|
|
41
|
-
shellcheck: { warnings: 2, errors: 0 },
|
|
42
|
-
totalWarnings: 2,
|
|
43
|
-
lastAnalyzed: new Date().toISOString(),
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
expect(() => storage.validate(entry as unknown as Record<string, import('../baseline').BaselineEntry>)).not.toThrow();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('rejects ruff entry with non-numeric warnings', () => {
|
|
50
|
-
const storage = new BaselineStorage();
|
|
51
|
-
const entry = {
|
|
52
|
-
'src/app.py': {
|
|
53
|
-
ruff: { warnings: 'high', errors: 2 },
|
|
54
|
-
totalWarnings: 5,
|
|
55
|
-
lastAnalyzed: new Date().toISOString(),
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
expect(() => storage.validate(entry as unknown as Record<string, import('../baseline').BaselineEntry>)).toThrow(/Invalid ruff properties/);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('combines all lint tools in getSummaryStatistics', () => {
|
|
62
|
-
const storage = new BaselineStorage();
|
|
63
|
-
const baseline: Record<string, unknown> = {
|
|
64
|
-
'src/app.py': {
|
|
65
|
-
ruff: { warnings: 5, errors: 2 },
|
|
66
|
-
totalWarnings: 5,
|
|
67
|
-
lastAnalyzed: new Date().toISOString(),
|
|
68
|
-
},
|
|
69
|
-
'src/main.go': {
|
|
70
|
-
golangci: { warnings: 3, errors: 1 },
|
|
71
|
-
totalWarnings: 3,
|
|
72
|
-
lastAnalyzed: new Date().toISOString(),
|
|
73
|
-
},
|
|
74
|
-
'deploy.sh': {
|
|
75
|
-
shellcheck: { warnings: 2, errors: 0 },
|
|
76
|
-
totalWarnings: 2,
|
|
77
|
-
lastAnalyzed: new Date().toISOString(),
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const stats = storage.getSummaryStatistics(baseline as Record<string, import('../baseline').BaselineEntry>);
|
|
82
|
-
|
|
83
|
-
expect(stats.totalFiles).toBe(3);
|
|
84
|
-
expect(stats.totalWarnings).toBe(10);
|
|
85
|
-
const richStats = stats as typeof stats & { ruff: { totalWarnings: number; totalErrors: number }; golangci: { totalWarnings: number; totalErrors: number }; shellcheck: { totalWarnings: number; totalErrors: number } };
|
|
86
|
-
expect(richStats.ruff.totalWarnings).toBe(5);
|
|
87
|
-
expect(richStats.ruff.totalErrors).toBe(2);
|
|
88
|
-
expect(richStats.golangci.totalWarnings).toBe(3);
|
|
89
|
-
expect(richStats.golangci.totalErrors).toBe(1);
|
|
90
|
-
expect(richStats.shellcheck.totalWarnings).toBe(2);
|
|
91
|
-
expect(richStats.shellcheck.totalErrors).toBe(0);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('BaselineStorage - extended coverage', () => {
|
|
96
|
-
let tmpDir: string;
|
|
97
|
-
let baselinePath: string;
|
|
98
|
-
|
|
99
|
-
beforeEach(async () => {
|
|
100
|
-
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'baseline-test-'));
|
|
101
|
-
baselinePath = path.join(tmpDir, '.warnings-baseline.json');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
afterEach(async () => {
|
|
105
|
-
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
106
|
-
vi.restoreAllMocks();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('getSummaryStatistics - ccn aggregation', () => {
|
|
110
|
-
it('aggregates ccn warnings and max across files', () => {
|
|
111
|
-
const storage = new BaselineStorage();
|
|
112
|
-
const baseline = {
|
|
113
|
-
'src/a.ts': {
|
|
114
|
-
ccn: { warnings: 3, max: 12 },
|
|
115
|
-
totalWarnings: 3,
|
|
116
|
-
lastAnalyzed: new Date().toISOString(),
|
|
117
|
-
},
|
|
118
|
-
'src/b.ts': {
|
|
119
|
-
ccn: { warnings: 5, max: 18 },
|
|
120
|
-
totalWarnings: 5,
|
|
121
|
-
lastAnalyzed: new Date().toISOString(),
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const rawStats = storage.getSummaryStatistics(baseline);
|
|
126
|
-
const stats = rawStats as { totalFiles: number; totalWarnings: number; averageWarningsPerFile: number; ccn: { totalWarnings: number; totalMax: number } };
|
|
127
|
-
|
|
128
|
-
expect(stats.totalFiles).toBe(2);
|
|
129
|
-
expect(stats.ccn.totalWarnings).toBe(8);
|
|
130
|
-
expect(stats.ccn.totalMax).toBe(30);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('returns averageWarningsPerFile of 0 for empty baseline', () => {
|
|
134
|
-
const storage = new BaselineStorage();
|
|
135
|
-
const stats = storage.getSummaryStatistics({});
|
|
136
|
-
|
|
137
|
-
expect(stats.totalFiles).toBe(0);
|
|
138
|
-
expect(stats.totalWarnings).toBe(0);
|
|
139
|
-
expect(stats.averageWarningsPerFile).toBe(0);
|
|
140
|
-
expect('ccn' in stats ? (stats as Record<string, unknown>).ccn : undefined).toBeUndefined();
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe('initializeWithAnalyzer - batching and progress', () => {
|
|
145
|
-
it('processes files in batches based on batchSize config', async () => {
|
|
146
|
-
const storage = new BaselineStorage({ batchSize: 2 });
|
|
147
|
-
const files = ['f1.ts', 'f2.ts', 'f3.ts', 'f4.ts', 'f5.ts'];
|
|
148
|
-
const callOrder: string[] = [];
|
|
149
|
-
|
|
150
|
-
const warningFn = vi.fn(async (file: string) => {
|
|
151
|
-
callOrder.push(file);
|
|
152
|
-
return { eslint: { warnings: 1, errors: 0 } };
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const result = await storage.initializeWithAnalyzer(files, warningFn);
|
|
156
|
-
|
|
157
|
-
expect(warningFn).toHaveBeenCalledTimes(5);
|
|
158
|
-
expect(Object.keys(result)).toHaveLength(5);
|
|
159
|
-
expect(callOrder).toEqual(files);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('invokes onProgress callback for each completed file', async () => {
|
|
163
|
-
const storage = new BaselineStorage({ batchSize: 2 });
|
|
164
|
-
const files = ['a.ts', 'b.ts', 'c.ts'];
|
|
165
|
-
const progressEvents: Array<{ current: number; total: number }> = [];
|
|
166
|
-
|
|
167
|
-
await storage.initializeWithAnalyzer(
|
|
168
|
-
files,
|
|
169
|
-
async () => ({ eslint: { warnings: 1, errors: 0 } }),
|
|
170
|
-
(progress) => {
|
|
171
|
-
progressEvents.push({ current: progress.current, total: progress.total });
|
|
172
|
-
},
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
expect(progressEvents).toHaveLength(3);
|
|
176
|
-
expect(progressEvents[progressEvents.length - 1].current).toBe(3);
|
|
177
|
-
expect(progressEvents.every((e) => e.total === 3)).toBe(true);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('initializeWithAnalyzer - error and limit handling', () => {
|
|
182
|
-
it('throws when files array exceeds maxSize', async () => {
|
|
183
|
-
const storage = new BaselineStorage({ maxSize: 2 });
|
|
184
|
-
const files = ['a.ts', 'b.ts', 'c.ts'];
|
|
185
|
-
|
|
186
|
-
await expect(
|
|
187
|
-
storage.initializeWithAnalyzer(files, async () => ({})),
|
|
188
|
-
).rejects.toThrow(/exceeds the maximum of 2/);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('logs errors via console.error when warningCountFunction rejects', async () => {
|
|
192
|
-
const storage = new BaselineStorage({ batchSize: 5 });
|
|
193
|
-
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => { /* noop */ });
|
|
194
|
-
const files = ['ok.ts', 'fail.ts'];
|
|
195
|
-
|
|
196
|
-
const warningFn = async (file: string) => {
|
|
197
|
-
if (file === 'fail.ts') {
|
|
198
|
-
throw new Error('analyzer crashed');
|
|
199
|
-
}
|
|
200
|
-
return { eslint: { warnings: 2, errors: 0 } };
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const result = await storage.initializeWithAnalyzer(files, warningFn);
|
|
204
|
-
|
|
205
|
-
expect(errorSpy).toHaveBeenCalledWith(
|
|
206
|
-
'Some files failed to analyze:',
|
|
207
|
-
expect.any(Array),
|
|
208
|
-
);
|
|
209
|
-
expect(result['ok.ts']).toBeDefined();
|
|
210
|
-
expect(result['fail.ts']).toBeUndefined();
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('rejects with timeout when processing exceeds timeoutMs', async () => {
|
|
214
|
-
const storage = new BaselineStorage({ timeoutMs: 50, batchSize: 1 });
|
|
215
|
-
const files = ['slow.ts'];
|
|
216
|
-
|
|
217
|
-
const warningFn = () =>
|
|
218
|
-
new Promise<{ totalWarnings: number }>((resolve) => {
|
|
219
|
-
setTimeout(() => resolve({ totalWarnings: 1 }), 200);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
await expect(
|
|
223
|
-
storage.initializeWithAnalyzer(files, warningFn),
|
|
224
|
-
).rejects.toThrow(/timed out/);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
describe('initializeWithAnalyzer - totalWarnings calculation', () => {
|
|
229
|
-
it('calculates totalWarnings from eslint-only entries', async () => {
|
|
230
|
-
const storage = new BaselineStorage();
|
|
231
|
-
const result = await storage.initializeWithAnalyzer(['a.ts'], async () => ({
|
|
232
|
-
eslint: { warnings: 7, errors: 1 },
|
|
233
|
-
}));
|
|
234
|
-
|
|
235
|
-
expect(result['a.ts'].totalWarnings).toBe(7);
|
|
236
|
-
expect(result['a.ts'].eslint).toEqual({ warnings: 7, errors: 1 });
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('calculates totalWarnings from principles-only entries', async () => {
|
|
240
|
-
const storage = new BaselineStorage();
|
|
241
|
-
const result = await storage.initializeWithAnalyzer(['b.ts'], async () => ({
|
|
242
|
-
principles: { warnings: 4, errors: 0 },
|
|
243
|
-
}));
|
|
244
|
-
|
|
245
|
-
expect(result['b.ts'].totalWarnings).toBe(4);
|
|
246
|
-
expect(result['b.ts'].principles).toEqual({ warnings: 4, errors: 0 });
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it('calculates totalWarnings from ccn-only entries', async () => {
|
|
250
|
-
const storage = new BaselineStorage();
|
|
251
|
-
const result = await storage.initializeWithAnalyzer(['c.ts'], async () => ({
|
|
252
|
-
ccn: { warnings: 6, max: 15 },
|
|
253
|
-
}));
|
|
254
|
-
|
|
255
|
-
expect(result['c.ts'].totalWarnings).toBe(6);
|
|
256
|
-
expect(result['c.ts'].ccn).toEqual({ warnings: 6, max: 15 });
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('uses explicit totalWarnings override when provided', async () => {
|
|
260
|
-
const storage = new BaselineStorage();
|
|
261
|
-
const result = await storage.initializeWithAnalyzer(['d.ts'], async () => ({
|
|
262
|
-
eslint: { warnings: 3, errors: 0 },
|
|
263
|
-
principles: { warnings: 2, errors: 0 },
|
|
264
|
-
ccn: { warnings: 1, max: 5 },
|
|
265
|
-
totalWarnings: 99,
|
|
266
|
-
}));
|
|
267
|
-
|
|
268
|
-
expect(result['d.ts'].totalWarnings).toBe(99);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it('aggregates totalWarnings across all three sources when no override', async () => {
|
|
272
|
-
const storage = new BaselineStorage();
|
|
273
|
-
const result = await storage.initializeWithAnalyzer(['e.ts'], async () => ({
|
|
274
|
-
eslint: { warnings: 2, errors: 0 },
|
|
275
|
-
principles: { warnings: 3, errors: 0 },
|
|
276
|
-
ccn: { warnings: 4, max: 10 },
|
|
277
|
-
}));
|
|
278
|
-
|
|
279
|
-
expect(result['e.ts'].totalWarnings).toBe(9);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it('sets totalWarnings to 0 when warningCountFunction returns empty object', async () => {
|
|
283
|
-
const storage = new BaselineStorage();
|
|
284
|
-
const result = await storage.initializeWithAnalyzer(['empty.ts'], async () => ({}));
|
|
285
|
-
|
|
286
|
-
expect(result['empty.ts'].totalWarnings).toBe(0);
|
|
287
|
-
expect(result['empty.ts'].eslint).toBeUndefined();
|
|
288
|
-
expect(result['empty.ts'].principles).toBeUndefined();
|
|
289
|
-
expect(result['empty.ts'].ccn).toBeUndefined();
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('honors explicit totalWarnings of 0 when provided', async () => {
|
|
293
|
-
const storage = new BaselineStorage();
|
|
294
|
-
const result = await storage.initializeWithAnalyzer(['z.ts'], async () => ({
|
|
295
|
-
eslint: { warnings: 5, errors: 0 },
|
|
296
|
-
totalWarnings: 0,
|
|
297
|
-
}));
|
|
298
|
-
|
|
299
|
-
expect(result['z.ts'].totalWarnings).toBe(0);
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
describe('initializeWithAnalyzer - integration with save/load', () => {
|
|
304
|
-
it('saves and reloads baseline produced by initializeWithAnalyzer', async () => {
|
|
305
|
-
const storage = new BaselineStorage();
|
|
306
|
-
const built = await storage.initializeWithAnalyzer(
|
|
307
|
-
['file1.ts', 'file2.ts'],
|
|
308
|
-
async (file) => ({
|
|
309
|
-
eslint: { warnings: file === 'file1.ts' ? 1 : 2, errors: 0 },
|
|
310
|
-
}),
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
await storage.save(baselinePath, built);
|
|
314
|
-
const loaded = await storage.load(baselinePath);
|
|
315
|
-
|
|
316
|
-
expect(Object.keys(loaded).sort()).toEqual(['file1.ts', 'file2.ts']);
|
|
317
|
-
expect(loaded['file2.ts'].totalWarnings).toBe(2);
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
it('handles empty files array without invoking analyzer', async () => {
|
|
321
|
-
const storage = new BaselineStorage();
|
|
322
|
-
const warningFn = vi.fn(async () => ({}));
|
|
323
|
-
|
|
324
|
-
const result = await storage.initializeWithAnalyzer([], warningFn);
|
|
325
|
-
|
|
326
|
-
expect(result).toEqual({});
|
|
327
|
-
expect(warningFn).not.toHaveBeenCalled();
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
});
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
|
|
3
|
-
vi.mock('fs/promises', async (importOriginal) => {
|
|
4
|
-
const actual = await importOriginal<typeof import('fs/promises')>();
|
|
5
|
-
return {
|
|
6
|
-
...actual,
|
|
7
|
-
readFile: vi.fn(),
|
|
8
|
-
access: vi.fn(),
|
|
9
|
-
writeFile: vi.fn(),
|
|
10
|
-
};
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
vi.mock('../analyzer', () => ({
|
|
14
|
-
analyze: vi.fn(),
|
|
15
|
-
getAdapterForFile: vi.fn(),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
vi.mock('../index', () => ({
|
|
19
|
-
getAllRules: vi.fn(() => []),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
import { writeFile, readFile } from 'fs/promises';
|
|
23
|
-
import { initBaselineCommand } from '../boy-scout';
|
|
24
|
-
import { analyze } from '../analyzer';
|
|
25
|
-
|
|
26
|
-
const mockAnalyze = vi.mocked(analyze);
|
|
27
|
-
const mockWriteFile = vi.mocked(writeFile);
|
|
28
|
-
const mockReadFile = vi.mocked(readFile);
|
|
29
|
-
|
|
30
|
-
function violationsFor(counts: Record<string, number>) {
|
|
31
|
-
const violations = [];
|
|
32
|
-
for (const [file, n] of Object.entries(counts)) {
|
|
33
|
-
for (let i = 0; i < n; i++) {
|
|
34
|
-
violations.push({
|
|
35
|
-
file,
|
|
36
|
-
line: i + 1,
|
|
37
|
-
ruleId: 'clean-code.magic-numbers',
|
|
38
|
-
message: 'm',
|
|
39
|
-
severity: 'warning' as const,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return { violations, summary: {}, fileResults: {}, ruleResults: {}, executionTimeMs: 0, errors: [] };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* A realistic ENOENT. `loadBaseline` distinguishes "no file yet" from every other
|
|
48
|
-
* I/O failure by `error.code`, so a mock that only says `new Error('ENOENT')`
|
|
49
|
-
* (no `code`) is not a real ENOENT and would be treated as unreadable (#455).
|
|
50
|
-
*/
|
|
51
|
-
function enoent(): NodeJS.ErrnoException {
|
|
52
|
-
return Object.assign(new Error('ENOENT: no such file or directory'), { code: 'ENOENT' });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @test REQ-DSH-014
|
|
57
|
-
* @intent 验证 `--init-baseline` 是**合并**语义而非覆盖:既有基线条目必须保留,
|
|
58
|
-
* 且写入路径必须尊重 `--baseline` 参数,不得硬编码 .warnings-baseline.json
|
|
59
|
-
* (#445 —— 实测该命令会把已跟踪的基线摧毁成 {})
|
|
60
|
-
* @covers AC-DSH-014-01
|
|
61
|
-
*/
|
|
62
|
-
describe('initBaselineCommand must not destroy existing baselines (#445)', () => {
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
vi.clearAllMocks();
|
|
65
|
-
mockWriteFile.mockResolvedValue(undefined);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('merges into the existing baseline instead of replacing it', async () => {
|
|
69
|
-
// Existing tracked baseline already has an entry for an unrelated file.
|
|
70
|
-
const existing = {
|
|
71
|
-
'src/legacy.ts': { totalWarnings: 3, lastAnalyzed: '2026-01-01T00:00:00.000Z' },
|
|
72
|
-
};
|
|
73
|
-
mockReadFile.mockResolvedValue(JSON.stringify(existing) as never);
|
|
74
|
-
mockAnalyze.mockResolvedValue(violationsFor({ 'src/new.ts': 2 }) as never);
|
|
75
|
-
|
|
76
|
-
await initBaselineCommand(['src/new.ts'], '.warnings-baseline.json');
|
|
77
|
-
|
|
78
|
-
expect(mockWriteFile).toHaveBeenCalledTimes(1);
|
|
79
|
-
const [, writtenRaw] = mockWriteFile.mock.calls[0];
|
|
80
|
-
const written = JSON.parse(String(writtenRaw));
|
|
81
|
-
|
|
82
|
-
// The pre-existing entry MUST survive.
|
|
83
|
-
expect(written['src/legacy.ts']).toBeDefined();
|
|
84
|
-
expect(written['src/legacy.ts'].totalWarnings).toBe(3);
|
|
85
|
-
// And the newly analysed file must be added.
|
|
86
|
-
expect(written['src/new.ts']).toBeDefined();
|
|
87
|
-
expect(written['src/new.ts'].totalWarnings).toBe(2);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('writes to the path given by --baseline, not the hardcoded default', async () => {
|
|
91
|
-
mockReadFile.mockRejectedValue(enoent() as never);
|
|
92
|
-
mockAnalyze.mockResolvedValue(violationsFor({ 'src/a.ts': 1 }) as never);
|
|
93
|
-
|
|
94
|
-
await initBaselineCommand(['src/a.ts'], 'custom/baseline.json');
|
|
95
|
-
|
|
96
|
-
const [targetPath] = mockWriteFile.mock.calls[0];
|
|
97
|
-
expect(String(targetPath)).toBe('custom/baseline.json');
|
|
98
|
-
expect(String(targetPath)).not.toBe('.warnings-baseline.json');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('does not persist an empty object when analysis yields no warnings', async () => {
|
|
102
|
-
const existing = {
|
|
103
|
-
'src/legacy.ts': { totalWarnings: 1, lastAnalyzed: '2026-01-01T00:00:00.000Z' },
|
|
104
|
-
};
|
|
105
|
-
mockReadFile.mockResolvedValue(JSON.stringify(existing) as never);
|
|
106
|
-
// File now has zero warnings.
|
|
107
|
-
mockAnalyze.mockResolvedValue(violationsFor({}) as never);
|
|
108
|
-
|
|
109
|
-
await initBaselineCommand(['src/clean.ts'], '.warnings-baseline.json');
|
|
110
|
-
|
|
111
|
-
const [, writtenRaw] = mockWriteFile.mock.calls[0];
|
|
112
|
-
const written = JSON.parse(String(writtenRaw));
|
|
113
|
-
// Must NOT be {} -- the legacy entry has to survive.
|
|
114
|
-
expect(Object.keys(written)).toContain('src/legacy.ts');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('reports which entries were added and which were preserved', async () => {
|
|
118
|
-
const existing = {
|
|
119
|
-
'src/legacy.ts': { totalWarnings: 3, lastAnalyzed: '2026-01-01T00:00:00.000Z' },
|
|
120
|
-
};
|
|
121
|
-
mockReadFile.mockResolvedValue(JSON.stringify(existing) as never);
|
|
122
|
-
mockAnalyze.mockResolvedValue(violationsFor({ 'src/new.ts': 1 }) as never);
|
|
123
|
-
const log = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
124
|
-
|
|
125
|
-
await initBaselineCommand(['src/new.ts'], '.warnings-baseline.json');
|
|
126
|
-
|
|
127
|
-
const output = log.mock.calls.map((c) => c.join(' ')).join('\n');
|
|
128
|
-
expect(output).toMatch(/src\/legacy\.ts/);
|
|
129
|
-
expect(output).toMatch(/src\/new\.ts/);
|
|
130
|
-
log.mockRestore();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('signals outcome via its return value, never process.exitCode', async () => {
|
|
134
|
-
// Delphi Round 1: three experts independently flagged that this command
|
|
135
|
-
// reported failure by mutating global exit state, so an unrelated
|
|
136
|
-
// non-zero process.exitCode would be misread as this command failing.
|
|
137
|
-
mockReadFile.mockRejectedValue(enoent() as never);
|
|
138
|
-
mockAnalyze.mockResolvedValue(violationsFor({ 'src/a.ts': 1 }) as never);
|
|
139
|
-
const previousExitCode = process.exitCode;
|
|
140
|
-
process.exitCode = 0;
|
|
141
|
-
|
|
142
|
-
const result = await initBaselineCommand(['src/a.ts'], '.warnings-baseline.json');
|
|
143
|
-
|
|
144
|
-
expect(result.ok).toBe(true);
|
|
145
|
-
// Global state must be untouched by the command.
|
|
146
|
-
expect(process.exitCode).toBe(0);
|
|
147
|
-
|
|
148
|
-
process.exitCode = previousExitCode;
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('can never empty a non-empty baseline, even when analysis finds nothing', async () => {
|
|
152
|
-
// The merge starts from the existing entries, so the destructive overwrite
|
|
153
|
-
// from #445 is structurally impossible rather than merely guarded.
|
|
154
|
-
const existing = {
|
|
155
|
-
'src/legacy.ts': { totalWarnings: 1, lastAnalyzed: '2026-01-01T00:00:00.000Z' },
|
|
156
|
-
};
|
|
157
|
-
mockReadFile.mockResolvedValue(JSON.stringify(existing) as never);
|
|
158
|
-
mockAnalyze.mockResolvedValue(violationsFor({}) as never);
|
|
159
|
-
|
|
160
|
-
const result = await initBaselineCommand(['src/clean.ts'], '.warnings-baseline.json');
|
|
161
|
-
|
|
162
|
-
expect(result.ok).toBe(true);
|
|
163
|
-
const [, writtenRaw] = mockWriteFile.mock.calls[0];
|
|
164
|
-
const written = JSON.parse(String(writtenRaw));
|
|
165
|
-
expect(Object.keys(written)).toContain('src/legacy.ts');
|
|
166
|
-
});
|
|
167
|
-
});
|