@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,169 @@
1
+ /**
2
+ * Locks on what a change reaches (#4979): `chant lock --reach`.
3
+ *
4
+ * A pull request's plan locks (`ci.locks: plan`, #4293) come from what its
5
+ * plan selected, which the plan job, running the change's code, wrote. A
6
+ * product that knows from the change's files alone which of its targets a
7
+ * change reaches, such as terragucci's roots, units and instances, gives a
8
+ * reach line instead: one shell line, written in the pipeline at the target
9
+ * branch's commit, that prints the targets the change from `$BASE_SHA` to
10
+ * `$HEAD_SHA` reaches, one a line. It reads the change as data from git
11
+ * (`git diff`, `git show <sha>:<path>`) and runs none of its code.
12
+ *
13
+ * The lock job runs it in a checkout of the target branch's commit. chant
14
+ * first fetches the pull request's head from the forge (`refs/pull/<n>/head`,
15
+ * GitLab's `refs/merge-requests/<n>/head`) and checks it is still the commit
16
+ * the job was started for: a head that moved is left to the run of the push
17
+ * that moved it. The line's variables are `BASE_SHA`, `HEAD_SHA` and
18
+ * `PR_NUMBER`; it holds the job's environment, and the line is the
19
+ * pipeline's, so none of the change's code runs with the job's token.
20
+ *
21
+ * On GitLab a merge request's pipeline is built from the merge request's own
22
+ * files, so its lock job runs in the target branch's plan notes pipeline and
23
+ * locks every open merge request from the project (`--open`), and releases
24
+ * the locks of a merge request that is no longer open.
25
+ */
26
+
27
+ import { spawnSync } from "node:child_process";
28
+ import type { ForgeKind } from "../pr-forge";
29
+
30
+ /** The variable the reach line is in: the pipeline's, set as the step's variable so no shell quoting carries it (#4979). */
31
+ export const LOCK_REACH_ENV = "CHANT_LOCK_REACH";
32
+
33
+ /** Where chant fetches the pull request's head to before the reach line runs (#4979). */
34
+ export const REACH_HEAD_REF = "refs/remotes/chant/pull-request-head";
35
+
36
+ /** A target name a reach line may print: no control characters, at most 512 characters. */
37
+ const TARGET_LINE = /^[^\u0000-\u001f\u007f]{1,512}$/;
38
+ const SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
39
+
40
+ /** The forge's ref for pull request `pr`'s head. */
41
+ export function pullRequestHeadRef(forge: ForgeKind, pr: number): string {
42
+ return forge === "gitlab" ? `refs/merge-requests/${pr}/head` : `refs/pull/${pr}/head`;
43
+ }
44
+
45
+ /** A process run, as `spawnSync` answers it. */
46
+ export type ReachRun = (argv: string[], o: { cwd?: string; env?: Record<string, string | undefined> }) => { status: number | null; stdout: string; stderr: string };
47
+
48
+ const defaultRun: ReachRun = (argv, o) => {
49
+ const r = spawnSync(argv[0]!, argv.slice(1), { encoding: "utf8", ...(o.cwd ? { cwd: o.cwd } : {}), ...(o.env ? { env: o.env as NodeJS.ProcessEnv } : {}) });
50
+ return { status: r.status, stdout: r.stdout ?? "", stderr: r.error ? r.error.message : (r.stderr ?? "") };
51
+ };
52
+
53
+ /** What {@link reachedTargets} takes. */
54
+ export interface ReachInput {
55
+ forge: ForgeKind;
56
+ pr: number;
57
+ /** The head the job was started for. */
58
+ head: string;
59
+ /** The target branch's commit the change is measured from. */
60
+ base: string;
61
+ /** The reach line. */
62
+ line: string;
63
+ cwd?: string;
64
+ /** The line's environment, to which `BASE_SHA`, `HEAD_SHA` and `PR_NUMBER` are added. Default the process's. */
65
+ env?: Record<string, string | undefined>;
66
+ run?: ReachRun;
67
+ }
68
+
69
+ /** The targets a change reaches, sorted; or that its head moved; or why the line could not say. */
70
+ export type Reached = { targets: string[] } | { moved: string } | { error: string };
71
+
72
+ /**
73
+ * The targets the change of pull request `pr` reaches (#4979): fetch its
74
+ * head, check it is `head`, and run the reach line. Blank lines are left
75
+ * out; a line holding a control character fails the read, so a target name
76
+ * never carries one into the lock file.
77
+ */
78
+ export function reachedTargets(i: ReachInput): Reached {
79
+ const run = i.run ?? defaultRun;
80
+ const name = i.forge === "gitlab" ? `merge request !${i.pr}` : `pull request ${i.pr}`;
81
+ if (!SHA.test(i.head)) return { error: `--head ${JSON.stringify(i.head)} is not a commit sha` };
82
+ if (!SHA.test(i.base)) return { error: `--base ${JSON.stringify(i.base)} is not a commit sha` };
83
+ if (!i.line.trim()) return { error: `the reach line in ${LOCK_REACH_ENV} is empty` };
84
+ const fetched = run(["git", "fetch", "-q", "--no-tags", "origin", `+${pullRequestHeadRef(i.forge, i.pr)}:${REACH_HEAD_REF}`], { ...(i.cwd ? { cwd: i.cwd } : {}) });
85
+ if (fetched.status !== 0) return { error: `could not fetch ${name}'s head (${fetched.stderr.trim() || `git exited ${fetched.status}`})` };
86
+ const now = run(["git", "rev-parse", REACH_HEAD_REF], { ...(i.cwd ? { cwd: i.cwd } : {}) }).stdout.trim();
87
+ if (now !== i.head) return { moved: `${name} moved to ${now.slice(0, 12) || "another commit"} after ${i.head.slice(0, 12)}, so the run of that push locks it` };
88
+ const env = { ...(i.env ?? process.env), BASE_SHA: i.base, HEAD_SHA: i.head, PR_NUMBER: String(i.pr) };
89
+ const out = run(["sh", "-c", i.line], { ...(i.cwd ? { cwd: i.cwd } : {}), env });
90
+ if (out.status !== 0) return { error: `the reach line exited ${out.status ?? "on a signal"}${out.stderr.trim() ? `: ${out.stderr.trim().split("\n").slice(-3).join(" ")}` : ""}` };
91
+ const targets = new Set<string>();
92
+ for (const raw of out.stdout.split("\n")) {
93
+ const t = raw.trim();
94
+ if (t === "") continue;
95
+ if (!TARGET_LINE.test(t)) return { error: `the reach line printed ${JSON.stringify(t.slice(0, 80))}, which is not a target name: one a line, no control characters, at most 512 characters` };
96
+ targets.add(t);
97
+ }
98
+ return { targets: [...targets].sort() };
99
+ }
100
+
101
+ /** One open pull request as {@link reachOpen} locks it. */
102
+ export interface ReachOpenPull {
103
+ number: number;
104
+ headSha: string;
105
+ base: string;
106
+ fork: boolean;
107
+ }
108
+
109
+ /** What one open pull request's lock came to. */
110
+ export type ReachOpenOutcome =
111
+ | { pr: number; kind: "locked"; targets: string[]; released: string[] }
112
+ | { pr: number; kind: "held"; text: string }
113
+ | { pr: number; kind: "skipped"; text: string }
114
+ | { pr: number; kind: "failed"; text: string };
115
+
116
+ /** What {@link reachOpen} takes besides the reach input of each pull request. */
117
+ export interface ReachOpenInput extends Omit<ReachInput, "pr" | "head"> {
118
+ /** The branch the pull requests merge into. */
119
+ branch: string;
120
+ open: readonly ReachOpenPull[];
121
+ /** Take the locks of one pull request; `held` names what another holds. */
122
+ take(pr: number, head: string, targets: string[]): Promise<{ ok: true; released: string[] } | { ok: false; held: string }>;
123
+ /** The pull requests that hold a lock now. */
124
+ holders(): Promise<number[]>;
125
+ /** Whether a holder outside the open list is open still (one that merges into another branch). */
126
+ isOpen(pr: number): Promise<boolean>;
127
+ /** Release every lock of a pull request that is no longer open. */
128
+ release(pr: number): Promise<string[]>;
129
+ }
130
+
131
+ /**
132
+ * `chant lock --reach --open` (#4979), GitLab's lock job in the target
133
+ * branch's plan notes pipeline: lock what each open merge request from the
134
+ * project that merges into `branch` reaches, then release the locks of every
135
+ * holder that is not open any more. A fork's merge request takes no lock.
136
+ */
137
+ export async function reachOpen(i: ReachOpenInput): Promise<{ outcomes: ReachOpenOutcome[]; released: Array<{ pr: number; targets: string[] }> }> {
138
+ const outcomes: ReachOpenOutcome[] = [];
139
+ const open = new Set<number>();
140
+ for (const p of i.open) {
141
+ open.add(p.number);
142
+ if (p.fork) {
143
+ outcomes.push({ pr: p.number, kind: "skipped", text: `!${p.number} comes from a fork, so it takes no lock` });
144
+ continue;
145
+ }
146
+ if (p.base !== i.branch) {
147
+ outcomes.push({ pr: p.number, kind: "skipped", text: `!${p.number} merges into ${p.base}, not ${i.branch}` });
148
+ continue;
149
+ }
150
+ const r = reachedTargets({ ...i, pr: p.number, head: p.headSha });
151
+ if ("error" in r) {
152
+ outcomes.push({ pr: p.number, kind: "failed", text: r.error });
153
+ continue;
154
+ }
155
+ if ("moved" in r) {
156
+ outcomes.push({ pr: p.number, kind: "skipped", text: r.moved });
157
+ continue;
158
+ }
159
+ const took = await i.take(p.number, p.headSha, r.targets);
160
+ outcomes.push(took.ok ? { pr: p.number, kind: "locked", targets: r.targets, released: took.released } : { pr: p.number, kind: "held", text: took.held });
161
+ }
162
+ const released: Array<{ pr: number; targets: string[] }> = [];
163
+ for (const pr of await i.holders()) {
164
+ if (open.has(pr) || (await i.isOpen(pr))) continue;
165
+ const targets = await i.release(pr);
166
+ if (targets.length > 0) released.push({ pr, targets });
167
+ }
168
+ return { outcomes, released };
169
+ }
@@ -120,7 +120,10 @@ export type ReleaseCutCode =
120
120
  | "release-version-invalid"
