@boyingliu01/xp-gate 0.38.76 → 0.38.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/lib/__tests__/gate2-verdict.test.js +58 -1
  2. package/lib/__tests__/mirror-sync.test.js +387 -5
  3. package/lib/gate-runner.js +88 -9
  4. package/lib/mattpocock-license-verdict.json +1 -1
  5. package/lib/mirror-sync.js +202 -15
  6. package/package.json +1 -1
  7. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  8. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  9. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  10. package/plugins/claude-code/skills/sprint-flow/references/phase-2-design.md +62 -2
  11. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  12. package/plugins/dsh/package.json +1 -1
  13. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  14. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  15. package/plugins/dsh/skills/sprint-flow/references/phase-2-design.md +62 -2
  16. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  17. package/plugins/opencode/package.json +1 -1
  18. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  19. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  20. package/plugins/opencode/skills/sprint-flow/references/phase-2-design.md +62 -2
  21. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  22. package/plugins/qoder/plugin.json +1 -1
  23. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  24. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  25. package/plugins/qoder/skills/sprint-flow/references/phase-2-design.md +62 -2
  26. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  27. package/scripts/generate-mirrors.cjs +10 -0
  28. package/skills/delphi-review/AGENTS.md +1 -1
  29. package/skills/sprint-flow/AGENTS.md +1 -1
  30. package/skills/sprint-flow/references/phase-2-design.md +62 -2
  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,162 +0,0 @@
