@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
@@ -0,0 +1,226 @@
1
+ import { connect } from 'node:net';
2
+ import { StringDecoder } from 'node:string_decoder';
3
+ import type { CommandOutput } from './ram-temp.js';
4
+
5
+ /**
6
+ * The silence the client allows the gateway before its first heartbeat line (05_gateway.md, "Deadlines"; Rust
7
+ * `UNPROVEN_SILENCE`): a gateway of an earlier build never heartbeats, and its slow answers still arrive within the
8
+ * minute doctor always gave it.
9
+ */
10
+ export const UNPROVEN_SILENCE_MS = 60_000;
11
+
12
+ /** The silence allowed once a heartbeat has come: three 5 s heartbeats (Rust `deadline::HEARTBEAT_SILENCE`). */
13
+ export const HEARTBEAT_SILENCE_MS = 15_000;
14
+
15
+ /** A detach answers its native output, which the gateway bounds; no answer grows past that. */
16
+ const ANSWER_BYTES_MAX = 2 * 64 * 1024 * 6 + 4096;
17
+
18
+ /** Monotonic milliseconds and the one silence timer; `after` answers its cancel. A test fires its timer itself. */
19
+ export interface SilenceTimers {
20
+ now(): number;
21
+ after(ms: number, fire: () => void): () => void;
22
+ }
23
+
24
+ const SYSTEM_TIMERS: SilenceTimers = {
25
+ now: () => performance.now(),
26
+ after(ms, fire) {
27
+ const timer = setTimeout(fire, ms);
28
+ return () => clearTimeout(timer);
29
+ },
30
+ };
31
+
32
+ /** The last thing the client saw the gateway do, which a `SILENT` failure names. */
33
+ type GatewayProgress = { kind: 'nothing' } | { kind: 'sent' } | { kind: 'heartbeat'; seq: number };
34
+
35
+ function describeProgress(progress: GatewayProgress): string {
36
+ switch (progress.kind) {
37
+ case 'nothing':
38
+ return 'nothing';
39
+ case 'sent':
40
+ return 'request sent';
41
+ case 'heartbeat':
42
+ return `heartbeat ${progress.seq}`;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Typed gateway mutation: no caller-owned native child or arbitrary argv. The request is a one-shot control op, so the
48
+ * answer is read under the gateway's silence rule (05_gateway.md, "Deadlines"), never under a total ceiling: until the
49
+ * first heartbeat line the gateway may be silent for {@link UNPROVEN_SILENCE_MS}, after each one for
50
+ * {@link HEARTBEAT_SILENCE_MS}. A silent gateway ends this caller's wait as `SILENT`, with unknown custody; the gateway's
51
+ * detach keeps running, and its late answer still completes `pending`.
52
+ */
53
+ export function detachGatewayRamDisk(
54
+ socket: string,
55
+ device: string,
56
+ registryEntry: string,
57
+ timers: SilenceTimers = SYSTEM_TIMERS,
58
+ ): Promise<CommandOutput> {
59
+ let resolve!: (output: CommandOutput) => void;
60
+ const answer = new Promise<CommandOutput>((done) => {
61
+ resolve = done;
62
+ });
63
+ let complete!: (output: CommandOutput | null) => void;
64
+ const completion = new Promise<CommandOutput | null>((done) => {
65
+ complete = done;
66
+ });
67
+ const started = timers.now();
68
+ let last: GatewayProgress = { kind: 'nothing' };
69
+ let silenceMs = UNPROVEN_SILENCE_MS;
70
+ let disarm = () => {};
71
+ const decoder = new StringDecoder('utf8');
72
+ let received = '';
73
+ let dispatched = false;
74
+ let bounded = false;
75
+ let finished = false;
76
+ const pending = { pid: null, completion };
77
+ const unknown = (reason: string): CommandOutput => ({ status: 1, stdout: '', stderr: reason, pending });
78
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: a unix-socket connect completes or fails at once, and the silence timer listen() arms below ends the whole exchange (05_gateway.md, "Deadlines")
79
+ const connection = connect(socket);
80
+ const finish = (output: CommandOutput | null, reason = 'gateway detach terminal status unavailable') => {
81
+ if (finished) return;
82
+ finished = true;
83
+ disarm();
84
+ complete(output);
85
+ if (!bounded) resolve(output ?? unknown(reason));
86
+ connection.destroy();
87
+ };
88
+ const silent = () => {
89
+ bounded = true;
90
+ resolve(
91
+ unknown(
92
+ `SILENT: ram-detach: the gateway at ${socket} wrote no heartbeat or answer for ${silenceMs} ms (waited ${Math.max(0, timers.now() - started)} ms; last progress: ${describeProgress(last)}); the gateway's detach keeps running, not killed`,
93
+ ),
94
+ );
95
+ connection.unref();
96
+ };
97
+ /** Allow the gateway `silenceMs` from now; once the caller's wait has ended there is nothing left to bound. */
98
+ const listen = () => {
99
+ if (bounded || finished) return;
100
+ disarm();
101
+ disarm = timers.after(silenceMs, silent);
102
+ };
103
+ listen();
104
+ connection.on('connect', () => {
105
+ dispatched = true;
106
+ connection.end(`${JSON.stringify({ op: 'ram-detach', device, registryEntry })}\n`);
107
+ last = { kind: 'sent' };
108
+ });
109
+ connection.on('data', (chunk: Buffer) => {
110
+ received += decoder.write(chunk);
111
+ for (let newline = received.indexOf('\n'); newline >= 0; newline = received.indexOf('\n')) {
112
+ const line = received.slice(0, newline);
113
+ received = received.slice(newline + 1);
114
+ // The gateway heartbeats an answer that is not ready yet (05_gateway.md, "Deadlines"): never the answer.
115
+ const seq = heartbeatSeq(line);
116
+ if (seq !== null) {
117
+ last = { kind: 'heartbeat', seq };
118
+ silenceMs = HEARTBEAT_SILENCE_MS;
119
+ listen();
120
+ continue;
121
+ }
122
+ // A line past the cap is refused before it is read, whatever chunk completed it.
123
+ if (Buffer.byteLength(line) > ANSWER_BYTES_MAX)
124
+ return finish(null, 'gateway detach reply exceeds its bounded output contract');
125
+ const parsed = readDetachAnswer(line);
126
+ if (parsed === null) finish(null, `gateway detach reply proves no terminal outcome: ${line.slice(0, 512)}`);
127
+ else finish(parsed);
128
+ return;
129
+ }
130
+ // Native output is bounded by the gateway contract; never buffer an unbounded peer reply.
131
+ if (Buffer.byteLength(received) > ANSWER_BYTES_MAX)
132
+ finish(null, 'gateway detach reply exceeds its bounded output contract');
133
+ });
134
+ connection.on('error', (error) => {
135
+ if (!dispatched) finish({ status: 103, stdout: '', stderr: `gateway detach did not start: ${error.message}` });
136
+ else finish(null, `gateway detach connection ended after dispatch: ${error.message}`);
137
+ });
138
+ connection.on('close', () => finish(null, 'gateway detach closed without an authoritative outcome'));
139
+ return answer;
140
+ }
141
+
142
+ /**
143
+ * The heartbeat's `progress` when `line` is exactly a gateway heartbeat, `{"ok":<bool>,"progress":<u64>}` and nothing
144
+ * else (Rust `ProgressLine`, `deny_unknown_fields`); `null` for any other line, which is the answer.
145
+ */
146
+ function heartbeatSeq(line: string): number | null {
147
+ let parsed: unknown;
148
+ try {
149
+ parsed = JSON.parse(line);
150
+ } catch {
151
+ return null;
152
+ }
153
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return null;
154
+ if (Object.keys(parsed).length !== 2 || !('ok' in parsed) || !('progress' in parsed)) return null;
155
+ const { ok, progress } = parsed;
156
+ return typeof ok === 'boolean' && typeof progress === 'number' && Number.isInteger(progress) && progress >= 0
157
+ ? progress
158
+ : null;
159
+ }
160
+
161
+ /** Only the gateway can attest whether its exact native child ran and was reaped. */
162
+ export function readDetachAnswer(line: string): CommandOutput | null {
163
+ let parsed: unknown;
164
+ try {
165
+ parsed = JSON.parse(line);
166
+ } catch {
167
+ return null;
168
+ }
169
+ if (typeof parsed !== 'object' || parsed === null || !('ok' in parsed)) return null;
170
+ if (parsed.ok === false && 'code' in parsed && parsed.code === 'invalid-request') {
171
+ return {
172
+ status: 103,
173
+ stdout: '',
174
+ stderr: `gateway detach did not start: ${'error' in parsed ? String(parsed.error) : 'invalid request'}`,
175
+ };
176
+ }
177
+ if (
178
+ parsed.ok !== true ||
179
+ !('ramDetach' in parsed) ||
180
+ typeof parsed.ramDetach !== 'object' ||
181
+ parsed.ramDetach === null
182
+ )
183
+ return null;
184
+ const result = parsed.ramDetach;
185
+ if (!('outcome' in result)) return null;
186
+ if (result.outcome === 'unknown') return null;
187
+ if (result.outcome === 'not-started' && 'reason' in result && typeof result.reason === 'string') {
188
+ return { status: 103, stdout: '', stderr: `gateway detach did not start: ${result.reason}` };
189
+ }
190
+ if (
191
+ result.outcome !== 'terminal' ||
192
+ !('status' in result) ||
193
+ typeof result.status !== 'object' ||
194
+ result.status === null ||
195
+ !('stdout' in result) ||
196
+ typeof result.stdout !== 'string' ||
197
+ !('stderr' in result) ||
198
+ typeof result.stderr !== 'string' ||
199
+ !('stdoutTruncated' in result) ||
200
+ typeof result.stdoutTruncated !== 'boolean' ||
201
+ !('stderrTruncated' in result) ||
202
+ typeof result.stderrTruncated !== 'boolean'
203
+ )
204
+ return null;
205
+ const status = result.status;
206
+ const code =
207
+ 'exit' in status && typeof status.exit === 'number' && Number.isSafeInteger(status.exit) && status.exit >= 0
208
+ ? status.exit
209
+ : 'signal' in status &&
210
+ typeof status.signal === 'number' &&
211
+ Number.isSafeInteger(status.signal) &&
212
+ status.signal > 0
213
+ ? 128 + status.signal
214
+ : null;
215
+ return code === null
216
+ ? null
217
+ : {
218
+ status: code,
219
+ stdout: result.stdout,
220
+ stderr:
221
+ result.stderr +
222
+ (result.stdoutTruncated || result.stderrTruncated
223
+ ? '\n[gateway detach output truncated at the native inline limit]'
224
+ : ''),
225
+ };
226
+ }
@@ -1,3 +1,25 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { appendFileSync, mkdirSync, readFileSync, rmdirSync, rmSync } from 'node:fs';
3
+ import { userInfo } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import {
7
+ createHostCommands,
8
+ describeRamTempError,
9
+ detachRamDisk,
10
+ type HostCommands,
11
+ RAM_TEMP_CAPACITY_BYTES,
12
+ type RamDisk,
13
+ type RamTempPaths,
14
+ RamTempVolume,
15
+ ramDisksIn,
16
+ ramTempPaths,
17
+ type TestNamespace,
18
+ testNamespace,
19
+ } from './ram-temp.js';
20
+
21
+ const MIB = 1024 * 1024;
22
+
1
23
  /** One attached image as `ioreg -r -c AppleDiskImageDevice -l -w0` lists it. */
2
24
  export function registryDevice(url: string, disk: string): string[] {
3
25
  return [
@@ -10,3 +32,339 @@ export function registryDevice(url: string, disk: string): string[] {
10
32
  ` | "BSD Name" = "${disk}s1"`,
11
33
  ];
12
34
  }
35
+
36
+ /**
37
+ * A host proof's RAM volume: its test namespace, where it lives, its size, and the record of the disks its attaches
38
+ * made. Every path derives from the namespace, and the namespace's root is the fixture's one directory.
39
+ */
40
+ export interface ScratchVolume {
41
+ readonly namespace: TestNamespace;
42
+ readonly paths: RamTempPaths;
43
+ readonly capacity: number;
44
+ readonly owned: string;
45
+ readonly gatewaySocket: string;
46
+ }
47
+
48
+ /**
49
+ * A fixture volume's size is the one name its namespace does not derive. A creator's stray reclaim matches RAM disks by
50
+ * user and size, so a fixture volume of the size of the user's own could take the user's disk.
51
+ */
52
+ function refuseUserVolumeSize(capacity: number): void {
53
+ if (capacity === RAM_TEMP_CAPACITY_BYTES) {
54
+ throw new Error(
55
+ `a fixture RAM volume has the size of the user's own volume (${capacity} bytes); a test owns a size of its own`,
56
+ );
57
+ }
58
+ }
59
+
60
+ /**
61
+ * A volume of its own for one host proof, in a test namespace of its own: `testNamespace(process.pid, index)`. It makes
62
+ * the namespace's root, `/private/var/folders/cowshed/<uid>/<ns>`, 0700, and refuses one that exists: a fixture adopts
63
+ * nothing. Every path derives from the namespace (`ramTempPaths`): the volume mounts at `<root>/ram3`, below the
64
+ * per-user root `cowshed setup` makes, as the user's own volume mounts below that root, so mds keeps no right for it
65
+ * (specs/cowshed/01a_apfs.md, "Spotlight media references"), and the fixture gateway serves `<root>/gateway.sock`
66
+ * (`startFixtureGateway`). Nothing it names can be what production names. The size is a name of its own: one no other
67
+ * test process uses, since the size and the user are what identify a RAM disk as this volume's. `index` is 0 to 3: the
68
+ * size spends 4 sectors per pid. `owned` records the disks the volume's attaches made, by identity: the only disks its
69
+ * teardown may detach.
70
+ */
71
+ export function scratchVolume(index: 0 | 1 | 2 | 3): ScratchVolume {
72
+ const { uid } = userInfo();
73
+ const namespace = testNamespace(process.pid, index);
74
+ const paths = ramTempPaths({ uid }, namespace);
75
+ const capacity = 64 * MIB + (process.pid * 4 + index + 1) * 512;
76
+ refuseUserVolumeSize(capacity);
77
+ try {
78
+ mkdirSync(paths.root, { mode: 0o700 });
79
+ } catch (error) {
80
+ if (error instanceof Error && 'code' in error && error.code === 'EEXIST') {
81
+ throw new Error(`fixture namespace root ${paths.root} exists: a fixture makes its own and adopts none`, {
82
+ cause: error,
83
+ });
84
+ }
85
+ throw error;
86
+ }
87
+ return {
88
+ namespace,
89
+ paths,
90
+ capacity,
91
+ owned: join(paths.root, 'owned-disks.jsonl'),
92
+ gatewaySocket: join(paths.root, 'gateway.sock'),
93
+ };
94
+ }
95
+
96
+ /**
97
+ * Start the prebuilt real gateway for the volume's namespace (`ram_fixture <ns>`, which serves `<root>/gateway.sock`);
98
+ * readiness and exit are observed, never polled or faked. The stop it returns ends the helper and awaits its exit; the
99
+ * root stays for the teardown (`removeScratchVolume`), which removes it once the volume is gone.
100
+ */
101
+ export async function startFixtureGateway(volume: ScratchVolume): Promise<() => Promise<void>> {
102
+ const binary = fileURLToPath(new URL('../../../../cowshed/.cache/ram-fixture/ram_fixture', import.meta.url));
103
+ const child = spawn(binary, [volume.namespace.name], { stdio: ['pipe', 'pipe', 'pipe'] });
104
+ let stderr = '';
105
+ let stdout = '';
106
+ child.stderr.setEncoding('utf8').on('data', (text: string) => {
107
+ stderr += text;
108
+ process.stderr.write(text);
109
+ });
110
+ const exited = new Promise<void>((resolve, reject) => {
111
+ child.once('error', reject);
112
+ child.once('close', (code, signal) => {
113
+ if (code === 0) resolve();
114
+ else reject(new Error(`fixture gateway ended (${String(code ?? signal)}): ${stderr}`));
115
+ });
116
+ });
117
+ // Install a rejection handler before readiness: early helper exit is the startup failure.
118
+ const readiness = new Promise<void>((resolve, reject) => {
119
+ child.stdout.setEncoding('utf8').on('data', (text: string) => {
120
+ stdout += text;
121
+ const newline = stdout.indexOf('\n');
122
+ if (newline < 0) return;
123
+ try {
124
+ const answer: unknown = JSON.parse(stdout.slice(0, newline));
125
+ if (
126
+ typeof answer !== 'object' ||
127
+ answer === null ||
128
+ !('socket' in answer) ||
129
+ answer.socket !== volume.gatewaySocket
130
+ ) {
131
+ throw new Error(`fixture gateway answered another socket: ${stdout}`);
132
+ }
133
+ process.stderr.write(`fixture gateway ready ${JSON.stringify(answer)}\n`);
134
+ resolve();
135
+ } catch (error) {
136
+ reject(error);
137
+ }
138
+ });
139
+ void exited.then(() => reject(new Error(`fixture gateway exited before readiness: ${stdout}${stderr}`)), reject);
140
+ });
141
+ try {
142
+ await readiness;
143
+ } catch (error) {
144
+ child.stdin.end();
145
+ await exited.catch((exitError: unknown) => process.stderr.write(`${String(exitError)}\n`));
146
+ // The caller got no stop to tear down with, and a root this cannot remove must not hide the failure it follows.
147
+ try {
148
+ removeScratchVolume(volume);
149
+ } catch (removeError) {
150
+ process.stderr.write(`fixture gateway startup: ${String(removeError)}\n`);
151
+ }
152
+ throw error;
153
+ }
154
+ return async () => {
155
+ child.stdin.end();
156
+ await exited;
157
+ };
158
+ }
159
+
160
+ /**
161
+ * Remove what a run left of the scratch volume: the directories its volume mounts on, then its namespace root with
162
+ * everything the fixture made there. Teardown must not hide the failure it follows, so a directory `rmdirSync` refuses,
163
+ * one still mounted on, is said on stderr instead of thrown, and the root stays with it: nothing is deleted through a
164
+ * mount.
165
+ */
166
+ export function removeScratchVolume(volume: ScratchVolume): void {
167
+ const { root, mountpoint, staging } = volume.paths;
168
+ let kept = false;
169
+ for (const directory of [mountpoint, staging]) {
170
+ try {
171
+ rmdirSync(directory);
172
+ } catch (error) {
173
+ if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT')) {
174
+ kept = true;
175
+ process.stderr.write(`scratch volume teardown: rmdir ${directory}: ${String(error)}; ${root} is kept\n`);
176
+ }
177
+ }
178
+ }
179
+ if (!kept) {
180
+ rmSync(root, { recursive: true, force: true });
181
+ }
182
+ }
183
+
184
+ /**
185
+ * This test's size of RAM disks, read from the I/O Registry as the module reads them: `hdiutil info` drops attached disks.
186
+ * A guard for assertions only: a disk of the size is no proof it is the test's, so nothing detaches by it.
187
+ */
188
+ export async function attachedDisks(paths: RamTempPaths, capacity: number, gatewaySocket: string): Promise<RamDisk[]> {
189
+ const host = createHostCommands(gatewaySocket);
190
+ const registry = await host.run('/usr/sbin/ioreg', ['-r', '-c', 'IOHDIXHDDriveOutKernel', '-l', '-w0']);
191
+ const table = await host.run('/sbin/mount', []);
192
+ if (registry.status !== 0 || table.status !== 0) {
193
+ throw new Error(
194
+ `inventory RAM disks: ioreg exit ${registry.status}: ${registry.stderr}; mount exit ${table.status}: ${table.stderr}`,
195
+ );
196
+ }
197
+ const disks = ramDisksIn(registry.stdout, table.stdout);
198
+ if (!disks.ok) {
199
+ throw new Error(`inventory RAM disks: ${disks.error}`);
200
+ }
201
+ return disks.value.filter((disk) => disk.uid === paths.uid && disk.sectors === capacity / 512);
202
+ }
203
+
204
+ /** A disk a fixture attached, by the identity the I/O Registry gave it right after the attach. */
205
+ interface OwnedDisk {
206
+ readonly entry: string;
207
+ readonly device: string;
208
+ readonly sectors: number;
209
+ }
210
+
211
+ /** The disks `owned` records; none when nothing was attached. A malformed record refuses the teardown. */
212
+ function ownedDisks(owned: string): OwnedDisk[] {
213
+ let text: string;
214
+ try {
215
+ text = readFileSync(owned, 'utf8');
216
+ } catch (error) {
217
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
218
+ return [];
219
+ }
220
+ throw error;
221
+ }
222
+ return text
223
+ .split('\n')
224
+ .filter((line) => line !== '')
225
+ .map((line) => {
226
+ const parsed: unknown = JSON.parse(line);
227
+ if (
228
+ typeof parsed === 'object' &&
229
+ parsed !== null &&
230
+ 'entry' in parsed &&
231
+ typeof parsed.entry === 'string' &&
232
+ 'device' in parsed &&
233
+ typeof parsed.device === 'string' &&
234
+ 'sectors' in parsed &&
235
+ typeof parsed.sectors === 'number'
236
+ ) {
237
+ return { entry: parsed.entry, device: parsed.device, sectors: parsed.sectors };
238
+ }
239
+ throw new Error(`${owned} holds a record that is no owned disk: ${line}`);
240
+ });
241
+ }
242
+
243
+ /** Exact custody comes only from this fixture's attach receipts, never a size or name filter. */
244
+ export function ownsRecordedDisk(owned: string, disk: RamDisk): boolean {
245
+ return ownedDisks(owned).some(
246
+ (record) => record.entry === disk.entry && record.device === disk.physical && record.sectors === disk.sectors,
247
+ );
248
+ }
249
+
250
+ /**
251
+ * Detach the disks `owned` records, each only while a fresh registry read still lists its entry with the same whole disk,
252
+ * size and owner `uid`; the detach is bound to that entry. A disk already gone needs nothing. Any other listing is
253
+ * refused and reported on stderr, outside the fixture's directories, and never detached; the refusals are thrown once
254
+ * every record has been seen, so the caller removes nothing that holds the evidence.
255
+ */
256
+ export async function detachOwned(owned: string, uid: number, gatewaySocket: string): Promise<void> {
257
+ const records = ownedDisks(owned);
258
+ if (records.length === 0) {
259
+ return;
260
+ }
261
+ const host = createHostCommands(gatewaySocket);
262
+ const registry = await host.run('/usr/sbin/ioreg', ['-r', '-c', 'IOHDIXHDDriveOutKernel', '-l', '-w0']);
263
+ const table = await host.run('/sbin/mount', []);
264
+ if (registry.status !== 0 || table.status !== 0) {
265
+ throw new Error(
266
+ `inventory RAM disks: ioreg exit ${registry.status}: ${registry.stderr}; mount exit ${table.status}: ${table.stderr}`,
267
+ );
268
+ }
269
+ const disks = ramDisksIn(registry.stdout, table.stdout);
270
+ if (!disks.ok) {
271
+ throw new Error(`inventory RAM disks: ${disks.error}`);
272
+ }
273
+ const refused: string[] = [];
274
+ for (const record of records) {
275
+ const disk = disks.value.find((candidate) => candidate.entry === record.entry);
276
+ if (disk === undefined) {
277
+ continue;
278
+ }
279
+ const { physical } = disk;
280
+ if (physical === null || physical !== record.device || disk.sectors !== record.sectors || disk.uid !== uid) {
281
+ refused.push(
282
+ `registry entry ${record.entry} now lists ${physical ?? 'no disk'} of ${disk.sectors} sectors (uid ${disk.uid}), not the ${record.device} of ${record.sectors} sectors this fixture attached: not detached`,
283
+ );
284
+ continue;
285
+ }
286
+ const detached = await detachRamDisk(host, { ...disk, physical }, 'teardown detach');
287
+ if (!detached.ok) {
288
+ refused.push(describeRamTempError(detached.error));
289
+ }
290
+ }
291
+ if (refused.length > 0) {
292
+ process.stderr.write(`fixture teardown of ${owned}:\n${refused.join('\n')}\n`);
293
+ throw new Error(refused.join('; '));
294
+ }
295
+ }
296
+
297
+ /**
298
+ * An attach through this fixture's real gateway. Right after the answer it reads the disk's registry entry and
299
+ * appends the exact attached identity to `owned`,
300
+ * the only record its teardown detaches from (`detachOwned`), and answers the lease. A disk it cannot record has its
301
+ * lease released, so no disk is left that neither the gateway nor the teardown detaches. The user's volume is attached by
302
+ * the gateway (`ram-lease`), so that no job's end takes it from another job's lease.
303
+ */
304
+ export function recordedRamAttach(
305
+ attach: HostCommands['attachRam'],
306
+ run: HostCommands['run'],
307
+ owned: string,
308
+ ): HostCommands['attachRam'] {
309
+ return async (sectors) => {
310
+ const attached = await attach(sectors);
311
+ if (!attached.ok) return attached;
312
+ const lease = attached.value;
313
+ const { device } = lease;
314
+ const registry = await run('/usr/sbin/ioreg', ['-r', '-c', 'IOHDIXHDDriveOutKernel', '-l', '-w0']);
315
+ const table = await run('/sbin/mount', []);
316
+ const disks =
317
+ registry.status === 0 && table.status === 0
318
+ ? ramDisksIn(registry.stdout, table.stdout)
319
+ : { ok: false as const, error: `ioreg exit ${registry.status}, mount exit ${table.status}` };
320
+ const listed = disks.ok ? disks.value.filter((disk) => disk.physical === device) : [];
321
+ const [disk] = listed;
322
+ if (listed.length !== 1 || disk === undefined || disk.sectors !== sectors || disk.uid !== userInfo().uid) {
323
+ const released = await lease.release();
324
+ return {
325
+ ok: false,
326
+ error: `hdiutil attached ${device}, but the I/O Registry lists ${disks.ok ? JSON.stringify(listed) : disks.error} for it: not recorded, so its lease was released (${released.ok ? `gateway detach exit ${released.value.status}` : released.error})`,
327
+ };
328
+ }
329
+ const identity = { entry: disk.entry, device, sectors };
330
+ appendFileSync(owned, `${JSON.stringify(identity)}\n`, { mode: 0o600 });
331
+ process.stderr.write(`fixture attached ${JSON.stringify(identity)}\n`);
332
+ return { ok: true, value: lease };
333
+ };
334
+ }
335
+
336
+ /**
337
+ * The provisioning step a host call is: `mount_apfs` and `umount` of the private staging mount, or
338
+ * the `mount_apfs` that places the volume at its mountpoint. Null for every other call.
339
+ */
340
+ export function stepOf(paths: RamTempPaths, file: string, args: readonly string[]): string | null {
341
+ if (file === '/sbin/mount_apfs') {
342
+ return args.at(-1) === paths.mountpoint ? 'mount' : 'mount_apfs';
343
+ }
344
+ return file === '/sbin/umount' ? 'unmount' : null;
345
+ }
346
+
347
+ /**
348
+ * A host proof's RAM volume: `volume`'s paths and size, its disk commands through `cowshed`, and its disk attached by the
349
+ * fixture's own gateway and recorded in `volume.owned`. Its paths and its gateway's socket derive from its test
350
+ * namespace, so none can be the user's own; its size is the one name a namespace does not derive, and the user's own is
351
+ * refused: no test leases, creates or detaches that volume.
352
+ */
353
+ export function fixtureRamVolume(
354
+ volume: {
355
+ readonly paths: RamTempPaths;
356
+ readonly capacity: number;
357
+ readonly owned: string;
358
+ readonly gatewaySocket: string;
359
+ },
360
+ cowshed: string | undefined,
361
+ ): RamTempVolume {
362
+ refuseUserVolumeSize(volume.capacity);
363
+ const host = createHostCommands(volume.gatewaySocket, undefined, undefined, cowshed);
364
+ return new RamTempVolume(volume.paths, volume.capacity, {
365
+ run: host.run,
366
+ detachRam: host.detachRam,
367
+ ownsRamDisk: (disk) => ownsRecordedDisk(volume.owned, disk),
368
+ attachRam: recordedRamAttach(host.attachRam, host.run, volume.owned),
369
+ });
370
+ }