@smoothbricks/nx-plugin 0.4.25 → 0.4.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/README.md +1078 -98
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +16 -85
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +16 -17
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +37 -44
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +50 -8
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +691 -71
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +108 -12
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +299 -18
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +213 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +624 -177
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +435 -230
  102. package/dist/managed-assets.d.ts +6 -0
  103. package/dist/managed-assets.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.d.ts +13 -0
  105. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  106. package/dist/managed-files/ci-workflow.js +44 -13
  107. package/dist/managed-files/files.d.ts +7 -1
  108. package/dist/managed-files/files.d.ts.map +1 -1
  109. package/dist/managed-files/files.js +62 -8
  110. package/dist/managed-files/json-edit.d.ts +21 -0
  111. package/dist/managed-files/json-edit.d.ts.map +1 -0
  112. package/dist/managed-files/json-edit.js +295 -0
  113. package/dist/managed-files/managed-format.d.ts +33 -1
  114. package/dist/managed-files/managed-format.d.ts.map +1 -1
  115. package/dist/managed-files/managed-format.js +82 -2
  116. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  117. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  119. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  120. package/dist/managed-files/publish-workflow.js +231 -48
  121. package/dist/managed-files/tree.d.ts +5 -0
  122. package/dist/managed-files/tree.d.ts.map +1 -1
  123. package/dist/managed-files/tree.js +5 -3
  124. package/dist/manifest-hash.js +3 -2
  125. package/dist/nextest-code-bound.d.ts +62 -0
  126. package/dist/nextest-code-bound.d.ts.map +1 -0
  127. package/dist/nextest-code-bound.js +154 -0
  128. package/dist/nextest-extraction.d.ts +24 -8
  129. package/dist/nextest-extraction.d.ts.map +1 -1
  130. package/dist/nextest-extraction.js +42 -7
  131. package/dist/package-target-policy.d.ts.map +1 -1
  132. package/dist/package-target-policy.js +3 -5
  133. package/dist/release-config-policy.d.ts.map +1 -1
  134. package/dist/release-config-policy.js +3 -5
  135. package/dist/runtime-input.d.ts +14 -0
  136. package/dist/runtime-input.d.ts.map +1 -0
  137. package/dist/runtime-input.js +15 -0
  138. package/dist/rust-tokens.d.ts +11 -0
  139. package/dist/rust-tokens.d.ts.map +1 -0
  140. package/dist/rust-tokens.js +81 -0
  141. package/dist/task-results.d.ts +6 -0
  142. package/dist/task-results.d.ts.map +1 -0
  143. package/dist/task-results.js +61 -0
  144. package/dist/test-program.d.ts +54 -0
  145. package/dist/test-program.d.ts.map +1 -0
  146. package/dist/test-program.js +292 -0
  147. package/dist/test-timings.d.ts +71 -0
  148. package/dist/test-timings.d.ts.map +1 -0
  149. package/dist/test-timings.js +393 -0
  150. package/dist/test-walk-policy.d.ts +103 -0
  151. package/dist/test-walk-policy.d.ts.map +1 -0
  152. package/dist/test-walk-policy.js +657 -0
  153. package/dist/testing.d.ts +177 -0
  154. package/dist/testing.d.ts.map +1 -0
  155. package/dist/testing.js +824 -0
  156. package/dist/type-guards.d.ts +3 -0
  157. package/dist/type-guards.d.ts.map +1 -0
  158. package/dist/type-guards.js +4 -0
  159. package/dist/typecheck-test-policy.d.ts +8 -5
  160. package/dist/typecheck-test-policy.d.ts.map +1 -1
  161. package/dist/typecheck-test-policy.js +113 -100
  162. package/dist/workspace-config-policy.d.ts +8 -0
  163. package/dist/workspace-config-policy.d.ts.map +1 -1
  164. package/dist/workspace-config-policy.js +175 -63
  165. package/dist/workspace-index.d.ts +12 -0
  166. package/dist/workspace-index.d.ts.map +1 -0
  167. package/dist/workspace-index.js +17 -0
  168. package/dist/workspace-manifest.d.ts +37 -1
  169. package/dist/workspace-manifest.d.ts.map +1 -1
  170. package/executors.json +5 -0
  171. package/loader.js +13 -11
  172. package/managed/raw/envrc +33 -62
  173. package/managed/raw/git-format-staged.yml +30 -35
  174. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  175. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  176. package/managed/raw/tooling/direnv/developer-links.ts +607 -17
  177. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -92
  178. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  179. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  180. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  181. package/managed/raw/tooling/direnv/repo-path +14 -2
  182. package/managed/raw/tooling/direnv/setup-environment.ts +1009 -118
  183. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  184. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  185. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  186. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  187. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  188. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  189. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  190. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  191. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  192. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  194. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  196. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  197. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  198. package/managed/templates/github/workflows/managed-files.yml +1 -2
  199. package/nextest.toml +8 -75
  200. package/package.json +75 -13
  201. package/runtime-input.sh +81 -0
  202. package/src/__tests__/counted-cargo-process.ts +286 -0
  203. package/src/__tests__/counted-cargo.ts +730 -0
  204. package/src/__tests__/fixture-cargo-home.ts +36 -0
  205. package/src/__tests__/fixture-nx-env.ts +157 -2
  206. package/src/__tests__/progress-clock.ts +43 -0
  207. package/src/__tests__/runtime-input.ts +23 -0
  208. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  209. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  210. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  211. package/src/bin/smoo-nx-exec.ts +17 -86
  212. package/src/bin/smoo-nx-failures.ts +4 -0
  213. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  214. package/src/bin/smoo-nx-test-walks.ts +42 -0
  215. package/src/bounded-test-policy.test.ts +268 -22
  216. package/src/bounded-test-policy.ts +114 -42
  217. package/src/build-state-output-policy.test.ts +115 -0
  218. package/src/build-state-output-policy.ts +90 -0
  219. package/src/bun-bootstrap.test.ts +57 -3
  220. package/src/bun-file-packages.test.ts +47 -0
  221. package/src/cargo-closure-input.test.ts +432 -62
  222. package/src/cargo-closure-input.ts +51 -57
  223. package/src/cargo-dev-profile.ts +137 -0
  224. package/src/cargo-resolve-cache.test.ts +1044 -0
  225. package/src/cargo-source-hash.test.ts +203 -93
  226. package/src/cargo-source-hash.ts +762 -75
  227. package/src/cargo-toolchain-policy.ts +6 -0
  228. package/src/cargo-workspace.test.ts +320 -0
  229. package/src/cargo-workspace.ts +344 -18
  230. package/src/cross-check-policy.test.ts +59 -1
  231. package/src/cross-check-policy.ts +25 -6
  232. package/src/disk-command-policy.test.ts +61 -0
  233. package/src/disk-command-policy.ts +107 -0
  234. package/src/ensure-built-receipt.test.ts +184 -0
  235. package/src/ensure-built-receipt.ts +263 -0
  236. package/src/ensure-built-witness.test.ts +344 -0
  237. package/src/ensure-built-witness.ts +252 -0
  238. package/src/ensure-built.test.ts +1043 -483
  239. package/src/ensure-built.ts +870 -197
  240. package/src/eslint-file-set.ts +9 -0
  241. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  242. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  243. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  244. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  245. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  246. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  247. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  248. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  249. package/src/executors/bounded-exec/executor.ts +565 -67
  250. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  251. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  252. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  253. package/src/executors/bounded-exec/progress.test.ts +79 -0
  254. package/src/executors/bounded-exec/progress.ts +118 -0
  255. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  256. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  257. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  258. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  259. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  260. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  261. package/src/executors/bounded-exec/schema.json +11 -5
  262. package/src/executors/bounded-exec/schema.ts +27 -11
  263. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  264. package/src/executors/bounded-exec/verdict.ts +433 -0
  265. package/src/executors/shard-timings/executor.ts +36 -0
  266. package/src/executors/shard-timings/schema.json +21 -0
  267. package/src/executors/shard-timings/schema.ts +4 -0
  268. package/src/failure-summary.ts +119 -0
  269. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  270. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  271. package/src/generators/create-package/generator.test.ts +6 -0
  272. package/src/generators/create-package/generator.ts +6 -2
  273. package/src/host-controller-wiring.test.ts +31 -0
  274. package/src/index.test.ts +1070 -360
  275. package/src/index.ts +524 -255
  276. package/src/linked-snapshots.nx.test.ts +172 -0
  277. package/src/managed-assets.ts +12 -0
  278. package/src/managed-files/ci-workflow.ts +54 -13
  279. package/src/managed-files/files.ts +65 -9
  280. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  281. package/src/managed-files/generator.test.ts +60 -1
  282. package/src/managed-files/json-edit.test.ts +216 -0
  283. package/src/managed-files/json-edit.ts +290 -0
  284. package/src/managed-files/managed-format-json.test.ts +308 -0
  285. package/src/managed-files/managed-format.ts +90 -2
  286. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  287. package/src/managed-files/publish-workflow.ts +285 -67
  288. package/src/managed-files/repo-path.test.ts +129 -0
  289. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  290. package/src/managed-files/tree.ts +11 -3
  291. package/src/manifest-hash.ts +3 -2
  292. package/src/nextest-code-bound.test.ts +155 -0
  293. package/src/nextest-code-bound.ts +195 -0
  294. package/src/nextest-extraction.test.ts +37 -5
  295. package/src/nextest-extraction.ts +51 -9
  296. package/src/nextest-partitions.test.ts +495 -0
  297. package/src/nx-cache-bound.test.ts +109 -0
  298. package/src/nx-cache-restore-mtime.test.ts +170 -0
  299. package/src/nx-daemon-claim.test.ts +277 -0
  300. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  301. package/src/nx-daemon-idle-policy.test.ts +51 -0
  302. package/src/nx-daemon-ignore-files.test.ts +210 -0
  303. package/src/nx-daemon-root-normalization.test.ts +105 -0
  304. package/src/nx-daemon-validity.test.ts +925 -0
  305. package/src/nx-dot-input-policy.test.ts +353 -0
  306. package/src/nx-failure-life-cycles.test.ts +207 -0
  307. package/src/nx-files-archive-racy.test.ts +97 -0
  308. package/src/nx-foreign-workspace-env.test.ts +329 -0
  309. package/src/nx-incomplete-run-summary.test.ts +70 -0
  310. package/src/nx-plugin-load-errors.test.ts +120 -0
  311. package/src/nx-project-resolution-cache.test.ts +176 -0
  312. package/src/nx-raw-inputs.test.ts +166 -0
  313. package/src/nx-resident-graph-workers.test.ts +112 -0
  314. package/src/nx-run-information.test.ts +118 -0
  315. package/src/nx-skipped-task-exit.test.ts +180 -0
  316. package/src/nx-state-location.test.ts +63 -0
  317. package/src/nx-store-resolution.test.ts +99 -0
  318. package/src/nx-task-graph-cycles.test.ts +148 -0
  319. package/src/nx-task-output-lease.test.ts +414 -0
  320. package/src/nx-use-local.test.ts +103 -0
  321. package/src/package-target-policy.ts +3 -6
  322. package/src/release-config-policy.ts +3 -6
  323. package/src/runtime-input.test.ts +215 -0
  324. package/src/runtime-input.ts +17 -0
  325. package/src/rust-tokens.ts +78 -0
  326. package/src/serial-group-wiring.test.ts +326 -0
  327. package/src/task-history-namespace.test.ts +181 -0
  328. package/src/task-results.test.ts +226 -0
  329. package/src/task-results.ts +75 -0
  330. package/src/test-program.test.ts +303 -0
  331. package/src/test-program.ts +341 -0
  332. package/src/test-timings.test.ts +240 -0
  333. package/src/test-timings.ts +311 -0
  334. package/src/test-walk-policy.test.ts +585 -0
  335. package/src/test-walk-policy.ts +731 -0
  336. package/src/testing.test.ts +509 -0
  337. package/src/testing.ts +922 -0
  338. package/src/type-guards.ts +4 -0
  339. package/src/typecheck-test-policy.test.ts +496 -11
  340. package/src/typecheck-test-policy.ts +137 -103
  341. package/src/workspace-config-policy.test.ts +212 -13
  342. package/src/workspace-config-policy.ts +101 -73
  343. package/src/workspace-index.ts +18 -0
  344. package/src/workspace-manifest.ts +41 -1
  345. package/test-timings.json +85 -28
  346. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -615
  347. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
  348. package/src/__tests__/in-process-nx-index.ts +0 -9
