mootant 0.2.0 → 0.3.0

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 (313) hide show
  1. package/bin/mootant.js +3 -2
  2. package/dist/adapters/jest/collect-jest-dependencies.d.ts +8 -6
  3. package/dist/adapters/jest/collect-jest-dependencies.js +20 -14
  4. package/dist/adapters/jest/get-jest-cache-inputs.d.ts +14 -13
  5. package/dist/adapters/jest/index.d.ts +3 -1
  6. package/dist/adapters/jest/run-dry.js +20 -20
  7. package/dist/adapters/jest/start-jest-session.d.ts +6 -2
  8. package/dist/adapters/jest/start-jest-session.js +9 -2
  9. package/dist/adapters/jest/types/jest-handle.d.ts +2 -1
  10. package/dist/adapters/jest/types/jest-record.d.ts +4 -3
  11. package/dist/adapters/jest/types/worker-channel.d.ts +7 -0
  12. package/dist/adapters/jest/worker/boot-worker.d.ts +5 -4
  13. package/dist/adapters/jest/worker/create-test-runner.d.ts +4 -1
  14. package/dist/adapters/jest/worker/keep-reset-loads.d.ts +13 -0
  15. package/dist/adapters/jest/worker/list-runtime-files.d.ts +13 -0
  16. package/dist/adapters/jest/worker/run-unit.d.ts +25 -20
  17. package/dist/adapters/jest/worker/vm-setup.js +1 -1
  18. package/dist/adapters/jest/worker/worker.js +1 -1
  19. package/dist/adapters/node-test/check-typescript.js +2 -2
  20. package/dist/adapters/node-test/collect-node-dependencies.d.ts +7 -5
  21. package/dist/adapters/node-test/collect-node-dependencies.js +26 -20
  22. package/dist/adapters/node-test/create-spare-processes.d.ts +26 -0
  23. package/dist/adapters/node-test/create-spare-processes.js +53 -0
  24. package/dist/adapters/node-test/filter-exec-argv.d.ts +2 -1
  25. package/dist/adapters/node-test/filter-exec-argv.js +13 -12
  26. package/dist/adapters/node-test/get-node-cache-inputs.js +1 -1
  27. package/dist/adapters/node-test/get-unit-deadline.d.ts +6 -5
  28. package/dist/adapters/node-test/index.d.ts +2 -2
  29. package/dist/adapters/node-test/index.js +1 -0
  30. package/dist/adapters/node-test/is-group-alive.d.ts +8 -0
  31. package/dist/adapters/node-test/is-group-alive.js +8 -0
  32. package/dist/adapters/node-test/list-setup-files.js +2 -2
  33. package/dist/adapters/node-test/place-preload.d.ts +2 -1
  34. package/dist/adapters/node-test/place-preload.js +24 -18
  35. package/dist/adapters/node-test/preload/create-commonjs-route.js +1 -1
  36. package/dist/adapters/node-test/preload/preload.js +54 -52
  37. package/dist/adapters/node-test/preload/read-line-sync.d.ts +11 -0
  38. package/dist/adapters/node-test/preload/read-line-sync.js +25 -0
  39. package/dist/adapters/node-test/preload/read-unit.d.ts +11 -5
  40. package/dist/adapters/node-test/preload/read-unit.js +5 -4
  41. package/dist/adapters/node-test/run-isolated.d.ts +19 -10
  42. package/dist/adapters/node-test/run-isolated.js +68 -52
  43. package/dist/adapters/node-test/run-test-file.d.ts +12 -4
  44. package/dist/adapters/node-test/run-test-file.js +18 -14
  45. package/dist/adapters/node-test/run-test-process.d.ts +30 -13
  46. package/dist/adapters/node-test/run-test-process.js +38 -40
  47. package/dist/adapters/node-test/start-node-test-session.d.ts +10 -2
  48. package/dist/adapters/node-test/start-node-test-session.js +90 -84
  49. package/dist/adapters/node-test/start-test-process.d.ts +30 -0
  50. package/dist/adapters/node-test/start-test-process.js +27 -0
  51. package/dist/adapters/node-test/types/node-test-handle.d.ts +14 -1
  52. package/dist/adapters/node-test/types/process-watch.d.ts +4 -3
  53. package/dist/adapters/node-test/types/spare-processes.d.ts +20 -0
  54. package/dist/adapters/node-test/types/test-process-outcome.d.ts +8 -1
  55. package/dist/adapters/shared/allows-spares.d.ts +11 -0
  56. package/dist/adapters/shared/allows-spares.js +23 -0
  57. package/dist/adapters/shared/create-environment-proxy.d.ts +4 -3
  58. package/dist/adapters/shared/create-input-filter.d.ts +17 -14
  59. package/dist/adapters/shared/create-input-filter.js +2 -2
  60. package/dist/adapters/shared/enable-compile-cache.d.ts +32 -0
  61. package/dist/adapters/shared/enable-compile-cache.js +7 -0
  62. package/dist/adapters/shared/find-tsconfig-property.d.ts +13 -0
  63. package/dist/adapters/shared/find-tsconfig-property.js +6 -0
  64. package/dist/adapters/shared/get-spare-limit.d.ts +10 -0
  65. package/dist/adapters/shared/get-spare-limit.js +5 -0
  66. package/dist/adapters/shared/index-environment-hashes.d.ts +2 -2
  67. package/dist/adapters/shared/index-environment-hashes.js +5 -13
  68. package/dist/adapters/{node-test → shared}/list-flag-values.d.ts +2 -1
  69. package/dist/adapters/shared/list-flag-values.js +10 -0
  70. package/dist/adapters/shared/list-tsconfig-files.d.ts +14 -5
  71. package/dist/adapters/shared/list-tsconfig-files.js +15 -13
  72. package/dist/adapters/shared/parse-tsconfig.d.ts +10 -0
  73. package/dist/adapters/shared/parse-tsconfig.js +19 -0
  74. package/dist/adapters/shared/read-flag-name.d.ts +9 -0
  75. package/dist/adapters/shared/read-flag-name.js +5 -0
  76. package/dist/adapters/shared/read-node-options.d.ts +11 -0
  77. package/dist/adapters/shared/read-node-options.js +6 -0
  78. package/dist/adapters/shared/read-prefork-switch.d.ts +10 -0
  79. package/dist/adapters/shared/read-prefork-switch.js +5 -0
  80. package/dist/adapters/shared/read-tsconfig-extends.d.ts +2 -5
  81. package/dist/adapters/shared/read-tsconfig-extends.js +16 -31
  82. package/dist/adapters/shared/read-tsconfig-references.d.ts +12 -0
  83. package/dist/adapters/shared/read-tsconfig-references.js +13 -0
  84. package/dist/adapters/shared/track-file-reads.d.ts +13 -12
  85. package/dist/adapters/shared/track-file-reads.js +71 -71
  86. package/dist/adapters/shared/track-process-group.d.ts +2 -1
  87. package/dist/adapters/shared/track-process-group.js +7 -2
  88. package/dist/adapters/vitest/build-isolated-facts.d.ts +4 -3
  89. package/dist/adapters/vitest/collect-dependencies.d.ts +11 -5
  90. package/dist/adapters/vitest/collect-dependencies.js +36 -27
  91. package/dist/adapters/vitest/configure-project.d.ts +3 -2
  92. package/dist/adapters/vitest/configure-project.js +1 -1
  93. package/dist/adapters/vitest/create-forks-pool.d.ts +34 -7
  94. package/dist/adapters/vitest/create-forks-pool.js +102 -24
  95. package/dist/adapters/vitest/create-interleaved-sequencer.d.ts +3 -2
  96. package/dist/adapters/vitest/drop-signal-listeners.d.ts +14 -0
  97. package/dist/adapters/vitest/drop-signal-listeners.js +15 -0
  98. package/dist/adapters/vitest/get-cache-inputs.d.ts +3 -1
  99. package/dist/adapters/vitest/get-cache-inputs.js +43 -28
  100. package/dist/adapters/vitest/get-module-file.d.ts +3 -5
  101. package/dist/adapters/vitest/get-module-file.js +1 -1
  102. package/dist/adapters/vitest/get-spare-key.d.ts +15 -0
  103. package/dist/adapters/vitest/get-spare-key.js +15 -0
  104. package/dist/adapters/vitest/index.d.ts +2 -1
  105. package/dist/adapters/vitest/index.js +1 -0
  106. package/dist/adapters/vitest/is-virtual-module.d.ts +1 -2
  107. package/dist/adapters/vitest/is-virtual-module.js +1 -1
  108. package/dist/adapters/vitest/list-script-defines.d.ts +13 -0
  109. package/dist/adapters/vitest/list-script-defines.js +22 -0
  110. package/dist/adapters/vitest/read-unit-inputs.d.ts +2 -1
  111. package/dist/adapters/vitest/run-dry.js +1 -1
  112. package/dist/adapters/vitest/run-plan.d.ts +10 -8
  113. package/dist/adapters/vitest/run-plan.js +1 -1
  114. package/dist/adapters/vitest/run-specifications.d.ts +9 -2
  115. package/dist/adapters/vitest/run-specifications.js +22 -12
  116. package/dist/adapters/vitest/runner.d.ts +60 -29
  117. package/dist/adapters/vitest/runner.js +109 -86
  118. package/dist/adapters/vitest/start-vitest-session.d.ts +5 -1
  119. package/dist/adapters/vitest/start-vitest-session.js +64 -59
  120. package/dist/adapters/vitest/stop-hung-worker.d.ts +11 -4
  121. package/dist/adapters/vitest/stop-hung-worker.js +20 -7
  122. package/dist/adapters/vitest/types/mootant-forks-pool.d.ts +47 -0
  123. package/dist/adapters/vitest/types/vitest-session-state.d.ts +9 -8
  124. package/dist/adapters/vitest/types/vitest-worker.d.ts +48 -33
  125. package/dist/adapters/vitest/wait-for-workers.d.ts +5 -2
  126. package/dist/adapters/vitest/wait-for-workers.js +15 -15
  127. package/dist/adapters/vitest/worker/track-meta-defines.d.ts +39 -0
  128. package/dist/adapters/vitest/worker/track-meta-defines.js +23 -0
  129. package/dist/adapters/vitest/worker/track-values.d.ts +38 -0
  130. package/dist/adapters/vitest/worker/track-values.js +45 -0
  131. package/dist/adapters/vitest/worker/value-prefixes.d.ts +12 -0
  132. package/dist/adapters/vitest/worker/value-prefixes.js +6 -0
  133. package/dist/adapters/vitest/worker/wait-for-turn.d.ts +8 -6
  134. package/dist/adapters/vitest/worker/watch-property.d.ts +17 -0
  135. package/dist/adapters/vitest/worker/watch-property.js +27 -0
  136. package/dist/cli/create-run-progress.d.ts +8 -1
  137. package/dist/cli/create-run-progress.js +4 -1
  138. package/dist/cli/ensure-exit.d.ts +11 -0
  139. package/dist/cli/ensure-exit.js +15 -0
  140. package/dist/cli/html/build-html-report.js +1 -0
  141. package/dist/cli/html/client/main.js +1 -1
  142. package/dist/cli/html/client/render-overview.d.ts +3 -3
  143. package/dist/cli/index.d.ts +1 -0
  144. package/dist/cli/index.js +3 -2
  145. package/dist/cli/parse-arguments.d.ts +4 -0
  146. package/dist/cli/parse-arguments.js +4 -1
  147. package/dist/cli/report/build-run-report.js +1 -0
  148. package/dist/cli/report/format-command.d.ts +5 -0
  149. package/dist/cli/report/format-command.js +1 -1
  150. package/dist/cli/report/format-run-text-report.d.ts +5 -4
  151. package/dist/cli/report/format-run-text-report.js +10 -10
  152. package/dist/cli/report/slim-run-report.d.ts +10 -10
  153. package/dist/cli/report/slim-run-report.js +1 -0
  154. package/dist/cli/run-mutation.d.ts +5 -1
  155. package/dist/cli/run-mutation.js +32 -24
  156. package/dist/cli/terminal/create-spinner.d.ts +1 -2
  157. package/dist/cli/terminal/create-spinner.js +23 -32
  158. package/dist/cli/watch-interrupts.d.ts +41 -0
  159. package/dist/cli/watch-interrupts.js +32 -0
  160. package/dist/core/cache/apply-cached-units.d.ts +8 -7
  161. package/dist/core/cache/build-hash.d.ts +9 -0
  162. package/dist/core/cache/build-hash.js +2 -0
  163. package/dist/core/cache/cache-version.d.ts +4 -4
  164. package/dist/core/cache/check-dry-snapshot.d.ts +25 -0
  165. package/dist/core/cache/check-dry-snapshot.js +13 -0
  166. package/dist/core/cache/create-dry-reuse-miss.d.ts +12 -0
  167. package/dist/core/cache/create-dry-reuse-miss.js +7 -0
  168. package/dist/core/cache/create-dry-snapshot.d.ts +71 -0
  169. package/dist/core/cache/create-dry-snapshot.js +27 -0
  170. package/dist/core/cache/create-run-cache.d.ts +20 -2
  171. package/dist/core/cache/create-run-cache.js +31 -22
  172. package/dist/core/cache/create-snapshot-session.d.ts +12 -0
  173. package/dist/core/cache/create-snapshot-session.js +19 -0
  174. package/dist/core/cache/get-build-id.d.ts +11 -0
  175. package/dist/core/cache/get-build-id.js +7 -0
  176. package/dist/core/cache/get-cache-path.d.ts +1 -1
  177. package/dist/core/cache/get-cache-path.js +1 -1
  178. package/dist/core/cache/get-dry-snapshot-key.d.ts +47 -0
  179. package/dist/core/cache/get-dry-snapshot-key.js +43 -0
  180. package/dist/core/cache/get-dry-snapshot-path.d.ts +9 -0
  181. package/dist/core/cache/get-dry-snapshot-path.js +5 -0
  182. package/dist/core/cache/get-environment-key.d.ts +9 -4
  183. package/dist/core/cache/get-environment-key.js +3 -2
  184. package/dist/core/cache/get-test-file-keys.d.ts +2 -1
  185. package/dist/core/cache/get-test-file-keys.js +11 -10
  186. package/dist/core/cache/hash-files.d.ts +8 -7
  187. package/dist/core/cache/hash-files.js +17 -11
  188. package/dist/core/cache/hash-project-tree.d.ts +22 -0
  189. package/dist/core/cache/hash-project-tree.js +69 -0
  190. package/dist/core/cache/is-dry-reuse-miss.d.ts +8 -0
  191. package/dist/core/cache/is-dry-reuse-miss.js +4 -0
  192. package/dist/core/cache/list-file-hashes.d.ts +4 -0
  193. package/dist/core/cache/list-file-hashes.js +5 -2
  194. package/dist/core/cache/list-install-states.d.ts +12 -0
  195. package/dist/core/cache/list-install-states.js +19 -0
  196. package/dist/core/cache/list-variable-hashes.d.ts +15 -0
  197. package/dist/core/cache/list-variable-hashes.js +14 -0
  198. package/dist/core/cache/prepare-run-cache.d.ts +48 -22
  199. package/dist/core/cache/prepare-run-cache.js +86 -73
  200. package/dist/core/cache/read-dry-snapshot.d.ts +10 -0
  201. package/dist/core/cache/read-dry-snapshot.js +15 -0
  202. package/dist/core/cache/read-run-cache.js +6 -2
  203. package/dist/core/cache/save-dry-snapshot.d.ts +34 -0
  204. package/dist/core/cache/save-dry-snapshot.js +32 -0
  205. package/dist/core/cache/volatile-variables.d.ts +7 -0
  206. package/dist/core/cache/volatile-variables.js +11 -0
  207. package/dist/core/cache/write-run-cache.js +1 -1
  208. package/dist/core/config/load-typescript-config.d.ts +6 -1
  209. package/dist/core/config/load-typescript-config.js +26 -10
  210. package/dist/core/config/prepare-run.d.ts +7 -3
  211. package/dist/core/config/prepare-run.js +1 -0
  212. package/dist/core/config/resolve-run-settings.d.ts +3 -2
  213. package/dist/core/config/resolve-run-settings.js +1 -0
  214. package/dist/core/config/validate-config.js +3 -2
  215. package/dist/core/files/get-package-manifest.d.ts +12 -0
  216. package/dist/core/files/get-package-manifest.js +7 -0
  217. package/dist/core/generate/collect-candidates.d.ts +5 -1
  218. package/dist/core/generate/collect-candidates.js +125 -97
  219. package/dist/core/generate/generate-file-mutants.js +6 -5
  220. package/dist/core/index.d.ts +18 -0
  221. package/dist/core/mutators/shared/get-branch-copy-skip.d.ts +2 -2
  222. package/dist/core/mutators/shared/get-comparison-plan.d.ts +2 -2
  223. package/dist/core/mutators/shared/get-default-option-skip.d.ts +2 -2
  224. package/dist/core/mutators/shared/get-group-constant.d.ts +2 -2
  225. package/dist/core/mutators/shared/get-literal-skip.d.ts +3 -3
  226. package/dist/core/mutators/shared/get-loop-running-skip.d.ts +2 -2
  227. package/dist/core/mutators/shared/get-nullish-swap-skip.d.ts +2 -2
  228. package/dist/core/mutators/shared/get-or-default-skip.d.ts +2 -2
  229. package/dist/core/mutators/shared/get-owned-constants.d.ts +2 -2
  230. package/dist/core/mutators/shared/leave-now-skip.d.ts +2 -2
  231. package/dist/core/mutators/shared/no-op-callback-skip.d.ts +2 -2
  232. package/dist/core/plugins/create-mutator-registry.d.ts +4 -2
  233. package/dist/core/plugins/create-mutator-registry.js +15 -5
  234. package/dist/core/plugins/validate-plugin.d.ts +3 -3
  235. package/dist/core/plugins/validate-plugin.js +32 -10
  236. package/dist/core/regex/collect-pattern-changes.d.ts +2 -2
  237. package/dist/core/regex/create-regex-replacement.d.ts +2 -2
  238. package/dist/core/run/apply-isolated-result.d.ts +22 -14
  239. package/dist/core/run/apply-isolated-result.js +45 -26
  240. package/dist/core/run/count-run.d.ts +2 -1
  241. package/dist/core/run/create-run-state.d.ts +5 -0
  242. package/dist/core/run/create-run-state.js +1 -0
  243. package/dist/core/run/create-work-directory.d.ts +4 -1
  244. package/dist/core/run/create-work-directory.js +15 -12
  245. package/dist/core/run/decide-evidence.d.ts +4 -3
  246. package/dist/core/run/get-unit-evidence.d.ts +13 -7
  247. package/dist/core/run/get-unit-evidence.js +1 -1
  248. package/dist/core/run/guard-session.d.ts +18 -0
  249. package/dist/core/run/guard-session.js +30 -0
  250. package/dist/core/run/live-work-directories.d.ts +5 -0
  251. package/dist/core/run/live-work-directories.js +2 -0
  252. package/dist/core/run/read-isolated-unit.d.ts +6 -3
  253. package/dist/core/run/read-isolated-unit.js +77 -38
  254. package/dist/core/run/remove-live-work-directories.d.ts +7 -0
  255. package/dist/core/run/remove-live-work-directories.js +12 -0
  256. package/dist/core/run/run-isolated-rounds.d.ts +16 -12
  257. package/dist/core/run/run-isolated-rounds.js +3 -2
  258. package/dist/core/run/validate-adapter.d.ts +1 -1
  259. package/dist/core/run/validate-adapter.js +1 -1
  260. package/dist/core/run-mutants.d.ts +34 -2
  261. package/dist/core/run-mutants.js +356 -216
  262. package/dist/core/skips/skip-rules.d.ts +3 -1
  263. package/dist/package.js +1 -1
  264. package/dist/types/adapter/adapter-context.d.ts +20 -0
  265. package/dist/types/adapter/adapter-session.d.ts +2 -1
  266. package/dist/types/adapter/cache-inputs.d.ts +3 -2
  267. package/dist/types/adapter/dry-file.d.ts +4 -2
  268. package/dist/types/adapter/isolated-plan.d.ts +2 -1
  269. package/dist/types/adapter/isolated-result.d.ts +3 -1
  270. package/dist/types/adapter/run-inputs.d.ts +5 -4
  271. package/dist/types/adapter/test-adapter.d.ts +7 -0
  272. package/dist/types/cache/cache-entry.d.ts +9 -7
  273. package/dist/types/cache/cached-inputs.d.ts +2 -2
  274. package/dist/types/cache/dry-snapshot.d.ts +76 -0
  275. package/dist/types/cache/project-tree.d.ts +16 -0
  276. package/dist/types/cache/run-cache-file.d.ts +1 -1
  277. package/dist/types/cache/run-cache.d.ts +6 -5
  278. package/dist/types/config/plugin.d.ts +11 -2
  279. package/dist/types/config/run-config.d.ts +10 -0
  280. package/dist/types/config/run-settings.d.ts +6 -0
  281. package/dist/types/mutant/core-note.d.ts +12 -0
  282. package/dist/types/mutant/diagnostic.d.ts +1 -0
  283. package/dist/types/mutant/registered-skip-rule.d.ts +11 -0
  284. package/dist/types/mutant/skip-note.d.ts +7 -6
  285. package/dist/types/mutant/skip-rule-id.d.ts +3 -2
  286. package/dist/types/mutant/skip-rule.d.ts +2 -1
  287. package/dist/types/mutant/skipped-candidate.d.ts +14 -7
  288. package/dist/types/mutant/skipped-mutant.d.ts +6 -6
  289. package/dist/types/mutator/mutator.d.ts +3 -2
  290. package/dist/types/mutator/registered-mutator.d.ts +8 -0
  291. package/dist/types/regex/regex-change.d.ts +2 -2
  292. package/dist/types/report/html-report.d.ts +3 -2
  293. package/dist/types/report/list-report-skipped.d.ts +3 -2
  294. package/dist/types/report/run-report.d.ts +11 -2
  295. package/dist/types/report/slim-run-report.d.ts +1 -1
  296. package/dist/types/run/isolated-evidence.d.ts +3 -2
  297. package/dist/types/run/isolated-reason.d.ts +2 -1
  298. package/dist/types/run/run-durations.d.ts +8 -3
  299. package/dist/types/run/run-event.d.ts +10 -7
  300. package/dist/types/run/run-result.d.ts +11 -2
  301. package/dist/types/run/run-state.d.ts +21 -0
  302. package/dist/types/run/try-cause.d.ts +2 -1
  303. package/package.json +1 -1
  304. package/readme.md +85 -68
  305. package/skills/mootant/SKILL.md +36 -19
  306. package/skills/mootant/references/mutators.md +29 -23
  307. package/dist/adapters/node-test/list-flag-values.js +0 -9
  308. /package/dist/adapters/{node-test → shared}/loader-flags.d.ts +0 -0
  309. /package/dist/adapters/{node-test → shared}/loader-flags.js +0 -0
  310. /package/dist/{adapters/shared → core/files}/list-package-files.d.ts +0 -0
  311. /package/dist/{adapters/shared → core/files}/list-package-files.js +0 -0
  312. /package/dist/{adapters/shared → core/files}/read-package-type.d.ts +0 -0
  313. /package/dist/{adapters/shared → core/files}/read-package-type.js +0 -0
