@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
package/src/testing.ts CHANGED
@@ -10,13 +10,19 @@
10
10
  * `<parent>/smoothbricks-fixtures/<suite>/run-<pid>`, where the caller names
11
11
  * the parent: the temp directory, or the directory of a volume the fixture has
12
12
  * to lie on. A process that gets SIGTERM, SIGINT or SIGHUP (a bounded test
13
- * leg's timeout sends SIGTERM, and SIGKILL 10 s later) first stops whatever
14
- * still works in every run it holds, then dies of that signal. One killed
15
- * outright cannot, so the first fixture a process creates for a suite under a
16
- * parent reclaims every run of that suite there whose owner is gone: each
17
- * process working in it is stopped, then the run is deleted. A run whose owner
18
- * still exists is never touched by another process, so nothing outside a dead
19
- * or dying run of the same suite is ever signalled.
13
+ * leg's timeout sends SIGTERM, and SIGKILL 10 s later) first names its own
14
+ * descendants that still run and deletes every run it holds, then dies of that
15
+ * signal. One killed outright cannot, so the first fixture a process creates
16
+ * for a suite under a parent deletes every run of that suite there whose owner
17
+ * is gone. A run whose owner still exists is never touched by another process.
18
+ * Nothing is signalled for working in a run: what a fixture left running is
19
+ * ended by the job's supervisor with the test command's subtree (bounded-exec).
20
+ *
21
+ * No helper here reads a process it was not given. Each starts from pids its
22
+ * caller holds (a child it spawned, a daemon's record, this process) and walks
23
+ * down their children, never across the host's process table: any process of
24
+ * the user caught in an uninterruptible kernel wait holds a reader of its
25
+ * files or arguments there with it.
20
26
  *
21
27
  * The module also says where a fixture's sockets and loopback listeners may
22
28
  * live, because a Cowshed sandbox admits only its own: a Unix socket under its
@@ -24,21 +30,21 @@
24
30
  * literal `/tmp/x.sock` or a port-0 listener still binds there, and then no
25
31
  * process of the workspace can reach it (specs/cowshed/04_sandbox.md).
26
32
  *
27
- * Node APIs and the library's public workspace-root finder only: this module
28
- * is built with the library and imported by Bun tests in other packages.
33
+ * Node APIs and the library's own modules only: this module is built with the
34
+ * library and imported by Bun tests in other packages.
29
35
  */
30
- import { execFile } from 'node:child_process';
31
36
  import { createHash } from 'node:crypto';
32
37
  import { lstatSync, readlinkSync, realpathSync, statSync } from 'node:fs';
33
38
  import { lstat, mkdir, mkdtemp, readdir, readFile, readlink, realpath, rm, symlink, writeFile } from 'node:fs/promises';
34
- import { tmpdir, userInfo } from 'node:os';
39
+ import { createServer, type Server } from 'node:net';
40
+ import { tmpdir } from 'node:os';
35
41
  import { dirname, isAbsolute, join, sep } from 'node:path';
36
42
  import { setTimeout as sleep } from 'node:timers/promises';
37
- import { promisify } from 'node:util';
38
43
  import { findNxWorkspaceRoot } from './ensure-built.js';
44
+ import { childPids } from './process-children.js';
45
+ import { listing } from './process-listing.js';
39
46
  import { BOUNDED_TEST_IDLE_TIMEOUT_MS } from './test-backstop.js';
40
47
 
41
- const run = promisify(execFile);
42
48
  /**
43
49
  * How long a stopped process may take to exit when no caller names a grace: the leg's no-progress backstop
44
50
  * (specs/cowshed/08_testing.md), so the exit itself decides and a hung one is the leg's to report. A smaller literal
@@ -46,8 +52,6 @@ const run = promisify(execFile);
46
52
  * 10 s on a loaded gate host and failed teardown of a test that had passed.
47
53
  */
48
54
  const EXIT_TIMEOUT_MS = BOUNDED_TEST_IDLE_TIMEOUT_MS;
49
- /** Under half of the SIGTERM-to-SIGKILL grace a bounded test leg gives, per round of signals. */
50
- const SIGNALLED_GRACE_MS = 3_000;
51
55
  const FIXTURE_HOME = 'smoothbricks-fixtures';
52
56
  const RUN_NAME = /^run-(\d+)$/;
53
57
  const SWEEP_LOCK = 'sweep.lock';
@@ -61,16 +65,31 @@ export interface ProcessEntry {
61
65
  readonly command: string;
62
66
  }
63
67
 
64
- /** Every process on the host, as `ps` lists it on macOS and Linux alike. */
65
- export async function processTable(): Promise<ProcessEntry[]> {
66
- const { stdout } = await run('ps', ['-A', '-o', 'pid=', '-o', 'ppid=', '-o', 'stat=', '-o', 'command='], {
67
- maxBuffer: 64 * 1024 * 1024,
68
- });
68
+ /**
69
+ * The processes among `pids` that still exist, zombies included, as `ps -p` lists them on macOS and Linux alike, in
70
+ * `ps`'s order. Only the named processes are read.
71
+ */
72
+ export async function processesOf(pids: readonly number[]): Promise<ProcessEntry[]> {
73
+ if (pids.length === 0) {
74
+ return [];
75
+ }
76
+ const stdout = await listing('ps', [
77
+ '-o',
78
+ 'pid=',
79
+ '-o',
80
+ 'ppid=',
81
+ '-o',
82
+ 'stat=',
83
+ '-o',
84
+ 'command=',
85
+ '-p',
86
+ pids.join(','),
87
+ ]);
69
88
  return stdout
70
89
  .split('\n')
71
90
  .filter((line) => line.trim() !== '')
72
91
  .map((line) => {
73
- const match = /^\s*(\d+)\s+(\d+)\s+(\S+)\s?(.*)$/.exec(line);
92
+ const match = /^\s*(\d+)\s+(\d+)\s+(\S+)\s*(.*)$/.exec(line);
74
93
  if (match === null) {
75
94
  throw new Error(`Unable to parse ps line: ${line}`);
76
95
  }
@@ -79,6 +98,39 @@ export async function processTable(): Promise<ProcessEntry[]> {
79
98
  });
80
99
  }
81
100
 
101
+ /**
102
+ /**
103
+ * `roots` and every process descending from one, each once, in the order found: generation by generation, each the
104
+ * children `children` lists for the pids the one before added. A pid already found is not walked again, so a reused
105
+ * pid listed as a child of its own descendant ends the walk instead of looping it. The walk reads nothing but
106
+ * `children`, and keeps a root that no longer runs: whoever reads the processes drops it.
107
+ */
108
+ export async function walkTree(
109
+ roots: readonly number[],
110
+ children: (parents: readonly number[]) => Promise<readonly number[]>,
111
+ ): Promise<number[]> {
112
+ const found = new Set<number>();
113
+ for (let generation = roots; generation.length > 0; ) {
114
+ const added = [...new Set(generation)].filter((pid) => !found.has(pid));
115
+ for (const pid of added) {
116
+ found.add(pid);
117
+ }
118
+ generation = added.length === 0 ? [] : await children(added);
119
+ }
120
+ return [...found];
121
+ }
122
+
123
+ /**
124
+ * The processes of `roots` that still exist and every process descending from one, roots first, in the order
125
+ * {@link walkTree} found them. Only those processes are read. A child forked after its parent's children were listed,
126
+ * or reparented away before, is not in it.
127
+ */
128
+ export async function processTree(roots: readonly number[]): Promise<ProcessEntry[]> {
129
+ const order = await walkTree(roots, childPids);
130
+ const listed = new Map((await processesOf(order)).map((entry) => [entry.pid, entry]));
131
+ return order.flatMap((pid) => listed.get(pid) ?? []);
132
+ }
133
+
82
134
  /**
83
135
  * The listed processes among `pids`, and every process descending from one, each once: a pid that
84
136
  * descends from another in `pids` is not listed twice.
@@ -144,7 +196,9 @@ export async function awaitExit(
144
196
  if (performance.now() > deadline) {
145
197
  // A signal probe also answers for a zombie, which has already exited.
146
198
  const live = new Set(
147
- (await processTable()).filter((entry) => !entry.stat.startsWith('Z')).map((entry) => entry.pid),
199
+ (await processesOf(waiting.map((entry) => entry.pid)))
200
+ .filter((entry) => !entry.stat.startsWith('Z'))
201
+ .map((entry) => entry.pid),
148
202
  );
149
203
  const survivors = waiting.filter((entry) => live.has(entry.pid));
150
204
  if (survivors.length === 0) {
@@ -159,113 +213,23 @@ export async function awaitExit(
159
213
  }
160
214
  }
161
215
 
162
- /** Every process of this user whose working directory is `root` or lies beneath it, deleted or not. */
163
- export async function pidsWorkingIn(root: string): Promise<number[]> {
164
- const under = (cwd: string) => cwd === root || cwd.startsWith(`${root}/`);
165
- switch (process.platform) {
166
- case 'linux': {
167
- const found: number[] = [];
168
- for (const pid of (await readdir('/proc')).filter((name) => /^\d+$/.test(name))) {
169
- const cwd = await readlink(`/proc/${pid}/cwd`).catch((error: unknown) => {
170
- // Another user's process, or one that exited since the listing.
171
- if (errorCode(error) === 'EACCES' || errorCode(error) === 'ENOENT' || errorCode(error) === 'ESRCH') {
172
- return null;
173
- }
174
- throw error;
175
- });
176
- if (cwd !== null && under(cwd.replace(/ \(deleted\)$/, ''))) {
177
- found.push(Number(pid));
178
- }
179
- }
180
- return found;
181
- }
182
- case 'darwin': {
183
- // lsof keeps naming a working directory after it has been deleted. It
184
- // exits 1 when a listed process vanished before it was read; what it
185
- // printed for the rest is still the answer.
186
- const fields = await run('/usr/sbin/lsof', ['-nP', '-a', '-d', 'cwd', '-u', String(userInfo().uid), '-Fpn'], {
187
- maxBuffer: 64 * 1024 * 1024,
188
- }).then(
189
- ({ stdout }) => stdout,
190
- (error: unknown) => {
191
- if (error instanceof Error && 'code' in error && error.code === 1 && 'stdout' in error) {
192
- return String(error.stdout);
193
- }
194
- throw error;
195
- },
196
- );
197
- const found: number[] = [];
198
- let pid = 0;
199
- for (const line of fields.split('\n')) {
200
- if (line.startsWith('p')) {
201
- pid = Number(line.slice(1));
202
- } else if (line.startsWith('n') && under(line.slice(1))) {
203
- found.push(pid);
204
- }
205
- }
206
- return found;
207
- }
208
- default:
209
- throw new Error(`No working-directory scan for ${process.platform}`);
210
- }
211
- }
212
-
213
216
  /**
214
- * Every process of this user started with `TMPDIR` set to `root` or beneath it. Such a process
215
- * writes there whatever its working directory: a ttsc plugin build copies its Go sources into
216
- * `$TMPDIR` from a process working in its project, and Node and Bun write their compile cache
217
- * there on the way out. The environment is the one the process was started with, which is the
218
- * one its children inherit unless it changed it for them.
217
+ * This process's descendants that still run, as text for a failure report about `subject`, or null when none does.
218
+ * A process is named as this process's own, never for where it works, and no caller signals anything on its word: a
219
+ * process is ended by the owner that started it, the supervisor's observed tree (specs/cowshed/11_shell.md, "Process
220
+ * identity and signal ownership"). One reparented away when its parent exited is no longer this process's to see. A
221
+ * listing that cannot be read says so instead of failing the report it serves.
219
222
  */
220
- export async function pidsWithTempIn(root: string): Promise<number[]> {
221
- // The value as it follows `TMPDIR=`: `root` itself, with or without its trailing slash, or below it.
222
- const names = (value: string) => value.startsWith(root) && ['', '/', ' '].includes(value.charAt(root.length));
223
- switch (process.platform) {
224
- case 'linux': {
225
- const found: number[] = [];
226
- for (const pid of (await readdir('/proc')).filter((name) => /^\d+$/.test(name))) {
227
- const environ = await readFile(`/proc/${pid}/environ`, 'utf8').catch((error: unknown) => {
228
- // Another user's process, or one that exited since the listing.
229
- if (errorCode(error) === 'EACCES' || errorCode(error) === 'ENOENT' || errorCode(error) === 'ESRCH') {
230
- return null;
231
- }
232
- throw error;
233
- });
234
- const entry = environ?.split('\0').find((variable) => variable.startsWith('TMPDIR='));
235
- if (entry !== undefined && names(entry.slice('TMPDIR='.length))) {
236
- found.push(Number(pid));
237
- }
238
- }
239
- return found;
240
- }
241
- case 'darwin': {
242
- // `ps -E` follows each command line with the environment it was started with, as words
243
- // separated by spaces, and only for this user's processes. A word `TMPDIR=<root>` is matched
244
- // with what follows it in that word, so a root containing a space is still found whole. An
245
- // argument spelled `TMPDIR=<root>` names the same directory and counts too: an `env` that
246
- // sets it is about to run something there. `/bin/ps` by path: a procps `ps` has no `-E`.
247
- const { stdout } = await run('/bin/ps', ['-E', '-ww', '-U', String(userInfo().uid), '-o', 'pid=,command='], {
248
- maxBuffer: 256 * 1024 * 1024,
249
- });
250
- const token = ` TMPDIR=${root}`;
251
- const found: number[] = [];
252
- for (const line of stdout.split('\n')) {
253
- const row = /^\s*(\d+) (.*)$/.exec(line);
254
- if (row === null) {
255
- continue;
256
- }
257
- const words = ` ${row[2]}`;
258
- for (let at = words.indexOf(token); at !== -1; at = words.indexOf(token, at + 1)) {
259
- if (names(words.slice(at + ' TMPDIR='.length))) {
260
- found.push(Number(row[1]));
261
- break;
262
- }
263
- }
264
- }
265
- return found;
266
- }
267
- default:
268
- throw new Error(`No TMPDIR scan for ${process.platform}`);
223
+ export async function descendantsDiagnostic(subject: string): Promise<string | null> {
224
+ try {
225
+ const named = (await processTree([process.pid]))
226
+ .filter((entry) => entry.pid !== process.pid && !entry.stat.startsWith('Z'))
227
+ .map((entry) => `${entry.pid} (${entry.command.slice(0, 160)})`);
228
+ return named.length === 0
229
+ ? null
230
+ : `descendants of this process still run at ${subject}: ${named.join(', ')} (diagnostic only: nothing was signalled)`;
231
+ } catch (error) {
232
+ return `descendants of this process at ${subject} could not be listed: ${error instanceof Error ? error.message : String(error)}`;
269
233
  }
270
234
  }
271
235
 
@@ -296,7 +260,7 @@ export async function nxDaemonProcesses(workspace: string): Promise<ProcessEntry
296
260
  ) {
297
261
  throw new Error(`Nx daemon record ${record} names no process id`);
298
262
  }
299
- return withDescendants(await processTable(), [parsed.processId]);
263
+ return processTree([parsed.processId]);
300
264
  }
301
265
 
302
266
  /**
@@ -307,48 +271,26 @@ export async function nxDaemonProcesses(workspace: string): Promise<ProcessEntry
307
271
  * is free to delete; the processes can. The daemon also leaves what it
308
272
  * spawned to end on its own: plugin workers once they see it gone, the editor
309
273
  * extension probe it starts at launch never. Those get SIGTERM with it, the
310
- * ones it started while it was stopping included. A child that outlives the
311
- * daemon is reparented to init and leaves the daemon's process tree, but it
312
- * still works in the workspace, so the workspace census ends what is left.
313
- * A missing record can mean startup has not published it yet: skip the
314
- * daemon-stop command, but never skip the working-directory census.
274
+ * ones it started while it was stopping included: the daemon's own record
275
+ * names the root, and the walk down its children the rest. A child that
276
+ * outlives the daemon is reparented and leaves that tree; it stays in the
277
+ * tree the job's supervisor observes, which ends it with the test command's
278
+ * subtree (bounded-exec). A missing record can mean startup has not published
279
+ * it yet: then nothing is stopped here.
315
280
  */
316
281
  export async function stopNxDaemon(workspace: string, stop: () => Promise<void>): Promise<void> {
317
282
  const [daemon, ...before] = await nxDaemonProcesses(workspace);
318
- if (daemon !== undefined) {
319
- await stop();
320
- const known = new Set([daemon.pid, ...before.map((entry) => entry.pid)]);
321
- const after = withDescendants(await processTable(), [daemon.pid]).filter((entry) => !known.has(entry.pid));
322
- const spawned = [...before, ...after];
323
- for (const entry of spawned) {
324
- terminate(entry.pid);
325
- }
326
- await awaitExit([daemon, ...spawned], `Nx daemon of ${workspace}`);
283
+ if (daemon === undefined) {
284
+ return;
327
285
  }
328
- await endWorkspaceProcesses(workspace, `Nx processes of ${workspace}`);
329
- }
330
-
331
- /**
332
- * End every process still working in `workspace`, round after round, until a
333
- * census finds none. The daemon has exited by now, so a process can start
334
- * another under the workspace only while it is alive, and a child started
335
- * just before its parent was ended is in the next census. A zombie has
336
- * exited already, and this process never ends itself.
337
- */
338
- async function endWorkspaceProcesses(workspace: string, owner: string): Promise<void> {
339
- for (;;) {
340
- const working = new Set(await pidsWorkingIn(workspace));
341
- const leftovers = (await processTable()).filter(
342
- (entry) => working.has(entry.pid) && entry.pid !== process.pid && !entry.stat.startsWith('Z'),
343
- );
344
- if (leftovers.length === 0) {
345
- return;
346
- }
347
- for (const entry of leftovers) {
348
- terminate(entry.pid);
349
- }
350
- await awaitExit(leftovers, owner);
286
+ await stop();
287
+ const known = new Set([daemon.pid, ...before.map((entry) => entry.pid)]);
288
+ const after = (await processTree([daemon.pid])).filter((entry) => !known.has(entry.pid));
289
+ const spawned = [...before, ...after];
290
+ for (const entry of spawned) {
291
+ terminate(entry.pid);
351
292
  }
293
+ await awaitExit([daemon, ...spawned], `Nx daemon of ${workspace}`);
352
294
  }
353
295
 
354
296
  /**
@@ -428,17 +370,20 @@ function ownRunSignals(): void {
428
370
  * open failed included, and one failing cuts no other short; each failure is
429
371
  * written to stderr with the suite directory of its run. A repeated signal
430
372
  * meets a handler, not the default, so it waits for this and neither starts a
431
- * second reclaim nor kills the first. That wait is the reclaim's own: for each
432
- * run, after any sweep it was still opening with, the scans, two rounds of
433
- * `SIGNALLED_GRACE_MS` (SIGTERM, then SIGKILL) for its processes, and the
434
- * delete. A bounded test leg's SIGKILL ends it whatever it is.
373
+ * second reclaim nor kills the first. That wait is the reclaim's own: the
374
+ * report of this process's descendants still running, then for each run, after
375
+ * any sweep it was still opening with, the delete. What a fixture left running
376
+ * is ended by the job's supervisor with the test command's subtree
377
+ * (bounded-exec), not here. A bounded test leg's SIGKILL ends this whatever it
378
+ * is.
435
379
  */
436
380
  async function retireRuns(signal: NodeJS.Signals): Promise<void> {
381
+ const left = await descendantsDiagnostic(`its ${signal}`);
382
+ if (left !== null) {
383
+ process.stderr.write(`reclaiming this process's fixture runs: ${left}\n`);
384
+ }
437
385
  const runs = [...runDirectories];
438
- // Inside the 10 s a bounded leg grants between SIGTERM and SIGKILL.
439
- const outcomes = await Promise.allSettled(
440
- runs.map(async ([, opened]) => reclaimRun(await opened, 'signalled fixture run', SIGNALLED_GRACE_MS)),
441
- );
386
+ const outcomes = await Promise.allSettled(runs.map(async ([, opened]) => reclaimRun(await opened)));
442
387
  for (const [index, outcome] of outcomes.entries()) {
443
388
  if (outcome.status === 'rejected') {
444
389
  const reason = outcome.reason instanceof Error ? outcome.reason.message : String(outcome.reason);
@@ -458,12 +403,13 @@ function refuseWhileRetiring(): void {
458
403
  }
459
404
 
460
405
  /**
461
- * Stop every process working in a run of `suite` under `parentDirectory` whose
462
- * owner is gone, then delete the run, and return the suite's directory there.
463
- * The first fixture root of a suite under a parent in a process does this; a
464
- * test that just watched a fixture-owning process die may too. An owner's pid
465
- * reused by an unrelated process makes its run look alive; it is reclaimed once
466
- * that process is gone too, never early.
406
+ * Delete every run of `suite` under `parentDirectory` whose owner is gone, and
407
+ * return the suite's directory there. The first fixture root of a suite under a
408
+ * parent in a process does this; a test that just watched a fixture-owning
409
+ * process die may too. An owner's pid reused by an unrelated process makes its
410
+ * run look alive; it is reclaimed once that process is gone too, never early.
411
+ * Nothing still working in a dead run is signalled here: whatever its owner
412
+ * left running belongs to that owner's subtree, which its supervisor retires.
467
413
  */
468
414
  export async function reclaimDeadFixtureRuns(parentDirectory: string, suite: string): Promise<string> {
469
415
  const suiteDirectory = join(await realpath(parentDirectory), FIXTURE_HOME, suite);
@@ -495,46 +441,14 @@ async function reclaimDeadRuns(suiteDirectory: string): Promise<void> {
495
441
  }
496
442
  try {
497
443
  for (const directory of dead) {
498
- await reclaimRun(directory, 'dead fixture run');
444
+ await reclaimRun(directory);
499
445
  }
500
446
  } finally {
501
447
  await rm(lock, { force: true });
502
448
  }
503
449
  }
504
450
 
505
- async function reclaimRun(directory: string, owner: string, graceMs = EXIT_TIMEOUT_MS): Promise<void> {
506
- const roots = await readdir(directory).catch((error: unknown) => {
507
- if (errorCode(error) === 'ENOENT') {
508
- return null;
509
- }
510
- throw error;
511
- });
512
- if (roots === null) {
513
- return;
514
- }
515
- // A fixture deletes its root only once nothing runs in it, so an emptied
516
- // run holds no process and needs no scan.
517
- if (roots.length > 0) {
518
- const working = await pidsWorkingIn(directory);
519
- const processes = (await processTable()).filter((entry) => working.includes(entry.pid));
520
- if (processes.length > 0) {
521
- process.stderr.write(
522
- `reclaiming ${owner} ${directory}: ${processes.map((entry) => `${entry.pid} (${entry.command})`).join(', ')}\n`,
523
- );
524
- for (const entry of processes) {
525
- terminate(entry.pid);
526
- }
527
- try {
528
- await awaitExit(processes, `processes of ${owner} ${directory}`, graceMs);
529
- } catch (error) {
530
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}; sending SIGKILL\n`);
531
- for (const entry of processes) {
532
- terminate(entry.pid, 'SIGKILL');
533
- }
534
- await awaitExit(processes, `processes of ${owner} ${directory} after SIGKILL`, graceMs);
535
- }
536
- }
537
- }
451
+ async function reclaimRun(directory: string): Promise<void> {
538
452
  // A killed fixture may never have reached its own alias retirement, and its
539
453
  // workspace may be gone. The alias is its own record: one whose target is the
540
454
  // socket state of a workspace in this reclaimed run, and whose name is that
@@ -897,7 +811,10 @@ export async function retireFixtureSocketDirectory(workspace: string): Promise<v
897
811
  type PortBlockEnvironment =
898
812
  /** Outside Cowshed, or on Linux: no block, so a listener binds port 0 as usual. */
899
813
  | { readonly kind: 'none' }
900
- /** The gateway listens on `base`; service ports are `base+1 … base+size-1`. */
814
+ /**
815
+ * The gateway listens on `base`. Fixture listeners take the odd offsets `base+1, base+3, … base+size-1`, the
816
+ * service ports; each even offset above `base` is the session port of the service port above it (08_testing.md).
817
+ */
901
818
  | { readonly kind: 'block'; readonly base: number; readonly size: number }
902
819
  | { readonly kind: 'broken'; readonly reason: string };
903
820
 
@@ -949,15 +866,51 @@ function portBlockEnvironment(env: NodeJS.ProcessEnv): PortBlockEnvironment {
949
866
  return { kind: 'block', base, size };
950
867
  }
951
868
 
869
+ /** The block's service ports from `base+first` on, lowest first: its odd offsets (08_testing.md). */
870
+ function servicePorts(block: { readonly base: number; readonly size: number }, first: 1 | 3): number[] {
871
+ const ports: number[] = [];
872
+ for (let offset = first; offset < block.size; offset += 2) ports.push(block.base + offset);
873
+ return ports;
874
+ }
875
+
876
+ /**
877
+ * `bind` on each of `candidates` in turn, and the first that binds. Only `EADDRINUSE` (by `code`) moves on to
878
+ * the next; any other failure is that bind's own and surfaces as is, and so does the last candidate's, so an exhausted
879
+ * block reports `EADDRINUSE`, never a silent port 0.
880
+ */
881
+ async function bindFirstFree<T>(
882
+ block: { readonly base: number; readonly size: number },
883
+ candidates: readonly number[],
884
+ bind: (port: number) => T | Promise<T>,
885
+ ): Promise<T> {
886
+ const last = candidates.at(-1);
887
+ if (last === undefined) {
888
+ throw new Error(`the Cowshed port block ${block.base}+${block.size} has no service port to bind`);
889
+ }
890
+ for (const port of candidates.slice(0, -1)) {
891
+ try {
892
+ return await bind(port);
893
+ } catch (error) {
894
+ if (errorCode(error) !== 'EADDRINUSE') {
895
+ throw error;
896
+ }
897
+ }
898
+ }
899
+ return bind(last);
900
+ }
901
+
952
902
  /**
953
903
  * Bind a real listener where a Cowshed job's other processes can connect to
954
- * it. In a block, `bind` is called with each candidate `base+1 … base+size-1`,
955
- * lowest first (a long-lived test listener scans from the bottom), and the
956
- * first that binds is kept: only a real bind claims a port, so nothing probes
957
- * and closes. Only `EADDRINUSE` (by `code`) moves on to the next candidate;
958
- * any other failure is that bind's own and surfaces as is, and so does the
959
- * last candidate's, so an exhausted block reports `EADDRINUSE`, never a silent
960
- * port 0. Outside a block `bind` is called with 0, and the kernel picks.
904
+ * it. In a block, `bind` is called with each service port `base+1, base+3, …
905
+ * base+size-1`, lowest first (a long-lived test listener scans from the
906
+ * bottom), and the first that binds is kept: only a real bind claims a port, so
907
+ * nothing probes and closes. Even offsets are never candidates: each is the
908
+ * session port of the service port above it, bound by that port's holder or by
909
+ * nobody (08_testing.md), which is what `claimRefusingPort` relies on. Only
910
+ * `EADDRINUSE` (by `code`) moves on to the next candidate; any other failure
911
+ * is that bind's own and surfaces as is, and so does the last candidate's, so an
912
+ * exhausted block reports `EADDRINUSE`, never a silent port 0. Outside a block
913
+ * `bind` is called with 0, and the kernel picks.
961
914
  *
962
915
  * `bind` creates and binds one listener per call and returns it, and a failed
963
916
  * bind leaves nothing behind. It may throw (`Bun.serve` does) or reject (a
@@ -972,18 +925,73 @@ export async function bindListener<T>(bind: (port: number) => T | Promise<T>): P
972
925
  return bind(0);
973
926
  case 'broken':
974
927
  throw new Error(`a listener cannot bind in a broken Cowshed port-block environment: ${block.reason}`);
928
+ case 'block':
929
+ return bindFirstFree(block, servicePorts(block, 1), bind);
930
+ }
931
+ }
932
+
933
+ /**
934
+ * A loopback port where nothing listens. In a port block it stays out of every other fixture's reach while it is held,
935
+ * and disposing it lets it go; outside one nothing claims it, and disposing it does nothing (`claimRefusingPort`).
936
+ */
937
+ export interface RefusingPort extends AsyncDisposable {
938
+ readonly port: number;
939
+ }
940
+
941
+ /** A `net` server on 127.0.0.1:`port` that hangs up on whoever connects; rejects with the bind's own error. */
942
+ function listenHangingUp(port: number): Promise<Server> {
943
+ return new Promise((resolve, reject) => {
944
+ const server = createServer((socket) => socket.destroy());
945
+ server.once('error', reject);
946
+ server.listen(port, '127.0.0.1', () => {
947
+ server.off('error', reject);
948
+ resolve(server);
949
+ });
950
+ });
951
+ }
952
+
953
+ function closeServer(server: Server): Promise<void> {
954
+ return new Promise((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
955
+ }
956
+
957
+ /** The TCP port `server` listens on. */
958
+ function listeningPort(server: Server): number {
959
+ const address = server.address();
960
+ if (address === null || typeof address === 'string') throw new Error(`not a TCP listener: ${String(address)}`);
961
+ return address.port;
962
+ }
963
+
964
+ /**
965
+ * A port where nothing listens, for a client that must be refused (a cache
966
+ * server that is down). In a block it is the session port of a service port
967
+ * this process holds for as long as the claim is held: no allocator binds a
968
+ * session port but its service port's holder (08_testing.md), so a connect to
969
+ * it is refused at once, and no other test's listener takes it while the client
970
+ * is still asking. A port bound and closed would be the next lowest-first
971
+ * allocator's to bind; a socket bound and never listening is no refusal either,
972
+ * since macOS drops the SYNs it gets and the connect times out. The service
973
+ * ports start at `base+3`, because the session port of `base+1` is the
974
+ * gateway's own `base`; a block of two ports has no session port to give.
975
+ *
976
+ * Outside a block (Linux, or no Cowshed) there is no shared allocator to claim
977
+ * against, so there is no claim: the port is one the kernel picked for a
978
+ * listener this process then closed, and another process's port-0 listener may
979
+ * be given it before the client connects.
980
+ */
981
+ export async function claimRefusingPort(): Promise<RefusingPort> {
982
+ const block = portBlockEnvironment(process.env);
983
+ switch (block.kind) {
984
+ case 'none': {
985
+ const server = await listenHangingUp(0);
986
+ const port = listeningPort(server);
987
+ await closeServer(server);
988
+ return { port, [Symbol.asyncDispose]: async () => {} };
989
+ }
990
+ case 'broken':
991
+ throw new Error(`a refusing port cannot be claimed in a broken Cowshed port-block environment: ${block.reason}`);
975
992
  case 'block': {
976
- const last = block.base + block.size - 1;
977
- for (let port = block.base + 1; port < last; port += 1) {
978
- try {
979
- return await bind(port);
980
- } catch (error) {
981
- if (errorCode(error) !== 'EADDRINUSE') {
982
- throw error;
983
- }
984
- }
985
- }
986
- return bind(last);
993
+ const service = await bindFirstFree(block, servicePorts(block, 3), listenHangingUp);
994
+ return { port: listeningPort(service) - 1, [Symbol.asyncDispose]: () => closeServer(service) };
987
995
  }
988
996
  }
989
997
  }