1
- /**
2
- * @test REQ-MUT-010 Mutation runner registry and resolution
3
- * @intent Verify registerAllRunners populates the registry, resolveRunner routes by extension,
4
- * and re-exports expose the expected types and classes.
5
- * @covers AC-MUT-010, AC-MUT-011
6
- */
7
-
8
- import { describe, it, expect, beforeEach } from 'vitest';
9
- import {
10
- runnerRegistry,
11
- registerAllRunners,
12
- resolveRunner,
13
- resolveRunners,
14
- StrykerRunner,
15
- MutmutRunner,
16
- GoMutantRunner,
17
- PitestRunner,
18
- } from '../runners/index';
19
- import type {
20
- MutationFileReport,
21
- MutationRunResult,
22
- MutationRunOutcome,
23
- RunMutationOptions,
24
- MutationRunner,
25
- } from '../runners/index';
26
-
27
- describe('runners/index', () => {
28
- beforeEach(() => {
29
- runnerRegistry.clear();
30
- });
31
-
32
- it('exposes runnerRegistry as a Map instance', () => {
33
- expect(runnerRegistry).toBeInstanceOf(Map);
34
- });
35
-
36
- it('registerAllRunners() registers all 5 runners', () => {
37
- registerAllRunners();
38
-
39
- expect(runnerRegistry.size).toBe(5);
40
- expect(runnerRegistry.has('Stryker')).toBe(true);
41
- expect(runnerRegistry.has('pytest-gremlins')).toBe(true);
42
- expect(runnerRegistry.has('mutmut')).toBe(true);
43
- expect(runnerRegistry.has('gomutants')).toBe(true);
44
- expect(runnerRegistry.has('pitest')).toBe(true);
45
- });
46
-
47
- it('registerAllRunners() stores correct runner class instances', () => {
48
- registerAllRunners();
49
-
50
- expect(runnerRegistry.get('Stryker')).toBeInstanceOf(StrykerRunner);
51
- expect(runnerRegistry.get('pytest-gremlins')).toBeDefined();
52
- expect(runnerRegistry.get('mutmut')).toBeInstanceOf(MutmutRunner);
53
- expect(runnerRegistry.get('gomutants')).toBeInstanceOf(GoMutantRunner);
54
- expect(runnerRegistry.get('pitest')).toBeInstanceOf(PitestRunner);
55
- });
56
-
57
- describe('resolveRunner()', () => {
58
- beforeEach(() => {
59
- registerAllRunners();
60
- });
61
-
62
- it.each([
63
- ['ts', 'Stryker'],
64
- ['tsx', 'Stryker'],
65
- ['py', 'pytest-gremlins'],
66
- ['go', 'gomutants'],
67
- ['java', 'pitest'],
68
- ['kt', 'pitest'],
69
- ['kts', 'pitest'],
70
- ])('returns %s runner for extension "%s"', (ext, expectedName) => {
71
- const runner = resolveRunner(ext);
72
- expect(runner).toBeDefined();
73
- expect(runner!.name).toBe(expectedName);
74
- });
75
-
76
- it('handles dot-prefixed extensions', () => {
77
- const runner = resolveRunner('.ts');
78
- expect(runner).toBeDefined();
79
- expect(runner!.name).toBe('Stryker');
80
- });
81
-
82
- it('returns undefined for unknown extensions', () => {
83
- expect(resolveRunner('rb')).toBeUndefined();
84
- expect(resolveRunner('swift')).toBeUndefined();
85
- expect(resolveRunner('')).toBeUndefined();
86
- });
87
- });
88
-
89
- describe('resolveRunners()', () => {
90
- beforeEach(() => {
91
- registerAllRunners();
92
- });
93
-
94
- it('returns the py runners in registration (priority) order for ".py"', () => {
95
- const runners = resolveRunners('.py');
96
- expect(runners.map(r => r.name)).toEqual(['pytest-gremlins', 'mutmut']);
97
- });
98
-
99
- it('returns a single-element list for extensions with one runner', () => {
100
- expect(resolveRunners('.go').map(r => r.name)).toEqual(['gomutants']);
101
- expect(resolveRunners('.ts').map(r => r.name)).toEqual(['Stryker']);
102
- });
103
-
104
- it('returns an empty list for unknown extensions', () => {
105
- expect(resolveRunners('.rb')).toEqual([]);
106
- });
107
-
108
- it('handles dot-prefixed extensions', () => {
109
- const runners = resolveRunners('.py');
110
- expect(runners.length).toBeGreaterThan(1);
111
- });
112
- });
113
-
114
- describe('re-exports', () => {
115
- it('re-exports all runner classes', () => {
116
- expect(StrykerRunner).toBeDefined();
117
- expect(MutmutRunner).toBeDefined();
118
- expect(GoMutantRunner).toBeDefined();
119
- expect(PitestRunner).toBeDefined();
120
- });
121
-
122
- it('re-exports types as usable type aliases', () => {
123
- // Type-only imports are verified at compile time.
124
- // This test ensures the module shape is importable without runtime error.
125
- const report: MutationFileReport = {
126
- mutationScore: 80,
127
- nrOfMutants: 10,
128
- nrOfKilledMutants: 8,
129
- nrOfSurvivedMutants: 2,
130
- };
131
- const result: MutationRunResult = {
132
- mutationScore: 80,
133
- nrOfMutants: 10,
134
- nrOfKilledMutants: 8,
135
- nrOfSurvivedMutants: 2,
136
- };
137
- const outcome: MutationRunOutcome = {
138
- report: result,
139
- timedOut: false,
140
- };
141
- const options: RunMutationOptions = {
142
- files: ['src/foo.ts'],
143
- timeoutMs: 30000,
144
- cwd: '/tmp',
145
- };
146
-
147
- expect(report.mutationScore).toBe(80);
148
- expect(result.nrOfMutants).toBe(10);
149
- expect(outcome.timedOut).toBe(false);
150
- expect(options.files).toEqual(['src/foo.ts']);
151
-
152
- // MutationRunner is an interface — verify it can be used as a type constraint
153
- const fakeRunner: MutationRunner = {
154
- name: 'fake',
155
- extensions: ['fake'],
156
- isAvailable: async () => true,
157
- run: async () => ({ report: null, timedOut: false }),
158
- };
159
- expect(fakeRunner.name).toBe('fake');
160
- });
161
- });
162
- });
@@ -1,455 +0,0 @@
1
- /**
2
- * @test REQ-MUT-004 Stryker mutation runner
3
- * @intent Verify StrykerRunner registration, availability checks, Stryker report parsing,
4
- * timeout handling, spawn errors, and per-file breakdown
5
- * @covers AC-MUT-004, AC-MUT-006
6
- */
7
-
8
- import { describe, it, expect, vi, beforeEach } from 'vitest';
9
- import { spawn, spawnSync, type ChildProcess } from 'child_process';
10
- import { writeFileSync, mkdirSync } from 'fs';
11
- import { tmpdir } from 'os';
12
- import { join } from 'path';
13
-
14
- vi.mock('child_process', () => ({
15
- spawn: vi.fn(),
16
- spawnSync: vi.fn(),
17
- }));
18
-
19
- vi.mock('fs', async () => {
20
- const actual = await vi.importActual<typeof import('fs')>('fs');
21
- return {
22
- ...actual,
23
- existsSync: vi.fn(actual.existsSync),
24
- readFileSync: vi.fn(actual.readFileSync),
25
- };
26
- });
27
-
28
- describe('StrykerRunner', () => {
29
- let StrykerRunner: typeof import('../runners/stryker-runner').StrykerRunner;
30
- let tmpDir: string;
31
-
32
- beforeEach(async () => {
33
- vi.clearAllMocks();
34
- tmpDir = join(tmpdir(), `xp-gate-stryker-test-${Date.now()}`);
35
- mkdirSync(tmpDir, { recursive: true });
36
- StrykerRunner = (await import('../runners/stryker-runner')).StrykerRunner;
37
- });
38
-
39
- // ── name and extensions ──────────────────────────────────────────────────────
40
-
41
- describe('name and extensions', () => {
42
- it('should have name "Stryker"', () => {
43
- const runner = new StrykerRunner();
44
- expect(runner.name).toBe('Stryker');
45
- });
46
-
47
- it('should handle .ts and .tsx extensions', () => {
48
- const runner = new StrykerRunner();
49
- expect(runner.extensions).toContain('ts');
50
- expect(runner.extensions).toContain('tsx');
51
- expect(runner.extensions).not.toContain('go');
52
- expect(runner.extensions).not.toContain('py');
53
- });
54
- });
55
-
56
- // ── isAvailable ──────────────────────────────────────────────────────────────
57
-
58
- describe('isAvailable', () => {
59
- it('should return true when npx stryker is available (exit 0)', async () => {
60
- vi.mocked(spawnSync).mockReturnValue({
61
- status: 0,
62
- output: [],
63
- pid: 0,
64
- signal: null,
65
- } as unknown as ReturnType<typeof spawnSync>);
66
-
67
- const runner = new StrykerRunner();
68
- const result = await runner.isAvailable();
69
- expect(result).toBe(true);
70
- expect(spawnSync).toHaveBeenCalledWith(
71
- 'npx',
72
- ['stryker', '--version'],
73
- expect.objectContaining({ stdio: 'pipe', timeout: 5000 }),
74
- );
75
- });
76
-
77
- it('should return false when npx stryker is not installed (non-zero exit)', async () => {
78
- vi.mocked(spawnSync).mockReturnValue({
79
- status: 1,
80
- output: [],
81
- pid: 0,
82
- signal: null,
83
- } as unknown as ReturnType<typeof spawnSync>);
84
-
85
- const runner = new StrykerRunner();
86
- const result = await runner.isAvailable();
87
- expect(result).toBe(false);
88
- });
89
-
90
- it('should return false when spawnSync throws', async () => {
91
- vi.mocked(spawnSync).mockImplementation(() => {
92
- throw new Error('ENOENT');
93
- });
94
-
95
- const runner = new StrykerRunner();
96
- const result = await runner.isAvailable();
97
- expect(result).toBe(false);
98
- });
99
- });
100
-
101
- // ── run ──────────────────────────────────────────────────────────────────────
102
-
103
- describe('run', () => {
104
- it('should spawn npx stryker run with correct args and parse valid report', async () => {
105
- let closeCb: ((code: number | null) => void) | null = null;
106
- const mockChild = {
107
- stdout: { on: vi.fn() },
108
- stderr: { on: vi.fn() },
109
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
110
- if (event === 'close') closeCb = cb;
111
- }),
112
- kill: vi.fn(),
113
- killed: false,
114
- };
115
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
116
-
117
- writeFileSync(join(tmpDir, 'stryker.prepush.conf.json'), '{}');
118
- writeFileSync(join(tmpDir, '.stryker-report.json'), JSON.stringify({
119
- mutationScore: 75,
120
- nrOfMutants: 40,
121
- nrOfKilledMutants: 30,
122
- nrOfSurvivedMutants: 10,
123
- }));
124
-
125
- const runner = new StrykerRunner();
126
- const promise = runner.run({
127
- files: ['src/a.ts', 'src/b.tsx'],
128
- timeoutMs: 60000,
129
- cwd: tmpDir,
130
- });
131
-
132
- closeCb!(0);
133
- const result = await promise;
134
-
135
- expect(spawn).toHaveBeenCalledWith(
136
- 'npx',
137
- [
138
- 'stryker', 'run',
139
- '--config', join(tmpDir, 'stryker.prepush.conf.json'),
140
- '--mutate', 'src/a.ts',
141
- '--mutate', 'src/b.tsx',
142
- ],
143
- expect.objectContaining({ cwd: tmpDir, stdio: 'pipe', shell: true }),
144
- );
145
-
146
- expect(result.timedOut).toBe(false);
147
- expect(result.report).not.toBeNull();
148
- expect(result.report!.mutationScore).toBe(75);
149
- expect(result.report!.nrOfMutants).toBe(40);
150
- expect(result.report!.nrOfKilledMutants).toBe(30);
151
- expect(result.report!.nrOfSurvivedMutants).toBe(10);
152
- expect(result.error).toBeUndefined();
153
- });
154
-
155
- it('should omit --config when stryker.prepush.conf.json does not exist', async () => {
156
- let closeCb: ((code: number | null) => void) | null = null;
157
- const mockChild = {
158
- stdout: { on: vi.fn() },
159
- stderr: { on: vi.fn() },
160
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
161
- if (event === 'close') closeCb = cb;
162
- }),
163
- kill: vi.fn(),
164
- killed: false,
165
- };
166
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
167
-
168
- const runner = new StrykerRunner();
169
- const promise = runner.run({
170
- files: ['src/a.ts'],
171
- timeoutMs: 60000,
172
- cwd: tmpDir,
173
- });
174
-
175
- closeCb!(0);
176
- await promise;
177
-
178
- expect(spawn).toHaveBeenCalledWith(
179
- 'npx',
180
- ['stryker', 'run', '--mutate', 'src/a.ts'],
181
- expect.objectContaining({ cwd: tmpDir }),
182
- );
183
- });
184
-
185
- it('should return timedOut=true when child is killed (close code null)', async () => {
186
- const mockChild = {
187
- stdout: { on: vi.fn() },
188
- stderr: { on: vi.fn() },
189
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
190
- if (event === 'close') setTimeout(() => cb(null), 10);
191
- }),
192
- kill: vi.fn(),
193
- killed: false,
194
- };
195
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
196
-
197
- const runner = new StrykerRunner();
198
- const result = await runner.run({
199
- files: ['src/a.ts'],
200
- timeoutMs: 100,
201
- cwd: tmpDir,
202
- });
203
-
204
- expect(result.timedOut).toBe(true);
205
- expect(result.report).toBeNull();
206
- });
207
-
208
- it('should return error when spawn fails (error event)', async () => {
209
- const mockChild = {
210
- stdout: { on: vi.fn() },
211
- stderr: { on: vi.fn() },
212
- on: vi.fn((event: string, cb: (err: Error) => void) => {
213
- if (event === 'error') setTimeout(() => cb(new Error('spawn ENOENT')), 10);
214
- }),
215
- kill: vi.fn(),
216
- killed: false,
217
- };
218
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
219
-
220
- const runner = new StrykerRunner();
221
- const result = await runner.run({
222
- files: ['src/a.ts'],
223
- timeoutMs: 60000,
224
- cwd: tmpDir,
225
- });
226
-
227
- expect(result.report).toBeNull();
228
- expect(result.timedOut).toBe(false);
229
- expect(result.error).toBe('spawn ENOENT');
230
- });
231
-
232
- it('should include stderr as error on non-zero exit code', async () => {
233
- let stderrCb: ((d: Buffer) => void) | null = null;
234
- const mockChild = {
235
- stdout: { on: vi.fn() },
236
- stderr: {
237
- on: vi.fn((_event: string, cb: (d: Buffer) => void) => {
238
- stderrCb = cb;
239
- }),
240
- },
241
- on: vi.fn((event: string, cb: (code: number) => void) => {
242
- if (event === 'close') {
243
- setTimeout(() => {
244
- if (stderrCb) stderrCb(Buffer.from('mutation score below threshold'));
245
- cb(1);
246
- }, 10);
247
- }
248
- }),
249
- kill: vi.fn(),
250
- killed: false,
251
- };
252
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
253
-
254
- writeFileSync(join(tmpDir, '.stryker-report.json'), JSON.stringify({
255
- mutationScore: 40,
256
- nrOfMutants: 50,
257
- nrOfKilledMutants: 20,
258
- nrOfSurvivedMutants: 30,
259
- }));
260
-
261
- const runner = new StrykerRunner();
262
- const result = await runner.run({
263
- files: ['src/a.ts'],
264
- timeoutMs: 60000,
265
- cwd: tmpDir,
266
- });
267
-
268
- expect(result.timedOut).toBe(false);
269
- expect(result.report).not.toBeNull();
270
- expect(result.report!.mutationScore).toBe(40);
271
- expect(result.error).toContain('mutation score below threshold');
272
- });
273
-
274
- it('should return null report when .stryker-report.json does not exist', async () => {
275
- const mockChild = {
276
- stdout: { on: vi.fn() },
277
- stderr: { on: vi.fn() },
278
- on: vi.fn((event: string, cb: (code: number) => void) => {
279
- if (event === 'close') setTimeout(() => cb(0), 10);
280
- }),
281
- kill: vi.fn(),
282
- killed: false,
283
- };
284
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
285
-
286
- const runner = new StrykerRunner();
287
- const result = await runner.run({
288
- files: ['src/a.ts'],
289
- timeoutMs: 60000,
290
- cwd: tmpDir,
291
- });
292
-
293
- expect(result.report).toBeNull();
294
- expect(result.timedOut).toBe(false);
295
- });
296
- });
297
-
298
- // ── Report parsing ────────────────────────────────────────────────────────────
299
-
300
- describe('report parsing', () => {
301
- it('should parse valid Stryker JSON report', async () => {
302
- let closeCb: ((code: number | null) => void) | null = null;
303
- const mockChild = {
304
- stdout: { on: vi.fn() },
305
- stderr: { on: vi.fn() },
306
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
307
- if (event === 'close') closeCb = cb;
308
- }),
309
- kill: vi.fn(),
310
- killed: false,
311
- };
312
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
313
-
314
- writeFileSync(join(tmpDir, '.stryker-report.json'), JSON.stringify({
315
- mutationScore: 88.5,
316
- nrOfMutants: 100,
317
- nrOfKilledMutants: 88,
318
- nrOfSurvivedMutants: 12,
319
- }));
320
-
321
- const runner = new StrykerRunner();
322
- const promise = runner.run({
323
- files: ['src/a.ts'],
324
- timeoutMs: 60000,
325
- cwd: tmpDir,
326
- });
327
-
328
- closeCb!(0);
329
- const result = await promise;
330
-
331
- expect(result.report).not.toBeNull();
332
- expect(result.report!.mutationScore).toBe(88.5);
333
- expect(result.report!.nrOfMutants).toBe(100);
334
- expect(result.report!.nrOfKilledMutants).toBe(88);
335
- expect(result.report!.nrOfSurvivedMutants).toBe(12);
336
- });
337
-
338
- it('should return null report for invalid JSON', async () => {
339
- let closeCb: ((code: number | null) => void) | null = null;
340
- const mockChild = {
341
- stdout: { on: vi.fn() },
342
- stderr: { on: vi.fn() },
343
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
344
- if (event === 'close') closeCb = cb;
345
- }),
346
- kill: vi.fn(),
347
- killed: false,
348
- };
349
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
350
-
351
- writeFileSync(join(tmpDir, '.stryker-report.json'), 'not valid json {{{');
352
-
353
- const runner = new StrykerRunner();
354
- const promise = runner.run({
355
- files: ['src/a.ts'],
356
- timeoutMs: 60000,
357
- cwd: tmpDir,
358
- });
359
-
360
- closeCb!(0);
361
- const result = await promise;
362
-
363
- expect(result.report).toBeNull();
364
- });
365
-
366
- it('should default missing numeric fields to 0 (asNumber fallback)', async () => {
367
- let closeCb: ((code: number | null) => void) | null = null;
368
- const mockChild = {
369
- stdout: { on: vi.fn() },
370
- stderr: { on: vi.fn() },
371
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
372
- if (event === 'close') closeCb = cb;
373
- }),
374
- kill: vi.fn(),
375
- killed: false,
376
- };
377
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
378
-
379
- writeFileSync(join(tmpDir, '.stryker-report.json'), JSON.stringify({
380
- someOtherField: 'value',
381
- }));
382
-
383
- const runner = new StrykerRunner();
384
- const promise = runner.run({
385
- files: ['src/a.ts'],
386
- timeoutMs: 60000,
387
- cwd: tmpDir,
388
- });
389
-
390
- closeCb!(0);
391
- const result = await promise;
392
-
393
- // asNumber defaults non-number values to 0; isNaN(0) is false → report is non-null
394
- expect(result.report).not.toBeNull();
395
- expect(result.report!.mutationScore).toBe(0);
396
- expect(result.report!.nrOfMutants).toBe(0);
397
- expect(result.report!.nrOfKilledMutants).toBe(0);
398
- expect(result.report!.nrOfSurvivedMutants).toBe(0);
399
- });
400
-
401
- it('should parse per-file breakdown from files object', async () => {
402
- let closeCb: ((code: number | null) => void) | null = null;
403
- const mockChild = {
404
- stdout: { on: vi.fn() },
405
- stderr: { on: vi.fn() },
406
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
407
- if (event === 'close') closeCb = cb;
408
- }),
409
- kill: vi.fn(),
410
- killed: false,
411
- };
412
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
413
-
414
- writeFileSync(join(tmpDir, '.stryker-report.json'), JSON.stringify({
415
- mutationScore: 70,
416
- nrOfMutants: 30,
417
- nrOfKilledMutants: 21,
418
- nrOfSurvivedMutants: 9,
419
- files: {
420
- 'src/a.ts': {
421
- mutationScore: 80,
422
- nrOfMutants: 10,
423
- nrOfKilledMutants: 8,
424
- nrOfSurvivedMutants: 2,
425
- },
426
- 'src/b.tsx': {
427
- mutationScore: 60,
428
- nrOfMutants: 20,
429
- nrOfKilledMutants: 12,
430
- nrOfSurvivedMutants: 8,
431
- },
432
- },
433
- }));
434
-
435
- const runner = new StrykerRunner();
436
- const promise = runner.run({
437
- files: ['src/a.ts', 'src/b.tsx'],
438
- timeoutMs: 60000,
439
- cwd: tmpDir,
440
- });
441
-
442
- closeCb!(0);
443
- const result = await promise;
444
-
445
- expect(result.report).not.toBeNull();
446
- expect(result.report!.files).toBeDefined();
447
- expect(result.report!.files!['src/a.ts'].mutationScore).toBe(80);
448
- expect(result.report!.files!['src/a.ts'].nrOfMutants).toBe(10);
449
- expect(result.report!.files!['src/a.ts'].nrOfKilledMutants).toBe(8);
450
- expect(result.report!.files!['src/a.ts'].nrOfSurvivedMutants).toBe(2);
451
- expect(result.report!.files!['src/b.tsx'].mutationScore).toBe(60);
452
- expect(result.report!.files!['src/b.tsx'].nrOfMutants).toBe(20);
453
- });
454
- });
455
- });
@@ -1,40 +0,0 @@
1
- /**
2
- * @test REQ-480
3
- * @intent "测试基础设施" 的定义在 githooks/pre-push(bash)与 src/mutation/gate-m.ts
4
- * (TypeScript)各写了一遍,没有共享常量的自然机制;一侧演化后 Gate M 与
5
- * pre-push 会对同一变更集给出不一致裁决(Round 2 架构 MA-02 / 可行性 FC-03)。
6
- * 跨语言无法共用函数,退而求其次:把两处文本钉成同一份定义。
7
- * @covers AC-480-04
8
- */
9
- import { describe, it, expect } from 'vitest';
10
- import fs from 'fs';
11
- import path from 'path';
12
-
13
- const repoRoot = path.resolve(__dirname, '..', '..', '..');
14
- const prePush = fs.readFileSync(path.join(repoRoot, 'githooks', 'pre-push'), 'utf8');
15
- const gateM = fs.readFileSync(path.join(repoRoot, 'src', 'mutation', 'gate-m.ts'), 'utf8');
16
-
17
- const prePushFilter =
18
- prePush.split('\n').find((line) => line.includes('CHANGED_SOURCE_FILES=')) || '';
19
-
20
- describe('test-path filter parity between pre-push and gate-m (#480)', () => {
21
- it('compares a real filter line, not an empty string', () => {
22
- expect(prePushFilter).toContain('grep -v');
23
- expect(gateM).toContain('export function filterSourceFiles');
24
- });
25
-
26
- it('both sides exclude the same test-tree segments', () => {
27
- expect(prePushFilter).toContain('(tests?|__tests__)/');
28
- expect(gateM).toContain(String.raw`(^|\/)(tests?|__tests__)\/`);
29
- });
30
-
31
- it('both sides exclude declaration files and spec-named tests', () => {
32
- expect(prePushFilter).toContain(String.raw`\.d\.ts$`);
33
- expect(prePushFilter).toContain(String.raw`\.spec\.`);
34
- // gate-m states each exclusion as an entry in EXCLUDED_PATH_PATTERNS rather
35
- // than as an endsWith/includes call, so the parity assertion follows the
36
- // regex. What it pins is unchanged: the TS side still excludes both.
37
- expect(gateM).toContain(String.raw`pattern: /\.d\.ts$/`);
38
- expect(gateM).toContain(String.raw`pattern: /\.spec\./`);
39
- });
40
- });