@smoothbricks/nx-plugin 0.4.26 → 0.4.27

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 (343) hide show
  1. package/README.md +994 -117
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +15 -73
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +3 -2
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +16 -15
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +43 -6
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +309 -73
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +101 -5
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +291 -10
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +207 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +576 -202
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +370 -138
  102. package/dist/managed-files/ci-workflow.d.ts +13 -0
  103. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.js +44 -13
  105. package/dist/managed-files/files.d.ts +7 -1
  106. package/dist/managed-files/files.d.ts.map +1 -1
  107. package/dist/managed-files/files.js +62 -8
  108. package/dist/managed-files/json-edit.d.ts +21 -0
  109. package/dist/managed-files/json-edit.d.ts.map +1 -0
  110. package/dist/managed-files/json-edit.js +295 -0
  111. package/dist/managed-files/managed-format.d.ts +33 -1
  112. package/dist/managed-files/managed-format.d.ts.map +1 -1
  113. package/dist/managed-files/managed-format.js +82 -2
  114. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  115. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  116. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  117. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/publish-workflow.js +231 -48
  119. package/dist/managed-files/tree.d.ts +5 -0
  120. package/dist/managed-files/tree.d.ts.map +1 -1
  121. package/dist/managed-files/tree.js +5 -3
  122. package/dist/manifest-hash.d.ts.map +1 -1
  123. package/dist/manifest-hash.js +2 -5
  124. package/dist/nextest-code-bound.d.ts +62 -0
  125. package/dist/nextest-code-bound.d.ts.map +1 -0
  126. package/dist/nextest-code-bound.js +154 -0
  127. package/dist/nextest-extraction.d.ts +24 -8
  128. package/dist/nextest-extraction.d.ts.map +1 -1
  129. package/dist/nextest-extraction.js +42 -7
  130. package/dist/package-target-policy.d.ts.map +1 -1
  131. package/dist/package-target-policy.js +3 -5
  132. package/dist/release-config-policy.d.ts.map +1 -1
  133. package/dist/release-config-policy.js +3 -5
  134. package/dist/runtime-input.d.ts +14 -0
  135. package/dist/runtime-input.d.ts.map +1 -0
  136. package/dist/runtime-input.js +15 -0
  137. package/dist/rust-tokens.d.ts +11 -0
  138. package/dist/rust-tokens.d.ts.map +1 -0
  139. package/dist/rust-tokens.js +81 -0
  140. package/dist/task-results.d.ts +6 -0
  141. package/dist/task-results.d.ts.map +1 -0
  142. package/dist/task-results.js +61 -0
  143. package/dist/test-program.d.ts +54 -0
  144. package/dist/test-program.d.ts.map +1 -0
  145. package/dist/test-program.js +292 -0
  146. package/dist/test-timings.d.ts +71 -0
  147. package/dist/test-timings.d.ts.map +1 -0
  148. package/dist/test-timings.js +393 -0
  149. package/dist/test-walk-policy.d.ts +103 -0
  150. package/dist/test-walk-policy.d.ts.map +1 -0
  151. package/dist/test-walk-policy.js +657 -0
  152. package/dist/testing.d.ts +177 -0
  153. package/dist/testing.d.ts.map +1 -0
  154. package/dist/testing.js +824 -0
  155. package/dist/type-guards.d.ts +3 -0
  156. package/dist/type-guards.d.ts.map +1 -0
  157. package/dist/type-guards.js +4 -0
  158. package/dist/typecheck-test-policy.d.ts +8 -5
  159. package/dist/typecheck-test-policy.d.ts.map +1 -1
  160. package/dist/typecheck-test-policy.js +113 -100
  161. package/dist/workspace-config-policy.d.ts +8 -0
  162. package/dist/workspace-config-policy.d.ts.map +1 -1
  163. package/dist/workspace-config-policy.js +175 -63
  164. package/dist/workspace-index.d.ts +12 -0
  165. package/dist/workspace-index.d.ts.map +1 -0
  166. package/dist/workspace-index.js +17 -0
  167. package/dist/workspace-manifest.d.ts +37 -0
  168. package/dist/workspace-manifest.d.ts.map +1 -1
  169. package/executors.json +5 -0
  170. package/loader.js +13 -11
  171. package/managed/raw/envrc +33 -67
  172. package/managed/raw/git-format-staged.yml +30 -35
  173. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  174. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  175. package/managed/raw/tooling/direnv/developer-links.ts +569 -11
  176. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
  177. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  178. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  179. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  180. package/managed/raw/tooling/direnv/repo-path +14 -2
  181. package/managed/raw/tooling/direnv/setup-environment.ts +962 -148
  182. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  183. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  184. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  185. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  186. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  187. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  188. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  189. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  190. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  191. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  192. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  194. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  196. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  197. package/managed/templates/github/workflows/managed-files.yml +1 -2
  198. package/nextest.toml +8 -41
  199. package/package.json +74 -12
  200. package/runtime-input.sh +81 -0
  201. package/src/__tests__/counted-cargo.ts +33 -14
  202. package/src/__tests__/fixture-nx-env.ts +111 -46
  203. package/src/__tests__/progress-clock.ts +43 -0
  204. package/src/__tests__/runtime-input.ts +23 -0
  205. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  206. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  207. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  208. package/src/bin/smoo-nx-exec.ts +16 -74
  209. package/src/bin/smoo-nx-failures.ts +4 -0
  210. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  211. package/src/bin/smoo-nx-test-walks.ts +42 -0
  212. package/src/bounded-test-policy.test.ts +268 -21
  213. package/src/bounded-test-policy.ts +114 -42
  214. package/src/build-state-output-policy.test.ts +115 -0
  215. package/src/build-state-output-policy.ts +90 -0
  216. package/src/bun-bootstrap.test.ts +57 -3
  217. package/src/bun-file-packages.test.ts +47 -0
  218. package/src/cargo-closure-input.test.ts +138 -66
  219. package/src/cargo-closure-input.ts +17 -15
  220. package/src/cargo-dev-profile.ts +137 -0
  221. package/src/cargo-resolve-cache.test.ts +70 -1
  222. package/src/cargo-source-hash.test.ts +193 -97
  223. package/src/cargo-source-hash.ts +345 -68
  224. package/src/cargo-toolchain-policy.ts +6 -0
  225. package/src/cargo-workspace.test.ts +320 -0
  226. package/src/cargo-workspace.ts +336 -10
  227. package/src/cross-check-policy.test.ts +59 -1
  228. package/src/cross-check-policy.ts +25 -6
  229. package/src/disk-command-policy.test.ts +61 -0
  230. package/src/disk-command-policy.ts +107 -0
  231. package/src/ensure-built-receipt.test.ts +184 -0
  232. package/src/ensure-built-receipt.ts +263 -0
  233. package/src/ensure-built-witness.test.ts +344 -0
  234. package/src/ensure-built-witness.ts +252 -0
  235. package/src/ensure-built.test.ts +1036 -578
  236. package/src/ensure-built.ts +820 -224
  237. package/src/eslint-file-set.ts +9 -0
  238. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  239. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  240. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  241. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  242. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  243. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  244. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  245. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  246. package/src/executors/bounded-exec/executor.ts +565 -67
  247. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  248. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  249. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  250. package/src/executors/bounded-exec/progress.test.ts +79 -0
  251. package/src/executors/bounded-exec/progress.ts +118 -0
  252. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  253. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  254. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  255. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  256. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  257. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  258. package/src/executors/bounded-exec/schema.json +11 -5
  259. package/src/executors/bounded-exec/schema.ts +27 -11
  260. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  261. package/src/executors/bounded-exec/verdict.ts +433 -0
  262. package/src/executors/shard-timings/executor.ts +36 -0
  263. package/src/executors/shard-timings/schema.json +21 -0
  264. package/src/executors/shard-timings/schema.ts +4 -0
  265. package/src/failure-summary.ts +119 -0
  266. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  267. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  268. package/src/generators/create-package/generator.test.ts +6 -0
  269. package/src/generators/create-package/generator.ts +6 -2
  270. package/src/host-controller-wiring.test.ts +31 -0
  271. package/src/index.test.ts +909 -295
  272. package/src/index.ts +441 -143
  273. package/src/linked-snapshots.nx.test.ts +172 -0
  274. package/src/managed-files/ci-workflow.ts +54 -13
  275. package/src/managed-files/files.ts +65 -9
  276. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  277. package/src/managed-files/generator.test.ts +60 -1
  278. package/src/managed-files/json-edit.test.ts +216 -0
  279. package/src/managed-files/json-edit.ts +290 -0
  280. package/src/managed-files/managed-format-json.test.ts +308 -0
  281. package/src/managed-files/managed-format.ts +90 -2
  282. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  283. package/src/managed-files/publish-workflow.ts +285 -67
  284. package/src/managed-files/repo-path.test.ts +129 -0
  285. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  286. package/src/managed-files/tree.ts +11 -3
  287. package/src/manifest-hash.ts +2 -6
  288. package/src/nextest-code-bound.test.ts +155 -0
  289. package/src/nextest-code-bound.ts +195 -0
  290. package/src/nextest-extraction.test.ts +37 -5
  291. package/src/nextest-extraction.ts +51 -9
  292. package/src/nextest-partitions.test.ts +427 -82
  293. package/src/nx-cache-bound.test.ts +5 -10
  294. package/src/nx-cache-restore-mtime.test.ts +170 -0
  295. package/src/nx-daemon-claim.test.ts +277 -0
  296. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  297. package/src/nx-daemon-idle-policy.test.ts +51 -0
  298. package/src/nx-daemon-ignore-files.test.ts +210 -0
  299. package/src/nx-daemon-root-normalization.test.ts +105 -0
  300. package/src/nx-daemon-validity.test.ts +925 -0
  301. package/src/nx-dot-input-policy.test.ts +353 -0
  302. package/src/nx-failure-life-cycles.test.ts +207 -0
  303. package/src/nx-files-archive-racy.test.ts +97 -0
  304. package/src/nx-foreign-workspace-env.test.ts +329 -0
  305. package/src/nx-incomplete-run-summary.test.ts +70 -0
  306. package/src/nx-plugin-load-errors.test.ts +120 -0
  307. package/src/nx-project-resolution-cache.test.ts +176 -0
  308. package/src/nx-raw-inputs.test.ts +166 -0
  309. package/src/nx-resident-graph-workers.test.ts +7 -16
  310. package/src/nx-run-information.test.ts +118 -0
  311. package/src/nx-skipped-task-exit.test.ts +180 -0
  312. package/src/nx-state-location.test.ts +63 -0
  313. package/src/nx-store-resolution.test.ts +26 -25
  314. package/src/nx-task-graph-cycles.test.ts +148 -0
  315. package/src/nx-task-output-lease.test.ts +414 -0
  316. package/src/nx-use-local.test.ts +103 -0
  317. package/src/package-target-policy.ts +3 -6
  318. package/src/release-config-policy.ts +3 -6
  319. package/src/runtime-input.test.ts +215 -0
  320. package/src/runtime-input.ts +17 -0
  321. package/src/rust-tokens.ts +78 -0
  322. package/src/serial-group-wiring.test.ts +326 -0
  323. package/src/task-history-namespace.test.ts +87 -89
  324. package/src/task-results.test.ts +226 -0
  325. package/src/task-results.ts +75 -0
  326. package/src/test-program.test.ts +303 -0
  327. package/src/test-program.ts +341 -0
  328. package/src/test-timings.test.ts +240 -0
  329. package/src/test-timings.ts +311 -0
  330. package/src/test-walk-policy.test.ts +585 -0
  331. package/src/test-walk-policy.ts +731 -0
  332. package/src/testing.test.ts +509 -0
  333. package/src/testing.ts +922 -0
  334. package/src/type-guards.ts +4 -0
  335. package/src/typecheck-test-policy.test.ts +496 -11
  336. package/src/typecheck-test-policy.ts +137 -103
  337. package/src/workspace-config-policy.test.ts +212 -13
  338. package/src/workspace-config-policy.ts +101 -73
  339. package/src/workspace-index.ts +18 -0
  340. package/src/workspace-manifest.ts +41 -0
  341. package/test-timings.json +85 -30
  342. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
  343. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
