@boyingliu01/xp-gate 0.38.75 → 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 (111) 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/lib/hooks.d.ts +10 -1
  10. package/plugins/dsh/lib/hooks.d.ts.map +1 -1
  11. package/plugins/dsh/lib/hooks.js +56 -5
  12. package/plugins/dsh/lib/index.js +6 -1
  13. package/plugins/dsh/package.json +1 -1
  14. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  15. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  16. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  17. package/plugins/dsh/src/hooks.test.ts +70 -0
  18. package/plugins/dsh/src/hooks.ts +66 -5
  19. package/plugins/dsh/src/index.ts +6 -1
  20. package/plugins/opencode/package.json +1 -1
  21. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  22. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  23. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  24. package/plugins/qoder/plugin.json +1 -1
  25. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  26. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  27. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  28. package/scripts/generate-mirrors.cjs +10 -0
  29. package/skills/delphi-review/AGENTS.md +1 -1
  30. package/skills/sprint-flow/AGENTS.md +1 -1
  31. package/skills/test-specification-alignment/AGENTS.md +1 -1
  32. package/mock-policy/__tests__/config.test.ts +0 -292
  33. package/mock-policy/__tests__/gate-m3.test.ts +0 -379
  34. package/mock-policy/__tests__/integration.test.ts +0 -600
  35. package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
  36. package/mock-policy/__tests__/schema.test.ts +0 -239
  37. package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
  38. package/mutation/__tests__/detect-ai-test.test.ts +0 -152
  39. package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
  40. package/mutation/__tests__/gate-m.test.ts +0 -246
  41. package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
  42. package/mutation/__tests__/gremlins-runner.test.ts +0 -167
  43. package/mutation/__tests__/init-baseline.test.ts +0 -347
  44. package/mutation/__tests__/mutation-mirror.test.ts +0 -49
  45. package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
  46. package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
  47. package/mutation/__tests__/pitest-runner.test.ts +0 -574
  48. package/mutation/__tests__/runners-index.test.ts +0 -162
  49. package/mutation/__tests__/stryker-runner.test.ts +0 -455
  50. package/mutation/__tests__/test-filter-parity.test.ts +0 -40
  51. package/mutation/__tests__/update-baseline.test.ts +0 -395
  52. package/principles/__tests__/adapter-metrics.test.ts +0 -292
  53. package/principles/__tests__/analyze-read-failure.test.ts +0 -70
  54. package/principles/__tests__/analyzer.test.ts +0 -367
  55. package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
  56. package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
  57. package/principles/__tests__/baseline-prune.test.ts +0 -399
  58. package/principles/__tests__/baseline-storage.test.ts +0 -188
  59. package/principles/__tests__/baseline.test.ts +0 -330
  60. package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
  61. package/principles/__tests__/boy-scout-integration.test.ts +0 -355
  62. package/principles/__tests__/boy-scout.test.ts +0 -893
  63. package/principles/__tests__/cli-files-separators.test.ts +0 -69
  64. package/principles/__tests__/config-arch-group.test.ts +0 -106
  65. package/principles/__tests__/config-enforcement.test.ts +0 -470
  66. package/principles/__tests__/config-git-timeout.test.ts +0 -66
  67. package/principles/__tests__/config-merge-warnings.test.ts +0 -148
  68. package/principles/__tests__/config.test.ts +0 -78
  69. package/principles/__tests__/direct-execution.test.ts +0 -187
  70. package/principles/__tests__/index.test.ts +0 -94
  71. package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
  72. package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
  73. package/principles/__tests__/lint-baseline.test.ts +0 -314
  74. package/principles/__tests__/many-exports-reexport.test.ts +0 -40
  75. package/principles/__tests__/reporter.test.ts +0 -660
  76. package/principles/__tests__/types.test.ts +0 -103
  77. package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
  78. package/principles/adapters/__tests__/base.test.ts +0 -95
  79. package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
  80. package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
  81. package/principles/adapters/__tests__/cpp.test.ts +0 -290
  82. package/principles/adapters/__tests__/dart.test.ts +0 -84
  83. package/principles/adapters/__tests__/go.test.ts +0 -68
  84. package/principles/adapters/__tests__/java.test.ts +0 -385
  85. package/principles/adapters/__tests__/kotlin.test.ts +0 -76
  86. package/principles/adapters/__tests__/objectivec.test.ts +0 -453
  87. package/principles/adapters/__tests__/python.test.ts +0 -84
  88. package/principles/adapters/__tests__/swift.test.ts +0 -68
  89. package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
  90. package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
  91. package/principles/adapters/__tests__/typescript.test.ts +0 -116
  92. package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
  93. package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
  94. package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
  95. package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
  96. package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
  97. package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
  98. package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
  99. package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
  100. package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
  101. package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
  102. package/principles/rules/__tests__/index.test.ts +0 -49
  103. package/principles/rules/__tests__/solid/dip.test.ts +0 -119
  104. package/principles/rules/__tests__/solid/isp.test.ts +0 -58
  105. package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
  106. package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
  107. package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
  108. package/principles/rules/__tests__/solid/srp.test.ts +0 -87
  109. package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
  110. package/principles/rules/arch/__tests__/naming.test.ts +0 -133
  111. package/principles/rules/arch/__tests__/shared.test.ts +0 -113
