@smoothbricks/nx-plugin 0.5.6 → 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 (440) hide show
  1. package/README.md +1095 -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/all-verdicts/executor.d.ts +35 -0
  59. package/dist/executors/all-verdicts/executor.d.ts.map +1 -0
  60. package/dist/executors/all-verdicts/executor.js +133 -0
  61. package/dist/executors/all-verdicts/schema.d.ts +10 -0
  62. package/dist/executors/all-verdicts/schema.d.ts.map +1 -0
  63. package/dist/executors/all-verdicts/schema.js +2 -0
  64. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  65. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  66. package/dist/executors/bounded-exec/bounds.js +43 -0
  67. package/dist/executors/bounded-exec/cpu-pool.d.ts +33 -36
  68. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/cpu-pool.js +54 -119
  70. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  71. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/executor.js +371 -239
  73. package/dist/executors/bounded-exec/gateway-lease.d.ts +22 -19
  74. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  75. package/dist/executors/bounded-exec/gateway-lease.js +81 -28
  76. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  77. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  78. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  79. package/dist/executors/bounded-exec/lease-wait.d.ts +43 -0
  80. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/lease-wait.js +68 -0
  82. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  83. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  84. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  85. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  86. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  88. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  89. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  90. package/dist/executors/bounded-exec/progress.js +5 -2
  91. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  92. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  93. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  94. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  95. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  96. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  97. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  98. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  100. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  101. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  102. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  103. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +4 -4
  104. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  105. package/dist/executors/bounded-exec/run-cpu-pool.js +20 -30
  106. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  107. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  108. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  109. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  110. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  111. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  112. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  113. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  114. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  115. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  116. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  117. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  118. package/dist/executors/bounded-exec/verdict.d.ts +40 -11
  119. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  120. package/dist/executors/bounded-exec/verdict.js +88 -19
  121. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  122. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  123. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  124. package/dist/executors/clean-outputs/executor.js +1 -0
  125. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  126. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/executor.js +367 -0
  128. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  129. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  130. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  131. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  132. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  133. package/dist/executors/scriptc-native/schema.js +1 -0
  134. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  135. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  136. package/dist/executors/typescript-emit/executor.js +164 -33
  137. package/dist/forbidden-spelling-policy.d.ts +56 -0
  138. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  139. package/dist/forbidden-spelling-policy.js +176 -0
  140. package/dist/generators/create-package/generator.d.ts.map +1 -1
  141. package/dist/generators/create-package/generator.js +3 -4
  142. package/dist/graph-input-contract.d.ts +14 -0
  143. package/dist/graph-input-contract.d.ts.map +1 -1
  144. package/dist/graph-input-contract.js +67 -2
  145. package/dist/index.d.ts +23 -6
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +676 -215
  148. package/dist/managed-assets.d.ts +2 -0
  149. package/dist/managed-assets.d.ts.map +1 -1
  150. package/dist/managed-files/files.d.ts +3 -3
  151. package/dist/managed-files/files.d.ts.map +1 -1
  152. package/dist/managed-files/files.js +28 -3
  153. package/dist/managed-files/managed-format.d.ts.map +1 -1
  154. package/dist/managed-files/managed-format.js +1 -0
  155. package/dist/nextest-code-bound.js +1 -0
  156. package/dist/nextest-timings.d.ts +35 -0
  157. package/dist/nextest-timings.d.ts.map +1 -0
  158. package/dist/nextest-timings.js +168 -0
  159. package/dist/owned-installation.d.ts +6 -5
  160. package/dist/owned-installation.d.ts.map +1 -1
  161. package/dist/owned-installation.js +150 -26
  162. package/dist/package-target-policy.d.ts.map +1 -1
  163. package/dist/package-target-policy.js +2 -3
  164. package/dist/process-children.d.ts +7 -0
  165. package/dist/process-children.d.ts.map +1 -0
  166. package/dist/process-children.darwin.d.ts +7 -0
  167. package/dist/process-children.darwin.d.ts.map +1 -0
  168. package/dist/process-children.darwin.js +13 -0
  169. package/dist/process-children.js +14 -0
  170. package/dist/process-children.linux.d.ts +8 -0
  171. package/dist/process-children.linux.d.ts.map +1 -0
  172. package/dist/process-children.linux.js +25 -0
  173. package/dist/process-group.d.ts +108 -0
  174. package/dist/process-group.d.ts.map +1 -0
  175. package/dist/process-group.js +171 -0
  176. package/dist/process-listing.d.ts +7 -0
  177. package/dist/process-listing.d.ts.map +1 -0
  178. package/dist/process-listing.js +51 -0
  179. package/dist/producer-receipts.d.ts +8 -2
  180. package/dist/producer-receipts.d.ts.map +1 -1
  181. package/dist/producer-receipts.js +75 -48
  182. package/dist/task-graph-policy.d.ts +21 -0
  183. package/dist/task-graph-policy.d.ts.map +1 -0
  184. package/dist/task-graph-policy.js +91 -0
  185. package/dist/test-timings.js +4 -4
  186. package/dist/test-walk-policy.d.ts +14 -5
  187. package/dist/test-walk-policy.d.ts.map +1 -1
  188. package/dist/test-walk-policy.js +8 -2
  189. package/dist/testing.d.ts +73 -28
  190. package/dist/testing.d.ts.map +1 -1
  191. package/dist/testing.js +217 -223
  192. package/dist/tool-bins.d.ts +33 -0
  193. package/dist/tool-bins.d.ts.map +1 -0
  194. package/dist/tool-bins.js +72 -0
  195. package/dist/typecheck-test-policy.d.ts.map +1 -1
  196. package/dist/typecheck-test-policy.js +3 -4
  197. package/dist/wait-why-policy.d.ts +28 -0
  198. package/dist/wait-why-policy.d.ts.map +1 -0
  199. package/dist/wait-why-policy.js +223 -0
  200. package/dist/workspace-config-policy.d.ts +14 -8
  201. package/dist/workspace-config-policy.d.ts.map +1 -1
  202. package/dist/workspace-config-policy.js +60 -16
  203. package/dist/workspace-manifest.d.ts +41 -6
  204. package/dist/workspace-manifest.d.ts.map +1 -1
  205. package/dist/workspace-manifest.js +57 -0
  206. package/executors.json +21 -1
  207. package/loader.js +2 -0
  208. package/managed/raw/envrc +11 -0
  209. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  210. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  211. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  212. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  213. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  214. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  215. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  216. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  217. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  218. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  219. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  220. package/managed/raw/tooling/direnv/repo-path +68 -6
  221. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  222. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  223. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  224. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  225. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  226. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  227. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  228. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  229. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  230. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  231. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  232. package/package.json +77 -13
  233. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  234. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  235. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  236. package/src/bounded-test-policy.ts +12 -14
  237. package/src/build-state-output-policy.ts +458 -34
  238. package/src/bun-lock-scope.ts +108 -0
  239. package/src/cargo-build-script-env.ts +265 -0
  240. package/src/cargo-closure-input.ts +74 -7
  241. package/src/cargo-retention-hook.ts +94 -0
  242. package/src/cargo-source-hash.ts +138 -41
  243. package/src/cargo-toolchain-paths.ts +95 -0
  244. package/src/cargo-toolchain-policy.ts +49 -5
  245. package/src/cargo-workspace.ts +72 -123
  246. package/src/cross-check-policy.ts +12 -10
  247. package/src/disk-command-policy.ts +1 -0
  248. package/src/ensure-built-receipt.ts +132 -39
  249. package/src/ensure-built-witness.ts +62 -10
  250. package/src/ensure-built.ts +11 -1
  251. package/src/eslint-config-closure.ts +357 -0
  252. package/src/executors/all-verdicts/executor.ts +164 -0
  253. package/src/executors/all-verdicts/schema.json +22 -0
  254. package/src/executors/all-verdicts/schema.ts +10 -0
  255. package/src/executors/bounded-exec/bounds.ts +76 -0
  256. package/src/executors/bounded-exec/cpu-pool.ts +51 -117
  257. package/src/executors/bounded-exec/executor.ts +423 -259
  258. package/src/executors/bounded-exec/gateway-lease.ts +82 -33
  259. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  260. package/src/executors/bounded-exec/lease-wait.ts +89 -0
  261. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  262. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  263. package/src/executors/bounded-exec/progress.ts +9 -3
  264. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  265. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  266. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  267. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  268. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  269. package/src/executors/bounded-exec/run-cpu-pool.ts +22 -30
  270. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  271. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  272. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  273. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  274. package/src/executors/bounded-exec/schema.json +11 -2
  275. package/src/executors/bounded-exec/schema.ts +19 -1
  276. package/src/executors/bounded-exec/verdict.ts +137 -34
  277. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  278. package/src/executors/clean-outputs/executor.ts +1 -0
  279. package/src/executors/scriptc-native/executor.ts +394 -0
  280. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  281. package/src/executors/scriptc-native/schema.json +60 -0
  282. package/src/executors/scriptc-native/schema.ts +34 -0
  283. package/src/executors/typescript-emit/executor.ts +205 -38
  284. package/src/forbidden-spelling-policy.ts +226 -0
  285. package/src/generators/create-package/generator.ts +7 -7
  286. package/src/graph-input-contract.ts +61 -2
  287. package/src/index.ts +792 -225
  288. package/src/managed-assets.ts +3 -0
  289. package/src/managed-files/files.ts +28 -3
  290. package/src/managed-files/managed-format.ts +1 -0
  291. package/src/nextest-code-bound.ts +1 -0
  292. package/src/nextest-timings.ts +106 -0
  293. package/src/owned-installation.ts +150 -23
  294. package/src/package-target-policy.ts +2 -3
  295. package/src/process-children.darwin.ts +14 -0
  296. package/src/process-children.linux.ts +33 -0
  297. package/src/process-children.ts +22 -0
  298. package/src/process-group.ts +209 -0
  299. package/src/process-listing.ts +54 -0
  300. package/src/producer-receipts.ts +68 -45
  301. package/src/task-graph-policy.ts +98 -0
  302. package/src/test-walk-policy.ts +23 -8
  303. package/src/testing.ts +240 -232
  304. package/src/tool-bins.ts +108 -0
  305. package/src/typecheck-test-policy.ts +2 -3
  306. package/src/wait-why-policy.ts +226 -0
  307. package/src/workspace-config-policy.ts +63 -15
  308. package/src/workspace-manifest.ts +89 -6
  309. package/test-timings.json +123 -98
  310. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  311. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  312. package/dist/bin/smoo-nx-failures.js +0 -3
  313. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  314. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  315. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  316. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  317. package/dist/failure-summary.d.ts +0 -5
  318. package/dist/failure-summary.d.ts.map +0 -1
  319. package/dist/failure-summary.js +0 -118
  320. package/dist/nextest-extraction.d.ts +0 -117
  321. package/dist/nextest-extraction.d.ts.map +0 -1
  322. package/dist/nextest-extraction.js +0 -303
  323. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  324. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  325. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  326. package/src/__tests__/counted-cargo-process.ts +0 -286
  327. package/src/__tests__/counted-cargo.ts +0 -713
  328. package/src/__tests__/directory-change.ts +0 -27
  329. package/src/__tests__/fixture-cargo-home.ts +0 -36
  330. package/src/__tests__/fixture-nx-env.ts +0 -193
  331. package/src/__tests__/owned-installation.ts +0 -13
  332. package/src/__tests__/past-tick.ts +0 -12
  333. package/src/__tests__/progress-clock.ts +0 -43
  334. package/src/__tests__/runtime-input.ts +0 -23
  335. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  336. package/src/bin/smoo-nx-failures.ts +0 -4
  337. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  338. package/src/bounded-test-policy.test.ts +0 -1029
  339. package/src/build-state-output-policy.test.ts +0 -115
  340. package/src/bun-bootstrap.test.ts +0 -102
  341. package/src/bun-file-packages.test.ts +0 -47
  342. package/src/cargo-closure-filesets.test.ts +0 -63
  343. package/src/cargo-closure-input.property.test.ts +0 -50
  344. package/src/cargo-closure-input.test.ts +0 -506
  345. package/src/cargo-closure-key.test.ts +0 -240
  346. package/src/cargo-resolve-cache.test.ts +0 -1181
  347. package/src/cargo-source-hash.test.ts +0 -707
  348. package/src/cargo-workspace.test.ts +0 -615
  349. package/src/cross-check-policy.test.ts +0 -316
  350. package/src/disk-command-policy.test.ts +0 -61
  351. package/src/ensure-built-receipt.test.ts +0 -279
  352. package/src/ensure-built-witness.test.ts +0 -688
  353. package/src/ensure-built.test.ts +0 -1462
  354. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  355. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  356. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  357. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  358. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  359. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  360. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  361. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  362. package/src/executors/bounded-exec/progress.test.ts +0 -139
  363. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  364. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  365. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  366. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  367. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  368. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  369. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  370. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  371. package/src/executors/clean-outputs/executor.test.ts +0 -20
  372. package/src/executors/typescript-emit/executor.test.ts +0 -83
  373. package/src/failure-summary.ts +0 -119
  374. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  375. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  376. package/src/generators/create-package/generator.test.ts +0 -190
  377. package/src/generators/make-public/generator.test.ts +0 -137
  378. package/src/graph-input-contract.test.ts +0 -379
  379. package/src/host-controller-wiring.test.ts +0 -31
  380. package/src/index.test.ts +0 -3319
  381. package/src/linked-snapshots.nx.test.ts +0 -254
  382. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  383. package/src/managed-files/generator.test.ts +0 -243
  384. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  385. package/src/managed-files/json-edit.test.ts +0 -216
  386. package/src/managed-files/managed-content.test.ts +0 -166
  387. package/src/managed-files/managed-format-json.test.ts +0 -308
  388. package/src/managed-files/repo-path.test.ts +0 -172
  389. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  390. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  391. package/src/managed-files/tree-permissions.test.ts +0 -109
  392. package/src/managed-files/tree.test.ts +0 -123
  393. package/src/manifest-hash.test.ts +0 -219
  394. package/src/nextest-code-bound.test.ts +0 -161
  395. package/src/nextest-extraction.test.ts +0 -216
  396. package/src/nextest-extraction.ts +0 -371
  397. package/src/nextest-partitions.test.ts +0 -501
  398. package/src/nx-cache-bound.test.ts +0 -109
  399. package/src/nx-cache-restore-mtime.test.ts +0 -170
  400. package/src/nx-daemon-claim.test.ts +0 -279
  401. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  402. package/src/nx-daemon-idle-policy.test.ts +0 -111
  403. package/src/nx-daemon-ignore-files.test.ts +0 -210
  404. package/src/nx-daemon-root-normalization.test.ts +0 -105
  405. package/src/nx-daemon-start-never.test.ts +0 -292
  406. package/src/nx-daemon-validity.test.ts +0 -1055
  407. package/src/nx-dot-input-policy.test.ts +0 -353
  408. package/src/nx-failure-life-cycles.test.ts +0 -207
  409. package/src/nx-files-archive-racy.test.ts +0 -97
  410. package/src/nx-foreign-workspace-env.test.ts +0 -329
  411. package/src/nx-incomplete-run-summary.test.ts +0 -70
  412. package/src/nx-plugin-load-errors.test.ts +0 -120
  413. package/src/nx-project-graph-errors.test.ts +0 -70
  414. package/src/nx-project-resolution-cache.test.ts +0 -176
  415. package/src/nx-raw-inputs.test.ts +0 -166
  416. package/src/nx-resident-graph-workers.test.ts +0 -112
  417. package/src/nx-run-information.test.ts +0 -118
  418. package/src/nx-skipped-task-exit.test.ts +0 -180
  419. package/src/nx-state-location.test.ts +0 -63
  420. package/src/nx-store-resolution.test.ts +0 -81
  421. package/src/nx-task-graph-cycles.test.ts +0 -148
  422. package/src/nx-task-output-lease.test.ts +0 -550
  423. package/src/nx-use-local.test.ts +0 -105
  424. package/src/owned-installation.test.ts +0 -105
  425. package/src/package-target-policy.test.ts +0 -1014
  426. package/src/producer-receipts.test.ts +0 -285
  427. package/src/release-config-policy.test.ts +0 -311
  428. package/src/runtime-input.test.ts +0 -393
  429. package/src/serial-group-wiring.test.ts +0 -326
  430. package/src/task-history-namespace.test.ts +0 -181
  431. package/src/task-results.test.ts +0 -228
  432. package/src/test-clock-policy.test.ts +0 -338
  433. package/src/test-program.test.ts +0 -303
  434. package/src/test-timings.test.ts +0 -240
  435. package/src/test-walk-policy.test.ts +0 -620
  436. package/src/testing.test.ts +0 -509
  437. package/src/typecheck-test-policy.test.ts +0 -1468
  438. package/src/typescript-resolution.test.ts +0 -76
  439. package/src/version-actions.test.ts +0 -80
  440. package/src/workspace-config-policy.test.ts +0 -737
