@smoothbricks/nx-plugin 0.4.25 → 0.4.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/README.md +1078 -98
  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 +16 -85
  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 +16 -17
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +37 -44
  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 +50 -8
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +691 -71
  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 +108 -12
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +299 -18
  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 +213 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +624 -177
  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 +435 -230
  102. package/dist/managed-assets.d.ts +6 -0
  103. package/dist/managed-assets.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.d.ts +13 -0
  105. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  106. package/dist/managed-files/ci-workflow.js +44 -13
  107. package/dist/managed-files/files.d.ts +7 -1
  108. package/dist/managed-files/files.d.ts.map +1 -1
  109. package/dist/managed-files/files.js +62 -8
  110. package/dist/managed-files/json-edit.d.ts +21 -0
  111. package/dist/managed-files/json-edit.d.ts.map +1 -0
  112. package/dist/managed-files/json-edit.js +295 -0
  113. package/dist/managed-files/managed-format.d.ts +33 -1
  114. package/dist/managed-files/managed-format.d.ts.map +1 -1
  115. package/dist/managed-files/managed-format.js +82 -2
  116. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  117. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  119. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  120. package/dist/managed-files/publish-workflow.js +231 -48
  121. package/dist/managed-files/tree.d.ts +5 -0
  122. package/dist/managed-files/tree.d.ts.map +1 -1
  123. package/dist/managed-files/tree.js +5 -3
  124. package/dist/manifest-hash.js +3 -2
  125. package/dist/nextest-code-bound.d.ts +62 -0
  126. package/dist/nextest-code-bound.d.ts.map +1 -0
  127. package/dist/nextest-code-bound.js +154 -0
  128. package/dist/nextest-extraction.d.ts +24 -8
  129. package/dist/nextest-extraction.d.ts.map +1 -1
  130. package/dist/nextest-extraction.js +42 -7
  131. package/dist/package-target-policy.d.ts.map +1 -1
  132. package/dist/package-target-policy.js +3 -5
  133. package/dist/release-config-policy.d.ts.map +1 -1
  134. package/dist/release-config-policy.js +3 -5
  135. package/dist/runtime-input.d.ts +14 -0
  136. package/dist/runtime-input.d.ts.map +1 -0
  137. package/dist/runtime-input.js +15 -0
  138. package/dist/rust-tokens.d.ts +11 -0
  139. package/dist/rust-tokens.d.ts.map +1 -0
  140. package/dist/rust-tokens.js +81 -0
  141. package/dist/task-results.d.ts +6 -0
  142. package/dist/task-results.d.ts.map +1 -0
  143. package/dist/task-results.js +61 -0
  144. package/dist/test-program.d.ts +54 -0
  145. package/dist/test-program.d.ts.map +1 -0
  146. package/dist/test-program.js +292 -0
  147. package/dist/test-timings.d.ts +71 -0
  148. package/dist/test-timings.d.ts.map +1 -0
  149. package/dist/test-timings.js +393 -0
  150. package/dist/test-walk-policy.d.ts +103 -0
  151. package/dist/test-walk-policy.d.ts.map +1 -0
  152. package/dist/test-walk-policy.js +657 -0
  153. package/dist/testing.d.ts +177 -0
  154. package/dist/testing.d.ts.map +1 -0
  155. package/dist/testing.js +824 -0
  156. package/dist/type-guards.d.ts +3 -0
  157. package/dist/type-guards.d.ts.map +1 -0
  158. package/dist/type-guards.js +4 -0
  159. package/dist/typecheck-test-policy.d.ts +8 -5
  160. package/dist/typecheck-test-policy.d.ts.map +1 -1
  161. package/dist/typecheck-test-policy.js +113 -100
  162. package/dist/workspace-config-policy.d.ts +8 -0
  163. package/dist/workspace-config-policy.d.ts.map +1 -1
  164. package/dist/workspace-config-policy.js +175 -63
  165. package/dist/workspace-index.d.ts +12 -0
  166. package/dist/workspace-index.d.ts.map +1 -0
  167. package/dist/workspace-index.js +17 -0
  168. package/dist/workspace-manifest.d.ts +37 -1
  169. package/dist/workspace-manifest.d.ts.map +1 -1
  170. package/executors.json +5 -0
  171. package/loader.js +13 -11
  172. package/managed/raw/envrc +33 -62
  173. package/managed/raw/git-format-staged.yml +30 -35
  174. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  175. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  176. package/managed/raw/tooling/direnv/developer-links.ts +607 -17
  177. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -92
  178. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  179. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  180. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  181. package/managed/raw/tooling/direnv/repo-path +14 -2
  182. package/managed/raw/tooling/direnv/setup-environment.ts +1009 -118
  183. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  184. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  185. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  186. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  187. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  188. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  189. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  190. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  191. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  192. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  194. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  196. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  197. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  198. package/managed/templates/github/workflows/managed-files.yml +1 -2
  199. package/nextest.toml +8 -75
  200. package/package.json +75 -13
  201. package/runtime-input.sh +81 -0
  202. package/src/__tests__/counted-cargo-process.ts +286 -0
  203. package/src/__tests__/counted-cargo.ts +730 -0
  204. package/src/__tests__/fixture-cargo-home.ts +36 -0
  205. package/src/__tests__/fixture-nx-env.ts +157 -2
  206. package/src/__tests__/progress-clock.ts +43 -0
  207. package/src/__tests__/runtime-input.ts +23 -0
  208. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  209. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  210. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  211. package/src/bin/smoo-nx-exec.ts +17 -86
  212. package/src/bin/smoo-nx-failures.ts +4 -0
  213. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  214. package/src/bin/smoo-nx-test-walks.ts +42 -0
  215. package/src/bounded-test-policy.test.ts +268 -22
  216. package/src/bounded-test-policy.ts +114 -42
  217. package/src/build-state-output-policy.test.ts +115 -0
  218. package/src/build-state-output-policy.ts +90 -0
  219. package/src/bun-bootstrap.test.ts +57 -3
  220. package/src/bun-file-packages.test.ts +47 -0
  221. package/src/cargo-closure-input.test.ts +432 -62
  222. package/src/cargo-closure-input.ts +51 -57
  223. package/src/cargo-dev-profile.ts +137 -0
  224. package/src/cargo-resolve-cache.test.ts +1044 -0
  225. package/src/cargo-source-hash.test.ts +203 -93
  226. package/src/cargo-source-hash.ts +762 -75
  227. package/src/cargo-toolchain-policy.ts +6 -0
  228. package/src/cargo-workspace.test.ts +320 -0
  229. package/src/cargo-workspace.ts +344 -18
  230. package/src/cross-check-policy.test.ts +59 -1
  231. package/src/cross-check-policy.ts +25 -6
  232. package/src/disk-command-policy.test.ts +61 -0
  233. package/src/disk-command-policy.ts +107 -0
  234. package/src/ensure-built-receipt.test.ts +184 -0
  235. package/src/ensure-built-receipt.ts +263 -0
  236. package/src/ensure-built-witness.test.ts +344 -0
  237. package/src/ensure-built-witness.ts +252 -0
  238. package/src/ensure-built.test.ts +1043 -483
  239. package/src/ensure-built.ts +870 -197
  240. package/src/eslint-file-set.ts +9 -0
  241. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  242. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  243. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  244. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  245. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  246. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  247. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  248. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  249. package/src/executors/bounded-exec/executor.ts +565 -67
  250. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  251. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  252. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  253. package/src/executors/bounded-exec/progress.test.ts +79 -0
  254. package/src/executors/bounded-exec/progress.ts +118 -0
  255. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  256. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  257. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  258. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  259. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  260. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  261. package/src/executors/bounded-exec/schema.json +11 -5
  262. package/src/executors/bounded-exec/schema.ts +27 -11
  263. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  264. package/src/executors/bounded-exec/verdict.ts +433 -0
  265. package/src/executors/shard-timings/executor.ts +36 -0
  266. package/src/executors/shard-timings/schema.json +21 -0
  267. package/src/executors/shard-timings/schema.ts +4 -0
  268. package/src/failure-summary.ts +119 -0
  269. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  270. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  271. package/src/generators/create-package/generator.test.ts +6 -0
  272. package/src/generators/create-package/generator.ts +6 -2
  273. package/src/host-controller-wiring.test.ts +31 -0
  274. package/src/index.test.ts +1070 -360
  275. package/src/index.ts +524 -255
  276. package/src/linked-snapshots.nx.test.ts +172 -0
  277. package/src/managed-assets.ts +12 -0
  278. package/src/managed-files/ci-workflow.ts +54 -13
  279. package/src/managed-files/files.ts +65 -9
  280. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  281. package/src/managed-files/generator.test.ts +60 -1
  282. package/src/managed-files/json-edit.test.ts +216 -0
  283. package/src/managed-files/json-edit.ts +290 -0
  284. package/src/managed-files/managed-format-json.test.ts +308 -0
  285. package/src/managed-files/managed-format.ts +90 -2
  286. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  287. package/src/managed-files/publish-workflow.ts +285 -67
  288. package/src/managed-files/repo-path.test.ts +129 -0
  289. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  290. package/src/managed-files/tree.ts +11 -3
  291. package/src/manifest-hash.ts +3 -2
  292. package/src/nextest-code-bound.test.ts +155 -0
  293. package/src/nextest-code-bound.ts +195 -0
  294. package/src/nextest-extraction.test.ts +37 -5
  295. package/src/nextest-extraction.ts +51 -9
  296. package/src/nextest-partitions.test.ts +495 -0
  297. package/src/nx-cache-bound.test.ts +109 -0
  298. package/src/nx-cache-restore-mtime.test.ts +170 -0
  299. package/src/nx-daemon-claim.test.ts +277 -0
  300. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  301. package/src/nx-daemon-idle-policy.test.ts +51 -0
  302. package/src/nx-daemon-ignore-files.test.ts +210 -0
  303. package/src/nx-daemon-root-normalization.test.ts +105 -0
  304. package/src/nx-daemon-validity.test.ts +925 -0
  305. package/src/nx-dot-input-policy.test.ts +353 -0
  306. package/src/nx-failure-life-cycles.test.ts +207 -0
  307. package/src/nx-files-archive-racy.test.ts +97 -0
  308. package/src/nx-foreign-workspace-env.test.ts +329 -0
  309. package/src/nx-incomplete-run-summary.test.ts +70 -0
  310. package/src/nx-plugin-load-errors.test.ts +120 -0
  311. package/src/nx-project-resolution-cache.test.ts +176 -0
  312. package/src/nx-raw-inputs.test.ts +166 -0
  313. package/src/nx-resident-graph-workers.test.ts +112 -0
  314. package/src/nx-run-information.test.ts +118 -0
  315. package/src/nx-skipped-task-exit.test.ts +180 -0
  316. package/src/nx-state-location.test.ts +63 -0
  317. package/src/nx-store-resolution.test.ts +99 -0
  318. package/src/nx-task-graph-cycles.test.ts +148 -0
  319. package/src/nx-task-output-lease.test.ts +414 -0
  320. package/src/nx-use-local.test.ts +103 -0
  321. package/src/package-target-policy.ts +3 -6
  322. package/src/release-config-policy.ts +3 -6
  323. package/src/runtime-input.test.ts +215 -0
  324. package/src/runtime-input.ts +17 -0
  325. package/src/rust-tokens.ts +78 -0
  326. package/src/serial-group-wiring.test.ts +326 -0
  327. package/src/task-history-namespace.test.ts +181 -0
  328. package/src/task-results.test.ts +226 -0
  329. package/src/task-results.ts +75 -0
  330. package/src/test-program.test.ts +303 -0
  331. package/src/test-program.ts +341 -0
  332. package/src/test-timings.test.ts +240 -0
  333. package/src/test-timings.ts +311 -0
  334. package/src/test-walk-policy.test.ts +585 -0
  335. package/src/test-walk-policy.ts +731 -0
  336. package/src/testing.test.ts +509 -0
  337. package/src/testing.ts +922 -0
  338. package/src/type-guards.ts +4 -0
  339. package/src/typecheck-test-policy.test.ts +496 -11
  340. package/src/typecheck-test-policy.ts +137 -103
  341. package/src/workspace-config-policy.test.ts +212 -13
  342. package/src/workspace-config-policy.ts +101 -73
  343. package/src/workspace-index.ts +18 -0
  344. package/src/workspace-manifest.ts +41 -1
  345. package/test-timings.json +85 -28
  346. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -615
  347. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
  348. package/src/__tests__/in-process-nx-index.ts +0 -9
