@smoothbricks/nx-plugin 0.4.26 → 0.4.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/README.md +994 -117
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +15 -73
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +3 -2
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +16 -15
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +43 -6
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +309 -73
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +101 -5
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +291 -10
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +207 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +576 -202
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +370 -138
  102. package/dist/managed-files/ci-workflow.d.ts +13 -0
  103. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.js +44 -13
  105. package/dist/managed-files/files.d.ts +7 -1
  106. package/dist/managed-files/files.d.ts.map +1 -1
  107. package/dist/managed-files/files.js +62 -8
  108. package/dist/managed-files/json-edit.d.ts +21 -0
  109. package/dist/managed-files/json-edit.d.ts.map +1 -0
  110. package/dist/managed-files/json-edit.js +295 -0
  111. package/dist/managed-files/managed-format.d.ts +33 -1
  112. package/dist/managed-files/managed-format.d.ts.map +1 -1
  113. package/dist/managed-files/managed-format.js +82 -2
  114. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  115. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  116. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  117. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/publish-workflow.js +231 -48
  119. package/dist/managed-files/tree.d.ts +5 -0
  120. package/dist/managed-files/tree.d.ts.map +1 -1
  121. package/dist/managed-files/tree.js +5 -3
  122. package/dist/manifest-hash.d.ts.map +1 -1
  123. package/dist/manifest-hash.js +2 -5
  124. package/dist/nextest-code-bound.d.ts +62 -0
  125. package/dist/nextest-code-bound.d.ts.map +1 -0
  126. package/dist/nextest-code-bound.js +154 -0
  127. package/dist/nextest-extraction.d.ts +24 -8
  128. package/dist/nextest-extraction.d.ts.map +1 -1
  129. package/dist/nextest-extraction.js +42 -7
  130. package/dist/package-target-policy.d.ts.map +1 -1
  131. package/dist/package-target-policy.js +3 -5
  132. package/dist/release-config-policy.d.ts.map +1 -1
  133. package/dist/release-config-policy.js +3 -5
  134. package/dist/runtime-input.d.ts +14 -0
  135. package/dist/runtime-input.d.ts.map +1 -0
  136. package/dist/runtime-input.js +15 -0
  137. package/dist/rust-tokens.d.ts +11 -0
  138. package/dist/rust-tokens.d.ts.map +1 -0
  139. package/dist/rust-tokens.js +81 -0
  140. package/dist/task-results.d.ts +6 -0
  141. package/dist/task-results.d.ts.map +1 -0
  142. package/dist/task-results.js +61 -0
  143. package/dist/test-program.d.ts +54 -0
  144. package/dist/test-program.d.ts.map +1 -0
  145. package/dist/test-program.js +292 -0
  146. package/dist/test-timings.d.ts +71 -0
  147. package/dist/test-timings.d.ts.map +1 -0
  148. package/dist/test-timings.js +393 -0
  149. package/dist/test-walk-policy.d.ts +103 -0
  150. package/dist/test-walk-policy.d.ts.map +1 -0
  151. package/dist/test-walk-policy.js +657 -0
  152. package/dist/testing.d.ts +177 -0
  153. package/dist/testing.d.ts.map +1 -0
  154. package/dist/testing.js +824 -0
  155. package/dist/type-guards.d.ts +3 -0
  156. package/dist/type-guards.d.ts.map +1 -0
  157. package/dist/type-guards.js +4 -0
  158. package/dist/typecheck-test-policy.d.ts +8 -5
  159. package/dist/typecheck-test-policy.d.ts.map +1 -1
  160. package/dist/typecheck-test-policy.js +113 -100
  161. package/dist/workspace-config-policy.d.ts +8 -0
  162. package/dist/workspace-config-policy.d.ts.map +1 -1
  163. package/dist/workspace-config-policy.js +175 -63
  164. package/dist/workspace-index.d.ts +12 -0
  165. package/dist/workspace-index.d.ts.map +1 -0
  166. package/dist/workspace-index.js +17 -0
  167. package/dist/workspace-manifest.d.ts +37 -0
  168. package/dist/workspace-manifest.d.ts.map +1 -1
  169. package/executors.json +5 -0
  170. package/loader.js +13 -11
  171. package/managed/raw/envrc +33 -67
  172. package/managed/raw/git-format-staged.yml +30 -35
  173. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  174. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  175. package/managed/raw/tooling/direnv/developer-links.ts +569 -11
  176. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
  177. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  178. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  179. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  180. package/managed/raw/tooling/direnv/repo-path +14 -2
  181. package/managed/raw/tooling/direnv/setup-environment.ts +962 -148
  182. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  183. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  184. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  185. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  186. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  187. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  188. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  189. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  190. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  191. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  192. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  194. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  196. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  197. package/managed/templates/github/workflows/managed-files.yml +1 -2
  198. package/nextest.toml +8 -41
  199. package/package.json +74 -12
  200. package/runtime-input.sh +81 -0
  201. package/src/__tests__/counted-cargo.ts +33 -14
  202. package/src/__tests__/fixture-nx-env.ts +111 -46
  203. package/src/__tests__/progress-clock.ts +43 -0
  204. package/src/__tests__/runtime-input.ts +23 -0
  205. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  206. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  207. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  208. package/src/bin/smoo-nx-exec.ts +16 -74
  209. package/src/bin/smoo-nx-failures.ts +4 -0
  210. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  211. package/src/bin/smoo-nx-test-walks.ts +42 -0
  212. package/src/bounded-test-policy.test.ts +268 -21
  213. package/src/bounded-test-policy.ts +114 -42
  214. package/src/build-state-output-policy.test.ts +115 -0
  215. package/src/build-state-output-policy.ts +90 -0
  216. package/src/bun-bootstrap.test.ts +57 -3
  217. package/src/bun-file-packages.test.ts +47 -0
  218. package/src/cargo-closure-input.test.ts +138 -66
  219. package/src/cargo-closure-input.ts +17 -15
  220. package/src/cargo-dev-profile.ts +137 -0
  221. package/src/cargo-resolve-cache.test.ts +70 -1
  222. package/src/cargo-source-hash.test.ts +193 -97
  223. package/src/cargo-source-hash.ts +345 -68
  224. package/src/cargo-toolchain-policy.ts +6 -0
  225. package/src/cargo-workspace.test.ts +320 -0
  226. package/src/cargo-workspace.ts +336 -10
  227. package/src/cross-check-policy.test.ts +59 -1
  228. package/src/cross-check-policy.ts +25 -6
  229. package/src/disk-command-policy.test.ts +61 -0
  230. package/src/disk-command-policy.ts +107 -0
  231. package/src/ensure-built-receipt.test.ts +184 -0
  232. package/src/ensure-built-receipt.ts +263 -0
  233. package/src/ensure-built-witness.test.ts +344 -0
  234. package/src/ensure-built-witness.ts +252 -0
  235. package/src/ensure-built.test.ts +1036 -578
  236. package/src/ensure-built.ts +820 -224
  237. package/src/eslint-file-set.ts +9 -0
  238. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  239. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  240. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  241. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  242. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  243. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  244. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  245. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  246. package/src/executors/bounded-exec/executor.ts +565 -67
  247. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  248. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  249. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  250. package/src/executors/bounded-exec/progress.test.ts +79 -0
  251. package/src/executors/bounded-exec/progress.ts +118 -0
  252. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  253. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  254. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  255. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  256. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  257. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  258. package/src/executors/bounded-exec/schema.json +11 -5
  259. package/src/executors/bounded-exec/schema.ts +27 -11
  260. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  261. package/src/executors/bounded-exec/verdict.ts +433 -0
  262. package/src/executors/shard-timings/executor.ts +36 -0
  263. package/src/executors/shard-timings/schema.json +21 -0
  264. package/src/executors/shard-timings/schema.ts +4 -0
  265. package/src/failure-summary.ts +119 -0
  266. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  267. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  268. package/src/generators/create-package/generator.test.ts +6 -0
  269. package/src/generators/create-package/generator.ts +6 -2
  270. package/src/host-controller-wiring.test.ts +31 -0
  271. package/src/index.test.ts +909 -295
  272. package/src/index.ts +441 -143
  273. package/src/linked-snapshots.nx.test.ts +172 -0
  274. package/src/managed-files/ci-workflow.ts +54 -13
  275. package/src/managed-files/files.ts +65 -9
  276. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  277. package/src/managed-files/generator.test.ts +60 -1
  278. package/src/managed-files/json-edit.test.ts +216 -0
  279. package/src/managed-files/json-edit.ts +290 -0
  280. package/src/managed-files/managed-format-json.test.ts +308 -0
  281. package/src/managed-files/managed-format.ts +90 -2
  282. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  283. package/src/managed-files/publish-workflow.ts +285 -67
  284. package/src/managed-files/repo-path.test.ts +129 -0
  285. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  286. package/src/managed-files/tree.ts +11 -3
  287. package/src/manifest-hash.ts +2 -6
  288. package/src/nextest-code-bound.test.ts +155 -0
  289. package/src/nextest-code-bound.ts +195 -0
  290. package/src/nextest-extraction.test.ts +37 -5
  291. package/src/nextest-extraction.ts +51 -9
  292. package/src/nextest-partitions.test.ts +427 -82
  293. package/src/nx-cache-bound.test.ts +5 -10
  294. package/src/nx-cache-restore-mtime.test.ts +170 -0
  295. package/src/nx-daemon-claim.test.ts +277 -0
  296. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  297. package/src/nx-daemon-idle-policy.test.ts +51 -0
  298. package/src/nx-daemon-ignore-files.test.ts +210 -0
  299. package/src/nx-daemon-root-normalization.test.ts +105 -0
  300. package/src/nx-daemon-validity.test.ts +925 -0
  301. package/src/nx-dot-input-policy.test.ts +353 -0
  302. package/src/nx-failure-life-cycles.test.ts +207 -0
  303. package/src/nx-files-archive-racy.test.ts +97 -0
  304. package/src/nx-foreign-workspace-env.test.ts +329 -0
  305. package/src/nx-incomplete-run-summary.test.ts +70 -0
  306. package/src/nx-plugin-load-errors.test.ts +120 -0
  307. package/src/nx-project-resolution-cache.test.ts +176 -0
  308. package/src/nx-raw-inputs.test.ts +166 -0
  309. package/src/nx-resident-graph-workers.test.ts +7 -16
  310. package/src/nx-run-information.test.ts +118 -0
  311. package/src/nx-skipped-task-exit.test.ts +180 -0
  312. package/src/nx-state-location.test.ts +63 -0
  313. package/src/nx-store-resolution.test.ts +26 -25
  314. package/src/nx-task-graph-cycles.test.ts +148 -0
  315. package/src/nx-task-output-lease.test.ts +414 -0
  316. package/src/nx-use-local.test.ts +103 -0
  317. package/src/package-target-policy.ts +3 -6
  318. package/src/release-config-policy.ts +3 -6
  319. package/src/runtime-input.test.ts +215 -0
  320. package/src/runtime-input.ts +17 -0
  321. package/src/rust-tokens.ts +78 -0
  322. package/src/serial-group-wiring.test.ts +326 -0
  323. package/src/task-history-namespace.test.ts +87 -89
  324. package/src/task-results.test.ts +226 -0
  325. package/src/task-results.ts +75 -0
  326. package/src/test-program.test.ts +303 -0
  327. package/src/test-program.ts +341 -0
  328. package/src/test-timings.test.ts +240 -0
  329. package/src/test-timings.ts +311 -0
  330. package/src/test-walk-policy.test.ts +585 -0
  331. package/src/test-walk-policy.ts +731 -0
  332. package/src/testing.test.ts +509 -0
  333. package/src/testing.ts +922 -0
  334. package/src/type-guards.ts +4 -0
  335. package/src/typecheck-test-policy.test.ts +496 -11
  336. package/src/typecheck-test-policy.ts +137 -103
  337. package/src/workspace-config-policy.test.ts +212 -13
  338. package/src/workspace-config-policy.ts +101 -73
  339. package/src/workspace-index.ts +18 -0
  340. package/src/workspace-manifest.ts +41 -0
  341. package/test-timings.json +85 -30
  342. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
  343. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
