@intentius/chant 0.124.86 → 0.124.88

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 (384) hide show
  1. package/dist/action-pins.d.ts +1 -0
  2. package/dist/action-pins.d.ts.map +1 -1
  3. package/dist/action-pins.js +2 -0
  4. package/dist/actor.d.ts +12 -0
  5. package/dist/actor.d.ts.map +1 -0
  6. package/dist/actor.js +18 -0
  7. package/dist/bundle-check.d.ts +20 -5
  8. package/dist/bundle-check.d.ts.map +1 -1
  9. package/dist/bundle-check.js +20 -5
  10. package/dist/chant-install.d.ts +98 -0
  11. package/dist/chant-install.d.ts.map +1 -1
  12. package/dist/chant-install.js +204 -2
  13. package/dist/ci-commit.d.ts.map +1 -1
  14. package/dist/ci-commit.js +1 -2
  15. package/dist/ci-control.d.ts +1 -1
  16. package/dist/ci-control.d.ts.map +1 -1
  17. package/dist/ci-control.js +1 -1
  18. package/dist/ci-evidence-claims.d.ts +59 -0
  19. package/dist/ci-evidence-claims.d.ts.map +1 -0
  20. package/dist/ci-evidence-claims.js +87 -0
  21. package/dist/ci-evidence-from-job.d.ts +103 -0
  22. package/dist/ci-evidence-from-job.d.ts.map +1 -0
  23. package/dist/ci-evidence-from-job.js +162 -0
  24. package/dist/ci-evidence-jobs.d.ts +69 -10
  25. package/dist/ci-evidence-jobs.d.ts.map +1 -1
  26. package/dist/ci-evidence-jobs.js +72 -8
  27. package/dist/ci-handover.d.ts +12 -0
  28. package/dist/ci-handover.d.ts.map +1 -1
  29. package/dist/ci-handover.js +15 -3
  30. package/dist/ci-identity.d.ts +32 -6
  31. package/dist/ci-identity.d.ts.map +1 -1
  32. package/dist/ci-identity.js +40 -8
  33. package/dist/ci-image.d.ts +47 -9
  34. package/dist/ci-image.d.ts.map +1 -1
  35. package/dist/ci-image.js +45 -18
  36. package/dist/ci-jobs.d.ts +1 -1
  37. package/dist/ci-jobs.d.ts.map +1 -1
  38. package/dist/ci-jobs.js +7 -2
  39. package/dist/ci-login.d.ts +75 -13
  40. package/dist/ci-login.d.ts.map +1 -1
  41. package/dist/ci-login.js +89 -37
  42. package/dist/ci-product-words.d.ts +20 -1
  43. package/dist/ci-product-words.d.ts.map +1 -1
  44. package/dist/ci-product-words.js +27 -1
  45. package/dist/ci-product.d.ts +20 -1
  46. package/dist/ci-product.d.ts.map +1 -1
  47. package/dist/ci-product.js +21 -2
  48. package/dist/cli/handlers/approve-confirm.d.ts +14 -0
  49. package/dist/cli/handlers/approve-confirm.d.ts.map +1 -1
  50. package/dist/cli/handlers/approve-confirm.js +46 -0
  51. package/dist/cli/handlers/build.d.ts +1 -1
  52. package/dist/cli/handlers/build.d.ts.map +1 -1
  53. package/dist/cli/handlers/build.js +22 -1
  54. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  55. package/dist/cli/handlers/ci-check.js +38 -14
  56. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  57. package/dist/cli/handlers/ci-evidence.js +238 -26
  58. package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -1
  59. package/dist/cli/handlers/ci-forge-check.js +34 -17
  60. package/dist/cli/handlers/generated-check.d.ts +3 -0
  61. package/dist/cli/handlers/generated-check.d.ts.map +1 -0
  62. package/dist/cli/handlers/generated-check.js +41 -0
  63. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  64. package/dist/cli/handlers/lifecycle.js +3 -0
  65. package/dist/cli/handlers/local-chant.d.ts +13 -0
  66. package/dist/cli/handlers/local-chant.d.ts.map +1 -1
  67. package/dist/cli/handlers/local-chant.js +42 -1
  68. package/dist/cli/handlers/pr.d.ts.map +1 -1
  69. package/dist/cli/handlers/pr.js +42 -5
  70. package/dist/cli/handlers/run-wave.js +8 -0
  71. package/dist/cli/main.d.ts.map +1 -1
  72. package/dist/cli/main.js +38 -4
  73. package/dist/cli/parse-args.d.ts.map +1 -1
  74. package/dist/cli/parse-args.js +66 -0
  75. package/dist/cli/registry.d.ts +24 -0
  76. package/dist/cli/registry.d.ts.map +1 -1
  77. package/dist/components/check-hooks.d.ts +10 -0
  78. package/dist/components/check-hooks.d.ts.map +1 -1
  79. package/dist/components/check-hooks.js +21 -3
  80. package/dist/components/check-steps.js +1 -1
  81. package/dist/components/pr-checks.d.ts +105 -0
  82. package/dist/components/pr-checks.d.ts.map +1 -0
  83. package/dist/components/pr-checks.js +119 -0
  84. package/dist/components/pr-pipeline.d.ts +34 -0
  85. package/dist/components/pr-pipeline.d.ts.map +1 -1
  86. package/dist/components/pr-pipeline.js +14 -1
  87. package/dist/components/product-pipeline.d.ts +16 -1
  88. package/dist/components/product-pipeline.d.ts.map +1 -1
  89. package/dist/components/product-pipeline.js +17 -2
  90. package/dist/components/product-plan.d.ts +262 -3
  91. package/dist/components/product-plan.d.ts.map +1 -1
  92. package/dist/components/product-plan.js +243 -11
  93. package/dist/config.d.ts +10 -6
  94. package/dist/config.d.ts.map +1 -1
  95. package/dist/config.js +11 -6
  96. package/dist/control/consumers.d.ts +6 -0
  97. package/dist/control/consumers.d.ts.map +1 -1
  98. package/dist/control/consumers.js +6 -0
  99. package/dist/dead-guards.d.ts.map +1 -1
  100. package/dist/dead-guards.js +9 -6
  101. package/dist/discovery/files.d.ts +1 -1
  102. package/dist/discovery/files.js +1 -1
  103. package/dist/drift-issue.d.ts +20 -3
  104. package/dist/drift-issue.d.ts.map +1 -1
  105. package/dist/drift-issue.js +16 -0
  106. package/dist/drift-record.d.ts +45 -5
  107. package/dist/drift-record.d.ts.map +1 -1
  108. package/dist/drift-record.js +27 -6
  109. package/dist/floor-table.d.ts +6 -6
  110. package/dist/floor-table.d.ts.map +1 -1
  111. package/dist/floor-table.data.d.ts.map +1 -1
  112. package/dist/floor-table.data.js +58 -20
  113. package/dist/floor-table.js +10 -7
  114. package/dist/forge-check/contract.d.ts +8 -0
  115. package/dist/forge-check/contract.d.ts.map +1 -1
  116. package/dist/forge-check/contract.js +4 -1
  117. package/dist/forge-check/index.d.ts +2 -0
  118. package/dist/forge-check/index.d.ts.map +1 -1
  119. package/dist/forge-check/index.js +2 -0
  120. package/dist/forge-flags.d.ts +10 -0
  121. package/dist/forge-flags.d.ts.map +1 -1
  122. package/dist/forge-flags.js +31 -0
  123. package/dist/forge-remote.d.ts +47 -0
  124. package/dist/forge-remote.d.ts.map +1 -0
  125. package/dist/forge-remote.js +69 -0
  126. package/dist/generated-check.d.ts +74 -0
  127. package/dist/generated-check.d.ts.map +1 -0
  128. package/dist/generated-check.js +216 -0
  129. package/dist/lexicon.d.ts +16 -0
  130. package/dist/lexicon.d.ts.map +1 -1
  131. package/dist/lifecycle/publish-npm.d.ts +15 -0
  132. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  133. package/dist/lifecycle/publish-npm.js +49 -3
  134. package/dist/lifecycle/release-images.d.ts +22 -1
  135. package/dist/lifecycle/release-images.d.ts.map +1 -1
  136. package/dist/lifecycle/release-images.js +27 -3
  137. package/dist/lifecycle/release-ledger.d.ts +4 -3
  138. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  139. package/dist/lifecycle/release-ledger.js +3 -2
  140. package/dist/local-chant.d.ts +57 -3
  141. package/dist/local-chant.d.ts.map +1 -1
  142. package/dist/local-chant.js +122 -13
  143. package/dist/op/op-waves-evidence-jobs.d.ts +92 -0
  144. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -0
  145. package/dist/op/op-waves-evidence-jobs.js +112 -0
  146. package/dist/op/op-waves-evidence.d.ts +17 -4
  147. package/dist/op/op-waves-evidence.d.ts.map +1 -1
  148. package/dist/op/op-waves-evidence.js +32 -10
  149. package/dist/op/op-waves-run.d.ts +12 -1
  150. package/dist/op/op-waves-run.d.ts.map +1 -1
  151. package/dist/op/op-waves-run.js +54 -3
  152. package/dist/op/op-waves.d.ts +8 -0
  153. package/dist/op/op-waves.d.ts.map +1 -1
  154. package/dist/op/op-waves.js +10 -0
  155. package/dist/op/schedule-overdue.d.ts +39 -2
  156. package/dist/op/schedule-overdue.d.ts.map +1 -1
  157. package/dist/op/schedule-overdue.js +89 -7
  158. package/dist/pr-forge-reads.d.ts +21 -1
  159. package/dist/pr-forge-reads.d.ts.map +1 -1
  160. package/dist/pr-forge-reads.js +19 -1
  161. package/dist/pr-forge.d.ts +7 -1
  162. package/dist/pr-forge.d.ts.map +1 -1
  163. package/dist/pr-forge.js +7 -2
  164. package/dist/pr-plan-note.d.ts +24 -0
  165. package/dist/pr-plan-note.d.ts.map +1 -1
  166. package/dist/pr-plan-note.js +11 -1
  167. package/dist/pr-plan-record.d.ts +47 -0
  168. package/dist/pr-plan-record.d.ts.map +1 -0
  169. package/dist/pr-plan-record.js +89 -0
  170. package/dist/pr-post.d.ts +40 -0
  171. package/dist/pr-post.d.ts.map +1 -1
  172. package/dist/pr-post.js +79 -6
  173. package/dist/pr-requires.d.ts +8 -0
  174. package/dist/pr-requires.d.ts.map +1 -1
  175. package/dist/pr-requires.js +3 -1
  176. package/dist/ref-gate-init.d.ts +76 -0
  177. package/dist/ref-gate-init.d.ts.map +1 -0
  178. package/dist/ref-gate-init.js +144 -0
  179. package/dist/ref-gate-rules.d.ts +19 -0
  180. package/dist/ref-gate-rules.d.ts.map +1 -0
  181. package/dist/ref-gate-rules.js +17 -0
  182. package/dist/release-floors.d.ts +51 -1
  183. package/dist/release-floors.d.ts.map +1 -1
  184. package/dist/release-floors.js +66 -16
  185. package/dist/state-migration.d.ts +23 -0
  186. package/dist/state-migration.d.ts.map +1 -1
  187. package/dist/state-migration.js +39 -3
  188. package/dist/state-unlock.d.ts +32 -1
  189. package/dist/state-unlock.d.ts.map +1 -1
  190. package/dist/state-unlock.js +31 -0
  191. package/dist/wave-runtime.mjs +310 -303
  192. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  193. package/dist/workspace/ci-green-cli.js +13 -7
  194. package/dist/workspace/ci-green.d.ts.map +1 -1
  195. package/dist/workspace/ci-green.js +4 -3
  196. package/dist/workspace/drift-cli.d.ts +1 -1
  197. package/dist/workspace/drift-cli.d.ts.map +1 -1
  198. package/dist/workspace/drift-cli.js +5 -12
  199. package/dist/workspace/forge-work.d.ts +3 -2
  200. package/dist/workspace/forge-work.d.ts.map +1 -1
  201. package/dist/workspace/forge-work.js +7 -17
  202. package/dist/workspace/lexicon-outputs.js +2 -2
  203. package/dist/workspace/release-workflow.d.ts +26 -3
  204. package/dist/workspace/release-workflow.d.ts.map +1 -1
  205. package/dist/workspace/release-workflow.js +48 -6
  206. package/dist/workspace/trust/check-evidence-report.d.ts +25 -0
  207. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  208. package/dist/workspace/trust/check-evidence-report.js +20 -0
  209. package/dist/workspace/trust/check-evidence.d.ts +59 -13
  210. package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
  211. package/dist/workspace/trust/check-evidence.js +101 -24
  212. package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
  213. package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
  214. package/dist/workspace/trust/dsse.d.ts +40 -2
  215. package/dist/workspace/trust/dsse.d.ts.map +1 -1
  216. package/dist/workspace/trust/dsse.js +34 -2
  217. package/dist/workspace/trust/evidence.d.ts +7 -2
  218. package/dist/workspace/trust/evidence.d.ts.map +1 -1
  219. package/dist/workspace/trust/evidence.js +5 -0
  220. package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
  221. package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
  222. package/dist/workspace/trust/keyless-fixture.js +161 -0
  223. package/dist/workspace/trust/keyless.d.ts +202 -0
  224. package/dist/workspace/trust/keyless.d.ts.map +1 -0
  225. package/dist/workspace/trust/keyless.js +488 -0
  226. package/dist/workspace/trust/local-evidence.d.ts +3 -0
  227. package/dist/workspace/trust/local-evidence.d.ts.map +1 -1
  228. package/dist/workspace/trust/op-run-statement.d.ts +2 -2
  229. package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
  230. package/dist/workspace/trust/open-evidence.d.ts +67 -0
  231. package/dist/workspace/trust/open-evidence.d.ts.map +1 -0
  232. package/dist/workspace/trust/open-evidence.js +92 -0
  233. package/dist/workspace/trust/policy.d.ts +56 -1
  234. package/dist/workspace/trust/policy.d.ts.map +1 -1
  235. package/dist/workspace/trust/policy.js +103 -2
  236. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
  237. package/dist/workspace/trust/ref-gate-cli.js +65 -3
  238. package/dist/workspace/trust/ref-gate.d.ts +62 -3
  239. package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
  240. package/dist/workspace/trust/ref-gate.js +75 -8
  241. package/dist/workspace/trust/run-statement.d.ts +3 -3
  242. package/dist/workspace/trust/run-statement.d.ts.map +1 -1
  243. package/dist/workspace/trust/runner-identity.d.ts +56 -0
  244. package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
  245. package/dist/workspace/trust/runner-identity.js +65 -0
  246. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  247. package/dist/workspace/trust/trust-files.js +8 -1
  248. package/package.json +1 -1
  249. package/src/action-pins.ts +2 -0
  250. package/src/actor.test.ts +12 -0
  251. package/src/actor.ts +19 -0
  252. package/src/bundle-check.test.ts +22 -0
  253. package/src/bundle-check.ts +33 -5
  254. package/src/chant-install.test.ts +109 -1
  255. package/src/chant-install.ts +243 -2
  256. package/src/ci-commit.test.ts +51 -5
  257. package/src/ci-commit.ts +1 -2
  258. package/src/ci-control.ts +1 -0
  259. package/src/ci-evidence-claims.ts +102 -0
  260. package/src/ci-evidence-from-job.test.ts +147 -0
  261. package/src/ci-evidence-from-job.ts +195 -0
  262. package/src/ci-evidence-jobs.ts +85 -10
  263. package/src/ci-handover.ts +16 -3
  264. package/src/ci-identity.test.ts +3 -3
  265. package/src/ci-identity.ts +51 -11
  266. package/src/ci-image.test.ts +60 -10
  267. package/src/ci-image.ts +78 -19
  268. package/src/ci-jobs.ts +7 -2
  269. package/src/ci-login.test.ts +131 -3
  270. package/src/ci-login.token-drop.test.ts +204 -0
  271. package/src/ci-login.ts +137 -39
  272. package/src/ci-product-words.ts +30 -0
  273. package/src/ci-product.ts +26 -1
  274. package/src/cli/commands/__fixtures__/source-dir-root/migrations/0001-init/backfill.ts +3 -0
  275. package/src/cli/handlers/approve-confirm.test.ts +35 -0
  276. package/src/cli/handlers/approve-confirm.ts +44 -0
  277. package/src/cli/handlers/build-source-dir.test.ts +4 -0
  278. package/src/cli/handlers/build.ts +20 -2
  279. package/src/cli/handlers/ci-check.ts +35 -13
  280. package/src/cli/handlers/ci-evidence-open.test.ts +164 -0
  281. package/src/cli/handlers/ci-evidence.ts +223 -24
  282. package/src/cli/handlers/ci-forge-check.ts +22 -9
  283. package/src/cli/handlers/generated-check.ts +39 -0
  284. package/src/cli/handlers/lifecycle.test.ts +20 -0
  285. package/src/cli/handlers/lifecycle.ts +4 -0
  286. package/src/cli/handlers/local-chant.ts +39 -1
  287. package/src/cli/handlers/pr.ts +43 -5
  288. package/src/cli/handlers/run-wave.ts +7 -0
  289. package/src/cli/main.ts +38 -4
  290. package/src/cli/parse-args.ts +46 -0
  291. package/src/cli/registry.ts +24 -0
  292. package/src/components/check-hooks.ts +25 -3
  293. package/src/components/check-report-summary.test.ts +78 -0
  294. package/src/components/check-steps.ts +1 -1
  295. package/src/components/pr-checks.ts +159 -0
  296. package/src/components/pr-pipeline.ts +41 -1
  297. package/src/components/product-pipeline.ts +25 -3
  298. package/src/components/product-plan.test.ts +102 -1
  299. package/src/components/product-plan.ts +419 -14
  300. package/src/config.ts +13 -8
  301. package/src/control/consumers.ts +7 -0
  302. package/src/dead-guards.test.ts +27 -5
  303. package/src/dead-guards.ts +9 -6
  304. package/src/discovery/files.ts +1 -1
  305. package/src/drift-issue.test.ts +29 -1
  306. package/src/drift-issue.ts +28 -3
  307. package/src/drift-record.test.ts +25 -0
  308. package/src/drift-record.ts +55 -6
  309. package/src/floor-table.data.ts +58 -20
  310. package/src/floor-table.ts +12 -9
  311. package/src/forge-check/contract.ts +11 -1
  312. package/src/forge-check/forge-check.test.ts +8 -0
  313. package/src/forge-check/index.ts +2 -0
  314. package/src/forge-flags.test.ts +25 -1
  315. package/src/forge-flags.ts +34 -0
  316. package/src/forge-remote.test.ts +37 -0
  317. package/src/forge-remote.ts +79 -0
  318. package/src/generated-check.e2e.test.ts +98 -0
  319. package/src/generated-check.test.ts +104 -0
  320. package/src/generated-check.ts +269 -0
  321. package/src/lexicon.ts +17 -0
  322. package/src/lifecycle/publish-npm.ts +56 -3
  323. package/src/lifecycle/release-catalog.test.ts +2 -2
  324. package/src/lifecycle/release-images-dockerfile.test.ts +20 -0
  325. package/src/lifecycle/release-images.test.ts +44 -0
  326. package/src/lifecycle/release-images.ts +39 -3
  327. package/src/lifecycle/release-ledger.ts +4 -3
  328. package/src/local-chant.e2e.test.ts +81 -6
  329. package/src/local-chant.test.ts +22 -3
  330. package/src/local-chant.ts +130 -13
  331. package/src/op/op-waves-evidence-jobs.ts +134 -0
  332. package/src/op/op-waves-evidence.test.ts +37 -4
  333. package/src/op/op-waves-evidence.ts +32 -11
  334. package/src/op/op-waves-run.ts +57 -2
  335. package/src/op/op-waves.ts +11 -0
  336. package/src/op/schedule-overdue.test.ts +83 -1
  337. package/src/op/schedule-overdue.ts +107 -9
  338. package/src/pr-forge-reads-compare.test.ts +2 -1
  339. package/src/pr-forge-reads.ts +37 -1
  340. package/src/pr-forge.ts +14 -3
  341. package/src/pr-plan-note.ts +32 -3
  342. package/src/pr-plan-record.test.ts +75 -0
  343. package/src/pr-plan-record.ts +101 -0
  344. package/src/pr-post-plan-note.test.ts +60 -0
  345. package/src/pr-post.test.ts +30 -0
  346. package/src/pr-post.ts +110 -6
  347. package/src/pr-requires.test.ts +20 -0
  348. package/src/pr-requires.ts +10 -1
  349. package/src/ref-gate-init.ts +189 -0
  350. package/src/ref-gate-rules.ts +26 -0
  351. package/src/release-floors.ts +88 -16
  352. package/src/state-migration-record.test.ts +90 -0
  353. package/src/state-migration.test.ts +1 -1
  354. package/src/state-migration.ts +52 -3
  355. package/src/state-unlock.test.ts +33 -1
  356. package/src/state-unlock.ts +49 -1
  357. package/src/workspace/ci-green-cli.ts +12 -6
  358. package/src/workspace/ci-green.ts +4 -3
  359. package/src/workspace/drift-cli.ts +6 -18
  360. package/src/workspace/forge-work.ts +7 -14
  361. package/src/workspace/lexicon-outputs.ts +2 -2
  362. package/src/workspace/release-workflow.test.ts +70 -0
  363. package/src/workspace/release-workflow.ts +56 -8
  364. package/src/workspace/trust/check-evidence-report.ts +33 -0
  365. package/src/workspace/trust/check-evidence.test.ts +3 -3
  366. package/src/workspace/trust/check-evidence.ts +110 -28
  367. package/src/workspace/trust/ci-tag-statement.ts +2 -2
  368. package/src/workspace/trust/dsse.ts +48 -4
  369. package/src/workspace/trust/evidence.ts +7 -2
  370. package/src/workspace/trust/keyless-fixture.ts +214 -0
  371. package/src/workspace/trust/keyless.test.ts +220 -0
  372. package/src/workspace/trust/keyless.ts +557 -0
  373. package/src/workspace/trust/local-evidence.ts +3 -1
  374. package/src/workspace/trust/op-run-statement.ts +2 -2
  375. package/src/workspace/trust/open-evidence.ts +129 -0
  376. package/src/workspace/trust/policy.ts +129 -2
  377. package/src/workspace/trust/ref-gate-cli.ts +59 -3
  378. package/src/workspace/trust/ref-gate-pieces.test.ts +175 -0
  379. package/src/workspace/trust/ref-gate.e2e.test.ts +17 -0
  380. package/src/workspace/trust/ref-gate.ts +90 -8
  381. package/src/workspace/trust/run-statement.ts +3 -3
  382. package/src/workspace/trust/runner-identity.ts +92 -0
  383. package/src/workspace/trust/trust-files.test.ts +6 -0
  384. package/src/workspace/trust/trust-files.ts +14 -1
