@smoothbricks/nx-plugin 0.4.26 → 0.4.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +962 -148
  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
@@ -1,10 +1,25 @@
1
- import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
1
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
- import { CARGO_TEST_TARGET, listCargoWorkspacePackages, packageNameFromCargoTestTarget } from './cargo-workspace.js';
3
+ import { expandWildcardTargetConfiguration } from 'nx/src/tasks-runner/utils.js';
4
+ import {
5
+ CARGO_TEST_ARCHIVE_TARGET,
6
+ CARGO_TEST_COMPILE_TARGET,
7
+ CARGO_TEST_TARGET,
8
+ listCargoWorkspacePackages,
9
+ packageNameFromCargoTestTarget,
10
+ } from './cargo-workspace.js';
11
+ import { writeJsonFile } from './managed-files/managed-format.js';
4
12
  import type { PackageTargetPolicyOptions, ResolvedProjectTargets } from './package-target-policy.js';
13
+ import { isTestRunnerTargetName } from './workspace-config-policy.js';
5
14
 
6
15
  export const BOUNDED_TEST_EXECUTOR = '@smoothbricks/nx-plugin:bounded-exec';
7
- export const BOUNDED_TEST_TIMEOUT_MS = 120_000;
16
+ /**
17
+ * A test target's one bound: the `idleTimeoutMs` with which no test may go unfinished, the hang backstop of
18
+ * specs/cowshed/08_testing.md. It is no wall-clock ceiling: a suite that keeps finishing tests runs as long as it
19
+ * needs. It is the longest any single test may run, so it stays above every slow-timeout class in the plugin's
20
+ * nextest.toml and every bun `--timeout`.
21
+ */
22
+ export const BOUNDED_TEST_IDLE_TIMEOUT_MS = 180_000;
8
23
  export const BOUNDED_TEST_KILL_AFTER_MS = 10_000;
9
24
  // Per-test timeout passed to `bun test --timeout=<ms>`. Bun's default is
10
25
  // 5000ms which is too tight for git-fixture tests on slower CI runners
