@smoothbricks/nx-plugin 0.4.26 → 0.4.27

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 (343) hide show
  1. package/README.md +994 -117
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +15 -73
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +3 -2
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +16 -15
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +43 -6
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +309 -73
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +101 -5
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +291 -10
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +207 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +576 -202
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +370 -138
  102. package/dist/managed-files/ci-workflow.d.ts +13 -0
  103. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.js +44 -13
  105. package/dist/managed-files/files.d.ts +7 -1
  106. package/dist/managed-files/files.d.ts.map +1 -1
  107. package/dist/managed-files/files.js +62 -8
  108. package/dist/managed-files/json-edit.d.ts +21 -0
  109. package/dist/managed-files/json-edit.d.ts.map +1 -0
  110. package/dist/managed-files/json-edit.js +295 -0
  111. package/dist/managed-files/managed-format.d.ts +33 -1
  112. package/dist/managed-files/managed-format.d.ts.map +1 -1
  113. package/dist/managed-files/managed-format.js +82 -2
  114. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  115. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  116. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  117. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/publish-workflow.js +231 -48
  119. package/dist/managed-files/tree.d.ts +5 -0
  120. package/dist/managed-files/tree.d.ts.map +1 -1
  121. package/dist/managed-files/tree.js +5 -3
  122. package/dist/manifest-hash.d.ts.map +1 -1
  123. package/dist/manifest-hash.js +2 -5
  124. package/dist/nextest-code-bound.d.ts +62 -0
  125. package/dist/nextest-code-bound.d.ts.map +1 -0
  126. package/dist/nextest-code-bound.js +154 -0
  127. package/dist/nextest-extraction.d.ts +24 -8
  128. package/dist/nextest-extraction.d.ts.map +1 -1
  129. package/dist/nextest-extraction.js +42 -7
  130. package/dist/package-target-policy.d.ts.map +1 -1
  131. package/dist/package-target-policy.js +3 -5
  132. package/dist/release-config-policy.d.ts.map +1 -1
  133. package/dist/release-config-policy.js +3 -5
  134. package/dist/runtime-input.d.ts +14 -0
  135. package/dist/runtime-input.d.ts.map +1 -0
  136. package/dist/runtime-input.js +15 -0
  137. package/dist/rust-tokens.d.ts +11 -0
  138. package/dist/rust-tokens.d.ts.map +1 -0
  139. package/dist/rust-tokens.js +81 -0
  140. package/dist/task-results.d.ts +6 -0
  141. package/dist/task-results.d.ts.map +1 -0
  142. package/dist/task-results.js +61 -0
  143. package/dist/test-program.d.ts +54 -0
  144. package/dist/test-program.d.ts.map +1 -0
  145. package/dist/test-program.js +292 -0
  146. package/dist/test-timings.d.ts +71 -0
  147. package/dist/test-timings.d.ts.map +1 -0
  148. package/dist/test-timings.js +393 -0
  149. package/dist/test-walk-policy.d.ts +103 -0
  150. package/dist/test-walk-policy.d.ts.map +1 -0
  151. package/dist/test-walk-policy.js +657 -0
  152. package/dist/testing.d.ts +177 -0
  153. package/dist/testing.d.ts.map +1 -0
  154. package/dist/testing.js +824 -0
  155. package/dist/type-guards.d.ts +3 -0
  156. package/dist/type-guards.d.ts.map +1 -0
  157. package/dist/type-guards.js +4 -0
  158. package/dist/typecheck-test-policy.d.ts +8 -5
  159. package/dist/typecheck-test-policy.d.ts.map +1 -1
  160. package/dist/typecheck-test-policy.js +113 -100
  161. package/dist/workspace-config-policy.d.ts +8 -0
  162. package/dist/workspace-config-policy.d.ts.map +1 -1
  163. package/dist/workspace-config-policy.js +175 -63
  164. package/dist/workspace-index.d.ts +12 -0
  165. package/dist/workspace-index.d.ts.map +1 -0
  166. package/dist/workspace-index.js +17 -0
  167. package/dist/workspace-manifest.d.ts +37 -0
  168. package/dist/workspace-manifest.d.ts.map +1 -1
  169. package/executors.json +5 -0
  170. package/loader.js +13 -11
  171. package/managed/raw/envrc +33 -67
  172. package/managed/raw/git-format-staged.yml +30 -35
  173. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  174. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  175. package/managed/raw/tooling/direnv/developer-links.ts +569 -11
  176. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
  177. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  178. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  179. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  180. package/managed/raw/tooling/direnv/repo-path +14 -2
  181. package/managed/raw/tooling/direnv/setup-environment.ts +962 -148
  182. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  183. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  184. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  185. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  186. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  187. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  188. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  189. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  190. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  191. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  192. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  194. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  196. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  197. package/managed/templates/github/workflows/managed-files.yml +1 -2
  198. package/nextest.toml +8 -41
  199. package/package.json +74 -12
  200. package/runtime-input.sh +81 -0
  201. package/src/__tests__/counted-cargo.ts +33 -14
  202. package/src/__tests__/fixture-nx-env.ts +111 -46
  203. package/src/__tests__/progress-clock.ts +43 -0
  204. package/src/__tests__/runtime-input.ts +23 -0
  205. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  206. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  207. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  208. package/src/bin/smoo-nx-exec.ts +16 -74
  209. package/src/bin/smoo-nx-failures.ts +4 -0
  210. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  211. package/src/bin/smoo-nx-test-walks.ts +42 -0
  212. package/src/bounded-test-policy.test.ts +268 -21
  213. package/src/bounded-test-policy.ts +114 -42
  214. package/src/build-state-output-policy.test.ts +115 -0
  215. package/src/build-state-output-policy.ts +90 -0
  216. package/src/bun-bootstrap.test.ts +57 -3
  217. package/src/bun-file-packages.test.ts +47 -0
  218. package/src/cargo-closure-input.test.ts +138 -66
  219. package/src/cargo-closure-input.ts +17 -15
  220. package/src/cargo-dev-profile.ts +137 -0
  221. package/src/cargo-resolve-cache.test.ts +70 -1
  222. package/src/cargo-source-hash.test.ts +193 -97
  223. package/src/cargo-source-hash.ts +345 -68
  224. package/src/cargo-toolchain-policy.ts +6 -0
  225. package/src/cargo-workspace.test.ts +320 -0
  226. package/src/cargo-workspace.ts +336 -10
  227. package/src/cross-check-policy.test.ts +59 -1
  228. package/src/cross-check-policy.ts +25 -6
  229. package/src/disk-command-policy.test.ts +61 -0
  230. package/src/disk-command-policy.ts +107 -0
  231. package/src/ensure-built-receipt.test.ts +184 -0
  232. package/src/ensure-built-receipt.ts +263 -0
  233. package/src/ensure-built-witness.test.ts +344 -0
  234. package/src/ensure-built-witness.ts +252 -0
  235. package/src/ensure-built.test.ts +1036 -578
  236. package/src/ensure-built.ts +820 -224
  237. package/src/eslint-file-set.ts +9 -0
  238. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  239. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  240. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  241. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  242. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  243. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  244. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  245. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  246. package/src/executors/bounded-exec/executor.ts +565 -67
  247. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  248. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  249. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  250. package/src/executors/bounded-exec/progress.test.ts +79 -0
  251. package/src/executors/bounded-exec/progress.ts +118 -0
  252. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  253. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  254. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  255. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  256. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  257. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  258. package/src/executors/bounded-exec/schema.json +11 -5
  259. package/src/executors/bounded-exec/schema.ts +27 -11
  260. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  261. package/src/executors/bounded-exec/verdict.ts +433 -0
  262. package/src/executors/shard-timings/executor.ts +36 -0
  263. package/src/executors/shard-timings/schema.json +21 -0
  264. package/src/executors/shard-timings/schema.ts +4 -0
  265. package/src/failure-summary.ts +119 -0
  266. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  267. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  268. package/src/generators/create-package/generator.test.ts +6 -0
  269. package/src/generators/create-package/generator.ts +6 -2
  270. package/src/host-controller-wiring.test.ts +31 -0
  271. package/src/index.test.ts +909 -295
  272. package/src/index.ts +441 -143
  273. package/src/linked-snapshots.nx.test.ts +172 -0
  274. package/src/managed-files/ci-workflow.ts +54 -13
  275. package/src/managed-files/files.ts +65 -9
  276. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  277. package/src/managed-files/generator.test.ts +60 -1
  278. package/src/managed-files/json-edit.test.ts +216 -0
  279. package/src/managed-files/json-edit.ts +290 -0
  280. package/src/managed-files/managed-format-json.test.ts +308 -0
  281. package/src/managed-files/managed-format.ts +90 -2
  282. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  283. package/src/managed-files/publish-workflow.ts +285 -67
  284. package/src/managed-files/repo-path.test.ts +129 -0
  285. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  286. package/src/managed-files/tree.ts +11 -3
  287. package/src/manifest-hash.ts +2 -6
  288. package/src/nextest-code-bound.test.ts +155 -0
  289. package/src/nextest-code-bound.ts +195 -0
  290. package/src/nextest-extraction.test.ts +37 -5
  291. package/src/nextest-extraction.ts +51 -9
  292. package/src/nextest-partitions.test.ts +427 -82
  293. package/src/nx-cache-bound.test.ts +5 -10
  294. package/src/nx-cache-restore-mtime.test.ts +170 -0
  295. package/src/nx-daemon-claim.test.ts +277 -0
  296. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  297. package/src/nx-daemon-idle-policy.test.ts +51 -0
  298. package/src/nx-daemon-ignore-files.test.ts +210 -0
  299. package/src/nx-daemon-root-normalization.test.ts +105 -0
  300. package/src/nx-daemon-validity.test.ts +925 -0
  301. package/src/nx-dot-input-policy.test.ts +353 -0
  302. package/src/nx-failure-life-cycles.test.ts +207 -0
  303. package/src/nx-files-archive-racy.test.ts +97 -0
  304. package/src/nx-foreign-workspace-env.test.ts +329 -0
  305. package/src/nx-incomplete-run-summary.test.ts +70 -0
  306. package/src/nx-plugin-load-errors.test.ts +120 -0
  307. package/src/nx-project-resolution-cache.test.ts +176 -0
  308. package/src/nx-raw-inputs.test.ts +166 -0
  309. package/src/nx-resident-graph-workers.test.ts +7 -16
  310. package/src/nx-run-information.test.ts +118 -0
  311. package/src/nx-skipped-task-exit.test.ts +180 -0
  312. package/src/nx-state-location.test.ts +63 -0
  313. package/src/nx-store-resolution.test.ts +26 -25
  314. package/src/nx-task-graph-cycles.test.ts +148 -0
  315. package/src/nx-task-output-lease.test.ts +414 -0
  316. package/src/nx-use-local.test.ts +103 -0
  317. package/src/package-target-policy.ts +3 -6
  318. package/src/release-config-policy.ts +3 -6
  319. package/src/runtime-input.test.ts +215 -0
  320. package/src/runtime-input.ts +17 -0
  321. package/src/rust-tokens.ts +78 -0
  322. package/src/serial-group-wiring.test.ts +326 -0
  323. package/src/task-history-namespace.test.ts +87 -89
  324. package/src/task-results.test.ts +226 -0
  325. package/src/task-results.ts +75 -0
  326. package/src/test-program.test.ts +303 -0
  327. package/src/test-program.ts +341 -0
  328. package/src/test-timings.test.ts +240 -0
  329. package/src/test-timings.ts +311 -0
  330. package/src/test-walk-policy.test.ts +585 -0
  331. package/src/test-walk-policy.ts +731 -0
  332. package/src/testing.test.ts +509 -0
  333. package/src/testing.ts +922 -0
  334. package/src/type-guards.ts +4 -0
  335. package/src/typecheck-test-policy.test.ts +496 -11
  336. package/src/typecheck-test-policy.ts +137 -103
  337. package/src/workspace-config-policy.test.ts +212 -13
  338. package/src/workspace-config-policy.ts +101 -73
  339. package/src/workspace-index.ts +18 -0
  340. package/src/workspace-manifest.ts +41 -0
  341. package/test-timings.json +85 -30
  342. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
  343. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
