@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,70 +0,0 @@
1
- /**
2
- * @test REQ-623
3
- * @intent A file the checker could not read must not be silently rounded down to
4
- * "no violations". Before this, `analyze` caught the read failure into
5
- * `result.errors` and `main()` never looked at that array, so the run
6
- * exited 0 with a clean report. That is how CI's SARIF step archived a
7
- * successful-looking report while its log said
8
- * `Analysis failed: Could not read file: <blob>` -- a report about fewer
9
- * files than were asked for, presented as a report about all of them.
10
- *
11
- * The contract kept here: an unreadable file is RECORDED (one entry, not
12
- * one per rule) and `main()` refuses to call the run clean.
13
- * @covers AC-623-04, AC-623-05
14
- */
15
-
16
- import { describe, it, expect } from 'vitest';
17
- import fs from 'node:fs';
18
- import os from 'node:os';
19
- import path from 'node:path';
20
- import { analyze, getAdapterForFile } from '../analyzer';
21
- import { getAllRules } from '../index';
22
-
23
- /** A directory named `*.ts`: resolves a TS adapter, then cannot be read. */
24
- function unreadableTsPath(): string {
25
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-analyze-'));
26
- const asDir = path.join(dir, 'broken.ts');
27
- fs.mkdirSync(asDir);
28
- return asDir;
29
- }
30
-
31
- describe('AC-623-04: an unreadable file is recorded, not swallowed', () => {
32
- it('puts the read failure in result.errors', async () => {
33
- const result = await analyze([unreadableTsPath()], getAllRules(), getAdapterForFile);
34
- expect(result.errors.length).toBeGreaterThan(0);
35
- });
36
-
37
- it('names the file that could not be read', async () => {
38
- const target = unreadableTsPath();
39
- const result = await analyze([target], getAllRules(), getAdapterForFile);
40
- expect(result.errors.join('\n')).toContain('broken.ts');
41
- });
42
-
43
- it('records one entry per file, not one per rule', async () => {
44
- // The unreadable file is touched by every enabled rule; the failure is a
45
- // property of the file, so the operator must not see it repeated per rule.
46
- const result = await analyze([unreadableTsPath()], getAllRules(), getAdapterForFile);
47
- expect(result.errors.length).toBe(1);
48
- });
49
-
50
- it('does not report the unreadable file as examined-and-clean', async () => {
51
- const result = await analyze([unreadableTsPath()], getAllRules(), getAdapterForFile);
52
- // No violations could have been found in a file that was never read.
53
- expect(result.violations).toHaveLength(0);
54
- // ...so the only honest signal is the error, and it must be present.
55
- expect(result.errors.length).toBeGreaterThan(0);
56
- });
57
- });
58
-
59
- describe('AC-623-05: a healthy run records no errors', () => {
60
- it('leaves errors empty when every file reads', async () => {
61
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-analyze-ok-'));
62
- const good = path.join(dir, 'good.ts');
63
- fs.writeFileSync(good, 'export const value = 1;\n', 'utf8');
64
-
65
- const result = await analyze([good], getAllRules(), getAdapterForFile);
66
-
67
- expect(result.errors).toHaveLength(0);
68
- expect(result.summary.filesChecked).toBe(1);
69
- });
70
- });
@@ -1,367 +0,0 @@
1
- /**
2
- * @test analyzer.ts - Rule orchestration engine
3
- * @intent Verify analyzer runs rules and aggregates violations correctly
4
- * @covers clean-code-solid-checker-design Section 3 (CORE ENGINE)
5
- */
6
-
7
- import { describe, it, expect, beforeEach, vi } from 'vitest';
8
- import { analyze } from '../analyzer';
9
- import { getDefaultConfig, resetActiveConfig, setActiveConfig } from '../config';
10
- import { Rule, Adapter, Severity } from '../types';
11
-
12
- describe('analyzer.ts - Rule Orchestration Engine', () => {
13
- let mockAdapter: Adapter;
14
- let mockRule: Rule;
15
-
16
- beforeEach(() => {
17
- // Mock adapter
18
- mockAdapter = {
19
- detectLanguage: vi.fn().mockReturnValue('typescript'),
20
- parseAST: vi.fn().mockReturnValue({}),
21
- extractFunctions: vi.fn().mockReturnValue([
22
- { name: 'testFunc', startLine: 1, length: 60 }
23
- ]),
24
- extractClasses: vi.fn().mockReturnValue([]),
25
- extractExports: vi.fn().mockReturnValue([]),
26
- countLines: vi.fn().mockReturnValue(100),
27
- getDuplication: vi.fn().mockReturnValue({ percentage: 0, blocks: [] }), declaresRuleCoverage: true
28
- };
29
-
30
- // Mock rule that detects violations
31
- mockRule = {
32
- id: 'clean-code.long-function',
33
- name: 'Long Function Rule',
34
- threshold: 50,
35
- severity: 'warning' as Severity,
36
- check: vi.fn().mockReturnValue([
37
- {
38
- file: 'test.ts',
39
- line: 1,
40
- ruleId: 'clean-code.long-function',
41
- message: 'Function "testFunc" is too long: 60 lines (maximum: 50)',
42
- severity: 'warning' as Severity
43
- }
44
- ])
45
- };
46
- });
47
-
48
- describe('analyze function', () => {
49
- it('should return AnalysisResult with violations array', async () => {
50
- const files = ['test.ts'];
51
- const rules = [mockRule];
52
-
53
- const result = await analyze(files, rules, mockAdapter);
54
-
55
- expect(result).toBeDefined();
56
- expect(result.violations).toBeInstanceOf(Array);
57
- expect(result.summary).toBeDefined();
58
- });
59
-
60
- it('should run each rule against each file', async () => {
61
- const files = ['test.ts', 'test2.ts'];
62
- const rules = [mockRule];
63
-
64
- await analyze(files, rules, mockAdapter);
65
-
66
- // Each file should be checked
67
- expect(mockRule.check).toHaveBeenCalledTimes(2);
68
- });
69
-
70
- it('should aggregate violations from all rules', async () => {
71
- const files = ['test.ts'];
72
- const rules = [
73
- mockRule,
74
- {
75
- id: 'clean-code.large-file',
76
- name: 'Large File Rule',
77
- threshold: 500,
78
- severity: 'warning' as Severity,
79
- check: vi.fn().mockReturnValue([
80
- {
81
- file: 'test.ts',
82
- line: 1,
83
- ruleId: 'clean-code.large-file',
84
- message: 'File is too large: 600 lines',
85
- severity: 'warning' as Severity
86
- }
87
- ])
88
- } as Rule
89
- ];
90
-
91
- const result = await analyze(files, rules, mockAdapter);
92
-
93
- expect(result.violations.length).toBe(2);
94
- expect(result.violations[0].ruleId).toBe('clean-code.long-function');
95
- expect(result.violations[1].ruleId).toBe('clean-code.large-file');
96
- });
97
-
98
- it('should filter rules by enabled config', async () => {
99
- const files = ['test.ts'];
100
-
101
- // Mock a disabled rule
102
- const disabledRule = {
103
- id: 'clean-code.disabled-rule',
104
- name: 'Disabled Rule',
105
- threshold: 10,
106
- severity: 'info' as Severity,
107
- check: vi.fn().mockReturnValue([])
108
- };
109
-
110
- await analyze(files, [mockRule, disabledRule], mockAdapter, {
111
- enabledRules: ['clean-code.long-function']
112
- });
113
-
114
- // Only enabled rule should run
115
- expect(mockRule.check).toHaveBeenCalled();
116
- expect(disabledRule.check).not.toHaveBeenCalled();
117
- });
118
-
119
- it('a rule disabled by config must not report files as checked (#457)', async () => {
120
- // `filesChecked` used to be incremented before the `enabled` check, so a rule
121
- // that never ran still claimed it had examined the file -- inflating per-rule
122
- // coverage statistics for work the rule did not do.
123
- const disabled = getDefaultConfig();
124
- disabled.rules['clean-code']['long-function'].enabled = false;
125
- try {
126
- setActiveConfig(disabled);
127
- const result = await analyze(['test.ts'], [mockRule], mockAdapter, {});
128
- expect(mockRule.check).not.toHaveBeenCalled();
129
- expect(result.ruleResults['clean-code.long-function'].filesChecked).toBe(0);
130
- } finally {
131
- // Restore the process-global config so later tests are unaffected.
132
- // `resetActiveConfig()` rather than re-installing the captured config:
133
- // replacing an already-installed config is exactly what the #457
134
- // guardrail reports, and this suite never installs a non-default one.
135
- resetActiveConfig();
136
- }
137
- });
138
-
139
- it('should return empty violations if all rules pass', async () => {
140
- const passingRule: Rule = {
141
- id: 'clean-code.passing',
142
- name: 'Passing Rule',
143
- threshold: 50,
144
- severity: 'warning' as Severity,
145
- check: vi.fn().mockReturnValue([])
146
- };
147
-
148
- const files = ['clean.ts'];
149
- const result = await analyze(files, [passingRule], mockAdapter);
150
-
151
- expect(result.violations.length).toBe(0);
152
- expect(result.summary.totalViolations).toBe(0);
153
- });
154
-
155
- it('should calculate summary statistics correctly', async () => {
156
- const files = ['test.ts'];
157
- const rules = [mockRule];
158
-
159
- const result = await analyze(files, rules, mockAdapter);
160
-
161
- expect(result.summary.totalViolations).toBe(1);
162
- expect(result.summary.warningCount).toBe(1);
163
- expect(result.summary.errorCount).toBe(0);
164
- expect(result.summary.infoCount).toBe(0);
165
- });
166
-
167
- it('should handle multiple severity levels in summary', async () => {
168
- const files = ['test.ts'];
169
- const rules = [
170
- mockRule,
171
- {
172
- id: 'test.error',
173
- name: 'Error Rule',
174
- threshold: 10,
175
- severity: 'error' as Severity,
176
- check: vi.fn().mockReturnValue([
177
- {
178
- file: 'test.ts',
179
- line: 1,
180
- ruleId: 'test.error',
181
- message: 'Error violation',
182
- severity: 'error' as Severity
183
- }
184
- ])
185
- } as Rule,
186
- {
187
- id: 'test.info',
188
- name: 'Info Rule',
189
- threshold: 10,
190
- severity: 'info' as Severity,
191
- check: vi.fn().mockReturnValue([
192
- {
193
- file: 'test.ts',
194
- line: 2,
195
- ruleId: 'test.info',
196
- message: 'Info violation',
197
- severity: 'info' as Severity
198
- }
199
- ])
200
- } as Rule
201
- ];
202
-
203
- const result = await analyze(files, rules, mockAdapter);
204
-
205
- expect(result.summary.errorCount).toBe(1);
206
- expect(result.summary.warningCount).toBe(1);
207
- expect(result.summary.infoCount).toBe(1);
208
- expect(result.summary.totalViolations).toBe(3);
209
- });
210
-
211
- it('should skip files that do not match adapter language', async () => {
212
- const files = ['test.py', 'test.ts'];
213
-
214
- const adapterFactory = (filePath: string): Adapter => {
215
- const ext = filePath.split('.').pop()?.toLowerCase();
216
- if (ext === 'ts' || ext === 'tsx') {
217
- return mockAdapter;
218
- }
219
- return {
220
- ...mockAdapter,
221
- detectLanguage: () => 'unknown'
222
- };
223
- };
224
-
225
- await analyze(files, [mockRule], adapterFactory);
226
-
227
- expect(mockRule.check).toHaveBeenCalledTimes(1);
228
- });
229
-
230
- it('should handle rule check errors gracefully', async () => {
231
- const errorRule: Rule = {
232
- id: 'error.rule',
233
- name: 'Error Rule',
234
- threshold: 10,
235
- severity: 'warning' as Severity,
236
- check: vi.fn().mockImplementation(() => {
237
- throw new Error('Rule check failed');
238
- })
239
- };
240
-
241
- const files = ['test.ts'];
242
-
243
- // Should not throw, should handle gracefully
244
- const result = await analyze(files, [errorRule], mockAdapter);
245
-
246
- expect(result.violations.length).toBe(0);
247
- expect(result.errors).toBeDefined();
248
- expect(result.errors.length).toBeGreaterThan(0);
249
- });
250
- });
251
-
252
- describe('runRuleOnFile (via analyze) — verifies context-object parameter bundling', () => {
253
- // Extracted from the test body: inlining this callback pushed the test past the
254
- // 4-level nesting limit for no readability gain.
255
- const ruleACheck = vi.fn().mockImplementation((file: string) => {
256
- if (file !== 'a.ts') return [];
257
- return [{ file: 'a.ts', line: 1, ruleId: 'test.rule-a', message: 'violation in a', severity: 'warning' as Severity }];
258
- });
259
-
260
- it('should correctly aggregate violations per file and per rule', async () => {
261
- const files = ['a.ts', 'b.ts'];
262
- const ruleA = {
263
- id: 'test.rule-a',
264
- name: 'Rule A',
265
- threshold: 10,
266
- severity: 'warning' as Severity,
267
- check: ruleACheck
268
- } as Rule;
269
- const ruleB = {
270
- id: 'test.rule-b',
271
- name: 'Rule B',
272
- threshold: 10,
273
- severity: 'error' as Severity,
274
- check: vi.fn().mockReturnValue([
275
- { file: 'a.ts', line: 2, ruleId: 'test.rule-b', message: 'error in a', severity: 'error' as Severity },
276
- { file: 'b.ts', line: 1, ruleId: 'test.rule-b', message: 'error in b', severity: 'error' as Severity },
277
- ])
278
- } as Rule;
279
-
280
- const result = await analyze(files, [ruleA, ruleB], mockAdapter);
281
-
282
- // fileResults — each file has the correct violations
283
- // ruleA: 1 violation for a.ts via file-match, 0 for b.ts; ruleB: mockReturnValue returns both for any file
284
- expect(result.fileResults['a.ts'].violations).toHaveLength(3);
285
- expect(result.fileResults['a.ts'].ruleIds).toEqual(['test.rule-a', 'test.rule-b']);
286
- // ruleB returns both violations on every call (mockReturnValue — no per-file filter)
287
- expect(result.fileResults['b.ts'].violations).toHaveLength(2);
288
- expect(result.fileResults['b.ts'].ruleIds).toEqual(['test.rule-b']);
289
-
290
- // ruleResults — each rule tracked correctly
291
- expect(result.ruleResults['test.rule-a'].violationCount).toBe(1);
292
- expect(result.ruleResults['test.rule-a'].filesChecked).toBe(2);
293
- // ruleB's violationCount accumulates across all files (2 per file × 2 files = 4)
294
- expect(result.ruleResults['test.rule-b'].violationCount).toBe(4);
295
- expect(result.ruleResults['test.rule-b'].filesChecked).toBe(2);
296
-
297
- // total violations = 1 (ruleA) + 4 (ruleB) = 5
298
- expect(result.summary.totalViolations).toBe(5);
299
- });
300
-
301
- it('should collect per-rule errors from runRuleOnFile into top-level errors array', async () => {
302
- const files = ['a.ts', 'b.ts'];
303
- const goodRule = {
304
- id: 'test.good',
305
- name: 'Good Rule',
306
- threshold: 10,
307
- severity: 'info' as Severity,
308
- check: vi.fn().mockReturnValue([])
309
- } as Rule;
310
- const badRule = {
311
- id: 'test.bad',
312
- name: 'Bad Rule',
313
- threshold: 10,
314
- severity: 'error' as Severity,
315
- check: vi.fn().mockImplementation((file: string) => {
316
- if (file === 'b.ts') throw new Error('crash on b');
317
- return [];
318
- })
319
- } as Rule;
320
-
321
- const result = await analyze(files, [goodRule, badRule], mockAdapter);
322
-
323
- // goodRule ran on both files
324
- expect(goodRule.check).toHaveBeenCalledTimes(2);
325
- // badRule crashed on b.ts — error captured, a.ts succeeded
326
- expect(result.errors).toContain('Rule test.bad failed on b.ts: crash on b');
327
- // goodRule results still intact
328
- expect(result.ruleResults['test.good'].filesChecked).toBe(2);
329
- // filesChecked counts attempted files (incremented before try/catch)
330
- expect(result.ruleResults['test.bad'].filesChecked).toBe(2);
331
- });
332
- });
333
-
334
- describe('AnalysisResult structure', () => {
335
- it('should include file-by-file breakdown', async () => {
336
- const files = ['test.ts'];
337
- const rules = [mockRule];
338
-
339
- const result = await analyze(files, rules, mockAdapter);
340
-
341
- expect(result.fileResults).toBeDefined();
342
- expect(result.fileResults['test.ts']).toBeDefined();
343
- expect(result.fileResults['test.ts'].violations.length).toBe(1);
344
- });
345
-
346
- it('should include execution time', async () => {
347
- const files = ['test.ts'];
348
- const rules = [mockRule];
349
-
350
- const result = await analyze(files, rules, mockAdapter);
351
-
352
- expect(result.executionTimeMs).toBeDefined();
353
- expect(result.executionTimeMs).toBeGreaterThanOrEqual(0);
354
- });
355
-
356
- it('should include rule-by-rule breakdown', async () => {
357
- const files = ['test.ts'];
358
- const rules = [mockRule];
359
-
360
- const result = await analyze(files, rules, mockAdapter);
361
-
362
- expect(result.ruleResults).toBeDefined();
363
- expect(result.ruleResults['clean-code.long-function']).toBeDefined();
364
- expect(result.ruleResults['clean-code.long-function'].violationCount).toBe(1);
365
- });
366
- });
367
- });
@@ -1,76 +0,0 @@
1
- /**
2
- * @test REQ-620
3
- * @intent Pin the single behavioural difference introduced when the two copies
4
- * of the per-tool accumulator were merged into buildEntry:
5
- * `createFromFiles` tested `totalWarnings` for TRUTHINESS, so a caller
6
- * passing an explicit `0` had it replaced by the sum of the per-tool
7
- * counts. That is exactly the case where the caller is overriding a
8
- * stale per-tool number, so the override was silently discarded.
9
- *
10
- * `initializeWithAnalyzer` already used `!== undefined`, so the two
11
- * entry points disagreed about the same input. The merged version uses
12
- * the `!== undefined` reading for both.
13
- * @covers AC-620-04
14
- */
15
- import { describe, it, expect } from 'vitest';
16
- import { BaselineStorage } from '../baseline';
17
-
18
- function storage(): InstanceType<typeof BaselineStorage> {
19
- // Explicit config: a timeout far above any test's runtime.
20
- return new BaselineStorage({ maxSize: 100, timeoutMs: 10000, batchSize: 5 });
21
- }
22
-
23
- describe('AC-620-04: an explicit totalWarnings wins, including zero', () => {
24
- it('uses an explicit zero instead of the summed per-tool count', async () => {
25
- const baseline = await storage().createFromFiles([
26
- { file: 'a.ts', counts: { eslint: { warnings: 3, errors: 0 }, totalWarnings: 0 } },
27
- ]);
28
- expect(baseline['a.ts'].totalWarnings).toBe(0);
29
- });
30
-
31
- it('uses an explicit nonzero value instead of the summed count', async () => {
32
- const baseline = await storage().createFromFiles([
33
- { file: 'a.ts', counts: { eslint: { warnings: 3, errors: 0 }, totalWarnings: 42 } },
34
- ]);
35
- expect(baseline['a.ts'].totalWarnings).toBe(42);
36
- });
37
-
38
- it('sums the per-tool counts when no explicit total is given', async () => {
39
- const baseline = await storage().createFromFiles([
40
- {
41
- file: 'a.ts',
42
- counts: {
43
- eslint: { warnings: 3, errors: 0 },
44
- ruff: { warnings: 2, errors: 1 },
45
- },
46
- },
47
- ]);
48
- expect(baseline['a.ts'].totalWarnings).toBe(5);
49
- });
50
-
51
- it('keeps every per-tool count it was given', async () => {
52
- const baseline = await storage().createFromFiles([
53
- {
54
- file: 'a.ts',
55
- counts: {
56
- eslint: { warnings: 1, errors: 2 },
57
- ccn: { warnings: 3, max: 9 },
58
- shellcheck: { warnings: 4, errors: 5 },
59
- },
60
- },
61
- ]);
62
- const entry = baseline['a.ts'];
63
- expect(entry.eslint).toEqual({ warnings: 1, errors: 2 });
64
- expect(entry.ccn).toEqual({ warnings: 3, max: 9 });
65
- expect(entry.shellcheck).toEqual({ warnings: 4, errors: 5 });
66
- // Tools that were not supplied must not appear at all.
67
- expect(entry.ruff).toBeUndefined();
68
- expect(entry.golangci).toBeUndefined();
69
- });
70
-
71
- it('reports zero warnings for a file with no tool counts', async () => {
72
- const baseline = await storage().createFromFiles([{ file: 'a.ts', counts: {} }]);
73
- expect(baseline['a.ts'].totalWarnings).toBe(0);
74
- expect(baseline['a.ts'].lastAnalyzed).toBeTypeOf('string');
75
- });
76
- });
@@ -1,71 +0,0 @@
1
- /**
2
- * @test REQ-452 REQ-3
3
- * @intent The baseline pruner runs inside a git hook, so its worst failure mode is
4
- * not a wrong answer but a commit that never returns. Every git call it
5
- * makes must carry a timeout, and the timeout must be short enough that a
6
- * wedged git degrades to "keep the entry" rather than hanging the hook.
7
- * @covers AC-452-14
8
- *
9
- * Mocked rather than stubbed with a fake binary: `execFileSync` resolves PATH
10
- * entries without consulting PATHEXT unless `shell` is set, so a `git.cmd` shim on
11
- * PATH is silently ignored in favour of the real binary -- a test built that way
12
- * passes while proving nothing. Asserting the options handed to child_process
13
- * tests the guard itself instead of Node's PATH resolution.
14
- */
15
-
16
- import { beforeEach, describe, expect, it, vi } from 'vitest';
17
-
18
- const execFileSyncMock = vi.fn();
19
-
20
- vi.mock('child_process', () => ({
21
- execFileSync: (...args: unknown[]) => execFileSyncMock(...args),
22
- }));
23
- vi.mock('fs', async () => {
24
- const actual = await vi.importActual<typeof import('fs')>('fs');
25
- return { ...actual, existsSync: vi.fn(() => false) };
26
- });
27
-
28
- import { pruneBaselineEntries } from '../baseline-prune';
29
-
30
- /** Generous for a healthy `git ls-files`, short enough not to wedge a hook. */
31
- const MAX_ACCEPTABLE_GIT_TIMEOUT_MS = 60_000;
32
-
33
- describe('baseline pruning git invocation (#452)', () => {
34
- beforeEach(() => {
35
- execFileSyncMock.mockReset();
36
- });
37
-
38
- it('AC-452-14: bounds every git call with a timeout', () => {
39
- execFileSyncMock.mockReturnValue('tracked.ts\n');
40
-
41
- pruneBaselineEntries(JSON.stringify({ 'gone.ts': { 'clean-code.large-file': 1 } }), '/tmp/project');
42
-
43
- expect(execFileSyncMock).toHaveBeenCalled();
44
- for (const call of execFileSyncMock.mock.calls) {
45
- const options = call[2] as { timeout?: number };
46
- expect(typeof options.timeout).toBe('number');
47
- expect(options.timeout).toBeGreaterThan(0);
48
- expect(options.timeout).toBeLessThanOrEqual(MAX_ACCEPTABLE_GIT_TIMEOUT_MS);
49
- }
50
- });
51
-
52
- it('AC-452-14: a git timeout keeps entries instead of failing the hook', () => {
53
- // execFileSync reports a killed process as an error with no stdout, which is
54
- // how a wedged git surfaces here.
55
- execFileSyncMock.mockImplementation(() => {
56
- const error = new Error('spawnSync git ETIMEDOUT') as Error & { signal?: string };
57
- error.signal = 'SIGTERM';
58
- throw error;
59
- });
60
-
61
- const result = pruneBaselineEntries(
62
- JSON.stringify({ 'gone.ts': { 'clean-code.large-file': 1 } }),
63
- '/tmp/project',
64
- );
65
-
66
- // Fail closed: an unreadable index must never justify deleting an entry.
67
- expect(result.removed).toEqual([]);
68
- expect(result.kept).toEqual(['gone.ts']);
69
- expect(result.error).toBeDefined();
70
- });
71
- });