@mutineerjs/mutineer 0.2.3 → 0.3.2

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 (162) hide show
  1. package/README.md +48 -42
  2. package/dist/bin/mutineer.js +0 -0
  3. package/dist/core/__tests__/module.spec.js +66 -3
  4. package/dist/core/__tests__/sfc.spec.js +76 -0
  5. package/dist/core/__tests__/variant-utils.spec.js +93 -0
  6. package/dist/mutators/__tests__/operator.spec.js +169 -0
  7. package/dist/mutators/__tests__/registry.spec.js +6 -0
  8. package/dist/mutators/__tests__/return-value.spec.js +239 -0
  9. package/dist/mutators/__tests__/utils.spec.js +68 -1
  10. package/dist/mutators/operator.d.ts +25 -0
  11. package/dist/mutators/operator.js +50 -0
  12. package/dist/mutators/registry.d.ts +6 -28
  13. package/dist/mutators/registry.js +14 -66
  14. package/dist/mutators/return-value.d.ts +39 -0
  15. package/dist/mutators/return-value.js +104 -0
  16. package/dist/mutators/utils.d.ts +21 -0
  17. package/dist/mutators/utils.js +44 -27
  18. package/dist/runner/__tests__/args.spec.js +225 -0
  19. package/dist/runner/__tests__/cache.spec.js +180 -0
  20. package/dist/runner/__tests__/changed.spec.js +227 -0
  21. package/dist/runner/__tests__/cleanup.spec.js +41 -0
  22. package/dist/runner/__tests__/config.spec.js +71 -0
  23. package/dist/runner/__tests__/coverage-resolver.spec.js +171 -0
  24. package/dist/runner/__tests__/pool-executor.spec.js +211 -0
  25. package/dist/runner/__tests__/tasks.spec.js +95 -0
  26. package/dist/runner/__tests__/variants.spec.js +261 -0
  27. package/dist/runner/args.d.ts +5 -0
  28. package/dist/runner/args.js +7 -0
  29. package/dist/runner/config.js +2 -2
  30. package/dist/runner/coverage-resolver.d.ts +21 -0
  31. package/dist/runner/coverage-resolver.js +96 -0
  32. package/dist/runner/discover.js +2 -1
  33. package/dist/runner/jest/__tests__/adapter.spec.js +1 -1
  34. package/dist/runner/jest/__tests__/pool.spec.d.ts +1 -0
  35. package/dist/runner/jest/__tests__/pool.spec.js +211 -0
  36. package/dist/runner/jest/__tests__/worker-runtime.spec.d.ts +1 -0
  37. package/dist/runner/jest/__tests__/worker-runtime.spec.js +148 -0
  38. package/dist/runner/jest/adapter.js +1 -1
  39. package/dist/runner/jest/pool.d.ts +1 -1
  40. package/dist/runner/jest/pool.js +6 -6
  41. package/dist/runner/jest/worker.mjs +1 -1
  42. package/dist/runner/orchestrator.js +43 -295
  43. package/dist/runner/pool-executor.d.ts +17 -0
  44. package/dist/runner/pool-executor.js +143 -0
  45. package/dist/runner/shared/__tests__/mutant-paths.spec.d.ts +1 -0
  46. package/dist/runner/shared/__tests__/mutant-paths.spec.js +66 -0
  47. package/dist/runner/shared/__tests__/redirect-state.spec.d.ts +1 -0
  48. package/dist/runner/shared/__tests__/redirect-state.spec.js +56 -0
  49. package/dist/runner/shared/index.d.ts +1 -1
  50. package/dist/runner/shared/index.js +1 -1
  51. package/dist/runner/shared/redirect-state.d.ts +2 -2
  52. package/dist/runner/shared/redirect-state.js +4 -4
  53. package/dist/runner/tasks.d.ts +12 -0
  54. package/dist/runner/tasks.js +25 -0
  55. package/dist/runner/types.d.ts +1 -1
  56. package/dist/runner/variants.d.ts +17 -2
  57. package/dist/runner/variants.js +33 -0
  58. package/dist/runner/vitest/__tests__/adapter.spec.js +1 -1
  59. package/dist/runner/vitest/__tests__/pool.spec.js +1 -1
  60. package/dist/runner/vitest/__tests__/redirect-loader.spec.js +87 -1
  61. package/dist/runner/vitest/__tests__/worker-runtime.spec.js +84 -0
  62. package/dist/runner/vitest/adapter.js +1 -1
  63. package/dist/runner/vitest/index.d.ts +0 -1
  64. package/dist/runner/vitest/index.js +0 -1
  65. package/dist/runner/vitest/pool.d.ts +1 -1
  66. package/dist/runner/vitest/pool.js +7 -7
  67. package/dist/runner/vitest/redirect-loader.d.ts +1 -1
  68. package/dist/runner/vitest/redirect-loader.js +1 -1
  69. package/dist/runner/vitest/worker-runtime.js +3 -3
  70. package/dist/runner/vitest/worker.mjs +1 -1
  71. package/dist/utils/__tests__/coverage.spec.js +167 -0
  72. package/dist/utils/__tests__/logger.spec.d.ts +1 -0
  73. package/dist/utils/__tests__/logger.spec.js +61 -0
  74. package/dist/utils/__tests__/normalizePath.spec.d.ts +1 -0
  75. package/dist/utils/__tests__/normalizePath.spec.js +22 -0
  76. package/dist/utils/__tests__/progress.spec.js +96 -0
  77. package/package.json +71 -22
  78. package/dist/admin/assets/index-B7nXq-e7.js +0 -32
  79. package/dist/admin/assets/index-B7nXq-e7.js.map +0 -1
  80. package/dist/admin/assets/index-BDQLkBUE.js +0 -32
  81. package/dist/admin/assets/index-BDQLkBUE.js.map +0 -1
  82. package/dist/admin/assets/index-DVkP-Tc7.css +0 -1
  83. package/dist/admin/index.html +0 -13
  84. package/dist/admin/server/admin.d.ts +0 -6
  85. package/dist/admin/server/admin.js +0 -234
  86. package/dist/bin/mutate-vitest.d.ts +0 -2
  87. package/dist/bin/mutate-vitest.js +0 -90
  88. package/dist/plugin/viteMutate.d.ts +0 -15
  89. package/dist/plugin/viteMutate.js +0 -52
  90. package/dist/plugin/vitest.setup.d.ts +0 -47
  91. package/dist/plugin/vitest.setup.js +0 -118
  92. package/dist/plugin/withVitest.d.ts +0 -13
  93. package/dist/plugin/withVitest.js +0 -30
  94. package/dist/runner/__tests__/orchestrator.spec.js +0 -55
  95. package/dist/runner/adapters/__tests__/jest.spec.js +0 -88
  96. package/dist/runner/adapters/__tests__/vitest-worker-runtime.spec.js +0 -59
  97. package/dist/runner/adapters/__tests__/vitest.spec.js +0 -118
  98. package/dist/runner/adapters/index.d.ts +0 -10
  99. package/dist/runner/adapters/index.js +0 -9
  100. package/dist/runner/adapters/jest/__tests__/index.spec.js +0 -88
  101. package/dist/runner/adapters/jest/index.d.ts +0 -24
  102. package/dist/runner/adapters/jest/index.js +0 -216
  103. package/dist/runner/adapters/jest/worker-runtime.d.ts +0 -37
  104. package/dist/runner/adapters/jest/worker-runtime.js +0 -171
  105. package/dist/runner/adapters/jest-worker-runtime.d.ts +0 -37
  106. package/dist/runner/adapters/jest-worker-runtime.js +0 -171
  107. package/dist/runner/adapters/jest.d.ts +0 -24
  108. package/dist/runner/adapters/jest.js +0 -216
  109. package/dist/runner/adapters/types.d.ts +0 -89
  110. package/dist/runner/adapters/types.js +0 -8
  111. package/dist/runner/adapters/vitest/__tests__/index.spec.js +0 -118
  112. package/dist/runner/adapters/vitest/__tests__/worker-runtime.spec.js +0 -59
  113. package/dist/runner/adapters/vitest/index.d.ts +0 -33
  114. package/dist/runner/adapters/vitest/index.js +0 -267
  115. package/dist/runner/adapters/vitest/worker-runtime.d.ts +0 -25
  116. package/dist/runner/adapters/vitest/worker-runtime.js +0 -118
  117. package/dist/runner/adapters/vitest-worker-runtime.d.ts +0 -25
  118. package/dist/runner/adapters/vitest-worker-runtime.js +0 -118
  119. package/dist/runner/adapters/vitest.d.ts +0 -33
  120. package/dist/runner/adapters/vitest.js +0 -267
  121. package/dist/runner/pool/__tests__/index.spec.js +0 -83
  122. package/dist/runner/pool/__tests__/pool-plugin.spec.js +0 -59
  123. package/dist/runner/pool/__tests__/pool-redirect-loader.spec.js +0 -78
  124. package/dist/runner/pool/index.d.ts +0 -8
  125. package/dist/runner/pool/index.js +0 -9
  126. package/dist/runner/pool/jest/pool.d.ts +0 -52
  127. package/dist/runner/pool/jest/pool.js +0 -309
  128. package/dist/runner/pool/jest/worker.mjs +0 -60
  129. package/dist/runner/pool/jest-pool.d.ts +0 -52
  130. package/dist/runner/pool/jest-pool.js +0 -309
  131. package/dist/runner/pool/jest-worker.mjs +0 -60
  132. package/dist/runner/pool/plugin.d.ts +0 -18
  133. package/dist/runner/pool/plugin.js +0 -60
  134. package/dist/runner/pool/pool-plugin.d.ts +0 -18
  135. package/dist/runner/pool/pool-plugin.js +0 -60
  136. package/dist/runner/pool/pool-redirect-loader.d.ts +0 -19
  137. package/dist/runner/pool/pool-redirect-loader.js +0 -116
  138. package/dist/runner/pool/pool-redirect-loader.mjs +0 -146
  139. package/dist/runner/pool/redirect-loader.d.ts +0 -19
  140. package/dist/runner/pool/redirect-loader.js +0 -116
  141. package/dist/runner/pool/vitest/pool.d.ts +0 -70
  142. package/dist/runner/pool/vitest/pool.js +0 -376
  143. package/dist/runner/pool/vitest/worker.d.mts +0 -15
  144. package/dist/runner/pool/vitest/worker.mjs +0 -96
  145. package/dist/runner/pool/vitest-worker.d.mts +0 -15
  146. package/dist/runner/pool/vitest-worker.mjs +0 -96
  147. package/dist/runner/shared-module-redirect.d.ts +0 -56
  148. package/dist/runner/shared-module-redirect.js +0 -84
  149. package/dist/types/api.d.ts +0 -20
  150. /package/dist/{runner/__tests__/orchestrator.spec.d.ts → core/__tests__/sfc.spec.d.ts} +0 -0
  151. /package/dist/{runner/adapters/__tests__/jest.spec.d.ts → core/__tests__/variant-utils.spec.d.ts} +0 -0
  152. /package/dist/{runner/adapters/__tests__/vitest-worker-runtime.spec.d.ts → mutators/__tests__/operator.spec.d.ts} +0 -0
  153. /package/dist/{runner/adapters/__tests__/vitest.spec.d.ts → mutators/__tests__/return-value.spec.d.ts} +0 -0
  154. /package/dist/runner/{adapters/jest/__tests__/index.spec.d.ts → __tests__/args.spec.d.ts} +0 -0
  155. /package/dist/runner/{adapters/vitest/__tests__/index.spec.d.ts → __tests__/cache.spec.d.ts} +0 -0
  156. /package/dist/runner/{adapters/vitest/__tests__/worker-runtime.spec.d.ts → __tests__/changed.spec.d.ts} +0 -0
  157. /package/dist/runner/{pool/__tests__/index.spec.d.ts → __tests__/cleanup.spec.d.ts} +0 -0
  158. /package/dist/runner/{pool/__tests__/pool-plugin.spec.d.ts → __tests__/config.spec.d.ts} +0 -0
  159. /package/dist/runner/{pool/__tests__/pool-redirect-loader.spec.d.ts → __tests__/coverage-resolver.spec.d.ts} +0 -0
  160. /package/dist/runner/{pool/jest-worker.d.mts → __tests__/pool-executor.spec.d.ts} +0 -0
  161. /package/dist/runner/{pool/jest/worker.d.mts → __tests__/tasks.spec.d.ts} +0 -0
  162. /package/dist/{types/api.js → runner/__tests__/variants.spec.d.ts} +0 -0