@@ -0,0 +1,53 @@
1
+ import { stopProcessGroup as e } from "../shared/stop-process-group.js";
2
+ import { startTestProcess as t } from "./start-test-process.js";
3
+ function n(e, n) {
4
+ let { context: i } = e, a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s = 0, c = 0;
5
+ function l(n) {
6
+ let r = t({
7
+ output: i.onOutput === void 0 ? "ignore" : "pipe",
8
+ env: {
9
+ ...e.env,
10
+ MOOTANT_UNIT_FD: "3"
11
+ },
12
+ args: [...e.args, n],
13
+ groups: e.groups,
14
+ node: e.node,
15
+ cwd: i.root,
16
+ pipe: !0
17
+ });
18
+ a.set(n, [...a.get(n) ?? [], r]), s += 1;
19
+ function o() {
20
+ let e = a.get(n);
21
+ e.includes(r) && (a.set(n, e.filter((e) => e !== r)), --s);
22
+ }
23
+ r.on("error", o), r.on("exit", o), r.pid !== void 0 && r.stdio[3]?.on("error", () => {});
24
+ }
25
+ function u() {
26
+ if (i.signal?.aborted === !0) return;
27
+ for (; o.has(c);) c += 1;
28
+ let t = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Map();
29
+ for (let r = c; r < n.length && t.size < e.spares; r += 1) {
30
+ let e = n[r];
31
+ !o.has(r) && !t.has(e.key) && (t.add(e.key), u.set(e.file, (u.get(e.file) ?? 0) + 1));
32
+ }
33
+ for (let [e, t] of a) {
34
+ let n = t.splice(u.get(e) ?? 0);
35
+ s -= n.length, r(n);
36
+ }
37
+ for (let [t, n] of u) for (let r = a.get(t)?.length ?? 0; r < n && s < e.spares; r += 1) l(t);
38
+ }
39
+ return {
40
+ take: (e, t) => {
41
+ o.add(e);
42
+ let { file: r } = n[e], [i = null, ...c] = t ? [] : a.get(r) ?? [];
43
+ return i !== null && (a.set(r, c), --s, (i.pid === void 0 || i.exitCode !== null || i.signalCode !== null) && (i = null)), u(), i;
44
+ },
45
+ stop: () => {
46
+ for (let e of a.values()) r(e);
47
+ }
48
+ };
49
+ }
50
+ function r(t) {
51
+ for (let { pid: n } of t) n !== void 0 && e(n);
52
+ }
53
+ export { n as createSpareProcesses };
@@ -8,7 +8,8 @@ import { Diagnostic } from '../../types/mutant/diagnostic.js';
8
8
  * `none`; `--test-global-setup` is kept with a warning, since it then runs in