@@ -0,0 +1,605 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import {
3
+ chmodSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ mkdtempSync,
7
+ readdirSync,
8
+ readFileSync,
9
+ rmdirSync,
10
+ rmSync,
11
+ statSync,
12
+ symlinkSync,
13
+ writeFileSync,
14
+ } from 'node:fs';
15
+ import { tmpdir, userInfo } from 'node:os';
16
+ import { join } from 'node:path';
17
+ import { fileURLToPath } from 'node:url';
18
+ import type { OpContextBinding } from '@smoothbricks/lmao';
19
+ import { useTestSpan } from '@smoothbricks/lmao/testing/bun';
20
+ import { pidsWorkingIn, processTable, terminate } from '../../testing.js';
21
+ import {
22
+ type CommandOutput,
23
+ createHostCommands,
24
+ type HostCommands,
25
+ leaseProcessesOn,
26
+ mountsBelow,
27
+ operationDisk,
28
+ type RamDisk,
29
+ type RamTempError,
30
+ type RamTempPaths,
31
+ RamTempVolume,
32
+ ramDisksIn,
33
+ } from './ram-temp.js';
34
+ import { registryDevice } from './ram-temp-fixtures.js';
35
+
36
+ const MIB = 1024 * 1024;
37
+
38
+ /**
39
+ * A volume of its own for one test: a lock beside it, and a name and a size no other test
40
+ * process uses, since the size and the user are what identify a RAM disk as this volume's.
41
+ */
42
+ function scratchVolume(index: number): { parent: string; paths: RamTempPaths; capacity: number } {
43
+ const parent = mkdtempSync(join(process.env.TMPDIR ?? '/tmp', 'rt-'));
44
+ const name = `smoo-ram-test-${process.pid}-${index}`;
45
+ return {
46
+ parent,
47
+ paths: {
48
+ mountpoint: join('/Volumes', name),
49
+ lockFile: join(parent, 'v.lock'),
50
+ volumeName: name,
51
+ staging: `/private/tmp/${name}-new`,
52
+ user: userInfo().username,
53
+ },
54
+ capacity: 64 * MIB + (process.pid * 4 + index + 1) * 512,
55
+ };
56
+ }
57
+
58
+ async function attachedDisks(paths: RamTempPaths, capacity: number): Promise<RamDisk[]> {
59
+ const info = await createHostCommands().run('/usr/bin/hdiutil', ['info']);
60
+ if (info.status !== 0) {
61
+ throw new Error(`inventory RAM disks: exit ${info.status}: ${info.stderr}`);
62
+ }
63
+ return ramDisksIn(info.stdout).filter((disk) => disk.user === paths.user && disk.sectors === capacity / 512);
64
+ }
65
+
66
+ async function detachAll(paths: RamTempPaths, capacity: number): Promise<void> {
67
+ const host = createHostCommands();
68
+ for (const disk of await attachedDisks(paths, capacity)) {
69
+ const output = await host.run('/usr/bin/hdiutil', ['detach', '-force', disk.physical]);
70
+ if (output.status !== 0) {
71
+ throw new Error(`hdiutil detach ${disk.physical}: exit ${output.status}: ${output.stderr}`);
72
+ }
73
+ }
74
+ }
75
+
76
+ /** A cowshed sandbox cannot attach images: creation fails at the host instead of leasing. */
77
+ function expectSandboxed(error: RamTempError): void {
78
+ expect(error.kind).toBe('provision-failed');
79
+ if (error.kind === 'provision-failed') {
80
+ expect(['hdiutil info', 'hdiutil attach']).toContain(error.step);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * The provisioning step a host call is: `mount_apfs` and `umount` of the private staging mount, or
86
+ * the `diskutil mount` that places the volume. Null for every other call.
87
+ */
88
+ function stepOf(file: string, args: readonly string[]): string | null {
89
+ if (file === '/sbin/mount_apfs') {
90
+ return 'mount_apfs';
91
+ }
92
+ if (file === '/sbin/umount') {
93
+ return 'unmount';
94
+ }
95
+ return file === '/usr/sbin/diskutil' && args[0] === 'mount' ? 'mount' : null;
96
+ }
97
+
98
+ /** A readonly tree, two directories deep, with a file at each level. */
99
+ function readonlyTree(directory: string): void {
100
+ const tree = join(directory, 'tree');
101
+ const inner = join(tree, 'inner');
102
+ mkdirSync(inner, { recursive: true });
103
+ writeFileSync(join(tree, 'file'), 'in a readonly directory');
104
+ writeFileSync(join(inner, 'deep'), 'in a nested readonly directory');
105
+ chmodSync(inner, 0o500);
106
+ chmodSync(tree, 0o555);
107
+ }
108
+
109
+ /** The directory a lease's link points at: it must keep its mode and contents, never be followed. */
110
+ function expectUntouched(outside: string): void {
111
+ expect(statSync(outside).mode & 0o777).toBe(0o555);
112
+ expect(readFileSync(join(outside, 'keep'), 'utf8')).toBe('outside the lease');
113
+ }
114
+
115
+ async function nativeRamVolume(): Promise<void> {
116
+ const { parent, paths, capacity } = scratchVolume(1);
117
+ const trace = useTestSpan<OpContextBinding>();
118
+ const caseStartedAt = Date.now();
119
+ process.stderr.write(`RAM lifecycle case started pid=${process.pid} wallAtMs=${caseStartedAt}\n`);
120
+ const processes = leaseProcessesOn({
121
+ async workingIn(directory) {
122
+ const startedAt = Date.now();
123
+ const starting = JSON.stringify({
124
+ phase: 'cwd-census-start',
125
+ directory,
126
+ pid: process.pid,
127
+ wallAtMs: startedAt,
128
+ caseElapsedMs: startedAt - caseStartedAt,
129
+ });
130
+ trace.log.info(starting);
131
+ process.stderr.write(`${starting}\n`);
132
+ try {
133
+ const pids = await pidsWorkingIn(directory);
134
+ const endedAt = Date.now();
135
+ const finished = JSON.stringify({
136
+ phase: 'cwd-census-end',
137
+ directory,
138
+ pid: process.pid,
139
+ wallAtMs: endedAt,
140
+ elapsedMs: endedAt - startedAt,
141
+ caseElapsedMs: endedAt - caseStartedAt,
142
+ pids,
143
+ });
144
+ trace.log.info(finished);
145
+ process.stderr.write(`${finished}\n`);
146
+ return pids;
147
+ } catch (error) {
148
+ const endedAt = Date.now();
149
+ const details = typeof error === 'object' && error !== null ? error : {};
150
+ const failed = JSON.stringify(
151
+ {
152
+ phase: 'cwd-census-error',
153
+ directory,
154
+ pid: process.pid,
155
+ wallAtMs: endedAt,
156
+ elapsedMs: endedAt - startedAt,
157
+ caseElapsedMs: endedAt - caseStartedAt,
158
+ message: error instanceof Error ? error.message : String(error),
159
+ code: 'code' in details ? details.code : null,
160
+ signal: 'signal' in details ? details.signal : null,
161
+ killed: 'killed' in details ? details.killed : null,
162
+ },
163
+ null,
164
+ 2,
165
+ );
166
+ trace.log.info(failed);
167
+ process.stderr.write(`${failed}\n`);
168
+ throw error;
169
+ }
170
+ },
171
+ table: processTable,
172
+ signal: terminate,
173
+ });
174
+ // A readonly directory outside every lease. Each lease links to it: removal must unlink the
175
+ // link and never follow it, leaving this directory's mode and contents as they were.
176
+ const outside = join(parent, 'outside');
177
+ mkdirSync(outside);
178
+ writeFileSync(join(outside, 'keep'), 'outside the lease');
179
+ chmodSync(outside, 0o555);
180
+ // The host's own commands, with one injectable image in the I/O Registry listing. The steps that
181
+ // mount, unmount or place the volume are recorded in the order provisioning runs them.
182
+ const delegate = createHostCommands();
183
+ const host: HostCommands = {
184
+ async run(file, args, deadlineMs) {
185
+ const startedAt = Date.now();
186
+ const starting = JSON.stringify({
187
+ phase: 'native-host-command-start',
188
+ file,
189
+ args,
190
+ deadlineMs: deadlineMs ?? null,
191
+ wallAtMs: startedAt,
192
+ caseElapsedMs: startedAt - caseStartedAt,
193
+ });
194
+ process.stderr.write(`${starting}\n`);
195
+ trace.log.info(starting);
196
+ const delegateStartedAt = Date.now();
197
+ const output = await delegate.run(file, args, deadlineMs);
198
+ const endedAt = Date.now();
199
+ const finished = JSON.stringify({
200
+ phase: 'native-host-command-end',
201
+ file,
202
+ args,
203
+ status: output.status,
204
+ stderr: output.stderr,
205
+ wallAtMs: endedAt,
206
+ elapsedMs: endedAt - startedAt,
207
+ delegateStartedWallAtMs: delegateStartedAt,
208
+ observationBeforeDelegateMs: delegateStartedAt - startedAt,
209
+ delegateElapsedMs: endedAt - delegateStartedAt,
210
+ caseElapsedMs: endedAt - caseStartedAt,
211
+ });
212
+ process.stderr.write(`${finished}\n`);
213
+ trace.log.info(finished);
214
+ return output;
215
+ },
216
+ };
217
+ const attachedBelow: { image: string | null; failInventory: boolean } = { image: null, failInventory: false };
218
+ const provisioning: string[] = [];
219
+ const commands: HostCommands = {
220
+ async run(file, args) {
221
+ const step = stepOf(file, args);
222
+ if (step !== null) {
223
+ provisioning.push(step);
224
+ }
225
+ if (step === 'unmount') {
226
+ // The volume leaves the staging directory only once its marker is in it.
227
+ expect(readFileSync(join(paths.staging, '.smoo-ram'), 'utf8')).toBe(`${paths.volumeName}\n`);
228
+ }
229
+ if (file === '/usr/sbin/ioreg' && attachedBelow.failInventory) {
230
+ attachedBelow.failInventory = false;
231
+ return { status: 1, stdout: '', stderr: 'injected holder inventory failure' };
232
+ }
233
+ const output = await host.run(file, args);
234
+ return file === '/usr/sbin/ioreg' && attachedBelow.image !== null
235
+ ? {
236
+ ...output,
237
+ stdout: [output.stdout, ...registryDevice(`file://${attachedBelow.image}`, 'disk999')].join('\n'),
238
+ }
239
+ : output;
240
+ },
241
+ };
242
+ const alive = new Set([101, 202]);
243
+ const first = new RamTempVolume(paths, capacity, commands, 101, (pid) => alive.has(pid), processes);
244
+ const second = new RamTempVolume(paths, capacity, commands, 202, (pid) => alive.has(pid), processes);
245
+ const run = async (file: string, args: string[]): Promise<string> => {
246
+ const output = await host.run(file, args);
247
+ if (output.status !== 0) {
248
+ throw new Error(`${file} ${args.join(' ')}: exit ${output.status}: ${output.stderr}`);
249
+ }
250
+ return output.stdout;
251
+ };
252
+ const volume = new RamTempVolume(paths, capacity, host, undefined, undefined, processes);
253
+ try {
254
+ // The debris: a volume mounted at the mountpoint by a creator that died before its marker
255
+ // (the order this module used to create in), and a RAM disk whose deadlined attach finished
256
+ // with nobody left to format it.
257
+ const sectors = `ram://${capacity / 512}`;
258
+ const orphan = await host.run('/usr/bin/hdiutil', ['attach', '-nomount', sectors]);
259
+ if (orphan.status !== 0) {
260
+ const acquired = await volume.acquire();
261
+ expect(acquired.ok).toBe(false);
262
+ if (!acquired.ok) {
263
+ expectSandboxed(acquired.error);
264
+ }
265
+ return;
266
+ }
267
+ const physical = /^(\/dev\/disk\d+)\b/.exec(orphan.stdout)?.[1] ?? '';
268
+ const container = operationDisk(await run('/usr/sbin/diskutil', ['apfs', 'createContainer', physical])) ?? '';
269
+ const orphanVolume =
270
+ operationDisk(
271
+ await run('/usr/sbin/diskutil', ['apfs', 'addVolume', container, 'APFS', paths.volumeName, '-nomount']),
272
+ ) ?? '';
273
+ await run('/usr/sbin/diskutil', ['mount', '-mountOptions', 'nobrowse', orphanVolume]);
274
+ await run('/usr/bin/hdiutil', ['attach', '-nomount', sectors]);
275
+ expect((await attachedDisks(paths, capacity)).map((disk) => disk.mountpoints)).toEqual([[paths.mountpoint], []]);
276
+
277
+ // An unmarked volume that carries a lease is someone's TMPDIR: it is named, not detached.
278
+ const lease = join(paths.mountpoint, `${process.pid}-abcdef`);
279
+ mkdirSync(lease);
280
+ const refused = await volume.acquire();
281
+ expect(refused).toEqual({
282
+ ok: false,
283
+ error: {
284
+ kind: 'provision-failed',
285
+ step: 'reclaim',
286
+ detail: `${physical} at ${paths.mountpoint} has no marker but carries leases ${process.pid}-abcdef; not detached`,
287
+ },
288
+ });
289
+ expect(existsSync(lease)).toBe(true);
290
+ rmdirSync(lease);
291
+
292
+ const a = await first.acquire();
293
+ if (!a.ok || a.value.kind !== 'leased') {
294
+ throw new Error(`lease over the debris failed: ${JSON.stringify(a)}`);
295
+ }
296
+ expect(a.value.kind).toBe('leased');
297
+ // Mounted and marked at its staging directory, unmounted, then placed by DiskArbitration: never renamed.
298
+ expect(provisioning).toEqual(['mount_apfs', 'unmount', 'mount']);
299
+ expect(a.value.lease.mountpoint).toBe(paths.mountpoint);
300
+ expect(readFileSync(join(paths.mountpoint, '.smoo-ram'), 'utf8')).toBe(`${paths.volumeName}\n`);
301
+ expect(existsSync(`${paths.mountpoint} 1`)).toBe(false);
302
+ expect((await attachedDisks(paths, capacity)).map((disk) => disk.mountpoints)).toEqual([[paths.mountpoint]]);
303
+
304
+ const leaseA = a.value.lease;
305
+ const b = await second.acquire();
306
+ if (!b.ok || b.value.kind !== 'leased') {
307
+ throw new Error(`second lease failed: ${JSON.stringify(b)}`);
308
+ }
309
+ const leaseB = b.value.lease;
310
+ readonlyTree(leaseB.directory);
311
+ symlinkSync(outside, join(leaseB.directory, 'outside-link'));
312
+ expect(leaseA.mountpoint).toBe(paths.mountpoint);
313
+ expect(leaseB.mountpoint).toBe(paths.mountpoint);
314
+ expect(leaseA.directory).not.toBe(leaseB.directory);
315
+ expect(statSync(leaseA.directory).dev).not.toBe(statSync(parent).dev);
316
+ writeFileSync(join(leaseA.directory, 'scratch'), 'on RAM');
317
+ readonlyTree(leaseA.directory);
318
+ symlinkSync(outside, join(leaseA.directory, 'outside-link'));
319
+
320
+ expect(await first.release(leaseA)).toEqual({ ok: true, value: undefined });
321
+ expect(existsSync(leaseA.directory)).toBe(false);
322
+ expectUntouched(outside);
323
+ expect(statSync(leaseB.directory).dev).not.toBe(statSync(parent).dev);
324
+
325
+ // The second task dies without releasing, with an image still attached from its lease: the
326
+ // registry entry is injected, so the test spends no attach of its own. The next task keeps
327
+ // the lease and names it instead of detaching another owner's image.
328
+ alive.delete(202);
329
+ const image = join(leaseB.directory, 'store', 'main.asif');
330
+ attachedBelow.image = image;
331
+ const third = new RamTempVolume(paths, capacity, commands, 101, (pid) => alive.has(pid), processes);
332
+ // A failed acquire must not leave its new live-pid lease or reclaim claim behind. Reuse
333
+ // this mounted volume: no extra attach is needed to cover the failed-publication path.
334
+ attachedBelow.failInventory = true;
335
+ const failedAcquire = await third.acquire();
336
+ expect(failedAcquire).toMatchObject({
337
+ ok: false,
338
+ error: { kind: 'provision-failed', step: 'ioreg (attached disk images)' },
339
+ });
340
+ expect(JSON.stringify(failedAcquire)).toContain('injected holder inventory failure');
341
+ expect(readdirSync(paths.mountpoint).filter((name) => /^\d+-[A-Za-z0-9]{6}$/.test(name))).toEqual([
342
+ leaseB.directory.slice(paths.mountpoint.length + 1),
343
+ ]);
344
+ expect(JSON.parse(readFileSync(`${paths.lockFile}.ledger`, 'utf8'))).toMatchObject({
345
+ lifecycle: null,
346
+ claims: [],
347
+ });
348
+ const c = await third.acquire();
349
+ if (!c.ok || c.value.kind !== 'leased') {
350
+ throw new Error(`third lease failed: ${JSON.stringify(c)}`);
351
+ }
352
+ expect(c.value.held).toEqual([
353
+ `${leaseB.directory} is kept: ${image} (/dev/disk999) still attached from below it; detach through its owner`,
354
+ ]);
355
+ expect(existsSync(leaseB.directory)).toBe(true);
356
+ // Held from below: the lease stays whole, its readonly tree and the link with it.
357
+ expect(statSync(join(leaseB.directory, 'tree')).mode & 0o777).toBe(0o555);
358
+ expect(statSync(join(leaseB.directory, 'tree', 'inner')).mode & 0o777).toBe(0o500);
359
+ expect(existsSync(join(leaseB.directory, 'tree', 'inner', 'deep'))).toBe(true);
360
+ expectUntouched(outside);
361
+ expect(await third.release(c.value.lease)).toEqual({ ok: true, value: undefined });
362
+ expect(existsSync(c.value.lease.directory)).toBe(false);
363
+ expect(statSync(leaseB.directory).dev).not.toBe(statSync(parent).dev);
364
+ expect(statSync(join(leaseB.directory, 'tree')).mode & 0o777).toBe(0o555);
365
+
366
+ // Once its owner has detached the image, the next task reclaims the lease, and its release,
367
+ // the last, detaches the volume.
368
+ attachedBelow.image = null;
369
+ const fourth = new RamTempVolume(paths, capacity, commands, 101, (pid) => alive.has(pid), processes);
370
+ const d = await fourth.acquire();
371
+ if (!d.ok || d.value.kind !== 'leased') {
372
+ throw new Error(`fourth lease failed: ${JSON.stringify(d)}`);
373
+ }
374
+ expect(d.value.held).toEqual([]);
375
+ expect(existsSync(leaseB.directory)).toBe(false);
376
+ expectUntouched(outside);
377
+ expect(await fourth.release(d.value.lease)).toEqual({ ok: true, value: undefined });
378
+ expect(existsSync(paths.mountpoint)).toBe(false);
379
+ expect(await attachedDisks(paths, capacity)).toEqual([]);
380
+ } finally {
381
+ // Restore the owner write the outside directory was given, so the parent can be removed.
382
+ chmodSync(outside, 0o755);
383
+ await detachAll(paths, capacity);
384
+ rmSync(parent, { recursive: true, force: true });
385
+ }
386
+ }
387
+
388
+ /** The provisioning steps a test fails in turn, each with the step name its failure must report. */
389
+ const FAILING_STEPS = [
390
+ { injected: 'mount_apfs', reported: 'mount_apfs (staging)' },
391
+ { injected: 'unmount', reported: 'umount (staging)' },
392
+ { injected: 'mount', reported: 'diskutil mount' },
393
+ ] as const;
394
+
395
+ /**
396
+ * A provisioning step that fails leaves nothing under the final name: the failure detaches the whole
397
+ * disk, with the staging mount on it, and removes the staging directory the attempt made.
398
+ */
399
+ async function aFailedStepLeavesNoNamedVolume(): Promise<void> {
400
+ const trace = useTestSpan<OpContextBinding>();
401
+ process.stderr.write(`RAM provisioning case started in ${process.pid}\n`);
402
+ for (const { injected, reported } of FAILING_STEPS) {
403
+ const { parent, paths, capacity } = scratchVolume(2);
404
+ const host = createHostCommands();
405
+ const calls: { file: string; args: readonly string[]; output: CommandOutput }[] = [];
406
+ const commands: HostCommands = {
407
+ async run(file, args, deadlineMs) {
408
+ const record =
409
+ stepOf(file, args) !== null ||
410
+ (file === '/usr/bin/hdiutil' && ['attach', 'detach'].includes(args[0] ?? '')) ||
411
+ (file === '/usr/sbin/diskutil' && args[0] === 'apfs');
412
+ const startedAt = Date.now();
413
+ const starting = JSON.stringify({ injected, phase: 'command-start', file, args });
414
+ trace.log.info(starting);
415
+ process.stderr.write(`${starting}\n`);
416
+ const output =
417
+ stepOf(file, args) === injected
418
+ ? { status: 1, stdout: '', stderr: 'injected' }
419
+ : await host.run(file, args, deadlineMs);
420
+ if (record) {
421
+ calls.push({ file, args, output });
422
+ }
423
+ const finished = JSON.stringify({
424
+ injected,
425
+ phase: 'command-end',
426
+ file,
427
+ args,
428
+ output: record
429
+ ? output
430
+ : { status: output.status, stderr: output.stderr, stdoutBytes: Buffer.byteLength(output.stdout) },
431
+ elapsedMs: Date.now() - startedAt,
432
+ });
433
+ trace.log.info(finished);
434
+ process.stderr.write(`${finished}\n`);
435
+ return output;
436
+ },
437
+ };
438
+ try {
439
+ const refused = await new RamTempVolume(paths, capacity, commands).acquire();
440
+ const refusal = JSON.stringify({ injected, refused }, null, 2);
441
+ trace.log.info(refusal);
442
+ process.stderr.write(`${refusal}\n`);
443
+ const failedDetach = calls.find(
444
+ (call) => call.file === '/usr/bin/hdiutil' && call.args[0] === 'detach' && call.output.status !== 0,
445
+ );
446
+ if (failedDetach !== undefined) {
447
+ const mountTable = await host.run('/sbin/mount', [], 1_000);
448
+ const filesystemHolders = await host.run(
449
+ '/usr/bin/sudo',
450
+ ['-n', '/usr/sbin/lsof', '-nP', '+f', '--', paths.staging],
451
+ 1_000,
452
+ );
453
+ const added = calls.find(
454
+ (call) => call.file === '/usr/sbin/diskutil' && call.args[0] === 'apfs' && call.args[1] === 'addVolume',
455
+ );
456
+ const volume = added === undefined ? null : operationDisk(added.output.stdout);
457
+ const devices = failedDetach.args.filter((argument) => argument.startsWith('/dev/disk'));
458
+ if (volume !== null) devices.push(`/dev/${volume}`);
459
+ if (devices.length === 0) throw new Error('rollback detach recorded no device for its diagnostic probe');
460
+ const devicePaths: string[] = [];
461
+ for (const device of devices) devicePaths.push(device, device.replace('/dev/', '/dev/r'));
462
+ const deviceHolders = await host.run(
463
+ '/usr/bin/sudo',
464
+ ['-n', '/usr/sbin/lsof', '-nP', '--', ...devicePaths],
465
+ 1_000,
466
+ );
467
+ const observations = JSON.stringify(
468
+ {
469
+ injected,
470
+ phase: 'rollback-refused-observations',
471
+ mountTable: {
472
+ status: mountTable.status,
473
+ stderr: mountTable.stderr,
474
+ matching: mountTable.stdout.split('\n').filter((line) => line.includes(paths.staging)),
475
+ },
476
+ filesystemHolders,
477
+ devicePaths,
478
+ deviceHolders,
479
+ },
480
+ null,
481
+ 2,
482
+ );
483
+ trace.log.info(observations);
484
+ process.stderr.write(`${observations}\n`);
485
+ }
486
+ // A cowshed sandbox cannot attach images, so provisioning stops before the injected step.
487
+ if (!refused.ok && refused.error.kind === 'provision-failed' && refused.error.step !== reported) {
488
+ expectSandboxed(refused.error);
489
+ continue;
490
+ }
491
+ const detail = JSON.stringify({ injected, refused, calls }, null, 2);
492
+ expect(refused, detail).toEqual({
493
+ ok: false,
494
+ error: { kind: 'provision-failed', step: reported, detail: 'exit 1: injected' },
495
+ });
496
+ expect(
497
+ calls
498
+ .filter((call) => call.file === '/usr/bin/hdiutil' && call.args[0] === 'detach')
499
+ .map((call) => call.output.status),
500
+ detail,
501
+ ).toEqual([0]);
502
+ const listed = await host.run('/usr/sbin/diskutil', ['list']);
503
+ const remaining = listed.stdout.split('\n').filter((line) => line.includes(paths.volumeName));
504
+ const inventory = JSON.stringify({ injected, inventory: { status: listed.status, remaining } }, null, 2);
505
+ trace.log.info(inventory);
506
+ process.stderr.write(`${inventory}\n`);
507
+ expect(listed.status).toBe(0);
508
+ expect(remaining, detail).toEqual([]);
509
+ const table = await host.run('/sbin/mount', []);
510
+ expect(table.status).toBe(0);
511
+ expect(mountsBelow(table.stdout, paths.mountpoint)).toEqual([]);
512
+ expect(mountsBelow(table.stdout, paths.staging)).toEqual([]);
513
+ expect(existsSync(paths.staging)).toBe(false);
514
+ } finally {
515
+ trace.log.info(JSON.stringify({ injected, phase: 'test-teardown-start' }));
516
+ await detachAll(paths, capacity);
517
+ rmSync(parent, { recursive: true, force: true });
518
+ trace.log.info(JSON.stringify({ injected, phase: 'test-teardown-done' }));
519
+ }
520
+ }
521
+ }
522
+
523
+ /** The non-Darwin executor owns no RAM disk: inherited and target-supplied temp directories stay with their owner. */
524
+ async function inheritedTempDirectory(): Promise<void> {
525
+ const root = mkdtempSync(join(tmpdir(), 'rt-policy-'));
526
+ const inherited = join(root, 'inherited');
527
+ const supplied = join(root, 'supplied');
528
+ const executor = fileURLToPath(new URL('../../../dist/executors/bounded-exec/executor.js', import.meta.url));
529
+ try {
530
+ for (const directory of [inherited, supplied]) {
531
+ mkdirSync(directory);
532
+ writeFileSync(join(directory, 'owned'), 'not a RAM lease');
533
+ }
534
+ const probe = join(root, 'probe.mjs');
535
+ writeFileSync(
536
+ probe,
537
+ [
538
+ "import { writeFileSync } from 'node:fs';",
539
+ "import { tmpdir } from 'node:os';",
540
+ "import { join } from 'node:path';",
541
+ "writeFileSync(join(tmpdir(), 'proof'), process.env.TMPDIR);",
542
+ '',
543
+ ].join('\n'),
544
+ );
545
+ for (const directory of [inherited, supplied]) {
546
+ const options = {
547
+ command: `node ${JSON.stringify(probe)}`,
548
+ timeoutMs: 5_000,
549
+ parallelism: 1,
550
+ env: {
551
+ // If the default runner incorrectly provisions an APFS volume here, it must fail,
552
+ // not silently use this host's cowshed or disk tools.
553
+ COWSHED_EXECUTABLE: join(root, 'no-disk-tools'),
554
+ ...(directory === supplied ? { TMPDIR: supplied } : {}),
555
+ },
556
+ };
557
+ const script = [
558
+ `import { runDefaultBoundedExec } from ${JSON.stringify(executor)};`,
559
+ `const result = await runDefaultBoundedExec(${JSON.stringify(options)}, ${JSON.stringify({ root })});`,
560
+ 'console.log(JSON.stringify(result));',
561
+ 'process.exitCode = result.success ? 0 : 1;',
562
+ ].join('\n');
563
+ const child = Bun.spawn(['node', '--input-type=module', '-e', script], {
564
+ env: { ...process.env, TMPDIR: inherited },
565
+ stdout: 'pipe',
566
+ stderr: 'pipe',
567
+ });
568
+ const [stdout, stderr, exitCode] = await Promise.all([
569
+ new Response(child.stdout).text(),
570
+ new Response(child.stderr).text(),
571
+ child.exited,
572
+ ]);
573
+ expect(exitCode, stdout + stderr).toBe(0);
574
+ expect(readFileSync(join(directory, 'proof'), 'utf8')).toBe(directory);
575
+ for (const owned of [inherited, supplied]) {
576
+ expect(readFileSync(join(owned, 'owned'), 'utf8')).toBe('not a RAM lease');
577
+ }
578
+ }
579
+ } finally {
580
+ rmSync(root, { recursive: true, force: true });
581
+ }
582
+ }
583
+
584
+ // Both platforms execute a host proof. APFS leasing is Darwin's contract; other hosts keep
585
+ // their inherited TMPDIR. Running Darwin's fixture there would test a feature the runner never uses.
586
+ describe('temporary-directory policy on this host', () => {
587
+ if (process.platform === 'darwin') {
588
+ it(
589
+ 'reclaims what a dead creator left, shares the volume between leases, and detaches it at the last release, never mounting beside it as "<name> 1"',
590
+ nativeRamVolume,
591
+ 60_000,
592
+ );
593
+ it(
594
+ 'leaves no volume under its final name, and no staging directory, when any provisioning step fails',
595
+ aFailedStepLeavesNoNamedVolume,
596
+ 180_000,
597
+ );
598
+ } else {
599
+ it(
600
+ 'keeps inherited temporary storage, honors a target override, and never provisions an APFS disk',
601
+ inheritedTempDirectory,
602
+ 30_000,
603
+ );
604
+ }
605
+ });