@smoothbricks/nx-plugin 0.5.7 → 0.6.1

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 (446) hide show
  1. package/README.md +1097 -360
  2. package/dist/.build-inputs.json +141 -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 +22 -5
  48. package/dist/ensure-built-receipt.d.ts.map +1 -1
  49. package/dist/ensure-built-receipt.js +168 -48
  50. package/dist/ensure-built-witness.d.ts +27 -8
  51. package/dist/ensure-built-witness.d.ts.map +1 -1
  52. package/dist/ensure-built-witness.js +45 -15
  53. package/dist/ensure-built.d.ts.map +1 -1
  54. package/dist/ensure-built.js +9 -1
  55. package/dist/eslint-config-closure.d.ts +7 -0
  56. package/dist/eslint-config-closure.d.ts.map +1 -0
  57. package/dist/eslint-config-closure.js +346 -0
  58. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  59. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  60. package/dist/executors/bounded-exec/bounds.js +43 -0
  61. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +28 -0
  62. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -0
  63. package/dist/executors/bounded-exec/cpu-pool-thread.js +20 -0
  64. package/dist/executors/bounded-exec/cpu-pool.d.ts +35 -38
  65. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  66. package/dist/executors/bounded-exec/cpu-pool.js +56 -120
  67. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  68. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/executor.js +389 -239
  70. package/dist/executors/bounded-exec/gateway-lease.d.ts +23 -19
  71. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/gateway-lease.js +102 -29
  73. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  74. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  75. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  76. package/dist/executors/bounded-exec/lease-wait.d.ts +64 -0
  77. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  78. package/dist/executors/bounded-exec/lease-wait.js +72 -0
  79. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  80. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  82. package/dist/executors/bounded-exec/mbx-pool.d.ts +31 -0
  83. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -0
  84. package/dist/executors/bounded-exec/mbx-pool.js +24 -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 +10 -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 +122 -35
  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 +48 -11
  119. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  120. package/dist/executors/bounded-exec/verdict.js +89 -20
  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/emit-overrides.d.ts +14 -0
  135. package/dist/executors/typescript-emit/emit-overrides.d.ts.map +1 -0
  136. package/dist/executors/typescript-emit/emit-overrides.js +24 -0
  137. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  138. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  139. package/dist/executors/typescript-emit/executor.js +146 -33
  140. package/dist/forbidden-spelling-policy.d.ts +56 -0
  141. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  142. package/dist/forbidden-spelling-policy.js +176 -0
  143. package/dist/generators/create-package/generator.d.ts.map +1 -1
  144. package/dist/generators/create-package/generator.js +3 -4
  145. package/dist/graph-input-contract.d.ts +14 -0
  146. package/dist/graph-input-contract.d.ts.map +1 -1
  147. package/dist/graph-input-contract.js +67 -2
  148. package/dist/index.d.ts +23 -6
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +672 -214
  151. package/dist/managed-assets.d.ts +2 -0
  152. package/dist/managed-assets.d.ts.map +1 -1
  153. package/dist/managed-files/files.d.ts +3 -3
  154. package/dist/managed-files/files.d.ts.map +1 -1
  155. package/dist/managed-files/files.js +28 -3
  156. package/dist/managed-files/managed-format.d.ts.map +1 -1
  157. package/dist/managed-files/managed-format.js +1 -0
  158. package/dist/managed-files/publish-workflow.js +14 -11
  159. package/dist/nextest-code-bound.js +1 -0
  160. package/dist/nextest-timings.d.ts +35 -0
  161. package/dist/nextest-timings.d.ts.map +1 -0
  162. package/dist/nextest-timings.js +168 -0
  163. package/dist/owned-installation.d.ts +6 -5
  164. package/dist/owned-installation.d.ts.map +1 -1
  165. package/dist/owned-installation.js +150 -26
  166. package/dist/package-target-policy.d.ts.map +1 -1
  167. package/dist/package-target-policy.js +2 -3
  168. package/dist/process-children.d.ts +7 -0
  169. package/dist/process-children.d.ts.map +1 -0
  170. package/dist/process-children.darwin.d.ts +7 -0
  171. package/dist/process-children.darwin.d.ts.map +1 -0
  172. package/dist/process-children.darwin.js +13 -0
  173. package/dist/process-children.js +14 -0
  174. package/dist/process-children.linux.d.ts +8 -0
  175. package/dist/process-children.linux.d.ts.map +1 -0
  176. package/dist/process-children.linux.js +25 -0
  177. package/dist/process-group.d.ts +108 -0
  178. package/dist/process-group.d.ts.map +1 -0
  179. package/dist/process-group.js +171 -0
  180. package/dist/process-listing.d.ts +7 -0
  181. package/dist/process-listing.d.ts.map +1 -0
  182. package/dist/process-listing.js +51 -0
  183. package/dist/producer-receipts.d.ts +8 -2
  184. package/dist/producer-receipts.d.ts.map +1 -1
  185. package/dist/producer-receipts.js +514 -47
  186. package/dist/task-graph-policy.d.ts +21 -0
  187. package/dist/task-graph-policy.d.ts.map +1 -0
  188. package/dist/task-graph-policy.js +91 -0
  189. package/dist/test-timings.js +4 -4
  190. package/dist/test-walk-policy.d.ts +14 -5
  191. package/dist/test-walk-policy.d.ts.map +1 -1
  192. package/dist/test-walk-policy.js +8 -2
  193. package/dist/testing.d.ts +73 -28
  194. package/dist/testing.d.ts.map +1 -1
  195. package/dist/testing.js +217 -223
  196. package/dist/tool-bins.d.ts +33 -0
  197. package/dist/tool-bins.d.ts.map +1 -0
  198. package/dist/tool-bins.js +72 -0
  199. package/dist/typecheck-test-policy.d.ts.map +1 -1
  200. package/dist/typecheck-test-policy.js +3 -4
  201. package/dist/wait-why-policy.d.ts +28 -0
  202. package/dist/wait-why-policy.d.ts.map +1 -0
  203. package/dist/wait-why-policy.js +223 -0
  204. package/dist/workspace-config-policy.d.ts +14 -8
  205. package/dist/workspace-config-policy.d.ts.map +1 -1
  206. package/dist/workspace-config-policy.js +60 -16
  207. package/dist/workspace-manifest.d.ts +41 -6
  208. package/dist/workspace-manifest.d.ts.map +1 -1
  209. package/dist/workspace-manifest.js +57 -0
  210. package/executors.json +16 -1
  211. package/loader.js +2 -0
  212. package/managed/raw/envrc +11 -0
  213. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  214. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  215. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  216. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  217. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  218. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  219. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  220. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  221. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  222. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  223. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  224. package/managed/raw/tooling/direnv/repo-path +68 -6
  225. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  226. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  227. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  228. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  229. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  230. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  231. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  232. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  233. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  234. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  235. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  236. package/package.json +95 -14
  237. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  238. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  239. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  240. package/src/bounded-test-policy.ts +12 -14
  241. package/src/build-state-output-policy.ts +458 -34
  242. package/src/bun-lock-scope.ts +108 -0
  243. package/src/cargo-build-script-env.ts +265 -0
  244. package/src/cargo-closure-input.ts +74 -7
  245. package/src/cargo-retention-hook.ts +94 -0
  246. package/src/cargo-source-hash.ts +138 -41
  247. package/src/cargo-toolchain-paths.ts +95 -0
  248. package/src/cargo-toolchain-policy.ts +49 -5
  249. package/src/cargo-workspace.ts +72 -123
  250. package/src/cross-check-policy.ts +12 -10
  251. package/src/disk-command-policy.ts +1 -0
  252. package/src/ensure-built-receipt.ts +173 -39
  253. package/src/ensure-built-witness.ts +62 -10
  254. package/src/ensure-built.ts +11 -1
  255. package/src/eslint-config-closure.ts +357 -0
  256. package/src/executors/bounded-exec/bounds.ts +76 -0
  257. package/src/executors/bounded-exec/cpu-pool-thread.ts +43 -0
  258. package/src/executors/bounded-exec/cpu-pool.ts +55 -120
  259. package/src/executors/bounded-exec/executor.ts +442 -260
  260. package/src/executors/bounded-exec/gateway-lease.ts +94 -35
  261. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  262. package/src/executors/bounded-exec/lease-wait.ts +116 -0
  263. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  264. package/src/executors/bounded-exec/mbx-pool.ts +48 -0
  265. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  266. package/src/executors/bounded-exec/progress.ts +9 -3
  267. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  268. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  269. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  270. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  271. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  272. package/src/executors/bounded-exec/run-cpu-pool.ts +129 -35
  273. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  274. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  275. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  276. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  277. package/src/executors/bounded-exec/schema.json +11 -2
  278. package/src/executors/bounded-exec/schema.ts +19 -1
  279. package/src/executors/bounded-exec/verdict.ts +145 -35
  280. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  281. package/src/executors/clean-outputs/executor.ts +1 -0
  282. package/src/executors/scriptc-native/executor.ts +394 -0
  283. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  284. package/src/executors/scriptc-native/schema.json +60 -0
  285. package/src/executors/scriptc-native/schema.ts +34 -0
  286. package/src/executors/typescript-emit/emit-overrides.ts +24 -0
  287. package/src/executors/typescript-emit/executor.ts +186 -38
  288. package/src/forbidden-spelling-policy.ts +226 -0
  289. package/src/generators/create-package/generator.ts +7 -7
  290. package/src/graph-input-contract.ts +61 -2
  291. package/src/index.ts +788 -224
  292. package/src/managed-assets.ts +3 -0
  293. package/src/managed-files/files.ts +28 -3
  294. package/src/managed-files/managed-format.ts +1 -0
  295. package/src/managed-files/publish-workflow.ts +20 -15
  296. package/src/nextest-code-bound.ts +1 -0
  297. package/src/nextest-timings.ts +106 -0
  298. package/src/owned-installation.ts +150 -23
  299. package/src/package-target-policy.ts +2 -3
  300. package/src/process-children.darwin.ts +14 -0
  301. package/src/process-children.linux.ts +33 -0
  302. package/src/process-children.ts +22 -0
  303. package/src/process-group.ts +209 -0
  304. package/src/process-listing.ts +54 -0
  305. package/src/producer-receipts.ts +92 -41
  306. package/src/task-graph-policy.ts +98 -0
  307. package/src/test-walk-policy.ts +23 -8
  308. package/src/testing.ts +240 -232
  309. package/src/tool-bins.ts +108 -0
  310. package/src/typecheck-test-policy.ts +2 -3
  311. package/src/wait-why-policy.ts +226 -0
  312. package/src/workspace-config-policy.ts +63 -15
  313. package/src/workspace-manifest.ts +89 -6
  314. package/test-timings.json +124 -99
  315. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  316. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  317. package/dist/bin/smoo-nx-failures.js +0 -3
  318. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  319. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  320. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  321. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  322. package/dist/failure-summary.d.ts +0 -5
  323. package/dist/failure-summary.d.ts.map +0 -1
  324. package/dist/failure-summary.js +0 -118
  325. package/dist/nextest-extraction.d.ts +0 -117
  326. package/dist/nextest-extraction.d.ts.map +0 -1
  327. package/dist/nextest-extraction.js +0 -303
  328. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  329. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  330. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  331. package/src/__tests__/counted-cargo-process.ts +0 -286
  332. package/src/__tests__/counted-cargo.ts +0 -713
  333. package/src/__tests__/directory-change.ts +0 -27
  334. package/src/__tests__/fixture-cargo-home.ts +0 -36
  335. package/src/__tests__/fixture-nx-env.ts +0 -193
  336. package/src/__tests__/owned-installation.ts +0 -13
  337. package/src/__tests__/past-tick.ts +0 -12
  338. package/src/__tests__/progress-clock.ts +0 -43
  339. package/src/__tests__/runtime-input.ts +0 -23
  340. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  341. package/src/bin/smoo-nx-failures.ts +0 -4
  342. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  343. package/src/bounded-test-policy.test.ts +0 -1029
  344. package/src/build-state-output-policy.test.ts +0 -115
  345. package/src/bun-bootstrap.test.ts +0 -102
  346. package/src/bun-file-packages.test.ts +0 -47
  347. package/src/cargo-closure-filesets.test.ts +0 -63
  348. package/src/cargo-closure-input.property.test.ts +0 -50
  349. package/src/cargo-closure-input.test.ts +0 -506
  350. package/src/cargo-closure-key.test.ts +0 -240
  351. package/src/cargo-resolve-cache.test.ts +0 -1181
  352. package/src/cargo-source-hash.test.ts +0 -707
  353. package/src/cargo-workspace.test.ts +0 -615
  354. package/src/cross-check-policy.test.ts +0 -316
  355. package/src/disk-command-policy.test.ts +0 -61
  356. package/src/ensure-built-receipt.test.ts +0 -279
  357. package/src/ensure-built-witness.test.ts +0 -688
  358. package/src/ensure-built.test.ts +0 -1462
  359. package/src/executors/all-verdicts/executor.test.ts +0 -135
  360. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  361. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  362. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  363. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  364. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  365. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  366. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  367. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  368. package/src/executors/bounded-exec/progress.test.ts +0 -139
  369. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  370. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  371. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  372. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  373. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  374. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  375. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  376. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  377. package/src/executors/clean-outputs/executor.test.ts +0 -20
  378. package/src/executors/typescript-emit/executor.test.ts +0 -83
  379. package/src/failure-summary.ts +0 -119
  380. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  381. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  382. package/src/generators/create-package/generator.test.ts +0 -190
  383. package/src/generators/make-public/generator.test.ts +0 -137
  384. package/src/graph-input-contract.test.ts +0 -379
  385. package/src/host-controller-wiring.test.ts +0 -31
  386. package/src/index.test.ts +0 -3321
  387. package/src/linked-snapshots.nx.test.ts +0 -254
  388. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  389. package/src/managed-files/generator.test.ts +0 -243
  390. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  391. package/src/managed-files/json-edit.test.ts +0 -216
  392. package/src/managed-files/managed-content.test.ts +0 -166
  393. package/src/managed-files/managed-format-json.test.ts +0 -308
  394. package/src/managed-files/repo-path.test.ts +0 -172
  395. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  396. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  397. package/src/managed-files/tree-permissions.test.ts +0 -109
  398. package/src/managed-files/tree.test.ts +0 -123
  399. package/src/manifest-hash.test.ts +0 -219
  400. package/src/nextest-code-bound.test.ts +0 -161
  401. package/src/nextest-extraction.test.ts +0 -216
  402. package/src/nextest-extraction.ts +0 -371
  403. package/src/nextest-partitions.test.ts +0 -501
  404. package/src/nx-cache-bound.test.ts +0 -109
  405. package/src/nx-cache-restore-mtime.test.ts +0 -170
  406. package/src/nx-daemon-claim.test.ts +0 -279
  407. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  408. package/src/nx-daemon-idle-policy.test.ts +0 -111
  409. package/src/nx-daemon-ignore-files.test.ts +0 -210
  410. package/src/nx-daemon-root-normalization.test.ts +0 -105
  411. package/src/nx-daemon-start-never.test.ts +0 -292
  412. package/src/nx-daemon-validity.test.ts +0 -1055
  413. package/src/nx-dot-input-policy.test.ts +0 -353
  414. package/src/nx-failure-life-cycles.test.ts +0 -207
  415. package/src/nx-files-archive-racy.test.ts +0 -97
  416. package/src/nx-foreign-workspace-env.test.ts +0 -329
  417. package/src/nx-incomplete-run-summary.test.ts +0 -70
  418. package/src/nx-plugin-load-errors.test.ts +0 -120
  419. package/src/nx-project-graph-errors.test.ts +0 -70
  420. package/src/nx-project-resolution-cache.test.ts +0 -176
  421. package/src/nx-raw-inputs.test.ts +0 -166
  422. package/src/nx-resident-graph-workers.test.ts +0 -112
  423. package/src/nx-run-information.test.ts +0 -118
  424. package/src/nx-skipped-task-exit.test.ts +0 -180
  425. package/src/nx-state-location.test.ts +0 -63
  426. package/src/nx-store-resolution.test.ts +0 -81
  427. package/src/nx-task-graph-cycles.test.ts +0 -148
  428. package/src/nx-task-output-lease.test.ts +0 -550
  429. package/src/nx-use-local.test.ts +0 -105
  430. package/src/owned-installation.test.ts +0 -105
  431. package/src/package-target-policy.test.ts +0 -1014
  432. package/src/producer-receipts.test.ts +0 -285
  433. package/src/release-config-policy.test.ts +0 -311
  434. package/src/runtime-input.test.ts +0 -393
  435. package/src/serial-group-wiring.test.ts +0 -326
  436. package/src/task-history-namespace.test.ts +0 -181
  437. package/src/task-results.test.ts +0 -228
  438. package/src/test-clock-policy.test.ts +0 -338
  439. package/src/test-program.test.ts +0 -303
  440. package/src/test-timings.test.ts +0 -240
  441. package/src/test-walk-policy.test.ts +0 -620
  442. package/src/testing.test.ts +0 -509
  443. package/src/typecheck-test-policy.test.ts +0 -1468
  444. package/src/typescript-resolution.test.ts +0 -76
  445. package/src/version-actions.test.ts +0 -80
  446. package/src/workspace-config-policy.test.ts +0 -737
