@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,167 +0,0 @@
1
- /**
2
- * @intent #410: mutmut 3.x depends on fork() and cannot run natively on
3
- * Windows — Gate M (Python) formed a structural deadlock (installed =>
4
- * always blocked, uninstalled => always skipped). pytest-gremlins is
5
- * architecturally cross-platform (mutation switching, no fork), so it
6
- * becomes the second engine. This runner drives
7
- * `pytest --gremlins` and parses the console report.
8
- * @covers GremlinsRunner availability probe + console report parsing
9
- */
10
-
11
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
12
- import { spawn, execSync, type ChildProcess } from 'child_process';
13
-
14
- vi.mock('child_process', () => ({
15
- spawn: vi.fn(),
16
- execSync: vi.fn(),
17
- }));
18
-
19
- /** Capture the stdout/close callbacks so the test can drive them by hand. */
20
- function mockChild(capture: {
21
- stdout?: (cb: (d: Buffer) => void) => void;
22
- stderr?: (cb: (d: Buffer) => void) => void;
23
- close?: (cb: (code: number | null) => void) => void;
24
- error?: (cb: (e: Error) => void) => void;
25
- }): ChildProcess {
26
- return {
27
- stdout: { on: (_e: string, cb: (d: Buffer) => void) => capture.stdout?.(cb) },
28
- stderr: { on: (_e: string, cb: (d: Buffer) => void) => capture.stderr?.(cb) },
29
- on: (event: string, cb: (arg: never) => void) => {
30
- if (event === 'close') capture.close?.(cb as (code: number | null) => void);
31
- if (event === 'error') capture.error?.(cb as unknown as (e: Error) => void);
32
- },
33
- kill: vi.fn(),
34
- } as unknown as ChildProcess;
35
- }
36
-
37
- describe('GremlinsRunner', () => {
38
- let GremlinsRunner: typeof import('../runners/gremlins-runner').GremlinsRunner;
39
-
40
- beforeEach(async () => {
41
- vi.clearAllMocks();
42
- vi.mocked(execSync).mockReset();
43
- vi.mocked(spawn).mockReset();
44
- vi.mocked(execSync).mockReturnValue('' as never);
45
- GremlinsRunner = (await import('../runners/gremlins-runner')).GremlinsRunner;
46
- });
47
-
48
- afterEach(() => {
49
- vi.useRealTimers();
50
- vi.restoreAllMocks();
51
- });
52
-
53
- it('declares the pytest-gremlins engine name and the py extension', () => {
54
- const runner = new GremlinsRunner();
55
- expect(runner.name).toBe('pytest-gremlins');
56
- expect(runner.extensions).toEqual(['py']);
57
- });
58
-
59
- it('isAvailable probes the pytest_gremlins import', async () => {
60
- const runner = new GremlinsRunner();
61
- await expect(runner.isAvailable()).resolves.toBe(true);
62
- const probed = vi.mocked(execSync).mock.calls[0]?.[0] as string;
63
- expect(probed).toContain('import pytest_gremlins');
64
- });
65
-
66
- it('isAvailable returns false when the import probe fails', async () => {
67
- vi.mocked(execSync).mockImplementation(() => {
68
- throw new Error('ModuleNotFoundError');
69
- });
70
- const runner = new GremlinsRunner();
71
- await expect(runner.isAvailable()).resolves.toBe(false);
72
- });
73
-
74
- it('parses the console report (Zapped/Survived) into a normalized result', async () => {
75
- let closeCb: ((code: number | null) => void) | undefined;
76
- let stdoutCb: ((d: Buffer) => void) | undefined;
77
- vi.mocked(spawn).mockReturnValue(
78
- mockChild({
79
- stdout: cb => { stdoutCb = cb; },
80
- close: cb => { closeCb = cb; },
81
- }),
82
- );
83
-
84
- const runner = new GremlinsRunner();
85
- const promise = runner.run({ files: ['src/foo.py'], timeoutMs: 5000, cwd: '/tmp' });
86
- await new Promise(r => setTimeout(r, 0));
87
-
88
- stdoutCb?.(
89
- Buffer.from(
90
- '================== pytest-gremlins mutation report ==================\n' +
91
- 'Zapped: 142 gremlins (89%)\n' +
92
- 'Survived: 18 gremlins (11%)\n' +
93
- '=====================================================================\n',
94
- ),
95
- );
96
- closeCb?.(0);
97
-
98
- const outcome = await promise;
99
- expect(outcome.report).not.toBeNull();
100
- expect(outcome.report?.nrOfKilledMutants).toBe(142);
101
- expect(outcome.report?.nrOfSurvivedMutants).toBe(18);
102
- expect(outcome.report?.nrOfMutants).toBe(160);
103
- expect(Math.round(outcome.report!.mutationScore)).toBe(89);
104
- expect(outcome.timedOut).toBe(false);
105
- });
106
-
107
- it('returns report=null (never throws) when the report lines are absent', async () => {
108
- let closeCb: ((code: number | null) => void) | undefined;
109
- vi.mocked(spawn).mockReturnValue(mockChild({ stdout: () => { /* no output: the stub emits nothing on stdout */ }, close: cb => { closeCb = cb; } }));
110
-
111
- const runner = new GremlinsRunner();
112
- const promise = runner.run({ files: ['src/foo.py'], timeoutMs: 5000, cwd: '/tmp' });
113
- await new Promise(r => setTimeout(r, 0));
114
- closeCb?.(1);
115
-
116
- const outcome = await promise;
117
- expect(outcome.report).toBeNull();
118
- });
119
-
120
- it('returns report=null when the report has zero gremlins', async () => {
121
- let closeCb: ((code: number | null) => void) | undefined;
122
- let stdoutCb: ((d: Buffer) => void) | undefined;
123
- vi.mocked(spawn).mockReturnValue(
124
- mockChild({ stdout: cb => { stdoutCb = cb; }, close: cb => { closeCb = cb; } }),
125
- );
126
-
127
- const runner = new GremlinsRunner();
128
- const promise = runner.run({ files: ['src/foo.py'], timeoutMs: 5000, cwd: '/tmp' });
129
- await new Promise(r => setTimeout(r, 0));
130
- stdoutCb?.(Buffer.from('Zapped: 0 gremlins (0%)\nSurvived: 0 gremlins (0%)\n'));
131
- closeCb?.(0);
132
-
133
- const outcome = await promise;
134
- expect(outcome.report).toBeNull();
135
- });
136
-
137
- it('passes --gremlin-targets derived from the changed file directories', async () => {
138
- let closeCb: ((code: number | null) => void) | undefined;
139
- vi.mocked(spawn).mockReturnValue(mockChild({ stdout: () => { /* no output: the stub emits nothing on stdout */ }, close: cb => { closeCb = cb; } }));
140
-
141
- const runner = new GremlinsRunner();
142
- const promise = runner.run({ files: ['src/foo/bar.py', 'src/baz.py'], timeoutMs: 5000, cwd: '/tmp' });
143
- await new Promise(r => setTimeout(r, 0));
144
- closeCb?.(0);
145
- await promise;
146
-
147
- const spawnArgs = vi.mocked(spawn).mock.calls[0]?.[1] as string[];
148
- const joined = spawnArgs.join(' ');
149
- expect(joined).toContain('--gremlins');
150
- expect(joined).toContain('--gremlin-targets=src/foo,src');
151
- });
152
-
153
- it('reports timedOut when the child exceeds the deadline', async () => {
154
- let closeCb: ((code: number | null) => void) | undefined;
155
- const child = mockChild({ stdout: () => { /* no output: the stub emits nothing on stdout */ }, close: cb => { closeCb = cb; } });
156
- vi.mocked(spawn).mockReturnValue(child);
157
-
158
- const runner = new GremlinsRunner();
159
- const promise = runner.run({ files: ['src/foo.py'], timeoutMs: 1, cwd: '/tmp' });
160
- await new Promise(r => setTimeout(r, 20));
161
- closeCb?.(null);
162
-
163
- const outcome = await promise;
164
- expect(outcome.timedOut).toBe(true);
165
- expect(child.kill).toHaveBeenCalled();
166
- });
167
- });
@@ -1,347 +0,0 @@
1
- /**
2
- * @test init-baseline.ts - Mutation Baseline Initialization
3
- * @intent Verify argument parsing, score calculation, baseline construction,
4
- * and source file filtering logic used by the init-baseline CLI script.
5
- * @covers REQ-MUT-002 AC-001, AC-002, AC-003, AC-004
6
- */
7
-
8
- import { describe, it, expect } from 'vitest';
9
-
10
- // ─── Inline copies of pure functions from init-baseline.ts ───────────────────
11
- // The module runs main() on import, so we cannot import it directly.
12
- // These are faithful copies of the pure logic for unit testing.
13
- // See gate-m.test.ts for the same pattern used in this project.
14
-
15
- interface MutantStatus {
16
- id: string;
17
- mutatorName: string;
18
- replacement: string;
19
- location: {
20
- start: { line: number; column: number };
21
- end: { line: number; column: number };
22
- };
23
- status: string;
24
- }
25
-
26
- interface StrykerFileReport {
27
- source: string;
28
- mutants: MutantStatus[];
29
- }
30
-
31
- interface StrykerReport {
32
- schemaVersion: string;
33
- thresholds: {
34
- high: number;
35
- low: number;
36
- break: number | null;
37
- };
38
- files: Record<string, StrykerFileReport>;
39
- }
40
-
41
- interface MutationScoreEntry {
42
- score: number;
43
- mutants: number;
44
- killed: number;
45
- survived: number;
46
- }
47
-
48
- interface MutationBaseline {
49
- version: string;
50
- generatedAt: string;
51
- source: 'local' | 'ci';
52
- scores: Record<string, MutationScoreEntry>;
53
- }
54
-
55
- function parseArgs(args: string[]): { filesPattern: string; source: 'local' | 'ci' } {
56
- let filesPattern = 'src/**/*.ts';
57
- let source: 'local' | 'ci' = 'local';
58
-
59
- for (let i = 0; i < args.length; i++) {
60
- if (args[i] === '--files' && args[i + 1]) {
61
- filesPattern = args[i + 1];
62
- i++;
63
- }
64
- if (args[i] === '--source' && args[i + 1]) {
65
- source = args[i + 1] as 'local' | 'ci';
66
- i++;
67
- }
68
- }
69
-
70
- return { filesPattern, source };
71
- }
72
-
73
- function calculateScore(entry: StrykerFileReport): MutationScoreEntry {
74
- const total = entry.mutants.length;
75
- const killed = entry.mutants.filter(m => m.status === 'Killed').length;
76
- const survived = entry.mutants.filter(m => m.status === 'Survived').length;
77
-
78
- return {
79
- score: total > 0 ? parseFloat(((killed / total) * 100).toFixed(1)) : 100,
80
- mutants: total,
81
- killed,
82
- survived
83
- };
84
- }
85
-
86
- function buildBaseline(
87
- report: StrykerReport,
88
- sourceFiles: string[],
89
- source: 'local' | 'ci'
90
- ): MutationBaseline {
91
- const scores: Record<string, MutationScoreEntry> = {};
92
-
93
- for (const [filePath, fileReport] of Object.entries(report.files)) {
94
- const relativePath = filePath.replace(/^\//, '');
95
- if (sourceFiles.includes(relativePath) || sourceFiles.some(sf => relativePath.endsWith(sf))) {
96
- scores[relativePath] = calculateScore(fileReport);
97
- }
98
- }
99
-
100
- return {
101
- version: '1.0',
102
- generatedAt: new Date().toISOString(),
103
- source,
104
- scores
105
- };
106
- }
107
-
108
- function isSourceFile(file: string): boolean {
109
- return (
110
- file.endsWith('.ts') &&
111
- !file.endsWith('.d.ts') &&
112
- !file.endsWith('.test.ts') &&
113
- !file.includes('/__tests__/') &&
114
- !file.includes('/adapters/')
115
- );
116
- }
117
-
118
- // ─── Helper factories ────────────────────────────────────────────────────────
119
-
120
- function makeMutant(status: string, id = '0'): MutantStatus {
121
- return {
122
- id,
123
- mutatorName: 'BlockMutator',
124
- replacement: '{}',
125
- location: {
126
- start: { line: 1, column: 0 },
127
- end: { line: 1, column: 10 }
128
- },
129
- status
130
- };
131
- }
132
-
133
- function makeFileReport(mutants: MutantStatus[]): StrykerFileReport {
134
- return { source: 'const x = 1;', mutants };
135
- }
136
-
137
- // ─── Tests ───────────────────────────────────────────────────────────────────
138
-
139
- describe('parseArgs', () => {
140
- it('returns defaults when no arguments provided', () => {
141
- const result = parseArgs([]);
142
- expect(result.filesPattern).toBe('src/**/*.ts');
143
- expect(result.source).toBe('local');
144
- });
145
-
146
- it('parses --files flag', () => {
147
- const result = parseArgs(['--files', 'lib/**/*.ts']);
148
- expect(result.filesPattern).toBe('lib/**/*.ts');
149
- expect(result.source).toBe('local');
150
- });
151
-
152
- it('parses --source flag', () => {
153
- const result = parseArgs(['--source', 'ci']);
154
- expect(result.filesPattern).toBe('src/**/*.ts');
155
- expect(result.source).toBe('ci');
156
- });
157
-
158
- it('parses both --files and --source flags', () => {
159
- const result = parseArgs(['--files', 'app/**/*.ts', '--source', 'ci']);
160
- expect(result.filesPattern).toBe('app/**/*.ts');
161
- expect(result.source).toBe('ci');
162
- });
163
-
164
- it('ignores --files without a following value', () => {
165
- const result = parseArgs(['--files']);
166
- expect(result.filesPattern).toBe('src/**/*.ts');
167
- });
168
-
169
- it('ignores unknown flags', () => {
170
- const result = parseArgs(['--verbose', '--dry-run']);
171
- expect(result.filesPattern).toBe('src/**/*.ts');
172
- expect(result.source).toBe('local');
173
- });
174
- });
175
-
176
- describe('calculateScore', () => {
177
- it('returns 100 score when no mutants exist', () => {
178
- const entry = makeFileReport([]);
179
- const result = calculateScore(entry);
180
- expect(result.score).toBe(100);
181
- expect(result.mutants).toBe(0);
182
- expect(result.killed).toBe(0);
183
- expect(result.survived).toBe(0);
184
- });
185
-
186
- it('calculates score from killed and total mutants', () => {
187
- const entry = makeFileReport([
188
- makeMutant('Killed', '0'),
189
- makeMutant('Killed', '1'),
190
- makeMutant('Survived', '2'),
191
- makeMutant('Survived', '3')
192
- ]);
193
- const result = calculateScore(entry);
194
- expect(result.mutants).toBe(4);
195
- expect(result.killed).toBe(2);
196
- expect(result.survived).toBe(2);
197
- expect(result.score).toBe(50);
198
- });
199
-
200
- it('returns 100 score when all mutants are killed', () => {
201
- const entry = makeFileReport([
202
- makeMutant('Killed', '0'),
203
- makeMutant('Killed', '1'),
204
- makeMutant('Killed', '2')
205
- ]);
206
- const result = calculateScore(entry);
207
- expect(result.score).toBe(100);
208
- expect(result.killed).toBe(3);
209
- expect(result.survived).toBe(0);
210
- });
211
-
212
- it('returns 0 score when all mutants survived', () => {
213
- const entry = makeFileReport([
214
- makeMutant('Survived', '0'),
215
- makeMutant('Survived', '1')
216
- ]);
217
- const result = calculateScore(entry);
218
- expect(result.score).toBe(0);
219
- expect(result.killed).toBe(0);
220
- expect(result.survived).toBe(2);
221
- });
222
-
223
- it('ignores non-Killed/Survived statuses in killed/survived counts', () => {
224
- const entry = makeFileReport([
225
- makeMutant('Killed', '0'),
226
- makeMutant('NoCoverage', '1'),
227
- makeMutant('RuntimeError', '2'),
228
- makeMutant('Survived', '3')
229
- ]);
230
- const result = calculateScore(entry);
231
- expect(result.mutants).toBe(4);
232
- expect(result.killed).toBe(1);
233
- expect(result.survived).toBe(1);
234
- expect(result.score).toBe(25);
235
- });
236
-
237
- it('rounds score to one decimal place', () => {
238
- const entry = makeFileReport([
239
- makeMutant('Killed', '0'),
240
- makeMutant('Killed', '1'),
241
- makeMutant('Survived', '2')
242
- ]);
243
- const result = calculateScore(entry);
244
- // 2/3 * 100 = 66.666... → 66.7
245
- expect(result.score).toBe(66.7);
246
- });
247
- });
248
-
249
- describe('buildBaseline', () => {
250
- const emptyReport: StrykerReport = {
251
- schemaVersion: '1.0',
252
- thresholds: { high: 80, low: 60, break: null },
253
- files: {}
254
- };
255
-
256
- it('returns empty scores when report has no files', () => {
257
- const baseline = buildBaseline(emptyReport, [], 'local');
258
- expect(baseline.version).toBe('1.0');
259
- expect(baseline.source).toBe('local');
260
- expect(baseline.scores).toEqual({});
261
- expect(baseline.generatedAt).toBeDefined();
262
- });
263
-
264
- it('includes only source files in baseline scores', () => {
265
- const report: StrykerReport = {
266
- schemaVersion: '1.0',
267
- thresholds: { high: 80, low: 60, break: null },
268
- files: {
269
- 'src/auth.ts': makeFileReport([makeMutant('Killed', '0')]),
270
- 'src/utils.ts': makeFileReport([makeMutant('Survived', '0')]),
271
- 'dist/bundle.js': makeFileReport([makeMutant('Killed', '0')])
272
- }
273
- };
274
- const sourceFiles = ['src/auth.ts', 'src/utils.ts'];
275
- const baseline = buildBaseline(report, sourceFiles, 'ci');
276
- expect(Object.keys(baseline.scores)).toHaveLength(2);
277
- expect(baseline.scores['src/auth.ts']).toBeDefined();
278
- expect(baseline.scores['src/utils.ts']).toBeDefined();
279
- expect(baseline.scores['dist/bundle.js']).toBeUndefined();
280
- expect(baseline.source).toBe('ci');
281
- });
282
-
283
- it('strips leading slash from file paths', () => {
284
- const report: StrykerReport = {
285
- schemaVersion: '1.0',
286
- thresholds: { high: 80, low: 60, break: null },
287
- files: {
288
- '/src/auth.ts': makeFileReport([makeMutant('Killed', '0')])
289
- }
290
- };
291
- const sourceFiles = ['src/auth.ts'];
292
- const baseline = buildBaseline(report, sourceFiles, 'local');
293
- expect(baseline.scores['src/auth.ts']).toBeDefined();
294
- });
295
-
296
- it('matches files by suffix when exact match fails', () => {
297
- const report: StrykerReport = {
298
- schemaVersion: '1.0',
299
- thresholds: { high: 80, low: 60, break: null },
300
- files: {
301
- 'packages/core/src/auth.ts': makeFileReport([makeMutant('Killed', '0')])
302
- }
303
- };
304
- const sourceFiles = ['src/auth.ts'];
305
- const baseline = buildBaseline(report, sourceFiles, 'local');
306
- expect(baseline.scores['packages/core/src/auth.ts']).toBeDefined();
307
- });
308
-
309
- it('sets generatedAt to a valid ISO date string', () => {
310
- const baseline = buildBaseline(emptyReport, [], 'local');
311
- const parsed = new Date(baseline.generatedAt);
312
- expect(parsed.toISOString()).toBe(baseline.generatedAt);
313
- });
314
- });
315
-
316
- describe('isSourceFile (getSourceFiles filter predicate)', () => {
317
- it('accepts regular .ts files', () => {
318
- expect(isSourceFile('src/auth.ts')).toBe(true);
319
- expect(isSourceFile('src/utils/helper.ts')).toBe(true);
320
- });
321
-
322
- it('rejects .d.ts declaration files', () => {
323
- expect(isSourceFile('src/types.d.ts')).toBe(false);
324
- expect(isSourceFile('src/global.d.ts')).toBe(false);
325
- });
326
-
327
- it('rejects .test.ts files', () => {
328
- expect(isSourceFile('src/auth.test.ts')).toBe(false);
329
- expect(isSourceFile('src/utils/helper.test.ts')).toBe(false);
330
- });
331
-
332
- it('rejects files in __tests__ directories', () => {
333
- expect(isSourceFile('src/__tests__/auth.test.ts')).toBe(false);
334
- expect(isSourceFile('src/__tests__/helpers.ts')).toBe(false);
335
- });
336
-
337
- it('rejects files in adapters directories', () => {
338
- expect(isSourceFile('githooks/adapters/typescript.sh')).toBe(false);
339
- expect(isSourceFile('src/adapters/go.ts')).toBe(false);
340
- });
341
-
342
- it('rejects non-.ts files', () => {
343
- expect(isSourceFile('src/index.js')).toBe(false);
344
- expect(isSourceFile('src/style.css')).toBe(false);
345
- expect(isSourceFile('README.md')).toBe(false);
346
- });
347
- });
@@ -1,49 +0,0 @@
1
- /**
2
- * @test #544 - the shipped mutation module stays a mirror of the source module
3
- * @intent src/npm-package/mutation/ is published to npm ("mutation/" is in the
4
- * package `files` list) but has no automated mirror check, unlike the
5
- * hooks and adapters which check-hook-mirror.sh diffs. It IS maintained
6
- * as a byte-identical copy today, so a fix applied only to src/mutation/
7
- * would ship stale code to every consumer -- exactly the v0.27.3 failure
8
- * (#542) where a mirror-only fix was rolled back at publish. This guard
9
- * makes that class of drift red instead of silent, and it is what caught
10
- * the hardcoded zero counts still living in the package copy.
11
- * @covers REQ-MUT-001 AC-001
12
- */
13
-
14
- import { describe, it, expect } from 'vitest';
15
- import fs from 'fs';
16
- import path from 'path';
17
-
18
- // This file lives at src/mutation/__tests__/, so the repo root is three levels
19
- // up (unlike scripts/__tests__/, which is two).
20
- const ROOT = path.resolve(__dirname, '..', '..', '..');
21
- const SRC = path.join(ROOT, 'src', 'mutation');
22
- const PKG = path.join(ROOT, 'src', 'npm-package', 'mutation');
23
-
24
- /** Files that must be identical in both trees. */
25
- const MIRRORED = ['gate-m.ts', 'update-baseline.ts', 'types.ts', 'detect-ai-test.ts', 'init-baseline.ts', 'stryker-types.ts'];
26
-
27
- describe('src/npm-package/mutation mirrors src/mutation', () => {
28
- it.each(MIRRORED)('%s is byte-identical in both trees', (file) => {
29
- const a = fs.readFileSync(path.join(SRC, file), 'utf8');
30
- const b = fs.readFileSync(path.join(PKG, file), 'utf8');
31
- expect(b, `${file} has drifted: edit src/mutation/${file} and copy it over`).toBe(a);
32
- });
33
-
34
- it('the mirror list is non-empty and every entry exists (anti-vacuity)', () => {
35
- expect(MIRRORED.length).toBeGreaterThan(3);
36
- for (const f of MIRRORED) {
37
- expect(fs.existsSync(path.join(SRC, f)), `missing source ${f}`).toBe(true);
38
- expect(fs.existsSync(path.join(PKG, f)), `missing mirror ${f}`).toBe(true);
39
- }
40
- });
41
-
42
- it('the package copy carries the #544 fix, not the zero-filling original', () => {
43
- // Anchor on the defect itself so this cannot pass with a stale-but-identical
44
- // pair of pre-fix files.
45
- const shipped = fs.readFileSync(path.join(PKG, 'gate-m.ts'), 'utf8');
46
- expect(shipped).not.toContain('mutants: 0, killed: 0, survived: 0');
47
- expect(shipped).toContain('MutantCounts');
48
- });
49
- });