@@ -1,5 +1,5 @@
1
- import { spawnSync } from "node:child_process";
2
- import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
1
+ import { spawn, spawnSync } from "node:child_process";
2
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { dirname, join, resolve } from "node:path";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -26,14 +26,15 @@ const write = (file: string, body: string | object) => {
26
26
  writeFileSync(file, typeof body === "string" ? body : JSON.stringify(body, null, 2) + "\n");
27
27
  };
28
28
 
29
- /** A chant checkout whose core and k8s lexicon are already built (dist/ in place, no prepack). */
30
- function checkout(): string {
29
+ /** A chant checkout whose core and k8s lexicon are already built (dist/ in place, no prepack); `next` writes a NEXT_RELEASE into its release-floors.ts. */
30
+ function checkout(next?: string): string {
31
31
  const dir = mkdtempSync(join(tmpdir(), "chant-4787-e2e-checkout-"));
32
32
  write(join(dir, "package.json"), { name: "chant-monorepo", private: true, workspaces: ["packages/*", "lexicons/*"] });
33
33
  write(join(dir, "packages/core/package.json"), { name: "@intentius/chant", version: "2.0.0", type: "module", files: ["dist/"], exports: { ".": { import: "./dist/index.js" } } });
34
34
  write(join(dir, "packages/core/dist/index.js"), "export const local = true;\n");
35
35
  write(join(dir, "lexicons/k8s/package.json"), { name: "@intentius/chant-lexicon-k8s", version: "2.0.0", type: "module", files: ["dist/"], exports: { ".": { default: "./dist/index.js" } }, peerDependencies: { "@intentius/chant": "2.0.0" } });
36
36
  write(join(dir, "lexicons/k8s/dist/index.js"), "export {};\n");
37
+ if (next) write(join(dir, "packages/core/src/release-floors.ts"), `export const NEXT_RELEASE = "${next}";\n`);
37
38
  // A lock for the checkout's npm ci: workspaces only, so npm writes it offline.
38
39
  const lock = spawnSync("npm", ["install", "--package-lock-only", "--offline", "--no-audit", "--no-fund"], { cwd: dir, encoding: "utf8" });
39
40
  if (lock.status !== 0) throw new Error(`npm install --package-lock-only: ${lock.stderr}`);
@@ -55,8 +56,11 @@ function product(): string {
55
56
  return dir;
56
57
  }
57
58
 
58
- const chant = (cwd: string, ...args: string[]) =>
59
- spawnSync(process.execPath, ["--import", tsxLoader, mainTs, ...args], { cwd, encoding: "utf8", env: { ...process.env, NO_COLOR: "1", npm_config_offline: "true" }, timeout: 110_000 });
59
+ const chant = (cwd: string, ...args: (string | { env: Record<string, string> })[]) => {
60
+ const extra = args.find((a): a is { env: Record<string, string> } => typeof a !== "string");
61
+ const argv = args.filter((a): a is string => typeof a === "string");
62
+ return spawnSync(process.execPath, ["--import", tsxLoader, mainTs, ...argv], { cwd, encoding: "utf8", env: { ...process.env, NO_COLOR: "1", npm_config_offline: "true", ...extra?.env }, timeout: 110_000 });
63
+ };
60
64
 
61
65
  describe("chant dev local (#4787)", () => {
62
66
  it("packs a checkout into a product, keeps its manifests and lock, builds, and checks the bundle", () => {
@@ -91,4 +95,75 @@ describe("chant dev local (#4787)", () => {
91
95
  expect(r.status).toBe(2);
92
96
  expect(r.stderr).toContain("chant dev local needs a chant checkout");
93
97
  }, 60_000);
98
+
99
+ it("keeps a dev dependency's peers and installs the checkout at its next release (#4921)", async () => {
100
+ const repo = checkout("2.1.0");
101
+ const dir = product();
102
+ // A test runner whose peer (vitest's vite, say) npm installs from the registry.
103
+ const vendor = join(dir, "vendor/tester");
104
+ write(join(vendor, "package.json"), { name: "tester", version: "1.0.0", peerDependencies: { helper: "^1.0.0" } });
105
+ const packed = spawnSync("npm", ["pack", "--silent", "--pack-destination", join(dir, "vendor")], { cwd: vendor, encoding: "utf8" });
106
+ expect(packed.status).toBe(0);
107
+ const root = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
108
+ root.devDependencies.tester = "file:vendor/tester-1.0.0.tgz";
109
+ write(join(dir, "package.json"), root);
110
+ const registry = await startRegistry(dir);
111
+ try {
112
+ const env = { npm_config_registry: registry.url, npm_config_offline: "false" };
113
+ const build = "mkdir -p packages/app/dist && printf 'import { local } from \"@intentius/chant\";\\n' > packages/app/dist/app.mjs";
114
+ const r = chant(dir, "dev", "local", repo, "--build", build, "--json", { env });
115
+ expect(r.stderr).not.toContain("ERESOLVE");
116
+ expect(r.status).toBe(0);
117
+ expect(existsSync(join(dir, "node_modules/helper/package.json"))).toBe(true);
118
+
119
+ const core = JSON.parse(readFileSync(join(dir, "node_modules/@intentius/chant/package.json"), "utf8"));
120
+ expect(core.version).toBe("2.1.0");
121
+ const lexicon = JSON.parse(readFileSync(join(dir, "node_modules/@intentius/chant-lexicon-k8s/package.json"), "utf8"));
122
+ expect(lexicon.version).toBe("2.1.0");
123
+ expect(lexicon.peerDependencies["@intentius/chant"]).toBe("2.1.0");
124
+ const out = JSON.parse(r.stdout);
125
+ expect(out.local.packed).toEqual([
126
+ { name: "@intentius/chant", version: "2.1.0" },
127
+ { name: "@intentius/chant-lexicon-k8s", version: "2.1.0" },
128
+ ]);
129
+ } finally {
130
+ registry.stop();
131
+ }
132
+ }, 120_000);
94
133
  });
134
+
135
+ /** A registry on localhost, in its own process, that serves `helper` 1.0.0. */
136
+ async function startRegistry(dir: string): Promise<{ url: string; stop: () => void }> {
137
+ const helper = join(dir, "vendor/helper");
138
+ write(join(helper, "package.json"), { name: "helper", version: "1.0.0" });
139
+ const packed = spawnSync("npm", ["pack", "--silent", "--pack-destination", join(dir, "vendor")], { cwd: helper, encoding: "utf8" });
140
+ if (packed.status !== 0) throw new Error(`npm pack helper: ${packed.stderr}`);
141
+ const server = join(dir, "vendor/registry.mjs");
142
+ write(
143
+ server,
144
+ `import { createServer } from "node:http";
145
+ import { readFileSync } from "node:fs";
146
+ import { createHash } from "node:crypto";
147
+ const tgz = readFileSync(${JSON.stringify(join(dir, "vendor/helper-1.0.0.tgz"))});
148
+ const s = createServer((req, res) => {
149
+ const base = "http://127.0.0.1:" + s.address().port;
150
+ if (req.url === "/helper") {
151
+ res.setHeader("content-type", "application/json");
152
+ res.end(JSON.stringify({ name: "helper", "dist-tags": { latest: "1.0.0" }, versions: { "1.0.0": { name: "helper", version: "1.0.0", dist: { tarball: base + "/helper-1.0.0.tgz", shasum: createHash("sha1").update(tgz).digest("hex") } } } }));
153
+ } else if (req.url === "/helper-1.0.0.tgz") {
154
+ res.end(tgz);
155
+ } else {
156
+ res.statusCode = 404;
157
+ res.end("{}");
158
+ }
159
+ });
160
+ s.listen(0, "127.0.0.1", () => console.log(s.address().port));
161
+ `,
162
+ );
163
+ const child = spawn(process.execPath, [server], { stdio: ["ignore", "pipe", "inherit"] });
164
+ const port = await new Promise<string>((ok, fail) => {
165
+ child.stdout.once("data", (b: Buffer) => ok(b.toString().trim()));
166
+ child.once("exit", (code) => fail(new Error(`the registry exited ${code}`)));
167
+ });
168
+ return { url: `http://127.0.0.1:${port}/`, stop: () => child.kill() };
169
+ }
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from
2
2
  import { tmpdir } from "node:os";
3
3
  import { basename, dirname, join } from "node:path";
4
4
  import { describe, expect, it } from "vitest";
5
- import { chantPackages, installLocalChant, LocalChantError, lockMismatches, packOrder, pointAtTarballs, productChantNames, productManifests, type Runner } from "./local-chant";
5
+ import { chantPackages, installLocalChant, LocalChantError, localChantVersion, lockMismatches, packOrder, pointAtTarballs, productChantNames, productManifests, type Runner } from "./local-chant";
6
6
 
7
7
  /** #4787: what terragucci's and plywood's scripts/chant-local.sh did, as chant's `chant dev local`. */
8
8
 
@@ -60,10 +60,26 @@ describe("the packages to pack (#4787)", () => {
60
60
  const root = pointAtTarballs({ dependencies: { "@intentius/chant": "1.0.0" } }, local, true);
61
61
  expect(root).toEqual({ dependencies: { "@intentius/chant": "file:/t/a.tgz" }, devDependencies: { "@intentius/chant-lexicon-k8s": "file:/t/b.tgz" } });
62
62
  });
63
+
64
+ it("gives a peer on a packed package its packed version (#4921)", () => {
65
+ const local = new Map([["@intentius/chant", "file:/t/a.tgz"]]);
66
+ const app = pointAtTarballs({ peerDependencies: { "@intentius/chant": "1.0.0", vitest: ">=2" } }, local, false, new Map([["@intentius/chant", "2.1.0"]]));
67
+ expect(app.peerDependencies).toEqual({ "@intentius/chant": "2.1.0", vitest: ">=2" });
68
+ });
69
+ });
70
+
71
+ describe("localChantVersion (#4921)", () => {
72
+ it("is the checkout's NEXT_RELEASE when it is newer than core's package.json version", () => {
73
+ const chant = checkout();
74
+ expect(localChantVersion(chant, "2.0.0")).toBe("2.0.0");
75
+ write(join(chant, "packages/core/src/release-floors.ts"), 'export const NEXT_RELEASE = "2.1.0";\n');
76
+ expect(localChantVersion(chant, "2.0.0")).toBe("2.1.0");
77
+ expect(localChantVersion(chant, "2.2.0")).toBe("2.2.0");
78
+ });
63
79
  });
64
80
 
65
81
  /** A runner standing in for npm: pack writes a versioned tarball; install copies each `file:` dependency the manifests name into node_modules. */
66
- function fakeNpm(seen: { manifests?: string[]; calls: string[] }, opts: { installVersion?: string } = {}): Runner {
82
+ function fakeNpm(seen: { manifests?: string[]; calls: string[]; installArgs?: string[] }, opts: { installVersion?: string } = {}): Runner {
67
83
  return (command, args, cwd) => {
68
84
  seen.calls.push(`${command} ${args[0]} ${basename(cwd)}`);
69
85
  if (args[0] === "pack") {
@@ -73,6 +89,7 @@ function fakeNpm(seen: { manifests?: string[]; calls: string[] }, opts: { instal
73
89
  return `${file}\n`;
74
90
  }
75
91
  if (args[0] === "install") {
92
+ seen.installArgs = args;
76
93
  seen.manifests = productManifests(cwd).map((f) => readFileSync(join(cwd, f), "utf8"));
77
94
  for (const f of productManifests(cwd)) {
78
95
  const p = JSON.parse(readFileSync(join(cwd, f), "utf8"));
@@ -95,11 +112,13 @@ describe("installLocalChant (#4787)", () => {
95
112
  const chant = checkout();
96
113
  const dir = product();
97
114
  const before = ["package.json", "packages/app/package.json", "package-lock.json"].map((f) => readFileSync(join(dir, f), "utf8"));
98
- const seen: { manifests?: string[]; calls: string[] } = { calls: [] };
115
+ const seen: { manifests?: string[]; calls: string[]; installArgs?: string[] } = { calls: [] };
99
116
  const r = installLocalChant({ productDir: dir, chantDir: chant, install: false, run: fakeNpm(seen), log: () => {} });
100
117
 
101
118
  expect(r.packed.map((p) => p.dir)).toEqual(["packages/core", "lexicons/k8s"]);
102
119
  expect(seen.calls).toEqual(["npm pack core", "npm pack k8s", `npm install ${basename(dir)}`]);
120
+ // #4921: peers stay installed.
121
+ expect(seen.installArgs).not.toContain("--legacy-peer-deps");
103
122
  expect(existsSync(join(dir, ".chant-local/intentius-chant.tgz"))).toBe(true);
104
123
  expect(existsSync(join(dir, ".chant-local/intentius-chant-2.0.0.tgz"))).toBe(false);
105
124
  // During the install every manifest named the tarballs.
@@ -11,11 +11,13 @@
11
11
  * follows the packages it builds against ({@link packOrder});
12
12
  * 2. `npm ci` in the checkout when its lock changed since the last run, then
13
13
  * `npm pack` each package (its prepack builds it) into `.chant-local/` in
14
- * the product, under a fixed name per package;
14
+ * the product, under a fixed name per package, at the checkout's next
15
+ * release ({@link localChantVersion}, #4921);
15
16
  * 3. point every package.json of the product at the tarballs, run
16
17
  * `npm install --no-save`, and put the manifests and package-lock.json
17
18
  * back byte for byte, so the workspace gets the local build everywhere and
18
- * git sees no change;
19
+ * git sees no change. The install keeps peer dependencies (#4921), so a
20
+ * test runner's peers stay installed;
19
21
  * 4. mark each installed copy's package.json with `chantLocal` (the commit and
20
22
  * the checkout), which `checkBundle` and a reader use to tell the local
21
23
  * build from the pin, and fail when a copy is not the local build.
@@ -25,7 +27,8 @@
25
27
  */
26
28
  import { spawnSync } from "node:child_process";
27
29
  import { createHash } from "node:crypto";
28
- import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
30
+ import { existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
31
+ import { tmpdir } from "node:os";
29
32
  import { join, relative, resolve } from "node:path";
30
33
 
31
34
  /** A chant workspace package that can be packed: not private. */
@@ -140,6 +143,54 @@ export function packOrder(pkgs: Map<string, ChantPackage>, want: Iterable<string
140
143
  return out;
141
144
  }
142
145
 
146
+ /** `a` against `b` as `x.y.z` versions, prerelease ignored: negative when `a` is older. */
147
+ function compareCore(a: string, b: string): number {
148
+ const pa = a.split(/[-+]/)[0]!.split(".").map(Number);
149
+ const pb = b.split(/[-+]/)[0]!.split(".").map(Number);
150
+ for (let i = 0; i < 3; i++) if ((pa[i] ?? 0) !== (pb[i] ?? 0)) return (pa[i] ?? 0) - (pb[i] ?? 0);
151
+ return 0;
152
+ }
153
+
154
+ /**
155
+ * The version `chant dev local` packs a checkout at (#4921): the checkout's
156
+ * `NEXT_RELEASE` (packages/core/src/release-floors.ts), the release its
157
+ * floors name, when that is newer than core's package.json version. A
158
+ * checkout's package.json keeps the version of the last time it was bumped by
159
+ * hand (0.124.34 while 0.124.87 was out), which failed a product's floor and
160
+ * `minReader` checks that pass on a published chant. Every floor the checkout
161
+ * declares is at or below `NEXT_RELEASE`, so the local build passes each one.
162
+ * The build is marked local by the `chantLocal` field on each installed copy,
163
+ * not in the version, because a prerelease of `NEXT_RELEASE` sorts below it.
164
+ */
165
+ export function localChantVersion(chantDir: string, coreVersion: string): string {
166
+ const f = join(chantDir, "packages/core/src/release-floors.ts");
167
+ const next = existsSync(f) ? /export const NEXT_RELEASE = "(\d+\.\d+\.\d+)"/.exec(readFileSync(f, "utf8"))?.[1] : undefined;
168
+ return next !== undefined && compareCore(next, coreVersion) > 0 ? next : coreVersion;
169
+ }
170
+
171
+ /**
172
+ * Set the version of one packed tarball's package.json, and every chant
173
+ * dependency, peer and optional dependency it names among `versions` to that
174
+ * package's packed version, so the packages npm installs agree with each
175
+ * other (#4921). The tarball is unpacked under the OS temp directory, which is
176
+ * left for the OS to clear, and packed again in place. Nothing is run when
177
+ * the manifest already says all of it.
178
+ */
179
+ export function restampTarball(tarball: string, versions: Map<string, string>, run: Runner): void {
180
+ const stage = mkdtempSync(join(tmpdir(), "chant-dev-local-"));
181
+ run("tar", ["-xzf", tarball, "-C", stage], stage);
182
+ const f = join(stage, "package", "package.json");
183
+ const p = readManifest(f);
184
+ const before = JSON.stringify(p);
185
+ if (p.name && versions.has(p.name)) p.version = versions.get(p.name)!;
186
+ for (const k of ["dependencies", "peerDependencies", "optionalDependencies"] as const) {
187
+ for (const n of Object.keys(p[k] ?? {})) if (versions.has(n)) p[k]![n] = versions.get(n)!;
188
+ }
189
+ if (JSON.stringify(p) === before) return;
190
+ writeFileSync(f, `${JSON.stringify(p, null, 2)}\n`);
191
+ run("tar", ["-czf", tarball, "-C", stage, "package"], stage);
192
+ }
193
+
143
194
  /** The fixed tarball name for a package, so a later run replaces it: `@intentius/chant-lexicon-k8s` is `intentius-chant-lexicon-k8s.tgz`. */
144
195
  export const tarballName = (name: string) => `${name.replace(/^@/, "").replace(/\//g, "-")}.tgz`;
145
196
 
@@ -148,15 +199,18 @@ export const tarballName = (name: string) => `${name.replace(/^@/, "").replace(/
148
199
  * and optionalDependency `local` names takes its `file:` spec. The root also
149
200
  * gets every tarball as a devDependency, so npm replaces a copy only a lexicon
150
201
  * reaches (a lexicon's own chant dependencies) instead of keeping a registry
151
- * release of it.
202
+ * release of it. A peerDependency on a packed package takes its packed
203
+ * version from `versions` (#4921), so the install needs no
204
+ * `--legacy-peer-deps`.
152
205
  */
153
- export function pointAtTarballs(manifest: Manifest, local: Map<string, string>, isRoot: boolean): Manifest {
206
+ export function pointAtTarballs(manifest: Manifest, local: Map<string, string>, isRoot: boolean, versions: Map<string, string> = new Map()): Manifest {
154
207
  const p: Manifest = structuredClone(manifest);
155
208
  for (const k of ["dependencies", "devDependencies", "optionalDependencies"] as const) {
156
209
  const deps = p[k];
157
210
  if (!deps) continue;
158
211
  for (const n of Object.keys(deps)) if (local.has(n)) deps[n] = local.get(n)!;
159
212
  }
213
+ for (const n of Object.keys(p.peerDependencies ?? {})) if (versions.has(n)) p.peerDependencies![n] = versions.get(n)!;
160
214
  if (isRoot) {
161
215
  const extra = Object.fromEntries([...local].filter(([n]) => !(n in (p.dependencies ?? {})) && !(n in (p.optionalDependencies ?? {}))));
162
216
  p.devDependencies = { ...p.devDependencies, ...extra };
@@ -186,9 +240,10 @@ export function installedChantCopies(productDir: string): { at: string; name: st
186
240
  /** How a command runs: throws {@link LocalChantError} when it exits non-zero. */
187
241
  export type Runner = (command: string, args: string[], cwd: string) => string;
188
242
 
189
- /** Run a command with its stderr on ours and its stdout returned. */
243
+ /** Run a command with its stderr on ours and its stdout returned. macOS tar is told not to add `._` metadata files. */
190
244
  export const defaultRunner: Runner = (command, args, cwd) => {
191
- const r = spawnSync(command, args, { cwd, stdio: ["ignore", "pipe", "inherit"], encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
245
+ const env = command === "tar" ? { ...process.env, COPYFILE_DISABLE: "1" } : process.env;
246
+ const r = spawnSync(command, args, { cwd, env, stdio: ["ignore", "pipe", "inherit"], encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
192
247
  if (r.error) throw new LocalChantError(`${command} ${args.join(" ")} in ${cwd}: ${r.error.message}`);
193
248
  if (r.status !== 0) throw new LocalChantError(`${command} ${args.join(" ")} in ${cwd} exited ${r.status ?? r.signal}`);
194
249
  return r.stdout;
@@ -255,6 +310,10 @@ export function installLocalChant(opts: LocalChantOptions): LocalChantResult {
255
310
 
256
311
  const outDir = join(productDir, ".chant-local");
257
312
  mkdirSync(join(outDir, "manifests"), { recursive: true });
313
+ // #4921: every package at the checkout's next release, which a product's floor checks accept.
314
+ const version = localChantVersion(chantDir, pkgs.get("@intentius/chant")?.version ?? order[0]!.version);
315
+ const stamped = new Map(order.map((p) => [p.name, version]));
316
+ const restamp = order.some((p) => p.version !== version);
258
317
  const packed: LocalChantResult["packed"] = [];
259
318
  for (const p of order) {
260
319
  log(`packing ${p.dir}`);
@@ -263,29 +322,34 @@ export function installLocalChant(opts: LocalChantOptions): LocalChantResult {
263
322
  if (!file || !existsSync(join(outDir, file))) throw new LocalChantError(`npm pack in ${p.dir} wrote no tarball`);
264
323
  const fixed = tarballName(p.name);
265
324
  if (file !== fixed) renameSync(join(outDir, file), join(outDir, fixed));
266
- packed.push({ ...p, tarball: join(outDir, fixed) });
325
+ if (restamp) restampTarball(join(outDir, fixed), stamped, run);
326
+ packed.push({ ...p, version, tarball: join(outDir, fixed) });
267
327
  }
328
+ if (restamp) log(`packed at ${version}, the checkout's next release; each installed copy is marked chantLocal`);
268
329
  writeFileSync(join(outDir, "commit"), `${mark.commit}\n`);
269
330
  writeFileSync(join(outDir, "packages.json"), `${JSON.stringify(packed.map((p) => ({ name: p.name, version: p.version, tarball: relative(productDir, p.tarball) })), null, 2)}\n`);
270
331
 
271
332
  // The workspace packages pin chant too, so installing at the root alone
272
333
  // would leave the pinned copies nested under packages/*/node_modules. Point
273
334
  // every package.json at the tarballs for one install and put each file
274
- // back afterwards, the lock with them. --legacy-peer-deps because the pinned
275
- // lexicons still in the tree want the pinned core as a peer until npm
276
- // replaces them.
335
+ // back afterwards, the lock with them. Peers are installed as npm always
336
+ // does (#4921): --legacy-peer-deps dropped a test runner's peers (vitest's
337
+ // vite, rolldown, lightningcss). The packed versions are the next release,
338
+ // which the pinned lexicons' `^` peers on core accept, and each manifest's
339
+ // peers on chant name the packed version.
277
340
  const local = new Map(packed.map((p) => [p.name, `file:${p.tarball}`]));
341
+ const packedVersions = new Map(packed.map((p) => [p.name, p.version]));
278
342
  const files = [...productManifests(productDir), ...(existsSync(join(productDir, "package-lock.json")) ? ["package-lock.json"] : [])];
279
343
  const saved = new Map(files.map((f) => [f, readFileSync(join(productDir, f))]));
280
344
  for (const [f, body] of saved) writeFileSync(join(outDir, "manifests", f.replace(/\//g, "_")), body);
281
345
  try {
282
346
  for (const f of files) {
283
347
  if (!f.endsWith("package.json")) continue;
284
- const p = pointAtTarballs(JSON.parse(saved.get(f)!.toString("utf8")) as Manifest, local, f === "package.json");
348
+ const p = pointAtTarballs(JSON.parse(saved.get(f)!.toString("utf8")) as Manifest, local, f === "package.json", packedVersions);
285
349
  writeFileSync(join(productDir, f), `${JSON.stringify(p, null, 2)}\n`);
286
350
  }
287
351
  log(`installing ${packed.length} tarballs with npm install --no-save`);
288
- run("npm", ["install", "--no-save", "--no-audit", "--no-fund", "--legacy-peer-deps"], productDir);
352
+ run("npm", ["install", "--no-save", "--no-audit", "--no-fund"], productDir);
289
353
  } finally {
290
354
  for (const [f, body] of saved) writeFileSync(join(productDir, f), body);
291
355
  }
@@ -339,3 +403,56 @@ export function resetLocalChant(opts: { productDir: string; log?: (line: string)
339
403
  const bad = lockMismatches(dir);
340
404
  if (bad.length) throw new LocalChantError(`node_modules does not match package-lock.json after npm ci:\n ${bad.join("\n ")}`);
341
405
  }
406
+
407
+ /** What a product's image build needs to install the chant the product has (#4909). */
408
+ export interface LocalChantImage {
409
+ /** The chant the image installs: the root's pin, or `local-<commit>` for a `chant dev local` build. */
410
+ version: string;
411
+ /** The mark, when the installed chant is a local build. */
412
+ local?: LocalChantMark;
413
+ /** The tarball directory the image installs from, when local: `<product>/.chant-local`. */
414
+ context?: string;
415
+ /**
416
+ * `docker build` arguments: `--build-arg CHANT_VERSION=<version>`, and for a
417
+ * local build `--build-context chant-local=<product>/.chant-local`, which
418
+ * the Dockerfile's `chant-local` stage (`FROM scratch AS chant-local`)
419
+ * stands in for when the chant is the pin.
420
+ */
421
+ args: string[];
422
+ }
423
+
424
+ /**
425
+ * The chant a product's image should install (#4909): the local build when
426
+ * `chant dev local` marked the installed `@intentius/chant`, else the root's
427
+ * pin. terragucci's stack/bootstrap.sh read the `chantLocal` mark with jq,
428
+ * checked `.chant-local/` for its tarballs and built the
429
+ * `--build-context` itself. For a local build every package in `with` (core
430
+ * is always one) must have its tarball, of the commit the mark names; a
431
+ * missing one is a {@link LocalChantError} that says to run `chant dev local`
432
+ * again with `--with`.
433
+ */
434
+ export function localChantImage(productDir: string, opts: { with?: string[]; buildArg?: string; contextName?: string } = {}): LocalChantImage {
435
+ const dir = resolve(productDir);
436
+ const buildArg = opts.buildArg ?? "CHANT_VERSION";
437
+ const contextName = opts.contextName ?? "chant-local";
438
+ const coreFile = join(dir, "node_modules/@intentius/chant/package.json");
439
+ if (!existsSync(coreFile)) throw new LocalChantError(`@intentius/chant is not installed in ${dir}; run npm ci`);
440
+ const core = readManifest(coreFile);
441
+ if (core.chantLocal) {
442
+ const outDir = join(dir, ".chant-local");
443
+ const commitFile = join(outDir, "commit");
444
+ const commit = existsSync(commitFile) ? readFileSync(commitFile, "utf8").trim() : undefined;
445
+ if (commit !== core.chantLocal.commit) {
446
+ throw new LocalChantError(`node_modules has the local chant ${core.chantLocal.commit}, but .chant-local/ holds ${commit ? `the tarballs of ${commit}` : "no tarballs"}; run chant dev local again`);
447
+ }
448
+ const names = ["@intentius/chant", ...(opts.with ?? [])];
449
+ const missing = names.filter((n) => !existsSync(join(outDir, tarballName(n))));
450
+ if (missing.length) throw new LocalChantError(`.chant-local/ has no tarball for ${missing.join(", ")}; run chant dev local again with ${missing.map((n) => `--with ${n}`).join(" ")}`);
451
+ const version = `local-${core.chantLocal.commit}`;
452
+ return { version, local: core.chantLocal, context: outDir, args: ["--build-context", `${contextName}=${outDir}`, "--build-arg", `${buildArg}=${version}`] };
453
+ }
454
+ const root = readManifest(join(dir, "package.json"));
455
+ const version = root.dependencies?.["@intentius/chant"] ?? root.devDependencies?.["@intentius/chant"] ?? core.version;
456
+ if (!version) throw new LocalChantError(`${coreFile} has no version`);
457
+ return { version, args: ["--build-arg", `${buildArg}=${version}`] };
458
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * How a generated waves pipeline signs each wave's checks (#4926), for the
3
+ * forge lexicons to render. No import beyond the spec's helpers and the
4
+ * claim file names, so the generators' bundles stay small.
5
+ *
6
+ * With a pipeline `evidence` identity, each wave's own or deciding job:
7
+ *
8
+ * - runs the wave's policy (`holds.policy`) as a step of its own before the
9
+ * command, `chant run wave --policy-only`; on GitLab, which reports no
10
+ * steps, as a `<wave job>-policy` job the wave job needs. Its result is
11
+ * the forge's to report, and `policy:<wave>` is signed from it alone.
12
+ * - is followed by `<wave job>-evidence`, which runs none of the change's
13
+ * code, reads the wave job's record through the forge and signs with
14
+ * `chant ci evidence sign --from-job`: `policy:<wave>` when the wave has a
15
+ * policy, and `plan:<wave>` too when the wave trades cloud credentials and
16
+ * signs keyless, since after the trade no step of the wave job may request
17
+ * the signing token (#4869).
18
+ * - signs `plan:<wave>` in its command step otherwise, as before (#4870).
19
+ *
20
+ * A wave with no policy and no keyless cloud trade renders as before.
21
+ * A later wave whose `evidence.requires` names a check an earlier wave's
22
+ * evidence job signs needs that job, so it reads the evidence once signed.
23
+ */
24
+
25
+ import { EVIDENCE_SOURCES_ENV, WAVE_EVIDENCE_ENV, type EvidenceSourceSpec } from "../ci-evidence-claims";
26
+ import { opWaveBinArgv, opWaveChecksDir, type OpWaveJob, type OpWavesSpec } from "./op-waves";
27
+
28
+ export { EVIDENCE_SOURCES_ENV, WAVE_EVIDENCE_ENV };
29
+
30
+ /** The `id` of a wave job's policy step on GitHub and Forgejo, which the command step's `if:` reads. */
31
+ export const OP_WAVE_POLICY_STEP_ID = "chant-policy";
32
+
33
+ /** How one wave job signs its checks (#4926). */
34
+ export interface OpWaveEvidencePlan {
35
+ /** The wave's two check names. */
36
+ plan: string;
37
+ policy: string;
38
+ /** The wave runs its policy as a step (GitLab: a job) of its own. */
39
+ policyStep: boolean;
40
+ /** `CHANT_WAVE_EVIDENCE` on the command step: `plan` signs plan only, `job` signs nothing there. Unset: as before. */
41
+ commandMode?: "plan" | "job";
42
+ /** The command step holds the signing identity (a key, or keyless with the job's own token). */
43
+ commandSigns: boolean;
44
+ /** The evidence job after the wave job, and the checks it signs. */
45
+ evidenceJob?: { name: string; checks: string[] };
46
+ }
47
+
48
+ /**
49
+ * What wave job `job` renders for its evidence, or undefined when the job
50
+ * signs nothing (a share or job group's job, or no `evidence` on the
51
+ * pipeline). `keylessCloud` is whether the job signs keyless and trades
52
+ * cloud credentials.
53
+ */
54
+ export function opWaveEvidencePlan(spec: Pick<OpWavesSpec, "holds" | "waves">, job: Pick<OpWaveJob, "kind" | "jobName" | "wave">, opts: { signs: boolean; keylessCloud: boolean }): OpWaveEvidencePlan | undefined {
55
+ if (!opts.signs || (job.kind !== "wave" && job.kind !== "decide")) return undefined;
56
+ const name = spec.waves[job.wave - 1]!.name;
57
+ const plan = `plan:${name}`;
58
+ const policy = `policy:${name}`;
59
+ const policyStep = spec.holds?.policy === true;
60
+ const checks = [...(opts.keylessCloud ? [plan] : []), ...(policyStep ? [policy] : [])];
61
+ if (checks.length === 0) return { plan, policy, policyStep, commandSigns: true };
62
+ return { plan, policy, policyStep, commandMode: opts.keylessCloud ? "job" : "plan", commandSigns: !opts.keylessCloud, evidenceJob: { name: `${job.jobName}-evidence`, checks } };
63
+ }
64
+
65
+ /** The GitLab job a wave's policy runs in (#4926). */
66
+ export function opWavePolicyJobName(job: Pick<OpWaveJob, "jobName">): string {
67
+ return `${job.jobName}-policy`;
68
+ }
69
+
70
+ /** The policy step's command: the wave job's own, with `--policy-only`. */
71
+ export function opWavePolicyCommand(job: Pick<OpWaveJob, "command">): string[] {
72
+ return [...job.command, "--policy-only"];
73
+ }
74
+
75
+ /** The policy step's name on GitHub and Forgejo, which the evidence job finds it by. */
76
+ export function opWavePolicyStepName(wave: number, name: string): string {
77
+ return `Check wave ${wave} (${name})'s plans against the policy`;
78
+ }
79
+
80
+ /**
81
+ * The evidence job's `CHANT_EVIDENCE_SOURCES`: on GitHub and Forgejo the
82
+ * command step for `plan:<wave>` and the policy step for `policy:<wave>`, by
83
+ * name; on GitLab the wave job and its policy job.
84
+ */
85
+ export function opWaveEvidenceSources(forge: "github" | "forgejo" | "gitlab", plan: OpWaveEvidencePlan, job: Pick<OpWaveJob, "jobName" | "wave">, waveName: string, commandStep: string): Record<string, EvidenceSourceSpec> {
86
+ const out: Record<string, EvidenceSourceSpec> = {};
87
+ for (const check of plan.evidenceJob?.checks ?? []) {
88
+ if (forge === "gitlab") out[check] = check === plan.policy ? { job: opWavePolicyJobName(job) } : {};
89
+ else out[check] = { step: check === plan.policy ? opWavePolicyStepName(job.wave, waveName) : commandStep };
90
+ }
91
+ return out;
92
+ }
93
+
94
+ /**
95
+ * The evidence job's lines (#4926): note the base and check it out, so the
96
+ * setup and the product's command after it are the base's code and none of
97
+ * the change's runs, then sign from the wave job. `sha` is the run's commit
98
+ * as the shell reads it; the first line keeps the base in
99
+ * {@link OP_WAVE_EVIDENCE_BASE_VAR}.
100
+ */
101
+ export function opWaveEvidenceLines(spec: Pick<OpWavesSpec, "name" | "base">, plan: OpWaveEvidencePlan, job: Pick<OpWaveJob, "jobName">, opts: { sha: string; bin?: string }): { checkout: string[]; sign: string[] } {
102
+ const base = spec.base ?? "HEAD^1";
103
+ const quoted = `'${base.replace(/'/g, "'\\''")}'`;
104
+ return {
105
+ checkout: [`${OP_WAVE_EVIDENCE_BASE_VAR}="$(git rev-parse --verify ${quoted}^{commit})" || exit 1`, `git checkout --quiet --detach "$${OP_WAVE_EVIDENCE_BASE_VAR}" || exit 1`],
106
+ sign: [
107
+ [
108
+ ...opWaveBinArgv(opts.bin),
109
+ "ci evidence sign --from-job",
110
+ job.jobName,
111
+ "--check-id",
112
+ plan.evidenceJob!.checks.join(","),
113
+ "--claims",
114
+ opWaveChecksDir(spec),
115
+ "--at",
116
+ opts.sha,
117
+ "--base",
118
+ `"$${OP_WAVE_EVIDENCE_BASE_VAR}"`,
119
+ ].join(" "),
120
+ ],
121
+ };
122
+ }
123
+
124
+ /** The variable the evidence job keeps the base commit in between its lines. */
125
+ export const OP_WAVE_EVIDENCE_BASE_VAR = "CHANT_EVIDENCE_BASE";
126
+
127
+ /**
128
+ * The evidence jobs each later wave job needs (#4926): those of earlier waves
129
+ * that sign a check `evidence.requires` names, by the wave's number.
130
+ */
131
+ export function opWaveEvidenceNeeds(spec: Pick<OpWavesSpec, "evidence">, plans: ReadonlyArray<{ wave: number; plan: OpWaveEvidencePlan | undefined }>): (wave: number) => string[] {
132
+ const requires = new Set(spec.evidence?.requires ?? []);
133
+ return (wave) => plans.filter((p) => p.wave < wave && p.plan?.evidenceJob && p.plan.evidenceJob.checks.some((c) => requires.has(c))).map((p) => p.plan!.evidenceJob!.name);
134
+ }
@@ -7,7 +7,8 @@
7
7
 
8
8
  import { execFileSync } from "node:child_process";
9
9
  import { generateKeyPairSync } from "node:crypto";
10
- import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
10
+ import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
11
+ import { readCheckClaimFile } from "../ci-evidence-claims";
11
12
  import { tmpdir } from "node:os";
12
13
  import { join } from "node:path";
13
14
  import { describe, expect, test } from "vitest";
@@ -36,14 +37,14 @@ const spec: OpWavesSpec = {
36
37
  };
37
38
 
38
39
  /** A base commit with the spec and a runner key in .chant/trust.json, and a merge on top of it. */
39
- function repo(): { cwd: string; base: string; head: string; pem: string } {
40
+ function repo(atBase: OpWavesSpec = spec): { cwd: string; base: string; head: string; pem: string } {
40
41
  const cwd = mkdtempSync(join(tmpdir(), "chant-4870-waves-"));
41
42
  const { privateKey } = generateKeyPairSync("ed25519");
42
43
  const pem = privateKey.export({ format: "pem", type: "pkcs8" }).toString();
43
44
  git(cwd, "init", "--quiet");
44
45
  mkdirSync(join(cwd, ".chant"));
45
46
  writeFileSync(join(cwd, ".chant/trust.json"), JSON.stringify({ schema: 1, runners: [{ principal: "ci", class: "runner", key: loadRunnerKey(pem).publicKey }] }));
46
- writeFileSync(join(cwd, "waves.json"), JSON.stringify(spec));
47
+ writeFileSync(join(cwd, "waves.json"), JSON.stringify(atBase));
47
48
  git(cwd, "add", ".");
48
49
  git(cwd, "commit", "--quiet", "-m", "base");
49
50
  const base = git(cwd, "rev-parse", "HEAD");
@@ -106,7 +107,7 @@ describe("evidence.requires (#4870)", () => {
106
107
 
107
108
  test("the same commit applies once its tree has current evidence for each required check", async () => {
108
109
  const { cwd, base, head, pem } = repo();
109
- await recordChecks(cwd, signChecks(cwd, head, [{ check: "plan" }, { check: "policy" }], runnerKeyEvidenceSigner(cwd, base, pem)), { push: false });
110
+ await recordChecks(cwd, await signChecks(cwd, head, [{ check: "plan" }, { check: "policy" }], runnerKeyEvidenceSigner(cwd, base, pem)), { push: false });
110
111
  const { result, ran } = await wave(cwd, head);
111
112
  expect(result.exitCode).toBe(0);
112
113
  expect(ran).toEqual(["network"]);
@@ -127,4 +128,36 @@ describe("evidence.requires (#4870)", () => {
127
128
  // No key, nothing signed and nothing said.
128
129
  expect(await signOpWaveChecks({ cwd, head, base, wave: "dev", policyRows: none, log: (l) => logs.push(l), env: {}, push: false })).toEqual([]);
129
130
  });
131
+
132
+ test("#4926: beside an evidence job the command step signs only its plan, or nothing, and leaves the plan's claim file", async () => {
133
+ const { cwd, base, head, pem } = repo();
134
+ const checksDir = join(cwd, "checks");
135
+ const passed = new Map([["network", { source: "ci.policy", result: "passed" as const, rules: [] }]]);
136
+ const env = { CHANT_RUNNER_KEY: pem, CHANT_WAVE_EVIDENCE: "plan" } as NodeJS.ProcessEnv;
137
+ expect(await signOpWaveChecks({ cwd, head, base, wave: "dev", planDigest: digest("1"), policyRows: passed, log: () => {}, env, push: false, checksDir })).toEqual(["plan:dev"]);
138
+ expect(readCheckClaimFile(checksDir, "plan:dev")).toEqual({ check: "plan:dev", passed: true, claim: digest("1") });
139
+ expect(await signOpWaveChecks({ cwd, head, base, wave: "dev", policyRows: passed, log: () => {}, env: { ...env, CHANT_WAVE_EVIDENCE: "job" }, push: false, checksDir })).toEqual([]);
140
+ });
141
+ });
142
+
143
+ describe("chant run wave --policy-only (#4926)", () => {
144
+ const policySpec: OpWavesSpec = { name: "roots", op: "tf-apply", step: { kind: "fake-apply", root: "{target}" }, waves: [{ name: "dev", runs: [{ target: "network" }], gate: "never" }] };
145
+
146
+ test("with no policy over the plans it fails, applies nothing, and its claim file says policy did not pass", async () => {
147
+ const { cwd, head } = repo(policySpec);
148
+ const { registry, ran } = fakeCapability();
149
+ const logs: string[] = [];
150
+ const result = await runOpWave({ spec: policySpec, specFile: "waves.json", wave: 1, policyOnly: true, cwd, head, show: atBase, gates: memoryGateLedgerPort(), capabilities: registry, runs, log: (l) => logs.push(l) });
151
+ expect(result.exitCode).toBe(CHANT_EXIT.failed);
152
+ expect(result.policyRows).toEqual([]);
153
+ expect(ran).toEqual([]);
154
+ expect(logs.at(-1)).toContain("no ci.policy ran over its plans");
155
+ expect(readCheckClaimFile(join(cwd, ".chant/op-waves/roots/checks"), "policy:dev")).toEqual({ check: "policy:dev", passed: false });
156
+ expect(existsSync(join(cwd, ".chant/op-waves/roots/outcomes/outcome-wave-1.json"))).toBe(false);
157
+ });
158
+
159
+ test("a share job has no policy step of its own", async () => {
160
+ const { cwd, head } = repo();
161
+ await expect(runOpWave({ spec: policySpec, specFile: "waves.json", wave: 1, policyOnly: true, share: 1, cwd, head, show: atBase, gates: memoryGateLedgerPort(), runs })).rejects.toThrow(/a share or job group's job has none/);
162
+ });
130
163
  });