@smoothbricks/nx-plugin 0.4.26 → 0.4.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/README.md +994 -117
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +15 -73
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +3 -2
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +16 -15
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +43 -6
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +309 -73
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +101 -5
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +291 -10
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +207 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +576 -202
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +370 -138
  102. package/dist/managed-files/ci-workflow.d.ts +13 -0
  103. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.js +44 -13
  105. package/dist/managed-files/files.d.ts +7 -1
  106. package/dist/managed-files/files.d.ts.map +1 -1
  107. package/dist/managed-files/files.js +62 -8
  108. package/dist/managed-files/json-edit.d.ts +21 -0
  109. package/dist/managed-files/json-edit.d.ts.map +1 -0
  110. package/dist/managed-files/json-edit.js +295 -0
  111. package/dist/managed-files/managed-format.d.ts +33 -1
  112. package/dist/managed-files/managed-format.d.ts.map +1 -1
  113. package/dist/managed-files/managed-format.js +82 -2
  114. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  115. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  116. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  117. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/publish-workflow.js +231 -48
  119. package/dist/managed-files/tree.d.ts +5 -0
  120. package/dist/managed-files/tree.d.ts.map +1 -1
  121. package/dist/managed-files/tree.js +5 -3
  122. package/dist/manifest-hash.d.ts.map +1 -1
  123. package/dist/manifest-hash.js +2 -5
  124. package/dist/nextest-code-bound.d.ts +62 -0
  125. package/dist/nextest-code-bound.d.ts.map +1 -0
  126. package/dist/nextest-code-bound.js +154 -0
  127. package/dist/nextest-extraction.d.ts +24 -8
  128. package/dist/nextest-extraction.d.ts.map +1 -1
  129. package/dist/nextest-extraction.js +42 -7
  130. package/dist/package-target-policy.d.ts.map +1 -1
  131. package/dist/package-target-policy.js +3 -5
  132. package/dist/release-config-policy.d.ts.map +1 -1
  133. package/dist/release-config-policy.js +3 -5
  134. package/dist/runtime-input.d.ts +14 -0
  135. package/dist/runtime-input.d.ts.map +1 -0
  136. package/dist/runtime-input.js +15 -0
  137. package/dist/rust-tokens.d.ts +11 -0
  138. package/dist/rust-tokens.d.ts.map +1 -0
  139. package/dist/rust-tokens.js +81 -0
  140. package/dist/task-results.d.ts +6 -0
  141. package/dist/task-results.d.ts.map +1 -0
  142. package/dist/task-results.js +61 -0
  143. package/dist/test-program.d.ts +54 -0
  144. package/dist/test-program.d.ts.map +1 -0
  145. package/dist/test-program.js +292 -0
  146. package/dist/test-timings.d.ts +71 -0
  147. package/dist/test-timings.d.ts.map +1 -0
  148. package/dist/test-timings.js +393 -0
  149. package/dist/test-walk-policy.d.ts +103 -0
  150. package/dist/test-walk-policy.d.ts.map +1 -0
  151. package/dist/test-walk-policy.js +657 -0
  152. package/dist/testing.d.ts +177 -0
  153. package/dist/testing.d.ts.map +1 -0
  154. package/dist/testing.js +824 -0
  155. package/dist/type-guards.d.ts +3 -0
  156. package/dist/type-guards.d.ts.map +1 -0
  157. package/dist/type-guards.js +4 -0
  158. package/dist/typecheck-test-policy.d.ts +8 -5
  159. package/dist/typecheck-test-policy.d.ts.map +1 -1
  160. package/dist/typecheck-test-policy.js +113 -100
  161. package/dist/workspace-config-policy.d.ts +8 -0
  162. package/dist/workspace-config-policy.d.ts.map +1 -1
  163. package/dist/workspace-config-policy.js +175 -63
  164. package/dist/workspace-index.d.ts +12 -0
  165. package/dist/workspace-index.d.ts.map +1 -0
  166. package/dist/workspace-index.js +17 -0
  167. package/dist/workspace-manifest.d.ts +37 -0
  168. package/dist/workspace-manifest.d.ts.map +1 -1
  169. package/executors.json +5 -0
  170. package/loader.js +13 -11
  171. package/managed/raw/envrc +33 -67
  172. package/managed/raw/git-format-staged.yml +30 -35
  173. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  174. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  175. package/managed/raw/tooling/direnv/developer-links.ts +569 -11
  176. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
  177. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  178. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  179. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  180. package/managed/raw/tooling/direnv/repo-path +14 -2
  181. package/managed/raw/tooling/direnv/setup-environment.ts +1146 -159
  182. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  183. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  184. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  185. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  186. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  187. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  188. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  189. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  190. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  191. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  192. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  194. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  196. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  197. package/managed/templates/github/workflows/managed-files.yml +1 -2
  198. package/nextest.toml +8 -41
  199. package/package.json +74 -12
  200. package/runtime-input.sh +81 -0
  201. package/src/__tests__/counted-cargo.ts +33 -14
  202. package/src/__tests__/fixture-nx-env.ts +111 -46
  203. package/src/__tests__/progress-clock.ts +43 -0
  204. package/src/__tests__/runtime-input.ts +23 -0
  205. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  206. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  207. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  208. package/src/bin/smoo-nx-exec.ts +16 -74
  209. package/src/bin/smoo-nx-failures.ts +4 -0
  210. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  211. package/src/bin/smoo-nx-test-walks.ts +42 -0
  212. package/src/bounded-test-policy.test.ts +268 -21
  213. package/src/bounded-test-policy.ts +114 -42
  214. package/src/build-state-output-policy.test.ts +115 -0
  215. package/src/build-state-output-policy.ts +90 -0
  216. package/src/bun-bootstrap.test.ts +57 -3
  217. package/src/bun-file-packages.test.ts +47 -0
  218. package/src/cargo-closure-input.test.ts +138 -66
  219. package/src/cargo-closure-input.ts +17 -15
  220. package/src/cargo-dev-profile.ts +137 -0
  221. package/src/cargo-resolve-cache.test.ts +70 -1
  222. package/src/cargo-source-hash.test.ts +193 -97
  223. package/src/cargo-source-hash.ts +345 -68
  224. package/src/cargo-toolchain-policy.ts +6 -0
  225. package/src/cargo-workspace.test.ts +320 -0
  226. package/src/cargo-workspace.ts +336 -10
  227. package/src/cross-check-policy.test.ts +59 -1
  228. package/src/cross-check-policy.ts +25 -6
  229. package/src/disk-command-policy.test.ts +61 -0
  230. package/src/disk-command-policy.ts +107 -0
  231. package/src/ensure-built-receipt.test.ts +184 -0
  232. package/src/ensure-built-receipt.ts +263 -0
  233. package/src/ensure-built-witness.test.ts +344 -0
  234. package/src/ensure-built-witness.ts +252 -0
  235. package/src/ensure-built.test.ts +1036 -578
  236. package/src/ensure-built.ts +820 -224
  237. package/src/eslint-file-set.ts +9 -0
  238. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  239. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  240. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  241. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  242. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  243. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  244. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  245. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  246. package/src/executors/bounded-exec/executor.ts +565 -67
  247. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  248. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  249. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  250. package/src/executors/bounded-exec/progress.test.ts +79 -0
  251. package/src/executors/bounded-exec/progress.ts +118 -0
  252. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  253. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  254. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  255. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  256. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  257. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  258. package/src/executors/bounded-exec/schema.json +11 -5
  259. package/src/executors/bounded-exec/schema.ts +27 -11
  260. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  261. package/src/executors/bounded-exec/verdict.ts +433 -0
  262. package/src/executors/shard-timings/executor.ts +36 -0
  263. package/src/executors/shard-timings/schema.json +21 -0
  264. package/src/executors/shard-timings/schema.ts +4 -0
  265. package/src/failure-summary.ts +119 -0
  266. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  267. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  268. package/src/generators/create-package/generator.test.ts +6 -0
  269. package/src/generators/create-package/generator.ts +6 -2
  270. package/src/host-controller-wiring.test.ts +31 -0
  271. package/src/index.test.ts +909 -295
  272. package/src/index.ts +441 -143
  273. package/src/linked-snapshots.nx.test.ts +172 -0
  274. package/src/managed-files/ci-workflow.ts +54 -13
  275. package/src/managed-files/files.ts +65 -9
  276. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  277. package/src/managed-files/generator.test.ts +60 -1
  278. package/src/managed-files/json-edit.test.ts +216 -0
  279. package/src/managed-files/json-edit.ts +290 -0
  280. package/src/managed-files/managed-format-json.test.ts +308 -0
  281. package/src/managed-files/managed-format.ts +90 -2
  282. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  283. package/src/managed-files/publish-workflow.ts +285 -67
  284. package/src/managed-files/repo-path.test.ts +129 -0
  285. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  286. package/src/managed-files/tree.ts +11 -3
  287. package/src/manifest-hash.ts +2 -6
  288. package/src/nextest-code-bound.test.ts +155 -0
  289. package/src/nextest-code-bound.ts +195 -0
  290. package/src/nextest-extraction.test.ts +37 -5
  291. package/src/nextest-extraction.ts +51 -9
  292. package/src/nextest-partitions.test.ts +427 -82
  293. package/src/nx-cache-bound.test.ts +5 -10
  294. package/src/nx-cache-restore-mtime.test.ts +170 -0
  295. package/src/nx-daemon-claim.test.ts +277 -0
  296. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  297. package/src/nx-daemon-idle-policy.test.ts +51 -0
  298. package/src/nx-daemon-ignore-files.test.ts +210 -0
  299. package/src/nx-daemon-root-normalization.test.ts +105 -0
  300. package/src/nx-daemon-validity.test.ts +925 -0
  301. package/src/nx-dot-input-policy.test.ts +353 -0
  302. package/src/nx-failure-life-cycles.test.ts +207 -0
  303. package/src/nx-files-archive-racy.test.ts +97 -0
  304. package/src/nx-foreign-workspace-env.test.ts +329 -0
  305. package/src/nx-incomplete-run-summary.test.ts +70 -0
  306. package/src/nx-plugin-load-errors.test.ts +120 -0
  307. package/src/nx-project-resolution-cache.test.ts +176 -0
  308. package/src/nx-raw-inputs.test.ts +166 -0
  309. package/src/nx-resident-graph-workers.test.ts +7 -16
  310. package/src/nx-run-information.test.ts +118 -0
  311. package/src/nx-skipped-task-exit.test.ts +180 -0
  312. package/src/nx-state-location.test.ts +63 -0
  313. package/src/nx-store-resolution.test.ts +26 -25
  314. package/src/nx-task-graph-cycles.test.ts +148 -0
  315. package/src/nx-task-output-lease.test.ts +414 -0
  316. package/src/nx-use-local.test.ts +103 -0
  317. package/src/package-target-policy.ts +3 -6
  318. package/src/release-config-policy.ts +3 -6
  319. package/src/runtime-input.test.ts +215 -0
  320. package/src/runtime-input.ts +17 -0
  321. package/src/rust-tokens.ts +78 -0
  322. package/src/serial-group-wiring.test.ts +326 -0
  323. package/src/task-history-namespace.test.ts +87 -89
  324. package/src/task-results.test.ts +226 -0
  325. package/src/task-results.ts +75 -0
  326. package/src/test-program.test.ts +303 -0
  327. package/src/test-program.ts +341 -0
  328. package/src/test-timings.test.ts +240 -0
  329. package/src/test-timings.ts +311 -0
  330. package/src/test-walk-policy.test.ts +585 -0
  331. package/src/test-walk-policy.ts +731 -0
  332. package/src/testing.test.ts +509 -0
  333. package/src/testing.ts +922 -0
  334. package/src/type-guards.ts +4 -0
  335. package/src/typecheck-test-policy.test.ts +496 -11
  336. package/src/typecheck-test-policy.ts +137 -103
  337. package/src/workspace-config-policy.test.ts +212 -13
  338. package/src/workspace-config-policy.ts +101 -73
  339. package/src/workspace-index.ts +18 -0
  340. package/src/workspace-manifest.ts +41 -0
  341. package/test-timings.json +85 -30
  342. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
  343. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
