@smoothbricks/nx-plugin 0.5.7 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (446) hide show
  1. package/README.md +1097 -360
  2. package/dist/.build-inputs.json +141 -0
  3. package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
  4. package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
  6. package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
  7. package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
  9. package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
  10. package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-nextest-timings.js +28 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +14 -15
  15. package/dist/build-state-output-policy.d.ts +95 -1
  16. package/dist/build-state-output-policy.d.ts.map +1 -1
  17. package/dist/build-state-output-policy.js +368 -30
  18. package/dist/bun-lock-scope.d.ts +44 -0
  19. package/dist/bun-lock-scope.d.ts.map +1 -0
  20. package/dist/bun-lock-scope.js +97 -0
  21. package/dist/cargo-build-script-env.d.ts +49 -0
  22. package/dist/cargo-build-script-env.d.ts.map +1 -0
  23. package/dist/cargo-build-script-env.js +324 -0
  24. package/dist/cargo-closure-input.d.ts +31 -4
  25. package/dist/cargo-closure-input.d.ts.map +1 -1
  26. package/dist/cargo-closure-input.js +66 -6
  27. package/dist/cargo-retention-hook.d.ts +17 -0
  28. package/dist/cargo-retention-hook.d.ts.map +1 -0
  29. package/dist/cargo-retention-hook.js +85 -0
  30. package/dist/cargo-source-hash.d.ts +25 -7
  31. package/dist/cargo-source-hash.d.ts.map +1 -1
  32. package/dist/cargo-source-hash.js +108 -43
  33. package/dist/cargo-toolchain-paths.d.ts +40 -0
  34. package/dist/cargo-toolchain-paths.d.ts.map +1 -0
  35. package/dist/cargo-toolchain-paths.js +84 -0
  36. package/dist/cargo-toolchain-policy.d.ts +25 -8
  37. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  38. package/dist/cargo-toolchain-policy.js +39 -5
  39. package/dist/cargo-workspace.d.ts +10 -4
  40. package/dist/cargo-workspace.d.ts.map +1 -1
  41. package/dist/cargo-workspace.js +65 -95
  42. package/dist/cross-check-policy.d.ts +9 -9
  43. package/dist/cross-check-policy.d.ts.map +1 -1
  44. package/dist/cross-check-policy.js +11 -11
  45. package/dist/disk-command-policy.d.ts.map +1 -1
  46. package/dist/disk-command-policy.js +1 -0
  47. package/dist/ensure-built-receipt.d.ts +22 -5
  48. package/dist/ensure-built-receipt.d.ts.map +1 -1
  49. package/dist/ensure-built-receipt.js +168 -48
  50. package/dist/ensure-built-witness.d.ts +27 -8
  51. package/dist/ensure-built-witness.d.ts.map +1 -1
  52. package/dist/ensure-built-witness.js +45 -15
  53. package/dist/ensure-built.d.ts.map +1 -1
  54. package/dist/ensure-built.js +9 -1
  55. package/dist/eslint-config-closure.d.ts +7 -0
  56. package/dist/eslint-config-closure.d.ts.map +1 -0
  57. package/dist/eslint-config-closure.js +346 -0
  58. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  59. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  60. package/dist/executors/bounded-exec/bounds.js +43 -0
  61. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +28 -0
  62. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -0
  63. package/dist/executors/bounded-exec/cpu-pool-thread.js +20 -0
  64. package/dist/executors/bounded-exec/cpu-pool.d.ts +35 -38
  65. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  66. package/dist/executors/bounded-exec/cpu-pool.js +56 -120
  67. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  68. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/executor.js +389 -239
  70. package/dist/executors/bounded-exec/gateway-lease.d.ts +23 -19
  71. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/gateway-lease.js +102 -29
  73. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  74. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  75. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  76. package/dist/executors/bounded-exec/lease-wait.d.ts +64 -0
  77. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  78. package/dist/executors/bounded-exec/lease-wait.js +72 -0
  79. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  80. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  82. package/dist/executors/bounded-exec/mbx-pool.d.ts +31 -0
  83. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -0
  84. package/dist/executors/bounded-exec/mbx-pool.js +24 -0
  85. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  86. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  88. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  89. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  90. package/dist/executors/bounded-exec/progress.js +5 -2
  91. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  92. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  93. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  94. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  95. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  96. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  97. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  98. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  100. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  101. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  102. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  103. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +10 -4
  104. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  105. package/dist/executors/bounded-exec/run-cpu-pool.js +122 -35
  106. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  107. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  108. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  109. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  110. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  111. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  112. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  113. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  114. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  115. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  116. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  117. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  118. package/dist/executors/bounded-exec/verdict.d.ts +48 -11
  119. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  120. package/dist/executors/bounded-exec/verdict.js +89 -20
  121. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  122. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  123. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  124. package/dist/executors/clean-outputs/executor.js +1 -0
  125. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  126. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/executor.js +367 -0
  128. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  129. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  130. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  131. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  132. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  133. package/dist/executors/scriptc-native/schema.js +1 -0
  134. package/dist/executors/typescript-emit/emit-overrides.d.ts +14 -0
  135. package/dist/executors/typescript-emit/emit-overrides.d.ts.map +1 -0
  136. package/dist/executors/typescript-emit/emit-overrides.js +24 -0
  137. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  138. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  139. package/dist/executors/typescript-emit/executor.js +146 -33
  140. package/dist/forbidden-spelling-policy.d.ts +56 -0
  141. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  142. package/dist/forbidden-spelling-policy.js +176 -0
  143. package/dist/generators/create-package/generator.d.ts.map +1 -1
  144. package/dist/generators/create-package/generator.js +3 -4
  145. package/dist/graph-input-contract.d.ts +14 -0
  146. package/dist/graph-input-contract.d.ts.map +1 -1
  147. package/dist/graph-input-contract.js +67 -2
  148. package/dist/index.d.ts +23 -6
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +672 -214
  151. package/dist/managed-assets.d.ts +2 -0
  152. package/dist/managed-assets.d.ts.map +1 -1
  153. package/dist/managed-files/files.d.ts +3 -3
  154. package/dist/managed-files/files.d.ts.map +1 -1
  155. package/dist/managed-files/files.js +28 -3
  156. package/dist/managed-files/managed-format.d.ts.map +1 -1
  157. package/dist/managed-files/managed-format.js +1 -0
  158. package/dist/managed-files/publish-workflow.js +14 -11
  159. package/dist/nextest-code-bound.js +1 -0
  160. package/dist/nextest-timings.d.ts +35 -0
  161. package/dist/nextest-timings.d.ts.map +1 -0
  162. package/dist/nextest-timings.js +168 -0
  163. package/dist/owned-installation.d.ts +6 -5
  164. package/dist/owned-installation.d.ts.map +1 -1
  165. package/dist/owned-installation.js +150 -26
  166. package/dist/package-target-policy.d.ts.map +1 -1
  167. package/dist/package-target-policy.js +2 -3
  168. package/dist/process-children.d.ts +7 -0
  169. package/dist/process-children.d.ts.map +1 -0
  170. package/dist/process-children.darwin.d.ts +7 -0
  171. package/dist/process-children.darwin.d.ts.map +1 -0
  172. package/dist/process-children.darwin.js +13 -0
  173. package/dist/process-children.js +14 -0
  174. package/dist/process-children.linux.d.ts +8 -0
  175. package/dist/process-children.linux.d.ts.map +1 -0
  176. package/dist/process-children.linux.js +25 -0
  177. package/dist/process-group.d.ts +108 -0
  178. package/dist/process-group.d.ts.map +1 -0
  179. package/dist/process-group.js +171 -0
  180. package/dist/process-listing.d.ts +7 -0
  181. package/dist/process-listing.d.ts.map +1 -0
  182. package/dist/process-listing.js +51 -0
  183. package/dist/producer-receipts.d.ts +8 -2
  184. package/dist/producer-receipts.d.ts.map +1 -1
  185. package/dist/producer-receipts.js +514 -47
  186. package/dist/task-graph-policy.d.ts +21 -0
  187. package/dist/task-graph-policy.d.ts.map +1 -0
  188. package/dist/task-graph-policy.js +91 -0
  189. package/dist/test-timings.js +4 -4
  190. package/dist/test-walk-policy.d.ts +14 -5
  191. package/dist/test-walk-policy.d.ts.map +1 -1
  192. package/dist/test-walk-policy.js +8 -2
  193. package/dist/testing.d.ts +73 -28
  194. package/dist/testing.d.ts.map +1 -1
  195. package/dist/testing.js +217 -223
  196. package/dist/tool-bins.d.ts +33 -0
  197. package/dist/tool-bins.d.ts.map +1 -0
  198. package/dist/tool-bins.js +72 -0
  199. package/dist/typecheck-test-policy.d.ts.map +1 -1
  200. package/dist/typecheck-test-policy.js +3 -4
  201. package/dist/wait-why-policy.d.ts +28 -0
  202. package/dist/wait-why-policy.d.ts.map +1 -0
  203. package/dist/wait-why-policy.js +223 -0
  204. package/dist/workspace-config-policy.d.ts +14 -8
  205. package/dist/workspace-config-policy.d.ts.map +1 -1
  206. package/dist/workspace-config-policy.js +60 -16
  207. package/dist/workspace-manifest.d.ts +41 -6
  208. package/dist/workspace-manifest.d.ts.map +1 -1
  209. package/dist/workspace-manifest.js +57 -0
  210. package/executors.json +16 -1
  211. package/loader.js +2 -0
  212. package/managed/raw/envrc +11 -0
  213. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  214. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  215. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  216. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  217. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  218. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  219. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  220. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  221. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  222. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  223. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  224. package/managed/raw/tooling/direnv/repo-path +68 -6
  225. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  226. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  227. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  228. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  229. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  230. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  231. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  232. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  233. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  234. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  235. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  236. package/package.json +95 -14
  237. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  238. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  239. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  240. package/src/bounded-test-policy.ts +12 -14
  241. package/src/build-state-output-policy.ts +458 -34
  242. package/src/bun-lock-scope.ts +108 -0
  243. package/src/cargo-build-script-env.ts +265 -0
  244. package/src/cargo-closure-input.ts +74 -7
  245. package/src/cargo-retention-hook.ts +94 -0
  246. package/src/cargo-source-hash.ts +138 -41
  247. package/src/cargo-toolchain-paths.ts +95 -0
  248. package/src/cargo-toolchain-policy.ts +49 -5
  249. package/src/cargo-workspace.ts +72 -123
  250. package/src/cross-check-policy.ts +12 -10
  251. package/src/disk-command-policy.ts +1 -0
  252. package/src/ensure-built-receipt.ts +173 -39
  253. package/src/ensure-built-witness.ts +62 -10
  254. package/src/ensure-built.ts +11 -1
  255. package/src/eslint-config-closure.ts +357 -0
  256. package/src/executors/bounded-exec/bounds.ts +76 -0
  257. package/src/executors/bounded-exec/cpu-pool-thread.ts +43 -0
  258. package/src/executors/bounded-exec/cpu-pool.ts +55 -120
  259. package/src/executors/bounded-exec/executor.ts +442 -260
  260. package/src/executors/bounded-exec/gateway-lease.ts +94 -35
  261. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  262. package/src/executors/bounded-exec/lease-wait.ts +116 -0
  263. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  264. package/src/executors/bounded-exec/mbx-pool.ts +48 -0
  265. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  266. package/src/executors/bounded-exec/progress.ts +9 -3
  267. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  268. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  269. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  270. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  271. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  272. package/src/executors/bounded-exec/run-cpu-pool.ts +129 -35
  273. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  274. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  275. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  276. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  277. package/src/executors/bounded-exec/schema.json +11 -2
  278. package/src/executors/bounded-exec/schema.ts +19 -1
  279. package/src/executors/bounded-exec/verdict.ts +145 -35
  280. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  281. package/src/executors/clean-outputs/executor.ts +1 -0
  282. package/src/executors/scriptc-native/executor.ts +394 -0
  283. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  284. package/src/executors/scriptc-native/schema.json +60 -0
  285. package/src/executors/scriptc-native/schema.ts +34 -0
  286. package/src/executors/typescript-emit/emit-overrides.ts +24 -0
  287. package/src/executors/typescript-emit/executor.ts +186 -38
  288. package/src/forbidden-spelling-policy.ts +226 -0
  289. package/src/generators/create-package/generator.ts +7 -7
  290. package/src/graph-input-contract.ts +61 -2
  291. package/src/index.ts +788 -224
  292. package/src/managed-assets.ts +3 -0
  293. package/src/managed-files/files.ts +28 -3
  294. package/src/managed-files/managed-format.ts +1 -0
  295. package/src/managed-files/publish-workflow.ts +20 -15
  296. package/src/nextest-code-bound.ts +1 -0
  297. package/src/nextest-timings.ts +106 -0
  298. package/src/owned-installation.ts +150 -23
  299. package/src/package-target-policy.ts +2 -3
  300. package/src/process-children.darwin.ts +14 -0
  301. package/src/process-children.linux.ts +33 -0
  302. package/src/process-children.ts +22 -0
  303. package/src/process-group.ts +209 -0
  304. package/src/process-listing.ts +54 -0
  305. package/src/producer-receipts.ts +92 -41
  306. package/src/task-graph-policy.ts +98 -0
  307. package/src/test-walk-policy.ts +23 -8
  308. package/src/testing.ts +240 -232
  309. package/src/tool-bins.ts +108 -0
  310. package/src/typecheck-test-policy.ts +2 -3
  311. package/src/wait-why-policy.ts +226 -0
  312. package/src/workspace-config-policy.ts +63 -15
  313. package/src/workspace-manifest.ts +89 -6
  314. package/test-timings.json +124 -99
  315. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  316. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  317. package/dist/bin/smoo-nx-failures.js +0 -3
  318. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  319. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  320. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  321. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  322. package/dist/failure-summary.d.ts +0 -5
  323. package/dist/failure-summary.d.ts.map +0 -1
  324. package/dist/failure-summary.js +0 -118
  325. package/dist/nextest-extraction.d.ts +0 -117
  326. package/dist/nextest-extraction.d.ts.map +0 -1
  327. package/dist/nextest-extraction.js +0 -303
  328. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  329. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  330. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  331. package/src/__tests__/counted-cargo-process.ts +0 -286
  332. package/src/__tests__/counted-cargo.ts +0 -713
  333. package/src/__tests__/directory-change.ts +0 -27
  334. package/src/__tests__/fixture-cargo-home.ts +0 -36
  335. package/src/__tests__/fixture-nx-env.ts +0 -193
  336. package/src/__tests__/owned-installation.ts +0 -13
  337. package/src/__tests__/past-tick.ts +0 -12
  338. package/src/__tests__/progress-clock.ts +0 -43
  339. package/src/__tests__/runtime-input.ts +0 -23
  340. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  341. package/src/bin/smoo-nx-failures.ts +0 -4
  342. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  343. package/src/bounded-test-policy.test.ts +0 -1029
  344. package/src/build-state-output-policy.test.ts +0 -115
  345. package/src/bun-bootstrap.test.ts +0 -102
  346. package/src/bun-file-packages.test.ts +0 -47
  347. package/src/cargo-closure-filesets.test.ts +0 -63
  348. package/src/cargo-closure-input.property.test.ts +0 -50
  349. package/src/cargo-closure-input.test.ts +0 -506
  350. package/src/cargo-closure-key.test.ts +0 -240
  351. package/src/cargo-resolve-cache.test.ts +0 -1181
  352. package/src/cargo-source-hash.test.ts +0 -707
  353. package/src/cargo-workspace.test.ts +0 -615
  354. package/src/cross-check-policy.test.ts +0 -316
  355. package/src/disk-command-policy.test.ts +0 -61
  356. package/src/ensure-built-receipt.test.ts +0 -279
  357. package/src/ensure-built-witness.test.ts +0 -688
  358. package/src/ensure-built.test.ts +0 -1462
  359. package/src/executors/all-verdicts/executor.test.ts +0 -135
  360. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  361. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  362. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  363. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  364. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  365. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  366. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  367. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  368. package/src/executors/bounded-exec/progress.test.ts +0 -139
  369. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  370. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  371. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  372. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  373. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  374. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  375. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  376. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  377. package/src/executors/clean-outputs/executor.test.ts +0 -20
  378. package/src/executors/typescript-emit/executor.test.ts +0 -83
  379. package/src/failure-summary.ts +0 -119
  380. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  381. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  382. package/src/generators/create-package/generator.test.ts +0 -190
  383. package/src/generators/make-public/generator.test.ts +0 -137
  384. package/src/graph-input-contract.test.ts +0 -379
  385. package/src/host-controller-wiring.test.ts +0 -31
  386. package/src/index.test.ts +0 -3321
  387. package/src/linked-snapshots.nx.test.ts +0 -254
  388. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  389. package/src/managed-files/generator.test.ts +0 -243
  390. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  391. package/src/managed-files/json-edit.test.ts +0 -216
  392. package/src/managed-files/managed-content.test.ts +0 -166
  393. package/src/managed-files/managed-format-json.test.ts +0 -308
  394. package/src/managed-files/repo-path.test.ts +0 -172
  395. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  396. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  397. package/src/managed-files/tree-permissions.test.ts +0 -109
  398. package/src/managed-files/tree.test.ts +0 -123
  399. package/src/manifest-hash.test.ts +0 -219
  400. package/src/nextest-code-bound.test.ts +0 -161
  401. package/src/nextest-extraction.test.ts +0 -216
  402. package/src/nextest-extraction.ts +0 -371
  403. package/src/nextest-partitions.test.ts +0 -501
  404. package/src/nx-cache-bound.test.ts +0 -109
  405. package/src/nx-cache-restore-mtime.test.ts +0 -170
  406. package/src/nx-daemon-claim.test.ts +0 -279
  407. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  408. package/src/nx-daemon-idle-policy.test.ts +0 -111
  409. package/src/nx-daemon-ignore-files.test.ts +0 -210
  410. package/src/nx-daemon-root-normalization.test.ts +0 -105
  411. package/src/nx-daemon-start-never.test.ts +0 -292
  412. package/src/nx-daemon-validity.test.ts +0 -1055
  413. package/src/nx-dot-input-policy.test.ts +0 -353
  414. package/src/nx-failure-life-cycles.test.ts +0 -207
  415. package/src/nx-files-archive-racy.test.ts +0 -97
  416. package/src/nx-foreign-workspace-env.test.ts +0 -329
  417. package/src/nx-incomplete-run-summary.test.ts +0 -70
  418. package/src/nx-plugin-load-errors.test.ts +0 -120
  419. package/src/nx-project-graph-errors.test.ts +0 -70
  420. package/src/nx-project-resolution-cache.test.ts +0 -176
  421. package/src/nx-raw-inputs.test.ts +0 -166
  422. package/src/nx-resident-graph-workers.test.ts +0 -112
  423. package/src/nx-run-information.test.ts +0 -118
  424. package/src/nx-skipped-task-exit.test.ts +0 -180
  425. package/src/nx-state-location.test.ts +0 -63
  426. package/src/nx-store-resolution.test.ts +0 -81
  427. package/src/nx-task-graph-cycles.test.ts +0 -148
  428. package/src/nx-task-output-lease.test.ts +0 -550
  429. package/src/nx-use-local.test.ts +0 -105
  430. package/src/owned-installation.test.ts +0 -105
  431. package/src/package-target-policy.test.ts +0 -1014
  432. package/src/producer-receipts.test.ts +0 -285
  433. package/src/release-config-policy.test.ts +0 -311
  434. package/src/runtime-input.test.ts +0 -393
  435. package/src/serial-group-wiring.test.ts +0 -326
  436. package/src/task-history-namespace.test.ts +0 -181
  437. package/src/task-results.test.ts +0 -228
  438. package/src/test-clock-policy.test.ts +0 -338
  439. package/src/test-program.test.ts +0 -303
  440. package/src/test-timings.test.ts +0 -240
  441. package/src/test-walk-policy.test.ts +0 -620
  442. package/src/testing.test.ts +0 -509
  443. package/src/typecheck-test-policy.test.ts +0 -1468
  444. package/src/typescript-resolution.test.ts +0 -76
  445. package/src/version-actions.test.ts +0 -80
  446. package/src/workspace-config-policy.test.ts +0 -737
