@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,519 +0,0 @@
1
- import { afterEach, describe, expect, it } from 'bun:test';
2
- import { rmSync } from 'node:fs';
3
- import { createServer, type Server, type Socket } from 'node:net';
4
- import { join } from 'node:path';
5
- import { ownedSocketDirectory } from '../../testing.js';
6
- import { CPU_TOKENS_ENV, gatewayCpuBudget, parseInheritedTokens, runnerDemand, sizeRunner } from './cpu-tokens.js';
7
-
8
- const servers: Server[] = [];
9
- const directories: string[] = [];
10
-
11
- afterEach(() => {
12
- for (const server of servers.splice(0)) {
13
- server.close();
14
- }
15
- for (const directory of directories.splice(0)) {
16
- rmSync(directory, { recursive: true, force: true });
17
- }
18
- });
19
-
20
- /**
21
- * A socket path in a directory of its own, made in the socket namespace the sandbox admits for Unix
22
- * sockets: a literal `/tmp` path binds, but no sandboxed process may connect to it, so a client of it
23
- * would see a refusal in place of the absent socket or the gateway the test means.
24
- */
25
- async function socketPath(name: string): Promise<string> {
26
- const directory = await ownedSocketDirectory('cpu-', name);
27
- directories.push(directory);
28
- return join(directory, name);
29
- }
30
-
31
- /** A gateway stand-in on a socket in a directory of its own that runs `serve` per client. */
32
- async function gateway(serve: (client: Socket) => void): Promise<string> {
33
- const socket = await socketPath('gw.sock');
34
- const server = createServer({ allowHalfOpen: true }, serve);
35
- const { promise, resolve, reject } = Promise.withResolvers<void>();
36
- server.once('error', reject);
37
- server.listen(socket, resolve);
38
- await promise;
39
- server.off('error', reject);
40
- servers.push(server);
41
- return socket;
42
- }
43
-
44
- /** The runner command the plugin infers for a nextest piece, as `index.ts` builds it. */
45
- const NEXTEST_PIECE =
46
- `extracted="$(node node_modules/@smoothbricks/nx-plugin/dist/bin/smoo-nx-nextest-extract.js .cache/nextest/archive.tar.zst)" && ` +
47
- `cargo --frozen nextest run --binaries-metadata "$extracted/m.json" --workspace-remap . -E 'package(core)' --partition hash:1/5 --no-tests=pass`;
48
-
49
- /** The test-thread ceilings of a run whose environment names none. */
50
- const NO_CEILINGS = { rust: null, nextest: null };
51
-
52
- describe('cowshed CPU budget client', () => {
53
- it('asks for what each runner would run at once', () => {
54
- expect(runnerDemand(NEXTEST_PIECE, undefined, 18, {})).toEqual({ kind: 'nextest', want: 18 });
55
- expect(runnerDemand('cargo-nextest nextest run --archive-file a.tar.zst', undefined, 12, {})).toEqual({
56
- kind: 'nextest',
57
- want: 12,
58
- });
59
- expect(runnerDemand('cargo nextest run --test-threads=4', undefined, 18, {})).toEqual({ kind: 'nextest', want: 4 });
60
- // `--no-capture` runs tests serially and ignores `--test-threads`: a host smoke of one test asks for one
61
- // token, not one per core it would hold idle while its own scratch jobs queue for the host's tokens.
62
- const smoke =
63
- "cargo --frozen nextest run --archive-file a.tar.zst -E 'test(smoke)' --run-ignored only --no-capture";
64
- expect(runnerDemand(smoke, undefined, 18, {})).toEqual({ kind: 'nextest', want: 1 });
65
- expect(runnerDemand(`${smoke} --test-threads 4`, undefined, 18, {})).toEqual({ kind: 'nextest', want: 1 });
66
- expect(runnerDemand('cargo nextest run -E all() -- --nocapture', undefined, 18, {})).toEqual({
67
- kind: 'nextest',
68
- want: 1,
69
- });
70
- // A flag that only shares the prefix is not it.
71
- expect(runnerDemand('cargo nextest run --no-capture-x', undefined, 18, {})).toEqual({ kind: 'nextest', want: 18 });
72
- // The same words in a cargo build are not nextest's.
73
- expect(runnerDemand('cargo test --workspace -- --nocapture', undefined, 18, {})).toEqual({
74
- kind: 'cargo',
75
- want: 18,
76
- testThreads: NO_CEILINGS,
77
- });
78
- expect(runnerDemand('bun test --timeout=0 --parallel=3', undefined, 18, {})).toEqual({
79
- kind: 'bun-parallel',
80
- want: 3,
81
- });
82
- expect(runnerDemand('bun test --parallel ./a.test.ts', undefined, 18, {})).toEqual({
83
- kind: 'bun-parallel',
84
- want: 18,
85
- });
86
- // A runtime pinned by path is the same runner.
87
- expect(runnerDemand('../bun-runtime/.runtime/bun test --parallel=5', undefined, 18, {})).toEqual({
88
- kind: 'bun-parallel',
89
- want: 5,
90
- });
91
- // One bun process: `test.concurrent` inside it is not another CPU.
92
- expect(runnerDemand('bun test --timeout=0 native.test.ts', undefined, 18, {})).toEqual({
93
- kind: 'process',
94
- want: 1,
95
- testThreads: NO_CEILINGS,
96
- });
97
- expect(runnerDemand('cargo --frozen test --workspace', undefined, 18, {})).toEqual({
98
- kind: 'cargo',
99
- want: 18,
100
- testThreads: NO_CEILINGS,
101
- });
102
- expect(runnerDemand('napi build --platform --release', undefined, 8, {})).toEqual({
103
- kind: 'cargo',
104
- want: 8,
105
- testThreads: NO_CEILINGS,
106
- });
107
- expect(runnerDemand('bun scripts/test-shard.ts 3', undefined, 18, {})).toEqual({
108
- kind: 'process',
109
- want: 1,
110
- testThreads: NO_CEILINGS,
111
- });
112
- // A declared parallelism outranks what the command names, within inherited ceilings.
113
- expect(runnerDemand('bun scripts/test-shard.ts 3', 2, 18, {})).toEqual({
114
- kind: 'process',
115
- want: 2,
116
- testThreads: NO_CEILINGS,
117
- });
118
- expect(runnerDemand('cargo nextest run --test-threads=4', 6, 18, {})).toEqual({ kind: 'nextest', want: 6 });
119
- });
120
-
121
- it("asks for Stryker's --concurrency, else its own default of one worker per core less one past four cores", () => {
122
- expect(runnerDemand('bun stryker run --concurrency 4', undefined, 18, {})).toEqual({ kind: 'stryker', want: 4 });
123
- expect(runnerDemand('bun stryker run -c 6', undefined, 18, {})).toEqual({ kind: 'stryker', want: 6 });
124
- expect(runnerDemand('npx stryker run --concurrency=3', undefined, 18, {})).toEqual({ kind: 'stryker', want: 3 });
125
- expect(runnerDemand('../../node_modules/.bin/stryker run -c 2', undefined, 18, {})).toEqual({
126
- kind: 'stryker',
127
- want: 2,
128
- });
129
- // Stryker takes the last count it is given.
130
- expect(runnerDemand('bun stryker run -c 8 --concurrency 5', undefined, 18, {})).toEqual({
131
- kind: 'stryker',
132
- want: 5,
133
- });
134
- // A share is of the cores, and never less than one worker.
135
- expect(runnerDemand('bun stryker run --concurrency=50%', undefined, 18, {})).toEqual({ kind: 'stryker', want: 9 });
136
- expect(runnerDemand('bun stryker run --concurrency 0%', undefined, 18, {})).toEqual({ kind: 'stryker', want: 1 });
137
- // Stryker's default, which sized nightly 477's sweeps to the whole host: n - 1 past four cores, else n.
138
- expect(runnerDemand('bun stryker run', undefined, 32, {})).toEqual({ kind: 'stryker', want: 31 });
139
- expect(runnerDemand('bun stryker run', undefined, 18, {})).toEqual({ kind: 'stryker', want: 17 });
140
- expect(runnerDemand('bun stryker run', undefined, 4, {})).toEqual({ kind: 'stryker', want: 4 });
141
- // Another command's `-c` in the same line is not Stryker's.
142
- expect(runnerDemand('ulimit -c 0 && bun stryker run', undefined, 18, {})).toEqual({ kind: 'stryker', want: 17 });
143
- expect(runnerDemand('bun stryker run && nice -c 3 true', undefined, 18, {})).toEqual({ kind: 'stryker', want: 17 });
144
- // A declared parallelism outranks the flag.
145
- expect(runnerDemand('bun stryker run --concurrency 8', 2, 18, {})).toEqual({ kind: 'stryker', want: 2 });
146
- // A test file named for Stryker is one bun process.
147
- expect(runnerDemand('bun test stryker.test.ts', undefined, 18, {})).toEqual({
148
- kind: 'process',
149
- want: 1,
150
- testThreads: NO_CEILINGS,
151
- });
152
- });
153
-
154
- it("asks for Vitest's --maxWorkers and go test's -p, else each runner's own per-core default", () => {
155
- // Vitest outside watch mode runs one worker per core less one.
156
- expect(runnerDemand('bun vitest run', undefined, 18, {})).toEqual({ kind: 'vitest', want: 17 });
157
- expect(runnerDemand('bun vitest run --config vitest.config.workers.ts', undefined, 18, {})).toEqual({
158
- kind: 'vitest',
159
- want: 17,
160
- });
161
- expect(runnerDemand('bun vitest run --maxWorkers=4', undefined, 18, {})).toEqual({ kind: 'vitest', want: 4 });
162
- expect(runnerDemand('vitest run --max-workers 50%', undefined, 18, {})).toEqual({ kind: 'vitest', want: 9 });
163
- expect(runnerDemand('bun vitest run --no-file-parallelism', undefined, 18, {})).toEqual({
164
- kind: 'vitest',
165
- want: 1,
166
- });
167
- // `go test -p` defaults to GOMAXPROCS, normally one per core.
168
- expect(runnerDemand('go test -count=1 ./hts/... ./host/...', undefined, 18, {})).toEqual({
169
- kind: 'go-test',
170
- want: 18,
171
- });
172
- expect(runnerDemand('cd go/ttscwire && go test ./...', undefined, 18, { GOMAXPROCS: '4' })).toEqual({
173
- kind: 'go-test',
174
- want: 4,
175
- });
176
- expect(runnerDemand('go test -p 3 -parallel 8 ./...', undefined, 18, {})).toEqual({ kind: 'go-test', want: 3 });
177
- // A shell word that is no count leaves the runner's default; it is still sized by the grant.
178
- expect(runnerDemand('bun ../scripts/gen-go-work.mjs && go test ./... -p="$(nproc)"', undefined, 18, {})).toEqual({
179
- kind: 'go-test',
180
- want: 18,
181
- });
182
- });
183
-
184
- it("asks for cargo-mutants' own jobserver, one task per core unless --jobserver-tasks names fewer", () => {
185
- // The plugin's inferred `mutation` command, with no flag: `--jobs` defaults to one cargo process, but its
186
- // jobserver defaults to one task per core (`n_tasks=<cores>`), shared by every cargo that process starts.
187
- expect(runnerDemand('cargo --frozen mutants --workspace', undefined, 18, {})).toEqual({
188
- kind: 'cargo-mutants',
189
- want: 18,
190
- jobs: 1,
191
- });
192
- // `--jobs` counts cargo processes, which still share that per-core jobserver.
193
- expect(runnerDemand('cargo mutants --jobs 4', undefined, 18, {})).toEqual({
194
- kind: 'cargo-mutants',
195
- want: 18,
196
- jobs: 4,
197
- });
198
- expect(runnerDemand('cargo mutants --jobserver-tasks 4', undefined, 18, {})).toEqual({
199
- kind: 'cargo-mutants',
200
- want: 4,
201
- jobs: 1,
202
- });
203
- expect(runnerDemand('cargo mutants -j2 --jobserver-tasks=4', undefined, 18, {})).toEqual({
204
- kind: 'cargo-mutants',
205
- want: 4,
206
- jobs: 2,
207
- });
208
- // Each cargo process runs at least one thread, whatever the jobserver allows.
209
- expect(runnerDemand('cargo mutants --jobs=6 --jobserver-tasks 4', undefined, 18, {})).toEqual({
210
- kind: 'cargo-mutants',
211
- want: 6,
212
- jobs: 6,
213
- });
214
- // `CARGO_MUTANTS_JOBS` as the command will see it: the target's own environment over the inherited one.
215
- expect(runnerDemand('cargo mutants --jobserver-tasks 4', undefined, 18, { CARGO_MUTANTS_JOBS: '3' })).toEqual({
216
- kind: 'cargo-mutants',
217
- want: 4,
218
- jobs: 3,
219
- });
220
- expect(
221
- runnerDemand(
222
- 'cargo mutants --jobserver-tasks 4',
223
- undefined,
224
- 18,
225
- { CARGO_MUTANTS_JOBS: '3' },
226
- { CARGO_MUTANTS_JOBS: '2' },
227
- ),
228
- ).toEqual({ kind: 'cargo-mutants', want: 4, jobs: 2 });
229
- expect(runnerDemand('cargo-mutants mutants --in-diff pr.diff', undefined, 12, {})).toEqual({
230
- kind: 'cargo-mutants',
231
- want: 12,
232
- jobs: 1,
233
- });
234
- // Another command's `-j` in the same line is not cargo-mutants'.
235
- expect(runnerDemand('cargo mutants --jobserver-tasks 4 && make -j 9', undefined, 18, {})).toEqual({
236
- kind: 'cargo-mutants',
237
- want: 4,
238
- jobs: 1,
239
- });
240
- expect(runnerDemand('cargo mutants', 3, 18, {})).toEqual({ kind: 'cargo-mutants', want: 3, jobs: 1 });
241
- // A package named `mutants` is an ordinary cargo build.
242
- expect(runnerDemand('cargo test -p mutants', undefined, 18, {})).toEqual({
243
- kind: 'cargo',
244
- want: 18,
245
- testThreads: NO_CEILINGS,
246
- });
247
- });
248
-
249
- it('sizes the worker-flag runners and cargo-mutants to their grant', () => {
250
- expect(sizeRunner({ kind: 'stryker', want: 17 }, 'bun stryker run', 4)).toEqual({
251
- command: 'bun stryker run --concurrency=4',
252
- env: { [CPU_TOKENS_ENV]: '4' },
253
- });
254
- expect(sizeRunner({ kind: 'stryker', want: 8 }, 'bun stryker run -c 8 --fileLogLevel off', 3).command).toBe(
255
- 'bun stryker run --concurrency=3 --fileLogLevel off',
256
- );
257
- expect(
258
- sizeRunner({ kind: 'stryker', want: 8 }, 'ulimit -c 0 && bun stryker run --concurrency 8 && echo done', 2)
259
- .command,
260
- ).toBe('ulimit -c 0 && bun stryker run --concurrency=2 && echo done');
261
- // A grant larger than the ask sizes to the ask.
262
- expect(sizeRunner({ kind: 'stryker', want: 4 }, 'bun stryker run --concurrency=4', 9).command).toBe(
263
- 'bun stryker run --concurrency=4',
264
- );
265
- expect(sizeRunner({ kind: 'cargo-mutants', want: 18, jobs: 1 }, 'cargo --frozen mutants --workspace', 5)).toEqual({
266
- command: 'cargo --frozen mutants --jobserver-tasks=5 --workspace',
267
- env: { [CPU_TOKENS_ENV]: '5', CARGO_BUILD_JOBS: '5', RUST_TEST_THREADS: '5', NEXTEST_TEST_THREADS: '5' },
268
- });
269
- // Its cargo processes share the grant: each tests on its share, and there are never more of them than tokens.
270
- expect(
271
- sizeRunner({ kind: 'cargo-mutants', want: 18, jobs: 4 }, 'cargo mutants --jobs 4 --jobserver-tasks 18', 8),
272
- ).toEqual({
273
- command: 'cargo mutants --jobs=4 --jobserver-tasks=8',
274
- env: {
275
- [CPU_TOKENS_ENV]: '8',
276
- CARGO_MUTANTS_JOBS: '4',
277
- CARGO_BUILD_JOBS: '2',
278
- RUST_TEST_THREADS: '2',
279
- NEXTEST_TEST_THREADS: '2',
280
- },
281
- });
282
- expect(sizeRunner({ kind: 'cargo-mutants', want: 18, jobs: 4 }, 'cargo mutants -j4', 2)).toEqual({
283
- command: 'cargo mutants --jobserver-tasks=2 --jobs=2',
284
- env: {
285
- [CPU_TOKENS_ENV]: '2',
286
- CARGO_MUTANTS_JOBS: '2',
287
- CARGO_BUILD_JOBS: '1',
288
- RUST_TEST_THREADS: '1',
289
- NEXTEST_TEST_THREADS: '1',
290
- },
291
- });
292
- // `--jobs` is never added: cargo-mutants refuses it beside `--in-place`.
293
- expect(sizeRunner({ kind: 'cargo-mutants', want: 18, jobs: 1 }, 'cargo mutants --in-place', 3).command).toBe(
294
- 'cargo mutants --jobserver-tasks=3 --in-place',
295
- );
296
- expect(sizeRunner({ kind: 'vitest', want: 17 }, 'bun vitest run --config vitest.config.workers.ts', 3)).toEqual({
297
- command: 'bun vitest run --maxWorkers=3 --config vitest.config.workers.ts',
298
- env: { [CPU_TOKENS_ENV]: '3' },
299
- });
300
- expect(sizeRunner({ kind: 'vitest', want: 4 }, 'bun vitest run --maxWorkers 4', 2).command).toBe(
301
- 'bun vitest run --maxWorkers=2',
302
- );
303
- expect(
304
- sizeRunner({ kind: 'go-test', want: 18 }, 'bun ../scripts/gen-go-work.mjs && go test ./... -p="$(nproc)"', 4)
305
- .command,
306
- ).toBe('bun ../scripts/gen-go-work.mjs && go test ./... -p=4');
307
- expect(sizeRunner({ kind: 'go-test', want: 18 }, 'cd go/ttscwire && go test ./...', 2).command).toBe(
308
- 'cd go/ttscwire && go test -p=2 ./...',
309
- );
310
- });
311
-
312
- it('sizes each runner to its grant', () => {
313
- expect(sizeRunner({ kind: 'nextest', want: 18 }, NEXTEST_PIECE, 5)).toEqual({
314
- command: NEXTEST_PIECE,
315
- env: { [CPU_TOKENS_ENV]: '5', NEXTEST_TEST_THREADS: '5' },
316
- });
317
- expect(sizeRunner({ kind: 'nextest', want: 16 }, 'cargo nextest run --test-threads 16 -E all()', 3).command).toBe(
318
- 'cargo nextest run --test-threads=3 -E all()',
319
- );
320
- expect(sizeRunner({ kind: 'bun-parallel', want: 3 }, 'bun test --parallel=3 --timeout=1', 2)).toEqual({
321
- command: 'bun test --parallel=2 --timeout=1',
322
- env: { [CPU_TOKENS_ENV]: '2' },
323
- });
324
- expect(sizeRunner({ kind: 'bun-parallel', want: 18 }, 'bun test --parallel', 7).command).toBe(
325
- 'bun test --parallel=7',
326
- );
327
- // Cargo's rustc count is its pool's jobserver fifo, never a `CARGO_BUILD_JOBS` from the grant; its test threads
328
- // take no token, so they are sized here, libtest's and nextest's alike.
329
- expect(sizeRunner({ kind: 'cargo', want: 18, testThreads: NO_CEILINGS }, 'cargo test', 4).env).toEqual({
330
- [CPU_TOKENS_ENV]: '4',
331
- RUST_TEST_THREADS: '4',
332
- NEXTEST_TEST_THREADS: '4',
333
- });
334
- expect(sizeRunner({ kind: 'process', want: 1, testThreads: NO_CEILINGS }, 'bun scripts/x.ts', 1)).toEqual({
335
- command: 'bun scripts/x.ts',
336
- env: { [CPU_TOKENS_ENV]: '1', RUST_TEST_THREADS: '1', NEXTEST_TEST_THREADS: '1' },
337
- });
338
- });
339
-
340
- it("sizes a process's test threads to its held grant, under inherited and configured ceilings", () => {
341
- // A script's own `cargo test` takes rustc tokens from the executor's jobserver fifo, but its test threads take
342
- // none, so the executor sets them to the whole grant the process holds.
343
- const unbounded = runnerDemand('bun scripts/x.ts', 5, 18, {});
344
- expect(unbounded).toEqual({ kind: 'process', want: 5, testThreads: NO_CEILINGS });
345
- expect(sizeRunner(unbounded, 'bun scripts/x.ts', 5)).toEqual({
346
- command: 'bun scripts/x.ts',
347
- env: { [CPU_TOKENS_ENV]: '5', RUST_TEST_THREADS: '5', NEXTEST_TEST_THREADS: '5' },
348
- });
349
- const capped = runnerDemand(
350
- 'bun scripts/x.ts',
351
- 5,
352
- 18,
353
- { RUST_TEST_THREADS: '4', NEXTEST_TEST_THREADS: '3' },
354
- { RUST_TEST_THREADS: '2', NEXTEST_TEST_THREADS: '64' },
355
- );
356
- // A configured count lowers an inherited ceiling and never raises it.
357
- expect(capped).toEqual({ kind: 'process', want: 5, testThreads: { rust: 2, nextest: 3 } });
358
- expect(sizeRunner(capped, 'bun scripts/x.ts', 5).env).toEqual({
359
- [CPU_TOKENS_ENV]: '5',
360
- RUST_TEST_THREADS: '2',
361
- NEXTEST_TEST_THREADS: '3',
362
- });
363
- });
364
-
365
- it('treats inherited runner bounds as ceilings even under larger grants', () => {
366
- const inherited = { NEXTEST_TEST_THREADS: '6', CARGO_BUILD_JOBS: '4', RUST_TEST_THREADS: '2' };
367
- const configured = { NEXTEST_TEST_THREADS: '64', CARGO_BUILD_JOBS: '64', RUST_TEST_THREADS: '64' };
368
- const nextest = runnerDemand('cargo nextest run --test-threads=18', 18, 18, inherited, configured);
369
- const cargo = runnerDemand('cargo test', 18, 18, inherited, configured);
370
- expect(nextest).toEqual({ kind: 'nextest', want: 6 });
371
- expect(cargo).toEqual({ kind: 'cargo', want: 4, testThreads: { rust: 2, nextest: 6 } });
372
- for (const tokens of [15, 18]) {
373
- expect(sizeRunner(nextest, 'cargo nextest run --test-threads=18', tokens)).toEqual({
374
- command: 'cargo nextest run --test-threads=6',
375
- env: { [CPU_TOKENS_ENV]: String(tokens), NEXTEST_TEST_THREADS: '6' },
376
- });
377
- expect(sizeRunner(cargo, 'cargo test', tokens).env).toEqual({
378
- [CPU_TOKENS_ENV]: String(tokens),
379
- RUST_TEST_THREADS: '2',
380
- NEXTEST_TEST_THREADS: '4',
381
- });
382
- }
383
- expect(sizeRunner(nextest, NEXTEST_PIECE, 3).env.NEXTEST_TEST_THREADS).toBe('3');
384
- expect(sizeRunner(cargo, 'cargo test', 3).env).toEqual({
385
- [CPU_TOKENS_ENV]: '3',
386
- RUST_TEST_THREADS: '2',
387
- NEXTEST_TEST_THREADS: '3',
388
- });
389
- expect(runnerDemand(NEXTEST_PIECE, 18, 18, inherited, { NEXTEST_TEST_THREADS: '2' }).want).toBe(2);
390
- expect(runnerDemand('cargo build', 18, 18, {}, { CARGO_BUILD_JOBS: '4' }).want).toBe(4);
391
- expect(runnerDemand(NEXTEST_PIECE, 18, 18, { NEXTEST_TEST_THREADS: '0' }).want).toBe(18);
392
- });
393
-
394
- it('reads an inherited count only as a positive safe integer', () => {
395
- expect(parseInheritedTokens(undefined)).toBeNull();
396
- for (const invalid of ['', '0', '-1', '1.5', '2e3', '0x10', ' 3', '3 ', '03', 'three', '9007199254740993']) {
397
- expect(parseInheritedTokens(invalid)).toBeNull();
398
- }
399
- expect(parseInheritedTokens('1')).toBe(1);
400
- expect(parseInheritedTokens('16')).toBe(16);
401
- expect(parseInheritedTokens(String(Number.MAX_SAFE_INTEGER))).toBe(Number.MAX_SAFE_INTEGER);
402
- });
403
-
404
- it('reads back the count a runner was sized to', () => {
405
- expect(
406
- parseInheritedTokens(
407
- sizeRunner({ kind: 'process', want: 5, testThreads: NO_CEILINGS }, 'bun scripts/x.ts', 5).env[CPU_TOKENS_ENV],
408
- ),
409
- ).toBe(5);
410
- });
411
-
412
- it('asks the gateway with one line, takes the granted count, and holds until released', async () => {
413
- const { promise: request, resolve: requested } = Promise.withResolvers<string>();
414
- const { promise: closed, resolve: close } = Promise.withResolvers<void>();
415
- const socket = await gateway((client) => {
416
- client.once('data', (chunk) => {
417
- requested(chunk.toString('utf8'));
418
- client.write('{"ok":true,"lease":"queued"}\n{"ok":true,"lease":"granted","tokens":6}\n');
419
- });
420
- // The gateway takes a lease back when it reads EOF. With allowHalfOpen the socket stays open
421
- // after the peer closes until the server ends it, so 'close' is not that signal on Linux.
422
- client.on('end', () => close());
423
- });
424
- const grant = await gatewayCpuBudget(socket).take(18, '/w/one', 'cargo nextest run');
425
- expect(JSON.parse(await request)).toEqual({
426
- op: 'cpu-tokens',
427
- want: 18,
428
- checkout: '/w/one',
429
- command: 'cargo nextest run',
430
- });
431
- expect(grant.granted && grant.tokens).toBe(6);
432
- if (grant.granted) {
433
- grant.release();
434
- // The client's side of the connection really closed, not merely its release call.
435
- await grant.closed;
436
- }
437
- await closed;
438
- });
439
-
440
- it('closes a granted lease when the gateway ends the connection', async () => {
441
- const socket = await gateway((client) => {
442
- client.once('data', () => {
443
- client.write('{"ok":true,"lease":"queued"}\n{"ok":true,"lease":"granted","tokens":2}\n');
444
- client.end();
445
- });
446
- });
447
- const grant = await gatewayCpuBudget(socket).take(2, '/w', 'x');
448
- if (!grant.granted) {
449
- throw new Error(grant.reason);
450
- }
451
- await grant.closed;
452
- });
453
-
454
- it('runs unbudgeted, said as absent, when no gateway listens', async () => {
455
- const grant = await gatewayCpuBudget(await socketPath('none.sock')).take(4, '/w', 'x');
456
- expect(grant.granted === false && grant.cause).toBe('absent');
457
- });
458
-
459
- it('recognizes a gateway that does not know the operation as predating the budget', async () => {
460
- const socket = await gateway((client) => {
461
- client.once('data', () =>
462
- client.end(
463
- '{"ok":false,"code":"invalid-request","error":"gateway control encoding failed: unknown gateway control operation"}\n',
464
- ),
465
- );
466
- });
467
- const grant = await gatewayCpuBudget(socket).take(4, '/w', 'x');
468
- expect(grant).toEqual({
469
- granted: false,
470
- cause: 'predates',
471
- reason:
472
- 'the gateway predates the CPU budget (invalid-request: gateway control encoding failed: unknown gateway control operation); restart it with `cowshed setup`',
473
- });
474
- });
475
-
476
- it('refuses a grant larger than it asked for', async () => {
477
- const socket = await gateway((client) => {
478
- client.once('data', () =>
479
- client.write('{"ok":true,"lease":"queued"}\n{"ok":true,"lease":"granted","tokens":9}\n'),
480
- );
481
- });
482
- const grant = await gatewayCpuBudget(socket).take(4, '/w', 'x');
483
- expect(grant).toEqual({ granted: false, cause: 'other', reason: 'the gateway granted 9 tokens for 4' });
484
- });
485
-
486
- it('returns a grant when the process holding it is killed mid-leg', async () => {
487
- const { promise: closed, resolve: close } = Promise.withResolvers<void>();
488
- const { promise: granted, resolve: grant } = Promise.withResolvers<void>();
489
- const socket = await gateway((client) => {
490
- client.once('data', () => {
491
- client.write('{"ok":true,"lease":"queued"}\n{"ok":true,"lease":"granted","tokens":2}\n');
492
- grant();
493
- });
494
- client.on('end', () => close());
495
- });
496
- // The holder is its own process so SIGKILL is a real death. Its script imports the module by
497
- // path because `bun -e` has no module of its own to import from statically; the held lease's
498
- // open socket is what keeps it alive.
499
- const holder = Bun.spawn(
500
- [
501
- process.execPath,
502
- '-e',
503
- `const { gatewayCpuBudget } = await import(${JSON.stringify(new URL('./cpu-tokens.ts', import.meta.url).pathname)});
504
- const grant = await gatewayCpuBudget(${JSON.stringify(socket)}).take(2, '/w', 'leg');
505
- if (!grant.granted) process.exit(3);
506
- console.log('holding');`,
507
- ],
508
- { stdout: 'pipe', stderr: 'inherit' },
509
- );
510
- await granted;
511
- const reader = holder.stdout.getReader();
512
- const { value } = await reader.read();
513
- expect(new TextDecoder().decode(value)).toContain('holding');
514
- holder.kill('SIGKILL');
515
- await holder.exited;
516
- // The gateway sees the connection close, which is how it takes the tokens back.
517
- await closed;
518
- });
519
- });