@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,1049 +0,0 @@
1
- /**
2
- * @test REQ-MUT-007 mutmut mutation runner
3
- * @intent Verify MutmutRunner registration, availability checks, emoji progress parsing,
4
- * pyproject.toml config management, and cleanup behavior
5
- * @covers AC-MUT-007, AC-MUT-008
6
- */
7
-
8
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
9
- import { spawn, execSync, type ChildProcess } from 'child_process';
10
- import {
11
- writeFileSync,
12
- readFileSync,
13
- existsSync,
14
- unlinkSync,
15
- } from 'fs';
16
- import { tmpdir } from 'os';
17
- import { join } from 'path';
18
-
19
- vi.mock('child_process', () => ({
20
- spawn: vi.fn(),
21
- execSync: vi.fn(),
22
- }));
23
-
24
- vi.mock('fs', () => ({
25
- writeFileSync: vi.fn(),
26
- readFileSync: vi.fn(),
27
- existsSync: vi.fn(),
28
- unlinkSync: vi.fn(),
29
- }));
30
-
31
- describe('MutmutRunner', () => {
32
- let MutmutRunner: typeof import('../runners/mutmut-runner').MutmutRunner;
33
- let tmpDir: string;
34
-
35
- /**
36
- * Wait until the runner has actually spawned the child process.
37
- *
38
- * `run()` awaits `isAvailable()` when the platform is win32 (the route is
39
- * resolved via a version probe), so `spawn` is NOT called synchronously with
40
- * `run()`. Calling `stdoutCb` right after `run()` therefore raced on Windows:
41
- * the callback had not been captured yet and the test threw
42
- * `stdoutCb is not a function`. Linux skipped the await entirely, which is why
43
- * CI stayed green while the same suite failed locally.
44
- */
45
- async function waitForSpawn(): Promise<void> {
46
- for (let i = 0; i < 50 && !vi.mocked(spawn).mock.calls.length; i++) {
47
- await new Promise(resolve => setTimeout(resolve, 0));
48
- }
49
- }
50
-
51
- /**
52
- * Build a fake child process whose `stdout`/`close` callbacks are captured so a
53
- * test can drive them by hand. Shared because every spawn-based test needs the
54
- * same shape, and inlining it in each one pushed those callbacks past the
55
- * function-length rule.
56
- */
57
- function mockChildProcess(capture: {
58
- stdout?: (cb: (d: Buffer) => void) => void;
59
- stderr?: (cb: (d: Buffer) => void) => void;
60
- close?: (cb: (code: number | null) => void) => void;
61
- /** Run when `close` is subscribed, instead of the test driving it by hand. */
62
- onClose?: (emit: { stderr: (d: Buffer) => void; close: (code: number) => void }) => void;
63
- }) {
64
- let stderrCb: ((d: Buffer) => void) | null = null;
65
- let closeCb: ((code: number | null) => void) | null = null;
66
- return {
67
- stdout: {
68
- on: vi.fn((_event: string, cb: (d: Buffer) => void) => capture.stdout?.(cb)),
69
- },
70
- stderr: {
71
- on: vi.fn((_event: string, cb: (d: Buffer) => void) => {
72
- stderrCb = cb;
73
- capture.stderr?.(cb);
74
- }),
75
- },
76
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
77
- if (event !== 'close') return;
78
- closeCb = cb;
79
- capture.close?.(cb);
80
- capture.onClose?.({
81
- stderr: d => stderrCb?.(d),
82
- close: code => closeCb?.(code),
83
- });
84
- }),
85
- kill: vi.fn(),
86
- killed: false,
87
- } as unknown as ChildProcess;
88
- }
89
-
90
- beforeEach(async () => {
91
- vi.clearAllMocks();
92
- vi.mocked(execSync).mockReset();
93
- vi.mocked(spawn).mockReset();
94
- vi.mocked(execSync).mockReturnValue('mutmut, version 3.0.0\n');
95
- tmpDir = join(tmpdir(), `xp-gate-mutmut-test-${Date.now()}`);
96
- MutmutRunner = (await import('../runners/mutmut-runner')).MutmutRunner;
97
- });
98
-
99
- afterEach(() => {
100
- vi.useRealTimers();
101
- vi.restoreAllMocks();
102
- });
103
-
104
- describe('name and extensions', () => {
105
- it('should have name "mutmut"', () => {
106
- const runner = new MutmutRunner();
107
- expect(runner.name).toBe('mutmut');
108
- });
109
-
110
- it('should handle .py extension', () => {
111
- const runner = new MutmutRunner();
112
- expect(runner.extensions).toContain('py');
113
- expect(runner.extensions).not.toContain('ts');
114
- expect(runner.extensions).not.toContain('go');
115
- });
116
- });
117
-
118
- describe('isAvailable', () => {
119
- it('should return true when mutmut is installed', async () => {
120
- vi.mocked(execSync).mockReturnValue('mutmut, version 3.0.0\n');
121
-
122
- const runner = new MutmutRunner('linux');
123
- const result = await runner.isAvailable();
124
- expect(result).toBe(true);
125
- expect(execSync).toHaveBeenCalledWith('mutmut --version', {
126
- stdio: 'pipe',
127
- timeout: 5000,
128
- });
129
- });
130
-
131
- it('should return false when mutmut is not installed', async () => {
132
- vi.mocked(execSync).mockImplementation(() => {
133
- throw new Error('command not found: mutmut');
134
- });
135
-
136
- const runner = new MutmutRunner();
137
- const result = await runner.isAvailable();
138
- expect(result).toBe(false);
139
- });
140
-
141
- it('should use WSL when native mutmut is unavailable on Windows', async () => {
142
- vi.mocked(execSync).mockImplementation((command) => {
143
- if (command === 'mutmut --version') {
144
- throw new Error('command not found: mutmut');
145
- }
146
- return 'mutmut, version 3.0.0\n';
147
- });
148
-
149
- const runner = new MutmutRunner('win32');
150
- const result = await runner.isAvailable();
151
-
152
- expect(result).toBe(true);
153
- // #410: win32 route is decided by the WSL probe alone (no native probe).
154
- expect(execSync).toHaveBeenCalledTimes(1);
155
- expect(execSync).toHaveBeenCalledWith('wsl mutmut --version', {
156
- stdio: 'pipe',
157
- timeout: 10000,
158
- });
159
- });
160
-
161
- it('should keep native detection unchanged on non-Windows platforms', async () => {
162
- vi.mocked(execSync).mockReturnValue('mutmut, version 3.0.0\n');
163
-
164
- const runner = new MutmutRunner('linux');
165
- const result = await runner.isAvailable();
166
-
167
- expect(result).toBe(true);
168
- expect(execSync).toHaveBeenCalledTimes(1);
169
- expect(execSync).toHaveBeenCalledWith('mutmut --version', {
170
- stdio: 'pipe',
171
- timeout: 5000,
172
- });
173
- });
174
-
175
- it('should report unavailable when native mutmut and WSL are unavailable', async () => {
176
- vi.mocked(execSync).mockImplementation(() => {
177
- throw new Error('command not found');
178
- });
179
-
180
- const runner = new MutmutRunner('win32');
181
- const result = await runner.isAvailable();
182
-
183
- expect(result).toBe(false);
184
- const outcome = await runner.run({
185
- files: ['src/main.py'],
186
- timeoutMs: 60000,
187
- cwd: tmpDir,
188
- });
189
-
190
- expect(outcome).toEqual({ report: null, timedOut: false });
191
- expect(spawn).not.toHaveBeenCalled();
192
- });
193
- });
194
-
195
- describe('run', () => {
196
- it('should spawn mutmut run and parse emoji progress', async () => {
197
- let stdoutCb: ((d: Buffer) => void) | null = null;
198
- let closeCb: ((code: number | null) => void) | null = null;
199
-
200
- vi.mocked(spawn).mockReturnValue(
201
- mockChildProcess({
202
- stdout: cb => { stdoutCb = cb; },
203
- close: cb => { closeCb = cb; },
204
- }),
205
- );
206
-
207
- // No existing pyproject.toml
208
- vi.mocked(existsSync).mockReturnValue(false);
209
-
210
- const runner = new MutmutRunner('linux');
211
- const promise = runner.run({
212
- files: ['src/main.py'],
213
- timeoutMs: 60000,
214
- cwd: tmpDir,
215
- });
216
-
217
- // Simulate stdout with emoji progress. One wait covers both callbacks --
218
- // they are captured by the same spawn invocation.
219
- const progressOutput =
220
- '38/38 🎉 9 🫥 29 ⏰ 0 🤔 0 🙁 0 🔇 0 🧙 0\n';
221
- await waitForSpawn();
222
- stdoutCb!(Buffer.from(progressOutput));
223
- closeCb!(0);
224
-
225
- const result = await promise;
226
-
227
- expect(spawn).toHaveBeenCalledWith(
228
- 'mutmut',
229
- ['run'],
230
- expect.objectContaining({ cwd: tmpDir }),
231
- );
232
- expect(result.timedOut).toBe(false);
233
- expect(result.report).not.toBeNull();
234
- expect(result.report!.mutationScore).toBeCloseTo(23.68, 1); // 9/38 * 100
235
- expect(result.report!.nrOfMutants).toBe(38);
236
- expect(result.report!.nrOfKilledMutants).toBe(9);
237
- expect(result.report!.nrOfSurvivedMutants).toBe(29);
238
- });
239
-
240
- it('should be unavailable on Windows when WSL is absent even if native mutmut is installed', async () => {
241
- const mockChild = {
242
- stdout: { on: vi.fn() },
243
- stderr: { on: vi.fn() },
244
- // Unavailable route: `run()` never spawns, so `close` is never subscribed.
245
- on: vi.fn(),
246
- kill: vi.fn(),
247
- killed: false,
248
- };
249
- vi.mocked(execSync).mockImplementation((command) => {
250
- if (command === 'mutmut --version') return 'mutmut, version 3.0.0\n';
251
- throw new Error('WSL unavailable');
252
- });
253
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
254
- vi.mocked(existsSync).mockReturnValue(false);
255
-
256
- const runner = new MutmutRunner('win32');
257
- // #410: native mutmut on Windows proves nothing about `mutmut run`
258
- // (fork()-based). The WSL route decides availability; no WSL → SKIP.
259
- expect(await runner.isAvailable()).toBe(false);
260
- const outcome = await runner.run({
261
- files: ['src/main.py'],
262
- timeoutMs: 60000,
263
- cwd: 'C:\\work\\project',
264
- });
265
-
266
- expect(outcome).toEqual({ report: null, timedOut: false });
267
- expect(spawn).not.toHaveBeenCalled();
268
- });
269
-
270
- it('should execute selected WSL route with Linux --cd and Windows host cwd', async () => {
271
- let closeCb: ((code: number | null) => void) | null = null;
272
- const mockChild = {
273
- stdout: { on: vi.fn() },
274
- stderr: { on: vi.fn() },
275
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
276
- if (event === 'close') closeCb = cb;
277
- }),
278
- kill: vi.fn(),
279
- killed: false,
280
- };
281
- vi.mocked(execSync).mockImplementation((command) => {
282
- if (command === 'mutmut --version') {
283
- throw new Error('native mutmut unavailable');
284
- }
285
- return 'mutmut, version 3.0.0\n';
286
- });
287
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
288
- vi.mocked(existsSync).mockReturnValue(false);
289
-
290
- const runner = new MutmutRunner('win32');
291
- expect(await runner.isAvailable()).toBe(true);
292
- const promise = runner.run({
293
- files: ['src/main.py'],
294
- timeoutMs: 60000,
295
- cwd: 'C:\\work\\project',
296
- });
297
- await waitForSpawn();
298
- closeCb!(0);
299
- await promise;
300
-
301
- expect(spawn).toHaveBeenCalledWith(
302
- 'wsl',
303
- ['--cd', '/mnt/c/work/project', 'mutmut', 'run'],
304
- expect.objectContaining({ cwd: 'C:\\work\\project' }),
305
- );
306
- expect(vi.mocked(spawn).mock.calls[0]?.[2]).not.toHaveProperty('shell');
307
- });
308
-
309
- it('should preserve spaced and metacharacter paths as one WSL argv item', async () => {
310
- let closeCb: ((code: number | null) => void) | null = null;
311
- const mockChild = {
312
- stdout: { on: vi.fn() },
313
- stderr: { on: vi.fn() },
314
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
315
- if (event === 'close') closeCb = cb;
316
- }),
317
- kill: vi.fn(),
318
- killed: false,
319
- };
320
- vi.mocked(execSync).mockImplementation((command) => {
321
- if (command === 'mutmut --version') throw new Error('native unavailable');
322
- return 'mutmut, version 3.0.0\n';
323
- });
324
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
325
- vi.mocked(existsSync).mockReturnValue(false);
326
-
327
- const runner = new MutmutRunner('win32');
328
- expect(await runner.isAvailable()).toBe(true);
329
- const promise = runner.run({
330
- files: ['src/main.py'],
331
- timeoutMs: 60000,
332
- cwd: 'C:\\work dir\\safe; echo injected',
333
- });
334
- await waitForSpawn();
335
- closeCb!(0);
336
- await promise;
337
-
338
- expect(spawn).toHaveBeenCalledWith(
339
- 'wsl',
340
- ['--cd', '/mnt/c/work dir/safe; echo injected', 'mutmut', 'run'],
341
- expect.objectContaining({ cwd: 'C:\\work dir\\safe; echo injected' }),
342
- );
343
- expect(vi.mocked(spawn).mock.calls[0]?.[2]).not.toHaveProperty('shell');
344
- });
345
-
346
- it.each([
347
- ['uppercase drive', 'C:\\Work\\Project', '/mnt/c/Work/Project'],
348
- ['forward slash drive', 'D:/Work/Project', '/mnt/d/Work/Project'],
349
- ])('should convert %s paths for WSL', async (_name, windowsPath, linuxPath) => {
350
- let closeCb: ((code: number | null) => void) | null = null;
351
- const mockChild = {
352
- stdout: { on: vi.fn() },
353
- stderr: { on: vi.fn() },
354
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
355
- if (event === 'close') closeCb = cb;
356
- }),
357
- kill: vi.fn(),
358
- killed: false,
359
- };
360
- vi.mocked(execSync).mockImplementation((command) => {
361
- if (command === 'mutmut --version') throw new Error('native unavailable');
362
- return 'mutmut, version 3.0.0\n';
363
- });
364
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
365
- vi.mocked(existsSync).mockReturnValue(false);
366
-
367
- const runner = new MutmutRunner('win32');
368
- expect(await runner.isAvailable()).toBe(true);
369
- const promise = runner.run({ files: ['src/main.py'], timeoutMs: 60000, cwd: windowsPath });
370
- await waitForSpawn();
371
- closeCb!(0);
372
- await promise;
373
-
374
- expect(vi.mocked(spawn).mock.calls[0]?.[1]).toEqual(['--cd', linuxPath, 'mutmut', 'run']);
375
- });
376
-
377
- it.each(['relative/project', '\\\\server\\share\\project'])(
378
- 'should fail closed for non-drive WSL path %s', async (cwd) => {
379
- vi.mocked(execSync).mockImplementation((command) => {
380
- if (command === 'mutmut --version') throw new Error('native unavailable');
381
- return 'mutmut, version 3.0.0\n';
382
- });
383
- vi.mocked(existsSync).mockReturnValue(false);
384
-
385
- const runner = new MutmutRunner('win32');
386
- expect(await runner.isAvailable()).toBe(true);
387
- const outcome = await runner.run({ files: ['src/main.py'], timeoutMs: 60000, cwd });
388
-
389
- expect(outcome).toEqual({ report: null, timedOut: false });
390
- expect(spawn).not.toHaveBeenCalled();
391
- },
392
- );
393
-
394
- it('should follow repeated native to WSL availability transitions', async () => {
395
- let closeCb: ((code: number | null) => void) | null = null;
396
- const mockChild = {
397
- stdout: { on: vi.fn() },
398
- stderr: { on: vi.fn() },
399
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
400
- if (event === 'close') closeCb = cb;
401
- }),
402
- kill: vi.fn(),
403
- killed: false,
404
- };
405
- let nativeAvailable = true;
406
- vi.mocked(execSync).mockImplementation((command) => {
407
- if (command === 'mutmut --version' && nativeAvailable) return 'native';
408
- if (command === 'wsl mutmut --version') return 'wsl';
409
- throw new Error('unavailable');
410
- });
411
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
412
- vi.mocked(existsSync).mockReturnValue(false);
413
-
414
- const runner = new MutmutRunner('win32');
415
- expect(await runner.isAvailable()).toBe(true);
416
- nativeAvailable = false;
417
- expect(await runner.isAvailable()).toBe(true);
418
- const promise = runner.run({ files: ['src/main.py'], timeoutMs: 60000, cwd: 'C:\\repo' });
419
- await waitForSpawn();
420
- closeCb!(0);
421
- await promise;
422
-
423
- expect(vi.mocked(spawn).mock.calls[0]?.[0]).toBe('wsl');
424
- });
425
-
426
- it('should keep the WSL route on Windows even when native mutmut becomes available', async () => {
427
- const mockChild = {
428
- stdout: { on: vi.fn() },
429
- stderr: { on: vi.fn() },
430
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
431
- if (event === 'close') cb(0);
432
- }),
433
- kill: vi.fn(),
434
- killed: false,
435
- };
436
- let nativeAvailable = false;
437
- vi.mocked(execSync).mockImplementation((command) => {
438
- if (command === 'mutmut --version' && nativeAvailable) return 'native';
439
- if (command === 'wsl mutmut --version') return 'wsl';
440
- throw new Error('unavailable');
441
- });
442
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
443
- vi.mocked(existsSync).mockReturnValue(false);
444
-
445
- const runner = new MutmutRunner('win32');
446
- expect(await runner.isAvailable()).toBe(true);
447
- nativeAvailable = true;
448
- // #410: even when native `mutmut --version` starts succeeding, the win32
449
- // route is decided by WSL alone — native success proves nothing about
450
- // `mutmut run` (fork()). The route must NOT flip to native.
451
- expect(await runner.isAvailable()).toBe(true);
452
- await runner.run({ files: ['src/main.py'], timeoutMs: 60000, cwd: 'C:\\repo' });
453
-
454
- expect(vi.mocked(spawn).mock.calls[0]?.[0]).toBe('wsl');
455
- });
456
-
457
- it('should stop spawning after availability transitions to unavailable', async () => {
458
- vi.mocked(execSync).mockImplementation(() => {
459
- throw new Error('unavailable');
460
- });
461
- vi.mocked(existsSync).mockReturnValue(false);
462
-
463
- const runner = new MutmutRunner('win32');
464
- expect(await runner.isAvailable()).toBe(false);
465
- const outcome = await runner.run({ files: ['src/main.py'], timeoutMs: 60000, cwd: 'C:\\repo' });
466
-
467
- expect(outcome).toEqual({ report: null, timedOut: false });
468
- expect(spawn).not.toHaveBeenCalled();
469
- });
470
-
471
- it('should clear timers when the child closes before timeout', async () => {
472
- vi.useFakeTimers();
473
- const mockChild = {
474
- stdout: { on: vi.fn() },
475
- stderr: { on: vi.fn() },
476
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
477
- if (event === 'close') cb(0);
478
- }),
479
- kill: vi.fn(),
480
- killed: false,
481
- };
482
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
483
- vi.mocked(existsSync).mockReturnValue(false);
484
-
485
- const result = await new MutmutRunner('linux').run({
486
- files: ['src/main.py'],
487
- timeoutMs: 100,
488
- cwd: tmpDir,
489
- });
490
- await vi.advanceTimersByTimeAsync(5100);
491
-
492
- expect(result.timedOut).toBe(false);
493
- expect(mockChild.kill).not.toHaveBeenCalled();
494
- });
495
-
496
- it('should clear timers when the child emits an error', async () => {
497
- vi.useFakeTimers();
498
- const mockChild = {
499
- stdout: { on: vi.fn() },
500
- stderr: { on: vi.fn() },
501
- on: vi.fn((event: string, cb: (error: Error) => void) => {
502
- if (event === 'error') cb(new Error('spawn failed'));
503
- }),
504
- kill: vi.fn(),
505
- killed: false,
506
- };
507
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
508
- vi.mocked(existsSync).mockReturnValue(false);
509
-
510
- const result = await new MutmutRunner('linux').run({
511
- files: ['src/main.py'],
512
- timeoutMs: 100,
513
- cwd: tmpDir,
514
- });
515
- await vi.advanceTimersByTimeAsync(5100);
516
-
517
- expect(result.error).toBe('spawn failed');
518
- expect(mockChild.kill).not.toHaveBeenCalled();
519
- });
520
-
521
- it('should report timeout when the timed-out process closes with a code', async () => {
522
- vi.useFakeTimers();
523
- let closeCb: ((code: number | null) => void) | null = null;
524
- const mockChild = {
525
- stdout: { on: vi.fn() },
526
- stderr: { on: vi.fn() },
527
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
528
- if (event === 'close') closeCb = cb;
529
- }),
530
- kill: vi.fn(),
531
- killed: false,
532
- };
533
- vi.mocked(execSync).mockImplementation((command) => {
534
- if (command === 'mutmut --version') throw new Error('native unavailable');
535
- return 'wsl';
536
- });
537
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
538
- vi.mocked(existsSync).mockReturnValue(false);
539
-
540
- const runner = new MutmutRunner('win32');
541
- expect(await runner.isAvailable()).toBe(true);
542
- const promise = runner.run({ files: ['src/main.py'], timeoutMs: 100, cwd: 'C:\\repo' });
543
- await vi.advanceTimersByTimeAsync(100);
544
- await waitForSpawn();
545
- closeCb!(1);
546
- const outcome = await promise;
547
-
548
- expect(outcome.timedOut).toBe(true);
549
- });
550
-
551
- it('should escalate to SIGKILL when SIGTERM does not close the child', async () => {
552
- vi.useFakeTimers();
553
- let closeCb: ((code: number | null) => void) | null = null;
554
- let killCount = 0;
555
- const mockChild = {
556
- stdout: { on: vi.fn() },
557
- stderr: { on: vi.fn() },
558
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
559
- if (event === 'close') closeCb = cb;
560
- }),
561
- kill: vi.fn(() => {
562
- killCount += 1;
563
- if (killCount === 2) closeCb?.(null);
564
- return true;
565
- }),
566
- killed: false,
567
- };
568
- vi.mocked(execSync).mockImplementation((command) => {
569
- if (command === 'mutmut --version') throw new Error('native unavailable');
570
- return 'wsl';
571
- });
572
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
573
- vi.mocked(existsSync).mockReturnValue(false);
574
-
575
- const runner = new MutmutRunner('win32');
576
- expect(await runner.isAvailable()).toBe(true);
577
- const promise = runner.run({ files: ['src/main.py'], timeoutMs: 100, cwd: 'C:\\repo' });
578
- await vi.advanceTimersByTimeAsync(100);
579
- await vi.advanceTimersByTimeAsync(5000);
580
-
581
- expect(mockChild.kill).toHaveBeenNthCalledWith(1, 'SIGTERM');
582
- expect(mockChild.kill).toHaveBeenNthCalledWith(2, 'SIGKILL');
583
- await promise;
584
- });
585
-
586
- it('should kill the selected WSL process and report timeout', async () => {
587
- vi.useFakeTimers();
588
- let closeCb: ((code: number | null) => void) | null = null;
589
- const mockChild = {
590
- stdout: { on: vi.fn() },
591
- stderr: { on: vi.fn() },
592
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
593
- if (event === 'close') closeCb = cb;
594
- }),
595
- kill: vi.fn(() => {
596
- closeCb?.(null);
597
- return true;
598
- }),
599
- killed: false,
600
- };
601
- vi.mocked(execSync).mockImplementation((command) => {
602
- if (command === 'mutmut --version') throw new Error('native unavailable');
603
- return 'mutmut, version 3.0.0\n';
604
- });
605
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
606
- vi.mocked(existsSync).mockReturnValue(false);
607
-
608
- const runner = new MutmutRunner('win32');
609
- expect(await runner.isAvailable()).toBe(true);
610
- const promise = runner.run({
611
- files: ['src/main.py'],
612
- timeoutMs: 100,
613
- cwd: 'D:\\repo',
614
- });
615
- await vi.advanceTimersByTimeAsync(100);
616
- const result = await promise;
617
-
618
- expect(spawn).toHaveBeenCalledWith(
619
- 'wsl',
620
- ['--cd', '/mnt/d/repo', 'mutmut', 'run'],
621
- expect.objectContaining({ cwd: 'D:\\repo' }),
622
- );
623
- expect(mockChild.kill).toHaveBeenCalledWith('SIGTERM');
624
- expect(result).toEqual({ report: null, timedOut: true });
625
- expect(vi.getTimerCount()).toBe(0);
626
- });
627
-
628
- it('should return timedOut=false when process closes before timeout (code=null)', async () => {
629
- const mockChild = {
630
- stdout: { on: vi.fn() },
631
- stderr: { on: vi.fn() },
632
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
633
- if (event === 'close') setTimeout(() => cb(null), 10);
634
- }),
635
- kill: vi.fn(),
636
- killed: false,
637
- };
638
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
639
- vi.mocked(existsSync).mockReturnValue(false);
640
-
641
- const runner = new MutmutRunner();
642
- const result = await runner.run({
643
- files: ['src/main.py'],
644
- timeoutMs: 100,
645
- cwd: tmpDir,
646
- });
647
-
648
- expect(result.timedOut).toBe(false);
649
- expect(result.report).toBeNull();
650
- });
651
-
652
- it('should return error when spawn fails', async () => {
653
- const mockChild = {
654
- stdout: { on: vi.fn() },
655
- stderr: { on: vi.fn() },
656
- on: vi.fn((event: string, cb: (err: Error) => void) => {
657
- if (event === 'error') setTimeout(() => cb(new Error('spawn mutmut ENOENT')), 10);
658
- }),
659
- kill: vi.fn(),
660
- killed: false,
661
- };
662
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
663
- vi.mocked(existsSync).mockReturnValue(false);
664
-
665
- const runner = new MutmutRunner();
666
- const result = await runner.run({
667
- files: ['src/main.py'],
668
- timeoutMs: 60000,
669
- cwd: tmpDir,
670
- });
671
-
672
- expect(result.report).toBeNull();
673
- expect(result.timedOut).toBe(false);
674
- expect(result.error).toBe('spawn mutmut ENOENT');
675
- });
676
-
677
- it('should return error message when exit code is non-zero', async () => {
678
- // The stderr line and the non-zero exit must arrive together, so the
679
- // factory emits both as soon as the runner subscribes to `close`.
680
- vi.mocked(spawn).mockReturnValue(
681
- mockChildProcess({
682
- onClose: emit => {
683
- setTimeout(() => {
684
- emit.stderr(Buffer.from('mutation failed'));
685
- emit.close(1);
686
- }, 10);
687
- },
688
- }),
689
- );
690
- vi.mocked(existsSync).mockReturnValue(false);
691
-
692
- const runner = new MutmutRunner();
693
- const result = await runner.run({
694
- files: ['src/main.py'],
695
- timeoutMs: 60000,
696
- cwd: tmpDir,
697
- });
698
-
699
- expect(result.timedOut).toBe(false);
700
- expect(result.error).toBe('mutation failed');
701
- });
702
- });
703
-
704
- describe('emoji progress parsing', () => {
705
- it('should parse standard progress line with all emojis', async () => {
706
- let stdoutCb: ((d: Buffer) => void) | null = null;
707
- let closeCb: ((code: number | null) => void) | null = null;
708
-
709
- const mockChild = {
710
- stdout: {
711
- on: vi.fn((_event: string, cb: (d: Buffer) => void) => {
712
- stdoutCb = cb;
713
- }),
714
- },
715
- stderr: { on: vi.fn() },
716
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
717
- if (event === 'close') closeCb = cb;
718
- }),
719
- kill: vi.fn(),
720
- killed: false,
721
- };
722
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
723
- vi.mocked(existsSync).mockReturnValue(false);
724
-
725
- const runner = new MutmutRunner();
726
- const promise = runner.run({
727
- files: ['src/calc.py'],
728
- timeoutMs: 60000,
729
- cwd: tmpDir,
730
- });
731
-
732
- const output = '20/20 🎉 10 🫥 5 ⏰ 2 🤔 1 🙁 2 🔇 0 🧙 0\n';
733
- await waitForSpawn();
734
- stdoutCb!(Buffer.from(output));
735
- closeCb!(0);
736
-
737
- const result = await promise;
738
- expect(result.report).not.toBeNull();
739
- // killed=10, survived=5+2+1+2+0+0=10, total=20
740
- expect(result.report!.nrOfKilledMutants).toBe(10);
741
- expect(result.report!.nrOfSurvivedMutants).toBe(10);
742
- expect(result.report!.nrOfMutants).toBe(20);
743
- expect(result.report!.mutationScore).toBe(50);
744
- });
745
-
746
- it('should return null report when no progress line found', async () => {
747
- let stdoutCb: ((d: Buffer) => void) | null = null;
748
- let closeCb: ((code: number | null) => void) | null = null;
749
-
750
- const mockChild = {
751
- stdout: {
752
- on: vi.fn((_event: string, cb: (d: Buffer) => void) => {
753
- stdoutCb = cb;
754
- }),
755
- },
756
- stderr: { on: vi.fn() },
757
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
758
- if (event === 'close') closeCb = cb;
759
- }),
760
- kill: vi.fn(),
761
- killed: false,
762
- };
763
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
764
- vi.mocked(existsSync).mockReturnValue(false);
765
-
766
- const runner = new MutmutRunner();
767
- const promise = runner.run({
768
- files: ['src/main.py'],
769
- timeoutMs: 60000,
770
- cwd: tmpDir,
771
- });
772
-
773
- await waitForSpawn();
774
-
775
- stdoutCb!(Buffer.from('Some random output without emoji\n'));
776
- await waitForSpawn();
777
- closeCb!(0);
778
- const result = await promise;
779
- expect(result.report).toBeNull();
780
- expect(result.timedOut).toBe(false);
781
- });
782
-
783
- it('should return null report when all mutant counts are zero', async () => {
784
- let stdoutCb: ((d: Buffer) => void) | null = null;
785
- let closeCb: ((code: number | null) => void) | null = null;
786
-
787
- const mockChild = {
788
- stdout: {
789
- on: vi.fn((_event: string, cb: (d: Buffer) => void) => {
790
- stdoutCb = cb;
791
- }),
792
- },
793
- stderr: { on: vi.fn() },
794
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
795
- if (event === 'close') closeCb = cb;
796
- }),
797
- kill: vi.fn(),
798
- killed: false,
799
- };
800
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
801
- vi.mocked(existsSync).mockReturnValue(false);
802
-
803
- const runner = new MutmutRunner();
804
- const promise = runner.run({
805
- files: ['src/main.py'],
806
- timeoutMs: 60000,
807
- cwd: tmpDir,
808
- });
809
-
810
- const output = '0/0 🎉 0 🫥 0 ⏰ 0 🤔 0 🙁 0 🔇 0 🧙 0\n';
811
- await waitForSpawn();
812
- stdoutCb!(Buffer.from(output));
813
- closeCb!(0);
814
-
815
- const result = await promise;
816
- expect(result.report).toBeNull();
817
- });
818
- });
819
-
820
- describe('pyproject.toml config writing', () => {
821
- it('should create new pyproject.toml when file does not exist', async () => {
822
- let closeCb: ((code: number | null) => void) | null = null;
823
- const mockChild = {
824
- stdout: { on: vi.fn() },
825
- stderr: { on: vi.fn() },
826
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
827
- if (event === 'close') closeCb = cb;
828
- }),
829
- kill: vi.fn(),
830
- killed: false,
831
- };
832
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
833
- vi.mocked(existsSync).mockReturnValue(false);
834
-
835
- const runner = new MutmutRunner();
836
- const promise = runner.run({
837
- files: ['src/main.py', 'src/utils.py'],
838
- timeoutMs: 60000,
839
- cwd: tmpDir,
840
- });
841
- await waitForSpawn();
842
- closeCb!(0);
843
- await promise;
844
-
845
- // Should have written pyproject.toml with source_paths
846
- expect(writeFileSync).toHaveBeenCalledWith(
847
- join(tmpDir, 'pyproject.toml'),
848
- expect.stringContaining('[tool.mutmut]'),
849
- { encoding: 'utf-8' },
850
- );
851
- expect(writeFileSync).toHaveBeenCalledWith(
852
- join(tmpDir, 'pyproject.toml'),
853
- expect.stringContaining('source_paths = ["src"]'),
854
- { encoding: 'utf-8' },
855
- );
856
- });
857
-
858
- it('should update existing pyproject.toml with [tool.mutmut] section', async () => {
859
- let closeCb: ((code: number | null) => void) | null = null;
860
- const mockChild = {
861
- stdout: { on: vi.fn() },
862
- stderr: { on: vi.fn() },
863
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
864
- if (event === 'close') closeCb = cb;
865
- }),
866
- kill: vi.fn(),
867
- killed: false,
868
- };
869
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
870
-
871
- // First call for pyproject.toml exists check, second for backup
872
- vi.mocked(existsSync).mockImplementation((path) => {
873
- const p = path.toString();
874
- if (p.endsWith('pyproject.toml')) return true;
875
- if (p.endsWith('.xp-gate-backup')) return false;
876
- return false;
877
- });
878
- vi.mocked(readFileSync).mockImplementation((path) => {
879
- const p = path.toString();
880
- if (p.endsWith('pyproject.toml')) {
881
- return '[tool.mutmut]\nsource_paths = ["old_path"]\n';
882
- }
883
- return '';
884
- });
885
-
886
- const runner = new MutmutRunner();
887
- const promise = runner.run({
888
- files: ['src/main.py'],
889
- timeoutMs: 60000,
890
- cwd: tmpDir,
891
- });
892
- await waitForSpawn();
893
- closeCb!(0);
894
- await promise;
895
-
896
- // Should have backed up and then written updated config
897
- expect(writeFileSync).toHaveBeenCalledWith(
898
- join(tmpDir, 'pyproject.toml.xp-gate-backup'),
899
- '[tool.mutmut]\nsource_paths = ["old_path"]\n',
900
- { encoding: 'utf-8' },
901
- );
902
- expect(writeFileSync).toHaveBeenCalledWith(
903
- join(tmpDir, 'pyproject.toml'),
904
- expect.stringContaining('source_paths = ["src"]'),
905
- { encoding: 'utf-8' },
906
- );
907
- });
908
-
909
- it('should append [tool.mutmut] section to existing file without it', async () => {
910
- let closeCb: ((code: number | null) => void) | null = null;
911
- const mockChild = {
912
- stdout: { on: vi.fn() },
913
- stderr: { on: vi.fn() },
914
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
915
- if (event === 'close') closeCb = cb;
916
- }),
917
- kill: vi.fn(),
918
- killed: false,
919
- };
920
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
921
-
922
- vi.mocked(existsSync).mockImplementation((path) => {
923
- const p = path.toString();
924
- if (p.endsWith('pyproject.toml')) return true;
925
- if (p.endsWith('.xp-gate-backup')) return false;
926
- return false;
927
- });
928
- vi.mocked(readFileSync).mockImplementation((path) => {
929
- const p = path.toString();
930
- if (p.endsWith('pyproject.toml')) {
931
- return '[tool.pytest]\ntestpaths = ["tests"]\n';
932
- }
933
- return '';
934
- });
935
-
936
- const runner = new MutmutRunner();
937
- const promise = runner.run({
938
- files: ['src/main.py'],
939
- timeoutMs: 60000,
940
- cwd: tmpDir,
941
- });
942
- await waitForSpawn();
943
- closeCb!(0);
944
- await promise;
945
-
946
- // Should have appended [tool.mutmut] section
947
- const writeCalls = vi.mocked(writeFileSync).mock.calls;
948
- const configWrite = writeCalls.find(
949
- (c) => c[0] === join(tmpDir, 'pyproject.toml') && c[1].toString().includes('[tool.mutmut]'),
950
- );
951
- expect(configWrite).toBeDefined();
952
- expect(configWrite![1].toString()).toContain('[tool.pytest]');
953
- expect(configWrite![1].toString()).toContain('[tool.mutmut]');
954
- });
955
- });
956
-
957
- describe('cleanup', () => {
958
- it('should restore backup after run completes', async () => {
959
- let closeCb: ((code: number | null) => void) | null = null;
960
- vi.mocked(spawn).mockReturnValue(
961
- mockChildProcess({ close: cb => { closeCb = cb; } }),
962
- );
963
-
964
- vi.mocked(existsSync).mockImplementation((path) => {
965
- const p = path.toString();
966
- if (p.endsWith('pyproject.toml') && !p.endsWith('.xp-gate-backup')) {
967
- return true; // exists both initially and during cleanup
968
- }
969
- if (p.endsWith('.xp-gate-backup')) return true; // backup exists for cleanup
970
- return false;
971
- });
972
-
973
- const originalContent = '[tool.mutmut]\nsource_paths = ["original"]\n';
974
- vi.mocked(readFileSync).mockImplementation((path) => {
975
- const p = path.toString();
976
- if (p.endsWith('pyproject.toml.xp-gate-backup')) return originalContent;
977
- if (p.endsWith('pyproject.toml')) return originalContent;
978
- return '';
979
- });
980
-
981
- const runner = new MutmutRunner();
982
- const promise = runner.run({
983
- files: ['src/main.py'],
984
- timeoutMs: 60000,
985
- cwd: tmpDir,
986
- });
987
- await waitForSpawn();
988
- closeCb!(0);
989
- await promise;
990
-
991
- // Should have restored the backup
992
- expect(readFileSync).toHaveBeenCalledWith(
993
- join(tmpDir, 'pyproject.toml.xp-gate-backup'),
994
- 'utf-8',
995
- );
996
- expect(writeFileSync).toHaveBeenCalledWith(
997
- join(tmpDir, 'pyproject.toml'),
998
- originalContent,
999
- { encoding: 'utf-8' },
1000
- );
1001
- expect(unlinkSync).toHaveBeenCalledWith(
1002
- join(tmpDir, 'pyproject.toml.xp-gate-backup'),
1003
- );
1004
- });
1005
-
1006
- it('should remove pyproject.toml when no backup existed', async () => {
1007
- let closeCb: ((code: number | null) => void) | null = null;
1008
- const mockChild = {
1009
- stdout: { on: vi.fn() },
1010
- stderr: { on: vi.fn() },
1011
- on: vi.fn((event: string, cb: (code: number | null) => void) => {
1012
- if (event === 'close') closeCb = cb;
1013
- }),
1014
- kill: vi.fn(),
1015
- killed: false,
1016
- };
1017
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
1018
-
1019
- let pyprojectExistsCallCount = 0;
1020
- vi.mocked(existsSync).mockImplementation((path) => {
1021
- const p = path.toString();
1022
- if (p.endsWith('.xp-gate-backup')) return false;
1023
- if (p.endsWith('pyproject.toml')) {
1024
- pyprojectExistsCallCount++;
1025
- // Calls 1-2: run() + writeMutmutConfig() → false (no pre-existing file)
1026
- // Call 3: cleanup finally block → true (code created it via mocked writeFileSync)
1027
- return pyprojectExistsCallCount > 2;
1028
- }
1029
- return false;
1030
- });
1031
-
1032
- const runner = new MutmutRunner();
1033
- const promise = runner.run({
1034
- files: ['src/main.py'],
1035
- timeoutMs: 60000,
1036
- cwd: tmpDir,
1037
- });
1038
- await waitForSpawn();
1039
- closeCb!(0);
1040
- await promise;
1041
-
1042
- expect(unlinkSync).toHaveBeenCalledWith(join(tmpDir, 'pyproject.toml'));
1043
- expect(readFileSync).not.toHaveBeenCalledWith(
1044
- join(tmpDir, 'pyproject.toml.xp-gate-backup'),
1045
- expect.anything(),
1046
- );
1047
- });
1048
- });
1049
- });