@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
@@ -430,6 +430,13 @@ export function foldPolicyRows(
430
430
  * (#4614): `runChantInProcess(["run", "wave", ...], words, { wave })`. The
431
431
  * job then calls the product's after-plan hooks, and plans and applies a
432
432
  * `step` through the product's own capability registry when it gives one.
433
+ *
434
+ * #4994: the same hook works in each job of a split wave
435
+ * (`run wave --phase plan|gate|apply|record`) and in the one-job shape. The
436
+ * plan job calls `afterPlan` and plans through `capabilities` and
437
+ * `runHooks`; the applying job plans its runs again and applies them
438
+ * through them; the gate and record jobs plan nothing. `hooks` serves the
439
+ * spec's own hooks in the process of whichever job runs them.
433
440
  */
434
441
  export interface ProductWaveHook {
435
442
  afterPlan?: OpWaveAfterPlanHook | readonly OpWaveAfterPlanHook[];
@@ -438,6 +445,12 @@ export interface ProductWaveHook {
438
445
  hookExec?: import("./stage-hooks").OpWaveAsyncExec;
439
446
  /** Hooks around each run of a wave with a `step` (#4842, `RunOpWaveOptions.runHooks`). */
440
447
  runHooks?: import("./op-waves-run-hooks").OpWaveRunHooks | readonly import("./op-waves-run-hooks").OpWaveRunHooks[];
448
+ /**
449
+ * The spec's hooks served in this process, by name (#4994,
450
+ * `RunOpWaveOptions.inProcessHooks`): in place of a hook command that
451
+ * called back into a long-lived product process over a socket.
452
+ */
453
+ hooks?: Readonly<Record<string, import("./stage-hooks").OpWaveInProcessHook>>;
441
454
  }
442
455
 
443
456
  let activeWave: ProductWaveHook | undefined;
@@ -15,7 +15,11 @@
15
15
  * policy, and `plan:<wave>` too when the wave trades cloud credentials and
16
16
  * signs keyless, since after the trade no step of the wave job may request
17
17
  * the signing token (#4869).
18
- * - signs `plan:<wave>` in its command step otherwise, as before (#4870).
18
+ * - signs `plan:<wave>` in its command step otherwise, as before (#4870),
19
+ * except on GitLab with a runner key (#4964): a wave job names its own
20
+ * deploy environment, so it cannot name the `chant-evidence` one the
21
+ * key's variable is scoped to, and the evidence job, which does, signs
22
+ * `plan:<wave>` from the wave job's status and claim file.
19
23
  *
20
24
  * A wave with no policy and no keyless cloud trade renders as before.
21
25
  * A later wave whose `evidence.requires` names a check an earlier wave's
@@ -24,6 +28,7 @@
24
28
 
25
29
  import { EVIDENCE_SOURCES_ENV, WAVE_EVIDENCE_ENV, type EvidenceSourceSpec } from "../ci-evidence-claims";
26
30
  import { opWaveBinArgv, opWaveChecksDir, type OpWaveJob, type OpWavesSpec } from "./op-waves";
31
+ import { BEFORE_MERGE_HEAD_ENV } from "./before-merge";
27
32
 
28
33
  export { EVIDENCE_SOURCES_ENV, WAVE_EVIDENCE_ENV };
29
34
 
@@ -51,15 +56,17 @@ export interface OpWaveEvidencePlan {
51
56
  * pipeline). `keylessCloud` is whether the job signs keyless and trades
52
57
  * cloud credentials.
53
58
  */
54
- export function opWaveEvidencePlan(spec: Pick<OpWavesSpec, "holds" | "waves">, job: Pick<OpWaveJob, "kind" | "jobName" | "wave">, opts: { signs: boolean; keylessCloud: boolean }): OpWaveEvidencePlan | undefined {
59
+ export function opWaveEvidencePlan(spec: Pick<OpWavesSpec, "holds" | "waves">, job: Pick<OpWaveJob, "kind" | "jobName" | "wave">, opts: { signs: boolean; keylessCloud: boolean; keyOutOfWave?: boolean }): OpWaveEvidencePlan | undefined {
55
60
  if (!opts.signs || (job.kind !== "wave" && job.kind !== "decide")) return undefined;
56
61
  const name = spec.waves[job.wave - 1]!.name;
57
62
  const plan = `plan:${name}`;
58
63
  const policy = `policy:${name}`;
59
64
  const policyStep = spec.holds?.policy === true;
60
- const checks = [...(opts.keylessCloud ? [plan] : []), ...(policyStep ? [policy] : [])];
65
+ // #4964: with `keyOutOfWave` (GitLab with a runner key) the wave job holds no key, so its evidence job signs the plan too.
66
+ const inJob = opts.keylessCloud || opts.keyOutOfWave === true;
67
+ const checks = [...(inJob ? [plan] : []), ...(policyStep ? [policy] : [])];
61
68
  if (checks.length === 0) return { plan, policy, policyStep, commandSigns: true };
62
- return { plan, policy, policyStep, commandMode: opts.keylessCloud ? "job" : "plan", commandSigns: !opts.keylessCloud, evidenceJob: { name: `${job.jobName}-evidence`, checks } };
69
+ return { plan, policy, policyStep, commandMode: inJob ? "job" : "plan", commandSigns: !inJob, evidenceJob: { name: `${job.jobName}-evidence`, checks } };
63
70
  }
64
71
 
65
72
  /** The GitLab job a wave's policy runs in (#4926). */
@@ -96,13 +103,20 @@ export function opWaveEvidenceSources(forge: "github" | "forgejo" | "gitlab", pl
96
103
  * setup and the product's command after it are the base's code and none of
97
104
  * the change's runs, then sign from the wave job. `sha` is the run's commit
98
105
  * as the shell reads it; the first line keeps the base in
99
- * {@link OP_WAVE_EVIDENCE_BASE_VAR}.
106
+ * {@link OP_WAVE_EVIDENCE_BASE_VAR}. With `beforeMerge` (#4984), a run of a
107
+ * pull request's decided head takes the checkout's commit, the default
108
+ * branch's the run started at, as its base; `sha` then names the head.
100
109
  */
101
- export function opWaveEvidenceLines(spec: Pick<OpWavesSpec, "name" | "base">, plan: OpWaveEvidencePlan, job: Pick<OpWaveJob, "jobName">, opts: { sha: string; bin?: string }): { checkout: string[]; sign: string[] } {
110
+ export function opWaveEvidenceLines(spec: Pick<OpWavesSpec, "name" | "base">, plan: OpWaveEvidencePlan, job: Pick<OpWaveJob, "jobName">, opts: { sha: string; bin?: string; beforeMerge?: boolean }): { checkout: string[]; sign: string[] } {
102
111
  const base = spec.base ?? "HEAD^1";
103
112
  const quoted = `'${base.replace(/'/g, "'\\''")}'`;
113
+ const fromSpec = `${OP_WAVE_EVIDENCE_BASE_VAR}="$(git rev-parse --verify ${quoted}^{commit})" || exit 1`;
114
+ // #4984: a run of a pull request's decided head was measured from the default branch's commit it started at, the checkout here.
115
+ const baseLine = opts.beforeMerge
116
+ ? `if [ -n "\${${BEFORE_MERGE_HEAD_ENV}:-}" ]; then ${OP_WAVE_EVIDENCE_BASE_VAR}="$(git rev-parse --verify HEAD^{commit})" || exit 1; else ${fromSpec}; fi`
117
+ : fromSpec;
104
118
  return {
105
- checkout: [`${OP_WAVE_EVIDENCE_BASE_VAR}="$(git rev-parse --verify ${quoted}^{commit})" || exit 1`, `git checkout --quiet --detach "$${OP_WAVE_EVIDENCE_BASE_VAR}" || exit 1`],
119
+ checkout: [baseLine, `git checkout --quiet --detach "$${OP_WAVE_EVIDENCE_BASE_VAR}" || exit 1`],
106
120
  sign: [
107
121
  [
108
122
  ...opWaveBinArgv(opts.bin),
@@ -0,0 +1,152 @@
1
+ /**
2
+ * #4998: the rest wave's record job records each follow-on it starts on
3
+ * `chant/lifecycle` before it starts it (the run, the wave, the decision or
4
+ * the pushed commit, and the chain's outcomes so far), and the last run's
5
+ * control outcome and apply status add up every run of the chain: a chain
6
+ * whose last wave changed nothing reports `applied`. On each forge.
7
+ */
8
+ import { describe, expect, test } from "vitest";
9
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ import { tmpdir } from "node:os";
12
+ import { opWaveOutcomeDir, opWaveRecordPath, type OpWavesSpec } from "./op-waves";
13
+ import { followOnAfterRecord, followOnChainOf, readOpWaveRestNote, withChainOutcomes, type OpWavesFollowOnTarget } from "./op-waves-follow-on";
14
+ import { memoryFollowOnChainPort, type FollowOnChainPort } from "./follow-on-store";
15
+ import { opWaveApplyStatus, postOpWaveApplyStatus } from "./apply-status";
16
+ import { applyOutcomeOf } from "../control/applied";
17
+ import { earlierWaveOutcomes, writeWaveOutcomeFile, type WaveMemberStatus } from "../wave-blocked";
18
+ import { CHANT_EXIT } from "../exit-codes";
19
+
20
+ const spec: OpWavesSpec = {
21
+ name: "tf-apply",
22
+ op: "tf-apply",
23
+ gateName: "wave-{k}",
24
+ digest: { over: "changing" },
25
+ planWave: ["tg", "plan", "{wave}", "{runs}", "{plans}"],
26
+ applyWave: ["tg", "apply", "{wave}", "{runs}", "{plans}"],
27
+ waves: [
28
+ { name: "layer", runs: [], discover: true, gate: "never" },
29
+ { name: "rest", runs: [], discover: true, rest: true, gate: "never" },
30
+ ],
31
+ };
32
+ const HEAD = "a".repeat(40);
33
+ const PUSHED = "d".repeat(40);
34
+ const DIGEST = `sha256:${"e".repeat(64)}`;
35
+
36
+ /** Each forge's record job: the follow-on target, and the variables a push's run and a decided head's run carry. */
37
+ const forges: Array<{ forge: OpWavesFollowOnTarget["forge"]; target: OpWavesFollowOnTarget; push: Record<string, string>; run: string; url?: string }> = [
38
+ { forge: "github", target: { forge: "github", workflow: "tf-apply.yml" }, push: { GITHUB_SHA: PUSHED, GITHUB_RUN_ID: "101", GITHUB_SERVER_URL: "https://github.com", GITHUB_REPOSITORY: "acme/infra" }, run: "101", url: "https://github.com/acme/infra/actions/runs/101" },
39
+ { forge: "forgejo", target: { forge: "forgejo", workflow: "tf-apply.yml" }, push: { GITHUB_SHA: PUSHED, GITHUB_RUN_ID: "7", GITHUB_SERVER_URL: "https://code.example", GITHUB_REPOSITORY: "acme/infra" }, run: "7" },
40
+ { forge: "gitlab", target: { forge: "gitlab" }, push: { CI_COMMIT_SHA: PUSHED, CI_PIPELINE_ID: "9001", CI_PIPELINE_URL: "https://gitlab.example/acme/infra/-/pipelines/9001" }, run: "9001", url: "https://gitlab.example/acme/infra/-/pipelines/9001" },
41
+ ];
42
+
43
+ /** A record job's checkout after wave `wave`: the gate's decision (the plan found `found` waves) and the run's outcomes. */
44
+ function recorded(wave: number, found: number, members: Record<string, WaveMemberStatus>, at: string): string {
45
+ const cwd = mkdtempSync(join(tmpdir(), "op-waves-follow-on-chain-"));
46
+ const dir = join(cwd, opWaveOutcomeDir(spec));
47
+ mkdirSync(dir, { recursive: true });
48
+ writeFileSync(join(cwd, opWaveRecordPath(spec, wave)), JSON.stringify({ wave, discovered: { waves: found } }));
49
+ writeWaveOutcomeFile(dir, wave, { apply: true }, Object.fromEntries(Object.entries(members).map(([m, status]) => [m, { status }])), at);
50
+ return cwd;
51
+ }
52
+
53
+ const outcomeIn = (cwd: string) => {
54
+ const dirs = [join(cwd, opWaveOutcomeDir(spec))];
55
+ return { dirs, own: applyOutcomeOf(earlierWaveOutcomes(dirs, Number.MAX_SAFE_INTEGER).members).outcome, chain: applyOutcomeOf(withChainOutcomes(earlierWaveOutcomes(dirs, Number.MAX_SAFE_INTEGER).members, readOpWaveRestNote(dirs))).outcome };
56
+ };
57
+
58
+ for (const f of forges) {
59
+ describe(`${f.forge}: a chain of follow-on runs (#4998)`, () => {
60
+ test("each record job records the follow-on, then starts it; the last run adds up the chain, so an unchanged last wave reports applied", async () => {
61
+ const chain = memoryFollowOnChainPort();
62
+ const env = { CHANT_WAVES_FOLLOW_ON: JSON.stringify(f.target), ...f.push };
63
+ const order: string[] = [];
64
+ const start = async (_t: OpWavesFollowOnTarget, wave: number) => {
65
+ // The record is on the ledger before the follow-on starts.
66
+ order.push(`start ${wave} with the record at wave ${(await chain.read("tf-apply", PUSHED))?.wave}`);
67
+ return {};
68
+ };
69
+ const at = (n: number) => () => new Date(`2026-11-10T12:0${n}:00.000Z`);
70
+
71
+ // Run 1: the rest wave (2) applies vpc; the plan found 4 waves.
72
+ const one = recorded(2, 4, { vpc: "applied" }, "2026-11-10T12:00:30.000Z");
73
+ expect(await followOnAfterRecord({ spec, wave: 2, exitCode: 0, cwd: one, env, chain, start, now: at(1), log: () => {} })).toBe(CHANT_EXIT.done);
74
+ expect(await chain.read("tf-apply", PUSHED)).toEqual({
75
+ key: PUSHED,
76
+ commit: PUSHED,
77
+ wave: 3,
78
+ from: 2,
79
+ run: f.run,
80
+ ...(f.url ? { url: f.url } : {}),
81
+ at: "2026-11-10T12:01:00.000Z",
82
+ outcomes: { vpc: { status: "applied", wave: 2, at: "2026-11-10T12:00:30.000Z" } },
83
+ });
84
+
85
+ // Run 2: wave 3 applies db, and records wave 4 with both runs' outcomes.
86
+ const two = recorded(3, 4, { db: "applied" }, "2026-11-10T12:02:30.000Z");
87
+ const follow = { ...env, CHANT_WAVES_WAVE: "3", CHANT_WAVES_COMMIT: PUSHED };
88
+ expect(await followOnAfterRecord({ spec, wave: 3, exitCode: 0, cwd: two, env: follow, chain, start, now: at(3), log: () => {} })).toBe(0);
89
+ expect(Object.keys((await chain.read("tf-apply", PUSHED))!.outcomes).sort()).toEqual(["db", "vpc"]);
90
+ expect(order).toEqual(["start 3 with the record at wave 3", "start 4 with the record at wave 4"]);
91
+
92
+ // Run 3, the last: wave 4 changes nothing. On its own it is unchanged; with the chain it applied.
93
+ const three = recorded(4, 4, { edge: "unchanged" }, "2026-11-10T12:04:30.000Z");
94
+ expect(await followOnAfterRecord({ spec, wave: 4, exitCode: 0, cwd: three, env: { ...follow, CHANT_WAVES_WAVE: "4" }, chain, start, now: at(5), log: () => {} })).toBe(0);
95
+ expect(order).toHaveLength(2);
96
+ const last = outcomeIn(three);
97
+ expect(last.own).toBe("unchanged");
98
+ expect(last.chain).toBe("applied");
99
+ expect(applyOutcomeOf(withChainOutcomes(earlierWaveOutcomes(last.dirs, Number.MAX_SAFE_INTEGER).members, readOpWaveRestNote(last.dirs))).applied).toEqual(["db", "vpc"]);
100
+
101
+ // The apply status of the last run posts the one success.
102
+ const posted: Array<{ state: string; description: string }> = [];
103
+ const forge = { kind: f.forge, setStatus: async (_sha: string, s: { state: string; description: string }) => void posted.push(s) };
104
+ expect(await postOpWaveApplyStatus({ forge, dirs: last.dirs, wave: 4, of: 2, context: "x/apply", at: PUSHED })).toBe(`x/apply on ${PUSHED.slice(0, 12)}: success: all 4 waves applied`);
105
+ });
106
+
107
+ test("a decided head's record names the decision; a last run that failed reports partial, not failed", async () => {
108
+ const chain = memoryFollowOnChainPort();
109
+ const env = { CHANT_WAVES_FOLLOW_ON: JSON.stringify(f.target), ...f.push, CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: DIGEST };
110
+ const one = recorded(2, 3, { vpc: "applied" }, "2026-11-10T12:00:30.000Z");
111
+ expect(await followOnAfterRecord({ spec, wave: 2, exitCode: 0, cwd: one, env, chain, start: async () => ({}), log: () => {} })).toBe(0);
112
+ expect(await chain.read("tf-apply", HEAD)).toMatchObject({ key: HEAD, pr: 7, digest: DIGEST, wave: 3, from: 2, run: f.run });
113
+ expect((await chain.read("tf-apply", HEAD))!.commit).toBeUndefined();
114
+ const two = recorded(3, 3, { db: "failed" }, "2026-11-10T12:02:30.000Z");
115
+ expect(await followOnAfterRecord({ spec, wave: 3, exitCode: CHANT_EXIT.failed, cwd: two, env: { ...env, CHANT_WAVES_WAVE: "3" }, chain, start: async () => Promise.reject(new Error("no start")), log: () => {} })).toBe(CHANT_EXIT.failed);
116
+ expect(outcomeIn(two)).toMatchObject({ own: "failed", chain: "partial" });
117
+ expect(opWaveApplyStatus(outcomeIn(two).dirs, 3, 3, f.forge)).toEqual({ state: "failed", description: "wave 3 of 3: 1 applied, 1 failed" });
118
+ });
119
+ });
120
+ }
121
+
122
+ describe("the record job's record (#4998)", () => {
123
+ const target: OpWavesFollowOnTarget = { forge: "github", workflow: "tf-apply.yml" };
124
+ const env = { CHANT_WAVES_FOLLOW_ON: JSON.stringify(target), GITHUB_SHA: PUSHED, GITHUB_RUN_ID: "5" };
125
+
126
+ test("a record that cannot be written starts no follow-on and fails the job", async () => {
127
+ const broken: FollowOnChainPort = { read: async () => undefined, write: async () => Promise.reject(new Error("could not push the follow-on record to chant/lifecycle (denied)")) };
128
+ const lines: string[] = [];
129
+ let started = 0;
130
+ const cwd = recorded(2, 3, { vpc: "applied" }, "2026-11-10T12:00:30.000Z");
131
+ expect(await followOnAfterRecord({ spec, wave: 2, exitCode: 0, cwd, env, chain: broken, start: async () => (started++, {}), log: (l) => lines.push(l) })).toBe(CHANT_EXIT.failed);
132
+ expect(started).toBe(0);
133
+ expect(lines.at(-1)).toContain("the follow-on for wave 3 could not be recorded on chant/lifecycle (could not push the follow-on record to chant/lifecycle (denied)), so none is started");
134
+ });
135
+
136
+ test("a follow-on whose record names another wave carries no chain, and says so", async () => {
137
+ const chain = memoryFollowOnChainPort();
138
+ await chain.write("tf-apply", { key: PUSHED, commit: PUSHED, wave: 5, from: 4, run: "4", at: "2026-11-10T12:00:00.000Z", outcomes: { vpc: { status: "applied", wave: 2, at: "2026-11-10T11:00:00.000Z" } } });
139
+ const lines: string[] = [];
140
+ const cwd = recorded(3, 3, { db: "unchanged" }, "2026-11-10T12:02:30.000Z");
141
+ await followOnAfterRecord({ spec, wave: 3, exitCode: 0, cwd, env: { ...env, CHANT_WAVES_WAVE: "3", CHANT_WAVES_COMMIT: PUSHED }, chain, start: async () => ({}), log: (l) => lines.push(l) });
142
+ expect(readOpWaveRestNote([join(cwd, opWaveOutcomeDir(spec))])?.chain).toBeUndefined();
143
+ expect(lines[0]).toContain("no record on chant/lifecycle started this wave");
144
+ });
145
+
146
+ test("the chain's key: the decided head before merge, else the commit the run applied", () => {
147
+ expect(followOnChainOf("github", { GITHUB_SHA: PUSHED })).toEqual({ key: PUSHED, commit: PUSHED });
148
+ expect(followOnChainOf("gitlab", { CI_COMMIT_SHA: "f".repeat(40), CHANT_WAVES_COMMIT: PUSHED })).toEqual({ key: PUSHED, commit: PUSHED });
149
+ expect(followOnChainOf("forgejo", { CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: DIGEST, GITHUB_SHA: PUSHED })).toEqual({ key: HEAD, pr: 7, digest: DIGEST });
150
+ expect(followOnChainOf("github", {})).toBeUndefined();
151
+ });
152
+ });
@@ -0,0 +1,247 @@
1
+ /**
2
+ * #4992: a `rest` wave before merge runs one wave per run. Its four jobs
3
+ * run the wave a follow-on run names, past the spec's waves; the record job
4
+ * leaves a note and, when the run applied and the plan found another wave,
5
+ * starts the follow-on; `before-merge-done`, the apply status and the
6
+ * control outcome take a run that started one as not the last.
7
+ */
8
+ import { describe, expect, test } from "vitest";
9
+ import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ import { tmpdir } from "node:os";
12
+ import { opWaveJobs, opWaveOutcomeDir, opWaveRecordPath, type OpWavesSpec } from "./op-waves";
13
+ import { runOpWave, type OpWaveExec, type OpWaveRunPort, type OpWaveRunsFile, type OpWaveShowAtBase } from "./op-waves-run";
14
+ import { opWaveSavedPlanPath, opWaveSplitJobs } from "./op-waves-split";
15
+ import {
16
+ followOnAfterRecord,
17
+ OP_WAVE_REST_NOTE,
18
+ opWaveRestPath,
19
+ opWavesRestWave,
20
+ parseFollowOnTarget,
21
+ readOpWaveRestNote,
22
+ startFollowOn,
23
+ type OpWavesFollowOnTarget,
24
+ } from "./op-waves-follow-on";
25
+ import { memoryGateLedgerPort } from "./gate";
26
+ import { memoryFollowOnChainPort } from "./follow-on-store";
27
+ import { beforeMergeDone } from "./before-merge-done";
28
+ import { beforeMergeDigest } from "./before-merge";
29
+ import { opWaveApplyStatus, postOpWaveApplyStatus } from "./apply-status";
30
+ import { writeWaveOutcomeFile } from "../wave-blocked";
31
+ import { resolveProductWords } from "../ci-product-words";
32
+ import { CHANT_EXIT } from "../exit-codes";
33
+
34
+ const digest = (n: string) => `sha256:${n.repeat(64)}`;
35
+ const spec: OpWavesSpec = {
36
+ name: "tf-apply",
37
+ op: "tf-apply",
38
+ gateName: "wave-{k}",
39
+ digest: { over: "changing" },
40
+ planWave: ["tg", "plan", "{wave}", "{runs}", "{plans}"],
41
+ applyWave: ["tg", "apply", "{wave}", "{runs}", "{plans}"],
42
+ waves: [
43
+ { name: "layer", runs: [], discover: true, gate: "never" },
44
+ { name: "rest", runs: [], discover: true, rest: true, gate: "never" },
45
+ ],
46
+ };
47
+ const github: OpWavesFollowOnTarget = { forge: "github", workflow: "tf-apply.yml" };
48
+ const env = { CHANT_WAVES_FOLLOW_ON: JSON.stringify(github), GITHUB_SHA: "d".repeat(40) };
49
+ /** #4998: the record each record job writes before it starts a follow-on, held in memory. */
50
+ const chain = memoryFollowOnChainPort();
51
+
52
+ /** A job's checkout: `layers[k-1]` is what wave k's plan finds. */
53
+ function checkout(layers: Array<Record<string, { planDigest: string }>>) {
54
+ const cwd = mkdtempSync(join(tmpdir(), "op-waves-follow-on-"));
55
+ const calls: string[] = [];
56
+ const exec: OpWaveExec = (argv, dir) => {
57
+ calls.push(argv.join(" "));
58
+ const runs = JSON.parse(readFileSync(join(dir, argv[3]!), "utf-8")) as OpWaveRunsFile;
59
+ if (argv[1] === "plan") {
60
+ const found = layers[runs.number - 1] ?? {};
61
+ writeFileSync(join(dir, argv[4]!), JSON.stringify({ runs: Object.entries(found).map(([target, p]) => ({ target, ...p })), waves: layers.length }));
62
+ }
63
+ return 0;
64
+ };
65
+ const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(spec) });
66
+ const records: unknown[] = [];
67
+ const runs: OpWaveRunPort = { append: async (r) => void records.push(r) };
68
+ return { cwd, calls, records, base: { spec, specFile: "waves.json", cwd, exec, show, log: () => {}, now: "2026-11-10T00:00:00.000Z" }, runs };
69
+ }
70
+
71
+ /** The four jobs of the rest wave's slot running wave `k`, each in the same checkout (the artifacts carry the files between them). */
72
+ async function runSlot(c: ReturnType<typeof checkout>, k: number) {
73
+ const gates = memoryGateLedgerPort();
74
+ const noRuns: OpWaveRunPort = { append: async () => Promise.reject(new Error("this job writes no run record to the ledger")) };
75
+ const plan = await runOpWave({ ...c.base, wave: k, phase: "plan", gates, runs: noRuns });
76
+ const gate = await runOpWave({ ...c.base, wave: k, phase: "gate", gates });
77
+ const apply = await runOpWave({ ...c.base, wave: k, phase: "apply", gates, runs: noRuns });
78
+ const record = await runOpWave({ ...c.base, wave: k, phase: "record", runs: c.runs });
79
+ return { plan, gate, apply, record };
80
+ }
81
+
82
+ const layers: Array<Record<string, { planDigest: string }>> = [{ vpc: { planDigest: digest("1") } }, { db: { planDigest: digest("2") } }, { app: { planDigest: digest("3") } }, { edge: { planDigest: digest("4") } }];
83
+
84
+ describe("the rest wave's jobs run the wave a follow-on run names (#4992)", () => {
85
+ test("the split jobs of the rest wave name the wave CHANT_WAVES_WAVE gives, their own by default", () => {
86
+ const split = opWaveSplitJobs(spec, opWaveJobs(spec, "waves.json", { beforeMerge: true }));
87
+ const rest = split.filter((j) => j.rest);
88
+ expect(rest.map((j) => j.jobName)).toEqual(["wave-2-rest-plan", "wave-2-rest-gate", "wave-2-rest", "wave-2-rest-record"]);
89
+ expect(rest[0]!.command.join(" ")).toBe('chant run wave --spec waves.json --wave "${CHANT_WAVES_WAVE:-2}" --base "${CHANT_WAVES_BASE:-HEAD^1}" --phase plan');
90
+ expect(split.find((j) => j.jobName === "wave-1-layer-plan")!.command.join(" ")).toContain("--wave 1 ");
91
+ expect(opWavesRestWave(spec)).toBe(2);
92
+ expect(opWavesRestWave({ waves: [spec.waves[0]!] })).toBeUndefined();
93
+ });
94
+
95
+ test("a rest wave's paths name the wave the run gives, and nothing else that holds its number", () => {
96
+ expect(opWaveRestPath(".chant/op-waves/x/wave-2/saved-plan.json", 2, "$W")).toBe(".chant/op-waves/x/wave-$W/saved-plan.json");
97
+ expect(opWaveRestPath(".chant/op-waves/x/outcomes/outcome-wave-2-apply.json", 2, "$W")).toBe(".chant/op-waves/x/outcomes/outcome-wave-$W-apply.json");
98
+ expect(opWaveRestPath(".chant/op-waves/x/outcomes/run-record-wave-2.json", 2, "$W")).toBe(".chant/op-waves/x/outcomes/run-record-wave-$W.json");
99
+ expect(opWaveRestPath(".chant/op-waves/x/wave-20.json", 2, "$W")).toBe(".chant/op-waves/x/wave-20.json");
100
+ });
101
+
102
+ test("the run applies wave 2 and starts wave 3; the follow-on applies waves 3 and 4, and the last starts none", async () => {
103
+ const first = checkout(layers);
104
+ const slot = await runSlot(first, 2);
105
+ expect(slot.record).toMatchObject({ exitCode: 0, applied: ["db"] });
106
+ const started: Array<[OpWavesFollowOnTarget, number]> = [];
107
+ const start = async (t: OpWavesFollowOnTarget, wave: number) => (started.push([t, wave]), {});
108
+ expect(await followOnAfterRecord({ spec, wave: 2, exitCode: slot.record.exitCode, cwd: first.cwd, env, chain, start, log: () => {} })).toBe(CHANT_EXIT.done);
109
+ expect(started).toEqual([[github, 3]]);
110
+ expect(readOpWaveRestNote([join(first.cwd, opWaveOutcomeDir(spec))])).toEqual({ version: 1, op: "tf-apply", wave: 2, found: 4, next: 3 });
111
+
112
+ // The follow-on run: a fresh checkout, the rest wave's jobs at wave 3, past the spec's two waves.
113
+ const second = checkout(layers);
114
+ const three = await runSlot(second, 3);
115
+ expect(three.plan.exitCode).toBe(0);
116
+ expect(JSON.parse(readFileSync(join(second.cwd, opWaveSavedPlanPath(spec, 3)), "utf-8"))).toMatchObject({ wave: 3, name: "rest", members: [{ member: "app" }] });
117
+ expect(three.gate.decision).toMatchObject({ status: "not-required", discovered: { waves: 4 } });
118
+ expect(three.record).toMatchObject({ exitCode: 0, applied: ["app"] });
119
+ // Planned once, in the plan job, and applied once, in the applying job, at wave 3's files.
120
+ expect(second.calls.map((c) => c.split(" ").slice(0, 3).join(" "))).toEqual(["tg plan rest", "tg apply rest"]);
121
+ expect(second.calls[1]).toContain("wave-3");
122
+ expect(await followOnAfterRecord({ spec, wave: 3, exitCode: three.record.exitCode, cwd: second.cwd, env, chain, start, log: () => {} })).toBe(0);
123
+ expect(started.at(-1)).toEqual([github, 4]);
124
+
125
+ const third = checkout(layers);
126
+ const four = await runSlot(third, 4);
127
+ expect(four.record).toMatchObject({ exitCode: 0, applied: ["edge"] });
128
+ expect(await followOnAfterRecord({ spec, wave: 4, exitCode: four.record.exitCode, cwd: third.cwd, env, chain, start, log: () => {} })).toBe(0);
129
+ expect(started).toHaveLength(2);
130
+ // #4998: the last run's note carries the outcomes of the runs before it, from the record that started it.
131
+ const note = readOpWaveRestNote([join(third.cwd, opWaveOutcomeDir(spec))]);
132
+ expect({ ...note, chain: undefined }).toEqual({ version: 1, op: "tf-apply", wave: 4, found: 4, chain: undefined });
133
+ expect(Object.fromEntries(Object.entries(note!.chain!).map(([m, o]) => [m, [o.status, o.wave]]))).toEqual({ db: ["applied", 2], app: ["applied", 3] });
134
+ });
135
+ });
136
+
137
+ /** A record job's checkout after wave `wave`: the gate's decision and the outcomes. */
138
+ function recorded(wave: number, found: number, status: "applied" | "failed" = "applied"): string {
139
+ const cwd = mkdtempSync(join(tmpdir(), "op-waves-follow-on-record-"));
140
+ mkdirSync(join(cwd, opWaveOutcomeDir(spec)), { recursive: true });
141
+ writeFileSync(join(cwd, opWaveRecordPath(spec, wave)), JSON.stringify({ wave, discovered: { waves: found } }));
142
+ writeWaveOutcomeFile(join(cwd, opWaveOutcomeDir(spec)), wave, { apply: true }, { db: { status } });
143
+ return cwd;
144
+ }
145
+
146
+ describe("the rest wave's record job (#4992)", () => {
147
+ const none = async () => Promise.reject(new Error("no follow-on starts here"));
148
+
149
+ test("a run that failed, or a plan that found no more waves, starts nothing and says it is the last", async () => {
150
+ const failed = recorded(2, 4, "failed");
151
+ expect(await followOnAfterRecord({ spec, wave: 2, exitCode: CHANT_EXIT.failed, cwd: failed, env, chain, start: none, log: () => {} })).toBe(CHANT_EXIT.failed);
152
+ expect(readOpWaveRestNote([join(failed, opWaveOutcomeDir(spec))])).toEqual({ version: 1, op: "tf-apply", wave: 2, found: 4 });
153
+ const done = recorded(2, 2);
154
+ expect(await followOnAfterRecord({ spec, wave: 2, exitCode: 0, cwd: done, env, chain, start: none, log: () => {} })).toBe(0);
155
+ expect(readOpWaveRestNote([join(done, opWaveOutcomeDir(spec))])).toEqual({ version: 1, op: "tf-apply", wave: 2, found: 2 });
156
+ });
157
+
158
+ test("a follow-on that cannot be started fails the job, and the note still says one was to start", async () => {
159
+ const cwd = recorded(2, 3);
160
+ const lines: string[] = [];
161
+ expect(await followOnAfterRecord({ spec, wave: 2, exitCode: 0, cwd, env, chain, start: async () => Promise.reject(new Error("403 Forbidden")), log: (l) => lines.push(l) })).toBe(CHANT_EXIT.failed);
162
+ expect(lines.at(-1)).toContain("the follow-on run for wave 3 could not be started (403 Forbidden)");
163
+ expect(readOpWaveRestNote([join(cwd, opWaveOutcomeDir(spec))])?.next).toBe(3);
164
+ });
165
+
166
+ test("a job that is not the rest wave's, or a pipeline that sets no follow-on, is left as it is", async () => {
167
+ const cwd = recorded(1, 4);
168
+ expect(await followOnAfterRecord({ spec, wave: 1, exitCode: 0, cwd, env, chain, start: none })).toBe(0);
169
+ expect(await followOnAfterRecord({ spec, wave: 2, exitCode: 0, cwd: recorded(2, 4), env: {}, start: none })).toBe(0);
170
+ expect(() => readFileSync(join(cwd, opWaveOutcomeDir(spec), OP_WAVE_REST_NOTE))).toThrow();
171
+ expect(() => parseFollowOnTarget('{"forge":"github"}')).toThrow("workflow");
172
+ expect(parseFollowOnTarget('{"forge":"gitlab"}')).toEqual({ forge: "gitlab" });
173
+ });
174
+ });
175
+
176
+ describe("starting the follow-on on each forge (#4992)", () => {
177
+ const HEAD = "a".repeat(40);
178
+ const PUSHED = "d".repeat(40);
179
+ const posts: Array<{ url: string; headers: Record<string, string>; body: unknown }> = [];
180
+ const fetchFn = (async (url: string, init: { headers: Record<string, string>; body: string }) => {
181
+ posts.push({ url, headers: init.headers, body: JSON.parse(init.body) });
182
+ return new Response(JSON.stringify({ web_url: "https://gitlab.example/acme/infra/-/pipelines/9" }), { status: 201 });
183
+ }) as unknown as typeof fetch;
184
+
185
+ test("GitHub dispatches the workflow on its branch with the decision and the wave", async () => {
186
+ await startFollowOn(github, 3, { GITHUB_REPOSITORY: "acme/infra", GITHUB_API_URL: "https://api.github.com", GITHUB_REF_NAME: "main", CHANT_WAVES_FOLLOW_ON_TOKEN: "job-token", CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: digest("e") }, fetchFn);
187
+ expect(posts.at(-1)).toMatchObject({ url: "https://api.github.com/repos/acme/infra/actions/workflows/tf-apply.yml/dispatches", headers: { Authorization: "token job-token" }, body: { ref: "main", inputs: { pr: "7", head: HEAD, digest: digest("e"), wave: "3" } } });
188
+ });
189
+
190
+ test("Forgejo dispatches a push's follow-on with the commit the run applied, with CHANT_FORGE_TOKEN", async () => {
191
+ await startFollowOn({ forge: "forgejo", workflow: "tf-apply.yml" }, 4, { FORGEJO_REPOSITORY: "acme/infra", FORGEJO_SERVER_URL: "https://code.example", GITHUB_REF: "refs/heads/main", CHANT_FORGE_TOKEN: "pat", CHANT_WAVES_COMMIT: PUSHED, GITHUB_SHA: "f".repeat(40) }, fetchFn);
192
+ expect(posts.at(-1)).toMatchObject({ url: "https://code.example/api/v1/repos/acme/infra/actions/workflows/tf-apply.yml/dispatches", headers: { Authorization: "token pat" }, body: { ref: "main", inputs: { wave: "4", commit: PUSHED } } });
193
+ });
194
+
195
+ test("GitLab starts a pipeline of the branch with the variables, with CHANT_FORGE_TOKEN", async () => {
196
+ const started = await startFollowOn({ forge: "gitlab" }, 3, { CI_API_V4_URL: "https://gitlab.example/api/v4", CI_PROJECT_ID: "42", CI_COMMIT_REF_NAME: "main", CI_COMMIT_SHA: PUSHED, CHANT_FORGE_TOKEN: "pat", CI_JOB_TOKEN: "job" }, fetchFn);
197
+ expect(started.url).toBe("https://gitlab.example/acme/infra/-/pipelines/9");
198
+ expect(posts.at(-1)).toMatchObject({
199
+ url: "https://gitlab.example/api/v4/projects/42/pipeline",
200
+ headers: { "PRIVATE-TOKEN": "pat" },
201
+ body: { ref: "main", variables: [{ key: "CHANT_WAVES_WAVE", value: "3", variable_type: "env_var" }, { key: "CHANT_WAVES_COMMIT", value: PUSHED, variable_type: "env_var" }] },
202
+ });
203
+ });
204
+ });
205
+
206
+ describe("the jobs after the waves read the note (#4992)", () => {
207
+ const words = resolveProductWords({});
208
+ const HEAD = "a".repeat(40);
209
+ const decision = { pr: 7, head: HEAD, base: "c".repeat(40), at: "2026-11-10T12:00:00.000Z", by: "alice" };
210
+ const record = { ...decision, digest: beforeMergeDigest("tf-apply", decision) };
211
+
212
+ test("before-merge-done merges nothing in a run that started a follow-on, and posts nothing", async () => {
213
+ const said: string[] = [];
214
+ const done = await beforeMergeDone({
215
+ op: "tf-apply",
216
+ waves: 2,
217
+ run: { pr: "7", head: HEAD, digest: record.digest },
218
+ record,
219
+ outcome: { outcome: "applied", applied: ["db"], counts: { applied: 1 } },
220
+ followOn: { wave: 2, next: 3, found: 4 },
221
+ merge: "auto",
222
+ forge: { kind: "github", addComment: async (_pr, text) => (said.push(text), { id: 1 }) },
223
+ release: async () => Promise.reject(new Error("nothing is released")),
224
+ words,
225
+ });
226
+ expect(done).toEqual({ code: 0, text: `wave 2 of 4 applied pull request 7's head ${HEAD.slice(0, 12)}, and a follow-on run goes on with wave 3; its done job merges, so nothing is merged here` });
227
+ expect(said).toEqual([]);
228
+ });
229
+
230
+ test("the apply status counts the waves the plan found, and stays pending in a run that started a follow-on", async () => {
231
+ const started = recorded(2, 4);
232
+ const dir = join(started, opWaveOutcomeDir(spec));
233
+ await followOnAfterRecord({ spec, wave: 2, exitCode: 0, cwd: started, env, chain, start: async () => ({}), log: () => {} });
234
+ const posted: unknown[] = [];
235
+ const forge = { kind: "github" as const, setStatus: async (_sha: string, s: unknown) => void posted.push(s) };
236
+ expect(await postOpWaveApplyStatus({ forge, dirs: [dir], wave: 2, of: 2, context: "x/apply", at: HEAD })).toContain("running: wave 2 of 4 applied");
237
+ // The last follow-on run, wave 4 of 4, posts the one success.
238
+ const last = recorded(4, 4);
239
+ await followOnAfterRecord({ spec, wave: 4, exitCode: 0, cwd: last, env, chain, start: async () => ({}), log: () => {} });
240
+ expect(await postOpWaveApplyStatus({ forge, dirs: [join(last, opWaveOutcomeDir(spec))], wave: 4, of: 2, context: "x/apply", at: HEAD })).toContain("success: all 4 waves applied");
241
+ // A follow-on whose gate waits leaves no note: the wave it ran is counted as the last one known.
242
+ const waiting = mkdtempSync(join(tmpdir(), "op-waves-follow-on-wait-"));
243
+ writeWaveOutcomeFile(waiting, 3, {}, { app: { status: "waiting" } });
244
+ expect(opWaveApplyStatus([waiting], 3, 3, "github")).toEqual({ state: "running", description: "wave 3 of 3 waits for an approval" });
245
+ expect(await postOpWaveApplyStatus({ forge, dirs: [waiting], wave: 3, of: 2, context: "x/apply", at: HEAD })).toContain("wave 3 of 3 waits for an approval");
246
+ });
247
+ });