@intentius/chant 0.124.88 → 0.124.90

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 (377) hide show
  1. package/dist/actor.d.ts +36 -1
  2. package/dist/actor.d.ts.map +1 -1
  3. package/dist/actor.js +39 -1
  4. package/dist/chant-install.d.ts.map +1 -1
  5. package/dist/chant-install.js +1 -2
  6. package/dist/ci-base.d.ts +30 -0
  7. package/dist/ci-base.d.ts.map +1 -0
  8. package/dist/ci-base.js +33 -0
  9. package/dist/ci-comment-commands.d.ts +193 -0
  10. package/dist/ci-comment-commands.d.ts.map +1 -0
  11. package/dist/ci-comment-commands.js +353 -0
  12. package/dist/ci-comment-replies.d.ts +40 -0
  13. package/dist/ci-comment-replies.d.ts.map +1 -0
  14. package/dist/ci-comment-replies.js +59 -0
  15. package/dist/ci-evidence-from-job.d.ts +25 -0
  16. package/dist/ci-evidence-from-job.d.ts.map +1 -1
  17. package/dist/ci-evidence-from-job.js +43 -2
  18. package/dist/ci-evidence-jobs.d.ts +30 -1
  19. package/dist/ci-evidence-jobs.d.ts.map +1 -1
  20. package/dist/ci-evidence-jobs.js +46 -3
  21. package/dist/ci-image.d.ts +21 -4
  22. package/dist/ci-image.d.ts.map +1 -1
  23. package/dist/ci-image.js +62 -10
  24. package/dist/ci-job-guard.d.ts +42 -45
  25. package/dist/ci-job-guard.d.ts.map +1 -1
  26. package/dist/ci-job-guard.js +206 -3
  27. package/dist/ci-note-commands.d.ts +104 -4
  28. package/dist/ci-note-commands.d.ts.map +1 -1
  29. package/dist/ci-note-commands.js +131 -38
  30. package/dist/ci-product-words.d.ts +42 -0
  31. package/dist/ci-product-words.d.ts.map +1 -1
  32. package/dist/ci-product-words.js +25 -0
  33. package/dist/ci-product.d.ts +72 -1
  34. package/dist/ci-product.d.ts.map +1 -1
  35. package/dist/ci-product.js +73 -6
  36. package/dist/cli/commands/build.d.ts.map +1 -1
  37. package/dist/cli/commands/build.js +29 -2
  38. package/dist/cli/handlers/approve.d.ts.map +1 -1
  39. package/dist/cli/handlers/approve.js +2 -1
  40. package/dist/cli/handlers/ci-check.d.ts +1 -1
  41. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  42. package/dist/cli/handlers/ci-check.js +17 -7
  43. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  44. package/dist/cli/handlers/ci-evidence.js +33 -7
  45. package/dist/cli/handlers/components.d.ts.map +1 -1
  46. package/dist/cli/handlers/components.js +3 -1
  47. package/dist/cli/handlers/generated-check.d.ts +8 -0
  48. package/dist/cli/handlers/generated-check.d.ts.map +1 -1
  49. package/dist/cli/handlers/generated-check.js +31 -1
  50. package/dist/cli/handlers/lock.d.ts.map +1 -1
  51. package/dist/cli/handlers/lock.js +121 -4
  52. package/dist/cli/handlers/pr-comment.d.ts +33 -0
  53. package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
  54. package/dist/cli/handlers/pr-comment.js +201 -0
  55. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  56. package/dist/cli/handlers/pr-env.js +6 -3
  57. package/dist/cli/handlers/pr-notes.d.ts.map +1 -1
  58. package/dist/cli/handlers/pr-notes.js +23 -1
  59. package/dist/cli/handlers/pr.d.ts +23 -1
  60. package/dist/cli/handlers/pr.d.ts.map +1 -1
  61. package/dist/cli/handlers/pr.js +71 -23
  62. package/dist/cli/handlers/promote.d.ts.map +1 -1
  63. package/dist/cli/handlers/promote.js +2 -1
  64. package/dist/cli/handlers/release.d.ts.map +1 -1
  65. package/dist/cli/handlers/release.js +11 -2
  66. package/dist/cli/handlers/run-wave.d.ts.map +1 -1
  67. package/dist/cli/handlers/run-wave.js +180 -4
  68. package/dist/cli/handlers/run.d.ts.map +1 -1
  69. package/dist/cli/handlers/run.js +2 -1
  70. package/dist/cli/main.d.ts.map +1 -1
  71. package/dist/cli/main.js +41 -2
  72. package/dist/cli/parse-args.d.ts.map +1 -1
  73. package/dist/cli/parse-args.js +31 -0
  74. package/dist/cli/registry.d.ts +19 -1
  75. package/dist/cli/registry.d.ts.map +1 -1
  76. package/dist/components/auto-release.d.ts.map +1 -1
  77. package/dist/components/auto-release.js +2 -1
  78. package/dist/components/pr-checks.d.ts +97 -6
  79. package/dist/components/pr-checks.d.ts.map +1 -1
  80. package/dist/components/pr-checks.js +107 -13
  81. package/dist/components/pr-pipeline.d.ts +19 -14
  82. package/dist/components/pr-pipeline.d.ts.map +1 -1
  83. package/dist/components/pr-pipeline.js +7 -13
  84. package/dist/components/product-pipeline.d.ts +96 -3
  85. package/dist/components/product-pipeline.d.ts.map +1 -1
  86. package/dist/components/product-pipeline.js +120 -14
  87. package/dist/components/product-plan.d.ts +203 -6
  88. package/dist/components/product-plan.d.ts.map +1 -1
  89. package/dist/components/product-plan.js +250 -43
  90. package/dist/drift-record.d.ts +7 -0
  91. package/dist/drift-record.d.ts.map +1 -1
  92. package/dist/drift-record.js +19 -0
  93. package/dist/floor-table.data.d.ts.map +1 -1
  94. package/dist/floor-table.data.js +63 -31
  95. package/dist/forge-check/contract.d.ts +11 -1
  96. package/dist/forge-check/contract.d.ts.map +1 -1
  97. package/dist/forge-check/contract.js +4 -1
  98. package/dist/forge-check/index.d.ts +2 -0
  99. package/dist/forge-check/index.d.ts.map +1 -1
  100. package/dist/forge-check/index.js +2 -0
  101. package/dist/gate-resume-run.d.ts +9 -1
  102. package/dist/gate-resume-run.d.ts.map +1 -1
  103. package/dist/gate-resume-run.js +26 -3
  104. package/dist/generated-check.d.ts +18 -4
  105. package/dist/generated-check.d.ts.map +1 -1
  106. package/dist/generated-check.js +37 -5
  107. package/dist/image-pins.d.ts +26 -0
  108. package/dist/image-pins.d.ts.map +1 -0
  109. package/dist/image-pins.js +19 -0
  110. package/dist/lexicon.d.ts +93 -4
  111. package/dist/lexicon.d.ts.map +1 -1
  112. package/dist/lifecycle/gate-applied.d.ts +9 -0
  113. package/dist/lifecycle/gate-applied.d.ts.map +1 -1
  114. package/dist/lifecycle/git.d.ts +11 -0
  115. package/dist/lifecycle/git.d.ts.map +1 -1
  116. package/dist/lifecycle/git.js +30 -3
  117. package/dist/lifecycle/publish-npm.d.ts +11 -0
  118. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  119. package/dist/lifecycle/publish-npm.js +27 -1
  120. package/dist/lifecycle/reach-locks.d.ts +131 -0
  121. package/dist/lifecycle/reach-locks.d.ts.map +1 -0
  122. package/dist/lifecycle/reach-locks.js +118 -0
  123. package/dist/lifecycle/release-cut.d.ts +3 -1
  124. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  125. package/dist/lifecycle/release-cut.js +15 -0
  126. package/dist/lifecycle/release-images.d.ts.map +1 -1
  127. package/dist/lifecycle/release-images.js +1 -2
  128. package/dist/notify-product.d.ts +12 -3
  129. package/dist/notify-product.d.ts.map +1 -1
  130. package/dist/notify-product.js +10 -6
  131. package/dist/op/activities/source-release.d.ts.map +1 -1
  132. package/dist/op/activities/source-release.js +2 -1
  133. package/dist/op/activities/source-rollback.d.ts.map +1 -1
  134. package/dist/op/activities/source-rollback.js +2 -1
  135. package/dist/op/apply-status.d.ts +84 -0
  136. package/dist/op/apply-status.d.ts.map +1 -0
  137. package/dist/op/apply-status.js +106 -0
  138. package/dist/op/before-merge-decide.d.ts +102 -0
  139. package/dist/op/before-merge-decide.d.ts.map +1 -0
  140. package/dist/op/before-merge-decide.js +142 -0
  141. package/dist/op/before-merge-done.d.ts +56 -0
  142. package/dist/op/before-merge-done.d.ts.map +1 -0
  143. package/dist/op/before-merge-done.js +69 -0
  144. package/dist/op/before-merge-store.d.ts +20 -0
  145. package/dist/op/before-merge-store.d.ts.map +1 -0
  146. package/dist/op/before-merge-store.js +48 -0
  147. package/dist/op/before-merge.d.ts +150 -0
  148. package/dist/op/before-merge.d.ts.map +1 -0
  149. package/dist/op/before-merge.js +207 -0
  150. package/dist/op/follow-on-run.d.ts +117 -0
  151. package/dist/op/follow-on-run.d.ts.map +1 -0
  152. package/dist/op/follow-on-run.js +154 -0
  153. package/dist/op/follow-on-store.d.ts +17 -0
  154. package/dist/op/follow-on-store.d.ts.map +1 -0
  155. package/dist/op/follow-on-store.js +54 -0
  156. package/dist/op/gate.d.ts +6 -0
  157. package/dist/op/gate.d.ts.map +1 -1
  158. package/dist/op/gate.js +10 -1
  159. package/dist/op/index.d.ts +5 -1
  160. package/dist/op/index.d.ts.map +1 -1
  161. package/dist/op/index.js +2 -0
  162. package/dist/op/op-waves-after-plan.d.ts +13 -0
  163. package/dist/op/op-waves-after-plan.d.ts.map +1 -1
  164. package/dist/op/op-waves-evidence-jobs.d.ts +10 -2
  165. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
  166. package/dist/op/op-waves-evidence-jobs.js +19 -5
  167. package/dist/op/op-waves-follow-on.d.ts +162 -0
  168. package/dist/op/op-waves-follow-on.d.ts.map +1 -0
  169. package/dist/op/op-waves-follow-on.js +355 -0
  170. package/dist/op/op-waves-render-spec.d.ts +100 -0
  171. package/dist/op/op-waves-render-spec.d.ts.map +1 -0
  172. package/dist/op/op-waves-render-spec.js +162 -0
  173. package/dist/op/op-waves-run.d.ts +148 -6
  174. package/dist/op/op-waves-run.d.ts.map +1 -1
  175. package/dist/op/op-waves-run.js +873 -100
  176. package/dist/op/op-waves-split.d.ts +122 -0
  177. package/dist/op/op-waves-split.d.ts.map +1 -0
  178. package/dist/op/op-waves-split.js +166 -0
  179. package/dist/op/op-waves.d.ts +24 -0
  180. package/dist/op/op-waves.d.ts.map +1 -1
  181. package/dist/op/op-waves.js +18 -1
  182. package/dist/op/schedule-overdue.d.ts +15 -1
  183. package/dist/op/schedule-overdue.d.ts.map +1 -1
  184. package/dist/op/schedule-overdue.js +77 -5
  185. package/dist/op/stage-hooks.d.ts +36 -1
  186. package/dist/op/stage-hooks.d.ts.map +1 -1
  187. package/dist/op/stage-hooks.js +17 -3
  188. package/dist/op/wave-stop.d.ts +67 -0
  189. package/dist/op/wave-stop.d.ts.map +1 -0
  190. package/dist/op/wave-stop.js +129 -0
  191. package/dist/planned-files.d.ts +76 -0
  192. package/dist/planned-files.d.ts.map +1 -0
  193. package/dist/planned-files.js +108 -0
  194. package/dist/pr-forge-job.d.ts +22 -0
  195. package/dist/pr-forge-job.d.ts.map +1 -0
  196. package/dist/pr-forge-job.js +46 -0
  197. package/dist/pr-loop.d.ts +3 -6
  198. package/dist/pr-loop.d.ts.map +1 -1
  199. package/dist/pr-loop.js +4 -81
  200. package/dist/pr-plan-note.d.ts +97 -0
  201. package/dist/pr-plan-note.d.ts.map +1 -1
  202. package/dist/pr-plan-note.js +94 -1
  203. package/dist/pr-post.d.ts +28 -3
  204. package/dist/pr-post.d.ts.map +1 -1
  205. package/dist/pr-post.js +146 -13
  206. package/dist/pr-status.d.ts +16 -0
  207. package/dist/pr-status.d.ts.map +1 -0
  208. package/dist/pr-status.js +90 -0
  209. package/dist/ref-gate-init.d.ts +16 -2
  210. package/dist/ref-gate-init.d.ts.map +1 -1
  211. package/dist/ref-gate-init.js +24 -13
  212. package/dist/release-floors.d.ts +39 -1
  213. package/dist/release-floors.d.ts.map +1 -1
  214. package/dist/release-floors.js +63 -25
  215. package/dist/render-module.d.ts +15 -0
  216. package/dist/render-module.d.ts.map +1 -0
  217. package/dist/render-module.js +73 -0
  218. package/dist/state-migration.d.ts.map +1 -1
  219. package/dist/state-migration.js +1 -2
  220. package/dist/wave-blocked.d.ts +7 -1
  221. package/dist/wave-blocked.d.ts.map +1 -1
  222. package/dist/wave-blocked.js +7 -2
  223. package/dist/wave-runtime.mjs +366 -350
  224. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  225. package/dist/workspace/ci-green-cli.js +3 -2
  226. package/dist/workspace/release-train.d.ts.map +1 -1
  227. package/dist/workspace/release-train.js +2 -1
  228. package/dist/workspace/release-workflow.d.ts +4 -3
  229. package/dist/workspace/release-workflow.d.ts.map +1 -1
  230. package/dist/workspace/release-workflow.js +10 -7
  231. package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
  232. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  233. package/dist/workspace/trust/check-evidence-report.js +15 -8
  234. package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
  235. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
  236. package/dist/workspace/trust/ref-gate-cli.js +30 -10
  237. package/dist/workspace/workspace-run.d.ts.map +1 -1
  238. package/dist/workspace/workspace-run.js +2 -1
  239. package/package.json +1 -1
  240. package/src/actor.test.ts +68 -2
  241. package/src/actor.ts +61 -1
  242. package/src/chant-install.test.ts +2 -3
  243. package/src/chant-install.ts +1 -2
  244. package/src/ci-base.test.ts +41 -0
  245. package/src/ci-base.ts +43 -0
  246. package/src/ci-comment-commands.test.ts +439 -0
  247. package/src/ci-comment-commands.ts +428 -0
  248. package/src/ci-comment-replies.ts +78 -0
  249. package/src/ci-commit.test.ts +2 -3
  250. package/src/ci-evidence-from-job.test.ts +18 -0
  251. package/src/ci-evidence-from-job.ts +58 -2
  252. package/src/ci-evidence-jobs.ts +50 -5
  253. package/src/ci-image.test.ts +130 -10
  254. package/src/ci-image.ts +85 -12
  255. package/src/ci-job-guard.before-merge.test.ts +148 -0
  256. package/src/ci-job-guard.follow-on-record.test.ts +137 -0
  257. package/src/ci-job-guard.follow-on.test.ts +144 -0
  258. package/src/ci-job-guard.ts +221 -3
  259. package/src/ci-note-commands.test.ts +76 -1
  260. package/src/ci-note-commands.ts +198 -46
  261. package/src/ci-product-words.ts +59 -0
  262. package/src/ci-product.ts +90 -6
  263. package/src/cli/commands/build.test.ts +41 -0
  264. package/src/cli/commands/build.ts +27 -2
  265. package/src/cli/handlers/approve.ts +2 -1
  266. package/src/cli/handlers/ci-check.ts +19 -7
  267. package/src/cli/handlers/ci-evidence.ts +29 -8
  268. package/src/cli/handlers/components.ts +3 -1
  269. package/src/cli/handlers/generated-check.ts +31 -1
  270. package/src/cli/handlers/lock-reach.test.ts +103 -0
  271. package/src/cli/handlers/lock.ts +100 -4
  272. package/src/cli/handlers/pr-comment.ts +187 -0
  273. package/src/cli/handlers/pr-env.ts +6 -3
  274. package/src/cli/handlers/pr-notes.ts +30 -6
  275. package/src/cli/handlers/pr-record.test.ts +1 -1
  276. package/src/cli/handlers/pr.ts +64 -21
  277. package/src/cli/handlers/promote.ts +2 -1
  278. package/src/cli/handlers/release.e2e.test.ts +35 -0
  279. package/src/cli/handlers/release.ts +14 -2
  280. package/src/cli/handlers/run-wave.ts +170 -4
  281. package/src/cli/handlers/run.ts +2 -1
  282. package/src/cli/main.ts +41 -2
  283. package/src/cli/parse-args.ts +23 -0
  284. package/src/cli/registry.ts +19 -1
  285. package/src/components/auto-release.ts +2 -1
  286. package/src/components/pr-checks.ts +165 -17
  287. package/src/components/pr-pipeline.ts +22 -18
  288. package/src/components/product-pipeline.apply-status.test.ts +50 -0
  289. package/src/components/product-pipeline.ts +204 -17
  290. package/src/components/product-plan.test.ts +60 -4
  291. package/src/components/product-plan.ts +367 -50
  292. package/src/drift-record.test.ts +20 -0
  293. package/src/drift-record.ts +16 -0
  294. package/src/floor-table.data.ts +63 -31
  295. package/src/forge-check/contract.ts +12 -1
  296. package/src/forge-check/forge-check.test.ts +17 -0
  297. package/src/forge-check/index.ts +2 -0
  298. package/src/gate-resume-run.ts +27 -3
  299. package/src/generated-check.e2e.test.ts +21 -1
  300. package/src/generated-check.test.ts +66 -0
  301. package/src/generated-check.ts +51 -10
  302. package/src/image-pins.ts +31 -0
  303. package/src/lexicon.ts +89 -1
  304. package/src/lifecycle/gate-applied.ts +7 -0
  305. package/src/lifecycle/git.test.ts +48 -0
  306. package/src/lifecycle/git.ts +27 -4
  307. package/src/lifecycle/publish-npm.ts +31 -1
  308. package/src/lifecycle/reach-locks.test.ts +87 -0
  309. package/src/lifecycle/reach-locks.ts +169 -0
  310. package/src/lifecycle/release-cut.ts +17 -1
  311. package/src/lifecycle/release-images.test.ts +56 -0
  312. package/src/lifecycle/release-images.ts +1 -2
  313. package/src/notify-product.ts +19 -8
  314. package/src/op/activities/source-release.ts +2 -1
  315. package/src/op/activities/source-rollback.ts +2 -1
  316. package/src/op/apply-status.test.ts +83 -0
  317. package/src/op/apply-status.ts +132 -0
  318. package/src/op/before-merge-decide.ts +190 -0
  319. package/src/op/before-merge-done.ts +99 -0
  320. package/src/op/before-merge-store.ts +44 -0
  321. package/src/op/before-merge.test.ts +201 -0
  322. package/src/op/before-merge.ts +266 -0
  323. package/src/op/follow-on-run.ts +206 -0
  324. package/src/op/follow-on-store.ts +54 -0
  325. package/src/op/gate-resume.test.ts +27 -0
  326. package/src/op/gate.ts +16 -1
  327. package/src/op/index.ts +15 -0
  328. package/src/op/op-waves-after-plan.ts +13 -0
  329. package/src/op/op-waves-evidence-jobs.ts +21 -7
  330. package/src/op/op-waves-follow-on-record.test.ts +152 -0
  331. package/src/op/op-waves-follow-on.test.ts +247 -0
  332. package/src/op/op-waves-follow-on.ts +385 -0
  333. package/src/op/op-waves-notify-words.test.ts +18 -0
  334. package/src/op/op-waves-render-spec.test.ts +159 -0
  335. package/src/op/op-waves-render-spec.ts +171 -0
  336. package/src/op/op-waves-run.ts +973 -94
  337. package/src/op/op-waves-split-product.test.ts +288 -0
  338. package/src/op/op-waves-split-step.test.ts +298 -0
  339. package/src/op/op-waves-split.test.ts +196 -0
  340. package/src/op/op-waves-split.ts +189 -0
  341. package/src/op/op-waves.ts +31 -3
  342. package/src/op/schedule-overdue.test.ts +72 -1
  343. package/src/op/schedule-overdue.ts +84 -6
  344. package/src/op/stage-hooks.ts +52 -4
  345. package/src/op/wave-stop.test.ts +72 -0
  346. package/src/op/wave-stop.ts +139 -0
  347. package/src/planned-files.test.ts +80 -0
  348. package/src/planned-files.ts +134 -0
  349. package/src/pr-forge-job.test.ts +53 -0
  350. package/src/pr-forge-job.ts +46 -0
  351. package/src/pr-loop-narrowed.test.ts +2 -1
  352. package/src/pr-loop-words.test.ts +2 -1
  353. package/src/pr-loop.test.ts +1 -2
  354. package/src/pr-loop.ts +4 -80
  355. package/src/pr-plan-note.ts +155 -3
  356. package/src/pr-post-replan.test.ts +144 -0
  357. package/src/pr-post-subject.test.ts +230 -0
  358. package/src/pr-post.test.ts +2 -1
  359. package/src/pr-post.ts +151 -15
  360. package/src/pr-status.ts +91 -0
  361. package/src/ref-gate-init.ts +30 -11
  362. package/src/release-floors.ts +81 -25
  363. package/src/render-module.ts +73 -0
  364. package/src/state-migration-record.test.ts +2 -3
  365. package/src/state-migration.ts +1 -2
  366. package/src/wave-blocked.ts +9 -4
  367. package/src/workspace/ci-green-cli.ts +3 -2
  368. package/src/workspace/ci-green-workflow.test.ts +32 -1
  369. package/src/workspace/release-train.ts +2 -1
  370. package/src/workspace/release-workflow.test.ts +36 -5
  371. package/src/workspace/release-workflow.ts +10 -7
  372. package/src/workspace/trust/check-evidence-report.ts +15 -8
  373. package/src/workspace/trust/check-evidence.test.ts +5 -0
  374. package/src/workspace/trust/ref-gate-cli.ts +30 -8
  375. package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
  376. package/src/workspace/trust/ref-gate.test.ts +10 -0
  377. package/src/workspace/workspace-run.ts +2 -1