@@ -0,0 +1,238 @@
1
+ import { connect, type Socket } from 'node:net';
2
+ import { readDetachAnswer } from './ram-detach.js';
3
+ import type { RamDiskLease, RamUnavailable, Result } from './ram-temp.js';
4
+
5
+ /**
6
+ * The client of the cowshed gateway's `ram-lease` (specs/cowshed/05_gateway.md, "RAM disks"). The RAM temp volume's
7
+ * disk lives in the `diskimages-helper` that `hdiutil attach ram://<n>` forks. Forked inside a task's job, the helper is
8
+ * that job's member, and the job's end retires it with the disk under every other job's lease on the volume. The helper
9
+ * belongs to the gateway, which no job contains and which attaches the disk; no job's retirement reaches it.
10
+ *
11
+ * The client writes one line, `{"op":"ram-lease","sectors":<n>}`, and keeps its connection open; the gateway answers
12
+ * one line, `{"ok":true,"ramDisk":{"device":"/dev/diskN","registryEntry":"0x…"}}` or a refusal. The connection is the
13
+ * lease: the gateway holds the disk until the client writes `{"end":"keep"}`, after which the disk is the caller's, or
14
+ * `{"end":"release"}`, which the gateway answers with its detach as `ram-detach` does. A connection that ends first,
15
+ * at the client's deadline or with its process, has the gateway detach the disk. An end the gateway never answers leaves
16
+ * nothing known: the gateway may have handed the disk over or left it to its next startup scan, so the caller detaches it
17
+ * by its entry.
18
+ */
19
+
20
+ export const RAM_LEASE_OP = 'ram-lease';
21
+
22
+ const WHOLE_DISK = /^\/dev\/disk\d+$/;
23
+ const REGISTRY_ENTRY = /^0x[0-9a-f]+$/;
24
+ /** A release answers what `ram-detach` does, whose native output the gateway bounds; no answer grows past that. */
25
+ const ANSWER_BYTES_MAX = 2 * 64 * 1024 * 6 + 4096;
26
+
27
+ /** What the lease's connection gave next: one answer line, or why it gave none. */
28
+ type Next =
29
+ | { readonly kind: 'line'; readonly line: string }
30
+ | { readonly kind: 'closed' }
31
+ | { readonly kind: 'failed'; readonly error: Error }
32
+ | { readonly kind: 'late' };
33
+
34
+ /** The disk a granted lease holds. */
35
+ interface Granted {
36
+ readonly device: string;
37
+ readonly registryEntry: string;
38
+ }
39
+
40
+ /** Ask the gateway at `socket` for a RAM disk of `sectors` 512-byte sectors; its lease, or why there is none. */
41
+ export async function attachRamDisk(
42
+ socket: string,
43
+ sectors: number,
44
+ deadlineMs: number,
45
+ ): Promise<Result<RamDiskLease, string | RamUnavailable>> {
46
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: a unix-socket connect completes or fails at once, and every answer on it is awaited by next(deadlineMs), whose timer ends the wait
47
+ const connection = connect(socket);
48
+ const next = answers(connection);
49
+ connection.on('connect', () => connection.write(`${JSON.stringify({ op: RAM_LEASE_OP, sectors })}\n`));
50
+ const granted = readGrant(await next(deadlineMs), socket, deadlineMs);
51
+ if (!granted.ok) {
52
+ connection.destroy();
53
+ return granted;
54
+ }
55
+ // The open connection is the lease; it never keeps this process alive on its own.
56
+ connection.unref();
57
+ return { ok: true, value: heldLease(connection, next, granted.value, deadlineMs) };
58
+ }
59
+
60
+ /** The connection's answer lines, one per call, each awaited for at most `deadlineMs`. */
61
+ function answers(connection: Socket): (deadlineMs: number) => Promise<Next> {
62
+ let received = '';
63
+ let gone: Next | null = null;
64
+ let waiting: ((next: Next) => void) | null = null;
65
+ const deliver = () => {
66
+ const wake = waiting;
67
+ if (wake === null) return;
68
+ const newline = received.indexOf('\n');
69
+ let next = gone;
70
+ if (newline >= 0) {
71
+ next = { kind: 'line', line: received.slice(0, newline) };
72
+ received = received.slice(newline + 1);
73
+ } else if (gone !== null && received !== '') {
74
+ next = { kind: 'line', line: received };
75
+ received = '';
76
+ }
77
+ if (next === null) return;
78
+ waiting = null;
79
+ wake(next);
80
+ };
81
+ connection.on('data', (chunk: Buffer) => {
82
+ received += chunk.toString('utf8');
83
+ if (received.length <= ANSWER_BYTES_MAX) return deliver();
84
+ received = '';
85
+ connection.destroy(new Error(`the gateway's answer exceeds ${ANSWER_BYTES_MAX} bytes`));
86
+ });
87
+ connection.on('error', (error) => {
88
+ gone ??= { kind: 'failed', error };
89
+ deliver();
90
+ });
91
+ connection.on('close', () => {
92
+ gone ??= { kind: 'closed' };
93
+ deliver();
94
+ });
95
+ return (deadlineMs) =>
96
+ new Promise((resolve) => {
97
+ const timer = setTimeout(() => {
98
+ waiting = null;
99
+ resolve({ kind: 'late' });
100
+ }, deadlineMs);
101
+ waiting = (next) => {
102
+ clearTimeout(timer);
103
+ resolve(next);
104
+ };
105
+ deliver();
106
+ });
107
+ }
108
+
109
+ /** The lease the attach answer grants, or why it grants none. */
110
+ function readGrant(next: Next, socket: string, deadlineMs: number): Result<Granted, string | RamUnavailable> {
111
+ switch (next.kind) {
112
+ case 'late':
113
+ return {
114
+ ok: false,
115
+ error: `the gateway answered no ram-lease within ${deadlineMs} ms; this client closed the lease, so the gateway detaches any disk its attach still makes`,
116
+ };
117
+ case 'failed':
118
+ return {
119
+ ok: false,
120
+ error:
121
+ 'code' in next.error && (next.error.code === 'ENOENT' || next.error.code === 'ECONNREFUSED')
122
+ ? {
123
+ kind: 'ram-unavailable',
124
+ reason: 'gateway-absent',
125
+ detail: `gateway ${socket} is unavailable: ${next.error.message}`,
126
+ }
127
+ : `gateway ram-lease I/O failed: ${next.error.message}`,
128
+ };
129
+ case 'closed':
130
+ return { ok: false, error: 'the gateway closed ram-lease without an answer' };
131
+ case 'line':
132
+ return readAnswer(next.line);
133
+ }
134
+ }
135
+
136
+ /** The fields of one JSON object answer line, or null for anything else. */
137
+ function fieldsOf(line: string): Readonly<Record<string, unknown>> | null {
138
+ let parsed: unknown;
139
+ try {
140
+ parsed = JSON.parse(line);
141
+ } catch {
142
+ return null;
143
+ }
144
+ return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)
145
+ ? Object.fromEntries(Object.entries(parsed))
146
+ : null;
147
+ }
148
+
149
+ /** The whole disk and registry entry a `ram-lease` answer names, or why the answer names none. */
150
+ function readAnswer(line: string): Result<Granted, string | RamUnavailable> {
151
+ const fields = fieldsOf(line);
152
+ if (fields === null) {
153
+ return { ok: false, error: `the gateway answered ram-lease with something that is not an answer: ${line}` };
154
+ }
155
+ if (fields.ok !== true) {
156
+ const why = `${String(fields.code ?? 'refused')}: ${String(fields.error ?? '')}`;
157
+ return {
158
+ ok: false,
159
+ error: String(fields.error ?? '').endsWith('unknown gateway control operation')
160
+ ? { kind: 'ram-unavailable', reason: 'gateway-unsupported', detail: `gateway predates ram-lease (${why})` }
161
+ : `the gateway refused ram-lease (${why})`,
162
+ };
163
+ }
164
+ const ramDisk = fields.ramDisk;
165
+ const device =
166
+ typeof ramDisk === 'object' && ramDisk !== null && 'device' in ramDisk && typeof ramDisk.device === 'string'
167
+ ? ramDisk.device
168
+ : null;
169
+ const registryEntry =
170
+ typeof ramDisk === 'object' &&
171
+ ramDisk !== null &&
172
+ 'registryEntry' in ramDisk &&
173
+ typeof ramDisk.registryEntry === 'string'
174
+ ? ramDisk.registryEntry
175
+ : null;
176
+ return device !== null && WHOLE_DISK.test(device) && registryEntry !== null && REGISTRY_ENTRY.test(registryEntry)
177
+ ? { ok: true, value: { device, registryEntry } }
178
+ : { ok: false, error: `the gateway's ram-lease answer names no whole disk and registry entry: ${line}` };
179
+ }
180
+
181
+ /** The lease `connection` holds on `disk`; each end is one line, half-closed, whose answer is awaited `deadlineMs`. */
182
+ function heldLease(
183
+ connection: Socket,
184
+ next: (deadlineMs: number) => Promise<Next>,
185
+ disk: Granted,
186
+ deadlineMs: number,
187
+ ): RamDiskLease {
188
+ let ended: 'keep' | 'release' | null = null;
189
+ const end = async (how: 'keep' | 'release'): Promise<Result<string, string>> => {
190
+ if (ended !== null) {
191
+ return {
192
+ ok: false,
193
+ error: `the ram-lease of ${disk.device} already ended at its ${ended}; nothing is known of a detach`,
194
+ };
195
+ }
196
+ ended = how;
197
+ connection.end(`${JSON.stringify({ end: how })}\n`);
198
+ const answer = await next(deadlineMs);
199
+ connection.destroy();
200
+ if (answer.kind === 'line') return { ok: true, value: answer.line };
201
+ const why =
202
+ answer.kind === 'late'
203
+ ? `none within ${deadlineMs} ms`
204
+ : answer.kind === 'failed'
205
+ ? answer.error.message
206
+ : 'it closed the connection';
207
+ return {
208
+ ok: false,
209
+ error: `the gateway answered no ${how} of the ram-lease of ${disk.device} (${why}): ${
210
+ how === 'keep'
211
+ ? 'nothing is known: the gateway may have handed the disk over or left it to its next startup scan; detach it by its entry'
212
+ : 'the lease is lost, so nothing is known of a detach'
213
+ }`,
214
+ };
215
+ };
216
+ return {
217
+ device: disk.device,
218
+ registryEntry: disk.registryEntry,
219
+ async keep() {
220
+ const answer = await end('keep');
221
+ if (!answer.ok) return answer;
222
+ return fieldsOf(answer.value)?.ok === true
223
+ ? { ok: true, value: undefined }
224
+ : { ok: false, error: `the gateway refused to keep the ram-lease of ${disk.device}: ${answer.value}` };
225
+ },
226
+ async release() {
227
+ const answer = await end('release');
228
+ if (!answer.ok) return answer;
229
+ const output = readDetachAnswer(answer.value);
230
+ return output === null
231
+ ? {
232
+ ok: false,
233
+ error: `the gateway's release of the ram-lease of ${disk.device} proves no detach outcome: ${answer.value}`,
234
+ }
235
+ : { ok: true, value: output };
236
+ },
237
+ };
238
+ }
@@ -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
+ }