@smoothbricks/nx-plugin 0.5.7 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (432) hide show
  1. package/README.md +1086 -360
  2. package/dist/.build-inputs.json +138 -0
  3. package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
  4. package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
  6. package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
  7. package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
  9. package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
  10. package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-nextest-timings.js +28 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +14 -15
  15. package/dist/build-state-output-policy.d.ts +95 -1
  16. package/dist/build-state-output-policy.d.ts.map +1 -1
  17. package/dist/build-state-output-policy.js +368 -30
  18. package/dist/bun-lock-scope.d.ts +44 -0
  19. package/dist/bun-lock-scope.d.ts.map +1 -0
  20. package/dist/bun-lock-scope.js +97 -0
  21. package/dist/cargo-build-script-env.d.ts +49 -0
  22. package/dist/cargo-build-script-env.d.ts.map +1 -0
  23. package/dist/cargo-build-script-env.js +324 -0
  24. package/dist/cargo-closure-input.d.ts +31 -4
  25. package/dist/cargo-closure-input.d.ts.map +1 -1
  26. package/dist/cargo-closure-input.js +66 -6
  27. package/dist/cargo-retention-hook.d.ts +17 -0
  28. package/dist/cargo-retention-hook.d.ts.map +1 -0
  29. package/dist/cargo-retention-hook.js +85 -0
  30. package/dist/cargo-source-hash.d.ts +25 -7
  31. package/dist/cargo-source-hash.d.ts.map +1 -1
  32. package/dist/cargo-source-hash.js +108 -43
  33. package/dist/cargo-toolchain-paths.d.ts +40 -0
  34. package/dist/cargo-toolchain-paths.d.ts.map +1 -0
  35. package/dist/cargo-toolchain-paths.js +84 -0
  36. package/dist/cargo-toolchain-policy.d.ts +25 -8
  37. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  38. package/dist/cargo-toolchain-policy.js +39 -5
  39. package/dist/cargo-workspace.d.ts +10 -4
  40. package/dist/cargo-workspace.d.ts.map +1 -1
  41. package/dist/cargo-workspace.js +65 -95
  42. package/dist/cross-check-policy.d.ts +9 -9
  43. package/dist/cross-check-policy.d.ts.map +1 -1
  44. package/dist/cross-check-policy.js +11 -11
  45. package/dist/disk-command-policy.d.ts.map +1 -1
  46. package/dist/disk-command-policy.js +1 -0
  47. package/dist/ensure-built-receipt.d.ts +13 -5
  48. package/dist/ensure-built-receipt.d.ts.map +1 -1
  49. package/dist/ensure-built-receipt.js +126 -47
  50. package/dist/ensure-built-witness.d.ts +27 -8
  51. package/dist/ensure-built-witness.d.ts.map +1 -1
  52. package/dist/ensure-built-witness.js +45 -15
  53. package/dist/ensure-built.d.ts.map +1 -1
  54. package/dist/ensure-built.js +9 -1
  55. package/dist/eslint-config-closure.d.ts +7 -0
  56. package/dist/eslint-config-closure.d.ts.map +1 -0
  57. package/dist/eslint-config-closure.js +346 -0
  58. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  59. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  60. package/dist/executors/bounded-exec/bounds.js +43 -0
  61. package/dist/executors/bounded-exec/cpu-pool.d.ts +33 -36
  62. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  63. package/dist/executors/bounded-exec/cpu-pool.js +54 -119
  64. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  65. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  66. package/dist/executors/bounded-exec/executor.js +371 -239
  67. package/dist/executors/bounded-exec/gateway-lease.d.ts +22 -19
  68. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/gateway-lease.js +81 -28
  70. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  71. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  73. package/dist/executors/bounded-exec/lease-wait.d.ts +43 -0
  74. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  75. package/dist/executors/bounded-exec/lease-wait.js +68 -0
  76. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  77. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  78. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  79. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  80. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  82. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  83. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  84. package/dist/executors/bounded-exec/progress.js +5 -2
  85. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  86. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  88. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  89. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  90. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  91. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  92. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  93. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  94. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  95. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  96. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  97. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +4 -4
  98. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/run-cpu-pool.js +20 -30
  100. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  101. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  102. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  103. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  104. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  105. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  106. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  107. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  108. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  109. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  110. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  111. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  112. package/dist/executors/bounded-exec/verdict.d.ts +40 -11
  113. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  114. package/dist/executors/bounded-exec/verdict.js +88 -19
  115. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  116. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  117. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  118. package/dist/executors/clean-outputs/executor.js +1 -0
  119. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  120. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  121. package/dist/executors/scriptc-native/executor.js +367 -0
  122. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  123. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  124. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  125. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  126. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/schema.js +1 -0
  128. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  129. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  130. package/dist/executors/typescript-emit/executor.js +164 -33
  131. package/dist/forbidden-spelling-policy.d.ts +56 -0
  132. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  133. package/dist/forbidden-spelling-policy.js +176 -0
  134. package/dist/generators/create-package/generator.d.ts.map +1 -1
  135. package/dist/generators/create-package/generator.js +3 -4
  136. package/dist/graph-input-contract.d.ts +14 -0
  137. package/dist/graph-input-contract.d.ts.map +1 -1
  138. package/dist/graph-input-contract.js +67 -2
  139. package/dist/index.d.ts +23 -6
  140. package/dist/index.d.ts.map +1 -1
  141. package/dist/index.js +672 -214
  142. package/dist/managed-assets.d.ts +2 -0
  143. package/dist/managed-assets.d.ts.map +1 -1
  144. package/dist/managed-files/files.d.ts +3 -3
  145. package/dist/managed-files/files.d.ts.map +1 -1
  146. package/dist/managed-files/files.js +28 -3
  147. package/dist/managed-files/managed-format.d.ts.map +1 -1
  148. package/dist/managed-files/managed-format.js +1 -0
  149. package/dist/nextest-code-bound.js +1 -0
  150. package/dist/nextest-timings.d.ts +35 -0
  151. package/dist/nextest-timings.d.ts.map +1 -0
  152. package/dist/nextest-timings.js +168 -0
  153. package/dist/owned-installation.d.ts +6 -5
  154. package/dist/owned-installation.d.ts.map +1 -1
  155. package/dist/owned-installation.js +150 -26
  156. package/dist/package-target-policy.d.ts.map +1 -1
  157. package/dist/package-target-policy.js +2 -3
  158. package/dist/process-children.d.ts +7 -0
  159. package/dist/process-children.d.ts.map +1 -0
  160. package/dist/process-children.darwin.d.ts +7 -0
  161. package/dist/process-children.darwin.d.ts.map +1 -0
  162. package/dist/process-children.darwin.js +13 -0
  163. package/dist/process-children.js +14 -0
  164. package/dist/process-children.linux.d.ts +8 -0
  165. package/dist/process-children.linux.d.ts.map +1 -0
  166. package/dist/process-children.linux.js +25 -0
  167. package/dist/process-group.d.ts +108 -0
  168. package/dist/process-group.d.ts.map +1 -0
  169. package/dist/process-group.js +171 -0
  170. package/dist/process-listing.d.ts +7 -0
  171. package/dist/process-listing.d.ts.map +1 -0
  172. package/dist/process-listing.js +51 -0
  173. package/dist/producer-receipts.d.ts +8 -2
  174. package/dist/producer-receipts.d.ts.map +1 -1
  175. package/dist/producer-receipts.js +75 -48
  176. package/dist/task-graph-policy.d.ts +21 -0
  177. package/dist/task-graph-policy.d.ts.map +1 -0
  178. package/dist/task-graph-policy.js +91 -0
  179. package/dist/test-timings.js +4 -4
  180. package/dist/test-walk-policy.d.ts +14 -5
  181. package/dist/test-walk-policy.d.ts.map +1 -1
  182. package/dist/test-walk-policy.js +8 -2
  183. package/dist/testing.d.ts +73 -28
  184. package/dist/testing.d.ts.map +1 -1
  185. package/dist/testing.js +217 -223
  186. package/dist/tool-bins.d.ts +33 -0
  187. package/dist/tool-bins.d.ts.map +1 -0
  188. package/dist/tool-bins.js +72 -0
  189. package/dist/typecheck-test-policy.d.ts.map +1 -1
  190. package/dist/typecheck-test-policy.js +3 -4
  191. package/dist/wait-why-policy.d.ts +28 -0
  192. package/dist/wait-why-policy.d.ts.map +1 -0
  193. package/dist/wait-why-policy.js +223 -0
  194. package/dist/workspace-config-policy.d.ts +14 -8
  195. package/dist/workspace-config-policy.d.ts.map +1 -1
  196. package/dist/workspace-config-policy.js +60 -16
  197. package/dist/workspace-manifest.d.ts +41 -6
  198. package/dist/workspace-manifest.d.ts.map +1 -1
  199. package/dist/workspace-manifest.js +57 -0
  200. package/executors.json +16 -1
  201. package/loader.js +2 -0
  202. package/managed/raw/envrc +11 -0
  203. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  204. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  205. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  206. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  207. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  208. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  209. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  210. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  211. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  212. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  213. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  214. package/managed/raw/tooling/direnv/repo-path +68 -6
  215. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  216. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  217. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  218. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  219. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  220. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  221. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  222. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  223. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  224. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  225. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  226. package/package.json +77 -13
  227. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  228. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  229. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  230. package/src/bounded-test-policy.ts +12 -14
  231. package/src/build-state-output-policy.ts +458 -34
  232. package/src/bun-lock-scope.ts +108 -0
  233. package/src/cargo-build-script-env.ts +265 -0
  234. package/src/cargo-closure-input.ts +74 -7
  235. package/src/cargo-retention-hook.ts +94 -0
  236. package/src/cargo-source-hash.ts +138 -41
  237. package/src/cargo-toolchain-paths.ts +95 -0
  238. package/src/cargo-toolchain-policy.ts +49 -5
  239. package/src/cargo-workspace.ts +72 -123
  240. package/src/cross-check-policy.ts +12 -10
  241. package/src/disk-command-policy.ts +1 -0
  242. package/src/ensure-built-receipt.ts +132 -39
  243. package/src/ensure-built-witness.ts +62 -10
  244. package/src/ensure-built.ts +11 -1
  245. package/src/eslint-config-closure.ts +357 -0
  246. package/src/executors/bounded-exec/bounds.ts +76 -0
  247. package/src/executors/bounded-exec/cpu-pool.ts +51 -117
  248. package/src/executors/bounded-exec/executor.ts +423 -259
  249. package/src/executors/bounded-exec/gateway-lease.ts +82 -33
  250. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  251. package/src/executors/bounded-exec/lease-wait.ts +89 -0
  252. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  253. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  254. package/src/executors/bounded-exec/progress.ts +9 -3
  255. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  256. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  257. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  258. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  259. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  260. package/src/executors/bounded-exec/run-cpu-pool.ts +22 -30
  261. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  262. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  263. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  264. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  265. package/src/executors/bounded-exec/schema.json +11 -2
  266. package/src/executors/bounded-exec/schema.ts +19 -1
  267. package/src/executors/bounded-exec/verdict.ts +137 -34
  268. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  269. package/src/executors/clean-outputs/executor.ts +1 -0
  270. package/src/executors/scriptc-native/executor.ts +394 -0
  271. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  272. package/src/executors/scriptc-native/schema.json +60 -0
  273. package/src/executors/scriptc-native/schema.ts +34 -0
  274. package/src/executors/typescript-emit/executor.ts +205 -38
  275. package/src/forbidden-spelling-policy.ts +226 -0
  276. package/src/generators/create-package/generator.ts +7 -7
  277. package/src/graph-input-contract.ts +61 -2
  278. package/src/index.ts +788 -224
  279. package/src/managed-assets.ts +3 -0
  280. package/src/managed-files/files.ts +28 -3
  281. package/src/managed-files/managed-format.ts +1 -0
  282. package/src/nextest-code-bound.ts +1 -0
  283. package/src/nextest-timings.ts +106 -0
  284. package/src/owned-installation.ts +150 -23
  285. package/src/package-target-policy.ts +2 -3
  286. package/src/process-children.darwin.ts +14 -0
  287. package/src/process-children.linux.ts +33 -0
  288. package/src/process-children.ts +22 -0
  289. package/src/process-group.ts +209 -0
  290. package/src/process-listing.ts +54 -0
  291. package/src/producer-receipts.ts +68 -45
  292. package/src/task-graph-policy.ts +98 -0
  293. package/src/test-walk-policy.ts +23 -8
  294. package/src/testing.ts +240 -232
  295. package/src/tool-bins.ts +108 -0
  296. package/src/typecheck-test-policy.ts +2 -3
  297. package/src/wait-why-policy.ts +226 -0
  298. package/src/workspace-config-policy.ts +63 -15
  299. package/src/workspace-manifest.ts +89 -6
  300. package/test-timings.json +122 -98
  301. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  302. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  303. package/dist/bin/smoo-nx-failures.js +0 -3
  304. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  305. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  306. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  307. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  308. package/dist/failure-summary.d.ts +0 -5
  309. package/dist/failure-summary.d.ts.map +0 -1
  310. package/dist/failure-summary.js +0 -118
  311. package/dist/nextest-extraction.d.ts +0 -117
  312. package/dist/nextest-extraction.d.ts.map +0 -1
  313. package/dist/nextest-extraction.js +0 -303
  314. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  315. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  316. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  317. package/src/__tests__/counted-cargo-process.ts +0 -286
  318. package/src/__tests__/counted-cargo.ts +0 -713
  319. package/src/__tests__/directory-change.ts +0 -27
  320. package/src/__tests__/fixture-cargo-home.ts +0 -36
  321. package/src/__tests__/fixture-nx-env.ts +0 -193
  322. package/src/__tests__/owned-installation.ts +0 -13
  323. package/src/__tests__/past-tick.ts +0 -12
  324. package/src/__tests__/progress-clock.ts +0 -43
  325. package/src/__tests__/runtime-input.ts +0 -23
  326. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  327. package/src/bin/smoo-nx-failures.ts +0 -4
  328. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  329. package/src/bounded-test-policy.test.ts +0 -1029
  330. package/src/build-state-output-policy.test.ts +0 -115
  331. package/src/bun-bootstrap.test.ts +0 -102
  332. package/src/bun-file-packages.test.ts +0 -47
  333. package/src/cargo-closure-filesets.test.ts +0 -63
  334. package/src/cargo-closure-input.property.test.ts +0 -50
  335. package/src/cargo-closure-input.test.ts +0 -506
  336. package/src/cargo-closure-key.test.ts +0 -240
  337. package/src/cargo-resolve-cache.test.ts +0 -1181
  338. package/src/cargo-source-hash.test.ts +0 -707
  339. package/src/cargo-workspace.test.ts +0 -615
  340. package/src/cross-check-policy.test.ts +0 -316
  341. package/src/disk-command-policy.test.ts +0 -61
  342. package/src/ensure-built-receipt.test.ts +0 -279
  343. package/src/ensure-built-witness.test.ts +0 -688
  344. package/src/ensure-built.test.ts +0 -1462
  345. package/src/executors/all-verdicts/executor.test.ts +0 -135
  346. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  347. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  348. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  349. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  350. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  351. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  352. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  353. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  354. package/src/executors/bounded-exec/progress.test.ts +0 -139
  355. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  356. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  357. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  358. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  359. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  360. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  361. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  362. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  363. package/src/executors/clean-outputs/executor.test.ts +0 -20
  364. package/src/executors/typescript-emit/executor.test.ts +0 -83
  365. package/src/failure-summary.ts +0 -119
  366. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  367. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  368. package/src/generators/create-package/generator.test.ts +0 -190
  369. package/src/generators/make-public/generator.test.ts +0 -137
  370. package/src/graph-input-contract.test.ts +0 -379
  371. package/src/host-controller-wiring.test.ts +0 -31
  372. package/src/index.test.ts +0 -3321
  373. package/src/linked-snapshots.nx.test.ts +0 -254
  374. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  375. package/src/managed-files/generator.test.ts +0 -243
  376. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  377. package/src/managed-files/json-edit.test.ts +0 -216
  378. package/src/managed-files/managed-content.test.ts +0 -166
  379. package/src/managed-files/managed-format-json.test.ts +0 -308
  380. package/src/managed-files/repo-path.test.ts +0 -172
  381. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  382. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  383. package/src/managed-files/tree-permissions.test.ts +0 -109
  384. package/src/managed-files/tree.test.ts +0 -123
  385. package/src/manifest-hash.test.ts +0 -219
  386. package/src/nextest-code-bound.test.ts +0 -161
  387. package/src/nextest-extraction.test.ts +0 -216
  388. package/src/nextest-extraction.ts +0 -371
  389. package/src/nextest-partitions.test.ts +0 -501
  390. package/src/nx-cache-bound.test.ts +0 -109
  391. package/src/nx-cache-restore-mtime.test.ts +0 -170
  392. package/src/nx-daemon-claim.test.ts +0 -279
  393. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  394. package/src/nx-daemon-idle-policy.test.ts +0 -111
  395. package/src/nx-daemon-ignore-files.test.ts +0 -210
  396. package/src/nx-daemon-root-normalization.test.ts +0 -105
  397. package/src/nx-daemon-start-never.test.ts +0 -292
  398. package/src/nx-daemon-validity.test.ts +0 -1055
  399. package/src/nx-dot-input-policy.test.ts +0 -353
  400. package/src/nx-failure-life-cycles.test.ts +0 -207
  401. package/src/nx-files-archive-racy.test.ts +0 -97
  402. package/src/nx-foreign-workspace-env.test.ts +0 -329
  403. package/src/nx-incomplete-run-summary.test.ts +0 -70
  404. package/src/nx-plugin-load-errors.test.ts +0 -120
  405. package/src/nx-project-graph-errors.test.ts +0 -70
  406. package/src/nx-project-resolution-cache.test.ts +0 -176
  407. package/src/nx-raw-inputs.test.ts +0 -166
  408. package/src/nx-resident-graph-workers.test.ts +0 -112
  409. package/src/nx-run-information.test.ts +0 -118
  410. package/src/nx-skipped-task-exit.test.ts +0 -180
  411. package/src/nx-state-location.test.ts +0 -63
  412. package/src/nx-store-resolution.test.ts +0 -81
  413. package/src/nx-task-graph-cycles.test.ts +0 -148
  414. package/src/nx-task-output-lease.test.ts +0 -550
  415. package/src/nx-use-local.test.ts +0 -105
  416. package/src/owned-installation.test.ts +0 -105
  417. package/src/package-target-policy.test.ts +0 -1014
  418. package/src/producer-receipts.test.ts +0 -285
  419. package/src/release-config-policy.test.ts +0 -311
  420. package/src/runtime-input.test.ts +0 -393
  421. package/src/serial-group-wiring.test.ts +0 -326
  422. package/src/task-history-namespace.test.ts +0 -181
  423. package/src/task-results.test.ts +0 -228
  424. package/src/test-clock-policy.test.ts +0 -338
  425. package/src/test-program.test.ts +0 -303
  426. package/src/test-timings.test.ts +0 -240
  427. package/src/test-walk-policy.test.ts +0 -620
  428. package/src/testing.test.ts +0 -509
  429. package/src/typecheck-test-policy.test.ts +0 -1468
  430. package/src/typescript-resolution.test.ts +0 -76
  431. package/src/version-actions.test.ts +0 -80
  432. package/src/workspace-config-policy.test.ts +0 -737