@@ -34,7 +34,7 @@ import { sortedJsonReplacer } from "../../utils";
34
34
  import { rankFoldBlockers, toCollapsedFormat, type FoldRankResult } from "../../discovery/fold-rank";
35
35
  import { foldExecutionCounts } from "../../discovery/fold-import";
36
36
  import { formatError, formatWarning, formatSuccess, formatBold, formatInfo } from "../format";
37
- import { writeFileSync, mkdirSync } from "fs";
37
+ import { existsSync, statSync, writeFileSync, mkdirSync } from "fs";
38
38
  import { resolve, dirname, join, relative } from "path";
39
39
  import { watchDirectory, formatTimestamp, formatChangedFiles } from "../watch";
40
40
 
@@ -924,7 +924,32 @@ export async function buildCommand(options: BuildOptions): Promise<BuildResult>
924
924
  console.error(formatInfo(`Wrote ${irWritten} op.json file(s) under ${join(options.path ?? ".", "dist", "ops")}/`));
925
925
  }
926
926
 
927
- if (options.output) {
927
+ // #4950: `--output <dir>/` (or an existing directory) writes the
928
+ // additional files into that directory and no primary file, so a docker
929
+ // project of Dockerfiles alone renders them where they are committed
930
+ // (`chant build images -o images/`) with no compose file to throw away.
931
+ // A build whose primary output holds anything needs a file to put it in.
932
+ const outputDir =
933
+ options.output !== undefined && (/[\\/]$/.test(options.output) || (existsSync(options.output) && statSync(options.output).isDirectory()))
934
+ ? resolve(options.output)
935
+ : undefined;
936
+ if (outputDir !== undefined) {
937
+ if (output.trim() !== "") {
938
+ errors.push(
939
+ formatError({
940
+ message: `--output ${options.output} names a directory, which takes a build's additional files (a docker project's Dockerfiles) but not its primary output; this build has one, so name a file for it`,
941
+ }),
942
+ );
943
+ } else if (additionalFiles.size === 0) {
944
+ errors.push(formatError({ message: `--output ${options.output} names a directory, but this build has no files to write into it` }));
945
+ } else {
946
+ try {
947
+ for (const [filename, entry] of additionalFiles) writeOutput(join(outputDir, filename), entry.content);
948
+ } catch (err) {
949
+ errors.push(formatError({ message: `Failed to write output file: ${err instanceof Error ? err.message : String(err)}` }));
950
+ }
951
+ }
952
+ } else if (options.output) {
928
953
  // Write to file — ensure parent directories exist for both the primary
929
954
  // output path and any nested additional-file paths (e.g. ops/<name>/...).
930
955
  try {
@@ -35,6 +35,7 @@ import { readFileSync } from "node:fs";
35
35
  import { resolve as resolvePath } from "node:path";
36
36
  import { formatError, formatWarning, formatSuccess, formatInfo } from "../format";
37
37
  import type { CommandContext } from "../registry";
38
+ import { actorFromEnv } from "../../actor";
38
39
 
39
40
  // ── chant approve <op> <gate> ───────────────────────────────────────────────
40
41
 
@@ -623,7 +624,7 @@ async function approveGate(
623
624
  // "unattested" reads as what it is; a name the model chose would read in
624
625
  // the ledger exactly like a name a person gave.
625
626
  ? UNATTESTED_APPROVER
626
- : process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_LOGIN ?? process.env.USER ?? "unknown");
627
+ : actorFromEnv());
627
628
 
628
629
  // #2508: who this is, as the gate's quorum and policy read it. A model on
629
630
  // MCP or ACP is an agent whatever it claims, the same reasoning that gives
@@ -24,8 +24,13 @@
24
24
  * #4914: `--summary <file>` appends the report's markdown section
25
25
  * (`checkReportSummary`) to the file, as a product's check report keeps it,
26
26
  * and a job with `GITHUB_STEP_SUMMARY` set gets it in its summary too.
27
+ *
28
+ * #4966: `--base` defaults to the job's base (`ciBaseRef`,
29
+ * `@intentius/chant/ci-base`), `--branch` naming the default branch on a
30
+ * forge whose job does not carry it.
27
31
  */
28
32
  import { resolve } from "node:path";
33
+ import { ciBaseRef } from "../../ci-base";
29
34
  import type { CheckStageEvidence, CheckStepsAdapter } from "../../components/check-steps";
30
35
  import { CHANT_EXIT } from "../../exit-codes";
31
36
  import { formatError } from "../format";
@@ -49,7 +54,7 @@ async function lexiconCheckSteps(ctx: CommandContext, cwd: string): Promise<Chec
49
54
  return plugins.map((p) => p.checkSteps?.()).filter((a): a is CheckStepsAdapter => a !== undefined);
50
55
  }