121
121
  | "release-unsigned"
122
122
  | "release-signer-refused"
123
- | "declaration-invalid";
123
+ | "declaration-invalid"
124
+ /** #4941: the npm target's image check, run by the cut (./publish-npm.ts `checkPackageImages`). */
125
+ | "publish-npm-carries-image"
126
+ | "publish-npm-pack-failed";
124
127
 
125
128
  export class ReleaseCutError extends Error {
126
129
  constructor(
@@ -722,6 +725,19 @@ export async function cutRelease(req: CutRequest): Promise<CutResult> {
722
725
  }
723
726
  const { targets, templates } = targetsOf(compiled);
724
727
  const release = makeRelease({ member: p.member, commit, artifactDigests: artifacts, targets });
728
+ // #4941: an npm package that would carry an image archive stops the cut here, before anything is recorded or
729
+ // tagged, rather than the publish job once the label is spent. The check is the npm target's own plan check.
730
+ if (release.artifactDigests.some((a) => a.kind === "image" && a.path !== "")) {
731
+ const { loadChantConfig } = await import("../config");
732
+ const { checkDeclaredPackageImages } = await import("./publish-npm");
733
+ const { PublishTargetError } = await import("./release-publish");
734
+ try {
735
+ checkDeclaredPackageImages((await loadChantConfig(cwd)).config.release?.publish ?? [], release, cwd);
736
+ } catch (err) {
737
+ if (err instanceof PublishTargetError) throw new ReleaseCutError(err.code as ReleaseCutCode, `no release was cut: ${err.message}`, err.fix);
738
+ throw err;
739
+ }
740
+ }
725
741
  const timestamp = (req.now ?? (() => new Date()))().toISOString();
726
742
  const signed = { releaseDigest: release.releaseDigest, label: req.label, actor: req.actor, timestamp };
727
743
  let signature: string | null = null;
@@ -283,4 +283,60 @@ describe("an npm package that would carry an image archive (#4934)", () => {
283
283
  const { dir, release } = fixture("npm-leaves-image-out", ["dist", "!dist/images/app.tar", "sbom.spdx.json"]);
284
284
  expect((await planOf(dir, release)).map((i) => i.name)).toEqual(["@acme/app@2.0.0"]);
285
285
  });
286
+
287
+ /** #4941: a member whose release.publish has an npm target for the package at its root, cut with an image built into dist/images. */
288
+ const cutCarrying = async (name: string, files: string[]) => {
289
+ const r = new TestRepo(name);
290
+ repos.push(r);
291
+ r.write("chant.config.ts", `export default { environments: ["dev"], release: { publish: [{ type: "npm", packages: ["."] }] } };\n`);
292
+ r.write("package.json", JSON.stringify({ name: "@acme/app", version: "2.0.0", files }, null, 2));
293
+ r.write(".gitignore", "dist/\n");
294
+ const head = r.commit("init");
295
+ r.git(["tag", `ci/green/${head}`]);
296
+ const compiler: TargetCompiler = {
297
+ async compile(env): Promise<CompiledTarget> {
298
+ writeFileSync(join(r.dir, "dist", "index.js"), "export {};\n");
299
+ return { env, params: [], components: [], buildSteps: {}, buildInputs: {}, componentFiles: {}, templates: [{ component: null, path: "dist/out.json", content: "{}\n" }] };
300
+ },
301
+ async buildArtifacts(): Promise<ReleaseArtifact[]> {
302
+ return [];
303
+ },
304
+ };
305
+ const cut = cutRelease({
306
+ cwd: r.dir,
307
+ compiler,
308
+ label: "v2",
309
+ actor: "alice",
310
+ env: {},
311
+ buildImages: () =>
312
+ buildReleaseImages({
313
+ images: [{ name: "app", build: "build", archive: "dist/images/app.tar" }],
314
+ cwd: r.dir,
315
+ sourceDateEpoch: 1762473600,
316
+ label: "v2",
317
+ archiveDigest: ociArchiveDigest,
318
+ run: (_c, o) => {
319
+ writeOciLayout(join(o.cwd, "dist/images/app.tar"), "app layer");
320
+ return 0;
321
+ },
322
+ }),
323
+ });
324
+ return { r, cut };
325
+ };
326
+
327
+ test("#4941: a cut whose npm package would carry the image archive stops before it records anything, so the label is not spent", async () => {
328
+ const { r, cut } = await cutCarrying("cut-carries-image", ["dist"]);
329
+ const err = await cut.catch((e: unknown) => e);
330
+ expect(err).toBeInstanceOf(ReleaseCutError);
331
+ expect((err as ReleaseCutError).code).toBe("publish-npm-carries-image");
332
+ expect((err as ReleaseCutError).message).toMatch(/^no release was cut: @acme\/app \(\.\) would carry dist\/images\/app\.tar\//);
333
+ expect((err as ReleaseCutError).fix).toContain('Add "!dist/images/app.tar" to "files" in package.json');
334
+ expect(() => r.git(["rev-parse", "--verify", "--quiet", "refs/heads/chant/lifecycle"])).toThrow();
335
+ });
336
+
337
+ test("#4941: the same cut with the archive left out of the package records the release", async () => {
338
+ const { cut } = await cutCarrying("cut-leaves-image-out", ["dist", "!dist/images/app.tar"]);
339
+ const { release } = await cut;
340
+ expect(release.artifactDigests.map((a) => a.component)).toEqual(["app"]);
341
+ });
286
342
  });
@@ -38,7 +38,6 @@
38
38
  import { spawnSync } from "node:child_process";
39
39
  import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
40
40
  import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
41
- import { NEXT_RELEASE } from "../release-floors";
42
41
  import type { PublishDeclaration } from "./publish-declaration";
43
42
  import type { Release, ReleaseArtifact } from "./release-store";
44
43
 
@@ -56,7 +55,7 @@ export const RELEASE_IMAGES_FLOOR = "0.124.71";
56
55
  export const RELEASE_IMAGE_DOCKERFILE_FLOOR = "0.124.78";
57
56
 
58
57
  /** The first chant whose Dockerfile entry in `release.images` takes `args`, build arguments beside the two chant passes (#4908). */
59
- export const RELEASE_IMAGE_ARGS_FLOOR = NEXT_RELEASE;
58
+ export const RELEASE_IMAGE_ARGS_FLOOR = "0.124.88";
60
59
 
61
60
  /** One image a release builds in its cut with a command of the product's. */
62
61
  export interface ReleaseImageBuild {
@@ -14,6 +14,7 @@
14
14
 
15
15
  import { CHANT_WORDS, isChantWords, type CiProductNotifyWords, type CiProductWords } from "./ci-product-words";
16
16
  import type { NotifyFields, SendNotifyOptions } from "./notify";
17
+ import { driftIssueRecords, driftRunFingerprint, type DriftRunStack } from "./drift-issue";
17
18
 
18
19
  /**
19
20
  * The first chant whose Slack and Teams messages take a product's words, a
@@ -48,12 +49,19 @@ export function productSendOptions(words: CiProductWords, options: SendNotifyOpt
48
49
 
49
50
  /** What a drift notice concerns. */
50
51
  export interface DriftNotifyInput {
51
- /** The members whose refresh found drift. */
52
- changed: string[];
52
+ /** The members whose refresh found drift. Left out, the {@link stacks} with drift records, in their order. */
53
+ changed?: string[];
53
54
  missing?: string[];
54
55
  /** The members whose refresh failed, so drift there is unknown. */
55
56
  failed?: string[];
57
+ /** The run's fingerprint. Left out, `driftRunFingerprint` of the {@link stacks}. */
56
58
  fingerprint?: string;
59
+ /**
60
+ * Each member's drift records, as the run read them (#4944). The notice
61
+ * then names the members with drift and carries the run's fingerprint, so
62
+ * a product passes what it read instead of computing either.
63
+ */
64
+ stacks?: readonly DriftRunStack[];
57
65
  project?: string;
58
66
  environment?: string;
59
67
  reportUrl?: string;
@@ -62,24 +70,27 @@ export interface DriftNotifyInput {
62
70
  /**
63
71
  * A `drift` event under `words`: `2 stacks drifted: shop-dev, shop-prod` for
64
72
  * plywood, `1 member drifted: net` for chant, with the failed refreshes
65
- * named after them.
73
+ * named after them. Given `stacks`, the drifted members and the
74
+ * fingerprint come from their records (#4944).
66
75
  */
67
76
  export function driftNotifyFields(words: CiProductWords, input: DriftNotifyInput): NotifyFields {
68
77
  const [one, many] = words.noun;
69
- const n = input.changed.length;
78
+ const changed = input.changed ?? (input.stacks ?? []).filter((s) => driftIssueRecords(s.records).length > 0).map((s) => s.stack);
79
+ const fingerprint = input.fingerprint ?? (input.stacks ? driftRunFingerprint(input.stacks) : undefined);
80
+ const n = changed.length;
70
81
  const failed = input.failed ?? [];
71
- const what = n > 0 ? `${n} ${n === 1 ? one : many} drifted: ${input.changed.join(", ")}` : `no ${many} drifted`;
82
+ const what = n > 0 ? `${n} ${n === 1 ? one : many} drifted: ${changed.join(", ")}` : `no ${many} drifted`;
72
83
  const summary = failed.length > 0 ? `${what}; ${failed.length} ${failed.length === 1 ? one : many} could not be refreshed: ${failed.join(", ")}` : what;
73
84
  return {
74
85
  source: productNotifySource(words),
75
86
  event: "drift",
76
87
  summary,
77
- targets: input.changed,
88
+ targets: changed,
78
89
  drift: {
79
- changed: input.changed,
90
+ changed,
80
91
  ...(input.missing?.length ? { missing: input.missing } : {}),
81
92
  ...(failed.length > 0 ? { failed } : {}),
82
- ...(input.fingerprint ? { fingerprint: input.fingerprint } : {}),
93
+ ...(fingerprint ? { fingerprint } : {}),
83
94
  },
84
95
  ...(input.project !== undefined ? { project: input.project } : {}),
85
96
  ...(input.environment !== undefined ? { environment: input.environment } : {}),
@@ -23,6 +23,7 @@ import { join, resolve } from "node:path";
23
23
  import type { ReleaseAdmission } from "../../lifecycle/release-ledger";
24
24
  import { sortedJsonReplacer } from "../../utils";
25
25
  import { archiveSourceTree, sha256Digest, type SourceArchive } from "../source-archive";
26
+ import { actorFromEnv } from "../../actor";
26
27
 
27
28
  // ── sourceArchive ─────────────────────────────────────────────────────────────
28
29
 
@@ -149,7 +150,7 @@ export async function releaseRecord(args: ReleaseRecordArgs): Promise<ReleaseRec
149
150
  return { recorded: false, digest: plan.digest, env, component, approver };
150
151
  }
151
152
 
152
- const actor = args.actor || process.env.GITHUB_ACTOR || process.env.GITLAB_USER_LOGIN || process.env.USER;
153
+ const actor = args.actor || actorFromEnv(process.env, "");
153
154
  if (!actor) throw new Error("releaseRecord: no actor: pass one, or set GITHUB_ACTOR, GITLAB_USER_LOGIN or USER");
154
155
  const { runId, runOrigin } = resolveRunId(args.runId);
155
156
  await persistReleasePlan(plan, opts);
@@ -26,6 +26,7 @@ import { realpathSync } from "node:fs";
26
26
  import { join, resolve } from "node:path";
27
27
  import type { ReleaseAdmission, ReleaseRecord, ReleaseRef } from "../../lifecycle/release-ledger";
28
28
  import { archiveSourceTree } from "../source-archive";
29
+ import { actorFromEnv } from "../../actor";
29
30
  import { readReleasePlan, releasePlan, releasePlanDigest } from "./source-release";
30
31
 
31
32
  // ── releaseRollbackPlan ───────────────────────────────────────────────────────
@@ -219,7 +220,7 @@ export async function releaseRollbackRecord(args: ReleaseRollbackRecordArgs): Pr
219
220
  return { recorded: false, digest: rollback.to, env, component, approver };
220
221
  }
221
222
 
222
- const actor = args.actor || process.env.GITHUB_ACTOR || process.env.GITLAB_USER_LOGIN || process.env.USER;
223
+ const actor = args.actor || actorFromEnv(process.env, "");
223
224
  if (!actor) throw new Error("releaseRollbackRecord: no actor: pass one, or set GITHUB_ACTOR, GITLAB_USER_LOGIN or USER");
224
225
  const { runId, runOrigin } = resolveRunId(args.runId);
225
226
  await appendReleaseRecord(
@@ -0,0 +1,83 @@
1
+ /**
2
+ * #4987: the apply status after each wave, from the wave jobs' outcome
3
+ * files: pending until the last wave's success, pending (failed on GitLab)
4
+ * while a run waits, failed when one failed, and nothing for a wave that
5
+ * wrote no outcome.
6
+ */
7
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
8
+ import { tmpdir } from "node:os";
9
+ import { join } from "node:path";
10
+ import { describe, expect, test } from "vitest";
11
+ import type { ForgeStatus } from "../pr-forge";
12
+ import { parseArgs } from "../cli/parse-args";
13
+ import { applyStatusCommand, applyStatusJobName, opWaveApplyStatus, postOpWaveApplyStatus } from "./apply-status";
14
+
15
+ type Status = "applied" | "unchanged" | "failed" | "waiting" | "blocked";
16
+
17
+ /** A directory of outcome files, one per wave: wave -> member -> status. */
18
+ function outcomes(waves: Record<number, Record<string, Status>>): string {
19
+ const dir = mkdtempSync(join(tmpdir(), "chant-apply-status-"));
20
+ for (const [wave, members] of Object.entries(waves)) {
21
+ const sub = join(dir, `tf-apply-wave-${wave}-outcome`);
22
+ mkdirSync(sub, { recursive: true });
23
+ const doc = { version: 1, wave: Number(wave), at: `2026-11-10T00:00:0${wave}Z`, members: Object.fromEntries(Object.entries(members).map(([m, status]) => [m, { status }])) };
24
+ writeFileSync(join(sub, `outcome-wave-${wave}.json`), JSON.stringify(doc));
25
+ }
26
+ return dir;
27
+ }
28
+
29
+ describe("the apply status after a wave (#4987)", () => {
30
+ test("pending after each wave that applied, and the one success after the last", () => {
31
+ const dir = outcomes({ 1: { dev: "applied" }, 2: { prod: "unchanged" } });
32
+ expect(opWaveApplyStatus([dir], 1, 2, "github")).toEqual({ state: "running", description: "wave 1 of 2 applied" });
33
+ expect(opWaveApplyStatus([dir], 2, 2, "github")).toEqual({ state: "success", description: "all 2 waves applied" });
34
+ expect(opWaveApplyStatus([outcomes({ 1: { dev: "applied" } })], 1, 1, "forgejo")).toEqual({ state: "success", description: "the wave applied" });
35
+ });
36
+
37
+ test("a wave that waits is pending on GitHub and Forgejo and failed on GitLab", () => {
38
+ const dir = outcomes({ 1: { dev: "applied" }, 2: { prod: "waiting" } });
39
+ expect(opWaveApplyStatus([dir], 2, 3, "github")).toEqual({ state: "running", description: "wave 2 of 3 waits for an approval" });
40
+ expect(opWaveApplyStatus([dir], 2, 3, "gitlab")).toEqual({ state: "failed", description: "wave 2 of 3 waits for an approval" });
41
+ });
42
+
43
+ test("a failed run fails the status, and the waves after it carry the failure", () => {
44
+ const dir = outcomes({ 1: { dev: "failed", qa: "applied" }, 2: { prod: "blocked" } });
45
+ expect(opWaveApplyStatus([dir], 1, 2, "github")).toEqual({ state: "failed", description: "wave 1 of 2: 1 applied, 1 failed" });
46
+ expect(opWaveApplyStatus([dir], 2, 2, "github")).toEqual({ state: "failed", description: "wave 2 of 2: 1 applied, 1 blocked, 1 failed" });
47
+ });
48
+
49
+ test("a wave that wrote no outcome posts nothing", async () => {
50
+ const dir = outcomes({ 1: { dev: "applied" } });
51
+ expect(opWaveApplyStatus([dir], 2, 2, "github")).toBeUndefined();
52
+ const posted: ForgeStatus[] = [];
53
+ const line = await postOpWaveApplyStatus({ forge: { kind: "github", setStatus: async (_sha, s) => void posted.push(s) }, dirs: [dir], wave: 2, of: 2, context: "terragucci/apply", at: "a".repeat(40) });
54
+ expect(posted).toEqual([]);
55
+ expect(line).toBe("wave 2 of 2 wrote no outcome, so terragucci/apply stays as the wave before it left it");
56
+ });
57
+
58
+ test("posts on the commit the waves applied, linked to the run, with GitLab's pipeline", async () => {
59
+ const dir = outcomes({ 1: { dev: "applied" } });
60
+ const posted: Array<[string, ForgeStatus]> = [];
61
+ const forge = { kind: "gitlab" as const, runUrl: "https://gitlab.example/p/-/pipelines/7", setStatus: async (sha: string, s: ForgeStatus) => void posted.push([sha, s]) };
62
+ const line = await postOpWaveApplyStatus({ forge, dirs: [dir], wave: 1, of: 2, context: "terragucci/apply", at: "b".repeat(40), pipelineId: 7 });
63
+ expect(posted).toEqual([["b".repeat(40), { context: "terragucci/apply", state: "running", description: "wave 1 of 2 applied", url: "https://gitlab.example/p/-/pipelines/7", pipelineId: 7 }]]);
64
+ expect(line).toBe("terragucci/apply on bbbbbbbbbbbb: running: wave 1 of 2 applied");
65
+ });
66
+
67
+ test("refuses a commit that is not a sha, a wave past the count, and a context that is not a status name", async () => {
68
+ const forge = { kind: "github" as const, setStatus: async () => {} };
69
+ const at = "c".repeat(40);
70
+ await expect(postOpWaveApplyStatus({ forge, dirs: [], wave: 1, of: 1, context: "x/apply", at: "HEAD" })).rejects.toThrow("a full sha");
71
+ await expect(postOpWaveApplyStatus({ forge, dirs: [], wave: 3, of: 2, context: "x/apply", at })).rejects.toThrow("--wave 3 is past the run's 2 waves");
72
+ await expect(postOpWaveApplyStatus({ forge, dirs: [], wave: 1, of: 1, context: "x apply", at })).rejects.toThrow("is not a status name");
73
+ });
74
+
75
+ test("the job's name and command, through the product's bin, and the flags parse", () => {
76
+ expect(applyStatusJobName(2)).toBe("apply-status-2");
77
+ const line = applyStatusCommand({ name: "tf-apply", waves: [1, 2] }, 1, "terragucci/apply", "github", '"$GITHUB_SHA"', "npx --no-install terragucci");
78
+ expect(line).toBe('npx --no-install terragucci run wave --op tf-apply --wave 1 --of 2 --apply-status terragucci/apply --at "$GITHUB_SHA" --forge github');
79
+ expect(parseArgs(["run", "wave", "--op", "tf-apply", "--wave", "1", "--of", "2", "--apply-status", "terragucci/apply", "--at", "abc", "--forge", "github"])).toMatchObject({ op: "tf-apply", wave: 1, of: 2, applyStatus: "terragucci/apply", at: "abc", forge: "github" });
80
+ expect(() => parseArgs(["run", "wave", "--of", "0"])).toThrow("--of needs the number of waves");
81
+ expect(() => parseArgs(["run", "wave", "--apply-status"])).toThrow("--apply-status needs the status's name");
82
+ });
83
+ });
@@ -0,0 +1,132 @@
1
+ /**
2
+ * The apply statuses of an Op waves run (#4987): `<product>/apply` on the
3
+ * commit the waves applied, after each wave and after the last.
4
+ *
5
+ * A job of its own posts each one, `apply-status-<n>`, after wave n's jobs,
6
+ * at the default branch's commit with the wave jobs' outcome files. It runs
7
+ * none of the change's code: a before-merge run's wave jobs run the pull
8
+ * request's head, and this job holds the status token they do not need.
9
+ * The commit is the push's, or a before-merge run's decided head.
10
+ *
11
+ * What it posts, from the outcomes of waves 1 to n (`applyOutcomeOf`):
12
+ *
13
+ * - every run applied or had nothing to apply: `wave n of N applied`,
14
+ * pending, until the last wave, whose status is the one success;
15
+ * - a run waits at its gate: pending, `wave n of N waits for an approval`
16
+ * (failed on GitLab, which refuses to move a running status back to
17
+ * pending and keeps the pipeline running while one is left running; a
18
+ * retry posts a new one);
19
+ * - a run failed, or was blocked by one that did: failed, with the counts.
20
+ *
21
+ * A wave that wrote no outcome (its job stopped before its command, or the
22
+ * waves stopped before it) gets no status: the one before it stands, and
23
+ * the run's own jobs say what stopped.
24
+ *
25
+ * A `rest` wave's status job (#4992) posts for the wave its run ran, which
26
+ * a follow-on run names in `CHANT_WAVES_WAVE`, counted out of the waves the
27
+ * plan found, from the rest wave's note (./op-waves-follow-on.ts): a run
28
+ * that started a follow-on is not the last, so its status stays pending.
29
+ * The last run's status adds up every run of the chain (#4998): the
30
+ * earlier runs' outcomes come in the note's `chain`.
31
+ *
32
+ * Kept free of the forge client and git, so the generators import the
33
+ * names and the command line alone.
34
+ */
35
+
36
+ import { applyOutcomeOf } from "../control/applied";
37
+ import { earlierWaveOutcomes, passesThrough, type WaveMemberOutcome } from "../wave-blocked";
38
+ import type { ForgeStatusState, PrForge } from "../pr-forge";
39
+ import { readOpWaveRestNote, withChainOutcomes } from "./op-waves-follow-on";
40
+
41
+ /** The apply statuses option of an Op waves pipeline (#4987), `OpWavesPipelineOptions.applyStatus`. */
42
+ export interface OpWavesApplyStatus {
43
+ /** The status's name, such as `terragucci/apply`: `productStatusContext(words, "apply", member)`. */
44
+ context: string;
45
+ }
46
+
47
+ /** The job after wave `wave` that posts its apply status. */
48
+ export function applyStatusJobName(wave: number): string {
49
+ return `apply-status-${wave}`;
50
+ }
51
+
52
+ /** Whether `context` is a status name a forge keeps: no spaces, quotes or shell characters, at most 255 characters. */
53
+ export function assertApplyStatusContext(context: string): void {
54
+ if (!/^[A-Za-z0-9][A-Za-z0-9_./:-]{0,254}$/.test(context)) throw new Error(`applyStatus.context ${JSON.stringify(context)} is not a status name: letters, digits, '.', '_', '/', ':' and '-'`);
55
+ }
56
+
57
+ /**
58
+ * The status job's command, through the product's bin: `chant run wave --op
59
+ * <op> --wave <n> --of <count> --apply-status <context> --at <sha> --forge
60
+ * <forge>`. It names the op and the wave count rather than the spec file,
61
+ * which a spec rendered at run time (#4982) leaves uncommitted.
62
+ */
63
+ export function applyStatusCommand(spec: { name: string; waves: readonly unknown[] }, wave: number | string, context: string, forge: "github" | "forgejo" | "gitlab", at: string, bin?: string): string {
64
+ const words = (bin ?? "").split(/\s+/).filter(Boolean);
65
+ return [
66
+ ...(words.length > 0 ? words : ["chant"]),
67
+ "run", "wave", "--op", spec.name, "--wave", String(wave), "--of", String(spec.waves.length),
68
+ "--apply-status", context, "--at", at, "--forge", forge,
69
+ ].join(" ");
70
+ }
71
+
72
+ /** The status one wave's job posts, or none. */
73
+ export interface OpWaveApplyStatus {
74
+ state: Extract<ForgeStatusState, "running" | "success" | "failed">;
75
+ description: string;
76
+ }
77
+
78
+ /**
79
+ * The apply status after wave `wave` of `of`, from the outcome files under
80
+ * `dirs`. Undefined when wave `wave` wrote no outcome.
81
+ */
82
+ export function opWaveApplyStatus(dirs: readonly string[], wave: number, of: number, forge: "github" | "forgejo" | "gitlab"): OpWaveApplyStatus | undefined {
83
+ // #4998: a follow-on's note carries the outcomes of the chain's earlier runs, which the status adds up with this run's.
84
+ const members = withChainOutcomes(earlierWaveOutcomes(dirs, wave + 1).members, readOpWaveRestNote(dirs), wave + 1);
85
+ if (![...members.values()].some((m) => m.wave === wave)) return undefined;
86
+ const summary = applyOutcomeOf(members);
87
+ const where = `wave ${wave} of ${of}`;
88
+ if (summary.outcome === "applied" || summary.outcome === "unchanged") {
89
+ if (wave < of) return { state: "running", description: `${where} applied` };
90
+ return { state: "success", description: of === 1 ? "the wave applied" : `all ${of} waves applied` };
91
+ }
92
+ // A run that waits, or one held by it, is not a failure; any other run that did not get through is.
93
+ const waits = (o: WaveMemberOutcome): boolean => o.status === "waiting" || (o.status === "blocked" && o.by !== undefined && members.get(o.by)?.status === "waiting");
94
+ const held = [...members.values()].filter((o) => !passesThrough(o));
95
+ if (held.length > 0 && held.every(waits)) return { state: forge === "gitlab" ? "failed" : "running", description: `${where} waits for an approval` };
96
+ const counts = Object.entries(summary.counts).sort(([a], [b]) => a.localeCompare(b)).map(([k, n]) => `${n} ${k}`).join(", ");
97
+ return { state: "failed", description: `${where}: ${counts}` };
98
+ }
99
+
100
+ /** What {@link postOpWaveApplyStatus} posts with. */
101
+ export interface PostApplyStatusInput {
102
+ forge: Pick<PrForge, "kind" | "setStatus" | "runUrl">;
103
+ /** The directories the wave jobs' outcome files were downloaded into. */
104
+ dirs: readonly string[];
105
+ wave: number;
106
+ of: number;
107
+ context: string;
108
+ /** The commit the waves applied: the push's, or a before-merge run's decided head. */
109
+ at: string;
110
+ /** GitLab: the pipeline the status belongs to, when `at` is the pipeline's own commit; else GitLab files it under the commit's newest pipeline. */
111
+ pipelineId?: number;
112
+ }
113
+
114
+ /**
115
+ * Post the apply status after wave `wave` on `at` (#4987), linked to the
116
+ * run. Resolves to the line the job logs; a wave with no outcome posts
117
+ * nothing. The forge's refusal is thrown.
118
+ */
119
+ export async function postOpWaveApplyStatus(i: PostApplyStatusInput): Promise<string> {
120
+ if (!/^[0-9a-f]{40,64}$/.test(i.at)) throw new Error(`--at names the commit the waves applied, a full sha, not ${JSON.stringify(i.at)}`);
121
+ // #4992: the rest wave's note counts the waves its plan found, past the spec's. A follow-on's wave past them that
122
+ // wrote an outcome and whose record job left no note (its gate waits) is counted as the last one known.
123
+ const note = readOpWaveRestNote(i.dirs);
124
+ const ran = i.wave > i.of && [...earlierWaveOutcomes(i.dirs, i.wave + 1).members.values()].some((m) => m.wave === i.wave);
125
+ const of = note && note.wave === i.wave ? Math.max(i.of, note.found, note.wave) : ran ? i.wave : i.of;
126
+ if (i.wave > of) throw new Error(`--wave ${i.wave} is past the run's ${of} waves`);
127
+ assertApplyStatusContext(i.context);
128
+ const status = opWaveApplyStatus(i.dirs, i.wave, of, i.forge.kind);
129
+ if (!status) return `wave ${i.wave} of ${of} wrote no outcome, so ${i.context} stays as the wave before it left it`;
130
+ await i.forge.setStatus(i.at, { context: i.context, state: status.state, description: status.description, ...(i.forge.runUrl ? { url: i.forge.runUrl } : {}), ...(i.pipelineId !== undefined ? { pipelineId: i.pipelineId } : {}) });
131
+ return `${i.context} on ${i.at.slice(0, 12)}: ${status.state}: ${status.description}`;
132
+ }