@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
@@ -35,7 +35,8 @@ import { execFileSync, spawnSync } from "node:child_process";
35
35
  import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
36
36
  import { dirname, isAbsolute, join } from "node:path";
37
37
  import { verifyEvidence } from "./evidence.js";
38
- import { policyAtBase } from "./provenance.js";
38
+ import { policyAtBase, resolveBase } from "./provenance.js";
39
+ import { runnersAt } from "./policy.js";
39
40
  import { OVERRIDE_APPLIED, OVERRIDE_LEDGER, OVERRIDERS_PATH, decideOverride, overrideCommand, overridersAt, parseAppliedOverrides, } from "../../override-gate.js";
40
41
  import { parseGateLedger } from "../../lifecycle/gate-ledger.js";
41
42
  import { gateSignersAt } from "../../gate-decision.js";
@@ -103,6 +104,46 @@ export function rulesFor(policy, ref) {
103
104
  ...(overrides ? { overrides } : {}),
104
105
  };
105
106
  }
107
+ /**
108
+ * The ref gate's rules for `ref` from the policy at `base` (#4913), the same
109
+ * read {@link decideRefUpdate} makes, for a product that acts on them
110
+ * without deciding an update: an apply that waits for the status the gate
111
+ * sets (`@intentius/chant/ref-gate-rules`), or a forge check that requires
112
+ * it. `base` defaults as `check` and `status` default it: `origin/HEAD`,
113
+ * then `main`, then `master`. A base that names no commit is a problem; no
114
+ * base at all is no policy, so nothing is required.
115
+ */
116
+ export function refGateRulesAt(repo, opts) {
117
+ const resolved = resolveBase(repo, opts.base);
118
+ const none = { ref: opts.ref, base: resolved.commit, matched: false, status: null, checks: [] };
119
+ if (!resolved.commit)
120
+ return { ...none, problems: opts.base !== undefined && resolved.problem ? [resolved.problem] : [] };
121
+ const policy = policyAtBase(repo, resolved);
122
+ if (policy.problems.length > 0)
123
+ return { ...none, problems: [...policy.problems] };
124
+ const rules = rulesFor(policy, opts.ref);
125
+ if (!rules.matched)
126
+ return { ...none, problems: [] };
127
+ return { ref: opts.ref, base: resolved.commit, matched: true, status: rules.status, checks: rules.checks, ...(rules.overrides ? { overrides: rules.overrides } : {}), problems: [] };
128
+ }
129
+ /**
130
+ * The status a forge's default branch should require for the ref gate
131
+ * (#4913), for a forge check whose pipeline renders the `ref-gate` job: the
132
+ * policy's status for `refs/heads/<defaultBranch>`, read at
133
+ * `origin/<defaultBranch>` when the checkout has it, else at `HEAD`. With
134
+ * no rule for the branch the job sets no status, so none is required and
135
+ * `note` says so; a policy that can't be read is a `problem`.
136
+ */
137
+ export function refGateStatusFor(repo, defaultBranch) {
138
+ const remote = `refs/remotes/origin/${defaultBranch}`;
139
+ const rules = refGateRulesAt(repo, { ref: `refs/heads/${defaultBranch}`, base: commitOf(repo, remote) ? remote : "HEAD" });
140
+ if (rules.problems.length > 0)
141
+ return { problem: `the trust policy can't be read, so the ref gate sets no status to require: ${rules.problems.join("; ")}` };
142
+ if (!rules.matched || !rules.status) {
143
+ return { note: `no refs rule in .chant/trust.json${rules.base ? ` at ${rules.base.slice(0, 8)}` : ""} matches refs/heads/${defaultBranch}, so the ref-gate job sets no status there and none is required` };
144
+ }
145
+ return { status: rules.status };
146
+ }
106
147
  // ── evidence notes ───────────────────────────────────────────────────────
107
148
  /** The envelopes in a note's text: one per line, or the whole note as one envelope or an array of them. */