@@ -0,0 +1,56 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import { initialiseRedirectState, setRedirect, getRedirect, clearRedirect, } from '../redirect-state.js';
3
+ describe('redirect-state', () => {
4
+ beforeEach(() => {
5
+ initialiseRedirectState();
6
+ });
7
+ describe('initialiseRedirectState', () => {
8
+ it('sets global redirect to null/null', () => {
9
+ expect(globalThis.__mutineer_redirect__).toEqual({
10
+ from: null,
11
+ to: null,
12
+ });
13
+ });
14
+ });
15
+ describe('setRedirect', () => {
16
+ it('sets the redirect config', () => {
17
+ setRedirect({ from: '/src/foo.ts', to: '/tmp/mutant.ts' });
18
+ expect(globalThis.__mutineer_redirect__).toEqual({
19
+ from: '/src/foo.ts',
20
+ to: '/tmp/mutant.ts',
21
+ });
22
+ });
23
+ });
24
+ describe('getRedirect', () => {
25
+ it('returns null when no redirect is set', () => {
26
+ expect(getRedirect()).toBeNull();
27
+ });
28
+ it('returns the redirect config when set', () => {
29
+ setRedirect({ from: '/src/foo.ts', to: '/tmp/mutant.ts' });
30
+ const redirect = getRedirect();
31
+ expect(redirect).toEqual({
32
+ from: '/src/foo.ts',
33
+ to: '/tmp/mutant.ts',
34
+ });
35
+ });
36
+ it('returns null when from is null', () => {
37
+ globalThis.__mutineer_redirect__ = { from: null, to: '/tmp/mutant.ts' };
38
+ expect(getRedirect()).toBeNull();
39
+ });
40
+ it('returns null when to is null', () => {
41
+ globalThis.__mutineer_redirect__ = { from: '/src/foo.ts', to: null };
42
+ expect(getRedirect()).toBeNull();
43
+ });
44
+ });
45
+ describe('clearRedirect', () => {
46
+ it('resets the redirect to null/null', () => {
47
+ setRedirect({ from: '/src/foo.ts', to: '/tmp/mutant.ts' });
48
+ clearRedirect();
49
+ expect(getRedirect()).toBeNull();
50
+ expect(globalThis.__mutineer_redirect__).toEqual({
51
+ from: null,
52
+ to: null,
53
+ });
54
+ });
55
+ });
56
+ });
@@ -5,5 +5,5 @@
5
5
  * including mutant file path generation and redirect state management.