@@ -1,399 +0,0 @@
1
- /**
2
- * @test REQ-452 REQ-3
3
- * @intent A baseline entry for a file that no longer exists must not be kept
4
- * forever. Previously `classifyFiles` parsed `deleted` but nothing
5
- * consumed it, so `.warnings-baseline.json` accumulated stale entries
6
- * that let a re-created file inherit a bogus allowance.
7
- * @covers AC-452-10, AC-452-11, AC-452-12, AC-452-13, AC-452-14
8
- *
9
- * The removal is deliberately DOUBLE-CONFIRMED: a path is only treated as
10
- * deleted when the filesystem says it is absent AND git no longer tracks it.
11
- * Either signal alone produces false positives -- a sparse checkout, a rebase
12
- * mid-flight, a case-insensitive filesystem, or a symlink all make an existing
13
- * tracked file look "missing".
14
- */
15
-
16
- import { execFileSync } from 'node:child_process';
17
- import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
18
- import { tmpdir } from 'node:os';
19
- import { join } from 'node:path';
20
- import { afterEach, describe, expect, it } from 'vitest';
21
- import { pruneBaselineEntries } from '../baseline-prune';
22
-
23
- const tempDirs: string[] = [];
24
-
25
- function makeTempDir(): string {
26
- const dir = mkdtempSync(join(tmpdir(), 'xpgate-452-'));
27
- tempDirs.push(dir);
28
- return dir;
29
- }
30
-
31
- /** Create a git repo with one committed file, and return its root. */
32
- function makeRepoWithCommit(): { root: string; tracked: string } {
33
- const root = makeTempDir();
34
- const tracked = 'tracked.ts';
35
- const run = (args: string[]): void => {
36
- try {
37
- execFileSync('git', args, { cwd: root, stdio: 'ignore' });
38
- } catch (error) {
39
- const detail = error instanceof Error ? error.message : String(error);
40
- throw new Error(`git ${args.join(' ')} failed in ${root}: ${detail}`);
41
- }
42
- };
43
- try {
44
- writeFileSync(join(root, tracked), 'export const a = 1;\n', 'utf8');
45
- } catch (error) {
46
- const detail = error instanceof Error ? error.message : String(error);
47
- throw new Error(`could not seed repo file: ${detail}`);
48
- }
49
- run(['init', '-b', 'main']);
50
- run(['config', 'user.email', 'test@example.com']);
51
- run(['config', 'user.name', 'Test']);
52
- // This fixture is scaffolding, not a real commit: the global XP-Gate hooks are
53
- // installed on this machine and would otherwise block the seed commit
54
- // (Gate 5a rejects an untested source file). `core.hooksPath` is set to a
55
- // non-existent path rather than using --no-verify so the intent is explicit
56
- // and cannot be mistaken for bypassing this repository's own gates.
57
- run(['config', 'core.hooksPath', join(root, '.no-hooks')]);
58
- run(['add', tracked]);
59
- run(['commit', '-m', 'seed']);
60
- return { root, tracked };
61
- }
62
-
63
- /**
64
- * Stage many paths at once, to push `git ls-files` output past the 1 MiB default
65
- * stdout buffer that `execFileSync` would otherwise apply.
66
- *
67
- * Uses `git update-index --index-info` to write the index directly rather than
68
- * creating files and running `git add`: that path costs over 50s for this many
69
- * entries (filesystem + index churn), whereas feeding the index in one batch takes
70
- * under a second. The blob hash is git's well-known empty-blob id, so nothing needs
71
- * to exist on disk -- which is fine, because the assertion is about `git ls-files`
72
- * reporting the index, not about the working tree.
73
- */
74
- function stageManyPaths(root: string, count: number, nameFor: (index: number) => string): void {
75
- const EMPTY_BLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391';
76
- const lines: string[] = [];
77
- for (let i = 0; i < count; i += 1) {
78
- lines.push(`100644 ${EMPTY_BLOB}\t${nameFor(i)}`);
79
- }
80
- try {
81
- execFileSync('git', ['update-index', '--index-info'], {
82
- cwd: root,
83
- input: `${lines.join('\n')}\n`,
84
- stdio: ['pipe', 'ignore', 'ignore'],
85
- });
86
- } catch (error) {
87
- const detail = error instanceof Error ? error.message : String(error);
88
- throw new Error(`could not stage filler paths: ${detail}`);
89
- }
90
- }
91
-
92
- /**
93
- * A baseline shaped like the real `.warnings-baseline.json` payload.
94
- *
95
- * The on-disk format is a FLAT path -> entry map, verified against the committed
96
- * file; there is no `files` wrapper.
97
- */
98
- function baselineWith(paths: string[]): string {
99
- const files: Record<string, unknown> = {};
100
- for (const path of paths) {
101
- files[path] = { totalWarnings: 3, lastAnalyzed: '2026-10-03T00:00:00.000Z' };
102
- }
103
- return JSON.stringify(files);
104
- }
105
-
106
- /**
107
- * Stage exact paths in the index without creating working-tree files.
108
- *
109
- * Index-only staging is what makes the case-sensitivity assertions portable:
110
- * neither spelling exists on disk (so the `existsSync` half of the double-confirm
111
- * is false everywhere), and the only signal left is the comparison against the
112
- * git index -- which is exactly the behavior under test. The blob hash is git's
113
- * well-known empty-blob id, so nothing needs to exist on disk.
114
- */
115
- function stageIndexOnly(root: string, paths: string[]): void {
116
- const EMPTY_BLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391';
117
- const input = paths.map((path) => `100644 ${EMPTY_BLOB}\t${path}`).join('\n');
118
- try {
119
- execFileSync('git', ['update-index', '--index-info'], {
120
- cwd: root,
121
- input: `${input}\n`,
122
- stdio: ['pipe', 'ignore', 'ignore'],
123
- });
124
- } catch (error) {
125
- const detail = error instanceof Error ? error.message : String(error);
126
- throw new Error(`could not stage index paths: ${detail}`);
127
- }
128
- }
129
-
130
- afterEach(() => {
131
- for (const dir of tempDirs.splice(0)) {
132
- try {
133
- rmSync(dir, { recursive: true, force: true });
134
- } catch {
135
- /* best effort */
136
- }
137
- }
138
- });
139
-
140
- describe('#452 REQ-3 stale baseline entries are pruned', () => {
141
- it('AC-452-10: a path that is absent AND untracked is reported for removal', () => {
142
- const { root } = makeRepoWithCommit();
143
- const stale = 'gone-forever.ts';
144
-
145
- const result = pruneBaselineEntries(baselineWith([stale]), root);
146
-
147
- expect(result.removed).toContain(stale);
148
- expect(result.kept).not.toContain(stale);
149
- });
150
-
151
- it('AC-452-11: an existing tracked file is KEPT even when absent from disk', () => {
152
- // Simulates a sparse checkout / mid-rebase / symlinked worktree: the file
153
- // is gone from the working tree but git still tracks it. Removing the entry
154
- // here would silently discard a legitimate allowance.
155
- const { root, tracked } = makeRepoWithCommit();
156
- rmSync(join(root, tracked));
157
-
158
- const result = pruneBaselineEntries(baselineWith([tracked]), root);
159
-
160
- expect(result.kept).toContain(tracked);
161
- expect(result.removed).not.toContain(tracked);
162
- });
163
-
164
- it('AC-452-12: a file present on disk is kept', () => {
165
- const { root, tracked } = makeRepoWithCommit();
166
-
167
- const result = pruneBaselineEntries(baselineWith([tracked]), root);
168
-
169
- expect(result.kept).toContain(tracked);
170
- expect(result.removed).toHaveLength(0);
171
- });
172
-
173
- it('AC-452-13: an untracked-but-present file is kept (git is not authoritative alone)', () => {
174
- const { root } = makeRepoWithCommit();
175
- const untracked = 'untracked.ts';
176
- mkdirSync(root, { recursive: true });
177
- try {
178
- writeFileSync(join(root, untracked), 'export const b = 2;\n', 'utf8');
179
- } catch (error) {
180
- const detail = error instanceof Error ? error.message : String(error);
181
- throw new Error(`could not write untracked file: ${detail}`);
182
- }
183
-
184
- const result = pruneBaselineEntries(baselineWith([untracked]), root);
185
-
186
- expect(result.kept).toContain(untracked);
187
- });
188
-
189
- it('AC-452-10: pruning is non-destructive — it never mutates the input', () => {
190
- const { root } = makeRepoWithCommit();
191
- const input = baselineWith(['gone-forever.ts', 'also-gone.ts']);
192
-
193
- pruneBaselineEntries(input, root);
194
-
195
- // The caller decides when to persist; the helper must not rewrite in place.
196
- const parsed = JSON.parse(input) as Record<string, unknown>;
197
- expect(Object.keys(parsed)).toHaveLength(2);
198
- });
199
-
200
- it('AC-452-11: every entry is preserved when git is unavailable', () => {
201
- // A non-repo directory means `git ls-files` fails. Failing closed (keep
202
- // everything) is safer than deleting entries we cannot confirm.
203
- const dir = makeTempDir();
204
- const paths = ['a.ts', 'b.ts'];
205
-
206
- const result = pruneBaselineEntries(baselineWith(paths), dir);
207
-
208
- expect(result.kept.sort()).toEqual(paths);
209
- expect(result.removed).toHaveLength(0);
210
- });
211
-
212
- it('AC-452-13: an empty baseline yields empty kept/removed lists', () => {
213
- const { root } = makeRepoWithCommit();
214
-
215
- const result = pruneBaselineEntries(baselineWith([]), root);
216
-
217
- expect(result.kept).toHaveLength(0);
218
- expect(result.removed).toHaveLength(0);
219
- });
220
-
221
- it('AC-452-12: a malformed baseline is preserved rather than silently emptied', () => {
222
- // The reporter's `{}` came from this path. Keeping the entries and
223
- // reporting an error is the fail-safe behaviour.
224
- const { root } = makeRepoWithCommit();
225
-
226
- const result = pruneBaselineEntries('{ not json', root);
227
-
228
- expect(result.removed).toHaveLength(0);
229
- expect(result.error).toBeDefined();
230
- });
231
-
232
- it('AC-452-10: pruning still works when the git index exceeds the default pipe buffer', () => {
233
- // `execFileSync` defaults to a 1 MiB stdout buffer. A repo whose `git
234
- // ls-files` output exceeds it throws, which `listTrackedFiles` would report
235
- // as "git unavailable" -- silently disabling pruning at exactly the scale
236
- // where a stale baseline is most likely. Committing enough paths to blow past
237
- // 1 MiB proves the raised maxBuffer is actually in effect: without it every
238
- // entry is merely "kept" and the stale path below would never be reported.
239
- const { root } = makeRepoWithCommit();
240
- // Measured: each path is ~48 bytes once `git ls-files` newline-joins it, so
241
- // 1 MiB / 48 = ~21.8k entries. Use 30000 (~1.4 MiB) so the threshold is
242
- // cleared with real headroom rather than marginally -- an earlier version used
243
- // 19000, which came to 0.88 MiB and passed even with the buffer bug present.
244
- stageManyPaths(root, 30000, (i) => `filler/s${i}/a-fairly-long-file-name-padding.ts`);
245
-
246
- const result = pruneBaselineEntries(baselineWith(['deleted-long-ago.ts']), root);
247
-
248
- expect(result.removed).toEqual(['deleted-long-ago.ts']);
249
- expect(result.error).toBeUndefined();
250
- });
251
-
252
- it('AC-452-14: on a case-sensitive filesystem the index path is the canonical form', () => {
253
- // Two tracked files whose names differ only by case are two DIFFERENT files on
254
- // Linux. A baseline key that matches neither spelling exactly is a phantom:
255
- // folding it to `case/alpha.ts` used to match the index and retain the entry
256
- // forever -- the same stale-allowance bug this module exists to remove, since
257
- // re-creating `case/ALPHA.ts` would inherit the retained allowance.
258
- const { root } = makeRepoWithCommit();
259
- stageIndexOnly(root, ['case/Alpha.ts', 'case/alpha.ts']);
260
-
261
- const result = pruneBaselineEntries(
262
- baselineWith(['case/ALPHA.ts']),
263
- root,
264
- { caseInsensitivePaths: false },
265
- );
266
-
267
- expect(result.removed).toEqual(['case/ALPHA.ts']);
268
- expect(result.kept).toHaveLength(0);
269
- });
270
-
271
- it('AC-452-14: a case-sensitive filesystem does not conflate a differently-cased key with a tracked path', () => {
272
- const { root } = makeRepoWithCommit();
273
- stageIndexOnly(root, ['src/Tracked.ts']);
274
-
275
- const result = pruneBaselineEntries(
276
- baselineWith(['src/tracked.ts']),
277
- root,
278
- { caseInsensitivePaths: false },
279
- );
280
-
281
- expect(result.removed).toEqual(['src/tracked.ts']);
282
- });
283
-
284
- it('AC-452-14: an exact index match is kept on a case-sensitive filesystem', () => {
285
- // Guards against the opposite regression: dropping the fold must not turn a
286
- // legitimately tracked path into a prunable one.
287
- const { root } = makeRepoWithCommit();
288
- stageIndexOnly(root, ['case/alpha.ts']);
289
-
290
- const result = pruneBaselineEntries(
291
- baselineWith(['case/alpha.ts']),
292
- root,
293
- { caseInsensitivePaths: false },
294
- );
295
-
296
- expect(result.kept).toContain('case/alpha.ts');
297
- expect(result.removed).toHaveLength(0);
298
- });
299
-
300
- it('AC-452-14: a case-insensitive filesystem keeps the retain-bias for a differently-cased key', () => {
301
- // On Windows (and macOS default volumes) `src/tracked.ts` and `src/Tracked.ts`
302
- // are the same file, and the key can be written by a tool that reported a
303
- // different casing than the index. Losing that allowance in a sparse checkout
304
- // -- when `existsSync` cannot confirm either spelling -- is the failure mode
305
- // the original fold was introduced to prevent, so case-folding stays enabled
306
- // exactly where the filesystem actually folds.
307
- const { root } = makeRepoWithCommit();
308
- stageIndexOnly(root, ['src/Tracked.ts']);
309
-
310
- const result = pruneBaselineEntries(
311
- baselineWith(['src/tracked.ts']),
312
- root,
313
- { caseInsensitivePaths: true },
314
- );
315
-
316
- expect(result.kept).toContain('src/tracked.ts');
317
- expect(result.removed).toHaveLength(0);
318
- });
319
-
320
- it('AC-452-14: the default follows the host filesystem, not a hardcoded assumption', () => {
321
- // This repository's own tests must stay portable: Linux CI and this Windows
322
- // checkout have to disagree here, because the correct answer IS platform
323
- // dependent. The assertion pins the wiring (default = detection) rather than a
324
- // single outcome.
325
- const { root } = makeRepoWithCommit();
326
- stageIndexOnly(root, ['src/Tracked.ts']);
327
-
328
- const result = pruneBaselineEntries(baselineWith(['src/tracked.ts']), root);
329
- const folded = process.platform === 'win32' || process.platform === 'darwin';
330
-
331
- if (folded) {
332
- expect(result.kept).toContain('src/tracked.ts');
333
- expect(result.removed).toHaveLength(0);
334
- } else {
335
- expect(result.removed).toEqual(['src/tracked.ts']);
336
- }
337
- });
338
- });
339
-
340
- /**
341
- * @test REQ-628
342
- * @intent `parseBaselineFiles` accepts two shapes: the FLAT map that
343
- * `saveBaseline` writes, and a legacy `{files: {...}}` wrapper kept for
344
- * forwards compatibility. The wrapper branch had no test, so deleting it
345
- * left the whole suite green — a silent regression that would make every
346
- * real baseline look empty (all entries filtered out as non-objects,
347
- * since the only top-level key is `files`). These cases pin both shapes
348
- * plus the scalar-filtering rule that follows from them.
349
- * @covers AC-628-01, AC-628-02, AC-628-03
350
- */
351
- describe('#628 REQ-3 parseBaselineFiles shape handling', () => {
352
- it('AC-628-01: a flat map is read entry-for-entry', () => {
353
- const { root } = makeRepoWithCommit();
354
- const flat = JSON.stringify({
355
- 'src/a.ts': { totalWarnings: 2, lastAnalyzed: '2026-01-01T00:00:00Z' },
356
- 'src/gone.ts': { totalWarnings: 1, lastAnalyzed: '2026-01-01T00:00:00Z' },
357
- });
358
- stageIndexOnly(root, ['src/a.ts']);
359
-
360
- const result = pruneBaselineEntries(flat, root);
361
- expect(result.kept).toContain('src/a.ts');
362
- expect(result.removed).toContain('src/gone.ts');
363
- expect(result.error).toBeUndefined();
364
- });
365
-
366
- it('AC-628-02: a {files:{...}} wrapper is unwrapped, not treated as one entry', () => {
367
- const { root } = makeRepoWithCommit();
368
- // Without the unwrap, the sole top-level key `files` is an object, so the
369
- // flat path would yield ONE entry called "files" and silently lose every
370
- // real path. Assert the real paths surface.
371
- const wrapped = JSON.stringify({
372
- files: {
373
- 'src/a.ts': { totalWarnings: 2, lastAnalyzed: '2026-01-01T00:00:00Z' },
374
- 'src/gone.ts': { totalWarnings: 1, lastAnalyzed: '2026-01-01T00:00:00Z' },
375
- },
376
- });
377
- stageIndexOnly(root, ['src/a.ts']);
378
-
379
- const result = pruneBaselineEntries(wrapped, root);
380
- expect(result.kept).toContain('src/a.ts');
381
- expect(result.removed).toContain('src/gone.ts');
382
- expect(result.kept).not.toContain('files');
383
- });
384
-
385
- it('AC-628-03: scalar top-level keys are metadata and are dropped, not kept as entries', () => {
386
- const { root } = makeRepoWithCommit();
387
- const withMeta = JSON.stringify({
388
- version: 2,
389
- generatedAt: '2026-01-01T00:00:00Z',
390
- 'src/a.ts': { totalWarnings: 2, lastAnalyzed: '2026-01-01T00:00:00Z' },
391
- });
392
- stageIndexOnly(root, ['src/a.ts']);
393
-
394
- const result = pruneBaselineEntries(withMeta, root);
395
- expect(result.kept).toEqual(['src/a.ts']);
396
- expect(result.kept).not.toContain('version');
397
- expect(result.kept).not.toContain('generatedAt');
398
- });
399
- });
@@ -1,188 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import fs from 'fs/promises';
3
- import { BaselineStorage, BaselineEntry, filterBaselineWarnings } from '../baseline';
4
-
5
- describe('Baseline Storage', () => {
6
- const mockBaselinePath = '.warnings-baseline.json';
7
- let baselineStorage: BaselineStorage;
8
-
9
- beforeEach(() => {
10
- baselineStorage = new BaselineStorage();
11
- });
12
-
13
- afterEach(() => {
14
- (fs.access as unknown as {mockRestore?: () => void}).mockRestore?.();
15
- (fs.readFile as unknown as {mockRestore?: () => void}).mockRestore?.();
16
- (fs.writeFile as unknown as {mockRestore?: () => void}).mockRestore?.();
17
- vi.resetAllMocks();
18
- });
19
-
20
- it('loads baseline from json file when exists', async () => {
21
- const mockBaseline = {
22
- 'src/example.ts': {
23
- eslint: { warnings: 5, errors: 0 },
24
- totalWarnings: 5,
25
- lastAnalyzed: new Date().toISOString()
26
- }
27
- };
28
-
29
- vi.spyOn(fs, 'access').mockResolvedValue();
30
- vi.spyOn(fs, 'readFile').mockResolvedValue(JSON.stringify(mockBaseline));
31
-
32
- const result = await baselineStorage.load(mockBaselinePath);
33
- expect(result).toEqual(mockBaseline);
34
- });
35
-
36
- it('returns empty baseline when file missing', async () => {
37
- vi.spyOn(fs, 'access').mockRejectedValue(new Error('File does not exist'));
38
-
39
- const result = await baselineStorage.load(mockBaselinePath);
40
- expect(result).toEqual({});
41
- });
42
-
43
- it('saves updated baseline on pass', async () => {
44
- const mockBaseline = {
45
- 'src/example.ts': {
46
- eslint: { warnings: 5, errors: 0 },
47
- totalWarnings: 5,
48
- lastAnalyzed: new Date().toISOString()
49
- }
50
- };
51
-
52
- const writeFileSpy = vi.spyOn(fs, 'writeFile').mockResolvedValue();
53
-
54
- await baselineStorage.save(mockBaselinePath, mockBaseline);
55
-
56
- expect(writeFileSpy).toHaveBeenCalledWith(
57
- mockBaselinePath,
58
- JSON.stringify(mockBaseline, null, 2)
59
- );
60
- });
61
-
62
- it('handles large baselines efficiently', async () => {
63
- const largeBaseline: Record<string, BaselineEntry> = {};
64
- for (let i = 0; i < 100; i++) {
65
- largeBaseline[`src/component-${i}.ts`] = {
66
- eslint: { warnings: 2, errors: 0 },
67
- totalWarnings: 2,
68
- lastAnalyzed: new Date().toISOString()
69
- };
70
- }
71
-
72
- const spyOnWrite = vi.spyOn(fs, 'writeFile').mockResolvedValue();
73
-
74
- await baselineStorage.save(mockBaselinePath, largeBaseline);
75
- expect(spyOnWrite).toHaveBeenCalledWith(
76
- mockBaselinePath,
77
- expect.any(String)
78
- );
79
-
80
- const [calledWithPath, content] = spyOnWrite.mock.calls[0];
81
- expect(calledWithPath).toBe(mockBaselinePath);
82
- expect(JSON.parse(content as string)).toEqual(largeBaseline);
83
- });
84
-
85
- it('validates baseline with proper structure', () => {
86
- const validBaseline = {
87
- 'src/file1.ts': {
88
- eslint: { warnings: 2, errors: 1 },
89
- principles: { warnings: 0, errors: 1 },
90
- ccn: { warnings: 0, max: 3 },
91
- totalWarnings: 2,
92
- lastAnalyzed: new Date().toISOString()
93
- }
94
- };
95
-
96
- expect(() => baselineStorage.validate(validBaseline)).not.toThrow();
97
- });
98
-
99
- it('throws error for invalid baseline', () => {
100
- const invalidBaseline = {
101
- 'src/file1.ts': {
102
- totalWarnings: -5,
103
- lastAnalyzed: new Date().toISOString()
104
- }
105
- };
106
-
107
- expect(() => baselineStorage.validate(invalidBaseline)).toThrow();
108
- });
109
-
110
- it('filters baseline to include only files with warnings', () => {
111
- const baseline = {
112
- 'src/clean1.ts': {
113
- eslint: { warnings: 0, errors: 0 },
114
- totalWarnings: 0,
115
- lastAnalyzed: new Date().toISOString()
116
- },
117
- 'src/warning1.ts': {
118
- eslint: { warnings: 5, errors: 0 },
119
- totalWarnings: 5,
120
- lastAnalyzed: new Date().toISOString()
121
- },
122
- 'src/clean2.ts': {
123
- eslint: { warnings: 0, errors: 0 },
124
- totalWarnings: 0,
125
- lastAnalyzed: new Date().toISOString()
126
- }
127
- };
128
-
129
- const filtered = filterBaselineWarnings(baseline, 1);
130
- expect(Object.keys(filtered)).toHaveLength(1);
131
- expect(filtered['src/warning1.ts']).toBeDefined();
132
- expect(filtered['src/clean1.ts']).toBeUndefined();
133
- expect(filtered['src/clean2.ts']).toBeUndefined();
134
- });
135
-
136
- it('gets summary statistics', () => {
137
- const baseline = {
138
- 'src/file1.ts': {
139
- eslint: { warnings: 2, errors: 1 },
140
- principles: { warnings: 1, errors: 0 },
141
- totalWarnings: 3,
142
- lastAnalyzed: new Date().toISOString()
143
- },
144
- 'src/file2.ts': {
145
- eslint: { warnings: 4, errors: 0 },
146
- principles: { warnings: 0, errors: 2 },
147
- totalWarnings: 4,
148
- lastAnalyzed: new Date().toISOString()
149
- }
150
- };
151
-
152
- const stats = baselineStorage.getSummaryStatistics(baseline);
153
-
154
- expect(stats.totalFiles).toBe(2);
155
- expect(stats.totalWarnings).toBe(7);
156
- expect(stats.averageWarningsPerFile).toBe(3.5);
157
- const richStats = stats as { totalFiles: number; totalWarnings: number; averageWarningsPerFile: number; eslint: { totalWarnings: number; totalErrors: number } };
158
- expect(richStats.eslint.totalWarnings).toBe(6);
159
- expect(richStats.eslint.totalErrors).toBe(1);
160
- });
161
-
162
- it('creates baseline from files with warning data', async () => {
163
- const warningData = [
164
- {
165
- file: 'src/example1.ts',
166
- counts: {
167
- eslint: { warnings: 2, errors: 1 },
168
- totalWarnings: 2
169
- }
170
- },
171
- {
172
- file: 'src/example2.ts',
173
- counts: {
174
- eslint: { warnings: 5, errors: 0 },
175
- principles: { warnings: 1, errors: 0 },
176
- totalWarnings: 6
177
- }
178
- }
179
- ];
180
-
181
- const result = await baselineStorage.createFromFiles(warningData);
182
-
183
- expect(Object.keys(result)).toEqual(['src/example1.ts', 'src/example2.ts']);
184
- expect(result['src/example1.ts'].totalWarnings).toBe(2);
185
- expect(result['src/example2.ts'].totalWarnings).toBe(6);
186
- expect(result['src/example1.ts'].eslint!.warnings).toBe(2);
187
- });
188
- });