@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
package/nextest.toml CHANGED
@@ -1,85 +1,18 @@
1
1
  # Injected by @smoothbricks/nx-plugin as `--config-file` on inferred cargo-test
2
- # package targets. `period` matches bun's `--timeout=30000`; `terminate-after = 1`
3
- # kills at that bound instead of warning then waiting another period.
2
+ # package targets. `period` matches bun's `--timeout=30000`. A slow-timeout here
3
+ # only warns: nextest prints a `SLOW` line naming the test every period, and
4
+ # never kills it. The run's no-progress bound (`idleTimeoutMs`, README "Bounded
5
+ # Test Targets") ends a test that never returns, and names it from those lines.
4
6
  [profile.default]
5
- slow-timeout = { period = "30s", terminate-after = 1 }
7
+ slow-timeout = { period = "30s" }
6
8
 
7
9
  # Compile-fail tests compile fixture crates (or rustc a negative contract) as
8
10
  # their body. `cargo test --no-run` cannot pre-build those; they are generated
9
11
  # at test time. Filterset matches the class by test name rather than listing
10
12
  # today's two tests (`compile_fail_cases`, `lesser_capabilities_fail_to_compile_*`).
11
13
  #
12
- # 180s is provisional: measure on an idle machine with `--test-threads=1`.
13
- # An unbounded run phase is how a hung test becomes a hung lane.
14
+ # Their raised period is what marks them exceptional: the plugin lifts them out
15
+ # of the ordinary hash into partitions of their own.
14
16
  [[profile.default.overrides]]
15
17
  filter = 'test(/compile_fail|fail_to_compile/)'
16
- slow-timeout = { period = "180s", terminate-after = 1 }
17
-
18
- # Tests that drive the host's REAL APFS stack — creating, attaching, mounting and
19
- # detaching actual disk images — contend on a single machine-wide serialization
20
- # point: Disk Arbitration and the APFS driver. Measured on this host, a read-only
21
- # `diskutil apfs list -plist` costs 0.7s idle at 33 attached images but up to
22
- # 14.4s while another process is attaching/detaching. Run in parallel these tests
23
- # manufacture exactly that contention for each other, so each one's wall time
24
- # becomes a function of how many siblings happen to be mid-attach — a test whose
25
- # verdict depends on that is measuring the scheduler, not the code.
26
- #
27
- # `max-threads = 1` makes the group a mutex across the WHOLE run (groups are
28
- # run-wide, not per-binary, so the lib unit tests and the apfs_integration binary
29
- # serialize against each other as intended). The other ~830 tests stay parallel.
30
- #
31
- # This bounds contention; it does NOT grant more time. The per-test deadline above
32
- # is unchanged and each of these tests is expected to fit it on its own merits.
33
- # Membership is by name: `real_apfs_*` is the class marker, so a new real-APFS
34
- # test joins the group by being named for what it touches. A bare `real_*` filter
35
- # would be wrong here — unrelated `real_*` tests exist in columine-arrow,
36
- # cowshed-cli and cowshed-gateway that touch no disk image at all.
37
- #
38
- # The `@tool:smoo:` prefix is not decoration: this file is passed as
39
- # `--tool-config-file smoo:...` so a repository's own `.config/nextest.toml`
40
- # can override it, and nextest REFUSES a tool config whose groups are not
41
- # namespaced ("test groups must start with '@tool:<tool-name>:'") precisely so
42
- # a tool cannot collide with a repository's group of the same name.
43
- [test-groups]
44
- "@tool:smoo:real-apfs" = { max-threads = 1 }
45
-
46
- # The full-lifecycle real-APFS tests cannot meet the default deadline, and
47
- # `specs/cowshed/08_testing.md` already contains the arithmetic that proves it.
48
- #
49
- # That spec sets the house rule for real-substrate timing: "CI asserts with a 3×
50
- # multiplier to absorb runner noise". `apfs_integration.rs` measured its lifecycle
51
- # at 14.8s on an IDLE host when it still ran a second image format, so under the
52
- # repo's own noise model CI needed 44.4s. A 30s deadline was therefore unreachable
53
- # by construction: the test was not slow, the bound contradicted the spec. The
54
- # one-format lifecycle measures 6.6-10.6s idle, so the bound below still covers it.
55
- #
56
- # Nor is the cost reducible. The same spec's "Attach floor verdict: not
57
- # flag-reducible" records that `-noverify` saves ~15ms (noise), `-noautofsck`
58
- # nothing, and `diskutil image attach` exposes no equivalent knobs — the ~235-400ms
59
- # per attach is inherent to DiskImages + APFS mount + DiskArbitration, and halving
60
- # it would need DiskImages2 or the diskarbitrationd private API, which the spec
61
- # explicitly forbids budgets from assuming. The lifecycle attaches once per phase
62
- # across adopt, mount, clone-under-churn, checkpoint, restore, retire, reclaim, GC
63
- # and detach, so its floor is a multiple of an irreducible constant.
64
- #
65
- # The alternative was splitting the lifecycle into phase-scoped tests so each fits
66
- # 30s. It loses: every split pays that attach constant again, so the suite's total
67
- # wall time rises to buy a smaller per-test bound; splitting phases buys only a
68
- # number.
69
- #
70
- # 60s is 3× the worst idle measurement (44.4s) rounded up, not a guess. It stays
71
- # bounded because an unbounded run phase is how a hung test becomes a hung lane.
72
- # Re-derive it if the idle measurements in `apfs_integration.rs` change.
73
- #
74
- # Membership is by name and narrower than the group: the fast `real_apfs_*` unit
75
- # tests in the lib keep the 30s default — they passed at 4.4s and 7.3s and have no
76
- # claim on more. This override precedes the group-only one so it wins the
77
- # first-match for both keys it sets.
78
- [[profile.default.overrides]]
79
- filter = 'test(/real_apfs_.*_substrate_lifecycle/)'
80
- slow-timeout = { period = "60s", terminate-after = 1 }
81
- test-group = '@tool:smoo:real-apfs'
82
-
83
- [[profile.default.overrides]]
84
- filter = 'test(/real_apfs_/)'
85
- test-group = '@tool:smoo:real-apfs'
18
+ slow-timeout = { period = "180s" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.4.25",
3
+ "version": "0.4.27",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -18,11 +18,31 @@
18
18
  "require": "./dist/version-actions.cjs",
19
19
  "default": "./dist/version-actions.cjs"
20
20
  },
