@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,308 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { chmod, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { FsTree, flushChanges } from 'nx/src/generators/tree.js';
7
+ import typia from 'typia';
8
+ import { applyWorkspaceBoundedTestTargetPolicy } from '../bounded-test-policy.js';
9
+ import { managedAssetsRoot } from '../managed-assets.js';
10
+ import { applyPackageTargetPolicy } from '../package-target-policy.js';
11
+ import { applyReleaseConfigPolicy } from '../release-config-policy.js';
12
+ import { renderTypecheckTestFiles } from '../typecheck-test-policy.js';
13
+ import { applyWorkspaceConfigPolicy } from '../workspace-config-policy.js';
14
+ import { biomeHookArguments, formatJsonWithBiome, jsonFileText, writeJsonFile } from './managed-format.js';
15
+ import { inspectManagedPaths } from './paths.js';
16
+ import { assertNoManagedConflicts, stageManagedFiles } from './tree.js';
17
+
18
+ /** What a consumer's repository formats JSON as: the shape this repository's own biome.json declares. */
19
+ const SPACED_BIOME_CONFIG = {
20
+ formatter: { enabled: true, indentStyle: 'space', indentWidth: 2, lineWidth: 120, lineEnding: 'lf' },
21
+ };
22
+
23
+ async function makeRepo(config: object = SPACED_BIOME_CONFIG): Promise<string> {
24
+ const root = await mkdtemp(join(tmpdir(), 'smoo-managed-json-'));
25
+ await writeFile(join(root, 'biome.json'), `${JSON.stringify(config)}\n`);
26
+ return root;
27
+ }
28
+
29
+ async function writeSourceJson(path: string, value: unknown): Promise<void> {
30
+ await mkdir(dirname(path), { recursive: true });
31
+ await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
32
+ }
33
+
34
+ /**
35
+ * The exact command `.git-format-staged.yml` runs on commit for a `*.json` file,
36
+ * read from the managed config and run as a subprocess, so the oracle is the
37
+ * commit hook itself rather than a second call into the code under test.
38
+ */
39
+ async function hookCommand(): Promise<string> {
40
+ const config = typia.assert<{ formatters: { biome: { command: string } } }>(
41
+ Bun.YAML.parse(await readFile(join(managedAssetsRoot, 'raw', 'git-format-staged.yml'), 'utf8')),
42
+ );
43
+ return config.formatters.biome.command;
44
+ }
45
+
46
+ async function hookOutput(root: string, path: string, text: string): Promise<string> {
47
+ const command = (await hookCommand()).replaceAll('{}', path);
48
+ const child = spawnSync('sh', ['-c', command], { cwd: root, input: text, encoding: 'utf8' });
49
+ expect(child.status).toBe(0);
50
+ return child.stdout;
51
+ }
52
+
53
+ async function theHookWouldRewrite(root: string, path: string): Promise<boolean> {
54
+ const text = await readFile(join(root, path), 'utf8');
55
+ return (await hookOutput(root, path, text)) !== text;
56
+ }
57
+
58
+ describe('JSON that smoo writes into a managed repository', () => {
59
+ it('keeps a short array on one line, the way the commit hook leaves it', async () => {
60
+ const root = await makeRepo();
61
+ try {
62
+ const text = jsonFileText(join(root, 'tsconfig.test.json'), { compilerOptions: { types: ['bun'] } });
63
+
64
+ expect(text).toBe('{\n "compilerOptions": {\n "types": ["bun"]\n }\n}\n');
65
+ } finally {
66
+ await rm(root, { recursive: true, force: true });
67
+ }
68
+ });
69
+
70
+ it('is a fixed point of the commit hook', async () => {
71
+ const root = await makeRepo();
72
+ try {
73
+ const value = {
74
+ extends: '../tsconfig.base.json',
75
+ compilerOptions: { types: ['bun'], lib: ['es2024', 'dom'] },
76
+ include: ['src/**/*.test.ts', 'src/**/*.spec.ts', 'src/**/__tests__/**/*.ts', 'src/**/__tests__/**/*.tsx'],
77
+ references: [{ path: '../packages/cli/tsconfig.lib.json' }],
78
+ };
79
+ const text = jsonFileText(join(root, 'tooling/tsconfig.test.json'), value);
80
+
81
+ expect(await hookOutput(root, 'tooling/tsconfig.test.json', text)).toBe(text);
82
+ expect(JSON.parse(text)).toEqual(value);
83
+ } finally {
84
+ await rm(root, { recursive: true, force: true });
85
+ }
86
+ });
87
+
88
+ it("obeys the consumer's own Biome configuration", async () => {
89
+ const root = await makeRepo({ formatter: { indentStyle: 'tab', lineWidth: 20 } });
90
+ try {
91
+ const text = jsonFileText(join(root, 'package.json'), { files: ['dist', 'src', 'README.md'] });
92
+
93
+ expect(text).toBe('{\n\t"files": [\n\t\t"dist",\n\t\t"src",\n\t\t"README.md"\n\t]\n}\n');
94
+ } finally {
95
+ await rm(root, { recursive: true, force: true });
96
+ }
97
+ });
98
+
99
+ it('formats a file whose directory does not exist yet', async () => {
100
+ const root = await makeRepo();
101
+ try {
102
+ const text = jsonFileText(join(root, 'packages/new/deep/tsconfig.json'), { include: ['src'] });
103
+
104
+ expect(text).toBe('{\n "include": ["src"]\n}\n');
105
+ } finally {
106
+ await rm(root, { recursive: true, force: true });
107
+ }
108
+ });
109
+
110
+ it('writes the formatted bytes to the file', async () => {
111
+ const root = await makeRepo();
112
+ try {
113
+ writeJsonFile(join(root, 'nx.json'), { plugins: ['@smoothbricks/nx-plugin'] });
114
+
115
+ expect(await readFile(join(root, 'nx.json'), 'utf8')).toBe('{\n "plugins": ["@smoothbricks/nx-plugin"]\n}\n');
116
+ expect(await theHookWouldRewrite(root, 'nx.json')).toBe(false);
117
+ } finally {
118
+ await rm(root, { recursive: true, force: true });
119
+ }
120
+ });
121
+
122
+ it('runs the command the managed commit hook runs', async () => {
123
+ expect(`biome ${biomeHookArguments('{}').join(' ')}`).toBe((await hookCommand()).replaceAll("'", ''));
124
+ });
125
+
126
+ it('refuses to write what a Biome that rejects the repository configuration returned', async () => {
127
+ const root = await makeRepo({ formatter: { lineWidth: 'wide' } });
128
+ try {
129
+ expect(() => jsonFileText(join(root, 'package.json'), { name: 'x' })).toThrow(/lineWidth/);
130
+ } finally {
131
+ await rm(root, { recursive: true, force: true });
132
+ }
133
+ });
134
+
135
+ it('passes the text through where no Biome is installed: that tree has no hook output to agree with', async () => {
136
+ const root = await makeRepo();
137
+ const path = process.env.PATH;
138
+ try {
139
+ process.env.PATH = '';
140
+ const text = '{"a":[1]}\n';
141
+
142
+ expect(formatJsonWithBiome(join(root, 'a.json'), text)).toBe(text);
143
+ } finally {
144
+ if (path === undefined) delete process.env.PATH;
145
+ else process.env.PATH = path;
146
+ await rm(root, { recursive: true, force: true });
147
+ }
148
+ });
149
+ });
150
+
151
+ describe('every update step that rewrites a JSON file leaves it as the commit hook would', () => {
152
+ it('nx.json through the workspace config policy', async () => {
153
+ const root = await makeRepo();
154
+ try {
155
+ await writeSourceJson(join(root, 'nx.json'), {
156
+ plugins: [],
157
+ targetDefaults: { build: { cache: false, dependsOn: ['^build'] } },
158
+ namedInputs: { default: ['{projectRoot}/**/*'] },
159
+ });
160
+
161
+ expect(applyWorkspaceConfigPolicy(root)).toBe(true);
162
+ expect(await theHookWouldRewrite(root, 'nx.json')).toBe(false);
163
+ } finally {
164
+ await rm(root, { recursive: true, force: true });
165
+ }
166
+ });
167
+
168
+ it('nx.json through the release config policy', async () => {
169
+ const root = await makeRepo();
170
+ try {
171
+ await writeSourceJson(join(root, 'nx.json'), { namedInputs: { default: ['{projectRoot}/**/*'] } });
172
+
173
+ expect(applyReleaseConfigPolicy(root)).toBe(true);
174
+ expect(await theHookWouldRewrite(root, 'nx.json')).toBe(false);
175
+ } finally {
176
+ await rm(root, { recursive: true, force: true });
177
+ }
178
+ });
179
+
180
+ it('package.json through the package target policy', async () => {
181
+ const root = await makeRepo();
182
+ try {
183
+ await writeSourceJson(join(root, 'package.json'), {
184
+ name: '@scope/root',
185
+ private: true,
186
+ workspaces: ['packages/*'],
187
+ });
188
+ await writeSourceJson(join(root, 'packages/lib/package.json'), {
189
+ name: '@scope/lib',
190
+ files: ['dist'],
191
+ scripts: { 'build:ts': 'nx run lib:build:ts' },
192
+ nx: {
193
+ name: 'lib',
194
+ targets: {
195
+ 'build:ts': {
196
+ executor: 'nx:run-commands',
197
+ options: { command: 'tsc --build tsconfig.lib.json', cwd: '{projectRoot}' },
198
+ },
199
+ build: { executor: 'nx:noop', dependsOn: ['^build', 'build:ts'] },
200
+ },
201
+ },
202
+ });
203
+
204
+ expect(applyPackageTargetPolicy(root)).toBe(true);
205
+ expect(await theHookWouldRewrite(root, 'packages/lib/package.json')).toBe(false);
206
+ } finally {
207
+ await rm(root, { recursive: true, force: true });
208
+ }
209
+ });
210
+
211
+ it('package.json through the bounded test target policy', async () => {
212
+ const root = await makeRepo();
213
+ try {
214
+ await writeSourceJson(join(root, 'package.json'), {
215
+ name: '@scope/root',
216
+ private: true,
217
+ workspaces: ['packages/*'],
218
+ });
219
+ await writeSourceJson(join(root, 'packages/app/package.json'), {
220
+ name: '@scope/app',
221
+ files: ['dist'],
222
+ scripts: { test: 'bun test --pass-with-no-tests' },
223
+ nx: { name: 'app' },
224
+ });
225
+
226
+ expect(applyWorkspaceBoundedTestTargetPolicy(root)).toBe(true);
227
+ expect(await theHookWouldRewrite(root, 'packages/app/package.json')).toBe(false);
228
+ } finally {
229
+ await rm(root, { recursive: true, force: true });
230
+ }
231
+ });
232
+ });
233
+
234
+ describe('tsconfig.test.json the managed generator writes', () => {
235
+ it('is what the commit hook would leave, so the workflow commit lints clean without the hook', async () => {
236
+ const root = await makeRepo();
237
+ try {
238
+ await writeSourceJson(join(root, 'package.json'), {
239
+ name: '@scope/root',
240
+ private: true,
241
+ workspaces: ['packages/*'],
242
+ });
243
+ await writeSourceJson(join(root, 'tsconfig.base.json'), { compilerOptions: {} });
244
+ await writeSourceJson(join(root, 'packages/app/package.json'), {
245
+ name: '@scope/app',
246
+ scripts: { test: 'bun test' },
247
+ });
248
+ await mkdir(join(root, 'packages/app/src'), { recursive: true });
249
+ await writeFile(join(root, 'packages/app/src/app.test.ts'), 'export {};\n');
250
+
251
+ const tree = new FsTree(root, false);
252
+ const files = renderTypecheckTestFiles(tree);
253
+ assertNoManagedConflicts(
254
+ stageManagedFiles(
255
+ tree,
256
+ files,
257
+ inspectManagedPaths(
258
+ root,
259
+ files.map((file) => file.target),
260
+ ),
261
+ ),
262
+ );
263
+ flushChanges(root, tree.listChanges());
264
+
265
+ expect(await readFile(join(root, 'packages/app/tsconfig.test.json'), 'utf8')).toContain('"types": ["bun"]');
266
+ expect(await theHookWouldRewrite(root, 'packages/app/tsconfig.test.json')).toBe(false);
267
+ } finally {
268
+ await rm(root, { recursive: true, force: true });
269
+ }
270
+ });
271
+ });
272
+
273
+ describe('the Biome smoo runs', () => {
274
+ async function repoWithBiome(script: string): Promise<string> {
275
+ const root = await makeRepo();
276
+ await mkdir(join(root, 'node_modules/.bin'), { recursive: true });
277
+ await writeFile(join(root, 'node_modules/.bin/biome'), `#!/bin/sh\n${script}\n`);
278
+ await chmod(join(root, 'node_modules/.bin/biome'), 0o755);
279
+ return root;
280
+ }
281
+
282
+ it("is the repository's own, found above the file, before the one on PATH", async () => {
283
+ const root = await repoWithBiome('echo LOCAL');
284
+ try {
285
+ expect(formatJsonWithBiome(join(root, 'packages/app/package.json'), '{}\n')).toBe('LOCAL\n');
286
+ } finally {
287
+ await rm(root, { recursive: true, force: true });
288
+ }
289
+ });
290
+
291
+ it('is an error when it exits non-zero, with what it said', async () => {
292
+ const root = await repoWithBiome('echo broken config >&2; exit 3');
293
+ try {
294
+ expect(() => formatJsonWithBiome(join(root, 'a.json'), '{}\n')).toThrow(/exited 3[\s\S]*broken config/);
295
+ } finally {
296
+ await rm(root, { recursive: true, force: true });
297
+ }
298
+ });
299
+
300
+ it('is an error when it answers nothing to real input, never an empty file', async () => {
301
+ const root = await repoWithBiome('exit 0');
302
+ try {
303
+ expect(() => formatJsonWithBiome(join(root, 'a.json'), '{}\n')).toThrow(/returned no content/);
304
+ } finally {
305
+ await rm(root, { recursive: true, force: true });
306
+ }
307
+ });
308
+ });
@@ -1,4 +1,6 @@
1
- import { join } from 'node:path';
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, writeFileSync } from 'node:fs';
3
+ import { dirname, join, resolve } from 'node:path';
2
4
  import type * as PrettierModule from 'prettier';