@@ -1,750 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { execFileSync, spawn } from 'node:child_process';
3
- import { once } from 'node:events';
4
- import { mkdirSync, mkdtempSync, readdirSync, realpathSync, rmSync } from 'node:fs';
5
- import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
6
- import { createServer, type Socket } from 'node:net';
7
- import { tmpdir } from 'node:os';
8
- import { join } from 'node:path';
9
- import { createInterface } from 'node:readline';
10
- import { whenChanged } from '../../__tests__/directory-change.js';
11
- import { BOUNDED_TEST_IDLE_TIMEOUT_MS } from '../../bounded-test-policy.js';
12
- import { awaitExit, ownedSocketDirectory, pidsWorkingIn, processTable, terminate } from '../../testing.js';
13
- import {
14
- COWSHED_EXECUTABLE_ENV,
15
- createHostCommands,
16
- diskCommand,
17
- hostLeaseProcesses,
18
- imagesBackedUnder,
19
- leaseProcessesOn,
20
- mountsBelow,
21
- operationDisk,
22
- RAM_TEMP_CAPACITY_BYTES,
23
- RamTempVolume,
24
- ramDisksIn,
25
- ramTempPaths,
26
- } from './ram-temp.js';
27
- import { registryDevice } from './ram-temp-fixtures.js';
28
-
29
- describe('RAM temp volume output parsing', () => {
30
- it('names the disk diskutil apfs reports it created', () => {
31
- const container =
32
- 'Creating APFS Container\nCreated new APFS Container disk271\nDisk from APFS operation: disk271\nFinished APFS operation on disk270\n';
33
- expect(operationDisk(container)).toBe('disk271');
34
- expect(operationDisk('Exporting new APFS Volume\nDisk from APFS operation: disk271s1\n')).toBe('disk271s1');
35
- expect(operationDisk('Error: -69808\n')).toBeNull();
36
- });
37
-
38
- it('lists the RAM disks hdiutil info reports, with their user, size and mountpoints', () => {
39
- const info = [
40
- 'framework : 683.160.3',
41
- 'driver : 683.160.3',
42
- 'images : 3',
43
- '================================================',
44
- 'image-path : /private/cowshed/store/x/main.asif',
45
- 'mounting user : example',
46
- 'framework name : DiskImages2',
47
- '/dev/disk10\t\t',
48
- '/dev/disk11\tEF57347C-0000-11AA-AA11-00306543ECAC\t',
49
- '/dev/disk11s1\t41504653-0000-11AA-AA11-00306543ECAC\t/Users/example/checkout',
50
- '================================================',
51
- 'image-path : ram://16777216',
52
- 'image-type : read/write',
53
- 'blockcount : 16777216',
54
- 'mounting user : example',
55
- 'mounting mode : <unknown>',
56
- 'process ID : 91006',
57
- 'framework name : DiskImages',
58
- '/dev/disk138\t\t',
59
- '/dev/disk139\tEF57347C-0000-11AA-AA11-00306543ECAC\t',
60
- '/dev/disk139s1\t41504653-0000-11AA-AA11-00306543ECAC\t/Volumes/smoo-ram-502 1',
61
- '================================================',
62
- 'image-path : ram://16777216',
63
- 'mounting user : root',
64
- '/dev/disk159\t\t',
65
- '',
66
- ].join('\n');
67
- expect(ramDisksIn(info)).toEqual([
68
- { physical: '/dev/disk138', sectors: 16777216, user: 'example', mountpoints: ['/Volumes/smoo-ram-502 1'] },
69
- { physical: '/dev/disk159', sectors: 16777216, user: 'root', mountpoints: [] },
70
- ]);
71
- });
72
-
73
- it('finds only the images whose backing file is on the volume', () => {
74
- const registry = [
75
- ...registryDevice('file:///private/tmp/smoo-ram-501/501-a1b2c3/store/main%20copy.asif', 'disk280'),
76
- ...registryDevice('file:///private/tmp/smoo-ram-5010/x.asif', 'disk281'),
77
- ...registryDevice('ram://134217728', 'disk270'),
78
- ].join('\n');
79
- expect(imagesBackedUnder(registry, '/private/tmp/smoo-ram-501/')).toEqual([
80
- '/private/tmp/smoo-ram-501/501-a1b2c3/store/main copy.asif (/dev/disk280)',
81
- ]);
82
- });
83
-
84
- it('finds the mounts that would make removing a lease delete through them', () => {
85
- const table = [
86
- '/dev/disk3s1s1 on / (apfs, sealed, local, read-only, journaled)',
87
- '/dev/disk271s1 on /private/tmp/smoo-ram-501 (apfs, local, nodev, nosuid, journaled, noowners, nobrowse)',
88
- '/dev/disk290s1 on /private/tmp/smoo-ram-501/501-a1b2c3/checkout (apfs, local, nobrowse, mounted by example)',
89
- '/dev/disk291s1 on /private/tmp/smoo-ram-501/501-a1b2c3x/other (apfs, local)',
90
- ].join('\n');
91
- expect(mountsBelow(table, '/private/tmp/smoo-ram-501/501-a1b2c3/')).toEqual([
92
- '/private/tmp/smoo-ram-501/501-a1b2c3/checkout',
93
- ]);
94
- });
95
-
96
- it('mounts where DiskArbitration puts it, short enough to hold sockets', () => {
97
- // sun_path is 104 bytes; a lease directory leaves room for nested fixture paths.
98
- expect(ramTempPaths({ uid: 501, username: 'ada' })).toEqual({
99
- mountpoint: '/Volumes/smoo-ram2-501',
100
- lockFile: '/private/tmp/smoo-ram2-501.lock',
101
- volumeName: 'smoo-ram2-501',
102
- staging: '/private/tmp/smoo-ram2-501-new',
103
- user: 'ada',
104
- });
105
- });
106
-
107
- it("never shares a volume or a RAM disk size with revision 1's checkouts", () => {
108
- // Revision 1 used /Volumes/smoo-ram-<uid> and ram://16777216; a creator's stray reclaim matches
109
- // user and size, so equal sizes would let either revision detach the other's attaching disk.
110
- expect(RAM_TEMP_CAPACITY_BYTES / 512).toBe(16777218);
111
- });
112
- });
113
-
114
- /** A real facade boundary: owns a detached stand-in, kills only SAFE children, and waits for reap.
115
- * The control socket gates facade exit after reap; protected output stays in owned files.
116
- */
117
- async function ownedDiskFacadeFixture() {
118
- const directory = await ownedSocketDirectory('rt-', 'facade.sock');
119
- const socketPath = join(directory, 'facade.sock');
120
- const executable = join(directory, 'cowshed');
121
- const server = createServer();
122
- const connected = new Promise<Socket>((resolve) => server.once('connection', resolve));
123
- await new Promise<void>((resolve, reject) => {
124
- server.once('error', reject);
125
- server.listen(socketPath, resolve);
126
- });
127
- const session = connected.then((socket) => ({
128
- socket,
129
- lines: createInterface({ input: socket })[Symbol.asyncIterator](),
130
- }));
131
- let facadePid: number | undefined;
132
- await writeFile(
133
- executable,
134
- `#!${process.execPath}\n` +
135
- "import { spawn } from 'node:child_process';\nimport { once } from 'node:events';\nimport { closeSync, openSync } from 'node:fs';\nimport { createConnection } from 'node:net';\nimport { dirname, join } from 'node:path';\nimport { createInterface } from 'node:readline';\n\nconst startedAt = performance.now();\nconst argv = process.argv.slice(2);\nconst control = createConnection(argv.at(-1));\nawait once(control, 'connect');\nconst tool = argv[1];\nconst safe = argv[2] === '--deadline-ms';\nconst budget = safe ? Number(argv[3]) : undefined;\nconst native = argv.slice(safe ? 5 : 3);\nconst image = tool === 'hdiutil' || (tool === 'diskutil' && (native[0] === 'image' || native[0] === 'eject'));\nif (argv[0] !== 'disk-command' || (tool !== 'hdiutil' && tool !== 'diskutil') ||\n argv[safe ? 4 : 2] !== '--' || safe === image ||\n (safe && (!Number.isSafeInteger(budget) || budget <= 0))) {\n control.end('invalid facade request\\n');\n process.exitCode = 2;\n} else {\n const mode = native[1];\n const tail = mode === 'exit' ? 'exit 7' : mode === 'signal' ? 'kill -TERM $$' : 'exec sleep 600';\n const files = image ? [openSync(join(dirname(argv.at(-1)), 'stdout'), 'w'), openSync(join(dirname(argv.at(-1)), 'stderr'), 'w')] : [];\n const child = spawn('/bin/sh', ['-c', 'printf \"owned stdout\\\\n\"; printf \"owned stderr\\\\n\" >&2; printf ready >&3; ' + tail], {\n detached: true,\n stdio: ['ignore', files[0] ?? 'pipe', files[1] ?? 'pipe', 'pipe'],\n });\n for (const fd of files) closeSync(fd);\n const ended = once(child, 'close');\n if (!image) {\n child.stdout.on('data', (chunk) => process.stdout.write(chunk));\n child.stderr.on('data', (chunk) => process.stderr.write(chunk));\n }\n let release;\n const finished = new Promise((resolve) => { release = resolve; });\n let reaped = false;\n const commands = createInterface({ input: control });\n commands.on('line', (line) => {\n if (line === 'cleanup') {\n if (!reaped && child.exitCode === null && child.signalCode === null) process.kill(-child.pid, 'SIGKILL');\n release();\n } else if (line === 'finish') {\n release();\n } else if (line === 'inspect') {\n process.kill(child.pid, 0);\n control.write('custody ' + child.pid + '\\n');\n }\n });\n let expired = false;\n const timer = safe ? setTimeout(() => {\n expired = true;\n control.write('deadline ' + budget + '\\n');\n process.kill(-child.pid, 'SIGKILL');\n }, Math.max(0, budget - (performance.now() - startedAt))) : undefined;\n const ready = await new Promise((resolve) => {\n child.stdio[3].once('data', () => resolve(true));\n child.stdio[3].once('end', () => resolve(false));\n child.stdio[3].once('error', () => resolve(false));\n });\n if (!ready) throw new Error('owned child ended before readiness');\n control.write('started ' + process.pid + ' ' + child.pid + '\\n');\n const [code, signal] = await ended;\n reaped = true;\n clearTimeout(timer);\n control.write('reaped ' + child.pid + ' ' + code + ' ' + signal + '\\n');\n if (expired) process.stderr.write('owned child ' + child.pid + ' terminated by ' + signal + ' and reaped after ' + budget + ' ms deadline\\n');\n await finished;\n commands.close();\n control.end();\n await once(control, 'close');\n if (mode === 'signal') process.kill(process.pid, 'SIGTERM');\n else process.exitCode = expired ? 1 : code ?? 1;\n}\n",
136
- { mode: 0o755 },
137
- );
138
- async function event(): Promise<string> {
139
- const { lines } = await session;
140
- const next = await lines.next();
141
- if (next.done) throw new Error('owned disk facade closed before the expected event');
142
- return next.value;
143
- }
144
- return {
145
- directory,
146
- executable,
147
- socketPath,
148
- event,
149
- async started() {
150
- const line = await event();
151
- const match = /^started (\d+) (\d+)$/.exec(line);
152
- if (match === null) throw new Error(`owned disk facade did not start its child: ${line}`);
153
- facadePid = Number(match[1]);
154
- return Number(match[2]);
155
- },
156
- async send(command: 'finish' | 'inspect') {
157
- const { socket } = await session;
158
- socket.write(`${command}\n`);
159
- },
160
- async cleanup() {
161
- try {
162
- const { socket } = await session;
163
- if (!socket.destroyed) {
164
- const closed = once(socket, 'close');
165
- socket.write('cleanup\n');
166
- await closed;
167
- }
168
- if (facadePid !== undefined) {
169
- await awaitExit(
170
- [{ pid: facadePid, ppid: process.pid, stat: 'S', command: executable }],
171
- 'owned disk facade cleanup',
172
- );
173
- }
174
- } finally {
175
- await new Promise<void>((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
176
- rmSync(directory, { recursive: true, force: true });
177
- }
178
- },
179
- };
180
- }
181
-
182
- describe('RAM temp volume on this host', () => {
183
- it('kills a deadlined command together with everything it spawned', async () => {
184
- // Ordinary helpers remain deadline-bound; disk-image tools are owned by cowshed instead. The command never answers:
185
- // its shell opens `lifetime`, hands it to a background `tail -f /dev/null` that never ends on its own, closes its
186
- // own copy and only then prints the tail's pid. So only the deadline ends the run, a printed pid means the FIFO
187
- // has a writer, and EOF on it is that descendant's death. The bound returns once it has signalled the group, not
188
- // once the kernel has torn it down, so a `ps` read straight after raced the kill (Linux CI saw it still running).
189
- const directory = mkdtempSync(join(realpathSync(tmpdir()), 'deadline-group-'));
190
- try {
191
- const lifetime = join(directory, 'lifetime.fifo');
192
- execFileSync('mkfifo', [lifetime]);
193
- const ended = readFile(lifetime, 'utf8');
194
- const result = await createHostCommands(500).run('/bin/sh', [
195
- '-c',
196
- 'exec 3>"$1"; tail -f /dev/null & exec 3>&-; echo $!; wait',
197
- 'sh',
198
- lifetime,
199
- ]);
200
- expect(result.status).not.toBe(0);
201
- expect(result.stderr).toMatch(/^no answer within 500 ms; killed process group \d+$/);
202
- expect(result.stdout.trim()).toMatch(/^\d+$/);
203
- expect(await ended).toBe('');
204
- } finally {
205
- rmSync(directory, { recursive: true, force: true });
206
- }
207
- });
208
-
209
- it('routes disk tools and their lifetime together without shell interpolation', () => {
210
- const target = '/image with spaces; echo unsafe';
211
- for (const file of ['hdiutil', '/usr/bin/hdiutil']) {
212
- expect(diskCommand(file, ['attach', target], 300)).toEqual({
213
- args: ['disk-command', 'hdiutil', '--', 'attach', target],
214
- lifetime: 'stop-wait',
215
- });
216
- }
217
- for (const file of ['diskutil', '/usr/sbin/diskutil']) {
218
- for (const verb of ['image', 'eject']) {
219
- expect(diskCommand(file, [verb, target], 300)).toEqual({
220
- args: ['disk-command', 'diskutil', '--', verb, target],
221
- lifetime: 'stop-wait',
222
- });
223
- }
224
- for (const verb of ['info', 'apfs', 'mount', 'unmount', 'Image']) {
225
- expect(diskCommand(file, [verb, target], 300)).toEqual({
226
- args: ['disk-command', 'diskutil', '--deadline-ms', '300', '--', verb, target],
227
- lifetime: 'facade-owned',
228
- });
229
- }
230
- }
231
- expect(diskCommand('/sbin/umount', ['/volume'], 300)).toBeNull();
232
- });
233
-
234
- it('waits past the SAFE deadline for actual owned child reap and the facade terminal exit', async () => {
235
- const fixture = await ownedDiskFacadeFixture();
236
- let settled = false;
237
- const result = createHostCommands(undefined, undefined, undefined, fixture.executable)
238
- .run('/usr/sbin/diskutil', ['info', 'overrun', fixture.socketPath], 300)
239
- .then((output) => {
240
- settled = true;
241
- return output;
242
- });
243
- try {
244
- const pid = await fixture.started();
245
- expect(await fixture.event()).toBe('deadline 300');
246
- expect(await fixture.event()).toBe(`reaped ${pid} null SIGKILL`);
247
- expect(settled).toBe(false);
248
- expect(() => process.kill(pid, 0)).toThrow();
249
- await fixture.send('finish');
250
- expect(await result).toEqual({
251
- status: 1,
252
- stdout: 'owned stdout\n',
253
- stderr: `owned stderr\nowned child ${pid} terminated by SIGKILL and reaped after 300 ms deadline\n`,
254
- });
255
- } finally {
256
- await fixture.cleanup();
257
- }
258
- });
259
-
260
- it('stops waiting only for protected images while preserving their live owner and file output', async () => {
261
- for (const { tool, verb } of [
262
- { tool: 'hdiutil', verb: 'attach' },
263
- { tool: 'diskutil', verb: 'image' },
264
- { tool: 'diskutil', verb: 'eject' },
265
- ]) {
266
- const fixture = await ownedDiskFacadeFixture();
267
- const result = createHostCommands(300, undefined, undefined, fixture.executable).run(tool, [
268
- verb,
269
- fixture.socketPath,
270
- ]);
271
- let pid = 0;
272
- try {
273
- pid = await fixture.started();
274
- const output = await result;
275
- expect(output.status).toBe(1);
276
- expect(output.stderr).toMatch(/^no answer within 300 ms; cowshed command \d+ left running, not killed/);
277
- expect(() => process.kill(pid, 0)).not.toThrow();
278
- await fixture.send('inspect');
279
- expect(await fixture.event()).toBe(`custody ${pid}`);
280
- expect(await readFile(join(fixture.directory, 'stdout'), 'utf8')).toBe('owned stdout\n');
281
- expect(await readFile(join(fixture.directory, 'stderr'), 'utf8')).toBe('owned stderr\n');
282
- } finally {
283
- // The fixture alone owns cleanup authority; it kills its exact stand-in and awaits reap.
284
- await fixture.cleanup();
285
- if (pid > 0) expect(() => process.kill(pid, 0)).toThrow();
286
- }
287
- }
288
- });
289
-
290
- it('preserves facade nonzero exit, signal diagnostics and the environment-selected owner', async () => {
291
- const before = process.env[COWSHED_EXECUTABLE_ENV];
292
- try {
293
- for (const mode of ['exit', 'signal']) {
294
- const fixture = await ownedDiskFacadeFixture();
295
- process.env[COWSHED_EXECUTABLE_ENV] = fixture.executable;
296
- const result = createHostCommands().run('/usr/sbin/diskutil', ['info', mode, fixture.socketPath]);
297
- try {
298
- const pid = await fixture.started();
299
- expect(await fixture.event()).toBe(`reaped ${pid} ${mode === 'exit' ? '7 null' : 'null SIGTERM'}`);
300
- await fixture.send('finish');
301
- expect(await result).toEqual({
302
- status: mode === 'exit' ? 7 : 1,
303
- stdout: 'owned stdout\n',
304
- stderr: mode === 'exit' ? 'owned stderr\n' : 'owned stderr\n\nkilled by SIGTERM',
305
- });
306
- } finally {
307
- await fixture.cleanup();
308
- }
309
- }
310
- } finally {
311
- if (before === undefined) delete process.env[COWSHED_EXECUTABLE_ENV];
312
- else process.env[COWSHED_EXECUTABLE_ENV] = before;
313
- }
314
- });
315
-
316
- it('reports an unavailable facade as a process-start error, not a child signal', async () => {
317
- const directory = await ownedSocketDirectory('rt-', 'missing-cowshed');
318
- try {
319
- const executable = join(directory, 'missing-cowshed');
320
- // The bound is the leg backstop: a missing facade fails at spawn, so the run ends at once.
321
- const host = createHostCommands(BOUNDED_TEST_IDLE_TIMEOUT_MS, undefined, undefined, executable);
322
- const output = await host.run('/usr/sbin/diskutil', ['info']);
323
- expect(output.status).toBe(1);
324
- expect(output.stdout).toBe('');
325
- expect(output.stderr).toContain(executable);
326
- expect(output.stderr).toContain('ENOENT');
327
- expect(output.stderr).not.toContain('killed by');
328
- } finally {
329
- rmSync(directory, { recursive: true, force: true });
330
- }
331
- });
332
-
333
- it('asks a gateway that predates disk leases once, not before every disk command', async () => {
334
- // Such a gateway answers only after 2 s of silence; asking it before each of a volume's
335
- // dozen hdiutil and diskutil calls once pushed a test shard past its 120 s bound.
336
- // A directory of its own in the socket namespace the sandbox admits, not a literal /tmp path.
337
- const directory = await ownedSocketDirectory('rt-', 'gw.sock');
338
- const socket = join(directory, 'gw.sock');
339
- let asked = 0;
340
- const server = createServer({ allowHalfOpen: true }, (client) => {
341
- asked += 1;
342
- client.resume();
343
- client.on('end', () =>
344
- client.end('{"ok":false,"code":"invalid-request","error":"unknown gateway control operation"}\n'),
345
- );
346
- });
347
- try {
348
- const { promise: listening, resolve: listened, reject: failed } = Promise.withResolvers<void>();
349
- server.once('error', failed);
350
- server.listen(socket, listened);
351
- await listening;
352
- server.off('error', failed);
353
- const host = createHostCommands(BOUNDED_TEST_IDLE_TIMEOUT_MS, socket);
354
- // `umount` with no operand only prints its usage, and it is a disk tool that takes a lease.
355
- expect((await host.run('/sbin/umount', [])).status).not.toBe(0);
356
- expect((await host.run('/sbin/umount', [])).status).not.toBe(0);
357
- expect(asked).toBe(1);
358
- } finally {
359
- server.close();
360
- rmSync(directory, { recursive: true, force: true });
361
- }
362
- });
363
-
364
- it('asks a gateway that refuses alone leases shared at once, and shared for a minute after', async () => {
365
- // A lease-scheduling gateway from before `share` refuses the field at once; the refused command
366
- // still runs leased, and later ones do not ask alone again.
367
- const directory = await ownedSocketDirectory('rt-', 'gw.sock');
368
- const socket = join(directory, 'gw.sock');
369
- const asked: string[] = [];
370
- const server = createServer({ allowHalfOpen: true }, (client) => {
371
- client.once('data', (chunk) => {
372
- const line = chunk.toString('utf8');
373
- asked.push(line.includes('"share":"alone"') ? 'alone' : 'shared');
374
- client.end(
375
- line.includes('"share"')
376
- ? '{"ok":false,"code":"invalid-request","error":"gateway control encoding failed: gateway control request contains an unknown field"}\n'
377
- : '{"ok":true,"lease":"queued"}\n{"ok":true,"lease":"granted"}\n',
378
- );
379
- });
380
- });
381
- try {
382
- const { promise: listening, resolve: listened, reject: failed } = Promise.withResolvers<void>();
383
- server.once('error', failed);
384
- server.listen(socket, listened);
385
- await listening;
386
- server.off('error', failed);
387
- const host = createHostCommands(BOUNDED_TEST_IDLE_TIMEOUT_MS, socket, 'alone');
388
- // `umount` with no operand only prints its usage, and it is a disk tool that takes a lease.
389
- expect((await host.run('/sbin/umount', [])).status).not.toBe(0);
390
- expect((await host.run('/sbin/umount', [])).status).not.toBe(0);
391
- expect(asked).toEqual(['alone', 'shared', 'shared']);
392
- } finally {
393
- server.close();
394
- rmSync(directory, { recursive: true, force: true });
395
- }
396
- });
397
- });
398
-
399
- describe('processes a task left working in its RAM lease', () => {
400
- it('skips only empty or absent lease directories and reports missing census tools as inspection failures', async () => {
401
- const directory = mkdtempSync(join(realpathSync(tmpdir()), 'lease-reap-errors-'));
402
- let scans = 0;
403
- let failure = Object.assign(new Error('spawn /usr/sbin/lsof ENOENT'), { code: 'ENOENT' });
404
- const volume = new RamTempVolume(
405
- ramTempPaths({ uid: 0, username: 'fixture' }),
406
- 1,
407
- {
408
- async run() {
409
- throw new Error('reap must not provision a disk');
410
- },
411
- },
412
- undefined,
413
- undefined,
414
- {
415
- async stopWorkingIn() {
416
- scans += 1;
417
- throw failure;
418
- },
419
- },
420
- );
421
- const lease = { directory, mountpoint: directory, capacityBytes: 1 };
422
- try {
423
- expect(await volume.reap(lease)).toEqual({ ok: true, value: [] });
424
- await rm(directory, { recursive: true });
425
- expect(await volume.reap(lease)).toEqual({ ok: true, value: [] });
426
- expect(scans).toBe(0);
427
- await mkdir(directory);
428
- await writeFile(join(directory, 'owned-file'), 'still requires inspection');
429
- for (const code of ['ENOENT', 'EACCES']) {
430
- failure = Object.assign(new Error(`spawn /usr/sbin/lsof ${code}`), { code });
431
- expect(await volume.reap(lease)).toEqual({
432
- ok: false,
433
- error: { kind: 'provision-failed', step: 'reap', detail: failure.message },
434
- });
435
- }
436
- expect(scans).toBe(2);
437
- } finally {
438
- await rm(directory, { recursive: true, force: true });
439
- }
440
- });
441
-
442
- const scratch = (): string => mkdtempSync(join(realpathSync(tmpdir()), 'lease-leftovers-'));
443
-
444
- /**
445
- * A fixture's Nx daemon, as Nx leaves it: its own session, working in the fixture, with a child of
446
- * its own (a plugin worker), so the command's process-group kill never reaches it. It starts the
447
- * child once a line can be read from `gate`, and prints the child's pid once it has.
448
- */
449
- function detachedDaemon(lease: string, gate: string) {
450
- const daemon = spawn('sh', ['-c', 'read go < "$1"; sleep 600 & echo $!; wait', 'daemon', gate], {
451
- cwd: lease,
452
- detached: true,
453
- stdio: ['ignore', 'pipe', 'ignore'],
454
- });
455
- const pid = daemon.pid;
456
- if (pid === undefined) {
457
- throw new Error('sh did not start');
458
- }
459
- const childPid = once(daemon.stdout, 'data').then(([line]) => Number(String(line).trim()));
460
- const exited = once(daemon, 'close');
461
- return { daemon, pid, childPid, exited };
462
- }
463
-
464
- async function liveAmong(pids: readonly number[]): Promise<number[]> {
465
- const live = (await processTable()).filter((entry) => !entry.stat.startsWith('Z')).map((entry) => entry.pid);
466
- return pids.filter((pid) => live.includes(pid));
467
- }
468
-
469
- it('stops a detached process working in the lease and what it started, and names them', async () => {
470
- const lease = scratch();
471
- const gate = join(lease, 'gate');
472
- execFileSync('mkfifo', [gate]);
473
- const { pid, childPid, exited } = detachedDaemon(lease, gate);
474
- let child = 0;
475
- try {
476
- await writeFile(gate, 'go\n');
477
- child = await childPid;
478
-
479
- const owned = [pid, child];
480
- let cwdReads = 0;
481
- let consecutiveStopped = 0;
482
- const processes = leaseProcessesOn({
483
- workingIn: async (directory) => {
484
- if (cwdReads > 0) {
485
- expect(consecutiveStopped).toBeGreaterThanOrEqual(2);
486
- }
487
- cwdReads += 1;
488
- return pidsWorkingIn(directory);
489
- },
490
- signal: terminate,
491
- async table() {
492
- const table = await processTable();
493
- const rows = table.filter((entry) => owned.includes(entry.pid));
494
- const bothStopped = rows.length === owned.length && rows.every((entry) => /^[TtZ]/.test(entry.stat));
495
- consecutiveStopped = bothStopped ? consecutiveStopped + 1 : 0;
496
- return table;
497
- },
498
- });
499
-
500
- const stopped = await processes.stopWorkingIn(lease);
501
-
502
- expect(stopped.map((entry) => Number(entry.split(' ')[0])).sort((a, b) => a - b)).toEqual(
503
- [pid, child].sort((a, b) => a - b),
504
- );
505
- expect(await liveAmong([pid, child])).toEqual([]);
506
- } finally {
507
- terminate(pid, 'SIGKILL');
508
- if (child !== 0) {
509
- terminate(child, 'SIGKILL');
510
- }
511
- await exited;
512
- rmSync(lease, { recursive: true, force: true });
513
- }
514
- });
515
-
516
- it('stops what a process starts after the process table was read, before it was signalled', async () => {
517
- const lease = scratch();
518
- const gate = join(lease, 'gate');
519
- execFileSync('mkfifo', [gate]);
520
- const { pid, childPid, exited } = detachedDaemon(lease, gate);
521
- let child = 0;
522
- // The daemon starts its child right after the table is read, so the table cannot name it.
523
- let reads = 0;
524
- const processes = leaseProcessesOn({
525
- workingIn: pidsWorkingIn,
526
- signal: terminate,
527
- async table() {
528
- const table = await processTable();
529
- reads += 1;
530
- if (reads === 1) {
531
- expect(table.some((entry) => entry.ppid === pid)).toBe(false);
532
- await writeFile(gate, 'go\n');
533
- child = await childPid;
534
- }
535
- return table;
536
- },
537
- });
538
- try {
539
- const stopped = await processes.stopWorkingIn(lease);
540
-
541
- expect(child).not.toBe(0);
542
- expect(await liveAmong([pid, child])).toEqual([]);
543
- expect(stopped.map((entry) => Number(entry.split(' ')[0])).sort((a, b) => a - b)).toEqual(
544
- [pid, child].sort((a, b) => a - b),
545
- );
546
- } finally {
547
- terminate(pid, 'SIGKILL');
548
- if (child !== 0) {
549
- terminate(child, 'SIGKILL');
550
- }
551
- await exited;
552
- rmSync(lease, { recursive: true, force: true });
553
- }
554
- });
555
-
556
- it('finds a child whose lease root exits before the process table is read', async () => {
557
- const lease = scratch();
558
- const gate = join(lease, 'gate');
559
- execFileSync('mkfifo', [gate]);
560
- const { daemon, pid, childPid, exited } = detachedDaemon(lease, gate);
561
- let child = 0;
562
- let reads = 0;
563
- const processes = leaseProcessesOn({
564
- workingIn: pidsWorkingIn,
565
- signal: terminate,
566
- async table() {
567
- reads += 1;
568
- if (reads === 1) {
569
- await writeFile(gate, 'go\n');
570
- child = await childPid;
571
- const ended = once(daemon, 'exit');
572
- terminate(pid, 'SIGKILL');
573
- await ended;
574
- }
575
- return processTable();
576
- },
577
- });
578
- try {
579
- const stopped = await processes.stopWorkingIn(lease);
580
- expect(stopped.map((entry) => Number(entry.split(' ')[0]))).toEqual([child]);
581
- expect(await liveAmong([pid, child])).toEqual([]);
582
- } finally {
583
- terminate(pid, 'SIGKILL');
584
- if (child !== 0) {
585
- terminate(child, 'SIGKILL');
586
- }
587
- await exited;
588
- rmSync(lease, { recursive: true, force: true });
589
- }
590
- });
591
-
592
- it('resumes a process held during discovery when a host read fails', async () => {
593
- const lease = scratch();
594
- const gate = join(lease, 'gate');
595
- execFileSync('mkfifo', [gate]);
596
- const { pid, childPid, exited } = detachedDaemon(lease, gate);
597
- let child = 0;
598
- let observedStopped = false;
599
- const failed = new Error('process table unavailable after SIGSTOP');
600
- const processes = leaseProcessesOn({
601
- workingIn: pidsWorkingIn,
602
- signal: terminate,
603
- async table() {
604
- const table = await processTable();
605
- if (table.some((entry) => entry.pid === pid && entry.stat.startsWith('T'))) {
606
- observedStopped = true;
607
- throw failed;
608
- }
609
- return table;
610
- },
611
- });
612
- try {
613
- await expect(processes.stopWorkingIn(lease)).rejects.toBe(failed);
614
- expect(observedStopped).toBe(true);
615
- // Reading the FIFO and starting the child requires the daemon to have resumed.
616
- await writeFile(gate, 'go\n');
617
- child = await childPid;
618
- expect(child).toBeGreaterThan(0);
619
- } finally {
620
- terminate(pid, 'SIGKILL');
621
- if (child !== 0) {
622
- terminate(child, 'SIGKILL');
623
- }
624
- await exited;
625
- rmSync(lease, { recursive: true, force: true });
626
- }
627
- });
628
-
629
- it('attempts every resume and preserves discovery failure when the first SIGCONT fails', async () => {
630
- const lease = scratch();
631
- const gate = join(lease, 'gate');
632
- execFileSync('mkfifo', [gate]);
633
- const { pid, childPid, exited } = detachedDaemon(lease, gate);
634
- let child = 0;
635
- const continued: number[] = [];
636
- const failedRead = new Error('process table unavailable after SIGSTOP');
637
- const failedResume = new Error('SIGCONT denied');
638
- const processes = leaseProcessesOn({
639
- workingIn: pidsWorkingIn,
640
- async table() {
641
- const table = await processTable();
642
- if (table.some((entry) => entry.pid === pid && entry.stat.startsWith('T'))) {
643
- throw failedRead;
644
- }
645
- return table;
646
- },
647
- signal(processId, signal) {
648
- if (signal === 'SIGCONT') {
649
- continued.push(processId);
650
- if (continued.length === 1) {
651
- throw failedResume;
652
- }
653
- }
654
- terminate(processId, signal);
655
- },
656
- });
657
- try {
658
- await writeFile(gate, 'go\n');
659
- child = await childPid;
660
- const cleanup = processes.stopWorkingIn(lease);
661
- await expect(cleanup).rejects.toBeInstanceOf(AggregateError);
662
- await expect(cleanup).rejects.toMatchObject({
663
- errors: [failedRead, expect.objectContaining({ cause: failedResume })],
664
- });
665
- expect(continued.slice().sort((a, b) => a - b)).toEqual([pid, child].sort((a, b) => a - b));
666
- await expect(cleanup).rejects.toThrow(`${continued[0]} (`);
667
- } finally {
668
- terminate(pid, 'SIGKILL');
669
- if (child !== 0) {
670
- terminate(child, 'SIGKILL');
671
- }
672
- await exited;
673
- rmSync(lease, { recursive: true, force: true });
674
- }
675
- });
676
-
677
- it('stops what writes into the lease through its TMPDIR from elsewhere, so the lease can be removed', async () => {
678
- const lease = scratch();
679
- const elsewhere = scratch();
680
- // As a dead task's ttsc plugin build leaves it: working in its project, writing into `$TMPDIR`
681
- // as fast as it can (shell builtins only, so it forks nothing), with a child of its own. macOS
682
- // spells TMPDIR with a trailing slash.
683
- const writer = spawn('sh', ['-c', 'sleep 600 & echo $!; i=0; while :; do i=$((i+1)); : > "$TMPDIR/w$i"; done'], {
684
- cwd: elsewhere,
685
- env: { ...process.env, TMPDIR: `${lease}/` },
686
- detached: true,
687
- stdio: ['ignore', 'pipe', 'ignore'],
688
- });
689
- // Another, started on its own with a TMPDIR beneath the lease.
690
- mkdirSync(join(lease, 'nested'));
691
- const nested = spawn('sleep', ['600'], {
692
- cwd: elsewhere,
693
- env: { ...process.env, TMPDIR: join(lease, 'nested') },
694
- detached: true,
695
- stdio: 'ignore',
696
- });
697
- const exited = [once(writer, 'close'), once(nested, 'close')];
698
- const pids = [writer.pid ?? 0, nested.pid ?? 0];
699
- let child = 0;
700
- try {
701
- child = Number(String((await once(writer.stdout, 'data'))[0]).trim());
702
- // Ends on the watch event that brings the lease to two entries: `nested`, and the writer's first file.
703
- await whenChanged(lease, () => readdirSync(lease).length >= 2);
704
- // None of them works in the lease by its working directory.
705
- expect(await pidsWorkingIn(lease)).toEqual([]);
706
-
707
- const stopped = await hostLeaseProcesses.stopWorkingIn(lease);
708
-
709
- expect(stopped.map((entry) => Number(entry.split(' ')[0])).sort((a, b) => a - b)).toEqual(
710
- [...pids, child].sort((a, b) => a - b),
711
- );
712
- expect(await liveAmong([...pids, child])).toEqual([]);
713
- // Nothing writes there any more: the lease goes whole, with no ENOTEMPTY.
714
- await rm(lease, { recursive: true });
715
- } finally {
716
- for (const pid of [...pids, child]) {
717
- if (pid !== 0) {
718
- terminate(pid, 'SIGKILL');
719
- }
720
- }
721
- await Promise.all(exited);
722
- rmSync(lease, { recursive: true, force: true });
723
- rmSync(elsewhere, { recursive: true, force: true });
724
- }
725
- });
726
-
727
- it('stops nothing in a lease no process works in, and nothing that works elsewhere', async () => {
728
- const lease = scratch();
729
- const elsewhere = scratch();
730
- const bystander = spawn('sleep', ['600'], { cwd: elsewhere, detached: true, stdio: 'ignore' });
731
- // A TMPDIR that only starts with the lease's name is another directory.
732
- const sibling = spawn('sleep', ['600'], {
733
- cwd: elsewhere,
734
- env: { ...process.env, TMPDIR: `${lease}x` },
735
- detached: true,
736
- stdio: 'ignore',
737
- });
738
- try {
739
- expect(await hostLeaseProcesses.stopWorkingIn(lease)).toEqual([]);
740
- for (const left of [bystander, sibling]) {
741
- expect(left.exitCode === null && left.signalCode === null).toBe(true);
742
- }
743
- } finally {
744
- bystander.kill('SIGKILL');
745
- sibling.kill('SIGKILL');
746
- rmSync(lease, { recursive: true, force: true });
747
- rmSync(elsewhere, { recursive: true, force: true });
748
- }
749
- });
750
- });