@@ -1,26 +1,46 @@
1
1
  import { expect, it } from 'bun:test';
2
- import { execFileSync } from 'node:child_process';
3
- import { mkdir, mkdtemp, readFile, realpath, rm, stat, symlink, utimes, writeFile } from 'node:fs/promises';
2
+ import { execFile, execFileSync } from 'node:child_process';
3
+ import { appendFile, mkdir, mkdtemp, readFile, realpath, rm, stat, symlink, utimes, writeFile } from 'node:fs/promises';
4
4
  import { tmpdir } from 'node:os';
5
5
  import { dirname, join } from 'node:path';
6
+ import { promisify } from 'node:util';
6
7
 
7
- import { resetWorkspaceContext } from 'nx/src/utils/workspace-context.js';
8
- import { fixtureNxEnv } from './__tests__/fixture-nx-env.js';
9
- import { CARGO_CLOSURE_INPUT } from './cargo-closure-input.js';
8
+ import type { CreateNodesResultV2 } from 'nx/src/devkit-exports.js';
9
+ import { Watcher, WorkspaceContext } from 'nx/src/native/index.js';
10
+ import { globWithWorkspaceContextSync, resetWorkspaceContext } from 'nx/src/utils/workspace-context.js';
11
+ import {
12
+ aggregateOf,
13
+ type CountedCargo,
14
+ countedCargo,
15
+ expectGraphRefusal,
16
+ guardEvent,
17
+ rejectionOf,
18
+ waitForCargoJoins,
19
+ withEnvironment,
20
+ } from './__tests__/counted-cargo.js';
21
+ import { useFixtureCargoHome } from './__tests__/fixture-cargo-home.js';
22
+ import { runtimeInputValue } from './__tests__/runtime-input.js';
23
+ import { CARGO_CLOSURE_INPUT, indexedCargoManifests } from './cargo-closure-input.js';
24
+ import { hashCargoPathInputs } from './cargo-source-hash.js';
10
25
  import { createNodesV2 } from './index.js';
