@smoothbricks/nx-plugin 0.4.26 → 0.4.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/README.md +994 -117
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +15 -73
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +3 -2
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +16 -15
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +43 -6
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +309 -73
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +101 -5
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +291 -10
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +207 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +576 -202
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +370 -138
  102. package/dist/managed-files/ci-workflow.d.ts +13 -0
  103. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.js +44 -13
  105. package/dist/managed-files/files.d.ts +7 -1
  106. package/dist/managed-files/files.d.ts.map +1 -1
  107. package/dist/managed-files/files.js +62 -8
  108. package/dist/managed-files/json-edit.d.ts +21 -0
  109. package/dist/managed-files/json-edit.d.ts.map +1 -0
  110. package/dist/managed-files/json-edit.js +295 -0
  111. package/dist/managed-files/managed-format.d.ts +33 -1
  112. package/dist/managed-files/managed-format.d.ts.map +1 -1
  113. package/dist/managed-files/managed-format.js +82 -2
  114. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  115. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  116. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  117. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/publish-workflow.js +231 -48
  119. package/dist/managed-files/tree.d.ts +5 -0
  120. package/dist/managed-files/tree.d.ts.map +1 -1
  121. package/dist/managed-files/tree.js +5 -3
  122. package/dist/manifest-hash.d.ts.map +1 -1
  123. package/dist/manifest-hash.js +2 -5
  124. package/dist/nextest-code-bound.d.ts +62 -0
  125. package/dist/nextest-code-bound.d.ts.map +1 -0
  126. package/dist/nextest-code-bound.js +154 -0
  127. package/dist/nextest-extraction.d.ts +24 -8
  128. package/dist/nextest-extraction.d.ts.map +1 -1
  129. package/dist/nextest-extraction.js +42 -7
  130. package/dist/package-target-policy.d.ts.map +1 -1
  131. package/dist/package-target-policy.js +3 -5
  132. package/dist/release-config-policy.d.ts.map +1 -1
  133. package/dist/release-config-policy.js +3 -5
  134. package/dist/runtime-input.d.ts +14 -0
  135. package/dist/runtime-input.d.ts.map +1 -0
  136. package/dist/runtime-input.js +15 -0
  137. package/dist/rust-tokens.d.ts +11 -0
  138. package/dist/rust-tokens.d.ts.map +1 -0
  139. package/dist/rust-tokens.js +81 -0
  140. package/dist/task-results.d.ts +6 -0
  141. package/dist/task-results.d.ts.map +1 -0
  142. package/dist/task-results.js +61 -0
  143. package/dist/test-program.d.ts +54 -0
  144. package/dist/test-program.d.ts.map +1 -0
  145. package/dist/test-program.js +292 -0
  146. package/dist/test-timings.d.ts +71 -0
  147. package/dist/test-timings.d.ts.map +1 -0
  148. package/dist/test-timings.js +393 -0
  149. package/dist/test-walk-policy.d.ts +103 -0
  150. package/dist/test-walk-policy.d.ts.map +1 -0
  151. package/dist/test-walk-policy.js +657 -0
  152. package/dist/testing.d.ts +177 -0
  153. package/dist/testing.d.ts.map +1 -0
  154. package/dist/testing.js +824 -0
  155. package/dist/type-guards.d.ts +3 -0
  156. package/dist/type-guards.d.ts.map +1 -0
  157. package/dist/type-guards.js +4 -0
  158. package/dist/typecheck-test-policy.d.ts +8 -5
  159. package/dist/typecheck-test-policy.d.ts.map +1 -1
  160. package/dist/typecheck-test-policy.js +113 -100
  161. package/dist/workspace-config-policy.d.ts +8 -0
  162. package/dist/workspace-config-policy.d.ts.map +1 -1
  163. package/dist/workspace-config-policy.js +175 -63
  164. package/dist/workspace-index.d.ts +12 -0
  165. package/dist/workspace-index.d.ts.map +1 -0
  166. package/dist/workspace-index.js +17 -0
  167. package/dist/workspace-manifest.d.ts +37 -0
  168. package/dist/workspace-manifest.d.ts.map +1 -1
  169. package/executors.json +5 -0
  170. package/loader.js +13 -11
  171. package/managed/raw/envrc +33 -67
  172. package/managed/raw/git-format-staged.yml +30 -35
  173. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  174. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  175. package/managed/raw/tooling/direnv/developer-links.ts +569 -11
  176. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
  177. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  178. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  179. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  180. package/managed/raw/tooling/direnv/repo-path +14 -2
  181. package/managed/raw/tooling/direnv/setup-environment.ts +1146 -159
  182. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  183. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  184. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  185. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  186. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  187. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  188. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  189. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  190. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  191. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  192. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  194. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  196. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  197. package/managed/templates/github/workflows/managed-files.yml +1 -2
  198. package/nextest.toml +8 -41
  199. package/package.json +74 -12
  200. package/runtime-input.sh +81 -0
  201. package/src/__tests__/counted-cargo.ts +33 -14
  202. package/src/__tests__/fixture-nx-env.ts +111 -46
  203. package/src/__tests__/progress-clock.ts +43 -0
  204. package/src/__tests__/runtime-input.ts +23 -0
  205. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  206. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  207. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  208. package/src/bin/smoo-nx-exec.ts +16 -74
  209. package/src/bin/smoo-nx-failures.ts +4 -0
  210. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  211. package/src/bin/smoo-nx-test-walks.ts +42 -0
  212. package/src/bounded-test-policy.test.ts +268 -21
  213. package/src/bounded-test-policy.ts +114 -42
  214. package/src/build-state-output-policy.test.ts +115 -0
  215. package/src/build-state-output-policy.ts +90 -0
  216. package/src/bun-bootstrap.test.ts +57 -3
  217. package/src/bun-file-packages.test.ts +47 -0
  218. package/src/cargo-closure-input.test.ts +138 -66
  219. package/src/cargo-closure-input.ts +17 -15
  220. package/src/cargo-dev-profile.ts +137 -0
  221. package/src/cargo-resolve-cache.test.ts +70 -1
  222. package/src/cargo-source-hash.test.ts +193 -97
  223. package/src/cargo-source-hash.ts +345 -68
  224. package/src/cargo-toolchain-policy.ts +6 -0
  225. package/src/cargo-workspace.test.ts +320 -0
  226. package/src/cargo-workspace.ts +336 -10
  227. package/src/cross-check-policy.test.ts +59 -1
  228. package/src/cross-check-policy.ts +25 -6
  229. package/src/disk-command-policy.test.ts +61 -0
  230. package/src/disk-command-policy.ts +107 -0
  231. package/src/ensure-built-receipt.test.ts +184 -0
  232. package/src/ensure-built-receipt.ts +263 -0
  233. package/src/ensure-built-witness.test.ts +344 -0
  234. package/src/ensure-built-witness.ts +252 -0
  235. package/src/ensure-built.test.ts +1036 -578
  236. package/src/ensure-built.ts +820 -224
  237. package/src/eslint-file-set.ts +9 -0
  238. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  239. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  240. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  241. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  242. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  243. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  244. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  245. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  246. package/src/executors/bounded-exec/executor.ts +565 -67
  247. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  248. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  249. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  250. package/src/executors/bounded-exec/progress.test.ts +79 -0
  251. package/src/executors/bounded-exec/progress.ts +118 -0
  252. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  253. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  254. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  255. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  256. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  257. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  258. package/src/executors/bounded-exec/schema.json +11 -5
  259. package/src/executors/bounded-exec/schema.ts +27 -11
  260. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  261. package/src/executors/bounded-exec/verdict.ts +433 -0
  262. package/src/executors/shard-timings/executor.ts +36 -0
  263. package/src/executors/shard-timings/schema.json +21 -0
  264. package/src/executors/shard-timings/schema.ts +4 -0
  265. package/src/failure-summary.ts +119 -0
  266. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  267. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  268. package/src/generators/create-package/generator.test.ts +6 -0
  269. package/src/generators/create-package/generator.ts +6 -2
  270. package/src/host-controller-wiring.test.ts +31 -0
  271. package/src/index.test.ts +909 -295
  272. package/src/index.ts +441 -143
  273. package/src/linked-snapshots.nx.test.ts +172 -0
  274. package/src/managed-files/ci-workflow.ts +54 -13
  275. package/src/managed-files/files.ts +65 -9
  276. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  277. package/src/managed-files/generator.test.ts +60 -1
  278. package/src/managed-files/json-edit.test.ts +216 -0
  279. package/src/managed-files/json-edit.ts +290 -0
  280. package/src/managed-files/managed-format-json.test.ts +308 -0
  281. package/src/managed-files/managed-format.ts +90 -2
  282. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  283. package/src/managed-files/publish-workflow.ts +285 -67
  284. package/src/managed-files/repo-path.test.ts +129 -0
  285. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  286. package/src/managed-files/tree.ts +11 -3
  287. package/src/manifest-hash.ts +2 -6
  288. package/src/nextest-code-bound.test.ts +155 -0
  289. package/src/nextest-code-bound.ts +195 -0
  290. package/src/nextest-extraction.test.ts +37 -5
  291. package/src/nextest-extraction.ts +51 -9
  292. package/src/nextest-partitions.test.ts +427 -82
  293. package/src/nx-cache-bound.test.ts +5 -10
  294. package/src/nx-cache-restore-mtime.test.ts +170 -0
  295. package/src/nx-daemon-claim.test.ts +277 -0
  296. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  297. package/src/nx-daemon-idle-policy.test.ts +51 -0
  298. package/src/nx-daemon-ignore-files.test.ts +210 -0
  299. package/src/nx-daemon-root-normalization.test.ts +105 -0
  300. package/src/nx-daemon-validity.test.ts +925 -0
  301. package/src/nx-dot-input-policy.test.ts +353 -0
  302. package/src/nx-failure-life-cycles.test.ts +207 -0
  303. package/src/nx-files-archive-racy.test.ts +97 -0
  304. package/src/nx-foreign-workspace-env.test.ts +329 -0
  305. package/src/nx-incomplete-run-summary.test.ts +70 -0
  306. package/src/nx-plugin-load-errors.test.ts +120 -0
  307. package/src/nx-project-resolution-cache.test.ts +176 -0
  308. package/src/nx-raw-inputs.test.ts +166 -0
  309. package/src/nx-resident-graph-workers.test.ts +7 -16
  310. package/src/nx-run-information.test.ts +118 -0
  311. package/src/nx-skipped-task-exit.test.ts +180 -0
  312. package/src/nx-state-location.test.ts +63 -0
  313. package/src/nx-store-resolution.test.ts +26 -25
  314. package/src/nx-task-graph-cycles.test.ts +148 -0
  315. package/src/nx-task-output-lease.test.ts +414 -0
  316. package/src/nx-use-local.test.ts +103 -0
  317. package/src/package-target-policy.ts +3 -6
  318. package/src/release-config-policy.ts +3 -6
  319. package/src/runtime-input.test.ts +215 -0
  320. package/src/runtime-input.ts +17 -0
  321. package/src/rust-tokens.ts +78 -0
  322. package/src/serial-group-wiring.test.ts +326 -0
  323. package/src/task-history-namespace.test.ts +87 -89
  324. package/src/task-results.test.ts +226 -0
  325. package/src/task-results.ts +75 -0
  326. package/src/test-program.test.ts +303 -0
  327. package/src/test-program.ts +341 -0
  328. package/src/test-timings.test.ts +240 -0
  329. package/src/test-timings.ts +311 -0
  330. package/src/test-walk-policy.test.ts +585 -0
  331. package/src/test-walk-policy.ts +731 -0
  332. package/src/testing.test.ts +509 -0
  333. package/src/testing.ts +922 -0
  334. package/src/type-guards.ts +4 -0
  335. package/src/typecheck-test-policy.test.ts +496 -11
  336. package/src/typecheck-test-policy.ts +137 -103
  337. package/src/workspace-config-policy.test.ts +212 -13
  338. package/src/workspace-config-policy.ts +101 -73
  339. package/src/workspace-index.ts +18 -0
  340. package/src/workspace-manifest.ts +41 -0
  341. package/test-timings.json +85 -30
  342. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
  343. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
