@smoothbricks/nx-plugin 0.5.7 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (446) hide show
  1. package/README.md +1097 -360
  2. package/dist/.build-inputs.json +141 -0
  3. package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
  4. package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
  6. package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
  7. package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
  9. package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
  10. package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-nextest-timings.js +28 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +14 -15
  15. package/dist/build-state-output-policy.d.ts +95 -1
  16. package/dist/build-state-output-policy.d.ts.map +1 -1
  17. package/dist/build-state-output-policy.js +368 -30
  18. package/dist/bun-lock-scope.d.ts +44 -0
  19. package/dist/bun-lock-scope.d.ts.map +1 -0
  20. package/dist/bun-lock-scope.js +97 -0
  21. package/dist/cargo-build-script-env.d.ts +49 -0
  22. package/dist/cargo-build-script-env.d.ts.map +1 -0
  23. package/dist/cargo-build-script-env.js +324 -0
  24. package/dist/cargo-closure-input.d.ts +31 -4
  25. package/dist/cargo-closure-input.d.ts.map +1 -1
  26. package/dist/cargo-closure-input.js +66 -6
  27. package/dist/cargo-retention-hook.d.ts +17 -0
  28. package/dist/cargo-retention-hook.d.ts.map +1 -0
  29. package/dist/cargo-retention-hook.js +85 -0
  30. package/dist/cargo-source-hash.d.ts +25 -7
  31. package/dist/cargo-source-hash.d.ts.map +1 -1
  32. package/dist/cargo-source-hash.js +108 -43
  33. package/dist/cargo-toolchain-paths.d.ts +40 -0
  34. package/dist/cargo-toolchain-paths.d.ts.map +1 -0
  35. package/dist/cargo-toolchain-paths.js +84 -0
  36. package/dist/cargo-toolchain-policy.d.ts +25 -8
  37. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  38. package/dist/cargo-toolchain-policy.js +39 -5
  39. package/dist/cargo-workspace.d.ts +10 -4
  40. package/dist/cargo-workspace.d.ts.map +1 -1
  41. package/dist/cargo-workspace.js +65 -95
  42. package/dist/cross-check-policy.d.ts +9 -9
  43. package/dist/cross-check-policy.d.ts.map +1 -1
  44. package/dist/cross-check-policy.js +11 -11
  45. package/dist/disk-command-policy.d.ts.map +1 -1
  46. package/dist/disk-command-policy.js +1 -0
  47. package/dist/ensure-built-receipt.d.ts +22 -5
  48. package/dist/ensure-built-receipt.d.ts.map +1 -1
  49. package/dist/ensure-built-receipt.js +168 -48
  50. package/dist/ensure-built-witness.d.ts +27 -8
  51. package/dist/ensure-built-witness.d.ts.map +1 -1
  52. package/dist/ensure-built-witness.js +45 -15
  53. package/dist/ensure-built.d.ts.map +1 -1
  54. package/dist/ensure-built.js +9 -1
  55. package/dist/eslint-config-closure.d.ts +7 -0
  56. package/dist/eslint-config-closure.d.ts.map +1 -0
  57. package/dist/eslint-config-closure.js +346 -0
  58. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  59. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  60. package/dist/executors/bounded-exec/bounds.js +43 -0
  61. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +28 -0
  62. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -0
  63. package/dist/executors/bounded-exec/cpu-pool-thread.js +20 -0
  64. package/dist/executors/bounded-exec/cpu-pool.d.ts +35 -38
  65. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  66. package/dist/executors/bounded-exec/cpu-pool.js +56 -120
  67. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  68. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/executor.js +389 -239
  70. package/dist/executors/bounded-exec/gateway-lease.d.ts +23 -19
  71. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/gateway-lease.js +102 -29
  73. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  74. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  75. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  76. package/dist/executors/bounded-exec/lease-wait.d.ts +64 -0
  77. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  78. package/dist/executors/bounded-exec/lease-wait.js +72 -0
  79. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  80. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  82. package/dist/executors/bounded-exec/mbx-pool.d.ts +31 -0
  83. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -0
  84. package/dist/executors/bounded-exec/mbx-pool.js +24 -0
  85. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  86. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  88. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  89. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  90. package/dist/executors/bounded-exec/progress.js +5 -2
  91. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  92. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  93. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  94. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  95. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  96. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  97. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  98. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  100. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  101. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  102. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  103. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +10 -4
  104. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  105. package/dist/executors/bounded-exec/run-cpu-pool.js +122 -35
  106. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  107. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  108. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  109. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  110. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  111. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  112. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  113. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  114. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  115. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  116. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  117. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  118. package/dist/executors/bounded-exec/verdict.d.ts +48 -11
  119. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  120. package/dist/executors/bounded-exec/verdict.js +89 -20
  121. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  122. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  123. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  124. package/dist/executors/clean-outputs/executor.js +1 -0
  125. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  126. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/executor.js +367 -0
  128. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  129. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  130. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  131. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  132. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  133. package/dist/executors/scriptc-native/schema.js +1 -0
  134. package/dist/executors/typescript-emit/emit-overrides.d.ts +14 -0
  135. package/dist/executors/typescript-emit/emit-overrides.d.ts.map +1 -0
  136. package/dist/executors/typescript-emit/emit-overrides.js +24 -0
  137. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  138. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  139. package/dist/executors/typescript-emit/executor.js +146 -33
  140. package/dist/forbidden-spelling-policy.d.ts +56 -0
  141. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  142. package/dist/forbidden-spelling-policy.js +176 -0
  143. package/dist/generators/create-package/generator.d.ts.map +1 -1
  144. package/dist/generators/create-package/generator.js +3 -4
  145. package/dist/graph-input-contract.d.ts +14 -0
  146. package/dist/graph-input-contract.d.ts.map +1 -1
  147. package/dist/graph-input-contract.js +67 -2
  148. package/dist/index.d.ts +23 -6
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +672 -214
  151. package/dist/managed-assets.d.ts +2 -0
  152. package/dist/managed-assets.d.ts.map +1 -1
  153. package/dist/managed-files/files.d.ts +3 -3
  154. package/dist/managed-files/files.d.ts.map +1 -1
  155. package/dist/managed-files/files.js +28 -3
  156. package/dist/managed-files/managed-format.d.ts.map +1 -1
  157. package/dist/managed-files/managed-format.js +1 -0
  158. package/dist/managed-files/publish-workflow.js +14 -11
  159. package/dist/nextest-code-bound.js +1 -0
  160. package/dist/nextest-timings.d.ts +35 -0
  161. package/dist/nextest-timings.d.ts.map +1 -0
  162. package/dist/nextest-timings.js +168 -0
  163. package/dist/owned-installation.d.ts +6 -5
  164. package/dist/owned-installation.d.ts.map +1 -1
  165. package/dist/owned-installation.js +150 -26
  166. package/dist/package-target-policy.d.ts.map +1 -1
  167. package/dist/package-target-policy.js +2 -3
  168. package/dist/process-children.d.ts +7 -0
  169. package/dist/process-children.d.ts.map +1 -0
  170. package/dist/process-children.darwin.d.ts +7 -0
  171. package/dist/process-children.darwin.d.ts.map +1 -0
  172. package/dist/process-children.darwin.js +13 -0
  173. package/dist/process-children.js +14 -0
  174. package/dist/process-children.linux.d.ts +8 -0
  175. package/dist/process-children.linux.d.ts.map +1 -0
  176. package/dist/process-children.linux.js +25 -0
  177. package/dist/process-group.d.ts +108 -0
  178. package/dist/process-group.d.ts.map +1 -0
  179. package/dist/process-group.js +171 -0
  180. package/dist/process-listing.d.ts +7 -0
  181. package/dist/process-listing.d.ts.map +1 -0
  182. package/dist/process-listing.js +51 -0
  183. package/dist/producer-receipts.d.ts +8 -2
  184. package/dist/producer-receipts.d.ts.map +1 -1
  185. package/dist/producer-receipts.js +514 -47
  186. package/dist/task-graph-policy.d.ts +21 -0
  187. package/dist/task-graph-policy.d.ts.map +1 -0
  188. package/dist/task-graph-policy.js +91 -0
  189. package/dist/test-timings.js +4 -4
  190. package/dist/test-walk-policy.d.ts +14 -5
  191. package/dist/test-walk-policy.d.ts.map +1 -1
  192. package/dist/test-walk-policy.js +8 -2
  193. package/dist/testing.d.ts +73 -28
  194. package/dist/testing.d.ts.map +1 -1
  195. package/dist/testing.js +217 -223
  196. package/dist/tool-bins.d.ts +33 -0
  197. package/dist/tool-bins.d.ts.map +1 -0
  198. package/dist/tool-bins.js +72 -0
  199. package/dist/typecheck-test-policy.d.ts.map +1 -1
  200. package/dist/typecheck-test-policy.js +3 -4
  201. package/dist/wait-why-policy.d.ts +28 -0
  202. package/dist/wait-why-policy.d.ts.map +1 -0
  203. package/dist/wait-why-policy.js +223 -0
  204. package/dist/workspace-config-policy.d.ts +14 -8
  205. package/dist/workspace-config-policy.d.ts.map +1 -1
  206. package/dist/workspace-config-policy.js +60 -16
  207. package/dist/workspace-manifest.d.ts +41 -6
  208. package/dist/workspace-manifest.d.ts.map +1 -1
  209. package/dist/workspace-manifest.js +57 -0
  210. package/executors.json +16 -1
  211. package/loader.js +2 -0
  212. package/managed/raw/envrc +11 -0
  213. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  214. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  215. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  216. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  217. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  218. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  219. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  220. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  221. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  222. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  223. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  224. package/managed/raw/tooling/direnv/repo-path +68 -6
  225. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  226. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  227. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  228. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  229. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  230. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  231. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  232. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  233. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  234. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  235. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  236. package/package.json +95 -14
  237. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  238. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  239. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  240. package/src/bounded-test-policy.ts +12 -14
  241. package/src/build-state-output-policy.ts +458 -34
  242. package/src/bun-lock-scope.ts +108 -0
  243. package/src/cargo-build-script-env.ts +265 -0
  244. package/src/cargo-closure-input.ts +74 -7
  245. package/src/cargo-retention-hook.ts +94 -0
  246. package/src/cargo-source-hash.ts +138 -41
  247. package/src/cargo-toolchain-paths.ts +95 -0
  248. package/src/cargo-toolchain-policy.ts +49 -5
  249. package/src/cargo-workspace.ts +72 -123
  250. package/src/cross-check-policy.ts +12 -10
  251. package/src/disk-command-policy.ts +1 -0
  252. package/src/ensure-built-receipt.ts +173 -39
  253. package/src/ensure-built-witness.ts +62 -10
  254. package/src/ensure-built.ts +11 -1
  255. package/src/eslint-config-closure.ts +357 -0
  256. package/src/executors/bounded-exec/bounds.ts +76 -0
  257. package/src/executors/bounded-exec/cpu-pool-thread.ts +43 -0
  258. package/src/executors/bounded-exec/cpu-pool.ts +55 -120
  259. package/src/executors/bounded-exec/executor.ts +442 -260
  260. package/src/executors/bounded-exec/gateway-lease.ts +94 -35
  261. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  262. package/src/executors/bounded-exec/lease-wait.ts +116 -0
  263. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  264. package/src/executors/bounded-exec/mbx-pool.ts +48 -0
  265. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  266. package/src/executors/bounded-exec/progress.ts +9 -3
  267. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  268. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  269. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  270. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  271. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  272. package/src/executors/bounded-exec/run-cpu-pool.ts +129 -35
  273. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  274. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  275. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  276. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  277. package/src/executors/bounded-exec/schema.json +11 -2
  278. package/src/executors/bounded-exec/schema.ts +19 -1
  279. package/src/executors/bounded-exec/verdict.ts +145 -35
  280. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  281. package/src/executors/clean-outputs/executor.ts +1 -0
  282. package/src/executors/scriptc-native/executor.ts +394 -0
  283. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  284. package/src/executors/scriptc-native/schema.json +60 -0
  285. package/src/executors/scriptc-native/schema.ts +34 -0
  286. package/src/executors/typescript-emit/emit-overrides.ts +24 -0
  287. package/src/executors/typescript-emit/executor.ts +186 -38
  288. package/src/forbidden-spelling-policy.ts +226 -0
  289. package/src/generators/create-package/generator.ts +7 -7
  290. package/src/graph-input-contract.ts +61 -2
  291. package/src/index.ts +788 -224
  292. package/src/managed-assets.ts +3 -0
  293. package/src/managed-files/files.ts +28 -3
  294. package/src/managed-files/managed-format.ts +1 -0
  295. package/src/managed-files/publish-workflow.ts +20 -15
  296. package/src/nextest-code-bound.ts +1 -0
  297. package/src/nextest-timings.ts +106 -0
  298. package/src/owned-installation.ts +150 -23
  299. package/src/package-target-policy.ts +2 -3
  300. package/src/process-children.darwin.ts +14 -0
  301. package/src/process-children.linux.ts +33 -0
  302. package/src/process-children.ts +22 -0
  303. package/src/process-group.ts +209 -0
  304. package/src/process-listing.ts +54 -0
  305. package/src/producer-receipts.ts +92 -41
  306. package/src/task-graph-policy.ts +98 -0
  307. package/src/test-walk-policy.ts +23 -8
  308. package/src/testing.ts +240 -232
  309. package/src/tool-bins.ts +108 -0
  310. package/src/typecheck-test-policy.ts +2 -3
  311. package/src/wait-why-policy.ts +226 -0
  312. package/src/workspace-config-policy.ts +63 -15
  313. package/src/workspace-manifest.ts +89 -6
  314. package/test-timings.json +124 -99
  315. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  316. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  317. package/dist/bin/smoo-nx-failures.js +0 -3
  318. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  319. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  320. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  321. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  322. package/dist/failure-summary.d.ts +0 -5
  323. package/dist/failure-summary.d.ts.map +0 -1
  324. package/dist/failure-summary.js +0 -118
  325. package/dist/nextest-extraction.d.ts +0 -117
  326. package/dist/nextest-extraction.d.ts.map +0 -1
  327. package/dist/nextest-extraction.js +0 -303
  328. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  329. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  330. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  331. package/src/__tests__/counted-cargo-process.ts +0 -286
  332. package/src/__tests__/counted-cargo.ts +0 -713
  333. package/src/__tests__/directory-change.ts +0 -27
  334. package/src/__tests__/fixture-cargo-home.ts +0 -36
  335. package/src/__tests__/fixture-nx-env.ts +0 -193
  336. package/src/__tests__/owned-installation.ts +0 -13
  337. package/src/__tests__/past-tick.ts +0 -12
  338. package/src/__tests__/progress-clock.ts +0 -43
  339. package/src/__tests__/runtime-input.ts +0 -23
  340. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  341. package/src/bin/smoo-nx-failures.ts +0 -4
  342. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  343. package/src/bounded-test-policy.test.ts +0 -1029
  344. package/src/build-state-output-policy.test.ts +0 -115
  345. package/src/bun-bootstrap.test.ts +0 -102
  346. package/src/bun-file-packages.test.ts +0 -47
  347. package/src/cargo-closure-filesets.test.ts +0 -63
  348. package/src/cargo-closure-input.property.test.ts +0 -50
  349. package/src/cargo-closure-input.test.ts +0 -506
  350. package/src/cargo-closure-key.test.ts +0 -240
  351. package/src/cargo-resolve-cache.test.ts +0 -1181
  352. package/src/cargo-source-hash.test.ts +0 -707
  353. package/src/cargo-workspace.test.ts +0 -615
  354. package/src/cross-check-policy.test.ts +0 -316
  355. package/src/disk-command-policy.test.ts +0 -61
  356. package/src/ensure-built-receipt.test.ts +0 -279
  357. package/src/ensure-built-witness.test.ts +0 -688
  358. package/src/ensure-built.test.ts +0 -1462
  359. package/src/executors/all-verdicts/executor.test.ts +0 -135
  360. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  361. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  362. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  363. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  364. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  365. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  366. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  367. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  368. package/src/executors/bounded-exec/progress.test.ts +0 -139
  369. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  370. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  371. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  372. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  373. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  374. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  375. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  376. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  377. package/src/executors/clean-outputs/executor.test.ts +0 -20
  378. package/src/executors/typescript-emit/executor.test.ts +0 -83
  379. package/src/failure-summary.ts +0 -119
  380. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  381. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  382. package/src/generators/create-package/generator.test.ts +0 -190
  383. package/src/generators/make-public/generator.test.ts +0 -137
  384. package/src/graph-input-contract.test.ts +0 -379
  385. package/src/host-controller-wiring.test.ts +0 -31
  386. package/src/index.test.ts +0 -3321
  387. package/src/linked-snapshots.nx.test.ts +0 -254
  388. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  389. package/src/managed-files/generator.test.ts +0 -243
  390. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  391. package/src/managed-files/json-edit.test.ts +0 -216
  392. package/src/managed-files/managed-content.test.ts +0 -166
  393. package/src/managed-files/managed-format-json.test.ts +0 -308
  394. package/src/managed-files/repo-path.test.ts +0 -172
  395. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  396. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  397. package/src/managed-files/tree-permissions.test.ts +0 -109
  398. package/src/managed-files/tree.test.ts +0 -123
  399. package/src/manifest-hash.test.ts +0 -219
  400. package/src/nextest-code-bound.test.ts +0 -161
  401. package/src/nextest-extraction.test.ts +0 -216
  402. package/src/nextest-extraction.ts +0 -371
  403. package/src/nextest-partitions.test.ts +0 -501
  404. package/src/nx-cache-bound.test.ts +0 -109
  405. package/src/nx-cache-restore-mtime.test.ts +0 -170
  406. package/src/nx-daemon-claim.test.ts +0 -279
  407. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  408. package/src/nx-daemon-idle-policy.test.ts +0 -111
  409. package/src/nx-daemon-ignore-files.test.ts +0 -210
  410. package/src/nx-daemon-root-normalization.test.ts +0 -105
  411. package/src/nx-daemon-start-never.test.ts +0 -292
  412. package/src/nx-daemon-validity.test.ts +0 -1055
  413. package/src/nx-dot-input-policy.test.ts +0 -353
  414. package/src/nx-failure-life-cycles.test.ts +0 -207
  415. package/src/nx-files-archive-racy.test.ts +0 -97
  416. package/src/nx-foreign-workspace-env.test.ts +0 -329
  417. package/src/nx-incomplete-run-summary.test.ts +0 -70
  418. package/src/nx-plugin-load-errors.test.ts +0 -120
  419. package/src/nx-project-graph-errors.test.ts +0 -70
  420. package/src/nx-project-resolution-cache.test.ts +0 -176
  421. package/src/nx-raw-inputs.test.ts +0 -166
  422. package/src/nx-resident-graph-workers.test.ts +0 -112
  423. package/src/nx-run-information.test.ts +0 -118
  424. package/src/nx-skipped-task-exit.test.ts +0 -180
  425. package/src/nx-state-location.test.ts +0 -63
  426. package/src/nx-store-resolution.test.ts +0 -81
  427. package/src/nx-task-graph-cycles.test.ts +0 -148
  428. package/src/nx-task-output-lease.test.ts +0 -550
  429. package/src/nx-use-local.test.ts +0 -105
  430. package/src/owned-installation.test.ts +0 -105
  431. package/src/package-target-policy.test.ts +0 -1014
  432. package/src/producer-receipts.test.ts +0 -285
  433. package/src/release-config-policy.test.ts +0 -311
  434. package/src/runtime-input.test.ts +0 -393
  435. package/src/serial-group-wiring.test.ts +0 -326
  436. package/src/task-history-namespace.test.ts +0 -181
  437. package/src/task-results.test.ts +0 -228
  438. package/src/test-clock-policy.test.ts +0 -338
  439. package/src/test-program.test.ts +0 -303
  440. package/src/test-timings.test.ts +0 -240
  441. package/src/test-walk-policy.test.ts +0 -620
  442. package/src/testing.test.ts +0 -509
  443. package/src/typecheck-test-policy.test.ts +0 -1468
  444. package/src/typescript-resolution.test.ts +0 -76
  445. package/src/version-actions.test.ts +0 -80
  446. package/src/workspace-config-policy.test.ts +0 -737
