@smoothbricks/nx-plugin 0.4.25 → 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 (348) hide show
  1. package/README.md +1078 -98
  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 +16 -85
  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 +16 -17
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +37 -44
  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 +50 -8
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +691 -71
  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 +108 -12
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +299 -18
  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 +213 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +624 -177
  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 +435 -230
  102. package/dist/managed-assets.d.ts +6 -0
  103. package/dist/managed-assets.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.d.ts +13 -0
  105. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  106. package/dist/managed-files/ci-workflow.js +44 -13
  107. package/dist/managed-files/files.d.ts +7 -1
  108. package/dist/managed-files/files.d.ts.map +1 -1
  109. package/dist/managed-files/files.js +62 -8
  110. package/dist/managed-files/json-edit.d.ts +21 -0
  111. package/dist/managed-files/json-edit.d.ts.map +1 -0
  112. package/dist/managed-files/json-edit.js +295 -0
  113. package/dist/managed-files/managed-format.d.ts +33 -1
  114. package/dist/managed-files/managed-format.d.ts.map +1 -1
  115. package/dist/managed-files/managed-format.js +82 -2
  116. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  117. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  119. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  120. package/dist/managed-files/publish-workflow.js +231 -48
  121. package/dist/managed-files/tree.d.ts +5 -0
  122. package/dist/managed-files/tree.d.ts.map +1 -1
  123. package/dist/managed-files/tree.js +5 -3
  124. package/dist/manifest-hash.js +3 -2
  125. package/dist/nextest-code-bound.d.ts +62 -0
  126. package/dist/nextest-code-bound.d.ts.map +1 -0
  127. package/dist/nextest-code-bound.js +154 -0
  128. package/dist/nextest-extraction.d.ts +24 -8
  129. package/dist/nextest-extraction.d.ts.map +1 -1
  130. package/dist/nextest-extraction.js +42 -7
  131. package/dist/package-target-policy.d.ts.map +1 -1
  132. package/dist/package-target-policy.js +3 -5
  133. package/dist/release-config-policy.d.ts.map +1 -1
  134. package/dist/release-config-policy.js +3 -5
  135. package/dist/runtime-input.d.ts +14 -0
  136. package/dist/runtime-input.d.ts.map +1 -0
  137. package/dist/runtime-input.js +15 -0
  138. package/dist/rust-tokens.d.ts +11 -0
  139. package/dist/rust-tokens.d.ts.map +1 -0
  140. package/dist/rust-tokens.js +81 -0
  141. package/dist/task-results.d.ts +6 -0
  142. package/dist/task-results.d.ts.map +1 -0
  143. package/dist/task-results.js +61 -0
  144. package/dist/test-program.d.ts +54 -0
  145. package/dist/test-program.d.ts.map +1 -0
  146. package/dist/test-program.js +292 -0
  147. package/dist/test-timings.d.ts +71 -0
  148. package/dist/test-timings.d.ts.map +1 -0
  149. package/dist/test-timings.js +393 -0
  150. package/dist/test-walk-policy.d.ts +103 -0
  151. package/dist/test-walk-policy.d.ts.map +1 -0
  152. package/dist/test-walk-policy.js +657 -0
  153. package/dist/testing.d.ts +177 -0
  154. package/dist/testing.d.ts.map +1 -0
  155. package/dist/testing.js +824 -0
  156. package/dist/type-guards.d.ts +3 -0
  157. package/dist/type-guards.d.ts.map +1 -0
  158. package/dist/type-guards.js +4 -0
  159. package/dist/typecheck-test-policy.d.ts +8 -5
  160. package/dist/typecheck-test-policy.d.ts.map +1 -1
  161. package/dist/typecheck-test-policy.js +113 -100
  162. package/dist/workspace-config-policy.d.ts +8 -0
  163. package/dist/workspace-config-policy.d.ts.map +1 -1
  164. package/dist/workspace-config-policy.js +175 -63
  165. package/dist/workspace-index.d.ts +12 -0
  166. package/dist/workspace-index.d.ts.map +1 -0
  167. package/dist/workspace-index.js +17 -0
  168. package/dist/workspace-manifest.d.ts +37 -1
  169. package/dist/workspace-manifest.d.ts.map +1 -1
  170. package/executors.json +5 -0
  171. package/loader.js +13 -11
  172. package/managed/raw/envrc +33 -62
  173. package/managed/raw/git-format-staged.yml +30 -35
  174. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  175. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  176. package/managed/raw/tooling/direnv/developer-links.ts +607 -17
  177. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -92
  178. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  179. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  180. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  181. package/managed/raw/tooling/direnv/repo-path +14 -2
  182. package/managed/raw/tooling/direnv/setup-environment.ts +1009 -118
  183. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  184. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  185. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  186. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  187. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  188. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  189. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  190. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  191. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  192. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  194. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  196. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  197. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  198. package/managed/templates/github/workflows/managed-files.yml +1 -2
  199. package/nextest.toml +8 -75
  200. package/package.json +75 -13
  201. package/runtime-input.sh +81 -0
  202. package/src/__tests__/counted-cargo-process.ts +286 -0
  203. package/src/__tests__/counted-cargo.ts +730 -0
  204. package/src/__tests__/fixture-cargo-home.ts +36 -0
  205. package/src/__tests__/fixture-nx-env.ts +157 -2
  206. package/src/__tests__/progress-clock.ts +43 -0
  207. package/src/__tests__/runtime-input.ts +23 -0
  208. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  209. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  210. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  211. package/src/bin/smoo-nx-exec.ts +17 -86
  212. package/src/bin/smoo-nx-failures.ts +4 -0
  213. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  214. package/src/bin/smoo-nx-test-walks.ts +42 -0
  215. package/src/bounded-test-policy.test.ts +268 -22
  216. package/src/bounded-test-policy.ts +114 -42
  217. package/src/build-state-output-policy.test.ts +115 -0
  218. package/src/build-state-output-policy.ts +90 -0
  219. package/src/bun-bootstrap.test.ts +57 -3
  220. package/src/bun-file-packages.test.ts +47 -0
  221. package/src/cargo-closure-input.test.ts +432 -62
  222. package/src/cargo-closure-input.ts +51 -57
  223. package/src/cargo-dev-profile.ts +137 -0
  224. package/src/cargo-resolve-cache.test.ts +1044 -0
  225. package/src/cargo-source-hash.test.ts +203 -93
  226. package/src/cargo-source-hash.ts +762 -75
  227. package/src/cargo-toolchain-policy.ts +6 -0
  228. package/src/cargo-workspace.test.ts +320 -0
  229. package/src/cargo-workspace.ts +344 -18
  230. package/src/cross-check-policy.test.ts +59 -1
  231. package/src/cross-check-policy.ts +25 -6
  232. package/src/disk-command-policy.test.ts +61 -0
  233. package/src/disk-command-policy.ts +107 -0
  234. package/src/ensure-built-receipt.test.ts +184 -0
  235. package/src/ensure-built-receipt.ts +263 -0
  236. package/src/ensure-built-witness.test.ts +344 -0
  237. package/src/ensure-built-witness.ts +252 -0
  238. package/src/ensure-built.test.ts +1043 -483
  239. package/src/ensure-built.ts +870 -197
  240. package/src/eslint-file-set.ts +9 -0
  241. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  242. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  243. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  244. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  245. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  246. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  247. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  248. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  249. package/src/executors/bounded-exec/executor.ts +565 -67
  250. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  251. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  252. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  253. package/src/executors/bounded-exec/progress.test.ts +79 -0
  254. package/src/executors/bounded-exec/progress.ts +118 -0
  255. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  256. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  257. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  258. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  259. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  260. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  261. package/src/executors/bounded-exec/schema.json +11 -5
  262. package/src/executors/bounded-exec/schema.ts +27 -11
  263. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  264. package/src/executors/bounded-exec/verdict.ts +433 -0
  265. package/src/executors/shard-timings/executor.ts +36 -0
  266. package/src/executors/shard-timings/schema.json +21 -0
  267. package/src/executors/shard-timings/schema.ts +4 -0
  268. package/src/failure-summary.ts +119 -0
  269. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  270. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  271. package/src/generators/create-package/generator.test.ts +6 -0
  272. package/src/generators/create-package/generator.ts +6 -2
  273. package/src/host-controller-wiring.test.ts +31 -0
  274. package/src/index.test.ts +1070 -360
  275. package/src/index.ts +524 -255
  276. package/src/linked-snapshots.nx.test.ts +172 -0
  277. package/src/managed-assets.ts +12 -0
  278. package/src/managed-files/ci-workflow.ts +54 -13
  279. package/src/managed-files/files.ts +65 -9
  280. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  281. package/src/managed-files/generator.test.ts +60 -1
  282. package/src/managed-files/json-edit.test.ts +216 -0
  283. package/src/managed-files/json-edit.ts +290 -0
  284. package/src/managed-files/managed-format-json.test.ts +308 -0
  285. package/src/managed-files/managed-format.ts +90 -2
  286. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  287. package/src/managed-files/publish-workflow.ts +285 -67
  288. package/src/managed-files/repo-path.test.ts +129 -0
  289. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  290. package/src/managed-files/tree.ts +11 -3
  291. package/src/manifest-hash.ts +3 -2
  292. package/src/nextest-code-bound.test.ts +155 -0
  293. package/src/nextest-code-bound.ts +195 -0
  294. package/src/nextest-extraction.test.ts +37 -5
  295. package/src/nextest-extraction.ts +51 -9
  296. package/src/nextest-partitions.test.ts +495 -0
  297. package/src/nx-cache-bound.test.ts +109 -0
  298. package/src/nx-cache-restore-mtime.test.ts +170 -0
  299. package/src/nx-daemon-claim.test.ts +277 -0
  300. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  301. package/src/nx-daemon-idle-policy.test.ts +51 -0
  302. package/src/nx-daemon-ignore-files.test.ts +210 -0
  303. package/src/nx-daemon-root-normalization.test.ts +105 -0
  304. package/src/nx-daemon-validity.test.ts +925 -0
  305. package/src/nx-dot-input-policy.test.ts +353 -0
  306. package/src/nx-failure-life-cycles.test.ts +207 -0
  307. package/src/nx-files-archive-racy.test.ts +97 -0
  308. package/src/nx-foreign-workspace-env.test.ts +329 -0
  309. package/src/nx-incomplete-run-summary.test.ts +70 -0
  310. package/src/nx-plugin-load-errors.test.ts +120 -0
  311. package/src/nx-project-resolution-cache.test.ts +176 -0
  312. package/src/nx-raw-inputs.test.ts +166 -0
  313. package/src/nx-resident-graph-workers.test.ts +112 -0
  314. package/src/nx-run-information.test.ts +118 -0
  315. package/src/nx-skipped-task-exit.test.ts +180 -0
  316. package/src/nx-state-location.test.ts +63 -0
  317. package/src/nx-store-resolution.test.ts +99 -0
  318. package/src/nx-task-graph-cycles.test.ts +148 -0
  319. package/src/nx-task-output-lease.test.ts +414 -0
  320. package/src/nx-use-local.test.ts +103 -0
  321. package/src/package-target-policy.ts +3 -6
  322. package/src/release-config-policy.ts +3 -6
  323. package/src/runtime-input.test.ts +215 -0
  324. package/src/runtime-input.ts +17 -0
  325. package/src/rust-tokens.ts +78 -0
  326. package/src/serial-group-wiring.test.ts +326 -0
  327. package/src/task-history-namespace.test.ts +181 -0
  328. package/src/task-results.test.ts +226 -0
  329. package/src/task-results.ts +75 -0
  330. package/src/test-program.test.ts +303 -0
  331. package/src/test-program.ts +341 -0
  332. package/src/test-timings.test.ts +240 -0
  333. package/src/test-timings.ts +311 -0
  334. package/src/test-walk-policy.test.ts +585 -0
  335. package/src/test-walk-policy.ts +731 -0
  336. package/src/testing.test.ts +509 -0
  337. package/src/testing.ts +922 -0
  338. package/src/type-guards.ts +4 -0
  339. package/src/typecheck-test-policy.test.ts +496 -11
  340. package/src/typecheck-test-policy.ts +137 -103
  341. package/src/workspace-config-policy.test.ts +212 -13
  342. package/src/workspace-config-policy.ts +101 -73
  343. package/src/workspace-index.ts +18 -0
  344. package/src/workspace-manifest.ts +41 -1
  345. package/test-timings.json +85 -28
  346. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -615
  347. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
  348. package/src/__tests__/in-process-nx-index.ts +0 -9
