@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
@@ -0,0 +1,428 @@
1
+ /**
2
+ * The comment job on GitHub and Forgejo (#4946): one job that reads every
3
+ * `/<product>` comment and answers the ones no other job of the pipeline
4
+ * takes, the GitHub and Forgejo half of what the GitLab note poll does
5
+ * (./ci-note-commands.ts). Moved from terragucci's `decideComment` and
6
+ * `decideApplyComment` (comment.ts, comment-apply.ts).
7
+ *
8
+ * GitHub and Forgejo start a workflow on the comment itself, so each job
9
+ * that answers a command (the re-plan, the comment lock and unlock, the
10
+ * action job, the agent, the commit jobs, the apply before merge) starts on
11
+ * its own comment, and this job leaves those comments alone. It answers the
12
+ * rest:
13
+ *
14
+ * - a comment the grammar refuses (`parseProductComment` with
15
+ * `leaveCommit`, so a commit word stays the commit job's), with the
16
+ * grammar's reason, an alias's product reason among them
17
+ * (`CiProductAlias.refuse`);
18
+ * - a command no job runs (`plan`, `apply`, `lock`, `unlock`, `action`,
19
+ * `agent`), with the words' reply for it (`words.replies`) or chant's;
20
+ * - with `applyOnMerge`, `/<product> apply` on a merged pull request: the
21
+ * newest push run at its merge commit that has an apply job is started
22
+ * again, unless a later commit of the default branch already carries the
23
+ * product's apply status. On GitHub the run's failed jobs run again
24
+ * (`rerun-failed-jobs`), each wave behind its own gate. Forgejo has no
25
+ * call that runs a run again, so the waves workflow is dispatched on the
26
+ * default branch, and only while the merge commit is still the branch's
27
+ * newest push. A forge re-run cannot stop the waves after one, so with
28
+ * the waves' op (`jobs.waves`, #4979) a `wave-<n>` writes a stop for the
29
+ * merge commit on `chant/lifecycle` before the run starts, and the waves
30
+ * after n wait (./op/wave-stop.ts); without it a wave-n is refused. On a
31
+ * fork, a pull request merged elsewhere, or one closed without merging,
32
+ * the reply says so.
33
+ * - with `noPlanFlags` (#4979), a plan comment with flags the product
34
+ * plan's re-plan cannot take, with the reason.
35
+ * - with `wavesBeforeMerge` (#4984), `/<product> apply [wave-<n>]` on an
36
+ * open pull request: the decision before merge
37
+ * (./op/before-merge-decide.ts) records the head on `chant/lifecycle`
38
+ * and dispatches the waves workflow on the default branch for it.
39
+ *
40
+ * Who asked comes first. On GitHub the commenter's permission is read from
41
+ * the forge; Forgejo answers 403 when a job's token asks for another user's
42
+ * permission, so there the event's `repository.permissions`, computed for
43
+ * the comment's author when the comment was created, is read, and the
44
+ * event must be for this repository and from the comment's author. Someone
45
+ * without write access gets no reply and nothing runs, as on GitLab.
46
+ *
47
+ * The comment is untrusted input: it is read from the event file, never
48
+ * from an expression in a script, and nothing of it reaches a shell. The
49
+ * job runs at the target branch's commit, so none of the change's code
50
+ * runs here.
51
+ */
52
+
53
+ import { commentTerms, forkReply, memberReply, notRunReply } from "./ci-comment-replies";
54
+ import { retryApply, type ApplyRerun, type ApplyRetried, type ChantNoteJobs, type StartedRun } from "./ci-note-commands";
55
+ import { parseProductComment, type CiProductWords, type ParsedProductComment } from "./ci-product-words";
56
+ import { ForgeApiError, type ForgeFetch, type PrForge } from "./pr-forge";
57
+ import type { ForgeReads, PullRequestDetail } from "./pr-forge-reads";
58
+ import type { DecideBeforeMergeInput, WavesBeforeMergeJobs } from "./op/before-merge-decide";
59
+
60
+ /** The comment job's name in a generated workflow (#4946). */
61
+ export const PR_COMMENT_JOB = "comment";
62
+
63
+ /** The variable the comment job reads the pipeline's jobs from, as JSON ({@link CommentJobs}), written by the generator (#4946). */
64
+ export const COMMENT_JOBS_ENV = "CHANT_COMMENT_JOBS";
65
+
66
+ /**
67
+ * The jobs the pipeline has that answer a comment (#4946), so the comment
68
+ * job leaves their comments to them. `preview` is any job that plans on the
69
+ * plan comment (the product plan's re-plan, or the comment preview).
70
+ */
71
+ export interface CommentJobs extends Omit<ChantNoteJobs, "members"> {
72
+ /** The action command is answered by a workflow: the product's own, or the pipeline's action job. */
73
+ actions?: boolean;
74
+ /**
75
+ * The product plan's targets, with its re-plan: a plan comment naming
76
+ * another is skipped by every re-plan job without a word, so the comment
77
+ * job replies with the words' `member` sentence.
78
+ */
79
+ targets?: readonly string[];
80
+ /** The product plan's re-plan skips a fork's pull request (`forks: "skip"`) without a word, so the comment job replies with the words' `fork` sentence. */
81
+ skipForks?: boolean;
82
+ /**
83
+ * The plan comment's job is the product plan's re-plan (#4979), which
84
+ * takes at most one word after the command and no flags: a plan comment
85
+ * with `--target`, `--refresh` or `--target-dependents` gets a reply that
86
+ * says so, where the re-plan would skip it without a word.
87
+ */
88
+ noPlanFlags?: boolean;
89
+ /**
90
+ * The waves on merge (#4979): the op they run as and how many there are.
91
+ * With them a merged pull request's `/<product> apply wave-<n>` runs the
92
+ * apply again and stops after wave n: the job writes the stop on
93
+ * `chant/lifecycle` for the merge commit (./op/wave-stop.ts) before it
94
+ * starts the run, and each later wave waits. An apply without a wave
95
+ * clears it.
96
+ */
97
+ waves?: { op: string; count: number };
98
+ /**
99
+ * The waves before merge (#4984), with `waves`: `/<product> apply
100
+ * [wave-<n>]` on an open pull request is this job's. It decides
101
+ * (./op/before-merge-decide.ts), records the decided head on
102
+ * `chant/lifecycle`, and dispatches the waves workflow for it.
103
+ */
104
+ wavesBeforeMerge?: WavesBeforeMergeJobs;
105
+ }
106
+
107
+ /** What the decision before merge reads and writes with (#4984), the comment job's handler's. */
108
+ export type CommentBeforeMerge = Pick<DecideBeforeMergeInput, "requires" | "statuses" | "git" | "cwd" | "lock" | "record" | "stop" | "now">;
109
+
110
+ /** Writes a wave stop for op `op` at `sha` on `chant/lifecycle`, or clears it (#4979). */
111
+ export type CommentWaveStops = (op: string, sha: string, stop: { through: number; at: string; by?: string; pr?: number } | null) => Promise<void>;
112
+
113
+ /**
114
+ * The apply jobs a re-run looks for at a merge commit: chant's op waves
115
+ * (`wave-<k>-<name>`, its decide and share jobs) and chant's and
116
+ * terragucci's pull request loop jobs (`apply`, `apply-wave-<k>`).
117
+ */
118
+ export const RERUN_APPLY_JOBS = /^(?:wave-([1-9][0-9]*)-[a-z0-9][a-z0-9_-]*|(?:[a-z0-9][a-z0-9-]*-)?apply(?:-wave-([1-9][0-9]*)(?:-share-[1-9][0-9]*)?)?)$/;
119
+
120
+ /** The writes a re-run makes, with the job's token. */
121
+ export interface CommentRuns {
122
+ /** GitHub: `POST /repos/{repo}/actions/runs/{run}/rerun-failed-jobs`. */
123
+ rerunFailed(run: number): Promise<StartedRun>;
124
+ /** Forgejo (and before merge, #4984, both): `POST /repos/{repo}/actions/workflows/{workflow}/dispatches` on `ref`, with `inputs`. */
125
+ dispatch(workflow: string, ref: string, inputs?: Record<string, string>): Promise<StartedRun>;
126
+ }
127
+
128
+ /** The writes for a GitHub or Forgejo API root, repository and token. */
129
+ export function commentRuns(opts: { apiBase: string; repo: string; token: string; fetch?: ForgeFetch }): CommentRuns {
130
+ const fetchImpl = opts.fetch ?? (globalThis.fetch as unknown as ForgeFetch);
131
+ const root = `${opts.apiBase.replace(/\/+$/, "")}/repos/${opts.repo}`;
132
+ const post = async (path: string, body: unknown): Promise<StartedRun> => {
133
+ const url = `${root}${path}`;
134
+ const res = await fetchImpl(url, { method: "POST", headers: { Authorization: `token ${opts.token}`, Accept: "application/json", "Content-Type": "application/json" }, body: JSON.stringify(body) });
135
+ const text = await res.text();
136
+ if (!res.ok) throw new ForgeApiError("POST", url, res.status, text);
137
+ return {};
138
+ };
139
+ return {
140
+ rerunFailed: (run) => post(`/actions/runs/${run}/rerun-failed-jobs`, {}),
141
+ dispatch: (workflow, ref, inputs) => post(`/actions/workflows/${encodeURIComponent(workflow)}/dispatches`, { ref, ...(inputs ? { inputs } : {}) }),
142
+ };
143
+ }
144
+
145
+ /** What {@link answerProductComment} takes. */
146
+ export interface AnswerCommentOptions {
147
+ forge: "github" | "forgejo";
148
+ /** The `issue_comment` event, as the event file has it. */
149
+ event: unknown;
150
+ /** `owner/name`. */
151
+ repo: string;
152
+ reads: ForgeReads;
153
+ /** chant's client, holding the job's token: it posts the reply and reads the statuses. */
154
+ poster: Pick<PrForge, "addComment" | "commitStatuses">;
155
+ runs: CommentRuns;
156
+ words: CiProductWords;
157
+ /** The default branch. */
158
+ base: string;
159
+ jobs: CommentJobs;
160
+ /** The job's environment, for the words' aliases. */
161
+ env?: Record<string, string | undefined>;
162
+ /** The commit words that take an argument, as `parseProductComment` takes them. */
163
+ commitArgs?: Readonly<Record<string, RegExp>>;
164
+ /** With `jobs.waves` (#4979): writes the wave stop before a re-run starts. Absent: a `wave-<n>` is refused, as before. */
165
+ stops?: CommentWaveStops;
166
+ /** The time a stop is written at. Default now. */
167
+ now?: () => string;
168
+ /** With `jobs.wavesBeforeMerge` (#4984): what the decision reads and writes with. Absent: an open pull request's apply is refused, as before. */
169
+ beforeMerge?: CommentBeforeMerge;
170
+ }
171
+
172
+ /** What the comment job did. */
173
+ export interface CommentOutcome {
174
+ /** The command's kind, when the comment parsed as one. */
175
+ command?: string;
176
+ /** True when a run was started again. */
177
+ ran: boolean;
178
+ /** True when the job posted a reply. */
179
+ replied: boolean;
180
+ /** True when something broke (a forge answer), not because the comment asked for nothing. The command exits non-zero on it. */
181
+ fail?: boolean;
182
+ reason: string;
183
+ url?: string;
184
+ }
185
+
186
+ /** Permissions on GitHub that may ask for a command: the same as may push. */
187
+ const MAY_ASK = new Set(["admin", "maintain", "write"]);
188
+ const LOGIN = /^[A-Za-z0-9_][A-Za-z0-9_.@-]{0,99}$/;
189
+
190
+ const short = (sha: string): string => sha.slice(0, 8);
191
+ const message = (e: unknown): string => (e instanceof Error ? e.message : String(e)).split("\n")[0]!;
192
+ const isObject = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
193
+
194
+ /** The command a comment asks for, for a job that only needs to know: the grammar's reading, leaving a commit word to the commit job. */
195
+ export function readProductComment(words: CiProductWords, body: unknown, env: Record<string, string | undefined> = {}, commitArgs: Readonly<Record<string, RegExp>> = {}): ParsedProductComment | undefined {
196
+ return parseProductComment(words, body, env, commitArgs, { leaveCommit: true });
197
+ }
198
+
199
+ /**
200
+ * Whether another job of the pipeline answers `parsed` on an open or a
201
+ * merged pull request, so the comment job says nothing (#4946).
202
+ */
203
+ export function answeredElsewhere(parsed: Exclude<ParsedProductComment, { kind: "refused" }>, jobs: CommentJobs, open: boolean | undefined): boolean {
204
+ switch (parsed.kind) {
205
+ case "plan":
206
+ return Boolean(jobs.preview);
207
+ case "lock":
208
+ case "unlock":
209
+ return Boolean(jobs.locks);
210
+ case "action":
211
+ return Boolean(jobs.actions);
212
+ case "agent":
213
+ return Boolean(jobs.agent);
214
+ case "commit":
215
+ return true;
216
+ case "apply":
217
+ // The apply before merge answers an open pull request's apply comment; a merged one's is this job's.
218
+ return Boolean(jobs.applyBeforeMerge) && open !== false;
219
+ }
220
+ }
221
+
222
+ /** Read the comment, and answer it when no other job does (#4946). */
223
+ export async function answerProductComment(o: AnswerCommentOptions): Promise<CommentOutcome> {
224
+ const e = o.event;
225
+ const t = commentTerms(o.forge);
226
+ const silent = (reason: string, command?: string): CommentOutcome => ({ ...(command ? { command } : {}), ran: false, replied: false, reason });
227
+ const broke = (reason: string, command?: string): CommentOutcome => ({ ...(command ? { command } : {}), ran: false, replied: false, fail: true, reason });
228
+ if (!isObject(e)) return broke("the event is not a JSON object");
229
+ if (e.action !== "created") return silent("not a new comment");
230
+ const comment = isObject(e.comment) ? e.comment : {};
231
+ const parsed = readProductComment(o.words, comment.body, o.env ?? {}, o.commitArgs ?? {});
232
+ if (parsed === undefined) return silent(`the comment is not addressed to ${o.words.product}, or another job answers it`);
233
+ const command = parsed.kind === "refused" ? undefined : parsed.kind;
234
+ const issue = isObject(e.issue) ? e.issue : {};
235
+ const n = issue.number;
236
+ if (typeof n !== "number" || !Number.isInteger(n) || n < 1) return silent("the comment has no issue number", command);
237
+ if (!issue.pull_request && issue.is_pull !== true && (e as { is_pull?: unknown }).is_pull !== true) return silent(`the comment is not on a ${t.request}`, command);
238
+ const user = isObject(comment.user) ? comment.user.login : undefined;
239
+ if (typeof user !== "string" || !LOGIN.test(user)) return silent("the comment has no usable author", command);
240
+
241
+ // Who asked comes first: someone without write access gets no reply and nothing runs.
242
+ if (o.forge === "forgejo") {
243
+ const repository = isObject(e.repository) ? e.repository : {};
244
+ if (repository.full_name !== o.repo) return silent("the event is not for this repository", command);
245
+ const sender = isObject(e.sender) ? e.sender.login : undefined;
246
+ if (sender !== user) return silent("the comment's author is not the event's sender", command);
247
+ const p = isObject(repository.permissions) ? repository.permissions : {};
248
+ if (p.push !== true && p.admin !== true) return silent(`${user} has no write access, so the comment is ignored`, command);
249
+ } else {
250
+ let permission: string | undefined;
251
+ try {
252
+ permission = await o.reads.permission(user);
253
+ } catch (err) {
254
+ return broke(`could not read ${user}'s permission, so nothing runs (${message(err)})`, command);
255
+ }
256
+ if (permission === undefined || !MAY_ASK.has(permission)) return silent(`${user} has no write access, so the comment is ignored`, command);
257
+ }
258
+
259
+ const reply = async (text: string, ran = false, url?: string): Promise<CommentOutcome> => {
260
+ const done = { ...(command ? { command } : {}), ran, ...(url ? { url } : {}) };
261
+ try {
262
+ await o.poster.addComment(n, `${o.words.product}: ${text}`);
263
+ } catch (err) {
264
+ return { ...done, replied: false, fail: true, reason: `${text}; and the reply failed (${message(err)})` };
265
+ }
266
+ return { ...done, replied: true, reason: text };
267
+ };
268
+
269
+ if (parsed.kind === "refused") return reply(parsed.reason);
270
+ // The product plan's re-plan skips these without a word: a target that is none of its own, and a fork with forks: "skip".
271
+ if (parsed.kind === "plan" && o.jobs.preview) {
272
+ // #4979: the product plan's re-plan plans what its verb plans, and takes no flag the grammar reads.
273
+ if (o.jobs.noPlanFlags && (parsed.targets?.length || parsed.refresh || parsed.targetDependents)) return reply(planFlagsReply(o.words));
274
+ if (parsed.member !== undefined && o.jobs.targets?.length && !o.jobs.targets.includes(parsed.member)) return reply(memberReply(o.words, parsed.member, o.jobs.targets, o.forge));
275
+ if (o.jobs.skipForks) {
276
+ let pr: PullRequestDetail | undefined;
277
+ try {
278
+ pr = await o.reads.pullRequest(n);
279
+ } catch (err) {
280
+ return broke(`could not read ${t.at(n)} (${message(err)})`, command);
281
+ }
282
+ if (pr && !pr.sameRepo) return reply(forkReply(o.words, o.forge));
283
+ }
284
+ }
285
+ // A command another job answers starts that job on this same comment.
286
+ if (parsed.kind !== "apply" && answeredElsewhere(parsed, o.jobs, true)) return silent("another job answers this comment", command);
287
+ switch (parsed.kind) {
288
+ case "plan":
289
+ case "lock":
290
+ case "unlock":
291
+ case "action":
292
+ case "agent":
293
+ return reply(notRunReply(o.words, parsed.kind, o.forge));
294
+ case "commit":
295
+ return silent("the commit job answers this comment", command);
296
+ case "apply":
297
+ break;
298
+ }
299
+
300
+ // An apply: the apply before merge answers an open pull request; this job a merged one, with applyOnMerge.
301
+ if (!o.jobs.applyBeforeMerge && !o.jobs.applyOnMerge && !o.jobs.wavesBeforeMerge) return reply(notRunReply(o.words, "apply", o.forge));
302
+ let pr: PullRequestDetail | undefined;
303
+ try {
304
+ pr = await o.reads.pullRequest(n);
305
+ } catch (err) {
306
+ return broke(`could not read ${t.at(n)} (${message(err)})`, command);
307
+ }
308
+ if (!pr) return broke(`the forge has no ${t.at(n)}`, command);
309
+ const at = t.at(n);
310
+ const verb = o.words.verbs.apply;
311
+ if (pr.state === "open") {
312
+ if (o.jobs.applyBeforeMerge) return silent("the apply before merge answers this comment", command);
313
+ // #4984: the waves before merge: decide, record the head and dispatch the waves workflow for it.
314
+ const bm = o.jobs.wavesBeforeMerge;
315
+ if (bm && o.jobs.waves && o.beforeMerge) {
316
+ const workflow = bm.workflow;
317
+ if (!workflow) return broke("the waves before merge name no workflow to dispatch", command);
318
+ const { decideWavesBeforeMerge } = await import("./op/before-merge-decide");
319
+ const done = await decideWavesBeforeMerge({
320
+ ...o.beforeMerge,
321
+ forge: o.forge,
322
+ pr,
323
+ user,
324
+ base: o.base,
325
+ ...(parsed.wave !== undefined ? { wave: parsed.wave } : {}),
326
+ op: o.jobs.waves.op,
327
+ count: o.jobs.waves.count,
328
+ jobs: bm,
329
+ words: o.words,
330
+ start: (r) => o.runs.dispatch(workflow, o.base, { pr: String(r.pr), head: r.head, digest: r.digest }),
331
+ });
332
+ if (done.kind === "fail") return broke(done.reason, command);
333
+ return reply(done.text, done.kind === "ran", done.kind === "ran" ? done.url : undefined);
334
+ }
335
+ return reply(`${at} is not merged: \`/${o.words.product} ${typedApply(o.words)}\` runs the ${verb[0]} of a merged ${t.request} again, from the default branch, and never ${verb[0]}s a ${t.request}'s branch`);
336
+ }
337
+ if (pr.state === "closed") return reply(`${at} was closed without merging, so there is nothing of it to ${verb[0]}`);
338
+ if (!o.jobs.applyOnMerge) return reply(`${at} is merged, and this ${t.place} ${verb[0]}s a ${t.request} before it merges, so there is nothing of it left to ${verb[0]}`);
339
+ if (!pr.sameRepo) return reply(forkReply(o.words, o.forge));
340
+ // #4979: with the waves' op the stop is written for the run; without it a re-run cannot stop.
341
+ const waves = o.stops ? o.jobs.waves : undefined;
342
+ const wave = parsed.wave;
343
+ if (wave !== undefined && !waves) {
344
+ return reply(`a run started again runs the waves after the one that stopped by itself, so \`wave-${wave}\` cannot stop them; write \`/${o.words.product} ${typedApply(o.words)}\`, and each wave still waits behind its own gate`);
345
+ }
346
+ if (wave !== undefined && waves && wave > waves.count) return reply(`the ${verb[0]} of this ${t.place} runs in ${waves.count} wave${waves.count === 1 ? "" : "s"}, so there is no \`wave-${wave}\``);
347
+ if (pr.base !== undefined && pr.base !== o.base) return reply(`${at} was merged into ${pr.base}, not the default branch ${o.base}, so nothing ${verb[1]} from it`);
348
+ if (!pr.mergeCommit) return broke(`${at} has no merge commit`, command);
349
+ const mergeCommit = pr.mergeCommit;
350
+ const start = o.forge === "github" ? githubRerun(o.runs) : forgejoRerun(o.runs, o.reads);
351
+ // The stop goes on chant/lifecycle just before the run starts, so every wave job of the run reads it; an apply without a wave clears it.
352
+ const rerun: ApplyRerun = waves
353
+ ? async (run, jobs, ctx) => {
354
+ try {
355
+ await o.stops!(waves.op, mergeCommit, wave !== undefined ? { through: wave, at: (o.now ?? (() => new Date().toISOString()))(), by: user, pr: n } : null);
356
+ } catch (err) {
357
+ return { kind: "fail", reason: `could not write the wave stop for ${short(mergeCommit)}, so nothing was started (${message(err)})` };
358
+ }
359
+ return start(run, jobs, ctx);
360
+ }
361
+ : start;
362
+ const done = await retryApply({ reads: o.reads, forge: o.poster, words: o.words, base: o.base }, o.forge, pr, user, { kind: "retry", sha: mergeCommit, jobs: RERUN_APPLY_JOBS }, rerun);
363
+ if (done.kind === "fail") return broke(done.reason, command);
364
+ const stopped = done.kind === "ran" && wave !== undefined && waves && wave < waves.count ? `; it stops after \`wave-${wave}\`, and the waves after it wait until \`/${o.words.product} ${typedApply(o.words)}\` runs it again` : "";
365
+ return reply(`${done.text}${stopped}`, done.kind === "ran", done.kind === "ran" ? done.url : undefined);
366
+ }
367
+
368
+ /** The reply to a plan comment with flags the product plan's re-plan cannot take (#4979). */
369
+ export function planFlagsReply(words: CiProductWords): string {
370
+ const line = Object.entries(words.commands).find(([, c]) => c === "plan")?.[0] ?? "plan";
371
+ const typed = `/${words.product} ${line}`;
372
+ return `\`${typed}\` plans whole ${words.noun[1]} again, every one or the one named after it, so it takes no \`--target\`, \`--refresh\` or \`--target-dependents\`; write \`${typed}\` or \`${typed} <${words.noun[0]}>\``;
373
+ }
374
+
375
+ /** The typed apply word. */
376
+ function typedApply(words: CiProductWords): string {
377
+ return Object.entries(words.commands).find(([, c]) => c === "apply")?.[0] ?? "apply";
378
+ }
379
+
380
+ /** Whether every apply job of a run succeeded, and the reply that says the run is still going. */
381
+ function finished(run: { done: boolean; status: string; id: number }, jobs: { status: string; conclusion?: string }[], sha: string, at: string): ApplyRetried | undefined {
382
+ if (!run.done) return { kind: "reply", text: `workflow run ${run.id} at ${short(sha)} is ${run.status} already, so it is not started again` };
383
+ if (jobs.every((j) => j.conclusion === "success" || j.status === "success")) return { kind: "reply", text: `every apply job of ${at}'s merge commit ${short(sha)} already succeeded` };
384
+ return undefined;
385
+ }
386
+
387
+ /** GitHub's start: run the run's failed jobs again, and the jobs that need them. */
388
+ export function githubRerun(runs: Pick<CommentRuns, "rerunFailed">): ApplyRerun {
389
+ return async (run, jobs, { sha, at, user }) => {
390
+ const stop = finished(run, jobs, sha, at);
391
+ if (stop) return stop;
392
+ try {
393
+ await runs.rerunFailed(run.id);
394
+ } catch (e) {
395
+ return { kind: "fail", reason: `could not run the failed jobs of workflow run ${run.id} again (${message(e)})` };
396
+ }
397
+ const link = run.url ? ` (${run.url})` : "";
398
+ return { kind: "ran", text: `started the failed jobs of workflow run ${run.id}${link} at ${at}'s merge commit ${short(sha)} again for ${user}; each wave's gate decides again, and the waves after it follow, each behind its own gate`, ...(run.url ? { url: run.url } : {}) };
399
+ };
400
+ }
401
+
402
+ /**
403
+ * Forgejo's start: Forgejo has no call that runs a run again, so the run's
404
+ * workflow is dispatched on the default branch, which runs its head. That
405
+ * is the merge commit only while no push came after it.
406
+ */
407
+ export function forgejoRerun(runs: Pick<CommentRuns, "dispatch">, reads: Pick<ForgeReads, "branchRuns">): ApplyRerun {
408
+ return async (run, jobs, { sha, at, user, base }) => {
409
+ const stop = finished(run, jobs, sha, at);
410
+ if (stop) return stop;
411
+ if (!run.workflow) return { kind: "fail", reason: `Forgejo did not name the workflow of run ${run.id}, so it cannot be dispatched` };
412
+ let newest;
413
+ try {
414
+ newest = (await reads.branchRuns(base, { event: "push", limit: 1 }))[0];
415
+ } catch (e) {
416
+ return { kind: "fail", reason: `could not read the newest push on ${base} (${message(e)})` };
417
+ }
418
+ if (newest && newest.headSha !== sha) {
419
+ return { kind: "reply", text: `Forgejo starts a workflow again only at the head of ${base}, which is now ${short(newest.headSha)}, so the merge commit ${short(sha)} of ${at} is not applied again: push to ${base} again` };
420
+ }
421
+ try {
422
+ await runs.dispatch(run.workflow, base);
423
+ } catch (e) {
424
+ return { kind: "fail", reason: `could not dispatch ${run.workflow} on ${base} (${message(e)})` };
425
+ }
426
+ return { kind: "ran", text: `dispatched ${run.workflow} on ${base} at ${at}'s merge commit ${short(sha)} for ${user}; each wave's gate decides again, and a wave that already applied plans nothing new` };
427
+ };
428
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The replies to comment commands no job runs (#4946), shared by the GitLab
3
+ * note poll (./ci-note-commands.ts) and the GitHub and Forgejo comment job
4
+ * (./ci-comment-commands.ts), so the two forges answer a command the same
5
+ * way and a product's own sentences (`words.replies`) reach both.
6
+ *
7
+ * A reply names the forge's things in the forge's words: `!12`, a merge
8
+ * request and a project on GitLab; pull request 12 and a repository on
9
+ * GitHub and Forgejo. GitLab's sentences are the ones the note poll wrote
10
+ * before #4946.
11
+ *
12
+ * This module imports nothing at run time.
13
+ */
14
+
15
+ import type { CiProductCommand, CiProductCommentReplies, CiProductWords } from "./ci-product-words";
16
+ import type { ForgeKind } from "./pr-forge";
17
+
18
+ /** How a reply names the forge's things. */
19
+ export interface CommentTerms {
20
+ /** The pull request by number: `!12`, or `pull request 12`. */
21
+ at(n: number): string;
22
+ /** `merge request` or `pull request`. */
23
+ request: string;
24
+ /** `project` or `repository`. */
25
+ place: string;
26
+ }
27
+
28
+ /** The terms for `forge`. */
29
+ export function commentTerms(forge: ForgeKind): CommentTerms {
30
+ return forge === "gitlab"
31
+ ? { at: (n) => `!${n}`, request: "merge request", place: "project" }
32
+ : { at: (n) => `pull request ${n}`, request: "pull request", place: "repository" };
33
+ }
34
+
35
+ /** `/<product> <word>` in backticks, for the word the words map onto `command`. */
36
+ export function commandLine(words: CiProductWords, command: CiProductCommand): string {
37
+ return `\`/${words.product} ${Object.entries(words.commands).find(([, c]) => c === command)?.[0] ?? command}\``;
38
+ }
39
+
40
+ /** The commands no job runs, by the slot a product's reply fills. */
41
+ export type NotRunCommand = Exclude<keyof CiProductCommentReplies, "fork" | "member">;
42
+
43
+ /**
44
+ * The reply to a command the pipeline runs no job for: the product's
45
+ * sentence when its words give one, else chant's.
46
+ */
47
+ export function notRunReply(words: CiProductWords, command: NotRunCommand, forge: ForgeKind): string {
48
+ const own = words.replies?.[command];
49
+ if (own !== undefined) return own;
50
+ const t = commentTerms(forge);
51
+ switch (command) {
52
+ case "plan":
53
+ return `this ${t.place} ${words.verbs.plan[0]}s a ${t.request} on each push to it, and no job ${words.verbs.plan[0]}s on a comment`;
54
+ case "apply":
55
+ return `this ${t.place} does not ${words.verbs.apply[0]} on a comment: re-run the ${words.verbs.apply[0]} job on the forge, or push to the default branch again`;
56
+ case "lock":
57
+ case "unlock":
58
+ return `${commandLine(words, command)} does not run here: this ${t.place} takes no locks`;
59
+ case "action":
60
+ return `this ${t.place} has no workflow that runs actions, so ${commandLine(words, "action")} does not run`;
61
+ case "agent":
62
+ return `the agent command is off in this ${t.place}`;
63
+ }
64
+ }
65
+
66
+ /** The reply to a command on a pull request from a fork. */
67
+ export function forkReply(words: CiProductWords, forge: ForgeKind): string {
68
+ const t = commentTerms(forge);
69
+ return words.replies?.fork ?? `a ${t.request} from a fork runs no command: its code never runs with this ${t.place}'s credentials`;
70
+ }
71
+
72
+ /** The reply to a comment that names a member the pipeline was not written with. */
73
+ export function memberReply(words: CiProductWords, member: string, members: readonly string[], forge: ForgeKind): string {
74
+ const listed = [...members].sort().map((m) => `\`${m}\``).join(", ");
75
+ const own = words.replies?.member;
76
+ if (own !== undefined) return own.split("{member}").join(member).split("{members}").join(listed);
77
+ return `${member} is not a ${words.noun[0]} of this ${commentTerms(forge).place}. The ${words.noun[1]} are ${listed}.`;
78
+ }
@@ -38,7 +38,6 @@ import {
38
38
  import { COMMENT_LEAVES_COMMIT_FLOOR } from "./ci-product";
39
39
  import { assertProductWords, commitWordOf, parseProductComment } from "./ci-product-words";
40
40
  import { PLYWOOD } from "./__fixtures__/product-words";
41
- import { NEXT_RELEASE } from "./release-floors";
42
41
  import type { OpRunRecord, OpRunRecordInput } from "./op/runtime";
43
42
  import type { PullRequestHead } from "./pr-forge";
44
43
 
@@ -663,8 +662,8 @@ describe("a comment job leaves the commit job's words to it, so a comment gets o
663
662
  expect(parseProductComment(aliased, "pw fmt", {}, {}, { leaveCommit: true })).toBeUndefined();
664
663
  });
665
664
 
666
- test("the floor is the next release", () => {
667
- expect(COMMENT_LEAVES_COMMIT_FLOOR).toBe(NEXT_RELEASE);
665
+ test("the floor is the release that shipped it", () => {
666
+ expect(COMMENT_LEAVES_COMMIT_FLOOR).toBe("0.124.88");
668
667
  });
669
668
  });
670
669
 
@@ -102,6 +102,24 @@ describe("which checks a job's record lets the evidence job sign (#4926)", () =>
102
102
  expect(got).toEqual({ sign: [{ check: "plan:dev", source: { run: 9, job: 40 } }], skipped: [{ check: "policy:dev", reason: "job wave-1-dev-policy ended failed" }] });
103
103
  });
104
104
 
105
+ test("#4978: a wave job retried with its evidence job is waited for, and signs once its new try ends", async () => {
106
+ const tries: RunJob[][] = [
107
+ [{ id: 50, name: "wave-1-dev", status: "created", done: false, run: 9, headSha: SHA }],
108
+ [{ id: 50, name: "wave-1-dev", status: "running", done: false, run: 9, headSha: SHA }],
109
+ [{ id: 50, name: "wave-1-dev", status: "success", done: true, run: 9, headSha: SHA }],
110
+ ];
111
+ let reads = 0;
112
+ const slept: number[] = [];
113
+ const runJobs = async () => tries[Math.min(reads++, tries.length - 1)]!;
114
+ const got = await checksFromJob({ reads: { runJobs }, run: 9, sha: SHA, fromJob: "wave-1-dev", checks: ["plan:dev"], waitMs: 60_000, pollMs: 10_000, sleep: async (ms) => void slept.push(ms) });
115
+ expect(got).toEqual({ sign: [{ check: "plan:dev", source: { run: 9, job: 50 } }], skipped: [] });
116
+ expect(slept).toEqual([10_000, 10_000]);
117
+ // Out of time, the job still going is not signed.
118
+ reads = 0;
119
+ const late = await checksFromJob({ reads: { runJobs: async () => tries[0]! }, run: 9, sha: SHA, fromJob: "wave-1-dev", checks: ["plan:dev"], waitMs: 20_000, pollMs: 10_000, sleep: async () => {} });
120
+ expect(late).toEqual({ sign: [], skipped: [{ check: "plan:dev", reason: "job wave-1-dev has not finished (created)" }] });
121
+ });
122
+
105
123
  test("the sources and claim files read as data", () => {
106
124
  expect(parseEvidenceSources('{"plan:dev":"Plan","policy:dev":{"job":"p"}}')).toEqual({ sources: { "plan:dev": { step: "Plan" }, "policy:dev": { job: "p" } } });
107
125
  expect(parseEvidenceSources("[]")).toHaveProperty("problem");
@@ -21,6 +21,11 @@
21
21
  *
22
22
  * Each check signed carries `source: { run, job, step }`, the ids it relied
23
23
  * on, so a verifier can look them up.
24
+ *
25
+ * A job it reads that has not finished is waited for, up to
26
+ * {@link FROM_JOB_WAIT_MS} (#4978): `chant run resume` retries a GitLab
27
+ * wave job's evidence job with the wave job, and the two may start
28
+ * together.
24
29
  */
25
30
 
26
31
  import type { ForgeReads, RunJob } from "./pr-forge-reads";
@@ -41,6 +46,16 @@ export interface ChecksFromJobInput {
41
46
  sources?: Readonly<Record<string, EvidenceSourceSpec>>;
42
47
  /** The directory of the jobs' claim files. Without it, a check needs only its step's success and signs no claim. */
43
48
  claims?: string;
49
+ /**
50
+ * How long to wait for a job it reads that has not finished (#4978), in
51
+ * milliseconds, reading the run's jobs again every `pollMs` (default 15
52
+ * seconds). A GitLab evidence job retried with its wave job can start
53
+ * before the new try ends. Default 0: a job not finished is not signed.
54
+ */
55
+ waitMs?: number;
56
+ pollMs?: number;
57
+ /** For tests: in place of a timer. */
58
+ sleep?: (ms: number) => Promise<void>;
44
59
  }
45
60
 
46
61
  /** What may be signed, and what not and why. */
@@ -55,9 +70,28 @@ function jobPassed(job: RunJob): boolean {
55
70
  return job.conclusion !== undefined ? job.conclusion === SUCCESS : job.status === SUCCESS;
56
71
  }
57
72
 
73
+ /**
74
+ * The run's jobs once every job the checks read has finished, or as they
75
+ * are when `waitMs` runs out (#4978). A job not in the run is left to
76
+ * {@link checksFromJob} to refuse.
77
+ */
78
+ async function settledJobs(input: ChecksFromJobInput): Promise<RunJob[]> {
79
+ const names = new Set(input.checks.map((c) => input.sources?.[c]?.job ?? input.fromJob));
80
+ const sleep = input.sleep ?? ((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));
81
+ const poll = Math.max(1, input.pollMs ?? 15_000);
82
+ let left = input.waitMs ?? 0;
83
+ for (;;) {
84
+ const jobs = await input.reads.runJobs(input.run);
85
+ const going = jobs.some((j) => names.has(j.name) && !j.done);
86
+ if (!going || left <= 0) return jobs;
87
+ await sleep(Math.min(poll, left));
88
+ left -= poll;
89
+ }
90
+ }
91
+
58
92
  /** The checks the run's record lets this job sign (#4926), or why the job it names does not count at all. */
59
93
  export async function checksFromJob(input: ChecksFromJobInput): Promise<ChecksFromJob> {
60
- const jobs = await input.reads.runJobs(input.run);
94
+ const jobs = await settledJobs(input);
61
95
  const found = new Map<string, RunJob | string>();
62
96
  const jobNamed = (name: string): RunJob | string => {
63
97
  const had = found.get(name);
@@ -142,8 +176,19 @@ export interface SignFromJobInput {
142
176
  push?: boolean;
143
177
  fetch?: typeof fetch;
144
178
  log?: (line: string) => void;
179
+ /** How long to wait for an unfinished job it reads (#4978). Default {@link FROM_JOB_WAIT_MS}. */
180
+ waitMs?: number;
181
+ pollMs?: number;
182
+ sleep?: (ms: number) => Promise<void>;
145
183
  }
146
184
 
185
+ /**
186
+ * How long `sign --from-job` waits for a job it reads to finish (#4978): a
187
+ * GitLab `<wave job>-evidence` retried with its wave job by `chant run
188
+ * resume` may start before the wave job's new try ends. 30 minutes.
189
+ */
190
+ export const FROM_JOB_WAIT_MS = 30 * 60_000;
191
+
147
192
  /** What {@link signFromJob} signed and skipped, or why it refused. */
148
193
  export type SignFromJobResult =
149
194
  | { signed: Array<{ check: string; runner: string; commit: string; tree: string; source: CheckSource }>; skipped: Array<{ check: string; reason: string }>; pushWarning?: string }
@@ -172,7 +217,18 @@ export async function signFromJob(input: SignFromJobInput): Promise<SignFromJobR
172
217
  if (commit !== sha) return { refused: `--at names ${commit.slice(0, 12)}, and this run is for ${sha.slice(0, 12)}; --from-job signs only the run's own commit` };
173
218
  const parsed = parseEvidenceSources(env[EVIDENCE_SOURCES_ENV]);
174
219
  if ("problem" in parsed) return { refused: parsed.problem };
175
- const decided = await checksFromJob({ reads: input.reads, run: Number(rawRun), sha, fromJob: input.fromJob, checks: input.checks, sources: parsed.sources, ...(input.claims !== undefined ? { claims: input.claims } : {}) });
220
+ const decided = await checksFromJob({
221
+ reads: input.reads,
222
+ run: Number(rawRun),
223
+ sha,
224
+ fromJob: input.fromJob,
225
+ checks: input.checks,
226
+ sources: parsed.sources,
227
+ ...(input.claims !== undefined ? { claims: input.claims } : {}),
228
+ waitMs: input.waitMs ?? FROM_JOB_WAIT_MS,
229
+ ...(input.pollMs !== undefined ? { pollMs: input.pollMs } : {}),
230
+ ...(input.sleep ? { sleep: input.sleep } : {}),
231
+ });
176
232
  if ("refused" in decided) return decided;
177
233
  for (const s of decided.skipped) log(`ci evidence: ${s.check} not signed: ${s.reason}`);
178
234
  if (decided.sign.length === 0) return { signed: [], skipped: decided.skipped };