@smoothbricks/nx-plugin 0.5.7 → 0.6.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 (432) hide show
  1. package/README.md +1086 -360
  2. package/dist/.build-inputs.json +138 -0
  3. package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
  4. package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
  6. package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
  7. package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
  9. package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
  10. package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-nextest-timings.js +28 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +14 -15
  15. package/dist/build-state-output-policy.d.ts +95 -1
  16. package/dist/build-state-output-policy.d.ts.map +1 -1
  17. package/dist/build-state-output-policy.js +368 -30
  18. package/dist/bun-lock-scope.d.ts +44 -0
  19. package/dist/bun-lock-scope.d.ts.map +1 -0
  20. package/dist/bun-lock-scope.js +97 -0
  21. package/dist/cargo-build-script-env.d.ts +49 -0
  22. package/dist/cargo-build-script-env.d.ts.map +1 -0
  23. package/dist/cargo-build-script-env.js +324 -0
  24. package/dist/cargo-closure-input.d.ts +31 -4
  25. package/dist/cargo-closure-input.d.ts.map +1 -1
  26. package/dist/cargo-closure-input.js +66 -6
  27. package/dist/cargo-retention-hook.d.ts +17 -0
  28. package/dist/cargo-retention-hook.d.ts.map +1 -0
  29. package/dist/cargo-retention-hook.js +85 -0
  30. package/dist/cargo-source-hash.d.ts +25 -7
  31. package/dist/cargo-source-hash.d.ts.map +1 -1
  32. package/dist/cargo-source-hash.js +108 -43
  33. package/dist/cargo-toolchain-paths.d.ts +40 -0
  34. package/dist/cargo-toolchain-paths.d.ts.map +1 -0
  35. package/dist/cargo-toolchain-paths.js +84 -0
  36. package/dist/cargo-toolchain-policy.d.ts +25 -8
  37. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  38. package/dist/cargo-toolchain-policy.js +39 -5
  39. package/dist/cargo-workspace.d.ts +10 -4
  40. package/dist/cargo-workspace.d.ts.map +1 -1
  41. package/dist/cargo-workspace.js +65 -95
  42. package/dist/cross-check-policy.d.ts +9 -9
  43. package/dist/cross-check-policy.d.ts.map +1 -1
  44. package/dist/cross-check-policy.js +11 -11
  45. package/dist/disk-command-policy.d.ts.map +1 -1
  46. package/dist/disk-command-policy.js +1 -0
  47. package/dist/ensure-built-receipt.d.ts +13 -5
  48. package/dist/ensure-built-receipt.d.ts.map +1 -1
  49. package/dist/ensure-built-receipt.js +126 -47
  50. package/dist/ensure-built-witness.d.ts +27 -8
  51. package/dist/ensure-built-witness.d.ts.map +1 -1
  52. package/dist/ensure-built-witness.js +45 -15
  53. package/dist/ensure-built.d.ts.map +1 -1
  54. package/dist/ensure-built.js +9 -1
  55. package/dist/eslint-config-closure.d.ts +7 -0
  56. package/dist/eslint-config-closure.d.ts.map +1 -0
  57. package/dist/eslint-config-closure.js +346 -0
  58. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  59. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  60. package/dist/executors/bounded-exec/bounds.js +43 -0
  61. package/dist/executors/bounded-exec/cpu-pool.d.ts +33 -36
  62. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  63. package/dist/executors/bounded-exec/cpu-pool.js +54 -119
  64. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  65. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  66. package/dist/executors/bounded-exec/executor.js +371 -239
  67. package/dist/executors/bounded-exec/gateway-lease.d.ts +22 -19
  68. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/gateway-lease.js +81 -28
  70. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  71. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  73. package/dist/executors/bounded-exec/lease-wait.d.ts +43 -0
  74. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  75. package/dist/executors/bounded-exec/lease-wait.js +68 -0
  76. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  77. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  78. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  79. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  80. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  82. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  83. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  84. package/dist/executors/bounded-exec/progress.js +5 -2
  85. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  86. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  88. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  89. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  90. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  91. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  92. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  93. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  94. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  95. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  96. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  97. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +4 -4
  98. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/run-cpu-pool.js +20 -30
  100. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  101. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  102. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  103. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  104. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  105. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  106. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  107. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  108. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  109. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  110. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  111. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  112. package/dist/executors/bounded-exec/verdict.d.ts +40 -11
  113. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  114. package/dist/executors/bounded-exec/verdict.js +88 -19
  115. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  116. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  117. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  118. package/dist/executors/clean-outputs/executor.js +1 -0
  119. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  120. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  121. package/dist/executors/scriptc-native/executor.js +367 -0
  122. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  123. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  124. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  125. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  126. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/schema.js +1 -0
  128. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  129. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  130. package/dist/executors/typescript-emit/executor.js +164 -33
  131. package/dist/forbidden-spelling-policy.d.ts +56 -0
  132. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  133. package/dist/forbidden-spelling-policy.js +176 -0
  134. package/dist/generators/create-package/generator.d.ts.map +1 -1
  135. package/dist/generators/create-package/generator.js +3 -4
  136. package/dist/graph-input-contract.d.ts +14 -0
  137. package/dist/graph-input-contract.d.ts.map +1 -1
  138. package/dist/graph-input-contract.js +67 -2
  139. package/dist/index.d.ts +23 -6
  140. package/dist/index.d.ts.map +1 -1
  141. package/dist/index.js +672 -214
  142. package/dist/managed-assets.d.ts +2 -0
  143. package/dist/managed-assets.d.ts.map +1 -1
  144. package/dist/managed-files/files.d.ts +3 -3
  145. package/dist/managed-files/files.d.ts.map +1 -1
  146. package/dist/managed-files/files.js +28 -3
  147. package/dist/managed-files/managed-format.d.ts.map +1 -1
  148. package/dist/managed-files/managed-format.js +1 -0
  149. package/dist/nextest-code-bound.js +1 -0
  150. package/dist/nextest-timings.d.ts +35 -0
  151. package/dist/nextest-timings.d.ts.map +1 -0
  152. package/dist/nextest-timings.js +168 -0
  153. package/dist/owned-installation.d.ts +6 -5
  154. package/dist/owned-installation.d.ts.map +1 -1
  155. package/dist/owned-installation.js +150 -26
  156. package/dist/package-target-policy.d.ts.map +1 -1
  157. package/dist/package-target-policy.js +2 -3
  158. package/dist/process-children.d.ts +7 -0
  159. package/dist/process-children.d.ts.map +1 -0
  160. package/dist/process-children.darwin.d.ts +7 -0
  161. package/dist/process-children.darwin.d.ts.map +1 -0
  162. package/dist/process-children.darwin.js +13 -0
  163. package/dist/process-children.js +14 -0
  164. package/dist/process-children.linux.d.ts +8 -0
  165. package/dist/process-children.linux.d.ts.map +1 -0
  166. package/dist/process-children.linux.js +25 -0
  167. package/dist/process-group.d.ts +108 -0
  168. package/dist/process-group.d.ts.map +1 -0
  169. package/dist/process-group.js +171 -0
  170. package/dist/process-listing.d.ts +7 -0
  171. package/dist/process-listing.d.ts.map +1 -0
  172. package/dist/process-listing.js +51 -0
  173. package/dist/producer-receipts.d.ts +8 -2
  174. package/dist/producer-receipts.d.ts.map +1 -1
  175. package/dist/producer-receipts.js +75 -48
  176. package/dist/task-graph-policy.d.ts +21 -0
  177. package/dist/task-graph-policy.d.ts.map +1 -0
  178. package/dist/task-graph-policy.js +91 -0
  179. package/dist/test-timings.js +4 -4
  180. package/dist/test-walk-policy.d.ts +14 -5
  181. package/dist/test-walk-policy.d.ts.map +1 -1
  182. package/dist/test-walk-policy.js +8 -2
  183. package/dist/testing.d.ts +73 -28
  184. package/dist/testing.d.ts.map +1 -1
  185. package/dist/testing.js +217 -223
  186. package/dist/tool-bins.d.ts +33 -0
  187. package/dist/tool-bins.d.ts.map +1 -0
  188. package/dist/tool-bins.js +72 -0
  189. package/dist/typecheck-test-policy.d.ts.map +1 -1
  190. package/dist/typecheck-test-policy.js +3 -4
  191. package/dist/wait-why-policy.d.ts +28 -0
  192. package/dist/wait-why-policy.d.ts.map +1 -0
  193. package/dist/wait-why-policy.js +223 -0
  194. package/dist/workspace-config-policy.d.ts +14 -8
  195. package/dist/workspace-config-policy.d.ts.map +1 -1
  196. package/dist/workspace-config-policy.js +60 -16
  197. package/dist/workspace-manifest.d.ts +41 -6
  198. package/dist/workspace-manifest.d.ts.map +1 -1
  199. package/dist/workspace-manifest.js +57 -0
  200. package/executors.json +16 -1
  201. package/loader.js +2 -0
  202. package/managed/raw/envrc +11 -0
  203. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  204. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  205. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  206. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  207. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  208. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  209. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  210. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  211. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  212. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  213. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  214. package/managed/raw/tooling/direnv/repo-path +68 -6
  215. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  216. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  217. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  218. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  219. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  220. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  221. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  222. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  223. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  224. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  225. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  226. package/package.json +77 -13
  227. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  228. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  229. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  230. package/src/bounded-test-policy.ts +12 -14
  231. package/src/build-state-output-policy.ts +458 -34
  232. package/src/bun-lock-scope.ts +108 -0
  233. package/src/cargo-build-script-env.ts +265 -0
  234. package/src/cargo-closure-input.ts +74 -7
  235. package/src/cargo-retention-hook.ts +94 -0
  236. package/src/cargo-source-hash.ts +138 -41
  237. package/src/cargo-toolchain-paths.ts +95 -0
  238. package/src/cargo-toolchain-policy.ts +49 -5
  239. package/src/cargo-workspace.ts +72 -123
  240. package/src/cross-check-policy.ts +12 -10
  241. package/src/disk-command-policy.ts +1 -0
  242. package/src/ensure-built-receipt.ts +132 -39
  243. package/src/ensure-built-witness.ts +62 -10
  244. package/src/ensure-built.ts +11 -1
  245. package/src/eslint-config-closure.ts +357 -0
  246. package/src/executors/bounded-exec/bounds.ts +76 -0
  247. package/src/executors/bounded-exec/cpu-pool.ts +51 -117
  248. package/src/executors/bounded-exec/executor.ts +423 -259
  249. package/src/executors/bounded-exec/gateway-lease.ts +82 -33
  250. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  251. package/src/executors/bounded-exec/lease-wait.ts +89 -0
  252. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  253. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  254. package/src/executors/bounded-exec/progress.ts +9 -3
  255. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  256. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  257. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  258. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  259. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  260. package/src/executors/bounded-exec/run-cpu-pool.ts +22 -30
  261. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  262. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  263. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  264. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  265. package/src/executors/bounded-exec/schema.json +11 -2
  266. package/src/executors/bounded-exec/schema.ts +19 -1
  267. package/src/executors/bounded-exec/verdict.ts +137 -34
  268. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  269. package/src/executors/clean-outputs/executor.ts +1 -0
  270. package/src/executors/scriptc-native/executor.ts +394 -0
  271. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  272. package/src/executors/scriptc-native/schema.json +60 -0
  273. package/src/executors/scriptc-native/schema.ts +34 -0
  274. package/src/executors/typescript-emit/executor.ts +205 -38
  275. package/src/forbidden-spelling-policy.ts +226 -0
  276. package/src/generators/create-package/generator.ts +7 -7
  277. package/src/graph-input-contract.ts +61 -2
  278. package/src/index.ts +788 -224
  279. package/src/managed-assets.ts +3 -0
  280. package/src/managed-files/files.ts +28 -3
  281. package/src/managed-files/managed-format.ts +1 -0
  282. package/src/nextest-code-bound.ts +1 -0
  283. package/src/nextest-timings.ts +106 -0
  284. package/src/owned-installation.ts +150 -23
  285. package/src/package-target-policy.ts +2 -3
  286. package/src/process-children.darwin.ts +14 -0
  287. package/src/process-children.linux.ts +33 -0
  288. package/src/process-children.ts +22 -0
  289. package/src/process-group.ts +209 -0
  290. package/src/process-listing.ts +54 -0
  291. package/src/producer-receipts.ts +68 -45
  292. package/src/task-graph-policy.ts +98 -0
  293. package/src/test-walk-policy.ts +23 -8
  294. package/src/testing.ts +240 -232
  295. package/src/tool-bins.ts +108 -0
  296. package/src/typecheck-test-policy.ts +2 -3
  297. package/src/wait-why-policy.ts +226 -0
  298. package/src/workspace-config-policy.ts +63 -15
  299. package/src/workspace-manifest.ts +89 -6
  300. package/test-timings.json +122 -98
  301. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  302. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  303. package/dist/bin/smoo-nx-failures.js +0 -3
  304. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  305. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  306. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  307. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  308. package/dist/failure-summary.d.ts +0 -5
  309. package/dist/failure-summary.d.ts.map +0 -1
  310. package/dist/failure-summary.js +0 -118
  311. package/dist/nextest-extraction.d.ts +0 -117
  312. package/dist/nextest-extraction.d.ts.map +0 -1
  313. package/dist/nextest-extraction.js +0 -303
  314. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  315. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  316. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  317. package/src/__tests__/counted-cargo-process.ts +0 -286
  318. package/src/__tests__/counted-cargo.ts +0 -713
  319. package/src/__tests__/directory-change.ts +0 -27
  320. package/src/__tests__/fixture-cargo-home.ts +0 -36
  321. package/src/__tests__/fixture-nx-env.ts +0 -193
  322. package/src/__tests__/owned-installation.ts +0 -13
  323. package/src/__tests__/past-tick.ts +0 -12
  324. package/src/__tests__/progress-clock.ts +0 -43
  325. package/src/__tests__/runtime-input.ts +0 -23
  326. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  327. package/src/bin/smoo-nx-failures.ts +0 -4
  328. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  329. package/src/bounded-test-policy.test.ts +0 -1029
  330. package/src/build-state-output-policy.test.ts +0 -115
  331. package/src/bun-bootstrap.test.ts +0 -102
  332. package/src/bun-file-packages.test.ts +0 -47
  333. package/src/cargo-closure-filesets.test.ts +0 -63
  334. package/src/cargo-closure-input.property.test.ts +0 -50
  335. package/src/cargo-closure-input.test.ts +0 -506
  336. package/src/cargo-closure-key.test.ts +0 -240
  337. package/src/cargo-resolve-cache.test.ts +0 -1181
  338. package/src/cargo-source-hash.test.ts +0 -707
  339. package/src/cargo-workspace.test.ts +0 -615
  340. package/src/cross-check-policy.test.ts +0 -316
  341. package/src/disk-command-policy.test.ts +0 -61
  342. package/src/ensure-built-receipt.test.ts +0 -279
  343. package/src/ensure-built-witness.test.ts +0 -688
  344. package/src/ensure-built.test.ts +0 -1462
  345. package/src/executors/all-verdicts/executor.test.ts +0 -135
  346. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  347. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  348. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  349. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  350. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  351. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  352. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  353. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  354. package/src/executors/bounded-exec/progress.test.ts +0 -139
  355. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  356. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  357. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  358. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  359. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  360. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  361. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  362. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  363. package/src/executors/clean-outputs/executor.test.ts +0 -20
  364. package/src/executors/typescript-emit/executor.test.ts +0 -83
  365. package/src/failure-summary.ts +0 -119
  366. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  367. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  368. package/src/generators/create-package/generator.test.ts +0 -190
  369. package/src/generators/make-public/generator.test.ts +0 -137
  370. package/src/graph-input-contract.test.ts +0 -379
  371. package/src/host-controller-wiring.test.ts +0 -31
  372. package/src/index.test.ts +0 -3321
  373. package/src/linked-snapshots.nx.test.ts +0 -254
  374. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  375. package/src/managed-files/generator.test.ts +0 -243
  376. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  377. package/src/managed-files/json-edit.test.ts +0 -216
  378. package/src/managed-files/managed-content.test.ts +0 -166
  379. package/src/managed-files/managed-format-json.test.ts +0 -308
  380. package/src/managed-files/repo-path.test.ts +0 -172
  381. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  382. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  383. package/src/managed-files/tree-permissions.test.ts +0 -109
  384. package/src/managed-files/tree.test.ts +0 -123
  385. package/src/manifest-hash.test.ts +0 -219
  386. package/src/nextest-code-bound.test.ts +0 -161
  387. package/src/nextest-extraction.test.ts +0 -216
  388. package/src/nextest-extraction.ts +0 -371
  389. package/src/nextest-partitions.test.ts +0 -501
  390. package/src/nx-cache-bound.test.ts +0 -109
  391. package/src/nx-cache-restore-mtime.test.ts +0 -170
  392. package/src/nx-daemon-claim.test.ts +0 -279
  393. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  394. package/src/nx-daemon-idle-policy.test.ts +0 -111
  395. package/src/nx-daemon-ignore-files.test.ts +0 -210
  396. package/src/nx-daemon-root-normalization.test.ts +0 -105
  397. package/src/nx-daemon-start-never.test.ts +0 -292
  398. package/src/nx-daemon-validity.test.ts +0 -1055
  399. package/src/nx-dot-input-policy.test.ts +0 -353
  400. package/src/nx-failure-life-cycles.test.ts +0 -207
  401. package/src/nx-files-archive-racy.test.ts +0 -97
  402. package/src/nx-foreign-workspace-env.test.ts +0 -329
  403. package/src/nx-incomplete-run-summary.test.ts +0 -70
  404. package/src/nx-plugin-load-errors.test.ts +0 -120
  405. package/src/nx-project-graph-errors.test.ts +0 -70
  406. package/src/nx-project-resolution-cache.test.ts +0 -176
  407. package/src/nx-raw-inputs.test.ts +0 -166
  408. package/src/nx-resident-graph-workers.test.ts +0 -112
  409. package/src/nx-run-information.test.ts +0 -118
  410. package/src/nx-skipped-task-exit.test.ts +0 -180
  411. package/src/nx-state-location.test.ts +0 -63
  412. package/src/nx-store-resolution.test.ts +0 -81
  413. package/src/nx-task-graph-cycles.test.ts +0 -148
  414. package/src/nx-task-output-lease.test.ts +0 -550
  415. package/src/nx-use-local.test.ts +0 -105
  416. package/src/owned-installation.test.ts +0 -105
  417. package/src/package-target-policy.test.ts +0 -1014
  418. package/src/producer-receipts.test.ts +0 -285
  419. package/src/release-config-policy.test.ts +0 -311
  420. package/src/runtime-input.test.ts +0 -393
  421. package/src/serial-group-wiring.test.ts +0 -326
  422. package/src/task-history-namespace.test.ts +0 -181
  423. package/src/task-results.test.ts +0 -228
  424. package/src/test-clock-policy.test.ts +0 -338
  425. package/src/test-program.test.ts +0 -303
  426. package/src/test-timings.test.ts +0 -240
  427. package/src/test-walk-policy.test.ts +0 -620
  428. package/src/testing.test.ts +0 -509
  429. package/src/typecheck-test-policy.test.ts +0 -1468
  430. package/src/typescript-resolution.test.ts +0 -76
  431. package/src/version-actions.test.ts +0 -80
  432. package/src/workspace-config-policy.test.ts +0 -737