@@ -1,118 +1,400 @@
1
- import { afterEach, expect, it } from 'bun:test';
1
+ import { afterAll, afterEach, beforeAll, expect, it } from 'bun:test';
2
2
  import { type ChildProcess, spawn } from 'node:child_process';
3
- import { mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
3
+ import { mkdir, mkdtemp, readdir, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
4
4
  import { tmpdir } from 'node:os';
5
5
  import { join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
6
7
  import type { TargetConfiguration } from 'nx/src/devkit-exports.js';
7
8
  import { useFixtureCargoHome } from './__tests__/fixture-cargo-home.js';
8
- import { createNodesV2 } from './index.js';
9
+ import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './bounded-test-policy.js';
10
+ import type { NxTaskContext } from './executors/bounded-exec/executor.js';
11
+ import { hostLeaseProcesses } from './executors/bounded-exec/ram-temp.js';
12
+ import type { BoundedExecOptions } from './executors/bounded-exec/schema.js';
13
+ import {
14
+ type BoundedExecRecord,
15
+ JUNIT_FILE,
16
+ readRecord,
17
+ taskDirectory,
18
+ writeRecord,
19
+ } from './executors/bounded-exec/verdict.js';
20
+ import { createNodesV2ForPlatform } from './index.js';
21
+ import { NEXTEST_EXTRACTION_DIRECTORY, nextestArchiveKey } from './nextest-extraction.js';
9
22
 
10
23
  useFixtureCargoHome();
11
24
 
12
- it('executes every archived test once across ordinary and exceptional partitions', async () => {
13
- const root = await realpath(await mkdtemp(join(tmpdir(), 'smoo-nextest-partitions-')));
14
- fixtureRoot = root;
15
- const ordinary = Array.from({ length: 13 }, (_, index) => `ordinary_${index}`);
16
- // The classes the plugin's nextest.toml singles out with an override: a
17
- // compile-fail test and the real-APFS lifecycle test each carry a raised
18
- // slow-timeout, so each is lifted out of the ordinary hash.
19
- const exceptional = [
20
- ...Array.from({ length: 6 }, (_, index) => `compile_fail_partition_${index}`),
21
- ...Array.from({ length: 6 }, (_, index) => `partition_${index}_fail_to_compile`),
22
- 'real_apfs_partition_substrate_lifecycle',
23
- ];
24
- const expected = [...ordinary, ...exceptional];
25
- await writeFile(join(root, 'package.json'), '{"name":"partition-fixture","private":true}\n');
26
- await writeFile(join(root, '.gitignore'), 'node_modules/\ntarget/\n.nx/\n*.log\n');
27
- await writeFile(
28
- join(root, 'Cargo.toml'),
29
- '[workspace]\nresolver = "2"\n\n[package]\nname = "partition-probe"\nversion = "0.1.0"\nedition = "2021"\n\n[package.metadata.smoothbricks.test]\nshards = 3\n',
30
- );
31
- await mkdir(join(root, 'src'));
32
- await writeFile(
33
- join(root, 'src/lib.rs'),
34
- `#[cfg(test)] mod tests {
25
+ const GROUP_TARGET = 'cargo-test-group-serial-probe';
26
+ const GROUP_ID = `partition-fixture:${GROUP_TARGET}`;
27
+ const GROUP_HASH = 'serial-probe-hash';
28
+ // The filter the plugin's group runner carries; the empty-selection case replaces exactly this text.
29
+ const SERIAL_FILTER_ARG = "-E '(test(/serial_probe_/))'";
30
+
31
+ const ordinary = Array.from({ length: 13 }, (_, index) => `ordinary_${index}`);
32
+ // The class the plugin's nextest.toml singles out with an override: the
33
+ // compile-fail tests carry a raised slow-timeout, so they are lifted out of the
34
+ // ordinary hash.
35
+ const exceptional = [
36
+ ...Array.from({ length: 6 }, (_, index) => `compile_fail_partition_${index}`),
37
+ ...Array.from({ length: 6 }, (_, index) => `partition_${index}_fail_to_compile`),
38
+ ];
39
+ const serial = Array.from({ length: 4 }, (_, index) => `serial_probe_${index}`);
40
+ const expected = [...ordinary, ...exceptional, ...serial];
41
+
42
+ /** The one Cargo fixture and archive every case reads, built once in beforeAll. */
43
+ interface SharedFixture {
44
+ readonly root: string;
45
+ readonly targets: Readonly<Record<string, TargetConfiguration>>;
46
+ readonly passingSeed: BoundedExecRecord;
47
+ }
48
+
49
+ /** A child this test started and has not yet seen close, with the command line that names it. */
50
+ interface OpenChild {
51
+ readonly command: string;
52
+ readonly closed: Promise<unknown>;
53
+ readonly graceful: boolean;
54
+ }
55
+
56
+ /** Set first in beforeAll, so afterAll can keep or remove a root even when beforeAll fails part way. */
57
+ let fixtureRoot: string | undefined;
58
+ /** Set last in beforeAll: the fixture every case reads. */
59
+ let shared: SharedFixture | undefined;
60
+ const openChildren = new Map<ChildProcess, OpenChild>();
61
+ /** Set once teardown begins: a body still running then may not start a child, nor keep the result of one. */
62
+ let ending = false;
63
+ /** The current setup or case body, so teardown waits for it before another case or removal. */
64
+ let bodyDone: Promise<void> = Promise.resolve();
65
+ /** A failed barrier keeps the fixture, even if a later cleanup attempt succeeds. */
66
+ let barrierFailure: string | undefined;
67
+
68
+ beforeAll(
69
+ caseBody(async () => {
70
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'smoo-nextest-partitions-')));
71
+ fixtureRoot = root;
72
+ await writeFile(join(root, 'package.json'), '{"name":"partition-fixture","private":true}\n');
73
+ await writeFile(join(root, '.gitignore'), 'node_modules/\ntarget/\n.nx/\n*.log\n');
74
+ await writeFile(
75
+ join(root, 'Cargo.toml'),
76
+ '[workspace]\nresolver = "2"\n\n[package]\nname = "partition-probe"\nversion = "0.1.0"\nedition = "2021"\n\n[package.metadata.smoothbricks.test]\nshards = 3\n',
77
+ );
78
+ await mkdir(join(root, '.config'));
79
+ await writeFile(
80
+ join(root, '.config/nextest.toml'),
81
+ [
82
+ '[test-groups.serial-probe]',
83
+ 'max-threads = 1',
84
+ '',
85
+ '[[profile.default.overrides]]',
86
+ "filter = 'test(/serial_probe_/)'",
87
+ `platform = 'cfg(target_os="macos")'`,
88
+ "test-group = 'serial-probe'",
89
+ '',
90
+ ].join('\n'),
91
+ );
92
+ await mkdir(join(root, 'src'));
93
+ await writeFile(
94
+ join(root, 'src/lib.rs'),
95
+ `#[cfg(test)] mod tests {
35
96
  use std::io::Write;
36
97
  fn record(name: &str) {
37
98
  let mut file = std::fs::OpenOptions::new().create(true).append(true)
38
99
  .open(std::env::var("PARTITION_EXECUTIONS").unwrap()).unwrap();
39
100
  file.write_all(format!("{name}\\n").as_bytes()).unwrap();
40
101
  }
41
- ${expected.map((name) => ` #[test] fn ${name}() { record("${name}"); }`).join('\n')}
102
+ fn fail_when_forced() {
103
+ if std::env::var_os("PARTITION_FAIL_SERIAL").is_some() {
104
+ panic!("forced failure");
105
+ }
106
+ }
107
+ ${expected.map((name) => ` #[test] fn ${name}() { record("${name}");${serial.includes(name) ? ' fail_when_forced();' : ''} }`).join('\n')}
42
108
  }
43
109
  `,
110
+ );
111
+ await symlink(join(import.meta.dir, '../../../node_modules'), join(root, 'node_modules'), 'dir');
112
+ await run(root, ['git', 'init', '--quiet']);
113
+ await run(root, ['cargo', 'generate-lockfile', '--offline']);
114
+ const [, infer] = createNodesV2ForPlatform('darwin', 'arm64');
115
+ const result = await infer(['package.json'], undefined, { workspaceRoot: root, nxJsonConfiguration: {} });
116
+ const targets = result[0]?.[1].projects?.['.']?.targets;
117
+ if (targets === undefined) throw new Error('Cargo fixture inferred no targets');
118
+ // The archive is the one real prerequisite: every runner executes its binaries.
119
+ await run(root, ['sh', '-c', command(targets, 'cargo-test-archive')]);
120
+ const source = { root, targets };
121
+ const passingSeed = await groupSucceeds(source);
122
+ shared = { ...source, passingSeed };
123
+ }),
124
+ );
125
+
126
+ /**
127
+ * One case's body, run as its own promise. `ending` is cleared for this case, and afterEach waits for the
128
+ * promise before the next case may start, so a body the deadline abandons cannot leak children into it.
129
+ */
130
+ function caseBody(body: () => Promise<void>): () => Promise<void> {
131
+ return async () => {
132
+ ending = false;
133
+ bodyDone = body();
134
+ await bodyDone;
135
+ };
136
+ }
137
+
138
+ /**
139
+ * The safety barrier. It runs after every case, and once more before the fixture is removed.
140
+ *
141
+ * A case's deadline abandons its body mid-`await`, so nothing it started may outlive the case. In order:
142
+ * `ending` makes every later `runTracked` refuse to spawn, and makes a captured-only child still running print its
143
+ * capture instead of returning it; each plain child's process
144
+ * group is killed; then the lease owner ends every process still working in the fixture, a driver first,
145
+ * with SIGTERM so its bounded executor relays the stop and releases its lease. Only once every child's exit has
146
+ * settled and the body has settled does the barrier report. A child whose exit was not confirmed, or any
147
+ * process left working, is returned by name, not hidden.
148
+ */
149
+ async function settle(): Promise<string[]> {
150
+ ending = true;
151
+ const open = [...openChildren];
152
+ openChildren.clear();
153
+ for (const [child, entry] of open) {
154
+ if (!entry.graceful) killProcessGroup(child);
155
+ }
156
+ let leftovers: string[];
157
+ try {
158
+ leftovers = fixtureRoot === undefined ? [] : await hostLeaseProcesses.stopWorkingIn(fixtureRoot);
159
+ } catch (error) {
160
+ barrierFailure = `the lease owner could not end its processes: ${String(error)}`;
161
+ throw error;
162
+ }
163
+ // Each close either resolved, so its child ended, or rejected, so its exit was never confirmed and it is named.
164
+ const exits = await Promise.all(
165
+ open.map(async ([, entry]) => {
166
+ try {
167
+ await entry.closed;
168
+ return null;
169
+ } catch (error) {
170
+ return `${entry.command}: ${String(error)}`;
171
+ }
172
+ }),
44
173
  );
45
- await symlink(join(import.meta.dir, '../../../node_modules'), join(root, 'node_modules'), 'dir');
46
- await run(root, ['git', 'init', '--quiet']);
47
- await run(root, ['cargo', 'generate-lockfile', '--offline']);
48
- const [, infer] = createNodesV2;
49
- const result = await infer(['package.json'], undefined, { workspaceRoot: root, nxJsonConfiguration: {} });
50
- const targets = result[0]?.[1].projects?.['.']?.targets;
51
- if (targets === undefined) throw new Error('Cargo fixture inferred no targets');
52
- // The archive is the one real prerequisite: every runner executes its binaries.
53
- await run(root, ['sh', '-c', command(targets, 'cargo-test-archive')]);
54
- // One log per partition kind, so the proof is exact selection and not only
55
- // coverage: the ordinary shards ran every ordinary test once and nothing
56
- // else, and the exceptional shards did the same for theirs. The six runners
57
- // are independent, so they run side by side exactly as Nx fans them out.
174
+ await Promise.allSettled([bodyDone]);
175
+ const problems: string[] = [];
176
+ const unconfirmed = exits.filter((line): line is string => line !== null);
177
+ if (unconfirmed.length > 0) {
178
+ problems.push(`child processes whose exit was not confirmed:\n${unconfirmed.join('\n')}`);
179
+ }
180
+ if (leftovers.length > 0) problems.push(`processes left working in the fixture:\n${leftovers.join('\n')}`);
181
+ if (problems.length > 0) barrierFailure = problems.join('\n');
182
+ return problems;
183
+ }
184
+
185
+ afterEach(async () => {
186
+ const problems = await settle();
187
+ if (problems.length > 0) throw new Error(`test ended with ${problems.join('\n')}`);
188
+ });
189
+
190
+ /**
191
+ * Removes the one fixture root, after the same barrier every case runs. If the barrier cannot account for
192
+ * every process, or the lease owner errors, the root is kept and the error names it, so the processes it
193
+ * names still have their directory.
194
+ */
195
+ afterAll(async () => {
196
+ if (fixtureRoot === undefined) return;
197
+ const root = fixtureRoot;
198
+ try {
199
+ await settle();
200
+ } catch (error) {
201
+ throw new Error(`kept fixture ${root}: the lease owner could not end its processes: ${String(error)}`);
202
+ }
203
+ if (barrierFailure !== undefined) throw new Error(`kept fixture ${root}:\n${barrierFailure}`);
204
+ fixtureRoot = undefined;
205
+ shared = undefined;
206
+ await rm(root, { recursive: true, force: true });
207
+ });
208
+
209
+ function fixture(): SharedFixture {
210
+ if (shared === undefined) {
211
+ throw new Error('the shared Cargo fixture was not built: its beforeAll did not complete');
212
+ }
213
+ return shared;
214
+ }
215
+
216
+ function groupContext(root: string): NxTaskContext {
217
+ return {
218
+ root,
219
+ projectName: 'partition-fixture',
220
+ targetName: GROUP_TARGET,
221
+ taskGraph: { tasks: { [GROUP_ID]: { hash: GROUP_HASH } } },
222
+ };
223
+ }
224
+
225
+ /**
226
+ * The group's verdict directory in the fixture's own workspace data, the same place the overlay sends the real
227
+ * executor. readRecord proves the two agree: a record written anywhere else leaves the verdict null.
228
+ */
229
+ function groupDirectory(root: string): string {
230
+ return taskDirectory(join(root, '.nx/workspace-data'), GROUP_ID);
231
+ }
232
+
233
+ /**
234
+ * The group's options as the plan infers them, run from the fixture root: the inferred cwd is the cargo root, which
235
+ * is the fixture root. `command` replaces the run's command, which stays the plan's byte-identical one otherwise.
236
+ */
237
+ function groupOptions(
238
+ targets: Readonly<Record<string, TargetConfiguration>>,
239
+ root: string,
240
+ run = command(targets, GROUP_TARGET),
241
+ ): BoundedExecOptions {
242
+ // The group runner is bounded by progress like every test target: no ceiling, one runnable test at a time.
243
+ expect(targets[GROUP_TARGET]?.options).toMatchObject({
244
+ idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
245
+ killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
246
+ parallelism: 1,
247
+ });
248
+ expect(targets[GROUP_TARGET]?.options).not.toHaveProperty('timeoutMs');
249
+ return {
250
+ command: run,
251
+ cwd: root,
252
+ idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
253
+ killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
254
+ parallelism: 1,
255
+ };
256
+ }
257
+
258
+ /**
259
+ * Every archived test runs exactly once, in the runner that owns its class, and the serial group lists exactly
260
+ * its probes. The runners are independent, so they run side by side exactly as Nx fans them out.
261
+ */
262
+ async function executesEveryTestOnce(): Promise<void> {
263
+ const { root, targets } = fixture();
264
+ // One log per runner kind, so the proof is exact selection and not only coverage: the ordinary shards ran
265
+ // every ordinary test once and nothing else, the exceptional shards did the same for theirs, and the serial
266
+ // group ran its class once in one unpartitioned runner.
267
+ const serialLog = join(root, 'serial.log');
58
268
  const partitions = [
59
269
  { kind: 'shard', log: join(root, 'ordinary.log'), tests: ordinary },
60
270
  { kind: 'exceptions-shard', log: join(root, 'exceptional.log'), tests: exceptional },
61
271
  ];
62
- await Promise.all(
63
- partitions.flatMap(({ kind, log }) =>
272
+ await Promise.all([
273
+ ...partitions.flatMap(({ kind, log }) =>
64
274
  [1, 2, 3].map((index) =>
65
275
  run(root, ['sh', '-c', command(targets, `cargo-test-partition-probe-${kind}${index}`)], {
66
276
  PARTITION_EXECUTIONS: log,
67
277
  }),
68
278
  ),
69
279
  ),
70
- );
71
- for (const { log, tests } of partitions) {
280
+ run(root, ['sh', '-c', command(targets, GROUP_TARGET)], { PARTITION_EXECUTIONS: serialLog }),
281
+ ]);
282
+ for (const { log, tests } of [...partitions, { log: serialLog, tests: serial }]) {
72
283
  const observed = (await readFile(log, 'utf8')).trim().split('\n').sort();
73
284
  expect(observed).toEqual([...tests].sort());
74
285
  }
75
- });
76
-
77
- function command(targets: Readonly<Record<string, TargetConfiguration>>, name: string): string {
78
- const single: unknown = targets[name]?.options?.command;
79
- if (typeof single !== 'string') throw new Error(`${name} inferred no executable command`);
80
- return single;
286
+ // The six runners shared one extraction, in Cargo's build tree: the archive's directory holds only the
287
+ // archive, the declared Nx output.
288
+ expect(await readdir(join(root, 'target', NEXTEST_EXTRACTION_DIRECTORY))).toEqual([
289
+ await nextestArchiveKey(join(root, '.cache/nextest/archive.tar.zst')),
290
+ ]);
291
+ expect(await readdir(join(root, '.cache/nextest'))).toEqual(['archive.tar.zst']);
292
+ // The serial group is one unpartitioned runner.
293
+ expect(command(targets, GROUP_TARGET)).not.toContain('--partition');
81
294
  }
82
295
 
83
- /** A child this test started and has not yet seen close, with the command line that names it. */
84
- interface OpenChild {
85
- readonly command: string;
86
- readonly closed: Promise<unknown>;
296
+ /**
297
+ * The real default executor, run for real on this fixture's group in a driver process. Its verdict is typed
298
+ * passed and returned to its caller: fixture setup retains one real seed before any case runs.
299
+ */
300
+ async function groupSucceeds(source: Pick<SharedFixture, 'root' | 'targets'> = fixture()): Promise<BoundedExecRecord> {
301
+ const { root, targets } = source;
302
+ const directory = groupDirectory(root);
303
+ const realCommand = command(targets, GROUP_TARGET);
304
+ // Group policy requires --no-fail-fast: ordinary failures must not stop the remaining tests. Checked before any run.
305
+ expect(realCommand).toContain('--no-fail-fast');
306
+ expect(realCommand).not.toContain('max-fail');
307
+ // The probes read PARTITION_EXECUTIONS and PARTITION_FAIL_SERIAL from the environment. Each run sets them on the
308
+ // driver's spawn; the runner inherits them, since bounded-exec merges process.env into every runner. The command
309
+ // stays the byte-identical one the plan generates.
310
+ const successLog = join(root, 'group-success.log');
311
+ await rm(successLog, { force: true });
312
+ const success = await runGroupExecutor(root, groupOptions(targets, root), groupContext(root), {
313
+ PARTITION_EXECUTIONS: successLog,
314
+ });
315
+ expect(success.code, success.output).toBe(0);
316
+ const passed = await readRecord(directory);
317
+ if (passed === null) throw new Error('a group run that passed wrote no verdict');
318
+ expect(passed).toMatchObject({ task: GROUP_ID, hash: GROUP_HASH, verdict: { outcome: 'passed' } });
319
+ // Budgeted runs reserve only the group's one runnable test; unbudgeted hosts have no receipt.
320
+ if (passed.cpu !== undefined) {
321
+ expect(passed.cpu).toMatchObject({ tokens: 1, want: 1 });
322
+ }
323
+ expect((await readFile(successLog, 'utf8')).trim().split('\n').sort()).toEqual([...serial].sort());
324
+ return passed;
87
325
  }
88
326
 
89
- const openChildren = new Map<ChildProcess, OpenChild>();
90
- let fixtureRoot: string | undefined;
327
+ /**
328
+ * A group whose filter selects nothing fails rather than passing a run that ran no test. The fixture's real passing
329
+ * run seeds the stale verdict and report the run must replace; the marker log proves no probe ran.
330
+ */
331
+ async function emptySelectionFails(): Promise<void> {
332
+ const { root, targets, passingSeed } = fixture();
333
+ const directory = groupDirectory(root);
334
+ await writeRecord(directory, passingSeed);
335
+ await writeFile(join(directory, JUNIT_FILE), 'stale report\n');
336
+ const realCommand = command(targets, GROUP_TARGET);
337
+ const emptied = realCommand.replace(SERIAL_FILTER_ARG, "-E 'none()'");
338
+ if (emptied === realCommand) throw new Error(`the group runner carries no ${SERIAL_FILTER_ARG} to empty`);
339
+ const emptyLog = join(root, 'group-empty.log');
340
+ await rm(emptyLog, { force: true });
341
+ const empty = await runGroupExecutor(root, groupOptions(targets, root, emptied), groupContext(root), {
342
+ PARTITION_EXECUTIONS: emptyLog,
343
+ });
344
+ expect(empty.code, empty.output).toBe(2);
345
+ const record = await readRecord(directory);
346
+ expect(record).toMatchObject({ task: GROUP_ID, hash: GROUP_HASH, verdict: { outcome: 'failed' } });
347
+ await expect(readFile(join(directory, JUNIT_FILE), 'utf8')).resolves.not.toBe('stale report\n');
348
+ await expect(readFile(emptyLog, 'utf8')).rejects.toMatchObject({ code: 'ENOENT' });
349
+ }
91
350
 
92
351
  /**
93
- * The only teardown, for a pass, a failure and the per-test deadline alike.
94
- *
95
- * The deadline abandons the test body mid-`await`, so the body cannot be
96
- * trusted to clean up after itself. This hook signals each open child's whole
97
- * process group (the same detached-group kill the bounded executor uses, since
98
- * `sh -c` leaves cargo and nextest as grandchildren), waits for every one to
99
- * close, and only then deletes the fixture they were running in. It then
100
- * names what was still open instead of leaving a bare timeout.
352
+ * Continuation past failure: each serial probe records, then fails through `fail_when_forced` because
353
+ * PARTITION_FAIL_SERIAL is set. The group must still run and report all four. This is the observed
354
+ * continuation, not a mutant count, and it says nothing about serialization: the override is macOS-only.
101
355
  */
102
- afterEach(async () => {
103
- const open = [...openChildren.values()];
104
- for (const child of openChildren.keys()) killProcessGroup(child);
105
- openChildren.clear();
106
- await Promise.allSettled(open.map((child) => child.closed));
107
- if (fixtureRoot !== undefined) {
108
- const root = fixtureRoot;
109
- fixtureRoot = undefined;
110
- await rm(root, { recursive: true, force: true });
356
+ async function continuesPastFailures(): Promise<void> {
357
+ const { root, targets } = fixture();
358
+ const directory = groupDirectory(root);
359
+ const failureLog = join(root, 'group-failure.log');
360
+ const failed = await runGroupExecutor(root, groupOptions(targets, root), groupContext(root), {
361
+ PARTITION_EXECUTIONS: failureLog,
362
+ PARTITION_FAIL_SERIAL: '1',
363
+ });
364
+ expect(failed.code, failed.output).toBe(2);
365
+ const failedRecord = await readRecord(directory);
366
+ if (failedRecord === null) throw new Error('a group run that failed wrote no verdict');
367
+ if (failedRecord.verdict.outcome !== 'failed') {
368
+ throw new Error(`a failing group wrote verdict ${failedRecord.verdict.outcome}, not failed`);
111
369
  }
112
- if (open.length > 0) {
113
- throw new Error(`test ended with child processes still open:\n${open.map((child) => child.command).join('\n')}`);
370
+ expect(failedRecord.verdict.tests).toHaveLength(serial.length);
371
+ for (const name of serial) {
372
+ expect(
373
+ failedRecord.verdict.tests.some((test) => test.includes(name)),
374
+ name,
375
+ ).toBe(true);
114
376
  }
115
- });
377
+ expect((await readFile(failureLog, 'utf8')).trim().split('\n').sort()).toEqual([...serial].sort());
378
+ }
379
+
380
+ it(
381
+ 'executes every archived test once across ordinary, exceptional and serial-group runners',
382
+ caseBody(executesEveryTestOnce),
383
+ );
384
+ it(
385
+ 'runs the serial group through the real default executor and keeps its passing verdict',
386
+ caseBody(async () => {
387
+ await groupSucceeds();
388
+ }),
389
+ );
390
+ it('fails a serial group whose filter selects no test, replacing the previous verdict', caseBody(emptySelectionFails));
391
+ it('runs the serial group past failing probes and reports all four', caseBody(continuesPastFailures));
392
+
393
+ function command(targets: Readonly<Record<string, TargetConfiguration>>, name: string): string {
394
+ const single: unknown = targets[name]?.options?.command;
395
+ if (typeof single !== 'string') throw new Error(`${name} inferred no executable command`);
396
+ return single;
397
+ }
116
398
 
117
399
  function killProcessGroup(child: ChildProcess): void {
118
400
  if (child.pid === undefined) return;
@@ -123,28 +405,91 @@ function killProcessGroup(child: ChildProcess): void {
123
405
  }
124
406
  }
125
407
 
126
- async function run(root: string, args: string[], overlay: Record<string, string> = {}): Promise<void> {
408
+ /** A child that ran to its close: its exit code and what it printed to stdout and stderr together. */
409
+ interface Tracked {
410
+ readonly code: number | null;
411
+ readonly output: string;
412
+ }
413
+
414
+ async function runTracked(
415
+ root: string,
416
+ args: string[],
417
+ options: { overlay?: Record<string, string>; graceful?: boolean; tee?: boolean } = {},
418
+ ): Promise<Tracked> {
419
+ if (ending) throw new Error(`teardown has begun; not starting ${args.join(' ')}`);
127
420
  const [program, ...rest] = args;
128
421
  if (program === undefined) throw new Error('run needs a program');
129
422
  const child = spawn(program, rest, {
130
423
  cwd: root,
131
- env: { ...process.env, ...overlay },
424
+ env: { ...process.env, ...options.overlay },
132
425
  detached: process.platform !== 'win32',
133
426
  });
134
427
  child.stdin?.end();
135
428
  const output: Buffer[] = [];
136
- child.stdout?.on('data', (chunk: Buffer) => output.push(chunk));
137
- child.stderr?.on('data', (chunk: Buffer) => output.push(chunk));
429
+ const tee = options.tee ?? false;
430
+ child.stdout?.on('data', (chunk: Buffer) => {
431
+ output.push(chunk);
432
+ if (tee) process.stdout.write(chunk);
433
+ });
434
+ child.stderr?.on('data', (chunk: Buffer) => {
435
+ output.push(chunk);
436
+ if (tee) process.stderr.write(chunk);
437
+ });
138
438
  const closed = new Promise<number | null>((resolve, reject) => {
139
439
  child.once('error', reject);
140
440
  child.once('close', resolve);
141
441
  });
142
- openChildren.set(child, { command: args.join(' '), closed });
442
+ openChildren.set(child, { command: args.join(' '), closed, graceful: options.graceful ?? false });
143
443
  let code: number | null;
144
444
  try {
145
445
  code = await closed;
146
446
  } finally {
147
447
  openChildren.delete(child);
448
+ // Teardown abandoned this case, so no caller will print the capture. A captured-only child prints it here; a teed
449
+ // child already printed it live.
450
+ if (ending && !tee) process.stdout.write(Buffer.concat(output).toString());
451
+ }
452
+ if (ending) {
453
+ throw new Error(
454
+ `teardown began while ${args.join(' ')} ran; its output is printed above and its result is discarded`,
455
+ );
148
456
  }
149
- expect(code, `${args.join(' ')}\n${Buffer.concat(output).toString()}`).toBe(0);
457
+ return { code, output: Buffer.concat(output).toString() };
458
+ }
459
+
460
+ async function run(root: string, args: string[], overlay: Record<string, string> = {}): Promise<void> {
461
+ const { code, output } = await runTracked(root, args, { overlay });
462
+ expect(code, `${args.join(' ')}\n${output}`).toBe(0);
463
+ }
464
+
465
+ /**
466
+ * The built production executor, in a driver process whose runner group the lease owner can end.
467
+ * The test target already depends on build: do not compile the TypeScript project again in every driver.
468
+ */
469
+ const EXECUTOR_MODULE = fileURLToPath(new URL('../dist/executors/bounded-exec/executor.js', import.meta.url));
470
+
471
+ /**
472
+ * Exit 0 when the executor reports success, 2 when its run fails. A crash in the driver
473
+ * exits 1, with the stack in `output`. `process.exitCode`, not `process.exit`, so stdout and stderr flush.
474
+ * Its stdout and stderr are teed live as they arrive, and the same text is returned in `output` for assertions.
475
+ * `environment` carries a run's probe variables onto the driver's spawn. The workspace data key comes last, so
476
+ * no caller's entry can override the fixture's own workspace data.
477
+ */
478
+ async function runGroupExecutor(
479
+ root: string,
480
+ options: BoundedExecOptions,
481
+ context: NxTaskContext,
482
+ environment: Record<string, string> = {},
483
+ ): Promise<Tracked> {
484
+ const script = `import boundedExecExecutor from ${JSON.stringify(EXECUTOR_MODULE)};
485
+ console.log('driver ready: calling the default executor');
486
+ const result = await boundedExecExecutor(${JSON.stringify(options)}, ${JSON.stringify(context)});
487
+ console.log('driver done: default executor success=' + result.success);
488
+ process.exitCode = result.success ? 0 : 2;`;
489
+ const result = await runTracked(root, ['node', '--input-type=module', '-e', script], {
490
+ graceful: true,
491
+ tee: true,
492
+ overlay: { ...environment, NX_WORKSPACE_DATA_DIRECTORY: join(root, '.nx/workspace-data') },
493
+ });
494
+ return result;
150
495
  }
@@ -1,10 +1,9 @@
1
1
  import { expect, it } from 'bun:test';
2
2
  import { execFileSync, spawn } from 'node:child_process';
3
- import { mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
4
- import { tmpdir } from 'node:os';
3
+ import { mkdir, readFile, symlink, writeFile } from 'node:fs/promises';
5
4
  import { join } from 'node:path';
6
5
  import { guardEvent } from './__tests__/counted-cargo.js';
7
- import { fixtureNxEnv } from './__tests__/fixture-nx-env.js';
6
+ import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
8
7
 
9
8
  /**
10
9
  * Guards the cache-bound hunk of `patches/nx@23.2.1.patch`, the local build of
@@ -72,8 +71,7 @@ async function runNx(root: string, env: Record<string, string>): Promise<{ code:
72
71
  }
73
72
 
74
73
  it('bounds the default cache from its own filesystem without listing the host disks', async () => {
75
- const root = await realpath(await mkdtemp(join(tmpdir(), 'nx-cache-bound-')));
76
- try {
74
+ await withNxFixture('nx-cache-bound-', async ({ workspace: root, socketDirectory }) => {
77
75
  await mkdir(join(root, 'app'));
78
76
  await symlink(join(repositoryRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
79
77
  await writeFile(join(root, '.gitignore'), 'node_modules\n.nx\napp/result.txt\n');
@@ -101,14 +99,11 @@ it('bounds the default cache from its own filesystem without listing the host di
101
99
  // The bound is taken by the client that runs the tasks, daemon or not.
102
100
  // The cache directory does not exist yet, as on a checkout's first run.
103
101
  const { code, output } = await runNx(root, {
104
- ...fixtureNxEnv(root),
105
- NX_DAEMON: 'false',
102
+ ...fixtureNxEnv(root, socketDirectory),
106
103
  NODE_OPTIONS: `--require ${join(root, 'forbid-disk-inventory.cjs')}`,
107
104
  });
108
105
  expect(output).not.toContain('Nx enumerated the host disks');
109
106
  expect(code, output).toBe(0);
110
107
  expect(await readFile(join(root, 'app/result.txt'), 'utf8')).toBe('built');
111
- } finally {
112
- await rm(root, { recursive: true, force: true });
113
- }
108
+ });
114
109
  });