@@ -1,1181 +0,0 @@
1
- import { afterAll, expect, it, jest } from 'bun:test';
2
- import { execFileSync } from 'node:child_process';
3
- import {
4
- appendFile,
5
- mkdir,
6
- mkdtemp,
7
- readdir,
8
- readFile,
9
- realpath,
10
- rename,
11
- rm,
12
- stat,
13
- symlink,
14
- utimes,
15
- writeFile,
16
- } from 'node:fs/promises';
17
- import { tmpdir } from 'node:os';
18
- import { delimiter, dirname, join } from 'node:path';
19
-
20
- import type { CreateNodesResultV2 } from 'nx/src/devkit-exports.js';
21
- import { FileLock } from 'nx/src/native/index.js';
22
- import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory.js';
23
- import { resetWorkspaceContext } from 'nx/src/utils/workspace-context.js';
24
- import {
25
- type CannedCargo,
26
- type CountedCargo,
27
- cannedCargo,
28
- countedCargo,
29
- expectCargoMetadataError,
30
- expectGraphRefusal,
31
- guardEvent,
32
- rejectionOf,
33
- waitForCargoJoins,
34
- withEnvironment,
35
- } from './__tests__/counted-cargo.js';
36
- import { useFixtureCargoHome } from './__tests__/fixture-cargo-home.js';
37
- import { testFileInstallation } from './__tests__/owned-installation.js';
38
- import { BOUNDED_TEST_IDLE_TIMEOUT_MS } from './bounded-test-policy.js';
39
- import { CARGO_CLOSURE_INPUT } from './cargo-closure-input.js';
40
- import {
41
- acquireCargoResolveLock,
42
- type CargoResolve,
43
- CargoResolveLockError,
44
- readCargoResolve,
45
- } from './cargo-source-hash.js';
46
- import { createNodesV2 } from './index.js';
47
-
48
- useFixtureCargoHome();
49
-
50
- /** The Nx installation this file's graph fixtures share; none may write into it. */
51
- const installation = testFileInstallation('cargo-resolve-installation');
52
- afterAll(() => installation.retire());
53
-
54
- /*
55
- * What Cargo resolution costs, measured by the one number that matters: how many `cargo metadata`
56
- * children were actually started. A `cargo` ahead of the real one on PATH reports each child's life
57
- * to the fixture as it happens (`__tests__/counted-cargo.ts`); no assertion here reads a clock, and
58
- * nothing here waits for one: every wait advances on a child's report, a process's output or exit,
59
- * or a sharer joining an in-flight resolution. Only the outer hang guards keep time, and they report
60
- * what was still open instead of advancing anything.
61
- *
62
- * These regressions exercise the content-keyed cache through `readCargoResolve`, project-graph
63
- * inference and the hash command. Join readiness comes from the resolution's diagnostics channel;
64
- * child counts and process-lifetime evidence come from the fixture's control connections.
65
- *
66
- * Every fixture is a temporary directory of its own, with its own Nx workspace-data directory (where
67
- * the cache is kept), deleted with the fixture.
68
- */
69
-
70
- const sourceModule = join(import.meta.dir, 'cargo-source-hash.ts');
71
- const cliModule = join(import.meta.dir, 'bin', 'smoo-nx-cargo-hash.ts');
72
-
73
- const spawned = async (cargo: CountedCargo): Promise<number> => (await cargo.runs()).spawned;
74
-
75
- async function put(root: string, path: string, text: string): Promise<void> {
76
- const file = join(root, path);
77
- await mkdir(dirname(file), { recursive: true });
78
- await writeFile(file, text);
79
- }
80
-
81
- /** Rewrite `path` as an editor that changed nothing would: the same bytes, a later mtime. */
82
- async function touch(root: string, path: string): Promise<void> {
83
- const file = join(root, path);
84
- await writeFile(file, await readFile(file));
85
- const later = new Date(Date.now() + 10_000);
86
- await utimes(file, later, later);
87
- }
88
-
89
- /** Whether `pid` names a process right now: one syscall, never a wait. */
90
- function alive(pid: number): boolean {
91
- try {
92
- process.kill(pid, 0);
93
- return true;
94
- } catch (error) {
95
- if (error instanceof Error && 'code' in error && error.code === 'ESRCH') return false;
96
- throw error;
97
- }
98
- }
99
-
100
- /** How a subprocess ended, with everything it printed. */
101
- interface Ended {
102
- readonly exitCode: number | null;
103
- readonly signalCode: Bun.Subprocess['signalCode'];
104
- readonly stdout: string;
105
- readonly stderr: string;
106
- }
107
-
108
- /**
109
- * A subprocess whose stdout and stderr are read from the moment it starts, so a full pipe never
110
- * stalls it and every failure message can say what it printed.
111
- */
112
- interface Drained {
113
- readonly pid: number;
114
- kill(signal: NodeJS.Signals): void;
115
- /** Settles when stdout has printed `line` as a whole line; rejects if stdout ends first. */
116
- printed(line: string): Promise<void>;
117
- /** Settles once the process has exited and both of its streams have ended. */
118
- readonly ended: Promise<Ended>;
119
- /** The command, whether it is still running, and what it has printed so far. */
120
- describe(): string;
121
- }
122
-
123
- async function drain(stream: ReadableStream<Uint8Array>, append: (text: string) => void): Promise<void> {
124
- const decoder = new TextDecoder();
125
- const reader = stream.getReader();
126
- for (let chunk = await reader.read(); !chunk.done; chunk = await reader.read()) {
127
- append(decoder.decode(chunk.value, { stream: true }));
128
- }
129
- append(decoder.decode());
130
- }
131
-
132
- function spawnDrained(command: readonly string[], cwd: string, environment: Readonly<Record<string, string>>): Drained {
133
- const proc = Bun.spawn([...command], {
134
- cwd,
135
- env: { ...process.env, ...environment },
136
- stdin: 'ignore',
137
- stdout: 'pipe',
138
- stderr: 'pipe',
139
- });
140
- let stdout = '';
141
- let stderr = '';
142
- let stdoutEnded = false;
143
- const waiting = new Set<{ readonly line: string; resolve(): void; reject(error: Error): void }>();
144
- const describe = (): string => {
145
- const state =
146
- proc.signalCode !== null
147
- ? `killed by ${proc.signalCode}`
148
- : proc.exitCode !== null
149
- ? `exited ${proc.exitCode}`
150
- : 'running';
151
- return `${command.join(' ')} (pid ${proc.pid}, ${state})\nstdout: ${JSON.stringify(stdout)}\nstderr: ${JSON.stringify(stderr)}`;
152
- };
153
- const notify = (): void => {
154
- const lines = new Set(stdout.split('\n').slice(0, -1));
155
- for (const waiter of waiting) {
156
- if (lines.has(waiter.line)) waiter.resolve();
157
- else if (stdoutEnded) waiter.reject(new Error(`stdout ended before printing ${waiter.line}: ${describe()}`));
158
- else continue;
159
- waiting.delete(waiter);
160
- }
161
- };
162
- const out = drain(proc.stdout, (text) => {
163
- stdout += text;
164
- notify();
165
- }).finally(() => {
166
- stdoutEnded = true;
167
- notify();
168
- });
169
- const err = drain(proc.stderr, (text) => {
170
- stderr += text;
171
- });
172
- return {
173
- pid: proc.pid,
174
- kill: (signal) => proc.kill(signal),
175
- printed: (line) =>
176
- new Promise<void>((resolve, reject) => {
177
- waiting.add({ line, resolve, reject });
178
- notify();
179
- }),
180
- ended: Promise.all([out, err, proc.exited]).then(
181
- (): Ended => ({ exitCode: proc.exitCode, signalCode: proc.signalCode, stdout, stderr }),
182
- ),
183
- describe,
184
- };
185
- }
186
-
187
- function summarize(resolved: CargoResolve) {
188
- return {
189
- root: resolved.root,
190
- members: [...resolved.members],
191
- local: resolved.local,
192
- edges: resolved.edges === null ? null : [...resolved.edges],
193
- };
194
- }
195
-
196
- /* ---- The cache's own behavior, against a Cargo that answers whatever the test says ---- */
197
-
198
- const WORKSPACE_MANIFEST = '[workspace]\nmembers = ["crates/leaf"]\nresolver = "2"\n';
199
- const WORKSPACE_FILES: Readonly<Record<string, string>> = {
200
- 'Cargo.toml': WORKSPACE_MANIFEST,
201
- 'Cargo.lock': '# fixture lock\nversion = 3\n',
202
- 'crates/leaf/Cargo.toml': '[package]\nname = "leaf"\nversion = "0.1.0"\nedition = "2021"\n',
203
- 'crates/leaf/src/lib.rs': 'pub fn leaf() -> u8 { 1 }\n',
204
- 'README.md': '# fixture\n',
205
- };
206
-
207
- /** A package outside the Nx workspace that the member depends on by path: Cargo's answer names it, so its manifest is an input. */
208
- const EXTERNAL_MANIFEST = '[package]\nname = "external"\nversion = "0.1.0"\nedition = "2021"\n[workspace]\n';
209
- const EXTERNAL_SOURCE = 'pub fn external() -> u8 { 10 }\n';
210
-
211
- /**
212
- * What `cargo metadata` prints for the fixture when the workspace's one member is called `name`:
213
- * it depends on the package outside the workspace, which Cargo reports as a local package too.
214
- */
215
- function metadataNamed(root: string, name: string) {
216
- const workspace = join(root, 'workspace');
217
- return {
218
- packages: [
219
- {
220
- id: name,
221
- name,
222
- version: '0.1.0',
223
- source: null,
224
- manifest_path: join(workspace, 'crates/leaf/Cargo.toml'),
225
- targets: [{ src_path: join(workspace, 'crates/leaf/src/lib.rs') }],
226
- },
227
- {
228
- id: 'external',
229
- name: 'external',
230
- version: '0.1.0',
231
- source: null,
232
- manifest_path: join(root, 'external/Cargo.toml'),
233
- targets: [{ src_path: join(root, 'external/src/lib.rs') }],
234
- },
235
- ],
236
- resolve: {
237
- nodes: [
238
- { id: name, deps: [{ pkg: 'external' }] },
239
- { id: 'external', deps: [] },
240
- ],
241
- },
242
- workspace_members: [name],
243
- workspace_root: workspace,
244
- };
245
- }
246
-
247
- /** A process that has never resolved anything: it says on stdout that it is about to ask, asks, and prints the answer. */
248
- const RESOLVE_WORKER = [
249
- `import { readCargoResolve } from ${JSON.stringify(sourceModule)};`,
250
- 'const [manifest, cwd] = process.argv.slice(2);',
251
- "process.stdout.write('ready\\n');",
252
- 'const resolved = await readCargoResolve(manifest, cwd);',
253
- 'process.stdout.write(',
254
- ' JSON.stringify({',
255
- ' root: resolved.root,',
256
- ' members: [...resolved.members],',
257
- ' local: resolved.local,',
258
- ' edges: resolved.edges === null ? null : [...resolved.edges],',
259
- " }) + '\\n',",
260
- ');',
261
- '',
262
- ].join('\n');
263
-
264
- interface CannedWorkspace {
265
- readonly root: string;
266
- readonly workspace: string;
267
- readonly manifest: string;
268
- readonly cargo: CannedCargo;
269
- /** What a process under test needs in its environment; this process already has it. */
270
- readonly environment: Readonly<Record<string, string>>;
271
- /** What Cargo says from now on: the workspace has one member, called `name`. */
272
- answer(name: string): Promise<void>;
273
- /** The members `readCargoResolve` reports for the workspace now. */
274
- members(): Promise<string[]>;
275
- }
276
-
277
- /** `body` over a temporary Cargo workspace and the canned Cargo the module under test will find first. */
278
- async function withCannedWorkspace(body: (fixture: CannedWorkspace) => Promise<void>): Promise<void> {
279
- const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-resolve-cache-')));
280
- try {
281
- const workspace = join(root, 'workspace');
282
- for (const [path, text] of Object.entries(WORKSPACE_FILES)) await put(workspace, path, text);
283
- await put(root, 'external/Cargo.toml', EXTERNAL_MANIFEST);
284
- await put(root, 'external/src/lib.rs', EXTERNAL_SOURCE);
285
- await put(root, 'resolve-worker.ts', RESOLVE_WORKER);
286
- const cargo = await cannedCargo(root);
287
- try {
288
- const manifest = join(workspace, 'Cargo.toml');
289
- const environment = { ...cargo.environment, CARGO_HOME: join(root, 'cargo-home') };
290
- await withEnvironment(environment, () =>
291
- body({
292
- root,
293
- workspace,
294
- manifest,
295
- cargo,
296
- environment,
297
- answer: (name) => cargo.answerWith(metadataNamed(root, name)),
298
- members: async () => [...(await readCargoResolve(manifest, workspace)).members],
299
- }),
300
- );
301
- } finally {
302
- await cargo.release();
303
- }
304
- } finally {
305
- await rm(root, { recursive: true, force: true });
306
- }
307
- }
308
-
309
- /**
310
- * `readCargoResolve` in a fresh process: a second Nx worker, or the next `nx` run. `ready` settles when
311
- * the process has said it is about to ask; `result` is the answer it printed once it exited cleanly.
312
- * Both are held to the fixture's hang guard, which reports what the process printed.
313
- */
314
- function freshResolver({ root, workspace, manifest, environment }: CannedWorkspace, name: string) {
315
- const worker = spawnDrained(
316
- [process.execPath, join(root, 'resolve-worker.ts'), manifest, workspace],
317
- workspace,
318
- environment,
319
- );
320
- const result = guardEvent(worker.ended, `fresh resolver ${name} to exit`, () => worker.describe()).then(
321
- (ended): unknown => {
322
- expect(ended.exitCode, worker.describe()).toBe(0);
323
- const [announced, ...rest] = ended.stdout.trimEnd().split('\n');
324
- expect(announced, worker.describe()).toBe('ready');
325
- const answer = rest.at(-1);
326
- if (answer === undefined) throw new Error(`fresh resolver ${name} printed no answer: ${worker.describe()}`);
327
- const resolved: unknown = JSON.parse(answer);
328
- return resolved;
329
- },
330
- );
331
- return {
332
- ready: () =>
333
- guardEvent(worker.printed('ready'), `fresh resolver ${name} to say it is about to ask`, () => worker.describe()),
334
- result,
335
- };
336
- }
337
-
338
- it('concurrent resolutions of one Cargo workspace share one cargo child, and an unchanged workspace never runs Cargo again', async () => {
339
- await withCannedWorkspace(async ({ cargo, answer, members, workspace, manifest }) => {
340
- await answer('before');
341
- // The child holds its answer, after it read the workspace, until each of the other fifteen calls
342
- // has joined its flight, so every call below arrives while it is pending.
343
- await cargo.beforeAnswer.close();
344
- const joins = waitForCargoJoins(manifest, 15);
345
- let results: CargoResolve[];
346
- try {
347
- const calls = Promise.all(Array.from({ length: 16 }, () => readCargoResolve(manifest, workspace)));
348
- await joins.joined;
349
- await cargo.beforeAnswer.open();
350
- results = await calls;
351
- } finally {
352
- joins.dispose();
353
- }
354
- expect(await spawned(cargo)).toBe(1);
355
- expect(new Set(results).size).toBe(1);
356
- for (const result of results) expect([...result.members]).toEqual(['before']);
357
-
358
- // Nothing Cargo's answer depends on has changed, so Cargo, which would
359
- // answer differently now, is not asked.
360
- await answer('after');
361
- expect(await members()).toEqual(['before']);
362
- expect(await spawned(cargo)).toBe(1);
363
-
364
- // A manifest edit is what changes the answer; it costs one child.
365
- await appendFile(manifest, '# edited\n');
366
- expect(await members()).toEqual(['after']);
367
- expect(await members()).toEqual(['after']);
368
- expect(await spawned(cargo)).toBe(2);
369
- });
370
- });
371
-
372
- it("a failed resolution rejects every sharer with a CargoMetadataError carrying Cargo's stderr, and is not kept for the next call", async () => {
373
- await withCannedWorkspace(async ({ cargo, answer, members, workspace, manifest }) => {
374
- await cargo.failWith('fake cargo: resolution failed\n');
375
- // The child that fails holds its refusal until the second call has joined its flight.
376
- await cargo.beforeAnswer.close();
377
- const joins = waitForCargoJoins(manifest, 1);
378
- let failures: unknown[];
379
- try {
380
- const refused = Promise.all(
381
- [readCargoResolve(manifest, workspace), readCargoResolve(manifest, workspace)].map(rejectionOf),
382
- );
383
- await joins.joined;
384
- await cargo.beforeAnswer.open();
385
- failures = await refused;
386
- } finally {
387
- joins.dispose();
388
- }
389
- for (const failure of failures) {
390
- expect(expectCargoMetadataError(failure, manifest).message).toContain('fake cargo: resolution failed');
391
- }
392
- expect(await spawned(cargo)).toBe(1);
393
-
394
- // Nothing on disk changed, and a refusal is no answer: Cargo is asked again.
395
- await cargo.recover();
396
- await answer('recovered');
397
- expect(await members()).toEqual(['recovered']);
398
- expect(await spawned(cargo)).toBe(2);
399
- expect(await members()).toEqual(['recovered']);
400
- expect(await spawned(cargo)).toBe(2);
401
- });
402
- });
403
-
404
- it('a Cargo that cannot run, or whose answer is not metadata, is a CargoMetadataError', async () => {
405
- await withCannedWorkspace(async ({ cargo, workspace, manifest }) => {
406
- for (const text of ['this is not JSON', '{"packages": 3}']) {
407
- await cargo.answerWithText(text);
408
- expectCargoMetadataError(await rejectionOf(readCargoResolve(manifest, workspace)), manifest);
409
- }
410
- expect(await spawned(cargo)).toBe(2);
411
-
412
- await withEnvironment({ PATH: join(workspace, 'no-cargo-here') }, async () => {
413
- expectCargoMetadataError(await rejectionOf(readCargoResolve(manifest, workspace)), manifest);
414
- });
415
- expect(await spawned(cargo)).toBe(2);
416
- });
417
- });
418
-
419
- it('source edits, non-Rust edits and a rewrite of the same bytes never run Cargo', async () => {
420
- await withCannedWorkspace(async ({ root, cargo, answer, members, workspace }) => {
421
- await answer('cold');
422
- expect(await members()).toEqual(['cold']);
423
- const unkeyed: [string, () => Promise<void>][] = [
424
- ['a source edit', () => put(workspace, 'crates/leaf/src/lib.rs', 'pub fn leaf() -> u8 { 2 }\n')],
425
- ['a new source file', () => put(workspace, 'crates/leaf/src/extra.rs', 'pub const EXTRA: u8 = 1;\n')],
426
- ['a non-Rust edit', () => put(workspace, 'README.md', '# edited\n')],
427
- ['a new non-Rust file', () => put(workspace, 'crates/leaf/notes.json', '{}\n')],
428
- ['the manifest rewritten with the same bytes', () => touch(workspace, 'crates/leaf/Cargo.toml')],
429
- ['Cargo.lock rewritten with the same bytes', () => touch(workspace, 'Cargo.lock')],
430
- [
431
- 'a source edit outside the workspace',
432
- () => put(root, 'external/src/lib.rs', 'pub fn external() -> u8 { 11 }\n'),
433
- ],
434
- ];
435
- for (const [what, change] of unkeyed) {
436
- await change();
437
- // A Cargo asked after this change would say so.
438
- await answer(`after ${what}`);
439
- expect(await members(), what).toEqual(['cold']);
440
- }
441
- expect(await spawned(cargo)).toBe(1);
442
- });
443
- });
444
-
445
- interface KeyedFile {
446
- readonly name: string;
447
- /** Relative to the fixture root; the workspace is `workspace/` in it. */
448
- readonly path: string;
449
- /** Whether the fixture has the file before the test touches it. */
450
- readonly exists: boolean;
451
- /** Whether the test may delete it: the fixture's Cargo answers with packages whose manifests must stay. */
452
- readonly removable: boolean;
453
- }
454
-
455
- /** Every file whose bytes Cargo's answer depends on, or that the toolchain pin and configuration stand for. */
456
- const KEYED_FILES: readonly KeyedFile[] = [
457
- { name: 'the workspace manifest', path: 'workspace/Cargo.toml', exists: true, removable: false },
458
- { name: "a member's manifest", path: 'workspace/crates/leaf/Cargo.toml', exists: true, removable: false },
459
- {
460
- name: "a path dependency's manifest outside the workspace",
461
- path: 'external/Cargo.toml',
462
- exists: true,
463
- removable: false,
464
- },
465
- { name: 'a new manifest in the workspace', path: 'workspace/crates/new/Cargo.toml', exists: false, removable: true },
466
- { name: 'Cargo.lock', path: 'workspace/Cargo.lock', exists: true, removable: true },
467
- {
468
- name: 'a .cargo/config.toml in the workspace',
469
- path: 'workspace/.cargo/config.toml',
470
- exists: false,
471
- removable: true,
472
- },
473
- { name: 'a .cargo/config in the workspace', path: 'workspace/.cargo/config', exists: false, removable: true },
474
- { name: 'a .cargo/config.toml above the workspace', path: '.cargo/config.toml', exists: false, removable: true },
475
- { name: 'a Cargo.toml above the workspace', path: 'Cargo.toml', exists: false, removable: true },
476
- { name: "CARGO_HOME's config.toml", path: 'cargo-home/config.toml', exists: false, removable: true },
477
- { name: 'rust-toolchain.toml', path: 'workspace/rust-toolchain.toml', exists: false, removable: true },
478
- { name: 'rust-toolchain', path: 'workspace/rust-toolchain', exists: false, removable: true },
479
- { name: 'devenv.lock', path: 'workspace/devenv.lock', exists: false, removable: true },
480
- { name: 'tooling/direnv/devenv.lock', path: 'workspace/tooling/direnv/devenv.lock', exists: false, removable: true },
481
- ];
482
-
483
- for (const file of KEYED_FILES) {
484
- it(`resolves again exactly once when ${file.name} changes, and not again for the same bytes`, async () => {
485
- await withCannedWorkspace(async ({ root, cargo, answer, members }) => {
486
- const resolvesAs = async (name: string): Promise<string[]> => {
487
- await answer(name);
488
- return members();
489
- };
490
- expect(await resolvesAs('cold')).toEqual(['cold']);
491
- expect(await spawned(cargo)).toBe(1);
492
-
493
- const original = file.exists ? await readFile(join(root, file.path), 'utf8') : '';
494
- await put(root, file.path, `${original}# one\n`);
495
- expect(await resolvesAs('one')).toEqual(['one']);
496
- expect(await spawned(cargo)).toBe(2);
497
-
498
- // The bytes are the same, so Cargo, which would answer differently, is not asked.
499
- await touch(root, file.path);
500
- expect(await resolvesAs('same bytes')).toEqual(['one']);
501
- expect(await spawned(cargo)).toBe(2);
502
-
503
- // Identical size and mtime cannot stand in for the current bytes.
504
- const before = await stat(join(root, file.path));
505
- await put(root, file.path, `${original}# two\n`);
506
- await utimes(join(root, file.path), before.atime, before.mtime);
507
- expect(await resolvesAs('two')).toEqual(['two']);
508
- expect(await spawned(cargo)).toBe(3);
509
-
510
- if (file.removable) {
511
- await rm(join(root, file.path));
512
- expect(await resolvesAs('removed')).toEqual(['removed']);
513
- expect(await spawned(cargo)).toBe(4);
514
- }
515
- expect(await resolvesAs('settled')).toEqual([file.removable ? 'removed' : 'two']);
516
- expect(await spawned(cargo)).toBe(file.removable ? 4 : 3);
517
- });
518
- });
519
- }
520
-
521
- it('retargeting a configuration symlink with identical bytes still resolves the new canonical input', async () => {
522
- await withCannedWorkspace(async ({ root, workspace, cargo, answer, members }) => {
523
- const config = join(workspace, '.cargo/config.toml');
524
- await put(root, 'config-a.toml', '[net]\noffline=true\n');
525
- await put(root, 'config-b.toml', '[net]\noffline=true\n');
526
- await mkdir(dirname(config), { recursive: true });
527
- await symlink(join(root, 'config-a.toml'), config);
528
- await answer('first target');
529
- expect(await members()).toEqual(['first target']);
530
- expect(await spawned(cargo)).toBe(1);
531
-
532
- await rm(config);
533
- await symlink(join(root, 'config-b.toml'), config);
534
- await answer('second target');
535
- expect(await members()).toEqual(['second target']);
536
- expect(await spawned(cargo)).toBe(2);
537
- await answer('unchanged');
538
- expect(await members()).toEqual(['second target']);
539
- expect(await spawned(cargo)).toBe(2);
540
- });
541
- });
542
-
543
- it('a resolution input read failure is not a missing file or a reusable answer', async () => {
544
- await withCannedWorkspace(async ({ workspace, manifest, cargo, answer }) => {
545
- // Use the graph caller's inventory so this tests the resolution reader,
546
- // independently of how the native workspace census treats a symlink loop.
547
- const indexed = new Set(['Cargo.toml', 'crates/leaf/Cargo.toml']);
548
- const members = async () => [...(await readCargoResolve(manifest, workspace, indexed)).members];
549
- await answer('cold');
550
- expect(await members()).toEqual(['cold']);
551
- const config = join(workspace, '.cargo/config.toml');
552
- await mkdir(dirname(config), { recursive: true });
553
- await symlink('config.toml', config);
554
- const failure = expectCargoMetadataError(await rejectionOf(members()), manifest);
555
- expect(failure.message).toContain('ELOOP');
556
- expect(failure.message).toContain(config);
557
- expect(await spawned(cargo)).toBe(1);
558
-
559
- await rm(config);
560
- await answer('trap');
561
- expect(await members()).toEqual(['cold']);
562
- expect(await spawned(cargo)).toBe(1);
563
- });
564
- });
565
-
566
- it('resolves again exactly once when the cargo on PATH or the rustup selection changes', async () => {
567
- await withCannedWorkspace(async ({ root, cargo, answer, members, environment }) => {
568
- const resolvesAs = async (name: string, selection: Record<string, string> = {}): Promise<string[]> => {
569
- await answer(name);
570
- return withEnvironment(selection, members);
571
- };
572
- expect(await resolvesAs('cold')).toEqual(['cold']);
573
- expect(await spawned(cargo)).toBe(1);
574
-
575
- expect(await resolvesAs('toolchain a', { RUSTUP_TOOLCHAIN: 'fixture-a' })).toEqual(['toolchain a']);
576
- expect(await spawned(cargo)).toBe(2);
577
- expect(await resolvesAs('same selection', { RUSTUP_TOOLCHAIN: 'fixture-a' })).toEqual(['toolchain a']);
578
- expect(await spawned(cargo)).toBe(2);
579
-
580
- expect(await resolvesAs('toolchain b', { RUSTUP_TOOLCHAIN: 'fixture-b' })).toEqual(['toolchain b']);
581
- expect(await spawned(cargo)).toBe(3);
582
-
583
- const selected = { RUSTUP_TOOLCHAIN: 'fixture-b', RUSTUP_HOME: join(root, 'rustup-home') };
584
- expect(await resolvesAs('rustup home', selected)).toEqual(['rustup home']);
585
- expect(await spawned(cargo)).toBe(4);
586
-
587
- // The same bytes of Cargo, found elsewhere, are not the same Cargo: a toolchain proxy is a path.
588
- const other = join(root, 'other-bin');
589
- await mkdir(other, { recursive: true });
590
- await writeFile(join(other, 'cargo'), await readFile(join(cargo.bin, 'cargo')), { mode: 0o755 });
591
- const elsewhere = { ...selected, PATH: `${other}${delimiter}${environment.PATH}` };
592
- expect(await resolvesAs('another cargo', elsewhere)).toEqual(['another cargo']);
593
- expect(await spawned(cargo)).toBe(5);
594
- expect(await resolvesAs('same cargo', elsewhere)).toEqual(['another cargo']);
595
- expect(await spawned(cargo)).toBe(5);
596
- });
597
- });
598
-
599
- it('a discovered manifest outside the workspace, edited while the first resolution holds, is never answered from before the edit', async () => {
600
- await withCannedWorkspace(async ({ root, cargo, answer, members, workspace, manifest }) => {
601
- // Nothing has resolved yet, so nothing knows the package outside the workspace is an input:
602
- // Cargo's own answer is the first to name it, while the child that gave it still holds that answer.
603
- await answer('before');
604
- await cargo.beforeAnswer.close();
605
- const first = readCargoResolve(manifest, workspace);
606
- await cargo.waitForRuns((runs) => runs.read === 1, 'the first cargo child to read the workspace');
607
- await appendFile(join(root, 'external/Cargo.toml'), '# edited\n');
608
- await answer('after');
609
- await cargo.beforeAnswer.open();
610
- expect([...(await first).members]).toEqual(['after']);
611
- const runs = await cargo.runs();
612
- expect(runs.spawned).toBe(2);
613
- expect(runs.peak).toBe(1);
614
-
615
- // What was kept is what the edited workspace resolved to, under the edited bytes.
616
- await answer('trap');
617
- expect(await members()).toEqual(['after']);
618
- expect(await spawned(cargo)).toBe(2);
619
- });
620
- });
621
-
622
- it('an edit made while Cargo resolves is answered by a resolution that follows the first, never beside it', async () => {
623
- await withCannedWorkspace(async ({ cargo, answer, members, workspace, manifest }) => {
624
- await answer('before');
625
- await cargo.beforeAnswer.close();
626
- const early = Array.from({ length: 4 }, () => readCargoResolve(manifest, workspace));
627
- await cargo.waitForRuns((runs) => runs.read === 1, 'the first cargo child to read the workspace');
628
-
629
- // That child holds the answer for the workspace as it was.
630
- await appendFile(manifest, '# edited\n');
631
- await answer('after');
632
- const late = Array.from({ length: 4 }, () => readCargoResolve(manifest, workspace));
633
- await cargo.beforeAnswer.open();
634
-
635
- // A call that began after the edit is never answered from before it.
636
- for (const result of await Promise.all(late)) expect([...result.members]).toEqual(['after']);
637
- // A call that began before it may see either side of the edit, and nothing else.
638
- for (const result of await Promise.all(early)) expect(['before', 'after']).toContain([...result.members][0]);
639
- const runs = await cargo.runs();
640
- expect(runs.spawned).toBe(2);
641
- expect(runs.peak).toBe(1);
642
-
643
- expect(await members()).toEqual(['after']);
644
- expect(await spawned(cargo)).toBe(2);
645
- });
646
- });
647
-
648
- it('an answer Cargo read after an edit is never kept for the workspace as it was before the edit', async () => {
649
- await withCannedWorkspace(async ({ cargo, answer, members, workspace, manifest }) => {
650
- const original = await readFile(manifest, 'utf8');
651
- await answer('before');
652
- await cargo.beforeRead.close();
653
- const first = readCargoResolve(manifest, workspace);
654
- await cargo.waitForRuns((runs) => runs.spawned === 1, 'the cargo child to start');
655
-
656
- // The call has taken the workspace as it is; Cargo reads it only after the edit.
657
- await writeFile(manifest, `${original}# edited\n`);
658
- await answer('after');
659
- await cargo.beforeRead.open();
660
- expect([...(await first).members]).toEqual(['after']);
661
-
662
- // The original bytes bring back the content the first call began with.
663
- // Whatever is kept for them must not be what Cargo said about the edit.
664
- await writeFile(manifest, original);
665
- await answer('before');
666
- expect(await members()).toEqual(['before']);
667
- });
668
- });
669
-
670
- it('a process that has never resolved an unchanged workspace reads the answer an earlier one left, without Cargo', async () => {
671
- await withCannedWorkspace(async (fixture) => {
672
- const { cargo, answer, workspace, manifest } = fixture;
673
- await answer('cold');
674
- const first = await freshResolver(fixture, 'first').result;
675
- expect(first).toMatchObject({ members: ['cold'] });
676
- expect(await spawned(cargo)).toBe(1);
677
-
678
- // A Cargo asked now would say so.
679
- await answer('trap');
680
- expect(await freshResolver(fixture, 'second').result).toEqual(first);
681
- expect(await spawned(cargo)).toBe(1);
682
- expect(first).toEqual(summarize(await readCargoResolve(manifest, workspace)));
683
- const together = await Promise.all(
684
- Array.from({ length: 4 }, (_, index) => freshResolver(fixture, `together-${index}`).result),
685
- );
686
- for (const result of together) expect(result).toEqual(first);
687
- expect(await spawned(cargo)).toBe(1);
688
-
689
- await appendFile(manifest, '# edited\n');
690
- await answer('edited');
691
- const edited = await freshResolver(fixture, 'edited').result;
692
- expect(edited).toMatchObject({ members: ['edited'] });
693
- expect(await freshResolver(fixture, 'edited again').result).toEqual(edited);
694
- expect(await spawned(cargo)).toBe(2);
695
- });
696
- });
697
-
698
- it('fresh processes that ask at once for a workspace nobody has resolved share one cargo child', async () => {
699
- await withCannedWorkspace(async (fixture) => {
700
- const { cargo, answer } = fixture;
701
- await answer('cold');
702
- // The child that starts first is held before it reads the workspace until every process has
703
- // said, on its stdout, that it is about to ask: they ask while that child resolves.
704
- await cargo.beforeRead.close();
705
- const resolvers = Array.from({ length: 4 }, (_, index) => freshResolver(fixture, `process-${index}`));
706
- await Promise.all(resolvers.map((resolver) => resolver.ready()));
707
- await cargo.waitForRuns((runs) => runs.spawned >= 1, 'a cargo child to start');
708
- await cargo.beforeRead.open();
709
-
710
- const results = await Promise.all(resolvers.map((resolver) => resolver.result));
711
- for (const result of results) expect(result).toEqual(results[0]);
712
- expect(results[0]).toMatchObject({ members: ['cold'] });
713
- expect(await spawned(cargo)).toBe(1);
714
- });
715
- });
716
-
717
- it('a worker that exits on SIGTERM while Cargo resolves leaves no cargo child behind', async () => {
718
- await withCannedWorkspace(async ({ root, workspace, manifest, cargo, answer, environment }) => {
719
- await answer('before');
720
- await cargo.beforeAnswer.close();
721
- const worker = join(root, 'worker.ts');
722
- await writeFile(
723
- worker,
724
- [
725
- `import { readCargoResolve } from ${JSON.stringify(sourceModule)};`,
726
- // What an Nx plugin worker does on SIGTERM, SIGINT, SIGQUIT and its host hanging up.
727
- "process.once('SIGTERM', () => process.exit(0));",
728
- `readCargoResolve(${JSON.stringify(manifest)}, ${JSON.stringify(workspace)})`,
729
- ' .then(() => process.exit(2), () => process.exit(3));',
730
- '',
731
- ].join('\n'),
732
- );
733
- const proc = spawnDrained([process.execPath, worker], workspace, environment);
734
- const [pid] = (await cargo.waitForRuns((runs) => runs.spawned === 1, 'the cargo child')).pids;
735
- if (pid === undefined) throw new Error('the cargo child has no pid');
736
- expect(alive(pid)).toBe(true);
737
- proc.kill('SIGTERM');
738
- const ended = await guardEvent(proc.ended, 'the worker to exit on SIGTERM', () => proc.describe());
739
- expect(ended.exitCode, proc.describe()).toBe(0);
740
- // The child's end is the end of its connection to the fixture, killed before it answered.
741
- await cargo.waitForDisconnects([pid]);
742
- });
743
- });
744
-
745
- it("a worker that exits with callers waiting on two resolutions leaves none of Cargo's processes behind, and the next process resolves normally", async () => {
746
- await withCannedWorkspace(async (fixture) => {
747
- const { root, workspace, manifest, cargo, answer, environment } = fixture;
748
- const otherWorkspace = join(root, 'other');
749
- await put(otherWorkspace, 'Cargo.toml', WORKSPACE_MANIFEST);
750
- const otherManifest = join(otherWorkspace, 'Cargo.toml');
751
-
752
- await answer('before');
753
- await cargo.leaveGrandchildren(true);
754
- await cargo.beforeAnswer.close();
755
- const worker = join(root, 'shared-worker.ts');
756
- await writeFile(
757
- worker,
758
- [
759
- `import { readCargoResolve } from ${JSON.stringify(sourceModule)};`,
760
- "process.once('SIGTERM', () => process.exit(0));",
761
- 'const [firstManifest, firstCwd, secondManifest, secondCwd] = process.argv.slice(2);',
762
- 'const calls = [',
763
- ' ...Array.from({ length: 8 }, () => readCargoResolve(firstManifest, firstCwd)),',
764
- ' ...Array.from({ length: 8 }, () => readCargoResolve(secondManifest, secondCwd)),',
765
- '];',
766
- 'Promise.all(calls).then(() => process.exit(2), () => process.exit(3));',
767
- '',
768
- ].join('\n'),
769
- );
770
- const proc = spawnDrained(
771
- [process.execPath, worker, manifest, workspace, otherManifest, otherWorkspace],
772
- workspace,
773
- environment,
774
- );
775
- // Sixteen callers, two workspaces: two children, each holding an answer and a process of its own.
776
- const runs = await cargo.waitForRuns(
777
- (held) => held.read === 2 && held.grandchildren.length === 2,
778
- 'both cargo children to hold an answer',
779
- );
780
- expect(runs.spawned).toBe(2);
781
- const running = [...runs.pids, ...runs.grandchildren];
782
- for (const pid of running) expect(alive(pid)).toBe(true);
783
-
784
- proc.kill('SIGTERM');
785
- const ended = await guardEvent(proc.ended, 'the worker to exit on SIGTERM', () => proc.describe());
786
- expect(ended.exitCode, proc.describe()).toBe(0);
787
- // Every child and what it left behind is killed: each one's connection ends without a normal end.
788
- await cargo.waitForDisconnects(running);
789
-
790
- // Nothing the dead worker held, a lock or a half-written answer, is in the next process's way.
791
- await cargo.leaveGrandchildren(false);
792
- await cargo.beforeAnswer.open();
793
- await answer('after');
794
- const next = await freshResolver(fixture, 'next').result;
795
- expect(next).toMatchObject({ members: ['after'] });
796
- expect(await spawned(cargo)).toBe(3);
797
- expect(await freshResolver(fixture, 'again').result).toEqual(next);
798
- expect(await spawned(cargo)).toBe(3);
799
- });
800
- });
801
-
802
- // A standalone `smoo-nx-cargo-hash` has no handler of its own, so a signal would end it on the spot,
803
- // before any exit hook could take the Cargo it started along. The module forwards the signal to
804
- // Cargo's process group and then raises it again, so the command still ends by that signal.
805
- for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP'] as const) {
806
- it(`a standalone smoo-nx-cargo-hash ended by ${signal} takes its cargo child and what the child left behind with it`, async () => {
807
- await withCannedWorkspace(async ({ workspace, cargo, answer, environment }) => {
808
- await answer('before');
809
- await cargo.leaveGrandchildren(true);
810
- await cargo.beforeAnswer.close();
811
- const proc = spawnDrained([process.execPath, cliModule, 'Cargo.toml'], workspace, environment);
812
- const runs = await cargo.waitForRuns(
813
- (held) => held.read === 1 && held.grandchildren.length === 1,
814
- 'the cargo child to hold an answer',
815
- );
816
- const running = [...runs.pids, ...runs.grandchildren];
817
- for (const pid of running) expect(alive(pid)).toBe(true);
818
-
819
- proc.kill(signal);
820
- const ended = await guardEvent(proc.ended, `smoo-nx-cargo-hash to end by ${signal}`, () => proc.describe());
821
- expect(ended.signalCode, proc.describe()).toBe(signal);
822
- await cargo.waitForDisconnects(running);
823
- });
824
- });
825
- }
826
-
827
- /* ---- The same, with the real Cargo, through the project graph and the hash command ---- */
828
-
829
- /** `leaf` as the fixture writes it, and the dependency that draws `unrelated` into every closure reaching `leaf`. */
830
- const LEAF_MANIFEST = '[package]\nname="leaf"\nversion="0.1.0"\nedition="2021"\n';
831
- const LEAF_LINK = '[dependencies]\nunrelated={path="../unrelated"}\n';
832
-
833
- /** The fileset the plugin names for the closure members `crates` (a name or a `{a,b}` set) under `crates/`. */
834
- const crateFiles = (crates: string) =>
835
- `{workspaceRoot}/crates/${crates}/**/{*.rs,Cargo.toml,.cargo/config,.cargo/config.toml}`;
836
-
837
- /** Bring Cargo.lock in line with the manifests. */
838
- function relock(workspace: string): void {
839
- execFileSync('cargo', ['generate-lockfile', '--offline', '--manifest-path', join(workspace, 'Cargo.toml')], {
840
- stdio: 'pipe',
841
- });
842
- }
843
-
844
- /**
845
- * An Nx workspace that is also the Cargo workspace. `app` reaches `leaf` through `bridge`, and
846
- * `external`, outside the Nx workspace, through `bridge` too. `unrelated` is a member nothing
847
- * depends on. Returns the workspace.
848
- */
849
- async function graphFixture(root: string): Promise<string> {
850
- const workspace = join(root, 'workspace');
851
- const files: Record<string, string> = {
852
- 'workspace/.gitignore': 'node_modules/\ntarget/\ndist/\n.nx/\n',
853
- 'workspace/package.json':
854
- '{"name":"cargo-resolve-cache-fixture","private":true,"workspaces":["packages/*","crates/*"]}\n',
855
- 'workspace/nx.json': JSON.stringify({
856
- plugins: ['@smoothbricks/nx-plugin'],
857
- namedInputs: { externalRustCrates: [] },
858
- }),
859
- 'workspace/Cargo.toml':
860
- '[workspace]\nmembers=["packages/app","crates/bridge","crates/leaf","crates/unrelated"]\nresolver="2"\n',
861
- 'workspace/packages/app/package.json': '{"name":"app","private":true}\n',
862
- 'workspace/packages/app/Cargo.toml':
863
- '[package]\nname="app"\nversion="0.1.0"\nedition="2021"\n[dependencies]\nbridge={path="../../crates/bridge"}\n',
864
- 'workspace/packages/app/src/main.rs': 'fn main() { println!("{}", bridge::answer()); }\n',
865
- 'workspace/crates/bridge/Cargo.toml':
866
- '[package]\nname="bridge"\nversion="0.1.0"\nedition="2021"\n[dependencies]\nleaf={path="../leaf"}\nexternal={path="../../../external"}\n',
867
- 'workspace/crates/bridge/src/lib.rs': 'pub fn answer() -> u8 { leaf::answer() + external::answer() }\n',
868
- 'workspace/crates/leaf/package.json': '{"name":"leaf","private":true}\n',
869
- 'workspace/crates/leaf/Cargo.toml': LEAF_MANIFEST,
870
- 'workspace/crates/leaf/src/lib.rs': 'pub fn answer() -> u8 { 1 }\n',
871
- 'workspace/crates/unrelated/Cargo.toml': '[package]\nname="unrelated"\nversion="0.1.0"\nedition="2021"\n',
872
- 'workspace/crates/unrelated/src/lib.rs': 'pub fn unrelated() -> u8 { 3 }\n',
873
- 'external/Cargo.toml': '[package]\nname="external"\nversion="0.1.0"\nedition="2021"\n[workspace]\n',
874
- 'external/src/lib.rs': 'pub fn answer() -> u8 { 10 }\n',
875
- };
876
- for (const [path, text] of Object.entries(files)) await put(root, path, text);
877
- execFileSync('git', ['init', '--quiet', workspace], { stdio: 'pipe' });
878
- await symlink(await installation.nodeModules(), join(workspace, 'node_modules'), 'dir');
879
- relock(workspace);
880
- return workspace;
881
- }
882
-
883
- interface GraphWorkspace {
884
- readonly root: string;
885
- readonly workspace: string;
886
- readonly cargo: CountedCargo;
887
- /** One project-graph computation over the fixture: the plugin's `createNodes`, as Nx runs it for each recomputation. */
888
- graph(): Promise<CreateNodesResultV2>;
889
- }
890
-
891
- /** `body` over a temporary Nx and Cargo workspace, with the real Cargo counted. */
892
- async function withGraphWorkspace(body: (fixture: GraphWorkspace) => Promise<void>): Promise<void> {
893
- const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-resolve-graph-')));
894
- try {
895
- const workspace = await graphFixture(root);
896
- const cargo = await countedCargo(root);
897
- const [, infer] = createNodesV2;
898
- try {
899
- await withEnvironment(cargo.environment, () => {
900
- resetWorkspaceContext();
901
- return body({
902
- root,
903
- workspace,
904
- cargo,
905
- graph: async () =>
906
- infer(['package.json', 'packages/app/package.json', 'crates/leaf/package.json'], undefined, {
907
- workspaceRoot: workspace,
908
- nxJsonConfiguration: { namedInputs: { externalRustCrates: [] } },
909
- }),
910
- });
911
- });
912
- } finally {
913
- await cargo.release();
914
- }
915
- } finally {
916
- await rm(root, { recursive: true, force: true });
917
- }
918
- }
919
-
920
- /** The computation's nodes in file order: the plugin pushes them as their projects finish. */
921
- function byFile(graph: CreateNodesResultV2): CreateNodesResultV2 {
922
- return [...graph].sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));
923
- }
924
-
925
- /** The `cargoClosure` definition the computation gave the project at `projectRoot`. */
926
- function closureOf(graph: CreateNodesResultV2, projectRoot: string) {
927
- return (
928
- graph.find(([file]) => dirname(file) === projectRoot)?.[1].projects?.[projectRoot]?.namedInputs?.[
929
- CARGO_CLOSURE_INPUT
930
- ] ?? []
931
- );
932
- }
933
-
934
- it('a project graph over an unchanged Cargo workspace runs Cargo once, however often it is recomputed', async () => {
935
- await withGraphWorkspace(async ({ root, workspace, cargo, graph }) => {
936
- const baseline = byFile(await graph());
937
- expect(closureOf(baseline, 'packages/app')).toContain(crateFiles('{bridge,leaf}'));
938
- expect(closureOf(baseline, 'packages/app')).not.toContain(crateFiles('{bridge,leaf,unrelated}'));
939
- expect(await spawned(cargo)).toBe(1);
940
-
941
- // The daemon recomputes the graph for every batch of file events.
942
- for (let round = 0; round < 3; round += 1) expect(byFile(await graph())).toEqual(baseline);
943
- expect(await spawned(cargo)).toBe(1);
944
-
945
- // A source, a new source file, a file that is not Rust, a manifest or lockfile rewritten byte for byte.
946
- await put(workspace, 'crates/leaf/src/lib.rs', 'pub fn answer() -> u8 { 2 }\n');
947
- await put(workspace, 'crates/leaf/src/extra.rs', 'pub const EXTRA: u8 = 1;\n');
948
- await put(workspace, 'crates/leaf/README.md', '# leaf\n');
949
- await touch(workspace, 'crates/leaf/Cargo.toml');
950
- await touch(workspace, 'Cargo.lock');
951
- expect(byFile(await graph())).toEqual(baseline);
952
- expect(await spawned(cargo)).toBe(1);
953
-
954
- // What Cargo reads brings it back once for the bytes that changed, not for every recomputation after.
955
- const inputs: [string, () => Promise<void>][] = [
956
- ['a member manifest', () => appendFile(join(workspace, 'crates/leaf/Cargo.toml'), '# note\n')],
957
- ['Cargo.lock', () => appendFile(join(workspace, 'Cargo.lock'), '# note\n')],
958
- ['Cargo configuration', () => put(workspace, '.cargo/config.toml', '[env]\nFIXTURE = "1"\n')],
959
- ['a manifest outside the Nx workspace', () => appendFile(join(root, 'external/Cargo.toml'), '# note\n')],
960
- ['the toolchain pin', () => put(workspace, 'devenv.lock', '{"nodes":{}}\n')],
961
- ];
962
- let expected = 1;
963
- for (const [what, change] of inputs) {
964
- await change();
965
- const changed = byFile(await graph());
966
- // A manifest comment also changes the inferred versionless-manifest task
967
- // input. Its dependency closure stays the same, and the new graph is stable.
968
- expect(closureOf(changed, 'packages/app'), what).toEqual(closureOf(baseline, 'packages/app'));
969
- expect(byFile(await graph()), what).toEqual(changed);
970
- expected += 1;
971
- expect(await spawned(cargo), what).toBe(expected);
972
- }
973
-
974
- // And what changes the resolution is seen: the new graph is not the cached one.
975
- await put(workspace, 'crates/leaf/Cargo.toml', LEAF_MANIFEST + LEAF_LINK);
976
- relock(workspace);
977
- const edited = byFile(await graph());
978
- expect(closureOf(edited, 'packages/app')).toContain(crateFiles('{bridge,leaf,unrelated}'));
979
- expect(byFile(await graph())).toEqual(edited);
980
- expect(await spawned(cargo)).toBe(expected + 1);
981
- });
982
- });
983
-
984
- it('a Cargo workspace Cargo refuses fails the project graph with a CargoMetadataError, and no runtime hash stands in', async () => {
985
- await withGraphWorkspace(async ({ workspace, cargo, graph }) => {
986
- expect(closureOf(byFile(await graph()), 'packages/app')).toContain(crateFiles('{bridge,leaf}'));
987
-
988
- // Cargo refuses a Cargo.lock the manifests have outgrown (`--locked`).
989
- await put(workspace, 'crates/leaf/Cargo.toml', LEAF_MANIFEST + LEAF_LINK);
990
- for (let attempt = 0; attempt < 2; attempt += 1) {
991
- const refusal = expectGraphRefusal(await rejectionOf(graph()), join(workspace, 'Cargo.toml'));
992
- for (const [, error] of refusal.errors) {
993
- expect(error.message).toContain('lock file');
994
- expect(error.message).toContain('--locked');
995
- }
996
- }
997
- // A refusal is no answer: the second computation asked Cargo again.
998
- expect(await spawned(cargo)).toBe(3);
999
-
1000
- relock(workspace);
1001
- const repaired = byFile(await graph());
1002
- expect(closureOf(repaired, 'packages/app')).toContain(crateFiles('{bridge,leaf,unrelated}'));
1003
- expect(JSON.stringify(repaired)).not.toContain('--include-workspace');
1004
- expect(byFile(await graph())).toEqual(repaired);
1005
- expect(await spawned(cargo)).toBe(4);
1006
- });
1007
- });
1008
-
1009
- for (const replaced of [false, true]) {
1010
- it(`cache publication records a ${replaced ? 'rebound' : 'missing'} parent with the original filesystem cause`, async () => {
1011
- await withGraphWorkspace(async ({ workspace, cargo }) => {
1012
- const manifest = join(workspace, 'Cargo.toml');
1013
- await cargo.beforeAnswer.close();
1014
- const refused = rejectionOf(readCargoResolve(manifest, workspace));
1015
- await cargo.waitForRuns((runs) => runs.read === 1, 'real locked/offline Cargo to read before cache publication');
1016
- const namespace = join(workspaceDataDirectoryForWorkspace(workspace), 'cargo-resolve');
1017
- const entries = await readdir(namespace);
1018
- expect(entries).toHaveLength(1);
1019
- const [entry] = entries;
1020
- if (entry === undefined) throw new Error('the real resolver created no owned cache namespace');
1021
- const directory = join(namespace, entry);
1022
- const before = await stat(directory, { bigint: true });
1023
- let atOpen = before;
1024
- if (replaced) {
1025
- await rename(directory, `${directory}.retired`);
1026
- await mkdir(directory);
1027
- atOpen = await stat(directory, { bigint: true });
1028
- expect(atOpen.ino).not.toBe(before.ino);
1029
- // Force publication to report the replacement rather than silently sign under a new namespace.
1030
- await mkdir(join(directory, 'entry.cache'));
1031
- } else {
1032
- await rm(directory, { recursive: true });
1033
- }
1034
- await cargo.beforeAnswer.open();
1035
- const failure = expectCargoMetadataError(await refused, manifest);
1036
- expect(failure.message).toContain(directory);
1037
- expect(failure.message).toContain('entry.cache.');
1038
- expect(failure.message).toContain(
1039
- `"parentBeforeLock":${JSON.stringify({ state: 'present', dev: before.dev.toString(), ino: before.ino.toString() })}`,
1040
- );
1041
- if (replaced) {
1042
- const expected = JSON.stringify({ state: 'present', dev: atOpen.dev.toString(), ino: atOpen.ino.toString() });
1043
- expect(failure.message).toContain(`"parentAtTmpOpen":${expected}`);
1044
- expect(failure.message).toContain(`"parentAfterFailure":${expected}`);
1045
- } else {
1046
- expect(failure.message).toContain('"parentAtTmpOpen":{"state":"unavailable","code":"ENOENT"');
1047
- expect(failure.message).toContain('"parentAfterFailure":{"state":"unavailable","code":"ENOENT"');
1048
- }
1049
- const publication = failure.cause;
1050
- expect(publication).toBeInstanceOf(Error);
1051
- if (!(publication instanceof Error)) throw new Error('cache publication lost its structured cause');
1052
- expect(publication.cause).toHaveProperty('code', replaced ? 'EISDIR' : 'ENOENT');
1053
- expect(await spawned(cargo)).toBe(1);
1054
- });
1055
- });
1056
- }
1057
-
1058
- it('fresh smoo-nx-cargo-hash processes over an unchanged Cargo workspace run Cargo once between them', async () => {
1059
- await withGraphWorkspace(async ({ root, workspace, cargo }) => {
1060
- // As nx.json's runtime input runs it: a process per hash, many at once at the start of a run.
1061
- const hash = async (...flags: string[]): Promise<string> => {
1062
- const child = Bun.spawn([process.execPath, cliModule, ...flags, '--closure', 'packages/app', 'Cargo.toml'], {
1063
- cwd: workspace,
1064
- env: { ...process.env, ...cargo.environment },
1065
- stdout: 'pipe',
1066
- stderr: 'pipe',
1067
- });
1068
- const [stdout, stderr, exitCode] = await Promise.all([
1069
- new Response(child.stdout).text(),
1070
- new Response(child.stderr).text(),
1071
- child.exited,
1072
- ]);
1073
- expect(exitCode, stderr).toBe(0);
1074
- expect(stderr).toBe('');
1075
- return stdout;
1076
- };
1077
-
1078
- const cold = await Promise.all(Array.from({ length: 4 }, () => hash()));
1079
- const [initial] = cold;
1080
- if (initial === undefined) throw new Error('no hash command ran');
1081
- for (const output of cold) expect(output).toBe(initial);
1082
- expect(await spawned(cargo)).toBe(1);
1083
- for (let round = 0; round < 3; round += 1) expect(await hash()).toBe(initial);
1084
- expect(await spawned(cargo)).toBe(1);
1085
-
1086
- // The digest still follows what it hashes: a source outside the Nx workspace, not one inside it.
1087
- await put(root, 'external/src/lib.rs', 'pub fn answer() -> u8 { 20 }\n');
1088
- const sourceEdited = await hash();
1089
- expect(sourceEdited).not.toBe(initial);
1090
- await put(workspace, 'crates/leaf/src/lib.rs', 'pub fn answer() -> u8 { 2 }\n');
1091
- expect(await hash()).toBe(sourceEdited);
1092
- expect(await spawned(cargo)).toBe(1);
1093
-
1094
- // A manifest outside the Nx workspace is one of Cargo's inputs: one more child, for it alone.
1095
- await appendFile(join(root, 'external/Cargo.toml'), '# note\n');
1096
- const manifestEdited = await hash();
1097
- expect(manifestEdited).not.toBe(sourceEdited);
1098
- expect(await hash()).toBe(manifestEdited);
1099
- expect(await spawned(cargo)).toBe(2);
1100
- });
1101
- });
1102
-
1103
- it('a Cargo child that never answers is killed and named at the resolve bound', async () => {
1104
- await withCannedWorkspace(async ({ cargo, answer, workspace, manifest }) => {
1105
- await answer('before');
1106
- await cargo.beforeAnswer.close();
1107
- try {
1108
- // The resolve bound is a timer in this process, started only once the lock is held and Cargo is spawned. The
1109
- // clock stays stopped until the canned Cargo reports that it read the workspace and is held at the closed
1110
- // answer latch; only then is the bound advanced, so it expires on a child that can never answer.
1111
- jest.useFakeTimers();
1112
- try {
1113
- const refusal = rejectionOf(readCargoResolve(manifest, workspace, undefined, 100));
1114
- await cargo.waitForRuns((runs) => runs.read >= 1, 'the canned Cargo to read the workspace and be held');
1115
- jest.advanceTimersByTime(100);
1116
- expect(String(await refusal)).toContain('did not finish within 100ms');
1117
- } finally {
1118
- jest.useRealTimers();
1119
- }
1120
- } finally {
1121
- await cargo.beforeAnswer.open();
1122
- }
1123
- });
1124
- });
1125
-
1126
- it('a held resolve lock times out with its name and elapsed wait and leaves no lock child', async () => {
1127
- const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-resolve-lock-')));
1128
- try {
1129
- const lockFile = join(root, 'resolve.lock');
1130
- const holder = new FileLock(lockFile);
1131
- holder.lock();
1132
- try {
1133
- // The lock's bound is a timer in this process, and the waiter cannot take the lock while the holder keeps it.
1134
- // The clock stays stopped while the waiter queues; advancing it by the bound is what ends the wait, and the
1135
- // refusal must then name the lock, the wait and the reaped waiter while the holder still holds the lock.
1136
- jest.useFakeTimers();
1137
- let refused: unknown;
1138
- try {
1139
- const attempt = rejectionOf(acquireCargoResolveLock(lockFile, 100));
1140
- jest.advanceTimersByTime(100);
1141
- refused = await attempt;
1142
- } finally {
1143
- jest.useRealTimers();
1144
- }
1145
- if (!(refused instanceof CargoResolveLockError)) throw new Error(`unexpected lock refusal: ${refused}`);
1146
- expect(refused.name).toBe('CargoResolveLockError');
1147
- expect(refused.message).toContain(lockFile);
1148
- expect(refused.message).toContain(`waited ${refused.waitedMs}ms`);
1149
- expect(refused.message).toContain('bound 100ms');
1150
- expect(refused.waitedMs).toBeGreaterThanOrEqual(100);
1151
- if (refused.waiterPid === undefined) throw new Error('the lock refusal named no spawned waiter');
1152
- expect(refused.message).toContain(`reaped lock waiter pid ${refused.waiterPid}`);
1153
- expect(alive(refused.waiterPid)).toBe(false);
1154
- expect(new FileLock(lockFile).check()).toBe(true);
1155
- } finally {
1156
- holder.unlock();
1157
- }
1158
- } finally {
1159
- await rm(root, { recursive: true, force: true });
1160
- }
1161
- });
1162
-
1163
- it('a successful resolve lock lease holds the kernel lock until its child is released and reaped', async () => {
1164
- const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-resolve-lease-')));
1165
- try {
1166
- const lockFile = join(root, 'resolve.lock');
1167
- // The lock is granted by the child's `locked` line and released by the child's exit, so I/O decides this case; the
1168
- // bound is the leg backstop, which an uncontended lock never reaches.
1169
- const lease = await acquireCargoResolveLock(lockFile, BOUNDED_TEST_IDLE_TIMEOUT_MS);
1170
- try {
1171
- expect(alive(lease.pid)).toBe(true);
1172
- expect(new FileLock(lockFile).check()).toBe(true);
1173
- } finally {
1174
- await lease.release();
1175
- }
1176
- expect(alive(lease.pid)).toBe(false);
1177
- expect(new FileLock(lockFile).check()).toBe(false);
1178
- } finally {
1179
- await rm(root, { recursive: true, force: true });
1180
- }
1181
- });