@@ -1,1819 +0,0 @@
1
- import { afterAll, afterEach, beforeAll, describe, expect, it, jest } from 'bun:test';
2
- import { spawnSync } from 'node:child_process';
3
- import { access, mkdir, mkdtemp, open, readFile, rm, writeFile } from 'node:fs/promises';
4
- import { createServer, type Socket } from 'node:net';
5
- import { tmpdir } from 'node:os';
6
- import { dirname, join } from 'node:path';
7
- import { onProgressClock } from '../../__tests__/progress-clock.js';
8
- import { BOUNDED_TEST_IDLE_TIMEOUT_MS } from '../../bounded-test-policy.js';
9
- import { ownedSocketDirectory } from '../../testing.js';
10
- import { CPU_POOL_ENV, type CpuPool, createCpuPool, type InheritedCpuPool, readInheritedCpuPool } from './cpu-pool.js';
11
- import { CPU_TOKENS_ENV, type CpuBudget, type TokenGrant } from './cpu-tokens.js';
12
- import {
13
- type BoundedExecContext,
14
- type BoundedExecResult,
15
- createProcessTreeKiller,
16
- type ProcessTreeKiller,
17
- resolveCowshedExecutable,
18
- runBoundedExec,
19
- type TempVolume,
20
- } from './executor.js';
21
- import type { HangDiagnostics } from './hang-diagnostics.js';
22
- import { createNoSpaceWatch } from './no-space.js';
23
- import type { RamTempAcquisition, RamTempError, RamTempLease, Result } from './ram-temp.js';
24
- import { readRecord, type TempVolumeSpace, VERDICT_FILE } from './verdict.js';
25
-
26
- const workspaces: string[] = [];
27
- const ownedProcessGroups = new Set<number>();
28
- const originalStdoutWrite = process.stdout.write;
29
- const originalStderrWrite = process.stderr.write;
30
-
31
- /** What the nextest cases declare as `parallelism`, and so what they ask: the suite runs under no inherited ceiling. */
32
- const nextestWant = 8;
33
-
34
- /**
35
- * Every sizing variable a holder exports to its command (specs/cowshed/05_gateway.md, "Sized to the grant", "Cargo reads
36
- * its holder's jobserver"). This suite's own process runs under them when a gate's `bounded-exec` started it, and the
37
- * executor reads them as inherited ceilings and pool beside the ones its cases construct, so the suite clears them
38
- * (specs/cowshed/08_testing.md: fixtures clear every inherited sizing variable before they set their own).
39
- */
40
- const INHERITED_SIZING_ENV = [
41
- CPU_POOL_ENV,
42
- CPU_TOKENS_ENV,
43
- 'NEXTEST_TEST_THREADS',
44
- 'RUST_TEST_THREADS',
45
- 'CARGO_BUILD_JOBS',
46
- 'CARGO_MAKEFLAGS',
47
- 'MAKEFLAGS',
48
- 'MFLAGS',
49
- ] as const;
50
- const inheritedSizing = INHERITED_SIZING_ENV.map((name) => [name, process.env[name]] as const);
51
-
52
- /**
53
- * Prints the budget variables it sees, then what a grandchild sees: a command's environment reaches its descendants,
54
- * so a budget that leaked past its grant shows on both lines.
55
- */
56
- const BUDGET_PROBE = `const { execFileSync } = require('node:child_process');
57
- const read = 'JSON.stringify([process.env.${CPU_POOL_ENV} ?? null, process.env.${CPU_TOKENS_ENV} ?? null])';
58
- console.log(JSON.stringify([process.env.${CPU_POOL_ENV} ?? null, process.env.${CPU_TOKENS_ENV} ?? null]));
59
- console.log(execFileSync('node', ['-p', read]).toString().trim());
60
- `;
61
-
62
- describe('@smoothbricks/nx-plugin:bounded-exec', () => {
63
- beforeAll(() => {
64
- for (const name of INHERITED_SIZING_ENV) {
65
- delete process.env[name];
66
- }
67
- });
68
-
69
- afterAll(() => {
70
- for (const [name, value] of inheritedSizing) {
71
- if (value === undefined) delete process.env[name];
72
- else process.env[name] = value;
73
- }
74
- });
75
-
76
- afterEach(async () => {
77
- process.stdout.write = originalStdoutWrite;
78
- process.stderr.write = originalStderrWrite;
79
- for (const pid of ownedProcessGroups) {
80
- try {
81
- process.kill(-pid, 'SIGKILL');
82
- } catch (cause) {
83
- const code = cause instanceof Error && 'code' in cause ? cause.code : undefined;
84
- if (code !== 'ESRCH') {
85
- throw new Error(`cleanup owned readiness process group pgid=${pid} failed`, { cause });
86
- }
87
- } finally {
88
- ownedProcessGroups.delete(pid);
89
- }
90
- }
91
- await Promise.all(workspaces.splice(0).map((workspace) => rm(workspace, { recursive: true, force: true })));
92
- });
93
-
94
- it('runs a successful shell command with cwd and env', async () => {
95
- const workspace = await createWorkspace();
96
- await workspace.write(
97
- 'package/print.js',
98
- 'console.log(process.cwd()); console.log(process.env.BOUNDED_EXEC_VALUE);\n',
99
- );
100
-
101
- // bounded-exec requires a ceiling; at the leg's backstop it cannot end a run whose `node` is slow to start
102
- // under load.
103
- const result = await runBoundedExec(
104
- {
105
- command: 'node print.js',
106
- cwd: 'package',
107
- env: { BOUNDED_EXEC_VALUE: 'from-env' },
108
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
109
- },
110
- workspace.context,
111
- createProcessTreeKiller(),
112
- null,
113
- null,
114
- );
115
-
116
- expect(result.success).toBe(true);
117
- expect(result.terminalOutput).toContain(join(workspace.root, 'package'));
118
- expect(result.terminalOutput).toContain('from-env');
119
- });
120
-
121
- it('returns failure for a nonzero command', async () => {
122
- const workspace = await createWorkspace();
123
-
124
- const result = await runBoundedExec(
125
- { command: 'node -e "process.exit(7)"', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
126
- workspace.context,
127
- createProcessTreeKiller(),
128
- null,
129
- null,
130
- );
131
-
132
- expect(result.success).toBe(false);
133
- expect(result.terminalOutput).toContain('Command exited with status 7');
134
- });
135
-
136
- it('streams stdout and stderr while collecting terminal output', async () => {
137
- const workspace = await createWorkspace();
138
- const stdout: string[] = [];
139
- const stderr: string[] = [];
140
- process.stdout.write = captureWrite(stdout);
141
- process.stderr.write = captureWrite(stderr);
142
-
143
- const result = await runBoundedExec(
144
- {
145
- command: "node -e \"console.log('out-value'); console.error('err-value')\"",
146
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
147
- },
148
- workspace.context,
149
- createProcessTreeKiller(),
150
- null,
151
- null,
152
- );
153
-
154
- expect(result.success).toBe(true);
155
- expect(stdout.join('')).toContain('out-value');
156
- expect(stderr.join('')).toContain('err-value');
157
- expect(result.terminalOutput).toContain('out-value');
158
- expect(result.terminalOutput).toContain('err-value');
159
- });
160
-
161
- it('fails on timeout and reports bounded execution details', async () => {
162
- const workspace = await createWorkspace();
163
-
164
- // The command never exits, so only the ceiling under test can end it.
165
- const result = await runBoundedExec(
166
- { command: 'node -e "process.stdin.resume()"', timeoutMs: 50, killAfterMs: 0 },
167
- workspace.context,
168
- createProcessTreeKiller(),
169
- null,
170
- null,
171
- );
172
-
173
- expect(result.success).toBe(false);
174
- expect(result.terminalOutput).toContain('Command timed out after');
175
- expect(result.terminalOutput).toContain('timeoutMs=50');
176
- expect(result.terminalOutput).toContain(`cwd=${workspace.root}`);
177
- });
178
-
179
- it('kills a silent command on the progress bound, with no ceiling at all', async () => {
180
- const workspace = await createWorkspace();
181
-
182
- // The command never exits and never speaks, so only the progress bound under test can end it.
183
- const result = await runBoundedExec(
184
- { command: 'node -e "process.stdin.resume()"', idleTimeoutMs: 100, killAfterMs: 0 },
185
- workspace.context,
186
- createProcessTreeKiller(),
187
- null,
188
- null,
189
- );
190
-
191
- expect(result.success).toBe(false);
192
- expect(result.terminalOutput).toContain('Command made no progress: no test finished for 100ms');
193
- expect(result.terminalOutput).toContain('idleTimeoutMs=100');
194
- expect(result.terminalOutput).toContain('the runner named no test still running');
195
- // The bound that fired is named, so a hang is never reported as a slow run.
196
- expect(result.terminalOutput).not.toContain('Command timed out after');
197
- });
198
-
199
- it('kills a runner that keeps warning of a slow test but finishes none, and names the test', async () => {
200
- const workspace = await createWorkspace();
201
- // nextest's own lines: one test finishes, then the other only ever says SLOW, every 50ms.
202
- await workspace.write(
203
- 'slow-runner.js',
204
- [
205
- "console.error(' PASS [ 0.010s] (1/2) fake tests::quick');",
206
- 'let periods = 0;',
207
- "setInterval(() => console.error(' SLOW [> ' + ++periods * 0.05 + 's] (───) fake tests::hangs'), 50);",
208
- '',
209
- ].join('\n'),
210
- );
211
-
212
- // The window ends only once the runner has said SLOW, however long node takes to start.
213
- const { result } = await onProgressClock(
214
- (chunk) => chunk.includes('SLOW [>'),
215
- 400,
216
- () =>
217
- runBoundedExec(
218
- { command: 'node slow-runner.js', idleTimeoutMs: 400, killAfterMs: 0 },
219
- workspace.context,
220
- createProcessTreeKiller(),
221
- null,
222
- null,
223
- ),
224
- );
225
-
226
- expect(result.success).toBe(false);
227
- expect(result.terminalOutput).toContain('SLOW [>');
228
- expect(result.terminalOutput).toContain('Command made no progress: no test finished for 400ms (idleTimeoutMs=400)');
229
- expect(result.terminalOutput).toContain('still running: fake tests::hangs (cwd=');
230
- expect(result.terminalOutput).not.toContain('fake tests::quick (cwd=');
231
- });
232
-
233
- it("stops the idle clock while a descendant's work is queued for host CPU tokens, and runs it on after", async () => {
234
- const workspace = await createWorkspace();
235
- // The runner finishes a test, then says through its pool that work it started is queued for host tokens, ends that
236
- // wait and goes silent. While the wait is held the clock moves well past the bound and nothing fires; once the wait
237
- // ends the same move ends the run.
238
- await workspace.write(
239
- 'queued-runner.js',
240
- [
241
- "const { connect } = require('node:net');",
242
- "console.error(' PASS [ 0.010s] (1/2) fake tests::quick');",
243
- `const socket = connect(process.env.${CPU_POOL_ENV});`,
244
- `socket.on('connect', () => socket.write('{"op":"host-wait"}\\n'));`,
245
- "socket.once('data', (reply) => { console.log('host wait ' + reply.toString().trim()); socket.end(); });",
246
- "socket.on('close', () => setInterval(() => {}, 60_000));",
247
- '',
248
- ].join('\n'),
249
- );
250
- const budget: CpuBudget = {
251
- async take() {
252
- return heldGrant(1, []);
253
- },
254
- };
255
-
256
- const { result } = await onProgressClock(
257
- (chunk) => chunk.includes('bounded-exec: idle clock'),
258
- 1_000,
259
- () =>
260
- runBoundedExec(
261
- { command: 'node queued-runner.js', idleTimeoutMs: 400, killAfterMs: 0 },
262
- workspace.context,
263
- createProcessTreeKiller(),
264
- null,
265
- budget,
266
- ),
267
- );
268
-
269
- const output = result.terminalOutput;
270
- expect(result.success).toBe(false);
271
- expect(output).toContain('host wait {"ok":true,"wait":"held"}');
272
- const stopped = output.indexOf(
273
- "bounded-exec: idle clock stopped: a descendant's work is queued for host CPU tokens",
274
- );
275
- const restarted = output.indexOf('bounded-exec: idle clock restarted');
276
- const expired = output.indexOf('Command made no progress: no test finished for 400ms (idleTimeoutMs=400)');
277
- // The 1000 ms move while the wait was held fired nothing; the one after it ended the run.
278
- expect(stopped).toBeGreaterThan(-1);
279
- expect(restarted).toBeGreaterThan(stopped);
280
- expect(expired).toBeGreaterThan(restarted);
281
- });
282
-
283
- it('emits a completed pre-expiry snapshot or an explicit incomplete capture without waiting for it', async () => {
284
- const workspace = await createWorkspace();
285
- // Child output drives the fake executor clock; the heartbeat period is not a timing oracle.
286
- await workspace.write('snapshot-clock.js', "setInterval(() => console.log('snapshot-clock'), 20);\n");
287
- for (const completes of [true, false]) {
288
- let pid: number | undefined;
289
- let signal: AbortSignal | undefined;
290
- const { result } = await onProgressClock(
291
- (chunk) => chunk.includes('snapshot-clock\n'),
292
- 5_000,
293
- () =>
294
- runBoundedExec(
295
- { command: 'node snapshot-clock.js', idleTimeoutMs: 10_000, killAfterMs: 0 },
296
- workspace.context,
297
- createProcessTreeKiller(),
298
- null,
299
- null,
300
- null,
301
- async (request) => {
302
- pid = request.pid;
303
- signal = request.signal;
304
- if (!completes) return new Promise<HangDiagnostics>(() => {});
305
- const capturedAtMs = Date.now();
306
- return {
307
- startedAtMs: capturedAtMs,
308
- capturedAtMs,
309
- offsetFromExpiryMs: request.expiresAtMs - capturedAtMs,
310
- outcome: 'holders',
311
- text: 'owned pre-signal process observation\n',
312
- };
313
- },
314
- ),
315
- );
316
- expect(result.success).toBe(false);
317
- expect(pid).toBeGreaterThan(0);
318
- expect(signal?.aborted).toBe(true);
319
- expect(result.terminalOutput).toContain(`Hang diagnostics: runner pid=${pid}`);
320
- if (completes) {
321
- expect(result.terminalOutput).toContain('outcome=holders capturedAtMs=');
322
- expect(result.terminalOutput).toContain('actualExpiryOffsetMs=5000');
323
- expect(result.terminalOutput).toContain('owned pre-signal process observation');
324
- } else {
325
- expect(result.terminalOutput).toContain('capture incomplete at expiry');
326
- expect(result.terminalOutput).toContain('no empty-holder conclusion');
327
- }
328
- }
329
- });
330
-
331
- it('discards the previous snapshot when a test finishes and captures the next idle interval', async () => {
332
- const workspace = await createWorkspace();
333
- const socketRoot = await ownedSocketDirectory('snapshot-progress-', 'control.sock');
334
- workspaces.push(socketRoot);
335
- const endpoint = join(socketRoot, 'control.sock');
336
- const connected = Promise.withResolvers<Socket>();
337
- const publicationHeld = Promise.withResolvers<void>();
338
- const sockets = new Set<Socket>();
339
- const server = createServer((socket) => {
340
- sockets.add(socket);
341
- socket.once('close', () => sockets.delete(socket));
342
- connected.resolve(socket);
343
- });
344
- await workspace.write(
345
- 'snapshot-progress.js',
346
- [
347
- "const { connect } = require('node:net');",
348
- "const { createInterface } = require('node:readline');",
349
- `const socket = connect(${JSON.stringify(endpoint)}, () => console.log('snapshot-clock\\nsnapshot-stage:initial'));`,
350
- "socket.on('error', error => { throw error; });",
351
- "createInterface({ input: socket }).on('line', command => {",
352
- " if (command === 'hold') console.log('snapshot-clock\\nsnapshot-stage:held');",
353
- " else if (command === 'progress') console.log(' PASS [ 0.010s] (1/1) fake tests::progress\\nsnapshot-clock\\nsnapshot-stage:progress');",
354
- " else if (command === 'expire') console.log('snapshot-clock\\nsnapshot-stage:captured');",
355
- " else throw new Error('unexpected snapshot command: ' + command);",
356
- '});',
357
- '',
358
- ].join('\n'),
359
- );
360
- await new Promise<void>((resolve, reject) => {
361
- server.once('error', reject);
362
- server.listen(endpoint, resolve);
363
- });
364
- const signals: Array<AbortSignal | undefined> = [];
365
- let partial = '';
366
- try {
367
- const { result, movedMs } = await onProgressClock(
368
- (chunk) => {
369
- const lines = (partial + chunk).split('\n');
370
- partial = lines.pop() ?? '';
371
- let move = false;
372
- for (const line of lines) {
373
- if (line === 'snapshot-stage:held') publicationHeld.resolve();
374
- if (
375
- line === 'snapshot-stage:initial' ||
376
- line === 'snapshot-stage:progress' ||
377
- line === 'snapshot-stage:captured'
378
- )
379
- move = true;
380
- }
381
- return move;
382
- },
383
- 5_000,
384
- () =>
385
- runBoundedExec(
386
- { command: 'node snapshot-progress.js', idleTimeoutMs: 10_000, killAfterMs: 0 },
387
- workspace.context,
388
- createProcessTreeKiller(),
389
- null,
390
- null,
391
- null,
392
- async (request) => {
393
- signals.push(request.signal);
394
- const ordinal = signals.length;
395
- const socket = await connected.promise;
396
- if (ordinal === 1) {
397
- // Deliberately deliver another heartbeat while publication is held. It cannot
398
- // spend the next interval: only the observed PASS releases that clock step.
399
- socket.write('hold\n');
400
- await publicationHeld.promise;
401
- socket.write('progress\n');
402
- } else {
403
- socket.write('expire\n');
404
- }
405
- const capturedAtMs = Date.now();
406
- return {
407
- startedAtMs: capturedAtMs,
408
- capturedAtMs,
409
- offsetFromExpiryMs: request.expiresAtMs - capturedAtMs,
410
- outcome: 'holders',
411
- text: `capture-interval-${ordinal}\n`,
412
- };
413
- },
414
- ),
415
- );
416
- expect(result.success).toBe(false);
417
- expect(signals).toHaveLength(2);
418
- expect(signals.every((signal) => signal?.aborted)).toBe(true);
419
- expect(result.terminalOutput).not.toContain('capture-interval-1');
420
- expect(result.terminalOutput).toContain('capture-interval-2');
421
- expect(result.terminalOutput).toContain('snapshot-stage:held');
422
- expect(movedMs).toBe(15_000);
423
- } finally {
424
- publicationHeld.resolve();
425
- for (const socket of sockets) socket.destroy();
426
- await new Promise<void>((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
427
- }
428
- });
429
-
430
- it('kills a command whose only output is a heartbeat', async () => {
431
- const workspace = await createWorkspace();
432
- await workspace.write('heartbeat.js', ["setInterval(() => console.log('still waiting...'), 20);", ''].join('\n'));
433
-
434
- const { result } = await onProgressClock(
435
- (chunk) => chunk.includes('still waiting...'),
436
- 300,
437
- () =>
438
- runBoundedExec(
439
- { command: 'node heartbeat.js', idleTimeoutMs: 300, killAfterMs: 0 },
440
- workspace.context,
441
- createProcessTreeKiller(),
442
- null,
443
- null,
444
- ),
445
- );
446
-
447
- expect(result.success).toBe(false);
448
- expect(result.terminalOutput).toContain('still waiting...');
449
- expect(result.terminalOutput).toContain('Command made no progress: no test finished for 300ms');
450
- });
451
-
452
- it('lets a run that keeps finishing tests outlive its progress bound', async () => {
453
- const workspace = await createWorkspace();
454
- // Ten tests under a 400ms progress bound and no ceiling, the clock moving 300ms at each: the run outlives the
455
- // bound, so passing proves the bound measures the gap between finished tests, not duration.
456
- await workspace.write(
457
- 'progressing.js',
458
- [
459
- 'let done = 0;',
460
- 'const timer = setInterval(() => {',
461
- ' done += 1;',
462
- " console.error(' PASS [ 0.120s] (' + done + '/10) fake tests::t' + done);",
463
- ' if (done === 10) clearInterval(timer);',
464
- '}, 120);',
465
- '',
466
- ].join('\n'),
467
- );
468
-
469
- const { result, movedMs } = await onProgressClock(
470
- (chunk) => chunk.includes('PASS ['),
471
- 300,
472
- () =>
473
- runBoundedExec(
474
- { command: 'node progressing.js', idleTimeoutMs: 400 },
475
- workspace.context,
476
- createProcessTreeKiller(),
477
- null,
478
- null,
479
- ),
480
- );
481
-
482
- expect(result.success).toBe(true);
483
- expect(result.terminalOutput).toContain('(10/10) fake tests::t10');
484
- expect(result.terminalOutput).not.toContain('made no progress');
485
- expect(movedMs).toBeGreaterThan(400);
486
- });
487
-
488
- it("counts bun's dots on stderr as finished tests", async () => {
489
- const workspace = await createWorkspace();
490
- // bun --dots writes one dot per finished test and no newline until another stream writes.
491
- await workspace.write(
492
- 'dots.js',
493
- [
494
- 'let done = 0;',
495
- 'const timer = setInterval(() => {',
496
- " process.stderr.write('.');",
497
- ' if (++done === 8) { clearInterval(timer); process.stderr.write("\\n"); }',
498
- '}, 120);',
499
- '',
500
- ].join('\n'),
501
- );
502
-
503
- const { result } = await onProgressClock(
504
- (chunk) => /^\.+$/.test(chunk),
505
- 300,
506
- () =>
507
- runBoundedExec(
508
- { command: 'node dots.js', idleTimeoutMs: 400 },
509
- workspace.context,
510
- createProcessTreeKiller(),
511
- null,
512
- null,
513
- ),
514
- );
515
-
516
- expect(result.success).toBe(true);
517
- expect(result.terminalOutput).toContain('........');
518
- });
519
-
520
- it('applies the absolute ceiling to a command that keeps talking forever', async () => {
521
- const workspace = await createWorkspace();
522
- await workspace.write('runaway.js', ["setInterval(() => console.log('still here'), 10);", ''].join('\n'));
523
-
524
- const result = await runBoundedExec(
525
- { command: 'node runaway.js', timeoutMs: 300, idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, killAfterMs: 0 },
526
- workspace.context,
527
- createProcessTreeKiller(),
528
- null,
529
- null,
530
- );
531
-
532
- expect(result.success).toBe(false);
533
- expect(result.terminalOutput).toContain('Command timed out after');
534
- expect(result.terminalOutput).toContain('timeoutMs=300');
535
- expect(result.terminalOutput).not.toContain('made no progress');
536
- });
537
-
538
- it('imposes no progress bound when idleTimeoutMs is omitted', async () => {
539
- const workspace = await createWorkspace();
540
- const go = join(workspace.root, 'go.fifo');
541
- expect(spawnSync('mkfifo', [go]).status).toBe(0);
542
- // Says `started`, then goes silent until the test writes `go.fifo`.
543
- await workspace.write(
544
- 'silent.js',
545
- [
546
- "const fs = require('node:fs');",
547
- "console.log('started');",
548
- "fs.readFileSync('go.fifo');",
549
- "console.log('late');",
550
- '',
551
- ].join('\n'),
552
- );
553
- const { promise: started, resolve: sawStarted } = Promise.withResolvers<void>();
554
- process.stdout.write = captureWrite([], (text) => {
555
- if (text.includes('started')) sawStarted();
556
- });
557
- // Every bound is armed as the command spawns, before it can say `started`. The clock then moves to just short of
558
- // the ceiling while the command is silent: any progress bound would have fired there, and the ceiling has not.
559
- // Only then is the command released, so the run ends by its own exit.
560
- jest.useFakeTimers();
561
- let result: BoundedExecResult;
562
- try {
563
- const run = runBoundedExec(
564
- { command: 'node silent.js', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
565
- workspace.context,
566
- createProcessTreeKiller(),
567
- null,
568
- null,
569
- );
570
- await started;
571
- jest.advanceTimersByTime(BOUNDED_TEST_IDLE_TIMEOUT_MS - 1);
572
- await writeFile(go, 'go\n');
573
- result = await run;
574
- } finally {
575
- jest.useRealTimers();
576
- }
577
-
578
- expect(result.success).toBe(true);
579
- expect(result.terminalOutput).toContain('late');
580
- expect(result.terminalOutput).not.toContain('made no progress');
581
- });
582
-
583
- it('uses graceful timeout termination before force-killing on POSIX', async () => {
584
- if (process.platform === 'win32') {
585
- return;
586
- }
587
-
588
- const workspace = await createWorkspace();
589
- const ready = join(workspace.root, 'cooperative-ready.fifo');
590
- const handled = join(workspace.root, 'handled.txt');
591
- expect(spawnSync('mkfifo', [ready]).status).toBe(0);
592
- await workspace.write(
593
- 'cooperative.js',
594
- [
595
- "const fs = require('node:fs');",
596
- "process.on('SIGTERM', () => {",
597
- " fs.writeFileSync('handled.txt', 'handled pid=' + process.pid + '\\n');",
598
- ' process.exit(0);',
599
- '});',
600
- "fs.writeFileSync('cooperative-ready.fifo', 'ready pid=' + process.pid + '\\n');",
601
- 'process.stdin.resume();',
602
- '',
603
- ].join('\n'),
604
- );
605
- let handlerPid: number | undefined;
606
- const termination = armedKiller('cooperative SIGTERM handler', async (pid) => {
607
- handlerPid = await armedPid(ready, pid, 'cooperative SIGTERM handler');
608
- expect(handlerPid, `handler readiness must name the command leader pid=${pid}`).toBe(pid);
609
- });
610
-
611
- // The ceiling is the subject; the grace after the graceful signal is the leg's backstop, so the command ends by its
612
- // handler alone however slowly a loaded host runs it.
613
- const result = await runBoundedExec(
614
- { command: 'exec node cooperative.js', timeoutMs: 50, killAfterMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
615
- workspace.context,
616
- termination.killer,
617
- null,
618
- null,
619
- );
620
-
621
- await termination.armed();
622
- // This fixture has no descendants; runBoundedExec has observed its leader's exit.
623
- termination.release();
624
- expect(result.success).toBe(false);
625
- expect(await readFile(handled, 'utf8'), `cooperative handler pid=${handlerPid} must handle SIGTERM`).toBe(
626
- `handled pid=${handlerPid}\n`,
627
- );
628
- expect(termination.calls).toEqual(['SIGTERM']);
629
- });
630
-
631
- it('force-kills after killAfterMs when graceful termination is ignored on POSIX', async () => {
632
- if (process.platform === 'win32') {
633
- return;
634
- }
635
-
636
- const workspace = await createWorkspace();
637
- const ignoring = ignoresTerm(workspace.root);
638
- const calls: string[] = [];
639
- const killer: ProcessTreeKiller = {
640
- async kill(pid, signal) {
641
- if (signal === 'SIGTERM') await ignoring.armed();
642
- calls.push(signal);
643
- process.kill(-pid, signal);
644
- },
645
- };
646
-
647
- const result = await runBoundedExec(
648
- {
649
- command: ignoring.command,
650
- timeoutMs: 50,
651
- killAfterMs: 50,
652
- },
653
- workspace.context,
654
- killer,
655
- null,
656
- null,
657
- );
658
-
659
- expect(result.success).toBe(false);
660
- expect(calls).toEqual(['SIGTERM', 'SIGKILL']);
661
- });
662
-
663
- it('returns after force-kill even when the process tree ignores SIGKILL', async () => {
664
- // Real clock: this is the platform kill/reap path. Fake timers cannot
665
- // drive child_process exit or SIGKILL delivery.
666
- if (process.platform === 'win32') {
667
- return;
668
- }
669
- const workspace = await createWorkspace();
670
- let leaked: number | undefined;
671
- const killer: ProcessTreeKiller = {
672
- async kill(pid) {
673
- leaked = pid;
674
- },
675
- };
676
- const result = await runBoundedExec(
677
- { command: 'node -e "process.stdin.resume()"', timeoutMs: 50, killAfterMs: 10 },
678
- workspace.context,
679
- killer,
680
- null,
681
- null,
682
- );
683
- // The command never exits and the killer delivers nothing, so the run returned by giving up on the tree after its
684
- // force-kill, not by the command ending: the command is still alive here.
685
- if (leaked === undefined) throw new Error('the killer was never asked to kill the command');
686
- const pid = leaked;
687
- expect(() => process.kill(pid, 0)).not.toThrow();
688
- expect(result.success).toBe(false);
689
- expect(result.terminalOutput).toContain('Force-killing timed out command');
690
- if (leaked !== undefined) {
691
- try {
692
- process.kill(-leaked, 'SIGKILL');
693
- } catch {
694
- // Already gone.
695
- }
696
- try {
697
- process.kill(leaked, 'SIGKILL');
698
- } catch {
699
- // Already gone.
700
- }
701
- }
702
- });
703
-
704
- it('forwards args by default and can suppress unparsed args', async () => {
705
- const workspace = await createWorkspace();
706
-
707
- const forwarded = await runBoundedExec(
708
- {
709
- command: 'node -e "console.log(process.argv.slice(1).join(\',\'))"',
710
- args: ['first'],
711
- __unparsed__: ['second'],
712
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
713
- },
714
- workspace.context,
715
- createProcessTreeKiller(),
716
- null,
717
- null,
718
- );
719
- const suppressed = await runBoundedExec(
720
- {
721
- command: 'node -e "console.log(process.argv.slice(1).join(\',\'))"',
722
- args: ['first'],
723
- __unparsed__: ['second'],
724
- forwardAllArgs: false,
725
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
726
- },
727
- workspace.context,
728
- createProcessTreeKiller(),
729
- null,
730
- null,
731
- );
732
-
733
- expect(forwarded.success).toBe(true);
734
- expect(forwarded.terminalOutput).toContain('first,second');
735
- expect(suppressed.success).toBe(true);
736
- expect(suppressed.terminalOutput).toContain('first');
737
- expect(suppressed.terminalOutput).not.toContain('second');
738
- });
739
-
740
- it('kills a POSIX child process group on timeout', async () => {
741
- if (process.platform === 'win32') {
742
- return;
743
- }
744
-
745
- const workspace = await createWorkspace();
746
- const ready = join(workspace.root, 'descendant-ready.fifo');
747
- const lifetime = join(workspace.root, 'descendant-lifetime.fifo');
748
- expect(spawnSync('mkfifo', [ready, lifetime]).status).toBe(0);
749
- await workspace.write(
750
- 'group-child.js',
751
- [
752
- "const fs = require('node:fs');",
753
- "fs.openSync('descendant-lifetime.fifo', 'w');",
754
- "fs.writeFileSync('descendant-ready.fifo', 'ready pid=' + process.pid + '\\n');",
755
- // Its stdin is /dev/null, so it holds itself: a wait no event ever ends, until a signal does.
756
- 'Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0);',
757
- '',
758
- ].join('\n'),
759
- );
760
- await workspace.write(
761
- 'spawn-child.js',
762
- [
763
- "import { spawn } from 'node:child_process';",
764
- "spawn(process.execPath, ['group-child.js'], { stdio: 'ignore' });",
765
- 'process.stdin.resume();',
766
- '',
767
- ].join('\n'),
768
- );
769
- // Only the descendant owns the writer and it never exits on its own: EOF observes its kill, not a time horizon.
770
- const closed = readToEnd(lifetime);
771
- let descendantPid: number | undefined;
772
- const termination = armedKiller('process-group descendant', async (pid) => {
773
- descendantPid = await armedPid(ready, pid, 'process-group descendant');
774
- expect(descendantPid, `ready descendant must differ from group leader pid=${pid}`).not.toBe(pid);
775
- });
776
-
777
- const result = await runBoundedExec(
778
- { command: 'exec node spawn-child.js', timeoutMs: 50, killAfterMs: 50 },
779
- workspace.context,
780
- termination.killer,
781
- null,
782
- null,
783
- );
784
-
785
- await termination.armed();
786
- const descendantOutput = await closed;
787
- termination.release();
788
- expect(descendantOutput, `ready descendant pid=${descendantPid} must close its lifetime FIFO on exit`).toBe('');
789
- expect(result.success).toBe(false);
790
- });
791
-
792
- it('force-kills what outlives a timed-out command in its process group', async () => {
793
- if (process.platform === 'win32') {
794
- return;
795
- }
796
-
797
- const workspace = await createWorkspace();
798
- const fifo = join(workspace.root, 'straggler.fifo');
799
- const ready = join(workspace.root, 'straggler-ready.fifo');
800
- expect(spawnSync('mkfifo', [fifo, ready]).status).toBe(0);
801
- // The leader exits on SIGTERM. The subshell beside it ignores SIGTERM, a disposition its
802
- // `tail` inherits, and announces itself only once that disposition is installed. Every
803
- // script descendant inherits the lifetime FIFO, so EOF proves all of them ended, not
804
- // just the ignoring child. A fork during signal delivery inherits that witness too.
805
- await workspace.write(
806
- 'straggle.sh',
807
- [
808
- 'exec 3>"$1"',
809
- '( trap "" TERM; echo ready; echo armed >"$2"; exec tail -f /dev/null ) | {',
810
- ' read -r line; echo "$line"; exec tail -f /dev/null',
811
- '}',
812
- '',
813
- ].join('\n'),
814
- );
815
- // All script descendants own a writer; the read ends only when the last one exits.
816
- const straggler = readToEnd(fifo);
817
- const termination = armedKiller('TERM-ignoring FIFO straggler', async (pid) => {
818
- expect(await readToEnd(ready), `straggler readiness pgid=${pid} must follow trap and FIFO open`).toBe('armed\n');
819
- });
820
-
821
- const result = await runBoundedExec(
822
- { command: `sh straggle.sh ${fifo} ${ready}`, timeoutMs: 5_000, killAfterMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
823
- workspace.context,
824
- termination.killer,
825
- null,
826
- null,
827
- );
828
-
829
- await termination.armed();
830
- const stragglerOutput = await straggler;
831
- termination.release();
832
- expect(result.terminalOutput).toContain('ready');
833
- expect(stragglerOutput).toBe('');
834
- expect(result.success).toBe(false);
835
- expect(result.terminalOutput).toContain('Force-killing what the timed-out command left in its process group');
836
- expect(
837
- [...ownedProcessGroups],
838
- 'leader exit and straggler FIFO EOF retire cleanup authority; afterEach must not signal their stale PGID',
839
- ).toEqual([]);
840
- });
841
-
842
- it('runs the command with its RAM lease as TMPDIR, names held dead leases, and ends the lease after it exits', async () => {
843
- const workspace = await createWorkspace();
844
- const directory = join(workspace.root, 'lease');
845
- await mkdir(directory);
846
- const held = '/v/9-abcdef is kept: /v/9-abcdef/x.asif (/dev/disk9) still attached from below it';
847
- const volume = scriptedVolume({
848
- ok: true,
849
- value: { kind: 'leased', lease: leaseAt(directory), held: [held], reaped: [] },
850
- });
851
-
852
- const result = await runBoundedExec(
853
- { command: 'node -e "console.log(process.env.TMPDIR)"', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
854
- workspace.context,
855
- createProcessTreeKiller(),
856
- volume,
857
- null,
858
- );
859
-
860
- expect(result.success).toBe(true);
861
- expect(result.terminalOutput).toContain(directory);
862
- expect(result.terminalOutput).toContain(`RAM temp volume: dead lease ${held}\n`);
863
- expect(volume.released).toEqual([directory]);
864
- });
865
-
866
- it('stops what the command left working in its lease before the lease ends, and says so', async () => {
867
- const workspace = await createWorkspace();
868
- const directory = join(workspace.root, 'lease');
869
- await mkdir(directory);
870
- const volume = scriptedVolume(
871
- {
872
- ok: true,
873
- value: { kind: 'leased', lease: leaseAt(directory), held: [], reaped: ['4242 (nx daemon of a dead task)'] },
874
- },
875
- null,
876
- ['31337 (bun nx daemon --start)'],
877
- );
878
-
879
- const result = await runBoundedExec(
880
- { command: 'node -e "0"', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
881
- workspace.context,
882
- createProcessTreeKiller(),
883
- volume,
884
- null,
885
- );
886
-
887
- expect(result.success).toBe(true);
888
- expect(result.terminalOutput).toContain(
889
- 'RAM temp volume: stopped 31337 (bun nx daemon --start), which the command left working in its lease\n',
890
- );
891
- expect(result.terminalOutput).toContain(
892
- 'RAM temp volume: stopped 4242 (nx daemon of a dead task), which a dead task left working in its lease\n',
893
- );
894
- expect(volume.order).toEqual([`reap ${directory}`, `release ${directory}`]);
895
- });
896
-
897
- it('keeps the inherited TMPDIR inside a sandbox and says so once', async () => {
898
- const workspace = await createWorkspace();
899
- const volume = scriptedVolume({ ok: true, value: { kind: 'sandboxed', detail: 'lock: EPERM' } });
900
-
901
- const result = await runBoundedExec(
902
- {
903
- command: `node -e 'console.log("tmp=" + process.env.TMPDIR)'`,
904
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
905
- env: { TMPDIR: '/shed/tmp' },
906
- },
907
- workspace.context,
908
- createProcessTreeKiller(),
909
- volume,
910
- null,
911
- );
912
-
913
- expect(result.success).toBe(true);
914
- expect(result.terminalOutput).toContain('tmp=/shed/tmp');
915
- expect(result.terminalOutput.match(/RAM temp volume unavailable in this sandbox \(lock: EPERM\)/g)).toHaveLength(1);
916
- expect(volume.released).toEqual([]);
917
- });
918
-
919
- it('does not run the command when the volume cannot be provisioned', async () => {
920
- const workspace = await createWorkspace();
921
- const marker = join(workspace.root, 'ran');
922
- const volume = scriptedVolume({
923
- ok: false,
924
- error: { kind: 'provision-failed', step: 'hdiutil attach', detail: 'exit 1: Device not configured' },
925
- });
926
-
927
- const result = await runBoundedExec(
928
- { command: `touch ${marker}`, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
929
- workspace.context,
930
- createProcessTreeKiller(),
931
- volume,
932
- null,
933
- );
934
-
935
- expect(result.success).toBe(false);
936
- expect(result.terminalOutput).toBe('RAM temp volume: hdiutil attach failed: exit 1: Device not configured\n');
937
- expect(await exists(marker)).toBe(false);
938
- });
939
-
940
- it('names the full volume when a failed command left it without space', async () => {
941
- const workspace = await createWorkspace();
942
- const directory = join(workspace.root, 'lease');
943
- await mkdir(directory);
944
- const volume = scriptedVolume(
945
- { ok: true, value: { kind: 'leased', lease: leaseAt(directory), held: [], reaped: [] } },
946
- { kind: 'volume-full', mountpoint: workspace.root, capacityBytes: 1024 * 1024 * 1024, freeBytes: 1024 * 1024 },
947
- );
948
-
949
- const result = await runBoundedExec(
950
- { command: 'node -e "process.exit(1)"', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
951
- workspace.context,
952
- createProcessTreeKiller(),
953
- volume,
954
- null,
955
- );
956
-
957
- expect(result.success).toBe(false);
958
- expect(result.terminalOutput).toContain(`RAM temp volume ${workspace.root} is full: 1 MiB free of 1024 MiB`);
959
- expect(volume.released).toEqual([directory]);
960
- });
961
-
962
- it('names ENOSPC, its writer and the volume as it stood when the output said so, not after the command exited', async () => {
963
- // From a downstream land gate: a compiler test shard printed ENOSPC for a 1 KB write into its lease and failed two.
964
- // By its exit the volume had space again (`fullness` answers null here), so a probe after exit named nothing and
965
- // the run read as two failed tests.
966
- const workspace = await createWorkspace();
967
- const directory = join(workspace.root, 'lease');
968
- await mkdir(directory);
969
- const lease = leaseAt(directory);
970
- const space = { lease: directory, mountpoint: workspace.root, capacityBytes: lease.capacityBytes, freeBytes: 4096 };
971
- const volume = scriptedVolume(
972
- { ok: true, value: { kind: 'leased', lease, held: [], reaped: [] } },
973
- null,
974
- [],
975
- space,
976
- );
977
- const record = { task: { id: 'compiler:test-10', hash: 'h' }, directory: join(workspace.root, 'record') };
978
- const line = 'ENOSPC: no space left on device, write';
979
-
980
- const result = await runBoundedExec(
981
- { command: `node -e "console.error('${line}'); process.exit(1)"`, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
982
- { ...workspace.context, record },
983
- createProcessTreeKiller(),
984
- volume,
985
- null,
986
- );
987
-
988
- expect(result.success).toBe(false);
989
- expect(result.terminalOutput).toContain(
990
- `compiler:test-10: ENOSPC (no space left on device): the command printed "${line}"; its TMPDIR ` +
991
- `${directory} is on the RAM temp volume ${workspace.root}, which had 0.0 MiB free of 1024.0 MiB when that ` +
992
- 'line arrived\n',
993
- );
994
- expect(result.terminalOutput).not.toContain('is full:');
995
- expect(await readRecord(record.directory)).toEqual({
996
- task: record.task.id,
997
- hash: 'h',
998
- verdict: { outcome: 'no-space', exitCode: 1, tests: [], line, volume: space },
999
- });
1000
- // Read while the lease was still the task's, before it was reaped and released.
1001
- expect(volume.order).toEqual(['space', `reap ${directory}`, `release ${directory}`]);
1002
- });
1003
-
1004
- it('keeps inherited nextest and Cargo ceilings under oversized grants', async () => {
1005
- const previousNextest = process.env.NEXTEST_TEST_THREADS;
1006
- const previousCargo = process.env.CARGO_BUILD_JOBS;
1007
- const previousRust = process.env.RUST_TEST_THREADS;
1008
- process.env.NEXTEST_TEST_THREADS = '6';
1009
- process.env.CARGO_BUILD_JOBS = '4';
1010
- process.env.RUST_TEST_THREADS = '6';
1011
- try {
1012
- for (const tokens of [15, 18]) {
1013
- const workspace = await createWorkspace();
1014
- const asked: number[] = [];
1015
- const released: number[] = [];
1016
- const budget: CpuBudget = {
1017
- async take(want) {
1018
- asked.push(want);
1019
- return heldGrant(tokens, released);
1020
- },
1021
- };
1022
- // Cargo's ceiling bounds its ask; its rustc count is then the sub-pool's jobserver fifo, and its test threads
1023
- // are sized under their own ceiling, never to the target's 64.
1024
- for (const scenario of [
1025
- { runner: 'nextest run', variable: 'NEXTEST_TEST_THREADS', cap: 6 },
1026
- { runner: 'cargo test', variable: 'RUST_TEST_THREADS', cap: 4 },
1027
- ]) {
1028
- const command = `node -e "console.log('cap=' + process.env.${scenario.variable} + ' held=' + process.env.BOUNDED_EXEC_CPU_TOKENS)" # ${scenario.runner}`;
1029
- const result = await runBoundedExec(
1030
- {
1031
- command,
1032
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1033
- parallelism: 18,
1034
- env: { NEXTEST_TEST_THREADS: '64', CARGO_BUILD_JOBS: '64', RUST_TEST_THREADS: '64' },
1035
- },
1036
- workspace.context,
1037
- createProcessTreeKiller(),
1038
- null,
1039
- budget,
1040
- );
1041
- expect(result.success).toBe(true);
1042
- expect(asked.at(-1)).toBe(scenario.cap);
1043
- expect(result.terminalOutput).toContain(`cap=${scenario.cap} held=${tokens}`);
1044
- }
1045
- expect(released).toEqual([tokens, tokens]);
1046
- }
1047
- } finally {
1048
- if (previousNextest === undefined) delete process.env.NEXTEST_TEST_THREADS;
1049
- else process.env.NEXTEST_TEST_THREADS = previousNextest;
1050
- if (previousCargo === undefined) delete process.env.CARGO_BUILD_JOBS;
1051
- else process.env.CARGO_BUILD_JOBS = previousCargo;
1052
- if (previousRust === undefined) delete process.env.RUST_TEST_THREADS;
1053
- else process.env.RUST_TEST_THREADS = previousRust;
1054
- }
1055
- });
1056
-
1057
- it("names the run's own jobserver fifo to its command, never one the target's env names", async () => {
1058
- const workspace = await createWorkspace();
1059
- const released: number[] = [];
1060
- const injected = '-j --jobserver-auth=fifo:/injected';
1061
- const command = `node -e "console.log(JSON.stringify([process.env.CARGO_MAKEFLAGS, process.env.MAKEFLAGS, process.env.${CPU_POOL_ENV}]))"`;
1062
- const result = await runBoundedExec(
1063
- {
1064
- command,
1065
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1066
- env: { CARGO_MAKEFLAGS: injected, MAKEFLAGS: injected, MFLAGS: injected },
1067
- },
1068
- workspace.context,
1069
- createProcessTreeKiller(),
1070
- null,
1071
- {
1072
- async take() {
1073
- return heldGrant(2, released);
1074
- },
1075
- },
1076
- );
1077
- expect(result.success).toBe(true);
1078
- for (const name of ['CARGO_MAKEFLAGS', 'MAKEFLAGS', 'MFLAGS']) {
1079
- expect(result.terminalOutput).toContain(
1080
- `cowshed: ${name} in the target's env is ignored: the CPU budget sets it`,
1081
- );
1082
- }
1083
- // Cargo and make both read the fifo beside the sub-pool's socket that this run serves its descendants.
1084
- expect(result.terminalOutput).toMatch(
1085
- /^\["-j --jobserver-auth=fifo:(\/\S+)\/j","-j --jobserver-auth=fifo:\1\/j","\1\/p\.sock"\]$/m,
1086
- );
1087
- expect(result.terminalOutput).not.toContain('/injected');
1088
- expect(released).toEqual([2]);
1089
- });
1090
-
1091
- it('starts the runner once granted, sized to its grant, and returns the tokens when it exits', async () => {
1092
- const workspace = await createWorkspace();
1093
- const asked: { want: number; checkout: string; command: string }[] = [];
1094
- const released: number[] = [];
1095
- const budget: CpuBudget = {
1096
- async take(want, checkout, command) {
1097
- asked.push({ want, checkout, command });
1098
- return heldGrant(3, released);
1099
- },
1100
- };
1101
- // `nextest run` in a trailing comment makes the shell command a nextest runner by invocation.
1102
- const command =
1103
- "node -e \"console.log('threads=' + process.env.NEXTEST_TEST_THREADS + ' tokens=' + process.env.BOUNDED_EXEC_CPU_TOKENS)\" # nextest run";
1104
-
1105
- const result = await runBoundedExec(
1106
- { command, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 8, env: { NEXTEST_TEST_THREADS: '64' } },
1107
- workspace.context,
1108
- createProcessTreeKiller(),
1109
- null,
1110
- budget,
1111
- );
1112
-
1113
- expect(result.success).toBe(true);
1114
- expect(asked).toEqual([{ want: nextestWant, checkout: workspace.root, command }]);
1115
- expect(result.terminalOutput).toContain(`threads=${Math.min(3, nextestWant)} tokens=3`);
1116
- expect(result.terminalOutput).toMatch(
1117
- new RegExp(
1118
- `^cowshed: cpu-tokens wait done elapsed=\\d+ms status=ok tokens=3/${nextestWant} runner=nextest$`,
1119
- 'm',
1120
- ),
1121
- );
1122
- expect(released).toEqual([3]);
1123
- });
1124
-
1125
- it('runs the command as asked, saying why, when the budget refuses', async () => {
1126
- const workspace = await createWorkspace();
1127
- const budget: CpuBudget = {
1128
- async take() {
1129
- return { granted: false, cause: 'predates', reason: 'the gateway predates the CPU budget' };
1130
- },
1131
- };
1132
-
1133
- // A nextest runner configured for 64 threads keeps them: nothing sizes it without a grant.
1134
- const result = await runBoundedExec(
1135
- {
1136
- command: 'node -e "console.log(\'threads=\' + process.env.NEXTEST_TEST_THREADS)" # nextest run',
1137
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1138
- env: { NEXTEST_TEST_THREADS: '64' },
1139
- },
1140
- workspace.context,
1141
- createProcessTreeKiller(),
1142
- null,
1143
- budget,
1144
- );
1145
-
1146
- expect(result.success).toBe(true);
1147
- expect(result.terminalOutput).toContain('threads=64');
1148
- expect(result.terminalOutput).toContain(
1149
- 'status=err runner=nextest runs unbudgeted: the gateway predates the CPU budget',
1150
- );
1151
- });
1152
-
1153
- it('says nothing and runs as asked where no gateway listens', async () => {
1154
- const workspace = await createWorkspace();
1155
- const budget: CpuBudget = {
1156
- async take() {
1157
- return { granted: false, cause: 'absent', reason: 'no socket' };
1158
- },
1159
- };
1160
-
1161
- const result = await runBoundedExec(
1162
- { command: 'node -e "console.log(\'ran\')"', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
1163
- workspace.context,
1164
- createProcessTreeKiller(),
1165
- null,
1166
- budget,
1167
- );
1168
-
1169
- expect(result.success).toBe(true);
1170
- expect(result.terminalOutput).toBe('ran\n');
1171
- });
1172
-
1173
- it('resolves the cowshed a run uses, in full precedence order', () => {
1174
- const root = '/workspace';
1175
- // The executor never chdirs, so an empty PATH component names its actual spawn cwd,
1176
- // deliberately not the workspace root: the two directories differ on purpose here.
1177
- const cwd = '/elsewhere';
1178
- // Every level present at once, removed one at a time from the top: each step must fall
1179
- // to exactly the next level, so the order itself is the assertion, not each level alone.
1180
- const everywhere = new Set([
1181
- '/opt/bin/cowshed',
1182
- '/elsewhere/cowshed',
1183
- '/workspace/packages/cowshed/bin/cowshed',
1184
- '/workspace/node_modules/@smoothbricks/cowshed/bin/cowshed',
1185
- ]);
1186
- const present = (path: string) => everywhere.has(path);
1187
- const select = (named?: string, inherited?: string, pathValue?: string) =>
1188
- resolveCowshedExecutable(root, named, inherited, pathValue, cwd, present);
1189
-
1190
- // 1. A target-named executable wins, made absolute against the workspace root.
1191
- expect(select('bin/cowshed', '/valid/bin/cowshed', '/opt/bin')).toBe('/workspace/bin/cowshed');
1192
- // 2. An explicit inherited executable outranks PATH and the workspace launcher — the
1193
- // precedence createHostCommands always had — and keeps the coordinate the parent
1194
- // gave it: absolute verbatim, relative untouched for spawn's own resolution,
1195
- // never retargeted to the workspace root.
1196
- expect(select(undefined, '/valid/bin/cowshed', '/opt/bin')).toBe('/valid/bin/cowshed');
1197
- expect(select(undefined, 'bin/cowshed', '/opt/bin')).toBe('bin/cowshed');
1198
- // 3. An installed cowshed on PATH wins (undefined: the bare name spawn already finds it).
1199
- expect(select(undefined, undefined, '/opt/bin')).toBeUndefined();
1200
- // 3b. An empty PATH component (the leading ':' below) names the current directory, as
1201
- // POSIX spawn resolution does — here the executor's cwd, not the workspace root:
1202
- // a cowshed in the cwd is installed too, and one merely in the root is not.
1203
- expect(select(undefined, undefined, ':/usr/bin')).toBeUndefined();
1204
- everywhere.delete('/elsewhere/cowshed');
1205
- everywhere.add('/workspace/cowshed');
1206
- expect(select(undefined, undefined, ':/usr/bin')).toBe('/workspace/packages/cowshed/bin/cowshed');
1207
- everywhere.delete('/workspace/cowshed');
1208
- // 4. Only when PATH provides none does the workspace's own launcher answer.
1209
- expect(select(undefined, undefined, '/usr/bin')).toBe('/workspace/packages/cowshed/bin/cowshed');
1210
- // 5. A linked workspace's launcher answers when the workspace has none of its own.
1211
- everywhere.delete('/workspace/packages/cowshed/bin/cowshed');
1212
- expect(select(undefined, undefined, '/usr/bin')).toBe('/workspace/node_modules/@smoothbricks/cowshed/bin/cowshed');
1213
- // 6. No cowshed anywhere keeps the bare name, so the spawn failure names the missing tool.
1214
- everywhere.clear();
1215
- expect(select(undefined, undefined, '/usr/bin')).toBeUndefined();
1216
- expect(select(undefined, undefined, undefined)).toBeUndefined();
1217
- });
1218
-
1219
- it('sizes a runner to the grant its parent pool lent, takes nothing from the host, and returns nothing to it', async () => {
1220
- const workspace = await createWorkspace();
1221
- const asked: number[] = [];
1222
- const released: number[] = [];
1223
- const budget: CpuBudget = {
1224
- async take(want) {
1225
- asked.push(want);
1226
- return heldGrant(1, released);
1227
- },
1228
- };
1229
- const lent = lentCount(nextestWant, 3);
1230
-
1231
- const result = await withPool(3, (pool) =>
1232
- runBoundedExec(
1233
- {
1234
- command: 'node -e "console.log(\'tokens=\' + process.env.BOUNDED_EXEC_CPU_TOKENS)" # nextest run',
1235
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1236
- parallelism: 8,
1237
- },
1238
- workspace.context,
1239
- createProcessTreeKiller(),
1240
- null,
1241
- budget,
1242
- inheritedFrom(pool),
1243
- ),
1244
- );
1245
-
1246
- expect(result.success).toBe(true);
1247
- expect(asked).toEqual([]);
1248
- expect(released).toEqual([]);
1249
- expect(result.terminalOutput).toContain(`tokens=${lent}\n`);
1250
- expect(result.terminalOutput).toContain(`inherited=true tokens=${lent}/${nextestWant} runner=nextest`);
1251
- });
1252
-
1253
- it('lends a runner no more than it asks for, even with no budget client', async () => {
1254
- const workspace = await createWorkspace();
1255
- const lent = lentCount(2, 16);
1256
-
1257
- const result = await withPool(16, (pool) =>
1258
- runBoundedExec(
1259
- {
1260
- command: 'node -e "console.log(\'threads=\' + process.env.NEXTEST_TEST_THREADS)" # nextest run',
1261
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1262
- parallelism: 2,
1263
- },
1264
- workspace.context,
1265
- createProcessTreeKiller(),
1266
- null,
1267
- null,
1268
- inheritedFrom(pool),
1269
- ),
1270
- );
1271
-
1272
- expect(result.success).toBe(true);
1273
- expect(result.terminalOutput).toContain(`threads=${lent}\n`);
1274
- expect(result.terminalOutput).toContain(`inherited=true tokens=${lent}/2 runner=nextest`);
1275
- });
1276
-
1277
- it('takes and returns its own grant when no parent lent one', async () => {
1278
- const workspace = await createWorkspace();
1279
- const asked: number[] = [];
1280
- const released: number[] = [];
1281
- const budget: CpuBudget = {
1282
- async take(want) {
1283
- asked.push(want);
1284
- return heldGrant(3, released);
1285
- },
1286
- };
1287
-
1288
- const result = await runBoundedExec(
1289
- { command: 'node -e "console.log(1)" # nextest run', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 8 },
1290
- workspace.context,
1291
- createProcessTreeKiller(),
1292
- null,
1293
- budget,
1294
- null,
1295
- );
1296
-
1297
- expect(result.success).toBe(true);
1298
- expect(asked).toEqual([nextestWant]);
1299
- expect(released).toEqual([3]);
1300
- expect(result.terminalOutput).toMatch(
1301
- new RegExp(
1302
- `^cowshed: cpu-tokens wait done elapsed=\\d+ms status=ok tokens=3/${nextestWant} runner=nextest$`,
1303
- 'm',
1304
- ),
1305
- );
1306
- expect(result.terminalOutput).not.toContain('inherited');
1307
- });
1308
-
1309
- it('records a borrowed grant as inherited, and an owned grant without that mark', async () => {
1310
- const workspace = await createWorkspace();
1311
- const command = 'node -e "0" # nextest run';
1312
- const task = { id: 'app:test', hash: null };
1313
- const borrowedDir = join(workspace.root, 'borrowed');
1314
- const ownedDir = join(workspace.root, 'owned');
1315
- const budget: CpuBudget = {
1316
- async take() {
1317
- return heldGrant(3, []);
1318
- },
1319
- };
1320
- const lent = lentCount(nextestWant, 3);
1321
-
1322
- const borrowed = await withPool(3, (pool) =>
1323
- runBoundedExec(
1324
- { command, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 8 },
1325
- { ...workspace.context, record: { task, directory: borrowedDir } },
1326
- createProcessTreeKiller(),
1327
- null,
1328
- null,
1329
- inheritedFrom(pool),
1330
- ),
1331
- );
1332
- const owned = await runBoundedExec(
1333
- { command, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 8 },
1334
- { ...workspace.context, record: { task, directory: ownedDir } },
1335
- createProcessTreeKiller(),
1336
- null,
1337
- budget,
1338
- null,
1339
- );
1340
-
1341
- expect(borrowed.success).toBe(true);
1342
- expect(owned.success).toBe(true);
1343
- const borrowedRecord: unknown = JSON.parse(await readFile(join(borrowedDir, VERDICT_FILE), 'utf8'));
1344
- expect(borrowedRecord).toHaveProperty('cpu', {
1345
- tokens: lent,
1346
- want: nextestWant,
1347
- waitedMs: expect.any(Number),
1348
- inherited: true,
1349
- });
1350
- const ownedRecord: unknown = JSON.parse(await readFile(join(ownedDir, VERDICT_FILE), 'utf8'));
1351
- expect(ownedRecord).toHaveProperty('cpu', { tokens: 3, want: nextestWant, waitedMs: expect.any(Number) });
1352
- expect(ownedRecord).not.toHaveProperty('cpu.inherited');
1353
- });
1354
-
1355
- it('keeps a command running when its borrowed grant closes, and judges it by its own exit', async () => {
1356
- if (process.platform === 'win32') return;
1357
- const workspace = await createWorkspace();
1358
- const directory = join(workspace.root, 'outlives-its-grant');
1359
- const started = join(workspace.root, 'started.fifo');
1360
- const go = join(workspace.root, 'go.fifo');
1361
- expect(spawnSync('mkfifo', [started, go]).status).toBe(0);
1362
- // The run says the grant ended on its stderr; that line is the signal the close was heard while the command runs.
1363
- const { promise: heard, resolve: hear } = Promise.withResolvers<void>();
1364
- process.stderr.write = captureWrite([], (text) => {
1365
- if (text.includes('cpu-tokens grant ended')) hear();
1366
- });
1367
- const result = await withPool(1, async (pool) => {
1368
- const running = runBoundedExec(
1369
- {
1370
- command: `sh -c 'echo started > "$0"; read -r line < "$1"' '${started}' '${go}'`,
1371
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1372
- },
1373
- { ...workspace.context, record: { task: { id: 'outlives-its-grant', hash: null }, directory } },
1374
- createProcessTreeKiller(),
1375
- null,
1376
- null,
1377
- inheritedFrom(pool),
1378
- );
1379
- // The command has started and waits on `go` while its borrowed grant closes under it.
1380
- expect(await readToEnd(started)).toBe('started\n');
1381
- const closed = await pool.close();
1382
- if (!closed.ok) throw new Error(closed.error);
1383
- await heard;
1384
- await writeFile(go, 'go\n');
1385
- return running;
1386
- });
1387
- expect(result.terminalOutput).toContain(
1388
- 'cowshed: cpu-tokens grant ended: the parent pool closed its 1-token grant while the command ran; it runs on over budget until it ends',
1389
- );
1390
- expect(result.terminalOutput).not.toContain('Force-killing');
1391
- expect(result.success).toBe(true);
1392
- const record: unknown = JSON.parse(await readFile(join(directory, VERDICT_FILE), 'utf8'));
1393
- expect(record).toHaveProperty('verdict.outcome', 'passed');
1394
- });
1395
-
1396
- it('asks the host budget when a parent pool refuses its descriptor, and says why', async () => {
1397
- const workspace = await createWorkspace();
1398
- const asked: number[] = [];
1399
- const released: number[] = [];
1400
- const budget: CpuBudget = {
1401
- async take(want) {
1402
- asked.push(want);
1403
- return heldGrant(3, released);
1404
- },
1405
- };
1406
- const gone = { socket: join(workspace.root, 'gone.sock'), tokens: 3 };
1407
-
1408
- const result = await runBoundedExec(
1409
- {
1410
- command: 'node -e "console.log(\'ran\')" # nextest run',
1411
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1412
- parallelism: 8,
1413
- },
1414
- workspace.context,
1415
- createProcessTreeKiller(),
1416
- null,
1417
- budget,
1418
- gone,
1419
- );
1420
-
1421
- expect(result.success).toBe(true);
1422
- expect(asked).toEqual([nextestWant]);
1423
- expect(released).toEqual([3]);
1424
- expect(result.terminalOutput).toContain('cowshed: cpu-tokens parent pool refused: ');
1425
- expect(result.terminalOutput).toContain(`status=ok tokens=3/${nextestWant} runner=nextest`);
1426
- expect(result.terminalOutput).not.toContain('inherited=true');
1427
- });
1428
-
1429
- it('ignores a target env that names the CPU budget, when no budget grants it', async () => {
1430
- const workspace = await createWorkspace();
1431
-
1432
- const result = await runBoundedExec(
1433
- {
1434
- command: 'node -e "console.log(\'tokens=\' + process.env.BOUNDED_EXEC_CPU_TOKENS)"',
1435
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1436
- env: { BOUNDED_EXEC_CPU_TOKENS: '977' },
1437
- },
1438
- workspace.context,
1439
- createProcessTreeKiller(),
1440
- null,
1441
- null,
1442
- );
1443
-
1444
- expect(result.success).toBe(true);
1445
- expect(result.terminalOutput).toContain('tokens=undefined\n');
1446
- expect(result.terminalOutput).toContain(
1447
- `cowshed: BOUNDED_EXEC_CPU_TOKENS in the target's env is ignored: the CPU budget sets it`,
1448
- );
1449
- });
1450
-
1451
- it('sizes the command from its own grant, whatever the target env names', async () => {
1452
- const workspace = await createWorkspace();
1453
- const released: number[] = [];
1454
- const budget: CpuBudget = {
1455
- async take() {
1456
- return heldGrant(2, released);
1457
- },
1458
- };
1459
-
1460
- const result = await runBoundedExec(
1461
- {
1462
- command: 'node -e "console.log(\'tokens=\' + process.env.BOUNDED_EXEC_CPU_TOKENS)" # nextest run',
1463
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1464
- parallelism: 8,
1465
- env: { BOUNDED_EXEC_CPU_TOKENS: '977' },
1466
- },
1467
- workspace.context,
1468
- createProcessTreeKiller(),
1469
- null,
1470
- budget,
1471
- );
1472
-
1473
- expect(result.success).toBe(true);
1474
- expect(result.terminalOutput).toContain('tokens=2\n');
1475
- expect(result.terminalOutput).not.toContain('977');
1476
- expect(released).toEqual([2]);
1477
- });
1478
-
1479
- it('refuses the run when its parent pool answers with a refusal, asking no host budget', async () => {
1480
- const socketDirectory = await ownedSocketDirectory('cpu-refuse-', 'p.sock');
1481
- workspaces.push(socketDirectory);
1482
- const socket = join(socketDirectory, 'p.sock');
1483
- // A live pool that refuses answers `other`, not `absent`: the run must fail, not ask the host.
1484
- const refusing = createServer((connection) => {
1485
- connection.once('data', () => {
1486
- connection.end('{"ok":false,"code":"refused","error":"the pool is shutting down"}\n');
1487
- });
1488
- });
1489
- await new Promise<void>((resolve) => refusing.listen(socket, resolve));
1490
- const workspace = await createWorkspace();
1491
- const asked: number[] = [];
1492
- const budget: CpuBudget = {
1493
- async take(want) {
1494
- asked.push(want);
1495
- return heldGrant(1, []);
1496
- },
1497
- };
1498
- try {
1499
- const result = await runBoundedExec(
1500
- { command: 'touch ran.marker', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
1501
- {
1502
- ...workspace.context,
1503
- record: { task: { id: 'refused', hash: null }, directory: join(workspace.root, 'refused') },
1504
- },
1505
- createProcessTreeKiller(),
1506
- null,
1507
- budget,
1508
- { socket, tokens: 3 },
1509
- );
1510
-
1511
- expect(result.success).toBe(false);
1512
- expect(asked).toEqual([]);
1513
- expect(await exists(join(workspace.root, 'ran.marker'))).toBe(false);
1514
- expect(result.terminalOutput).toContain('cowshed: cpu-tokens parent pool refused: ');
1515
- expect(result.terminalOutput).toContain('refusing to run the command without asking the host budget');
1516
- expect(await readFile(join(workspace.root, 'refused', VERDICT_FILE), 'utf8')).toMatch(/"outcome":\s*"failed"/);
1517
- } finally {
1518
- await new Promise<void>((resolve) => refusing.close(() => resolve()));
1519
- }
1520
- });
1521
-
1522
- it('never gives a command a budget it was not granted, whatever pool or count its environment names', async () => {
1523
- const workspace = await createWorkspace();
1524
- await workspace.write('probe.js', BUDGET_PROBE);
1525
- const previousPool = process.env[CPU_POOL_ENV];
1526
- const previousTokens = process.env[CPU_TOKENS_ENV];
1527
- // A stale descriptor in this process's own environment is no budget either.
1528
- process.env[CPU_POOL_ENV] = '/stale.sock';
1529
- process.env[CPU_TOKENS_ENV] = '5';
1530
- try {
1531
- const absent: CpuBudget = {
1532
- async take() {
1533
- return { granted: false, cause: 'absent', reason: 'no budget socket' };
1534
- },
1535
- };
1536
- const unbudgeted = await withPool(3, (pool) =>
1537
- runBoundedExec(
1538
- {
1539
- command: 'node probe.js',
1540
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1541
- env: { ...pool.environment, [CPU_TOKENS_ENV]: '9' },
1542
- },
1543
- workspace.context,
1544
- createProcessTreeKiller(),
1545
- null,
1546
- absent,
1547
- ),
1548
- );
1549
- expect(unbudgeted.terminalOutput).toContain('[null,null]\n[null,null]\n');
1550
-
1551
- const released: number[] = [];
1552
- let injected = '';
1553
- const granted = await withPool(3, (pool) => {
1554
- injected = inheritedFrom(pool).socket;
1555
- return runBoundedExec(
1556
- {
1557
- command: 'node probe.js',
1558
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1559
- env: { ...pool.environment, [CPU_TOKENS_ENV]: '9' },
1560
- },
1561
- workspace.context,
1562
- createProcessTreeKiller(),
1563
- null,
1564
- {
1565
- async take() {
1566
- return heldGrant(2, released);
1567
- },
1568
- },
1569
- );
1570
- });
1571
- const [own, grandchild] = granted.terminalOutput.split('\n').filter((line) => line.startsWith('['));
1572
- expect(own).toBe(grandchild);
1573
- expect(own).toMatch(/,"2"\]$/);
1574
- expect(own).not.toContain(injected);
1575
- expect(own).not.toContain('/stale.sock');
1576
- expect(released).toEqual([2]);
1577
- } finally {
1578
- if (previousPool === undefined) {
1579
- delete process.env[CPU_POOL_ENV];
1580
- } else {
1581
- process.env[CPU_POOL_ENV] = previousPool;
1582
- }
1583
- if (previousTokens === undefined) {
1584
- delete process.env[CPU_TOKENS_ENV];
1585
- } else {
1586
- process.env[CPU_TOKENS_ENV] = previousTokens;
1587
- }
1588
- }
1589
- });
1590
- });
1591
-
1592
- describe('createNoSpaceWatch', () => {
1593
- it("finds nextest's ENOSPC split across chunks, past colour codes, and reports it once", () => {
1594
- // nextest's own report of a failed archive extraction into a full RAM lease, from a downstream land gate.
1595
- const watch = createNoSpaceWatch();
1596
- expect(watch.scan('stderr', 'Caused by:\n No space left')).toBeNull();
1597
- expect(watch.scan('stdout', ' on device (os error 28)\n')).toBeNull();
1598
- expect(watch.scan('stderr', ' on device \u001b[1m(os error 28)\u001b[0m\nCommand exited')).toBe(
1599
- 'No space left on device (os error 28)',
1600
- );
1601
- expect(watch.scan('stderr', 'ENOSPC: no space left on device, write\n')).toBeNull();
1602
- });
1603
-
1604
- it("finds Bun's errno name, and not a word that merely contains it", () => {
1605
- const watch = createNoSpaceWatch();
1606
- expect(watch.scan('stdout', 'XENOSPCY is not an errno\n')).toBeNull();
1607
- expect(watch.scan('stdout', ' code: "ENOSPC"\n')).toBe('code: "ENOSPC"');
1608
- });
1609
- });
1610
-
1611
- interface WorkspaceFixture {
1612
- root: string;
1613
- context: BoundedExecContext;
1614
- write(filePath: string, contents: string): Promise<void>;
1615
- }
1616
-
1617
- /** Everything written to the FIFO at `path` until its last writer closes it. */
1618
- async function readToEnd(path: string): Promise<string> {
1619
- const handle = await open(path, 'r');
1620
- try {
1621
- return await handle.readFile('utf8');
1622
- } finally {
1623
- await handle.close();
1624
- }
1625
- }
1626
-
1627
- /** Reuses the real killer, delaying delivery (not the bound) until the named fixture is armed. */
1628
- function armedKiller(subject: string, ready: (pid: number) => Promise<void>) {
1629
- const real = createProcessTreeKiller();
1630
- const calls: NodeJS.Signals[] = [];
1631
- let armed: Promise<void> | undefined;
1632
- let group: number | undefined;
1633
- return {
1634
- calls,
1635
- killer: {
1636
- async kill(pid: number, signal: NodeJS.Signals) {
1637
- group = pid;
1638
- ownedProcessGroups.add(pid);
1639
- armed ??= ready(pid);
1640
- await armed;
1641
- calls.push(signal);
1642
- await real.kill(pid, signal);
1643
- },
1644
- } satisfies ProcessTreeKiller,
1645
- async armed() {
1646
- expect(armed, `${subject}: readiness was never requested before timeout signal delivery`).toBeDefined();
1647
- // The executor tolerates killer errors; re-await here so a failed readiness assertion cannot be swallowed.
1648
- await armed;
1649
- },
1650
- /** Called only after leader exit and EOF from every descendant's inherited lifetime writer. */
1651
- release() {
1652
- if (group === undefined) throw new Error(`${subject}: no process group was armed`);
1653
- ownedProcessGroups.delete(group);
1654
- },
1655
- };
1656
- }
1657
-
1658
- /** A complete readiness line identifies a live member of the executor's own process group. */
1659
- async function armedPid(path: string, pgid: number, subject: string): Promise<number> {
1660
- const text = await readToEnd(path);
1661
- const match = /^ready pid=(\d+)\n$/.exec(text);
1662
- const pid = Number(match?.[1]);
1663
- const detail = `${subject}: ready=${JSON.stringify(text)} fifo=${path} pid=${pid} expected pgid=${pgid}`;
1664
- expect(Number.isSafeInteger(pid) && pid > 0, `${detail}; state=unobserved (invalid readiness PID)`).toBe(true);
1665
- // Bare `ps` through PATH: NixOS has no /bin/ps, and a failed spawn leaves stdout null.
1666
- const observed = spawnSync('ps', ['-o', 'pid=,ppid=,pgid=,stat=', '-p', String(pid)], { encoding: 'utf8' });
1667
- const observedStdout = observed.stdout ?? '';
1668
- const state = `${detail}; state=${observedStdout.trim()} status=${observed.status} stderr=${observed.stderr} error=${observed.error}`;
1669
- expect(observed.status, state).toBe(0);
1670
- const [seenPid, , seenGroup, stat] = observedStdout.trim().split(/\s+/);
1671
- expect(Number(seenPid), state).toBe(pid);
1672
- expect(Number(seenGroup), state).toBe(pgid);
1673
- expect(stat !== undefined && !stat.startsWith('Z'), state).toBe(true);
1674
- return pid;
1675
- }
1676
-
1677
- /**
1678
- * A command that ignores SIGTERM, a disposition its `tail` inherits, and never exits on its own, so only the escalation
1679
- * can end it; and `armed`, which resolves once it ignores SIGTERM. A killer that awaits `armed` before the graceful
1680
- * signal sends it to a command that cannot die of it: a bound that fires before the command's shell has even run
1681
- * `trap` (a 250 ms timer lost that race in a loaded gate) ends it on the default disposition, and the escalation under
1682
- * test never runs. The command's FIFO write waits for the reader, so the announcement can neither precede the trap nor
1683
- * be missed.
1684
- */
1685
- function ignoresTerm(root: string): { command: string; armed: () => Promise<void> } {
1686
- const fifo = join(root, 'armed.fifo');
1687
- expect(spawnSync('mkfifo', [fifo]).status).toBe(0);
1688
- return {
1689
- command: `sh -c 'trap "" TERM; echo armed > "$0"; exec tail -f /dev/null' '${fifo}'`,
1690
- armed: async () => {
1691
- expect(await readToEnd(fifo)).toBe('armed\n');
1692
- },
1693
- };
1694
- }
1695
-
1696
- async function createWorkspace(): Promise<WorkspaceFixture> {
1697
- const root = await mkdtemp(join(tmpdir(), 'smoothbricks-bounded-exec-'));
1698
- workspaces.push(root);
1699
- return {
1700
- root,
1701
- context: { root },
1702
- async write(filePath: string, contents: string): Promise<void> {
1703
- const absolutePath = join(root, filePath);
1704
- await mkdir(dirname(absolutePath), { recursive: true });
1705
- await writeFile(absolutePath, contents);
1706
- },
1707
- };
1708
- }
1709
-
1710
- function leaseAt(directory: string): RamTempLease {
1711
- return { directory, mountpoint: dirname(directory), capacityBytes: 1024 * 1024 * 1024 };
1712
- }
1713
-
1714
- /** A temp volume whose answers are fixed, recording which leases were reaped and released, and when space was read. */
1715
- function scriptedVolume(
1716
- acquisition: Result<RamTempAcquisition, RamTempError>,
1717
- full: RamTempError | null = null,
1718
- leftovers: string[] = [],
1719
- space: TempVolumeSpace | null = null,
1720
- ): TempVolume & { released: string[]; order: string[] } {
1721
- const released: string[] = [];
1722
- const order: string[] = [];
1723
- return {
1724
- released,
1725
- order,
1726
- acquire: () => Promise.resolve(acquisition),
1727
- reap(lease) {
1728
- order.push(`reap ${lease.directory}`);
1729
- return Promise.resolve({ ok: true, value: leftovers });
1730
- },
1731
- release(lease) {
1732
- released.push(lease.directory);
1733
- order.push(`release ${lease.directory}`);
1734
- return Promise.resolve({ ok: true, value: undefined });
1735
- },
1736
- fullness: () => Promise.resolve(full),
1737
- space() {
1738
- order.push('space');
1739
- return Promise.resolve(space);
1740
- },
1741
- };
1742
- }
1743
-
1744
- function captureWrite(chunks: string[], onChunk?: (text: string) => void): typeof process.stdout.write {
1745
- return ((
1746
- chunk: string | Uint8Array,
1747
- encodingOrCallback?: BufferEncoding | ((error?: Error | null) => void),
1748
- callback?: (error?: Error | null) => void,
1749
- ) => {
1750
- const text = chunk.toString();
1751
- chunks.push(text);
1752
- onChunk?.(text);
1753
- const cb = typeof encodingOrCallback === 'function' ? encodingOrCallback : callback;
1754
- cb?.();
1755
- return true;
1756
- }) as typeof process.stdout.write;
1757
- }
1758
-
1759
- async function exists(path: string): Promise<boolean> {
1760
- try {
1761
- await access(path);
1762
- return true;
1763
- } catch {
1764
- return false;
1765
- }
1766
- }
1767
-
1768
- /** A granted host grant whose `closed` resolves on release, as the gateway's does when the grant's socket closes. */
1769
- function heldGrant(tokens: number, released: number[]): TokenGrant {
1770
- let closeGrant!: () => void;
1771
- const closed = new Promise<void>((resolve) => {
1772
- closeGrant = resolve;
1773
- });
1774
- return {
1775
- granted: true,
1776
- tokens,
1777
- release: () => {
1778
- released.push(tokens);
1779
- closeGrant();
1780
- },
1781
- closed,
1782
- };
1783
- }
1784
-
1785
- /** A parent's CPU pool of `tokens`, open while `body` runs. Its upstream never closes on its own, and no run owns the
1786
- * host waits its children report. */
1787
- async function withPool<T>(tokens: number, body: (pool: CpuPool) => Promise<T>): Promise<T> {
1788
- const created = await createCpuPool(tokens, new Promise<void>(() => {}), { begin() {}, end() {} });
1789
- if (!created.ok) {
1790
- throw new Error(`cpu pool: ${created.error}`);
1791
- }
1792
- let result: { ok: true; value: T } | { ok: false; error: unknown };
1793
- try {
1794
- result = { ok: true, value: await body(created.pool) };
1795
- } catch (error) {
1796
- result = { ok: false, error };
1797
- }
1798
- const outcome = await created.pool.close();
1799
- if (!outcome.ok) {
1800
- const failure = new Error(`cpu pool did not close: ${outcome.error}`);
1801
- throw result.ok ? failure : new AggregateError([result.error, failure], 'CPU pool body and cleanup failed');
1802
- }
1803
- if (!result.ok) throw result.error;
1804
- return result.value;
1805
- }
1806
-
1807
- /** The descriptor a run under `pool` inherits: the pool's own environment, read back the way a child reads it. */
1808
- function inheritedFrom(pool: CpuPool): InheritedCpuPool {
1809
- const parent = readInheritedCpuPool(pool.environment);
1810
- if (parent === null) {
1811
- throw new Error('the pool environment names no endpoint');
1812
- }
1813
- return parent;
1814
- }
1815
-
1816
- /** The count a pool of `tokens` lends a run that wants `want`: min(want, tokens). */
1817
- function lentCount(want: number, tokens: number): number {
1818
- return Math.min(want, tokens);
1819
- }