21
+ "./eslint-file-set": {
22
+ "types": "./dist/eslint-file-set.d.ts",
23
+ "import": "./dist/eslint-file-set.js",
24
+ "default": "./dist/eslint-file-set.js"
25
+ },
26
+ "./failure-summary": {
27
+ "types": "./dist/failure-summary.d.ts",
28
+ "import": "./dist/failure-summary.js",
29
+ "default": "./dist/failure-summary.js"
30
+ },
21
31
  "./bounded-test-policy": {
22
32
  "types": "./dist/bounded-test-policy.d.ts",
23
33
  "import": "./dist/bounded-test-policy.js",
24
34
  "default": "./dist/bounded-test-policy.js"
25
35
  },
36
+ "./build-state-output-policy": {
37
+ "types": "./dist/build-state-output-policy.d.ts",
38
+ "import": "./dist/build-state-output-policy.js",
39
+ "default": "./dist/build-state-output-policy.js"
40
+ },
41
+ "./test-walk-policy": {
42
+ "types": "./dist/test-walk-policy.d.ts",
43
+ "import": "./dist/test-walk-policy.js",
44
+ "default": "./dist/test-walk-policy.js"
45
+ },
26
46
  "./workspace-config-policy": {
27
47
  "types": "./dist/workspace-config-policy.d.ts",
28
48
  "import": "./dist/workspace-config-policy.js",
@@ -43,11 +63,21 @@
43
63
  "import": "./dist/typecheck-test-policy.js",
44
64
  "default": "./dist/typecheck-test-policy.js"
45
65
  },