@@ -0,0 +1,7 @@
1
+ import { expect, it } from 'bun:test';
2
+ import { TRACE_DB_DIRECTORY, TRACE_DB_FILENAME } from '@smoothbricks/lmao/sqlite';
3
+ import { TRACE_DB_ARTIFACT_GLOB } from './ci-workflow.js';
4
+
5
+ it('uploads the trace sink from where lmao writes it, WAL sidecars included', () => {
6
+ expect(TRACE_DB_ARTIFACT_GLOB).toBe(`packages/*/${TRACE_DB_DIRECTORY}/${TRACE_DB_FILENAME}*`);
7
+ });
@@ -11,6 +11,11 @@ export interface ManagedFile {
11
11
  target: string;
12
12
  content: string | null;
13
13
  executable?: boolean;
14
+ /**
15
+ * Why a `null` content is null, when the generator chose not to write a target
16
+ * it would otherwise own. Reported on the `skipped` result; it blocks nothing.
17
+ */
18
+ skipReason?: string;
14
19
  }
15
20
 
16
21
  /** Only facts Tree cannot expose. File contents always come from Tree. */
@@ -64,7 +69,7 @@ export function stageManagedFiles(
64
69
  const seen = new Set<string>();
65
70
  const pending = new Map(tree.listChanges().map((change) => [change.path, change]));
66
71
  const targets = new Set(files.map((file) => file.target));
67
- return files.map(({ target, content, executable = false }): FileResult => {
72
+ return files.map(({ target, content, executable = false, skipReason }): FileResult => {
68
73
  const conflict = (reason: string): FileResult => ({ target, action: 'drifted', reason });
69
74
  if (!isManagedTarget(target)) return conflict('expected a canonical workspace-relative path');
70
75
  if (seen.has(target)) return conflict('duplicate managed target');
@@ -73,7 +78,10 @@ export function stageManagedFiles(
73
78
  if (parts.some((_, i) => i > 0 && targets.has(parts.slice(0, i).join('/')))) {
74
79
  return conflict('a managed file is also declared as a parent directory');
75
80
  }
76
- if (content === null) return { target, action: 'skipped' };
81
+ if (content === null)
82
+ return skipReason === undefined
83
+ ? { target, action: 'skipped' }
84
+ : { target, action: 'skipped', reason: skipReason };
77
85
  const path = paths.get(target);
78
86
  if (path?.error) return conflict(path.error);
79
87
  for (let i = 1; i < parts.length; i++) {
@@ -109,7 +117,7 @@ export function stageManagedFiles(
109
117
  }
110
118
 
111
119
  export function assertNoManagedConflicts(results: readonly FileResult[]): void {
112
- const conflicts = results.filter((result) => result.reason !== undefined);
120
+ const conflicts = results.filter((result) => result.action === 'drifted' && result.reason !== undefined);
113
121
  if (conflicts.length > 0) {
114
122
  throw new ManagedContentConflict(
115
123
  `Managed-file update refused before writing:\n${conflicts.map(({ target, reason }) => `${target}: ${reason}`).join('\n')}`,
@@ -2,8 +2,7 @@ import { createHash, type Hash } from 'node:crypto';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { join, posix } from 'node:path';
4
4
 
5
- import { globWithWorkspaceContext, globWithWorkspaceContextSync } from 'nx/src/utils/workspace-context.js';
6
- import { workspaceRoot as daemonWorkspaceRoot } from 'nx/src/utils/workspace-root.js';
5
+ import { globIndexedFiles } from './workspace-index.js';
7
6
 
8
7
  /**
9
8
  * A release rewrites `version` in every manifest it publishes. Those manifests
@@ -182,10 +181,7 @@ export async function hashVersionlessCrateManifests(projectRoot: string, workspa
182
181
  async function listCrateManifests(projectRoot: string, workspaceRoot: string): Promise<string[]> {
183
182
  const prefix = projectRoot === '.' ? '' : `${posix.normalize(projectRoot)}/`;
184
183
  const pattern = [`${prefix}**/${CARGO_MANIFEST}`];
185
- const files =
186
- workspaceRoot === daemonWorkspaceRoot
187
- ? await globWithWorkspaceContext(workspaceRoot, pattern)
188
- : globWithWorkspaceContextSync(workspaceRoot, pattern);
184
+ const files = await globIndexedFiles(workspaceRoot, pattern);
189
185
  return files.map((file) => file.slice(prefix.length)).sort();
190
186
  }
191
187
 
@@ -0,0 +1,155 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { chmodSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { codeTime, describeCodeTime, parseWaitRecord, type WaitEdge } from './nextest-code-bound.js';
8
+
9
+ const WRAPPER = fileURLToPath(new URL('./nextest-code-bound.ts', import.meta.url));
10
+
11
+ const start = (pid: number, seq: number, atUs: number): WaitEdge => ({
12
+ kind: 'start',
13
+ pid,
14
+ seq,
15
+ atUs,
16
+ diskClass: 'storage',
17
+ });
18
+ const end = (pid: number, seq: number, atUs: number): WaitEdge => ({ kind: 'end', pid, seq, atUs });
19
+
20
+ describe('lease-wait record', () => {
21
+ it('reads both edge shapes as clients write them and refuses anything else', () => {
22
+ expect(parseWaitRecord('start 7 0 100 storage\nend 7 0 250\n')).toEqual({
23
+ ok: true,
24
+ edges: [start(7, 0, 100), end(7, 0, 250)],
25
+ });
26
+ expect(parseWaitRecord('')).toEqual({ ok: true, edges: [] });
27
+ for (const bad of [
28
+ 'start 7 0 100',
29
+ 'end 7 0',
30
+ 'end 7 0 1 x',
31
+ 'begin 7 0 1',
32
+ 'end 7 -1 5',
33
+ 'start 7 0 1.5 storage',
34
+ ]) {
35
+ expect(parseWaitRecord(`${bad}\n`).ok).toBe(false);
36
+ }
37
+ });
38
+ });
39
+
40
+ describe('code time', () => {
41
+ it('is the wall time less every wait', () => {
42
+ const time = codeTime([start(1, 0, 1_000), end(1, 0, 3_000), start(1, 1, 5_000), end(1, 1, 6_000)], 0, 10_000);
43
+ expect(time).toEqual({ wallUs: 10_000, waitUs: 3_000, codeUs: 7_000, waits: 2, open: [], strayEnds: 0 });
44
+ });
45
+
46
+ it('counts concurrent waits of several processes once, as their union', () => {
47
+ const edges = [
48
+ start(1, 0, 1_000),
49
+ start(2, 0, 2_000),
50
+ end(1, 0, 4_000),
51
+ end(2, 0, 5_000),
52
+ start(1, 1, 4_500),
53
+ end(1, 1, 4_800),
54
+ ];
55
+ expect(codeTime(edges, 0, 10_000)).toMatchObject({ waitUs: 4_000, codeUs: 6_000, waits: 3 });
56
+ });
57
+
58
+ it('clips waits to the test run', () => {
59
+ expect(codeTime([start(1, 0, 0), end(1, 0, 3_000)], 1_000, 5_000)).toMatchObject({ waitUs: 2_000, codeUs: 2_000 });
60
+ });
61
+
62
+ it('counts a wait that never ended to the end of the test and names it', () => {
63
+ const time = codeTime([start(1, 0, 1_000), end(1, 0, 2_000), start(9, 3, 8_000)], 0, 10_000);
64
+ expect(time).toMatchObject({ waitUs: 3_000, codeUs: 7_000, open: [{ pid: 9, seq: 3, startedUs: 8_000 }] });
65
+ expect(describeCodeTime(time, 30_000_000)).toContain("pid 9's wait 3 never ended");
66
+ });
67
+
68
+ it('counts an end without a start as code time', () => {
69
+ expect(codeTime([end(1, 0, 2_000)], 0, 10_000)).toMatchObject({ waitUs: 0, codeUs: 10_000, strayEnds: 1 });
70
+ });
71
+
72
+ it('says whether the code time is within its class', () => {
73
+ const time = codeTime([start(1, 0, 0), end(1, 0, 20_000_000)], 0, 45_000_000);
74
+ expect(describeCodeTime(time, 30_000_000)).toBe(
75
+ 'nextest-code-bound: code 25.0s of 30.0s, within its class (wall 45.0s less 20.0s waiting for the host disk lease over 1 waits)',
76
+ );
77
+ expect(describeCodeTime(time, 20_000_000)).toStartWith(
78
+ 'nextest-code-bound: code 25.0s of 20.0s, OVER its class (a warning)',
79
+ );
80
+ });
81
+ });
82
+
83
+ describe('nextest-code-bound wrapper', () => {
84
+ /**
85
+ * A stand-in test binary: it records `wait` seconds of lease wait in the record its wrapper names,
86
+ * from a child process as a disk-lease client in the test's tree would, then works `work` seconds
87
+ * and exits `status`.
88
+ */
89
+ const runWrapped = (bound: string, wait: number, work: number, status: number) => {
90
+ const root = mkdtempSync(join(tmpdir(), 'nextest-code-bound-'));
91
+ try {
92
+ const binary = join(root, 'fake-test');
93
+ writeFileSync(
94
+ binary,
95
+ [
96
+ '#!/bin/sh',
97
+ 'sh -c \'echo "start $$ 0 $(perl -MTime::HiRes=time -e "printf q(%d), time() * 1000000") namespace" >> "$COWSHED_LEASE_WAIT_RECORD"; ' +
98
+ `sleep ${wait}; ` +
99
+ 'echo "end $$ 0 $(perl -MTime::HiRes=time -e "printf q(%d), time() * 1000000")" >> "$COWSHED_LEASE_WAIT_RECORD"\'',
100
+ `sleep ${work}`,
101
+ 'echo "argument $1"',
102
+ `exit ${status}`,
103
+ ].join('\n'),
104
+ );
105
+ chmodSync(binary, 0o755);
106
+ // The wrapper makes its record in its TMPDIR: this case's own root, so the count below is this run's alone.
107
+ const run = spawnSync(WRAPPER, [bound, binary, '--exact'], {
108
+ encoding: 'utf8',
109
+ env: { ...process.env, TMPDIR: root },
110
+ });
111
+ const recordsLeft = readdirSync(root).filter((name) => name.startsWith('cowshed-lease-waits-')).length;
112
+ return { status: run.status, stdout: run.stdout, stderr: run.stderr, recordsLeft };
113
+ } finally {
114
+ rmSync(root, { recursive: true, force: true });
115
+ }
116
+ };
117
+
118
+ // Real processes and real time, so the cases sleep as little as proves each verdict: 0.75s in all.
119
+ it('passes a test whose wall time is over its class only by its lease waits', () => {
120
+ const run = runWrapped('0.3', 0.4, 0, 0);
121
+ expect(run.stdout).toContain('argument --exact');
122
+ expect(run.stderr).toMatch(
123
+ /nextest-code-bound: code 0\.\d+s of 0\.3s, within its class \(wall \d+\.\d+s less \d+\.\ds waiting/,
124
+ );
125
+ expect(run.status).toBe(0);
126
+ expect(run.recordsLeft).toBe(0);
127
+ });
128
+
129
+ it('reports code-time verdicts without changing the test exit status', () => {
130
+ for (const { label, bound, work, status, verdict } of [
131
+ {
132
+ label: 'warns of a passing test whose code time is over its class, and still passes it',
133
+ bound: '0.3',
134
+ work: 0.35,
135
+ status: 0,
136
+ verdict: 'OVER its class (a warning)',
137
+ },
138
+ {
139
+ label: "keeps a failing test's own exit status and still reports its split",
140
+ bound: '30',
141
+ work: 0,
142
+ status: 3,
143
+ verdict: 'within its class',
144
+ },
145
+ ]) {
146
+ const run = runWrapped(bound, 0, work, status);
147
+ expect(run.stderr, label).toContain(verdict);
148
+ expect(run.status, label).toBe(status);
149
+ }
150
+ });
151
+
152
+ it('refuses to run without a class', () => {
153
+ expect(spawnSync(WRAPPER, ['soon', '/bin/true'], { encoding: 'utf8' }).status).toBe(2);
154
+ });
155
+ });
@@ -0,0 +1,195 @@
1
+ #!/usr/bin/env bun
2
+ import { spawn } from 'node:child_process';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { readFileSync, rmSync, writeFileSync } from 'node:fs';
5
+ import { tmpdir } from 'node:os';
6
+ import { join, resolve } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+
9
+ /**
10
+ * A nextest run-wrapper that measures a test's code time rather than its wall time against its class
11
+ * (specs/cowshed/08_testing.md, "Integration tests (real substrate)").
12
+ *
13
+ * A real-APFS test spends part of its wall time queued for the host disk-lifecycle lease, behind
14
+ * every other cowshed process on the host (05_gateway.md, "Disk-lifecycle lease"). That queue is
15
+ * the host's, not the test's code. The wrapper names a fresh lease-wait record in
16
+ * `COWSHED_LEASE_WAIT_RECORD`, runs the test binary, which every disk-lease client of the test's
17
+ * process tree appends its waits to, and then measures the test's code time, its wall time less the
18
+ * union of those waits, against the class it was configured with. It says the split on stderr after
19
+ * the test body, and warns when the code time is over the class; the test keeps its own exit status.
20
+ * A class is a slow warning, never a kill or a failure: the run's no-progress bound ends a hang.
21
+ *
22
+ * Usage, as nextest invokes it: `nextest-code-bound.ts <class-seconds> <test-binary> [args…]`.
23
+ */
24
+
25
+ /** The variable naming the record; the same name every disk-lease client reads. */
26
+ export const LEASE_WAIT_RECORD_ENV = 'COWSHED_LEASE_WAIT_RECORD';
27
+
28
+ /** One line of the record: a wait's start, before its client asks, or its end, however it ended. */
29
+ export type WaitEdge =
30
+ | {
31
+ readonly kind: 'start';
32
+ readonly pid: number;
33
+ readonly seq: number;
34
+ readonly atUs: number;
35
+ readonly diskClass: string;
36
+ }
37
+ | { readonly kind: 'end'; readonly pid: number; readonly seq: number; readonly atUs: number };
38
+
39
+ export type ParsedRecord = { ok: true; edges: WaitEdge[] } | { ok: false; error: string };
40
+
41
+ const INTEGER = /^\d+$/;
42
+
43
+ /** Reads a record as its clients write it. Any line that is not one of the two shapes is refused. */
44
+ export function parseWaitRecord(text: string): ParsedRecord {
45
+ const edges: WaitEdge[] = [];
46
+ for (const line of text.split('\n')) {
47
+ if (line === '') {
48
+ continue;
49
+ }
50
+ const fields = line.split(' ');
51
+ const [kind, pid, seq, atUs] = fields;
52
+ const numeric = [pid, seq, atUs].every((field) => field !== undefined && INTEGER.test(field));
53
+ if (kind === 'start' && fields.length === 5 && numeric) {
54
+ edges.push({ kind, pid: Number(pid), seq: Number(seq), atUs: Number(atUs), diskClass: fields[4] });
55
+ } else if (kind === 'end' && fields.length === 4 && numeric) {
56
+ edges.push({ kind, pid: Number(pid), seq: Number(seq), atUs: Number(atUs) });
57
+ } else {
58
+ return { ok: false, error: `line ${JSON.stringify(line)} is neither a wait's start nor its end` };
59
+ }
60
+ }
61
+ return { ok: true, edges };
62
+ }
63
+
64
+ /** A wait whose end never reached the record: its process died while waiting, or still waits. */
65
+ export interface OpenWait {
66
+ readonly pid: number;
67
+ readonly seq: number;
68
+ readonly startedUs: number;
69
+ }
70
+
71
+ export interface CodeTime {
72
+ readonly wallUs: number;
73
+ /** The union of every wait, clipped to the test's run: concurrent waits count once. */
74
+ readonly waitUs: number;
75
+ readonly codeUs: number;
76
+ readonly waits: number;
77
+ /** Counted to the test's end: the record cannot say when they stopped. */
78
+ readonly open: readonly OpenWait[];
79
+ /** Ends with no start, which can only follow an unwritable start: counted as code time. */
80
+ readonly strayEnds: number;
81
+ }
82
+
83
+ /** The test's code time: its wall time from `startedUs` to `endedUs` less the union of its waits. */
84
+ export function codeTime(edges: readonly WaitEdge[], startedUs: number, endedUs: number): CodeTime {
85
+ const starts = new Map<string, { atUs: number; pid: number; seq: number }>();
86
+ const intervals: Array<[number, number]> = [];
87
+ let strayEnds = 0;
88
+ for (const edge of edges) {
89
+ const key = `${edge.pid}:${edge.seq}`;
90
+ if (edge.kind === 'start') {
91
+ starts.set(key, { atUs: edge.atUs, pid: edge.pid, seq: edge.seq });
92
+ continue;
93
+ }
94
+ const start = starts.get(key);
95
+ if (start === undefined) {
96
+ strayEnds += 1;
97
+ continue;
98
+ }
99
+ starts.delete(key);
100
+ intervals.push([start.atUs, edge.atUs]);
101
+ }
102
+ const open = [...starts.values()].map(({ pid, seq, atUs }) => ({ pid, seq, startedUs: atUs }));
103
+ for (const wait of open) {
104
+ intervals.push([wait.startedUs, endedUs]);
105
+ }
106
+ const waits = intervals.length;
107
+ const clipped = intervals
108
+ .map(([from, to]): [number, number] => [Math.max(from, startedUs), Math.min(to, endedUs)])
109
+ .filter(([from, to]) => to > from)
110
+ .sort((left, right) => left[0] - right[0]);
111
+ let waitUs = 0;
112
+ let reach = startedUs;
113
+ for (const [from, to] of clipped) {
114
+ const begin = Math.max(from, reach);
115
+ if (to > begin) {
116
+ waitUs += to - begin;
117
+ reach = to;
118
+ }
119
+ }
120
+ const wallUs = Math.max(0, endedUs - startedUs);
121
+ return { wallUs, waitUs, codeUs: wallUs - waitUs, waits, open, strayEnds };
122
+ }
123
+
124
+ const seconds = (us: number): string => `${(us / 1_000_000).toFixed(1)}s`;
125
+
126
+ /** The one line the wrapper prints after the test body. */
127
+ export function describeCodeTime(time: CodeTime, classUs: number): string {
128
+ const verdict = time.codeUs > classUs ? 'OVER its class (a warning)' : 'within its class';
129
+ const parts = [
130
+ `nextest-code-bound: code ${seconds(time.codeUs)} of ${seconds(classUs)}, ${verdict}`,
131
+ `(wall ${seconds(time.wallUs)} less ${seconds(time.waitUs)} waiting for the host disk lease over ${time.waits} waits)`,
132
+ ];
133
+ for (const wait of time.open) {
134
+ parts.push(`; pid ${wait.pid}'s wait ${wait.seq} never ended and counts to the test's end`);
135
+ }
136
+ if (time.strayEnds > 0) {
137
+ parts.push(`; ${time.strayEnds} wait ends had no recorded start and count as code time`);
138
+ }
139
+ return parts.join(' ');
140
+ }
141
+
142
+ const CLASS_PATTERN = /^\d+(\.\d+)?$/;
143
+
144
+ /** The signals the wrapper passes on to the test rather than dying of. */
145
+ const FORWARDED: readonly NodeJS.Signals[] = ['SIGTERM', 'SIGINT', 'SIGHUP'];
146
+
147
+ /** Runs the test under the record, reports its code time, and exits as the test did. */
148
+ async function main(argv: readonly string[]): Promise<never> {
149
+ const [codeClass, binary, ...args] = argv;
150
+ if (codeClass === undefined || !CLASS_PATTERN.test(codeClass) || Number(codeClass) <= 0 || binary === undefined) {
151
+ process.stderr.write('nextest-code-bound: usage: nextest-code-bound.ts <class-seconds> <test-binary> [args…]\n');
152
+ process.exit(2);
153
+ }
154
+ const classUs = Number(codeClass) * 1_000_000;
155
+ const record = join(tmpdir(), `cowshed-lease-waits-${process.pid}-${randomUUID()}`);
156
+ writeFileSync(record, '', { mode: 0o600, flag: 'wx' });
157
+ const startedUs = Math.round((performance.timeOrigin + performance.now()) * 1000);
158
+ const child = spawn(binary, args, { stdio: 'inherit', env: { ...process.env, [LEASE_WAIT_RECORD_ENV]: record } });
159
+ // nextest stops a test by signalling its process group, which the child is in; the wrapper stays
160
+ // to report what the stopped test spent, and passes on a signal sent to it alone.
161
+ const handlers = FORWARDED.map((signal) => {
162
+ const handler = () => {
163
+ child.kill(signal);
164
+ };
165
+ process.on(signal, handler);
166
+ return { signal, handler };
167
+ });
168
+ const exit = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((settle) => {
169
+ child.once('error', (error) => {
170
+ process.stderr.write(`nextest-code-bound: could not start ${binary}: ${error.message}\n`);
171
+ settle({ code: 1, signal: null });
172
+ });
173
+ child.once('exit', (code, signal) => settle({ code, signal }));
174
+ });
175
+ const endedUs = Math.round((performance.timeOrigin + performance.now()) * 1000);
176
+ for (const { signal, handler } of handlers) {
177
+ process.removeListener(signal, handler);
178
+ }
179
+ const parsed = parseWaitRecord(readFileSync(record, 'utf8'));
180
+ rmSync(record, { force: true });
181
+ if (!parsed.ok) {
182
+ process.stderr.write(`nextest-code-bound: the lease-wait record ${record} is unreadable: ${parsed.error}\n`);
183
+ process.exit(exit.code === 0 ? 1 : (exit.code ?? 1));
184
+ }
185
+ const time = codeTime(parsed.edges, startedUs, endedUs);
186
+ process.stderr.write(`${describeCodeTime(time, classUs)}\n`);
187
+ if (exit.signal !== null) {
188
+ process.kill(process.pid, exit.signal);
189
+ }
190
+ process.exit(exit.code ?? 1);
191
+ }
192
+
193
+ if (process.argv[1] !== undefined && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
194
+ await main(process.argv.slice(2));
195
+ }
@@ -1,15 +1,18 @@
1
1
  import { describe, expect, it } from 'bun:test';
2
- import { mkdir, mkdtemp, readdir, rm, stat, utimes, writeFile } from 'node:fs/promises';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { mkdir, mkdtemp, readdir, realpath, rm, stat, utimes, writeFile } from 'node:fs/promises';
3
4
  import { tmpdir } from 'node:os';
4
5
  import { join } from 'node:path';
5
6
  import {
6
7
  EXTRACTED_BINARIES_METADATA,
7
8
  EXTRACTED_CARGO_METADATA,
8
9
  ensureNextestArchiveExtracted,
10
+ NEXTEST_EXTRACTION_DIRECTORY,
9
11
  type NextestArchiveExtractor,
10
12
  type NextestExtractionEvent,
11
13
  nextestArchiveKey,
12
14
  nextestExtractionPaths,
15
+ nextestExtractionRoot,
13
16
  } from './nextest-extraction.js';
14
17
 
15
18
  /** What nextest leaves behind: the two metadata files a reuse run reads. */
@@ -27,7 +30,7 @@ describe('ensureNextestArchiveExtracted', () => {
27
30
  try {
28
31
  const archive = join(root, 'archive.tar.zst');
29
32
  await writeFile(archive, 'archive bytes');
30
- const paths = nextestExtractionPaths(archive, await nextestArchiveKey(archive));
33
+ const paths = nextestExtractionPaths(join(root, 'extractions'), await nextestArchiveKey(archive));
31
34
  // A holder killed mid-extraction (a bounded run's SIGKILL) leaves its
32
35
  // lock behind, and a pid in it that may since belong to anyone.
33
36
  await mkdir(paths.root, { recursive: true });
@@ -36,7 +39,13 @@ describe('ensureNextestArchiveExtracted', () => {
36
39
  await utimes(paths.lock, minuteAgo, minuteAgo);
37
40
 
38
41
  const events: NextestExtractionEvent[] = [];
39
- const extraction = await ensureNextestArchiveExtracted(archive, unpack, (event) => events.push(event), FAST);
42
+ const extraction = await ensureNextestArchiveExtracted(
43
+ archive,
44
+ paths.root,
45
+ unpack,
46
+ (event) => events.push(event),
47
+ FAST,
48
+ );
40
49
 
41
50
  expect(extraction).toMatchObject({ kind: 'extracted', directory: paths.directory });
42
51
  expect(events).toEqual([{ kind: 'stale-lock', holder: `pid ${process.pid}`, ageMs: expect.any(Number) }]);
@@ -51,7 +60,7 @@ describe('ensureNextestArchiveExtracted', () => {
51
60
  try {
52
61
  const archive = join(root, 'archive.tar.zst');
53
62
  await writeFile(archive, 'archive bytes');
54
- const paths = nextestExtractionPaths(archive, await nextestArchiveKey(archive));
63
+ const paths = nextestExtractionPaths(join(root, 'extractions'), await nextestArchiveKey(archive));
55
64
  // Unpacked from the old bytes, but the directory would be named for
56
65
  // them while the path now holds others: a later run hashing the new
57
66
  // bytes would never find it, and one hashing the old bytes again — the
@@ -61,7 +70,7 @@ describe('ensureNextestArchiveExtracted', () => {
61
70
  await writeFile(archive, 'rebuilt archive bytes');
62
71
  };
63
72
 
64
- await expect(ensureNextestArchiveExtracted(archive, rebuiltMidway, () => {}, FAST)).rejects.toThrow(
73
+ await expect(ensureNextestArchiveExtracted(archive, paths.root, rebuiltMidway, () => {}, FAST)).rejects.toThrow(
65
74
  /changed while it was being extracted/,
66
75
  );
67
76
  // No directory under the old key, no staging left over, no lock held.
@@ -72,3 +81,26 @@ describe('ensureNextestArchiveExtracted', () => {
72
81
  }
73
82
  });
74
83
  });
84
+
85
+ describe('nextestExtractionRoot', () => {
86
+ it("extracts under the target directory Cargo reports, never beside the archive's Nx output", async () => {
87
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'nextest-extraction-root-')));
88
+ try {
89
+ await writeFile(
90
+ join(root, 'Cargo.toml'),
91
+ '[package]\nname = "extraction-root-probe"\nversion = "0.1.0"\nedition = "2021"\n',
92
+ );
93
+ await mkdir(join(root, 'src'));
94
+ await writeFile(join(root, 'src/lib.rs'), '');
95
+ expect(spawnSync('cargo', ['generate-lockfile', '--offline'], { cwd: root }).status).toBe(0);
96
+ expect(await nextestExtractionRoot(root)).toBe(join(root, 'target', NEXTEST_EXTRACTION_DIRECTORY));
97
+
98
+ // A repository that moves Cargo's build tree moves its extractions with it.
99
+ await mkdir(join(root, '.cargo'));
100
+ await writeFile(join(root, '.cargo/config.toml'), '[build]\ntarget-dir = "out/cargo"\n');
101
+ expect(await nextestExtractionRoot(root)).toBe(join(root, 'out/cargo', NEXTEST_EXTRACTION_DIRECTORY));
102
+ } finally {
103
+ await rm(root, { recursive: true, force: true });
104
+ }
105
+ });
106
+ });
@@ -62,9 +62,19 @@ export async function nextestArchiveKey(archive: string): Promise<string> {
62
62
  }
63
63
 
64
64
  /**
65
- * One archive path's extractions live beside it, each under the hash of the
66
- * bytes it came from; the lock and staging directories of a key carry that
67
- * key as their prefix, so cleanup can tell them from another key's.
65
+ * The directory, inside the Cargo target directory, that holds a workspace's
66
+ * archive extractions. An extraction is content-keyed per-checkout tool state
67
+ * of the same kind as the rest of the target directory: rebuilt from an Nx
68
+ * output, reused by the next run, never an Nx output itself. It therefore lives
69
+ * wherever Cargo's build tree lives, which a checkout that keeps its build state
70
+ * on its own volume already keeps off its source tree.
71
+ */
72
+ export const NEXTEST_EXTRACTION_DIRECTORY = 'nextest-extracted';
73
+
74
+ /**
75
+ * A workspace's extractions live under one root, each under the hash of the
76
+ * bytes it came from; the lock and staging directories of a key carry that key
77
+ * as their prefix, so cleanup can tell them from another key's.
68
78
  */
69
79
  export interface NextestExtractionPaths {
70
80
  root: string;
@@ -73,8 +83,7 @@ export interface NextestExtractionPaths {
73
83
  stagingPrefix: string;
74
84
  }
75
85
 
76
- export function nextestExtractionPaths(archive: string, key: string): NextestExtractionPaths {
77
- const root = `${archive}.extracted`;
86
+ export function nextestExtractionPaths(root: string, key: string): NextestExtractionPaths {
78
87
  return {
79
88
  root,
80
89
  directory: join(root, key),
@@ -84,8 +93,40 @@ export function nextestExtractionPaths(archive: string, key: string): NextestExt
84
93
  }
85
94
 
86
95
  /**
87
- * The directory holding `archive`'s extraction, extracting it first if no
88
- * caller has yet.
96
+ * The extraction root of the Cargo workspace in `cwd`:
97
+ * `<target_directory>/nextest-extracted`, with the target directory Cargo itself
98
+ * reports, so a `build.target-dir` in the repository's Cargo config is honoured
99
+ * exactly as every build of the workspace honours it.
100
+ */
101
+ export async function nextestExtractionRoot(cwd: string): Promise<string> {
102
+ const args = ['--frozen', 'metadata', '--no-deps', '--format-version', '1'];
103
+ const child = spawn('cargo', args, { cwd, stdio: ['ignore', 'pipe', 'inherit'] });
104
+ const chunks: Buffer[] = [];
105
+ child.stdout.on('data', (chunk: Buffer) => chunks.push(chunk));
106
+ // 'close', not 'exit': stdout may still hold unread metadata when the process exits.
107
+ const [code, signal]: unknown[] = await once(child, 'close');
108
+ if (code !== 0) {
109
+ throw new Error(
110
+ `cargo ${args.join(' ')} ${code === null ? `died of ${String(signal)}` : `exited with status ${String(code)}`}`,
111
+ );
112
+ }
113
+ return join(cargoTargetDirectory(Buffer.concat(chunks).toString('utf8')), NEXTEST_EXTRACTION_DIRECTORY);
114
+ }
115
+
116
+ /** `target_directory` from `cargo metadata --format-version 1` output. */
117
+ function cargoTargetDirectory(metadata: string): string {
118
+ const parsed: unknown = JSON.parse(metadata);
119
+ const directory =
120
+ typeof parsed === 'object' && parsed !== null && 'target_directory' in parsed ? parsed.target_directory : undefined;
121
+ if (typeof directory !== 'string' || directory.length === 0) {
122
+ throw new Error('cargo metadata named no target_directory');
123
+ }
124
+ return directory;
125
+ }
126
+
127
+ /**
128
+ * The directory under `root` holding `archive`'s extraction, extracting it
129
+ * first if no caller has yet.
89
130
  *
90
131
  * Correctness does not rest on the lock. An extraction lands under the hash of
91
132
  * the bytes it came from by renaming a private staging directory into place,
@@ -96,20 +137,21 @@ export function nextestExtractionPaths(archive: string, key: string): NextestExt
96
137
  * runner of one Nx run from unpacking the same bytes side by side, which is the
97
138
  * cost it exists to remove.
98
139
  *
99
- * Publishing a key removes every other key's extraction of this archive path,
140
+ * Publishing a key removes every other key's extraction under `root`,
100
141
  * including stale locks and staging left by a holder that died. Leftovers of
101
142
  * the CURRENT key are not touched: a holder that took over a stale lock may
102
143
  * still be extracting into one.
103
144
  */
104
145
  export async function ensureNextestArchiveExtracted(
105
146
  archive: string,
147
+ root: string,
106
148
  extract: NextestArchiveExtractor,
107
149
  onEvent: (event: NextestExtractionEvent) => void,
108
150
  timing: NextestExtractionTiming = DEFAULT_TIMING,
109
151
  ): Promise<NextestExtraction> {
110
152
  const started = performance.now();
111
153
  const key = await nextestArchiveKey(archive);
112
- const paths = nextestExtractionPaths(archive, key);
154
+ const paths = nextestExtractionPaths(root, key);
113
155
  if (await isDirectory(paths.directory)) {
114
156
  return { kind: 'reused', key, directory: paths.directory };
115
157
  }