@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,288 @@
1
+ /**
2
+ * #4994: a product's bin runs each job of a split wave, and the one-job
3
+ * shape, with its own process's hooks.
4
+ *
5
+ * - A hook the spec names is served in the job's own process by name
6
+ * (`inProcessHooks`, a product wave hook's `hooks`): in the plan job, the
7
+ * gate job and the applying job, each in its own process, in place of a
8
+ * command that called back into a long-lived product process. What the
9
+ * plan job's code keeps for the later jobs goes under
10
+ * `opWaveProductStateDir`, which the gate and applying jobs read.
11
+ * - A hold that asks chant to `record` its gate works with the split: the
12
+ * plan job finds the approval and cannot spend it, the gate job spends it
13
+ * for a re-run of the hook at the wave's commit, the next run's plan job
14
+ * runs the hook again under it, and the gate job after that writes the
15
+ * finished line. The approval is used once.
16
+ */
17
+ import { afterAll, describe, expect, test } from "vitest";
18
+ import { execFileSync } from "node:child_process";
19
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
20
+ import { tmpdir } from "node:os";
21
+ import { dirname, join } from "node:path";
22
+ import { opWaveRecordPath, type OpWavesSpec } from "./op-waves";
23
+ import { runOpWave, type OpWaveDecision, type OpWaveExec, type OpWaveInProcessHook, type OpWaveRunPort, type OpWaveSavedPlan, type OpWaveShowAtBase } from "./op-waves-run";
24
+ import { opWaveProductStateDir, opWaveSavedPlanPath } from "./op-waves-split";
25
+ import { memoryGateLedgerPort } from "./gate";
26
+ import { CHANT_EXIT } from "../exit-codes";
27
+
28
+ const dirs: string[] = [];
29
+ afterAll(() => {
30
+ for (const d of dirs) rmSync(d, { recursive: true, force: true });
31
+ });
32
+
33
+ function tmp(prefix: string): string {
34
+ const d = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
35
+ dirs.push(d);
36
+ return d;
37
+ }
38
+
39
+ const digest = (n: string) => `sha256:${n.repeat(64)}`;
40
+ const noWrites: OpWaveRunPort = { append: async () => Promise.reject(new Error("this job writes no run record to the ledger")) };
41
+
42
+ /** A spec whose hooks, read at base, called back into the product's process over a socket (`product-call ...`). */
43
+ const spec: OpWavesSpec = {
44
+ name: "roots",
45
+ op: "tf-apply",
46
+ plan: ["tool", "plan", "{target}", "--out", "{plan}"],
47
+ apply: ["tool", "apply", "{target}", "--plan", "{plan}"],
48
+ hooks: {
49
+ before: {
50
+ plan: [{ name: "migrations", command: ["product-call", "migrate-check", "{runs}"] }],
51
+ apply: [{ name: "ready", command: ["product-call", "ready", "{runs}"] }],
52
+ },
53
+ after: { gate: [{ name: "report", command: ["product-call", "gate", "{runs}"] }] },
54
+ },
55
+ waves: [{ name: "dev", runs: [{ target: "network" }], gate: "never" }],
56
+ };
57
+ const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(spec) });
58
+
59
+ /** The tools a job runs: the engine's plan and apply, and the socket client, which finds no product process to call. */
60
+ function tools(): { exec: OpWaveExec; socketCalls: string[]; applied: string[] } {
61
+ const socketCalls: string[] = [];
62
+ const applied: string[] = [];
63
+ const exec: OpWaveExec = (argv, dir) => {
64
+ if (argv[0] === "product-call") {
65
+ socketCalls.push(argv.join(" "));
66
+ return 1;
67
+ }
68
+ if (argv[0] === "tool" && argv[1] === "plan") writeFileSync(join(dir, argv[4]!), JSON.stringify({ planDigest: digest("a") }));
69
+ if (argv[0] === "tool" && argv[1] === "apply") applied.push(argv[2]!);
70
+ return 0;
71
+ };
72
+ return { exec, socketCalls, applied };
73
+ }
74
+
75
+ /** The product's hooks, each in the job's own process: the plan job keeps a note for the gate job's report. */
76
+ function productHooks(log: string[]): Record<string, OpWaveInProcessHook> {
77
+ const state = (cwd: string) => join(cwd, opWaveProductStateDir(spec, 1), "planned.json");
78
+ return {
79
+ migrations: async (call) => {
80
+ log.push(`${call.moment} ${call.name}`);
81
+ mkdirSync(dirname(state(call.cwd)), { recursive: true });
82
+ writeFileSync(state(call.cwd), JSON.stringify({ roots: ["network"] }));
83
+ return 0;
84
+ },
85
+ report: async (call) => {
86
+ const kept = existsSync(state(call.cwd)) ? (JSON.parse(readFileSync(state(call.cwd), "utf-8")) as { roots: string[] }).roots.join(",") : "none";
87
+ log.push(`${call.moment} ${call.name} ${call.env.CHANT_GATE_STATUS} planned=${kept} argv=${call.argv.slice(0, 2).join(" ")}`);
88
+ return 0;
89
+ },
90
+ ready: async (call) => {
91
+ log.push(`${call.moment} ${call.name}`);
92
+ return 0;
93
+ },
94
+ };
95
+ }
96
+
97
+ describe("a product's hooks in its own process (#4994)", () => {
98
+ test("each job of a split wave calls the hooks it runs in its own process, in place of their commands", async () => {
99
+ const cwd = tmp("split-product-");
100
+ const { exec, socketCalls, applied } = tools();
101
+ const gates = memoryGateLedgerPort();
102
+ const base = { spec, specFile: "waves.json", wave: 1, cwd, exec, show, gates, log: () => {} };
103
+
104
+ const plan: string[] = [];
105
+ expect((await runOpWave({ ...base, phase: "plan", runs: noWrites, inProcessHooks: productHooks(plan) })).exitCode).toBe(CHANT_EXIT.done);
106
+ expect(plan).toEqual(["before-plan migrations"]);
107
+
108
+ // The gate job is a process of its own: its report reads what the plan job's hook kept.
109
+ const gate: string[] = [];
110
+ expect((await runOpWave({ ...base, phase: "gate", runs: { append: async () => {} }, inProcessHooks: productHooks(gate) })).exitCode).toBe(CHANT_EXIT.done);
111
+ expect(gate).toEqual(["after-gate report not-required planned=network argv=product-call gate"]);
112
+
113
+ const apply: string[] = [];
114
+ expect((await runOpWave({ ...base, phase: "apply", runs: noWrites, inProcessHooks: productHooks(apply) })).exitCode).toBe(CHANT_EXIT.done);
115
+ expect(apply).toEqual(["before-apply ready"]);
116
+ expect(applied).toEqual(["network"]);
117
+
118
+ expect((await runOpWave({ ...base, phase: "record", runs: { append: async () => {} }, inProcessHooks: productHooks([]) })).exitCode).toBe(CHANT_EXIT.done);
119
+ // No job ran a command that called back over a socket.
120
+ expect(socketCalls).toEqual([]);
121
+ });
122
+
123
+ test("the one-job shape calls the same hooks in its one process", async () => {
124
+ const cwd = tmp("split-product-one-");
125
+ const { exec, socketCalls, applied } = tools();
126
+ const log: string[] = [];
127
+ const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd, exec, show, gates: memoryGateLedgerPort(), runs: { append: async () => {} }, releases: false, log: () => {}, inProcessHooks: productHooks(log) });
128
+ expect(result.exitCode).toBe(CHANT_EXIT.done);
129
+ expect(log).toEqual(["before-plan migrations", "after-gate report not-required planned=network argv=product-call gate", "before-apply ready"]);
130
+ expect(applied).toEqual(["network"]);
131
+ expect(socketCalls).toEqual([]);
132
+ });
133
+
134
+ test("a hook the process does not serve runs its command, as before", async () => {
135
+ const cwd = tmp("split-product-cmd-");
136
+ const { exec, socketCalls } = tools();
137
+ const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd, exec, show, gates: memoryGateLedgerPort(), runs: { append: async () => {} }, releases: false, log: () => {}, inProcessHooks: { report: async () => 0, ready: async () => 0 } });
138
+ // The before-plan hook's command found no product process, so the wave failed before it planned.
139
+ expect(result.exitCode).toBe(CHANT_EXIT.failed);
140
+ expect(socketCalls).toEqual(["product-call migrate-check .chant/op-waves/roots/wave-1/runs.json"]);
141
+ });
142
+ });
143
+
144
+ /** A wave held before it plans on `tf-migrate / split-queues` by a hook that asks chant to record the gate, served in process. */
145
+ function recordHold() {
146
+ const cwd = tmp("split-record-hold-");
147
+ const migrate = { name: "migrate", command: ["product-call", "migrate", "{runs}"], onFailure: "approve" as const };
148
+ const holdSpec: OpWavesSpec = {
149
+ name: "migrations",
150
+ op: "migrate",
151
+ plan: ["tool", "plan", "{target}", "--out", "{plan}"],
152
+ apply: ["tool", "apply", "{target}", "--plan", "{plan}"],
153
+ hooks: { before: { plan: [migrate] } },
154
+ waves: [{ name: "staging", runs: [{ target: "staging" }], gate: "never" }],
155
+ };
156
+ const { exec, socketCalls } = tools();
157
+ const reruns: Array<Record<string, string>> = [];
158
+ const hooks: Record<string, OpWaveInProcessHook> = {
159
+ migrate: async ({ cwd: dir, env }) => {
160
+ if (env.CHANT_HOLD_APPROVED) {
161
+ reruns.push(env);
162
+ // The migration ran under the approval: how it ended, for the finished line.
163
+ writeFileSync(join(dir, env.CHANT_HOLD_FINISHED!), JSON.stringify({ result: "applied", detail: { moved: 2 } }));
164
+ return 0;
165
+ }
166
+ writeFileSync(join(dir, env.CHANT_HOLD!), JSON.stringify({ op: "tf-migrate", gate: "split-queues", digest: digest("m"), description: "move the queues", record: true }));
167
+ return 3;
168
+ },
169
+ };
170
+ const approval = { version: 1 as const, op: "tf-migrate", gate: "split-queues", resolvedBy: "alice", timestamp: "2026-11-10T00:00:00Z", planDigest: digest("m") };
171
+ const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(holdSpec) });
172
+ const head = "c".repeat(40);
173
+ return { cwd, holdSpec, socketCalls, reruns, approval, head, base: { spec: holdSpec, specFile: "waves.json", wave: 1, cwd, exec, show, inProcessHooks: hooks, log: () => {} } };
174
+ }
175
+
176
+ describe("a `record` hold with the split (#4994)", () => {
177
+ test("the gate job spends the approval, the next run's plan job runs the hook again under it, and its gate job writes the finished line", async () => {
178
+ const h = recordHold();
179
+ const gates = memoryGateLedgerPort({ resolutions: [h.approval] });
180
+ const lines: string[] = [];
181
+ const log = (l: string) => lines.push(l);
182
+
183
+ // Run 1, plan job: the gate is approved, and this job cannot spend the approval.
184
+ const planned = await runOpWave({ ...h.base, phase: "plan", head: h.head, gates, runs: noWrites, log });
185
+ expect(planned.exitCode).toBe(CHANT_EXIT.waiting);
186
+ expect(h.reruns).toEqual([]);
187
+ expect(gates.applied).toEqual([]);
188
+ const saved = JSON.parse(readFileSync(join(h.cwd, opWaveSavedPlanPath(h.holdSpec, 1)), "utf-8")) as OpWaveSavedPlan;
189
+ expect(saved.end?.decision?.heldOn?.deferred?.spend).toMatchObject({ approvedBy: "alice", head: h.head });
190
+
191
+ // Run 1, gate job: it spends the approval for the hook's re-run at this commit, and the wave waits.
192
+ const gated = await runOpWave({ ...h.base, phase: "gate", head: h.head, gates, runs: { append: async () => {} }, log });
193
+ expect(gated.exitCode).toBe(CHANT_EXIT.waiting);
194
+ expect(gates.applied).toEqual([expect.objectContaining({ op: "tf-migrate", gate: "split-queues", planDigest: digest("m"), approvedBy: "alice", rerun: { head: h.head } })]);
195
+ const decision = JSON.parse(readFileSync(join(h.cwd, opWaveRecordPath(h.holdSpec, 1)), "utf-8")) as OpWaveDecision;
196
+ expect(decision.heldOn?.spentForRerun).toMatchObject({ approvedBy: "alice", rerun: { head: h.head } });
197
+ expect(gates.appended).toEqual([]);
198
+ expect(lines.join("\n")).toContain("is spent for before-plan hook migrate to run again; run the wave again from its plan job");
199
+
200
+ // Another commit's plan job does not run the hook under it.
201
+ const other = await runOpWave({ ...h.base, phase: "plan", head: "d".repeat(40), gates, runs: noWrites, log });
202
+ expect(other.exitCode).toBe(CHANT_EXIT.waiting);
203
+ expect(h.reruns).toEqual([]);
204
+
205
+ // Run 2, plan job: the hook runs again under the spent approval, and the wave plans.
206
+ const again = await runOpWave({ ...h.base, phase: "plan", head: h.head, gates, runs: noWrites, log });
207
+ expect(again.exitCode, lines.join("\n")).toBe(CHANT_EXIT.done);
208
+ expect(h.reruns).toHaveLength(1);
209
+ expect(JSON.parse(h.reruns[0]!.CHANT_HOLD_APPROVED!)).toMatchObject({ op: "tf-migrate", gate: "split-queues", approvedBy: "alice" });
210
+ expect(gates.finished).toEqual([]);
211
+ const savedAgain = JSON.parse(readFileSync(join(h.cwd, opWaveSavedPlanPath(h.holdSpec, 1)), "utf-8")) as OpWaveSavedPlan;
212
+ expect(savedAgain.holdsFinished).toEqual([expect.objectContaining({ result: "applied", detail: { moved: 2 } })]);
213
+
214
+ // Run 2, gate job: it writes the finished line, then decides the wave.
215
+ const decided = await runOpWave({ ...h.base, phase: "gate", head: h.head, gates, runs: { append: async () => {} }, log });
216
+ expect(decided.exitCode).toBe(CHANT_EXIT.done);
217
+ expect(gates.finished).toEqual([expect.objectContaining({ op: "tf-migrate", gate: "split-queues", planDigest: digest("m"), applied: gates.applied[0]!.timestamp, result: "applied", detail: { moved: 2 } })]);
218
+
219
+ // Run 3: the approval was used once. A hook that holds on the same digest again does not run again, and its gate
220
+ // job refuses to spend the approval twice, as a one-job wave refuses it.
221
+ const third = await runOpWave({ ...h.base, phase: "plan", head: h.head, gates, runs: noWrites, log });
222
+ expect(third.exitCode).toBe(CHANT_EXIT.waiting);
223
+ expect(h.reruns).toHaveLength(1);
224
+ const refused = await runOpWave({ ...h.base, phase: "gate", head: h.head, gates, runs: { append: async () => {} }, log });
225
+ expect(refused.exitCode).toBe(CHANT_EXIT.failed);
226
+ expect(lines.join("\n")).toContain("a held request applies once, so it is not spent again");
227
+ expect(gates.applied).toHaveLength(1);
228
+ expect(h.socketCalls).toEqual([]);
229
+ });
230
+
231
+ test("a finished line the plan job claims for an applied line the ledger does not hold is not written", async () => {
232
+ const h = recordHold();
233
+ const gates = memoryGateLedgerPort({ resolutions: [h.approval] });
234
+ await runOpWave({ ...h.base, phase: "plan", head: h.head, gates, runs: noWrites });
235
+ await runOpWave({ ...h.base, phase: "gate", head: h.head, gates, runs: { append: async () => {} } });
236
+ await runOpWave({ ...h.base, phase: "plan", head: h.head, gates, runs: noWrites });
237
+ // The change's code in the plan job rewrites what it hands on.
238
+ const path = join(h.cwd, opWaveSavedPlanPath(h.holdSpec, 1));
239
+ const saved = JSON.parse(readFileSync(path, "utf-8")) as OpWaveSavedPlan;
240
+ saved.holdsFinished = saved.holdsFinished!.map((f) => ({ ...f, applied: { ...f.applied, timestamp: "2020-01-01T00:00:00.000Z" } }));
241
+ writeFileSync(path, JSON.stringify(saved));
242
+ const lines: string[] = [];
243
+ await runOpWave({ ...h.base, phase: "gate", head: h.head, gates, runs: { append: async () => {} }, log: (l) => lines.push(l) });
244
+ expect(gates.finished).toEqual([]);
245
+ expect(lines.join("\n")).toContain("which the ledger holds no re-run of this commit for, so no finished line is written");
246
+ });
247
+
248
+ test("the gate job does not spend an approval for a commit other than the plan job's", async () => {
249
+ const h = recordHold();
250
+ const gates = memoryGateLedgerPort({ resolutions: [h.approval] });
251
+ await runOpWave({ ...h.base, phase: "plan", head: h.head, gates, runs: noWrites });
252
+ const gated = await runOpWave({ ...h.base, phase: "gate", head: "e".repeat(40), gates, runs: { append: async () => {} } });
253
+ expect(gated.exitCode).toBe(CHANT_EXIT.failed);
254
+ expect(gates.applied).toEqual([]);
255
+ });
256
+ });
257
+
258
+ describe("a product's bin runs a split wave's job with its wave hook (#4994)", () => {
259
+ test("runChantInProcess with `hooks` runs `run wave --phase plan` with the hook in process", async () => {
260
+ const cwd = tmp("split-product-bin-");
261
+ const git = (...args: string[]) => execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
262
+ git("init", "-q", "-b", "main");
263
+ git("config", "user.email", "t@chant.dev");
264
+ git("config", "user.name", "T");
265
+ git("config", "commit.gpgsign", "false");
266
+ const plan = ["node", "-e", `require("fs").writeFileSync(process.argv[1], JSON.stringify({ planDigest: "${digest("a")}" }))`, "{plan}"];
267
+ const binSpec: OpWavesSpec = { ...spec, plan, apply: ["true"] };
268
+ mkdirSync(join(cwd, ".chant"), { recursive: true });
269
+ writeFileSync(join(cwd, ".chant", "waves.json"), JSON.stringify(binSpec));
270
+ git("add", ".");
271
+ git("commit", "-q", "-m", "spec");
272
+ const { runChantInProcess } = await import("../ci-product");
273
+ const calls: string[] = [];
274
+ const was = process.cwd();
275
+ process.chdir(cwd);
276
+ let code: number;
277
+ try {
278
+ code = await runChantInProcess(["run", "wave", "--spec", ".chant/waves.json", "--wave", "1", "--phase", "plan", "--base", "HEAD"], { product: "terragucci" }, {
279
+ wave: { hooks: { migrations: async (c) => (calls.push(`${c.moment} ${c.name}`), 0) } },
280
+ });
281
+ } finally {
282
+ process.chdir(was);
283
+ }
284
+ expect(code).toBe(CHANT_EXIT.done);
285
+ expect(calls).toEqual(["before-plan migrations"]);
286
+ expect(existsSync(join(cwd, opWaveSavedPlanPath(binSpec, 1)))).toBe(true);
287
+ }, 20_000);
288
+ });
@@ -0,0 +1,298 @@
1
+ /**
2
+ * #4992: the four jobs of a split wave take a `step` spec and a hook that
3
+ * holds the wave on another gate.
4
+ *
5
+ * - A step spec plans in the plan job's process, and the saved plan keeps
6
+ * its step plans. The gate job leases the rows they change before it
7
+ * spends the approval and names the lease in the decision; the applying
8
+ * job plans its runs again through the step, applies each whose digest
9
+ * the decision holds and writes nothing to the ledger; the record job
10
+ * writes the run and release records and lets go of the rows.
11
+ * - A hook in the plan or apply job that holds the wave on another gate
12
+ * reads that gate with no write token: while it waits, the gate job (a
13
+ * plan job's hold) or the record job (an apply job's) records its pending
14
+ * fact. A hold that asks chant to record the gate fails in the apply job
15
+ * once approved, since its approval is spent before the hook runs again;
16
+ * the plan job leaves the spend to the gate job (#4994,
17
+ * `op-waves-split-product.test.ts`).
18
+ */
19
+ import { afterAll, describe, expect, test } from "vitest";
20
+ import { execFileSync } from "node:child_process";
21
+ import { existsSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
22
+ import { tmpdir } from "node:os";
23
+ import { join } from "node:path";
24
+ import { opWaveOutcomeDir, opWaveRecordPath, type OpWavesSpec } from "./op-waves";
25
+ import { runOpWave, type OpWaveDecision, type OpWaveExec, type OpWaveRunPort, type OpWaveSavedPlan, type OpWaveShowAtBase } from "./op-waves-run";
26
+ import { opWaveRunRecordFileName, opWaveSavedPlanPath } from "./op-waves-split";
27
+ import type { OpWaveReleasePort, OpWaveReleaseRequest } from "./op-waves-release";
28
+ import { memoryGateLedgerPort } from "./gate";
29
+ import { CapabilityRegistry, type Capability } from "../components/capability";
30
+ import type { ChangeSetPart } from "../change-set";
31
+ import { leaseLockRows, readLockRows } from "../lifecycle/resource-lock";
32
+ import { CHANT_EXIT } from "../exit-codes";
33
+ import type { OpRunRecordInput } from "./runtime";
34
+
35
+ const dirs: string[] = [];
36
+ afterAll(() => {
37
+ for (const d of dirs) rmSync(d, { recursive: true, force: true });
38
+ });
39
+
40
+ function tmp(prefix: string): string {
41
+ const d = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
42
+ dirs.push(d);
43
+ return d;
44
+ }
45
+
46
+ function git(cwd: string, ...args: string[]): string {
47
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
48
+ }
49
+
50
+ /** A bare remote and `n` clones of it, each a writer of chant/lifecycle. */
51
+ function writers(n: number): string[] {
52
+ const remote = tmp("split-step-remote-");
53
+ git(remote, "init", "-q", "--bare", "-b", "main");
54
+ const seed = tmp("split-step-seed-");
55
+ git(seed, "init", "-q", "-b", "main");
56
+ git(seed, "config", "user.email", "seed@chant.dev");
57
+ git(seed, "config", "user.name", "Seed");
58
+ git(seed, "config", "commit.gpgsign", "false");
59
+ writeFileSync(join(seed, "README.md"), "# t\n");
60
+ git(seed, "add", "README.md");
61
+ git(seed, "commit", "-q", "-m", "init");
62
+ git(seed, "remote", "add", "origin", remote);
63
+ git(seed, "push", "-q", "origin", "main");
64
+ return Array.from({ length: n }, (_, i) => {
65
+ const c = tmp(`split-step-clone-${i}-`);
66
+ git(c, "clone", "-q", remote, ".");
67
+ git(c, "config", "user.email", `w${i}@chant.dev`);
68
+ git(c, "config", "user.name", `Writer ${i}`);
69
+ git(c, "config", "commit.gpgsign", "false");
70
+ return c;
71
+ });
72
+ }
73
+
74
+ const digest = (n: string) => `sha256:${n.repeat(64)}`;
75
+ const alive = async () => "alive" as const;
76
+ const ROW = "root network aws_s3_bucket.network";
77
+
78
+ /** A root on the resource grain: one row per root; `planned` says which digest the next plan gives. */
79
+ function rootCapability(): { registry: CapabilityRegistry; ran: string[]; plans: { count: number; digest: string } } {
80
+ const ran: string[] = [];
81
+ const plans = { count: 0, digest: digest("1") };
82
+ const part = (member: string): ChangeSetPart => ({
83
+ member: { member, lexicon: "terraform", planner: "chant", status: "planned", planDigest: plans.digest, holes: [] },
84
+ entries: [{ member, address: `aws_s3_bucket.${member}`, type: "aws_s3_bucket", action: "create" } as ChangeSetPart["entries"][number]],
85
+ });
86
+ const cap: Capability<Record<string, unknown>, unknown> = {
87
+ kind: "fake-root",
88
+ async plan(_ctx, input) {
89
+ plans.count++;
90
+ const root = String(input.root);
91
+ return { member: root, planDigest: plans.digest, artifact: { root, engineFile: `/tmp/${root}.tfplan` }, changeSet: part(root) };
92
+ },
93
+ async run(_ctx, input) {
94
+ ran.push(String(input.root));
95
+ return { applied: input.root };
96
+ },
97
+ defaultLockGrain: () => "resource",
98
+ lockRows: (input) => [{ key: `root ${String(input.root)} aws_s3_bucket.${String(input.root)}`, target: String(input.root), address: `aws_s3_bucket.${String(input.root)}` }],
99
+ };
100
+ return { registry: new CapabilityRegistry().register(cap), ran, plans };
101
+ }
102
+
103
+ const stepSpec: OpWavesSpec = {
104
+ name: "roots",
105
+ op: "tf-apply",
106
+ step: { kind: "fake-root", root: "{target}" },
107
+ waves: [{ name: "dev", runs: [{ target: "network" }], gate: "never" }],
108
+ };
109
+ const stepShow: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(stepSpec) });
110
+
111
+ /** The rows another writer reads on the remote. */
112
+ async function rowsSeenBy(cwd: string): Promise<Record<string, string>> {
113
+ return (await readLockRows("pr-apply", { cwd })).rows;
114
+ }
115
+
116
+ describe("a split wave with a step (#4992)", () => {
117
+ test("plan, gate, apply and record: the gate job leases the rows, the applying job plans again and writes nothing, the record job lets go", async () => {
118
+ const [other, job] = writers(2) as [string, string];
119
+ const { registry, ran, plans } = rootCapability();
120
+ const records: OpRunRecordInput[] = [];
121
+ const releases: OpWaveReleaseRequest[] = [];
122
+ const releasePort: OpWaveReleasePort = { record: async (r) => (releases.push(...r), r.map((q) => ({ recorded: true as const, env: q.env, component: q.component, digest: q.planDigest }))) };
123
+ const noWrites: OpWaveRunPort = { append: async () => Promise.reject(new Error("this job writes no run record to the ledger")) };
124
+ const noReleases: OpWaveReleasePort = { record: async () => Promise.reject(new Error("this job writes no release record")) };
125
+ const gates = memoryGateLedgerPort();
126
+ const base = { spec: stepSpec, specFile: "waves.json", wave: 1, cwd: job, show: stepShow, gates, capabilities: registry, lockLiveness: alive, log: () => {} };
127
+
128
+ const planned = await runOpWave({ ...base, phase: "plan", runs: noWrites, releases: noReleases });
129
+ expect(planned.exitCode).toBe(CHANT_EXIT.done);
130
+ const saved = JSON.parse(readFileSync(join(job, opWaveSavedPlanPath(stepSpec, 1)), "utf-8")) as OpWaveSavedPlan;
131
+ // The saved plan keeps the step plan with its rows, and leaves the engine's artifact in the plan job.
132
+ expect(saved.steps).toEqual([expect.objectContaining({ target: "network", planDigest: digest("1"), lock: expect.objectContaining({ grain: "resource" }) })]);
133
+ expect(JSON.stringify(saved.steps)).not.toContain("tfplan");
134
+ expect(await rowsSeenBy(other)).toEqual({});
135
+
136
+ const gated = await runOpWave({ ...base, phase: "gate" });
137
+ expect(gated.exitCode).toBe(CHANT_EXIT.done);
138
+ const decision = JSON.parse(readFileSync(join(job, opWaveRecordPath(stepSpec, 1)), "utf-8")) as OpWaveDecision;
139
+ expect(decision.lease).toMatchObject({ gate: "pr-apply", keys: [ROW] });
140
+ const holder = decision.lease!.run;
141
+ expect(await rowsSeenBy(other)).toEqual({ [ROW]: holder });
142
+ // The gate plans nothing.
143
+ expect(plans.count).toBe(1);
144
+
145
+ const applied = await runOpWave({ ...base, phase: "apply", runs: noWrites });
146
+ expect(applied).toMatchObject({ exitCode: 0, applied: ["network"] });
147
+ expect(ran).toEqual(["network"]);
148
+ // It planned its run again through the step, and left the rows to the record job.
149
+ expect(plans.count).toBe(2);
150
+ expect(await rowsSeenBy(other)).toEqual({ [ROW]: holder });
151
+ const file = JSON.parse(readFileSync(join(job, opWaveOutcomeDir(stepSpec), opWaveRunRecordFileName(1)), "utf-8")) as { handoff?: { releases?: OpWaveReleaseRequest[] } };
152
+ expect(file.handoff?.releases).toEqual([expect.objectContaining({ env: "dev", component: "network", target: "network", planDigest: digest("1") })]);
153
+
154
+ const recorded = await runOpWave({ ...base, phase: "record", gates: undefined, runs: { append: async (r) => void records.push(r) }, releases: releasePort });
155
+ expect(recorded).toMatchObject({ exitCode: 0, applied: ["network"] });
156
+ expect(records).toHaveLength(1);
157
+ expect(records[0]).not.toHaveProperty("handoff");
158
+ expect(releases.map((r) => r.target)).toEqual(["network"]);
159
+ expect(await rowsSeenBy(other)).toEqual({});
160
+ });
161
+
162
+ test("a row another run holds ends the wave in the gate job, held, before anything applies", async () => {
163
+ const [other, job] = writers(2) as [string, string];
164
+ const taken = await leaseLockRows("pr-apply", [{ key: ROW, target: "network", address: "aws_s3_bucket.network" }], { cwd: other, alive, holder: { run: "71", at: new Date().toISOString() } });
165
+ expect(taken.ok).toBe(true);
166
+ const { registry, ran } = rootCapability();
167
+ const base = { spec: stepSpec, specFile: "waves.json", wave: 1, cwd: job, show: stepShow, gates: memoryGateLedgerPort(), capabilities: registry, lockLiveness: alive, releases: false as const, log: () => {} };
168
+ await runOpWave({ ...base, phase: "plan" });
169
+ const held = await runOpWave({ ...base, phase: "gate" });
170
+ expect(held).toMatchObject({ exitCode: CHANT_EXIT.held, outcome: { outcome: "held", holder: { run: "71" } } });
171
+ expect(existsSync(join(job, opWaveRecordPath(stepSpec, 1)))).toBe(true);
172
+ expect((JSON.parse(readFileSync(join(job, opWaveRecordPath(stepSpec, 1)), "utf-8")) as OpWaveDecision).lease).toBeUndefined();
173
+ expect(ran).toEqual([]);
174
+ expect(await rowsSeenBy(other)).toEqual({ [ROW]: "71" });
175
+ });
176
+
177
+ test("a plan that moved since the gate is not applied, and the record job lets go of the rows all the same", async () => {
178
+ const [other, job] = writers(2) as [string, string];
179
+ const { registry, ran, plans } = rootCapability();
180
+ const base = { spec: stepSpec, specFile: "waves.json", wave: 1, cwd: job, show: stepShow, gates: memoryGateLedgerPort(), capabilities: registry, lockLiveness: alive, releases: false as const, log: () => {} };
181
+ await runOpWave({ ...base, phase: "plan" });
182
+ const gated = await runOpWave({ ...base, phase: "gate" });
183
+ expect(gated.exitCode).toBe(CHANT_EXIT.done);
184
+ plans.digest = digest("9");
185
+ const moved = await runOpWave({ ...base, phase: "apply" });
186
+ expect(moved).toMatchObject({ exitCode: CHANT_EXIT.moved, applied: [], moved: ["network"] });
187
+ expect(ran).toEqual([]);
188
+ // The record job lets go of the rows whatever the applying job did.
189
+ expect((await runOpWave({ ...base, phase: "record", gates: undefined, runs: { append: async () => {} } })).exitCode).toBe(CHANT_EXIT.moved);
190
+ expect(await rowsSeenBy(other)).toEqual({});
191
+ });
192
+ });
193
+
194
+ /** A command spec whose hooks, read at base, hold the wave on `tf-migrate / split-queues`. */
195
+ function holdHarness(moment: "plan" | "apply", request: Record<string, unknown>) {
196
+ const cwd = mkdtempSync(join(tmpdir(), "split-hold-"));
197
+ dirs.push(cwd);
198
+ const migrate = { name: "migrate", command: ["migrate", "{runs}"], onFailure: "approve" as const };
199
+ const spec: OpWavesSpec = {
200
+ name: "migrations",
201
+ op: "migrate",
202
+ plan: ["tool", "plan", "{target}", "--out", "{plan}"],
203
+ apply: ["tool", "apply", "{target}", "--plan", "{plan}"],
204
+ hooks: { before: { [moment]: [migrate] } },
205
+ waves: [{ name: "staging", runs: [{ target: "staging" }], gate: "never" }],
206
+ };
207
+ const calls: string[] = [];
208
+ const reruns: Array<Record<string, string>> = [];
209
+ const exec: OpWaveExec = (argv, dir, env = {}) => {
210
+ calls.push(argv.join(" "));
211
+ if (argv[0] === "tool" && argv[1] === "plan") writeFileSync(join(dir, argv[4]!), JSON.stringify({ planDigest: digest("a") }));
212
+ if (argv[0] !== "migrate") return 0;
213
+ if (env.CHANT_HOLD_APPROVED) {
214
+ reruns.push(env);
215
+ return 0;
216
+ }
217
+ writeFileSync(join(dir, env.CHANT_HOLD!), JSON.stringify({ op: "tf-migrate", gate: "split-queues", digest: digest("m"), description: "move the queues", ...request }));
218
+ return 3;
219
+ };
220
+ const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(spec) });
221
+ const approval = { version: 1 as const, op: "tf-migrate", gate: "split-queues", resolvedBy: "alice", timestamp: "2026-11-10T00:00:00Z", planDigest: digest("m") };
222
+ return { cwd, calls, reruns, approval, base: { spec, specFile: "waves.json", wave: 1, cwd, exec, show, log: () => {} } };
223
+ }
224
+
225
+ describe("a hold on another gate in a split wave (#4992)", () => {
226
+ const noWrites: OpWaveRunPort = { append: async () => Promise.reject(new Error("this job writes no run record to the ledger")) };
227
+
228
+ test("a plan job's hold is recorded by the gate job, and the wave goes on once that gate is approved", async () => {
229
+ const h = holdHarness("plan", { attachment: '{"proof":1}', pending: { members: [] } });
230
+ const gates = memoryGateLedgerPort();
231
+ const planned = await runOpWave({ ...h.base, phase: "plan", gates, runs: noWrites });
232
+ expect(planned.exitCode).toBe(CHANT_EXIT.waiting);
233
+ // The plan job wrote nothing to the ledger: no pending fact, no request file.
234
+ expect(gates.appended).toEqual([]);
235
+ expect(gates.attachments.size).toBe(0);
236
+ const saved = JSON.parse(readFileSync(join(h.cwd, opWaveSavedPlanPath(h.base.spec, 1)), "utf-8")) as OpWaveSavedPlan;
237
+ expect(saved.end?.decision?.heldOn).toMatchObject({ op: "tf-migrate", gate: "split-queues", status: "waiting", deferred: { input: { op: "tf-migrate", gate: "split-queues", planDigest: digest("m") } } });
238
+
239
+ const records: OpRunRecordInput[] = [];
240
+ const gated = await runOpWave({ ...h.base, phase: "gate", gates, runs: { append: async (r) => void records.push(r) } });
241
+ expect(gated).toMatchObject({ exitCode: CHANT_EXIT.waiting, decision: { status: "waiting", heldOn: { op: "tf-migrate", gate: "split-queues", recorded: true } } });
242
+ expect(gates.appended).toEqual([expect.objectContaining({ op: "tf-migrate", gate: "split-queues", planDigest: digest("m"), description: "move the queues", heldBy: { hook: "migrate", moment: "before-plan" } })]);
243
+ expect(gates.attachments.get(`tf-migrate/${digest("m")}`)).toBe('{"proof":1}');
244
+ const decision = JSON.parse(readFileSync(join(h.cwd, opWaveRecordPath(h.base.spec, 1)), "utf-8")) as OpWaveDecision;
245
+ expect(decision.heldOn).toMatchObject({ op: "tf-migrate", gate: "split-queues", recorded: true });
246
+ expect(decision.heldOn).not.toHaveProperty("deferred");
247
+ expect(records.map((r) => r.status)).toEqual(["gated"]);
248
+
249
+ // Approved: the plan job reads the approval with no token, the hook runs again, and the wave plans.
250
+ const approved = memoryGateLedgerPort({ resolutions: [h.approval] });
251
+ const again = await runOpWave({ ...h.base, phase: "plan", gates: approved, runs: noWrites });
252
+ expect(again.exitCode).toBe(CHANT_EXIT.done);
253
+ expect(JSON.parse(h.reruns[0]!.CHANT_HOLD_APPROVED!)).toMatchObject({ op: "tf-migrate", gate: "split-queues", approvedBy: "alice" });
254
+ expect(h.calls).toContain("tool plan staging --out .chant/op-waves/migrations/wave-1/staging.plan.json");
255
+ expect(approved.appended).toEqual([]);
256
+ });
257
+
258
+ test("an approved hold that asks chant to record its gate waits in the plan job, which leaves the spend to the gate job (#4994)", async () => {
259
+ const h = holdHarness("plan", { record: true });
260
+ const approved = memoryGateLedgerPort({ resolutions: [h.approval] });
261
+ const lines: string[] = [];
262
+ const planned = await runOpWave({ ...h.base, phase: "plan", gates: approved, runs: noWrites, log: (l) => lines.push(l) });
263
+ expect(planned.exitCode).toBe(CHANT_EXIT.waiting);
264
+ expect(h.reruns).toEqual([]);
265
+ expect(approved.applied).toEqual([]);
266
+ expect(lines.join("\n")).toContain("this plan job holds no write token, so the gate job spends it");
267
+ });
268
+
269
+ test("an approved hold that asks chant to record its gate fails in the applying job, which cannot spend it", async () => {
270
+ const h = holdHarness("apply", { record: true });
271
+ const approved = memoryGateLedgerPort({ resolutions: [h.approval] });
272
+ await runOpWave({ ...h.base, phase: "plan", gates: approved, runs: noWrites });
273
+ expect((await runOpWave({ ...h.base, phase: "gate", gates: approved })).exitCode).toBe(CHANT_EXIT.done);
274
+ const lines: string[] = [];
275
+ const applied = await runOpWave({ ...h.base, phase: "apply", gates: approved, runs: noWrites, log: (l) => lines.push(l) });
276
+ expect(applied.exitCode).toBe(CHANT_EXIT.failed);
277
+ expect(h.reruns).toEqual([]);
278
+ expect(approved.applied).toEqual([]);
279
+ expect(lines.join("\n")).toContain("this apply job of a split wave holds no write token, so it cannot spend it");
280
+ });
281
+
282
+ test("an applying job's hold is recorded by the record job, and the wave waits", async () => {
283
+ const h = holdHarness("apply", { pending: { members: [] } });
284
+ const gates = memoryGateLedgerPort();
285
+ await runOpWave({ ...h.base, phase: "plan", gates, runs: noWrites });
286
+ expect((await runOpWave({ ...h.base, phase: "gate", gates })).exitCode).toBe(CHANT_EXIT.done);
287
+ const applied = await runOpWave({ ...h.base, phase: "apply", gates, runs: noWrites });
288
+ expect(applied.exitCode).toBe(CHANT_EXIT.waiting);
289
+ expect(h.calls.some((c) => c.startsWith("tool apply"))).toBe(false);
290
+ expect(gates.appended).toEqual([]);
291
+ const file = JSON.parse(readFileSync(join(h.cwd, opWaveOutcomeDir(h.base.spec), opWaveRunRecordFileName(1)), "utf-8")) as { handoff?: { heldOn?: { deferred?: unknown } } };
292
+ expect(file.handoff?.heldOn?.deferred).toBeDefined();
293
+
294
+ const recorded = await runOpWave({ ...h.base, phase: "record", gates, runs: { append: async () => {} } });
295
+ expect(recorded.exitCode).toBe(CHANT_EXIT.waiting);
296
+ expect(gates.appended).toEqual([expect.objectContaining({ op: "tf-migrate", gate: "split-queues", planDigest: digest("m"), heldBy: { hook: "migrate", moment: "before-apply" } })]);
297
+ });
298
+ });