@smoothbricks/nx-plugin 0.4.26 → 0.4.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/README.md +994 -117
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +15 -73
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +3 -2
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +16 -15
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +43 -6
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +309 -73
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +101 -5
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +291 -10
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +207 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +576 -202
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +370 -138
  102. package/dist/managed-files/ci-workflow.d.ts +13 -0
  103. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.js +44 -13
  105. package/dist/managed-files/files.d.ts +7 -1
  106. package/dist/managed-files/files.d.ts.map +1 -1
  107. package/dist/managed-files/files.js +62 -8
  108. package/dist/managed-files/json-edit.d.ts +21 -0
  109. package/dist/managed-files/json-edit.d.ts.map +1 -0
  110. package/dist/managed-files/json-edit.js +295 -0
  111. package/dist/managed-files/managed-format.d.ts +33 -1
  112. package/dist/managed-files/managed-format.d.ts.map +1 -1
  113. package/dist/managed-files/managed-format.js +82 -2
  114. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  115. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  116. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  117. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/publish-workflow.js +231 -48
  119. package/dist/managed-files/tree.d.ts +5 -0
  120. package/dist/managed-files/tree.d.ts.map +1 -1
  121. package/dist/managed-files/tree.js +5 -3
  122. package/dist/manifest-hash.d.ts.map +1 -1
  123. package/dist/manifest-hash.js +2 -5
  124. package/dist/nextest-code-bound.d.ts +62 -0
  125. package/dist/nextest-code-bound.d.ts.map +1 -0
  126. package/dist/nextest-code-bound.js +154 -0
  127. package/dist/nextest-extraction.d.ts +24 -8
  128. package/dist/nextest-extraction.d.ts.map +1 -1
  129. package/dist/nextest-extraction.js +42 -7
  130. package/dist/package-target-policy.d.ts.map +1 -1
  131. package/dist/package-target-policy.js +3 -5
  132. package/dist/release-config-policy.d.ts.map +1 -1
  133. package/dist/release-config-policy.js +3 -5
  134. package/dist/runtime-input.d.ts +14 -0
  135. package/dist/runtime-input.d.ts.map +1 -0
  136. package/dist/runtime-input.js +15 -0
  137. package/dist/rust-tokens.d.ts +11 -0
  138. package/dist/rust-tokens.d.ts.map +1 -0
  139. package/dist/rust-tokens.js +81 -0
  140. package/dist/task-results.d.ts +6 -0
  141. package/dist/task-results.d.ts.map +1 -0
  142. package/dist/task-results.js +61 -0
  143. package/dist/test-program.d.ts +54 -0
  144. package/dist/test-program.d.ts.map +1 -0
  145. package/dist/test-program.js +292 -0
  146. package/dist/test-timings.d.ts +71 -0
  147. package/dist/test-timings.d.ts.map +1 -0
  148. package/dist/test-timings.js +393 -0
  149. package/dist/test-walk-policy.d.ts +103 -0
  150. package/dist/test-walk-policy.d.ts.map +1 -0
  151. package/dist/test-walk-policy.js +657 -0
  152. package/dist/testing.d.ts +177 -0
  153. package/dist/testing.d.ts.map +1 -0
  154. package/dist/testing.js +824 -0
  155. package/dist/type-guards.d.ts +3 -0
  156. package/dist/type-guards.d.ts.map +1 -0
  157. package/dist/type-guards.js +4 -0
  158. package/dist/typecheck-test-policy.d.ts +8 -5
  159. package/dist/typecheck-test-policy.d.ts.map +1 -1
  160. package/dist/typecheck-test-policy.js +113 -100
  161. package/dist/workspace-config-policy.d.ts +8 -0
  162. package/dist/workspace-config-policy.d.ts.map +1 -1
  163. package/dist/workspace-config-policy.js +175 -63
  164. package/dist/workspace-index.d.ts +12 -0
  165. package/dist/workspace-index.d.ts.map +1 -0
  166. package/dist/workspace-index.js +17 -0
  167. package/dist/workspace-manifest.d.ts +37 -0
  168. package/dist/workspace-manifest.d.ts.map +1 -1
  169. package/executors.json +5 -0
  170. package/loader.js +13 -11
  171. package/managed/raw/envrc +33 -67
  172. package/managed/raw/git-format-staged.yml +30 -35
  173. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  174. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  175. package/managed/raw/tooling/direnv/developer-links.ts +569 -11
  176. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
  177. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  178. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  179. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  180. package/managed/raw/tooling/direnv/repo-path +14 -2
  181. package/managed/raw/tooling/direnv/setup-environment.ts +1146 -159
  182. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  183. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  184. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  185. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  186. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  187. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  188. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  189. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  190. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  191. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  192. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  194. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  196. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  197. package/managed/templates/github/workflows/managed-files.yml +1 -2
  198. package/nextest.toml +8 -41
  199. package/package.json +74 -12
  200. package/runtime-input.sh +81 -0
  201. package/src/__tests__/counted-cargo.ts +33 -14
  202. package/src/__tests__/fixture-nx-env.ts +111 -46
  203. package/src/__tests__/progress-clock.ts +43 -0
  204. package/src/__tests__/runtime-input.ts +23 -0
  205. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  206. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  207. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  208. package/src/bin/smoo-nx-exec.ts +16 -74
  209. package/src/bin/smoo-nx-failures.ts +4 -0
  210. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  211. package/src/bin/smoo-nx-test-walks.ts +42 -0
  212. package/src/bounded-test-policy.test.ts +268 -21
  213. package/src/bounded-test-policy.ts +114 -42
  214. package/src/build-state-output-policy.test.ts +115 -0
  215. package/src/build-state-output-policy.ts +90 -0
  216. package/src/bun-bootstrap.test.ts +57 -3
  217. package/src/bun-file-packages.test.ts +47 -0
  218. package/src/cargo-closure-input.test.ts +138 -66
  219. package/src/cargo-closure-input.ts +17 -15
  220. package/src/cargo-dev-profile.ts +137 -0
  221. package/src/cargo-resolve-cache.test.ts +70 -1
  222. package/src/cargo-source-hash.test.ts +193 -97
  223. package/src/cargo-source-hash.ts +345 -68
  224. package/src/cargo-toolchain-policy.ts +6 -0
  225. package/src/cargo-workspace.test.ts +320 -0
  226. package/src/cargo-workspace.ts +336 -10
  227. package/src/cross-check-policy.test.ts +59 -1
  228. package/src/cross-check-policy.ts +25 -6
  229. package/src/disk-command-policy.test.ts +61 -0
  230. package/src/disk-command-policy.ts +107 -0
  231. package/src/ensure-built-receipt.test.ts +184 -0
  232. package/src/ensure-built-receipt.ts +263 -0
  233. package/src/ensure-built-witness.test.ts +344 -0
  234. package/src/ensure-built-witness.ts +252 -0
  235. package/src/ensure-built.test.ts +1036 -578
  236. package/src/ensure-built.ts +820 -224
  237. package/src/eslint-file-set.ts +9 -0
  238. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  239. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  240. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  241. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  242. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  243. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  244. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  245. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  246. package/src/executors/bounded-exec/executor.ts +565 -67
  247. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  248. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  249. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  250. package/src/executors/bounded-exec/progress.test.ts +79 -0
  251. package/src/executors/bounded-exec/progress.ts +118 -0
  252. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  253. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  254. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  255. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  256. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  257. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  258. package/src/executors/bounded-exec/schema.json +11 -5
  259. package/src/executors/bounded-exec/schema.ts +27 -11
  260. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  261. package/src/executors/bounded-exec/verdict.ts +433 -0
  262. package/src/executors/shard-timings/executor.ts +36 -0
  263. package/src/executors/shard-timings/schema.json +21 -0
  264. package/src/executors/shard-timings/schema.ts +4 -0
  265. package/src/failure-summary.ts +119 -0
  266. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  267. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  268. package/src/generators/create-package/generator.test.ts +6 -0
  269. package/src/generators/create-package/generator.ts +6 -2
  270. package/src/host-controller-wiring.test.ts +31 -0
  271. package/src/index.test.ts +909 -295
  272. package/src/index.ts +441 -143
  273. package/src/linked-snapshots.nx.test.ts +172 -0
  274. package/src/managed-files/ci-workflow.ts +54 -13
  275. package/src/managed-files/files.ts +65 -9
  276. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  277. package/src/managed-files/generator.test.ts +60 -1
  278. package/src/managed-files/json-edit.test.ts +216 -0
  279. package/src/managed-files/json-edit.ts +290 -0
  280. package/src/managed-files/managed-format-json.test.ts +308 -0
  281. package/src/managed-files/managed-format.ts +90 -2
  282. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  283. package/src/managed-files/publish-workflow.ts +285 -67
  284. package/src/managed-files/repo-path.test.ts +129 -0
  285. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  286. package/src/managed-files/tree.ts +11 -3
  287. package/src/manifest-hash.ts +2 -6
  288. package/src/nextest-code-bound.test.ts +155 -0
  289. package/src/nextest-code-bound.ts +195 -0
  290. package/src/nextest-extraction.test.ts +37 -5
  291. package/src/nextest-extraction.ts +51 -9
  292. package/src/nextest-partitions.test.ts +427 -82
  293. package/src/nx-cache-bound.test.ts +5 -10
  294. package/src/nx-cache-restore-mtime.test.ts +170 -0
  295. package/src/nx-daemon-claim.test.ts +277 -0
  296. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  297. package/src/nx-daemon-idle-policy.test.ts +51 -0
  298. package/src/nx-daemon-ignore-files.test.ts +210 -0
  299. package/src/nx-daemon-root-normalization.test.ts +105 -0
  300. package/src/nx-daemon-validity.test.ts +925 -0
  301. package/src/nx-dot-input-policy.test.ts +353 -0
  302. package/src/nx-failure-life-cycles.test.ts +207 -0
  303. package/src/nx-files-archive-racy.test.ts +97 -0
  304. package/src/nx-foreign-workspace-env.test.ts +329 -0
  305. package/src/nx-incomplete-run-summary.test.ts +70 -0
  306. package/src/nx-plugin-load-errors.test.ts +120 -0
  307. package/src/nx-project-resolution-cache.test.ts +176 -0
  308. package/src/nx-raw-inputs.test.ts +166 -0
  309. package/src/nx-resident-graph-workers.test.ts +7 -16
  310. package/src/nx-run-information.test.ts +118 -0
  311. package/src/nx-skipped-task-exit.test.ts +180 -0
  312. package/src/nx-state-location.test.ts +63 -0
  313. package/src/nx-store-resolution.test.ts +26 -25
  314. package/src/nx-task-graph-cycles.test.ts +148 -0
  315. package/src/nx-task-output-lease.test.ts +414 -0
  316. package/src/nx-use-local.test.ts +103 -0
  317. package/src/package-target-policy.ts +3 -6
  318. package/src/release-config-policy.ts +3 -6
  319. package/src/runtime-input.test.ts +215 -0
  320. package/src/runtime-input.ts +17 -0
  321. package/src/rust-tokens.ts +78 -0
  322. package/src/serial-group-wiring.test.ts +326 -0
  323. package/src/task-history-namespace.test.ts +87 -89
  324. package/src/task-results.test.ts +226 -0
  325. package/src/task-results.ts +75 -0
  326. package/src/test-program.test.ts +303 -0
  327. package/src/test-program.ts +341 -0
  328. package/src/test-timings.test.ts +240 -0
  329. package/src/test-timings.ts +311 -0
  330. package/src/test-walk-policy.test.ts +585 -0
  331. package/src/test-walk-policy.ts +731 -0
  332. package/src/testing.test.ts +509 -0
  333. package/src/testing.ts +922 -0
  334. package/src/type-guards.ts +4 -0
  335. package/src/typecheck-test-policy.test.ts +496 -11
  336. package/src/typecheck-test-policy.ts +137 -103
  337. package/src/workspace-config-policy.test.ts +212 -13
  338. package/src/workspace-config-policy.ts +101 -73
  339. package/src/workspace-index.ts +18 -0
  340. package/src/workspace-manifest.ts +41 -0
  341. package/test-timings.json +85 -30
  342. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
  343. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
