@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,148 @@
1
+ /**
2
+ * The guard before merge (#4984): a waves run started for an open pull
3
+ * request's head is admitted only as the decision recorded for that head on
4
+ * `chant/lifecycle`, and every other run that names a head is refused. The
5
+ * `node -e` program reads the decision from a real repository and agrees
6
+ * with checkJob.
7
+ */
8
+
9
+ import { spawnSync } from "node:child_process";
10
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import { beforeAll, describe, expect, test } from "vitest";
14
+ import { checkJob, describeJobGuard, JOB_GUARD_ENV, JOB_GUARD_JS, jobGuardSpec, jobSeen, type JobGuardSpec } from "./ci-job-guard";
15
+ import { CHANT_EXIT } from "./exit-codes";
16
+ import { beforeMergeDigest, beforeMergePath, renderBeforeMerge, type BeforeMergeRecord } from "./op/before-merge";
17
+
18
+ const HEAD = "a".repeat(40);
19
+ const OTHER = "b".repeat(40);
20
+ const BASE = "c".repeat(40);
21
+ const decision = { pr: 7, head: HEAD, base: BASE, at: "2026-11-10T12:00:00.000Z", by: "alice" };
22
+ const record: BeforeMergeRecord = { ...decision, digest: beforeMergeDigest("deploy", decision) };
23
+
24
+ const gh: JobGuardSpec = { forge: "github", job: "wave 1 (prod) of deploy", branches: ["main"], beforeMerge: { op: "deploy" } };
25
+ const gl: JobGuardSpec = { forge: "gitlab", job: "wave 1 (prod) of deploy", branches: ["main"], beforeMerge: { op: "deploy" } };
26
+ const run = { pr: "7", head: HEAD, digest: record.digest };
27
+
28
+ describe("checkJob before merge", () => {
29
+ test("the decided head, on the default branch, runs", () => {
30
+ const r = checkJob(gh, { ref: "refs/heads/main", beforeMerge: run, beforeMergeRecord: record });
31
+ expect(r.problems).toEqual([]);
32
+ expect(r.checked).toEqual(["ref refs/heads/main", `before merge: pull request 7's decided head ${HEAD.slice(0, 12)}`]);
33
+ });
34
+
35
+ test("a push run names no head and is checked as before", () => {
36
+ expect(checkJob(gh, { ref: "refs/heads/main" }).checked).toEqual(["ref refs/heads/main"]);
37
+ });
38
+
39
+ test("a head no decision names is refused", () => {
40
+ const r = checkJob(gh, { ref: "refs/heads/main", beforeMerge: { ...run, head: OTHER }, beforeMergeRecord: null });
41
+ expect(r.problems).toEqual([`before merge: no decision on chant/lifecycle names head ${OTHER.slice(0, 12)} of deploy, so this run applies nothing`]);
42
+ });
43
+
44
+ test("another pull request's run, another digest, and a decision edited by hand are refused", () => {
45
+ expect(checkJob(gh, { ref: "refs/heads/main", beforeMerge: { ...run, pr: "8" }, beforeMergeRecord: record }).problems).toEqual([`before merge: the decision for head ${HEAD.slice(0, 12)} is pull request 7's, not 8's`]);
46
+ const other = `sha256:${"0".repeat(64)}`;
47
+ expect(checkJob(gh, { ref: "refs/heads/main", beforeMerge: { ...run, digest: other }, beforeMergeRecord: record }).problems).toEqual([`before merge: the run carries digest ${other}, and the decision for head ${HEAD.slice(0, 12)} has ${record.digest}`]);
48
+ expect(checkJob(gh, { ref: "refs/heads/main", beforeMerge: run, beforeMergeRecord: { ...record, through: 1 } }).problems).toEqual([`before merge: the decision for head ${HEAD.slice(0, 12)} was changed after it was made: its fields give another digest`]);
49
+ });
50
+
51
+ test("a decided head started on another ref is refused for the ref", () => {
52
+ const r = checkJob(gh, { ref: "refs/heads/feature", beforeMerge: run, beforeMergeRecord: record });
53
+ expect(r.problems).toEqual(["ref: expected refs/heads/main, found refs/heads/feature"]);
54
+ const l = checkJob(gl, { ref: "feature", refProtected: "false", forgeEnvironment: null, beforeMerge: run, beforeMergeRecord: record });
55
+ expect(l.problems).toEqual(["ref: expected main, found feature", "ref: expected a protected ref (CI_COMMIT_REF_PROTECTED true), found false"]);
56
+ });
57
+
58
+ test("a job without the before-merge mode refuses any run that names a head", () => {
59
+ const spec: JobGuardSpec = { forge: "github", job: "w", branches: ["main"] };
60
+ expect(checkJob(spec, { ref: "refs/heads/main", beforeMerge: run }).problems).toEqual([`before merge: the run names pull request 7's head ${HEAD}, and this job applies only the pushes to its branches`]);
61
+ });
62
+
63
+ test("variables that are not a decision's, and a ledger that cannot be read", () => {
64
+ expect(checkJob(gh, { ref: "refs/heads/main", beforeMerge: { head: "main" } }).problems).toEqual([
65
+ "before merge: the run's pull request none is not a number",
66
+ 'before merge: the run\'s head "main" is not a commit sha',
67
+ "before merge: the run's digest none is not a sha256 digest",
68
+ ]);
69
+ expect(checkJob(gh, { ref: "refs/heads/main", beforeMerge: run, beforeMergeError: "no token" }).problems).toEqual(["before merge: the decisions on chant/lifecycle could not be read: no token"]);
70
+ });
71
+
72
+ test("jobGuardSpec carries the mode", () => {
73
+ expect(jobGuardSpec({ forge: "forgejo", job: "w", branches: ["main"], beforeMerge: { op: "deploy" } }).beforeMerge).toEqual({ op: "deploy" });
74
+ });
75
+
76
+ test("jobSeen reads the decision for the run's head only with the mode", async () => {
77
+ const env = { GITHUB_REF: "refs/heads/main", CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest };
78
+ const read: string[] = [];
79
+ const reader = (_f: string, _e: NodeJS.ProcessEnv, path: string) => {
80
+ read.push(path);
81
+ return renderBeforeMerge({ version: 1, heads: { [HEAD]: record } });
82
+ };
83
+ const seen = await jobSeen(gh, env, fetch, reader);
84
+ expect(read).toEqual([beforeMergePath("deploy")]);
85
+ expect(seen.beforeMergeRecord).toEqual(record);
86
+ const plain = await jobSeen({ forge: "github", job: "w", branches: ["main"] }, env, fetch, reader);
87
+ expect(plain.beforeMergeRecord).toBeUndefined();
88
+ expect(read).toHaveLength(1);
89
+ });
90
+ });
91
+
92
+ describe("the node -e program reads the decision from chant/lifecycle", () => {
93
+ let server = "";
94
+ beforeAll(() => {
95
+ // A bare repository standing in for the forge, with the decisions file on chant/lifecycle.
96
+ server = mkdtempSync(join(tmpdir(), "chant-guard-forge-"));
97
+ const work = mkdtempSync(join(tmpdir(), "chant-guard-work-"));
98
+ const git = (cwd: string, ...args: string[]) => {
99
+ const r = spawnSync("git", args, { cwd, encoding: "utf-8", env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" } });
100
+ if (r.status !== 0) throw new Error(r.stderr);
101
+ };
102
+ mkdirSync(join(server, "acme"), { recursive: true });
103
+ git(join(server, "acme"), "init", "-q", "--bare", "infra.git");
104
+ git(work, "init", "-q", "-b", "chant/lifecycle");
105
+ mkdirSync(join(work, "_waves"));
106
+ writeFileSync(join(work, beforeMergePath("deploy")), renderBeforeMerge({ version: 1, heads: { [HEAD]: record } }));
107
+ git(work, "add", ".");
108
+ git(work, "commit", "-q", "-m", "decide");
109
+ git(work, "push", "-q", join(server, "acme", "infra.git"), "chant/lifecycle");
110
+ });
111
+
112
+ const run = (spec: JobGuardSpec, env: Record<string, string>) =>
113
+ spawnSync(process.execPath, ["-e", JOB_GUARD_JS], { env: { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "", [JOB_GUARD_ENV]: JSON.stringify(spec), ...env }, encoding: "utf-8" });
114
+ const forgeEnv = (spec: JobGuardSpec): Record<string, string> =>
115
+ spec.forge === "gitlab"
116
+ ? { CI_SERVER_URL: `file://${server}`, CI_PROJECT_PATH: "acme/infra", CI_JOB_TOKEN: "t", CI_COMMIT_REF_NAME: "main", CI_COMMIT_REF_PROTECTED: "true" }
117
+ : { GITHUB_SERVER_URL: `file://${server}`, GITHUB_REPOSITORY: "acme/infra", GITHUB_TOKEN: "t", GITHUB_REF: "refs/heads/main" };
118
+
119
+ const cases: Array<[string, JobGuardSpec, Record<string, string>]> = [
120
+ ["GitHub: the decided head", gh, { CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest }],
121
+ ["GitLab: the decided head", gl, { CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest }],
122
+ ["Forgejo: a head nothing decided", { ...gh, forge: "forgejo" }, { CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: OTHER, CHANT_BEFORE_MERGE_DIGEST: record.digest }],
123
+ ["GitHub: another pull request's number", gh, { CHANT_BEFORE_MERGE_PR: "9", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest }],
124
+ ["GitHub: the decided head dispatched on another branch", gh, { GITHUB_REF: "refs/heads/feature", CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest }],
125
+ ["GitLab: a head that is not a sha", gl, { CHANT_BEFORE_MERGE_HEAD: "refs/heads/feature" }],
126
+ ["GitHub: no mode, and a run that names a head", { forge: "github", job: "w", branches: ["main"] }, { CHANT_BEFORE_MERGE_HEAD: HEAD }],
127
+ ];
128
+
129
+ for (const [name, spec, extra] of cases) {
130
+ test(name, async () => {
131
+ const env = { ...forgeEnv(spec), ...extra };
132
+ const r = run(spec, env);
133
+ const want = describeJobGuard(spec, checkJob(spec, await jobSeen(spec, { ...process.env, ...env }, (() => Promise.reject(new Error("no fetch"))) as unknown as typeof fetch)));
134
+ expect(r.status).toBe(want.ok ? 0 : CHANT_EXIT.misplaced);
135
+ expect(r.stdout.trim().split("\n").filter(Boolean)).toEqual(want.out);
136
+ expect(r.stderr.trim().split("\n").filter(Boolean)).toEqual(want.err);
137
+ });
138
+ }
139
+
140
+ test("the decided head is admitted, and any other ref refused", async () => {
141
+ expect(run(gh, { ...forgeEnv(gh), CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest }).status).toBe(0);
142
+ for (const head of [OTHER, BASE]) {
143
+ const r = run(gh, { ...forgeEnv(gh), CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: head, CHANT_BEFORE_MERGE_DIGEST: record.digest });
144
+ expect(r.status).toBe(CHANT_EXIT.misplaced);
145
+ expect(r.stderr).toContain(`no decision on chant/lifecycle names head ${head.slice(0, 12)}`);
146
+ }
147
+ });
148
+ });
@@ -0,0 +1,137 @@
1
+ /**
2
+ * #4998: the guard admits a follow-on run only for the wave the newest
3
+ * record job of its chain started, as its record on `chant/lifecycle`
4
+ * names it. A wave started by hand past it (wave N+3 of a chain at N+1),
5
+ * or an earlier wave run again after the chain went on, is refused, on
6
+ * each forge, by checkJob and by the `node -e` program alike.
7
+ */
8
+
9
+ import { spawnSync } from "node:child_process";
10
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import { beforeAll, describe, expect, test } from "vitest";
14
+ import { checkJob, describeJobGuard, JOB_GUARD_ENV, JOB_GUARD_JS, jobSeen, type JobGuardForge, type JobGuardSpec } from "./ci-job-guard";
15
+ import { CHANT_EXIT } from "./exit-codes";
16
+ import { beforeMergeDigest, beforeMergePath, renderBeforeMerge, type BeforeMergeRecord } from "./op/before-merge";
17
+ import { followOnPath, followOnRecordProblems, parseFollowOn, renderFollowOn, type FollowOnRecord } from "./op/follow-on-run";
18
+
19
+ const HEAD = "a".repeat(40);
20
+ const BASE = "c".repeat(40);
21
+ const PUSHED = "d".repeat(40);
22
+ const UNRECORDED = "e".repeat(40);
23
+ const decision = { pr: 7, head: HEAD, base: BASE, at: "2026-11-10T12:00:00.000Z", by: "alice" };
24
+ const record: BeforeMergeRecord = { ...decision, digest: beforeMergeDigest("deploy", decision) };
25
+ const decided = { CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest };
26
+
27
+ // The rest wave is wave 3 (N); its record job started wave 4 (N+1), which is where each chain stands.
28
+ const chained = (key: string, wave: number, extra: Partial<FollowOnRecord> = {}): FollowOnRecord => ({ key, wave, from: wave - 1, run: "41", at: "2026-11-10T12:30:00.000Z", outcomes: { vpc: { status: "applied", wave: 3, at: "2026-11-10T12:20:00.000Z" } }, ...extra });
29
+ const headChain = chained(HEAD, 4, { pr: 7, digest: record.digest });
30
+ const pushChain = chained(PUSHED, 4, { commit: PUSHED });
31
+ const restOn = (forge: JobGuardForge): JobGuardSpec => ({ forge, job: "the plan job of wave 3 (rest) of deploy", branches: ["main"], beforeMerge: { op: "deploy" }, rest: 3 });
32
+
33
+ describe("the follow-on records (#4998)", () => {
34
+ test("parse keeps a well-formed entry, drops a malformed one, and renders the newest chains", () => {
35
+ const text = renderFollowOn({ version: 1, chains: { [HEAD]: headChain, [PUSHED]: pushChain } });
36
+ expect(parseFollowOn(text).chains).toEqual({ [HEAD]: headChain, [PUSHED]: pushChain });
37
+ const bad = JSON.stringify({ version: 1, chains: { [HEAD]: { ...headChain, wave: 1 }, [PUSHED]: { ...pushChain, key: HEAD }, main: pushChain } });
38
+ expect(parseFollowOn(bad).chains).toEqual({});
39
+ expect(parseFollowOn("not json").chains).toEqual({});
40
+ expect(followOnPath("deploy")).toBe("_waves/deploy.follow-on.json");
41
+ });
42
+
43
+ test("the lines: no record, another wave, another decision", () => {
44
+ expect(followOnRecordProblems("deploy", "4", HEAD, record.digest, headChain)).toEqual([]);
45
+ expect(followOnRecordProblems("deploy", "6", HEAD, record.digest, headChain)).toEqual([`follow-on: the newest record job of deploy for head ${HEAD.slice(0, 12)} started wave 4, and this run names wave 6`]);
46
+ expect(followOnRecordProblems("deploy", "4", UNRECORDED, undefined, null)).toEqual([`follow-on: no record job of deploy started a follow-on for commit ${UNRECORDED.slice(0, 12)}, so this run applies nothing`]);
47
+ });
48
+ });
49
+
50
+ describe("checkJob refuses a follow-on its chain's record does not name (#4998)", () => {
51
+ const at = { ref: "refs/heads/main" };
52
+ for (const forge of ["github", "gitlab", "forgejo"] as const) {
53
+ const seenAt = forge === "gitlab" ? { ref: "main", refProtected: "true" } : at;
54
+ test(`${forge}: a wave started by hand past the chain's (wave 6 of a chain at wave 4) is refused`, () => {
55
+ const r = checkJob(restOn(forge), { ...seenAt, beforeMerge: { pr: "7", head: HEAD, digest: record.digest }, beforeMergeRecord: record, followOn: { wave: "6" }, followOnRecord: headChain });
56
+ expect(r.problems).toEqual([`follow-on: the newest record job of deploy for head ${HEAD.slice(0, 12)} started wave 4, and this run names wave 6`]);
57
+ expect(r.checked).not.toContain("follow-on wave 6");
58
+ const push = checkJob(restOn(forge), { ...seenAt, followOn: { wave: "6", commit: PUSHED }, followOnRecord: pushChain });
59
+ expect(push.problems).toEqual([`follow-on: the newest record job of deploy for commit ${PUSHED.slice(0, 12)} started wave 4, and this run names wave 6`]);
60
+ });
61
+ }
62
+
63
+ test("an earlier wave run again once the chain went on is refused; the wave the record names is admitted", () => {
64
+ const moved = chained(PUSHED, 5, { commit: PUSHED });
65
+ expect(checkJob(restOn("github"), { ...at, followOn: { wave: "4", commit: PUSHED }, followOnRecord: moved }).problems).toEqual([
66
+ `follow-on: the newest record job of deploy for commit ${PUSHED.slice(0, 12)} started wave 5, and this run names wave 4`,
67
+ ]);
68
+ expect(checkJob(restOn("github"), { ...at, followOn: { wave: "5", commit: PUSHED }, followOnRecord: moved }).checked).toContain(`follow-on wave 5 at ${PUSHED.slice(0, 12)}`);
69
+ });
70
+
71
+ test("records that cannot be read refuse the run, and a run that is no follow-on reads none", async () => {
72
+ expect(checkJob(restOn("github"), { ...at, followOn: { wave: "4", commit: PUSHED }, followOnError: "could not fetch chant/lifecycle: denied" }).problems).toEqual([
73
+ "follow-on: the follow-on records on chant/lifecycle could not be read: could not fetch chant/lifecycle: denied",
74
+ ]);
75
+ const reads: string[] = [];
76
+ const reader = (_f: JobGuardForge, _e: NodeJS.ProcessEnv, path: string) => (reads.push(path), null);
77
+ await jobSeen(restOn("github"), { GITHUB_REF: "refs/heads/main", CHANT_WAVES_WAVE: "3" }, fetch, reader);
78
+ await jobSeen(restOn("github"), { GITHUB_REF: "refs/heads/main", CHANT_WAVES_WAVE: "2", CHANT_WAVES_COMMIT: PUSHED }, fetch, reader);
79
+ expect(reads).toEqual([]);
80
+ const seen = await jobSeen(restOn("github"), { GITHUB_REF: "refs/heads/main", CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: PUSHED }, fetch, reader);
81
+ expect(reads).toEqual(["_waves/deploy.follow-on.json"]);
82
+ expect(seen.followOnRecord).toBeNull();
83
+ });
84
+ });
85
+
86
+ describe("the node -e program agrees on each forge (#4998)", () => {
87
+ let server = "";
88
+ beforeAll(() => {
89
+ server = mkdtempSync(join(tmpdir(), "chant-guard-follow-on-record-"));
90
+ const work = mkdtempSync(join(tmpdir(), "chant-guard-follow-on-record-work-"));
91
+ const git = (cwd: string, ...args: string[]) => {
92
+ const r = spawnSync("git", args, { cwd, encoding: "utf-8", env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" } });
93
+ if (r.status !== 0) throw new Error(r.stderr);
94
+ };
95
+ mkdirSync(join(server, "acme"), { recursive: true });
96
+ git(join(server, "acme"), "init", "-q", "--bare", "infra.git");
97
+ git(work, "init", "-q", "-b", "chant/lifecycle");
98
+ mkdirSync(join(work, "_waves"));
99
+ writeFileSync(join(work, beforeMergePath("deploy")), renderBeforeMerge({ version: 1, heads: { [HEAD]: record } }));
100
+ writeFileSync(join(work, followOnPath("deploy")), renderFollowOn({ version: 1, chains: { [HEAD]: headChain, [PUSHED]: pushChain } }));
101
+ git(work, "add", ".");
102
+ git(work, "commit", "-q", "-m", "decide and follow on");
103
+ git(work, "push", "-q", join(server, "acme", "infra.git"), "chant/lifecycle");
104
+ });
105
+
106
+ const node = (spec: JobGuardSpec, env: Record<string, string>) =>
107
+ spawnSync(process.execPath, ["-e", JOB_GUARD_JS], { env: { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "", [JOB_GUARD_ENV]: JSON.stringify(spec), ...env }, encoding: "utf-8" });
108
+ const forgeEnv = (forge: JobGuardForge): Record<string, string> =>
109
+ forge === "gitlab"
110
+ ? { CI_SERVER_URL: `file://${server}`, CI_PROJECT_PATH: "acme/infra", CI_JOB_TOKEN: "t", CI_COMMIT_REF_NAME: "main", CI_COMMIT_REF_PROTECTED: "true" }
111
+ : { GITHUB_SERVER_URL: `file://${server}`, GITHUB_REPOSITORY: "acme/infra", GITHUB_TOKEN: "t", GITHUB_REF: "refs/heads/main" };
112
+
113
+ const cases: Array<[string, JobGuardForge, Record<string, string>, boolean]> = [];
114
+ for (const forge of ["github", "gitlab", "forgejo"] as const) {
115
+ cases.push(
116
+ [`${forge}: the wave the record job started, of the decided head`, forge, { ...decided, CHANT_WAVES_WAVE: "4" }, true],
117
+ [`${forge}: a wave started by hand past it, of the decided head`, forge, { ...decided, CHANT_WAVES_WAVE: "6" }, false],
118
+ [`${forge}: the wave the record job started, of a push`, forge, { CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: PUSHED }, true],
119
+ [`${forge}: a wave started by hand past it, of a push`, forge, { CHANT_WAVES_WAVE: "6", CHANT_WAVES_COMMIT: PUSHED }, false],
120
+ [`${forge}: a push no record job followed on`, forge, { CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: UNRECORDED }, false],
121
+ );
122
+ }
123
+
124
+ for (const [name, forge, extra, ok] of cases) {
125
+ test(name, async () => {
126
+ const spec = restOn(forge);
127
+ const env = { ...forgeEnv(forge), ...extra };
128
+ const r = node(spec, env);
129
+ const want = describeJobGuard(spec, checkJob(spec, await jobSeen(spec, { ...process.env, ...env }, (() => Promise.reject(new Error("no fetch"))) as unknown as typeof fetch)));
130
+ expect(want.ok).toBe(ok);
131
+ expect(r.status).toBe(ok ? 0 : CHANT_EXIT.misplaced);
132
+ expect(r.stdout.trim().split("\n").filter(Boolean)).toEqual(want.out);
133
+ expect(r.stderr.trim().split("\n").filter(Boolean)).toEqual(want.err);
134
+ if (!ok) expect(want.err[0]).toMatch(/follow-on: (the newest record job of deploy .* started wave 4, and this run names wave 6|no record job of deploy started a follow-on)/);
135
+ });
136
+ }
137
+ });
@@ -0,0 +1,144 @@
1
+ /**
2
+ * #4992: the guard admits a follow-on run of the rest wave only in a job of
3
+ * the rest wave, only for a wave after it, and only as the same decided
4
+ * head: a follow-on for another head or digest is refused as any run of
5
+ * one is. A push's follow-on names its commit. The `node -e` program agrees
6
+ * with checkJob, reading the decision from a real repository.
7
+ */
8
+
9
+ import { spawnSync } from "node:child_process";
10
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import { beforeAll, describe, expect, test } from "vitest";
14
+ import { checkJob, describeJobGuard, JOB_GUARD_ENV, JOB_GUARD_JS, jobGuardSpec, jobSeen, parseJobGuardSpec, type JobGuardSpec } from "./ci-job-guard";
15
+ import { CHANT_EXIT } from "./exit-codes";
16
+ import { beforeMergeDigest, beforeMergePath, renderBeforeMerge, type BeforeMergeRecord } from "./op/before-merge";
17
+ import { followOnPath, renderFollowOn, type FollowOnRecord } from "./op/follow-on-run";
18
+
19
+ const HEAD = "a".repeat(40);
20
+ const OTHER = "b".repeat(40);
21
+ const BASE = "c".repeat(40);
22
+ const PUSHED = "d".repeat(40);
23
+ const decision = { pr: 7, head: HEAD, base: BASE, at: "2026-11-10T12:00:00.000Z", by: "alice" };
24
+ const record: BeforeMergeRecord = { ...decision, digest: beforeMergeDigest("deploy", decision) };
25
+ const run = { pr: "7", head: HEAD, digest: record.digest };
26
+
27
+ /** #4998: the record a record job wrote when it started wave `wave` of the chain keyed `key`. */
28
+ const chained = (key: string, wave: number, extra: Partial<FollowOnRecord> = {}): FollowOnRecord => ({ key, wave, from: wave - 1, run: "41", at: "2026-11-10T12:30:00.000Z", outcomes: {}, ...extra });
29
+ const headChain = chained(HEAD, 4, { pr: 7, digest: record.digest });
30
+ const pushChain = chained(PUSHED, 4, { commit: PUSHED });
31
+
32
+ const rest: JobGuardSpec ={ forge: "github", job: "the plan job of wave 3 (rest) of deploy", branches: ["main"], beforeMerge: { op: "deploy" }, rest: 3 };
33
+ const earlier: JobGuardSpec = { forge: "github", job: "the plan job of wave 2 (layer) of deploy", branches: ["main"], beforeMerge: { op: "deploy" } };
34
+ const at = { ref: "refs/heads/main" };
35
+
36
+ describe("checkJob in a follow-on run (#4992)", () => {
37
+ test("the rest wave's jobs admit a follow-on of the decided head for a later wave", () => {
38
+ const r = checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "4" }, followOnRecord: headChain });
39
+ expect(r.problems).toEqual([]);
40
+ expect(r.checked).toEqual(["ref refs/heads/main", `before merge: pull request 7's decided head ${HEAD.slice(0, 12)}`, "follow-on wave 4"]);
41
+ });
42
+
43
+ test("a follow-on for another head or another digest is refused", () => {
44
+ expect(checkJob(rest, { ...at, beforeMerge: { ...run, head: OTHER }, beforeMergeRecord: null, followOn: { wave: "4" }, followOnRecord: null }).problems).toEqual([
45
+ `before merge: no decision on chant/lifecycle names head ${OTHER.slice(0, 12)} of deploy, so this run applies nothing`,
46
+ `follow-on: no record job of deploy started a follow-on for head ${OTHER.slice(0, 12)}, so this run applies nothing`,
47
+ ]);
48
+ const other = `sha256:${"0".repeat(64)}`;
49
+ expect(checkJob(rest, { ...at, beforeMerge: { ...run, digest: other }, beforeMergeRecord: record, followOn: { wave: "4" }, followOnRecord: headChain }).problems).toEqual([
50
+ `before merge: the run carries digest ${other}, and the decision for head ${HEAD.slice(0, 12)} has ${record.digest}`,
51
+ `follow-on: wave 4 of head ${HEAD.slice(0, 12)} was started for the decision with digest ${record.digest}, and the run carries ${other}`,
52
+ ]);
53
+ });
54
+
55
+ test("the rest wave's own number is no follow-on, and a run that is none is checked as before", () => {
56
+ expect(checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "3" } }).problems).toEqual([]);
57
+ expect(checkJob(rest, { ...at }).checked).toEqual(["ref refs/heads/main"]);
58
+ expect(checkJob(earlier, { ...at }).checked).toEqual(["ref refs/heads/main"]);
59
+ });
60
+
61
+ test("a wave that is not after the rest wave, a job of another wave, and a commit beside a decided head are refused", () => {
62
+ expect(checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "2" } }).problems).toEqual(['follow-on: the run\'s wave "2" is no wave after wave 3']);
63
+ expect(checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "4; rm -rf /" } }).problems).toEqual(['follow-on: the run\'s wave "4; rm -rf /" is no wave after wave 3']);
64
+ expect(checkJob(earlier, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "4" } }).problems).toEqual([
65
+ "follow-on: the run names wave 4 and commit none, and this job is none of the rest wave's, which alone runs in a follow-on",
66
+ ]);
67
+ expect(checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "4", commit: PUSHED } }).problems).toEqual([
68
+ `follow-on: a follow-on of a decided head checks out that head, and the run names the commit ${PUSHED} too`,
69
+ ]);
70
+ });
71
+
72
+ test("a push's follow-on names the commit it goes on with", () => {
73
+ const r = checkJob(rest, { ...at, followOn: { wave: "4", commit: PUSHED }, followOnRecord: pushChain });
74
+ expect(r.problems).toEqual([]);
75
+ expect(r.checked).toEqual(["ref refs/heads/main", `follow-on wave 4 at ${PUSHED.slice(0, 12)}`]);
76
+ expect(checkJob(rest, { ...at, followOn: { wave: "4" } }).problems).toEqual(["follow-on: a push's follow-on names the commit it goes on with, and the run's none is not a commit sha"]);
77
+ expect(checkJob(rest, { ...at, followOn: { wave: "4", commit: "main" } }).problems).toEqual(['follow-on: a push\'s follow-on names the commit it goes on with, and the run\'s "main" is not a commit sha']);
78
+ expect(checkJob(rest, { ...at, followOn: { commit: PUSHED } }).problems).toEqual([`follow-on: the run names the commit ${PUSHED} and no wave after wave 3, so it is no follow-on`]);
79
+ });
80
+
81
+ test("jobGuardSpec carries the rest wave, the parse checks it, and jobSeen reads the variables", async () => {
82
+ expect(jobGuardSpec({ forge: "gitlab", job: "w", branches: ["main"], rest: 3 }).rest).toBe(3);
83
+ expect(() => parseJobGuardSpec(JSON.stringify({ ...rest, rest: "3" }))).toThrow("rest is the rest wave's number");
84
+ const seen = await jobSeen(rest, { GITHUB_REF: "refs/heads/main", CHANT_WAVES_WAVE: " 4 ", CHANT_WAVES_COMMIT: PUSHED });
85
+ expect(seen.followOn).toEqual({ wave: "4", commit: PUSHED });
86
+ expect((await jobSeen(rest, { GITHUB_REF: "refs/heads/main" })).followOn).toBeUndefined();
87
+ });
88
+ });
89
+
90
+ describe("the node -e program agrees in a follow-on run", () => {
91
+ let server = "";
92
+ beforeAll(() => {
93
+ server = mkdtempSync(join(tmpdir(), "chant-guard-follow-on-"));
94
+ const work = mkdtempSync(join(tmpdir(), "chant-guard-follow-on-work-"));
95
+ const git = (cwd: string, ...args: string[]) => {
96
+ const r = spawnSync("git", args, { cwd, encoding: "utf-8", env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" } });
97
+ if (r.status !== 0) throw new Error(r.stderr);
98
+ };
99
+ mkdirSync(join(server, "acme"), { recursive: true });
100
+ git(join(server, "acme"), "init", "-q", "--bare", "infra.git");
101
+ git(work, "init", "-q", "-b", "chant/lifecycle");
102
+ mkdirSync(join(work, "_waves"));
103
+ writeFileSync(join(work, beforeMergePath("deploy")), renderBeforeMerge({ version: 1, heads: { [HEAD]: record } }));
104
+ writeFileSync(join(work, followOnPath("deploy")), renderFollowOn({ version: 1, chains: { [HEAD]: headChain, [PUSHED]: pushChain } }));
105
+ git(work, "add", ".");
106
+ git(work, "commit", "-q", "-m", "decide");
107
+ git(work, "push", "-q", join(server, "acme", "infra.git"), "chant/lifecycle");
108
+ });
109
+
110
+ const node = (spec: JobGuardSpec, env: Record<string, string>) =>
111
+ spawnSync(process.execPath, ["-e", JOB_GUARD_JS], { env: { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "", [JOB_GUARD_ENV]: JSON.stringify(spec), ...env }, encoding: "utf-8" });
112
+ const forgeEnv = (spec: JobGuardSpec): Record<string, string> =>
113
+ spec.forge === "gitlab"
114
+ ? { CI_SERVER_URL: `file://${server}`, CI_PROJECT_PATH: "acme/infra", CI_JOB_TOKEN: "t", CI_COMMIT_REF_NAME: "main", CI_COMMIT_REF_PROTECTED: "true" }
115
+ : { GITHUB_SERVER_URL: `file://${server}`, GITHUB_REPOSITORY: "acme/infra", GITHUB_TOKEN: "t", GITHUB_REF: "refs/heads/main" };
116
+ const decided = { CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest };
117
+ const gl: JobGuardSpec = { ...rest, forge: "gitlab" };
118
+ const fj: JobGuardSpec = { ...rest, forge: "forgejo" };
119
+
120
+ const cases: Array<[string, JobGuardSpec, Record<string, string>, boolean]> = [
121
+ ["GitHub: a follow-on of the decided head", rest, { ...decided, CHANT_WAVES_WAVE: "4" }, true],
122
+ ["GitLab: a follow-on of the decided head", gl, { ...decided, CHANT_WAVES_WAVE: "4" }, true],
123
+ ["Forgejo: a push's follow-on", fj, { CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: PUSHED }, true],
124
+ ["GitHub: the rest wave's own number in a run that is none", rest, { ...decided, CHANT_WAVES_WAVE: "3" }, true],
125
+ ["GitHub: a follow-on for another head", rest, { ...decided, CHANT_BEFORE_MERGE_HEAD: OTHER, CHANT_WAVES_WAVE: "4" }, false],
126
+ ["GitLab: a follow-on for another digest", gl, { ...decided, CHANT_BEFORE_MERGE_DIGEST: `sha256:${"0".repeat(64)}`, CHANT_WAVES_WAVE: "4" }, false],
127
+ ["Forgejo: a follow-on in a job of an earlier wave", { ...earlier, forge: "forgejo" }, { ...decided, CHANT_WAVES_WAVE: "4" }, false],
128
+ ["GitHub: a wave before the rest wave", rest, { ...decided, CHANT_WAVES_WAVE: "1" }, false],
129
+ ["GitLab: a push's follow-on with no commit", gl, { CHANT_WAVES_WAVE: "4" }, false],
130
+ ["GitHub: a commit beside a decided head", rest, { ...decided, CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: PUSHED }, false],
131
+ ];
132
+
133
+ for (const [name, spec, extra, ok] of cases) {
134
+ test(name, async () => {
135
+ const env = { ...forgeEnv(spec), ...extra };
136
+ const r = node(spec, env);
137
+ const want = describeJobGuard(spec, checkJob(spec, await jobSeen(spec, { ...process.env, ...env }, (() => Promise.reject(new Error("no fetch"))) as unknown as typeof fetch)));
138
+ expect(want.ok).toBe(ok);
139
+ expect(r.status).toBe(ok ? 0 : CHANT_EXIT.misplaced);
140
+ expect(r.stdout.trim().split("\n").filter(Boolean)).toEqual(want.out);
141
+ expect(r.stderr.trim().split("\n").filter(Boolean)).toEqual(want.err);
142
+ });
143
+ }
144
+ });