@@ -0,0 +1,433 @@
1
+ import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+
4
+ /**
5
+ * Why one bounded run ended, recorded per Nx task so a caller can tell a load-sensitive bound
6
+ * from a real failure without reading the run's output.
7
+ *
8
+ * - `bound`: the run hit a wall-clock bound and nothing else failed. Either the command
9
+ * outlived `timeoutMs` (`total`), or every failing test in the runner's report failed on
10
+ * its runner's per-test timeout (`test`). A loaded host produces exactly these.
11
+ * - `wedged`: `idleTimeoutMs` fired: no test finished for that long. A machine that is only slow still finishes
12
+ * tests, so this is a hang, not a slow host, and the fix is the opposite one, so it is never a `bound`. It names
13
+ * the tests still running: those the runner said were running and never said finished, and those its report says
14
+ * it aborted when the bound stopped it.
15
+ * - `failed`: anything else that did not pass. That includes an assertion named in the report,
16
+ * or a non-zero exit with no report to say why.
17
+ */
18
+ export type BoundedExecVerdict =
19
+ | { readonly outcome: 'passed' }
20
+ | { readonly outcome: 'bound'; readonly bound: 'total'; readonly limitMs: number; readonly elapsedMs: number }
21
+ | { readonly outcome: 'bound'; readonly bound: 'test'; readonly tests: readonly string[] }
22
+ | {
23
+ readonly outcome: 'wedged';
24
+ readonly idleMs: number;
25
+ readonly elapsedMs: number;
26
+ readonly tests: readonly string[];
27
+ }
28
+ | { readonly outcome: 'failed'; readonly exitCode: number; readonly tests: readonly string[] };
29
+
30
+ /** One task's verdict, keyed by the Nx task and the hash it ran at. */
31
+ export interface BoundedExecRecord {
32
+ readonly task: string;
33
+ readonly hash: string | null;
34
+ readonly verdict: BoundedExecVerdict;
35
+ /**
36
+ * The host CPU budget's grant the run started under: tokens granted of those asked for, and
37
+ * how long it waited. Absent when it ran unbudgeted; written for the reader of a slow run,
38
+ * never read back.
39
+ */
40
+ readonly cpu?: {
41
+ readonly tokens: number;
42
+ readonly want: number;
43
+ readonly waitedMs: number;
44
+ /** Set when the tokens came from an ancestor's CPU pool, not the host budget; `waitedMs` is the wait for that pool. */
45
+ readonly inherited?: true;
46
+ };
47
+ }
48
+
49
+ /** The Nx task a run executes as. Nx gives an executor no task id, only its parts. */
50
+ export interface BoundedExecTask {
51
+ readonly id: string;
52
+ readonly hash: string | null;
53
+ }
54
+
55
+ /** The environment variable naming the absolute path a command writes its JUnit report to. */
56
+ export const JUNIT_REPORT_ENV = 'BOUNDED_EXEC_JUNIT';
57
+
58
+ /**
59
+ * JUnit failure `type`s that mean "the runner's per-test timeout fired". `cargo-nextest` writes
60
+ * `test timeout` for a test it terminated at its slow-timeout; `bun test` writes `TimeoutError`
61
+ * for a test or hook that outlived `--timeout`. Every other type is a failure of the test itself.
62
+ */
63
+ const TIMEOUT_FAILURE_TYPES: Readonly<Record<string, true>> = { 'test timeout': true, TimeoutError: true };
64
+
65
+ /**
66
+ * The JUnit failure that means "the runner stopped this test because its command was told to stop". When the
67
+ * SIGTERM bounded-exec sends at a bound reaches `cargo-nextest`, it ends the tests still running and reports each as
68
+ * a `test abort` whose message names the signal: SIGTERM, or SIGKILL once the force-kill has followed. A test that
69
+ * dies of any other signal (SIGSEGV, SIGABRT) is a crash of the test itself.
70
+ */
71
+ const CANCELLED_ABORT_TYPE = 'test abort';
72
+ const CANCELLED_ABORT_MESSAGE = /^process aborted with signal (?:15 \(SIGTERM\)|9 \(SIGKILL\))$/;
73
+
74
+ type FailureKind = 'timedOut' | 'cancelled' | 'failed';
75
+
76
+ function failureKind(type: string, message: string): FailureKind {
77
+ if (Object.hasOwn(TIMEOUT_FAILURE_TYPES, type)) {
78
+ return 'timedOut';
79
+ }
80
+ return type === CANCELLED_ABORT_TYPE && CANCELLED_ABORT_MESSAGE.test(message) ? 'cancelled' : 'failed';
81
+ }
82
+
83
+ /** The failing tests of one JUnit report, split by what failed them. */
84
+ export interface JunitFailures {
85
+ /** Failed only on the runner's per-test timeout. */
86
+ readonly timedOut: readonly string[];
87
+ /** Aborted by the runner because its command was told to stop, not failed by anything they did. */
88
+ readonly cancelled: readonly string[];
89
+ readonly failed: readonly string[];
90
+ }
91
+
92
+ /**
93
+ * Read the failing test cases out of a JUnit document. A case fails when it holds a `failure`
94
+ * or `error` element; it counts as timed out only when every such element is a timeout.
95
+ * Retry elements (`flakyFailure`, `rerunFailure`, ...) describe attempts, not the verdict.
96
+ */
97
+ export function junitFailures(xml: string): JunitFailures {
98
+ const timedOut: string[] = [];
99
+ const cancelled: string[] = [];
100
+ const failed: string[] = [];
101
+ const text = xml.replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, '').replace(/<!--[\s\S]*?-->/g, '');
102
+ const tags = /<(\/?)(testcase|failure|error)\b((?:[^>"']|"[^"]*"|'[^']*')*?)(\/?)>/g;
103
+ let current: { name: string; kinds: FailureKind[] } | null = null;
104
+ const close = (): void => {
105
+ if (current === null) {
106
+ return;
107
+ }
108
+ const [first] = current.kinds;
109
+ if (first !== undefined) {
110
+ const kind = current.kinds.every((one) => one === first) ? first : 'failed';
111
+ (kind === 'timedOut' ? timedOut : kind === 'cancelled' ? cancelled : failed).push(current.name);
112
+ }
113
+ current = null;
114
+ };
115
+ for (const [, slash, tag, attributes = '', selfClosing] of text.matchAll(tags)) {
116
+ if (tag === 'testcase') {
117
+ if (slash === '/') {
118
+ close();
119
+ continue;
120
+ }
121
+ close();
122
+ const name = attribute(attributes, 'name') ?? '';
123
+ const classname = attribute(attributes, 'classname');
124
+ current = { name: classname ? `${classname} ${name}` : name, kinds: [] };
125
+ if (selfClosing === '/') {
126
+ close();
127
+ }
128
+ continue;
129
+ }
130
+ if (slash === '/' || current === null) {
131
+ continue;
132
+ }
133
+ current.kinds.push(failureKind(attribute(attributes, 'type') ?? '', attribute(attributes, 'message') ?? ''));
134
+ }
135
+ close();
136
+ return { timedOut, cancelled, failed };
137
+ }
138
+
139
+ function attribute(attributes: string, name: string): string | null {
140
+ const match = new RegExp(`(?:^|\\s)${name}\\s*=\\s*("([^"]*)"|'([^']*)')`).exec(attributes);
141
+ if (match === null) {
142
+ return null;
143
+ }
144
+ return decodeEntities(match[2] ?? match[3] ?? '');
145
+ }
146
+
147
+ function decodeEntities(value: string): string {
148
+ return value.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|amp|lt|gt|quot|apos);/g, (_, entity: string) => {
149
+ switch (entity) {
150
+ case 'amp':
151
+ return '&';
152
+ case 'lt':
153
+ return '<';
154
+ case 'gt':
155
+ return '>';
156
+ case 'quot':
157
+ return '"';
158
+ case 'apos':
159
+ return "'";
160
+ default:
161
+ return String.fromCodePoint(
162
+ entity.startsWith('#x') ? Number.parseInt(entity.slice(2), 16) : Number.parseInt(entity.slice(1), 10),
163
+ );
164
+ }
165
+ });
166
+ }
167
+
168
+ /**
169
+ * The bound that ended a run. `total` is a wall-clock ceiling: it answers "is this run unbounded?". `idle` is the
170
+ * no-progress bound: it answers "is this run hung?", and carries the tests the runner reported still running.
171
+ *
172
+ * These are different questions and one number cannot answer both. A ceiling tight enough to catch a hang promptly
173
+ * is also tight enough to fail a correct run on a busy machine; a ceiling loose enough never to do that cannot catch
174
+ * a hang promptly. Keeping the two bounds separate is what makes each honest.
175
+ */
176
+ export type ExpiredBound =
177
+ | { readonly kind: 'total'; readonly limitMs: number }
178
+ | { readonly kind: 'idle'; readonly limitMs: number; readonly tests: readonly string[] };
179
+
180
+ /** How a run ended, as the executor saw it. */
181
+ export interface RunEnd {
182
+ readonly exitCode: number;
183
+ readonly elapsedMs: number;
184
+ readonly expiry: ExpiredBound | null;
185
+ /** The run's report, or `null` when the command was asked for none or wrote none. */
186
+ readonly report: JunitFailures | null;
187
+ }
188
+
189
+ /**
190
+ * Judge a run. A test that failed on its own is a failure even when a bound fired too, and the no-progress bound is
191
+ * never load: the report's assertions and the idle bound are read first. A test the runner aborted because the total
192
+ * bound told its command to stop is not one that failed; one it aborted at the idle bound is a test still running.
193
+ */
194
+ export function judgeRun(run: RunEnd): BoundedExecVerdict {
195
+ if (run.expiry?.kind === 'idle') {
196
+ const tests = [...new Set([...run.expiry.tests, ...(run.report?.cancelled ?? [])])];
197
+ return { outcome: 'wedged', idleMs: run.expiry.limitMs, elapsedMs: run.elapsedMs, tests };
198
+ }
199
+ if (run.report !== null && run.report.failed.length > 0) {
200
+ return { outcome: 'failed', exitCode: run.exitCode, tests: run.report.failed };
201
+ }
202
+ // The tests the runner aborted when the ceiling's SIGTERM reached it are the bound's casualties: they are in the
203
+ // report as failures, but nothing about them failed. Aborted with no total bound to explain it, they are failures,
204
+ // whatever else the run shows: a zero exit or a per-test timeout does not excuse a test someone else stopped.
205
+ if (run.expiry?.kind === 'total') {
206
+ return { outcome: 'bound', bound: 'total', limitMs: run.expiry.limitMs, elapsedMs: run.elapsedMs };
207
+ }
208
+ if (run.report !== null && run.report.cancelled.length > 0) {
209
+ return { outcome: 'failed', exitCode: run.exitCode, tests: run.report.cancelled };
210
+ }
211
+ if (run.exitCode === 0) {
212
+ return { outcome: 'passed' };
213
+ }
214
+ if (run.report !== null && run.report.timedOut.length > 0) {
215
+ return { outcome: 'bound', bound: 'test', tests: run.report.timedOut };
216
+ }
217
+ return { outcome: 'failed', exitCode: run.exitCode, tests: [] };
218
+ }
219
+
220
+ /**
221
+ * A run that failed for a reason its command did not cause: its CPU grant was lost, or its sub-pool did not close
222
+ * cleanly. It is an ordinary failure whatever the command exited with and whatever bound also fired, and the tests it
223
+ * reports are failures, never bounds. A failed run never records exit 0.
224
+ */
225
+ export function judgeOperationalFailure(exitCode: number, report: JunitFailures | null): BoundedExecVerdict {
226
+ const tests = report === null ? [] : [...report.failed, ...report.timedOut, ...report.cancelled];
227
+ return { outcome: 'failed', exitCode: exitCode === 0 ? 1 : exitCode, tests };
228
+ }
229
+
230
+ /** Where `task`'s verdict and report live: this checkout's own Nx workspace-data directory. */
231
+ export function taskDirectory(workspaceData: string, taskId: string): string {
232
+ return join(workspaceData, 'bounded-exec', encodeURIComponent(taskId));
233
+ }
234
+
235
+ export const VERDICT_FILE = 'verdict.json';
236
+ export const JUNIT_FILE = 'report.xml';
237
+ const NEXTEST_REPORT_CONFIG_FILE = 'nextest-report.toml';
238
+
239
+ /**
240
+ * `bun test`, or nextest's `nextest run` under any cargo spelling, as one shell word sequence.
241
+ * Global, for `match` and `replace`; `search` ignores the flag where only presence matters.
242
+ *
243
+ * `bun` is any unquoted command word whose basename is `bun`, so a runtime pinned by path
244
+ * (`../bun-runtime/.runtime/bun test`) is the runner too. Capture group 1 is that word, which
245
+ * a rewrite must keep: it is the binary the target chose. An assignment (`BUN_EXE=../x/bun test`
246
+ * runs the command `test`) and a longer basename (`debug-bun test`) are not it.
247
+ */
248
+ export const BUN_TEST = /(?<=^|[\s;&|()])((?:[^\s;&|()<>'"`\\=]*\/)?bun)\s+test(?=\s|$)/g;
249
+ export const NEXTEST_RUN = /(?<=^|[\s;&|()-])nextest\s+run(?=\s|$)/g;
250
+
251
+ /**
252
+ * `command` with its test runner asked to write a JUnit report into `directory`, the report
253
+ * `judgeRun` reads. Both runners are recognised by their invocation, so every target that runs
254
+ * one gets a report without restating it: `bun test` takes the path as flags, and nextest takes
255
+ * it only from configuration, so it gets a one-key tool config written beside the report.
256
+ *
257
+ * A command that runs no runner, or more than one (two runs would overwrite one report), or
258
+ * that already chose bun's reporter, is returned unchanged and judged by its exit alone.
259
+ */
260
+ export async function withJunitReport(command: string, directory: string): Promise<string> {
261
+ const bun = command.match(BUN_TEST)?.length ?? 0;
262
+ const nextest = command.match(NEXTEST_RUN)?.length ?? 0;
263
+ if (bun + nextest !== 1) {
264
+ return command;
265
+ }
266
+ const report = join(directory, JUNIT_FILE);
267
+ if (bun === 1) {
268
+ return /(^|\s)--reporter(=|\s|$)/.test(command)
269
+ ? command
270
+ : command.replace(
271
+ BUN_TEST,
272
+ (_match, runtime: string) => `${runtime} test --reporter=junit --reporter-outfile=${shellQuote(report)}`,
273
+ );
274
+ }
275
+ const config = join(directory, NEXTEST_REPORT_CONFIG_FILE);
276
+ await writeFile(config, `[profile.default.junit]\npath = ${JSON.stringify(report)}\n`);
277
+ return command.replace(NEXTEST_RUN, () => `nextest run --tool-config-file ${shellQuote(`smoo-report:${config}`)}`);
278
+ }
279
+
280
+ function shellQuote(value: string): string {
281
+ return `'${value.replaceAll("'", "'\\''")}'`;
282
+ }
283
+
284
+ /** Remove a previous run's verdict and report, so neither can be read as this run's. */
285
+ export async function clearTaskDirectory(directory: string): Promise<void> {
286
+ await mkdir(directory, { recursive: true });
287
+ await Promise.all([
288
+ rm(join(directory, VERDICT_FILE), { force: true }),
289
+ rm(join(directory, JUNIT_FILE), { force: true }),
290
+ ]);
291
+ }
292
+
293
+ export async function writeRecord(directory: string, record: BoundedExecRecord): Promise<void> {
294
+ const target = join(directory, VERDICT_FILE);
295
+ const staged = `${target}.${process.pid}`;
296
+ await writeFile(staged, `${JSON.stringify(record, null, 2)}\n`);
297
+ await rename(staged, target);
298
+ }
299
+
300
+ /** The record in `directory`, or `null` when there is none. A malformed record throws. */
301
+ export async function readRecord(directory: string): Promise<BoundedExecRecord | null> {
302
+ let text: string;
303
+ try {
304
+ text = await readFile(join(directory, VERDICT_FILE), 'utf8');
305
+ } catch (error) {
306
+ if (isNotFound(error)) {
307
+ return null;
308
+ }
309
+ throw error;
310
+ }
311
+ return parseRecord(JSON.parse(text));
312
+ }
313
+
314
+ /** The JUnit report a command wrote into `directory`, or `null` when it wrote none. */
315
+ export async function readJunitReport(directory: string): Promise<JunitFailures | null> {
316
+ try {
317
+ return junitFailures(await readFile(join(directory, JUNIT_FILE), 'utf8'));
318
+ } catch (error) {
319
+ if (isNotFound(error)) {
320
+ return null;
321
+ }
322
+ throw error;
323
+ }
324
+ }
325
+
326
+ function isNotFound(error: unknown): boolean {
327
+ return typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT';
328
+ }
329
+
330
+ function parseRecord(value: unknown): BoundedExecRecord {
331
+ if (!isObject(value) || typeof value.task !== 'string' || !(typeof value.hash === 'string' || value.hash === null)) {
332
+ throw new Error(`not a bounded-exec record: ${JSON.stringify(value)}`);
333
+ }
334
+ return { task: value.task, hash: value.hash, verdict: parseVerdict(value.verdict) };
335
+ }
336
+
337
+ function parseVerdict(value: unknown): BoundedExecVerdict {
338
+ if (isObject(value)) {
339
+ switch (value.outcome) {
340
+ case 'passed':
341
+ return { outcome: 'passed' };
342
+ case 'bound':
343
+ if (value.bound === 'total' && typeof value.limitMs === 'number' && typeof value.elapsedMs === 'number') {
344
+ return { outcome: 'bound', bound: 'total', limitMs: value.limitMs, elapsedMs: value.elapsedMs };
345
+ }
346
+ if (value.bound === 'test' && isStrings(value.tests)) {
347
+ return { outcome: 'bound', bound: 'test', tests: value.tests };
348
+ }
349
+ break;
350
+ case 'wedged':
351
+ if (typeof value.idleMs === 'number' && typeof value.elapsedMs === 'number' && isStrings(value.tests)) {
352
+ return { outcome: 'wedged', idleMs: value.idleMs, elapsedMs: value.elapsedMs, tests: value.tests };
353
+ }
354
+ break;
355
+ case 'failed':
356
+ if (typeof value.exitCode === 'number' && isStrings(value.tests)) {
357
+ return { outcome: 'failed', exitCode: value.exitCode, tests: value.tests };
358
+ }
359
+ break;
360
+ }
361
+ }
362
+ throw new Error(`not a bounded-exec verdict: ${JSON.stringify(value)}`);
363
+ }
364
+
365
+ function isObject(value: unknown): value is Record<string, unknown> {
366
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
367
+ }
368
+
369
+ function isStrings(value: unknown): value is string[] {
370
+ return Array.isArray(value) && value.every((item) => typeof item === 'string');
371
+ }
372
+
373
+ /** A failed task of an Nx run, and whether its bounded-exec record shows only a bound. */
374
+ export type FailedTask =
375
+ | { readonly task: string; readonly bound: true; readonly verdict: Extract<BoundedExecVerdict, { outcome: 'bound' }> }
376
+ | { readonly task: string; readonly bound: false; readonly reason: string };
377
+
378
+ /**
379
+ * Each failed task of the run Nx summarised in `runJson` (its cache directory's `run.json`),
380
+ * judged by the record bounded-exec wrote for exactly that run: same task, same hash. A task
381
+ * with no record, or a record from another hash, is not a bound; nothing is assumed.
382
+ */
383
+ export async function failedTasksOfRun(runJson: unknown, workspaceData: string): Promise<FailedTask[]> {
384
+ if (!isObject(runJson) || !Array.isArray(runJson.tasks)) {
385
+ throw new Error('run.json has no task list');
386
+ }
387
+ const failed: FailedTask[] = [];
388
+ for (const entry of runJson.tasks) {
389
+ if (!isObject(entry) || typeof entry.taskId !== 'string' || typeof entry.status !== 'number') {
390
+ throw new Error(`run.json holds a malformed task: ${JSON.stringify(entry)}`);
391
+ }
392
+ if (entry.status === 0) {
393
+ continue;
394
+ }
395
+ const task = entry.taskId;
396
+ const record = await readRecord(taskDirectory(workspaceData, task));
397
+ if (record === null) {
398
+ failed.push({ task, bound: false, reason: 'no bounded-exec verdict' });
399
+ } else if (record.task !== task || record.hash !== entry.hash) {
400
+ failed.push({
401
+ task,
402
+ bound: false,
403
+ reason: `its verdict is from hash ${record.hash}, not this run's ${entry.hash}`,
404
+ });
405
+ } else if (record.verdict.outcome === 'bound') {
406
+ failed.push({ task, bound: true, verdict: record.verdict });
407
+ } else {
408
+ failed.push({ task, bound: false, reason: describeVerdict(record.verdict) });
409
+ }
410
+ }
411
+ return failed;
412
+ }
413
+
414
+ export function describeVerdict(verdict: BoundedExecVerdict): string {
415
+ switch (verdict.outcome) {
416
+ case 'passed':
417
+ return 'passed';
418
+ case 'bound':
419
+ return verdict.bound === 'total'
420
+ ? `outlived its ${verdict.limitMs}ms bound (${verdict.elapsedMs}ms)`
421
+ : `per-test timeout only: ${verdict.tests.join(', ')}`;
422
+ case 'wedged':
423
+ return `wedged: no test finished for ${verdict.idleMs}ms after ${verdict.elapsedMs}ms; ${
424
+ verdict.tests.length > 0
425
+ ? `still running: ${verdict.tests.join(', ')}`
426
+ : 'the runner named no test still running'
427
+ }`;
428
+ case 'failed':
429
+ return verdict.tests.length > 0
430
+ ? `failed: ${verdict.tests.join(', ')}`
431
+ : `exited ${verdict.exitCode} with no report naming a timeout`;
432
+ }
433
+ }
@@ -0,0 +1,36 @@
1
+ import { posix } from 'node:path';
2
+
3
+ import { timingsCoverage, untimedTestFilesReport } from '../../test-timings.js';
4
+ import type { ShardTimingsOptions } from './schema.js';
5
+
6
+ interface ShardTimingsContext {
7
+ root: string;
8
+ projectName?: string;
9
+ }
10
+
11
+ /**
12
+ * Replays Bun's test discovery rules for the suite, running no test, and fails listing each discovered file the
13
+ * `--timings` manifests do not name, with the command that refreshes them.
14
+ */
15
+ export default async function shardTimingsExecutor(
16
+ options: ShardTimingsOptions,
17
+ context: ShardTimingsContext,
18
+ ): Promise<{ success: boolean }> {
19
+ const projectName = context.projectName;
20
+ if (!projectName) {
21
+ throw new Error('@smoothbricks/nx-plugin:shard-timings requires a project context.');
22
+ }
23
+ const result = await timingsCoverage(context.root, options);
24
+ if (!result.ok) {
25
+ console.error(`shard-timings: ${result.error}`);
26
+ return { success: false };
27
+ }
28
+ const { coverage } = result;
29
+ if (coverage.untimed.length > 0) {
30
+ console.error(untimedTestFilesReport(projectName, options.cwd, coverage));
31
+ return { success: false };
32
+ }
33
+ const manifest = posix.join(options.cwd, coverage.manifests[0] ?? '');
34
+ console.log(`shard-timings: ${manifest} names all ${coverage.files.length} test files the shards run`);
35
+ return { success: true };
36
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "version": 2,
4
+ "title": "Shard Timings Executor",
5
+ "description": "Fail when a timings-sharded bun test suite runs a file its --timings manifest does not name.",
6
+ "type": "object",
7
+ "cli": "nx",
8
+ "required": ["cwd", "args"],
9
+ "properties": {
10
+ "cwd": {
11
+ "type": "string",
12
+ "description": "Where the shards run bun test, relative to the workspace root."
13
+ },
14
+ "args": {
15
+ "type": "array",
16
+ "items": { "type": "string" },
17
+ "description": "The bun test arguments every shard shares, without --shard."
18
+ }
19
+ },
20
+ "additionalProperties": false
21
+ }
@@ -0,0 +1,4 @@
1
+ import type { TimingsShardedSuite } from '../../test-timings.js';
2
+
3
+ /** Options of `@smoothbricks/nx-plugin:shard-timings`: the suite whose `--timings` manifests must name every file. */
4
+ export type ShardTimingsOptions = Pick<TimingsShardedSuite, 'cwd' | 'args'>;
@@ -0,0 +1,119 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ const ANSI = new RegExp(String.fromCharCode(27) + '\\[[0-9;]*[A-Za-z]', 'g');
4
+ // Recognized diagnostic sections keep their exact lines, including assertion diffs and stack locations.
5
+ // Unknown formats fall back to their output; the complete log is retained by the caller in either case.
6
+ const DIAGNOSTIC =
7
+ /^(?:\s*(?:error(?:\[[^\]]+\])?:|[\w.]*Error:|thread .*panicked at|assertion .*failed|TIMEOUT\b|FAIL\b|SIG(?:ABRT|SEGV|TERM)\b|bounded-exec:|RAM temp volume:)|\.*Internal error:|.*:\d+(?::\d+)?: (?:error|fatal error)|\s*\d+:\d+\s+error\b)/i;
8
+ const PROGRESS =
9
+ /^\s*(?:\(pass\) |\(skip\) |PASS\s+\[|SKIP\s+\[|Compiling |Checking |Finished |Downloaded |Downloading |\d+ (?:pass|fail|skip)$|Ran \d+ tests?|Command exited with status |\[trace\]|DEBUG |\[NX |Time taken for |bun test v|--shard=)|^\.{3,}/;
10
+ const FAILED_TEST = /^\s*(?:\(fail\)|\u2717\s)/;
11
+
12
+ /** A summary is not a verdict: it selects diagnostic text, never changes it or excuses a failed command. */
13
+ function diagnostics(lines: readonly string[]): string[] {
14
+ const messages = new Set<string>();
15
+ let block: string[] = [];
16
+ const flush = (): void => {
17
+ if (block.length > 0) messages.add(block.join('\n').trimEnd());
18
+ block = [];
19
+ };
20
+ for (const line of lines) {
21
+ if (DIAGNOSTIC.test(line)) {
22
+ flush();
23
+ block.push(line);
24
+ } else if (PROGRESS.test(line)) {
25
+ flush();
26
+ } else if (block.length > 0) {
27
+ block.push(line);
28
+ if (FAILED_TEST.test(line)) flush();
29
+ }
30
+ }
31
+ flush();
32
+ if (messages.size > 0) return [...messages];
33
+ return [
34
+ ...new Set(
35
+ lines
36
+ .filter((line) => !PROGRESS.test(line))
37
+ .join('\n')
38
+ .split(/\n[ \t]*\n/)
39
+ .map((part) => part.replace(/^\n+/, '').trimEnd())
40
+ .filter((part) => part.trim() !== ''),
41
+ ),
42
+ ];
43
+ }
44
+
45
+ /** Nx's final named list, never an earlier task's own nested run. */
46
+ function taskList(lines: readonly string[], header: string): string[] {
47
+ const at = lines.lastIndexOf(header);
48
+ const tasks = new Set<string>();
49
+ for (const line of at < 0 ? [] : lines.slice(at + 1)) {
50
+ const task = /^- (\S+)$/.exec(line)?.[1];
51
+ if (task !== undefined) tasks.add(task);
52
+ else if (line !== '' || tasks.size > 0) break;
53
+ }
54
+ return [...tasks];
55
+ }
56
+
57
+ /** Reporting only: the caller must retain the raw output and propagate the gate's actual exit status. */
58
+ export function summarizeFailures(output: string): string {
59
+ const lines = output
60
+ .replace(ANSI, '')
61
+ .split('\n')
62
+ .map((line) => line.trimEnd());
63
+ const failed = taskList(lines, 'Failed tasks:');
64
+ const stopped = taskList(lines, 'Tasks stopped before they finished:');
65
+ const unfinished = taskList(lines, 'Tasks the run ended without finishing:');
66
+ const bodies = new Map<string, string[]>();
67
+ let body: string[] | undefined;
68
+ for (const line of lines) {
69
+ // Full failed-task logs start with '> nx run'; successful compact lines also end the preceding body.
70
+ const command = /^(?:> |\S\s+)nx run (\S+)/.exec(line)?.[1];
71
+ if (command !== undefined) {
72
+ body = undefined;
73
+ if (line.startsWith('> nx run ')) {
74
+ body = bodies.get(command) ?? [];
75
+ bodies.set(command, body);
76
+ body.push('');
77
+ }
78
+ } else if (/^\s*NX\s|^Failed tasks:|^Tasks (?:not run|stopped|the run ended)/.test(line)) {
79
+ body = undefined;
80
+ } else {
81
+ body?.push(line);
82
+ }
83
+ }
84
+ const sections: string[] = [];
85
+ for (const task of failed) {
86
+ const messages = diagnostics(bodies.get(task) ?? []);
87
+ sections.push(
88
+ 'failed ' +
89
+ task +
90
+ '\n' +
91
+ (messages.length > 0 ? messages.join('\n\n') : 'diagnostic unavailable: this run printed no task output'),
92
+ );
93
+ }
94
+ for (const task of stopped) sections.push('stopped ' + task + ': Nx stopped it before it finished');
95
+ for (const task of unfinished) sections.push('unfinished ' + task + ': the run ended without finishing it');
96
+ if (sections.length === 0) {
97
+ sections.push(
98
+ 'Gate failed without a task-level failure summary:\n' +
99
+ (diagnostics(lines).join('\n\n') || 'diagnostic unavailable: this run printed no output'),
100
+ );
101
+ }
102
+ return sections.join('\n\n') + '\n';
103
+ }
104
+
105
+ /** CLI entry shared by the installed binary and repository host entrypoints; success means reporting succeeded only. */
106
+ export function runFailureSummary(args: readonly string[]): number {
107
+ const path = args[0];
108
+ if (path === undefined) {
109
+ process.stderr.write('usage: smoo-nx-failures OUTPUT\n');
110
+ return 64;
111
+ }
112
+ try {
113
+ process.stdout.write(summarizeFailures(readFileSync(path, 'utf8')));
114
+ return 0;
115
+ } catch (error) {
116
+ process.stderr.write('smoo-nx-failures: ' + (error instanceof Error ? error.message : String(error)) + '\n');
117
+ return 1;
118
+ }
119
+ }
@@ -4,9 +4,9 @@ import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
4
4
 
5
5
  import {
6
6
  BOUNDED_TEST_EXECUTOR,
7
+ BOUNDED_TEST_IDLE_TIMEOUT_MS,
7
8
  BOUNDED_TEST_KILL_AFTER_MS,
8
9
  BOUNDED_TEST_PER_TEST_TIMEOUT_MS,
9
- BOUNDED_TEST_TIMEOUT_MS,
10
10
  } from '../../bounded-test-policy.js';
11
11
 
12
12
  const TIMEOUT_FLAG = `--timeout=${BOUNDED_TEST_PER_TEST_TIMEOUT_MS}`;
@@ -47,7 +47,7 @@ describe('bounded-test-targets generator', () => {
47
47
  options: {
48
48
  command: `bun test ${TIMEOUT_FLAG} --target`,
49
49
  cwd: '{projectRoot}',
50
- timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
50
+ idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
51
51
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
52
52
  },
53
53
  });
@@ -70,7 +70,7 @@ describe('bounded-test-targets generator', () => {
70
70
  options: {
71
71
  command: `bun test ${TIMEOUT_FLAG} --script`,
72
72
  cwd: '{projectRoot}',
73
- timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
73
+ idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
74
74
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
75
75
  },
76
76
  });
@@ -116,7 +116,7 @@ describe('bounded-test-targets generator', () => {
116
116
  options: {
117
117
  command: `bun test ${TIMEOUT_FLAG} --project-target`,
118
118
  cwd: '{projectRoot}',
119
- timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
119
+ idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
120
120
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
121
121
  },
122
122
  });
@@ -3,9 +3,9 @@ import { addProjectConfiguration, readJson, type Tree } from 'nx/src/devkit-expo
3
3
  import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
4
4
 
5
5
  import {
6
+ BOUNDED_TEST_IDLE_TIMEOUT_MS,
6
7
  BOUNDED_TEST_KILL_AFTER_MS,
7
8
  BOUNDED_TEST_PER_TEST_TIMEOUT_MS,
8
- BOUNDED_TEST_TIMEOUT_MS,
9
9
  } from '../../bounded-test-policy.js';
10
10
  import generator from './generator.js';
11
11
 
@@ -79,7 +79,7 @@ describe('bun-test-tracing generator', () => {
79
79
  options: {
80
80
  command: `bun test --timeout=${BOUNDED_TEST_PER_TEST_TIMEOUT_MS}`,
81
81
  cwd: '{projectRoot}',
82
- timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
82
+ idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
83
83
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
84
84
  },
85
85
  });