11
26
 
12
27
  const repositoryRoot = join(import.meta.dir, '../../..');
13
28
 
29
+ useFixtureCargoHome();
30
+
14
31
  /**
15
32
  * An Nx workspace that is also the Cargo workspace. `app` reaches `leaf`
16
33
  * through `bridge`, and `external` — outside the Nx workspace — through
17
- * `bridge` too. `unrelated` is a member nothing depends on. `app` records
18
- * every real compile in `executions.log`, so a cache hit is an unchanged log.
34
+ * `bridge` too. `unrelated` is a member nothing depends on. `app` declares a
35
+ * custom cached target keyed on its closure.
36
+ * `extraFiles` (paths relative to `root`) are written with the rest, last.
19
37
  */
20
- async function closureFixture(root: string, gitignore = 'node_modules/\ntarget/\ndist/\n.nx/\n') {
38
+ async function closureFixture(
39
+ root: string,
40
+ gitignore = 'node_modules/\ntarget/\ndist/\n.nx/\n',
41
+ extraFiles: Record<string, string> = {},
42
+ ) {
21
43
  const workspace = join(root, 'workspace');
22
- const executions = join(root, 'executions.log');
23
- const output = join(workspace, 'packages/app/dist/result.txt');
24
44
  const files: Record<string, string> = {
25
45
  'workspace/.gitignore': gitignore,
26
46
  'workspace/package.json':
@@ -39,20 +59,12 @@ async function closureFixture(root: string, gitignore = 'node_modules/\ntarget/\
39
59
  compile: {
40
60
  executor: 'nx:run-commands',
41
61
  cache: true,
42
- inputs: ['{projectRoot}/compile.ts', CARGO_CLOSURE_INPUT],
43
- outputs: ['{projectRoot}/dist'],
44
- options: { command: 'bun packages/app/compile.ts' },
62
+ inputs: [CARGO_CLOSURE_INPUT],
63
+ options: { command: 'cargo build --quiet --locked --offline --manifest-path packages/app/Cargo.toml' },
45
64
  },
46
65
  },
47
66
  },
48
67
  }),
49
- 'workspace/packages/app/compile.ts': `import { execFileSync } from 'node:child_process';
50
- import { appendFile, mkdir, writeFile } from 'node:fs/promises';
51
- const result = execFileSync('cargo', ['run', '--quiet', '--locked', '--offline', '--manifest-path', 'packages/app/Cargo.toml'], { encoding: 'utf8' });
52
- await mkdir(${JSON.stringify(dirname(output))}, { recursive: true });
53
- await writeFile(${JSON.stringify(output)}, result);
54
- await appendFile(${JSON.stringify(executions)}, result);
55
- `,
56
68
  'workspace/packages/app/Cargo.toml':
