@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,660 +0,0 @@
1
- /**
2
- * @test reporter.ts - Output formatting
3
- * @intent Verify reporter formats violations for console and other outputs
4
- * @covers clean-code-solid-checker-design Section 3 (CORE ENGINE)
5
- */
6
-
7
- import { describe, it, expect } from 'vitest';
8
- import { formatConsole, formatJSON, formatSARIF, formatSummary } from '../reporter';
9
- import { AnalysisResult, Violation } from '../analyzer';
10
-
11
- /**
12
- * Build an AnalysisResult summary.
13
- *
14
- * Extracted because these fixtures were written out in full 25 times, which the
15
- * clean-code.code-duplication rule scored at 44.2% (threshold 15%) and the Boy
16
- * Scout gate then blocked. The counts are positional rather than a params object
17
- * because every call site already reads as one line of counts, and a named-field
18
- * object per fixture would be longer than the literal it replaces.
19
- *
20
- * `unanalysedLanguages` defaults to empty: no fixture here exercises the
21
- * not-analysed notice, and tests that do set it explicitly via the options and
22
- * assert on it there.
23
- */
24
- function summaryOf(
25
- totalViolations: number,
26
- errorCount: number,
27
- warningCount: number,
28
- infoCount: number,
29
- filesChecked: number,
30
- rulesRun: number,
31
- unanalysedLanguages: string[] = []
32
- ): AnalysisResult['summary'] {
33
- return {
34
- totalViolations,
35
- errorCount,
36
- warningCount,
37
- infoCount,
38
- filesChecked,
39
- rulesRun,
40
- unanalysedLanguages,
41
- };
42
- }
43
-
44
- /**
45
- * The empty `fileResults` / `ruleResults` / `errors` set plus a duration.
46
- *
47
- * These lines appeared verbatim in 14 fixtures -- the remainder of the
48
- * duplication the `summaryOf` extraction above did not reach (`errors: []` alone
49
- * accounted for 21 of the repeated 3-line windows). Kept separate from summaryOf
50
- * because the two vary independently: several tests supply real ruleResults, and
51
- * one supplies a NaN errorCount.
52
- */
53
- function emptyResults(executionTimeMs: number): Pick<
54
- AnalysisResult,
55
- 'fileResults' | 'ruleResults' | 'executionTimeMs' | 'errors'
56
- > {
57
- return { fileResults: {}, ruleResults: {}, executionTimeMs, errors: [] };
58
- }
59
-
60
- /**
61
- * Build a Violation.
62
- *
63
- * These were written out as five-to-six line object literals 17 times, which the
64
- * clean-code.code-duplication rule scored well above its 15% threshold and the
65
- * Boy Scout gate blocked. Named fields would be longer than the literal they
66
- * replace and would bury the one thing each fixture is really saying -- which
67
- * file, which rule, which message -- so the two axes stay positional here.
68
- *
69
- * `column` is optional because only the first fixture asserts on it.
70
- */
71
- function violation(
72
- file: string,
73
- line: number,
74
- ruleId: string,
75
- message: string,
76
- severity: Violation['severity'],
77
- column?: number
78
- ): Violation {
79
- return column === undefined
80
- ? { file, line, ruleId, message, severity }
81
- : { file, line, column, ruleId, message, severity };
82
- }
83
-
84
- describe('reporter.ts - Output Formatting', () => {
85
- const sampleViolation: Violation = violation("src/test.ts", 10, "clean-code.long-function", "Function \"processData\" is too long: 65 lines (maximum: 50)", "warning", 5);
86
-
87
- const sampleResult: AnalysisResult = {
88
- violations: [
89
- sampleViolation,
90
- violation("src/utils.ts", 1, "clean-code.large-file", "File is too large: 600 lines (maximum: 500)", "warning"),
91
- violation("src/api.ts", 20, "solid.dip", "Direct instantiation detected: new UserRepository()", "warning")
92
- ],
93
- summary: summaryOf(3, 0, 3, 0, 3, 3),
94
- fileResults: {
95
- 'src/test.ts': { violations: [sampleViolation], ruleIds: ['clean-code.long-function'] }
96
- },
97
- ruleResults: {
98
- 'clean-code.long-function': { violationCount: 1, filesChecked: 3 }
99
- },
100
- executionTimeMs: 150,
101
- errors: []
102
- };
103
-
104
- describe('formatConsole', () => {
105
- it('should format violations as human-readable console output', () => {
106
- const output = formatConsole(sampleResult);
107
-
108
- expect(output).toContain('clean-code.long-function');
109
- expect(output).toContain('Function "processData" is too long');
110
- expect(output).toContain('src/test.ts');
111
- expect(output).toContain('line 10');
112
- });
113
-
114
- it('should group violations by file', () => {
115
- const output = formatConsole(sampleResult);
116
-
117
- expect(output).toContain('src/test.ts');
118
- expect(output).toContain('src/utils.ts');
119
- expect(output).toContain('src/api.ts');
120
- });
121
-
122
- it('should show severity indicators', () => {
123
- const output = formatConsole(sampleResult);
124
-
125
- expect(output).toContain('⚠');
126
- expect(output).toContain('WARNING');
127
- });
128
-
129
- it('should show execution time', () => {
130
- const output = formatConsole(sampleResult);
131
-
132
- expect(output).toContain('150ms');
133
- expect(output).toContain('Execution time');
134
- });
135
-
136
- it('should handle empty violations', () => {
137
- const emptyResult: AnalysisResult = {
138
- violations: [],
139
- summary: summaryOf(0, 0, 0, 0, 5, 3),
140
- ...emptyResults(50),
141
- };
142
-
143
- const output = formatConsole(emptyResult);
144
-
145
- expect(output).toContain('✓');
146
- expect(output).toContain('No violations found');
147
- });
148
- });
149
-
150
- describe('formatJSON', () => {
151
- it('should output valid JSON structure', () => {
152
- const output = formatJSON(sampleResult);
153
- const parsed = JSON.parse(output);
154
-
155
- expect(parsed.violations).toBeDefined();
156
- expect(parsed.summary).toBeDefined();
157
- expect(parsed.executionTimeMs).toBe(150);
158
- });
159
-
160
- it('should include all violation details', () => {
161
- const output = formatJSON(sampleResult);
162
- const parsed = JSON.parse(output);
163
-
164
- expect(parsed.violations[0].file).toBe('src/test.ts');
165
- expect(parsed.violations[0].ruleId).toBe('clean-code.long-function');
166
- });
167
-
168
- it('should be parseable for downstream tools', () => {
169
- const output = formatJSON(sampleResult);
170
-
171
- expect(() => JSON.parse(output)).not.toThrow();
172
- });
173
- });
174
-
175
- describe('formatSummary', () => {
176
- it('should show total violations count', () => {
177
- const output = formatSummary(sampleResult);
178
-
179
- expect(output).toContain('3 violations');
180
- });
181
-
182
- it('should show breakdown by severity', () => {
183
- const output = formatSummary(sampleResult);
184
-
185
- expect(output).toContain('0 errors');
186
- expect(output).toContain('3 warnings');
187
- expect(output).toContain('0 info');
188
- });
189
-
190
- it('should show files and rules checked', () => {
191
- const output = formatSummary(sampleResult);
192
-
193
- expect(output).toContain('3 files');
194
- expect(output).toContain('3 rules');
195
- });
196
-
197
- it('should indicate pass/fail status', () => {
198
- const output = formatSummary(sampleResult);
199
-
200
- expect(output).toContain('FAIL');
201
- });
202
-
203
- it('should not read a missing summary as FAIL (NaN must not decide the verdict)', () => {
204
- // Round 3 of the Delphi review, three seats independently: `undefined + 0`
205
- // is NaN, and `NaN === 0` is false, so an incomplete summary would make
206
- // this report FAIL unconditionally -- the exact symptom the info fix
207
- // removed, reintroduced through a different door. formatSummary is
208
- // exported, so it cannot assume its caller honoured the type.
209
- const noSummary = {
210
- violations: [],
211
- ...emptyResults(1),
212
- } as unknown as AnalysisResult;
213
-
214
- const output = formatSummary(noSummary);
215
- expect(output).toContain('PASS');
216
- expect(output).not.toContain('NaN');
217
- });
218
-
219
- it('should flag a malformed summary instead of silently treating it as clean', () => {
220
- // Round 5, three seats independently: zeroing a non-numeric count stops the
221
- // permanent-FAIL bug but also swallows an upstream defect -- a corrupted
222
- // summary would read as "nothing to report". Keep the non-blocking verdict
223
- // (crashing the reporter would be worse) but say so in the output.
224
- const corrupted = {
225
- violations: [],
226
- summary: summaryOf(1, Number.NaN, 0, 0, 1, 1),
227
- ...emptyResults(1),
228
- } as unknown as AnalysisResult;
229
-
230
- const output = formatSummary(corrupted);
231
- expect(output).toMatch(/malformed|invalid|corrupt/i);
232
- // The damaged field must be named, so a reader can tell WHICH count is
233
- // untrustworthy. Echoing the raw value is the point of the diagnostic --
234
- // only the verdict must never be decided by it.
235
- expect(output).toContain('errorCount');
236
- expect(output).toContain('PASS');
237
- });
238
-
239
- it('should show PASS when the only findings are info (info is log-only)', () => {
240
- // AGENTS.md: info = "log only". An info finding is how a rule says "I
241
- // could not judge this file" (the arch layout diagnostic), so treating it
242
- // as a failure would block a commit for a blind spot rather than a defect.
243
- const infoOnly: AnalysisResult = {
244
- violations: [
245
- violation("java/com/acme/UserController.java", 1, "arch.controller", "Skipped: no recognisable Java source root", "info")
246
- ],
247
- summary: summaryOf(1, 0, 0, 1, 1, 1),
248
- ...emptyResults(1),
249
- };
250
- const output = formatSummary(infoOnly);
251
- expect(output).toContain('PASS');
252
- expect(output).not.toContain('FAIL');
253
- });
254
-
255
- it('should show PASS when no violations', () => {
256
- const emptyResult: AnalysisResult = {
257
- violations: [],
258
- summary: summaryOf(0, 0, 0, 0, 5, 3),
259
- ...emptyResults(50),
260
- };
261
-
262
- const output = formatSummary(emptyResult);
263
-
264
- expect(output).toContain('PASS');
265
- });
266
-
267
- it('should show error count when severity has errors', () => {
268
- const errorResult: AnalysisResult = {
269
- violations: [
270
- violation("src/auth.ts", 5, "solid.srp", "Class handles both auth and logging", "error")
271
- ],
272
- summary: summaryOf(1, 1, 0, 0, 1, 1),
273
- ...emptyResults(30),
274
- };
275
-
276
- const output = formatSummary(errorResult);
277
-
278
- expect(output).toContain('1 errors');
279
- expect(output).toContain('0 warnings');
280
- });
281
- });
282
-
283
- describe('formatSARIF', () => {
284
- it('should return valid SARIF JSON with version 2.1.0', () => {
285
- const result: AnalysisResult = {
286
- violations: [sampleViolation],
287
- summary: summaryOf(1, 0, 1, 0, 1, 1),
288
- fileResults: {},
289
- ruleResults: {
290
- 'clean-code.long-function': { violationCount: 1, filesChecked: 1 }
291
- },
292
- executionTimeMs: 100,
293
- errors: []
294
- };
295
-
296
- const output = formatSARIF(result);
297
- const parsed = JSON.parse(output);
298
-
299
- expect(parsed.version).toBe('2.1.0');
300
- expect(parsed.$schema).toContain('sarif-schema-2.1.0');
301
- });
302
-
303
- it('should include runs array with tool driver info', () => {
304
- const result: AnalysisResult = {
305
- violations: [sampleViolation],
306
- summary: summaryOf(1, 0, 1, 0, 3, 2),
307
- fileResults: {},
308
- ruleResults: {
309
- 'clean-code.long-function': { violationCount: 1, filesChecked: 3 }
310
- },
311
- executionTimeMs: 95,
312
- errors: []
313
- };
314
-
315
- const output = formatSARIF(result);
316
- const parsed = JSON.parse(output);
317
-
318
- expect(parsed.runs).toBeDefined();
319
- expect(parsed.runs).toHaveLength(1);
320
- expect(parsed.runs[0].tool.driver.name).toBe('Principles Checker');
321
- expect(parsed.runs[0].tool.driver.version).toBe('1.0.0');
322
- });
323
-
324
- it('should map violations to SARIF results with correct levels', () => {
325
- const result: AnalysisResult = {
326
- violations: [
327
- violation("src/auth.ts", 5, "solid.srp", "Multiple responsibilities", "error", 10),
328
- violation("src/utils.ts", 20, "clean-code.long-function", "Function too long", "warning"),
329
- violation("src/config.ts", 3, "clean-code.magic-numbers", "Magic number 42", "info")
330
- ],
331
- summary: summaryOf(3, 1, 1, 1, 3, 3),
332
- fileResults: {},
333
- ruleResults: {
334
- 'solid.srp': { violationCount: 1, filesChecked: 1 },
335
- 'clean-code.long-function': { violationCount: 1, filesChecked: 1 },
336
- 'clean-code.magic-numbers': { violationCount: 1, filesChecked: 1 }
337
- },
338
- executionTimeMs: 200,
339
- errors: []
340
- };
341
-
342
- const output = formatSARIF(result);
343
- const parsed = JSON.parse(output);
344
- const results = parsed.runs[0].results;
345
-
346
- expect(results).toHaveLength(3);
347
- expect(results[0].level).toBe('error');
348
- expect(results[1].level).toBe('warning');
349
- expect(results[2].level).toBe('note');
350
- });
351
-
352
- it('should include file, line, and column in result locations', () => {
353
- const result: AnalysisResult = {
354
- violations: [
355
- violation("src/api.ts", 42, "clean-code.deep-nesting", "Nesting depth 6 exceeds threshold 4", "warning", 15)
356
- ],
357
- summary: summaryOf(1, 0, 1, 0, 1, 1),
358
- fileResults: {},
359
- ruleResults: {
360
- 'clean-code.deep-nesting': { violationCount: 1, filesChecked: 1 }
361
- },
362
- executionTimeMs: 80,
363
- errors: []
364
- };
365
-
366
- const output = formatSARIF(result);
367
- const parsed = JSON.parse(output);
368
- const location = parsed.runs[0].results[0].locations[0].physicalLocation;
369
-
370
- expect(location.artifactLocation.uri).toBe('src/api.ts');
371
- expect(location.region.startLine).toBe(42);
372
- expect(location.region.startColumn).toBe(15);
373
- });
374
-
375
- it('should default column to 1 when violation has no column', () => {
376
- const result: AnalysisResult = {
377
- violations: [
378
- violation("src/big.ts", 500, "clean-code.large-file", "File too large", "warning")
379
- ],
380
- summary: summaryOf(1, 0, 1, 0, 1, 1),
381
- fileResults: {},
382
- ruleResults: {
383
- 'clean-code.large-file': { violationCount: 1, filesChecked: 1 }
384
- },
385
- executionTimeMs: 50,
386
- errors: []
387
- };
388
-
389
- const output = formatSARIF(result);
390
- const parsed = JSON.parse(output);
391
- const location = parsed.runs[0].results[0].locations[0].physicalLocation;
392
-
393
- expect(location.region.startColumn).toBe(1);
394
- });
395
-
396
- it('should include ruleDescriptors for all rules in ruleResults', () => {
397
- const result: AnalysisResult = {
398
- violations: [sampleViolation],
399
- summary: summaryOf(1, 0, 1, 0, 2, 2),
400
- fileResults: {},
401
- ruleResults: {
402
- 'clean-code.long-function': { violationCount: 1, filesChecked: 2 },
403
- 'clean-code.missing-error-handling': { violationCount: 0, filesChecked: 2 }
404
- },
405
- executionTimeMs: 60,
406
- errors: []
407
- };
408
-
409
- const output = formatSARIF(result);
410
- const parsed = JSON.parse(output);
411
- const rules = parsed.runs[0].tool.driver.rules;
412
-
413
- expect(rules).toHaveLength(2);
414
- expect(rules[0].id).toBe('clean-code.long-function');
415
- expect(rules[0].shortDescription.text).toContain('Function');
416
- expect(rules[1].id).toBe('clean-code.missing-error-handling');
417
- expect(rules[1].shortDescription.text).toContain('error handling');
418
- });
419
-
420
- it('should include execution properties (filesChecked, rulesRun, executionTimeMs)', () => {
421
- const result: AnalysisResult = {
422
- violations: [],
423
- summary: summaryOf(0, 0, 0, 0, 10, 5),
424
- fileResults: {},
425
- ruleResults: {
426
- 'clean-code.long-function': { violationCount: 0, filesChecked: 10 }
427
- },
428
- executionTimeMs: 150,
429
- errors: []
430
- };
431
-
432
- const output = formatSARIF(result);
433
- const parsed = JSON.parse(output);
434
- const props = parsed.runs[0].properties;
435
-
436
- expect(props.filesChecked).toBe(10);
437
- expect(props.rulesRun).toBe(5);
438
- expect(props.executionTimeMs).toBe(150);
439
- });
440
-
441
- it('should return empty results array when no violations', () => {
442
- const result: AnalysisResult = {
443
- violations: [],
444
- summary: summaryOf(0, 0, 0, 0, 5, 3),
445
- fileResults: {},
446
- ruleResults: {
447
- 'clean-code.long-function': { violationCount: 0, filesChecked: 5 }
448
- },
449
- executionTimeMs: 30,
450
- errors: []
451
- };
452
-
453
- const output = formatSARIF(result);
454
- const parsed = JSON.parse(output);
455
-
456
- expect(parsed.runs[0].results).toEqual([]);
457
- });
458
-
459
- it('should map DIP violation to error level when violation severity is error', () => {
460
- const result: AnalysisResult = {
461
- violations: [
462
- violation("src/service.ts", 8, "solid.dip", "Direct instantiation detected", "error", 1)
463
- ],
464
- summary: summaryOf(1, 1, 0, 0, 1, 1),
465
- fileResults: {},
466
- ruleResults: {
467
- 'solid.dip': { violationCount: 1, filesChecked: 1 }
468
- },
469
- executionTimeMs: 25,
470
- errors: []
471
- };
472
-
473
- const output = formatSARIF(result);
474
- const parsed = JSON.parse(output);
475
-
476
- expect(parsed.runs[0].results[0].level).toBe('error');
477
- });
478
-
479
- it('should include ruleDescriptors with defaultConfiguration levels', () => {
480
- const result: AnalysisResult = {
481
- violations: [],
482
- summary: summaryOf(0, 0, 0, 0, 1, 3),
483
- fileResults: {},
484
- ruleResults: {
485
- 'solid.srp': { violationCount: 0, filesChecked: 1 },
486
- 'clean-code.long-function': { violationCount: 0, filesChecked: 1 },
487
- 'clean-code.magic-numbers': { violationCount: 0, filesChecked: 1 }
488
- },
489
- executionTimeMs: 40,
490
- errors: []
491
- };
492
-
493
- const output = formatSARIF(result);
494
- const parsed = JSON.parse(output);
495
- const rules = parsed.runs[0].tool.driver.rules;
496
-
497
- const srpRule = rules.find((r: { id: string }) => r.id === 'solid.srp');
498
- const longFuncRule = rules.find((r: { id: string }) => r.id === 'clean-code.long-function');
499
- const magicNumRule = rules.find((r: { id: string }) => r.id === 'clean-code.magic-numbers');
500
-
501
- expect(srpRule.defaultConfiguration.level).toBe('error');
502
- expect(longFuncRule.defaultConfiguration.level).toBe('warning');
503
- expect(magicNumRule.defaultConfiguration.level).toBe('note');
504
- });
505
- });
506
-
507
- describe('formatConsole - additional cases', () => {
508
- it('should show error severity with ✗ icon', () => {
509
- const errorResult: AnalysisResult = {
510
- violations: [
511
- violation("src/auth.ts", 5, "solid.srp", "Multiple responsibilities", "error", 1)
512
- ],
513
- summary: summaryOf(1, 1, 0, 0, 1, 1),
514
- ...emptyResults(30),
515
- };
516
-
517
- const output = formatConsole(errorResult);
518
-
519
- expect(output).toContain('✗');
520
- expect(output).toContain('ERROR');
521
- });
522
-
523
- it('should show info severity with ℹ icon', () => {
524
- const infoResult: AnalysisResult = {
525
- violations: [
526
- violation("src/config.ts", 3, "clean-code.magic-numbers", "Magic number 42", "info", 10)
527
- ],
528
- summary: summaryOf(1, 0, 0, 1, 1, 1),
529
- ...emptyResults(20),
530
- };
531
-
532
- const output = formatConsole(infoResult);
533
-
534
- expect(output).toContain('ℹ');
535
- expect(output).toContain('INFO');
536
- });
537
-
538
- it('should handle violations without column number', () => {
539
- const noColumnResult: AnalysisResult = {
540
- violations: [
541
- violation("src/big.ts", 600, "clean-code.large-file", "File is too large: 600 lines (maximum: 500)", "warning")
542
- ],
543
- summary: summaryOf(1, 0, 1, 0, 1, 1),
544
- ...emptyResults(25),
545
- };
546
-
547
- const output = formatConsole(noColumnResult);
548
-
549
- expect(output).toContain('line 600');
550
- expect(output).not.toContain('col');
551
- });
552
-
553
- it('should include analysis errors only when violations exist', () => {
554
- const resultWithErrors: AnalysisResult = {
555
- violations: [
556
- violation("src/test.ts", 5, "clean-code.long-function", "Function too long", "warning", 1)
557
- ],
558
- summary: summaryOf(1, 0, 1, 0, 2, 1),
559
- ...emptyResults(50),
560
- errors: [
561
- 'Rule clean-code.long-function failed on src/corrupt.ts: Parse error',
562
- 'Rule solid.srp failed on src/broken.ts: Timeout'
563
- ]
564
- };
565
-
566
- const output = formatConsole(resultWithErrors);
567
-
568
- expect(output).toContain('Analysis errors');
569
- expect(output).toContain('Parse error');
570
- expect(output).toContain('Timeout');
571
- });
572
-
573
- it('should not show analysis errors section when errors array is empty', () => {
574
- const emptyResult: AnalysisResult = {
575
- violations: [],
576
- summary: summaryOf(0, 0, 0, 0, 5, 3),
577
- ...emptyResults(50),
578
- };
579
-
580
- const output = formatConsole(emptyResult);
581
-
582
- expect(output).not.toContain('Analysis errors');
583
- });
584
-
585
- it('should show files checked in empty violations output', () => {
586
- const emptyResult: AnalysisResult = {
587
- violations: [],
588
- summary: summaryOf(0, 0, 0, 0, 15, 8),
589
- ...emptyResults(75),
590
- };
591
-
592
- const output = formatConsole(emptyResult);
593
-
594
- expect(output).toContain('Files checked: 15');
595
- expect(output).toContain('Rules run: 8');
596
- expect(output).toContain('75ms');
597
- });
598
-
599
- it('should include summary section with violation details', () => {
600
- const mixedResult: AnalysisResult = {
601
- violations: [
602
- violation("src/a.ts", 5, "solid.srp", "SRP violation", "error", 1),
603
- violation("src/b.ts", 10, "clean-code.long-function", "Too long", "warning")
604
- ],
605
- summary: summaryOf(2, 1, 1, 0, 2, 2),
606
- ...emptyResults(60),
607
- };
608
-
609
- const output = formatConsole(mixedResult);
610
-
611
- expect(output).toContain('2 violations total');
612
- expect(output).toContain('1 errors');
613
- expect(output).toContain('1 warnings');
614
- expect(output).toContain('2 files checked');
615
- expect(output).toContain('2 rules run');
616
- });
617
- });
618
-
619
- describe('formatJSON - additional cases', () => {
620
- it('should include empty arrays for no violations', () => {
621
- const emptyResult: AnalysisResult = {
622
- violations: [],
623
- summary: summaryOf(0, 0, 0, 0, 5, 3),
624
- ...emptyResults(30),
625
- };
626
-
627
- const output = formatJSON(emptyResult);
628
- const parsed = JSON.parse(output);
629
-
630
- expect(parsed.violations).toEqual([]);
631
- expect(parsed.errors).toEqual([]);
632
- expect(parsed.executionTimeMs).toBe(30);
633
- });
634
-
635
- it('should include all fields: violations, summary, fileResults, ruleResults, executionTimeMs, errors', () => {
636
- const result: AnalysisResult = {
637
- violations: [sampleViolation],
638
- summary: summaryOf(1, 0, 1, 0, 3, 2),
639
- fileResults: {
640
- 'src/test.ts': { violations: [sampleViolation], ruleIds: ['clean-code.long-function'] }
641
- },
642
- ruleResults: {
643
- 'clean-code.long-function': { violationCount: 1, filesChecked: 3 }
644
- },
645
- executionTimeMs: 120,
646
- errors: ['Some analysis error']
647
- };
648
-
649
- const output = formatJSON(result);
650
- const parsed = JSON.parse(output);
651
-
652
- expect(parsed.violations).toHaveLength(1);
653
- expect(parsed.summary.totalViolations).toBe(1);
654
- expect(parsed.fileResults['src/test.ts'].ruleIds).toContain('clean-code.long-function');
655
- expect(parsed.ruleResults['clean-code.long-function'].violationCount).toBe(1);
656
- expect(parsed.executionTimeMs).toBe(120);
657
- expect(parsed.errors).toEqual(['Some analysis error']);
658
- });
659
- });
660
- });