@@ -0,0 +1,143 @@
1
+ import { connect } from 'node:net';
2
+ /**
3
+ * The client half of a lease held on the cowshed gateway's control socket: the host
4
+ * disk-lifecycle lease (`disk-lease.ts`) and the host CPU budget (`cpu-tokens.ts`) speak the same
5
+ * protocol (specs/cowshed/05_gateway.md, "Disk-lifecycle lease" and "Host CPU budget").
6
+ *
7
+ * The client writes one request line and keeps the connection open without half-closing it. The
8
+ * gateway answers `queued` at once and `granted` when the lease is the client's, and the lease
9
+ * lasts until the client closes the connection, so a client that dies holding one releases it with
10
+ * its socket. A lease never decides whether a command runs: without a grant, it runs without one
11
+ * and the caller says why.
12
+ */
13
+ /** The cowshed gateway's control socket, at the store root every peer agrees on. */
14
+ export const GATEWAY_SOCKET = '/private/cowshed/store/gateway.sock';
15
+ /**
16
+ * Ask the gateway at `socket` for the lease `request` names, `what` in its messages ("disk
17
+ * leases", "the CPU budget"). A gateway from before one-line requests says nothing until it reads
18
+ * EOF, so a request not queued within `ackMs` is half-closed and that gateway's refusal read; a
19
+ * gateway that reads the line but does not know the operation refuses it at once. Both predate the
20
+ * lease.
21
+ */
22
+ export function holdLease(socket, request, what, bounds, onQueued) {
23
+ // `Promise.withResolvers` would read better but needs lib es2024; this package inherits lib
24
+ // es2022 from tsconfig.base.json.
25
+ let resolve;
26
+ const promise = new Promise((settled) => {
27
+ resolve = settled;
28
+ });
29
+ const connection = connect(socket);
30
+ // `closed` is made when a consumer reads it, so a lease nobody watches allocates no promise. The
31
+ // flag, not `connection.destroyed`, says the socket really closed: `destroy()` sets that flag before
32
+ // the `close` event fires.
33
+ let socketClosed = false;
34
+ let closed;
35
+ let state = 'connecting';
36
+ let buffered = '';
37
+ let timer;
38
+ const settle = (outcome) => {
39
+ if (state === 'settled') {
40
+ return;
41
+ }
42
+ state = 'settled';
43
+ clearTimeout(timer);
44
+ if (!outcome.granted) {
45
+ connection.destroy();
46
+ }
47
+ resolve(outcome);
48
+ };
49
+ const unleased = (reason, cause = 'other', code) => settle({ granted: false, cause, reason, ...(code === undefined ? {} : { code }) });
50
+ const wait = (ms, onExpiry) => {
51
+ clearTimeout(timer);
52
+ timer = setTimeout(onExpiry, ms);
53
+ };
54
+ const answer = (line) => {
55
+ let parsed;
56
+ try {
57
+ parsed = JSON.parse(line);
58
+ }
59
+ catch {
60
+ unleased(`the gateway answered something that is not an answer: ${line}`);
61
+ return;
62
+ }
63
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
64
+ unleased(`the gateway answered something that is not an answer: ${line}`);
65
+ return;
66
+ }
67
+ const fields = Object.fromEntries(Object.entries(parsed));
68
+ const lease = fields.lease;
69
+ if (fields.ok !== true) {
70
+ const error = String(fields.error ?? '');
71
+ const why = `${String(fields.code ?? 'refused')}: ${error}`;
72
+ if (state === 'half-closed' || error.endsWith('unknown gateway control operation')) {
73
+ unleased(`the gateway predates ${what} (${why}); restart it with \`cowshed setup\``, 'predates');
74
+ }
75
+ else if (error.endsWith('contains an unknown field')) {
76
+ unleased(`the gateway predates a field of ${what} (${why}); restart it with \`cowshed setup\``, 'predates-field');
77
+ }
78
+ else {
79
+ unleased(`the gateway refused the lease (${why})`, 'other', typeof fields.code === 'string' ? fields.code : undefined);
80
+ }
81
+ }
82
+ else if (state === 'half-closed') {
83
+ unleased('the gateway did not queue the request in time; it is alive but overloaded');
84
+ }
85
+ else if (state === 'asked' && lease === 'queued') {
86
+ state = 'queued';
87
+ onQueued?.();
88
+ const grantMs = bounds.grantMs;
89
+ if (grantMs === null) {
90
+ clearTimeout(timer);
91
+ }
92
+ else {
93
+ wait(grantMs, () => unleased(`the gateway granted nothing within ${grantMs} ms`));
94
+ }
95
+ }
96
+ else if (state === 'queued' && lease === 'granted') {
97
+ settle({
98
+ granted: true,
99
+ answer: fields,
100
+ release: () => connection.destroy(),
101
+ get closed() {
102
+ closed ??= socketClosed
103
+ ? Promise.resolve()
104
+ : new Promise((done) => connection.once('close', () => done()));
105
+ return closed;
106
+ },
107
+ });
108
+ }
109
+ else {
110
+ unleased(`the gateway answered out of turn: ${line}`);
111
+ }
112
+ };
113
+ connection.on('connect', () => {
114
+ state = 'asked';
115
+ connection.write(`${JSON.stringify(request)}\n`);
116
+ wait(bounds.ackMs, () => {
117
+ state = 'half-closed';
118
+ connection.end();
119
+ wait(bounds.afterCloseMs, () => unleased('the gateway answered nothing'));
120
+ });
121
+ });
122
+ connection.on('data', (chunk) => {
123
+ buffered += chunk.toString('utf8');
124
+ for (let newline = buffered.indexOf('\n'); newline !== -1; newline = buffered.indexOf('\n')) {
125
+ const line = buffered.slice(0, newline);
126
+ buffered = buffered.slice(newline + 1);
127
+ answer(line);
128
+ }
129
+ });
130
+ connection.on('error', (error) => {
131
+ if (state === 'connecting') {
132
+ unleased(`the gateway's control socket ${socket} does not answer (${error.message})`, 'absent');
133
+ }
134
+ else {
135
+ unleased(error.message);
136
+ }
137
+ });
138
+ connection.on('close', () => {
139
+ socketClosed = true;
140
+ unleased('the gateway closed the lease connection');
141
+ });
142
+ return promise;
143
+ }
@@ -0,0 +1,35 @@
1
+ export declare const HANG_CAPTURE_MS = 5000;
2
+ export interface HangDiagnostics {
3
+ startedAtMs: number;
4
+ capturedAtMs: number;
5
+ /** Positive when the observation completed before the idle expiry. */
6
+ offsetFromExpiryMs: number;
7
+ outcome: 'holders' | 'none' | 'incomplete';
8
+ text: string;
9
+ }
10
+ export interface HangCaptureRequest {
11
+ pid: number;
12
+ pgid: number | null;
13
+ expiresAtMs: number;
14
+ deadlineMs: number;
15
+ signal?: AbortSignal;
16
+ }
17
+ export type HangProbeResult = {
18
+ status: 'exited';
19
+ code: number;
20
+ stdout: string;
21
+ stderr: string;
22
+ } | {
23
+ status: 'unavailable' | 'timed-out' | 'failed';
24
+ detail: string;
25
+ stdout: string;
26
+ stderr: string;
27
+ };
28
+ /** The process boundary, injectable so unavailable and non-answering probes have exact witnesses. */
29
+ export interface HangDiagnosticHost {
30
+ platform: NodeJS.Platform;
31
+ probe(file: string, args: readonly string[], timeoutMs: number, signal: AbortSignal): Promise<HangProbeResult>;
32
+ }
33
+ /** A pre-expiry observation, never an assertion that an open file is a contested lock. */
34
+ export declare function captureHangDiagnostics(request: HangCaptureRequest, source?: HangDiagnosticHost): Promise<HangDiagnostics>;
35
+ //# sourceMappingURL=hang-diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hang-diagnostics.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/hang-diagnostics.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,OAAQ,CAAC;AAIrC,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,SAAS,GAAG,MAAM,GAAG,YAAY,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClE;IAAE,MAAM,EAAE,aAAa,GAAG,WAAW,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvG,qGAAqG;AACrG,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAChH;AAUD,0FAA0F;AAC1F,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,kBAAkB,EAC3B,MAAM,GAAE,kBAAyB,GAChC,OAAO,CAAC,eAAe,CAAC,CAyK1B"}
@@ -0,0 +1,231 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { withDescendants } from '../../testing.js';
3
+ export const HANG_CAPTURE_MS = 5_000;
4
+ const MAX_PROBE_BYTES = 4 * 1024 * 1024;
5
+ const PS_FIELDS = 'pid=,ppid=,pgid=,stat=,%cpu=,etime=,lstart=,command=';
6
+ const host = { platform: process.platform, probe: runProbe };
7
+ /** A pre-expiry observation, never an assertion that an open file is a contested lock. */
8
+ export function captureHangDiagnostics(request, source = host) {
9
+ const startedAtMs = Date.now();
10
+ const budgetMs = Math.max(0, Math.min(HANG_CAPTURE_MS, request.deadlineMs, request.expiresAtMs - startedAtMs));
11
+ const endsAtMs = startedAtMs + budgetMs;
12
+ const controller = new AbortController();
13
+ const lines = [
14
+ `Hang snapshot: pid=${request.pid} pgid=${request.pgid ?? 'unknown'} startedAtMs=${startedAtMs}`,
15
+ 'Open files and process observations are evidence, not proof of a contested lock or its owner.',
16
+ ];
17
+ let active = 'process census';
18
+ let finished = false;
19
+ // This package targets lib es2022, which does not declare Promise.withResolvers.
20
+ return new Promise((resolve) => {
21
+ const finish = (outcome) => {
22
+ if (finished)
23
+ return;
24
+ finished = true;
25
+ clearTimeout(timer);
26
+ request.signal?.removeEventListener('abort', cancelled);
27
+ controller.abort();
28
+ const capturedAtMs = Date.now();
29
+ const offsetFromExpiryMs = request.expiresAtMs - capturedAtMs;
30
+ resolve({
31
+ startedAtMs,
32
+ capturedAtMs,
33
+ offsetFromExpiryMs,
34
+ outcome,
35
+ text: `${lines.join('\n')}\nHang snapshot outcome=${outcome} capturedAtMs=${capturedAtMs} offsetFromExpiryMs=${offsetFromExpiryMs}\n`,
36
+ });
37
+ };
38
+ const timer = setTimeout(() => {
39
+ lines.push(`Capture incomplete: ${budgetMs}ms deadline reached during ${active}; no empty-holder conclusion.`);
40
+ finish('incomplete');
41
+ }, budgetMs);
42
+ const cancelled = () => {
43
+ if (finished)
44
+ return;
45
+ lines.push(`Capture cancelled during ${active}; its progress generation is no longer current.`);
46
+ finish('incomplete');
47
+ };
48
+ request.signal?.addEventListener('abort', cancelled, { once: true });
49
+ if (request.signal?.aborted) {
50
+ cancelled();
51
+ return;
52
+ }
53
+ if (budgetMs === 0) {
54
+ lines.push('Capture incomplete: the pre-expiry window already ended or has no budget; no probe started.');
55
+ finish('incomplete');
56
+ return;
57
+ }
58
+ const probe = async (name, file, args, limitMs) => {
59
+ active = name;
60
+ lines.push(`${name}: ${file} ${args.join(' ')}`);
61
+ const result = await source.probe(file, args, Math.max(0, Math.min(limitMs, endsAtMs - Date.now())), controller.signal);
62
+ if (!finished) {
63
+ lines.push(`${name}: ${result.status}${result.status === 'exited' ? ` code=${result.code}` : ` ${result.detail}`}`);
64
+ if (result.stderr.trim() !== '')
65
+ lines.push(`${name} stderr:\n${result.stderr.trimEnd()}`);
66
+ }
67
+ return result;
68
+ };
69
+ const census = async (name) => {
70
+ // Bare `ps`, resolved through PATH like testing.ts's processTable: NixOS has no /bin/ps.
71
+ const result = await probe(name, 'ps', ['-A', '-o', PS_FIELDS], 1_000);
72
+ if (finished)
73
+ return null;
74
+ if (result.status !== 'exited' || result.code !== 0) {
75
+ lines.push(`${name}: could not inspect the process table; not an empty process tree.`);
76
+ return null;
77
+ }
78
+ const parsed = [];
79
+ for (const row of result.stdout.split('\n').filter((line) => line.trim() !== '')) {
80
+ const match = /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+\s+\S+\s+\d+\s+\d\d:\d\d:\d\d\s+\d{4})\s+(.*)$/.exec(row);
81
+ if (match === null) {
82
+ lines.push(`${name}: could not decode ps row: ${row}`);
83
+ return null;
84
+ }
85
+ const [, pid, ppid, pgid, stat, , , started, command] = match;
86
+ if (pid === undefined ||
87
+ ppid === undefined ||
88
+ pgid === undefined ||
89
+ stat === undefined ||
90
+ started === undefined ||
91
+ command === undefined) {
92
+ lines.push(`${name}: incomplete ps row: ${row}`);
93
+ return null;
94
+ }
95
+ parsed.push({ pid: Number(pid), ppid: Number(ppid), pgid: Number(pgid), stat, started, command, raw: row });
96
+ }
97
+ const roots = [request.pid, ...parsed.filter((entry) => entry.pgid === request.pgid).map((entry) => entry.pid)];
98
+ const selected = new Set(withDescendants(parsed, roots).map((entry) => entry.pid));
99
+ const tree = parsed.filter((entry) => selected.has(entry.pid));
100
+ lines.push(`${name}: PID PPID PGID STAT %CPU ELAPSED STARTED COMMAND`);
101
+ lines.push(...tree.map((entry) => entry.raw));
102
+ if (!tree.some((entry) => entry.pid === request.pid)) {
103
+ lines.push(`${name}: root pid ${request.pid} exited or is not visible; capture raced or is incomplete.`);
104
+ return null;
105
+ }
106
+ return tree;
107
+ };
108
+ const collect = async () => {
109
+ const before = await census('ps before');
110
+ if (finished)
111
+ return;
112
+ if (before === null)
113
+ return finish('incomplete');
114
+ let incomplete = false;
115
+ let observed = before.length > 0;
116
+ if (source.platform === 'darwin') {
117
+ const args = ['-nP', '-p', before.map((entry) => entry.pid).join(',')];
118
+ // Bare `sudo`/`lsof` through PATH, like `ps` above: NixOS provides neither /usr/bin/sudo nor /usr/sbin/lsof.
119
+ let resources = await probe('lsof privileged', 'sudo', ['-n', 'lsof', ...args], 1_500);
120
+ if (finished)
121
+ return;
122
+ const answered = (result) => result.status === 'exited' && (result.code === 0 || (result.code === 1 && result.stderr.trim() === ''));
123
+ if (!answered(resources)) {
124
+ incomplete = true;
125
+ if (resources.stdout.trim() !== '')
126
+ lines.push(`Partial privileged lsof output:\n${resources.stdout.trimEnd()}`);
127
+ lines.push('Privileged resource census unavailable; fallback is ordinary-user visibility only, not proof of no holders.');
128
+ resources = await probe('lsof user-scoped fallback', 'lsof', args, 1_000);
129
+ if (finished)
130
+ return;
131
+ }
132
+ if (resources.stdout.trim() !== '')
133
+ lines.push(`lsof open files/sockets (not contested-lock proof):\n${resources.stdout.trimEnd()}`);
134
+ if (!answered(resources) || resources.stderr.trim() !== '')
135
+ incomplete = true;
136
+ observed = resources.stdout.trim() !== '';
137
+ if (!observed && answered(resources))
138
+ lines.push('lsof reported no open-file matches within its stated visibility.');
139
+ }
140
+ else {
141
+ lines.push(`Open-file census not provided on ${source.platform}; observations below name processes only.`);
142
+ }
143
+ const after = await census('ps after');
144
+ if (finished)
145
+ return;
146
+ if (after === null)
147
+ return finish('incomplete');
148
+ if (before.length !== after.length ||
149
+ before.some((entry) => !after.some((other) => other.pid === entry.pid &&
150
+ other.ppid === entry.ppid &&
151
+ other.pgid === entry.pgid &&
152
+ other.started === entry.started &&
153
+ other.command === entry.command &&
154
+ other.stat.startsWith('Z') === entry.stat.startsWith('Z')))) {
155
+ incomplete = true;
156
+ lines.push('Process identities or membership changed during capture; open-file census raced.');
157
+ }
158
+ finish(incomplete ? 'incomplete' : observed ? 'holders' : 'none');
159
+ };
160
+ void collect().catch((error) => {
161
+ if (finished)
162
+ return;
163
+ lines.push(`Capture incomplete during ${active}: ${error instanceof Error ? error.message : String(error)}`);
164
+ finish('incomplete');
165
+ });
166
+ });
167
+ }
168
+ /** A probe owns its group and output pipes; its deadline never waits for an unresponsive child to reap. */
169
+ function runProbe(file, args, timeoutMs, signal) {
170
+ // Keep the package's es2022-compatible event-completion convention.
171
+ return new Promise((resolve) => {
172
+ if (signal.aborted) {
173
+ resolve({ status: 'timed-out', detail: 'capture deadline already reached', stdout: '', stderr: '' });
174
+ return;
175
+ }
176
+ const child = spawn(file, [...args], { detached: true, stdio: ['ignore', 'pipe', 'pipe'] });
177
+ let stdout = '';
178
+ let stderr = '';
179
+ let bytes = 0;
180
+ let settled = false;
181
+ const finish = (result) => {
182
+ if (settled)
183
+ return;
184
+ settled = true;
185
+ clearTimeout(timer);
186
+ signal.removeEventListener('abort', aborted);
187
+ child.stdout.destroy();
188
+ child.stderr.destroy();
189
+ child.unref();
190
+ resolve(result);
191
+ };
192
+ const stop = (detail, status = 'timed-out') => {
193
+ if (settled)
194
+ return;
195
+ let killFailure = '';
196
+ if (child.pid !== undefined) {
197
+ try {
198
+ process.kill(-child.pid, 'SIGKILL');
199
+ }
200
+ catch (error) {
201
+ killFailure = `; probe group cleanup: ${error instanceof Error ? error.message : String(error)}`;
202
+ }
203
+ }
204
+ finish({ status, detail: detail + killFailure, stdout, stderr });
205
+ };
206
+ const aborted = () => stop('capture deadline reached');
207
+ const timer = setTimeout(() => stop(`probe exceeded ${timeoutMs}ms`), timeoutMs);
208
+ signal.addEventListener('abort', aborted, { once: true });
209
+ const append = (stream, chunk) => {
210
+ bytes += Buffer.byteLength(chunk);
211
+ if (bytes > MAX_PROBE_BYTES) {
212
+ stop(`probe output exceeded ${MAX_PROBE_BYTES} bytes; output is incomplete`, 'failed');
213
+ return;
214
+ }
215
+ if (stream === 'stdout')
216
+ stdout += chunk;
217
+ else
218
+ stderr += chunk;
219
+ };
220
+ child.stdout.setEncoding('utf8').on('data', (chunk) => append('stdout', chunk));
221
+ child.stderr.setEncoding('utf8').on('data', (chunk) => append('stderr', chunk));
222
+ child.once('error', (error) => {
223
+ finish({ status: 'unavailable', detail: error.message, stdout, stderr });
224
+ });
225
+ child.once('close', (code, killedBy) => {
226
+ finish(code === null
227
+ ? { status: 'failed', detail: `probe ended by ${killedBy ?? 'unknown signal'}`, stdout, stderr }
228
+ : { status: 'exited', code, stdout, stderr });
229
+ });
230
+ });
231
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * What a run's output says about its forward motion: whether a test finished, and which tests the runner said
3
+ * are running and has not said finished. `idleTimeoutMs` re-arms only on a finished test.
4
+ *
5
+ * Output alone is not progress. nextest repeats a `SLOW` line for every test still running at each slow-timeout
6
+ * period, and a hung test may print a heartbeat, so a bound on silence never fires on either. A finished test is
7
+ * what each runner reports once per test:
8
+ *
9
+ * - nextest: a status line carrying the run's counter, `PASS [ 0.438s] (1/4) nt tests::quick` (also `FAIL`,
10
+ * `LEAK`, a signal name, `TRY 2 FAIL`, ...). A test still running is named by a `SLOW [> 30.000s] (───) …` or
11
+ * `START` line, which carries no counter; the name is nextest's `<binary-id> <test>`, as its JUnit report
12
+ * spells `classname name`.
13
+ * - libtest (`cargo test`): `test tests::quick ... ok` (or `FAILED`, `ignored`); a test still running is named by
14
+ * `test tests::slow has been running for over 60 seconds`.
15
+ * - bun: a line of dots, one per test finished (`--dots`, which `withProgressReport` asks for: bun prints nothing
16
+ * per passing test when it believes an agent runs it), or a `(pass)`/`(fail)`/`(skip)`/`(todo)` line. bun names
17
+ * no test before it finishes, so a bun run names nothing in flight.
18
+ *
19
+ * A command that reports no tests makes progress only by exiting.
20
+ */
21
+ export interface RunProgress {
22
+ /** One chunk of one of the command's output streams; true when it reports at least one finished test. */
23
+ scan(stream: OutputStream, chunk: string): boolean;
24
+ /** The tests the runner reported running and has not reported finished, in the order it first named them. */
25
+ inFlight(): string[];
26
+ }
27
+ export type OutputStream = 'stdout' | 'stderr';
28
+ export declare function createRunProgress(): RunProgress;
29
+ /**
30
+ * `command` with its one `bun test` asked for a line of dots, one per finished test: the only per-test report bun
31
+ * prints whoever runs it. A command that runs no bun, more than one runner, or already chose bun's dots is returned
32
+ * unchanged.
33
+ */
34
+ export declare function withProgressReport(command: string): string;
35
+ //# sourceMappingURL=progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/progress.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,WAAW;IAC1B,yGAAyG;IACzG,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACnD,6GAA6G;IAC7G,QAAQ,IAAI,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAsB/C,wBAAgB,iBAAiB,IAAI,WAAW,CAoD/C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAO1D"}
@@ -0,0 +1,79 @@
1
+ import { BUN_TEST, NEXTEST_RUN } from './verdict.js';
2
+ const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*[A-Za-z]`, 'g');
3
+ /** Lines naming a test that finished; group 1 is its name. */
4
+ const FINISHED = [
5
+ /^\s*(?:[A-Z0-9][A-Z0-9-]*\s+)+\[\s*[0-9.]+s\]\s+\(\s*\d+\/\d+\)\s+(\S.*)$/,
6
+ /^test (\S+) \.\.\. (?:ok|FAILED|ignored)\b/,
7
+ /^\((?:pass|fail|skip|todo)\) (.+)$/,
8
+ ];
9
+ /** Lines naming a test still running; group 1 is its name. */
10
+ const RUNNING = [
11
+ /^\s*(?:SLOW|START)\s+\[[^\]]*\]\s+(?:\([^)]*\)\s+)?(\S.*)$/,
12
+ /^test (\S+) has been running for over \d+ seconds$/,
13
+ ];
14
+ const DOTS = /^\.+$/;
15
+ export function createRunProgress() {
16
+ const streams = {
17
+ stdout: { partial: '', countedDots: 0 },
18
+ stderr: { partial: '', countedDots: 0 },
19
+ };
20
+ const running = new Set();
21
+ // One complete line, ANSI stripped, that is not a line of dots: true when it names a finished test.
22
+ const finishedLine = (text) => {
23
+ for (const pattern of FINISHED) {
24
+ const name = pattern.exec(text)?.[1];
25
+ if (name !== undefined) {
26
+ running.delete(name);
27
+ return true;
28
+ }
29
+ }
30
+ for (const pattern of RUNNING) {
31
+ const name = pattern.exec(text)?.[1];
32
+ if (name !== undefined) {
33
+ running.add(name);
34
+ return false;
35
+ }
36
+ }
37
+ return false;
38
+ };
39
+ return {
40
+ scan(stream, chunk) {
41
+ const state = streams[stream];
42
+ const lines = (state.partial + chunk).split('\n');
43
+ const rest = lines.pop() ?? '';
44
+ let progressed = false;
45
+ // The first complete line continues the partial one, whose dots were counted as they came.
46
+ let counted = state.countedDots;
47
+ for (const raw of lines) {
48
+ const text = raw.replace(ANSI, '').trimEnd();
49
+ if (DOTS.test(text)) {
50
+ progressed ||= text.length > counted;
51
+ }
52
+ else if (finishedLine(text)) {
53
+ progressed = true;
54
+ }
55
+ counted = 0;
56
+ }
57
+ const tail = rest.replace(ANSI, '');
58
+ const dots = DOTS.test(tail) ? tail.length : 0;
59
+ progressed ||= dots > counted;
60
+ state.partial = rest;
61
+ state.countedDots = dots;
62
+ return progressed;
63
+ },
64
+ inFlight: () => [...running],
65
+ };
66
+ }
67
+ /**
68
+ * `command` with its one `bun test` asked for a line of dots, one per finished test: the only per-test report bun
69
+ * prints whoever runs it. A command that runs no bun, more than one runner, or already chose bun's dots is returned
70
+ * unchanged.
71
+ */
72
+ export function withProgressReport(command) {
73
+ const bun = command.match(BUN_TEST)?.length ?? 0;
74
+ const nextest = command.match(NEXTEST_RUN)?.length ?? 0;
75
+ if (bun !== 1 || nextest !== 0 || /(?:^|\s)(?:--dots|--reporter[=\s]dots)(?=\s|$)/.test(command)) {
76
+ return command;
77
+ }
78
+ return command.replace(BUN_TEST, (_match, runtime) => `${runtime} test --dots`);
79
+ }
@@ -0,0 +1,3 @@
1
+ /** One attached image as `ioreg -r -c AppleDiskImageDevice -l -w0` lists it. */
2
+ export declare function registryDevice(url: string, disk: string): string[];
3
+ //# sourceMappingURL=ram-temp-fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ram-temp-fixtures.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/ram-temp-fixtures.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAUlE"}
@@ -0,0 +1,12 @@
1
+ /** One attached image as `ioreg -r -c AppleDiskImageDevice -l -w0` lists it. */
2
+ export function registryDevice(url, disk) {
3
+ return [
4
+ '+-o AppleDiskImageDevice@5d6 <class AppleDiskImageDevice, id 0x100659c38, registered, matched, active>',
5
+ ` | "DiskImageURL" = "${url}"`,
6
+ ' +-o IOBlockStorageDriver <class IOBlockStorageDriver, id 0x100659c3a, registered>',
7
+ ' +-o Apple Disk Image Media <class IOMedia, id 0x100659c3b, registered>',
8
+ ` | "BSD Name" = "${disk}"`,
9
+ ' +-o Untitled 1@1 <class IOMedia, id 0x10037ce47, registered>',
10
+ ` | "BSD Name" = "${disk}s1"`,
11
+ ];
12
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * A dead RAM lease kept because something is attached from below it stays kept until its owner
3
+ * detaches it, and every acquisition visits it. Proving it is still held from the host's full
4
+ * attachment inventory (`ioreg` and `mount`) costs seconds a pass; this module proves it again
5
+ * from a no-follow `lstat` of each mount the last inventory named.
6
+ *
7
+ * A verdict is only ever positive: it records holders that were there, never their absence, so
8
+ * nothing read from it can remove a lease. A mount is keyed by its root's dev, inode and birth,
9
+ * on a device other than the RAM volume's: files coming and going in it move only its ctime, and
10
+ * an unmount exposes the RAM directory beneath. An attached image has no such key: a whole-disk
11
+ * node's identity is not measured to change when DiskImages reuses its number for another image,
12
+ * so an image holder leaves nothing to cache and its lease keeps the fresh inventory's result.
13
+ * Any absence or change sends the caller back to a fresh inventory. This module reads only; the
14
+ * volume's owner stores verdicts.
15
+ */
16
+ /** Which volume incarnation and lease a verdict is about; keyed by the volume's owner. */
17
+ export interface HeldContext {
18
+ /** The mounted RAM root's and marker's stable identity: no root ctime or mtime. */
19
+ readonly volumeKey: string;
20
+ /** The lease directory's identity. */
21
+ readonly leaseKey: string;
22
+ /** The mounted RAM root's `st_dev`, in decimal. */
23
+ readonly ramDevice: string;
24
+ }
25
+ /** A holder the inventory named below a lease, with the text that names it to the task. */
26
+ export type HeldCandidate = {
27
+ readonly kind: 'image';
28
+ readonly imagePath: string;
29
+ readonly diskPath: string;
30
+ readonly description: string;
31
+ } | {
32
+ readonly kind: 'mount';
33
+ readonly mountpoint: string;
34
+ readonly description: string;
35
+ };
36
+ /**
37
+ * A mount as it was keyed: the identity of the mounted root, which stays the same for as long as
38
+ * the same volume is mounted there. Decimal strings: exact on the wire.
39
+ */
40
+ export interface HeldProof {
41
+ readonly kind: 'mount';
42
+ readonly mountpoint: string;
43
+ readonly description: string;
44
+ readonly root: {
45
+ readonly dev: string;
46
+ readonly ino: string;
47
+ readonly birthtimeNs: string;
48
+ };
49
+ }
50
+ /** A lease proven held by every one of its holders, as JSON carries it. */
51
+ export interface HeldVerdict {
52
+ readonly version: 1;
53
+ readonly context: HeldContext;
54
+ readonly holders: readonly [HeldProof, ...HeldProof[]];
55
+ }
56
+ export type CacheResult<T> = {
57
+ ok: true;
58
+ value: T;
59
+ } | {
60
+ ok: false;
61
+ error: string;
62
+ };
63
+ /** The no-follow metadata a proof reads: `lstat(path, { bigint: true })` on the host. */
64
+ export interface HolderStats {
65
+ readonly dev: bigint;
66
+ readonly ino: bigint;
67
+ readonly birthtimeNs: bigint;
68
+ isDirectory(): boolean;
69
+ }
70
+ /** Proving held leases over `read`; a seam so mounts are testable on any host. */
71
+ export interface HeldProver {
72
+ capture(context: HeldContext, candidates: readonly HeldCandidate[]): Promise<CacheResult<HeldVerdict | undefined>>;
73
+ validate(verdict: HeldVerdict, context: HeldContext): Promise<CacheResult<boolean>>;
74
+ }
75
+ export declare function heldProverOn(read: (path: string) => Promise<HolderStats>): HeldProver;
76
+ /**
77
+ * The verdict that `candidates`, the holders a fresh inventory found below the lease, still hold
78
+ * it; `undefined` when there are none or one cannot be keyed, an image always among them, which
79
+ * leaves the inventory's held result standing uncached. An unreadable holder is an error, not a
80
+ * verdict.
81
+ */
82
+ export declare function captureHeldVerdict(context: HeldContext, candidates: readonly HeldCandidate[]): Promise<CacheResult<HeldVerdict | undefined>>;
83
+ /**
84
+ * Whether `verdict` still proves its lease held in `context`: the same volume incarnation and
85
+ * lease, and every holder still mounted with the identity it was keyed by. `false` asks for a
86
+ * fresh inventory; it never says the lease is free.
87
+ */
88
+ export declare function validateHeldVerdict(verdict: HeldVerdict, context: HeldContext): Promise<CacheResult<boolean>>;
89
+ /** A verdict from its JSON value; `undefined` for anything malformed, which asks for a fresh inventory. */
90
+ export declare function parseHeldVerdict(value: unknown): HeldVerdict | undefined;
91
+ //# sourceMappingURL=ram-temp-held.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ram-temp-held.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/ram-temp-held.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AAEH,0FAA0F;AAC1F,MAAM,WAAW,WAAW;IAC1B,mFAAmF;IACnF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sCAAsC;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,2FAA2F;AAC3F,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC/G;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1F;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7F;AAED,2EAA2E;AAC3E,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;CACxD;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnF,yFAAyF;AACzF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,WAAW,IAAI,OAAO,CAAC;CACxB;AAED,kFAAkF;AAClF,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC;IACnH,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;CACrF;AAKD,wBAAgB,YAAY,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,UAAU,CAyFrF;AAID;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,SAAS,aAAa,EAAE,GACnC,OAAO,CAAC,WAAW,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAE7G;AAED,2GAA2G;AAC3G,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,SAAS,CAexE"}