@@ -1,800 +0,0 @@
1
- import { afterEach, describe, expect, it } from 'bun:test';
2
- import { spawn, spawnSync } from 'node:child_process';
3
- import { chmod, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
4
- import { createServer, type Socket } from 'node:net';
5
- import { tmpdir } from 'node:os';
6
- import { basename, dirname, join } from 'node:path';
7
- import { fileURLToPath } from 'node:url';
8
- import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from '../../bounded-test-policy.js';
9
- import { CPU_POOL_ENV, type CpuPool, createCpuPool } from './cpu-pool.js';
10
- import { CPU_TOKENS_ENV } from './cpu-tokens.js';
11
- import type { BoundedExecOptions } from './schema.js';
12
- import { VERDICT_FILE } from './verdict.js';
13
-
14
- /**
15
- * The production runner's built Node artifact, run in its own process, with the real RAM volume and CPU-budget owners.
16
- * `test-host` already depends on this package's build; these peers must not compile TypeScript inside a test.
17
- * These proofs need the host (`hdiutil` on darwin), so the pure shards exclude this file.
18
- */
19
- const PACKAGE_ROOT = fileURLToPath(new URL('../../..', import.meta.url));
20
- const EXECUTOR = join(PACKAGE_ROOT, 'dist/executors/bounded-exec/executor.js');
21
-
22
- /**
23
- * Names a child never inherits from the process that starts it: budget markers a bounded-exec parent sets for its
24
- * children, and the fixture socket names `fixtureNxEnv` drops. TMPDIR stays, because each run keeps the RAM volume it
25
- * was admitted to (`specs/cowshed/08_testing.md` 208-212).
26
- */
27
- const WITHHELD_ENV = new Set([CPU_TOKENS_ENV, CPU_POOL_ENV, 'NX_SOCKET_DIR', 'NX_DAEMON_SOCKET_DIR']);
28
-
29
- /** One line the sibling proof's barrier heard: a sibling reporting its start or its end with its granted tokens. */
30
- type SiblingEvent = { readonly kind: 'start' | 'end'; readonly name: string; readonly tokens: number };
31
-
32
- const EVENT = /^(start|end) ([a-z]+) ([0-9]+)$/;
33
-
34
- /** The marker a runner's SIGUSR2 handler prints before the Node resources it still has active, as JSON. */
35
- const ACTIVE_RESOURCES = 'cowshed-test active-resources ';
36
-
37
- /** Churn workers a foreground proof runs beside: two, each cycling one lease at a time. */
38
- const CHURN_NAMES = ['churna', 'churnb'] as const;
39
- /** Written into a case's root to stop its churn workers; each checks it between runs, never mid-run. */
40
- const CHURN_STOP = 'churn.stop';
41
- /**
42
- * One churn run: `true` on one token, so each lease is a real acquire, run and release. Its `timeoutMs` is the leg
43
- * backstop: a run ends on its own exit, and only a hung run reaches the bound (`specs/cowshed/08_testing.md:511-514`).
44
- */
45
- const CHURN_OPTIONS: BoundedExecOptions = { command: 'true', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 1 };
46
- /** A churn worker's stdout: a `begin` line before each run it starts, a `ran` line after each run that succeeded. */
47
- const CHURN_BEGIN = /^cowshed-test churn [a-z]+ begin [0-9]+$/gm;
48
- const CHURN_RAN = /^cowshed-test churn [a-z]+ ran [0-9]+$/gm;
49
- /** The stderr line a run logs when its one token came from the inherited parent pool. */
50
- const INHERITED_GRANT = /inherited=true tokens=1\/1/g;
51
-
52
- interface ChildRun {
53
- /** The script's file name, so an attribution names the case its child ran. */
54
- readonly label: string;
55
- readonly exited: Promise<number | null>;
56
- stdout(): string;
57
- stderr(): string;
58
- /** Whether the child has exited and closed its output streams. */
59
- closed(): boolean;
60
- /**
61
- * Sends SIGUSR2, which a runner answers on stdout with the Node resources it still has active. The answer is in
62
- * `stdout()` once the child has closed, unless the runner exited before its handler ran.
63
- */
64
- askResources(): void;
65
- /** Resolves once `marker` has been printed to stdout; rejects if the child exits without printing it. */
66
- printed(marker: string): Promise<void>;
67
- /** Resolves once `marker` has been written to stderr; rejects if the child exits without writing it. */
68
- said(marker: string): Promise<void>;
69
- /** Stops a surviving runner with SIGTERM, which it forwards to its command's process tree, and awaits its exit. */
70
- stop(): Promise<void>;
71
- }
72
-
73
- interface Barrier {
74
- readonly port: number;
75
- events(): readonly SiblingEvent[];
76
- malformed(): readonly string[];
77
- /**
78
- * Resolves once `ready` holds for the events heard so far; rejects if the barrier failed or heard a malformed line.
79
- */
80
- until(ready: (events: readonly SiblingEvent[]) => boolean): Promise<void>;
81
- go(name: string): void;
82
- close(): Promise<void>;
83
- }
84
-
85
- /** What a foreground proof saw of its churn while its body ran. */
86
- interface Churn<T> {
87
- readonly value: T;
88
- /** Lease attempts in flight at body entry or begun while it ran: traffic sharing the ledger with the foreground. */
89
- readonly begun: number;
90
- readonly workers: readonly ChildRun[];
91
- }
92
-
93
- /** Parent pools a case has opened and not yet closed; afterEach closes what a case left open. */
94
- const pools = new Set<CpuPool>();
95
- /** Barriers a case has opened and not yet closed; afterEach closes what a case left open. */
96
- const barriers = new Set<Barrier>();
97
- const workspaces: string[] = [];
98
- const children = new Set<ChildRun>();
99
-
100
- describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
101
- afterEach(async () => {
102
- // A child still open here was not awaited by its case: the case failed before awaiting it. Its cumulative output is
103
- // written before anything waits, so a kill of the run during the waits below cannot lose it. Each live runner is
104
- // also asked, by SIGUSR2, what Node still has active; the answer lands in its stdout before the child closes.
105
- const live = [...children].filter((child) => !child.closed());
106
- for (const child of live) {
107
- process.stderr.write(attribution(child, 'before teardown'));
108
- child.askResources();
109
- }
110
-
111
- // Pools close first, then every runner still open is stopped: a closed grant never stops a command on its own.
112
- const outcomes = await Promise.all([...pools].map((pool) => pool.close()));
113
- pools.clear();
114
- await Promise.all([...children].map((child) => child.stop()));
115
- for (const child of live) {
116
- process.stderr.write(attribution(child, 'after teardown'));
117
- }
118
- children.clear();
119
- await Promise.all([...barriers].map((barrier) => barrier.close()));
120
- await Promise.all(workspaces.splice(0).map((root) => rm(root, { recursive: true, force: true })));
121
- for (const outcome of outcomes) {
122
- if (!outcome.ok) {
123
- throw new Error(`cpu pool did not close: ${outcome.error}`);
124
- }
125
- }
126
- });
127
-
128
- it('runs a nested command on its parent sub-pool, granting it no more than the sub-pool holds', async () => {
129
- const root = await createRoot();
130
- await withPool(4, async (pool) => {
131
- const leafDirectory = join(root, 'leaf');
132
- const leafScript = await writeRunner(
133
- root,
134
- 'leaf',
135
- { command: `node -e "console.log('leaf')"`, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 1 },
136
- leafDirectory,
137
- );
138
- const nestedDirectory = join(root, 'nested');
139
- const nestedCommand = `node ${JSON.stringify(leafScript)}`;
140
- // Churn draws from this pool beside the nested run. It can delay the nested grant, never widen the pool.
141
- const churn = await withChurn(root, pool.environment, async () => {
142
- const run = await startRunner(
143
- root,
144
- 'nested',
145
- { command: nestedCommand, cwd: PACKAGE_ROOT, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 2 },
146
- nestedDirectory,
147
- childEnv(pool.environment),
148
- );
149
- await run.exited;
150
- return run;
151
- });
152
- const nested = churn.value;
153
- expect(await nested.exited, nested.stderr()).toBe(0);
154
-
155
- // The nested run logs its own grant before its command starts; the leaf's grant reaches the same stderr.
156
- const granted = [...nested.stderr().matchAll(/inherited=true tokens=(\d+)\//g)].map((match) => Number(match[1]));
157
- expect(granted).toHaveLength(2);
158
- const [nestedTokens = 0, leafTokens = 0] = granted;
159
- expect(nestedTokens).toBeGreaterThanOrEqual(1);
160
- expect(leafTokens).toBeGreaterThanOrEqual(1);
161
- expect(leafTokens).toBeLessThanOrEqual(nestedTokens);
162
-
163
- for (const directory of [nestedDirectory, leafDirectory]) {
164
- expect(await readFile(join(directory, VERDICT_FILE), 'utf8')).toMatch(/"inherited":\s*true/);
165
- }
166
- await expectChurn(churn);
167
- });
168
- });
169
-
170
- it('admits five concurrent RAM leases without blocking the lock holder behind filesystem workers', async () => {
171
- const root = await createRoot();
172
- await withPool(1, async (pool) => {
173
- const script = join(root, 'contended.mjs');
174
- await writeFile(
175
- script,
176
- [
177
- `import { runDefaultBoundedExec } from ${JSON.stringify(EXECUTOR)};`,
178
- RESOURCES_HANDLER,
179
- `const options = ${JSON.stringify({
180
- command: `node -e "console.log('lease')"`,
181
- cwd: PACKAGE_ROOT,
182
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
183
- parallelism: 1,
184
- })};`,
185
- `const context = ${JSON.stringify({ root })};`,
186
- 'const results = await Promise.all(Array.from({ length: 5 }, () => runDefaultBoundedExec(options, context)));',
187
- "console.log('leases-complete');",
188
- 'process.exitCode = results.every((result) => result.success) ? 0 : 1;',
189
- '',
190
- ].join('\n'),
191
- );
192
- // Five requests leave four contended opens beside the holder. Blocking opens consume all
193
- // four libuv workers, so even the holder's marker read cannot finish. The one-token pool
194
- // still serializes actual commands: five lease requests are not five runnable commands.
195
- const run = startChild(script, childEnv({ ...pool.environment, UV_THREADPOOL_SIZE: '4' }));
196
- expect(await run.exited, run.stderr()).toBe(0);
197
- expect(run.stdout().match(/^lease$/gm)).toHaveLength(5);
198
- expect(run.stdout()).toContain('leases-complete');
199
- expect([...run.stderr().matchAll(/inherited=true tokens=1\/1/g)]).toHaveLength(5);
200
- });
201
- });
202
-
203
- it('holds a parent pool to its count: three siblings on a pool of two never hold more than two', async () => {
204
- const root = await createRoot();
205
- await withPool(2, async (pool) => {
206
- const barrier = await startBarrier();
207
- try {
208
- // Churn draws from this pool beside the siblings. It can delay a sibling's admission, never widen the pool, so
209
- // the two-token peak below is still the pool's own count.
210
- const churn = await withChurn(root, pool.environment, async () => {
211
- const siblings = await Promise.all(
212
- ['a', 'b', 'c'].map((name) =>
213
- startRunner(
214
- root,
215
- name,
216
- {
217
- command: siblingCommand(barrier.port, name),
218
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
219
- parallelism: 1,
220
- },
221
- join(root, name),
222
- childEnv(pool.environment),
223
- ),
224
- ),
225
- );
226
-
227
- // Two siblings are admitted together and the third waits for a release. Which two is not fixed, so the proof
228
- // releases whichever started first, then every other started sibling in turn.
229
- await barrier.until((events) => namesOf(events, 'start').length >= 2);
230
- const [first = ''] = namesOf(barrier.events(), 'start');
231
- barrier.go(first);
232
- await barrier.until((events) => events.some((event) => event.kind === 'end' && event.name === first));
233
- await barrier.until((events) => namesOf(events, 'start').length >= 3);
234
- const ended = new Set(namesOf(barrier.events(), 'end'));
235
- for (const name of namesOf(barrier.events(), 'start')) {
236
- if (!ended.has(name)) {
237
- barrier.go(name);
238
- }
239
- }
240
- await barrier.until((events) => namesOf(events, 'end').length >= 3);
241
- return siblings;
242
- });
243
- for (const sibling of churn.value) {
244
- expect(await sibling.exited).toBe(0);
245
- }
246
-
247
- const events = barrier.events();
248
- expect(barrier.malformed()).toEqual([]);
249
- expect(namesOf(events, 'start').sort()).toEqual(['a', 'b', 'c']);
250
- expect(namesOf(events, 'end').sort()).toEqual(['a', 'b', 'c']);
251
-
252
- let held = 0;
253
- let peak = 0;
254
- for (const event of events) {
255
- expect(Number.isSafeInteger(event.tokens)).toBe(true);
256
- expect(event.tokens).toBeGreaterThanOrEqual(1);
257
- held += event.kind === 'start' ? event.tokens : -event.tokens;
258
- expect(held).toBeGreaterThanOrEqual(0);
259
- expect(held).toBeLessThanOrEqual(2);
260
- peak = Math.max(peak, held);
261
- }
262
- expect(peak).toBe(2);
263
- expect(held).toBe(0);
264
- await expectChurn(churn);
265
- } finally {
266
- await barrier.close();
267
- }
268
- });
269
- });
270
-
271
- it('uses a real backing budget after its named pool is absent and returns the allocation', async () => {
272
- const root = await createRoot();
273
- const stale = await withPool(1, async (pool) => pool.environment);
274
- await withPool(1, async (outer) => {
275
- const options: BoundedExecOptions = {
276
- command: `node -e "console.log('actual-tokens=' + process.env.${CPU_TOKENS_ENV})"`,
277
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
278
- parallelism: 1,
279
- };
280
- const directory = join(root, 'stale');
281
- const context = { root, record: { task: { id: 'stale', hash: null }, directory } };
282
- const script = join(root, 'stale.mjs');
283
- await writeFile(
284
- script,
285
- [
286
- `import assert from 'node:assert/strict';`,
287
- `import { runBoundedExec, createProcessTreeKiller } from ${JSON.stringify(EXECUTOR)};`,
288
- `import { readInheritedCpuPool, takeParentCpuTokens } from ${JSON.stringify(join(dirname(EXECUTOR), 'cpu-pool.js'))};`,
289
- RESOURCES_HANDLER,
290
- `const backing = readInheritedCpuPool(${JSON.stringify(outer.environment)});`,
291
- `const stale = readInheritedCpuPool(${JSON.stringify({ ...stale, [CPU_TOKENS_ENV]: '977' })});`,
292
- 'assert(backing !== null && stale !== null);',
293
- `const options = ${JSON.stringify(options)};`,
294
- `const context = ${JSON.stringify(context)};`,
295
- 'const asked = [];',
296
- 'const allocations = [];',
297
- 'let released = 0;',
298
- 'const budget = { async take(want, checkout, command) {',
299
- ' asked.push({ want, checkout, command });',
300
- ' const grant = await takeParentCpuTokens(backing, want);',
301
- ' assert(grant.granted, grant.reason);',
302
- ' allocations.push(grant);',
303
- ' return { ...grant, release() { released++; grant.release(); } };',
304
- '} };',
305
- 'const result = await runBoundedExec(options, context, createProcessTreeKiller(), null, budget, stale);',
306
- 'assert(result.success, result.terminalOutput);',
307
- 'assert.deepEqual(asked, [{ want: 1, checkout: context.root, command: options.command }]);',
308
- 'assert.equal(released, 1);',
309
- 'await allocations[0].closed;',
310
- 'const returned = await takeParentCpuTokens(backing, 1);',
311
- 'assert(returned.granted, returned.reason);',
312
- 'assert.equal(returned.tokens, 1);',
313
- 'returned.release();',
314
- 'await returned.closed;',
315
- `console.log('actual-allocation-returned');`,
316
- '',
317
- ].join('\n'),
318
- );
319
- const run = startChild(script, childEnv(outer.environment));
320
- expect(await run.exited, run.stderr()).toBe(0);
321
- expect(run.stderr()).toContain('cowshed: cpu-tokens parent pool refused: ');
322
- expect(run.stderr()).toContain('status=ok inherited=true tokens=1/1');
323
- expect(run.stdout()).toContain('actual-tokens=1');
324
- expect(run.stdout()).toContain('actual-allocation-returned');
325
- expect(run.stdout()).not.toContain('977');
326
- expect(await readFile(join(directory, VERDICT_FILE), 'utf8')).toMatch(/"tokens":\s*1/);
327
- });
328
- });
329
-
330
- it('keeps a command running when its parent pool closes under it, and judges it by its own exit', async () => {
331
- const root = await createRoot();
332
- const go = join(root, 'go.fifo');
333
- expect(spawnSync('mkfifo', [go]).status).toBe(0);
334
- await withPool(2, async (pool) => {
335
- const run = await startRunner(
336
- root,
337
- 'outlives',
338
- {
339
- command: `sh -c 'echo started; read -r line < "$0"; echo finished' '${go}'`,
340
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
341
- killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
342
- parallelism: 1,
343
- },
344
- join(root, 'outlives'),
345
- childEnv(pool.environment),
346
- );
347
- await run.printed('started');
348
- const outcome = await pool.close();
349
- expect(outcome.ok).toBe(true);
350
- await run.said('cowshed: cpu-tokens grant ended: the parent pool closed its 1-token grant');
351
- expect(run.closed()).toBe(false);
352
- await writeFile(go, 'go\n');
353
- expect(await run.exited, run.stderr()).toBe(0);
354
- expect(run.stdout()).toContain('finished');
355
- expect(await readFile(join(root, 'outlives', VERDICT_FILE), 'utf8')).toMatch(/"outcome":\s*"passed"/);
356
- });
357
- });
358
-
359
- it('fails a run whose sub-pool does not close cleanly, even when its command exits 0', async () => {
360
- const root = await createRoot();
361
- let stuck = '';
362
- try {
363
- await withPool(1, async (pool) => {
364
- const unremovable = await startRunner(
365
- root,
366
- 'unremovable',
367
- { command: UNREMOVABLE_COMMAND, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 1 },
368
- join(root, 'unremovable'),
369
- childEnv(pool.environment),
370
- );
371
- expect(await unremovable.exited, unremovable.stderr()).toBe(1);
372
- stuck = unremovable.stdout().trim();
373
- expect(basename(dirname(stuck)).startsWith('cpu-pool-')).toBe(true);
374
- expect(unremovable.stderr()).toContain('cowshed: cpu pool did not close cleanly: ');
375
- const record: unknown = JSON.parse(await readFile(join(root, 'unremovable', VERDICT_FILE), 'utf8'));
376
- expect(record).toHaveProperty('verdict', { outcome: 'failed', exitCode: 1, tests: [] });
377
-
378
- // The failed run gave its one token back, so a sibling on the same one-token pool is admitted.
379
- const next = await startRunner(
380
- root,
381
- 'next',
382
- {
383
- command: `node -e "console.log(process.env.${CPU_TOKENS_ENV})"`,
384
- timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
385
- parallelism: 1,
386
- },
387
- join(root, 'next'),
388
- childEnv(pool.environment),
389
- );
390
- expect(await next.exited, next.stderr()).toBe(0);
391
- expect(next.stderr()).toContain('inherited=true tokens=1/1');
392
- });
393
- } finally {
394
- // The sub-pool's directory is private to it; the pool could not remove `stuck`, so the proof removes it.
395
- if (stuck !== '' && basename(dirname(stuck)).startsWith('cpu-pool-')) {
396
- await chmod(stuck, 0o700);
397
- await rm(dirname(stuck), { recursive: true, force: true });
398
- }
399
- }
400
- });
401
- });
402
-
403
- async function createRoot(): Promise<string> {
404
- const root = await mkdtemp(join(tmpdir(), 'smoothbricks-bounded-exec-host-'));
405
- workspaces.push(root);
406
- return root;
407
- }
408
-
409
- /** The environment a child starts with: this process's, minus the withheld names, plus `extra`. */
410
- function childEnv(extra: Readonly<Record<string, string>>): NodeJS.ProcessEnv {
411
- const env: NodeJS.ProcessEnv = {};
412
- for (const [name, value] of Object.entries(process.env)) {
413
- if (value !== undefined && !WITHHELD_ENV.has(name)) {
414
- env[name] = value;
415
- }
416
- }
417
- return { ...env, ...extra };
418
- }
419
-
420
- /** A parent's CPU pool of `tokens`, open while `body` runs. Its upstream never closes on its own, and no run owns the
421
- * host waits its children report. */
422
- async function withPool<T>(tokens: number, body: (pool: CpuPool) => Promise<T>): Promise<T> {
423
- const created = await createCpuPool(tokens, new Promise<void>(() => {}), { begin() {}, end() {} });
424
- if (!created.ok) {
425
- throw new Error(`cpu pool: ${created.error}`);
426
- }
427
- pools.add(created.pool);
428
- let result: { ok: true; value: T } | { ok: false; error: unknown };
429
- try {
430
- result = { ok: true, value: await body(created.pool) };
431
- } catch (error) {
432
- result = { ok: false, error };
433
- }
434
- const outcome = await created.pool.close();
435
- pools.delete(created.pool);
436
- if (!outcome.ok) {
437
- const failure = new Error(`cpu pool did not close: ${outcome.error}`);
438
- throw result.ok ? failure : new AggregateError([result.error, failure], 'CPU pool body and cleanup failed');
439
- }
440
- if (!result.ok) throw result.error;
441
- return result.value;
442
- }
443
-
444
- /** Installed in each runner first: SIGUSR2 makes it report the Node resources it still has active. Reads only. */
445
- const RESOURCES_HANDLER = [
446
- "process.on('SIGUSR2', () => {",
447
- ' const resources = JSON.stringify(process.getActiveResourcesInfo());',
448
- ` process.stdout.write(${JSON.stringify(ACTIVE_RESOURCES)} + resources + '\\n');`,
449
- '});',
450
- ].join('\n');
451
-
452
- /** Writes a script that runs `options` through the production runner, recording its verdict in `directory`. */
453
- async function writeRunner(
454
- root: string,
455
- name: string,
456
- options: BoundedExecOptions,
457
- directory: string,
458
- ): Promise<string> {
459
- await mkdir(directory, { recursive: true });
460
- const context = { root, record: { task: { id: name, hash: null }, directory } };
461
- const script = join(root, `${name}.mjs`);
462
- await writeFile(
463
- script,
464
- [
465
- `import { runDefaultBoundedExec } from ${JSON.stringify(EXECUTOR)};`,
466
- RESOURCES_HANDLER,
467
- `const result = await runDefaultBoundedExec(${JSON.stringify(options)}, ${JSON.stringify(context)});`,
468
- 'process.exitCode = result.success ? 0 : 1;',
469
- '',
470
- ].join('\n'),
471
- );
472
- return script;
473
- }
474
-
475
- async function startRunner(
476
- root: string,
477
- name: string,
478
- options: BoundedExecOptions,
479
- directory: string,
480
- env: NodeJS.ProcessEnv,
481
- ): Promise<ChildRun> {
482
- return startChild(await writeRunner(root, name, options, directory), env);
483
- }
484
-
485
- /**
486
- * Starts `script` with Node against the exact compiled artifact Nx's executor registration names.
487
- * Stdout and stderr are captured; `exited` resolves once the child has closed both streams.
488
- */
489
- function startChild(script: string, env: NodeJS.ProcessEnv): ChildRun {
490
- const child = spawn('node', [script], {
491
- cwd: PACKAGE_ROOT,
492
- env,
493
- stdio: ['ignore', 'pipe', 'pipe'],
494
- });
495
- let out = '';
496
- let err = '';
497
- let closed = false;
498
- const waiters = new Set<() => void>();
499
- const wake = (): void => {
500
- for (const waiter of [...waiters]) {
501
- waiter();
502
- }
503
- };
504
- child.stdout.on('data', (chunk: Buffer) => {
505
- out += chunk.toString('utf8');
506
- wake();
507
- });
508
- child.stderr.on('data', (chunk: Buffer) => {
509
- err += chunk.toString('utf8');
510
- wake();
511
- });
512
- const exited = new Promise<number | null>((resolve) => {
513
- const done = (code: number | null): void => {
514
- closed = true;
515
- resolve(code);
516
- wake();
517
- };
518
- child.once('error', (error) => {
519
- err += `${error.message}\n`;
520
- done(null);
521
- });
522
- child.once('close', (code) => done(code));
523
- });
524
- const appeared = (text: () => string, marker: string, what: string): Promise<void> => {
525
- const { promise, resolve, reject } = Promise.withResolvers<void>();
526
- const check = (): void => {
527
- if (text().includes(marker)) {
528
- waiters.delete(check);
529
- resolve();
530
- } else if (closed) {
531
- waiters.delete(check);
532
- reject(new Error(`child exited before ${what} ${JSON.stringify(marker)}; stderr:\n${err}`));
533
- }
534
- };
535
- waiters.add(check);
536
- check();
537
- return promise;
538
- };
539
- const run: ChildRun = {
540
- label: basename(script),
541
- exited,
542
- stdout: () => out,
543
- stderr: () => err,
544
- closed: () => closed,
545
- askResources(): void {
546
- child.kill('SIGUSR2');
547
- },
548
- printed: (marker) => appeared(() => out, marker, 'printing'),
549
- said: (marker) => appeared(() => err, marker, 'writing to stderr'),
550
- async stop(): Promise<void> {
551
- if (!closed) child.kill('SIGTERM');
552
- await exited;
553
- },
554
- };
555
- children.add(run);
556
- return run;
557
- }
558
-
559
- /**
560
- * What a runner has printed and written so far, named by its script and the stage it is attributed at. Cumulative and
561
- * untrimmed: a runner still open at teardown says what it was doing, not just that it never finished.
562
- */
563
- function attribution(child: ChildRun, stage: string): string {
564
- return [
565
- `cowshed host proof ${stage}: ${child.label} ${child.closed() ? 'closed' : 'still open'}`,
566
- '--- stdout ---',
567
- child.stdout(),
568
- '--- stderr ---',
569
- child.stderr(),
570
- `--- end ${child.label} ---`,
571
- '',
572
- ].join('\n');
573
- }
574
-
575
- /**
576
- * The sibling's command: report `start NAME TOKENS` to the barrier, wait for `go`, then report `end NAME TOKENS`.
577
- * It is plain `node`, so it needs no preload.
578
- */
579
- function siblingCommand(port: number, name: string): string {
580
- const tokens = `process.env.${CPU_TOKENS_ENV}`;
581
- const script = [
582
- `const s = require('node:net').connect(${port}, '127.0.0.1', () =>`,
583
- `s.write('start ${name} ' + ${tokens} + '\\n'));`,
584
- `let got = ''; s.on('data', (d) => { got += d;`,
585
- `if (got.includes('go\\n')) s.end('end ${name} ' + ${tokens} + '\\n'); });`,
586
- ].join(' ');
587
- return `node -e ${JSON.stringify(script)}`;
588
- }
589
-
590
- /**
591
- * Writes one churn worker: a loop that runs `CHURN_OPTIONS` through the production runner, one lease after another,
592
- * until `stopFile` exists. It prints a `begin` line before each run and a `ran` line after each success, so the parent
593
- * reads its progress from stdout, with no socket and no clock. A failed run exits the worker with the run's output.
594
- */
595
- async function writeChurnWorker(root: string, name: string, stopFile: string): Promise<string> {
596
- const script = join(root, `${name}.mjs`);
597
- await writeFile(
598
- script,
599
- [
600
- "import { existsSync } from 'node:fs';",
601
- `import { runDefaultBoundedExec } from ${JSON.stringify(EXECUTOR)};`,
602
- RESOURCES_HANDLER,
603
- `const options = ${JSON.stringify(CHURN_OPTIONS)};`,
604
- `const context = ${JSON.stringify({ root })};`,
605
- `for (let run = 1; !existsSync(${JSON.stringify(stopFile)}); run += 1) {`,
606
- ` process.stdout.write('cowshed-test churn ${name} begin ' + run + '\\n');`,
607
- ' const result = await runDefaultBoundedExec(options, context);',
608
- ' if (!result.success) {',
609
- ` process.stderr.write('cowshed host proof churn ${name} failed at run ' + run + ':\\n');`,
610
- ' process.stderr.write(result.terminalOutput);',
611
- ' process.exitCode = 1;',
612
- ' break;',
613
- ' }',
614
- ` process.stdout.write('cowshed-test churn ${name} ran ' + run + '\\n');`,
615
- '}',
616
- '',
617
- ].join('\n'),
618
- );
619
- return script;
620
- }
621
-
622
- /**
623
- * Runs `body` beside two churn workers that draw from `poolEnvironment`'s parent pool, so churn competes for the same
624
- * tokens and the same RAM ledger as the foreground. `body` starts only after each worker has completed a run. The
625
- * workers are stopped and awaited before this returns, whatever `body` did, so no assertion sees a live churn child.
626
- */
627
- async function withChurn<T>(
628
- root: string,
629
- poolEnvironment: Readonly<Record<string, string>>,
630
- body: () => Promise<T>,
631
- ): Promise<Churn<T>> {
632
- const stopFile = join(root, CHURN_STOP);
633
- const workers: { readonly name: string; readonly run: ChildRun }[] = [];
634
- try {
635
- for (const name of CHURN_NAMES) {
636
- const script = await writeChurnWorker(root, name, stopFile);
637
- workers.push({ name, run: startChild(script, childEnv(poolEnvironment)) });
638
- }
639
- for (const { name, run } of workers) {
640
- await run.printed(`cowshed-test churn ${name} ran 1`);
641
- }
642
- const marks = workers.map(({ run }) => {
643
- const output = run.stdout();
644
- const inFlight = [...output.matchAll(CHURN_BEGIN)].length - [...output.matchAll(CHURN_RAN)].length;
645
- return { run, mark: output.length, inFlight };
646
- });
647
- const value = await body();
648
- const begun = marks.reduce(
649
- (sum, { run, mark, inFlight }) => sum + inFlight + [...run.stdout().slice(mark).matchAll(CHURN_BEGIN)].length,
650
- 0,
651
- );
652
- return { value, begun, workers: workers.map(({ run }) => run) };
653
- } finally {
654
- await writeFile(stopFile, '');
655
- await Promise.all(workers.map(({ run }) => run.exited));
656
- }
657
- }
658
-
659
- /**
660
- * Asserts, after `withChurn` has returned, that the churn ran on the parent pool and stopped cleanly. Each worker exited
661
- * 0 and completed a run, and logged an inherited grant for every run it completed: no churn run took tokens the fixture
662
- * pool did not hold. At least one lease was in flight at body entry or began while the foreground body was running.
663
- */
664
- async function expectChurn(churn: Churn<unknown>): Promise<void> {
665
- const report = churn.workers.map((worker) => attribution(worker, 'after the churn stopped')).join('\n');
666
- expect(churn.begun, report).toBeGreaterThanOrEqual(1);
667
- for (const worker of churn.workers) {
668
- expect(await worker.exited, report).toBe(0);
669
- const ran = [...worker.stdout().matchAll(CHURN_RAN)];
670
- expect(ran.length, report).toBeGreaterThanOrEqual(1);
671
- expect([...worker.stderr().matchAll(INHERITED_GRANT)], report).toHaveLength(ran.length);
672
- }
673
- }
674
-
675
- /**
676
- * A command that makes its sub-pool's directory unremovable: it creates `stuck` under the pool's private directory,
677
- * puts a file in it, locks it (mode 000), and exits 0. The pool's cleanup cannot enter `stuck`, so its close fails.
678
- */
679
- const UNREMOVABLE_SCRIPT = [
680
- "const fs = require('node:fs');",
681
- "const path = require('node:path');",
682
- "const stuck = path.join(path.dirname(process.env.BOUNDED_EXEC_CPU_POOL), 'stuck');",
683
- "fs.mkdirSync(stuck); fs.writeFileSync(path.join(stuck, 'held'), ''); fs.chmodSync(stuck, 0o000);",
684
- 'console.log(stuck);',
685
- ].join(' ');
686
- const UNREMOVABLE_COMMAND = `node -e ${JSON.stringify(UNREMOVABLE_SCRIPT)}`;
687
-
688
- /** The names of the sibling events of `kind`, in the order the barrier heard them. */
689
- function namesOf(events: readonly SiblingEvent[], kind: SiblingEvent['kind']): string[] {
690
- return events.filter((event) => event.kind === kind).map((event) => event.name);
691
- }
692
-
693
- /**
694
- * A TCP barrier the sibling proof drives. It stamps each sibling event in the order it hears it, so the proof never
695
- * needs a clock: a sibling's `start` and `end` are the only ordering it trusts. A connection error, a server error, or
696
- * a malformed line fails the barrier, and every pending `until` rejects with that failure.
697
- */
698
- function startBarrier(): Promise<Barrier> {
699
- const events: SiblingEvent[] = [];
700
- const malformed: string[] = [];
701
- const sockets = new Map<string, Socket>();
702
- const connections = new Set<Socket>();
703
- const waiters = new Set<() => void>();
704
- let failure: Error | null = null;
705
-
706
- const wake = (): void => {
707
- for (const waiter of [...waiters]) {
708
- waiter();
709
- }
710
- };
711
- const fail = (error: Error): void => {
712
- failure ??= error;
713
- wake();
714
- };
715
- const record = (connection: Socket, line: string): void => {
716
- const match = EVENT.exec(line);
717
- if (match === null) {
718
- malformed.push(line);
719
- fail(new Error(`barrier heard a malformed line: ${JSON.stringify(line)}`));
720
- return;
721
- }
722
- const [, kind = '', name = '', tokens = ''] = match;
723
- if (kind === 'start') {
724
- sockets.set(name, connection);
725
- }
726
- events.push({ kind: kind === 'start' ? 'start' : 'end', name, tokens: Number(tokens) });
727
- wake();
728
- };
729
-
730
- const server = createServer((connection) => {
731
- connections.add(connection);
732
- connection.on('close', () => {
733
- connections.delete(connection);
734
- });
735
- connection.on('error', (error) => {
736
- fail(new Error(`barrier connection failed: ${error.message}`));
737
- });
738
- connection.setEncoding('utf8');
739
- let pending = '';
740
- connection.on('data', (chunk: string) => {
741
- const lines = (pending + chunk).split('\n');
742
- pending = lines.pop() ?? '';
743
- for (const line of lines) {
744
- record(connection, line);
745
- }
746
- });
747
- });
748
- server.on('error', (error) => {
749
- fail(new Error(`barrier server failed: ${error.message}`));
750
- });
751
-
752
- return new Promise<Barrier>((resolve, reject) => {
753
- server.once('error', reject);
754
- server.listen(0, '127.0.0.1', () => {
755
- const address = server.address();
756
- if (address === null || typeof address === 'string') {
757
- reject(new Error('the barrier is not listening on a TCP port'));
758
- return;
759
- }
760
- const barrier: Barrier = {
761
- port: address.port,
762
- events: () => events,
763
- malformed: () => malformed,
764
- until(ready) {
765
- return new Promise<void>((done, rejectUntil) => {
766
- const check = (): void => {
767
- if (failure !== null) {
768
- waiters.delete(check);
769
- rejectUntil(failure);
770
- } else if (ready(events)) {
771
- waiters.delete(check);
772
- done();
773
- }
774
- };
775
- waiters.add(check);
776
- check();
777
- });
778
- },
779
- go(name) {
780
- const socket = sockets.get(name);
781
- if (socket === undefined) {
782
- throw new Error(`sibling ${JSON.stringify(name)} has not reported its start`);
783
- }
784
- socket.write('go\n');
785
- },
786
- close() {
787
- barriers.delete(barrier);
788
- for (const connection of connections) {
789
- connection.destroy();
790
- }
791
- return new Promise<void>((done, rejectClose) => {
792
- server.close((error) => (error === undefined ? done() : rejectClose(error)));
793
- });
794
- },
795
- };
796
- barriers.add(barrier);
797
- resolve(barrier);
798
- });
799
- });
800
- }