66
+ "./test-timings": {
67
+ "types": "./dist/test-timings.d.ts",
68
+ "import": "./dist/test-timings.js",
69
+ "default": "./dist/test-timings.js"
70
+ },
46
71
  "./ensure-built": {
47
72
  "types": "./dist/ensure-built.d.ts",
48
73
  "import": "./dist/ensure-built.js",
49
74
  "default": "./dist/ensure-built.js"
50
75
  },
76
+ "./testing": {
77
+ "types": "./dist/testing.d.ts",
78
+ "import": "./dist/testing.js",
79
+ "default": "./dist/testing.js"
80
+ },
51
81
  "./cross-check-policy": {
52
82
  "types": "./dist/cross-check-policy.d.ts",
53
83
  "import": "./dist/cross-check-policy.js",
@@ -58,6 +88,11 @@
58
88
  "import": "./dist/cargo-toolchain-policy.js",
59
89
  "default": "./dist/cargo-toolchain-policy.js"
60
90
  },
91
+ "./cargo-dev-profile": {
92
+ "types": "./dist/cargo-dev-profile.d.ts",
93
+ "import": "./dist/cargo-dev-profile.js",
94
+ "default": "./dist/cargo-dev-profile.js"
95
+ },
61
96
  "./workspace-manifest": {
62
97
  "types": "./dist/workspace-manifest.d.ts",
63
98
  "import": "./dist/workspace-manifest.js",
@@ -142,7 +177,10 @@
142
177
  "bin": {
143
178
  "smoo-nx-exec": "./dist/bin/smoo-nx-exec.js",
144
179
  "smoo-nx-cargo-hash": "./dist/bin/smoo-nx-cargo-hash.js",
145
- "smoo-nx-nextest-extract": "./dist/bin/smoo-nx-nextest-extract.js"
180
+ "smoo-nx-nextest-extract": "./dist/bin/smoo-nx-nextest-extract.js",
181
+ "smoo-nx-bound-failures": "./dist/bin/smoo-nx-bound-failures.js",
182
+ "smoo-nx-failures": "./dist/bin/smoo-nx-failures.js",
183
+ "smoo-nx-test-walks": "./dist/bin/smoo-nx-test-walks.js"
146
184
  },
147
185
  "generators": "./generators.json",
148
186
  "executors": "./executors.json",
@@ -158,42 +196,63 @@
158
196
  "test-shard1",
159
197
  "test-shard2",
160
198
  "test-shard3",
161
- "test-shard4"
199
+ "test-shard4",
200
+ "test-host"
162
201
  ]
163
202
  },
164
203
  "test-shard1": {
165
204
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
166
205
  "options": {
167
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=1/4",
206
+ "command": "bun test --timeout=30000 --timings=test-timings.json --shard=1/4 --path-ignore-patterns='**/*-host.test.ts'",
168
207
  "cwd": "{projectRoot}",
169
- "timeoutMs": 120000,
208
+ "idleTimeoutMs": 180000,
170
209
  "killAfterMs": 10000
171
210
  }
172
211
  },
173
212
  "test-shard2": {
174
213
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
175
214
  "options": {
176
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=2/4",
215
+ "command": "bun test --timeout=30000 --timings=test-timings.json --shard=2/4 --path-ignore-patterns='**/*-host.test.ts'",
177
216
  "cwd": "{projectRoot}",
178
- "timeoutMs": 120000,
217
+ "idleTimeoutMs": 180000,
179
218
  "killAfterMs": 10000
180
219
  }
181
220
  },
182
221
  "test-shard3": {
183
222
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
184
223
  "options": {
185
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=3/4",
224
+ "command": "bun test --timeout=30000 --timings=test-timings.json --shard=3/4 --path-ignore-patterns='**/*-host.test.ts'",
186
225
  "cwd": "{projectRoot}",
187
- "timeoutMs": 120000,
226
+ "idleTimeoutMs": 180000,
188
227
  "killAfterMs": 10000
189
228
  }
190
229
  },