6
6
  */
7
7
  export { getMutantFilePath } from './mutant-paths.js';
8
- export { setRedirect, getRedirect, clearRedirect, initializeRedirectState, } from './redirect-state.js';
8
+ export { setRedirect, getRedirect, clearRedirect, initialiseRedirectState, } from './redirect-state.js';
9
9
  export type { RedirectConfig } from './redirect-state.js';
@@ -5,4 +5,4 @@
5
5
  * including mutant file path generation and redirect state management.
6
6
  */
7
7
  export { getMutantFilePath } from './mutant-paths.js';
8
- export { setRedirect, getRedirect, clearRedirect, initializeRedirectState, } from './redirect-state.js';
8
+ export { setRedirect, getRedirect, clearRedirect, initialiseRedirectState, } from './redirect-state.js';
@@ -23,10 +23,10 @@ export interface RedirectConfig {
23
23
  readonly to: string;
24
24
  }
25
25
  /**
26
- * Initialize the global redirect state.
26
+ * Initialise the global redirect state.
27
27
  * Must be called once at module load time.
28
28
  */
29
- export declare function initializeRedirectState(): void;
29
+ export declare function initialiseRedirectState(): void;
30
30
  /**
31
31
  * Set the active redirect configuration.
32
32
  *
@@ -8,10 +8,10 @@
8
8
  * test execution.
9
9
  */