package/src/index.test.ts CHANGED
@@ -3,17 +3,29 @@ import { chmod, mkdir, mkdtemp, readdir, readFile, realpath, rm, symlink, writeF
3
3
  import { tmpdir } from 'node:os';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
-
7
- import type { CreateNodesContextV2, CreateNodesV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
6
+ import { isEslintFileSet } from '@smoothbricks/nx-plugin/eslint-file-set';
7
+ import type {
8
+ CreateNodesContextV2,
9
+ CreateNodesV2,
10
+ ProjectGraph,
11
+ ProjectGraphProjectNode,
12
+ TargetConfiguration,
13
+ } from 'nx/src/devkit-exports.js';
14
+ import { WorkspaceContext } from 'nx/src/native/index.js';
8
15
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
9
16
  import { createTargetDefaultsResults } from 'nx/src/project-graph/utils/project-configuration/target-defaults.js';
10
17
  import { mergeTargetConfigurations } from 'nx/src/project-graph/utils/project-configuration-utils.js';
18
+ import { createTaskGraph } from 'nx/src/tasks-runner/create-task-graph.js';
19
+ import { getOutputsForTargetAndConfiguration } from 'nx/src/tasks-runner/utils.js';
20
+ import { resetWorkspaceContext } from 'nx/src/utils/workspace-context.js';
11
21
  import { useFixtureCargoHome } from './__tests__/fixture-cargo-home.js';
12
- import { fixtureNxEnv, stopFixtureNxDaemon } from './__tests__/fixture-nx-env.js';
13
- import { BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
22
+ import { runtimeInputValue } from './__tests__/runtime-input.js';
23
+ import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './bounded-test-policy.js';
24
+ import { CARGO_CLOSURE_INPUT } from './cargo-closure-input.js';
14
25
  import { exceptionalTestFilter, packageNameFromCargoTestTarget } from './cargo-workspace.js';
15
26
  import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_LINT_CLIPPY_COMMAND } from './cross-check-policy.js';
16
- import { createNodesV2, createNodesV2ForPlatform } from './index.js';
27
+ import { cargoCommandNpmPackages, createNodesV2, createNodesV2ForPlatform } from './index.js';
28
+ import { NEXTEST_EXTRACTION_DIRECTORY } from './nextest-extraction.js';
17
29
  import { applyWorkspaceConfig, RELEASE_CONFIGURATION } from './workspace-config-policy.js';
18
30
 
19
31
  useFixtureCargoHome();
@@ -25,157 +37,46 @@ const inferTargets: typeof rawInferTargets = async (files, options, context) =>
25
37
  };
26
38
 
27
39
  describe('@smoothbricks/nx-plugin inferred targets', () => {
28
- it('runs Rust-only lint without ESLint and checks JavaScript when sources appear', async () => {
29
- const workspace = await createNxWorkspace();
30
- const root = workspace.context.workspaceRoot;
31
- const repositoryRoot = fileURLToPath(new URL('../../../', import.meta.url));
32
- try {
33
- await symlink(join(repositoryRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
34
- await workspace.write('package.json', '{"name":"lint-workspace","private":true,"workspaces":["packages/*"]}\n');
35
- await workspace.write(
36
- 'nx.json',
37
- JSON.stringify({
38
- plugins: [fileURLToPath(new URL('../dist/index.js', import.meta.url))],
39
- namedInputs: { default: ['{projectRoot}/**/*'] },
40
- targetDefaults: { lint: { cache: true } },
41
- }),
42
- );
43
- await workspace.write(
44
- 'biome.json',
45
- '{"formatter":{"enabled":false},"linter":{"rules":{"suspicious":{"noDebugger":"off"}}}}\n',
46
- );
47
- await workspace.write(
48
- 'eslint.config.mjs',
49
- 'export default [{ files: ["**/*.{js,ts}"], rules: { "no-debugger": "error" } }];\n',
50
- );
51
- await workspace.write('Cargo.toml', '[workspace]\nmembers = ["packages/rust"]\nresolver = "2"\n');
52
- await workspace.write('Cargo.lock', 'version = 4\n\n[[package]]\nname = "lint-crate"\nversion = "0.1.0"\n');
53
- await workspace.write('packages/rust/package.json', '{"name":"rust-fixture"}\n');
54
- await workspace.write(
55
- 'packages/rust/Cargo.toml',
56
- '[package]\nname = "lint-crate"\nversion = "0.1.0"\nedition = "2021"\n',
57
- );
58
- await workspace.write('packages/rust/src/lib.rs', 'pub fn answer() -> u32 {\n 42\n}\n');
59
- const runLint = async () => {
60
- const child = Bun.spawn(['bun', join(repositoryRoot, 'node_modules/.bin/nx'), 'run', 'rust-fixture:lint'], {
61
- cwd: root,
62
- env: {
63
- ...fixtureNxEnv(root),
64
- PATH: `${join(repositoryRoot, 'node_modules/.bin')}:${process.env.PATH ?? ''}`,
65
- RUSTC_WRAPPER: '',
66
- RUSTC_WORKSPACE_WRAPPER: '',
67
- },
68
- stdout: 'pipe',
69
- stderr: 'pipe',
70
- });
71
- const [exitCode, stdout, stderr] = await Promise.all([
72
- child.exited,
73
- new Response(child.stdout).text(),
74
- new Response(child.stderr).text(),
75
- ]);
76
- return { exitCode, output: stdout + stderr };
77
- };
78
- const rustOnly = await runLint();
79
- expect(rustOnly).toMatchObject({ exitCode: 0 });
80
- expect(rustOnly.output).toContain('cargo-lint');
81
- await workspace.write('packages/rust/src/check.js', 'debugger;\n');
82
- const withJavaScript = await runLint();
83
- expect(withJavaScript.exitCode).not.toBe(0);
84
- expect(withJavaScript.output).toContain('no-debugger');
85
- await workspace.write(
86
- 'packages/rust/package.json',
87
- JSON.stringify({
88
- name: 'rust-fixture',
89
- nx: { targets: { lint: { executor: 'nx:run-commands', options: { command: 'printf explicit-lint' } } } },
90
- }),
91
- );
92
- const overridden = await runLint();
93
- expect(overridden).toMatchObject({ exitCode: 0 });
94
- expect(overridden.output).toContain('explicit-lint');
95
- } finally {
96
- await cleanupNxWorkspace(workspace);
97
- }
98
- }, 120_000);
99
-
100
- it('never restores a stale child artifact from the cached build aggregate', async () => {
101
- const workspace = await createNxWorkspace();
102
- const root = workspace.context.workspaceRoot;
103
- const repositoryRoot = fileURLToPath(new URL('../../../', import.meta.url));
40
+ it('never lets a cache hit on the build aggregate restore its children’s dist', async () => {
41
+ const workspace = await createWorkspace();
42
+ // The emitter keys on one input outside its project, as a transform or toolchain does. The
43
+ // aggregate hashes only the project, so a toolchain change moves the emitter's key and not the
44
+ // aggregate's: the aggregate replays from cache right after the emitter reran.
45
+ const emit: TargetConfiguration = {
46
+ executor: 'nx:run-commands',
47
+ cache: true,
48
+ inputs: ['{projectRoot}/source.txt', '{workspaceRoot}/toolchain.txt'],
49
+ outputs: ['{projectRoot}/dist'],
50
+ options: { command: 'mkdir -p dist && cat source.txt ../../toolchain.txt > dist/app.js', cwd: '{projectRoot}' },
51
+ };
52
+ const declared = { 'emit-js': emit };
104
53
  try {
105
- await symlink(join(repositoryRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
106
- await workspace.write(
107
- 'package.json',
108
- '{"name":"aggregate-workspace","private":true,"workspaces":["packages/*"]}\n',
109
- );
110
- await workspace.write(
111
- 'nx.json',
112
- JSON.stringify({
113
- plugins: [fileURLToPath(new URL('../dist/index.js', import.meta.url))],
114
- namedInputs: { default: ['{projectRoot}/**/*'] },
115
- }),
116
- );
117
- // Emitted artifacts are not sources, so the aggregate's own inputs never see them.
118
- await workspace.write('.gitignore', 'dist\n.nx\nnode_modules\n');
119
- await workspace.write('toolchain.txt', 'toolchain-1\n');
120
- await workspace.write('packages/app/source.txt', 'source\n');
121
- // The emitter keys on one input outside its project, as a transform or
122
- // toolchain does. The inferred `build` aggregate hashes only the project,
123
- // so a toolchain change moves the emitter's key and not the aggregate's.
124
54
  await workspace.write(
125
55
  'packages/app/package.json',
126
- JSON.stringify({
127
- name: 'app',
128
- private: true,
129
- nx: {
130
- targets: {
131
- 'emit-js': {
132
- executor: 'nx:run-commands',
133
- cache: true,
134
- inputs: ['{projectRoot}/source.txt', '{workspaceRoot}/toolchain.txt'],
135
- outputs: ['{projectRoot}/dist'],
136
- options: {
137
- command: 'mkdir -p dist && cat source.txt ../../toolchain.txt > dist/app.js',
138
- cwd: '{projectRoot}',
139
- },
140
- },
141
- },
142
- },
143
- }),
144
- );
145
- const build = async () => {
146
- const child = Bun.spawn(['bun', join(repositoryRoot, 'node_modules/.bin/nx'), 'run', 'app:build'], {
147
- cwd: root,
148
- env: {
149
- ...fixtureNxEnv(root),
150
- PATH: `${join(repositoryRoot, 'node_modules/.bin')}:${process.env.PATH ?? ''}`,
151
- },
152
- stdout: 'pipe',
153
- stderr: 'pipe',
154
- });
155
- const [exitCode, stdout, stderr] = await Promise.all([
156
- child.exited,
157
- new Response(child.stdout).text(),
158
- new Response(child.stderr).text(),
159
- ]);
160
- return { exitCode, output: stdout + stderr };
56
+ JSON.stringify({ name: 'app', private: true, nx: { targets: declared } }),
57
+ );
58
+ const targets = await inferProjectTargets(workspace, 'packages/app/package.json');
59
+ const build = resolveDeclaredOverInferred(targets, declared, 'build');
60
+ expect(build?.dependsOn).toContain('emit-js');
61
+ expect(build?.cache).toBe(true);
62
+ if (build === undefined) throw new Error('app infers no build aggregate over emit-js');
63
+
64
+ // A replay restores exactly what Nx resolves as the task's outputs. Left without `outputs`, a
65
+ // `build` target gets Nx's legacy defaults, `{projectRoot}/dist` among them, and the replay
66
+ // puts back the dist the emitter wrote on the run that last produced the aggregate's key.
67
+ const app: ProjectGraphProjectNode = {
68
+ name: 'app',
69
+ type: 'lib',
70
+ data: { root: 'packages/app', targets: { build, 'emit-js': emit } },
161
71
  };
162
- const artifact = () => readFile(join(root, 'packages/app/dist/app.js'), 'utf8');
163
-
164
- const first = await build();
165
- expect(first.exitCode, first.output).toBe(0);
166
- expect(await artifact()).toBe('source\ntoolchain-1\n');
167
-
168
- await workspace.write('toolchain.txt', 'toolchain-2\n');
169
- const second = await build();
170
- expect(second.exitCode, second.output).toBe(0);
171
- // The emitter reran on its new key. The aggregate's key did not move, so
172
- // it replays from cache — and a replay must not put back the dist it
173
- // would have claimed on the first run.
174
- expect(await artifact(), second.output).toBe('source\ntoolchain-2\n');
72
+ expect(getOutputsForTargetAndConfiguration({ project: 'app', target: 'build' }, {}, app)).toEqual([]);
73
+ expect(getOutputsForTargetAndConfiguration({ project: 'app', target: 'emit-js' }, {}, app)).toEqual([
74
+ 'packages/app/dist',
75
+ ]);
175
76
  } finally {
176
- await cleanupNxWorkspace(workspace);
77
+ await workspace.cleanup();
177
78
  }
178
- }, 120_000);
79
+ });
179
80
 
180
81
  it('names standalone package projects from package metadata', async () => {
181
82
  const workspace = await createWorkspace();
@@ -252,6 +153,63 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
252
153
  }
253
154
  });
254
155
 
156
+ it('keys installed patch data and pins without keying patch documentation', async () => {
157
+ const workspace = await createWorkspace();
158
+ try {
159
+ await workspace.write('packages/example/package.json', '{"name":"example","scripts":{"test":"bun test"}}\n');
160
+ await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
161
+ await workspace.write('packages/example/tsconfig.test.json', '{}\n');
162
+ await workspace.write('patches/nx.patch', 'patch-one\n');
163
+ await workspace.write('patches/compiler/PIN', 'revision-one\n');
164
+ await workspace.write('patches/compiler/VERSION', 'version-one\n');
165
+ await workspace.write('patches/README.md', 'documentation-one\n');
166
+ await workspace.write('patches/compiler/notes.md', 'nested documentation-one\n');
167
+ await workspace.write('packages/unrelated/source.ts', 'export const value = 1;\n');
168
+ const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
169
+ const context = new WorkspaceContext(
170
+ workspace.context.workspaceRoot,
171
+ join(workspace.context.workspaceRoot, '.nx/patch-input-context'),
172
+ );
173
+ for (const name of ['tsc-js', 'typecheck', 'typecheck-tests', 'lint']) {
174
+ const inputs = targets[name]?.inputs ?? [];
175
+ const patchInputs = inputs.filter(
176
+ (input): input is string => typeof input === 'string' && input.includes('{workspaceRoot}/patches/'),
177
+ );
178
+ expect(patchInputs.length).toBeGreaterThan(0);
179
+ const positive = patchInputs
180
+ .filter((input) => !input.startsWith('!'))
181
+ .map((input) => input.slice('{workspaceRoot}/'.length));
182
+ const negative = patchInputs
183
+ .filter((input) => input.startsWith('!'))
184
+ .map((input) => input.slice('!{workspaceRoot}/'.length));
185
+ expect(context.glob(positive, negative).sort()).toEqual([
186
+ 'patches/compiler/PIN',
187
+ 'patches/compiler/VERSION',
188
+ 'patches/nx.patch',
189
+ ]);
190
+ const before = context.hashFilesMatchingGlob(positive, negative);
191
+ await workspace.write('patches/README.md', name + ' docs\n');
192
+ await workspace.write('patches/compiler/notes.md', name + ' nested docs\n');
193
+ await workspace.write('packages/unrelated/source.ts', 'export const value = ' + name.length + ';\n');
194
+ context.incrementalUpdate(
195
+ ['patches/README.md', 'patches/compiler/notes.md', 'packages/unrelated/source.ts'],
196
+ [],
197
+ );
198
+ expect(context.hashFilesMatchingGlob(positive, negative)).toBe(before);
199
+ let previous = before;
200
+ for (const file of ['patches/nx.patch', 'patches/compiler/PIN', 'patches/compiler/VERSION']) {
201
+ await workspace.write(file, name + ' changed ' + file + '\n');
202
+ context.incrementalUpdate([file], []);
203
+ const changed = context.hashFilesMatchingGlob(positive, negative);
204
+ expect(changed).not.toBe(previous);
205
+ previous = changed;
206
+ }
207
+ }
208
+ } finally {
209
+ await workspace.cleanup();
210
+ }
211
+ });
212
+
255
213
  it('uses the transformer-aware compiler for emit and validation', async () => {
256
214
  const workspace = await createWorkspace();
257
215
  try {
@@ -274,6 +232,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
274
232
  '{workspaceRoot}/package.json',
275
233
  '{workspaceRoot}/bun.lock',
276
234
  '{workspaceRoot}/patches/**/*',
235
+ '!{workspaceRoot}/patches/**/*.md',
277
236
  '{workspaceRoot}/tsconfig.base.json',
278
237
  ];
279
238
  // An emit is a shipped artifact: it hashes the raw manifests, so a
@@ -285,20 +244,28 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
285
244
  '{projectRoot}/tsconfig.lib.json',
286
245
  ]);
287
246
  expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}']);
247
+ // Typecheck runs the compiler devenv.smoo.nix pins (SMOO_TYPECHECK_TSC) itself, not through
248
+ // ttsc, whose auto-loaded transform plugins would check with their own compiler; and it refuses
249
+ // to fall back to another when the shell does not provide it.
250
+ const typecheckCompiler =
251
+ '"${SMOO_TYPECHECK_TSC:?is unset, enter the devenv shell (devenv.smoo.nix builds the typecheck compiler)}"';
288
252
  expect(targets.typecheck?.options).toMatchObject({
289
- command: 'ttsc -p tsconfig.lib.json --noEmit',
253
+ command: `${typecheckCompiler} -p tsconfig.lib.json --noEmit`,
290
254
  cwd: 'packages/example',
291
255
  });
292
256
  const checkToolchainInputs = [
293
257
  '{workspaceRoot}/patches/**/*',
258
+ '!{workspaceRoot}/patches/**/*.md',
294
259
  '{workspaceRoot}/tsconfig.base.json',
295
- { json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
260
+ { json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
296
261
  { json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
297
262
  ];
263
+ // The compiler's store path names its pinned revision, so a compiler bump misses the cache.
298
264
  expect(targets.typecheck?.inputs).toEqual([
299
265
  'versionlessProduction',
300
266
  '^production',
301
267
  ...checkToolchainInputs,
268
+ { env: 'SMOO_TYPECHECK_TSC' },
302
269
  '{projectRoot}/tsconfig.lib.json',
303
270
  ]);
304
271
  expect(targets.build?.executor).toBe('nx:noop');
@@ -311,20 +278,21 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
311
278
  expect(targets['typecheck-tests']?.cache).toBe(true);
312
279
  expect(targets['typecheck-tests']?.dependsOn).toEqual(['tsc-js', 'typecheck']);
313
280
  expect(targets['typecheck-tests']?.options).toMatchObject({
314
- command: 'ttsc -p tsconfig.test.json --noEmit',
281
+ command: `${typecheckCompiler} -p tsconfig.test.json --noEmit`,
315
282
  cwd: 'packages/example',
316
283
  });
317
284
  expect(targets['typecheck-tests']?.inputs).toEqual([
318
285
  'versionlessDefault',
319
286
  '^production',
320
287
  ...checkToolchainInputs,
288
+ { env: 'SMOO_TYPECHECK_TSC' },
321
289
  '{projectRoot}/tsconfig.test.json',
322
290
  ]);
323
291
 
324
292
  expect(targets['typecheck-tests:watch']?.executor).toBe('nx:run-commands');
325
293
  expect(targets['typecheck-tests:watch']?.continuous).toBe(true);
326
294
  expect(targets['typecheck-tests:watch']?.options).toMatchObject({
327
- command: 'ttsc -p tsconfig.test.json --noEmit --watch',
295
+ command: `${typecheckCompiler} -p tsconfig.test.json --noEmit --watch`,
328
296
  cwd: 'packages/example',
329
297
  });
330
298
 
@@ -338,6 +306,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
338
306
 
339
307
  expect(targets.lint?.cache).toBe(true);
340
308
  expect(targets.lint?.dependsOn).toEqual(['typecheck-tests']);
309
+ expect(targets.lint?.inputs).toContain('^production');
341
310
  } finally {
342
311
  await workspace.cleanup();
343
312
  }
@@ -356,10 +325,13 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
356
325
  const targets = project?.targets ?? {};
357
326
  const checkToolchain = [
358
327
  '{workspaceRoot}/patches/**/*',
328
+ '!{workspaceRoot}/patches/**/*.md',
359
329
  '{workspaceRoot}/tsconfig.base.json',
360
330
  // Hashed by Nx itself: a `json` input costs no process, and neither
361
331
  // does the crate digest that replaces the manifests below.
362
- { json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
332
+ // The root manifest's scripts, smoo and nx sections are read by no check: an
333
+ // edit to a script or a developer link must not re-key every lint and typecheck.
334
+ { json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
363
335
  { json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
364
336
  ];
365
337
 
@@ -381,16 +353,19 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
381
353
  'versionlessProduction',
382
354
  { input: 'versionlessProduction', dependencies: true },
383
355
  ...checkToolchain,
356
+ { env: 'SMOO_TYPECHECK_TSC' },
384
357
  '{projectRoot}/tsconfig.lib.json',
385
358
  ]);
386
359
  expect(targets['typecheck-tests']?.inputs).toEqual([
387
360
  'versionlessDefault',
388
361
  { input: 'versionlessProduction', dependencies: true },
389
362
  ...checkToolchain,
363
+ { env: 'SMOO_TYPECHECK_TSC' },
390
364
  '{projectRoot}/tsconfig.test.json',
391
365
  ]);
392
366
  expect(targets.lint?.inputs).toEqual([
393
367
  'versionlessDefault',
368
+ { input: 'versionlessProduction', dependencies: true },
394
369
  ...checkToolchain,
395
370
  ...[
396
371
  'biome.json',
@@ -416,6 +391,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
416
391
  '{workspaceRoot}/package.json',
417
392
  '{workspaceRoot}/bun.lock',
418
393
  '{workspaceRoot}/patches/**/*',
394
+ '!{workspaceRoot}/patches/**/*.md',
419
395
  '{workspaceRoot}/tsconfig.base.json',
420
396
  '{projectRoot}/tsconfig.lib.json',
421
397
  ]);
@@ -478,9 +454,11 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
478
454
  'versionlessProduction',
479
455
  '^production',
480
456
  '{workspaceRoot}/patches/**/*',
457
+ '!{workspaceRoot}/patches/**/*.md',
481
458
  '{workspaceRoot}/tsconfig.base.json',
482
- { json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
459
+ { json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
483
460
  { json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
461
+ { env: 'SMOO_TYPECHECK_TSC' },
484
462
  '{projectRoot}/tsconfig.lib.json',
485
463
  ]);
486
464
  } finally {
@@ -515,20 +493,23 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
515
493
  ];
516
494
  const checkToolchain = [
517
495
  '{workspaceRoot}/patches/**/*',
496
+ '!{workspaceRoot}/patches/**/*.md',
518
497
  ...configChain,
519
- { json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
498
+ { json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
520
499
  { json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
521
500
  ];
522
501
  expect(targets.typecheck?.inputs).toEqual([
523
502
  'versionlessProduction',
524
503
  '^production',
525
504
  ...checkToolchain,
505
+ { env: 'SMOO_TYPECHECK_TSC' },
526
506
  '{projectRoot}/tsconfig.lib.json',
527
507
  ]);
528
508
  expect(targets['typecheck-tests']?.inputs).toEqual([
529
509
  'versionlessDefault',
530
510
  '^production',
531
511
  ...checkToolchain,
512
+ { env: 'SMOO_TYPECHECK_TSC' },
532
513
  '{projectRoot}/tsconfig.test.json',
533
514
  ]);
534
515
  // An emit reads the same options, and a stale artifact is worse than a
@@ -539,6 +520,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
539
520
  '{workspaceRoot}/package.json',
540
521
  '{workspaceRoot}/bun.lock',
541
522
  '{workspaceRoot}/patches/**/*',
523
+ '!{workspaceRoot}/patches/**/*.md',
542
524
  ...configChain,
543
525
  '{projectRoot}/tsconfig.lib.json',
544
526
  ]);
@@ -602,11 +584,13 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
602
584
  'versionlessProduction',
603
585
  '^production',
604
586
  '{workspaceRoot}/patches/**/*',
587
+ '!{workspaceRoot}/patches/**/*.md',
605
588
  '{workspaceRoot}/tsconfig.base.json',
606
589
  '{workspaceRoot}/packages/example/tsconfig.cycle.json',
607
590
  '{workspaceRoot}/packages/example/tsconfig.lib.json',
608
- { json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
591
+ { json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
609
592
  { json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
593
+ { env: 'SMOO_TYPECHECK_TSC' },
610
594
  '{projectRoot}/tsconfig.lib.json',
611
595
  ]);
612
596
  expect(JSON.stringify(inputs)).not.toContain('node_modules');
@@ -645,10 +629,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
645
629
  'versionlessProduction',
646
630
  '^production',
647
631
  '{workspaceRoot}/patches/**/*',
632
+ '!{workspaceRoot}/patches/**/*.md',
648
633
  '{workspaceRoot}/tsconfig.base.json',
649
634
  '{workspaceRoot}/packages/tsconfig/base.json',
650
- { json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
635
+ { json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
651
636
  { json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
637
+ { env: 'SMOO_TYPECHECK_TSC' },
652
638
  '{projectRoot}/tsconfig.lib.json',
653
639
  ]);
654
640
  expect(stderr).toBe('');
@@ -681,9 +667,11 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
681
667
  'versionlessProduction',
682
668
  '^production',
683
669
  '{workspaceRoot}/patches/**/*',
670
+ '!{workspaceRoot}/patches/**/*.md',
684
671
  '{workspaceRoot}/tsconfig.base.json',
685
- { json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
672
+ { json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
686
673
  { json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
674
+ { env: 'SMOO_TYPECHECK_TSC' },
687
675
  '{projectRoot}/tsconfig.lib.json',
688
676
  ]);
689
677
  } finally {
@@ -729,6 +717,42 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
729
717
  }
730
718
  });
731
719
 
720
+ it('makes lint check that the timing manifest names every file a timings-sharded Bun suite runs', async () => {
721
+ const workspace = await createWorkspace();
722
+ try {
723
+ const shard = (n: number) => ({
724
+ executor: '@smoothbricks/nx-plugin:bounded-exec',
725
+ options: { command: `bun test --timings=test-timings.json --shard=${n}/2`, cwd: '{projectRoot}' },
726
+ });
727
+ await workspace.write(
728
+ 'packages/sharded/package.json',
729
+ JSON.stringify({ name: 'sharded', nx: { targets: { 'test-a': shard(1), 'test-b': shard(2) } } }),
730
+ );
731
+ await workspace.write(
732
+ 'packages/counted/package.json',
733
+ JSON.stringify({
734
+ name: 'counted',
735
+ nx: { targets: { 'test-a': { options: { command: 'bun test --shard=1/1', cwd: '{projectRoot}' } } } },
736
+ }),
737
+ );
738
+
739
+ const sharded = await inferProjectTargets(workspace, 'packages/sharded/package.json');
740
+ const counted = await inferProjectTargets(workspace, 'packages/counted/package.json');
741
+
742
+ expect(sharded['shard-timings']).toEqual({
743
+ executor: '@smoothbricks/nx-plugin:shard-timings',
744
+ cache: false,
745
+ outputs: [],
746
+ options: { cwd: 'packages/sharded', args: ['--timings=test-timings.json'] },
747
+ });
748
+ expect(sharded.lint?.dependsOn).toEqual(['shard-timings']);
749
+ expect(counted['shard-timings']).toBeUndefined();
750
+ expect(counted.lint).toBeUndefined();
751
+ } finally {
752
+ await workspace.cleanup();
753
+ }
754
+ });
755
+
732
756
  it('infers aggregate build for package-local output targets without owning them', async () => {
733
757
  const workspace = await createWorkspace();
734
758
  try {
@@ -879,7 +903,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
879
903
  // builds, re-resolves features, or writes cargo's flocked `target/`.
880
904
  expect(targets['cargo-test-archive']?.executor).toBe('nx:run-commands');
881
905
  expect(targets['cargo-test-archive']?.cache).toBe(true);
882
- expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/target/nextest/archive.tar.zst']);
906
+ expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/.cache/nextest/archive.tar.zst']);
883
907
  expect(targets['cargo-test-archive']?.options).toMatchObject({ cwd: 'packages/ferris' });
884
908
  // nextest does not create the archive's parent directory and fails the
885
909
  // whole build if it is missing (measured: "error writing to archive").
@@ -889,9 +913,11 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
889
913
  // sit UNDER the repository's `.config/nextest.toml`, which is the only
890
914
  // place an `archive.include` for a cdylib or fixture can be declared.
891
915
  // `$PWD` because tool config paths must be absolute and an absolute path
892
- // in the command text would split one cache entry per checkout.
893
- expect(String(targets['cargo-test-archive']?.options?.command)).toMatch(
894
- /^mkdir -p target\/nextest && cargo --frozen nextest archive --workspace --archive-file target\/nextest\/archive\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
916
+ // in the command text would split one cache entry per checkout; through
917
+ // the root `node_modules` link because the plugin's real location is a
918
+ // different number of `../` away from each checkout.
919
+ expect(String(targets['cargo-test-archive']?.options?.command)).toBe(
920
+ 'mkdir -p .cache/nextest && cargo --frozen nextest archive --workspace --archive-file .cache/nextest/archive.tar.zst --user-config-file none --tool-config-file "smoo:$PWD/../../node_modules/@smoothbricks/nx-plugin/nextest.toml"',
895
921
  );
896
922
  expect(targets['cargo-test-archive']?.inputs).toContain('{projectRoot}/.config/nextest.toml');
897
923
  // Tests compile the dev profile only. Nx forwards a run's configuration
@@ -911,7 +937,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
911
937
  // moved tree). `--workspace` is not merely redundant here, nextest
912
938
  // rejects it beside a reused build.
913
939
  expect(targets['cargo-test-ferris-core']?.options?.command).toMatch(
914
- /^extracted="\$\(node \.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/dist\/bin\/smoo-nx-nextest-extract\.js target\/nextest\/archive\.tar\.zst\)" && cargo --frozen nextest run --binaries-metadata "\$extracted\/target\/nextest\/binaries-metadata\.json" --cargo-metadata "\$extracted\/target\/nextest\/cargo-metadata\.json" --target-dir-remap "\$extracted\/target" --workspace-remap \. -E 'package\(ferris-core\)' --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
940
+ /^extracted="\$\(node \.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/dist\/bin\/smoo-nx-nextest-extract\.js \.cache\/nextest\/archive\.tar\.zst\)" && cargo --frozen nextest run --binaries-metadata "\$extracted\/target\/nextest\/binaries-metadata\.json" --cargo-metadata "\$extracted\/target\/nextest\/cargo-metadata\.json" --target-dir-remap "\$extracted\/target" --workspace-remap \. -E 'package\(ferris-core\)' --no-fail-fast --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/\.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/nextest\.toml"$/,
915
941
  );
916
942
  expect(targets['cargo-test-ferris-core']?.inputs).toContain(
917
943
  '{workspaceRoot}/packages/ferris/.config/nextest.toml',
@@ -930,7 +956,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
930
956
  // test compile: a directory of its own compiled every host unit twice.
931
957
  const [fmt, clippy] = targets['cargo-lint']?.options?.commands ?? [];
932
958
  expect(fmt).toBe('cargo fmt --all --check');
933
- expect(clippy).toMatch(/^cargo --frozen clippy --workspace --all-targets .*-- -D warnings$/);
959
+ expect(clippy).toBe(CARGO_LINT_CLIPPY_COMMAND);
960
+ expect(clippy).toMatch(/^cargo --frozen clippy --workspace --all-targets /);
934
961
  for (const command of [clippy, targets['cargo-test-compile']?.options?.command]) {
935
962
  expect(command).not.toContain('--target-dir');
936
963
  }
@@ -979,8 +1006,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
979
1006
  expect(targets.clean?.cache).toBe(false);
980
1007
  expect(targets.clean?.options?.outputs).toEqual([
981
1008
  '{projectRoot}/dist',
1009
+ '{workspaceRoot}/packages/ferris/.cache/nextest',
982
1010
  '{workspaceRoot}/packages/ferris/target/cargo-lint-cross',
983
- '{workspaceRoot}/packages/ferris/target/nextest',
984
1011
  ]);
985
1012
  } finally {
986
1013
  await workspace.cleanup();
@@ -1018,11 +1045,18 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1018
1045
  await workspace.write(`${root}/package.json`, '{"name":"ferris"}\n');
1019
1046
  await workspace.write(`${root}/Cargo.toml`, '[workspace]\nmembers = ["crates/core"]\n');
1020
1047
  await workspace.write(`${root}/crates/core/Cargo.toml`, '[package]\nname = "ferris-core"\n');
1048
+ const biome = `biome check --files-ignore-unknown=true '${root}'`;
1021
1049
  const rust = await inferProjectTargets(workspace, `${root}/package.json`);
1022
1050
  const rustLint = resolveLint(rust);
1023
1051
  expect(rustLint.executor).toBe('nx:run-commands');
1024
1052
  expect(rustLint.dependsOn).toEqual(['cargo-lint']);
1025
- expect(rustLint.options?.commands).toEqual([`biome check --files-ignore-unknown=true '${root}'`]);
1053
+ expect(rustLint.options?.commands).toEqual([biome]);
1054
+
1055
+ // A JavaScript source joins ESLint's file list the moment it appears, with no tsconfig to announce it.
1056
+ await workspace.write(`${root}/src/check.js`, 'debugger;\n');
1057
+ const withJavaScript = resolveLint(await inferProjectTargets(workspace, `${root}/package.json`));
1058
+ expect(withJavaScript.dependsOn).toEqual(['cargo-lint']);
1059
+ expect(withJavaScript.options?.commands).toEqual([biome, `eslint '${root}/src/check.js'`]);
1026
1060
 
1027
1061
  const custom = { executor: 'nx:run-commands', options: { command: 'custom-linter package.json' } };
1028
1062
  await workspace.write(
@@ -1037,8 +1071,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1037
1071
  await workspace.write(`${root}/src/index.ts`, 'export const value = 1;\n');
1038
1072
  const mixed = await inferProjectTargets(workspace, `${root}/package.json`);
1039
1073
  expect(resolveLint(mixed).options?.commands).toEqual([
1040
- `biome check --files-ignore-unknown=true '${root}'`,
1041
- `eslint '${root}/src/index.ts'`,
1074
+ biome,
1075
+ `eslint '${root}/src/check.js' '${root}/src/index.ts'`,
1042
1076
  ]);
1043
1077
  expectNoSchedulerThrottle(mixed);
1044
1078
  } finally {
@@ -1046,6 +1080,92 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1046
1080
  }
1047
1081
  });
1048
1082
 
1083
+ it('lints the declared test program outside src and keys its sources and inherited declaration', async () => {
1084
+ const workspace = await createWorkspace();
1085
+ try {
1086
+ await workspace.write('eslint.config.mjs', 'export default [{ files: ["**/*.ts"] }];\n');
1087
+ await workspace.write('packages/example/package.json', '{"name":"example"}\n');
1088
+ await workspace.write(
1089
+ 'packages/test-base.json',
1090
+ JSON.stringify({
1091
+ include: ['\u0024{configDir}/tests/**/*.ts'],
1092
+ exclude: ['\u0024{configDir}/tests/excluded.ts'],
1093
+ files: ['contract/schema.d.ts'],
1094
+ }),
1095
+ );
1096
+ await workspace.write('packages/example/tsconfig.test.json', '{"extends":"../test-base.json"}\n');
1097
+ await workspace.write('packages/example/src/index.ts', 'export const value = 1;\n');
1098
+ await workspace.write('packages/example/tests/check.test.ts', 'export const check = 1;\n');
1099
+ await workspace.write('packages/example/tests/helper.ts', 'export const helper = 1;\n');
1100
+ await workspace.write('packages/example/tests/excluded.ts', 'export const excluded = 1;\n');
1101
+ await workspace.write('packages/example/other/stray.test.ts', 'export const stray = 1;\n');
1102
+ await workspace.write('packages/contract/schema.d.ts', 'export interface Contract { value: number }\n');
1103
+
1104
+ const { lint } = await inferProjectTargets(workspace, 'packages/example/package.json');
1105
+ expect(lint?.options?.commands).toEqual([
1106
+ "eslint 'packages/contract/schema.d.ts' 'packages/example/src/index.ts' 'packages/example/tests/check.test.ts' 'packages/example/tests/helper.ts'",
1107
+ ]);
1108
+ expect(lint?.metadata?.eslintFileSet).toEqual({
1109
+ command: lint?.options?.commands?.[0],
1110
+ files: [
1111
+ 'packages/contract/schema.d.ts',
1112
+ 'packages/example/src/index.ts',
1113
+ 'packages/example/tests/check.test.ts',
1114
+ 'packages/example/tests/helper.ts',
1115
+ ],
1116
+ });
1117
+ expect(isEslintFileSet(lint?.metadata?.eslintFileSet)).toBe(true);
1118
+ expect(isEslintFileSet({ command: 'eslint invalid', files: [null] })).toBe(false);
1119
+ expect(lint?.inputs).toEqual(
1120
+ expect.arrayContaining([
1121
+ '{projectRoot}/tsconfig.test.json',
1122
+ '{workspaceRoot}/packages/test-base.json',
1123
+ '{workspaceRoot}/packages/contract/schema.d.ts',
1124
+ '{workspaceRoot}/packages/example/tests/check.test.ts',
1125
+ '{workspaceRoot}/packages/example/tests/helper.ts',
1126
+ ]),
1127
+ );
1128
+ expect(lint?.inputs).not.toContain('{workspaceRoot}/packages/example/tests/excluded.ts');
1129
+ expect(lint?.inputs).not.toContain('{workspaceRoot}/packages/example/other/stray.test.ts');
1130
+ } finally {
1131
+ await workspace.cleanup();
1132
+ }
1133
+ });
1134
+
1135
+ it('lints and keys only the sources Nx indexes, never ignored files a build left on disk', async () => {
1136
+ const workspace = await createWorkspace();
1137
+ try {
1138
+ await workspace.write('eslint.config.mjs', 'export default [{ files: ["**/*.ts"] }];\n');
1139
+ // Generated outputs one build wrote and a fresh checkout lacks: a root ignore, a
1140
+ // project-level one, and an .nxignore, the three ways Nx keeps a file out of its index.
1141
+ await workspace.write('.gitignore', 'packages/example/src/generated/\n');
1142
+ await workspace.write('packages/example/.gitignore', '*.generated.ts\n');
1143
+ await workspace.write('.nxignore', 'packages/example/tests/nx-ignored.ts\n');
1144
+ await workspace.write('packages/example/package.json', '{"name":"example"}\n');
1145
+ await workspace.write('packages/example/tsconfig.test.json', '{"include":["tests/**/*.ts"]}\n');
1146
+ await workspace.write('packages/example/src/index.ts', 'export const value = 1;\n');
1147
+ await workspace.write('packages/example/src/generated/schemas.gen.ts', 'export const schemas = 1;\n');
1148
+ await workspace.write('packages/example/src/catalog.generated.ts', 'export const catalog = 1;\n');
1149
+ await workspace.write('packages/example/tests/check.test.ts', 'export const check = 1;\n');
1150
+ await workspace.write('packages/example/tests/helpers/catalog.generated.ts', 'export const c = 1;\n');
1151
+ await workspace.write('packages/example/tests/nx-ignored.ts', 'export const ignored = 1;\n');
1152
+
1153
+ const { lint } = await inferProjectTargets(workspace, 'packages/example/package.json');
1154
+ const files = ['packages/example/src/index.ts', 'packages/example/tests/check.test.ts'];
1155
+ expect(lint?.metadata?.eslintFileSet).toEqual({
1156
+ command: `eslint ${files.map((file) => `'${file}'`).join(' ')}`,
1157
+ files,
1158
+ });
1159
+ expect(lint?.options?.commands).toEqual([lint?.metadata?.eslintFileSet.command]);
1160
+ const programInputs = (lint?.inputs ?? []).filter(
1161
+ (input): input is string => typeof input === 'string' && input.startsWith('{workspaceRoot}/packages/example/'),
1162
+ );
1163
+ expect(programInputs).toEqual(['{workspaceRoot}/packages/example/tests/check.test.ts']);
1164
+ } finally {
1165
+ await workspace.cleanup();
1166
+ }
1167
+ });
1168
+
1049
1169
  it('attributes one repository-root Cargo workspace across package projects', async () => {
1050
1170
  const workspace = await createWorkspace();
1051
1171
  try {
@@ -1136,13 +1256,17 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1136
1256
  expect(runtime['cargo-test-runtime-core-exceptions-shard1']?.dependsOn).toEqual([rootFetch, rootArchive]);
1137
1257
  expect(runtime['cargo-test-runtime-core-exceptions-shard2']?.dependsOn).toEqual([rootFetch, rootArchive]);
1138
1258
  expect(runtime['cargo-test-runtime-core-shard1']?.options).toMatchObject({ cwd: '.' });
1139
- // At the root the helper is the root's own `node_modules` link, no `../`.
1259
+ // At the root the helper and the plugin's nextest config are the root's
1260
+ // own `node_modules` link, no `../`.
1140
1261
  expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toStartWith(
1141
- 'extracted="$(node node_modules/@smoothbricks/nx-plugin/dist/bin/smoo-nx-nextest-extract.js target/nextest/archive.tar.zst)" && ',
1262
+ 'extracted="$(node node_modules/@smoothbricks/nx-plugin/dist/bin/smoo-nx-nextest-extract.js .cache/nextest/archive.tar.zst)" && ',
1142
1263
  );
1143
1264
  expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toContain(
1144
1265
  `--target-dir-remap "$extracted/target" --workspace-remap . -E 'package(runtime-core)`,
1145
1266
  );
1267
+ expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toEndWith(
1268
+ '--tool-config-file "smoo:$PWD/node_modules/@smoothbricks/nx-plugin/nextest.toml"',
1269
+ );
1146
1270
  expect(native['cargo-test-native-napi']?.options?.command).toContain('--no-tests=pass');
1147
1271
  expect(runtime['cargo-test']?.dependsOn).toEqual([
1148
1272
  'cargo-test-runtime-core-shard1',
@@ -1157,6 +1281,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1157
1281
  expect(runtime.clean).toBeUndefined();
1158
1282
 
1159
1283
  expect(wasm['cargo-test-runtime-wasm']?.dependsOn).toEqual([rootFetch, rootArchive]);
1284
+ expect(wasm['cargo-wasm']?.inputs).toContain(CARGO_CLOSURE_INPUT);
1285
+ expect(wasm['cargo-wasm']?.inputs).not.toContain('{workspaceRoot}/**/*.rs');
1160
1286
  expect(wasm['cargo-wasm']?.options).toMatchObject({ cwd: '.' });
1161
1287
  // Dev by default, in the workspace's own `target/`; only the release
1162
1288
  // configuration compiles, and binds, the release artifact.
@@ -1192,6 +1318,18 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1192
1318
  expect(
1193
1319
  napiInputs.some((input) => typeof input === 'object' && 'runtime' in input && input.runtime.includes('.napi')),
1194
1320
  ).toBe(true);
1321
+ for (const [name, target] of Object.entries(native)) {
1322
+ if (!name.startsWith('napi-') || target.cache !== true) continue;
1323
+ expect(target.inputs).toContain(CARGO_CLOSURE_INPUT);
1324
+ expect(target.inputs).not.toContain('{workspaceRoot}/**/*.rs');
1325
+ }
1326
+ const nativeClosure = projects.get('packages/native')?.namedInputs?.[CARGO_CLOSURE_INPUT] ?? [];
1327
+ expect(nativeClosure).toContain(
1328
+ '{workspaceRoot}/packages/native/crates/native-napi/**/{*.rs,Cargo.toml,.cargo/config,.cargo/config.toml}',
1329
+ );
1330
+ expect(nativeClosure.some((input) => typeof input === 'string' && input.includes('packages/runtime'))).toBe(
1331
+ false,
1332
+ );
1195
1333
  expect(napiInputs).not.toContain('{workspaceRoot}/bun.lock');
1196
1334
  expect(napiInputs.some((input) => typeof input === 'string' && input.endsWith('/package.json'))).toBe(false);
1197
1335
  // ... and on the toolchain pin, which it must state itself: `napi build`
@@ -1342,6 +1480,43 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1342
1480
  }
1343
1481
  });
1344
1482
 
1483
+ // Without an `externalDependencies` input Nx keys a task whose executor is
1484
+ // not an `@nx/` one on every package in the lockfile, so a lockfile-only
1485
+ // commit re-ran every cargo verdict (measured in a consumer: every cargo-test-*
1486
+ // runner and the archive re-keyed on a one-integrity bun.lock edit). Here
1487
+ // the plugin is this repository's workspace project, which Nx refuses as an
1488
+ // external dependency, so each target names none.
1489
+ it('keys every cached cargo target on the npm packages it runs, not the lockfile', async () => {
1490
+ const workspace = await createWorkspace();
1491
+ try {
1492
+ await writeCargoIdentityFixture(workspace);
1493
+ const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
1494
+ const cached = cachedCargoTargets(targets);
1495
+ expect(cached.length).toBeGreaterThan(0);
1496
+ for (const [name, target] of cached) {
1497
+ const named = (target.inputs ?? []).filter(
1498
+ (input) => typeof input === 'object' && 'externalDependencies' in input,
1499
+ );
1500
+ expect([name, named]).toEqual([name, [{ externalDependencies: [] }]]);
1501
+ }
1502
+ } finally {
1503
+ await workspace.cleanup();
1504
+ }
1505
+ });
1506
+
1507
+ it('names the installed plugin for a cargo target that runs its executor or files, and nothing for cargo alone', () => {
1508
+ const plugin = 'node_modules/.bun/@smoothbricks+nx-plugin@0.4.26/node_modules/@smoothbricks/nx-plugin';
1509
+ const runner = { executor: '@smoothbricks/nx-plugin:bounded-exec' };
1510
+ const archive = `cargo --frozen nextest archive --workspace --tool-config-file "smoo:$PWD/${plugin}/nextest.toml"`;
1511
+ const clippy = CARGO_LINT_CLIPPY_COMMAND;
1512
+ expect(cargoCommandNpmPackages(runner, 'cargo --frozen nextest run', true)).toEqual(['@smoothbricks/nx-plugin']);
1513
+ expect(cargoCommandNpmPackages({ executor: 'nx:run-commands' }, archive, true)).toEqual([
1514
+ '@smoothbricks/nx-plugin',
1515
+ ]);
1516
+ expect(cargoCommandNpmPackages({ executor: 'nx:run-commands' }, clippy, true)).toEqual([]);
1517
+ expect(cargoCommandNpmPackages(runner, archive, false)).toEqual([]);
1518
+ });
1519
+
1345
1520
  // The property that decides whether Rust can ever use a shared cache. A cargo
1346
1521
  // target's identity used to include a dump of the ambient cargo environment,
1347
1522
  // whose values are absolute `/nix/store/…` and per-checkout devenv state
@@ -1349,15 +1524,20 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1349
1524
  // bare shell and inside a devenv profile, which made the pre-push
1350
1525
  // cross-compile probe unsatisfiable by construction.
1351
1526
  //
1352
- // Runtime inputs are checked by their OUTPUT, not their command text, because
1353
- // that is what Nx hashes: measured, two workspaces at different absolute
1354
- // paths whose only difference is the spelling of a runtime command producing
1355
- // identical stdout hash identically.
1527
+ // The runtime value AND its command declaration must be portable: Nx also
1528
+ // hashes the owning project's target configuration.
1356
1529
  it('hashes no machine-local value into a cached cargo target', async () => {
1357
1530
  const workspace = await createWorkspace();
1358
1531
  try {
1359
1532
  await writeCargoIdentityFixture(workspace);
1360
1533
  const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
1534
+ // Installed the way a consumer links it, so the inputs find the wrapper they name. After
1535
+ // inference, whose fixture walk would follow the link.
1536
+ await mkdir(join(workspace.context.workspaceRoot, 'node_modules/@smoothbricks'), { recursive: true });
1537
+ await symlink(
1538
+ fileURLToPath(new URL('..', import.meta.url)),
1539
+ join(workspace.context.workspaceRoot, 'node_modules/@smoothbricks/nx-plugin'),
1540
+ );
1361
1541
  const offenders: string[] = [];
1362
1542
  for (const [name, target] of cachedCargoTargets(targets)) {
1363
1543
  for (const input of target.inputs ?? []) {
@@ -1367,6 +1547,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1367
1547
  }
1368
1548
  if ('env' in input) offenders.push(`${name}: environment input ${String(input.env)}`);
1369
1549
  if (!('runtime' in input)) continue;
1550
+ if (input.runtime.includes(fileURLToPath(new URL('..', import.meta.url)))) {
1551
+ offenders.push(`${name}: runtime command names the plugin checkout`);
1552
+ }
1370
1553
  const value = await runtimeInputValue(input.runtime, workspace.context.workspaceRoot);
1371
1554
  const rooted = PATH_OUTSIDE_WORKSPACE.exec(value);
1372
1555
  if (rooted) offenders.push(`${name}: runtime input yields ${rooted[0].trim()} — from ${input.runtime}`);
@@ -1378,6 +1561,51 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1378
1561
  }
1379
1562
  }, 60_000);
1380
1563
 
1564
+ // A consumer links the plugin from a checkout of its own, outside the
1565
+ // workspace, and its forks sit at different depths. Nx hashes a project's
1566
+ // configuration into every task of that project and of its dependents, so
1567
+ // the configuration must not know how deep the workspace is: measured, a
1568
+ // `../` count in the tool config path re-keyed 118 tasks of a fork of a warm
1569
+ // main.
1570
+ it('infers byte-identical cargo targets for a workspace at any depth', async () => {
1571
+ const parent = await realpath(await mkdtemp(join(tmpdir(), 'smoothbricks-nx-plugin-depth-')));
1572
+ const plugin = fileURLToPath(new URL('..', import.meta.url));
1573
+ const pluginNextestConfig = await readFile(join(plugin, 'nextest.toml'), 'utf8');
1574
+ try {
1575
+ const inferred: string[] = [];
1576
+ for (const dir of [parent, join(parent, 'a/b/c')]) {
1577
+ await mkdir(dir, { recursive: true });
1578
+ const workspace = await createWorkspace(dir);
1579
+ const root = workspace.context.workspaceRoot;
1580
+ await writeCargoIdentityFixture(workspace);
1581
+ const project = await inferProject(workspace, 'packages/ferris/package.json');
1582
+ // Installed the way a consumer links it: a checkout outside the
1583
+ // workspace. After inference, whose fixture walk would follow it.
1584
+ await mkdir(join(root, 'node_modules/@smoothbricks'), { recursive: true });
1585
+ await symlink(plugin, join(root, 'node_modules/@smoothbricks/nx-plugin'));
1586
+ // Stable is not enough: from where each command runs, the spelling
1587
+ // must name the config the plugin ships.
1588
+ const configured: string[] = [];
1589
+ for (const [name, target] of cachedCargoTargets(project?.targets ?? {})) {
1590
+ const named = /--tool-config-file "smoo:\$PWD\/([^"]+)"/.exec(String(target.options?.command));
1591
+ if (!named?.[1]) continue;
1592
+ configured.push(name);
1593
+ const config = await readFile(join(root, String(target.options?.cwd), named[1]), 'utf8');
1594
+ expect([name, config]).toEqual([name, pluginNextestConfig]);
1595
+ }
1596
+ expect(configured.sort()).toEqual([
1597
+ 'cargo-cross-test-archive-aarch64-apple-darwin',
1598
+ 'cargo-test-archive',
1599
+ 'cargo-test-ferris-core',
1600
+ ]);
1601
+ inferred.push(JSON.stringify(project, null, 2));
1602
+ }
1603
+ expect(inferred[1]).toBe(inferred[0]);
1604
+ } finally {
1605
+ await rm(parent, { recursive: true, force: true });
1606
+ }
1607
+ });
1608
+
1381
1609
  it('scopes each per-crate cargo-test command to exactly one package', async () => {
1382
1610
  const workspace = await createWorkspace();
1383
1611
  try {
@@ -1428,7 +1656,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1428
1656
  // A cargo that does what nextest does with an archive, and says so: an
1429
1657
  // `--archive-file` unpacks it (into `--extract-to`, or a private temp
1430
1658
  // dir when a run is given the archive itself), and a run reports which
1431
- // archive's binaries it executed.
1659
+ // archive's binaries it executed. `metadata` names the workspace's
1660
+ // target directory, where the extraction root lives.
1432
1661
  const log = join(root, 'nextest.log');
1433
1662
  await workspace.write(
1434
1663
  'bin/cargo',
@@ -1437,6 +1666,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1437
1666
  'archive= dest= binaries=',
1438
1667
  'while [ $# -gt 0 ]; do',
1439
1668
  ' case "$1" in',
1669
+ ' metadata) printf \'{"target_directory":"%s/target"}\\n\' "$PWD"; exit 0 ;;',
1440
1670
  ' --archive-file) archive=$2; shift ;;',
1441
1671
  ' --extract-to) dest=$2; shift ;;',
1442
1672
  ' --binaries-metadata) binaries=$2; shift ;;',
@@ -1472,7 +1702,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1472
1702
  }),
1473
1703
  );
1474
1704
 
1475
- await workspace.write('packages/ferris/target/nextest/archive.tar.zst', 'first archive');
1705
+ await workspace.write('packages/ferris/.cache/nextest/archive.tar.zst', 'first archive');
1476
1706
  for (const run of await runAll()) {
1477
1707
  expect(run).toMatchObject({ exitCode: 0 });
1478
1708
  }
@@ -1485,7 +1715,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1485
1715
 
1486
1716
  // A rebuilt archive is new bytes at the same path: the runners must not
1487
1717
  // execute what the old one unpacked, and the old unpacking is garbage.
1488
- await workspace.write('packages/ferris/target/nextest/archive.tar.zst', 'second archive');
1718
+ await workspace.write('packages/ferris/.cache/nextest/archive.tar.zst', 'second archive');
1489
1719
  for (const run of await runAll()) {
1490
1720
  expect(run).toMatchObject({ exitCode: 0 });
1491
1721
  }
@@ -1499,13 +1729,16 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1499
1729
  'run second archive',
1500
1730
  'run second archive',
1501
1731
  ]);
1502
- const target = join(root, 'packages/ferris/target');
1503
- const unpacked = (await readdir(target, { recursive: true })).filter((path) =>
1732
+ // The old unpacking is gone from Cargo's build tree, and the archive's
1733
+ // directory holds only the archive, the declared Nx output.
1734
+ const extracted = join(root, 'packages/ferris/target', NEXTEST_EXTRACTION_DIRECTORY);
1735
+ const unpacked = (await readdir(extracted, { recursive: true })).filter((path) =>
1504
1736
  path.endsWith('binaries-metadata.json'),
1505
1737
  );
1506
- expect(await Promise.all(unpacked.map((path) => readFile(join(target, path), 'utf8')))).toEqual([
1738
+ expect(await Promise.all(unpacked.map((path) => readFile(join(extracted, path), 'utf8')))).toEqual([
1507
1739
  'second archive',
1508
1740
  ]);
1741
+ expect(await readdir(join(root, 'packages/ferris/.cache/nextest'))).toEqual(['archive.tar.zst']);
1509
1742
  } finally {
1510
1743
  await workspace.cleanup();
1511
1744
  }
@@ -1818,7 +2051,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1818
2051
  'napi-debug',
1819
2052
  ]);
1820
2053
  expect(targets['cargo-test-cowshed-napi']?.options?.command).toMatch(
1821
- /^extracted="\$\(node \.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/dist\/bin\/smoo-nx-nextest-extract\.js target\/nextest\/archive\.tar\.zst\)" && cargo --frozen nextest run --binaries-metadata "\$extracted\/target\/nextest\/binaries-metadata\.json" --cargo-metadata "\$extracted\/target\/nextest\/cargo-metadata\.json" --target-dir-remap "\$extracted\/target" --workspace-remap \. -E 'package\(cowshed-napi\)' --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
2054
+ /^extracted="\$\(node \.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/dist\/bin\/smoo-nx-nextest-extract\.js \.cache\/nextest\/archive\.tar\.zst\)" && cargo --frozen nextest run --binaries-metadata "\$extracted\/target\/nextest\/binaries-metadata\.json" --cargo-metadata "\$extracted\/target\/nextest\/cargo-metadata\.json" --target-dir-remap "\$extracted\/target" --workspace-remap \. -E 'package\(cowshed-napi\)' --no-fail-fast --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
1822
2055
  );
1823
2056
  expect(targets['napi-test']).toMatchObject({
1824
2057
  executor: '@smoothbricks/nx-plugin:bounded-exec',
@@ -1828,7 +2061,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1828
2061
  command: 'bun test --config=../bunfig.toml --timeout=30000 native.test.ts',
1829
2062
  cwd: 'packages/cowshed/src',
1830
2063
  env: { NAPI_DEBUG_ADDON: '1' },
1831
- timeoutMs: 120000,
2064
+ idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
1832
2065
  killAfterMs: 10000,
1833
2066
  },
1834
2067
  });
@@ -1923,7 +2156,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1923
2156
  // An unsharded crate keeps the bare name and takes no --partition, so
1924
2157
  // declaring nothing is exactly the old single-target behaviour.
1925
2158
  expect(targets['cargo-test-small']?.options?.command).toMatch(
1926
- /--workspace-remap \. -E 'package\(small\)' --no-tests=pass --user-config-file none/,
2159
+ /--workspace-remap \. -E 'package\(small\)' --no-fail-fast --no-tests=pass --user-config-file none/,
1927
2160
  );
1928
2161
  // The shards partition the crate MINUS the classes nextest.toml singles
1929
2162
  // out, i of N. Those are lifted out because a test carrying a raised
@@ -1935,18 +2168,19 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1935
2168
  }
1936
2169
  for (const index of [1, 2, 3]) {
1937
2170
  expect(targets[`cargo-test-big-shard${index}`]?.options?.command).toContain(
1938
- `-E 'package(big) and not (${exceptional})' --partition hash:${index}/3 --no-tests=pass`,
2171
+ `-E 'package(big) and not (${exceptional})' --partition hash:${index}/3 --no-fail-fast --no-tests=pass`,
1939
2172
  );
1940
- expect(targets[`cargo-test-big-shard${index}`]?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
2173
+ expect(targets[`cargo-test-big-shard${index}`]?.options?.idleTimeoutMs).toBe(BOUNDED_TEST_IDLE_TIMEOUT_MS);
2174
+ expect(targets[`cargo-test-big-shard${index}`]?.options).not.toHaveProperty('timeoutMs');
1941
2175
  }
1942
2176
  // Exceptional partitions are the exact complement, hashed by the same
1943
2177
  // declared count; each keeps the full bounded window.
1944
2178
  for (const index of [1, 2, 3]) {
1945
2179
  const name = `cargo-test-big-exceptions-shard${index}`;
1946
2180
  expect(targets[name]?.options?.command).toContain(
1947
- `-E 'package(big) and (${exceptional})' --partition hash:${index}/3 --no-tests=pass`,
2181
+ `-E 'package(big) and (${exceptional})' --partition hash:${index}/3 --no-fail-fast --no-tests=pass`,
1948
2182
  );
1949
- expect(targets[name]?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
2183
+ expect(targets[name]?.options?.idleTimeoutMs).toBe(BOUNDED_TEST_IDLE_TIMEOUT_MS);
1950
2184
  expect(packageNameFromCargoTestTarget(name)).toBe('big');
1951
2185
  }
1952
2186
  expect(targets['cargo-test-big-exceptions']).toBeUndefined();
@@ -1987,6 +2221,345 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1987
2221
  }
1988
2222
  });
1989
2223
 
2224
+ it('runs the serial test group once, unpartitioned, and excludes its tests from every crate piece on macOS', async () => {
2225
+ const workspace = await createWorkspace();
2226
+ try {
2227
+ await workspace.write('packages/rusty/package.json', '{"name":"rusty"}\n');
2228
+ await workspace.write('packages/rusty/Cargo.toml', '[workspace]\nmembers = ["crates/big", "crates/small"]\n');
2229
+ await workspace.write(
2230
+ 'packages/rusty/crates/big/Cargo.toml',
2231
+ '[package]\nname = "big"\n\n[package.metadata.smoothbricks.test]\nshards = 3\n',
2232
+ );
2233
+ await workspace.write('packages/rusty/crates/small/Cargo.toml', '[package]\nname = "small"\n');
2234
+ await workspace.write(
2235
+ 'packages/rusty/.config/nextest.toml',
2236
+ [
2237
+ '[test-groups.real-apfs]',
2238
+ 'max-threads = 1',
2239
+ '',
2240
+ '[[profile.default.overrides]]',
2241
+ "filter = 'test(/real_apfs_/)'",
2242
+ `platform = 'cfg(target_os="macos")'`,
2243
+ "test-group = 'real-apfs'",
2244
+ '',
2245
+ ].join('\n'),
2246
+ );
2247
+
2248
+ const macos = await inferProjectTargets(
2249
+ workspace,
2250
+ 'packages/rusty/package.json',
2251
+ createNodesV2ForPlatform('darwin', 'arm64'),
2252
+ );
2253
+ const serial = '(test(/real_apfs_/))';
2254
+ const group = macos['cargo-test-group-real-apfs'];
2255
+ // One runner for the workspace, owned by the cargo root beside the archive it executes: a progress bound and no
2256
+ // ceiling like every test target, one CPU token, no partition and no thread flag. A filter that selects
2257
+ // nothing fails the run.
2258
+ expect(group?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
2259
+ expect(group?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
2260
+ expect(String(group?.options?.command)).toContain('nextest run ');
2261
+ expect(String(group?.options?.command)).toContain(
2262
+ `-E '${serial}' --no-fail-fast --no-tests=fail --user-config-file none`,
2263
+ );
2264
+ expect(group?.options).not.toHaveProperty('timeoutMs');
2265
+ expect(group?.options?.idleTimeoutMs).toBe(BOUNDED_TEST_IDLE_TIMEOUT_MS);
2266
+ expect(group?.options?.killAfterMs).toBe(BOUNDED_TEST_KILL_AFTER_MS);
2267
+ expect(group?.options?.parallelism).toBe(1);
2268
+ expect(group?.inputs).toContain('{workspaceRoot}/packages/rusty/.config/nextest.toml');
2269
+ expect(JSON.stringify(group?.inputs)).toContain('nextest-code-bound.ts');
2270
+ expect(JSON.stringify(macos['cargo-test-small']?.inputs)).not.toContain('nextest-code-bound.ts');
2271
+ expect(String(group?.options?.command)).not.toMatch(/--partition|test-threads|max-fail/);
2272
+
2273
+ // Every crate piece excludes the group's tests, so each test is selected by exactly one target.
2274
+ const exceptional = exceptionalTestFilter(fileURLToPath(new URL('../nextest.toml', import.meta.url)));
2275
+ if (exceptional === null) {
2276
+ throw new Error('nextest.toml declares no overrides; this test asserts the pin that protects them');
2277
+ }
2278
+ expect(macos['cargo-test-small']?.options?.command).toContain(
2279
+ `-E 'package(small) and not ((test(/real_apfs_/)))' --no-fail-fast --no-tests=pass`,
2280
+ );
2281
+ for (const index of [1, 2, 3]) {
2282
+ expect(macos[`cargo-test-big-shard${index}`]?.options?.command).toContain(
2283
+ `-E 'package(big) and not (${exceptional}) and not ((test(/real_apfs_/)))' --partition hash:${index}/3 --no-fail-fast --no-tests=pass`,
2284
+ );
2285
+ expect(macos[`cargo-test-big-exceptions-shard${index}`]?.options?.command).toContain(
2286
+ `-E 'package(big) and (${exceptional}) and not ((test(/real_apfs_/)))' --partition hash:${index}/3 --no-fail-fast --no-tests=pass`,
2287
+ );
2288
+ }
2289
+ // `cargo-test` and `test` are the ordinary suite alone: neither infers an edge to the group.
2290
+ expect(macos['cargo-test']?.dependsOn).not.toContain('cargo-test-group-real-apfs');
2291
+ expect(macos.test?.dependsOn).toEqual(['cargo-test']);
2292
+
2293
+ // Off macOS nextest applies the group nowhere, so it is not inferred and no piece excludes its tests.
2294
+ const linux = await inferProjectTargets(
2295
+ workspace,
2296
+ 'packages/rusty/package.json',
2297
+ createNodesV2ForPlatform('linux', 'x64'),
2298
+ );
2299
+ expect(linux['cargo-test-group-real-apfs']).toBeUndefined();
2300
+ expect(linux['cargo-test-small']?.options?.command).toContain(
2301
+ `-E 'package(small)' --no-fail-fast --no-tests=pass`,
2302
+ );
2303
+ expect(linux['cargo-test']?.dependsOn).not.toContain('cargo-test-group-real-apfs');
2304
+ expect(linux.test?.dependsOn).toEqual(['cargo-test']);
2305
+ } finally {
2306
+ await workspace.cleanup();
2307
+ }
2308
+ });
2309
+
2310
+ it("scopes each serial group's runner inputs to its packages and their closure, and keeps an unscoped group workspace-wide", async () => {
2311
+ const workspace = await createWorkspace();
2312
+ try {
2313
+ await writeApfsSplitFixture(workspace, [
2314
+ ...APFS_SPLIT_GROUPS,
2315
+ '[test-groups.wide]',
2316
+ 'max-threads = 1',
2317
+ '',
2318
+ ...serialOverride('test(/wide_/)', 'wide'),
2319
+ ]);
2320
+ const root = (await inferApfsSplit(workspace)).get('.') ?? {};
2321
+ const device = root['cargo-test-group-real-apfs'];
2322
+ const host = root['cargo-test-group-real-apfs-host'];
2323
+ const wide = root['cargo-test-group-wide'];
2324
+
2325
+ // A group scoped to packages hashes those crates and every crate they link, and no other.
2326
+ expect(hashedCrates(device)).toEqual(['cowshed-apfs', 'cowshed-apfs-tests', 'cowshed-os']);
2327
+ expect(hashedCrates(host)).toEqual(['cowshed-apfs', 'cowshed-cli', 'cowshed-core', 'cowshed-os']);
2328
+ // A filter scoped to no package keeps every member's tree, as the archive hashes them.
2329
+ expect(hashedCrates(wide)).toEqual([
2330
+ 'cowshed-apfs',
2331
+ 'cowshed-apfs-tests',
2332
+ 'cowshed-cli',
2333
+ 'cowshed-core',
2334
+ 'cowshed-os',
2335
+ 'lmao-core',
2336
+ ]);
2337
+
2338
+ // The proof as the three cases it makes. An unrelated crate reruns neither scoped group. A scenario
2339
+ // edit reruns the device group alone: the scenarios are a crate of their own that no host crate
2340
+ // depends on. A change to the production substrate, or to what it links, reruns both, because the
2341
+ // host crates link it too. Nothing here excludes a tests tree, and the test support every real-image
2342
+ // binary compiles in stays hashed for both groups.
2343
+ const hashedBy = (path: string) => ({
2344
+ device: hashes(device, path),
2345
+ host: hashes(host, path),
2346
+ wide: hashes(wide, path),
2347
+ });
2348
+ expect(hashedBy('packages/lmao/crates/lmao-core/src/lib.rs')).toEqual({ device: false, host: false, wide: true });
2349
+ expect(hashedBy('packages/cowshed/crates/cowshed-apfs-tests/src/tests.rs')).toEqual({
2350
+ device: true,
2351
+ host: false,
2352
+ wide: true,
2353
+ });
2354
+ expect(hashedBy('packages/cowshed/crates/cowshed-core/src/lib.rs')).toEqual({
2355
+ device: false,
2356
+ host: true,
2357
+ wide: true,
2358
+ });
2359
+ expect(hashedBy('packages/cowshed/crates/cowshed-cli/src/lib.rs')).toEqual({
2360
+ device: false,
2361
+ host: true,
2362
+ wide: true,
2363
+ });
2364
+ for (const shared of [
2365
+ 'packages/cowshed/crates/cowshed-apfs/src/lib.rs',
2366
+ 'packages/cowshed/crates/cowshed-apfs/tests/support/blank_image.rs',
2367
+ 'packages/cowshed/crates/cowshed-os/src/lib.rs',
2368
+ ]) {
2369
+ expect(hashedBy(shared), shared).toEqual({ device: true, host: true, wide: true });
2370
+ }
2371
+ for (const group of [device, host]) {
2372
+ const exclusions = (group?.inputs ?? []).filter(
2373
+ (input): input is string => typeof input === 'string' && input.startsWith('!'),
2374
+ );
2375
+ expect(exclusions.filter((input) => /\btests?\b/.test(input))).toEqual([]);
2376
+ }
2377
+
2378
+ // Every scoped group still hashes every member manifest, the repository's nextest config and the
2379
+ // run-wrapper its tests are bounded by: those decide a verdict whichever crates it selects.
2380
+ for (const group of [device, host, wide]) {
2381
+ expect(group?.inputs).toContain('{workspaceRoot}/packages/lmao/crates/lmao-core/Cargo.toml');
2382
+ expect(group?.inputs).toContain('{workspaceRoot}/.config/nextest.toml');
2383
+ expect(JSON.stringify(group?.inputs)).toContain('nextest-code-bound.ts');
2384
+ }
2385
+ } finally {
2386
+ await workspace.cleanup();
2387
+ }
2388
+ });
2389
+
2390
+ it('refuses a serial group scoped to a package that is not a member of the Cargo workspace', async () => {
2391
+ const workspace = await createWorkspace();
2392
+ try {
2393
+ await writeApfsSplitFixture(workspace, [
2394
+ '[test-groups.real-apfs]',
2395
+ 'max-threads = 1',
2396
+ '',
2397
+ ...serialOverride('package(cowshed-missing) and test(/real_apfs_/)', 'real-apfs'),
2398
+ ]);
2399
+ // Nx wraps a createNodes throw in AggregateCreateNodesError, so the reason is in the nested error.
2400
+ const failure = await inferApfsSplit(workspace).then(
2401
+ () => undefined,
2402
+ (error: unknown) => error,
2403
+ );
2404
+ if (!(failure instanceof AggregateCreateNodesError)) {
2405
+ throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
2406
+ }
2407
+ expect(failure.errors[0]?.[1]?.message).toMatch(
2408
+ /test-group "real-apfs" selects package\(cowshed-missing\), which is not a member of the Cargo workspace/,
2409
+ );
2410
+ } finally {
2411
+ await workspace.cleanup();
2412
+ }
2413
+ });
2414
+
2415
+ it('keeps cargo-test and test to the ordinary suite, so no gate of the root or a member reaches a serial group', async () => {
2416
+ const workspace = await createWorkspace();
2417
+ try {
2418
+ await writeApfsSplitFixture(workspace, APFS_SPLIT_GROUPS);
2419
+ const macos = await inferApfsSplit(workspace);
2420
+ const root = macos.get('.') ?? {};
2421
+ const cowshed = macos.get('packages/cowshed') ?? {};
2422
+ const lmao = macos.get('packages/lmao') ?? {};
2423
+
2424
+ // `cargo-test` is the ordinary suite alone, whichever project owns the aggregate.
2425
+ expect(root['cargo-test']?.dependsOn).toEqual([
2426
+ { projects: ['cowshed'], target: 'cargo-test-cowshed-apfs' },
2427
+ { projects: ['cowshed'], target: 'cargo-test-cowshed-apfs-tests' },
2428
+ { projects: ['cowshed'], target: 'cargo-test-cowshed-cli' },
2429
+ { projects: ['cowshed'], target: 'cargo-test-cowshed-core' },
2430
+ { projects: ['cowshed'], target: 'cargo-test-cowshed-os' },
2431
+ { projects: ['lmao'], target: 'cargo-test-lmao-core' },
2432
+ ]);
2433
+ expect(cowshed['cargo-test']?.dependsOn).toEqual([
2434
+ 'cargo-test-cowshed-apfs',
2435
+ 'cargo-test-cowshed-apfs-tests',
2436
+ 'cargo-test-cowshed-cli',
2437
+ 'cargo-test-cowshed-core',
2438
+ 'cargo-test-cowshed-os',
2439
+ ]);
2440
+ expect(lmao['cargo-test']?.dependsOn).toEqual(['cargo-test-lmao-core']);
2441
+
2442
+ // Ordinary test inference excludes serial groups at both the root and every member. Explicit repository
2443
+ // host aggregates, not inference, own those edges.
2444
+ for (const targets of [root, cowshed, lmao]) {
2445
+ expect(targets.test?.dependsOn).toEqual(['cargo-test']);
2446
+ }
2447
+
2448
+ // Inference orders nothing between the groups: that edge is the repository's explicit config.
2449
+ for (const name of ['cargo-test-group-real-apfs', 'cargo-test-group-real-apfs-host']) {
2450
+ expect(root[name]?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
2451
+ }
2452
+
2453
+ // Every crate piece, scoped to a package the groups hold or not, excludes both groups' tests.
2454
+ const exclusion =
2455
+ 'not ((package(cowshed-apfs-tests) and test(/real_apfs_/)) or ' +
2456
+ '(package(cowshed-core) and (test(/real_apfs_/) or binary(apfs_native_macos))) or ' +
2457
+ '(package(cowshed-cli) and test(/real_apfs_/)))';
2458
+ const pieces: ReadonlyArray<readonly [TargetConfiguration | undefined, string]> = [
2459
+ [cowshed['cargo-test-cowshed-apfs'], 'cowshed-apfs'],
2460
+ [cowshed['cargo-test-cowshed-apfs-tests'], 'cowshed-apfs-tests'],
2461
+ [lmao['cargo-test-lmao-core'], 'lmao-core'],
2462
+ ];
2463
+ for (const [piece, crate] of pieces) {
2464
+ expect(piece?.options?.command, crate).toContain(
2465
+ `-E 'package(${crate}) and ${exclusion}' --no-fail-fast --no-tests=pass`,
2466
+ );
2467
+ }
2468
+
2469
+ // Off macOS the groups are not inferred at all, and the gate is the same ordinary suite.
2470
+ const linux = await inferApfsSplit(workspace, createNodesV2ForPlatform('linux', 'x64'));
2471
+ expect(linux.get('.')?.test?.dependsOn).toEqual(['cargo-test']);
2472
+ expect(linux.get('packages/cowshed')?.test?.dependsOn).toEqual(['cargo-test']);
2473
+ expect(linux.get('.')?.['cargo-test-group-real-apfs-host']).toBeUndefined();
2474
+ } finally {
2475
+ await workspace.cleanup();
2476
+ }
2477
+ });
2478
+
2479
+ it('runs the host group after the device group through the explicit targetDefaults edge, and no test gate runs either', async () => {
2480
+ const workspace = await createWorkspace();
2481
+ try {
2482
+ await writeApfsSplitFixture(workspace, APFS_SPLIT_GROUPS);
2483
+ const macos = await inferApfsSplit(workspace);
2484
+ const rootProject = '@fixture/codebase';
2485
+ const rootTargets = macos.get('.') ?? {};
2486
+
2487
+ // The edge as the repository's nx.json states it. Nx expands `...` to the inferred list, so the
2488
+ // archive and the locked fetch stay ahead of the host group beside the device group.
2489
+ const nxJson = {
2490
+ targetDefaults: { 'cargo-test-group-real-apfs-host': { dependsOn: ['...', 'cargo-test-group-real-apfs'] } },
2491
+ };
2492
+ let host = rootTargets['cargo-test-group-real-apfs-host'] ?? {};
2493
+ for (const [, , result] of createTargetDefaultsResults(
2494
+ { '.': { root: '.', targets: rootTargets } },
2495
+ {},
2496
+ nxJson,
2497
+ )) {
2498
+ const target = result.projects?.['.']?.targets?.['cargo-test-group-real-apfs-host'];
2499
+ if (target) host = mergeTargetConfigurations(target, host);
2500
+ }
2501
+ expect(host.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive', 'cargo-test-group-real-apfs']);
2502
+
2503
+ const nodes: Record<string, ProjectGraphProjectNode> = {
2504
+ [rootProject]: {
2505
+ name: rootProject,
2506
+ type: 'app',
2507
+ data: { root: '.', targets: { ...rootTargets, 'cargo-test-group-real-apfs-host': host } },
2508
+ },
2509
+ cowshed: {
2510
+ name: 'cowshed',
2511
+ type: 'lib',
2512
+ data: { root: 'packages/cowshed', targets: macos.get('packages/cowshed') ?? {} },
2513
+ },
2514
+ lmao: {
2515
+ name: 'lmao',
2516
+ type: 'lib',
2517
+ data: { root: 'packages/lmao', targets: macos.get('packages/lmao') ?? {} },
2518
+ },
2519
+ };
2520
+ const graph: ProjectGraph = { nodes, dependencies: { [rootProject]: [], cowshed: [], lmao: [] } };
2521
+ const task = (project: string, target: string): string => `${project}:${target}`;
2522
+ // Every task `from` waits on, directly or through the tasks it waits on.
2523
+ const reached = (dependencies: Record<string, string[]>, from: string): string[] => {
2524
+ const seen = new Set<string>();
2525
+ const pending = [from];
2526
+ while (pending.length > 0) {
2527
+ const next = pending.pop();
2528
+ if (next === undefined || seen.has(next)) continue;
2529
+ seen.add(next);
2530
+ pending.push(...(dependencies[next] ?? []));
2531
+ }
2532
+ return [...seen];
2533
+ };
2534
+ const groupsReached = (dependencies: Record<string, string[]>, from: string): string[] =>
2535
+ reached(dependencies, from).filter((id) => id.includes(':cargo-test-group-'));
2536
+ const device = task(rootProject, 'cargo-test-group-real-apfs');
2537
+ const hosted = task(rootProject, 'cargo-test-group-real-apfs-host');
2538
+
2539
+ // The task graph `nx run-many -t test` runs reaches neither group, from the root or from a member.
2540
+ for (const project of [rootProject, 'cowshed']) {
2541
+ const gate = createTaskGraph(graph, {}, [project], ['test'], undefined, {});
2542
+ expect(groupsReached(gate.dependencies, task(project, 'test'))).toEqual([]);
2543
+ }
2544
+
2545
+ // When a run selects both groups, the host starts only once the device group is done, so two real-image
2546
+ // runners never overlap, and the device group waits on no other group.
2547
+ const named = createTaskGraph(
2548
+ graph,
2549
+ {},
2550
+ [rootProject],
2551
+ ['test', 'cargo-test-group-real-apfs', 'cargo-test-group-real-apfs-host'],
2552
+ undefined,
2553
+ {},
2554
+ );
2555
+ expect(named.dependencies[hosted]).toContain(device);
2556
+ expect(groupsReached(named.dependencies, device)).toEqual([device]);
2557
+ expect(groupsReached(named.dependencies, task(rootProject, 'test'))).toEqual([]);
2558
+ } finally {
2559
+ await workspace.cleanup();
2560
+ }
2561
+ });
2562
+
1990
2563
  it('rejects a shard count that cannot describe a partition', async () => {
1991
2564
  const workspace = await createWorkspace();
1992
2565
  try {
@@ -2104,7 +2677,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
2104
2677
  expect(cargoTest?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-wasm']);
2105
2678
  expect(cargoTest?.options).toBeUndefined();
2106
2679
  expect(targets['cargo-test-ferris-core']?.options?.command).toContain("-E 'package(ferris-core)'");
2107
- expect(targets['cargo-test-ferris-core']?.options?.timeoutMs).toBe(120000);
2680
+ expect(targets['cargo-test-ferris-core']?.options?.idleTimeoutMs).toBe(BOUNDED_TEST_IDLE_TIMEOUT_MS);
2108
2681
 
2109
2682
  const cargoTestCompile = resolveDeclaredOverInferred(targets, declared, 'cargo-test-compile');
2110
2683
  expect(cargoTestCompile?.executor).toBe('nx:run-commands');
@@ -2296,80 +2869,40 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
2296
2869
  });
2297
2870
 
2298
2871
  it('orders a three-project chain of INFERRED deploys through one run-many', async () => {
2299
- const workspace = await createNxWorkspace();
2300
- const root = workspace.context.workspaceRoot;
2301
- const repositoryRoot = fileURLToPath(new URL('../../../', import.meta.url));
2872
+ const workspace = await createWorkspace();
2873
+ // c is deepest: a's deploy calls into b's, b's calls into c's. No project declares a deploy
2874
+ // target — each only has a wrangler manifest and, where it needs ordering, the edge. Nothing
2875
+ // here says "round one" or "round two", and no project knows the depth.
2876
+ const chain: Record<string, string[]> = { a: ['b:deploy'], b: ['c:deploy'], c: [] };
2302
2877
  try {
2303
- await symlink(join(repositoryRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
2304
- await workspace.write('package.json', '{"name":"chain-workspace","private":true,"workspaces":["packages/*"]}\n');
2305
- await workspace.write(
2306
- 'nx.json',
2307
- JSON.stringify({
2308
- plugins: [fileURLToPath(new URL('../dist/index.js', import.meta.url))],
2309
- namedInputs: { default: ['{projectRoot}/**/*'] },
2310
- }),
2311
- );
2312
- // c is deepest: a's deploy calls into b's, b's calls into c's. No project declares a
2313
- // deploy target — each only has a wrangler manifest and, where it needs ordering, the
2314
- // edge. Nothing here says "round one" or "round two", and no project knows the depth.
2315
- const chain: Record<string, string[]> = { a: ['b:deploy'], b: ['c:deploy'], c: [] };
2316
- for (const [name, dependsOn] of Object.entries(chain)) {
2878
+ const nodes: Record<string, ProjectGraphProjectNode> = {};
2879
+ for (const [name, edges] of Object.entries(chain)) {
2880
+ const declared: Record<string, TargetConfiguration> =
2881
+ edges.length > 0 ? { deploy: { dependsOn: ['...', ...edges] } } : {};
2317
2882
  await workspace.write(`packages/${name}/wrangler.toml`, `name = "${name}"\n`);
2318
2883
  await workspace.write(
2319
2884
  `packages/${name}/package.json`,
2320
- JSON.stringify({
2321
- name,
2322
- private: true,
2323
- nx: {
2324
- targets: {
2325
- deploy: {
2326
- ...(dependsOn.length > 0 ? { dependsOn: ['...', ...dependsOn] } : {}),
2327
- // The real inferred command deploys to Cloudflare. Only `command` is
2328
- // overridden, so this still proves the rest of the inferred target — the
2329
- // executor that runs it, and the edges — is what carries the run.
2330
- options: {
2331
- command: `printf '%s\\n' ${name} >> ${join(root, 'deploy-order.txt')}`,
2332
- forwardAllArgs: false,
2333
- },
2334
- },
2335
- },
2336
- },
2337
- }),
2885
+ JSON.stringify({ name, private: true, nx: { targets: declared } }),
2338
2886
  );
2887
+ const targets = await inferProjectTargets(workspace, `packages/${name}/package.json`);
2888
+ const deploy = resolveDeclaredOverInferred(targets, declared, 'deploy');
2889
+ // The edge rides on the inferred target: its executor and command still carry the run.
2890
+ expect(deploy?.executor).toBe('nx:run-commands');
2891
+ expect(deploy?.options?.command).toBe('smoo wrangler deploy-stage --stage {args.stage}');
2892
+ if (deploy === undefined) throw new Error(`${name} infers no deploy`);
2893
+ nodes[name] = { name, type: 'app', data: { root: `packages/${name}`, targets: { ...targets, deploy } } };
2339
2894
  }
2340
- const child = Bun.spawn(
2341
- [
2342
- 'bun',
2343
- join(repositoryRoot, 'node_modules/.bin/nx'),
2344
- 'run-many',
2345
- '-t',
2346
- 'deploy',
2347
- '--projects=a,b,c',
2348
- '--parallel=3',
2349
- '--stage=staging',
2350
- ],
2351
- {
2352
- cwd: root,
2353
- env: {
2354
- ...fixtureNxEnv(root),
2355
- PATH: `${join(repositoryRoot, 'node_modules/.bin')}:${process.env.PATH ?? ''}`,
2356
- },
2357
- stdout: 'pipe',
2358
- stderr: 'pipe',
2359
- },
2360
- );
2361
- const [exitCode, stdout, stderr] = await Promise.all([
2362
- child.exited,
2363
- new Response(child.stdout).text(),
2364
- new Response(child.stderr).text(),
2365
- ]);
2366
- expect({ exitCode, output: stdout + stderr }).toMatchObject({ exitCode: 0 });
2367
- const order = (await readFile(join(root, 'deploy-order.txt'), 'utf8')).trim().split('\n');
2368
- expect(order).toEqual(['c', 'b', 'a']);
2895
+ const graph: ProjectGraph = { nodes, dependencies: { a: [], b: [], c: [] } };
2896
+
2897
+ // The task graph `nx run-many -t deploy --projects=a,b,c` runs: Nx starts a task only once
2898
+ // every task it depends on has finished, so this is the order.
2899
+ const tasks = createTaskGraph(graph, {}, ['a', 'b', 'c'], ['deploy'], undefined, { stage: 'staging' });
2900
+ expect(tasks.dependencies).toEqual({ 'a:deploy': ['b:deploy'], 'b:deploy': ['c:deploy'], 'c:deploy': [] });
2901
+ expect(tasks.roots).toEqual(['c:deploy']);
2369
2902
  } finally {
2370
- await cleanupNxWorkspace(workspace);
2903
+ await workspace.cleanup();
2371
2904
  }
2372
- }, 120_000);
2905
+ });
2373
2906
 
2374
2907
  it('archives a declared foreign triple beside the host archive, and runs it without building', async () => {
2375
2908
  const workspace = await createWorkspace();
@@ -2390,8 +2923,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
2390
2923
 
2391
2924
  // A distinct archive file, declared as this target's output: the host
2392
2925
  // archive must survive a cross build and each must be cached as itself.
2393
- expect(archive?.outputs).toEqual(['{projectRoot}/target/nextest/archive-aarch64-apple-darwin.tar.zst']);
2394
- expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/target/nextest/archive.tar.zst']);
2926
+ expect(archive?.outputs).toEqual(['{projectRoot}/.cache/nextest/archive-aarch64-apple-darwin.tar.zst']);
2927
+ expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/.cache/nextest/archive.tar.zst']);
2395
2928
  expect(archive?.cache).toBe(true);
2396
2929
  // Everything the host archive hashes, plus the declared driver: the
2397
2930
  // script that decides how the foreign link happens is an input of the
@@ -2407,7 +2940,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
2407
2940
  // `cargo-nextest`, not `cargo nextest`: cargo overwrites CARGO for its
2408
2941
  // subcommands, and CARGO is the only seam a cross cargo driver has.
2409
2942
  expect(String(archive?.options?.command)).toMatch(
2410
- /^mkdir -p target\/nextest && cargo-nextest nextest archive --workspace --target aarch64-apple-darwin --frozen --archive-file target\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
2943
+ /^mkdir -p \.cache\/nextest && cargo-nextest nextest archive --workspace --target aarch64-apple-darwin --frozen --archive-file \.cache\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
2411
2944
  );
2412
2945
  expect(archive?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
2413
2946
  expect(run?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
@@ -2416,7 +2949,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
2416
2949
  expect(archive?.dependsOn).toEqual(['cargo-fetch']);
2417
2950
  expect(run?.dependsOn).toEqual([]);
2418
2951
  expect(String(run?.options?.command)).toMatch(
2419
- /^cargo-nextest nextest run --archive-file target\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --workspace-remap \. --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
2952
+ /^cargo-nextest nextest run --archive-file \.cache\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --workspace-remap \. --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
2420
2953
  );
2421
2954
  expect(run?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
2422
2955
  // Not a crate: the per-crate coverage policy reads `cargo-test-<name>`,
@@ -2498,10 +3031,10 @@ async function prepareCargoFixture(root: string): Promise<void> {
2498
3031
  }
2499
3032
  }
2500
3033
 
2501
- async function createWorkspace(): Promise<WorkspaceFixture> {
3034
+ async function createWorkspace(parent = tmpdir()): Promise<WorkspaceFixture> {
2502
3035
  // Canonical, because macOS puts the temp directory behind a /private symlink
2503
3036
  // and a daemon never sees an edit made under a root named through one.
2504
- const root = await realpath(await mkdtemp(join(tmpdir(), 'smoothbricks-nx-plugin-')));
3037
+ const root = await realpath(await mkdtemp(join(parent, 'smoothbricks-nx-plugin-')));
2505
3038
 
2506
3039
  return {
2507
3040
  context: {
@@ -2519,27 +3052,6 @@ async function createWorkspace(): Promise<WorkspaceFixture> {
2519
3052
  };
2520
3053
  }
2521
3054
 
2522
- /**
2523
- * A workspace that runs real Nx. It gets its own Git boundary, as every other
2524
- * fixture here that runs Nx does: a daemon's ignore-aware watcher drops all of
2525
- * a fixture's edits when an enclosing checkout ignores the temp directory.
2526
- */
2527
- async function createNxWorkspace(): Promise<WorkspaceFixture> {
2528
- const workspace = await createWorkspace();
2529
- const initialized = Bun.spawnSync(['git', 'init', '--quiet', workspace.context.workspaceRoot]);
2530
- expect(initialized.exitCode).toBe(0);
2531
- return workspace;
2532
- }
2533
-
2534
- /** Release the fixture's own Nx daemon through Nx before its root is deleted. */
2535
- async function cleanupNxWorkspace(workspace: WorkspaceFixture): Promise<void> {
2536
- try {
2537
- await stopFixtureNxDaemon(workspace.context.workspaceRoot);
2538
- } finally {
2539
- await workspace.cleanup();
2540
- }
2541
- }
2542
-
2543
3055
  interface WorkspaceFixture {
2544
3056
  context: CreateNodesContextV2;
2545
3057
  write(filePath: string, contents: string): Promise<void>;
@@ -2609,18 +3121,6 @@ function cachedCargoTargets(targets: Record<string, TargetConfiguration>): [stri
2609
3121
  });
2610
3122
  }
2611
3123
 
2612
- /** What Nx actually hashes for a `runtime` input: the command's stdout. */
2613
- async function runtimeInputValue(command: string, cwd: string): Promise<string> {
2614
- const child = Bun.spawn(['sh', '-c', command], { cwd, stdout: 'pipe', stderr: 'pipe' });
2615
- const [exitCode, stdout, stderr] = await Promise.all([
2616
- child.exited,
2617
- new Response(child.stdout).text(),
2618
- new Response(child.stderr).text(),
2619
- ]);
2620
- expect({ command, exitCode, stderr }).toMatchObject({ command, exitCode: 0 });
2621
- return stdout;
2622
- }
2623
-
2624
3124
  async function inferProject(
2625
3125
  workspace: WorkspaceFixture,
2626
3126
  packageJsonPath: string,
@@ -2628,6 +3128,9 @@ async function inferProject(
2628
3128
  ) {
2629
3129
  const [, infer] = createNodes;
2630
3130
  await prepareCargoFixture(workspace.context.workspaceRoot);
3131
+ // Each inference indexes the tree as it is now, as a fresh Nx process would: the
3132
+ // in-process workspace context otherwise keeps the files of the first inference.
3133
+ resetWorkspaceContext();
2631
3134
  const result = await infer([packageJsonPath], undefined, workspace.context);
2632
3135
  return result[0]?.[1].projects?.[dirname(packageJsonPath)];
2633
3136
  }
@@ -2644,6 +3147,7 @@ async function inferProjectWithNxJson(
2644
3147
  ) {
2645
3148
  const [, infer] = createNodesV2;
2646
3149
  await prepareCargoFixture(workspace.context.workspaceRoot);
3150
+ resetWorkspaceContext();
2647
3151
  const result = await infer([packageJsonPath], undefined, {
2648
3152
  workspaceRoot: workspace.context.workspaceRoot,
2649
3153
  nxJsonConfiguration,
@@ -2725,3 +3229,113 @@ function expectNoSchedulerThrottle(targets: Record<string, TargetConfiguration>)
2725
3229
  expect(target.options?.parallel, `${name} options.parallel`).toBeUndefined();
2726
3230
  }
2727
3231
  }
3232
+
3233
+ /** A default-profile override that puts the tests `filter` selects in `group`, on the platform serial groups run on. */
3234
+ function serialOverride(filter: string, group: string): string[] {
3235
+ return [
3236
+ '[[profile.default.overrides]]',
3237
+ `filter = '${filter}'`,
3238
+ `platform = 'cfg(target_os="macos")'`,
3239
+ `test-group = '${group}'`,
3240
+ '',
3241
+ ];
3242
+ }
3243
+
3244
+ /** The real-image split in miniature: a device group over one crate, a host group over the two crates above it. */
3245
+ const APFS_SPLIT_GROUPS: readonly string[] = [
3246
+ '[test-groups.real-apfs]',
3247
+ 'max-threads = 1',
3248
+ '',
3249
+ '[test-groups.real-apfs-host]',
3250
+ 'max-threads = 1',
3251
+ '',
3252
+ ...serialOverride('package(cowshed-apfs-tests) and test(/real_apfs_/)', 'real-apfs'),
3253
+ ...serialOverride('package(cowshed-core) and (test(/real_apfs_/) or binary(apfs_native_macos))', 'real-apfs-host'),
3254
+ ...serialOverride('package(cowshed-cli) and test(/real_apfs_/)', 'real-apfs-host'),
3255
+ ];
3256
+
3257
+ /**
3258
+ * A repository-root Cargo workspace with two projects: `cowshed` holds the production device layer (`cowshed-apfs`,
3259
+ * which links `cowshed-os` and carries the test support the crates above it compile in), the real-image scenarios in a
3260
+ * crate of their own (`cowshed-apfs-tests`, which nothing depends on) and the host crates, and `lmao` holds a crate no
3261
+ * group can reach. `nextest` is the repository's `.config/nextest.toml`.
3262
+ */
3263
+ async function writeApfsSplitFixture(workspace: WorkspaceFixture, nextest: readonly string[]): Promise<void> {
3264
+ const crate = (
3265
+ project: string,
3266
+ name: string,
3267
+ dependencies: readonly string[] = [],
3268
+ section: 'dependencies' | 'dev-dependencies' = 'dependencies',
3269
+ ): Promise<void> =>
3270
+ workspace.write(
3271
+ `packages/${project}/crates/${name}/Cargo.toml`,
3272
+ [
3273
+ '[package]',
3274
+ `name = "${name}"`,
3275
+ ...(dependencies.length === 0
3276
+ ? []
3277
+ : ['', `[${section}]`, ...dependencies.map((dependency) => `${dependency} = { path = "../${dependency}" }`)]),
3278
+ '',
3279
+ ].join('\n'),
3280
+ );
3281
+ await workspace.write('package.json', '{"name":"@fixture/codebase"}\n');
3282
+ await workspace.write('packages/cowshed/package.json', '{"name":"@fixture/cowshed","nx":{"name":"cowshed"}}\n');
3283
+ await workspace.write('packages/lmao/package.json', '{"name":"@fixture/lmao","nx":{"name":"lmao"}}\n');
3284
+ await workspace.write('Cargo.toml', '[workspace]\nmembers = ["packages/*/crates/*"]\n');
3285
+ await crate('cowshed', 'cowshed-os');
3286
+ await crate('cowshed', 'cowshed-apfs', ['cowshed-os']);
3287
+ await crate('cowshed', 'cowshed-apfs-tests', ['cowshed-apfs', 'cowshed-os'], 'dev-dependencies');
3288
+ await crate('cowshed', 'cowshed-core', ['cowshed-apfs', 'cowshed-os']);
3289
+ await crate('cowshed', 'cowshed-cli', ['cowshed-core']);
3290
+ await crate('lmao', 'lmao-core');
3291
+ await workspace.write(
3292
+ 'packages/cowshed/crates/cowshed-apfs/tests/support/blank_image.rs',
3293
+ '// shared test support\n',
3294
+ );
3295
+ await workspace.write('.config/nextest.toml', nextest.join('\n'));
3296
+ }
3297
+
3298
+ /** Inference over the split fixture's three projects in the one call Nx makes: project root to inferred targets. */
3299
+ async function inferApfsSplit(
3300
+ workspace: WorkspaceFixture,
3301
+ createNodes: CreateNodesV2 = createNodesV2ForPlatform('darwin', 'arm64'),
3302
+ ): Promise<Map<string, Record<string, TargetConfiguration>>> {
3303
+ const [, infer] = createNodes;
3304
+ await prepareCargoFixture(workspace.context.workspaceRoot);
3305
+ resetWorkspaceContext();
3306
+ const inferred = await infer(
3307
+ ['package.json', 'packages/cowshed/package.json', 'packages/lmao/package.json'],
3308
+ undefined,
3309
+ workspace.context,
3310
+ );
3311
+ return new Map(
3312
+ inferred.flatMap(([, result]) =>
3313
+ Object.entries(result.projects ?? {}).map(([root, project]): [string, Record<string, TargetConfiguration>] => [
3314
+ root,
3315
+ project.targets ?? {},
3316
+ ]),
3317
+ ),
3318
+ );
3319
+ }
3320
+
3321
+ /** The crates whose whole tree a target hashes: one `{workspaceRoot}/…/crates/<crate>/**\/*` fileset each. */
3322
+ function hashedCrates(target: TargetConfiguration | undefined): string[] {
3323
+ const crates = (target?.inputs ?? []).flatMap((input) =>
3324
+ typeof input === 'string'
3325
+ ? (/^\{workspaceRoot\}\/packages\/[^/]+\/crates\/([^/]+)\/\*\*\/\*$/.exec(input)?.[1] ?? [])
3326
+ : [],
3327
+ );
3328
+ return [...new Set(crates)].sort((left, right) => left.localeCompare(right));
3329
+ }
3330
+
3331
+ /** Whether Nx would hash `path` (workspace-relative) under the `{workspaceRoot}` filesets of `target`'s inputs. */
3332
+ function hashes(target: TargetConfiguration | undefined, path: string): boolean {
3333
+ const filesets = (target?.inputs ?? []).flatMap((input) =>
3334
+ typeof input === 'string' && input.includes('{workspaceRoot}') ? [input] : [],
3335
+ );
3336
+ const matches = (fileset: string): boolean => new Bun.Glob(fileset.replace('{workspaceRoot}/', '')).match(path);
3337
+ return (
3338
+ filesets.some((input) => !input.startsWith('!') && matches(input)) &&
3339
+ !filesets.some((input) => input.startsWith('!') && matches(input.slice(1)))
3340
+ );
3341
+ }