@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,385 @@
1
+ /**
2
+ * `rest` waves in a split pipeline (#4992): one wave per run, each run
3
+ * starting the next.
4
+ *
5
+ * Maintainer decision (2026-11-10): a follow-on run. Before merge (and on a
6
+ * push of the same pipeline) each wave is four jobs (./op-waves-split.ts),
7
+ * and the jobs of a wave the plan finds at run time cannot be rendered up
8
+ * front. So the rest wave's four jobs (the last rendered wave, N) run wave
9
+ * N in a run, and their record job, once every wave of the run applied and
10
+ * the plan found more waves, starts the waves workflow again for wave N+1:
11
+ *
12
+ * - GitHub and Forgejo dispatch the workflow on its branch with the inputs
13
+ * `wave` and, before merge, `pr`, `head` and `digest`, or, for a push,
14
+ * `commit` (the pushed commit, which every job of the follow-on checks
15
+ * out and checks is on the branch). GitHub dispatches with the job's
16
+ * token (`actions: write` on that job alone); Forgejo with the
17
+ * `CHANT_FORGE_TOKEN` secret, as its resume does.
18
+ * - GitLab starts a pipeline of the branch with the same values as
19
+ * variables (`CHANT_WAVES_WAVE`, the decision's three or
20
+ * `CHANT_WAVES_COMMIT`), with `CHANT_FORGE_TOKEN`, since the job token
21
+ * cannot start one.
22
+ *
23
+ * In the follow-on the jobs of waves 1 to N-1 do not run, and the rest
24
+ * wave's jobs run wave N+1 (`--wave "${CHANT_WAVES_WAVE:-N}"`, and their
25
+ * files at that wave's paths, {@link opWaveRestPath}). The guard admits the
26
+ * run as the same decided head (./follow-on-run.ts). It goes on until the
27
+ * wave the plan found last.
28
+ *
29
+ * The record job leaves a note in the outcome directory
30
+ * ({@link OP_WAVE_REST_NOTE}): the wave it ran, how many the plan found, and
31
+ * the wave it started, if it started one. `before-merge-done`, the control
32
+ * dispatch and the apply status read it, so a run that started a follow-on
33
+ * is not the last: nothing merges, the control repo hears from the last
34
+ * run, and the status stays pending with `wave k of M applied`.
35
+ *
36
+ * #4998: before it starts a follow-on, the record job records it on
37
+ * `chant/lifecycle` (./follow-on-run.ts, ./follow-on-store.ts): the wave it
38
+ * starts, its own run, the decision or the pushed commit, and the outcomes
39
+ * of every run of the chain so far, its own added. The follow-on's guard
40
+ * admits that wave alone. A follow-on's record job reads the record that
41
+ * started it and puts the earlier runs' outcomes in its note as `chain`, so
42
+ * the last run's control dispatch and apply status add up the whole chain
43
+ * ({@link withChainOutcomes}): a chain whose last wave changed nothing
44
+ * reports `applied` when an earlier run applied.
45
+ */
46
+
47
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
48
+ import { isAbsolute, join } from "node:path";
49
+ import { CHANT_EXIT } from "../exit-codes";
50
+ import { CONTROL_OUTCOME_VAR } from "../control/dispatch";
51
+ import { beforeMergeRunFromEnv, isBeforeMergeRun } from "./before-merge";
52
+ import { OP_WAVES_COMMIT_ENV, OP_WAVES_WAVE_ENV, type FollowOnChainPort, type FollowOnOutcome, type FollowOnRecord } from "./follow-on-run";
53
+ import type { WaveMemberOutcome } from "../wave-blocked";
54
+ import { opWaveOutcomeDir, opWaveRecordPath, type OpWavesSpec } from "./op-waves";
55
+
56
+ export { FOLLOW_ON_INPUTS, OP_WAVES_COMMIT_ENV, OP_WAVES_WAVE_ENV } from "./follow-on-run";
57
+
58
+ /** The variable the rest wave's record job is told how to start a follow-on in: `{ "forge": ..., "workflow": ... }` as JSON. */
59
+ export const OP_WAVES_FOLLOW_ON_ENV = "CHANT_WAVES_FOLLOW_ON";
60
+
61
+ /**
62
+ * The variable the rest wave's record step hands the token that starts the
63
+ * follow-on in (GitHub: the job's token; Forgejo: the `CHANT_FORGE_TOKEN`
64
+ * secret), so no other line of the job reads it as the forge's token.
65
+ * Unset (GitLab), the record job reads {@link FORGE_TOKEN_VAR}.
66
+ */
67
+ export const FOLLOW_ON_TOKEN_ENV = "CHANT_WAVES_FOLLOW_ON_TOKEN";
68
+
69
+ /** The secret (Forgejo) or CI/CD variable (GitLab) a token that may start a run is kept in. */
70
+ export const FORGE_TOKEN_VAR = "CHANT_FORGE_TOKEN";
71
+
72
+ /** How the rest wave's record job starts a follow-on. */
73
+ export interface OpWavesFollowOnTarget {
74
+ forge: "github" | "forgejo" | "gitlab";
75
+ /** GitHub and Forgejo: the waves workflow's file name, which the record job dispatches. */
76
+ workflow?: string;
77
+ }
78
+
79
+ /** The rest wave's number when the spec's last wave has `rest`, else undefined. */
80
+ export function opWavesRestWave(spec: Pick<OpWavesSpec, "waves">): number | undefined {
81
+ return spec.waves[spec.waves.length - 1]?.rest === true ? spec.waves.length : undefined;
82
+ }
83
+
84
+ /**
85
+ * A path of the rest wave's (`wave-N.json`, `wave-N/`, `outcome-wave-N-apply.json`,
86
+ * `run-record-wave-N.json`) with its wave number put as `token`, the form
87
+ * the forge reads `CHANT_WAVES_WAVE` in at that place.
88
+ */
89
+ export function opWaveRestPath(path: string, wave: number, token: string): string {
90
+ return path.replace(new RegExp(`(^|[/-])wave-${wave}(?=[./-]|$)`, "g"), (_m, lead: string) => `${lead}wave-${token}`);
91
+ }
92
+
93
+ /** The value of {@link OP_WAVES_FOLLOW_ON_ENV} for a forge. */
94
+ export function opWavesFollowOnEnv(target: OpWavesFollowOnTarget): string {
95
+ return JSON.stringify(target);
96
+ }
97
+
98
+ /** Read {@link OP_WAVES_FOLLOW_ON_ENV}; undefined when unset, and a value that is no target throws. */
99
+ export function parseFollowOnTarget(raw: string | undefined): OpWavesFollowOnTarget | undefined {
100
+ if (raw === undefined || raw.trim() === "") return undefined;
101
+ let v: unknown;
102
+ try {
103
+ v = JSON.parse(raw);
104
+ } catch {
105
+ throw new Error(`${OP_WAVES_FOLLOW_ON_ENV} is not JSON`);
106
+ }
107
+ const o = v as Partial<OpWavesFollowOnTarget> | null;
108
+ if (!o || (o.forge !== "github" && o.forge !== "forgejo" && o.forge !== "gitlab")) throw new Error(`${OP_WAVES_FOLLOW_ON_ENV}.forge is github, forgejo or gitlab`);
109
+ if (o.forge !== "gitlab" && (typeof o.workflow !== "string" || !/^[A-Za-z0-9._-]+\.ya?ml$/.test(o.workflow))) throw new Error(`${OP_WAVES_FOLLOW_ON_ENV}.workflow names the waves workflow's file`);
110
+ return { forge: o.forge, ...(o.workflow ? { workflow: o.workflow } : {}) };
111
+ }
112
+
113
+ /**
114
+ * The lines every job of the rest wave runs after its checkout (#4992): in
115
+ * a push's follow-on, stop (exit 9, `misplaced`) unless the commit it goes
116
+ * on with is on the branch the run checked out, then check that commit
117
+ * out. Nothing in any other run. The guard checked it is a commit sha.
118
+ */
119
+ export function followOnCommitScript(product: string): string {
120
+ return [
121
+ `if [ -n "\${${OP_WAVES_COMMIT_ENV}:-}" ]; then`,
122
+ ` git merge-base --is-ancestor "$${OP_WAVES_COMMIT_ENV}" HEAD || { echo "${product}: the follow-on's commit $(printf %.12s "$${OP_WAVES_COMMIT_ENV}") is not on the branch this run checked out, so nothing is applied" >&2; exit ${CHANT_EXIT.misplaced}; }`,
123
+ ` git checkout -q --detach "$${OP_WAVES_COMMIT_ENV}" || exit 1`,
124
+ "fi",
125
+ ].join("\n");
126
+ }
127
+
128
+ /**
129
+ * The first line of the control dispatch's script in a pipeline with a rest
130
+ * wave (#4992): `chant run wave --waves-outcome` adds up nothing for a run
131
+ * that started a follow-on, and the dispatch sends nothing then; the last
132
+ * run of the waves sends the outcome.
133
+ */
134
+ export function followOnControlSkip(product: string): string {
135
+ return `if [ -z "\${${CONTROL_OUTCOME_VAR}:-}" ]; then echo "${product}: this run started a follow-on run for the next wave, which tells the control repo how the waves ended"; exit 0; fi`;
136
+ }
137
+
138
+ /** The note the rest wave's record job leaves in the outcome directory. */
139
+ export const OP_WAVE_REST_NOTE = "rest-wave.json";
140
+
141
+ /** What the note holds. */
142
+ export interface OpWaveRestNote {
143
+ version: 1;
144
+ op: string;
145
+ /** The wave the run's rest wave jobs ran. */
146
+ wave: number;
147
+ /** How many waves the plan found. */
148
+ found: number;
149
+ /** The wave of the follow-on the record job started. Absent: this run is the last. */
150
+ next?: number;
151
+ /** A follow-on's: the outcomes of the chain's earlier runs, by member (#4998), from the record that started it. */
152
+ chain?: Record<string, FollowOnOutcome>;
153
+ }
154
+
155
+ /** A member's outcome as the jobs after the waves add it up: `earlierWaveOutcomes`' entries. */
156
+ export type ChainedOutcome = WaveMemberOutcome & { wave: number; at: string };
157
+
158
+ /** The outcomes of a chain's runs: a valid entry of each, the rest dropped. */
159
+ function chainOf(v: unknown): Record<string, FollowOnOutcome> | undefined {
160
+ if (!v || typeof v !== "object") return undefined;
161
+ const out: Record<string, FollowOnOutcome> = {};
162
+ for (const [member, o] of Object.entries(v as Record<string, Partial<FollowOnOutcome> | null>)) {
163
+ if (!o || typeof o.status !== "string" || !Number.isInteger(o.wave) || typeof o.at !== "string" || (o.by !== undefined && typeof o.by !== "string")) continue;
164
+ out[member] = { status: o.status, ...(o.by !== undefined ? { by: o.by } : {}), wave: o.wave!, at: o.at };
165
+ }
166
+ return Object.keys(out).length > 0 ? out : undefined;
167
+ }
168
+
169
+ /**
170
+ * The outcomes the jobs after the waves add up (#4998): this run's, from
171
+ * its outcome files (`members`, `earlierWaveOutcomes` below wave `before`),
172
+ * with the chain's earlier runs' from the rest wave's note. A member's
173
+ * newer outcome wins. With no note, or one with no chain, `members`.
174
+ */
175
+ export function withChainOutcomes(members: ReadonlyMap<string, ChainedOutcome>, note: OpWaveRestNote | undefined, before: number = Number.MAX_SAFE_INTEGER): Map<string, ChainedOutcome> {
176
+ const out = new Map<string, ChainedOutcome>();
177
+ for (const [member, o] of Object.entries(note?.chain ?? {})) if (o.wave < before) out.set(member, o as ChainedOutcome);
178
+ for (const [member, o] of members) {
179
+ const had = out.get(member);
180
+ if (!had || had.at <= o.at) out.set(member, o);
181
+ }
182
+ return out;
183
+ }
184
+
185
+ /** Where the record job writes the note. */
186
+ export function opWaveRestNotePath(spec: Pick<OpWavesSpec, "name">): string {
187
+ return `${opWaveOutcomeDir(spec)}/${OP_WAVE_REST_NOTE}`;
188
+ }
189
+
190
+ /** The note under `dirs` (downloaded artifacts keep it in a directory of their own, four deep at most), the newest wave's when there are more. */
191
+ export function readOpWaveRestNote(dirs: readonly string[]): OpWaveRestNote | undefined {
192
+ let found: OpWaveRestNote | undefined;
193
+ const walk = (dir: string, depth: number): void => {
194
+ let names: string[];
195
+ try {
196
+ names = readdirSync(dir);
197
+ } catch {
198
+ return;
199
+ }
200
+ for (const name of names) {
201
+ const abs = join(dir, name);
202
+ let isDir = false;
203
+ try {
204
+ isDir = statSync(abs).isDirectory();
205
+ } catch {
206
+ continue;
207
+ }
208
+ if (isDir) {
209
+ if (depth < 4) walk(abs, depth + 1);
210
+ continue;
211
+ }
212
+ if (name !== OP_WAVE_REST_NOTE) continue;
213
+ let v: Partial<OpWaveRestNote> | null;
214
+ try {
215
+ v = JSON.parse(readFileSync(abs, "utf-8")) as Partial<OpWaveRestNote> | null;
216
+ } catch {
217
+ continue;
218
+ }
219
+ if (!v || v.version !== 1 || typeof v.op !== "string" || !Number.isInteger(v.wave) || !Number.isInteger(v.found)) continue;
220
+ if (v.next !== undefined && (!Number.isInteger(v.next) || v.next !== v.wave! + 1)) continue;
221
+ const chain = chainOf(v.chain);
222
+ if (!found || v.wave! > found.wave) found = { version: 1, op: v.op, wave: v.wave!, found: v.found!, ...(v.next !== undefined ? { next: v.next } : {}), ...(chain ? { chain } : {}) };
223
+ }
224
+ };
225
+ for (const d of dirs) if (existsSync(d)) walk(d, 0);
226
+ return found;
227
+ }
228
+
229
+ /** A started run, as the forge links it. */
230
+ export interface StartedFollowOn {
231
+ url?: string;
232
+ }
233
+
234
+ /** What {@link followOnAfterRecord} takes. */
235
+ export interface FollowOnAfterRecordInput {
236
+ spec: OpWavesSpec;
237
+ /** The wave the record job wrote. */
238
+ wave: number;
239
+ /** The record job's exit. */
240
+ exitCode: number;
241
+ cwd?: string;
242
+ env?: Record<string, string | undefined>;
243
+ /** Start the follow-on; default the forge's API ({@link startFollowOn}). */
244
+ start?: (target: OpWavesFollowOnTarget, wave: number, env: Record<string, string | undefined>) => Promise<StartedFollowOn>;
245
+ /** Where the chain's record is read and written (#4998); default `chant/lifecycle` through the checkout's git. */
246
+ chain?: FollowOnChainPort;
247
+ now?: () => Date;
248
+ log?: (line: string) => void;
249
+ }
250
+
251
+ /** What a chain is keyed by and what its record names (#4998): before merge the decision, for a push the commit the run applied. */
252
+ export function followOnChainOf(forge: OpWavesFollowOnTarget["forge"], env: Record<string, string | undefined>): Pick<FollowOnRecord, "key" | "pr" | "digest" | "commit"> | undefined {
253
+ const run = beforeMergeRunFromEnv(env);
254
+ if (isBeforeMergeRun(run)) return run.head ? { key: run.head, ...(run.pr && /^[1-9][0-9]*$/.test(run.pr) ? { pr: Number(run.pr) } : {}), ...(run.digest ? { digest: run.digest } : {}) } : undefined;
255
+ const commit = env[OP_WAVES_COMMIT_ENV]?.trim() || (forge === "gitlab" ? env.CI_COMMIT_SHA : env.GITHUB_SHA)?.trim();
256
+ return commit ? { key: commit, commit } : undefined;
257
+ }
258
+
259
+ /** The run a record job runs in, as the record names it: GitHub and Forgejo `GITHUB_RUN_ID`, GitLab `CI_PIPELINE_ID`, and its page when the forge says. */
260
+ function runOf(forge: OpWavesFollowOnTarget["forge"], env: Record<string, string | undefined>): Pick<FollowOnRecord, "run" | "url"> {
261
+ if (forge === "gitlab") {
262
+ const url = env.CI_PIPELINE_URL?.trim();
263
+ return { run: env.CI_PIPELINE_ID?.trim() || "unknown", ...(url && /^https?:\/\//.test(url) ? { url } : {}) };
264
+ }
265
+ const id = env.GITHUB_RUN_ID?.trim();
266
+ const server = env.GITHUB_SERVER_URL?.trim().replace(/\/+$/, "");
267
+ const repo = env.GITHUB_REPOSITORY?.trim();
268
+ return { run: id || "unknown", ...(forge === "github" && id && server && repo && /^https?:\/\//.test(server) ? { url: `${server}/${repo}/actions/runs/${id}` } : {}) };
269
+ }
270
+
271
+ /**
272
+ * After the rest wave's record job wrote its run records (#4992): leave the
273
+ * note, and when the run applied every wave it ran and the plan found more,
274
+ * start the follow-on for the next one. Resolves to the job's exit: the
275
+ * record job's own, or failed when the follow-on could not be started (the
276
+ * note still says it was to be, so nothing after the run takes it for the
277
+ * last). A job that is not the rest wave's, or whose pipeline sets no
278
+ * {@link OP_WAVES_FOLLOW_ON_ENV}, is left as it is.
279
+ */
280
+ export async function followOnAfterRecord(i: FollowOnAfterRecordInput): Promise<number> {
281
+ const env = i.env ?? process.env;
282
+ const log = i.log ?? ((line: string) => console.error(line));
283
+ const rest = opWavesRestWave(i.spec);
284
+ if (rest === undefined || i.wave < rest) return i.exitCode;
285
+ const target = parseFollowOnTarget(env[OP_WAVES_FOLLOW_ON_ENV]);
286
+ if (!target) return i.exitCode;
287
+ const cwd = i.cwd ?? process.cwd();
288
+ let found: number | undefined;
289
+ try {
290
+ const decision = JSON.parse(readFileSync(join(cwd, opWaveRecordPath(i.spec, i.wave)), "utf-8")) as { discovered?: { waves?: unknown } };
291
+ const w = decision?.discovered?.waves;
292
+ if (Number.isInteger(w)) found = w as number;
293
+ } catch {
294
+ found = undefined;
295
+ }
296
+ const outcomeDir = opWaveOutcomeDir(i.spec);
297
+ const dir = isAbsolute(outcomeDir) ? outcomeDir : join(cwd, outcomeDir);
298
+ const { earlierWaveOutcomes } = await import("../wave-blocked");
299
+ const { applyOutcomeOf } = await import("../control/applied");
300
+ const own = earlierWaveOutcomes([dir], Number.MAX_SAFE_INTEGER).members;
301
+ const summary = applyOutcomeOf(own);
302
+ const through = summary.outcome === "applied" || summary.outcome === "unchanged";
303
+ const next = i.exitCode === CHANT_EXIT.done && through && found !== undefined && found > i.wave ? i.wave + 1 : undefined;
304
+ // #4998: a follow-on's record job reads the record that started it, for the outcomes of the chain's earlier runs.
305
+ const chainKey = followOnChainOf(target.forge, env);
306
+ let port = i.chain;
307
+ const chainPort = async (): Promise<FollowOnChainPort> => (port ??= (await import("./follow-on-store")).gitFollowOnChainPort({ cwd }));
308
+ let chain: Record<string, FollowOnOutcome> = {};
309
+ if (i.wave > rest && chainKey) {
310
+ try {
311
+ const started = await (await chainPort()).read(i.spec.name, chainKey.key);
312
+ if (started && started.wave === i.wave) chain = started.outcomes;
313
+ else log(`wave ${i.wave}: no record on chant/lifecycle started this wave for ${chainKey.key.slice(0, 12)}, so the outcomes of the chain's earlier runs are not added up`);
314
+ } catch (err) {
315
+ log(`wave ${i.wave}: the record that started this run could not be read (${(err instanceof Error ? err.message : String(err)).split("\n")[0]}), so the outcomes of the chain's earlier runs are not added up`);
316
+ }
317
+ }
318
+ mkdirSync(dir, { recursive: true });
319
+ const note: OpWaveRestNote = { version: 1, op: i.spec.name, wave: i.wave, found: found ?? i.wave, ...(next !== undefined ? { next } : {}), ...(Object.keys(chain).length > 0 ? { chain } : {}) };
320
+ writeFileSync(join(dir, OP_WAVE_REST_NOTE), JSON.stringify(note, null, 2) + "\n");
321
+ if (next === undefined) {
322
+ if (found !== undefined && found > i.wave) log(`wave ${i.wave}: the plan found ${found} waves, and this run ended ${summary.outcome} (exit ${i.exitCode}), so no run starts wave ${i.wave + 1}`);
323
+ return i.exitCode;
324
+ }
325
+ // #4998: record the follow-on before it starts: its guard admits the wave this record names, and no other.
326
+ try {
327
+ if (!chainKey) throw new Error("the run names no decided head and no commit to go on with");
328
+ const outcomes: Record<string, FollowOnOutcome> = {};
329
+ for (const [member, o] of withChainOutcomes(own, note)) outcomes[member] = { status: o.status, ...(o.by !== undefined ? { by: o.by } : {}), wave: o.wave, at: o.at };
330
+ const record: FollowOnRecord = { ...chainKey, wave: next, from: i.wave, ...runOf(target.forge, env), at: (i.now ?? (() => new Date()))().toISOString(), outcomes };
331
+ await (await chainPort()).write(i.spec.name, record);
332
+ } catch (err) {
333
+ const message = err instanceof Error ? err.message : String(err);
334
+ log(`wave ${i.wave} applied, and the follow-on for wave ${next} could not be recorded on chant/lifecycle (${message.split("\n")[0]}), so none is started: its guard would refuse it`);
335
+ return CHANT_EXIT.failed;
336
+ }
337
+ try {
338
+ const started = await (i.start ?? startFollowOn)(target, next, env);
339
+ log(`wave ${i.wave} applied; the plan found ${found} waves, so a follow-on run${started.url ? ` (${started.url})` : ""} goes on with wave ${next}`);
340
+ return i.exitCode;
341
+ } catch (err) {
342
+ const message = err instanceof Error ? err.message : String(err);
343
+ log(`wave ${i.wave} applied, and the follow-on run for wave ${next} could not be started (${message.split("\n")[0]}); start the waves workflow by hand with ${OP_WAVES_WAVE_ENV}=${next} and this run's other inputs`);
344
+ return CHANT_EXIT.failed;
345
+ }
346
+ }
347
+
348
+ /**
349
+ * Start the follow-on run for wave `wave` through the forge's API: the
350
+ * values the run carries come from the record job's own variables (the
351
+ * decision, or the commit the run applied).
352
+ */
353
+ export async function startFollowOn(target: OpWavesFollowOnTarget, wave: number, env: Record<string, string | undefined>, fetchFn: typeof fetch = fetch): Promise<StartedFollowOn> {
354
+ const run = beforeMergeRunFromEnv(env);
355
+ const bm = isBeforeMergeRun(run);
356
+ const commit = bm ? undefined : followOnChainOf(target.forge, env)?.commit;
357
+ if (!bm && !commit) throw new Error("the run names no commit to go on with");
358
+ const values: Record<string, string> = bm ? { pr: run.pr!, head: run.head!, digest: run.digest!, wave: String(wave) } : { wave: String(wave), commit: commit! };
359
+ const { forgeTargetFromEnv } = await import("../pr-forge");
360
+ const tokenEnv = [FOLLOW_ON_TOKEN_ENV, FORGE_TOKEN_VAR].find((n) => env[n]?.trim());
361
+ const t = forgeTargetFromEnv(env, { kind: target.forge, ...(tokenEnv ? { tokenEnv } : {}) });
362
+ const post = async (url: string, headers: Record<string, string>, body: unknown): Promise<unknown> => {
363
+ const res = await fetchFn(url, { method: "POST", headers: { ...headers, Accept: "application/json", "Content-Type": "application/json" }, body: JSON.stringify(body) });
364
+ const text = await res.text();
365
+ if (!res.ok) throw new Error(`POST ${url} answered ${res.status}${text ? `: ${text.slice(0, 200)}` : ""}`);
366
+ try {
367
+ return text ? JSON.parse(text) : null;
368
+ } catch {
369
+ return null;
370
+ }
371
+ };
372
+ if (target.forge === "gitlab") {
373
+ const ref = env.CI_COMMIT_REF_NAME;
374
+ if (!ref) throw new Error("the job names no branch (no CI_COMMIT_REF_NAME)");
375
+ const names: Record<string, string> = { pr: "CHANT_BEFORE_MERGE_PR", head: "CHANT_BEFORE_MERGE_HEAD", digest: "CHANT_BEFORE_MERGE_DIGEST", wave: OP_WAVES_WAVE_ENV, commit: OP_WAVES_COMMIT_ENV };
376
+ const variables = Object.entries(values).map(([k, value]) => ({ key: names[k]!, value, variable_type: "env_var" }));
377
+ const project = encodeURIComponent(decodeURIComponent(t.repo));
378
+ const v = (await post(`${t.apiBase}/projects/${project}/pipeline`, { [t.tokenHeader ?? "PRIVATE-TOKEN"]: t.token }, { ref, variables })) as { web_url?: unknown } | null;
379
+ return typeof v?.web_url === "string" && /^https?:\/\//.test(v.web_url) ? { url: v.web_url } : {};
380
+ }
381
+ const ref = env.GITHUB_REF_NAME?.trim() || env.GITHUB_REF?.replace(/^refs\/heads\//, "");
382
+ if (!ref) throw new Error("the job names no branch (no GITHUB_REF_NAME)");
383
+ await post(`${t.apiBase}/repos/${t.repo}/actions/workflows/${encodeURIComponent(target.workflow!)}/dispatches`, { Authorization: `token ${t.token}` }, { ref, inputs: values });
384
+ return {};
385
+ }
@@ -7,6 +7,7 @@ import { afterEach, describe, expect, test } from "vitest";
7
7
  import { assertProductWords, CHANT_WORDS, notifyWaveLabel, productWordsProblems, resolveProductWords, setActiveProductWords } from "../ci-product-words";
8
8
  import { makeNotifyEvent, slackMessage, teamsMessage, verifyWebhook, type NotifyFetch, type NotifyFields } from "../notify";
9
9
  import { driftNotifyFields, productSendOptions } from "../notify-product";
10
+ import { driftRunFingerprint, type DriftIssueRecord } from "../drift-issue";
10
11
  import type { OpWavesSpec } from "./op-waves";
11
12
  import { notifyOpWave, opWaveNotifyFields, type OpWaveOutcome } from "./op-waves-notify";
12
13
 
@@ -97,6 +98,23 @@ describe("notify words (#4610)", () => {
97
98
  expect(driftNotifyFields(CHANT_WORDS, { changed: ["net"], failed: ["db"] }).summary).toBe("1 member drifted: net; 1 member could not be refreshed: db");
98
99
  });
99
100
 
101
+ test("a drift notice given the stacks' records names the drifted ones and computes the run's fingerprint (#4944)", () => {
102
+ const record = (member: string, status: "drifted" | "in-sync"): DriftIssueRecord => ({ member, address: "bucket", status, ...(status === "drifted" ? { attributes: [{ path: "acl", before: "private", after: "public-read" }] } : {}) });
103
+ const stacks = [
104
+ { stack: "shop-prod", records: [record("shop-prod", "drifted")] },
105
+ { stack: "shop-dev", records: [record("shop-dev", "in-sync")] },
106
+ { stack: "shop-eu", records: [record("shop-eu", "drifted")] },
107
+ ];
108
+ const fields = driftNotifyFields(PLYWOOD, { stacks, failed: ["shop-us"] });
109
+ expect(fields).toMatchObject({
110
+ summary: "2 stacks drifted: shop-prod, shop-eu; 1 stack could not be refreshed: shop-us",
111
+ targets: ["shop-prod", "shop-eu"],
112
+ drift: { changed: ["shop-prod", "shop-eu"], failed: ["shop-us"], fingerprint: driftRunFingerprint(stacks) },
113
+ });
114
+ expect(driftNotifyFields(PLYWOOD, { stacks, fingerprint: "fp" }).drift?.fingerprint).toBe("fp");
115
+ expect(driftNotifyFields(PLYWOOD, { stacks, changed: ["shop-prod"] }).drift?.changed).toEqual(["shop-prod"]);
116
+ });
117
+
100
118
  test("sql-yodeler's words keep source sql-yodeler while its product word is yodel", () => {
101
119
  expect(YODEL.notify).toEqual({ source: "sql-yodeler", wave: "wave {k} ({name}) of {spec}", headers: "x-yodel" });
102
120
  expect(opWaveNotifyFields(spec, 2, outcomes.failed!, {}, YODEL)).toMatchObject({ source: "sql-yodeler" });
@@ -0,0 +1,159 @@
1
+ /**
2
+ * #4982: a waves spec the job renders at run time. The product's command
3
+ * prints the spec at the commit chant hands it, the job runs on the spec it
4
+ * printed at base, and the gate policy is read from that same render, so a
5
+ * change that loosens the product's config at its head does not loosen its
6
+ * own gate.
7
+ */
8
+
9
+ import { afterEach, beforeEach, describe, expect, test } from "vitest";
10
+ import { execFileSync } from "node:child_process";
11
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ import { tmpdir } from "node:os";
14
+ import { gitShowAtBase, parseOpWavesSpec, readOpWavePolicy, runOpWave, type OpWaveExec } from "./op-waves-run";
15
+ import { memoryGateLedgerPort } from "./gate";
16
+ import {
17
+ commandSpecRender,
18
+ OP_WAVES_SPEC_COMMAND_ENV,
19
+ opWavesRenderSpecEnv,
20
+ opWavesSpecCommandFromEnv,
21
+ renderedJobMissing,
22
+ renderedSpecShow,
23
+ renderOpWavesSpecFile,
24
+ RUNTIME_WAVES_SPEC_FLOOR,
25
+ } from "./op-waves-render-spec";
26
+ import type { OpWavesSpec } from "./op-waves";
27
+ import { parseArgs } from "../cli/parse-args";
28
+ import { runOpWaveCommand } from "../cli/handlers/run-wave";
29
+ import type { CommandContext } from "../cli/registry";
30
+
31
+ const SPEC_FILE = ".chant/op-waves/tf-apply.spec.json";
32
+
33
+ /** A product's command: the spec, with wave dev's gate and shares read from `config.json` at the commit chant names. */
34
+ const RENDER_JS = `
35
+ const { execFileSync } = require("node:child_process");
36
+ const at = process.env.CHANT_WAVES_SPEC_AT;
37
+ if (process.env.RENDER_FAIL) process.exit(2);
38
+ let config;
39
+ try { config = JSON.parse(execFileSync("git", ["show", at + ":config.json"], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] })); } catch { process.exit(0); }
40
+ process.stdout.write(JSON.stringify({
41
+ name: "tf-apply", op: "tf-apply",
42
+ plan: ["tool", "plan", "{target}", "--out", "{plan}"], apply: ["tool", "apply", "{target}", "--plan", "{plan}"],
43
+ waves: [{ name: "dev", gate: config.gate, shares: config.shares, runs: [{ target: "a" }, { target: "b" }] }],
44
+ }));
45
+ `;
46
+
47
+ let repo: string;
48
+ let tools: string;
49
+ let command: string[];
50
+ const git = (...args: string[]) => execFileSync("git", args, { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
51
+
52
+ beforeEach(() => {
53
+ repo = mkdtempSync(join(tmpdir(), "op-waves-render-"));
54
+ tools = mkdtempSync(join(tmpdir(), "op-waves-render-tool-"));
55
+ writeFileSync(join(tools, "render.cjs"), RENDER_JS);
56
+ command = [process.execPath, join(tools, "render.cjs")];
57
+ git("init", "-q", "-b", "main");
58
+ git("config", "user.email", "t@example.com");
59
+ git("config", "user.name", "t");
60
+ writeFileSync(join(repo, "config.json"), JSON.stringify({ gate: "always", shares: 2 }));
61
+ git("add", ".");
62
+ git("commit", "-q", "-m", "base");
63
+ // The change loosens the gate in the product's config.
64
+ writeFileSync(join(repo, "config.json"), JSON.stringify({ gate: "never", shares: 2 }));
65
+ git("commit", "-q", "-am", "loosen");
66
+ });
67
+
68
+ afterEach(() => {
69
+ delete process.env.RENDER_FAIL;
70
+ rmSync(repo, { recursive: true, force: true });
71
+ rmSync(tools, { recursive: true, force: true });
72
+ });
73
+
74
+ describe("a waves spec the job renders at run time (#4982)", () => {
75
+ test("the gate policy comes from the spec the command prints at base, not from the change's config", () => {
76
+ const show = renderedSpecShow(SPEC_FILE, commandSpecRender(command, SPEC_FILE, repo), gitShowAtBase);
77
+ const rules = readOpWavePolicy(SPEC_FILE, "dev", "HEAD^1", repo, show);
78
+ expect(rules).toMatchObject({ policy: "always", source: "base", base: git("rev-parse", "HEAD^1") });
79
+ // Without the render there is no spec at base at all.
80
+ expect(readOpWavePolicy(SPEC_FILE, "dev", "HEAD^1", repo).source).toBe("absent-at-base");
81
+ });
82
+
83
+ test("the job's spec is rendered once per commit and written over the spec file", () => {
84
+ let calls = 0;
85
+ const render = commandSpecRender(command, SPEC_FILE, repo);
86
+ const show = renderedSpecShow(SPEC_FILE, (sha) => (calls++, render(sha)), gitShowAtBase);
87
+ const { spec, sha } = renderOpWavesSpecFile({ specFile: SPEC_FILE, base: "HEAD^1", cwd: repo, show, parse: parseOpWavesSpec });
88
+ expect(sha).toBe(git("rev-parse", "HEAD^1"));
89
+ expect(spec.waves[0]).toMatchObject({ name: "dev", gate: "always" });
90
+ expect(parseOpWavesSpec(readFileSync(join(repo, SPEC_FILE), "utf-8"), "file").waves[0]!.gate).toBe("always");
91
+ readOpWavePolicy(SPEC_FILE, "dev", "HEAD^1", repo, show);
92
+ expect(calls).toBe(1);
93
+ // Any other file is read through git.
94
+ expect(show("HEAD", "config.json", repo).text).toContain('"never"');
95
+ });
96
+
97
+ test("a wave on the rendered spec waits under the gate at base, whatever the change's config says", async () => {
98
+ const show = renderedSpecShow(SPEC_FILE, commandSpecRender(command, SPEC_FILE, repo), gitShowAtBase);
99
+ const { spec } = renderOpWavesSpecFile({ specFile: SPEC_FILE, base: "HEAD^1", cwd: repo, show, parse: parseOpWavesSpec });
100
+ const applied: string[] = [];
101
+ const exec: OpWaveExec = (argv, dir) => {
102
+ if (argv[1] === "plan") writeFileSync(join(dir, argv[4]!), JSON.stringify({ planDigest: `sha256:${"1".repeat(64)}`, changes: { create: 1 } }));
103
+ if (argv[1] === "apply") applied.push(argv[2]!);
104
+ return 0;
105
+ };
106
+ const result = await runOpWave({ spec: { ...spec, waves: [{ ...spec.waves[0]!, shares: undefined }] }, specFile: SPEC_FILE, wave: 1, cwd: repo, exec, show, gates: memoryGateLedgerPort(), head: git("rev-parse", "HEAD") });
107
+ expect(result.exitCode).toBe(3);
108
+ expect(result.decision).toMatchObject({ status: "waiting", policy: "always" });
109
+ expect(applied).toEqual([]);
110
+ });
111
+
112
+ test("a command that fails fails the job; one that prints nothing reads as no spec at that commit", () => {
113
+ process.env.RENDER_FAIL = "1";
114
+ const failing = renderedSpecShow(SPEC_FILE, commandSpecRender(command, SPEC_FILE, repo), gitShowAtBase);
115
+ expect(() => readOpWavePolicy(SPEC_FILE, "dev", "HEAD^1", repo, failing)).toThrow(/the spec command \(.*render\.cjs\) exited 2 at [0-9a-f]{12}/);
116
+ delete process.env.RENDER_FAIL;
117
+ git("rm", "-q", "config.json");
118
+ git("commit", "-q", "-m", "drop the config");
119
+ const empty = renderedSpecShow(SPEC_FILE, commandSpecRender(command, SPEC_FILE, repo), gitShowAtBase);
120
+ expect(readOpWavePolicy(SPEC_FILE, "dev", "HEAD", repo, empty)).toMatchObject({ policy: "always", source: "absent-at-base" });
121
+ expect(() => renderOpWavesSpecFile({ specFile: SPEC_FILE, base: "HEAD", cwd: repo, show: empty, parse: parseOpWavesSpec })).toThrow(/printed no spec at HEAD/);
122
+ });
123
+
124
+ test("a share or job group the shape has and the rendered spec does not has nothing to apply", () => {
125
+ const spec: OpWavesSpec = { name: "s", op: "o", plan: ["p"], apply: ["a"], waves: [{ name: "w", runs: [{ target: "a" }, { target: "b" }], shares: 2 }, { name: "g", runs: [{ target: "a" }], jobs: [{ name: "eu", runs: ["a"], shares: 2 }] }] };
126
+ expect(renderedJobMissing(spec, 1, { share: 2 })).toBeUndefined();
127
+ expect(renderedJobMissing(spec, 1, { share: 3 })).toBe("wave 1 (w) has 2 shares in the spec rendered at base");
128
+ expect(renderedJobMissing(spec, 2, { group: "us" })).toBe('wave 2 (g) has no job group "us" in the spec rendered at base');
129
+ expect(renderedJobMissing(spec, 2, { group: "eu", share: 3 })).toBe('job group "eu" of wave 2 (g) has 2 shares in the spec rendered at base');
130
+ expect(renderedJobMissing(spec, 2, { group: "eu", share: 1 })).toBeUndefined();
131
+ });
132
+
133
+ test("the command comes from CHANT_WAVES_SPEC_COMMAND as a JSON list of words", () => {
134
+ expect(opWavesSpecCommandFromEnv({ [OP_WAVES_SPEC_COMMAND_ENV]: '["terragucci","waves-spec"]' })).toEqual(["terragucci", "waves-spec"]);
135
+ expect(() => opWavesSpecCommandFromEnv({})).toThrow(/CHANT_WAVES_SPEC_COMMAND names, and it is unset/);
136
+ expect(() => opWavesSpecCommandFromEnv({ [OP_WAVES_SPEC_COMMAND_ENV]: "terragucci waves-spec" })).toThrow(/must be a JSON list of words/);
137
+ expect(opWavesRenderSpecEnv({ command: ["terragucci", "waves-spec"] })).toEqual({ CHANT_WAVES_SPEC_COMMAND: '["terragucci","waves-spec"]' });
138
+ expect(opWavesRenderSpecEnv(undefined)).toEqual({});
139
+ expect(() => opWavesRenderSpecEnv({ command: [] })).toThrow(/renderSpec.command must be/);
140
+ expect(RUNTIME_WAVES_SPEC_FLOOR).toBe("0.124.89");
141
+ });
142
+
143
+ test("chant run wave --render-spec writes the rendered spec, and a share it does not have exits 0", async () => {
144
+ const was = process.cwd();
145
+ const env = process.env[OP_WAVES_SPEC_COMMAND_ENV];
146
+ process.env[OP_WAVES_SPEC_COMMAND_ENV] = JSON.stringify(command);
147
+ process.chdir(repo);
148
+ try {
149
+ const ctx = { args: parseArgs(["run", "wave", "--spec", SPEC_FILE, "--wave", "1", "--share", "3", "--render-spec"]), plugins: [], serializers: [] } as unknown as CommandContext;
150
+ expect(ctx.args.renderSpec).toBe(true);
151
+ expect(await runOpWaveCommand(ctx)).toBe(0);
152
+ expect(parseOpWavesSpec(readFileSync(join(repo, SPEC_FILE), "utf-8"), "file").waves[0]).toMatchObject({ gate: "always", shares: 2 });
153
+ } finally {
154
+ process.chdir(was);
155
+ if (env === undefined) delete process.env[OP_WAVES_SPEC_COMMAND_ENV];
156
+ else process.env[OP_WAVES_SPEC_COMMAND_ENV] = env;
157
+ }
158
+ });
159
+ });