10
10
  /**
11
- * Initialize the global redirect state.
11
+ * Initialise the global redirect state.
12
12
  * Must be called once at module load time.
13
13
  */
14
- export function initializeRedirectState() {
14
+ export function initialiseRedirectState() {
15
15
  globalThis.__mutineer_redirect__ = { from: null, to: null };
16
16
  }
17
17
  /**
@@ -46,5 +46,5 @@ export function getRedirect() {
46
46
  export function clearRedirect() {
47
47
  globalThis.__mutineer_redirect__ = { from: null, to: null };
48
48
  }
49
- // Initialize on module load
50
- initializeRedirectState();
49
+ // Initialise on module load
50
+ initialiseRedirectState();
@@ -0,0 +1,12 @@
1
+ import type { Variant } from '../types/mutant.js';
2
+ import type { PerTestCoverageMap } from '../utils/coverage.js';
3
+ export interface MutantTask {
4
+ v: Variant;
5
+ tests: string[];
6
+ key: string;
7
+ }
8
+ /**
9
+ * Prepare mutant tasks from variants by pruning tests via per-test coverage,
10
+ * sorting tests deterministically, and computing cache keys.
11
+ */
12
+ export declare function prepareTasks(variants: readonly Variant[], perTestCoverage: PerTestCoverageMap | null): MutantTask[];
@@ -0,0 +1,25 @@
1
+ import { filterTestsByCoverage } from './variants.js';
2
+ import { hash, keyForTests } from './cache.js';
3
+ import { createLogger } from '../utils/logger.js';
4
+ const log = createLogger('tasks');
5
+ /**
6
+ * Prepare mutant tasks from variants by pruning tests via per-test coverage,
7
+ * sorting tests deterministically, and computing cache keys.
8
+ */
9
+ export function prepareTasks(variants, perTestCoverage) {
10
+ return variants.map((v) => {
11
+ let tests = Array.from(v.tests);
12
+ if (perTestCoverage && tests.length) {
13
+ const before = tests.length;
14
+ tests = filterTestsByCoverage(perTestCoverage, tests, v.file, v.line);
15
+ if (tests.length !== before) {
16
+ log.debug(`Pruned tests ${before} -> ${tests.length} for mutant ${v.name} via per-test coverage`);
17
+ }
18
+ }
19
+ tests.sort();
20
+ const testSig = hash(keyForTests(tests));
21
+ const codeSig = hash(v.code);
22
+ const key = `${testSig}:${codeSig}`;
23
+ return { v, tests, key };
24
+ });
25
+ }
@@ -41,7 +41,7 @@ export interface TestRunnerAdapter {
41
41
  */
42
42
  readonly name: string;
43
43
  /**
44
- * Initialize the adapter (start worker pools, etc.).
44
+ * Initialise the adapter (start worker pools, etc.).
45
45
  * Must be called before running tests.
46
46
  */
47
47
  init(concurrencyOverride?: number): Promise<void>;
@@ -4,8 +4,10 @@
4
4
  * Functions for enumerating mutation variants from source files.
5
5
  * Handles both regular modules and Vue SFC files.
6
6
  */
7
- import type { MutateTarget } from '../types/config.js';
8
- import type { MutantPayload } from '../types/mutant.js';
7
+ import type { MutateTarget, MutineerConfig } from '../types/config.js';
8
+ import type { MutantPayload, Variant } from '../types/mutant.js';
9
+ import { type CoverageData } from '../utils/coverage.js';
10
+ import type { TestMap } from './discover.js';
9
11
  /**
10
12
  * Get file path from target (handles both string and object forms).
11
13
  */
@@ -18,4 +20,17 @@ export declare function enumerateVariantsForTarget(root: string, t: MutateTarget
18
20
  * Filter tests to only those that cover a specific line in a file.
19
21
  */
20
22
  export declare function filterTestsByCoverage(perTest: Map<string, Map<string, Set<number>>>, tests: readonly string[], filePath: string, line: number): string[];
23
+ export interface EnumerateAllParams {
24
+ cwd: string;
25
+ targets: readonly MutateTarget[];
26
+ testMap: TestMap;
27
+ changedFiles: Set<string> | null;
28
+ coverageData: CoverageData | null;
29
+ config: MutineerConfig;
30
+ }
31
+ /**
32
+ * Enumerate variants for all targets, filtering by changed files and coverage.
33
+ * Links each variant to its relevant test files via the testMap.
34
+ */
35
+ export declare function enumerateAllVariants(params: EnumerateAllParams): Promise<Variant[]>;
21
36
  export type { Variant } from '../types/mutant.js';
@@ -8,6 +8,8 @@ import fs from 'node:fs/promises';
8
8
  import path from 'node:path';
9
9
  import { mutateVueSfcScriptSetup } from '../core/sfc.js';
10
10
  import { mutateModuleSource } from '../core/module.js';
11
+ import { normalizePath } from '../utils/normalizePath.js';
12
+ import { isLineCovered } from '../utils/coverage.js';
11
13
  import { createLogger } from '../utils/logger.js';
12
14
  const log = createLogger('variants');
13
15
  /**
@@ -64,3 +66,34 @@ export function filterTestsByCoverage(perTest, tests, filePath, line) {
64
66
  return lines.has(line);
65
67
  });
66
68
  }
69
+ /**
70
+ * Enumerate variants for all targets, filtering by changed files and coverage.
71
+ * Links each variant to its relevant test files via the testMap.
72
+ */
73
+ export async function enumerateAllVariants(params) {
74
+ const { cwd, targets, testMap, changedFiles, coverageData, config } = params;
75
+ const enumerated = await Promise.all(targets.map(async (target) => {
76
+ const file = getTargetFile(target);
77
+ const absFile = normalizePath(path.isAbsolute(file) ? file : path.join(cwd, file));
78
+ if (changedFiles && !changedFiles.has(absFile))
79
+ return [];
80
+ log.debug('Target file: ' + absFile);
81
+ const files = await enumerateVariantsForTarget(cwd, target, config.include, config.exclude, config.maxMutantsPerFile);
82
+ const testsAbs = testMap.get(normalizePath(absFile));
83
+ const tests = testsAbs ? Array.from(testsAbs) : [];
84
+ log.debug(` found ${files.length} variants, linked to ${tests.length} tests`);
85
+ // Filter by coverage if enabled
86
+ let filtered = files;
87
+ if (coverageData) {
88
+ filtered = files.filter((v) => isLineCovered(coverageData, absFile, v.line));
89
+ if (filtered.length !== files.length) {
90
+ log.debug(` filtered ${files.length} -> ${filtered.length} variants by coverage`);
91
+ }
92
+ }
93
+ return filtered.map((v) => ({ ...v, tests }));
94
+ }));
95
+ const variants = [];
96
+ for (const list of enumerated)
97
+ variants.push(...list);
98
+ return variants;
99
+ }
@@ -41,7 +41,7 @@ describe('Vitest adapter', () => {
41
41
  afterEach(() => {
42
42
  vi.useRealTimers();
43
43
  });
44
- it('initializes pool with override concurrency', async () => {
44
+ it('initialises pool with override concurrency', async () => {
45
45
  const adapter = makeAdapter();
46
46
  await adapter.init(5);
47
47
  expect(poolInstance?.init).toHaveBeenCalledTimes(1);
@@ -40,7 +40,7 @@ describe('VitestPool', () => {
40
40
  cwd: process.cwd(),
41
41
  concurrency: 1,
42
42
  timeoutMs: 5000,
43
- createWorker: (id, opts) => {
43
+ createWorker: (id) => {
44
44
  const worker = new EventEmitter();
45
45
  worker.id = id;
46
46
  worker.start = vi.fn().mockResolvedValue(undefined);
@@ -3,11 +3,16 @@ import fs from 'node:fs/promises';
3
3
  import path from 'node:path';
4
4
  import os from 'node:os';
5
5
  import { pathToFileURL } from 'node:url';
6
- import { resolve as poolResolve } from '../redirect-loader.js';
6
+ vi.mock('node:module', async (importOriginal) => {
7
+ const actual = await importOriginal();
8
+ return { ...actual, register: vi.fn() };
9
+ });
10
+ import { resolve as poolResolve, initialise } from '../redirect-loader.js';
7
11
  describe('pool-redirect-loader resolve', () => {
8
12
  afterEach(() => {
9
13
  ;
10
14
  globalThis.__mutineer_redirect__ = undefined;
15
+ delete process.env.MUTINEER_DEBUG;
11
16
  vi.restoreAllMocks();
12
17
  });
13
18
  it('resolves .js to .ts in the same directory', async () => {
@@ -84,4 +89,85 @@ describe('pool-redirect-loader resolve', () => {
84
89
  await fs.rm(tmpDir, { recursive: true, force: true });
85
90
  }
86
91
  });
92
+ it('passes through non-.js specifiers to nextResolve', async () => {
93
+ const nextResolve = vi.fn().mockResolvedValue({
94
+ url: 'file:///some/module.ts',
95
+ shortCircuit: false,
96
+ });
97
+ const result = await poolResolve('./module', { parentURL: 'file:///src/index.ts' }, nextResolve);
98
+ expect(nextResolve).toHaveBeenCalled();
99
+ expect(result.url).toBe('file:///some/module.ts');
100
+ });
101
+ it('passes through builtin modules to nextResolve', async () => {
102
+ const nextResolve = vi.fn().mockResolvedValue({
103
+ url: 'node:fs',
104
+ shortCircuit: true,
105
+ });
106
+ const result = await poolResolve('node:fs', { parentURL: 'file:///src/index.ts' }, nextResolve);
107
+ expect(nextResolve).toHaveBeenCalled();
108
+ expect(result.url).toBe('node:fs');
109
+ });
110
+ it('skips .js->ts resolution for non-relative specifiers', async () => {
111
+ const nextResolve = vi.fn().mockResolvedValue({
112
+ url: 'file:///node_modules/pkg/index.js',
113
+ shortCircuit: false,
114
+ });
115
+ const result = await poolResolve('some-package/foo.js', { parentURL: 'file:///src/index.ts' }, nextResolve);
116
+ expect(nextResolve).toHaveBeenCalled();
117
+ expect(result.url).toBe('file:///node_modules/pkg/index.js');
118
+ });
119
+ it('resolves .js to .tsx when .ts does not exist', async () => {
120
+ const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-pool-loader-'));
121
+ const parentFile = path.join(tmpDir, 'src', 'index.ts');
122
+ const tsxFile = path.join(tmpDir, 'src', 'comp.tsx');
123
+ await fs.mkdir(path.dirname(parentFile), { recursive: true });
124
+ await fs.writeFile(parentFile, 'export {}', 'utf8');
125
+ await fs.writeFile(tsxFile, 'export const Comp = () => null', 'utf8');
126
+ try {
127
+ const nextResolve = vi.fn();
128
+ const result = await poolResolve('./comp.js', { parentURL: pathToFileURL(parentFile).href }, nextResolve);
129
+ expect(nextResolve).not.toHaveBeenCalled();
130
+ expect(result.shortCircuit).toBe(true);
131
+ expect(result.url).toBe(pathToFileURL(tsxFile).href);
132
+ }
133
+ finally {
134
+ await fs.rm(tmpDir, { recursive: true, force: true });
135
+ }
136
+ });
137
+ it('tries parent of __mutineer__ directory for ts resolution', async () => {
138
+ const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-pool-loader-'));
139
+ const srcDir = path.join(tmpDir, 'src');
140
+ const mutineerDir = path.join(srcDir, '__mutineer__');
141
+ await fs.mkdir(mutineerDir, { recursive: true });
142
+ const parentFile = path.join(mutineerDir, 'mutant.ts');
143
+ const tsFile = path.join(srcDir, 'sibling.ts');
144
+ await fs.writeFile(parentFile, 'export {}', 'utf8');
145
+ await fs.writeFile(tsFile, 'export const x = 1', 'utf8');
146
+ try {
147
+ const nextResolve = vi.fn();
148
+ const result = await poolResolve('./sibling.js', { parentURL: pathToFileURL(parentFile).href }, nextResolve);
149
+ expect(nextResolve).not.toHaveBeenCalled();
150
+ expect(result.shortCircuit).toBe(true);
151
+ expect(result.url).toBe(pathToFileURL(tsFile).href);
152
+ }
153
+ finally {
154
+ await fs.rm(tmpDir, { recursive: true, force: true });
155
+ }
156
+ });
157
+ it('initialise sets debug mode', () => {
158
+ // Should not throw
159
+ initialise({ debug: true });
160
+ initialise({ debug: false });
161
+ initialise(undefined);
162
+ });
163
+ it('returns null from tryResolveTsExtension when parentURL is invalid', async () => {
164
+ const nextResolve = vi.fn().mockResolvedValue({
165
+ url: 'file:///fallback.js',
166
+ shortCircuit: false,
167
+ });
168
+ // parentURL is not a valid file URL, so tryResolveTsExtension should return null
169
+ await poolResolve('./foo.js', { parentURL: 'not-a-valid-url' }, nextResolve);
170
+ // Falls through to nextResolve
171
+ expect(nextResolve).toHaveBeenCalled();
172
+ });
87
173
  });
@@ -55,6 +55,90 @@ describe('VitestWorkerRuntime', () => {
55
55
  expect(fs.existsSync(path.join(tmp, 'src', '__mutineer__'))).toBe(false);
56
56
  await runtime.shutdown();
57
57
  });
58
+ it('throws when run is called before init', async () => {
59
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
60
+ tmpFiles.push(tmp);
61
+ const runtime = createVitestWorkerRuntime({
62
+ workerId: 'w-noinit',
63
+ cwd: tmp,
64
+ });
65
+ await expect(runtime.run({
66
+ id: 'mut#err',
67
+ name: 'm',
68
+ file: path.join(tmp, 'src.ts'),
69
+ code: 'export const x=1',
70
+ line: 1,
71
+ col: 1,
72
+ }, [path.join(tmp, 'test.ts')])).rejects.toThrow('Vitest runtime not initialised');
73
+ });
74
+ it('shutdown is a no-op when not initialised', async () => {
75
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
76
+ tmpFiles.push(tmp);
77
+ const runtime = createVitestWorkerRuntime({
78
+ workerId: 'w-noinit2',
79
+ cwd: tmp,
80
+ });
81
+ // Should not throw
82
+ await runtime.shutdown();
83
+ expect(closeFn).not.toHaveBeenCalled();
84
+ });
85
+ it('passes vitestConfigPath option to createVitest', async () => {
86
+ const { createVitest } = await import('vitest/node');
87
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
88
+ tmpFiles.push(tmp);
89
+ const runtime = createVitestWorkerRuntime({
90
+ workerId: 'w-config',
91
+ cwd: tmp,
92
+ vitestConfigPath: '/custom/vitest.config.ts',
93
+ });
94
+ await runtime.init();
95
+ expect(createVitest).toHaveBeenCalledWith('test', expect.objectContaining({ config: '/custom/vitest.config.ts' }), expect.any(Object));
96
+ await runtime.shutdown();
97
+ });
98
+ it('handles non-Error thrown during run', async () => {
99
+ runSpecsFn.mockRejectedValue('string error');
100
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
101
+ tmpFiles.push(tmp);
102
+ const runtime = createVitestWorkerRuntime({
103
+ workerId: 'w-strerr',
104
+ cwd: tmp,
105
+ });
106
+ await runtime.init();
107
+ const result = await runtime.run({
108
+ id: 'mut#3',
109
+ name: 'm',
110
+ file: path.join(tmp, 'src.ts'),
111
+ code: 'export const x=1',
112
+ line: 1,
113
+ col: 1,
114
+ }, [path.join(tmp, 'test.ts')]);
115
+ expect(result.killed).toBe(true);
116
+ expect(result.error).toBe('string error');
117
+ await runtime.shutdown();
118
+ });
119
+ it('falls back to all testModules when no relevant modules match', async () => {
120
+ runSpecsFn.mockResolvedValue({
121
+ testModules: [{ moduleId: 'unknown-module', ok: () => true }],
122
+ });
123
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
124
+ tmpFiles.push(tmp);
125
+ const runtime = createVitestWorkerRuntime({
126
+ workerId: 'w-fallback',
127
+ cwd: tmp,
128
+ });
129
+ await runtime.init();
130
+ const result = await runtime.run({
131
+ id: 'mut#4',
132
+ name: 'm',
133
+ file: path.join(tmp, 'src.ts'),
134
+ code: 'export const x=1',
135
+ line: 1,
136
+ col: 1,
137
+ }, [path.join(tmp, 'test.ts')]);
138
+ // Falls back to all testModules; 'unknown-module' reports ok() = true
139
+ expect(result.killed).toBe(false);
140
+ await runtime.shutdown();
141
+ });
58
142
  it('returns escaped when no specs produced', async () => {
59
143
  getProjectByNameFn.mockReturnValue({ createSpecification: () => null });
60
144
  const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
@@ -154,7 +154,7 @@ export class VitestAdapter {
154
154
  }
155
155
  async runMutant(mutant, tests) {
156
156
  if (!this.pool) {
157
- throw new Error('VitestAdapter not initialized. Call init() first.');
157
+ throw new Error('VitestAdapter not initialised. Call init() first.');
158
158
  }
159
159
  try {
160
160
  const result = await this.pool.run(mutant, [...tests]);
@@ -7,5 +7,4 @@
7
7
  export { VitestAdapter, createVitestAdapter, isCoverageRequestedInArgs, } from './adapter.js';
8
8
  export { VitestPool, runWithPool, type VitestPoolOptions } from './pool.js';
9
9
  export { poolMutineerPlugin } from './plugin.js';
10
- export { resolve as poolRedirectResolve } from './redirect-loader.js';
11
10
  export type { MutantPayload, MutantRunResult, MutantRunSummary, } from '../../types/mutant.js';
@@ -7,4 +7,3 @@
7
7
  export { VitestAdapter, createVitestAdapter, isCoverageRequestedInArgs, } from './adapter.js';
8
8
  export { VitestPool, runWithPool } from './pool.js';
9
9
  export { poolMutineerPlugin } from './plugin.js';
10
- export { resolve as poolRedirectResolve } from './redirect-loader.js';
@@ -47,7 +47,7 @@ export declare class VitestPool {
47
47
  private availableWorkers;
48
48
  private waitingTasks;
49
49
  private readonly options;
50
- private initialized;
50
+ private initialised;
51
51
  private shuttingDown;
52
52
  constructor(options: VitestPoolOptions);
53
53
  init(): Promise<void>;
@@ -221,7 +221,7 @@ export class VitestPool {
221
221
  this.workers = [];
222
222
  this.availableWorkers = [];
223
223
  this.waitingTasks = [];
224
- this.initialized = false;
224
+ this.initialised = false;
225
225
  this.shuttingDown = false;
226
226
  this.options = {
227
227
  cwd: options.cwd,
@@ -232,7 +232,7 @@ export class VitestPool {
232
232
  };
233
233
  }
234
234
  async init() {
235
- if (this.initialized)
235
+ if (this.initialised)
236
236
  return;
237
237
  poolLog.debug(`Initializing pool with ${this.options.concurrency} workers`);
238
238
  const startPromises = [];
@@ -254,8 +254,8 @@ export class VitestPool {
254
254
  }));
255
255
  }
256
256
  await Promise.all(startPromises);
257
- this.initialized = true;
258
- poolLog.debug('Pool initialized');
257
+ this.initialised = true;
258
+ poolLog.debug('Pool initialised');
259
259
  }
260
260
  handleWorkerExit(worker) {
261
261
  // Remove from available list
@@ -313,8 +313,8 @@ export class VitestPool {
313
313
  }
314
314
  }
315
315
  async run(mutant, tests) {
316
- if (!this.initialized) {
317
- throw new Error('Pool not initialized. Call init() first.');
316
+ if (!this.initialised) {
317
+ throw new Error('Pool not initialised. Call init() first.');
318
318
  }
319
319
  if (this.shuttingDown) {
320
320
  throw new Error('Pool is shutting down');
@@ -336,7 +336,7 @@ export class VitestPool {
336
336
  await Promise.all(this.workers.map((w) => w.shutdown()));
337
337
  this.workers = [];
338
338
  this.availableWorkers = [];
339
- this.initialized = false;
339
+ this.initialised = false;
340
340
  poolLog.debug('Pool shut down');
341
341
  }
342
342
  }
@@ -13,7 +13,7 @@ declare global {
13
13
  to: string | null;
14
14
  } | undefined;
15
15
  }
16
- export declare function initialize(data: {
16
+ export declare function initialise(data: {
17
17
  debug?: boolean;
18
18
  } | undefined): void;
19
19
  export declare function resolve(specifier: string, context: {
@@ -17,7 +17,7 @@ register(import.meta.url, {
17
17
  data: { debug: process.env.MUTINEER_DEBUG === '1' },
18
18
  });
19
19
  let DEBUG = process.env.MUTINEER_DEBUG === '1';
20
- export function initialize(data) {
20
+ export function initialise(data) {
21
21
  if (data?.debug !== undefined) {
22
22
  DEBUG = data.debug;
23
23
  }
@@ -25,10 +25,10 @@ export class VitestWorkerRuntime {
25
25
  plugins: [poolMutineerPlugin()],
26
26
  });
27
27
  await this.vitest.init();
28
- log.debug(`Vitest initialized for worker ${this.options.workerId}`);
28
+ log.debug(`Vitest initialised for worker ${this.options.workerId}`);
29
29
  }
30
30
  catch (err) {
31
- log.error(`Failed to initialize Vitest: ${err}`);
31
+ log.error(`Failed to initialise Vitest: ${err}`);
32
32
  throw err;
33
33
  }
34
34
  }
@@ -40,7 +40,7 @@ export class VitestWorkerRuntime {
40
40
  }
41
41
  async run(mutant, tests) {
42
42
  if (!this.vitest) {
43
- throw new Error('Vitest runtime not initialized');
43
+ throw new Error('Vitest runtime not initialised');
44
44
  }
45
45
  const start = Date.now();
46
46
  try {
@@ -36,7 +36,7 @@ async function main() {
36
36
  await runtime.init();
37
37
  }
38
38
  catch (err) {
39
- log.error(`Failed to initialize Vitest: ${err}`);
39
+ log.error(`Failed to initialise Vitest: ${err}`);
40
40
  process.exit(1);
41
41
  }
42
42
  // Signal ready