@@ -0,0 +1,154 @@
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
+ * A nextest run-wrapper that measures a test's code time rather than its wall time against its class
10
+ * (specs/cowshed/08_testing.md, "Integration tests (real substrate)").
11
+ *
12
+ * A real-APFS test spends part of its wall time queued for the host disk-lifecycle lease, behind
13
+ * every other cowshed process on the host (05_gateway.md, "Disk-lifecycle lease"). That queue is
14
+ * the host's, not the test's code. The wrapper names a fresh lease-wait record in
15
+ * `COWSHED_LEASE_WAIT_RECORD`, runs the test binary, which every disk-lease client of the test's
16
+ * process tree appends its waits to, and then measures the test's code time, its wall time less the
17
+ * union of those waits, against the class it was configured with. It says the split on stderr after
18
+ * the test body, and warns when the code time is over the class; the test keeps its own exit status.
19
+ * A class is a slow warning, never a kill or a failure: the run's no-progress bound ends a hang.
20
+ *
21
+ * Usage, as nextest invokes it: `nextest-code-bound.ts <class-seconds> <test-binary> [args…]`.
22
+ */
23
+ /** The variable naming the record; the same name every disk-lease client reads. */
24
+ export const LEASE_WAIT_RECORD_ENV = 'COWSHED_LEASE_WAIT_RECORD';
25
+ const INTEGER = /^\d+$/;
26
+ /** Reads a record as its clients write it. Any line that is not one of the two shapes is refused. */
27
+ export function parseWaitRecord(text) {
28
+ const edges = [];
29
+ for (const line of text.split('\n')) {
30
+ if (line === '') {
31
+ continue;
32
+ }
33
+ const fields = line.split(' ');
34
+ const [kind, pid, seq, atUs] = fields;
35
+ const numeric = [pid, seq, atUs].every((field) => field !== undefined && INTEGER.test(field));
36
+ if (kind === 'start' && fields.length === 5 && numeric) {
37
+ edges.push({ kind, pid: Number(pid), seq: Number(seq), atUs: Number(atUs), diskClass: fields[4] });
38
+ }
39
+ else if (kind === 'end' && fields.length === 4 && numeric) {
40
+ edges.push({ kind, pid: Number(pid), seq: Number(seq), atUs: Number(atUs) });
41
+ }
42
+ else {
43
+ return { ok: false, error: `line ${JSON.stringify(line)} is neither a wait's start nor its end` };
44
+ }
45
+ }
46
+ return { ok: true, edges };
47
+ }
48
+ /** The test's code time: its wall time from `startedUs` to `endedUs` less the union of its waits. */
49
+ export function codeTime(edges, startedUs, endedUs) {
50
+ const starts = new Map();
51
+ const intervals = [];
52
+ let strayEnds = 0;
53
+ for (const edge of edges) {
54
+ const key = `${edge.pid}:${edge.seq}`;
55
+ if (edge.kind === 'start') {
56
+ starts.set(key, { atUs: edge.atUs, pid: edge.pid, seq: edge.seq });
57
+ continue;
58
+ }
59
+ const start = starts.get(key);
60
+ if (start === undefined) {
61
+ strayEnds += 1;
62
+ continue;
63
+ }
64
+ starts.delete(key);
65
+ intervals.push([start.atUs, edge.atUs]);
66
+ }
67
+ const open = [...starts.values()].map(({ pid, seq, atUs }) => ({ pid, seq, startedUs: atUs }));
68
+ for (const wait of open) {
69
+ intervals.push([wait.startedUs, endedUs]);
70
+ }
71
+ const waits = intervals.length;
72
+ const clipped = intervals
73
+ .map(([from, to]) => [Math.max(from, startedUs), Math.min(to, endedUs)])
74
+ .filter(([from, to]) => to > from)
75
+ .sort((left, right) => left[0] - right[0]);
76
+ let waitUs = 0;
77
+ let reach = startedUs;
78
+ for (const [from, to] of clipped) {
79
+ const begin = Math.max(from, reach);
80
+ if (to > begin) {
81
+ waitUs += to - begin;
82
+ reach = to;
83
+ }
84
+ }
85
+ const wallUs = Math.max(0, endedUs - startedUs);
86
+ return { wallUs, waitUs, codeUs: wallUs - waitUs, waits, open, strayEnds };
87
+ }
88
+ const seconds = (us) => `${(us / 1_000_000).toFixed(1)}s`;
89
+ /** The one line the wrapper prints after the test body. */
90
+ export function describeCodeTime(time, classUs) {
91
+ const verdict = time.codeUs > classUs ? 'OVER its class (a warning)' : 'within its class';
92
+ const parts = [
93
+ `nextest-code-bound: code ${seconds(time.codeUs)} of ${seconds(classUs)}, ${verdict}`,
94
+ `(wall ${seconds(time.wallUs)} less ${seconds(time.waitUs)} waiting for the host disk lease over ${time.waits} waits)`,
95
+ ];
96
+ for (const wait of time.open) {
97
+ parts.push(`; pid ${wait.pid}'s wait ${wait.seq} never ended and counts to the test's end`);
98
+ }
99
+ if (time.strayEnds > 0) {
100
+ parts.push(`; ${time.strayEnds} wait ends had no recorded start and count as code time`);
101
+ }
102
+ return parts.join(' ');
103
+ }
104
+ const CLASS_PATTERN = /^\d+(\.\d+)?$/;
105
+ /** The signals the wrapper passes on to the test rather than dying of. */
106
+ const FORWARDED = ['SIGTERM', 'SIGINT', 'SIGHUP'];
107
+ /** Runs the test under the record, reports its code time, and exits as the test did. */
108
+ async function main(argv) {
109
+ const [codeClass, binary, ...args] = argv;
110
+ if (codeClass === undefined || !CLASS_PATTERN.test(codeClass) || Number(codeClass) <= 0 || binary === undefined) {
111
+ process.stderr.write('nextest-code-bound: usage: nextest-code-bound.ts <class-seconds> <test-binary> [args…]\n');
112
+ process.exit(2);
113
+ }
114
+ const classUs = Number(codeClass) * 1_000_000;
115
+ const record = join(tmpdir(), `cowshed-lease-waits-${process.pid}-${randomUUID()}`);
116
+ writeFileSync(record, '', { mode: 0o600, flag: 'wx' });
117
+ const startedUs = Math.round((performance.timeOrigin + performance.now()) * 1000);
118
+ const child = spawn(binary, args, { stdio: 'inherit', env: { ...process.env, [LEASE_WAIT_RECORD_ENV]: record } });
119
+ // nextest stops a test by signalling its process group, which the child is in; the wrapper stays
120
+ // to report what the stopped test spent, and passes on a signal sent to it alone.
121
+ const handlers = FORWARDED.map((signal) => {
122
+ const handler = () => {
123
+ child.kill(signal);
124
+ };
125
+ process.on(signal, handler);
126
+ return { signal, handler };
127
+ });
128
+ const exit = await new Promise((settle) => {
129
+ child.once('error', (error) => {
130
+ process.stderr.write(`nextest-code-bound: could not start ${binary}: ${error.message}\n`);
131
+ settle({ code: 1, signal: null });
132
+ });
133
+ child.once('exit', (code, signal) => settle({ code, signal }));
134
+ });
135
+ const endedUs = Math.round((performance.timeOrigin + performance.now()) * 1000);
136
+ for (const { signal, handler } of handlers) {
137
+ process.removeListener(signal, handler);
138
+ }
139
+ const parsed = parseWaitRecord(readFileSync(record, 'utf8'));
140
+ rmSync(record, { force: true });
141
+ if (!parsed.ok) {
142
+ process.stderr.write(`nextest-code-bound: the lease-wait record ${record} is unreadable: ${parsed.error}\n`);
143
+ process.exit(exit.code === 0 ? 1 : (exit.code ?? 1));
144
+ }
145
+ const time = codeTime(parsed.edges, startedUs, endedUs);
146
+ process.stderr.write(`${describeCodeTime(time, classUs)}\n`);
147
+ if (exit.signal !== null) {
148
+ process.kill(process.pid, exit.signal);
149
+ }
150
+ process.exit(exit.code ?? 1);
151
+ }
152
+ if (process.argv[1] !== undefined && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
153
+ await main(process.argv.slice(2));
154
+ }
@@ -56,9 +56,18 @@ export interface NextestExtractionTiming {
56
56
  /** The SHA-256 of the archive's bytes: the only identity an extraction is ever looked up by. */
57
57
  export declare function nextestArchiveKey(archive: string): Promise<string>;
58
58
  /**
59
- * One archive path's extractions live beside it, each under the hash of the
60
- * bytes it came from; the lock and staging directories of a key carry that
61
- * key as their prefix, so cleanup can tell them from another key's.
59
+ * The directory, inside the Cargo target directory, that holds a workspace's
60
+ * archive extractions. An extraction is content-keyed per-checkout tool state
61
+ * of the same kind as the rest of the target directory: rebuilt from an Nx
62
+ * output, reused by the next run, never an Nx output itself. It therefore lives
63
+ * wherever Cargo's build tree lives, which a checkout that keeps its build state
64
+ * on its own volume already keeps off its source tree.
65
+ */
66
+ export declare const NEXTEST_EXTRACTION_DIRECTORY = "nextest-extracted";
67
+ /**
68
+ * A workspace's extractions live under one root, each under the hash of the
69
+ * bytes it came from; the lock and staging directories of a key carry that key
70
+ * as their prefix, so cleanup can tell them from another key's.
62
71
  */
63
72
  export interface NextestExtractionPaths {
64
73
  root: string;
@@ -66,10 +75,17 @@ export interface NextestExtractionPaths {
66
75
  lock: string;
67
76
  stagingPrefix: string;
68
77
  }
69
- export declare function nextestExtractionPaths(archive: string, key: string): NextestExtractionPaths;
78
+ export declare function nextestExtractionPaths(root: string, key: string): NextestExtractionPaths;
79
+ /**
80
+ * The extraction root of the Cargo workspace in `cwd`:
81
+ * `<target_directory>/nextest-extracted`, with the target directory Cargo itself
82
+ * reports, so a `build.target-dir` in the repository's Cargo config is honoured
83
+ * exactly as every build of the workspace honours it.
84
+ */
85
+ export declare function nextestExtractionRoot(cwd: string): Promise<string>;
70
86
  /**
71
- * The directory holding `archive`'s extraction, extracting it first if no
72
- * caller has yet.
87
+ * The directory under `root` holding `archive`'s extraction, extracting it
88
+ * first if no caller has yet.
73
89
  *
74
90
  * Correctness does not rest on the lock. An extraction lands under the hash of
75
91
  * the bytes it came from by renaming a private staging directory into place,
@@ -80,12 +96,12 @@ export declare function nextestExtractionPaths(archive: string, key: string): Ne
80
96
  * runner of one Nx run from unpacking the same bytes side by side, which is the
81
97
  * cost it exists to remove.
82
98
  *
83
- * Publishing a key removes every other key's extraction of this archive path,
99
+ * Publishing a key removes every other key's extraction under `root`,
84
100
  * including stale locks and staging left by a holder that died. Leftovers of
85
101
  * the CURRENT key are not touched: a holder that took over a stale lock may
86
102
  * still be extracting into one.
87
103
  */
88
- export declare function ensureNextestArchiveExtracted(archive: string, extract: NextestArchiveExtractor, onEvent: (event: NextestExtractionEvent) => void, timing?: NextestExtractionTiming): Promise<NextestExtraction>;
104
+ export declare function ensureNextestArchiveExtracted(archive: string, root: string, extract: NextestArchiveExtractor, onEvent: (event: NextestExtractionEvent) => void, timing?: NextestExtractionTiming): Promise<NextestExtraction>;
89
105
  /**
90
106
  * nextest's own extractor: `nextest list --list-type binaries-only` unpacks the
91
107
  * archive and executes nothing from it.
@@ -1 +1 @@
1
- {"version":3,"file":"nextest-extraction.d.ts","sourceRoot":"","sources":["../src/nextest-extraction.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,6EAA6E,CAAC;AAE9G;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAC7C,eAAO,MAAM,2BAA2B,0CAA0C,CAAC;AACnF,eAAO,MAAM,wBAAwB,uCAAuC,CAAC;AAE7E,0EAA0E;AAC1E,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9F,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACxE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,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AS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,sBAAsB,CAOxF;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAaxE;AAaD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,EAChD,MAAM,GAAE,uBAAwC,GAC/C,OAAO,CAAC,iBAAiB,CAAC,CAiD5B;AA4GD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,EAAE,uBAiChC,CAAC"}
@@ -31,8 +31,16 @@ export async function nextestArchiveKey(archive) {
31
31
  }
32
32
  return hash.digest('hex');
33
33
  }
34
- export function nextestExtractionPaths(archive, key) {
35
- const root = `${archive}.extracted`;
34
+ /**
35
+ * The directory, inside the Cargo target directory, that holds a workspace's
36
+ * archive extractions. An extraction is content-keyed per-checkout tool state
37
+ * of the same kind as the rest of the target directory: rebuilt from an Nx
38
+ * output, reused by the next run, never an Nx output itself. It therefore lives
39
+ * wherever Cargo's build tree lives, which a checkout that keeps its build state
40
+ * on its own volume already keeps off its source tree.
41
+ */
42
+ export const NEXTEST_EXTRACTION_DIRECTORY = 'nextest-extracted';
43
+ export function nextestExtractionPaths(root, key) {
36
44
  return {
37
45
  root,
38
46
  directory: join(root, key),
@@ -41,8 +49,35 @@ export function nextestExtractionPaths(archive, key) {
41
49
  };
42
50
  }
43
51
  /**
44
- * The directory holding `archive`'s extraction, extracting it first if no
45
- * caller has yet.
52
+ * The extraction root of the Cargo workspace in `cwd`:
53
+ * `<target_directory>/nextest-extracted`, with the target directory Cargo itself
54
+ * reports, so a `build.target-dir` in the repository's Cargo config is honoured
55
+ * exactly as every build of the workspace honours it.
56
+ */
57
+ export async function nextestExtractionRoot(cwd) {
58
+ const args = ['--frozen', 'metadata', '--no-deps', '--format-version', '1'];
59
+ const child = spawn('cargo', args, { cwd, stdio: ['ignore', 'pipe', 'inherit'] });
60
+ const chunks = [];
61
+ child.stdout.on('data', (chunk) => chunks.push(chunk));
62
+ // 'close', not 'exit': stdout may still hold unread metadata when the process exits.
63
+ const [code, signal] = await once(child, 'close');
64
+ if (code !== 0) {
65
+ throw new Error(`cargo ${args.join(' ')} ${code === null ? `died of ${String(signal)}` : `exited with status ${String(code)}`}`);
66
+ }
67
+ return join(cargoTargetDirectory(Buffer.concat(chunks).toString('utf8')), NEXTEST_EXTRACTION_DIRECTORY);
68
+ }
69
+ /** `target_directory` from `cargo metadata --format-version 1` output. */
70
+ function cargoTargetDirectory(metadata) {
71
+ const parsed = JSON.parse(metadata);
72
+ const directory = typeof parsed === 'object' && parsed !== null && 'target_directory' in parsed ? parsed.target_directory : undefined;
73
+ if (typeof directory !== 'string' || directory.length === 0) {
74
+ throw new Error('cargo metadata named no target_directory');
75
+ }
76
+ return directory;
77
+ }
78
+ /**
79
+ * The directory under `root` holding `archive`'s extraction, extracting it
80
+ * first if no caller has yet.
46
81
  *
47
82
  * Correctness does not rest on the lock. An extraction lands under the hash of
48
83
  * the bytes it came from by renaming a private staging directory into place,
@@ -53,15 +88,15 @@ export function nextestExtractionPaths(archive, key) {
53
88
  * runner of one Nx run from unpacking the same bytes side by side, which is the
54
89
  * cost it exists to remove.
55
90
  *
56
- * Publishing a key removes every other key's extraction of this archive path,
91
+ * Publishing a key removes every other key's extraction under `root`,
57
92
  * including stale locks and staging left by a holder that died. Leftovers of
58
93
  * the CURRENT key are not touched: a holder that took over a stale lock may
59
94
  * still be extracting into one.
60
95
  */
61
- export async function ensureNextestArchiveExtracted(archive, extract, onEvent, timing = DEFAULT_TIMING) {
96
+ export async function ensureNextestArchiveExtracted(archive, root, extract, onEvent, timing = DEFAULT_TIMING) {
62
97
  const started = performance.now();
63
98
  const key = await nextestArchiveKey(archive);
64
- const paths = nextestExtractionPaths(archive, key);
99
+ const paths = nextestExtractionPaths(root, key);
65
100
  if (await isDirectory(paths.directory)) {
66
101
  return { kind: 'reused', key, directory: paths.directory };
67
102
  }
@@ -1 +1 @@
1
- {"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,IAAI,EAAc,MAAM,0BAA0B,CAAC;AAIxF,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,kBAAkB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACvE,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AA0HD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,C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D,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACrC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACjC,aAAa,EAAE,CAEjB;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,EACnC,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAAC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAO,GAC1F,OAAO,CAMT;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAoBhH;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8BxG"}
@@ -1,7 +1,8 @@
1
- import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
1
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { getProjects, readJson, updateJson } from 'nx/src/devkit-exports.js';
4
4
  import { boundedTestScriptAlias } from './bounded-test-policy.js';
5
+ import { writeJsonFile } from './managed-files/managed-format.js';
5
6
  import { isNonSourceDirectory } from './source-directories.js';
6
7
  import { BUILD_OUTPUT_DEPENDENCIES, isBuildOutputTargetName, isTestRunnerTargetName, LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, } from './workspace-config-policy.js';
7
8
  export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
@@ -51,9 +52,6 @@ function readJsonObject(path) {
51
52
  const parsed = JSON.parse(readFileSync(path, 'utf8'));
52
53
  return isRecord(parsed) ? parsed : null;
53
54
  }
54
- function writeJsonObject(path, value) {
55
- writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
56
- }
57
55
  function listWorkspacePackageJsonPaths(root) {
58
56
  const rootPackagePath = join(root, 'package.json');
59
57
  if (!existsSync(rootPackagePath)) {
@@ -1048,7 +1046,7 @@ export function applyPackageTargetPolicy(root, options = {}) {
1048
1046
  applyPackageScriptPolicyForPkg(pkg, packagePath, workspaceNames, { resolvedTargets: resolvedProject }) ||
1049
1047
  packageChanged;
1050
1048
  if (packageChanged) {
1051
- writeJsonObject(packageJsonPath, pkg);
1049
+ writeJsonFile(packageJsonPath, pkg);
1052
1050
  changed = true;
1053
1051
  }
1054
1052
  }
@@ -1 +1 @@
1
- {"version":3,"file":"release-config-policy.d.ts","sourceRoot":"","sources":["../src/release-config-policy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,eAAO,MAAM,uBAAuB,4CAA4C,CAAC;AACjF;;;;;;GAMG;AACH,eAAO,MAAM,sCAAsC,QAAgC,CAAC;AACpF,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAoBrE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CAuFnF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAyC3E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKlE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU1D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYtE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAW9D"}
1
+ {"version":3,"file":"release-config-policy.d.ts","sourceRoot":"","sources":["../src/release-config-policy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAIrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,eAAO,MAAM,uBAAuB,4CAA4C,CAAC;AACjF;;;;;;GAMG;AACH,eAAO,MAAM,sCAAsC,QAAgC,CAAC;AACpF,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAoBrE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CAuFnF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAyC3E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKlE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU1D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYtE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAW9D"}
@@ -1,7 +1,8 @@
1
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { readJson, updateJson } from 'nx/src/devkit-exports.js';
5
+ import { writeJsonFile } from './managed-files/managed-format.js';
5
6
  export const SMOO_NX_VERSION_ACTIONS = '@smoothbricks/nx-plugin/version-actions';
6
7
  /**
7
8
  * The same module as a workspace path. Nx resolves `versionActions` with
@@ -201,7 +202,7 @@ export function applyReleaseConfigPolicy(root) {
201
202
  }
202
203
  const changed = applyReleaseConfig(nxJson);
203
204
  if (changed) {
204
- writeJsonObject(nxJsonPath, nxJson);
205
+ writeJsonFile(nxJsonPath, nxJson);
205
206
  }
206
207
  return changed;
207
208
  }
@@ -217,9 +218,6 @@ function readJsonObject(path) {
217
218
  return null;
218
219
  }
219
220
  }
220
- function writeJsonObject(path, value) {
221
- writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
222
- }
223
221
  function isRecord(value) {
224
222
  return value !== null && typeof value === 'object' && !Array.isArray(value);
225
223
  }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The one script every Nx runtime input runs through, named as the workspace
3
+ * root's `node_modules` links this package: Nx runs runtime inputs from the
4
+ * workspace root. `runtime-input.sh` explains why it exists: Nx hashes a failed
5
+ * input's error text as its value.
6
+ */
7
+ export declare const RUNTIME_INPUT_SCRIPT = "node_modules/@smoothbricks/nx-plugin/runtime-input.sh";
8
+ /** A runtime input whose failure stops Nx. `command` is shell words, already quoted. */
9
+ export declare function runtimeInput(command: string): {
10
+ runtime: string;
11
+ };
12
+ /** One shell word: bare when nothing in it is special to `sh`, single-quoted otherwise. */
13
+ export declare function shellWord(word: string): string;
14
+ //# sourceMappingURL=runtime-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-input.d.ts","sourceRoot":"","sources":["../src/runtime-input.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,0DAA0D,CAAC;AAE5F,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAEjE;AAED,2FAA2F;AAC3F,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The one script every Nx runtime input runs through, named as the workspace
3
+ * root's `node_modules` links this package: Nx runs runtime inputs from the
4
+ * workspace root. `runtime-input.sh` explains why it exists: Nx hashes a failed
5
+ * input's error text as its value.
6
+ */
7
+ export const RUNTIME_INPUT_SCRIPT = 'node_modules/@smoothbricks/nx-plugin/runtime-input.sh';
8
+ /** A runtime input whose failure stops Nx. `command` is shell words, already quoted. */
9
+ export function runtimeInput(command) {
10
+ return { runtime: `sh ${RUNTIME_INPUT_SCRIPT} ${command}` };
11
+ }
12
+ /** One shell word: bare when nothing in it is special to `sh`, single-quoted otherwise. */
13
+ export function shellWord(word) {
14
+ return /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", `'"'"'`)}'`;
15
+ }
@@ -0,0 +1,11 @@
1
+ /** Tokens shared by Rust input inference and statement comparison. */
2
+ export interface RustToken {
3
+ readonly text: string;
4
+ readonly literal: boolean;
5
+ readonly local: boolean;
6
+ readonly kind: 'ident' | 'literal' | 'punct' | 'lifetime';
7
+ readonly offset: number;
8
+ }
9
+ /** A Rust lexer that keeps exactly what statement comparison needs: idents, literals, lifetimes, punctuation. */
10
+ export declare function rustTokens(text: string): RustToken[];
11
+ //# sourceMappingURL=rust-tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rust-tokens.d.ts","sourceRoot":"","sources":["../src/rust-tokens.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAUD,iHAAiH;AACjH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,CA2DpD"}
@@ -0,0 +1,81 @@
1
+ const RUST_IDENT = /[A-Za-z_][A-Za-z0-9_]*/uy;
2
+ const RUST_NUMBER = /(?:0[xob][0-9A-Fa-f_]+|[0-9][0-9_]*(?:\.[0-9][0-9_]*)?(?:[eE][+-]?[0-9_]+)?)(?:[iuf](?:8|16|32|64|128|size))?/uy;
3
+ const RUST_RAW_STRING = /b?r(#*)"/uy;
4
+ const RUST_CHAR = /b?'(?:\\(?:u\{[0-9A-Fa-f]+\}|x[0-9A-Fa-f]{2}|.)|[^\\'\n])'/uy;
5
+ /** Longest first: `..` is one token, so a range end (`0..5`) is never read as a tuple index after `.`. */
6
+ const RUST_PUNCT = ['..=', '::', '->', '=>', '==', '!=', '<=', '>=', '&&', '||', '..'];
7
+ /** A Rust lexer that keeps exactly what statement comparison needs: idents, literals, lifetimes, punctuation. */
8
+ export function rustTokens(text) {
9
+ const tokens = [];
10
+ let index = 0;
11
+ const at = (pattern) => {
12
+ pattern.lastIndex = index;
13
+ return pattern.exec(text)?.[0];
14
+ };
15
+ const push = (kind, start) => {
16
+ tokens.push({ text: text.slice(start, index), literal: kind === 'literal', local: false, kind, offset: start });
17
+ };
18
+ while (index < text.length) {
19
+ const char = text[index] ?? '';
20
+ const start = index;
21
+ if (/\s/u.test(char))
22
+ index += 1;
23
+ else if (text.startsWith('//', index)) {
24
+ const end = text.indexOf('\n', index);
25
+ index = end === -1 ? text.length : end;
26
+ }
27
+ else if (text.startsWith('/*', index)) {
28
+ let depth = 0;
29
+ do {
30
+ if (text.startsWith('/*', index))
31
+ depth += 1;
32
+ else if (text.startsWith('*/', index))
33
+ depth -= 1;
34
+ index += text.startsWith('/*', index) || text.startsWith('*/', index) ? 2 : 1;
35
+ } while (depth > 0 && index < text.length);
36
+ }
37
+ else if (at(RUST_RAW_STRING) !== undefined) {
38
+ const raw = at(RUST_RAW_STRING) ?? '';
39
+ const close = `"${raw.slice(raw.indexOf('r') + 1, -1)}`;
40
+ const end = text.indexOf(close, index + raw.length);
41
+ index = end === -1 ? text.length : end + close.length;
42
+ push('literal', start);
43
+ }
44
+ else if (char === '"' || (char === 'b' && text[index + 1] === '"')) {
45
+ index += char === 'b' ? 2 : 1;
46
+ while (index < text.length && text[index] !== '"')
47
+ index += text[index] === '\\' ? 2 : 1;
48
+ index += 1;
49
+ push('literal', start);
50
+ }
51
+ else if (at(RUST_CHAR) !== undefined) {
52
+ index += at(RUST_CHAR)?.length ?? 0;
53
+ push('literal', start);
54
+ }
55
+ else if (char === "'") {
56
+ index += 1;
57
+ index += at(RUST_IDENT)?.length ?? 0;
58
+ push('lifetime', start);
59
+ }
60
+ else if (at(RUST_IDENT) !== undefined) {
61
+ const ident = at(RUST_IDENT) ?? '';
62
+ index += ident.length;
63
+ push(ident === 'true' || ident === 'false' ? 'literal' : 'ident', start);
64
+ }
65
+ else if (tokens.at(-1)?.text === '.' && /[0-9]/u.test(char)) {
66
+ // A tuple index (`pair.0.1`) names a field; lexed as a number it would read `0.1` as one float literal.
67
+ while (/[0-9]/u.test(text[index] ?? ''))
68
+ index += 1;
69
+ push('ident', start);
70
+ }
71
+ else if ((at(RUST_NUMBER) ?? '') !== '') {
72
+ index += at(RUST_NUMBER)?.length ?? 0;
73
+ push('literal', start);
74
+ }
75
+ else {
76
+ index += RUST_PUNCT.find((punct) => text.startsWith(punct, index))?.length ?? 1;
77
+ push('punct', start);
78
+ }
79
+ }
80
+ return tokens;
81
+ }
@@ -0,0 +1,6 @@
1
+ import type { PostTasksExecutionContext, PreTasksExecutionContext } from 'nx/src/project-graph/plugins/public-api.js';
2
+ /** A controller-selected hint namespace, not publication authority or a backend credential. */
3
+ export declare const NX_TASK_RECEIPT_ENV = "COWSHED_NX_TASK_RECEIPT_ID";
4
+ export declare function preTasksExecution(_options: unknown, _context: PreTasksExecutionContext): void;
5
+ export declare function postTasksExecution(_options: unknown, context: PostTasksExecutionContext): Promise<void>;
6
+ //# sourceMappingURL=task-results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-results.d.ts","sourceRoot":"","sources":["../src/task-results.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAItH,+FAA+F;AAC/F,eAAO,MAAM,mBAAmB,+BAA+B,CAAC;AAsBhE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,wBAAwB,GAAG,IAAI,CAO7F;AAqBD,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAe7G"}
@@ -0,0 +1,61 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdir, rename, writeFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { cacheDir, logger } from 'nx/src/devkit-exports.js';
5
+ import typia from 'typia';
6
+ /** A controller-selected hint namespace, not publication authority or a backend credential. */
7
+ export const NX_TASK_RECEIPT_ENV = 'COWSHED_NX_TASK_RECEIPT_ID';
8
+ const isRequestId = (() => {
9
+ return input => "string" === typeof input && RegExp("^[0-9a-f]{32}$").test(input);
10
+ })();
11
+ const WRITTEN = { ok: true };
12
+ function requestId() {
13
+ const value = process.env[NX_TASK_RECEIPT_ENV];
14
+ return isRequestId(value) ? value : undefined;
15
+ }
16
+ export function preTasksExecution(_options, _context) {
17
+ const requested = process.env[NX_TASK_RECEIPT_ENV];
18
+ if (requested !== undefined && !isRequestId(requested)) {
19
+ logger.warn(`${NX_TASK_RECEIPT_ENV} is not a controller-selected 32-hex request id; no task hint will be recorded.`);
20
+ }
21
+ }
22
+ async function writeHint(hint) {
23
+ const directory = join(cacheDir, '.cowshed-task-results', hint.requestId);
24
+ const invocation = createHash('sha256').update(hint.run.id).digest('hex');
25
+ const destination = join(directory, `${invocation}.json`);
26
+ const temporary = join(directory, `.${invocation}-${process.pid}.tmp`);
27
+ const json = JSON.stringify(hint);
28
+ if (Buffer.byteLength(json) > 1024 * 1024) {
29
+ return { ok: false, path: destination, reason: 'task-results hint exceeds the 1 MiB inspection envelope' };
30
+ }
31
+ try {
32
+ await mkdir(directory, { recursive: true, mode: 0o700 });
33
+ await writeFile(temporary, json, { mode: 0o600, flag: 'wx' });
34
+ await rename(temporary, destination);
35
+ return WRITTEN;
36
+ }
37
+ catch (cause) {
38
+ // A leftover temporary makes the private inspector refuse the whole namespace; it can
39
+ // never be mistaken for a successful hint. The workspace's own retirement owns the bytes.
40
+ return { ok: false, path: destination, reason: String(cause) };
41
+ }
42
+ }
43
+ export async function postTasksExecution(_options, context) {
44
+ const id = requestId();
45
+ if (id === undefined)
46
+ return;
47
+ const results = Object.values(context.taskResults);
48
+ // Hash-only API inspections pair the hooks too but ran no task; never overwrite real hints.
49
+ if (results.length === 0)
50
+ return;
51
+ const hint = {
52
+ version: 1,
53
+ requestId: id,
54
+ workspaceRoot: context.workspaceRoot,
55
+ run: { id: context.id, argv: context.argv, startTime: context.startTime, endTime: context.endTime },
56
+ tasks: results.map(({ task, status, code }) => ({ task: { id: task.id, hash: task.hash }, status, code })),
57
+ };
58
+ const written = await writeHint(hint);
59
+ if (!written.ok)
60
+ logger.warn(`Cannot record Nx task-results hint ${written.path}: ${written.reason}`);
61
+ }
@@ -0,0 +1,54 @@
1
+ import type { Tree } from 'nx/src/devkit-exports.js';
2
+ /**
3
+ * Everything the test typecheck needs to know about one project's files.
4
+ *
5
+ * `tsconfig.test.json` is a program, and a program that selects none of the
6
+ * project's tests passes `tsc --noEmit` by compiling nothing: the gate is green
7
+ * while no test has ever been typechecked. So its `include` has to come from
8
+ * where the tests are, and one that selects none of them has to be reported
9
+ * rather than trusted.
10
+ */
11
+ export interface TestProgram {
12
+ /** Workspace-relative root of the project: `tooling`, `packages/app`. */
13
+ readonly projectRoot: string;
14
+ /** Project-relative TypeScript sources under the project, outside any build-output tree. */
15
+ readonly files: readonly string[];
16
+ /** A tsconfig by workspace-relative path; null when the file is absent. */
17
+ readonly readConfig: (path: string) => Record<string, unknown> | null;
18
+ }
19
+ /** A directory listing the walker can use: an Nx `Tree`, or the disk behind a small adapter. */
20
+ export type ProjectTree = Pick<Tree, 'children' | 'isFile'>;
21
+ /** Why a test program typechecks none of what it exists to typecheck. */
22
+ export type TestProgramFault = {
23
+ readonly kind: 'no-tests';
24
+ } | {
25
+ readonly kind: 'tests-unselected';
26
+ readonly tests: readonly string[];
27
+ };
28
+ /**
29
+ * The TypeScript sources of a project, project-relative and sorted.
30
+ *
31
+ * A directory below the project that is a project of its own (its own manifest or Nx project file) is not part of
32
+ * this one: its files are its own tests, found by its own policy pass, and folding them in would count them twice.
33
+ * A directory that merely carries a tsconfig is not that: in a monorepo of Bun programs such a file routes the
34
+ * directory's files to the parent's program (a `tests/tsconfig.json` extending `../tsconfig.test.json`), and
35
+ * nothing typechecks the directory but that program.
36
+ */
37
+ export declare function listTypeScriptSources(tree: ProjectTree, projectRoot: string): string[];
38
+ /**
39
+ * The globs a test program's `include` must carry, given the `include` it has.
40
+ *
41
+ * A new file, or a package on the `src/` convention, gets the canonical globs
42
+ * (merging them is a no-op when they are there). A project off the convention
43
+ * that wrote an `include` of its own gets a directory's globs only for the
44
+ * directories whose tests that `include` does not already select, so a
45
+ * hand-written include that already names `direnv`'s tests is never followed by four redundant entries.
46
+ */
47
+ export declare function includeGlobsFor(program: TestProgram, config: Record<string, unknown>, isNew: boolean): string[];
48
+ /**
49
+ * How, if at all, this program typechecks none of what it exists to typecheck:
50
+ * none of the project's tests, or, for a project with no tests at all, no file.
51
+ * Unknowable is not a fault.
52
+ */
53
+ export declare function testProgramFault(program: TestProgram, config: Record<string, unknown>): TestProgramFault | null;
54
+ //# sourceMappingURL=test-program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-program.d.ts","sourceRoot":"","sources":["../src/test-program.ts"],"names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