57
69
  '[package]\nname="app"\nversion="0.1.0"\nedition="2021"\n[dependencies]\nbridge={path="../../crates/bridge"}\n',
58
70
  'workspace/packages/app/src/main.rs': 'fn main() { println!("{}", bridge::answer()); }\n',
@@ -66,6 +78,7 @@ await appendFile(${JSON.stringify(executions)}, result);
66
78
  'workspace/crates/unrelated/src/lib.rs': 'pub fn unrelated() -> u8 { 3 }\n',
67
79
  'external/Cargo.toml': '[package]\nname="external"\nversion="0.1.0"\nedition="2021"\n[workspace]\n',
68
80
  'external/src/lib.rs': 'pub fn answer() -> u8 { 10 }\n',
81
+ ...extraFiles,
69
82
  };
70
83
  for (const [path, text] of Object.entries(files)) {
71
84
  await mkdir(dirname(join(root, path)), { recursive: true });
@@ -77,21 +90,6 @@ await appendFile(${JSON.stringify(executions)}, result);
77
90
  stdio: 'pipe',
78
91
  });
79
92
 
80
- /** `nx run app:compile` in a fresh process, as CI runs it; the built plugin is the one Nx loads. */
81
- async function compile(): Promise<void> {
82
- const child = Bun.spawn(['bun', join(repositoryRoot, 'node_modules/.bin/nx'), 'run', 'app:compile'], {
83
- cwd: workspace,
84
- env: fixtureNxEnv(workspace),
85
- stdout: 'pipe',
86
- stderr: 'pipe',
87
- });
88
- const [exitCode, stdout, stderr] = await Promise.all([
89
- child.exited,
90
- new Response(child.stdout).text(),
91
- new Response(child.stderr).text(),
92
- ]);
93
- expect(exitCode, stdout + stderr).toBe(0);
94
- }
95
93
  /**
96
94
  * Rewrite a fixture file as an edit Nx can see. Nx keeps each file's hash
97
95
  * beside its mtime in whole seconds and reuses the hash until that second
@@ -106,47 +104,125 @@ await appendFile(${JSON.stringify(executions)}, result);
106
104
  const edited = new Date(Math.max(Date.now(), mtimeMs + 1000));
107
105
  await utimes(file, edited, edited);
108
106
  }
109
- const log = () => readFile(executions, 'utf8');
110
- return { workspace, compile, edit, log };
107
+ return { workspace, edit };
111
108
  }
112
109
 
113
110
  it('keys a custom target on exactly its Cargo closure, inside the workspace and out', async () => {
114
111
  const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-')));
115
112
  try {
116
- const { compile, edit, log } = await closureFixture(root);
117
- await compile();
118
- expect(await log()).toBe('11\n');
119
- await compile();
120
- expect(await log()).toBe('11\n');
121
-
122
- // Reached only through bridge: no path of app's own names it.
123
- await edit('workspace/crates/leaf/src/lib.rs', 'pub fn answer() -> u8 { 2 }\n');
124
- await compile();
125
- expect(await log()).toBe('11\n12\n');
126
-
127
- // A workspace member outside the closure is not an input.
113
+ const { workspace, edit } = await closureFixture(root);
114
+ resetWorkspaceContext();
115
+ const closure = closureOf(byFile(await graphComputation(workspace)()), 'packages/app');
116
+ const filesets = closure.flatMap((input) => (typeof input === 'string' ? [input] : []));
117
+ const runtime = closure.flatMap((input) =>
118
+ typeof input === 'object' && 'runtime' in input ? [input.runtime] : [],
119
+ );
120
+ // What the closure's filesets reach, as Nx's own file index matches them: `!` entries exclude. In
121
+ // process, as the plugin reads a root no daemon serves (`indexedCargoManifests`).
122
+ const anchored = (inputs: string[]) =>
123
+ inputs.map((input) => {
124
+ expect(input).toStartWith('{workspaceRoot}/');
125
+ return input.slice('{workspaceRoot}/'.length);
126
+ });
127
+ const keyed = globWithWorkspaceContextSync(
128
+ workspace,
129
+ anchored(filesets.filter((input) => !input.startsWith('!'))),
130
+ anchored(filesets.flatMap((input) => (input.startsWith('!') ? [input.slice(1)] : []))),
131
+ );
132
+ // The one runtime entry, which Nx keys on by its stdout.
133
+ expect(runtime).toHaveLength(1);
134
+ const outside = () => runtimeInputValue(runtime.join(), workspace);
135
+ const before = await outside();
136
+
137
+ // Reached only through bridge: no path of app's own names it. A workspace member outside the
138
+ // closure is not an input.
139
+ expect(keyed.filter((path) => path.endsWith('.rs')).sort()).toEqual([
140
+ 'crates/bridge/src/lib.rs',
141
+ 'crates/leaf/src/lib.rs',
142
+ 'packages/app/src/main.rs',
143
+ ]);
128
144
  await edit('workspace/crates/unrelated/src/lib.rs', 'pub fn unrelated() -> u8 { 4 }\n');
129
- await compile();
130
- expect(await log()).toBe('11\n12\n');
145
+ expect(await outside()).toBe(before);
131
146
 
132
- // Outside the Nx workspace, where no fileset reaches.
147
+ // Outside the Nx workspace, where no fileset reaches: the runtime entry does.
133
148
  await edit('external/src/lib.rs', 'pub fn answer() -> u8 { 20 }\n');
134
- await compile();
135
- expect(await log()).toBe('11\n12\n22\n');
149
+ expect(await outside()).not.toBe(before);
150
+ } finally {
151
+ await rm(root, { recursive: true, force: true });
152
+ }
153
+ }, 120_000);
154
+
155
+ it('keys literal compiled-in data inside and outside crate directories without keying comments or unrelated crates', async () => {
156
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-compiled-data-')));
157
+ try {
158
+ const { workspace, edit } = await closureFixture(root, undefined, {
159
+ 'workspace/packages/app/src/main.rs':
160
+ 'const LOCAL: &str = include_str!("data/local.txt");\nfn main() { println!("{}", bridge::answer()); }\n',
161
+ 'workspace/packages/app/src/data/local.txt': 'local-one',
162
+ 'workspace/crates/bridge/src/lib.rs':
163
+ 'pub fn answer() -> u8 { leaf::answer() + external::answer() }\npub const DATA: &[u8] = include_bytes!("../../shared/config.json");\n',
164
+ 'workspace/crates/shared/config.json': '{"value":1}',
165
+ 'workspace/crates/leaf/src/lib.rs': [
166
+ 'pub fn answer() -> u8 { 1 }',
167
+ 'pub const SKILL: &str = include_str!(r#"../../../skills/SKILL.md"#,);',
168
+ '// include_str!("../../../comment-only.txt")',
169
+ '/* nested /* include_bytes!("../../../comment-only.txt") */ comment */',
170
+ 'const EXAMPLE: &str = r#"include_str!("../../../example-only.txt")"#;',
171
+ ].join('\n'),
172
+ 'workspace/skills/SKILL.md': 'skill-one',
173
+ 'workspace/comment-only.txt': 'comment-one',
174
+ 'workspace/example-only.txt': 'example-one',
175
+ 'external/src/lib.rs': 'pub fn answer() -> u8 { 10 }\nconst DATA: &str = include_str!("../data.txt");\n',
176
+ 'external/data.txt': 'external-one',
177
+ });
178
+ resetWorkspaceContext();
179
+ const inputs = closureOf(byFile(await graphComputation(workspace)()), 'packages/app');
180
+ const positive = inputs.flatMap((input) =>
181
+ typeof input === 'string' && !input.startsWith('!') ? [input.slice('{workspaceRoot}/'.length)] : [],
182
+ );
183
+ const negative = inputs.flatMap((input) =>
184
+ typeof input === 'string' && input.startsWith('!') ? [input.slice('!{workspaceRoot}/'.length)] : [],
185
+ );
186
+ const context = new WorkspaceContext(workspace, join(workspace, '.nx/compiled-data-context'));
187
+ const keyed = context.glob(positive, negative);
188
+ for (const path of ['packages/app/src/data/local.txt', 'crates/shared/config.json', 'skills/SKILL.md'])
189
+ expect(keyed).toContain(path);
190
+ for (const path of ['comment-only.txt', 'example-only.txt', 'crates/unrelated/src/lib.rs'])
191
+ expect(keyed).not.toContain(path);
192
+ const before = context.hashFilesMatchingGlob(positive, negative);
193
+ await edit('workspace/packages/app/src/data/local.txt', 'local-two');
194
+ context.incrementalUpdate(['packages/app/src/data/local.txt'], []);
195
+ const changed = context.hashFilesMatchingGlob(positive, negative);
196
+ expect(changed).not.toBe(before);
197
+ await edit('workspace/comment-only.txt', 'comment-two');
198
+ await edit('workspace/crates/unrelated/src/lib.rs', 'pub fn unrelated() -> u8 { 4 }\n');
199
+ context.incrementalUpdate(['comment-only.txt', 'crates/unrelated/src/lib.rs'], []);
200
+ expect(context.hashFilesMatchingGlob(positive, negative)).toBe(changed);
201
+ const outside = await hashCargoPathInputs(join(workspace, 'Cargo.toml'), workspace, {
202
+ closure: join(workspace, 'packages/app'),
203
+ });
204
+ await edit('external/data.txt', 'external-two');
205
+ expect(
206
+ await hashCargoPathInputs(join(workspace, 'Cargo.toml'), workspace, { closure: join(workspace, 'packages/app') }),
207
+ ).not.toBe(outside);
136
208
  } finally {
137
209
  await rm(root, { recursive: true, force: true });
138
210
  }