@@ -58,7 +73,7 @@ export function applyBoundedTestTargetPolicy(
58
73
  nextTestTarget.options = {
59
74
  command,
60
75
  cwd: '{projectRoot}',
61
- timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
76
+ idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
62
77
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
63
78
  };
64
79
 
@@ -93,9 +108,9 @@ export function applyWorkspaceBoundedTestTargetPolicy(root: string, options: Pac
93
108
  if (JSON.stringify(packageJson) === beforePackageJson && JSON.stringify(projectJson) === beforeProjectJson) {
94
109
  continue;
95
110
  }
96
- writePackageJson(packageJsonPath, packageJson);
111
+ writeJsonFile(packageJsonPath, packageJson);
97
112
  if (projectJson) {
98
- writeProjectJson(projectJsonPath, projectJson);
113
+ writeJsonFile(projectJsonPath, projectJson);
99
114
  }
100
115
  changed = true;
101
116
  }
@@ -215,6 +230,7 @@ export function checkWorkspaceCargoTestReachabilityPolicy(
215
230
  * to catch.
216
231
  */
217
232
  function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string): boolean {
233
+ const targetNames = [...project.targets];
218
234
  const visiting = new Set<string>();
219
235
  const visit = (targetName: string): boolean => {
220
236
  if (visiting.has(targetName) || !project.targets.has(targetName)) {
@@ -230,7 +246,7 @@ function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string
230
246
  const reached =
231
247
  runs ||
232
248
  (project.targetDependencies?.get(targetName) ?? []).some((dependency) =>
233
- matchingResolvedTargets(dependency, project.targets).some(visit),
249
+ matchingResolvedTargets(dependency, project.targets, targetNames).some(visit),
234
250
  );
235
251
  visiting.delete(targetName);
236
252
  return reached;
@@ -244,6 +260,7 @@ function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string
244
260
  * inference uses; the child list is the graph, not a hand-written crate list.
245
261
  */
246
262
  function cargoTestPackageChildren(project: ResolvedProjectTargets): string[] {
263
+ const targetNames = [...project.targets];
247
264
  const packages = new Set<string>();
248
265
  const visiting = new Set<string>();
249
266
  const visit = (targetName: string): void => {
@@ -256,7 +273,7 @@ function cargoTestPackageChildren(project: ResolvedProjectTargets): string[] {
256
273
  packages.add(pkg);
257
274
  }
258
275
  for (const dependency of project.targetDependencies?.get(targetName) ?? []) {
259
- for (const matched of matchingResolvedTargets(dependency, project.targets)) {
276
+ for (const matched of matchingResolvedTargets(dependency, project.targets, targetNames)) {
260
277
  visit(matched);
261
278
  }
262
279
  }
@@ -306,11 +323,12 @@ function commandOf(project: ResolvedProjectTargets, targetName: string): string
306
323
  if (options === undefined || options === null) {
307
324
  return undefined;
308
325
  }
309
- const command = (options as Record<string, unknown>).command;
326
+ const command = options.command;
310
327
  return typeof command === 'string' ? command : undefined;
311
328
  }
312
329
 
313
330
  function resolvedTargetReaches(project: ResolvedProjectTargets, from: string, goal: string): boolean {
331
+ const targetNames = [...project.targets];
314
332
  const visiting = new Set<string>();
315
333
  const visit = (targetName: string): boolean => {
316
334
  if (targetName === goal) {
@@ -321,7 +339,7 @@ function resolvedTargetReaches(project: ResolvedProjectTargets, from: string, go
321
339
  }
322
340
  visiting.add(targetName);
323
341
  const reached = (project.targetDependencies?.get(targetName) ?? []).some((dependency) =>
324
- matchingResolvedTargets(dependency, project.targets).some(visit),
342
+ matchingResolvedTargets(dependency, project.targets, targetNames).some(visit),
325
343
  );
326
344
  visiting.delete(targetName);
327
345
  return reached;
@@ -360,8 +378,10 @@ export function checkBoundedTestTargetPolicy(
360
378
  * bounded `bun test` command. A `commands` array (a multi-runner gate) would
361
379
  * be flattened to the default command — deleting the very checks the target
362
380
  * exists to run — and a non-bun runner (cargo, go) would inherit wall-clock
363
- * bounds scaled for bun suites. Those targets are left in place for the check
364
- * to report, so restructuring them stays a human decision.
381
+ * bounds scaled for bun suites. A no-op aggregate already delegates execution
382
+ * to its legs; adding a runner would execute the suite a second time. Those
383
+ * targets are left in place for the check to report, so restructuring them
384
+ * stays a human decision.
365
385
  */
366
386
  function boundableTestTarget(
367
387
  packageJson: BoundedTestPolicyPackageJson,
@@ -371,8 +391,8 @@ function boundableTestTarget(
371
391
  if (!isRecord(target)) {
372
392
  return true;
373
393
  }
374
- if (isNoopAggregateTarget(target)) {
375
- return true;
394
+ if (target.executor === 'nx:noop' || isNoopAggregateTarget(target)) {
395
+ return false;
376
396
  }
377
397
  const targetOptions = isRecord(target.options) ? target.options : undefined;
378
398
  if (targetOptions && Array.isArray(targetOptions.commands)) {
@@ -389,7 +409,7 @@ function isNoopAggregateTarget(target: Record<string, unknown>): boolean {
389
409
  if (typeof target.command === 'string' || (isRecord(target.options) && typeof target.options.command === 'string')) {
390
410
  return false;
391
411
  }
392
- return Array.isArray(target.dependsOn) && target.dependsOn.length > 0;
412
+ return Array.isArray(target.dependsOn);
393
413
  }
394
414
 
395
415
  function isPositiveSafeInteger(value: unknown): value is number {
@@ -405,18 +425,55 @@ function isBoundedExecutionTarget(executor: unknown, rawOptions: unknown, allowe
405
425
  typeof command === 'string' &&
406
426
  command.length > 0 &&
407
427
  isPackageTestScriptRunnerCommand(command) === false &&
408
- command === ensureBunTestTimeoutFlag(command) &&
428
+ // A test leg is bounded by progress alone: a wall-clock ceiling fails a suite that is only slow.
429
+ rawOptions.timeoutMs === undefined &&
430
+ isPositiveSafeInteger(rawOptions.idleTimeoutMs) &&
431
+ bunTestTimeoutIsBounded(command, rawOptions.idleTimeoutMs) &&
409
432
  typeof rawOptions.cwd === 'string' &&
410
- allowedCwds.has(rawOptions.cwd) &&
411
- isPositiveSafeInteger(rawOptions.timeoutMs) &&
433
+ // `bun test` walks its working directory looking for test files, so it must start where that walk is cheap: the
434
+ // project root or its `src/`. Any other command names what it runs and has no walk to bound. A cargo workspace's
435
+ // per-crate nextest legs run from the workspace root, which no member project owns, and a gate may run a script
436
+ // that lives in another project; both are bounded by their progress bound alone.
437
+ (!BUN_TEST_PREFIX.test(command) || allowedCwds.has(rawOptions.cwd)) &&
412
438
  isPositiveSafeInteger(rawOptions.killAfterMs)
413
439
  );
414
440
  }
415
441
 
442
+ /** A bun leg's per-test `--timeout` must fire before the leg's progress bound would. */
443
+ function bunTestTimeoutIsBounded(command: string, idleTimeoutMs: number): boolean {
444
+ if (!BUN_TEST_PREFIX.test(command)) {
445
+ return true;
446
+ }
447
+ let found = false;
448
+ for (const match of command.matchAll(/(?:^|\s)--timeout(?==|\s|$)(?:=(\S*)|\s+(\S+))?/g)) {
449
+ const value = match[1] ?? match[2];
450
+ const perTestTimeoutMs = Number(value);
451
+ if (
452
+ value === undefined ||
453
+ !/^\d+$/.test(value) ||
454
+ !isPositiveSafeInteger(perTestTimeoutMs) ||
455
+ perTestTimeoutMs > idleTimeoutMs
456
+ ) {
457
+ return false;
458
+ }
459
+ found = true;
460
+ }
461
+ return found;
462
+ }
463
+
464
+ function isTestLegTargetName(name: string): boolean {
465
+ return (
466
+ name !== CARGO_TEST_COMPILE_TARGET &&
467
+ name !== CARGO_TEST_ARCHIVE_TARGET &&
468
+ (isTestRunnerTargetName(name) || name.endsWith('-test'))
469
+ );
470
+ }
471
+
416
472
  function resolvedAggregateTestIsBounded(project: ResolvedProjectTargets | undefined): boolean {
417
473
  if (!project?.targetDependencies || !project.targetExecutors || !project.targetOptions) {
418
474
  return false;
419
475
  }
476
+ const targetNames = [...project.targets];
420
477
  const visiting = new Set<string>();
421
478
  const verified = new Map<string, boolean>();
422
479
  const allowedCwds = new Set(
@@ -433,18 +490,36 @@ function resolvedAggregateTestIsBounded(project: ResolvedProjectTargets | undefi
433
490
  }
434
491
  visiting.add(targetName);
435
492
  const executor = project.targetExecutors?.get(targetName);
436
- let valid: boolean;
437
- if (executor !== undefined && executor !== 'nx:noop') {
438
- valid = isBoundedExecutionTarget(executor, project.targetOptions?.get(targetName), allowedCwds);
439
- } else {
440
- const dependencies = project.targetDependencies?.get(targetName) ?? [];
441
- valid =
442
- dependencies.length > 0 &&
443
- dependencies.every((dependency) => {
444
- const matches = matchingResolvedTargets(dependency, project.targets);
445
- return matches.length > 0 && matches.every(visit);
446
- });
493
+ const executes = executor !== undefined && executor !== 'nx:noop';
494
+ let valid = !executes || isBoundedExecutionTarget(executor, project.targetOptions?.get(targetName), allowedCwds);
495
+ let hasTestLeg = executes;
496
+ if (valid) {
497
+ for (const dependency of project.targetDependencies?.get(targetName) ?? []) {
498
+ if (dependency.startsWith('^')) {
499
+ continue;
500
+ }
501
+ const matches = matchingResolvedTargets(dependency, project.targets, targetNames);
502
+ if (matches.length === 0 && isTestLegTargetName(dependency)) {
503
+ valid = false;
504
+ break;
505
+ }
506
+ for (const matched of matches) {
507
+ // Nx omits a task's dependency on itself, including a glob that selects it.
508
+ if (matched === targetName || !isTestLegTargetName(matched)) {
509
+ continue;
510
+ }
511
+ hasTestLeg = true;
512
+ if (!visit(matched)) {
513
+ valid = false;
514
+ break;
515
+ }
516
+ }
517
+ if (!valid) {
518
+ break;
519
+ }
520
+ }
447
521
  }
522
+ valid = valid && hasTestLeg;
448
523
  visiting.delete(targetName);
449
524
  verified.set(targetName, valid);
450
525
  return valid;
@@ -453,15 +528,20 @@ function resolvedAggregateTestIsBounded(project: ResolvedProjectTargets | undefi
453
528
  return visit('test');
454
529
  }
455
530
 
456
- function matchingResolvedTargets(dependency: string, targets: ReadonlySet<string>): string[] {
531
+ function matchingResolvedTargets(dependency: string, targets: ReadonlySet<string>, targetNames: string[]): string[] {
457
532
  if (dependency.startsWith('^')) {
458
533
  return [];
459
534
  }
460
- if (!dependency.startsWith('*')) {
461
- return targets.has(dependency) ? [dependency] : [];
535
+ if (targets.has(dependency)) {
536
+ return [dependency];
462
537
  }
463
- const suffix = dependency.slice(1);
464
- return [...targets].filter((targetName) => targetName.endsWith(suffix));
538
+ const matches: string[] = [];
539
+ for (const { target } of expandWildcardTargetConfiguration({ target: dependency, projects: [] }, targetNames)) {
540
+ if (targets.has(target)) {
541
+ matches.push(target);
542
+ }
543
+ }
544
+ return matches;
465
545
  }
466
546
 
467
547
  function resolvedProjectFor(
@@ -602,10 +682,6 @@ function readPackageJson(path: string): BoundedTestPolicyPackageJson {
602
682
  };
603
683
  }
604
684
 
605
- function writePackageJson(path: string, packageJson: BoundedTestPolicyPackageJson): void {
606
- writeFileSync(path, `${JSON.stringify(packageJson, null, 2)}\n`);
607
- }
608
-
609
685
  function readProjectJson(path: string): BoundedTestPolicyProjectJson {
610
686
  const parsed = readJsonObject(path);
611
687
  return {
@@ -634,10 +710,6 @@ function readTargets(value: unknown): Record<string, Record<string, unknown>> |
634
710
  return targets;
635
711
  }
636
712
 
637
- function writeProjectJson(path: string, projectJson: BoundedTestPolicyProjectJson): void {
638
- writeFileSync(path, `${JSON.stringify(projectJson, null, 2)}\n`);
639
- }
640
-
641
713
  function hasTestEntrypoint(
642
714
  packageJson: BoundedTestPolicyPackageJson,
643
715
  projectJson: BoundedTestPolicyProjectJson | undefined,
@@ -0,0 +1,115 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import type { ProjectGraph } from 'nx/src/config/project-graph';
3
+ import type { TargetConfiguration } from 'nx/src/devkit-exports.js';
4
+ import { BuildStateOutputError, refuseOutputsUnderBuildState } from './build-state-output-policy.js';
5
+
6
+ const workspaceRoot = '/checkout';
7
+ const buildStatePaths = [
8
+ { checkout: 'target', volume: 'target' },
9
+ { checkout: '.nx/cache', volume: 'nx/cache' },
10
+ { checkout: '.nx/workspace-data', volume: 'nx/workspace-data' },
11
+ { checkout: 'packages/nested/out/cargo', volume: 'cargo/nested' },
12
+ { checkout: '.codegraph', volume: 'codegraph' },
13
+ ];
14
+
15
+ function graph(target: TargetConfiguration, root = 'packages/example'): ProjectGraph {
16
+ return {
17
+ nodes: { example: { name: 'example', type: 'lib', data: { root, targets: { archive: target } } } },
18
+ dependencies: { example: [] },
19
+ };
20
+ }
21
+
22
+ function validate(outputs: string[]): void {
23
+ refuseOutputsUnderBuildState(graph({ outputs }), buildStatePaths, workspaceRoot);
24
+ }
25
+
26
+ describe('build-state Nx output policy', () => {
27
+ it('refuses an output at or under every contributed build-state path', () => {
28
+ for (const { checkout } of buildStatePaths) {
29
+ for (const output of [checkout, `${checkout}/artifact`, `${checkout}/**/*`]) {
30
+ expect(() => validate([`{workspaceRoot}/${output}`])).toThrow(BuildStateOutputError);
31
+ }
32
+ }
33
+ });
34
+
35
+ it('refuses ancestors whose restore can remove fixed build-state links', () => {
36
+ for (const output of ['{workspaceRoot}', '{workspaceRoot}/.nx', '{workspaceRoot}/packages/nested/out']) {
37
+ expect(() => validate([output])).toThrow(BuildStateOutputError);
38
+ }
39
+ });
40
+
41
+ it('refuses glob prefixes that can cover build state, including an unbounded glob', () => {
42
+ for (const output of ['{workspaceRoot}/**/*', '{workspaceRoot}/packages/*/out', '{workspaceRoot}/target-*']) {
43
+ expect(() => validate([output])).toThrow(BuildStateOutputError);
44
+ }
45
+ });
46
+
47
+ it('resolves absolute outputs against the supplied workspace root', () => {
48
+ for (const output of ['/checkout/target/archive', '/checkout/packages/nested', '/checkout/**/archive', '/']) {
49
+ expect(() => validate([output])).toThrow(BuildStateOutputError);
50
+ }
51
+ expect(() => validate(['/elsewhere/target/archive'])).not.toThrow();
52
+ });
53
+
54
+ it('allows disjoint source-tree archive and compiler outputs without prefix false positives', () => {
55
+ expect(() =>
56
+ validate([
57
+ '{workspaceRoot}/.cache/nextest/archive.tar.zst',
58
+ '{projectRoot}/dist/**/*',
59
+ '{workspaceRoot}/targeted/artifact',
60
+ '{workspaceRoot}/packages/nested/out/cargo-docs',
61
+ '{workspaceRoot}/.nx-other/**/*',
62
+ ]),
63
+ ).not.toThrow();
64
+ });
65
+
66
+ it('uses stock Nx interpolation for project, options and every configuration', () => {
67
+ const resolved = graph({
68
+ outputs: ['{options.outputPath}'],
69
+ options: { outputPath: 'dist/example' },
70
+ configurations: {
71
+ unsafe: { outputPath: 'packages/nested/out/cargo/archive' },
72
+ safe: { outputPath: 'dist/safe' },
73
+ },
74
+ });
75
+ try {
76
+ refuseOutputsUnderBuildState(resolved, buildStatePaths, workspaceRoot);
77
+ throw new Error('unsafe configured output was accepted');
78
+ } catch (error) {
79
+ expect(error).toBeInstanceOf(BuildStateOutputError);
80
+ if (!(error instanceof BuildStateOutputError)) throw error;
81
+ expect(error.findings).toEqual([
82
+ {
83
+ project: 'example',
84
+ target: 'archive',
85
+ configuration: 'unsafe',
86
+ output: 'packages/nested/out/cargo/archive',
87
+ buildStatePath: 'packages/nested/out/cargo',
88
+ },
89
+ ]);
90
+ expect(error.message).toContain('example:archive:unsafe');
91
+ }
92
+ expect(() =>
93
+ refuseOutputsUnderBuildState(
94
+ graph({ outputs: ['{projectRoot}/artifact'] }, 'target'),
95
+ buildStatePaths,
96
+ workspaceRoot,
97
+ ),
98
+ ).toThrow(BuildStateOutputError);
99
+ });
100
+
101
+ it('checks stock Nx outputPath fallback and the resolved graph override rather than plugin declarations', () => {
102
+ expect(() =>
103
+ refuseOutputsUnderBuildState(
104
+ graph({ options: { outputPath: 'target/archive' } }),
105
+ buildStatePaths,
106
+ workspaceRoot,
107
+ ),
108
+ ).toThrow(BuildStateOutputError);
109
+ const resolved = graph({ outputs: ['{workspaceRoot}/.cache/nextest/archive.tar.zst'] });
110
+ const project = resolved.nodes.example;
111
+ if (!project) throw new Error('fixture project missing');
112
+ project.data.targets = { archive: { outputs: ['{workspaceRoot}/target/overridden'] } };
113
+ expect(() => refuseOutputsUnderBuildState(resolved, buildStatePaths, workspaceRoot)).toThrow(BuildStateOutputError);
114
+ });
115
+ });
@@ -0,0 +1,90 @@
1
+ import { posix } from 'node:path';
2
+ import type { ProjectGraph } from 'nx/src/config/project-graph';
3
+ import { getOutputsForTargetAndConfiguration, interpolate } from 'nx/src/tasks-runner/utils';
4
+
5
+ /** The read-only path records returned by `cowshed build-state --json`. */
6
+ export interface BuildStatePath {
7
+ readonly checkout: string;
8
+ readonly volume: string;
9
+ }
10
+
11
+ export interface BuildStateOutputFinding {
12
+ readonly project: string;
13
+ readonly target: string;
14
+ readonly configuration: string | undefined;
15
+ readonly output: string;
16
+ readonly buildStatePath: string;
17
+ }
18
+
19
+ export class BuildStateOutputError extends Error {
20
+ constructor(readonly findings: readonly BuildStateOutputFinding[]) {
21
+ super(
22
+ `Nx outputs must not cover cowshed build-state paths:\n${findings
23
+ .map(
24
+ ({ project, target, configuration, output, buildStatePath }) =>
25
+ ` ${project}:${target}${configuration ? `:${configuration}` : ''}: ${JSON.stringify(output)} covers ${JSON.stringify(buildStatePath)}`,
26
+ )
27
+ .join('\n')}`,
28
+ );
29
+ this.name = 'BuildStateOutputError';
30
+ }
31
+ }
32
+
33
+ function contains(parent: string, child: string): boolean {
34
+ return parent === child || child.startsWith(parent.endsWith('/') ? parent : `${parent}/`);
35
+ }
36
+
37
+ /** The non-glob directory prefix, conservatively including every possible glob match. */
38
+ function staticPrefix(output: string): string {
39
+ const parts = output.replaceAll('\\', '/').split('/');
40
+ const firstGlob = parts.findIndex((part) => /[*?[\]{}()!]/.test(part));
41
+ return firstGlob < 0 ? parts.join('/') : parts.slice(0, firstGlob).join('/') || '.';
42
+ }
43
+
44
+ /**
45
+ * Enforce spec 16 at the consuming repository's Nx lint boundary, using its already resolved
46
+ * graph (including project overrides). Never construct a graph during cowshed job admission.
47
+ * An Nx restore may remove an output before restoring it, so ancestors and overlapping glob
48
+ * prefixes are unsafe too: they can replace the fixed links even without naming a tool's files.
49
+ */
50
+ export function refuseOutputsUnderBuildState(
51
+ graph: ProjectGraph,
52
+ buildStatePaths: readonly BuildStatePath[],
53
+ workspaceRoot: string,
54
+ ): void {
55
+ const root = workspaceRoot.replaceAll('\\', '/');
56
+ if (!posix.isAbsolute(root)) throw new Error('build-state output validation requires an absolute workspace root');
57
+ const paths = buildStatePaths.map(({ checkout }) => ({ checkout, absolute: posix.resolve(root, checkout) }));
58
+ const findings: BuildStateOutputFinding[] = [];
59
+ for (const [project, node] of Object.entries(graph.nodes)) {
60
+ for (const [target, options] of Object.entries(node.data.targets ?? {})) {
61
+ const configurations: (string | undefined)[] = [undefined, ...Object.keys(options.configurations ?? {})];
62
+ for (const configuration of configurations) {
63
+ // Nx's task helper rejects root globs and absolute declarations before expanding
64
+ // them. This lint must name the overlapping build path even for those declarations.
65
+ const outputs = options.outputs
66
+ ? options.outputs
67
+ .map((output) =>
68
+ interpolate(output, {
69
+ workspaceRoot: root,
70
+ projectRoot: node.data.root,
71
+ projectName: node.name,
72
+ project: { ...node.data, name: node.name },
73
+ options: { ...options.options, ...(configuration ? options.configurations?.[configuration] : {}) },
74
+ }),
75
+ )
76
+ .filter((output) => output && !/{(projectRoot|workspaceRoot|(options.*))}/.test(output))
77
+ : getOutputsForTargetAndConfiguration({ project, target, configuration }, {}, node);
78
+ for (const output of outputs) {
79
+ const prefix = posix.resolve(root, staticPrefix(output));
80
+ for (const path of paths) {
81
+ if (contains(prefix, path.absolute) || contains(path.absolute, prefix)) {
82
+ findings.push({ project, target, configuration, output, buildStatePath: path.checkout });
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ if (findings.length) throw new BuildStateOutputError(findings);
90
+ }
@@ -1,10 +1,58 @@
1
1
  import { describe, expect, it } from 'bun:test';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { copyFile, mkdtemp, rm, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
2
6
 
3
7
  describe('Bun bootstrap imports', () => {
4
8
  it('imports the main plugin entry point', async () => {
5
- const plugin = await import('./index.js');
9
+ // Module loading is the boundary under test; the public entry must select the transformed product.
10
+ const plugin = await import('@smoothbricks/nx-plugin');
6
11
  expect(plugin.createNodesV2).toBeDefined();
7
12
  expect(Array.isArray(plugin.createNodesV2)).toBe(true);
13
+ expect(typeof plugin.preTasksExecution).toBe('function');
14
+ expect(typeof plugin.postTasksExecution).toBe('function');
15
+ expect(typeof plugin.default.preTasksExecution).toBe('function');
16
+ expect(typeof plugin.default.postTasksExecution).toBe('function');
17
+ });
18
+
19
+ it('refuses a cold missing bootstrap product instead of returning an empty graph', async () => {
20
+ const root = await mkdtemp(join(tmpdir(), 'nx-plugin-bootstrap-'));
21
+ try {
22
+ await writeFile(join(root, 'package.json'), '{"type":"module"}\n');
23
+ await copyFile(join(import.meta.dir, '../loader.js'), join(root, 'loader.js'));
24
+ const script = `await import(${JSON.stringify(join(root, 'loader.js'))})`;
25
+ const child = spawnSync(process.execPath, ['--no-install', '-e', script], { cwd: root, encoding: 'utf8' });
26
+ expect(child.status).not.toBe(0);
27
+ expect(child.stderr).toContain('The Nx plugin bootstrap product is missing:');
28
+ expect(child.stderr).toContain('ttsc -p packages/nx-plugin/tsconfig.lib.json --emit');
29
+ } finally {
30
+ await rm(root, { recursive: true, force: true });
31
+ }
32
+ });
33
+
34
+ it('loads the public policy caller closure without a transform preload', () => {
35
+ const script = [
36
+ 'const { fileURLToPath } = await import("node:url");',
37
+ 'const { handleImport } = await import("nx/src/utils/handle-import.js");',
38
+ 'const root = await handleImport(fileURLToPath(import.meta.resolve("@smoothbricks/nx-plugin")));',
39
+ 'if (!Array.isArray(root.createNodesV2)) throw new Error("the compiled plugin entry is incomplete");',
40
+ 'const policy = await import("@smoothbricks/nx-plugin/workspace-config-policy");',
41
+ 'const bounded = await import("@smoothbricks/nx-plugin/bounded-test-policy");',
42
+ 'const targets = await import("@smoothbricks/nx-plugin/package-target-policy");',
43
+ 'const eslint = await import("@smoothbricks/nx-plugin/eslint-file-set");',
44
+ 'if (!policy.checkWorkspaceConfig({plugins:[{plugin:42}]}).some(issue => issue.message.startsWith("plugins is malformed:"))) throw new Error("the public policy did not validate");',
45
+ 'if (typeof bounded.applyBoundedTestTargetPolicy !== "function" || typeof targets.applyPackageTargetPolicy !== "function") throw new Error("the compiled caller closure is incomplete");',
46
+ 'if (!eslint.isEslintFileSet({command:"eslint src/fixture.ts",files:["src/fixture.ts"]}) || eslint.isEslintFileSet({command:42,files:[]})) throw new Error("the compiled ESLint file-set owner did not validate");',
47
+ ].join('\n');
48
+ for (const conditions of [[], ['--conditions=development']]) {
49
+ const child = spawnSync(
50
+ process.execPath,
51
+ ['--config=/dev/null', '--no-env-file', '--no-install', ...conditions, '-e', script],
52
+ { cwd: join(import.meta.dir, '../../cli'), encoding: 'utf8' },
53
+ );
54
+ expect(child.status, child.stdout + child.stderr).toBe(0);
55
+ }
8
56
  });
9
57
 
10
58
  it('imports bounded-test-policy', async () => {
@@ -17,16 +65,22 @@ describe('Bun bootstrap imports', () => {
17
65
  expect(typeof policy.resolveTestCommand).toBe('function');
18
66
  expect(typeof policy.ensureBunTestTimeoutFlag).toBe('function');
19
67
  expect(typeof policy.BOUNDED_TEST_EXECUTOR).toBe('string');
20
- expect(typeof policy.BOUNDED_TEST_TIMEOUT_MS).toBe('number');
68
+ expect(typeof policy.BOUNDED_TEST_IDLE_TIMEOUT_MS).toBe('number');
21
69
  expect(typeof policy.BOUNDED_TEST_KILL_AFTER_MS).toBe('number');
22
70
  expect(typeof policy.BOUNDED_TEST_PER_TEST_TIMEOUT_MS).toBe('number');
23
71
  });
24
72
 
25
73
  it('imports workspace-config-policy', async () => {
26
- const policy = await import('./workspace-config-policy.js');
74
+ // Module loading is the boundary under test; no test preload may mask a raw public policy entry.
75
+ const policy = await import('@smoothbricks/nx-plugin/workspace-config-policy');
27
76
  expect(typeof policy.checkWorkspaceConfigPolicy).toBe('function');
28
77
  expect(typeof policy.applyWorkspaceConfigPolicy).toBe('function');
29
78
  expect(Array.isArray(policy.BUILD_OUTPUT_DEPENDENCIES)).toBe(true);
79
+ expect(
80
+ policy
81
+ .checkWorkspaceConfig({ plugins: [{ plugin: 42 }] })
82
+ .some((issue) => issue.message.startsWith('plugins is malformed:')),
83
+ ).toBe(true);
30
84
  });
31
85
 
32
86
  it('imports release-config-policy', async () => {
@@ -0,0 +1,47 @@
1
+ import { expect, test } from 'bun:test';
2
+ import { createHash } from 'node:crypto';
3
+ import { DependencyType } from 'nx/src/config/project-graph';
4
+ import { getBunTextLockfileDependencies, getBunTextLockfileNodes } from 'nx/src/plugins/js/lock-file/bun-parser';
5
+ import type { CreateDependenciesContext } from 'nx/src/project-graph/plugins';
6
+
7
+ // A local file package is not an Nx workspace merely because Bun copied it.
8
+ // Keep the real parser and native hasher: these assertions fail on stock Nx 23.2.1.
9
+ test('Bun file packages retain their external node and consumer edge without externalizing actual workspaces', () => {
10
+ const lock = JSON.stringify({
11
+ lockfileVersion: 3,
12
+ workspaces: {
13
+ '': {
14
+ name: 'file-package-host',
15
+ dependencies: {
16
+ consumer: '1.0.0',
17
+ '@fixture/sdk': 'file:./.managed/sdk',
18
+ '@fixture/worker': 'file:./packages/worker',
19
+ },
20
+ },
21
+ 'packages/worker': { name: '@fixture/worker', version: '1.0.0' },
22
+ },
23
+ packages: {
24
+ consumer: ['consumer@1.0.0', '', { dependencies: { '@fixture/sdk': 'file:.managed/sdk' } }, 'sha512-consumer'],
25
+ '@fixture/sdk': ['@fixture/sdk@file:.managed/sdk', {}],
26
+ '@fixture/worker': ['@fixture/worker@file:./packages/worker', {}],
27
+ },
28
+ });
29
+ const hash = createHash('sha256').update(lock).digest('hex');
30
+ const nodes = getBunTextLockfileNodes(lock, hash);
31
+ expect(nodes['npm:@fixture/sdk@file:.managed/sdk']?.data.packageName).toBe('@fixture/sdk');
32
+ expect(nodes['npm:@fixture/sdk@file:.managed/sdk']?.data.version).toBe('file:.managed/sdk');
33
+ expect(Object.values(nodes).some((node) => node.data.packageName === '@fixture/worker')).toBe(false);
34
+ const context: CreateDependenciesContext = {
35
+ externalNodes: nodes,
36
+ projects: { worker: { root: 'packages/worker', name: 'worker' } },
37
+ nxJsonConfiguration: {},
38
+ fileMap: { projectFileMap: {}, nonProjectFiles: [] },
39
+ filesToProcess: { projectFileMap: {}, nonProjectFiles: [] },
40
+ workspaceRoot: process.cwd(),
41
+ };
42
+ expect(getBunTextLockfileDependencies(lock, hash, context)).toContainEqual({
43
+ source: 'npm:consumer@1.0.0',
44
+ target: 'npm:@fixture/sdk@file:.managed/sdk',
45
+ type: DependencyType.static,
46
+ });
47
+ });