191
230
  "test-shard4": {
192
231
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
193
232
  "options": {
194
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=4/4",
233
+ "command": "bun test --timeout=30000 --timings=test-timings.json --shard=4/4 --path-ignore-patterns='**/*-host.test.ts'",
234
+ "cwd": "{projectRoot}",
235
+ "idleTimeoutMs": 180000,
236
+ "killAfterMs": 10000
237
+ }
238
+ },
239
+ "test-host": {
240
+ "executor": "@smoothbricks/nx-plugin:bounded-exec",
241
+ "dependsOn": [
242
+ {
243
+ "projects": [
244
+ "cowshed"
245
+ ],
246
+ "target": "build"
247
+ }
248
+ ],
249
+ "options": {
250
+ "command": "bun test --timeout=30000 ./src/executors/bounded-exec/ram-temp-host.test.ts ./src/executors/bounded-exec/executor-host.test.ts",
195
251
  "cwd": "{projectRoot}",
196
- "timeoutMs": 120000,
252
+ "env": {
253
+ "COWSHED_EXECUTABLE": "{workspaceRoot}/packages/cowshed/bin/cowshed"
254
+ },
255
+ "idleTimeoutMs": 180000,
197
256
  "killAfterMs": 10000
198
257
  }
199
258
  }
@@ -207,6 +266,7 @@
207
266
  "dist",
208
267
  "src",
209
268
  "nextest.toml",
269
+ "runtime-input.sh",
210
270
  "test-timings.json",
211
271
  "README.md",
212
272
  "loader.js",
@@ -225,16 +285,18 @@
225
285
  "directory": "packages/nx-plugin"
226
286
  },
227
287
  "dependencies": {
228
- "@nx/js": "latest",
288
+ "@nx/js": "23.2.1",
289
+ "jsonc-parser": "^3.3.1",
229
290
  "nx": "latest",
230
291
  "prettier": "^3.9.8",
231
292
  "smol-toml": "^1.6.1",
232
293
  "tslib": "^2.8.1",
294
+ "typescript": "^6.0.3",
233
295
  "typia": "14.0.6",
234
296
  "yaml": "^2.9.0"
235
297
  },
236
298
  "devDependencies": {
237
- "@smoothbricks/lmao": "0.5.2",
299
+ "@smoothbricks/lmao": "0.5.4",
238
300
  "@smoothbricks/validation": "0.1.10",
239
301
  "fast-check": "^4.4.0"
240
302
  }