@@ -1,1468 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises';
3
- import { tmpdir } from 'node:os';
4
- import { dirname, join } from 'node:path';
5
-
6
- import { addProjectConfiguration, parseJson, readJson, type Tree, writeJson } from 'nx/src/devkit-exports.js';
7
- import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
8
- import { FsTree, flushChanges } from 'nx/src/generators/tree.js';
9
- import { inspectManagedPaths } from './managed-files/paths.js';
10
- import { assertNoManagedConflicts, stageManagedFiles } from './managed-files/tree.js';
11
- import type { TestProgram } from './test-program.js';
12
-
13
- import {
14
- applyTypecheckTestDefaults,
15
- checkTsconfigTestReference,
16
- checkTypecheckTestConfig,
17
- checkTypecheckTestPolicy,
18
- checkTypecheckTestPolicyTree,
19
- detectPackageTestRunners,
20
- removeTsconfigTestReference,
21
- renderTypecheckTestFiles,
22
- } from './typecheck-test-policy.js';
23
-
24
- // ---------------------------------------------------------------------------
25
- // Helpers for filesystem tests
26
- // ---------------------------------------------------------------------------
27
-
28
- async function writeJsonFs(path: string, value: unknown): Promise<void> {
29
- await mkdir(dirname(path), { recursive: true });
30
- await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
31
- }
32
-
33
- function applyTypecheckTestPolicyTree(tree: Tree): boolean {
34
- const results = stageManagedFiles(tree, renderTypecheckTestFiles(tree));
35
- assertNoManagedConflicts(results);
36
- return results.some((result) => result.action === 'created' || result.action === 'updated');
37
- }
38
-
39
- function applyTypecheckTestPolicy(root: string): boolean {
40
- const tree = new FsTree(root, false);
41
- const files = renderTypecheckTestFiles(tree);
42
- const results = stageManagedFiles(
43
- tree,
44
- files,
45
- inspectManagedPaths(
46
- root,
47
- files.map((file) => file.target),
48
- ),
49
- );
50
- assertNoManagedConflicts(results);
51
- const changes = tree.listChanges();
52
- flushChanges(root, changes);
53
- return changes.length > 0;
54
- }
55
-
56
- async function readJsonFs(path: string): Promise<unknown> {
57
- return JSON.parse(await readFile(path, 'utf8'));
58
- }
59
-
60
- // ---------------------------------------------------------------------------
61
- // Layer 1: Pure core function tests
62
- // ---------------------------------------------------------------------------
63
-
64
- describe('detectPackageTestRunners', () => {
65
- it('detects bun from scripts', () => {
66
- const runners = detectPackageTestRunners({ scripts: { test: 'bun test' } });
67
- expect(runners.has('bun')).toBe(true);
68
- expect(runners.size).toBe(1);
69
- });
70
-
71
- it('detects vitest from scripts', () => {
72
- const runners = detectPackageTestRunners({ scripts: { test: 'vitest run' } });
73
- expect(runners.has('vitest')).toBe(true);
74
- expect(runners.size).toBe(1);
75
- });
76
-
77
- it('detects bun from nx targets in package.json', () => {
78
- const runners = detectPackageTestRunners({
79
- nx: { targets: { test: { options: { command: 'bun test --coverage' } } } },
80
- });
81
- expect(runners.has('bun')).toBe(true);
82
- });
83
-
84
- it('detects bun from project targets', () => {
85
- const runners = detectPackageTestRunners({}, { test: { options: { command: 'bun test' } } });
86
- expect(runners.has('bun')).toBe(true);
87
- expect(runners.size).toBe(1);
88
- });
89
-
90
- it('detects vitest from project targets', () => {
91
- const runners = detectPackageTestRunners({}, { test: { options: { command: 'vitest run' } } });
92
- expect(runners.has('vitest')).toBe(true);
93
- });
94
-
95
- it('detects bun behind env prefix', () => {
96
- const runners = detectPackageTestRunners({ scripts: { test: 'NODE_ENV=test bun test' } });
97
- expect(runners.has('bun')).toBe(true);
98
- });
99
-
100
- it('returns empty set for non-test runners', () => {
101
- const runners = detectPackageTestRunners({ scripts: { test: 'node --test' } });
102
- expect(runners.size).toBe(0);
103
- });
104
-
105
- it('returns empty set for no scripts or targets', () => {
106
- const runners = detectPackageTestRunners({});
107
- expect(runners.size).toBe(0);
108
- });
109
-
110
- it('merges runners from scripts and project targets', () => {
111
- const runners = detectPackageTestRunners(
112
- { scripts: { test: 'bun test' } },
113
- { 'test-vitest': { options: { command: 'vitest run' } } },
114
- );
115
- expect(runners.has('bun')).toBe(true);
116
- expect(runners.has('vitest')).toBe(true);
117
- expect(runners.size).toBe(2);
118
- });
119
- });
120
-
121
- describe('checkTypecheckTestConfig', () => {
122
- it('returns no issues for valid config', () => {
123
- const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, composite: false } }, 'packages/app');
124
- expect(issues).toEqual([]);
125
- });
126
-
127
- it('reports missing noEmit', () => {
128
- const issues = checkTypecheckTestConfig({ compilerOptions: { composite: false } }, 'packages/app');
129
- expect(issues.length).toBe(1);
130
- expect(issues[0]?.message).toContain('noEmit must be true');
131
- });
132
-
133
- it('reports composite = true', () => {
134
- const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, composite: true } }, 'packages/app');
135
- expect(issues.length).toBe(1);
136
- expect(issues[0]?.message).toContain('composite');
137
- });
138
-
139
- it('reports declaration = true', () => {
140
- const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, declaration: true } }, 'packages/app');
141
- expect(issues.length).toBe(1);
142
- expect(issues[0]?.message).toContain('declaration = true');
143
- });
144
-
145
- it('reports declarationMap = true', () => {
146
- const issues = checkTypecheckTestConfig(
147
- { compilerOptions: { noEmit: true, declarationMap: true } },
148
- 'packages/app',
149
- );
150
- expect(issues.length).toBe(1);
151
- expect(issues[0]?.message).toContain('declarationMap');
152
- });
153
-
154
- it('reports dist-test outDir', () => {
155
- const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, outDir: 'dist-test' } }, 'packages/app');
156
- expect(issues.length).toBe(1);
157
- expect(issues[0]?.message).toContain('dist-test');
158
- });
159
-
160
- it('reports dist-test tsBuildInfoFile', () => {
161
- const issues = checkTypecheckTestConfig(
162
- { compilerOptions: { noEmit: true, tsBuildInfoFile: 'dist-test/tsconfig.test.tsbuildinfo' } },
163
- 'packages/app',
164
- );
165
- expect(issues.length).toBe(1);
166
- expect(issues[0]?.message).toContain('dist-test');
167
- });
168
-
169
- it('returns empty for null input', () => {
170
- const issues = checkTypecheckTestConfig(null, 'packages/app');
171
- expect(issues).toEqual([]);
172
- });
173
-
174
- it('uses packagePath in issue path', () => {
175
- const issues = checkTypecheckTestConfig({ compilerOptions: {} }, 'packages/mylib');
176
- expect(issues[0]?.path).toContain('packages/mylib');
177
- expect(issues[0]?.path).toContain('tsconfig.test.json');
178
- });
179
- });
180
-
181
- describe('checkTsconfigTestReference', () => {
182
- it('returns no issues when no test reference', () => {
183
- const issues = checkTsconfigTestReference({ references: [{ path: './tsconfig.lib.json' }] }, 'packages/app');
184
- expect(issues).toEqual([]);
185
- });
186
-
187
- it('reports test reference', () => {
188
- const issues = checkTsconfigTestReference(
189
- { references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }] },
190
- 'packages/app',
191
- );
192
- expect(issues.length).toBe(1);
193
- expect(issues[0]?.message).toContain('must not reference ./tsconfig.test.json');
194
- });
195
-
196
- it('returns empty for null input', () => {
197
- const issues = checkTsconfigTestReference(null, 'packages/app');
198
- expect(issues).toEqual([]);
199
- });
200
- });
201
-
202
- describe('applyTypecheckTestDefaults', () => {
203
- const program: TestProgram = { projectRoot: 'packages/app', files: ['src/app.test.ts'], readConfig: () => null };
204
-
205
- it('applies all defaults to empty object', () => {
206
- const tsconfigTest: Record<string, unknown> = {};
207
- const changed = applyTypecheckTestDefaults(tsconfigTest, {
208
- testRunners: new Set(['bun'] as const),
209
- testExtends: '../../tsconfig.base.json',
210
- referencePaths: ['./tsconfig.lib.json'],
211
- program,
212
- isNew: true,
213
- });
214
- expect(changed).toBe(true);
215
- expect(tsconfigTest.extends).toBe('../../tsconfig.base.json');
216
-
217
- const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
218
- expect(compilerOptions.noEmit).toBe(true);
219
- expect(compilerOptions.composite).toBe(false);
220
- expect(compilerOptions.declaration).toBe(false);
221
- expect(compilerOptions.declarationMap).toBe(false);
222
- expect(compilerOptions.emitDeclarationOnly).toBe(false);
223
- expect(compilerOptions.types).toContain('bun');
224
-
225
- const include = expectStringArray(tsconfigTest.include);
226
- expect(include).toContain('src/**/*.test.ts');
227
- expect(include).toContain('src/**/*.spec.ts');
228
-
229
- const references = expectReferences(tsconfigTest.references);
230
- expect(references).toContainEqual({ path: './tsconfig.lib.json' });
231
- });
232
-
233
- it('leaves an inherited include alone: minting one narrows the program to nothing', () => {
234
- // A package keeping its suites in `test/` inherits src + test + tooling
235
- // from its tsconfig.json. Writing `include` with src-test globs replaced
236
- // that with a program of zero files, which passed the gate by compiling
237
- // nothing (the false green the policy exists to prevent).
238
- const declared: Record<string, unknown> = { extends: './tsconfig.json', compilerOptions: { noEmit: true } };
239
- applyTypecheckTestDefaults(declared, {
240
- testRunners: new Set(['bun'] as const),
241
- testExtends: '../../tsconfig.base.json',
242
- referencePaths: [],
243
- program,
244
- });
245
- expect(declared.extends).toBe('./tsconfig.json');
246
- expect(Object.hasOwn(declared, 'include')).toBe(false);
247
- // Same for `types`: declaring it would drop the workers types the program inherits.
248
- expect(Object.hasOwn(expectRecord(declared.compilerOptions), 'types')).toBe(false);
249
-
250
- const explicit: Record<string, unknown> = { extends: './tsconfig.json', include: ['test/**/*.ts'] };
251
- applyTypecheckTestDefaults(explicit, {
252
- testRunners: new Set(['bun'] as const),
253
- testExtends: '../../tsconfig.base.json',
254
- referencePaths: [],
255
- program,
256
- });
257
- expect(expectStringArray(explicit.include)).toEqual(expect.arrayContaining(['test/**/*.ts', 'src/**/*.test.ts']));
258
- });
259
-
260
- it('fills compiler options the test program left out and keeps the ones it declared', () => {
261
- // A Bun-only test program declaring es2023 says something the library cannot
262
- // know: its runtime has change-array-by-copy while the library's output ships
263
- // to node, workerd and browsers. Overwriting it made `toSorted` a type error
264
- // in a suite that calls it, and every `smoo monorepo update` reintroduced it.
265
- const declared: Record<string, unknown> = {
266
- compilerOptions: { lib: ['es2023'], types: ['bun'], noEmit: true },
267
- };
268
- applyTypecheckTestDefaults(declared, {
269
- testRunners: new Set(['bun'] as const),
270
- testExtends: '../../tsconfig.base.json',
271
- referencePaths: [],
272
- program,
273
- libCompilerOptions: { lib: ['es2022'], module: 'preserve' },
274
- });
275
-
276
- const declaredOptions = expectRecord(declared.compilerOptions);
277
- expect(declaredOptions.lib).toEqual(['es2023']);
278
- expect(declaredOptions.module).toBe('preserve');
279
-
280
- const silent: Record<string, unknown> = { compilerOptions: {} };
281
- applyTypecheckTestDefaults(silent, {
282
- testRunners: new Set(['bun'] as const),
283
- testExtends: '../../tsconfig.base.json',
284
- referencePaths: [],
285
- program,
286
- libCompilerOptions: { lib: ['es2022'] },
287
- });
288
- expect(expectRecord(silent.compilerOptions).lib).toEqual(['es2022']);
289
- });
290
-
291
- it('extends what it is given when the file names nothing', () => {
292
- const tsconfigTest: Record<string, unknown> = {};
293
- applyTypecheckTestDefaults(tsconfigTest, {
294
- testRunners: new Set(['bun'] as const),
295
- testExtends: '../tsconfig.custom.json',
296
- referencePaths: [],
297
- program,
298
- });
299
- expect(tsconfigTest.extends).toBe('../tsconfig.custom.json');
300
- });
301
-
302
- it('copies lib compiler options', () => {
303
- const tsconfigTest: Record<string, unknown> = {};
304
- applyTypecheckTestDefaults(tsconfigTest, {
305
- testRunners: new Set(['bun'] as const),
306
- testExtends: '../../tsconfig.base.json',
307
- libCompilerOptions: { baseUrl: '.', module: 'esnext', jsx: 'react-jsx' },
308
- referencePaths: [],
309
- program,
310
- });
311
- const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
312
- expect(compilerOptions.baseUrl).toBe('.');
313
- expect(compilerOptions.module).toBe('esnext');
314
- expect(compilerOptions.jsx).toBe('react-jsx');
315
- });
316
-
317
- it('does not add bun types for vitest-only', () => {
318
- const tsconfigTest: Record<string, unknown> = {};
319
- applyTypecheckTestDefaults(tsconfigTest, {
320
- testRunners: new Set(['vitest'] as const),
321
- testExtends: '../../tsconfig.base.json',
322
- referencePaths: [],
323
- program,
324
- });
325
- const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
326
- expect(compilerOptions.types).toBeUndefined();
327
- });
328
-
329
- it('removes outDir and tsBuildInfoFile', () => {
330
- const tsconfigTest: Record<string, unknown> = {
331
- compilerOptions: { outDir: 'dist-test', tsBuildInfoFile: 'dist-test/tsconfig.tsbuildinfo' },
332
- };
333
- const changed = applyTypecheckTestDefaults(tsconfigTest, {
334
- testRunners: new Set(['bun'] as const),
335
- testExtends: '../../tsconfig.base.json',
336
- referencePaths: [],
337
- program,
338
- });
339
- expect(changed).toBe(true);
340
- const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
341
- expect('outDir' in compilerOptions).toBe(false);
342
- expect('tsBuildInfoFile' in compilerOptions).toBe(false);
343
- });
344
-
345
- it('is idempotent', () => {
346
- const tsconfigTest: Record<string, unknown> = {};
347
- const opts = {
348
- testRunners: new Set(['bun'] as const),
349
- testExtends: '../../tsconfig.base.json',
350
- libCompilerOptions: { lib: ['es2024', 'webworker'] },
351
- referencePaths: ['./tsconfig.lib.json'],
352
- program,
353
- };
354
- applyTypecheckTestDefaults(tsconfigTest, opts);
355
- const secondChanged = applyTypecheckTestDefaults(tsconfigTest, opts);
356
- expect(secondChanged).toBe(false);
357
- });
358
- });
359
-
360
- describe('removeTsconfigTestReference', () => {
361
- it('removes test reference', () => {
362
- const tsconfig: Record<string, unknown> = {
363
- references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }],
364
- };
365
- removeTsconfigTestReference(tsconfig);
366
- expect(tsconfig.references).toEqual([{ path: './tsconfig.lib.json' }]);
367
- });
368
-
369
- it('leaves a document with no test reference as it was', () => {
370
- const tsconfig: Record<string, unknown> = {
371
- references: [{ path: './tsconfig.lib.json' }],
372
- };
373
- removeTsconfigTestReference(tsconfig);
374
- expect(tsconfig).toEqual({ references: [{ path: './tsconfig.lib.json' }] });
375
- });
376
-
377
- it('does not invent a references list', () => {
378
- const tsconfig: Record<string, unknown> = {};
379
- removeTsconfigTestReference(tsconfig);
380
- expect(tsconfig).toEqual({});
381
- });
382
- });
383
-
384
- // ---------------------------------------------------------------------------
385
- // Layer 2: Tree-based tests
386
- // ---------------------------------------------------------------------------
387
-
388
- describe('typecheck test policy (Tree)', () => {
389
- it('creates tsconfig.test.json for bun test package', () => {
390
- const tree = createTreeWithEmptyWorkspace();
391
- addProjectConfiguration(tree, 'app', { root: 'packages/app', targets: {} });
392
- // Remove auto-created project.json to test package.json-only detection
393
- if (tree.exists('packages/app/project.json')) tree.delete('packages/app/project.json');
394
- writeJson(tree, 'packages/app/package.json', {
395
- name: '@scope/app',
396
- scripts: { test: 'bun test' },
397
- nx: { name: 'app' },
398
- });
399
- writeJson(tree, 'packages/app/tsconfig.lib.json', {
400
- extends: '../../tsconfig.base.json',
401
- compilerOptions: { composite: true, baseUrl: '.', rootDir: 'src', outDir: 'dist' },
402
- });
403
-
404
- tree.write('packages/app/src/app.test.ts', 'export {};\n');
405
- const changed = applyTypecheckTestPolicyTree(tree);
406
- expect(changed).toBe(true);
407
-
408
- const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json');
409
- const compilerOptions = expectRecord(tsconfig.compilerOptions);
410
- expect(compilerOptions.noEmit).toBe(true);
411
- expect(compilerOptions.composite).toBe(false);
412
- expect(compilerOptions.types).toContain('bun');
413
- expect(compilerOptions.baseUrl).toBe('.');
414
- expect(tsconfig.extends).toBe('../../tsconfig.base.json');
415
-
416
- const include = expectStringArray(tsconfig.include);
417
- expect(include).toContain('src/**/*.test.ts');
418
- expect(include).toContain('src/**/*.spec.ts');
419
-
420
- const references = expectReferences(tsconfig.references);
421
- expect(references).toContainEqual({ path: './tsconfig.lib.json' });
422
- });
423
-
424
- it('extends the workspace base from the project root when there is no lib program', () => {
425
- // `tooling` sits one level below the workspace root. A fixed
426
- // '../../tsconfig.base.json' named a file above the repository.
427
- const tree = createTreeWithEmptyWorkspace();
428
- for (const [name, root] of [
429
- ['tooling', 'tooling'],
430
- ['app', 'packages/app'],
431
- ] as const) {
432
- addProjectConfiguration(tree, name, { root, targets: {} });
433
- if (tree.exists(`${root}/project.json`)) tree.delete(`${root}/project.json`);
434
- writeJson(tree, `${root}/package.json`, { name: `@scope/${name}`, scripts: { test: 'bun test' }, nx: { name } });
435
- }
436
-
437
- tree.write('tooling/src/tooling.test.ts', 'export {};\n');
438
- tree.write('packages/app/src/app.test.ts', 'export {};\n');
439
- applyTypecheckTestPolicyTree(tree);
440
- expect(readJson<Record<string, unknown>>(tree, 'tooling/tsconfig.test.json').extends).toBe('../tsconfig.base.json');
441
- expect(readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json').extends).toBe(
442
- '../../tsconfig.base.json',
443
- );
444
- });
445
-
446
- it('references only composite lib programs (TS6306 otherwise), resolving composite through extends', () => {
447
- const tree = createTreeWithEmptyWorkspace();
448
- writeJson(tree, 'tsconfig.composite.json', { compilerOptions: { composite: true } });
449
- for (const [name, composite] of [
450
- ['app', 'no'],
451
- ['lib', 'own'],
452
- ['inherits', 'base'],
453
- ] as const) {
454
- addProjectConfiguration(tree, name, { root: `packages/${name}`, targets: {} });
455
- if (tree.exists(`packages/${name}/project.json`)) tree.delete(`packages/${name}/project.json`);
456
- writeJson(tree, `packages/${name}/package.json`, {
457
- name: `@scope/${name}`,
458
- scripts: { test: 'bun test' },
459
- nx: { name },
460
- ...(name === 'app' ? { dependencies: { '@scope/lib': 'workspace:*', '@scope/inherits': 'workspace:*' } } : {}),
461
- });
462
- writeJson(tree, `packages/${name}/tsconfig.lib.json`, {
463
- extends:
464
- composite === 'base' ? ['../../tsconfig.base.json', '../../tsconfig.composite'] : '../../tsconfig.base.json',
465
- compilerOptions: { rootDir: 'src', outDir: 'dist', ...(composite === 'own' ? { composite: true } : {}) },
466
- });
467
- }
468
-
469
- for (const name of ['app', 'lib', 'inherits']) {
470
- tree.write(`packages/${name}/src/${name}.test.ts`, 'export {};\n');
471
- }
472
- applyTypecheckTestPolicyTree(tree);
473
- const references = expectReferences(
474
- readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json').references,
475
- );
476
- // The app's own emit program is not composite: its sources are in the
477
- // test program by glob, not by reference. The composite dependencies are —
478
- // whether composite is declared on the file or inherited from a base.
479
- expect(references).toEqual([{ path: '../lib/tsconfig.lib.json' }, { path: '../inherits/tsconfig.lib.json' }]);
480
- });
481
-
482
- it('detects bun test in project.json targets', () => {
483
- const tree = createTreeWithEmptyWorkspace();
484
- addProjectConfiguration(tree, 'app', {
485
- root: 'packages/app',
486
- targets: { test: { executor: 'nx:run-commands', options: { command: 'bun test' } } },
487
- });
488
- writeJson(tree, 'packages/app/package.json', { name: '@scope/app' });
489
-
490
- const issues = checkTypecheckTestPolicyTree(tree);
491
- // Should detect bun test from project.json and require tsconfig.test.json
492
- expect(issues.some((i) => i.message.includes('requires tsconfig.test.json'))).toBe(true);
493
- expect(issues.some((i) => i.message.includes('bun test'))).toBe(true);
494
- });
495
-
496
- it('detects vitest in project.json targets', () => {
497
- const tree = createTreeWithEmptyWorkspace();
498
- addProjectConfiguration(tree, 'web', {
499
- root: 'packages/web',
500
- targets: { test: { executor: 'nx:run-commands', options: { command: 'vitest run' } } },
501
- });
502
- writeJson(tree, 'packages/web/package.json', { name: '@scope/web' });
503
-
504
- const issues = checkTypecheckTestPolicyTree(tree);
505
- expect(issues.some((i) => i.message.includes('vitest'))).toBe(true);
506
- });
507
-
508
- it('reports issues for bad tsconfig.test.json contents', () => {
509
- const tree = createTreeWithEmptyWorkspace();
510
- addProjectConfiguration(tree, 'bad', { root: 'packages/bad', targets: {} });
511
- writeJson(tree, 'packages/bad/package.json', {
512
- name: '@scope/bad',
513
- scripts: { test: 'bun test' },
514
- nx: { name: 'bad' },
515
- });
516
- writeJson(tree, 'packages/bad/tsconfig.test.json', {
517
- compilerOptions: {
518
- composite: true,
519
- declaration: true,
520
- outDir: 'dist-test',
521
- },
522
- });
523
-
524
- const issues = checkTypecheckTestPolicyTree(tree);
525
- const messages = issues.map((i) => i.message);
526
- expect(messages).toContainEqual(expect.stringContaining('noEmit must be true'));
527
- expect(messages).toContainEqual(expect.stringContaining('composite'));
528
- expect(messages).toContainEqual(expect.stringContaining('declaration = true'));
529
- expect(messages).toContainEqual(expect.stringContaining('dist-test'));
530
- });
531
-
532
- it('reports tsconfig.json test reference', () => {
533
- const tree = createTreeWithEmptyWorkspace();
534
- addProjectConfiguration(tree, 'app', { root: 'packages/app', targets: {} });
535
- writeJson(tree, 'packages/app/package.json', {
536
- name: '@scope/app',
537
- scripts: { test: 'bun test' },
538
- nx: { name: 'app' },
539
- });
540
- writeJson(tree, 'packages/app/tsconfig.test.json', {
541
- compilerOptions: { noEmit: true },
542
- });
543
- writeJson(tree, 'packages/app/tsconfig.json', {
544
- references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }],
545
- });
546
-
547
- const issues = checkTypecheckTestPolicyTree(tree);
548
- expect(issues.some((i) => i.message.includes('must not reference'))).toBe(true);
549
- });
550
-
551
- it('removes tsconfig.json test reference on apply', () => {
552
- const tree = createTreeWithEmptyWorkspace();
553
- addProjectConfiguration(tree, 'app', { root: 'packages/app', targets: {} });
554
- writeJson(tree, 'packages/app/package.json', {
555
- name: '@scope/app',
556
- scripts: { test: 'bun test' },
557
- nx: { name: 'app' },
558
- });
559
- writeJson(tree, 'packages/app/tsconfig.test.json', {
560
- extends: '../../tsconfig.base.json',
561
- compilerOptions: {
562
- noEmit: true,
563
- composite: false,
564
- declaration: false,
565
- declarationMap: false,
566
- emitDeclarationOnly: false,
567
- types: ['bun'],
568
- },
569
- include: [
570
- 'src/**/*.test.ts',
571
- 'src/**/*.spec.ts',
572
- 'src/**/__tests__/**/*.ts',
573
- 'src/**/__tests__/**/*.tsx',
574
- 'src/test-suite-tracer.ts',
575
- ],
576
- });
577
- writeJson(tree, 'packages/app/tsconfig.json', {
578
- references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }],
579
- });
580
-
581
- tree.write('packages/app/src/app.test.ts', 'export {};\n');
582
- const changed = applyTypecheckTestPolicyTree(tree);
583
- expect(changed).toBe(true);
584
-
585
- const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.json');
586
- const references = expectReferences(tsconfig.references);
587
- expect(references).toEqual([{ path: './tsconfig.lib.json' }]);
588
- });
589
-
590
- it('skips root project', () => {
591
- const tree = createTreeWithEmptyWorkspace();
592
- // Root project with root "." should be skipped
593
- addProjectConfiguration(tree, 'root', { root: '.', targets: {} });
594
- writeJson(tree, 'package.json', {
595
- name: '@scope/root',
596
- scripts: { test: 'bun test' },
597
- });
598
-
599
- const issues = checkTypecheckTestPolicyTree(tree);
600
- expect(issues).toEqual([]);
601
- });
602
-
603
- it('skips packages without test runners', () => {
604
- const tree = createTreeWithEmptyWorkspace();
605
- addProjectConfiguration(tree, 'utils', { root: 'packages/utils', targets: {} });
606
- writeJson(tree, 'packages/utils/package.json', {
607
- name: '@scope/utils',
608
- scripts: { build: 'tsc' },
609
- });
610
-
611
- const issues = checkTypecheckTestPolicyTree(tree);
612
- expect(issues).toEqual([]);
613
- expect(applyTypecheckTestPolicyTree(tree)).toBe(false);
614
- });
615
-
616
- it('adds workspace dependency references', () => {
617
- const tree = createTreeWithEmptyWorkspace();
618
-
619
- // Library dependency
620
- addProjectConfiguration(tree, 'lib', { root: 'packages/lib', targets: {} });
621
- writeJson(tree, 'packages/lib/package.json', { name: '@scope/lib' });
622
- writeJson(tree, 'packages/lib/tsconfig.lib.json', {
623
- extends: '../../tsconfig.base.json',
624
- compilerOptions: { composite: true },
625
- });
626
-
627
- // App that depends on lib
628
- addProjectConfiguration(tree, 'app', { root: 'packages/app', targets: {} });
629
- writeJson(tree, 'packages/app/package.json', {
630
- name: '@scope/app',
631
- scripts: { test: 'bun test' },
632
- dependencies: { '@scope/lib': 'workspace:*' },
633
- nx: { name: 'app' },
634
- });
635
- writeJson(tree, 'packages/app/tsconfig.lib.json', {
636
- extends: '../../tsconfig.base.json',
637
- compilerOptions: { composite: true },
638
- });
639
-
640
- tree.write('packages/app/src/app.test.ts', 'export {};\n');
641
- expect(applyTypecheckTestPolicyTree(tree)).toBe(true);
642
-
643
- const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json');
644
- const references = expectReferences(tsconfig.references);
645
- expect(references).toContainEqual({ path: './tsconfig.lib.json' });
646
- expect(references).toContainEqual({ path: '../lib/tsconfig.lib.json' });
647
- });
648
- });
649
-
650
- // ---------------------------------------------------------------------------
651
- // Layer 3: Filesystem-based tests (existing)
652
- // ---------------------------------------------------------------------------
653
-
654
- describe('typecheck test policy', () => {
655
- it('reads a documented tsconfig.test.json instead of treating it as absent', async () => {
656
- // tsconfig files are JSONC: TypeScript permits comments. A plain
657
- // JSON.parse failed, the reader answered "absent", and the policy
658
- // regenerated the file — deleting a declared `lib`, an `exclude`, extra
659
- // `include` globs and every comment explaining them. That is how a
660
- // Bun-only test program loses es2023 and `toSorted` becomes a type error.
661
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-jsonc-'));
662
- try {
663
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
664
- await writeJsonFs(join(root, 'packages/app/package.json'), {
665
- name: '@scope/app',
666
- scripts: { test: 'bun test' },
667
- });
668
- await mkdir(join(root, 'packages/app'), { recursive: true });
669
- const documented = [
670
- '{',
671
- ' "extends": "../../tsconfig.base.json",',
672
- ' // WHY es2023: this program is Bun-only and JSC has change-array-by-copy.',
673
- ' "compilerOptions": { "lib": ["es2023"], "types": ["bun"], "noEmit": true, "composite": false,',
674
- ' "declaration": false, "declarationMap": false, "emitDeclarationOnly": false },',
675
- ' "include": ["src/**/*.test.ts", "src/**/*.spec.ts", "src/**/__tests__/**/*.ts",',
676
- ' "src/**/__tests__/**/*.tsx", "src/test-suite-tracer.ts", "tests/**/*.ts"],',
677
- ' "exclude": ["src/lib/ts-plugin.ts"]',
678
- '}',
679
- '',
680
- ].join('\n');
681
- await writeFile(join(root, 'packages/app/tsconfig.test.json'), documented);
682
-
683
- // Nothing the policy wants is missing, so it must not rewrite the file.
684
- expect(applyTypecheckTestPolicy(root)).toBe(false);
685
- expect(await readFile(join(root, 'packages/app/tsconfig.test.json'), 'utf8')).toBe(documented);
686
- } finally {
687
- await rm(root, { recursive: true, force: true });
688
- }
689
- });
690
-
691
- describe('a documented config that drifts from the policy', () => {
692
- const BIOME_SPACES = '{"formatter":{"indentStyle":"space","indentWidth":2,"lineWidth":120}}\n';
693
-
694
- /** An app that depends on a composite lib, so the policy wants a reference its tsconfig.test.json lacks. */
695
- async function appWithCompositeDependency(root: string): Promise<void> {
696
- await writeFile(join(root, 'biome.json'), BIOME_SPACES);
697
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
698
- await writeJsonFs(join(root, 'tsconfig.base.json'), { compilerOptions: { composite: true } });
699
- await writeJsonFs(join(root, 'packages/lib/package.json'), { name: '@scope/lib' });
700
- await writeJsonFs(join(root, 'packages/lib/tsconfig.lib.json'), { extends: '../../tsconfig.base.json' });
701
- await writeJsonFs(join(root, 'packages/app/package.json'), {
702
- name: '@scope/app',
703
- scripts: { test: 'bun test' },
704
- dependencies: { '@scope/lib': 'workspace:*' },
705
- });
706
- // The program extends it, so the policy can read what the program selects through it.
707
- await writeJsonFs(join(root, 'packages/app/tsconfig.json'), { extends: '../../tsconfig.base.json' });
708
- await writeSource(join(root, 'packages/app/scripts/app.test.ts'));
709
- }
710
-
711
- const documented = [
712
- '{',
713
- " // WHY the program extends the package's own config: these are Bun programs.",
714
- ' "extends": "./tsconfig.json",',
715
- ' "compilerOptions": {',
716
- ' "composite": false,',
717
- ' "declaration": false,',
718
- ' "declarationMap": false,',
719
- ' "emitDeclarationOnly": false,',
720
- ' "noEmit": true, // kept as the policy requires',
721
- ' "types": ["bun"]',
722
- ' },',
723
- ' /* the suites live beside the scripts they exercise */',
724
- ' "include": ["scripts/**/*.test.ts"],',
725
- '}',
726
- '',
727
- ].join('\n');
728
-
729
- it('is repaired in place: the policy edits what it owns and every comment survives', async () => {
730
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-documented-'));
731
- try {
732
- await appWithCompositeDependency(root);
733
- const path = join(root, 'packages/app/tsconfig.test.json');
734
- await writeFile(path, documented);
735
-
736
- expect(checkTypecheckTestPolicy(root).map((issue) => issue.message)).toEqual([
737
- 'must match the canonical no-emit test typecheck configuration',
738
- ]);
739
- expect(applyTypecheckTestPolicy(root)).toBe(true);
740
-
741
- const written = await readFile(path, 'utf8');
742
- expect(written).toContain("// WHY the program extends the package's own config: these are Bun programs.");
743
- expect(written).toContain('// kept as the policy requires');
744
- expect(written).toContain('/* the suites live beside the scripts they exercise */');
745
- expect(parseJson(written)).toEqual({
746
- extends: './tsconfig.json',
747
- compilerOptions: {
748
- composite: false,
749
- declaration: false,
750
- declarationMap: false,
751
- emitDeclarationOnly: false,
752
- noEmit: true,
753
- types: ['bun'],
754
- },
755
- include: ['scripts/**/*.test.ts'],
756
- references: [{ path: '../lib/tsconfig.lib.json' }],
757
- });
758
- expect(checkTypecheckTestPolicy(root)).toEqual([]);
759
- // The policy is at its own fixed point: a second run changes nothing.
760
- expect(applyTypecheckTestPolicy(root)).toBe(false);
761
- expect(await readFile(path, 'utf8')).toBe(written);
762
- } finally {
763
- await rm(root, { recursive: true, force: true });
764
- }
765
- });
766
-
767
- it('has its test reference removed from tsconfig.json without losing the comments around it', async () => {
768
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-documented-'));
769
- try {
770
- await appWithCompositeDependency(root);
771
- await writeFile(join(root, 'packages/app/tsconfig.test.json'), documented);
772
- const path = join(root, 'packages/app/tsconfig.json');
773
- await writeFile(
774
- path,
775
- [
776
- '{',
777
- ' // The project is its lib program; the tests are typechecked on their own.',
778
- ' "references": [{ "path": "./tsconfig.lib.json" }, { "path": "./tsconfig.test.json" }]',
779
- '}',
780
- '',
781
- ].join('\n'),
782
- );
783
-
784
- applyTypecheckTestPolicy(root);
785
-
786
- const written = await readFile(path, 'utf8');
787
- expect(written).toContain('// The project is its lib program; the tests are typechecked on their own.');
788
- expect(parseJson(written)).toEqual({ references: [{ path: './tsconfig.lib.json' }] });
789
- } finally {
790
- await rm(root, { recursive: true, force: true });
791
- }
792
- });
793
- });
794
-
795
- it('creates tsconfig.test.json for bun test package', async () => {
796
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
797
- try {
798
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
799
- await writeJsonFs(join(root, 'packages/app/package.json'), {
800
- name: '@scope/app',
801
- scripts: { test: 'bun test' },
802
- });
803
-
804
- // check should report missing tsconfig.test.json
805
- const issues = checkTypecheckTestPolicy(root);
806
- expect(issues.length).toBe(1);
807
- expect(issues[0]?.message).toContain('bun test');
808
- expect(issues[0]?.message).toContain('tsconfig.test.json');
809
-
810
- // apply should create it
811
- expect(applyTypecheckTestPolicy(root)).toBe(true);
812
-
813
- const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
814
- const compilerOptions = expectRecord(tsconfig.compilerOptions);
815
- expect(compilerOptions.noEmit).toBe(true);
816
- expect(compilerOptions.composite).toBe(false);
817
- expect(compilerOptions.declaration).toBe(false);
818
- expect(compilerOptions.declarationMap).toBe(false);
819
- expect(compilerOptions.emitDeclarationOnly).toBe(false);
820
- expect(compilerOptions.types).toContain('bun');
821
- expect(tsconfig.extends).toBe('../../tsconfig.base.json');
822
-
823
- const include = expectStringArray(tsconfig.include);
824
- expect(include).toContain('src/**/*.test.ts');
825
- expect(include).toContain('src/**/*.spec.ts');
826
- expect(include).toContain('src/**/__tests__/**/*.ts');
827
- expect(include).toContain('src/test-suite-tracer.ts');
828
-
829
- // second apply should be idempotent
830
- expect(applyTypecheckTestPolicy(root)).toBe(false);
831
-
832
- // check should now pass
833
- expect(checkTypecheckTestPolicy(root)).toEqual([]);
834
- } finally {
835
- await rm(root, { recursive: true, force: true });
836
- }
837
- });
838
-
839
- it('creates tsconfig.test.json for vitest package', async () => {
840
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
841
- try {
842
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
843
- await writeJsonFs(join(root, 'packages/web/package.json'), {
844
- name: '@scope/web',
845
- scripts: { test: 'vitest run' },
846
- });
847
-
848
- expect(applyTypecheckTestPolicy(root)).toBe(true);
849
-
850
- const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/web/tsconfig.test.json')));
851
- const compilerOptions = expectRecord(tsconfig.compilerOptions);
852
- expect(compilerOptions.noEmit).toBe(true);
853
- // vitest should NOT add bun types
854
- expect(compilerOptions.types).toBeUndefined();
855
-
856
- expect(checkTypecheckTestPolicy(root)).toEqual([]);
857
- } finally {
858
- await rm(root, { recursive: true, force: true });
859
- }
860
- });
861
-
862
- it('detects bun test in Nx targets', async () => {
863
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
864
- try {
865
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
866
- await writeJsonFs(join(root, 'packages/lib/package.json'), {
867
- name: '@scope/lib',
868
- nx: {
869
- targets: {
870
- test: {
871
- options: { command: 'bun test --coverage' },
872
- },
873
- },
874
- },
875
- });
876
-
877
- const issues = checkTypecheckTestPolicy(root);
878
- expect(issues.length).toBe(1);
879
- expect(issues[0]?.message).toContain('bun test');
880
-
881
- expect(applyTypecheckTestPolicy(root)).toBe(true);
882
-
883
- const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/lib/tsconfig.test.json')));
884
- const compilerOptions = expectRecord(tsconfig.compilerOptions);
885
- expect(compilerOptions.noEmit).toBe(true);
886
- expect(compilerOptions.types).toContain('bun');
887
- } finally {
888
- await rm(root, { recursive: true, force: true });
889
- }
890
- });
891
-
892
- it('rejects composite/declaration/dist-test in tsconfig.test.json', async () => {
893
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
894
- try {
895
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
896
- await writeJsonFs(join(root, 'packages/bad/package.json'), {
897
- name: '@scope/bad',
898
- scripts: { test: 'bun test' },
899
- });
900
- await writeSource(join(root, 'packages/bad/src/bad.test.ts'));
901
- await writeJsonFs(join(root, 'packages/bad/tsconfig.test.json'), {
902
- compilerOptions: {
903
- composite: true,
904
- declaration: true,
905
- declarationMap: true,
906
- outDir: 'dist-test',
907
- tsBuildInfoFile: 'dist-test/tsconfig.test.tsbuildinfo',
908
- },
909
- });
910
-
911
- const issues = checkTypecheckTestPolicy(root);
912
- // Should report: noEmit missing, composite, declaration, declarationMap, outDir dist-test, tsBuildInfoFile dist-test
913
- expect(issues.length).toBe(6);
914
- const messages = issues.map((issue) => issue.message);
915
- expect(messages).toContainEqual(expect.stringContaining('noEmit must be true'));
916
- expect(messages).toContainEqual(expect.stringContaining('composite'));
917
- expect(messages).toContainEqual(expect.stringContaining('declaration = true'));
918
- expect(messages).toContainEqual(expect.stringContaining('declarationMap'));
919
- expect(messages).toContainEqual(expect.stringContaining('dist-test'));
920
- } finally {
921
- await rm(root, { recursive: true, force: true });
922
- }
923
- });
924
-
925
- it('removes tsconfig.json reference to ./tsconfig.test.json', async () => {
926
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
927
- try {
928
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
929
- await writeJsonFs(join(root, 'packages/app/package.json'), {
930
- name: '@scope/app',
931
- scripts: { test: 'bun test' },
932
- });
933
- await writeJsonFs(join(root, 'packages/app/tsconfig.test.json'), {
934
- extends: '../../tsconfig.base.json',
935
- compilerOptions: {
936
- noEmit: true,
937
- composite: false,
938
- declaration: false,
939
- declarationMap: false,
940
- emitDeclarationOnly: false,
941
- },
942
- include: ['src/**/*.test.ts'],
943
- });
944
- await writeJsonFs(join(root, 'packages/app/tsconfig.json'), {
945
- references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }],
946
- });
947
-
948
- // check should report the bad reference
949
- const issues = checkTypecheckTestPolicy(root);
950
- const referenceIssues = issues.filter((i) => i.message.includes('must not reference'));
951
- expect(referenceIssues.length).toBe(1);
952
-
953
- // apply should remove it
954
- expect(applyTypecheckTestPolicy(root)).toBe(true);
955
-
956
- const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.json')));
957
- const references = expectReferences(tsconfig.references);
958
- expect(references).toEqual([{ path: './tsconfig.lib.json' }]);
959
- } finally {
960
- await rm(root, { recursive: true, force: true });
961
- }
962
- });
963
-
964
- it('copies lib compiler options', async () => {
965
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
966
- try {
967
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
968
- await writeJsonFs(join(root, 'packages/app/package.json'), {
969
- name: '@scope/app',
970
- scripts: { test: 'bun test' },
971
- });
972
- await writeJsonFs(join(root, 'packages/app/tsconfig.lib.json'), {
973
- extends: '../../tsconfig.base.json',
974
- compilerOptions: {
975
- composite: true,
976
- baseUrl: '.',
977
- module: 'esnext',
978
- moduleResolution: 'bundler',
979
- jsx: 'react-jsx',
980
- lib: ['ES2023', 'DOM'],
981
- },
982
- });
983
-
984
- expect(applyTypecheckTestPolicy(root)).toBe(true);
985
-
986
- const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
987
- const compilerOptions = expectRecord(tsconfig.compilerOptions);
988
- expect(compilerOptions.baseUrl).toBe('.');
989
- expect(compilerOptions.module).toBe('esnext');
990
- expect(compilerOptions.moduleResolution).toBe('bundler');
991
- expect(compilerOptions.jsx).toBe('react-jsx');
992
- expect(compilerOptions.lib).toEqual(['ES2023', 'DOM']);
993
- // extends should come from tsconfig.lib.json
994
- expect(tsconfig.extends).toBe('../../tsconfig.base.json');
995
-
996
- // references should include ./tsconfig.lib.json
997
- const references = expectReferences(tsconfig.references);
998
- expect(references).toContainEqual({ path: './tsconfig.lib.json' });
999
- } finally {
1000
- await rm(root, { recursive: true, force: true });
1001
- }
1002
- });
1003
-
1004
- it('adds workspace dependency references', async () => {
1005
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1006
- try {
1007
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
1008
- await writeJsonFs(join(root, 'packages/lib/package.json'), {
1009
- name: '@scope/lib',
1010
- });
1011
- await writeJsonFs(join(root, 'packages/lib/tsconfig.lib.json'), {
1012
- extends: '../../tsconfig.base.json',
1013
- compilerOptions: { composite: true },
1014
- });
1015
- await writeJsonFs(join(root, 'packages/app/package.json'), {
1016
- name: '@scope/app',
1017
- scripts: { test: 'bun test' },
1018
- dependencies: { '@scope/lib': 'workspace:*' },
1019
- });
1020
- await writeJsonFs(join(root, 'packages/app/tsconfig.lib.json'), {
1021
- extends: '../../tsconfig.base.json',
1022
- compilerOptions: { composite: true },
1023
- });
1024
-
1025
- expect(applyTypecheckTestPolicy(root)).toBe(true);
1026
-
1027
- const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
1028
- const references = expectReferences(tsconfig.references);
1029
- expect(references).toContainEqual({ path: './tsconfig.lib.json' });
1030
- expect(references).toContainEqual({ path: '../lib/tsconfig.lib.json' });
1031
- } finally {
1032
- await rm(root, { recursive: true, force: true });
1033
- }
1034
- });
1035
-
1036
- it('does not require tsconfig.test.json for non-bun/vitest runners', async () => {
1037
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1038
- try {
1039
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
1040
- await writeJsonFs(join(root, 'packages/app/package.json'), {
1041
- name: '@scope/app',
1042
- scripts: { test: 'node --test' },
1043
- });
1044
-
1045
- expect(checkTypecheckTestPolicy(root)).toEqual([]);
1046
- expect(applyTypecheckTestPolicy(root)).toBe(false);
1047
- } finally {
1048
- await rm(root, { recursive: true, force: true });
1049
- }
1050
- });
1051
-
1052
- it('accepts valid noEmit test tsconfig', async () => {
1053
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1054
- try {
1055
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
1056
- await writeJsonFs(join(root, 'packages/app/package.json'), {
1057
- name: '@scope/app',
1058
- scripts: { test: 'bun test' },
1059
- });
1060
- await writeJsonFs(join(root, 'packages/app/tsconfig.test.json'), {
1061
- extends: '../../tsconfig.base.json',
1062
- compilerOptions: {
1063
- composite: false,
1064
- declaration: false,
1065
- declarationMap: false,
1066
- emitDeclarationOnly: false,
1067
- noEmit: true,
1068
- types: ['bun'],
1069
- },
1070
- include: [
1071
- 'src/**/*.test.ts',
1072
- 'src/**/*.spec.ts',
1073
- 'src/**/__tests__/**/*.ts',
1074
- 'src/**/__tests__/**/*.tsx',
1075
- 'src/test-suite-tracer.ts',
1076
- ],
1077
- });
1078
-
1079
- expect(checkTypecheckTestPolicy(root)).toEqual([]);
1080
- } finally {
1081
- await rm(root, { recursive: true, force: true });
1082
- }
1083
- });
1084
-
1085
- it('detects bun test behind env prefix', async () => {
1086
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1087
- try {
1088
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
1089
- await writeJsonFs(join(root, 'packages/app/package.json'), {
1090
- name: '@scope/app',
1091
- scripts: { test: 'NODE_ENV=test bun test' },
1092
- });
1093
-
1094
- const issues = checkTypecheckTestPolicy(root);
1095
- expect(issues.length).toBe(1);
1096
- expect(issues[0]?.message).toContain('bun test');
1097
- } finally {
1098
- await rm(root, { recursive: true, force: true });
1099
- }
1100
- });
1101
- });
1102
-
1103
- // ---------------------------------------------------------------------------
1104
- // The test program's include comes from where the tests live, and a program
1105
- // that selects no file is refused
1106
- // ---------------------------------------------------------------------------
1107
-
1108
- const SRC_GLOBS = [
1109
- 'src/**/*.test.ts',
1110
- 'src/**/*.spec.ts',
1111
- 'src/**/__tests__/**/*.ts',
1112
- 'src/**/__tests__/**/*.tsx',
1113
- 'src/test-suite-tracer.ts',
1114
- ];
1115
-
1116
- function globsFor(directory: string): string[] {
1117
- return [
1118
- `${directory}/**/*.test.ts`,
1119
- `${directory}/**/*.spec.ts`,
1120
- `${directory}/**/__tests__/**/*.ts`,
1121
- `${directory}/**/__tests__/**/*.tsx`,
1122
- ];
1123
- }
1124
-
1125
- async function writeSource(path: string, text = 'export {};\n'): Promise<void> {
1126
- await mkdir(dirname(path), { recursive: true });
1127
- await writeFile(path, text);
1128
- }
1129
-
1130
- /** The shape of this repository's `tooling` project: tests beside the shell scripts, no src/. */
1131
- async function toolingShapedWorkspace(root: string): Promise<void> {
1132
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*', 'tooling'] });
1133
- await writeJsonFs(join(root, 'tsconfig.base.json'), { compilerOptions: {} });
1134
- await writeJsonFs(join(root, 'tooling/package.json'), {
1135
- name: '@scope/tooling',
1136
- private: true,
1137
- nx: {
1138
- name: 'tooling',
1139
- targets: {
1140
- test: {
1141
- executor: '@smoothbricks/nx-plugin:bounded-exec',
1142
- options: { command: 'bun test --timeout=0 direnv', cwd: '{projectRoot}' },
1143
- },
1144
- },
1145
- },
1146
- });
1147
- await writeSource(join(root, 'tooling/direnv/enter-shell.test.ts'));
1148
- }
1149
-
1150
- describe('where the test program looks for tests', () => {
1151
- it('includes the directory a src-less project keeps its tests in, not src', async () => {
1152
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1153
- try {
1154
- await toolingShapedWorkspace(root);
1155
-
1156
- expect(applyTypecheckTestPolicy(root)).toBe(true);
1157
-
1158
- const tsconfig = expectRecord(await readJsonFs(join(root, 'tooling/tsconfig.test.json')));
1159
- expect(tsconfig.include).toEqual(globsFor('direnv'));
1160
- expect(applyTypecheckTestPolicy(root)).toBe(false);
1161
- expect(checkTypecheckTestPolicy(root)).toEqual([]);
1162
- } finally {
1163
- await rm(root, { recursive: true, force: true });
1164
- }
1165
- });
1166
-
1167
- it('keeps the src convention for a package whose tests live in src', async () => {
1168
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1169
- try {
1170
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
1171
- await writeJsonFs(join(root, 'packages/app/package.json'), { name: '@scope/app', scripts: { test: 'bun test' } });
1172
- await writeSource(join(root, 'packages/app/src/app.test.ts'));
1173
- // A stray outside src stays the stray-test policy's to report; it must not widen the program.
1174
- await writeSource(join(root, 'packages/app/scripts/helper.test.ts'));
1175
-
1176
- applyTypecheckTestPolicy(root);
1177
-
1178
- const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
1179
- expect(tsconfig.include).toEqual(SRC_GLOBS);
1180
- } finally {
1181
- await rm(root, { recursive: true, force: true });
1182
- }
1183
- });
1184
-
1185
- it('does not add a glob for tests an include the project wrote already selects', async () => {
1186
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1187
- try {
1188
- await toolingShapedWorkspace(root);
1189
- await writeJsonFs(join(root, 'tooling/tsconfig.test.json'), {
1190
- extends: '../tsconfig.base.json',
1191
- compilerOptions: {
1192
- composite: false,
1193
- declaration: false,
1194
- declarationMap: false,
1195
- emitDeclarationOnly: false,
1196
- noEmit: true,
1197
- types: ['bun'],
1198
- },
1199
- include: ['direnv/**/*'],
1200
- });
1201
-
1202
- expect(applyTypecheckTestPolicy(root)).toBe(false);
1203
-
1204
- const tsconfig = expectRecord(await readJsonFs(join(root, 'tooling/tsconfig.test.json')));
1205
- expect(tsconfig.include).toEqual(['direnv/**/*']);
1206
- } finally {
1207
- await rm(root, { recursive: true, force: true });
1208
- }
1209
- });
1210
-
1211
- it('adds the directory to an include the project wrote that selects none of its tests', async () => {
1212
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1213
- try {
1214
- await toolingShapedWorkspace(root);
1215
- await writeJsonFs(join(root, 'tooling/tsconfig.test.json'), {
1216
- extends: '../tsconfig.base.json',
1217
- compilerOptions: {
1218
- composite: false,
1219
- declaration: false,
1220
- declarationMap: false,
1221
- emitDeclarationOnly: false,
1222
- noEmit: true,
1223
- types: ['bun'],
1224
- },
1225
- include: ['src/**/*.test.ts'],
1226
- });
1227
-
1228
- expect(applyTypecheckTestPolicy(root)).toBe(true);
1229
-
1230
- const tsconfig = expectRecord(await readJsonFs(join(root, 'tooling/tsconfig.test.json')));
1231
- expect(tsconfig.include).toEqual(['src/**/*.test.ts', ...globsFor('direnv')]);
1232
- } finally {
1233
- await rm(root, { recursive: true, force: true });
1234
- }
1235
- });
1236
- });
1237
-
1238
- describe('a test program that selects none of its tests', () => {
1239
- async function packageWithoutTests(root: string): Promise<void> {
1240
- await writeJsonFs(join(root, 'package.json'), { workspaces: ['packages/*'] });
1241
- await writeJsonFs(join(root, 'tsconfig.base.json'), { compilerOptions: {} });
1242
- await writeJsonFs(join(root, 'packages/app/package.json'), { name: '@scope/app', scripts: { test: 'bun test' } });
1243
- await writeSource(join(root, 'packages/app/src/index.ts'));
1244
- }
1245
-
1246
- it('is reported by the generator without writing the file, naming the project and why', async () => {
1247
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1248
- try {
1249
- await packageWithoutTests(root);
1250
- const tree = new FsTree(root, false);
1251
-
1252
- const results = stageManagedFiles(tree, renderTypecheckTestFiles(tree));
1253
- const skipped = results.find((result) => result.target === 'packages/app/tsconfig.test.json');
1254
-
1255
- expect(skipped?.action).toBe('skipped');
1256
- expect(skipped?.reason).toContain('matches no file');
1257
- expect(skipped?.reason).toContain('packages/app');
1258
- expect(tree.exists('packages/app/tsconfig.test.json')).toBe(false);
1259
- expect(() => assertNoManagedConflicts(results)).not.toThrow();
1260
- } finally {
1261
- await rm(root, { recursive: true, force: true });
1262
- }
1263
- });
1264
-
1265
- it('is reported by the policy check', async () => {
1266
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1267
- try {
1268
- await packageWithoutTests(root);
1269
- await writeJsonFs(join(root, 'packages/app/tsconfig.test.json'), {
1270
- extends: '../../tsconfig.base.json',
1271
- compilerOptions: {
1272
- composite: false,
1273
- declaration: false,
1274
- declarationMap: false,
1275
- emitDeclarationOnly: false,
1276
- noEmit: true,
1277
- types: ['bun'],
1278
- },
1279
- include: SRC_GLOBS,
1280
- });
1281
-
1282
- const issues = checkTypecheckTestPolicy(root);
1283
-
1284
- expect(issues.map((issue) => issue.path)).toEqual([join(root, 'packages/app/tsconfig.test.json')]);
1285
- expect(issues[0]?.message).toContain('matches no file');
1286
- } finally {
1287
- await rm(root, { recursive: true, force: true });
1288
- }
1289
- });
1290
-
1291
- it('is refused when its exclude removes every test', async () => {
1292
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1293
- try {
1294
- await packageWithoutTests(root);
1295
- await writeSource(join(root, 'packages/app/src/app.test.ts'));
1296
- await writeJsonFs(join(root, 'packages/app/tsconfig.test.json'), {
1297
- extends: '../../tsconfig.base.json',
1298
- compilerOptions: {
1299
- composite: false,
1300
- declaration: false,
1301
- declarationMap: false,
1302
- emitDeclarationOnly: false,
1303
- noEmit: true,
1304
- types: ['bun'],
1305
- },
1306
- include: SRC_GLOBS,
1307
- exclude: ['src'],
1308
- });
1309
-
1310
- const issues = checkTypecheckTestPolicy(root);
1311
-
1312
- expect(issues.map((issue) => issue.message).join('\n')).toContain('matches no file');
1313
- } finally {
1314
- await rm(root, { recursive: true, force: true });
1315
- }
1316
- });
1317
-
1318
- it('is not refused while an inherited include the plugin cannot read may select files', async () => {
1319
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1320
- try {
1321
- await packageWithoutTests(root);
1322
- await writeJsonFs(join(root, 'packages/app/tsconfig.test.json'), {
1323
- extends: '@acme/tsconfig/bun.json',
1324
- compilerOptions: {
1325
- composite: false,
1326
- declaration: false,
1327
- declarationMap: false,
1328
- emitDeclarationOnly: false,
1329
- noEmit: true,
1330
- types: ['bun'],
1331
- },
1332
- });
1333
-
1334
- expect(checkTypecheckTestPolicy(root).some((issue) => issue.message.includes('matches no file'))).toBe(false);
1335
- } finally {
1336
- await rm(root, { recursive: true, force: true });
1337
- }
1338
- });
1339
-
1340
- it('is reported for a workspace member named by path, which the packages/* listing never walked', async () => {
1341
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1342
- try {
1343
- await toolingShapedWorkspace(root);
1344
- await writeJsonFs(join(root, 'tooling/tsconfig.test.json'), {
1345
- extends: '../tsconfig.base.json',
1346
- compilerOptions: {
1347
- composite: false,
1348
- declaration: false,
1349
- declarationMap: false,
1350
- emitDeclarationOnly: false,
1351
- noEmit: true,
1352
- types: ['bun'],
1353
- },
1354
- include: ['src/**/*.test.ts'],
1355
- });
1356
-
1357
- const issues = checkTypecheckTestPolicy(root);
1358
-
1359
- expect(issues.map((issue) => issue.path)).toEqual([
1360
- join(root, 'tooling/tsconfig.test.json'),
1361
- join(root, 'tooling/tsconfig.test.json'),
1362
- ]);
1363
- expect(issues[0]?.message).toContain('matches no file of its tests');
1364
- expect(issues[1]?.message).toContain('canonical');
1365
- } finally {
1366
- await rm(root, { recursive: true, force: true });
1367
- }
1368
- });
1369
-
1370
- it('is reported by the Tree check too', () => {
1371
- const tree = createTreeWithEmptyWorkspace();
1372
- addProjectConfiguration(tree, 'app', { root: 'packages/app', targets: {} });
1373
- writeJson(tree, 'packages/app/package.json', {
1374
- name: '@scope/app',
1375
- scripts: { test: 'bun test' },
1376
- nx: { name: 'app' },
1377
- });
1378
- writeJson(tree, 'tsconfig.base.json', { compilerOptions: {} });
1379
- tree.write('packages/app/src/index.ts', 'export {};\n');
1380
- writeJson(tree, 'packages/app/tsconfig.test.json', {
1381
- extends: '../../tsconfig.base.json',
1382
- compilerOptions: { noEmit: true, composite: false, declaration: false, declarationMap: false, types: ['bun'] },
1383
- include: SRC_GLOBS,
1384
- });
1385
-
1386
- expect(checkTypecheckTestPolicyTree(tree).map((issue) => issue.message)).toEqual([
1387
- expect.stringContaining('matches no file (the project has no test file)'),
1388
- ]);
1389
- });
1390
-
1391
- it('leaves an existing config it cannot honor as it was, and still repairs the project tsconfig.json', async () => {
1392
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1393
- try {
1394
- await packageWithoutTests(root);
1395
- await writeJsonFs(join(root, 'packages/app/tsconfig.json'), {
1396
- references: [{ path: './tsconfig.lib.json' }, { path: './tsconfig.test.json' }],
1397
- });
1398
-
1399
- const tree = new FsTree(root, false);
1400
- const results = stageManagedFiles(tree, renderTypecheckTestFiles(tree));
1401
-
1402
- expect(results.find((result) => result.target === 'packages/app/tsconfig.json')?.action).toBe('updated');
1403
- expect(results.find((result) => result.target === 'packages/app/tsconfig.test.json')?.action).toBe('skipped');
1404
- } finally {
1405
- await rm(root, { recursive: true, force: true });
1406
- }
1407
- });
1408
-
1409
- it('does not stumble on a dangling link beside the sources', async () => {
1410
- const root = await mkdtemp(join(tmpdir(), 'smoo-typecheck-test-policy-'));
1411
- try {
1412
- await packageWithoutTests(root);
1413
- await writeSource(join(root, 'packages/app/src/app.test.ts'));
1414
- await symlink(join(root, 'nowhere'), join(root, 'packages/app/result'));
1415
-
1416
- expect(applyTypecheckTestPolicy(root)).toBe(true);
1417
- expect(checkTypecheckTestPolicy(root)).toEqual([]);
1418
- } finally {
1419
- await rm(root, { recursive: true, force: true });
1420
- }
1421
- });
1422
- });
1423
-
1424
- interface TypeScriptReference {
1425
- path: string;
1426
- }
1427
-
1428
- function expectRecord(value: unknown): Record<string, unknown> {
1429
- if (!isRecord(value)) {
1430
- throw new Error('expected object');
1431
- }
1432
- return value;
1433
- }
1434
-
1435
- function isRecord(value: unknown): value is Record<string, unknown> {
1436
- return value !== null && typeof value === 'object' && !Array.isArray(value);
1437
- }
1438
-
1439
- function expectStringArray(value: unknown): string[] {
1440
- if (!Array.isArray(value)) {
1441
- throw new Error('expected array');
1442
- }
1443
- const values: unknown[] = value;
1444
- if (!values.every((entry): entry is string => typeof entry === 'string')) {
1445
- throw new Error('expected string array');
1446
- }
1447
- return values;
1448
- }
1449
-
1450
- function expectReferences(value: unknown): TypeScriptReference[] {
1451
- if (!Array.isArray(value)) {
1452
- throw new Error('expected array');
1453
- }
1454
- const values: unknown[] = value;
1455
- if (
1456
- !values.every(
1457
- (entry): entry is TypeScriptReference =>
1458
- entry !== null &&
1459
- typeof entry === 'object' &&
1460
- !Array.isArray(entry) &&
1461
- 'path' in entry &&
1462
- typeof entry.path === 'string',
1463
- )
1464
- ) {
1465
- throw new Error('expected TypeScript references');
1466
- }
1467
- return values;
1468
- }