139
211
  }, 120_000);
140
212
 
141
- it('hashes a closure member in an ignored directory, which no fileset can see', async () => {
213
+ it('refuses a closure member in an ignored directory, which no fileset can see, instead of hashing the whole workspace', async () => {
142
214
  const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-ignored-')));
143
215
  try {
144
- const { compile, edit, log } = await closureFixture(root, 'node_modules/\ntarget/\ndist/\n.nx/\ncrates/leaf/\n');
145
- await compile();
146
- expect(await log()).toBe('11\n');
147
- await edit('workspace/crates/leaf/src/lib.rs', 'pub fn answer() -> u8 { 2 }\n');
148
- await compile();
149
- expect(await log()).toBe('11\n12\n');
216
+ const { workspace } = await closureFixture(root, 'node_modules/\ntarget/\ndist/\n.nx/\ncrates/leaf/\n');
217
+ resetWorkspaceContext();
218
+ const failure = aggregateOf(await rejectionOf(graphComputation(workspace)()));
219
+ const refusals = failure.errors.flatMap(([, error]) => (error.name === 'CargoClosureInputError' ? [error] : []));
220
+ expect(refusals.length).toBeGreaterThan(0);
221
+ for (const error of refusals) expect(error.message).toContain('crates/leaf');
222
+ // `app` reaches the ignored crate through `bridge`: its closure is what no fileset can name.
223
+ expect(refusals.map((error) => Reflect.get(error, 'projectRoot'))).toContain('packages/app');
224
+ // No runtime hash of the whole workspace stands in for it.
225
+ expect(JSON.stringify(failure.partialResults)).not.toContain('--include-workspace');
150
226
  } finally {
151
227
  await rm(root, { recursive: true, force: true });
152
228
  }
@@ -176,9 +252,303 @@ it('leaves a closure inside the workspace to Nx: no process runs when its tasks
176
252
  // app reaches `external`, the one member only a process can hash, and
177
253
  // only it: the in-workspace members stay filesets.
178
254
  expect(runtimeCommands('packages/app')).toEqual([
179
- 'node node_modules/@smoothbricks/nx-plugin/dist/bin/smoo-nx-cargo-hash.js --closure packages/app Cargo.toml',
255
+ 'sh node_modules/@smoothbricks/nx-plugin/runtime-input.sh node node_modules/@smoothbricks/nx-plugin/dist/bin/smoo-nx-cargo-hash.js --closure packages/app Cargo.toml',
180
256
  ]);
181
257
  } finally {
182
258
  await rm(root, { recursive: true, force: true });
183
259
  }
184
260
  }, 120_000);
261
+
262
+ /** `leaf` as the fixture writes it, and the dependency that draws `unrelated` into every closure reaching `leaf`. */
263
+ const LEAF_MANIFEST = '[package]\nname="leaf"\nversion="0.1.0"\nedition="2021"\n';
264
+ const LEAF_LINK = '[dependencies]\nunrelated={path="../unrelated"}\n';
265
+
266
+ /** The fileset the plugin names for the closure members `crates` (a name or a `{a,b}` set) under `crates/`. */
267
+ const crateFiles = (crates: string) =>
268
+ `{workspaceRoot}/crates/${crates}/**/{*.rs,Cargo.toml,.cargo/config,.cargo/config.toml}`;
269
+
270
+ /** One project-graph computation over the fixture: the plugin's `createNodes`, as Nx runs it for each recomputation. */
271
+ function graphComputation(workspace: string) {
272
+ const [, infer] = createNodesV2;
273
+ return async () =>
274
+ infer(['package.json', 'packages/app/package.json', 'crates/leaf/package.json'], undefined, {
275
+ workspaceRoot: workspace,
276
+ nxJsonConfiguration: { namedInputs: { externalRustCrates: [] } },
277
+ });
278
+ }
279
+
280
+ /** The computation's nodes in file order: the plugin pushes them as their projects finish. */
281
+ function byFile(graph: CreateNodesResultV2): CreateNodesResultV2 {
282
+ return [...graph].sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));
283
+ }
284
+
285
+ /** The `cargoClosure` definition the computation gave the project at `projectRoot`. */
286
+ function closureOf(graph: CreateNodesResultV2, projectRoot: string) {
287
+ return (
288
+ graph.find(([file]) => dirname(file) === projectRoot)?.[1].projects?.[projectRoot]?.namedInputs?.[
289
+ CARGO_CLOSURE_INPUT
290
+ ] ?? []
291
+ );
292
+ }
293
+
294
+ /** Turn `leaf`'s dependency on `unrelated` on or off, and bring Cargo.lock in line with the manifests. */
295
+ function leafControls(workspace: string, edit: (path: string, text: string) => Promise<void>) {
296
+ return {
297
+ linkLeaf: (linked: boolean) => edit('workspace/crates/leaf/Cargo.toml', LEAF_MANIFEST + (linked ? LEAF_LINK : '')),
298
+ relock: () =>
299
+ execFileSync('cargo', ['generate-lockfile', '--offline', '--manifest-path', join(workspace, 'Cargo.toml')], {
300
+ stdio: 'pipe',
301
+ }),
302
+ };
303
+ }
304
+
305
+ it('delegates counted Cargo through the caller launcher without re-entering its broker', async () => {
306
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-counted-delegate-')));
307
+ let fixtureCargo: CountedCargo | undefined;
308
+ try {
309
+ const { workspace } = await closureFixture(root);
310
+ const manifest = join(workspace, 'Cargo.toml');
311
+ const args = ['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', manifest];
312
+ const expected = execFileSync('cargo', args, { encoding: 'utf8' });
313
+ const cargo = await countedCargo(root);
314
+ fixtureCargo = cargo;
315
+ await withEnvironment(cargo.environment, async () => {
316
+ const answer = promisify(execFile)('cargo', args);
317
+ await cargo.waitForRuns((runs) => runs.read === 1, 'the delegated real Cargo answer');
318
+ expect((await answer).stdout).toBe(expected);
319
+ expect(await cargo.runs()).toMatchObject({ spawned: 1, read: 1, peak: 1 });
320
+ // Forwarded subcommands must use the same original delegate path, not loop through the shim.
321
+ const located = await promisify(execFile)('cargo', [
322
+ 'locate-project',
323
+ '--workspace',
324
+ '--manifest-path',
325
+ manifest,
326
+ '--message-format',
327
+ 'plain',
328
+ ]);
329
+ expect(located.stdout.trim()).toBe(manifest);
330
+ expect((await cargo.runs()).spawned).toBe(1);
331
+ });
332
+ } finally {
333
+ await fixtureCargo?.release();
334
+ await rm(root, { recursive: true, force: true });
335
+ }
336
+ }, 30_000);
337
+
338
+ it('shares one Cargo child among overlapping graph computations, and an unchanged workspace never asks Cargo again', async () => {
339
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-overlap-')));
340
+ let fixtureCargo: CountedCargo | undefined;
341
+ try {
342
+ const { workspace, edit } = await closureFixture(root);
343
+ const { linkLeaf, relock } = leafControls(workspace, edit);
344
+ const cargo = await countedCargo(root);
345
+ fixtureCargo = cargo;
346
+ const graph = graphComputation(workspace);
347
+ resetWorkspaceContext();
348
+ await withEnvironment(cargo.environment, async () => {
349
+ // Watcher events start computations while earlier ones still run: here sixteen at once, over a
350
+ // workspace nobody has resolved, each Cargo child holding its answer so that a child per
351
+ // computation would certainly overlap. One child answers all of them.
352
+ await cargo.beforeAnswer.close();
353
+ const joins = waitForCargoJoins(join(workspace, 'Cargo.toml'), 15);
354
+ let overlapping: CreateNodesResultV2[];
355
+ try {
356
+ const computations = Array.from({ length: 16 }, graph);
357
+ await cargo.waitForRuns((runs) => runs.read === 1, 'the shared Cargo answer');
358
+ await joins.joined;
359
+ await cargo.beforeAnswer.open();
360
+ overlapping = await Promise.all(computations);
361
+ } finally {
362
+ joins.dispose();
363
+ }
364
+ const overlapped = await cargo.runs();
365
+ expect(overlapped.spawned).toBe(1);
366
+ expect(overlapped.peak).toBe(1);
367
+
368
+ const baseline = byFile(await graph());
369
+ for (const computed of overlapping) expect(byFile(computed)).toEqual(baseline);
370
+ expect(closureOf(baseline, 'packages/app')).toContain(crateFiles('{bridge,leaf}'));
371
+ expect(closureOf(baseline, 'packages/app')).not.toContain(crateFiles('{bridge,leaf,unrelated}'));
372
+
373
+ // Nothing Cargo reads has changed since, so no computation asks it again, however often it runs.
374
+ expect(byFile(await graph())).toEqual(baseline);
375
+ expect((await cargo.runs()).spawned).toBe(1);
376
+
377
+ // An edit to what Cargo reads is seen by the next computation, and costs one child.
378
+ await linkLeaf(true);
379
+ relock();
380
+ const edited = byFile(await graph());
381
+ expect(closureOf(edited, 'packages/app')).toContain(crateFiles('{bridge,leaf,unrelated}'));
382
+ expect(byFile(await graph())).toEqual(edited);
383
+ const settled = await cargo.runs();
384
+ expect(settled.spawned).toBe(2);
385
+ expect(settled.peak).toBe(1);
386
+ });
387
+ } finally {
388
+ await fixtureCargo?.release();
389
+ await rm(root, { recursive: true, force: true });
390
+ }
391
+ }, 120_000);
392
+
393
+ it('refuses with a typed error what Cargo refuses, and follows an edit made while a child holds its answer with a resolution after it', async () => {
394
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-pending-')));
395
+ let fixtureCargo: CountedCargo | undefined;
396
+ try {
397
+ const { workspace, edit } = await closureFixture(root);
398
+ const { linkLeaf, relock } = leafControls(workspace, edit);
399
+ const cargo = await countedCargo(root);
400
+ fixtureCargo = cargo;
401
+ const graph = graphComputation(workspace);
402
+ const baselineLock = await readFile(join(workspace, 'Cargo.lock'), 'utf8');
403
+ resetWorkspaceContext();
404
+ await withEnvironment(cargo.environment, async () => {
405
+ const baseline = byFile(await graph());
406
+
407
+ // Cargo refuses a Cargo.lock the manifests have outgrown (`--locked`): the computation fails,
408
+ // whole, with Cargo's reason. No runtime hash stands in for the closure, and the refusal is
409
+ // not kept for the next computation.
410
+ await linkLeaf(true);
411
+ expectGraphRefusal(await rejectionOf(graph()), join(workspace, 'Cargo.toml'));
412
+ relock();
413
+ const repaired = byFile(await graph());
414
+ expect(closureOf(repaired, 'packages/app')).toContain(crateFiles('{bridge,leaf,unrelated}'));
415
+ expect(JSON.stringify(repaired)).not.toContain('--include-workspace');
416
+ expect((await cargo.runs()).spawned).toBe(3);
417
+
418
+ // A computation that asks while a child holds its answer waits for that child. One that asks
419
+ // after an edit made since the child read the workspace does not take that answer for the edited
420
+ // workspace's: a resolution follows the first, never beside it.
421
+ await cargo.beforeAnswer.close();
422
+ await linkLeaf(false);
423
+ await writeFile(join(workspace, 'Cargo.lock'), baselineLock);
424
+ const before = await cargo.runs();
425
+ const early = graph();
426
+ await cargo.waitForRuns((runs) => runs.read > before.read, 'the running Cargo child to read the workspace');
427
+ // Use content the successful cache has never seen; restoring the repaired
428
+ // content would correctly reuse that entry after discarding the held answer.
429
+ await edit(
430
+ 'workspace/crates/leaf/Cargo.toml',
431
+ (LEAF_MANIFEST + LEAF_LINK).replace('version="0.1.0"', 'version="0.2.0"'),
432
+ );
433
+ relock();
434
+ const joins = waitForCargoJoins(join(workspace, 'Cargo.toml'), 1);
435
+ const late = graph();
436
+ try {
437
+ await joins.joined;
438
+ } finally {
439
+ joins.dispose();
440
+ }
441
+ await cargo.beforeAnswer.open();
442
+ expect(byFile(await late)).toEqual(repaired);
443
+ // The early computation began before the edit: it saw the workspace on either side of it.
444
+ expect([baseline, repaired]).toContainEqual(byFile(await early));
445
+ const shared = await cargo.runs();
446
+ expect(shared.spawned - before.spawned).toBe(2);
447
+ expect(shared.peak).toBe(1);
448
+
449
+ // Nothing is pending once both have settled, and nothing has changed since.
450
+ expect(byFile(await graph())).toEqual(repaired);
451
+ expect((await cargo.runs()).spawned).toBe(shared.spawned);
452
+ });
453
+ } finally {
454
+ await fixtureCargo?.release();
455
+ await rm(root, { recursive: true, force: true });
456
+ }
457
+ }, 120_000);
458
+
459
+ it("indexes a source tree's Cargo manifests and none of the runtime state a cowshed keeps in it", async () => {
460
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-runtime-state-')));
461
+ try {
462
+ const { workspace } = await closureFixture(root, undefined, {
463
+ 'workspace/.nxignore': await readFile(join(repositoryRoot, '.nxignore'), 'utf8'),
464
+ 'workspace/.cowshed/cache/nx/workspace-data/d/daemon.log': 'daemon log\n',
465
+ 'workspace/.cowshed/job/1/stdout.log': 'job output\n',
466
+ 'workspace/.cowshed/cache/cargo/registry/Cargo.toml':
467
+ '[package]\nname="cached"\nversion="0.1.0"\nedition="2021"\n',
468
+ });
469
+ resetWorkspaceContext();
470
+ expect([...(await indexedCargoManifests(workspace))].sort()).toEqual([
471
+ 'Cargo.toml',
472
+ 'crates/bridge/Cargo.toml',
473
+ 'crates/leaf/Cargo.toml',
474
+ 'crates/unrelated/Cargo.toml',
475
+ 'packages/app/Cargo.toml',
476
+ ]);
477
+ } finally {
478
+ await rm(root, { recursive: true, force: true });
479
+ }
480
+ }, 120_000);
481
+
482
+ const SOURCE_FILE = 'src/lib.rs';
483
+
484
+ /**
485
+ * Every path the native watcher reports for a fresh workspace under `nxignore`
486
+ * while a cowshed writes its runtime state (the daemon's own log, job output,
487
+ * a supervisor's pid file) beside a source file that changes every round. This is
488
+ * the watcher Nx's daemon subscribes to the workspace with: it recomputes the
489
+ * project graph for each batch of events it reports, with no filter of its
490
+ * own. Each round advances on its unique source file's native callback, not
491
+ * on a guessed subscription or debounce delay.
492
+ */
493
+ async function watchedPaths(nxignore: string): Promise<string[]> {
494
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-watch-')));
495
+ const reported = new Set<string>();
496
+ const failures: string[] = [];
497
+ let watcher: Watcher | undefined;
498
+ let pending: { path: string; resolve(): void; reject(error: Error): void } | undefined;
499
+ try {
500
+ execFileSync('git', ['init', '--quiet', root], { stdio: 'pipe' });
501
+ await writeFile(join(root, '.nxignore'), nxignore);
502
+ await mkdir(join(root, 'src'), { recursive: true });
503
+ await mkdir(join(root, '.cowshed/cache/nx/workspace-data/d'), { recursive: true });
504
+ await mkdir(join(root, '.cowshed/run'), { recursive: true });
505
+ watcher = new Watcher(root);
506
+ // Native watch() registers the filesystem subscription synchronously.
507
+ watcher.watch((error, events) => {
508
+ if (error !== null) {
509
+ failures.push(error);
510
+ pending?.reject(new Error(error));
511
+ }
512
+ for (const event of events) {
513
+ reported.add(event.path);
514
+ if (event.path === pending?.path) {
515
+ pending.resolve();
516
+ pending = undefined;
517
+ }
518
+ }
519
+ });
520
+ for (let round = 0; round < 5; round += 1) {
521
+ const source = round === 0 ? SOURCE_FILE : `src/round-${round}.rs`;
522
+ const observed = new Promise<void>((resolve, reject) => {
523
+ pending = { path: source, resolve, reject };
524
+ });
525
+ const writes = (async () => {
526
+ await appendFile(join(root, '.cowshed/cache/nx/workspace-data/d/daemon.log'), `round ${round}\n`);
527
+ await mkdir(join(root, '.cowshed/job', String(round)), { recursive: true });
528
+ await writeFile(join(root, '.cowshed/job', String(round), 'stdout.log'), `round ${round}\n`);
529
+ await writeFile(join(root, '.cowshed/run/supervisor.pid'), `${round}\n`);
530
+ await writeFile(join(root, source), `pub fn round() -> u8 { ${round} }\n`);
531
+ })();
532
+ await guardEvent(Promise.all([observed, writes]), `native watcher callback for ${source}`, () =>
533
+ JSON.stringify({ pending: pending?.path, reported: [...reported], failures }),
534
+ );
535
+ for (const event of watcher.forceFlushPending()) reported.add(event.path);
536
+ }
537
+ expect(failures).toEqual([]);
538
+ return [...reported].sort();
539
+ } finally {
540
+ await watcher?.stop();
541
+ await rm(root, { recursive: true, force: true });
542
+ }
543
+ }
544
+
545
+ it("keeps a cowshed's runtime state from waking the watcher that recomputes the project graph", async () => {
546
+ // With nothing ignored, the watcher does report runtime state: that is what
547
+ // makes the daemon's own log writes feed its next recomputation.
548
+ expect((await watchedPaths('')).filter((path) => path.startsWith('.cowshed'))).not.toEqual([]);
549
+
550
+ // With the repository's own .nxignore it reports the source file alone.
551
+ const paths = await watchedPaths(await readFile(join(repositoryRoot, '.nxignore'), 'utf8'));
552
+ expect(paths).toContain(SOURCE_FILE);
553
+ expect(paths.filter((path) => path.startsWith('.cowshed'))).toEqual([]);
554
+ }, 120_000);