@@ -0,0 +1,81 @@
1
+ #!/bin/sh
2
+ # Runs one Nx `runtime` input:
3
+ #
4
+ # sh node_modules/@smoothbricks/nx-plugin/runtime-input.sh <command> [argument...]
5
+ #
6
+ # The input's value is the command's stdout. A command that fails stops Nx with
7
+ # an error; its failure never becomes a key.
8
+ #
9
+ # WHY the 0xFF byte. Nx 23.2.1 (`packages/nx/src/native/tasks/hashers/
10
+ # hash_runtime.rs`) runs a runtime input under `sh -c`, hashes its trimmed
11
+ # stdout followed by its trimmed stderr, and never looks at the exit status. A
12
+ # failed input is therefore a valid key: its error text, the same string for
13
+ # every history, toolchain or file it failed to read, so a result cached under
14
+ # one is replayed for all of them. Nx refuses exactly one outcome: a stream
15
+ # that is not UTF-8. `std::str::from_utf8` fails, the hash fails, and `nx run`
16
+ # exits 1 with `invalid utf-8 sequence of 1 bytes from index N`. So a failed
17
+ # command ends this script's stdout with 0xFF, a byte no UTF-8 text contains.
18
+ # runtime-input.test.ts plants a failure through real Nx and goes red the day
19
+ # Nx hashes these bytes instead of refusing them; if Nx starts honouring the
20
+ # exit status, the byte is redundant and can go.
21
+ #
22
+ # Nx drops runtime stderr, so it is not a reliable diagnostic channel. Failures
23
+ # retain private argv, byte-exact stderr, status and a readable report below
24
+ # $PWD/.runtime-input-failures/, outside Nx and temporary state. Read them with
25
+ # `cat .runtime-input-failures/*/report` after a decoder error. Stderr and a
26
+ # controlling /dev/tty also name the failure where those channels are visible.
27
+ #
28
+ # The command's stderr is not part of the value; it surfaces only on failure.
29
+ # Diagnostics name temp paths, process ids and the boundary the input ran in
30
+ # (an Nx daemon inside a sandbox runs inputs with the sandbox's view of the
31
+ # client's environment), none of which is the input.
32
+ set -u
33
+ if [ "$#" -eq 0 ]; then
34
+ echo 'usage: runtime-input.sh <command> [argument...]' >&2
35
+ printf '\377'
36
+ exit 64
37
+ fi
38
+ if diagnostic=$(mktemp "${TMPDIR:-/tmp}/nx-runtime-input.XXXXXXXXXX"); then
39
+ :
40
+ else
41
+ printf 'runtime input could not capture stderr: %s\n' "$*" >&2
42
+ printf '\377'
43
+ exit 73
44
+ fi
45
+ if "$@" 2>"$diagnostic"; then
46
+ rm -f "$diagnostic"
47
+ exit 0
48
+ else
49
+ status=$?
50
+ fi
51
+ cat "$diagnostic" >&2
52
+ if record=$(umask 077; mkdir -p "$PWD/.runtime-input-failures" &&
53
+ mktemp -d "$PWD/.runtime-input-failures/failure.XXXXXXXXXX"); then
54
+ if printf '%s\000' "$@" >"$record/argv" &&
55
+ printf '%s\n' "$status" >"$record/exit-status" &&
56
+ mv "$diagnostic" "$record/stderr" && {
57
+ printf 'runtime input exited %s: %s\n' "$status" "$*"
58
+ printf 'working directory: %s\n' "$PWD"
59
+ index=0
60
+ for argument
61
+ do
62
+ printf 'argv[%s]: <%s>\n' "$index" "$argument"
63
+ index=$((index + 1))
64
+ done
65
+ printf 'original stderr:\n'
66
+ cat "$record/stderr"
67
+ } >"$record/report"; then
68
+ printf '\nruntime input exited %s: %s; evidence: %s/report\n' "$status" "$*" "$record" >&2
69
+ # A detached daemon may have no terminal. Preserve that error too, rather
70
+ # than sending it into Nx's discarded stderr or swallowing it.
71
+ (exec 4>/dev/tty && cat "$record/report" >&4) 2>"$record/terminal-error"
72
+ else
73
+ printf '\nruntime input exited %s: %s; evidence incomplete: %s; stderr capture: %s\n' \
74
+ "$status" "$*" "$record" "$diagnostic" >&2
75
+ fi
76
+ else
77
+ printf '\nruntime input exited %s: %s; could not retain evidence; stderr capture: %s\n' \
78
+ "$status" "$*" "$diagnostic" >&2
79
+ fi
80
+ printf '\377'
81
+ exit "$status"
@@ -0,0 +1,286 @@
1
+ /**
2
+ * The processes behind the counted Cargo (`counted-cargo.ts`): every `cargo metadata` child, and the
3
+ * process a child leaves running behind it when asked to, as a real Cargo leaves rustc. Each holds one
4
+ * control connection to the fixture's broker in the test process for its whole life and reports its
5
+ * life over it; the broker answers each step when the test lets it. Nothing here waits on a clock:
6
+ * a child is held by a read on its connection, and a process's death is its connection's EOF.
7
+ *
8
+ * The protocol is a line per message, the broker's payload text JSON-quoted:
9
+ *
10
+ * child → broker start <pid> | read <grandchild pid | -> | end <exit status>
11
+ * grandchild → broker grandchild <pid> <parent pid>
12
+ * broker → child read <0|1 leave a grandchild> <canned answer | null> | answer <failure stderr | null>
13
+ *
14
+ * The broker never speaks to a grandchild; it ends a grandchild's connection on `release`, and a
15
+ * grandchild lives exactly until its connection ends.
16
+ */
17
+ import { spawn } from 'node:child_process';
18
+ import { closeSync, openSync, writeSync } from 'node:fs';
19
+ import { connect, type Socket } from 'node:net';
20
+ import { constants } from 'node:os';
21
+ import { join } from 'node:path';
22
+ import { fileURLToPath } from 'node:url';
23
+
24
+ /** What a `cargo metadata` child or a grandchild tells the broker. */
25
+ export type ProcessReport =
26
+ | { readonly kind: 'start'; readonly pid: number }
27
+ | { readonly kind: 'read'; readonly grandchild: number | null }
28
+ | { readonly kind: 'end'; readonly status: number }
29
+ | { readonly kind: 'grandchild'; readonly pid: number; readonly parent: number };
30
+
31
+ /** What the broker tells a `cargo metadata` child, each when its gate lets it. */
32
+ export type BrokerOrder =
33
+ | { readonly kind: 'read'; readonly grandchild: boolean; readonly canned: string | null }
34
+ | { readonly kind: 'answer'; readonly failure: string | null };
35
+
36
+ export const BROKER_HOST = '127.0.0.1';
37
+
38
+ export function encodeReport(report: ProcessReport): string {
39
+ switch (report.kind) {
40
+ case 'start':
41
+ return `start ${report.pid}\n`;
42
+ case 'read':
43
+ return `read ${report.grandchild ?? '-'}\n`;
44
+ case 'end':
45
+ return `end ${report.status}\n`;
46
+ case 'grandchild':
47
+ return `grandchild ${report.pid} ${report.parent}\n`;
48
+ }
49
+ }
50
+
51
+ export function encodeOrder(order: BrokerOrder): string {
52
+ switch (order.kind) {
53
+ case 'read':
54
+ return `read ${order.grandchild ? 1 : 0} ${JSON.stringify(order.canned)}\n`;
55
+ case 'answer':
56
+ return `answer ${JSON.stringify(order.failure)}\n`;
57
+ }
58
+ }
59
+
60
+ function integer(text: string | undefined, what: string): number | Error {
61
+ const value = Number(text);
62
+ return text !== undefined && text !== '' && Number.isSafeInteger(value) && value >= 0
63
+ ? value
64
+ : new Error(`${what} is not a non-negative integer: ${JSON.stringify(text)}`);
65
+ }
66
+
67
+ function text(json: string): string | null | Error {
68
+ let value: unknown;
69
+ try {
70
+ value = JSON.parse(json);
71
+ } catch (error) {
72
+ return new Error(`payload is not JSON: ${json}`, { cause: error });
73
+ }
74
+ return typeof value === 'string' || value === null ? value : new Error(`expected a JSON string or null, got ${json}`);
75
+ }
76
+
77
+ export function parseReport(line: string): ProcessReport | Error {
78
+ const [kind, first, second, ...extra] = line.split(' ');
79
+ if (extra.length > 0 || (kind === 'grandchild') === (second === undefined)) {
80
+ return new Error(`malformed report ${JSON.stringify(line)}`);
81
+ }
82
+ switch (kind) {
83
+ case 'start': {
84
+ const pid = integer(first, 'start pid');
85
+ return pid instanceof Error ? pid : { kind: 'start', pid };
86
+ }
87
+ case 'read': {
88
+ if (first === '-') return { kind: 'read', grandchild: null };
89
+ const grandchild = integer(first, 'grandchild pid');
90
+ return grandchild instanceof Error ? grandchild : { kind: 'read', grandchild };
91
+ }
92
+ case 'end': {
93
+ const status = integer(first, 'exit status');
94
+ return status instanceof Error ? status : { kind: 'end', status };
95
+ }
96
+ case 'grandchild': {
97
+ const pid = integer(first, 'grandchild pid');
98
+ if (pid instanceof Error) return pid;
99
+ const parent = integer(second, 'parent pid');
100
+ return parent instanceof Error ? parent : { kind: 'grandchild', pid, parent };
101
+ }
102
+ default:
103
+ return new Error(`unknown report ${JSON.stringify(line)}`);
104
+ }
105
+ }
106
+
107
+ export function parseOrder(line: string): BrokerOrder | Error {
108
+ if (line.startsWith('read ')) {
109
+ const flag = line.slice(5, 6);
110
+ if ((flag !== '0' && flag !== '1') || line[6] !== ' ') return new Error(`malformed order ${JSON.stringify(line)}`);
111
+ const canned = text(line.slice(7));
112
+ return canned instanceof Error ? canned : { kind: 'read', grandchild: flag === '1', canned };
113
+ }
114
+ if (line.startsWith('answer ')) {
115
+ const failure = text(line.slice(7));
116
+ return failure instanceof Error ? failure : { kind: 'answer', failure };
117
+ }
118
+ return new Error(`unknown order ${JSON.stringify(line)}`);
119
+ }
120
+
121
+ /**
122
+ * Calls `onLine` with each newline-terminated line `socket` delivers, in order. Returns what has
123
+ * arrived since the last newline: a peer that died mid-line leaves it there for diagnostics.
124
+ */
125
+ export function readLines(socket: Socket, onLine: (line: string) => void): () => string {
126
+ let pending: Buffer = Buffer.alloc(0);
127
+ socket.on('data', (chunk: Buffer) => {
128
+ let data = pending.length === 0 ? chunk : Buffer.concat([pending, chunk]);
129
+ for (let newline = data.indexOf(10); newline !== -1; newline = data.indexOf(10)) {
130
+ onLine(data.toString('utf8', 0, newline));
131
+ data = data.subarray(newline + 1);
132
+ }
133
+ pending = data;
134
+ });
135
+ return () => pending.toString('utf8');
136
+ }
137
+
138
+ /** One process's end, said on its stderr: the parent that reads it, or the log a grandchild writes. */
139
+ function fail(message: string): never {
140
+ writeSync(2, `counted cargo process ${process.pid}: ${message}\n`);
141
+ process.exit(1);
142
+ }
143
+
144
+ function connectToBroker(port: number): Promise<Socket> {
145
+ return new Promise((resolve, reject) => {
146
+ const socket = connect({ host: BROKER_HOST, port });
147
+ socket.once('error', reject);
148
+ socket.once('connect', () => {
149
+ socket.off('error', reject);
150
+ resolve(socket);
151
+ });
152
+ });
153
+ }
154
+
155
+ /** The broker's orders, one at a time, in the order they arrive; `null` once the broker has hung up. */
156
+ function orders(socket: Socket): () => Promise<BrokerOrder | null> {
157
+ const arrived: (BrokerOrder | Error)[] = [];
158
+ const waiting: ((order: BrokerOrder | Error | null) => void)[] = [];
159
+ let closed = false;
160
+ readLines(socket, (line) => {
161
+ const order = parseOrder(line);
162
+ const waiter = waiting.shift();
163
+ if (waiter === undefined) arrived.push(order);
164
+ else waiter(order);
165
+ });
166
+ socket.on('close', () => {
167
+ closed = true;
168
+ for (const waiter of waiting.splice(0)) waiter(null);
169
+ });
170
+ socket.on('error', (error) => fail(`connection to the broker failed: ${error.message}`));
171
+ return async () => {
172
+ const next =
173
+ arrived.shift() ??
174
+ (closed
175
+ ? null
176
+ : await new Promise<BrokerOrder | Error | null>((resolve) => {
177
+ waiting.push(resolve);
178
+ }));
179
+ if (next instanceof Error) fail(next.message);
180
+ return next;
181
+ };
182
+ }
183
+
184
+ function write(stream: NodeJS.WritableStream, data: string | Buffer): Promise<void> {
185
+ return new Promise((resolve, reject) => {
186
+ stream.write(data, (error) => (error ? reject(error) : resolve()));
187
+ });
188
+ }
189
+
190
+ /** What the real `cargo metadata` prints, and the status it exits with; its stderr is this child's. */
191
+ function runReal(real: string, args: readonly string[]): Promise<{ stdout: Buffer; status: number }> {
192
+ return new Promise((resolve, reject) => {
193
+ const cargo = spawn(real, args, { stdio: ['ignore', 'pipe', 'inherit'] });
194
+ const chunks: Buffer[] = [];
195
+ cargo.stdout.on('data', (chunk: Buffer) => chunks.push(chunk));
196
+ cargo.once('error', reject);
197
+ cargo.once('close', (code, signal) =>
198
+ resolve({
199
+ stdout: Buffer.concat(chunks),
200
+ status: code ?? 128 + (signal === null ? 0 : constants.signals[signal]),
201
+ }),
202
+ );
203
+ });
204
+ }
205
+
206
+ /**
207
+ * A process left running in this child's process group, as real Cargo leaves rustc. Its output goes
208
+ * to a log in the fixture, never this child's pipes, so it holds nothing of Cargo's open.
209
+ */
210
+ function leaveGrandchild(port: number, directory: string): number {
211
+ const log = openSync(join(directory, `grandchild-of-${process.pid}.log`), 'a');
212
+ try {
213
+ const program = fileURLToPath(import.meta.url);
214
+ const grandchild = spawn(process.execPath, [program, 'grandchild', String(port), String(process.pid)], {
215
+ stdio: ['ignore', log, log],
216
+ });
217
+ const pid = grandchild.pid;
218
+ if (pid === undefined) fail('the grandchild did not start');
219
+ grandchild.once('error', (error) => fail(`the grandchild failed: ${error.message}`));
220
+ grandchild.unref();
221
+ return pid;
222
+ } finally {
223
+ closeSync(log);
224
+ }
225
+ }
226
+
227
+ /** One `cargo metadata` child: reports its life, and takes each step only when the broker orders it. */
228
+ async function metadataChild(port: number, real: string, directory: string, args: readonly string[]): Promise<void> {
229
+ const socket = await connectToBroker(port);
230
+ const next = orders(socket);
231
+ socket.write(encodeReport({ kind: 'start', pid: process.pid }));
232
+
233
+ const read = await next();
234
+ if (read === null) fail('the broker hung up before letting this child read the workspace');
235
+ if (read.kind !== 'read') fail(`expected the order to read, got ${read.kind}`);
236
+ const produced = read.canned === null ? await runReal(real, args) : { stdout: Buffer.from(read.canned), status: 0 };
237
+ const grandchild = read.grandchild ? leaveGrandchild(port, directory) : null;
238
+ socket.write(encodeReport({ kind: 'read', grandchild }));
239
+
240
+ const answer = await next();
241
+ if (answer === null) fail('the broker hung up before letting this child answer');
242
+ if (answer.kind !== 'answer') fail(`expected the order to answer, got ${answer.kind}`);
243
+ let status = produced.status;
244
+ if (answer.failure === null) {
245
+ await write(process.stdout, produced.stdout);
246
+ } else {
247
+ await write(process.stderr, answer.failure);
248
+ status = 101;
249
+ }
250
+ socket.end(encodeReport({ kind: 'end', status }));
251
+ // The process ends when the connection is done and the event loop drains, with every byte written.
252
+ process.exitCode = status;
253
+ }
254
+
255
+ /** A grandchild: registers, and lives exactly as long as its connection to the broker. */
256
+ async function grandchild(port: number, parent: number): Promise<void> {
257
+ const socket = await connectToBroker(port);
258
+ socket.on('error', (error) => fail(`connection to the broker failed: ${error.message}`));
259
+ socket.on('data', (chunk: Buffer) => fail(`the broker spoke to a grandchild: ${JSON.stringify(String(chunk))}`));
260
+ socket.write(encodeReport({ kind: 'grandchild', pid: process.pid, parent }));
261
+ }
262
+
263
+ async function main([role, portText, ...rest]: readonly string[]): Promise<void> {
264
+ const port = integer(portText, 'broker port');
265
+ if (port instanceof Error) fail(port.message);
266
+ switch (role) {
267
+ case 'metadata': {
268
+ const [real, directory, ...args] = rest;
269
+ if (real === undefined || directory === undefined) fail('usage: metadata <port> <real> <directory> <args...>');
270
+ return metadataChild(port, real, directory, args);
271
+ }
272
+ case 'grandchild': {
273
+ const parent = integer(rest[0], 'parent pid');
274
+ if (parent instanceof Error) fail(parent.message);
275
+ return grandchild(port, parent);
276
+ }
277
+ default:
278
+ fail(`unknown role ${JSON.stringify(role)}`);
279
+ }
280
+ }
281
+
282
+ if (import.meta.main) {
283
+ await main(process.argv.slice(2)).catch((error: unknown) =>
284
+ fail(error instanceof Error ? (error.stack ?? error.message) : String(error)),
285
+ );
286
+ }