3
5
  import type { Options as PrettierOptions } from 'prettier';
4
6
 
@@ -13,7 +15,9 @@ import type { Options as PrettierOptions } from 'prettier';
13
15
  * parser and the content passes through untouched, exactly as
14
16
  * `prettier --ignore-unknown` leaves it in the hook.
15
17
  *
16
- * `managed-format.test.ts` pins this list to that config.
18
+ * `managed-format.test.ts` pins this list to that config. Content in these
19
+ * extensions that a template supplies verbatim passes through here; JSON that
20
+ * smoo synthesizes goes through {@link formatJsonWithBiome} instead.
17
21
  */
18
22
  export const BIOME_OWNED_EXTENSIONS: readonly string[] = [
19
23
  '.js',
@@ -100,3 +104,87 @@ export async function formatManagedContent(root: string, target: string, content
100
104
  throw new Error(`${target}: generated managed content is not valid ${info.inferredParser}`, { cause: error });
101
105
  }
102
106
  }
107
+
108
+ /**
109
+ * The arguments `.git-format-staged.yml` gives Biome for every file it owns,
110
+ * with `stdinFilePath` standing in for the hook's `{}`. A test pins the joined
111
+ * command to that config.
112
+ */
113
+ export function biomeHookArguments(stdinFilePath: string): string[] {
114
+ return ['format', '--files-ignore-unknown=true', '--use-editorconfig=true', `--stdin-file-path=${stdinFilePath}`];
115
+ }
116
+
117
+ /** The missing-Biome diagnostic is one line per process, not one per file written. */
118
+ let missingBiomeReported = false;
119
+
120
+ /**
121
+ * The bytes the commit hook leaves in a JSON file whose content `text` is.
122
+ *
123
+ * `formatManagedContent` passes Biome-owned content through because a template
124
+ * is copied from this package's own, already formatted, sources. JSON that smoo
125
+ * *synthesizes* is different: `JSON.stringify` expands every array that Biome
126
+ * keeps on one line, so a generated `tsconfig.test.json` or a rewritten
127
+ * `nx.json` fails `biome check` until the hook has run. Locally the hook runs on
128
+ * commit; the Managed files workflow commits with no hook, and its pull request
129
+ * arrives red. Running the hook's own Biome command here makes the written bytes
130
+ * a fixed point of it, under the consumer's own `biome.json`.
131
+ *
132
+ * Biome is the repository's, found as the hook finds it: the nearest
133
+ * `node_modules/.bin/biome` above the file, else the one on `PATH`. A tree with
134
+ * no Biome at all (a repository mid-bootstrap, before its first install) has no
135
+ * hook output to agree with, so the text passes through and the first `update`
136
+ * after the install converges. Every other failure is loud: a Biome that
137
+ * rejects the repository's configuration would fail the hook the same way.
138
+ */
139
+ export function formatJsonWithBiome(path: string, text: string): string {
140
+ const absolute = resolve(path);
141
+ const cwd = nearestExistingDirectory(dirname(absolute));
142
+ const child = spawnSync(biomeBinary(cwd), biomeHookArguments(absolute), { cwd, input: text, encoding: 'utf8' });
143
+ if (child.error) {
144
+ if ('code' in child.error && child.error.code === 'ENOENT') {
145
+ if (!missingBiomeReported) {
146
+ missingBiomeReported = true;
147
+ console.warn(
148
+ `${path}: Biome is not installed here, so generated JSON keeps JSON.stringify's formatting; run smoo monorepo update again after the install.`,
149
+ );
150
+ }
151
+ return text;
152
+ }
153
+ throw new Error(`${path}: Biome could not be run to format generated JSON`, { cause: child.error });
154
+ }
155
+ if (child.status !== 0) {
156
+ throw new Error(
157
+ `${path}: Biome exited ${child.status ?? `on signal ${child.signal}`}, so generated JSON cannot be written in the bytes the commit hook would leave:\n${child.stderr}`,
158
+ );
159
+ }
160
+ // Biome echoes what it cannot format, so an empty answer to real input is a fault, never a result.
161
+ if (child.stdout === '' && text !== '') {
162
+ throw new Error(`${path}: Biome returned no content for generated JSON:\n${child.stderr}`);
163
+ }
164
+ return child.stdout;
165
+ }
166
+
167
+ /** `JSON.stringify` of `value`, in the bytes the commit hook leaves. */
168
+ export function jsonFileText(path: string, value: unknown): string {
169
+ return formatJsonWithBiome(path, `${JSON.stringify(value, null, 2)}\n`);
170
+ }
171
+
172
+ /** The one writer for JSON files `smoo monorepo update` rewrites in place. */
173
+ export function writeJsonFile(path: string, value: unknown): void {
174
+ writeFileSync(path, jsonFileText(path, value));
175
+ }
176
+
177
+ /** The directory a file about to be created would sit in, as far up as exists: spawning needs a real `cwd`. */
178
+ function nearestExistingDirectory(directory: string): string {
179
+ let current = directory;
180
+ while (!existsSync(current)) current = dirname(current);
181
+ return current;
182
+ }
183
+
184
+ function biomeBinary(directory: string): string {
185
+ for (let current = directory; ; current = dirname(current)) {
186
+ const local = join(current, 'node_modules', '.bin', 'biome');
187
+ if (existsSync(local)) return local;
188
+ if (dirname(current) === current) return 'biome';
189
+ }
190
+ }
@@ -13,6 +13,7 @@ import {
13
13
  cargoCredentialStepLines,
14
14
  cloudflareCredentialEnvLines,
15
15
  environmentLine,
16
+ githubActionPins,
16
17
  privateNpmReadTokenJobEnv,
17
18
  sourceCheckoutsStepLines,
18
19
  } from './ci-workflow.js';