51
56
 
52
- const USAGE = "chant ci check --base <rev> [<target>...] [--output <dir>] [--summary <file>] [--no-push] [--json]";
57
+ const USAGE = "chant ci check [--base <rev>] [--branch <default branch>] [<target>...] [--output <dir>] [--summary <file>] [--no-push] [--json]";
53
58
 
54
59
  /**
55
60
  * The check stage's signer (#4870), when the job has a runner identity: a
@@ -91,10 +96,17 @@ async function localEvidenceAt(base: string): Promise<{ base: string } | undefin
91
96
  }
92
97
  }
93
98
 
94
- export async function runCiCheck(ctx: CommandContext): Promise<number> {
99
+ export async function runCiCheck(ctx: CommandContext, env: Record<string, string | undefined> = process.env): Promise<number> {
95
100
  const { args } = ctx;
96
- if (!args.base) {
97
- console.error(formatError({ message: "chant ci check needs --base <rev>, the commit the change is measured from", hint: `${USAGE}. The hooks are read at base, so a change cannot remove a required check.` }));
101
+ // #4966: with no --base, the job's own (`ciBaseRef`): a pull request's target branch, else the default branch (--branch) for a push to another branch.
102
+ const base = args.base ?? ciBaseRef(env, args.branch ? { defaultBranch: args.branch } : {});
103
+ if (!base) {
104
+ console.error(
105
+ formatError({
106
+ message: "chant ci check needs --base <rev>, the commit the change is measured from, and the job names no pull request target or default branch to take it from",
107
+ hint: `${USAGE}. The hooks are read at base, so a change cannot remove a required check.`,
108
+ }),
109
+ );
98
110
  return 1;
99
111
  }
100
112
  const targets = (args.positionals ?? []).slice(1);
@@ -102,10 +114,10 @@ export async function runCiCheck(ctx: CommandContext): Promise<number> {
102
114
  let report;
103
115
  try {
104
116
  const adapters = await lexiconCheckSteps(ctx, process.cwd());
105
- const evidence = await checkEvidenceSigner(args.base, args.noPush === true);
117
+ const evidence = await checkEvidenceSigner(base, args.noPush === true);
106
118
  // #4868: a job that signs local evidence runs every hook; any other may skip one on local evidence.
107
- const local = evidence && "class" in evidence.signer ? undefined : await localEvidenceAt(args.base);
108
- report = await runCheckStage({ base: args.base, targets, adapters, ...(args.output ? { dir: args.output } : {}), ...(evidence ? { evidence } : {}), ...(local ? { localEvidence: local } : {}) });
119
+ const local = evidence && "class" in evidence.signer ? undefined : await localEvidenceAt(base);
120
+ report = await runCheckStage({ base, targets, adapters, ...(args.output ? { dir: args.output } : {}), ...(evidence ? { evidence } : {}), ...(local ? { localEvidence: local } : {}) });
109
121
  } catch (err) {
110
122
  console.error(formatError({ message: err instanceof Error ? err.message : String(err), hint: USAGE }));
111
123
  return CHANT_EXIT.failed;
@@ -14,7 +14,9 @@
14
14
  * `<dir>`, and `policy` when the policy evaluated inside that plan did not
15
15
  * deny it (a `pr-plan.json`'s `policy`, a plan note hand-off's overrides).
16
16
  * It writes `evidence.json` in `<dir>`, which `pr-post` reads to say in the
17
- * note which checks were signed.
17
+ * note which checks were signed. With `--member <name>` (#4964), a
18
+ * workspace member's plan report or (#4978) a product plan target's, the
19
+ * two are `plan:<name>` and `policy:<name>`.
18
20
  * - `sign --from-report <dir>` on a check job's report (#4935), a
19
21
  * `check-hooks.json` from `chant ci check`, is the `check-evidence` job's
20
22
  * form: it signs each hook that passed, by name, with the runs as its
@@ -50,6 +52,7 @@
50
52
  import { execFileSync, spawnSync } from "node:child_process";
51
53
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
52
54
  import { join } from "node:path";
55
+ import { EVIDENCE_MEMBER_NAME } from "../../ci-evidence-jobs";
53
56
  import { CHANT_EXIT } from "../../exit-codes";
54
57
  import { formatError } from "../format";
55
58
  import type { CommandContext } from "../registry";
@@ -68,8 +71,8 @@ import {
68
71
  import { CHECK_EVIDENCE_FILE, LOCAL_EVIDENCE_KEY_ENV, planReportChecks, type CheckEvidenceNote } from "../../workspace/trust/check-evidence-report";
69
72
 
70
73
  const USAGE =
71
- "chant ci evidence sign (--check-id <id>[,<id>...] | --from-report <dir> --result <result>) [--at <rev>] [--base <rev>] [--key <file>] [--claim <file>] [--no-push] [--json]\n" +
72
- " chant ci evidence sign --open --job <job> --from-report <dir> -o <out> [--branch <branch>] [--base <rev>] [--key <file>] [--no-push] [--json]\n" +
74
+ "chant ci evidence sign (--check-id <id>[,<id>...] | --from-report <dir> [--member <name>] --result <result>) [--at <rev>] [--base <rev>] [--key <file>] [--claim <file>] [--no-push] [--json]\n" +
75
+ " chant ci evidence sign --open --job <job> --from-report <dir> [--member <name>] -o <out> [--branch <branch>] [--base <rev>] [--key <file>] [--no-push] [--json]\n" +
73
76
  " chant ci evidence sign --from-job <job> --check-id <id>[,<id>...] [--claims <dir>] [--at <rev>] [--base <rev>] [--key <file>] [--no-push] [--json]\n" +
74
77
  " chant ci evidence sign --local --check-id <id>[,<id>...] [--at <rev>] [--base <rev>] [--key <file>] [--claim <file>] [--no-push] [--json]\n" +
75
78
  " chant ci evidence verify [--local] --check-id <id>[,<id>...] [--at <rev>] [--base <rev>] [--json]";
@@ -170,19 +173,34 @@ async function sign(ctx: CommandContext, repo: string, base: string, at: string)
170
173
  if (args.fromJob) return signFromJobCommand(ctx, repo, base);
171
174
  const fromReport = args.fromReport;
172
175
  if (!fromReport && idsOf(args.checkId).length === 0) return usage("sign needs --check-id <id>, or --from-report <dir> in a plan note job");
176
+ const member = memberOf(args.members, Boolean(fromReport));
177
+ if (typeof member === "object") return usage(member.usage);
173
178
  const pem = args.key ? readFileSync(args.key, "utf-8") : process.env[CHECK_EVIDENCE_KEY_ENV];
174
179
  let wanted: Array<{ check: string; claim?: Buffer | string }> | undefined;
175
180
  if (!fromReport) {
176
181
  const claim = args.claim ? readFileSync(args.claim) : undefined;
177
182
  wanted = idsOf(args.checkId).map((check) => ({ check, ...(claim ? { claim } : {}) }));
178
183
  }
179
- const done = await signChecksOf(repo, base, at, { ...(fromReport ? { fromReport } : {}), ...(wanted ? { wanted } : {}), ...(args.planResult ? { result: args.planResult } : {}), pem, push: !args.noPush });
184
+ const done = await signChecksOf(repo, base, at, { ...(fromReport ? { fromReport } : {}), ...(wanted ? { wanted } : {}), ...(args.planResult ? { result: args.planResult } : {}), ...(member ? { member } : {}), pem, push: !args.noPush });
180
185
  if ("usage" in done) return usage(done.usage);
181
186
  if (fromReport) writeFileSync(join(fromReport, CHECK_EVIDENCE_FILE), JSON.stringify(done.note, null, 2) + "\n");
182
187
  if (args.json) console.log(JSON.stringify(done.note, null, 2));
183
188
  return done.code;
184
189
  }
185
190
 
191
+ /**
192
+ * `--member <name>` (#4964): the workspace member whose plan report this is,
193
+ * or (#4978) the product plan target whose plan job wrote it, so `plan` and
194
+ * `policy` are signed as `plan:<name>` and `policy:<name>`. One name, and
195
+ * only with a plan report.
196
+ */
197
+ function memberOf(members: string[] | undefined, fromReport: boolean): string | undefined | { usage: string } {
198
+ if (!members || members.length === 0) return undefined;
199
+ if (!fromReport) return { usage: "--member names the member whose plan report --from-report signs; --check-id names its checks in full" };
200
+ if (members.length > 1 || !EVIDENCE_MEMBER_NAME.test(members[0]!)) return { usage: `--member takes one member or target name, letters, digits, - and _, not ${members.join(",")}` };
201
+ return members[0];
202
+ }
203
+
186
204
  /**
187
205
  * Sign the checks of a report directory (`fromReport`) or the named ones
188
206
  * (`wanted`) at `at`, against the runner identities at `base`. With
@@ -194,20 +212,21 @@ async function signChecksOf(
194
212
  repo: string,
195
213
  base: string,
196
214
  at: string,
197
- opts: { fromReport?: string; wanted?: Array<{ check: string; claim?: Buffer | string }>; result?: string; pem?: string; push: boolean; skipCurrent?: boolean },
215
+ opts: { fromReport?: string; wanted?: Array<{ check: string; claim?: Buffer | string }>; result?: string; member?: string; pem?: string; push: boolean; skipCurrent?: boolean },
198
216
  ): Promise<{ note: CheckEvidenceNote; code: number } | { usage: string }> {
199
217
  const { fromReport, pem } = opts;
200
218
  const identity = pem !== undefined && pem !== "" ? "key" : process.env[RUNNER_IDENTITY_ENV] ? "oidc" : undefined;
201
219
  const note: CheckEvidenceNote = { signed: [], skipped: [] };
202
220
  let wanted: Array<{ check: string; claim?: Buffer | string }>;
203
221
  if (fromReport && isCheckReportDir(fromReport)) {
204
- // #4935: a check job's report, each passed hook signed by name.
222
+ // #4935: a check job's report, each passed hook signed by name; #4964: a hook is the workspace's or the member's by its own name.
223
+ if (opts.member) return { usage: `--member names a plan report's member, and ${fromReport} is a check job's report, whose hooks are signed by their own names` };
205
224
  const decided = await checkReportChecks(fromReport, opts.result);
206
225
  if ("error" in decided) return { usage: decided.error };
207
226
  wanted = decided.sign;
208
227
  note.skipped.push(...decided.skipped);
209
228
  } else if (fromReport) {
210
- const decided = planReportChecks(fromReport, opts.result);
229
+ const decided = planReportChecks(fromReport, opts.result, opts.member);
211
230
  wanted = decided.sign;
212
231
  note.skipped.push(...decided.skipped);
213
232
  } else {
@@ -268,6 +287,8 @@ async function signOpen(ctx: CommandContext, repo: string, base: string): Promis
268
287
  if (!args.fromReport) return usage("sign --open needs the job's report directory as its artifact keeps it: --from-report .chant/pr");
269
288
  if (!args.output) return usage("sign --open needs where to keep each merge request's evidence.json: -o .chant/evidence/<job>");
270
289
  if (args.checkId || args.at || args.planResult) return usage("sign --open finds each merge request's head and its job's result itself, so it takes no --check-id, --at or --result");
290
+ const member = memberOf(args.members, true);
291
+ if (typeof member === "object") return usage(member.usage);
271
292
  const branch = args.branch ?? process.env.CI_COMMIT_BRANCH;
272
293
  if (!branch) return usage("sign --open signs for the merge requests into a branch: run it in a branch pipeline, or pass --branch <branch>");
273
294
  const pem = args.key ? readFileSync(args.key, "utf-8") : process.env[CHECK_EVIDENCE_KEY_ENV];
@@ -287,7 +308,7 @@ async function signOpen(ctx: CommandContext, repo: string, base: string): Promis
287
308
  ...(args.noForks ? { noForks: true } : {}),
288
309
  fetchHead: (pr, head) => fetchMergeRequestHead(repo, pr, head),
289
310
  sign: async (dir, head, result) => {
290
- const r = await signChecksOf(repo, base, head, { fromReport: dir, result, ...(pem ? { pem } : {}), push: !args.noPush, skipCurrent: true });
311
+ const r = await signChecksOf(repo, base, head, { fromReport: dir, result, ...(member ? { member } : {}), ...(pem ? { pem } : {}), push: !args.noPush, skipCurrent: true });
291
312
  if ("usage" in r) throw new Error(r.usage);
292
313
  if (r.code !== CHANT_EXIT.done) failed = true;
293
314
  return r.note;
@@ -60,6 +60,7 @@ import type { Phase, Component } from "../../components/component";
60
60
  import { deployUnits } from "../../components/deploy-units";
61
61
  import { sortedJsonReplacer } from "../../utils";
62
62
  import { withoutReadFlags } from "../../lifecycle/legacy-digest";
63
+ import { actorFromEnv } from "../../actor";
63
64
 
64
65
  /**
65
66
  * chant components release <env> --component <name> --digest <sha256:...>
@@ -141,7 +142,8 @@ export async function runComponentsReleaseRecord(ctx: CommandContext): Promise<n
141
142
  // Id + origin resolved together from the same environment (#2045), so the
142
143
  // recorded runId always says which id space it lives in and how to reach it.
143
144
  const { runId, runOrigin } = resolveRunId(args.runId);
144
- const actor = args.actor ?? process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_LOGIN ?? process.env.USER;
145
+ // #4952: the fallback is actorFromEnv's; an empty answer is no actor, refused below.
146
+ const actor = args.actor ?? (actorFromEnv(process.env, "") || undefined);
145
147
  // Who approved a gated change (#1035). Optional — omitted for an ungated
146
148
  // change, and never defaulted to `actor`, since recording the approver as the
147
149
  // triggerer would defeat the separation-of-duties the field exists to attest.
@@ -4,7 +4,8 @@
4
4
  * package.json) into a directory under the OS temp directory, compare each
5
5
  * with the committed file, and exit 1 naming every one that drifted. The
6
6
  * directory is left in place and printed. Exit 2 when the product declares
7
- * no `chantGenerated`.
7
+ * no `chantGenerated`. Also `chant dev render` (#4950), which writes a
8
+ * module's file-text export in place.
8
9
  */