108
149
  export function parseEvidenceNote(text) {
@@ -186,7 +227,8 @@ function judgeCheck(repo, policy, envelopes, check, commit, tree) {
186
227
  let stale;
187
228
  let bad;
188
229
  for (const env of envelopes) {
189
- const v = verifyEvidence(env, policy.runners, repo, commit);
230
+ // #4869: keys and keyless identities; under keyless.since, keys only for a commit before it.
231
+ const v = verifyEvidence(env, runnersAt(policy, { repo, commit }), repo, commit);
190
232
  if (!v.ok) {
191
233
  if (claimedCheck(env) === check && !bad)
192
234
  bad = { code: v.code, reason: v.reason };
@@ -399,8 +441,23 @@ export function runPrePush(repo, stdin, opts = {}) {
399
441
  }
400
442
  // ── words ────────────────────────────────────────────────────────────────
401
443
  const short = (s) => (s ? s.slice(0, 8) : "(none)");
402
- /** What the gate says about one decision: each missing check and its command, and how to override a blocked one. */
403
- export function describeDecision(d) {
444
+ /**
445
+ * The command that records the request for an override of `d`'s blocked
446
+ * checks from a checkout (#4913): `check` for the same ref, commit and base
447
+ * the remote decided, so it reaches the same decision and records the
448
+ * request on `chant/lifecycle`, which a pre-receive hook can't move.
449
+ */
450
+ export function requestCommand(d) {
451
+ return `chant workspace ref-gate check --ref ${d.ref} --at ${d.new ?? "HEAD"}${d.base ? ` --base ${d.base}` : ""}`;
452
+ }
453
+ /**
454
+ * What the gate says about one decision: each missing check and its command,
455
+ * and how to override a blocked one. At `pre-receive` (#4913) the request
456
+ * can't be recorded where the decision is made, so the refusal prints the
457
+ * exact command that records it from the checkout, then the override and
458
+ * the push that spends it.
459
+ */
460
+ export function describeDecision(d, opts = {}) {
404
461
  const out = [];
405
462
  const verb = d.decision === "admit" ? "admitted" : "refused";
406
463
  out.push(`chant ref gate: ${verb} ${d.ref} ${short(d.old)}..${short(d.new)}`);
@@ -421,10 +478,20 @@ export function describeDecision(d) {
421
478
  const blocked = d.checks.filter((c) => c.action === "block" && (c.status === "missing" || c.status === "stale"));
422
479
  if (blocked.length > 0) {
423
480
  out.push(` Attach each check's evidence to ${short(d.new)} (chant workspace ref-gate attach --envelope <file> --at ${short(d.new)}) and push ${EVIDENCE_NOTES_REF} with the ref.`);
424
- out.push(` To let ${short(d.new)} through without a check, a person listed in ${OVERRIDERS_PATH} at base can override it once the request is recorded`);
425
- out.push(` (the pre-push hook records it, or chant workspace ref-gate check --ref ${d.ref} --at ${short(d.new)}):`);
426
- for (const c of blocked)
427
- out.push(` ${overrideCommand(c.subject, [c.check])}`);
481
+ if (opts.site === "pre-receive") {
482
+ out.push(` To let ${short(d.new)} through without a check, record the request for an override in your checkout (this remote can't):`);
483
+ out.push(` ${requestCommand(d)}`);
484
+ out.push(` then a person listed in ${OVERRIDERS_PATH} at base overrides each check:`);
485
+ for (const c of blocked)
486
+ out.push(` ${overrideCommand(c.subject, [c.check])}`);
487
+ out.push(` and the push goes again with chant/lifecycle: git push origin chant/lifecycle ${d.new ?? "HEAD"}:${d.ref}`);
488
+ }
489
+ else {
490
+ out.push(` To let ${short(d.new)} through without a check, a person listed in ${OVERRIDERS_PATH} at base can override it once the request is recorded`);
491
+ out.push(` (the pre-push hook records it, or ${requestCommand(d)}):`);
492
+ for (const c of blocked)
493
+ out.push(` ${overrideCommand(c.subject, [c.check])}`);
494
+ }
428
495
  }
429
496
  return out;
430
497
  }
@@ -25,7 +25,7 @@ import { z } from "zod";
25
25
  import type { RunEndLine, RunStartLine, RunView } from "../runs.js";
26
26
  import { type DsseEnvelope } from "./dsse.js";
27
27
  import type { KeyObject } from "node:crypto";
28
- import type { RunnerKey } from "./policy.js";
28
+ import type { Runner, RunnerKey } from "./policy.js";
29
29
  export declare const AGENT_RUN_PREDICATE = "https://intentius.io/chant/agent-run/v1";
30
30
  /** The statement a runner signs for a run. Strict, so a verifier never acts on a field it does not know. */
31
31
  export declare const runStatementSchema: z.ZodObject<{
@@ -103,7 +103,7 @@ export type RunStatementVerdict = {
103
103
  * well-formed statement whose signer is that key's principal, for this run,
104
104
  * and agreeing with its record. Never throws.
105
105
  */
106
- export declare function verifyRunStatement(envelope: unknown, runners: readonly RunnerKey[], run: RunView): RunStatementVerdict;
106
+ export declare function verifyRunStatement(envelope: unknown, runners: readonly Runner[], run: RunView): RunStatementVerdict;
107
107
  /** A run's attestation: its best statement, or why it has none. */
108
108
  export interface RunAttestation {
109
109
  /**
@@ -124,5 +124,5 @@ export interface RunAttestation {
124
124
  statements: RunStatementVerdict[];
125
125
  }
126
126
  /** Judge every statement the ledger holds for `run`. */
127
- export declare function attestRun(run: RunView, runners: readonly RunnerKey[]): RunAttestation;
127
+ export declare function attestRun(run: RunView, runners: readonly Runner[]): RunAttestation;
128
128
  //# sourceMappingURL=run-statement.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-statement.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/run-statement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAsD,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,eAAO,MAAM,mBAAmB,4C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CAAC;CAChB,CAAC;AAIN;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,GAAG,mBAAmB,CAuCnH;AAED,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC;IACrE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACjC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,iFAAiF;IACjF,IAAI,EAAE,uBAAuB,GAAG,IAAI,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,yDAAyD;IACzD,UAAU,EAAE,mBAAmB,EAAE,CAAC;CACnC;AAID,wDAAwD;AACxD,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,cAAc,CAqBlF"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The runner identity an init writes into `.chant/trust.json` (#4869).
3
+ *
4
+ * None of the CI products' inits wrote `.chant/trust.json`, a runner key
5
+ * or an identity, so a keyless runner had nowhere to come from. These are
6
+ * the pieces an init calls: {@link ciRunnerIdentity} names the identity the
7
+ * generated workflow signs as, on the forge it runs on, and
8
+ * {@link withRunnerIdentity} adds it to the file's text under `keyless`,
9
+ * with the principal in `roles.runner`, which ci tags and Op runs need.
10
+ *
11
+ * The subject is the certificate's subject alternative name the
12
+ * certificate authority writes for that job: on GitHub the workflow file at
13
+ * a ref (`https://github.com/<owner>/<repo>/<workflow path>@<ref>`), on
14
+ * GitLab the CI config at a ref (`<server>/<project>//<config path>@<ref>`).
15
+ * A Forgejo job's certificate comes from a private authority, whose
16
+ * issuer and subject the project names itself.
17
+ */
18
+ /** The trusted root an init points `keyless.trustedRoot` at, unless told. */
19
+ export declare const DEFAULT_TRUSTED_ROOT_PATH = ".chant/trusted_root.json";
20
+ /** One entry of `keyless.identities`. */
21
+ export interface KeylessIdentityEntry {
22
+ principal: string;
23
+ class: "runner" | "service";
24
+ issuer: string;
25
+ subject: string;
26
+ }
27
+ export interface CiRunnerIdentityInput {
28
+ forge: "github" | "gitlab" | "forgejo";
29
+ /** `owner/repo` on GitHub and Forgejo, the project path on GitLab. */
30
+ repository: string;
31
+ /** The workflow file (GitHub, Forgejo), such as `.github/workflows/chant-pr.yml`, or the CI config path (GitLab, default `.gitlab-ci.yml`). A `*` matches within the file name. */
32
+ workflow?: string;
33
+ /** The ref the job runs at. Default `refs/heads/main`. A pull request job runs at another ref, such as `refs/pull/*\/merge`. */
34
+ ref?: string;
35
+ /** The forge's URL. Default `https://github.com` or `https://gitlab.com`; required on Forgejo. */
36
+ server?: string;
37
+ /** The OIDC issuer. Default GitHub's or the GitLab server; required on Forgejo. */
38
+ issuer?: string;
39
+ /** The subject pattern, instead of the one the forge's job would have. Required on Forgejo. */
40
+ subject?: string;
41
+ /** Default `ci`. */
42
+ principal?: string;
43
+ }
44
+ /** The `keyless.identities` entry for the generated workflow's jobs on `forge`. Throws when the forge's identity cannot be worked out. */
45
+ export declare function ciRunnerIdentity(input: CiRunnerIdentityInput): KeylessIdentityEntry;
46
+ /**
47
+ * `.chant/trust.json`'s text (or none, for a new file) with `identity` under
48
+ * `keyless.identities` and its principal in `roles.runner`. An identity
49
+ * with the same issuer and subject is not added twice. `trustedRoot` is
50
+ * written when the file sets none. Throws when the result is not a valid
51
+ * trust config.
52
+ */
53
+ export declare function withRunnerIdentity(text: string | undefined, identity: KeylessIdentityEntry, opts?: {
54
+ trustedRoot?: string;
55
+ }): string;
56
+ //# sourceMappingURL=runner-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner-identity.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/runner-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,6EAA6E;AAC7E,eAAO,MAAM,yBAAyB,6BAA6B,CAAC;AAEpE,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IACvC,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAC;IACnB,mLAAmL;IACnL,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gIAAgI;IAChI,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kGAAkG;IAClG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID,0IAA0I;AAC1I,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,oBAAoB,CAiBnF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,oBAAoB,EAAE,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAaxI"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The runner identity an init writes into `.chant/trust.json` (#4869).
3
+ *
4
+ * None of the CI products' inits wrote `.chant/trust.json`, a runner key
5
+ * or an identity, so a keyless runner had nowhere to come from. These are
6
+ * the pieces an init calls: {@link ciRunnerIdentity} names the identity the
7
+ * generated workflow signs as, on the forge it runs on, and
8
+ * {@link withRunnerIdentity} adds it to the file's text under `keyless`,
9
+ * with the principal in `roles.runner`, which ci tags and Op runs need.
10
+ *
11
+ * The subject is the certificate's subject alternative name the
12
+ * certificate authority writes for that job: on GitHub the workflow file at
13
+ * a ref (`https://github.com/<owner>/<repo>/<workflow path>@<ref>`), on
14
+ * GitLab the CI config at a ref (`<server>/<project>//<config path>@<ref>`).
15
+ * A Forgejo job's certificate comes from a private authority, whose
16
+ * issuer and subject the project names itself.
17
+ */
18
+ import { trustConfigSchema } from "./policy.js";
19
+ /** The trusted root an init points `keyless.trustedRoot` at, unless told. */
20
+ export const DEFAULT_TRUSTED_ROOT_PATH = ".chant/trusted_root.json";
21
+ const trim = (u) => u.replace(/\/+$/, "");
22
+ /** The `keyless.identities` entry for the generated workflow's jobs on `forge`. Throws when the forge's identity cannot be worked out. */
23
+ export function ciRunnerIdentity(input) {
24
+ const ref = input.ref ?? "refs/heads/main";
25
+ const principal = input.principal ?? "ci";
26
+ if (!/^[^\s/][^\s]*\/[^\s]+$/.test(input.repository))
27
+ throw new Error(`repository ${JSON.stringify(input.repository)} is not an owner/name path`);
28
+ if (input.forge === "github") {
29
+ if (!input.workflow)
30
+ throw new Error("a GitHub runner identity names its workflow file, such as .github/workflows/chant-pr.yml");
31
+ const server = trim(input.server ?? "https://github.com");
32
+ return { principal, class: "runner", issuer: input.issuer ?? "https://token.actions.githubusercontent.com", subject: input.subject ?? `${server}/${input.repository}/${input.workflow}@${ref}` };
33
+ }
34
+ if (input.forge === "gitlab") {
35
+ const server = trim(input.server ?? "https://gitlab.com");
36
+ return { principal, class: "runner", issuer: input.issuer ?? server, subject: input.subject ?? `${server}/${input.repository}//${input.workflow ?? ".gitlab-ci.yml"}@${ref}` };
37
+ }
38
+ if (!input.issuer || !input.subject) {
39
+ throw new Error("a Forgejo job's certificate comes from the certificate authority the project runs, so its runner identity names that authority's issuer and the subject it writes");
40
+ }
41
+ return { principal, class: "runner", issuer: input.issuer, subject: input.subject };
42
+ }
43
+ /**
44
+ * `.chant/trust.json`'s text (or none, for a new file) with `identity` under
45
+ * `keyless.identities` and its principal in `roles.runner`. An identity
46
+ * with the same issuer and subject is not added twice. `trustedRoot` is
47
+ * written when the file sets none. Throws when the result is not a valid
48
+ * trust config.
49
+ */
50
+ export function withRunnerIdentity(text, identity, opts = {}) {
51
+ const config = text === undefined || text.trim() === "" ? { schema: 1 } : JSON.parse(text);
52
+ const keyless = config.keyless ?? { trustedRoot: opts.trustedRoot ?? DEFAULT_TRUSTED_ROOT_PATH, identities: [] };
53
+ if (!keyless.identities.some((i) => i.issuer === identity.issuer && i.subject === identity.subject))
54
+ keyless.identities = [...keyless.identities, identity];
55
+ const runners = config.roles?.runner ?? [];
56
+ const next = {
57
+ ...config,
58
+ roles: { ...(config.roles ?? {}), runner: runners.includes(identity.principal) ? runners : [...runners, identity.principal] },
59
+ keyless,
60
+ };
61
+ const parsed = trustConfigSchema.safeParse(next);
62
+ if (!parsed.success)
63
+ throw new Error(`the trust config with the runner identity is invalid: ${parsed.error.issues.map((i) => `${i.path.join(".") || "/"}: ${i.message}`).join("; ")}`);
64
+ return `${JSON.stringify(next, null, 2)}\n`;
65
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"trust-files.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/trust-files.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,0GAA0G;AAC1G,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,2BAA2B,CAAC;AAe7D,uEAAuE;AACvE,MAAM,WAAW,MAAM;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,kGAAkG;IAClG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,4DAA4D;AAC5D,MAAM,WAAW,cAA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AAE,MAAM,GAAG,SAAS,CAkD3D;AAED,8FAA8F;AAC9F,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAM9D;AASD,yEAAyE;AACzE,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAElD;AAOD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,EAAE,CAiH1D"}
@@ -175,7 +175,7 @@ export function trustConfigProblems(raw) {
175
175
  if (!ok)
176
176
  problems.push(`${field}: ${message}`);
177
177
  };
178
- check("/", only(raw, ["schema", "signers", "roles", "adopted", "runners", "passkeys", "admitted", "refs", "local"]), "unknown key");
178
+ check("/", only(raw, ["schema", "signers", "roles", "adopted", "runners", "keyless", "passkeys", "admitted", "refs", "local"]), "unknown key");
179
179
  check("schema", raw.schema === 1, "expected 1");
180
180
  check("signers", optional(raw.signers, isRepoPath), "a path inside the repository, with / separators and no ..");
181
181
  check("roles", optional(raw.roles, (r) => isObject(r) && Object.entries(r).every(([k, v]) => /^[a-z][a-z0-9-]*$/.test(k) && Array.isArray(v) && v.every(nonEmpty))), "role names to lists of principals");
@@ -183,6 +183,13 @@ export function trustConfigProblems(raw) {
183
183
  a.every((e) => isObject(e) && only(e, ["from", "to", "note"]) && optional(e.from, (f) => typeof f === "string" && FULL_COMMIT.test(f)) && typeof e.to === "string" && FULL_COMMIT.test(e.to) && optional(e.note, (n) => typeof n === "string"))), "commit ranges of full commit ids");
184
184
  check("runners", optional(raw.runners, (a) => Array.isArray(a) &&
185
185
  a.every((e) => isObject(e) && only(e, ["principal", "class", "key"]) && nonEmpty(e.principal) && (e.class === "runner" || e.class === "service") && typeof e.key === "string" && SSH_ED25519.test(e.key))), "runner keys: a principal, a class and an ssh-ed25519 key");
186
+ const httpUrl = (v) => typeof v === "string" && /^https?:\/\/[^\s]+$/.test(v);
187
+ check("keyless", optional(raw.keyless, (k) => isObject(k) && only(k, ["trustedRoot", "identities", "since", "fulcio", "timestamp", "audience"]) &&
188
+ isRepoPath(k.trustedRoot) &&
189
+ optional(k.since, (f) => typeof f === "string" && FULL_COMMIT.test(f)) &&
190
+ optional(k.fulcio, httpUrl) && optional(k.timestamp, httpUrl) && optional(k.audience, nonEmpty) &&
191
+ Array.isArray(k.identities) && k.identities.length > 0 &&
192
+ k.identities.every((e) => isObject(e) && only(e, ["principal", "class", "issuer", "subject"]) && nonEmpty(e.principal) && (e.class === "runner" || e.class === "service") && httpUrl(e.issuer) && nonEmpty(e.subject))), "keyless identities (#4869): a trusted root path and identities, each a principal, a class, an issuer URL and a subject pattern");
186
193
  const b64url = (v) => typeof v === "string" && /^[A-Za-z0-9_-]+$/.test(v);
187
194
  check("passkeys", optional(raw.passkeys, (a) => Array.isArray(a) &&
188
195
  a.every((e) => isObject(e) && only(e, ["principal", "id", "publicKey", "rpId", "origins"]) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.124.86",
3
+ "version": "0.124.88",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -49,6 +49,8 @@ export const ACTION_PINS = {
49
49
  setupBun2: pin("oven-sh/setup-bun", "v2", "0c5077e51419868618aeaa5fe8019c62421857d6", "v2.2.0"),
50
50
  golangciLint9: pin("golangci/golangci-lint-action", "v9", "ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a", "v9.3.0"),
51
51
  dockerLogin4: pin("docker/login-action", "v4", "81c6f93d4bc991e510b342a00b419b3bb4efc5c6", "v4.7.0"),
52
+ // #4876: the release workflow's QEMU binfmt setup for a `release.images` platform the runner can't run.
53
+ dockerSetupQemu4: pin("docker/setup-qemu-action", "v4", "99012661954931238ded8c8b007157a8430204e1", "v4.4.0"),
52
54
  dockerSetupBuildx4: pin("docker/setup-buildx-action", "v4", "f87e5991a6d7451dcb8d9637bfbc97413f497069", "v4.4.1"),
53
55
  dockerMetadata6: pin("docker/metadata-action", "v6", "dc802804100637a589fabce1cb79ff13a1411302", "v6.2.0"),
54
56
  dockerBuildPush7: pin("docker/build-push-action", "v7", "c3c9e263c25d99ce0380d002d59b67737d91b0dc", "v7.4.0"),
@@ -0,0 +1,12 @@
1
+ /** #4911: one actor fallback for the lexicons' gated requests and the products' requesters. */
2
+ import { expect, test } from "vitest";
3
+ import { actorFromEnv } from "./actor";
4
+
5
+ test("the forge's actor, then the login, then unknown", () => {
6
+ expect(actorFromEnv({ GITHUB_ACTOR: "octo", GITLAB_USER_LOGIN: "gl", USER: "me" })).toBe("octo");
7
+ expect(actorFromEnv({ GITLAB_USER_LOGIN: "gl", USER: "me" })).toBe("gl");
8
+ expect(actorFromEnv({ GITHUB_ACTOR: " ", USER: "me" })).toBe("me");
9
+ expect(actorFromEnv({ USERNAME: "win" })).toBe("win");
10
+ expect(actorFromEnv({})).toBe("unknown");
11
+ expect(actorFromEnv({}, "chant")).toBe("chant");
12
+ });
package/src/actor.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Who runs a command, when the caller names nobody (#4911): the forge's
3
+ * actor in a job (`GITHUB_ACTOR`, which Forgejo sets too, then
4
+ * `GITLAB_USER_LOGIN`), else the login (`USER`, `USERNAME` on Windows).
5
+ * The terraform and pulumi lexicons' gated requests and the products'
6
+ * requesters read it here rather than each writing the order.
7
+ */
8
+
9
+ /** The actor fallback's variables, in the order {@link actorFromEnv} reads them. */
10
+ export const ACTOR_ENV_ORDER = ["GITHUB_ACTOR", "GITLAB_USER_LOGIN", "USER", "USERNAME"] as const;
11
+
12
+ /** The first of {@link ACTOR_ENV_ORDER} set to something other than blanks, else `fallback` (default `unknown`). */
13
+ export function actorFromEnv(env: Record<string, string | undefined> = process.env, fallback = "unknown"): string {
14
+ for (const name of ACTOR_ENV_ORDER) {
15
+ const v = env[name]?.trim();
16
+ if (v) return v;
17
+ }
18
+ return fallback;
19
+ }
@@ -64,6 +64,28 @@ describe("chantRuntimeTarget (#4787)", () => {
64
64
  expect(cb!({ path: "@intentius/chant/ts-only" })).toBeUndefined();
65
65
  expect([...external]).toEqual(["@intentius/chant/notify"]);
66
66
  });
67
+
68
+ it("keeps external only the chant packages in the package's dependencies, or the ones it is given (#4922)", () => {
69
+ const { app, root } = product();
70
+ const lexicon = join(root, "node_modules/@intentius/chant-lexicon-k8s");
71
+ write(join(lexicon, "package.json"), { name: "@intentius/chant-lexicon-k8s", version: "1.2.3", exports: { ".": { import: "./dist/index.js" } } });
72
+ write(join(lexicon, "dist/index.js"), "export {};\n");
73
+ const resolver = (plugin: ReturnType<typeof chantExternalPlugin>) => {
74
+ let cb: ((a: { path: string }) => unknown) | undefined;
75
+ plugin.setup({ onResolve: (_o, f) => { cb = f; } });
76
+ return cb!;
77
+ };
78
+ // The app depends on @intentius/chant only, so the lexicon (a devDependency it bundles) stays in the bundle.
79
+ const byDeps = resolver(chantExternalPlugin(app));
80
+ expect(byDeps({ path: "@intentius/chant/notify" })).toEqual({ path: "@intentius/chant/notify", external: true });
81
+ expect(byDeps({ path: "@intentius/chant-lexicon-k8s" })).toBeUndefined();
82
+ // Named packages win over the dependencies.
83
+ const external = new Set<string>();
84
+ const named = resolver(chantExternalPlugin(app, { packages: ["@intentius/chant-lexicon-k8s"], external }));
85
+ expect(named({ path: "@intentius/chant-lexicon-k8s" })).toEqual({ path: "@intentius/chant-lexicon-k8s", external: true });
86
+ expect(named({ path: "@intentius/chant" })).toBeUndefined();
87
+ expect([...external]).toEqual(["@intentius/chant-lexicon-k8s"]);
88
+ });
67
89
  });
68
90
 
69
91
  describe("bundleImports (#4787)", () => {
@@ -113,18 +113,46 @@ export interface EsbuildPluginLike {
113
113
  }): void;
114
114
  }
115
115
 
116
+ /** What {@link chantExternalPlugin} keeps external, and where it records it. */
117
+ export interface ChantExternalOptions {
118
+ /**
119
+ * The chant packages whose imports may stay external (#4922). Default: the
120
+ * `@intentius/chant*` packages in the `dependencies` of `pkgDir`'s
121
+ * package.json, the ones an install of the published package brings. A
122
+ * product that bundles its lexicons (devDependencies) and depends only on
123
+ * `@intentius/chant` gets core external and the lexicons bundled.
124
+ */
125
+ packages?: Iterable<string>;
126
+ /** Collects the specifiers left external. */
127
+ external?: Set<string>;
128
+ }
129
+
130
+ /** The `@intentius/chant*` names in the `dependencies` of the package at `pkgDir`. */
131
+ function chantDependencies(pkgDir: string): string[] {
132
+ const f = join(pkgDir, "package.json");
133
+ if (!existsSync(f)) return [];
134
+ const deps = (JSON.parse(readFileSync(f, "utf8")) as { dependencies?: Record<string, string> }).dependencies ?? {};
135
+ return Object.keys(deps).filter((n) => CHANT.test(n));
136
+ }
137
+
116
138
  /**
117
139
  * An esbuild plugin that leaves an `@intentius/chant*` import external when
118
- * the chant installed for `pkgDir` (where the bin runs) serves it as compiled
119
- * JS, so the bundle runs the installed, pinned chant. Any other chant import
120
- * goes on to the next plugin and esbuild, which bundle it. `external`, when
121
- * given, collects the specifiers left external.
140
+ * its package is one of `options.packages` (by default the package's chant
141
+ * `dependencies`, #4922) and the chant installed for `pkgDir` (where the bin
142
+ * runs) serves it as compiled JS, so the bundle runs the installed, pinned
143
+ * chant. Any other chant import goes on to the next plugin and esbuild, which
144
+ * bundle it. A bundled lexicon's own imports of core come through here too.
145
+ * The second argument may still be the `external` set alone.
122
146
  */
123
- export function chantExternalPlugin(pkgDir: string, external?: Set<string>): EsbuildPluginLike {
147
+ export function chantExternalPlugin(pkgDir: string, options?: ChantExternalOptions | Set<string>): EsbuildPluginLike {
148
+ const opts: ChantExternalOptions = options instanceof Set ? { external: options } : (options ?? {});
149
+ const external = opts.external;
150
+ const keep = new Set(opts.packages ?? chantDependencies(pkgDir));
124
151
  return {
125
152
  name: "chant-external",
126
153
  setup(b) {
127
154
  b.onResolve({ filter: CHANT }, (args) => {
155
+ if (!keep.has(CHANT.exec(args.path)![1])) return undefined;
128
156
  if (chantRuntimeTarget(args.path, pkgDir) === undefined) return undefined;
129
157
  external?.add(args.path);
130
158
  return { path: args.path, external: true };
@@ -4,11 +4,30 @@
4
4
  * runs with, and plywood's resolve fallback for a repository with no chant.
5
5
  */
6
6
 
7
+ import { spawnSync } from "node:child_process";
7
8
  import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
8
9
  import { tmpdir } from "node:os";
9
10
  import { delimiter, join } from "node:path";
11
+ import { pathToFileURL } from "node:url";
10
12
  import { afterAll, describe, expect, test } from "vitest";
11
- import { bundledChant, CHANT_SPECIFIER, chantArgv, chantCommand, chantEnv, chantResolveFallback, installedChant } from "./chant-install";
13
+ import {
14
+ bareResolveFallback,
15
+ bundledChant,
16
+ CHANT_RUN_FLOOR,
17
+ CHANT_SPECIFIER,
18
+ chantArgv,
19
+ chantCommand,
20
+ chantEnv,
21
+ chantResolveFallback,
22
+ fallbackImportArgs,
23
+ fallbackParent,
24
+ hasNodeModulesAbove,
25
+ installedChant,
26
+ isBareSpecifier,
27
+ lastJsonLine,
28
+ runChant,
29
+ } from "./chant-install";
30
+ import { NEXT_RELEASE } from "./release-floors";
12
31
 
13
32
  const scratch = mkdtempSync(join(tmpdir(), "chant-install-"));
14
33
  afterAll(() => rmSync(scratch, { recursive: true, force: true }));
@@ -110,3 +129,92 @@ describe("chantResolveFallback", () => {
110
129
  expect(() => hook("@intentius/chant", { parentURL: from }, fail(missing))).toThrow("not found");
111
130
  });
112
131
  });
132
+
133
+ /** #4889: a file with no node_modules above it, outside every checkout and install. */
134
+ describe("the resolve fallback for any bare specifier (#4889)", () => {
135
+ const worktree = join(import.meta.dirname, "..", "..", "..");
136
+ const parent = pathToFileURL(join(worktree, "chant-resolve-fallback.js")).href;
137
+ const missing = Object.assign(new Error("not found"), { code: "ERR_MODULE_NOT_FOUND" });
138
+ const bare = join(scratch, "worktree");
139
+ mkdirSync(join(bare, "src"), { recursive: true });
140
+ const importer = pathToFileURL(join(bare, "src", "chant.config.ts")).href;
141
+
142
+ test("a bare specifier is a package name, nothing else", () => {
143
+ for (const s of ["semver", "@intentius/sql-yodeler", "@intentius/chant/op"]) expect(isBareSpecifier(s), s).toBe(true);
144
+ for (const s of ["./a.js", "../a.js", "/abs/a.js", "file:///a.js", "node:fs", "data:text/javascript,", "#internal"]) expect(isBareSpecifier(s), s).toBe(false);
145
+ });
146
+
147
+ test("the scratch worktree has no node_modules above it, and this file does", () => {
148
+ expect(hasNodeModulesAbove(importer)).toBe(false);
149
+ expect(hasNodeModulesAbove(pathToFileURL(import.meta.filename).href)).toBe(true);
150
+ expect(hasNodeModulesAbove("node:fs")).toBe(true);
151
+ });
152
+
153
+ test("fallbackParent is a file beside the node_modules holding chant, or chant's own file in a checkout", () => {
154
+ expect(fallbackParent("file:///opt/yodel/node_modules/@intentius/chant/dist/chant-install.js")).toBe("file:///opt/yodel/chant-resolve-fallback.js");
155
+ expect(fallbackParent("file:///src/chant/packages/core/src/chant-install.ts")).toBe("file:///src/chant/packages/core/src/chant-install.ts");
156
+ });
157
+
158
+ test("retries a bare import of a file with no install from the product's, and leaves the rest as Node reports them", () => {
159
+ const hook = bareResolveFallback(parent);
160
+ const seen: unknown[] = [];
161
+ const next = (specifier: string, context?: Record<string, unknown>) => {
162
+ seen.push(context?.parentURL);
163
+ if (context?.parentURL !== parent) throw missing;
164
+ return { url: `file:///product/node_modules/${specifier}/index.js` };
165
+ };
166
+ expect(hook("@intentius/sql-yodeler", { parentURL: importer }, next).url).toBe("file:///product/node_modules/@intentius/sql-yodeler/index.js");
167
+ expect(seen).toEqual([importer, parent]);
168
+ const fail = (e: Error) => () => {
169
+ throw e;
170
+ };
171
+ expect(() => hook("./local.js", { parentURL: importer }, fail(missing))).toThrow("not found");
172
+ expect(() => hook("left-pad", { parentURL: pathToFileURL(import.meta.filename).href }, fail(missing))).toThrow("not found");
173
+ expect(() => hook("left-pad", { parentURL: importer }, fail(new Error("syntax")))).toThrow("syntax");
174
+ });
175
+
176
+ test("fallbackImportArgs lets a child import a package from the product's install", () => {
177
+ const file = join(bare, "src", "uses-semver.mjs");
178
+ writeFileSync(file, 'import semver from "semver";\nconsole.log(semver.valid("1.2.3"));\n');
179
+ const without = spawnSync(process.execPath, [file], { encoding: "utf8" });
180
+ expect(without.status).not.toBe(0);
181
+ expect(without.stderr).toMatch(/Cannot find package 'semver'/);
182
+ const withIt = spawnSync(process.execPath, [...fallbackImportArgs(parent), file], { encoding: "utf8" });
183
+ expect(withIt.stderr).toBe("");
184
+ expect(withIt.stdout.trim()).toBe("1.2.3");
185
+ });
186
+ });
187
+
188
+ describe("runChant (#4889)", () => {
189
+ test("lastJsonLine is the last line that is a JSON object, or a pretty-printed document", () => {
190
+ expect(lastJsonLine('fold: 1 file folded\n{"a":1}\n{not json\n')).toEqual({ a: 1 });
191
+ expect(lastJsonLine('{"a":1}\nlog\n{"b":2}\n')).toEqual({ b: 2 });
192
+ expect(lastJsonLine('{\n "a": 2\n}\n')).toEqual({ a: 2 });
193
+ expect(lastJsonLine("no json here")).toBeUndefined();
194
+ });
195
+
196
+ test("runs the install's bin with this node, the fallback's --import and chant's bin first on PATH, and reads its --json document", async () => {
197
+ const root = pkg(join(scratch, "run", "node_modules", "@intentius", "chant"), { name: "@intentius/chant", version: "9.9.9", bin: { chant: "./bin/chant" } }, "bin/chant");
198
+ writeFileSync(
199
+ join(root, "bin", "chant"),
200
+ 'console.error("chant: working");\nconsole.log("a log line");\nconsole.log(JSON.stringify({ args: process.argv.slice(2), imports: process.execArgv.filter((a) => a.startsWith("data:")).length, path: process.env.PATH.split(require("path").delimiter)[0], color: process.env.NO_COLOR ?? null }));\nprocess.exit(3);\n',
201
+ );
202
+ const install = installedChant([join(scratch, "run")])!;
203
+ const chunks: string[] = [];
204
+ const ran = await runChant(["build", "--json"], { install, cwd: scratch, resolveFallback: true, noColor: true, onStderr: (t) => chunks.push(t) });
205
+ expect(ran.code).toBe(3);
206
+ expect(ran.stdout).toMatch(/^a log line\n/);
207
+ expect(ran.json).toEqual({ args: ["build", "--json"], imports: 1, path: install.binDir, color: "1" });
208
+ expect(chunks.join("")).toBe("chant: working\n");
209
+ });
210
+
211
+ test("a named chant runs as it is, and a child that cannot start rejects", async () => {
212
+ const ran = await runChant(["-e", "console.log(JSON.stringify({ ok: true }))"], { chant: process.execPath });
213
+ expect(ran).toMatchObject({ code: 0, json: { ok: true } });
214
+ await expect(runChant([], { chant: join(scratch, "no-such-chant") })).rejects.toThrow(/ENOENT/);
215
+ });
216
+
217
+ test("CHANT_RUN_FLOOR is the next release", () => {
218
+ expect(CHANT_RUN_FLOOR).toBe(NEXT_RELEASE);
219
+ });
220
+ });