@@ -0,0 +1,107 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
3
+ import { basename, extname, resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ /** Root's fixed boot script cannot execute a user-writable cowshed binary. No image verbs belong here. */
7
+ export const PHYSICAL_BOOT_LAYER = 'packages/cowshed/crates/cowshed-core/src/storage/bootstrap/native/macos.rs';
8
+
9
+ /** Direct disk-image executors bypass cowshed's detached lifetime and can leak kernel devices. */
10
+ export function directDiskCommands(source: string, path = ''): number[] {
11
+ // Preserve newlines for diagnostics; prose comments are not executable call sites.
12
+ const code = source
13
+ .replace(/\/\*[\s\S]*?\*\//g, (comment) => comment.replace(/[^\n]/g, ' '))
14
+ .replace(/(?:"""[\s\S]*?"""|'''[\s\S]*?''')/g, (comment) => comment.replace(/[^\n]/g, ' '))
15
+ .replace(/^[ \t]*(?:\/\/|#(?!!)).*$/gm, '');
16
+ const tool = String.raw`(?:\/usr\/(?:s?bin)\/)?(?:hdiutil|diskutil)`;
17
+ const quoted = `["']${tool}["']`;
18
+ const aliases = [
19
+ ...code.matchAll(new RegExp(String.raw`\b([A-Za-z_]\w*)\s*(?::[^=\n]+)?=\s*(?:\(?\s*\[\s*)?${quoted}`, 'g')),
20
+ ]
21
+ .map((match) => match[1])
22
+ .filter((name): name is string => name !== undefined);
23
+ const program = `(?:${quoted}|HDIUTIL|DISKUTIL${aliases.map((name) => `|${name}`).join('')})`;
24
+ const patterns = [
25
+ // Rust, Node, Python and argv-list launchers, including literal aliases.
26
+ new RegExp(
27
+ String.raw`\b(?:Command::new|spawn(?:Sync)?|execFile(?:Sync)?|exec(?:Sync)?|execa(?:Sync)?|Popen|check_call|check_output|subprocess\.run|sh|trial)\s*\(\s*(?:\{\s*cmd:\s*)?(?:&?\[\s*)?${program}(?=\s*[,\)\]])`,
28
+ 'g',
29
+ ),
30
+ new RegExp(String.raw`(?:^|\n|\$\(|\$\x60|\|)[ \t]*(?:sudo\s+)?${tool}(?=\s|$)`, 'g'),
31
+ new RegExp(String.raw`HostCommand::new\s*\(\s*${program}\s*,\s*\[\s*"(?:image|eject|attach|detach|create)"`, 'g'),
32
+ ];
33
+ if (['.sh', '.bash', '.zsh', '.nix', '.yaml', '.yml'].includes(extname(path))) {
34
+ patterns.push(new RegExp(String.raw`[;\x60&][ \t]*(?:sudo\s+)?${tool}(?=\s|$)`, 'g'));
35
+ }
36
+ if (['package.json', 'project.json'].includes(basename(path))) {
37
+ patterns.push(new RegExp(String.raw`"[^"\n]+"\s*:\s*"${tool}(?=\s)`, 'g'));
38
+ }
39
+ const lines = new Set<number>();
40
+ for (const pattern of patterns) {
41
+ for (const match of code.matchAll(pattern)) {
42
+ const start = match.index + match[0].search(/\S/);
43
+ const line = code.slice(0, start).split('\n').length;
44
+ const text = code.split('\n')[line - 1]?.trim() ?? '';
45
+ if (
46
+ path === PHYSICAL_BOOT_LAYER &&
47
+ /^(?:info=\$\()?\/usr\/sbin\/diskutil info -plist "\$uuid"\)?$|^\| \/usr\/sbin\/diskutil apfs unlockVolume "\$uuid" -nomount -stdinpassphrase$|^\/usr\/sbin\/diskutil mount -nobrowse -mountPoint "\$mountpoint" "\$uuid"$/.test(
48
+ text,
49
+ )
50
+ )
51
+ continue;
52
+ lines.add(line);
53
+ }
54
+ }
55
+ return [...lines].sort((left, right) => left - right);
56
+ }
57
+
58
+ /** Scan tracked code, tests and scripts, never build output, prose or recorded benchmark data. */
59
+ export function checkDiskCommandBoundary(root: string): string[] {
60
+ const files = execFileSync('git', ['ls-files', '-z', '--cached', '--others', '--exclude-standard'], {
61
+ cwd: root,
62
+ encoding: 'utf8',
63
+ maxBuffer: 32 * 1024 * 1024,
64
+ })
65
+ .split('\0')
66
+ .filter(Boolean);
67
+ const extensions = [
68
+ '.rs',
69
+ '.ts',
70
+ '.tsx',
71
+ '.js',
72
+ '.mjs',
73
+ '.cjs',
74
+ '.py',
75
+ '.sh',
76
+ '.bash',
77
+ '.zsh',
78
+ '.nix',
79
+ '.yaml',
80
+ '.yml',
81
+ ];
82
+ const failures: string[] = [];
83
+ for (const path of files) {
84
+ if (
85
+ extname(path) !== '' &&
86
+ !extensions.includes(extname(path)) &&
87
+ !['package.json', 'project.json'].includes(basename(path))
88
+ )
89
+ continue;
90
+ const source = readFileSync(resolve(root, path), 'utf8');
91
+ for (const line of directDiskCommands(source, path)) {
92
+ failures.push(`${path}:${line}: direct disk tool; use cowshed disk-command or SystemCommandRunner`);
93
+ }
94
+ }
95
+ return failures;
96
+ }
97
+
98
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
99
+ const roots = process.argv.slice(2);
100
+ if (roots.length === 0) roots.push(process.cwd());
101
+ for (const root of roots) {
102
+ const failures = checkDiskCommandBoundary(root);
103
+ for (const failure of failures) console.error(`${root}/${failure}`);
104
+ if (failures.length > 0) process.exitCode = 1;
105
+ else console.log(`${root}: no direct disk-tool executions`);
106
+ }
107
+ }
@@ -0,0 +1,184 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
2
+ import { createHash } from 'node:crypto';
3
+ import { chmod, lstat, mkdir, mkdtemp, realpath, rm, symlink, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ import type { Task } from 'nx/src/config/task-graph';
7
+ import { expandOutputs } from 'nx/src/native';
8
+ import { cargoRuntimeInput } from './cargo-toolchain-policy.js';
9
+ import {
10
+ boundedReceiptRuntimes,
11
+ dirtyProviderPaths,
12
+ type ProviderInputProof,
13
+ providerReceipt,
14
+ } from './ensure-built-receipt.js';
15
+
16
+ let root = '';
17
+ const task = {
18
+ id: 'app:build',
19
+ target: { project: 'app', target: 'build' },
20
+ overrides: {},
21
+ outputs: ['output'],
22
+ cache: true,
23
+ hash: 'current-key',
24
+ } satisfies Task;
25
+ const inputs = { files: ['source.txt'], runtime: [], environment: [], depOutputs: [], external: [] };
26
+ const proof: ProviderInputProof = {
27
+ kind: 'exact-file-inputs',
28
+ files: ['source.txt'],
29
+ inputs: { [task.id]: inputs },
30
+ runtimeSource: { kind: 'bounded' },
31
+ };
32
+ function git(...args: string[]): void {
33
+ const result = Bun.spawnSync(['git', '-C', root, ...args], { stderr: 'pipe' });
34
+ expect(result.exitCode, result.stderr.toString()).toBe(0);
35
+ }
36
+
37
+ beforeEach(async () => {
38
+ root = await realpath(await mkdtemp(join(tmpdir(), 'ensure-built-receipt-')));
39
+ git('init', '--quiet');
40
+ await writeFile(join(root, '.gitignore'), 'output/\n');
41
+ await writeFile(join(root, 'source.txt'), 'source');
42
+ git('add', '.');
43
+ git('-c', 'user.name=Receipt fixture', '-c', 'user.email=receipt@example.invalid', 'commit', '-qm', 'fixture');
44
+ await mkdir(join(root, 'output/empty'), { recursive: true });
45
+ await writeFile(join(root, 'output/file'), 'public bytes');
46
+ await symlink('file', join(root, 'output/link'));
47
+ await chmod(join(root, 'output/file'), 0o644);
48
+ await chmod(join(root, 'output/empty'), 0o755);
49
+ });
50
+ afterEach(async () => {
51
+ await rm(root, { recursive: true, force: true });
52
+ });
53
+
54
+ describe('provider receipt', () => {
55
+ it('does not borrow the caller Git directory/index/object namespace for provider provenance', () => {
56
+ const saved = process.env.GIT_DIR;
57
+ process.env.GIT_DIR = join(root, 'not-the-provider-git-directory');
58
+ try {
59
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('hit');
60
+ } finally {
61
+ if (saved === undefined) delete process.env.GIT_DIR;
62
+ else process.env.GIT_DIR = saved;
63
+ }
64
+ });
65
+ it('names current hashes, HEAD/tree, independent file digests, link text and empty directory modes', async () => {
66
+ const result = providerReceipt(root, task.id, [task], proof, expandOutputs);
67
+ expect(result.disposition).toBe('hit');
68
+ if (result.disposition !== 'hit') throw new Error(result.reason.detail);
69
+ expect(result.receipt.head).toMatch(/^[a-f0-9]{40,64}$/);
70
+ expect(result.receipt.headTree).toMatch(/^[a-f0-9]{40,64}$/);
71
+ expect(result.receipt.workspaceRoot).toBe(root);
72
+ expect(result.receipt.runtimeEnvironmentProvenance).toBe('nx-task-hash-only');
73
+ expect(result.receipt.tasks[0].id).toBe(task.id);
74
+ expect(result.receipt.tasks[0].hash).toBe(task.hash);
75
+ expect(result.receipt.tasks[0].outputs).toContainEqual({
76
+ path: 'output/file',
77
+ type: 'file',
78
+ mode: 0o644,
79
+ sha256: createHash('sha256').update('public bytes').digest('hex'),
80
+ });
81
+ expect(result.receipt.tasks[0].outputs).toContainEqual({
82
+ path: 'output/link',
83
+ type: 'symlink',
84
+ mode: (await lstat(join(root, 'output/link'))).mode & 0o7777,
85
+ linkText: 'file',
86
+ });
87
+ expect(result.receipt.tasks[0].outputs.find(({ path }) => path === 'output/empty')).toMatchObject({
88
+ type: 'directory',
89
+ mode: 0o755,
90
+ entries: [],
91
+ });
92
+ });
93
+
94
+ it('does not refuse an unrelated untracked source when FILE closure is exactly proven', async () => {
95
+ await writeFile(join(root, 'unrelated.ts'), 'unrelated');
96
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('hit');
97
+ expect(
98
+ providerReceipt(root, task.id, [task], { ...proof, kind: 'conservative-provider-source' }, expandOutputs)
99
+ .disposition,
100
+ ).toBe('failed');
101
+ });
102
+
103
+ it('refuses modified, deleted, newly matched and index-only dirty FILE inputs', async () => {
104
+ await writeFile(join(root, 'source.txt'), 'changed');
105
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('failed');
106
+ git('add', 'source.txt');
107
+ await writeFile(join(root, 'source.txt'), 'source');
108
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('failed');
109
+ git('restore', '--staged', 'source.txt');
110
+ await writeFile(join(root, 'new-source.txt'), 'new');
111
+ expect(
112
+ providerReceipt(root, task.id, [task], { ...proof, files: [...proof.files, 'new-source.txt'] }, expandOutputs)
113
+ .disposition,
114
+ ).toBe('failed');
115
+ await rm(join(root, 'source.txt'));
116
+ expect(providerReceipt(root, task.id, [task], { ...proof, files: [] }, expandOutputs).disposition).toBe('failed');
117
+ });
118
+
119
+ it('recomputes output byte/directory identities after every public mutation', async () => {
120
+ const first = providerReceipt(root, task.id, [task], proof, expandOutputs);
121
+ if (first.disposition !== 'hit') throw new Error(first.reason.detail);
122
+ await writeFile(join(root, 'output/file'), 'PUBLIC BYTES');
123
+ await chmod(join(root, 'output/empty'), 0o700);
124
+ const next = providerReceipt(root, task.id, [task], proof, expandOutputs);
125
+ if (next.disposition !== 'hit') throw new Error(next.reason.detail);
126
+ expect(next.receipt.tasks[0].outputs).not.toEqual(first.receipt.tasks[0].outputs);
127
+ expect(next.receipt.tasks[0].outputs.find(({ path }) => path === 'output/empty')).toMatchObject({ mode: 0o700 });
128
+ });
129
+
130
+ it('refuses unreadable public bytes, missing outputs and opaque runtime closure', async () => {
131
+ await chmod(join(root, 'output/file'), 0);
132
+ try {
133
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('failed');
134
+ } finally {
135
+ await chmod(join(root, 'output/file'), 0o600);
136
+ }
137
+ await rm(join(root, 'output'), { recursive: true });
138
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('failed');
139
+ expect(
140
+ providerReceipt(
141
+ root,
142
+ task.id,
143
+ [task],
144
+ { ...proof, runtimeSource: { kind: 'opaque', detail: 'unnameable command input closure' } },
145
+ expandOutputs,
146
+ ),
147
+ ).toMatchObject({
148
+ disposition: 'failed',
149
+ reason: { kind: 'provider-proof', detail: 'unnameable command input closure' },
150
+ });
151
+ });
152
+ });
153
+
154
+ describe('receipt runtime provenance', () => {
155
+ it('admits only the existing generated pinned toolchain-version recipe, never a command containing the same words', () => {
156
+ const recipe = cargoRuntimeInput('packages/app', 'rustc -vV && cargo -V').runtime;
157
+ const planned = { [task.id]: { ...inputs, runtime: [recipe] } };
158
+ expect(boundedReceiptRuntimes(planned, ['packages/app'], ['devenv.lock'], true)).toEqual({ kind: 'bounded' });
159
+ expect(boundedReceiptRuntimes(planned, ['packages/app'], [], true).kind).toBe('opaque');
160
+ expect(boundedReceiptRuntimes(planned, ['packages/app'], ['devenv.lock'], false).kind).toBe('opaque');
161
+ expect(
162
+ boundedReceiptRuntimes(
163
+ { [task.id]: { ...inputs, runtime: [recipe + '; cat /unproved/external'] } },
164
+ ['packages/app'],
165
+ ['devenv.lock'],
166
+ true,
167
+ ).kind,
168
+ ).toBe('opaque');
169
+ expect(
170
+ boundedReceiptRuntimes(
171
+ { [task.id]: { ...inputs, runtime: ['sh arbitrary-source-reader.sh'] } },
172
+ ['packages/app'],
173
+ ['devenv.lock'],
174
+ true,
175
+ ).kind,
176
+ ).toBe('opaque');
177
+ });
178
+
179
+ it('preserves whitespace, both sides of renames, deletion and index-only status paths', () => {
180
+ expect(
181
+ dirtyProviderPaths(' M source with spaces.ts\0R new.ts\0old.ts\0D deleted.ts\0?? new-source.ts\0'),
182
+ ).toEqual(['source with spaces.ts', 'new.ts', 'old.ts', 'deleted.ts', 'new-source.ts']);
183
+ });
184
+ });
@@ -0,0 +1,263 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import type { BigIntStats } from 'node:fs';
4
+ import { closeSync, lstatSync, openSync, readdirSync, readlinkSync, readSync, realpathSync } from 'node:fs';
5
+ import { isAbsolute, join, relative } from 'node:path';
6
+ import type { Task } from 'nx/src/config/task-graph';
7
+ import type { expandOutputs, HashInputs } from 'nx/src/native';
8
+ import { CARGO_TOOLCHAIN_PIN_INPUTS, cargoRuntimeInput } from './cargo-toolchain-policy.js';
9
+ import type { EnsureBuiltOutputReceipt, EnsureBuiltProbeFailure, EnsureBuiltReceipt } from './ensure-built.js';
10
+ import { type NodeWitness, nodeStamp, nodesUnchanged } from './ensure-built-witness.js';
11
+
12
+ type Evidence<T> = { readonly ok: true; readonly value: T } | { readonly ok: false; readonly detail: string };
13
+
14
+ export interface ProviderInputProof {
15
+ readonly kind: 'exact-file-inputs' | 'conservative-provider-source';
16
+ readonly files: readonly string[];
17
+ readonly inputs: Readonly<Record<string, HashInputs>>;
18
+ readonly runtimeSource: { readonly kind: 'bounded' } | { readonly kind: 'opaque'; readonly detail: string };
19
+ }
20
+
21
+ function git(root: string, args: string[]): Evidence<string> {
22
+ // Provenance belongs to this provider, not a Git directory/index/object
23
+ // namespace an outer build lent the process. Nx's hashing environment is
24
+ // unchanged; only these read-only evidence children bind their own Git state.
25
+ const env = { ...process.env };
26
+ for (const key of [
27
+ 'GIT_DIR',
28
+ 'GIT_COMMON_DIR',
29
+ 'GIT_WORK_TREE',
30
+ 'GIT_INDEX_FILE',
31
+ 'GIT_OBJECT_DIRECTORY',
32
+ 'GIT_ALTERNATE_OBJECT_DIRECTORIES',
33
+ 'GIT_NAMESPACE',
34
+ ])
35
+ delete env[key];
36
+ const child = spawnSync('git', ['-C', root, ...args], { env, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
37
+ return child.status === 0 && child.error === undefined
38
+ ? { ok: true, value: child.stdout }
39
+ : {
40
+ ok: false,
41
+ detail: `git ${args.join(' ')}: ${child.error?.message ?? child.stderr.trim()} (exit ${child.status}, signal ${child.signal})`,
42
+ };
43
+ }
44
+
45
+ /** NUL-delimited Git paths preserve whitespace, rename sources and index-only changes. */
46
+ export function dirtyProviderPaths(status: string): string[] {
47
+ const entries = status.split('\0');
48
+ const paths: string[] = [];
49
+ for (let index = 0; index < entries.length; index += 1) {
50
+ const entry = entries[index];
51
+ if (entry === '') continue;
52
+ paths.push(entry.slice(3));
53
+ if (entry[0] === 'R' || entry[0] === 'C' || entry[1] === 'R' || entry[1] === 'C') {
54
+ index += 1;
55
+ if (entries[index] !== undefined) paths.push(entries[index]);
56
+ }
57
+ }
58
+ return paths;
59
+ }
60
+
61
+ export function providerReceipt(
62
+ workspaceRoot: string,
63
+ taskId: string,
64
+ tasks: readonly Task[],
65
+ proof: ProviderInputProof,
66
+ expand: typeof expandOutputs,
67
+ ): { readonly disposition: 'hit'; readonly receipt: EnsureBuiltReceipt } | EnsureBuiltProbeFailure {
68
+ const root = realpathSync(workspaceRoot);
69
+ const failed = (detail: string): EnsureBuiltProbeFailure => ({
70
+ disposition: 'failed',
71
+ reason: { kind: 'provider-proof', taskId, workspaceRoot: root, detail },
72
+ exitCode: 1,
73
+ signal: null,
74
+ });
75
+ if (proof.runtimeSource.kind === 'opaque') return failed(proof.runtimeSource.detail);
76
+ const revision = git(root, ['rev-parse', '--verify', 'HEAD']);
77
+ if (!revision.ok) return failed(revision.detail);
78
+ const head = revision.value.trim();
79
+ const tree = git(root, ['rev-parse', '--verify', `${head}^{tree}`]);
80
+ if (!tree.ok) return failed(tree.detail);
81
+ const status = git(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all']);
82
+ if (!status.ok) return failed(status.detail);
83
+ const listed = git(root, ['ls-tree', '-r', '-z', '--full-tree', head]);
84
+ if (!listed.ok) return failed(listed.detail);
85
+ const format = git(root, ['rev-parse', '--show-object-format']);
86
+ if (!format.ok) return failed(format.detail);
87
+ const algorithm = format.value.trim();
88
+ if (algorithm !== 'sha1' && algorithm !== 'sha256') return failed(`Unproved Git object format ${algorithm}`);
89
+ const tracked = new Map<string, { mode: string; oid: string }>();
90
+ for (const entry of listed.value.split('\0')) {
91
+ if (entry === '') continue;
92
+ const tab = entry.indexOf('\t');
93
+ const [mode, kind, oid] = entry.slice(0, tab).split(' ');
94
+ if (tab < 0 || oid === undefined) return failed(`Unproved HEAD tree entry ${entry}`);
95
+ if (kind !== 'blob') continue;
96
+ tracked.set(entry.slice(tab + 1), { mode, oid });
97
+ }
98
+ const observed: NodeWitness[] = [];
99
+ const buffer = Buffer.allocUnsafe(1 << 20);
100
+ const outputNodes = new Map<string, EnsureBuiltOutputReceipt>();
101
+ function observe(path: string): BigIntStats {
102
+ const stats = lstatSync(path, { bigint: true });
103
+ observed.push({ path, stamp: nodeStamp(stats) });
104
+ return stats;
105
+ }
106
+ function fileDigest(path: string, size: number, algorithm: 'sha1' | 'sha256', gitBlob: boolean): string {
107
+ const hash = createHash(algorithm);
108
+ if (gitBlob) hash.update(`blob ${size}\0`);
109
+ const fd = openSync(path, 'r');
110
+ try {
111
+ for (let offset = 0; offset < size; offset += buffer.length) {
112
+ const count = Math.min(buffer.length, size - offset);
113
+ if (readSync(fd, buffer, 0, count, offset) !== count) throw new Error(`File moved while reading ${path}`);
114
+ hash.update(buffer.subarray(0, count));
115
+ }
116
+ } finally {
117
+ closeSync(fd);
118
+ }
119
+ return hash.digest('hex');
120
+ }
121
+ function visit(path: string): EnsureBuiltOutputReceipt {
122
+ const rel = relative(root, path);
123
+ if (rel === '..' || rel.startsWith('../') || isAbsolute(rel)) throw new Error(`Output escapes provider: ${path}`);
124
+ const previous = outputNodes.get(rel);
125
+ if (previous !== undefined) return previous;
126
+ const stats = observe(path);
127
+ const mode = Number(stats.mode & 0o7777n);
128
+ let node: EnsureBuiltOutputReceipt;
129
+ if (stats.isFile()) {
130
+ node = { path: rel, type: 'file', mode, sha256: fileDigest(path, Number(stats.size), 'sha256', false) };
131
+ } else if (stats.isSymbolicLink()) {
132
+ node = { path: rel, type: 'symlink', mode, linkText: readlinkSync(path) };
133
+ } else if (stats.isDirectory()) {
134
+ const children = readdirSync(path)
135
+ .sort()
136
+ .map((name) => visit(join(path, name)));
137
+ const entries = children.map(({ path: child }) => relative(rel, child));
138
+ node = {
139
+ path: rel,
140
+ type: 'directory',
141
+ mode,
142
+ entries,
143
+ sha256: createHash('sha256').update(JSON.stringify(children)).digest('hex'),
144
+ };
145
+ } else {
146
+ throw new Error(`Unsupported public output node ${path}`);
147
+ }
148
+ outputNodes.set(rel, node);
149
+ return node;
150
+ }
151
+ try {
152
+ const receipts: EnsureBuiltReceipt['tasks'][number][] = [];
153
+ for (const task of tasks) {
154
+ if (task.hash === undefined) return failed(`No current hash for ${task.id}`);
155
+ const entries = task.outputs.length === 0 ? [] : expand(root, task.outputs);
156
+ if (task.outputs.length > 0 && entries.length === 0) return failed(`No public outputs for ${task.id}`);
157
+ const selected = new Set<string>();
158
+ for (const entry of entries) {
159
+ if (isAbsolute(entry) || entry.split('/').includes('..'))
160
+ return failed(`Invalid public output ${entry} for ${task.id}`);
161
+ // Root-to-entry parent directories must be real; do not follow a
162
+ // parent link into an unrelated tree and sign its bytes.
163
+ let parent = root;
164
+ for (const segment of entry.split('/').slice(0, -1)) {
165
+ parent = join(parent, segment);
166
+ if (!observe(parent).isDirectory()) return failed(`Symlinked public output parent ${parent}`);
167
+ }
168
+ visit(join(root, entry));
169
+ for (const path of outputNodes.keys()) {
170
+ if (path === entry || path.startsWith(`${entry}/`)) selected.add(path);
171
+ }
172
+ }
173
+ receipts.push({
174
+ id: task.id,
175
+ hash: task.hash,
176
+ outputs: [...selected].sort().map((path) => {
177
+ const node = outputNodes.get(path);
178
+ if (node === undefined) throw new Error(`Lost output census node ${path}`);
179
+ return node;
180
+ }),
181
+ });
182
+ }
183
+ const fileInputs = new Set(proof.files);
184
+ const deletedSource = status.value
185
+ .split('\0')
186
+ .some((entry) => (entry[0] === 'D' || entry[1] === 'D') && !outputNodes.has(entry.slice(3)));
187
+ const effectiveKind = deletedSource ? 'conservative-provider-source' : proof.kind;
188
+ const dirty = dirtyProviderPaths(status.value).filter(
189
+ (path) =>
190
+ (!outputNodes.has(path) || fileInputs.has(path)) &&
191
+ (effectiveKind === 'conservative-provider-source' || fileInputs.has(path)),
192
+ );
193
+ if (dirty.length > 0) return failed(`${effectiveKind}: provider source differs from ${head}: ${dirty.join(', ')}`);
194
+ for (const file of fileInputs) {
195
+ const expected = tracked.get(file);
196
+ if (expected === undefined) return failed(`Nx file input is not in provider HEAD tree: ${file}`);
197
+ const path = join(root, file);
198
+ const stats = observe(path);
199
+ const mode = stats.isSymbolicLink() ? '120000' : (stats.mode & 0o111n) !== 0n ? '100755' : '100644';
200
+ if (mode !== expected.mode) return failed(`Nx file input mode differs from provider HEAD: ${file}`);
201
+ if (!stats.isFile()) return failed(`Unproved linked or non-file input source closure: ${file}`);
202
+ const oid = fileDigest(path, Number(stats.size), algorithm, true);
203
+ if (oid !== expected.oid) return failed(`Nx file input bytes differ from provider HEAD: ${file}`);
204
+ }
205
+ const finalHead = git(root, ['rev-parse', '--verify', 'HEAD']);
206
+ const finalStatus = git(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all']);
207
+ if (!finalHead.ok) return failed(finalHead.detail);
208
+ if (!finalStatus.ok) return failed(finalStatus.detail);
209
+ const newlyDirty = dirtyProviderPaths(finalStatus.value).some(
210
+ (path) =>
211
+ (!outputNodes.has(path) || fileInputs.has(path)) &&
212
+ (effectiveKind === 'conservative-provider-source' || fileInputs.has(path)),
213
+ );
214
+ if (finalHead.value.trim() !== head || newlyDirty || !nodesUnchanged(observed)) {
215
+ return failed('Provider source, revision or public output nodes moved during receipt capture');
216
+ }
217
+ return {
218
+ disposition: 'hit',
219
+ receipt: {
220
+ workspaceRoot: root,
221
+ head,
222
+ headTree: tree.value.trim(),
223
+ tasks: receipts,
224
+ fileInputProvenance: effectiveKind,
225
+ runtimeEnvironmentProvenance: 'nx-task-hash-only',
226
+ },
227
+ };
228
+ } catch (error) {
229
+ if (error instanceof Error) return failed(`Cannot prove provider source/public outputs: ${error.message}`);
230
+ throw error;
231
+ }
232
+ }
233
+
234
+ /** Admit only recipes emitted by the same owning toolchain generator.
235
+ * No shell parsing or keyword approximation confers file-source provenance.
236
+ */
237
+ export function boundedReceiptRuntimes(
238
+ inputs: Readonly<Record<string, HashInputs>>,
239
+ directories: readonly string[],
240
+ files: readonly string[],
241
+ installationProved: boolean,
242
+ ): ProviderInputProof['runtimeSource'] {
243
+ const runtimes = Object.values(inputs).flatMap((input) => input.runtime);
244
+ if (runtimes.length === 0) return { kind: 'bounded' };
245
+ if (!installationProved) return { kind: 'opaque', detail: 'Runtime input plugin/module source closure is unproved' };
246
+ const pins = CARGO_TOOLCHAIN_PIN_INPUTS.map((path) => path.replace('{workspaceRoot}/', ''));
247
+ if (!pins.some((pin) => files.includes(pin)))
248
+ return { kind: 'opaque', detail: 'Version runtime input has no declared toolchain FILE pin' };
249
+ const allowed = new Set(
250
+ directories.flatMap((directory) =>
251
+ [
252
+ 'rustc -vV && cargo -V',
253
+ 'rustc -vV && cargo -V && cargo clippy -V',
254
+ 'rustc -vV && cargo -V && cargo clippy -V && cargo fmt --version',
255
+ 'rustc -vV && cargo -V && cargo nextest --version',
256
+ ].map((command) => cargoRuntimeInput(directory, command).runtime),
257
+ ),
258
+ );
259
+ const opaque = runtimes.filter((runtime) => !allowed.has(runtime));
260
+ return opaque.length === 0
261
+ ? { kind: 'bounded' }
262
+ : { kind: 'opaque', detail: `Unbounded runtime source closure: ${opaque.join('; ')}` };
263
+ }