9
10
  import { checkGenerated, readGeneratedCheckConfig } from "../../generated-check";
10
11
  import { formatError } from "../format";
@@ -37,3 +38,32 @@ export async function runDevGeneratedCheck(ctx: CommandContext): Promise<number>
37
38
  }
38
39
  return result.ok ? 0 : 1;
39
40
  }
41
+
42
+ const RENDER_USAGE = "chant dev render <module> <export> [--output <root>]";
43
+
44
+ /**
45
+ * `chant dev render <module> <export> [--output <root>]` (#4950): import the
46
+ * module, call its export (a `{ path: text }` object, or a function that
47
+ * returns one) and write each file at its path below the root, the working
48
+ * directory unless `--output` names one. Under `chant dev generated-check`
49
+ * a path inside the product goes to the render tree instead.
50
+ */
51
+ export async function runDevRender(ctx: CommandContext): Promise<number> {
52
+ const [, modulePath, exportName] = ctx.args.positionals ?? [];
53
+ if (!modulePath || !exportName) {
54
+ console.error(formatError({ message: "name the module and its export that returns the files", hint: RENDER_USAGE }));
55
+ return 2;
56
+ }
57
+ const { resolve } = await import("node:path");
58
+ const { renderPathOf } = await import("../../generated-check");
59
+ const { renderModuleFiles, writeRenderedFiles } = await import("../../render-module");
60
+ try {
61
+ const files = await renderModuleFiles(modulePath, exportName);
62
+ const root = resolve(ctx.args.output ?? ".");
63
+ for (const path of writeRenderedFiles(root, files, renderPathOf)) console.error(` wrote ${path}`);
64
+ return 0;
65
+ } catch (err) {
66
+ console.error(formatError({ message: `chant dev render: ${err instanceof Error ? err.message : String(err)}`, hint: RENDER_USAGE }));
67
+ return 1;
68
+ }
69
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * #4979: `chant lock --reach` end to end, in a clone of a bare remote that
3
+ * holds a pull request's head at `refs/pull/<n>/head`: the head is fetched
4
+ * and checked, the reach line reads the change from git, and what it prints
5
+ * is locked on `chant/lifecycle` and pushed.
6
+ */
7
+ import { execFileSync } from "node:child_process";
8
+ import { mkdirSync, mkdtempSync, realpathSync, writeFileSync } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+ import { afterEach, describe, expect, test, vi } from "vitest";
12
+ import { commandRegistry, parseArgs } from "../main";
13
+ import { resolveCommand } from "../registry";
14
+
15
+ const home = process.cwd();
16
+
17
+ function git(cwd: string, ...args: string[]): string {
18
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
19
+ }
20
+
21
+ /** A bare remote with main and pull request 7's head, which changes envs/dev, and a clone of main. */
22
+ function world(): { clone: string; remote: string; base: string; head: string } {
23
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "chant-lock-reach-")));
24
+ const remote = join(root, "remote.git");
25
+ git(root, "init", "-q", "--bare", "-b", "main", remote);
26
+ const work = join(root, "work");
27
+ mkdirSync(work);
28
+ git(work, "init", "-q", "-b", "main");
29
+ for (const [k, v] of [["user.email", "test@chant.dev"], ["user.name", "Test"], ["commit.gpgsign", "false"]]) git(work, "config", k!, v!);
30
+ mkdirSync(join(work, "envs", "dev"), { recursive: true });
31
+ mkdirSync(join(work, "envs", "prod"), { recursive: true });
32
+ writeFileSync(join(work, "envs", "dev", "main.tf"), "# dev\n");
33
+ writeFileSync(join(work, "envs", "prod", "main.tf"), "# prod\n");
34
+ git(work, "add", ".");
35
+ git(work, "commit", "-q", "-m", "init");
36
+ const base = git(work, "rev-parse", "HEAD");
37
+ git(work, "remote", "add", "origin", remote);
38
+ git(work, "push", "-q", "origin", "main");
39
+ writeFileSync(join(work, "envs", "dev", "main.tf"), "# dev, changed\n");
40
+ git(work, "commit", "-q", "-am", "change dev");
41
+ const head = git(work, "rev-parse", "HEAD");
42
+ git(work, "push", "-q", "origin", `${head}:refs/pull/7/head`);
43
+ const clone = join(root, "clone");
44
+ git(root, "clone", "-q", remote, clone);
45
+ for (const [k, v] of [["user.email", "test@chant.dev"], ["user.name", "Test"], ["commit.gpgsign", "false"]]) git(clone, "config", k!, v!);
46
+ return { clone, remote, base, head };
47
+ }
48
+
49
+ async function run(argv: string[], env: Record<string, string>): Promise<{ code: number; err: string }> {
50
+ let err = "";
51
+ vi.spyOn(console, "log").mockImplementation(() => undefined);
52
+ vi.spyOn(console, "error").mockImplementation((s) => void (err += String(s) + "\n"));
53
+ vi.spyOn(console, "warn").mockImplementation(() => undefined);
54
+ const saved = Object.fromEntries(Object.keys(env).map((k) => [k, process.env[k]]));
55
+ Object.assign(process.env, env);
56
+ try {
57
+ const args = parseArgs(argv);
58
+ const match = resolveCommand(args, commandRegistry);
59
+ const code = await match!.def.handler({ args, plugins: [], serializers: [] });
60
+ return { code: code ?? 0, err };
61
+ } finally {
62
+ for (const [k, v] of Object.entries(saved)) {
63
+ if (v === undefined) delete process.env[k];
64
+ else process.env[k] = v;
65
+ }
66
+ vi.restoreAllMocks();
67
+ }
68
+ }
69
+
70
+ // The forge's API is a port nothing listens on: the status post is a warning, and no other holder needs asking.
71
+ const forgeEnv = { GITHUB_REPOSITORY: "acme/infra", GITHUB_TOKEN: "t", GITHUB_API_URL: "http://127.0.0.1:9", CHANT_LOCK_REACH: 'git diff --name-only "$BASE_SHA" "$HEAD_SHA" | cut -d/ -f1-2 | sort -u' };
72
+
73
+ afterEach(() => process.chdir(home));
74
+
75
+ describe("chant lock --reach (#4979)", () => {
76
+ test("locks what the reach line prints for the pull request's head, and pushes chant/lifecycle", async () => {
77
+ const w = world();
78
+ process.chdir(w.clone);
79
+ const got = await run(["lock", "--reach", "--pr", "7", "--head", w.head, "--base", w.base, "--stage", "plan", "--gate", "tf-apply", "--forge", "github"], forgeEnv);
80
+ expect(got.err).toMatch(/pull request 7 holds envs\/dev on tf-apply/);
81
+ expect(got.code).toBe(0);
82
+ const locks = JSON.parse(git(w.remote, "show", "chant/lifecycle:_locks/tf-apply.json")) as { locks: Record<string, { pr: number; stage: string; head: string }> };
83
+ expect(Object.keys(locks.locks)).toEqual(["envs/dev"]);
84
+ expect(locks.locks["envs/dev"]).toMatchObject({ pr: 7, stage: "plan", head: w.head });
85
+ });
86
+
87
+ test("a head that moved since the job started locks nothing, and the job passes", async () => {
88
+ const w = world();
89
+ process.chdir(w.clone);
90
+ const got = await run(["lock", "--reach", "--pr", "7", "--head", w.base, "--base", w.base, "--stage", "plan", "--forge", "github"], forgeEnv);
91
+ expect(got.code).toBe(0);
92
+ expect(got.err).toMatch(/pull request 7 moved to .*, so the run of that push locks it/);
93
+ });
94
+
95
+ test("is refused without the line, the forge, or the two commits", async () => {
96
+ const w = world();
97
+ process.chdir(w.clone);
98
+ expect((await run(["lock", "--reach", "--pr", "7", "--head", w.head, "--base", w.base, "--forge", "github"], { ...forgeEnv, CHANT_LOCK_REACH: "" })).err).toMatch(/CHANT_LOCK_REACH, which is not set/);
99
+ expect((await run(["lock", "--reach", "--pr", "7", "--head", w.head, "--base", w.base], forgeEnv)).err).toMatch(/give --forge github, gitlab or forgejo/);
100
+ expect((await run(["lock", "--reach", "--pr", "7", "--head", w.head, "--forge", "github"], forgeEnv)).err).toMatch(/from --base <sha> to --head <sha>/);
101
+ expect((await run(["lock", "--reach", "envs/dev", "--pr", "7", "--head", w.head, "--base", w.base, "--forge", "github"], forgeEnv)).err).toMatch(/drop the names/);
102
+ });
103
+ });
@@ -6,6 +6,8 @@
6
6
  * chant lock <target>... --pr <n> [--stage plan|apply|lock] [--head <sha>] [--by <who>] [--gate <name>] [--forge <kind>] [--json]