@@ -86,17 +87,82 @@ ${environmentLine(options.environments?.staging)} defaults:
86
87
  working-directory: tooling/direnv
87
88
  ${setupJobEnv(options)} steps:
88
89
  - name: Checkout
89
- uses: actions/checkout@v6.0.2
90
+ uses: ${githubActionPins.checkout.ref} # ${githubActionPins.checkout.version}
90
91
  with:
91
- filter: blob:none
92
92
  fetch-depth: 1
93
+ persist-credentials: false
93
94
  ${preflightSteps(options)}
94
95
  - name: Setup Nix/devenv
95
96
  uses: ./.github/actions/setup-devenv
96
97
 
98
+ # A transient Cloudflare or network failure retries here; one that outlasts
99
+ # the retries is collected by the scheduled PR Stage Sweep, because
100
+ # cleanup-pr keeps the records of a cleanup that stopped.
97
101
  - name: Cleanup PR environment
98
102
  ${cloudflareCredentialEnvLines(options.deploySecrets).join('\n')}
99
- run: smoo wrangler cleanup-pr --pr \${{ github.event.pull_request.number }}
103
+ run: |
104
+ for attempt in 1 2 3; do
105
+ smoo wrangler cleanup-pr --pr \${{ github.event.pull_request.number }} && exit 0
106
+ echo "::warning::cleanup attempt $attempt failed"
107
+ if [ "$attempt" -lt 3 ]; then sleep $((attempt * 30)); fi
108
+ done
109
+ echo "::error::cleanup failed 3 times; the scheduled PR Stage Sweep retries it"
110
+ exit 1
111
+ `;
112
+ }
113
+
114
+ /**
115
+ * The safety net behind the close-time cleanup: every 6 hours, and by hand, it collects the stage of
116
+ * every closed pull request that still holds records, and fails (red run, job summary) when the
117
+ * account nears Cloudflare's 500 Durable Object namespace limit. A hand run may name one pull
118
+ * request; it is collected only if closed, exactly as the sweep decides.
119
+ */
120
+ export function renderPrStageSweepWorkflowYaml(options: PrPreviewCleanupWorkflowOptions = {}): string {
121
+ return `name: PR Stage Sweep
122
+
123
+ on:
124
+ schedule:
125
+ - cron: '17 */6 * * *'
126
+ workflow_dispatch:
127
+ inputs:
128
+ pr:
129
+ description: One pull request number to collect if closed; empty sweeps every closed pull request
130
+ required: false
131
+ type: string
132
+
133
+ permissions:
134
+ contents: read
135
+ pull-requests: read
136
+
137
+ # One sweep at a time; a hand run waits for a scheduled one instead of racing it.
138
+ concurrency:
139
+ group: pr-stage-sweep
140
+ cancel-in-progress: false
141
+
142
+ jobs:
143
+ sweep:
144
+ name: Sweep closed PR stages
145
+ ${renderRunsOnLine(options.runsOn)}
146
+ timeout-minutes: 60
147
+ ${environmentLine(options.environments?.staging)} defaults:
148
+ run:
149
+ working-directory: tooling/direnv
150
+ ${setupJobEnv(options)} steps:
151
+ - name: Checkout
152
+ uses: ${githubActionPins.checkout.ref} # ${githubActionPins.checkout.version}
153
+ with:
154
+ filter: blob:none
155
+ fetch-depth: 1
156
+ persist-credentials: false
157
+ ${preflightSteps(options)}
158
+ - name: Setup Nix/devenv
159
+ uses: ./.github/actions/setup-devenv
160
+
161
+ - name: Sweep closed PR stages
162
+ ${cloudflareCredentialEnvLines(options.deploySecrets).join('\n')}
163
+ GH_TOKEN: \${{ github.token }}
164
+ PR: \${{ inputs.pr }}
165
+ run: smoo wrangler sweep-pr-stages \${PR:+--pr "$PR"}
100
166
  `;
101
167
  }
102
168