9
9
  * every test process; `--test-randomize` without a seed gets a fixed seed, so
10
10
  * every process of every run orders tests the same way. Every other flag is
11
- * kept in order.
11
+ * kept in order. Names are read as Node's option parser reads them
12
+ * (`readFlagName`), so `--test_update_snapshots` is left out too.
12
13
  *
13
14
  * @param flags - Flags of the command, each with its value.
14
15
  * @returns Flags of the test processes and `config-overridden` warnings.
@@ -1,25 +1,26 @@
1
- const e = /* @__PURE__ */ new Set([
1
+ import { readFlagName as e } from "../shared/read-flag-name.js";
2
+ const t = /* @__PURE__ */ new Set([
2
3
  "--experimental-test-coverage",
3
4
  "--test-reporter-destination",
4
5
  "--test-concurrency",
5
6
  "--test-reporter",
6
7
  "--test"
7
- ]), t = /* @__PURE__ */ new Set([
8
+ ]), n = /* @__PURE__ */ new Set([
8
9
  "--watch-preserve-output",
9
10
  "--test-update-snapshots",
10
11
  "--test-rerun-failures",
11
12
  "--watch-path",
12
13
  "--test-shard",
13
14
  "--watch"
14
- ]), n = /* @__PURE__ */ new Set(["--experimental-test-isolation", "--test-isolation"]);
15
- function r(r) {
16
- let i = /* @__PURE__ */ new Map(), a = [], o = r.map(([e]) => e.split("=", 1)[0]);
17
- for (let [s, c] of r.entries()) {
18
- let r = o[s], l = c[1] ?? c[0].slice(r.length + 1);
19
- t.has(r) ? i.set(r, r === "--test-update-snapshots" ? "mootant never writes snapshots, so it ignores --test-update-snapshots of the test command." : `mootant ignores ${r} of the test command.`) : n.has(r) ? l === "none" && i.set(r, `mootant runs every test file in a process of its own, so it ignores ${r}=none of the test command.`) : !e.has(r) && !r.startsWith("--test-coverage-") && (a.push(...c), r === "--test-global-setup" && i.set(r, "The global setup of --test-global-setup runs in every test process under mootant, not once per run."));
15
+ ]), r = /* @__PURE__ */ new Set(["--experimental-test-isolation", "--test-isolation"]);
16
+ function i(i) {
17
+ let a = /* @__PURE__ */ new Map(), o = [], s = i.map(([t]) => e(t));
18
+ for (let [e, c] of i.entries()) {
19
+ let i = s[e], l = c[1] ?? c[0].slice(i.length + 1);
20
+ n.has(i) ? a.set(i, i === "--test-update-snapshots" ? "mootant never writes snapshots, so it ignores --test-update-snapshots of the test command." : `mootant ignores ${i} of the test command.`) : r.has(i) ? l === "none" && a.set(i, `mootant runs every test file in a process of its own, so it ignores ${i}=none of the test command.`) : !t.has(i) && !i.startsWith("--test-coverage-") && (o.push(...c), i === "--test-global-setup" && a.set(i, "The global setup of --test-global-setup runs in every test process under mootant, not once per run."));
20
21
  }
21
- return o.includes("--test-randomize") && !o.includes("--test-random-seed") && a.push("--test-random-seed=1"), {
22
- diagnostics: [...i.values()].map((e) => ({
22
+ return s.includes("--test-randomize") && !s.includes("--test-random-seed") && o.push("--test-random-seed=1"), {
23
+ diagnostics: [...a.values()].map((e) => ({
23
24
  code: "config-overridden",
24
25
  severity: "warning",
25
26
  column: null,
@@ -27,7 +28,7 @@ function r(r) {
27
28
  file: null,
28
29
  message: e
29
30
  })),
30
- execArgv: a
31
+ execArgv: o
31
32
  };
32
33
  }
33
- export { r as filterExecArgv };
34
+ export { i as filterExecArgv };
@@ -1,7 +1,7 @@
1
1
  import { VERDICT_VARIABLE_PATTERN as e } from "../shared/verdict-variable-pattern.js";
2
2
  import { listTsconfigFiles as t } from "../shared/list-tsconfig-files.js";
3
3
  import { hashEnvironment as n } from "../shared/hash-environment.js";
4
- import { listFlagValues as r } from "./list-flag-values.js";
4
+ import { listFlagValues as r } from "../shared/list-flag-values.js";
5
5
  import i from "node:path";
6
6
  const a = /* @__PURE__ */ new Set([
7
7
  "--experimental-config-file",
@@ -1,12 +1,13 @@
1
1
  import { ProcessWatch } from './types/process-watch.js';
2
2
  /**
3
3
  * Computes the deadline of an isolated unit: its timeout from the moment the
4
- * preload started (`start` record), so the time the process takes to start is
5
- * not counted; before that record, the timeout plus ten seconds from the start
6
- * of the process, so a process that hangs before the preload runs, as in a
7
- * module another flag loads first, is stopped too.
4
+ * preload got the unit (`start` record), so the time the process takes to
5
+ * start, or a spare waited, is not counted; before that record, the timeout
6
+ * plus ten seconds from the start of the process, or from the moment a spare
7
+ * got its unit, so a process that hangs before the preload runs, as in a module
8
+ * another flag loads first, is stopped too.
8
9
  *
9
- * @param watch - Records so far and when the process started.
10
+ * @param watch - Records so far and when the process started or got its unit.
10
11
  * @param timeout - Milliseconds the unit may take (`IsolatedUnit.limits`).
11
12
  * @returns Epoch milliseconds, or `Infinity`.
12
13
  */
@@ -7,7 +7,7 @@ export type { NodeTestAdapterOptions } from './types/node-test-adapter-options.j
7
7
  *
8
8
  * @param options - Test command, test files, flags, variables and Node binary,
9
9
  * when not those of the project's test scripts.
10
- * @returns Adapter named `node-test` without batch mode and with mootant's
11
- * version.
10
+ * @returns Adapter named `node-test` with parallel units, without batch mode,
11
+ * and with mootant's version.
12
12
  */
13
13
  export declare function nodeTestAdapter(options?: NodeTestAdapterOptions): TestAdapter;
@@ -3,6 +3,7 @@ import { version as t } from "../../package.js";
3
3
  function n(n = {}) {
4
4
  return {
5
5
  start: (t) => e(t, n),
6
+ parallelUnits: !0,
6
7
  name: "node-test",
7
8
  batch: !1,
8
9
  version: t
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Tells whether a process group has a process left. A group that cannot be
3
+ * looked at, as on Windows, counts as one with processes left.
4
+ *
5
+ * @param pid - Process id of the leader of the group.
6
+ * @returns Whether a process of the group is left.
7
+ */
8
+ export declare function isGroupAlive(pid: number): boolean;
@@ -0,0 +1,8 @@
1
+ function e(e) {
2
+ try {
3
+ return process.kill(-e, 0), !0;
4
+ } catch (e) {
5
+ return e.code !== "ESRCH";
6
+ }
7
+ }
8
+ export { e as isGroupAlive };
@@ -1,5 +1,5 @@
1
- import { listFlagValues as e } from "./list-flag-values.js";
2
- import { LOADER_FLAGS as t } from "./loader-flags.js";
1
+ import { listFlagValues as e } from "../shared/list-flag-values.js";
2
+ import { LOADER_FLAGS as t } from "../shared/loader-flags.js";
3
3
  import n from "node:path";
4
4
  import { fileURLToPath as r } from "node:url";
5
5
  const i = /* @__PURE__ */ new Set(["--test-global-setup"]);
@@ -4,7 +4,8 @@
4
4
  * `NODE_OPTIONS` before those of the command line, so: when the project
5
5
  * requires modules, the preload is the first `--require` (of `NODE_OPTIONS` if
6
6
  * they require one); otherwise it is the first `--import`, of `NODE_OPTIONS`
7
- * when they load modules, else of the command line.
7
+ * when they load modules, else of the command line. `NODE_OPTIONS` are read as
8
+ * Node reads them (`readNodeOptions`, `readFlagName`), quotes included.
8
9
  *
9
10
  * @param preload - Absolute path of the preload.
10
11
  * @param execArgv - Flags of the test processes.
@@ -1,27 +1,33 @@
1
- import { pathToFileURL as e } from "node:url";
2
- const t = /(?:^|\s)(?:--require|-r)(?:[\s=]|$)/u, n = /(?:^|\s)(?:--experimental-loader|--import|--loader)(?:[\s=]|$)/u, r = /* @__PURE__ */ new Set(["--require", "-r"]);
3
- function i(i, a, o) {
4
- let s = e(i).href, c = a.some((e) => r.has(e.split("=", 1)[0]));
5
- return t.test(o) ? {
6
- nodeOptions: `--require=${JSON.stringify(i)} ${o}`,
7
- args: [...a]
8
- } : c ? {
1
+ import { readNodeOptions as e } from "../shared/read-node-options.js";
2
+ import { readFlagName as t } from "../shared/read-flag-name.js";
3
+ import { pathToFileURL as n } from "node:url";
4
+ const r = /* @__PURE__ */ new Set(["--require", "-r"]), i = /* @__PURE__ */ new Set([
5
+ "--experimental-loader",
6
+ "--import",
7
+ "--loader"
8
+ ]);
9
+ function a(a, o, s) {
10
+ let c = n(a).href, l = o.some((e) => r.has(e.split("=", 1)[0])), u = e(s).map(t);
11
+ return u.some((e) => r.has(e)) ? {
12
+ nodeOptions: `--require=${JSON.stringify(a)} ${s}`,
13
+ args: [...o]
14
+ } : l ? {
9
15
  args: [
10
16
  "--require",
11
- i,
12
- ...a
17
+ a,
18
+ ...o
13
19
  ],
14
- nodeOptions: o
15
- } : n.test(o) ? {
16
- nodeOptions: `--import=${s} ${o}`,
17
- args: [...a]
20
+ nodeOptions: s
21
+ } : u.some((e) => i.has(e)) ? {
22
+ nodeOptions: `--import=${c} ${s}`,
23
+ args: [...o]
18
24
  } : {
19
25
  args: [
20
26
  "--import",
21
- s,
22
- ...a
27
+ c,
28
+ ...o
23
29
  ],
24
- nodeOptions: o
30
+ nodeOptions: s
25
31
  };
26
32
  }
27
- export { i as placePreload };
33
+ export { a as placePreload };
@@ -1,4 +1,4 @@
1
- import { readPackageType as e } from "../../shared/read-package-type.js";
1
+ import { readPackageType as e } from "../../../core/files/read-package-type.js";
2
2
  function t(t) {
3
3
  let n = /* @__PURE__ */ new Map();
4
4
  return (r, i) => {
@@ -1,74 +1,76 @@
1
1
  import { installMutantRuntime as e } from "../../../core/runtime/install-mutant-runtime.js";
2
- import { installMarkerReceivers as t } from "./install-marker-receivers.js";
3
- import { createSourceSwitcher as n } from "./create-source-switcher.js";
4
- import { installModuleHooks as r } from "./install-module-hooks.js";
5
- import { createRecordWriter as i } from "./create-record-writer.js";
6
- import { createFileRecorder as a } from "./create-file-recorder.js";
7
- import { captureClock as o } from "../../shared/capture-clock.js";
8
- import { trackInputs as s } from "../../shared/track-inputs.js";
9
- import { createTryTracker as c } from "./create-try-tracker.js";
10
- import { readUnit as l } from "./read-unit.js";
11
- import { isMainThread as u } from "node:worker_threads";
12
- import * as d from "node:module";
13
- import { beforeEach as f } from "node:test";
14
- import { realpathSync as p } from "node:fs";
15
- import m from "node:path";
16
- const h = ["NODE_TEST_CONTEXT", "FORCE_COLOR"];
17
- let g = Date.now(), _ = o(), v = _.now(), y = l(process.env, u);
18
- if (y !== null) {
19
- let o = i(y.out), l = c({
2
+ import { enableCompileCache as t } from "../../shared/enable-compile-cache.js";
3
+ import { installMarkerReceivers as n } from "./install-marker-receivers.js";
4
+ import { createSourceSwitcher as r } from "./create-source-switcher.js";
5
+ import { installModuleHooks as i } from "./install-module-hooks.js";
6
+ import { createRecordWriter as a } from "./create-record-writer.js";
7
+ import { createFileRecorder as o } from "./create-file-recorder.js";
8
+ import { captureClock as s } from "../../shared/capture-clock.js";
9
+ import { trackInputs as c } from "../../shared/track-inputs.js";
10
+ import { createTryTracker as l } from "./create-try-tracker.js";
11
+ import { readUnit as u } from "./read-unit.js";
12
+ import { isMainThread as d } from "node:worker_threads";
13
+ import * as f from "node:module";
14
+ import { beforeEach as p } from "node:test";
15
+ import { realpathSync as m } from "node:fs";
16
+ import h from "node:path";
17
+ const g = ["NODE_TEST_CONTEXT", "FORCE_COLOR"];
18
+ let _ = s(), v = u(process, d), y = Date.now(), b = _.now();
19
+ if (v !== null) {
20
+ t(f, v.directory);
21
+ let s = a(v.out), u = l({
20
22
  runtime: e(),
21
23
  now: _.now,
22
- started: v,
23
- write: o,
24
- unit: y
25
- }), u = p(process.argv[1]);
26
- t({
24
+ started: b,
25
+ write: s,
26
+ unit: v
27
+ }), d = m(process.argv[1]);
28
+ n({
27
29
  reported: (e, t) => {
28
- o(e), e.kind === "todo" && l.todo(t);
30
+ s(e), e.kind === "todo" && u.todo(t);
29
31
  },
30
32
  loaded: () => {
31
- l.loaded();
33
+ u.loaded();
32
34
  },
33
- served: a(o, "served")
35
+ served: o(s, "served")
34
36
  });
35
- let b = `hooks${m.extname(import.meta.url)}`, x = r(d, {
36
- switcher: n({
37
- plan: y.plan,
38
- write: o,
39
- main: u
37
+ let x = `hooks${h.extname(import.meta.url)}`, S = i(f, {
38
+ switcher: r({
39
+ plan: v.plan,
40
+ write: s,
41
+ main: d
40
42
  }),
41
43
  data: {
42
- plan: y.plan,
43
- out: y.out,
44
- main: u
44
+ plan: v.plan,
45
+ out: v.out,
46
+ main: d
45
47
  },
46
- record: a(o, "load"),
47
- prototype: d.Module.prototype,
48
- hooks: new URL(b, import.meta.url),
49
- commonjs: y.commonjs
48
+ record: o(s, "load"),
49
+ prototype: f.Module.prototype,
50
+ hooks: new URL(x, import.meta.url),
51
+ commonjs: v.commonjs
50
52
  });
51
- o({
53
+ s({
52
54
  node: process.version,
53
55
  pid: process.pid,
54
56
  kind: "start",
55
- hooks: x,
56
- time: g
57
+ hooks: S,
58
+ time: y
57
59
  });
58
- let S = s({
59
- directory: y.directory,
60
- root: y.root
61
- }, { ignored: h }), C = d.createRequire(import.meta.url);
62
- f((e) => {
63
- l.open(e);
60
+ let C = c({
61
+ directory: v.directory,
62
+ root: v.root
63
+ }, { ignored: g }), w = f.createRequire(import.meta.url);
64
+ p((e) => {
65
+ u.open(e);
64
66
  }), process.on("uncaughtExceptionMonitor", (e) => {
65
- l.error(e);
67
+ u.error(e);
66
68
  }), process.on("unhandledRejection", (e) => {
67
- l.error(e);
69
+ u.error(e);
68
70
  }), process.on("exit", (e) => {
69
- l.exit(e, {
70
- ...S.stop(),
71
- required: Object.keys(C.cache)
71
+ u.exit(e, {
72
+ ...C.stop(),
73
+ required: Object.keys(w.cache)
72
74
  });
73
75
  });
74
76
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Reads the first line of a file descriptor, blocking the thread until its end
3
+ * arrives, then closes the descriptor. A read that finds no data ready yet or
4
+ * is interrupted by a signal is tried again; an error of another kind ends the
5
+ * input.
6
+ *
7
+ * @param descriptor - File descriptor to read, such as a pipe.
8
+ * @returns The line without its line feed, or null when the input ended before
9
+ * one.
10
+ */
11
+ export declare function readLineSync(descriptor: number): string | null;
@@ -0,0 +1,25 @@
1
+ import { closeSync as e, readSync as t } from "node:fs";
2
+ const n = /* @__PURE__ */ new Set(["EAGAIN", "EINTR"]);
3
+ function r(r) {
4
+ let i = Buffer.alloc(65536), a = new Int32Array(new SharedArrayBuffer(4)), o = [];
5
+ try {
6
+ for (;;) {
7
+ let e;
8
+ try {
9
+ e = t(r, i, 0, i.length, null);
10
+ } catch (e) {
11
+ if (!n.has(e.code ?? "")) return null;
12
+ Atomics.wait(a, 0, 0, 10);
13
+ continue;
14
+ }
15
+ if (e === 0) return null;
16
+ let s = i.subarray(0, e), c = s.indexOf(10);
17
+ if (o.push(Buffer.from(c === -1 ? s : s.subarray(0, c))), c !== -1) return Buffer.concat(o).toString("utf8");
18
+ }
19
+ } finally {
20
+ try {
21
+ e(r);
22
+ } catch {}
23
+ }
24
+ }
25
+ export { r as readLineSync };
@@ -1,13 +1,19 @@
1
1
  import { NodeTestUnit } from '../types/node-test-unit.js';
2
2
  /**
3
- * Reads what the test process runs from `MOOTANT_UNIT` and removes the
4
- * variable, so processes the test code starts with the variables of this one,
5
- * such as through `fork()`, do not take the unit for theirs.
3
+ * Reads what the test process runs and removes the variables that carry it, so
4
+ * processes the test code starts with the variables of this one, such as
5
+ * through `fork()`, do not take the unit for theirs. The unit comes as a line
6
+ * through the file descriptor in `MOOTANT_UNIT_FD`; the process waits for it
7
+ * there, which lets a spare process start before mootant knows its unit, and
8
+ * closes the descriptor once read. A process that gets no line, as a spare that
9
+ * mootant no longer needs or whose mootant is gone, exits at once, before any
10
+ * module of the project loads. Where mootant sends no line, as on Windows, the
11
+ * unit is in `MOOTANT_UNIT`.
6
12
  *
7
- * @param environment - Environment variables of the process.
13
+ * @param target - The process, with its environment variables and its exit.
8
14
  * @param main - Whether the code runs in the main thread; a worker thread loads
9
15
  * the preload too, since it inherits the flags of the process.
10
16
  * @returns The unit, or null when this process or thread is not the unit's own,
11
17
  * so the preload stays inert.
12
18
  */
13
- export declare function readUnit(environment: NodeJS.ProcessEnv, main: boolean): NodeTestUnit | null;
19
+ export declare function readUnit(target: Pick<NodeJS.Process, 'exit' | 'env'>, main: boolean): NodeTestUnit | null;
@@ -1,5 +1,6 @@
1
- function e(e, t) {
2
- let n = e.MOOTANT_UNIT;
3
- return delete e.MOOTANT_UNIT, !t || n === void 0 ? null : JSON.parse(n);
1
+ import { readLineSync as e } from "./read-line-sync.js";
2
+ function t(t, n) {
3
+ let { env: r } = t, i = r.MOOTANT_UNIT, a = r.MOOTANT_UNIT_FD;
4
+ return delete r.MOOTANT_UNIT, delete r.MOOTANT_UNIT_FD, n ? (a !== void 0 && (i = e(Number(a)) ?? t.exit()), i === void 0 ? null : JSON.parse(i)) : null;
4
5
  }
5
- export { e as readUnit };
6
+ export { t as readUnit };
@@ -4,16 +4,25 @@ import { NodeTestHandle } from './types/node-test-handle.js';
4
4
  /**
5
5
  * Executes isolated units, each in a test process of its own with its mutant
6
6
  * active from the start, with the session's processes at once but never two
7
- * units of one test file at once, in plan order per file (`runInPool`). A unit
8
- * stops starting tests after a test failed once the mutant was reached, unless
9
- * its test file reported a todo test or suite in its dry run, since node:test
10
- * reports todo tests only some time after they ran; tests that failed in the
11
- * file's dry run of a process that still exited with 0 never count. A unit that
12
- * stopped for a failure that turned out a todo test, as one that only the
13
- * mutant made todo, runs again without stopping (`checkTodoBail`). A watchdog
14
- * stops a unit past its timeout (`getUnitDeadline`). Every unit reports its
15
- * facts (`buildIsolatedFacts`) and, once its process reached its end, what it
16
- * read, to the result and, as it ends, to the context's `onUnitEnd`.
7
+ * units of one test file at once, in plan order per file (`runInPool`), unless
8
+ * the context allows parallel units, when every unit has a key of its own. A
9
+ * unit stops starting tests after a test failed once the mutant was reached,
10
+ * unless its test file reported a todo test or suite in its dry run, since
11
+ * node:test reports todo tests only some time after they ran; tests that failed
12
+ * in the file's dry run of a process that still exited with 0 never count. A
13
+ * unit that stopped for a failure that turned out a todo test, as one that only
14
+ * the mutant made todo, runs again without stopping (`checkTodoBail`). A
15
+ * watchdog stops a unit past its timeout (`getUnitDeadline`). A unit runs in a
16
+ * spare process of its test file when one is ready (`createSpareProcesses`),
17
+ * except right after a unit whose processes outlived it or hung
18
+ * (`TestProcessOutcome.lingering`): the next unit to start, and the next unit
19
+ * of the same test file, start a process of their own then, so what those
20
+ * processes held is free for as long as a process takes to start, as without
21
+ * spares. A unit whose spare ended before it began the unit runs again in a
22
+ * process of its own, as a run again after a todo test does. The spares no unit
23
+ * took stop once the run is over. Every unit reports its facts
24
+ * (`buildIsolatedFacts`) and, once its process reached its end, what it read,
25
+ * to the result and, as it ends, to the context's `onUnitEnd`.
17
26
  *
18
27
  * @param handle - Live session.
19
28
  * @param plan - Units to run.