7
7
  * chant lock --from-report <pr-plan.json> --pr <n> [--stage plan] [--forge <kind>] [--json]
8
8
  * chant lock --keep --pr <n> [--head <sha>] [--gate <name>] [--forge <kind>] [--json]
9
+ * chant lock --reach --pr <n> --head <sha> --base <sha> --forge <kind> [--stage plan|apply|lock] [--gate <name>] [--json]
10
+ * chant lock --reach --open --base <sha> --forge gitlab [--branch <name>] [--stage plan] [--gate <name>] [--json]
9
11
  * chant lock --list [--gate <name>] [--json]
10
12
  * chant lock --alive <run>
11
13
  * chant unlock --pr <n> [<target>...] [--gate <name>] [--json]
@@ -20,6 +22,13 @@
20
22
  * a member is on the resource lock grain (#4552) the report carries
21
23
  * `lockTargets`, its row keys, and those are locked instead.
22
24
  *
25
+ * `--reach` (#4979) locks what a change reaches by the pipeline's reach line
26
+ * in `CHANT_LOCK_REACH`, which prints target names one a line from the
27
+ * change's files read as data (../../lifecycle/reach-locks.ts). chant first
28
+ * fetches the pull request's head and checks it is `--head`. With `--open`
29
+ * (GitLab's plan notes pipeline) every open merge request into the branch is
30
+ * locked, and a holder that is no longer open releases its locks.
31
+ *
23
32
  * `--list` prints the target locks, then the apply rows of the gate's rows
24
33
  * file (#4552, #4594), each with the run that holds it and when it took it.
25
34
  *
@@ -53,8 +62,11 @@ import { CHANT_EXIT } from "../../exit-codes";
53
62
  import { resolve } from "node:path";
54
63
  import type { CommandContext } from "../registry";
55
64
  import { formatError, formatInfo, formatSuccess, formatWarning } from "../format";
56
- import { FORGE_KINDS, forgeFromEnv, type ForgeKind, type PrForge } from "../../pr-forge";
65
+ import { FORGE_KINDS, type ForgeKind, type PrForge } from "../../pr-forge";
66
+ // #4964: a status for a pull_request run's merge preview goes on the pull request's head.
67
+ import { forgeFromJobEnv } from "../../pr-forge-job";
57
68
  import { PR_APPLY_GATE } from "../../pr-loop";
69
+ import { actorFromEnv } from "../../actor";
58
70
  import {
59
71
  describeHeldTargetLocks,
60
72
  readTargetLocks,
@@ -65,6 +77,7 @@ import {
65
77
  TARGET_LOCK_STAGES,
66
78
  type TargetLockStage,
67
79
  } from "../../lifecycle/target-lock";
80
+ import { LOCK_REACH_ENV, reachedTargets, reachOpen } from "../../lifecycle/reach-locks";
68
81
 
69
82
  /** The exit for a target another open pull request holds: `CHANT_EXIT.held`, 5 (#4553). */
70
83
  const HELD_EXIT_CODE = CHANT_EXIT.held;
@@ -93,7 +106,7 @@ function forgeOf(ctx: CommandContext): PrForge | undefined | { error: string } {
93
106
  if (kind === undefined) return undefined;
94
107
  if (!(FORGE_KINDS as readonly string[]).includes(kind)) return { error: `--forge ${kind} is not one of ${FORGE_KINDS.join(", ")}` };
95
108
  try {
96
- return forgeFromEnv(kind as ForgeKind);
109
+ return forgeFromJobEnv(kind as ForgeKind);
97
110
  } catch (err) {
98
111
  return { error: err instanceof Error ? err.message : String(err) };
99
112
  }
@@ -194,13 +207,29 @@ export async function runLock(ctx: CommandContext): Promise<number> {
194
207
  return 0;
195
208
  }
196
209
 
210
+ // #4979: GitLab's lock job, in the target branch's plan notes pipeline, locks what every open merge request reaches.
211
+ if (args.lockReach && args.open) return runReachOpen(ctx, gate);
197
212
  if (args.pr === undefined) return fail("chant lock needs the pull or merge request that holds the locks: --pr <n>", "chant lock --list prints the locks held now.");
198
213
  const stage = (args.lockStage ?? "lock") as TargetLockStage;
199
214
  if (!(TARGET_LOCK_STAGES as readonly string[]).includes(stage)) return fail(`--stage ${args.lockStage} is not one of ${TARGET_LOCK_STAGES.join(", ")}`);
200
215
 
201
216
  let targets = targetsOf(ctx);
202
217
  let head = args.head;
203
- if (args.keepLocks) {
218
+ if (args.lockReach) {
219
+ // #4979: the targets the change reaches, from the pipeline's reach line, after the head is fetched and checked.
220
+ if (targets.length > 0 || args.fromReport || args.keepLocks) return fail("--reach locks what the reach line prints; drop the names, --from-report and --keep");
221
+ const line = process.env[LOCK_REACH_ENV] ?? "";
222
+ if (!line.trim()) return fail(`--reach runs the reach line in ${LOCK_REACH_ENV}, which is not set`, "The generated lock job sets it from the product plan's reach.");
223
+ if (args.forge === undefined || !(FORGE_KINDS as readonly string[]).includes(args.forge)) return fail("--reach fetches the pull request's head from the forge: give --forge github, gitlab or forgejo");
224
+ if (!head || args.base === undefined) return fail("--reach measures the change from --base <sha> to --head <sha>");
225
+ const reached = reachedTargets({ forge: args.forge as ForgeKind, pr: args.pr, head, base: args.base, line });
226
+ if ("error" in reached) return fail(reached.error);
227
+ if ("moved" in reached) {
228
+ console.error(formatInfo(reached.moved));
229
+ return 0;
230
+ }
231
+ targets = reached.targets;
232
+ } else if (args.keepLocks) {
204
233
  if (targets.length > 0 || args.fromReport) return fail("--keep keeps the locks the pull request holds; drop the names and --from-report");
205
234
  let file;
206
235
  try {
@@ -224,7 +253,7 @@ export async function runLock(ctx: CommandContext): Promise<number> {
224
253
  const forge = forgeOf(ctx);
225
254
  if (forge && "error" in forge) return fail(forge.error);
226
255
  const isOpen = forge?.pullRequestOpen?.bind(forge);
227
- const by = args.by ?? process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_LOGIN ?? process.env.USER ?? "unknown";
256
+ const by = args.by ?? actorFromEnv();
228
257
  const name = prName(forge);
229
258
 
230
259
  let result;
@@ -261,6 +290,73 @@ export async function runLock(ctx: CommandContext): Promise<number> {
261
290
  return 0;
262
291
  }
263
292
 
293
+ /**
294
+ * `chant lock --reach --open --base <sha> --forge gitlab [--branch <name>]`
295
+ * (#4979): GitLab's lock job, in a pipeline of the target branch. Every
296
+ * open merge request from the project that merges into the branch (default
297
+ * `CI_COMMIT_BRANCH`) takes the locks of what its change reaches, and a
298
+ * holder that is no longer open releases its locks. Exit 3 when another
299
+ * merge request holds what one reaches, 1 when a reach could not be read.
300
+ */
301
+ async function runReachOpen(ctx: CommandContext, gate: string): Promise<number> {
302
+ const { args } = ctx;
303
+ const line = process.env[LOCK_REACH_ENV] ?? "";
304
+ if (!line.trim()) return fail(`--reach runs the reach line in ${LOCK_REACH_ENV}, which is not set`);
305
+ if (args.pr !== undefined || targetsOf(ctx).length > 0) return fail("--open locks every open merge request; drop --pr and the names");
306
+ if (args.base === undefined) return fail("--reach measures each change from --base <sha>, the target branch's commit");
307
+ const stage = (args.lockStage ?? "plan") as TargetLockStage;
308
+ if (!(TARGET_LOCK_STAGES as readonly string[]).includes(stage)) return fail(`--stage ${args.lockStage} is not one of ${TARGET_LOCK_STAGES.join(", ")}`);
309
+ const forge = forgeOf(ctx);
310
+ if (!forge) return fail("--open asks the forge for the open merge requests: give --forge gitlab");
311
+ if ("error" in forge) return fail(forge.error);
312
+ const branch = args.branch ?? process.env.CI_COMMIT_BRANCH ?? "";
313
+ if (!branch) return fail("--open locks the merge requests into one branch: give --branch <name>, or run it in a branch pipeline");
314
+ if (!forge.openPullRequests || !forge.pullRequestOpen) return fail(`the ${forge.kind} client cannot list the open merge requests`);
315
+ const isOpen = forge.pullRequestOpen.bind(forge);
316
+ const name = prName(forge);
317
+ let open;
318
+ try {
319
+ open = await forge.openPullRequests(branch);
320
+ } catch (err) {
321
+ return fail(`could not list the open merge requests into ${branch}: ${err instanceof Error ? err.message : String(err)}`);
322
+ }
323
+ const by = actorFromEnv();
324
+ const { outcomes, released } = await reachOpen({
325
+ forge: forge.kind,
326
+ base: args.base,
327
+ line,
328
+ branch,
329
+ open,
330
+ isOpen,
331
+ take: async (pr, head, targets) => {
332
+ const r = await takeTargetLocks(gate, targets, { pr, by, at: new Date().toISOString(), stage, head }, { isOpen, releaseStalePlan: stage === "plan" });
333
+ if (r.ok) {
334
+ await postStatus(forge, head, "success", r.taken.length > 0 ? `holds ${r.taken.join(", ")}` : "reaches no target");
335
+ return { ok: true, released: r.released };
336
+ }
337
+ await postStatus(forge, head, "failure", `locked by ${[...new Set(r.held.map((h) => h.pr))].map(name).join(", ")}: ${r.held.map((h) => h.target).join(", ")}`);
338
+ return { ok: false, held: `${describeHeldTargetLocks(r.held, name)}, so ${name(pr)} is not locked` };
339
+ },
340
+ holders: async () => [...new Set(Object.values((await readTargetLocks(gate)).locks).map((l) => l.pr))].sort((a, b) => a - b),
341
+ release: async (pr) => (await releaseTargetLocks(gate, pr)).released,
342
+ });
343
+ let code = 0;
344
+ for (const o of outcomes) {
345
+ if (o.kind === "locked") console.error(formatSuccess(`${name(o.pr)} ${o.targets.length > 0 ? `holds ${o.targets.join(", ")}` : "reaches no target"} on ${gate}${o.released.length > 0 ? `; released ${o.released.join(", ")}, which it no longer reaches` : ""}`));
346
+ else if (o.kind === "skipped") console.error(formatInfo(o.text));
347
+ else if (o.kind === "held") {
348
+ console.error(formatError({ message: o.text }));
349
+ if (code === 0) code = HELD_EXIT_CODE;
350
+ } else {
351
+ console.error(formatError({ message: `${name(o.pr)}: ${o.text}` }));
352
+ code = 1;
353
+ }
354
+ }
355
+ for (const r of released) console.error(formatInfo(`${name(r.pr)} is not open, so its locks on ${r.targets.join(", ")} are released`));
356
+ if (args.json) console.log(JSON.stringify({ gate, outcomes, released }, null, 2));
357
+ return code;
358
+ }
359
+
264
360
  /** chant unlock */
265
361
  export async function runUnlock(ctx: CommandContext): Promise<number> {
266
362
  const { args } = ctx;