@intentius/chant 0.124.108 → 0.124.110

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 (342) hide show
  1. package/dist/__golden__/wave-loop/fan-out-applied.json +12 -6
  2. package/dist/__golden__/wave-loop/fan-out-apply-fails.json +8 -4
  3. package/dist/__golden__/wave-loop/fan-out-gated.json +4 -2
  4. package/dist/__golden__/wave-loop/fan-out-no-members.json +16 -8
  5. package/dist/__golden__/wave-loop/fan-out-plan-fails.json +8 -4
  6. package/dist/__golden__/wave-loop/fan-out-same-root.json +4 -2
  7. package/dist/agent-facts.d.ts +130 -0
  8. package/dist/agent-facts.js +196 -0
  9. package/dist/change-risk.d.ts +216 -0
  10. package/dist/change-risk.js +304 -0
  11. package/dist/change-set.d.ts +8 -0
  12. package/dist/ci-agent-alert.d.ts +139 -0
  13. package/dist/ci-agent-alert.js +342 -0
  14. package/dist/ci-agent-triggers.d.ts +152 -0
  15. package/dist/ci-agent-triggers.js +232 -0
  16. package/dist/ci-agent-verify-failed.d.ts +149 -0
  17. package/dist/ci-agent-verify-failed.js +191 -0
  18. package/dist/ci-agent.d.ts +136 -8
  19. package/dist/ci-agent.js +353 -26
  20. package/dist/ci-comment-commands.d.ts +8 -0
  21. package/dist/ci-comment-commands.js +17 -1
  22. package/dist/ci-comment-reject.d.ts +70 -0
  23. package/dist/ci-comment-reject.js +135 -0
  24. package/dist/ci-comment-replies.d.ts +3 -1
  25. package/dist/ci-comment-replies.js +6 -0
  26. package/dist/ci-estate/delivery.d.ts +25 -3
  27. package/dist/ci-estate/delivery.js +28 -9
  28. package/dist/ci-estate/page.d.ts +7 -3
  29. package/dist/ci-estate/page.js +19 -4
  30. package/dist/ci-estate/rows.d.ts +14 -2
  31. package/dist/ci-estate/rows.js +9 -1
  32. package/dist/ci-estate.d.ts +5 -2
  33. package/dist/ci-estate.js +3 -2
  34. package/dist/ci-handover.d.ts +2 -7
  35. package/dist/ci-handover.js +3 -20
  36. package/dist/ci-jobs.d.ts +6 -0
  37. package/dist/ci-jobs.js +17 -0
  38. package/dist/ci-note-commands.d.ts +2 -0
  39. package/dist/ci-note-commands.js +12 -1
  40. package/dist/ci-product-words.d.ts +151 -1
  41. package/dist/ci-product-words.js +1390 -3
  42. package/dist/ci-product.d.ts +100 -4
  43. package/dist/ci-product.js +99 -3
  44. package/dist/ci-respond-run.d.ts +9 -0
  45. package/dist/ci-respond-run.js +35 -4
  46. package/dist/ci-respond-summary-env.d.ts +56 -0
  47. package/dist/ci-respond-summary-env.js +81 -0
  48. package/dist/ci-respond-summary.d.ts +103 -0
  49. package/dist/ci-respond-summary.js +243 -0
  50. package/dist/ci-respond.d.ts +4 -2
  51. package/dist/ci-respond.js +4 -2
  52. package/dist/cli/command-group.js +1 -1
  53. package/dist/cli/commands/lint.js +21 -3
  54. package/dist/cli/handlers/agent.js +49 -4
  55. package/dist/cli/handlers/approve.js +3 -1
  56. package/dist/cli/handlers/build.d.ts +97 -1
  57. package/dist/cli/handlers/build.js +251 -3
  58. package/dist/cli/handlers/fan-out.js +55 -0
  59. package/dist/cli/handlers/graph.d.ts +14 -0
  60. package/dist/cli/handlers/graph.js +58 -3
  61. package/dist/cli/handlers/lifecycle-health.d.ts +7 -0
  62. package/dist/cli/handlers/lifecycle-health.js +47 -9
  63. package/dist/cli/handlers/lifecycle.js +4 -1
  64. package/dist/cli/handlers/notify-relay.d.ts +2 -2
  65. package/dist/cli/handlers/notify-relay.js +67 -7
  66. package/dist/cli/handlers/pipeline-agent.d.ts +30 -0
  67. package/dist/cli/handlers/pipeline-agent.js +255 -0
  68. package/dist/cli/handlers/pipeline-artifacts.d.ts +39 -0
  69. package/dist/cli/handlers/pipeline-artifacts.js +203 -0
  70. package/dist/cli/handlers/pipeline.d.ts +16 -0
  71. package/dist/cli/handlers/pipeline.js +112 -0
  72. package/dist/cli/handlers/pr-comment.js +4 -0
  73. package/dist/cli/handlers/pr-notes.js +4 -1
  74. package/dist/cli/handlers/pr.d.ts +20 -0
  75. package/dist/cli/handlers/pr.js +114 -11
  76. package/dist/cli/handlers/promote.js +792 -47
  77. package/dist/cli/handlers/reject.d.ts +84 -0
  78. package/dist/cli/handlers/reject.js +216 -0
  79. package/dist/cli/handlers/release.js +4 -2
  80. package/dist/cli/handlers/replan.d.ts +54 -0
  81. package/dist/cli/handlers/replan.js +177 -0
  82. package/dist/cli/handlers/run-generate.d.ts +5 -0
  83. package/dist/cli/handlers/run-generate.js +31 -4
  84. package/dist/cli/handlers/run-wave.js +15 -2
  85. package/dist/cli/handlers/run.js +4 -2
  86. package/dist/cli/handlers/stage.d.ts +35 -0
  87. package/dist/cli/handlers/stage.js +90 -0
  88. package/dist/cli/lsp/server.js +4 -0
  89. package/dist/cli/main.js +88 -8
  90. package/dist/cli/parse-args.js +35 -2
  91. package/dist/cli/registry.d.ts +12 -0
  92. package/dist/components/auto-release.d.ts +2 -0
  93. package/dist/components/auto-release.js +1 -0
  94. package/dist/components/capability.d.ts +40 -0
  95. package/dist/components/cli-support.d.ts +21 -1
  96. package/dist/components/cli-support.js +28 -6
  97. package/dist/components/component.d.ts +23 -4
  98. package/dist/components/component.schema.json +28 -0
  99. package/dist/components/declared-reads.d.ts +44 -4
  100. package/dist/components/declared-reads.js +80 -3
  101. package/dist/components/discover.d.ts +8 -0
  102. package/dist/components/discover.js +1 -1
  103. package/dist/components/driver.d.ts +13 -0
  104. package/dist/components/driver.js +23 -2
  105. package/dist/components/environment-sets.d.ts +229 -0
  106. package/dist/components/environment-sets.js +338 -0
  107. package/dist/components/fan-out-canary.d.ts +47 -0
  108. package/dist/components/fan-out-canary.js +58 -0
  109. package/dist/components/fan-out-run.d.ts +17 -0
  110. package/dist/components/fan-out-run.js +14 -1
  111. package/dist/components/fan-out-support.d.ts +7 -0
  112. package/dist/components/fan-out-support.js +1 -1
  113. package/dist/components/groups.d.ts +8 -1
  114. package/dist/components/groups.js +19 -1
  115. package/dist/components/index.d.ts +5 -2
  116. package/dist/components/index.js +4 -1
  117. package/dist/components/pr-cost.d.ts +28 -0
  118. package/dist/components/pr-cost.js +53 -0
  119. package/dist/components/pr-pipeline.d.ts +33 -0
  120. package/dist/components/pr-pipeline.js +32 -5
  121. package/dist/components/pr-policy.d.ts +33 -2
  122. package/dist/components/pr-policy.js +5 -2
  123. package/dist/components/pr-risk.d.ts +42 -0
  124. package/dist/components/pr-risk.js +74 -0
  125. package/dist/components/product-pipeline.d.ts +43 -0
  126. package/dist/components/product-pipeline.js +67 -1
  127. package/dist/components/promote.d.ts +6 -0
  128. package/dist/components/promote.js +13 -0
  129. package/dist/components/release-compile.js +3 -1
  130. package/dist/components/release-gate.d.ts +6 -1
  131. package/dist/components/release-gate.js +10 -2
  132. package/dist/components/step-environments.d.ts +236 -0
  133. package/dist/components/step-environments.js +392 -0
  134. package/dist/components/upstream-replan.d.ts +201 -0
  135. package/dist/components/upstream-replan.js +249 -0
  136. package/dist/components/verify-step.d.ts +30 -0
  137. package/dist/components/verify-step.js +27 -0
  138. package/dist/components/wave-plan.js +6 -2
  139. package/dist/config-environments.d.ts +4 -2
  140. package/dist/control/dispatch.d.ts +15 -0
  141. package/dist/control/dispatch.js +28 -4
  142. package/dist/cost-estimate.d.ts +188 -0
  143. package/dist/cost-estimate.js +363 -0
  144. package/dist/drift-record.d.ts +36 -0
  145. package/dist/drift-record.js +44 -0
  146. package/dist/engine-facts.d.ts +105 -0
  147. package/dist/engine-facts.js +111 -0
  148. package/dist/exit-codes.d.ts +4 -3
  149. package/dist/exit-codes.js +4 -3
  150. package/dist/flag-params.d.ts +2 -2
  151. package/dist/flag-params.js +9 -4
  152. package/dist/floor-table.data.js +53 -0
  153. package/dist/forge-token-vars.d.ts +12 -0
  154. package/dist/forge-token-vars.js +25 -0
  155. package/dist/gate-decision.d.ts +3 -1
  156. package/dist/gate-decision.js +3 -1
  157. package/dist/gated-waves.d.ts +2 -0
  158. package/dist/gated-waves.js +1 -0
  159. package/dist/graph-ir.d.ts +30 -0
  160. package/dist/graph-ir.js +33 -1
  161. package/dist/graph-refs.d.ts +26 -0
  162. package/dist/graph-refs.js +34 -3
  163. package/dist/graph-schema/graph.schema.json +136 -0
  164. package/dist/health.d.ts +65 -0
  165. package/dist/health.js +62 -0
  166. package/dist/lexicon.d.ts +188 -1
  167. package/dist/lifecycle/disruption.d.ts +14 -1
  168. package/dist/lifecycle/disruption.js +5 -1
  169. package/dist/lifecycle/gate-change-set.d.ts +8 -0
  170. package/dist/lifecycle/gate-change-set.js +2 -1
  171. package/dist/lifecycle/gate-ledger.d.ts +26 -0
  172. package/dist/lifecycle/gate-rejection.d.ts +82 -0
  173. package/dist/lifecycle/gate-rejection.js +93 -0
  174. package/dist/lifecycle/gate-seal.d.ts +3 -3
  175. package/dist/lifecycle/gate-seal.js +5 -5
  176. package/dist/lifecycle/observe.d.ts +17 -0
  177. package/dist/lifecycle/observe.js +10 -1
  178. package/dist/lifecycle/release-cut.js +4 -0
  179. package/dist/lifecycle/release-ledger.d.ts +8 -0
  180. package/dist/lifecycle/release-risk.d.ts +137 -0
  181. package/dist/lifecycle/release-risk.js +214 -0
  182. package/dist/lifecycle/release-store.d.ts +9 -0
  183. package/dist/lifecycle/release-store.js +4 -0
  184. package/dist/lifecycle/stage-log.d.ts +85 -0
  185. package/dist/lifecycle/stage-log.js +141 -0
  186. package/dist/lint/canary-checks.d.ts +31 -0
  187. package/dist/lint/canary-checks.js +45 -0
  188. package/dist/lint/rule.d.ts +1 -0
  189. package/dist/lint/rules/evl012-pipeline-fold.d.ts +14 -0
  190. package/dist/lint/rules/evl012-pipeline-fold.js +30 -0
  191. package/dist/lint/rules/index.d.ts +1 -0
  192. package/dist/lint/rules/index.js +3 -0
  193. package/dist/notify-relay-repo.d.ts +54 -0
  194. package/dist/notify-relay-repo.js +84 -0
  195. package/dist/notify-relay.d.ts +53 -3
  196. package/dist/notify-relay.js +96 -3
  197. package/dist/notify.d.ts +57 -1
  198. package/dist/notify.js +7 -1
  199. package/dist/notify.schema.json +61 -3
  200. package/dist/observation.d.ts +34 -0
  201. package/dist/observation.js +14 -1
  202. package/dist/op/activities/review-agent.d.ts +39 -2
  203. package/dist/op/activities/review-agent.js +88 -5
  204. package/dist/op/agent-permit.d.ts +88 -0
  205. package/dist/op/agent-permit.js +97 -0
  206. package/dist/op/gate-approval-base.d.ts +8 -0
  207. package/dist/op/gate-approval-base.js +9 -0
  208. package/dist/op/gate-approval.d.ts +30 -1
  209. package/dist/op/gate-approval.js +23 -2
  210. package/dist/op/gate-quorum.d.ts +114 -8
  211. package/dist/op/gate-quorum.js +198 -21
  212. package/dist/op/gate-reject.d.ts +79 -0
  213. package/dist/op/gate-reject.js +96 -0
  214. package/dist/op/gate-summary.js +1 -1
  215. package/dist/op/gate.d.ts +28 -3
  216. package/dist/op/gate.js +55 -13
  217. package/dist/op/generate-pipeline.d.ts +15 -1
  218. package/dist/op/generate-pipeline.js +32 -5
  219. package/dist/op/index.d.ts +11 -6
  220. package/dist/op/index.js +10 -5
  221. package/dist/op/local-executor.d.ts +2 -0
  222. package/dist/op/local-executor.js +23 -4
  223. package/dist/op/op-waves-after-plan.d.ts +23 -0
  224. package/dist/op/op-waves-after-plan.js +12 -1
  225. package/dist/op/op-waves-capability-spec.d.ts +14 -0
  226. package/dist/op/op-waves-capability-spec.js +46 -6
  227. package/dist/op/op-waves-capability.d.ts +21 -13
  228. package/dist/op/op-waves-capability.js +22 -59
  229. package/dist/op/op-waves-environment-sets.d.ts +41 -0
  230. package/dist/op/op-waves-environment-sets.js +82 -0
  231. package/dist/op/op-waves-quorum-warnings.d.ts +53 -0
  232. package/dist/op/op-waves-quorum-warnings.js +90 -0
  233. package/dist/op/op-waves-release-port.d.ts +7 -0
  234. package/dist/op/op-waves-release-port.js +15 -3
  235. package/dist/op/op-waves-release.d.ts +15 -0
  236. package/dist/op/op-waves-release.js +15 -0
  237. package/dist/op/op-waves-run.d.ts +37 -3
  238. package/dist/op/op-waves-run.js +141 -18
  239. package/dist/op/op-waves-soak.d.ts +57 -0
  240. package/dist/op/op-waves-soak.js +111 -0
  241. package/dist/op/op-waves-split.d.ts +4 -0
  242. package/dist/op/op-waves-split.js +4 -0
  243. package/dist/op/op-waves.d.ts +67 -4
  244. package/dist/op/op-waves.js +71 -3
  245. package/dist/pipeline/agent-ajv.d.ts +4 -0
  246. package/dist/pipeline/agent-ajv.js +14 -0
  247. package/dist/pipeline/agent-steps.d.ts +329 -0
  248. package/dist/pipeline/agent-steps.js +602 -0
  249. package/dist/pipeline/artifacts.d.ts +264 -0
  250. package/dist/pipeline/artifacts.js +425 -0
  251. package/dist/pipeline/diff.d.ts +45 -0
  252. package/dist/pipeline/diff.js +177 -0
  253. package/dist/pipeline/fold.d.ts +43 -0
  254. package/dist/pipeline/fold.js +140 -0
  255. package/dist/pipeline/generate.d.ts +52 -0
  256. package/dist/pipeline/generate.js +120 -0
  257. package/dist/pipeline/product.d.ts +225 -0
  258. package/dist/pipeline/product.js +257 -0
  259. package/dist/pipeline/promote.d.ts +404 -0
  260. package/dist/pipeline/promote.js +694 -0
  261. package/dist/pipeline/read.d.ts +37 -0
  262. package/dist/pipeline/read.js +58 -0
  263. package/dist/pipeline/rendered.d.ts +25 -0
  264. package/dist/pipeline/rendered.js +53 -0
  265. package/dist/pipeline/soak-checks.d.ts +80 -0
  266. package/dist/pipeline/soak-checks.js +254 -0
  267. package/dist/pipeline/soak-gate.d.ts +97 -0
  268. package/dist/pipeline/soak-gate.js +176 -0
  269. package/dist/pipeline/soak-sources.d.ts +17 -0
  270. package/dist/pipeline/soak-sources.js +42 -0
  271. package/dist/pipeline/soak.d.ts +260 -0
  272. package/dist/pipeline/soak.js +378 -0
  273. package/dist/pipeline/spec.d.ts +724 -0
  274. package/dist/pipeline/spec.js +567 -0
  275. package/dist/pipeline/stage-ledger.d.ts +187 -0
  276. package/dist/pipeline/stage-ledger.js +185 -0
  277. package/dist/pipeline/stage-waves.d.ts +114 -0
  278. package/dist/pipeline/stage-waves.js +161 -0
  279. package/dist/pipeline/stages.d.ts +64 -0
  280. package/dist/pipeline/stages.js +174 -0
  281. package/dist/pipeline/verify-rollback.d.ts +277 -0
  282. package/dist/pipeline/verify-rollback.js +393 -0
  283. package/dist/pipeline.d.ts +142 -0
  284. package/dist/pipeline.js +143 -0
  285. package/dist/pr-loop.d.ts +22 -0
  286. package/dist/pr-loop.js +8 -0
  287. package/dist/pr-plan-note.d.ts +15 -1
  288. package/dist/pr-plan-note.js +8 -0
  289. package/dist/pr-post.d.ts +31 -0
  290. package/dist/pr-post.js +89 -0
  291. package/dist/release-floors.d.ts +1 -1
  292. package/dist/release-floors.js +1 -1
  293. package/dist/report-store/audit.schema.json +50 -0
  294. package/dist/report-store/dora.schema.json +331 -0
  295. package/dist/report-store/estate.schema.json +96 -0
  296. package/dist/report-store/run.schema.json +14 -0
  297. package/dist/report-store.d.ts +151 -0
  298. package/dist/report-store.js +344 -0
  299. package/dist/run-event.d.ts +7 -2
  300. package/dist/wave-runtime.mjs +458 -404
  301. package/dist/workspace/catalog-edges.js +3 -3
  302. package/dist/workspace/change-set.schema.json +4 -0
  303. package/dist/workspace/ci-cloud-identity.d.ts +4 -0
  304. package/dist/workspace/ci-cloud-identity.js +30 -0
  305. package/dist/workspace/ci-run.js +17 -2
  306. package/dist/workspace/ci-secrets.d.ts +3 -1
  307. package/dist/workspace/ci-secrets.js +7 -1
  308. package/dist/workspace/compose-graph.d.ts +1 -1
  309. package/dist/workspace/compose-graph.js +3 -1
  310. package/dist/workspace/declaration.d.ts +27 -0
  311. package/dist/workspace/declaration.js +35 -0
  312. package/dist/workspace/declaration.schema.json +56 -0
  313. package/dist/workspace/graph-cli.js +26 -0
  314. package/dist/workspace/graph.schema.json +5 -1
  315. package/dist/workspace/identity-gate-rule.d.ts +4 -0
  316. package/dist/workspace/identity-gate-rule.js +2 -2
  317. package/dist/workspace/identity-reject-rule.d.ts +14 -0
  318. package/dist/workspace/identity-reject-rule.js +24 -0
  319. package/dist/workspace/identity.d.ts +3 -0
  320. package/dist/workspace/identity.js +2 -1
  321. package/dist/workspace/nested-graph.js +2 -0
  322. package/dist/workspace/pr-report.schema.json +65 -0
  323. package/dist/workspace/promotion-order.d.ts +19 -4
  324. package/dist/workspace/promotion-order.js +26 -4
  325. package/dist/workspace/release-train.d.ts +14 -0
  326. package/dist/workspace/release-train.js +32 -0
  327. package/dist/workspace/run-event.schema.json +2 -2
  328. package/dist/workspace/stack-read-edges.d.ts +19 -0
  329. package/dist/workspace/stack-read-edges.js +54 -0
  330. package/dist/workspace/status-gates.d.ts +51 -1
  331. package/dist/workspace/status-gates.js +60 -0
  332. package/dist/workspace/status-stages.d.ts +223 -0
  333. package/dist/workspace/status-stages.js +279 -0
  334. package/dist/workspace/status.d.ts +45 -1
  335. package/dist/workspace/status.js +109 -5
  336. package/dist/workspace/status.schema.json +283 -2
  337. package/dist/workspace/train-cut.js +5 -2
  338. package/dist/workspace/train-shell.d.ts +18 -0
  339. package/dist/workspace/train-shell.js +43 -0
  340. package/dist/workspace/trust/seal.d.ts +7 -0
  341. package/dist/workspace/trust/seal.js +9 -0
  342. package/package.json +5 -1
@@ -31,12 +31,13 @@ import { fetchLifecycle, getHeadCommit, pushLifecycle } from "../../lifecycle/gi
31
31
  import { appendReleaseRecord, latestPerComponent, readReleaseLedger, resolveRunId, } from "../../lifecycle/release-ledger.js";
32
32
  import { isComponentList, resolveComponentTargets } from "../../components/cli-support.js";
33
33
  import { applyConfigDefaults } from "../../components/config-defaults.js";
34
+ import { componentForEnvironment } from "../../components/step-environments.js";
34
35
  import { withDeclaredReads } from "../../components/declared-reads.js";
35
36
  import { fanOutRegistry } from "../../components/fan-out-support.js";
36
37
  import { renderDriverHuman } from "../../components/driver-output.js";
37
38
  import { ndjsonProgressSink } from "../../components/run-progress.js";
38
39
  import { openCliRunEvents, refusesBothStreams } from "../run-events.js";
39
- import { parseDigestPins, planPromotion, planRollback, planReleaseRollback, planRedeploy, withoutBuildSteps, runPromotion, promotionRecord, rollbackRecord, redeployRecord, gateApprover, gateAdmission, } from "../../components/promote.js";
40
+ import { parseDigestPins, planPromotion, planRollback, planReleaseRollback, planRedeploy, withoutBuildSteps, runPromotion, promotionRecord, rollbackRecord, redeployRecord, gateApprover, gatesSkipped, gateAdmission, } from "../../components/promote.js";
40
41
  import { failedRunExitCode } from "../../components/driver.js";
41
42
  import { summaryLedgerPrefix, writeGatedRunSummary } from "../../op/gate-summary.js";
42
43
  import { approveCommand, describeGateMismatch, gateIsSealed, gitGateLedgerPort } from "../../op/gate.js";
@@ -46,8 +47,21 @@ import { GATED_EXIT_CODE } from "./run.js";
46
47
  import { withComponentEndpoint } from "../component-endpoint.js";
47
48
  import { redeployLine, releaseRollbackLine, rollbackTarget, unsettledComponents } from "../../lifecycle/mixed-environment.js";
48
49
  import { actorFromEnv } from "../../actor.js";
49
- const PROMOTE_USAGE = "chant components promote --to <env> [--from <env>] [--allow-skip] [--release <label|digest> [--plan-only]] [--component <name> [--digest <sha256:...>] | --digest <component>=<sha256:...> ...] [--wave-gate <gate>] [--resume <file>] [--dry-run] [--json]";
50
- const ROLLBACK_USAGE = "chant components rollback <env> (--component <name> [--digest <sha256:...>] | --release <label|digest>) [--dry-run] [--json]";
50
+ import { promoteBase, readPipelineAt } from "../../pipeline/read.js";
51
+ import { pipelinePromoteRejected, pipelinePromoteSoaks, pipelinePromoteSource, pipelineStageEntry, pipelineStageFinished, pipelineUrgentUpstream, promotedDigest, urgentUpstreamStop } from "../../pipeline/promote.js";
52
+ import { gitStageLedgerPort, pauseLine, releaseMissingIn, stagePaused, stagePausedLine, supersededBy, waitingLine } from "../../pipeline/stage-ledger.js";
53
+ import { stageSoakGate } from "../../pipeline/soak-gate.js";
54
+ import { stageWavesName } from "../../pipeline/stages.js";
55
+ import { stageReleaseItems, stageRunsWaves } from "../../pipeline/stage-waves.js";
56
+ import { canaryStagesBefore } from "../../pipeline/spec.js";
57
+ import { soakCheckReader } from "../../pipeline/soak-checks.js";
58
+ import { jobSoakSources } from "../../pipeline/soak-sources.js";
59
+ import { isPendingGateExpired } from "../../lifecycle/gate-ledger-select.js";
60
+ import { failedVerify } from "../../components/verify-step.js";
61
+ import { failureDetail, memberStatesOf, soakFailureOf, requestedRollbackGate, requestStageRollback, rolledBackLine, stageOnVerifyFail, stageRollbackGate, standingRollbackRequest } from "../../pipeline/verify-rollback.js";
62
+ import { activeProductWords } from "../../ci-product-words.js";
63
+ const PROMOTE_USAGE = "chant components promote --to <env> [--from <env>] [--allow-skip] [--pending] [--release <label|digest> [--plan-only]] [--urgent --reason <text>] [--component <name> [--digest <sha256:...>] | --digest <component>=<sha256:...> ...] [--wave-gate <gate>] [--resume <file>] [--dry-run] [--json]";
64
+ const ROLLBACK_USAGE = "chant components rollback <env> (--component <name> [--digest <sha256:...>] | --release <label|digest> | --requested) [--dry-run] [--json]";
51
65
  const REDEPLOY_USAGE = "chant components redeploy <env> --component <name> [--digest <sha256:...>] [--dry-run] [--json]";
52
66
  function renderPlan(verb, plan, removed) {
53
67
  console.error(formatBold(verb === "promote" ? `promote ${plan.from} -> ${plan.to}` : `${verb} ${plan.to}`));
@@ -347,17 +361,34 @@ function approvalLine(r) {
347
361
  * and which field names the earlier release on the new record.
348
362
  */
349
363
  /** {@link deployPlanIn}, with `plan.to`'s declared endpoint applied (#4281). */
350
- function deployPlan(ctx, verb, plan, project, actor, record, under) {
351
- return withComponentEndpoint(ctx, () => deployPlanIn(ctx, verb, plan, project, actor, record, under), { config: project.config, environment: plan.to });
364
+ function deployPlan(ctx, verb, plan, project, actor, record, under, observe) {
365
+ return withComponentEndpoint(ctx, () => deployPlanIn(ctx, verb, plan, project, actor, record, under, observe), { config: project.config, environment: plan.to });
352
366
  }
353
- async function deployPlanIn(ctx, verb, plan, project, actor, record, under) {
367
+ async function deployPlanIn(ctx, verb, plan, project, actor, record, under,
368
+ /** Handed the run once it ended (#5328), so a promote can read each member's state. */
369
+ observe) {
354
370
  const { args } = ctx;
355
371
  if (refusesBothStreams(args))
356
372
  return 1;
357
- const byName = new Map(project.targets.map((c) => [c.name, applyConfigDefaults(c, project.config)]));
373
+ // #5360: each step's inputs for the environment deployed to, so the plan, the release pin and the run read that environment's target.
374
+ const resolvedFor = new Map(project.targets.map((c) => [c.name, componentForEnvironment(applyConfigDefaults(c, project.config), plan.to)]));
375
+ const byName = new Map([...resolvedFor].map(([name, r]) => [name, r.component]));
358
376
  const prepared = [];
359
377
  const removed = new Map();
360
- const refusals = [];
378
+ const refusals = plan.items.flatMap((item) => (resolvedFor.get(item.component)?.refusals ?? []).map((r) => r.message));
379
+ // #5401: the gates that name other environments, which this run skips; the plan lists them.
380
+ const skippedGates = plan.items.flatMap((item) => resolvedFor.get(item.component)?.skippedGates ?? []);
381
+ const skippedJson = skippedGates.length > 0 ? { gatesSkipped: skippedGates.map((g) => ({ component: g.component, phase: g.phase, gate: g.gate, environments: g.environments })) } : {};
382
+ const skippedLines = () => {
383
+ for (const g of skippedGates)
384
+ console.error(formatInfo(`${g.component}: gate "${g.gate}" is skipped in "${plan.to}"; it applies in ${g.environments.join(", ")}`));
385
+ };
386
+ if (refusals.length > 0) {
387
+ for (const message of refusals)
388
+ console.error(formatError({ message }));
389
+ console.error(formatError({ message: `nothing was deployed` }));
390
+ return 1;
391
+ }
361
392
  // #4222: a component with no artifact, deployed from the templates the release records, and its record's digest.
362
393
  const templateDigests = new Map();
363
394
  const { releaseTemplatesDigest } = await import("../../components/release-promote.js");
@@ -430,16 +461,19 @@ async function deployPlanIn(ctx, verb, plan, project, actor, record, under) {
430
461
  : {};
431
462
  if (args.dryRun) {
432
463
  if (args.json)
433
- console.log(JSON.stringify({ ...planJson(plan, removed), ...releaseJson }, null, 2));
464
+ console.log(JSON.stringify({ ...planJson(plan, removed), ...releaseJson, ...skippedJson }, null, 2));
434
465
  else {
435
466
  renderPlan(verb, plan, removed);
467
+ skippedLines();
436
468
  if (under)
437
469
  console.error(` under release ${under.label ?? under.release.releaseDigest}: ${under.target.templates.length} template(s) from its "${plan.to}" target`);
438
470
  }
439
471
  return 0;
440
472
  }
441
- if (!args.json)
473
+ if (!args.json) {
442
474
  renderPlan(verb, plan, removed);
475
+ skippedLines();
476
+ }
443
477
  // #4045: the pinned templates are written for this run and removed after it.
444
478
  const { writePinnedTemplates, removePinnedTemplates } = await import("../../components/release-promote.js");
445
479
  const tidy = () => {
@@ -464,7 +498,7 @@ async function deployPlanIn(ctx, verb, plan, project, actor, record, under) {
464
498
  // an importer deploys after the exporter it reads. Read once the release's
465
499
  // templates are written, so they are the files read; a read of a component
466
500
  // this promote does not deploy is left out.
467
- prepared.splice(0, prepared.length, ...(await withDeclaredReads(prepared, registry, project.projectPath)));
501
+ prepared.splice(0, prepared.length, ...(await withDeclaredReads(prepared, registry, project.projectPath, { env: plan.to })));
468
502
  const port = gitGateLedgerPort();
469
503
  // #4045: under a release, every gate binds the release's change set for this environment.
470
504
  let releaseGate;
@@ -572,11 +606,12 @@ async function deployPlanIn(ctx, verb, plan, project, actor, record, under) {
572
606
  changeSet: bound?.doc.digest ?? null,
573
607
  empty: bound?.empty ?? null,
574
608
  components: plan.items.map((i) => i.component),
609
+ ...skippedJson,
575
610
  };
576
611
  if (args.json)
577
612
  console.log(JSON.stringify(planned, null, 2));
578
613
  else if (!bound)
579
- console.error(formatInfo(`release ${under.label ?? under.release.releaseDigest} for "${plan.to}": no promoted composition declares a gate, so there is no change set to approve; nothing was deployed`));
614
+ console.error(formatInfo(`release ${under.label ?? under.release.releaseDigest} for "${plan.to}": no promoted composition declares a gate${skippedGates.length > 0 ? ` that applies in "${plan.to}"` : ""}, so there is no change set to approve; nothing was deployed`));
580
615
  else
581
616
  console.error(formatInfo(`release ${under.label ?? under.release.releaseDigest} for "${plan.to}": change set ${planned.changeSet}${planned.empty ? ", empty" : ""}, gates ${planned.gates.join(", ")}; nothing was deployed`));
582
617
  return 0;
@@ -702,6 +737,7 @@ async function deployPlanIn(ctx, verb, plan, project, actor, record, under) {
702
737
  events?.settle(run.status === "fail" ? "failed" : run.status);
703
738
  if (!args.json)
704
739
  renderDriverHuman(run);
740
+ observe?.(run);
705
741
  // Record every component that deployed, whatever happened to the rest: a
706
742
  // component that reached the environment and is missing from its ledger
707
743
  // would be exactly the unrecorded deploy the ledger exists to rule out.
@@ -719,7 +755,8 @@ async function deployPlanIn(ctx, verb, plan, project, actor, record, under) {
719
755
  const result = run.results.find((r) => r.component === item.component);
720
756
  const approver = gateApprover(result);
721
757
  const admission = gateAdmission(result);
722
- const input = record(item, plan.to, { runId, ...(runOrigin ? { runOrigin } : {}), actor: actor, timestamp, ...(approver ? { approver } : {}), ...(admission ? { admission } : {}) });
758
+ const skipped = gatesSkipped(result);
759
+ const input = record(item, plan.to, { runId, ...(runOrigin ? { runOrigin } : {}), actor: actor, timestamp, ...(approver ? { approver } : {}), ...(admission ? { admission } : {}), ...(skipped ? { gatesSkipped: skipped } : {}) });
723
760
  const templates = templateDigests.get(item.component);
724
761
  const { record: written } = await appendReleaseRecord(under ? { ...input, ...(templates ? { digest: templates, digestKind: "templates" } : {}), releaseDigest: under.release.releaseDigest } : input);
725
762
  recorded.push(written);
@@ -736,7 +773,7 @@ async function deployPlanIn(ctx, verb, plan, project, actor, record, under) {
736
773
  const withChangeSet = under && changeSetJson ? { release: { ...releaseJson.release, ...changeSetJson } } : releaseJson;
737
774
  const stagedJson = staged ? { stages: staged.stages, ...(bound?.plannedOutputs ? { plannedOutputs: bound.plannedOutputs } : {}), ...(bound?.unknownInputs ? { unknownInputs: bound.unknownInputs } : {}) } : {};
738
775
  const prJson = pullRequests.length > 0 ? { pullRequests: pullRequests.map((r) => ({ commit: r.commit, source: r.source, plan: r.plan, digest: r.digest, approvedBy: r.approvedBy, ...(r.authorApproved ? { authorApproved: r.authorApproved } : {}) })) } : {};
739
- console.log(JSON.stringify({ ...planJson(plan, removed), ...withChangeSet, ...stagedJson, ...prJson, ...groupsReport, run, recorded, ...(outcome ? { outcome } : {}) }, null, 2));
776
+ console.log(JSON.stringify({ ...planJson(plan, removed), ...withChangeSet, ...skippedJson, ...stagedJson, ...prJson, ...groupsReport, run, recorded, ...(outcome ? { outcome } : {}) }, null, 2));
740
777
  }
741
778
  else {
742
779
  for (const r of recorded) {
@@ -773,7 +810,7 @@ async function deployPlanIn(ctx, verb, plan, project, actor, record, under) {
773
810
  if (run.gateMismatch) {
774
811
  console.error(formatWarning({ message: describeGateMismatch(pending.op, pending.gate, run.gateMismatch, sealed) }));
775
812
  }
776
- console.error(formatInfo(`approve : ${approveCommand(pending.op, pending.gate, pending.environment, undefined, sealed)}`));
813
+ console.error(formatInfo(`approve : ${approveCommand(pending.op, pending.gate, pending.environment, pending.planDigest, sealed)}`));
777
814
  console.error(formatInfo(`then run the same ${verb} again`));
778
815
  writeGatedRunSummary({
779
816
  sealed,
@@ -789,6 +826,14 @@ async function deployPlanIn(ctx, verb, plan, project, actor, record, under) {
789
826
  return GATED_EXIT_CODE;
790
827
  }
791
828
  if (run.status !== "ok") {
829
+ // #5339: a failed verify step is a fact for the verify-failed agent, with CHANT_AGENT_FACTS=verify-failed; the exit stands either way.
830
+ if (verb !== "rollback" && !ctx.args.dryRun) {
831
+ const { recordVerifyFailed, verifyFailedRecords } = await import("../../ci-agent-verify-failed.js");
832
+ const records = verifyFailedRecords({ stage: plan.to, verb, ...(under ? { releaseDigest: under.release.releaseDigest } : {}), steps: run.results.flatMap((r) => r.records) });
833
+ const line = await recordVerifyFailed(records, {});
834
+ if (line)
835
+ console.error(formatInfo(line));
836
+ }
792
837
  console.error(formatError({ message: `${verb} failed at "${run.failedComponent ?? "unknown"}"` }));
793
838
  // A step that refused a plan that moved since it was approved exits 3 (#3997).
794
839
  return failedRunExitCode(run.results);
@@ -827,8 +872,13 @@ async function revokedOrRefuse(what) {
827
872
  * code returned, when the release can't be found, has no target for `env`,
828
873
  * is of a project with no components (#4046), or was cut from a revoked
829
874
  * commit (#4033), so a gate pending for it can't pass.
875
+ *
876
+ * With `waves` (#5427), the release is promoted by a stage's op waves, which
877
+ * apply from the checkout and read no template the release recorded: a
878
+ * release with no target for `env`, or of a project with no components, is
879
+ * taken, with an empty target.
830
880
  */
831
- async function resolveUnderRelease(ref, env, verb, fix) {
881
+ async function resolveUnderRelease(ref, env, verb, fix, opts = {}) {
832
882
  const { resolveRelease } = await import("../../lifecycle/release-store.js");
833
883
  const { targetFor, isImplicitRelease } = await import("../../components/release-promote.js");
834
884
  const found = await resolveRelease(ref);
@@ -836,14 +886,15 @@ async function resolveUnderRelease(ref, env, verb, fix) {
836
886
  console.error(formatError({ message: `no release is labelled or digested "${ref}" in this member`, hint: "List them with: chant release list" }));
837
887
  return 1;
838
888
  }
839
- const target = targetFor(found.release, env);
889
+ const targetOf = targetFor(found.release, env);
890
+ const target = "error" in targetOf && opts.waves ? { target: { env, templates: [], params: [] } } : targetOf;
840
891
  if ("error" in target) {
841
892
  console.error(formatError({ message: target.error }));
842
893
  return 1;
843
894
  }
844
895
  // #4046: a release of a project with no components records build output
845
896
  // and no component, so there is no deploy step here to point at it.
846
- if (isImplicitRelease(found.release)) {
897
+ if (isImplicitRelease(found.release) && !opts.waves) {
847
898
  const name = found.label ?? found.release.releaseDigest;
848
899
  console.error(formatError({
849
900
  message: `release ${name} is of a project with no components, so ${verb} has no component to deploy`,
@@ -949,30 +1000,75 @@ export async function runComponentsPromote(ctx) {
949
1000
  console.error(formatError({ message: "--plan-only plans a release's change set: it needs --release <label|digest>", hint: PROMOTE_USAGE }));
950
1001
  return 1;
951
1002
  }
1003
+ if (args.pendingPromotion)
1004
+ return runPendingPromotion(ctx, to);
952
1005
  const who = actorOrRefuse(ctx);
953
1006
  if (typeof who === "number")
954
1007
  return who;
955
1008
  const project = await loadProject(ctx, args.component ?? "all", to);
956
1009
  if (typeof project === "number")
957
1010
  return project;
958
- // The member's `environments` array is its promotion order (#4030). It
959
- // defaults --from and refuses a skipped step; a member that declares none
960
- // has no order, so --from is required and nothing is refused.
961
- const resolved = resolvePromotionSource({
962
- order: promotionOrder(project.config.environments),
963
- to,
964
- ...(args.migrateFrom ? { from: args.migrateFrom } : {}),
965
- ...(args.allowSkip ? { allowSkip: true } : {}),
966
- });
967
- if ("error" in resolved) {
968
- console.error(formatError({ message: `${resolved.error.message} [${resolved.error.code}]`, hint: resolved.error.fix }));
969
- return 1;
1011
+ // #5324: a member's pipeline, read at the default branch's tip, orders the
1012
+ // stages, holds and freezes them, and gates each promotion and each skip.
1013
+ const pipeline = readPromotePipeline(project.projectPath, to);
1014
+ if (typeof pipeline === "number")
1015
+ return pipeline;
1016
+ // #5355: the urgent path is a pipeline stage's rule, for one release, with a reason on the record.
1017
+ if (args.urgent) {
1018
+ const missing = !pipeline ? "--urgent passes a pipeline stage's urgent rule, and this member's pipeline has no stage " + JSON.stringify(to) : !args.release ? "--urgent promotes one release: it needs --release <label|digest>" : !args.reason ? "--urgent needs --reason <text>, which the stage's ledger records" : undefined;
1019
+ if (missing) {
1020
+ console.error(formatError({ message: missing, hint: PROMOTE_USAGE }));
1021
+ return 1;
1022
+ }
1023
+ }
1024
+ let skipped = [];
1025
+ let upstreams;
1026
+ let from;
1027
+ if (pipeline) {
1028
+ const source = pipelinePromoteSource({ spec: pipeline, to, ...(args.migrateFrom ? { from: args.migrateFrom } : {}), ...(args.allowSkip ? { allowSkip: true } : {}), ...(args.urgent ? { urgent: true } : {}), now: new Date() });
1029
+ if (source && "exitCode" in source) {
1030
+ console.error(formatError({ message: `${source.message}${source.code ? ` [${source.code}]` : ""}`, ...(source.hint ? { hint: source.hint } : {}) }));
1031
+ return source.exitCode;
1032
+ }
1033
+ from = source.from;
1034
+ skipped = source.skipped;
1035
+ upstreams = source.upstreams;
1036
+ }
1037
+ else {
1038
+ // The member's `environments` array is its promotion order (#4030). It
1039
+ // defaults --from and refuses a skipped step; a member that declares none
1040
+ // has no order, so --from is required and nothing is refused.
1041
+ const resolved = resolvePromotionSource({
1042
+ order: promotionOrder(project.config.environments),
1043
+ to,
1044
+ ...(args.migrateFrom ? { from: args.migrateFrom } : {}),
1045
+ ...(args.allowSkip ? { allowSkip: true } : {}),
1046
+ });
1047
+ if ("error" in resolved) {
1048
+ console.error(formatError({ message: `${resolved.error.message} [${resolved.error.code}]`, hint: resolved.error.fix }));
1049
+ return 1;
1050
+ }
1051
+ from = resolved.from;
970
1052
  }
971
- const from = resolved.from;
972
1053
  if (!from) {
973
1054
  console.error(formatError({ message: "--from <env> is required: this member declares no environments, so there is no promotion order to default it from", hint: PROMOTE_USAGE }));
974
1055
  return 1;
975
1056
  }
1057
+ // #5427: a member with no components promotes into a stage that applies through a step by running the stage's op waves.
1058
+ const waves = pipeline !== undefined && project.targets.length === 0 && !args.component && stageRunsWaves(pipeline, to);
1059
+ if (waves) {
1060
+ const refusal = !args.release
1061
+ ? "needs --release <label|digest>: the stage's op waves apply one release, and the stage's gate binds that release"
1062
+ : args.digest || args.digests?.length
1063
+ ? "takes no --digest: the stage's op waves plan what the release applies, and their gates bind those plans"
1064
+ : args.planOnly || args.waveGate !== undefined || args.resume !== undefined
1065
+ ? `takes no ${args.planOnly ? "--plan-only" : args.waveGate !== undefined ? "--wave-gate" : "--resume"}: each of the stage's op waves plans and decides its own gate, and the same promote carries on from the wave that waits`
1066
+ : undefined;
1067
+ if (refusal) {
1068
+ console.error(formatError({ message: `stage "${to}" applies through its op waves and this member declares no components, so the promote ${refusal}`, hint: PROMOTE_USAGE }));
1069
+ return 1;
1070
+ }
1071
+ }
976
1072
  // Without --component, each --digest is <component>=<digest> (#2602): a
977
1073
  // generated promote job pins every component to the release its own
978
1074
  // pipeline run recorded, rather than whatever is latest in --from.
@@ -994,31 +1090,592 @@ export async function runComponentsPromote(ctx) {
994
1090
  // #4026: --release names the release this promote deploys, by label or digest.
995
1091
  let under;
996
1092
  if (args.release) {
997
- const found = await resolveUnderRelease(args.release, to, "promote", () => "Promote a release cut from a green commit: `chant ci last-green` names the newest, and `chant release list` marks the revoked releases. Fetch the tags first: git fetch origin --tags");
1093
+ const found = await resolveUnderRelease(args.release, to, "promote", () => "Promote a release cut from a green commit: `chant ci last-green` names the newest, and `chant release list` marks the revoked releases. Fetch the tags first: git fetch origin --tags", waves ? { waves } : {});
998
1094
  if (typeof found === "number")
999
1095
  return found;
1000
1096
  under = found;
1001
1097
  }
1002
- const plan = planPromotion({
1003
- from,
1004
- to,
1005
- sourceRecords: await readLedger(from),
1006
- declared: project.targets.map((c) => c.name),
1007
- ...(args.component ? { component: args.component } : {}),
1008
- ...(args.component && args.digest ? { digest: args.digest } : {}),
1009
- ...(pins ? { pins } : {}),
1010
- });
1098
+ // #5356: the artifacts of earlier stages the stage reads, of this same
1099
+ // release, refused before any gate or deploy when one was not published.
1100
+ let readVariables = {};
1101
+ if (pipeline) {
1102
+ const { gitStageArtifactPort, resolveStageReads } = await import("../../pipeline/artifacts.js");
1103
+ const reads = await resolveStageReads(pipeline, to, under?.release.releaseDigest, gitStageArtifactPort());
1104
+ if (reads.status === "refused") {
1105
+ console.error(formatError({ message: `nothing was promoted into "${to}": ${reads.problems.join("; ")}` }));
1106
+ return 1;
1107
+ }
1108
+ readVariables = reads.variables;
1109
+ for (const r of reads.reads)
1110
+ console.error(formatInfo(`${r.variable}: artifact "${r.artifact}" of stage "${r.stage}"${r.kind === "secret" ? ", a secret's reference" : ""}`));
1111
+ }
1112
+ // #5427: under op waves, what the stage promoted from applied of the release, which its soak's clock reads.
1113
+ const wavesRelease = waves && under ? { releaseDigest: under.release.releaseDigest, commit: under.release.commit } : undefined;
1114
+ const plan = wavesRelease
1115
+ ? stageWavesPlan(from, to, under, stageReleaseItems(await readLedger(from), from, wavesRelease))
1116
+ : planPromotion({
1117
+ from,
1118
+ to,
1119
+ sourceRecords: await readLedger(from),
1120
+ declared: project.targets.map((c) => c.name),
1121
+ ...(args.component ? { component: args.component } : {}),
1122
+ ...(args.component && args.digest ? { digest: args.digest } : {}),
1123
+ ...(pins ? { pins } : {}),
1124
+ });
1011
1125
  if ("error" in plan) {
1012
1126
  console.error(formatError({ message: plan.error, hint: PROMOTE_USAGE }));
1013
1127
  return 1;
1014
1128
  }
1015
- return deployPlan(ctx, "promote", plan, project, who.actor, promotionRecord, under);
1129
+ // #5355: a paused stage refuses with exit 3 and records the release that waited; a release a resume superseded is refused.
1130
+ const stageDigest = under?.release.releaseDigest ?? promotedDigest(plan.items);
1131
+ const stagePort = gitStageLedgerPort();
1132
+ if (pipeline) {
1133
+ const stopped = await pausedOrSuperseded({ spec: pipeline, to, port: stagePort, digest: stageDigest, label: under?.label ?? null, by: who.actor ?? "unknown", record: !args.dryRun });
1134
+ if (stopped) {
1135
+ console.error(formatError({ message: `${stopped.message}${stopped.code ? ` [${stopped.code}]` : ""}`, ...(stopped.hint ? { hint: stopped.hint } : {}) }));
1136
+ return stopped.exitCode;
1137
+ }
1138
+ }
1139
+ // #5355: the urgent path takes only a release that succeeded in every stage upstream of the target.
1140
+ if (pipeline && args.urgent && under) {
1141
+ const { readDeployOutcomes } = await import("../../lifecycle/deploy-outcome.js");
1142
+ const components = plan.items.map((i) => i.component);
1143
+ const missing = await pipelineUrgentUpstream({
1144
+ spec: pipeline,
1145
+ to,
1146
+ missingIn: async (stage) => releaseMissingIn({ records: (await readLedger(stage)).filter((r) => r.env === stage), outcomes: await readDeployOutcomes(stage).catch(() => []), releaseDigest: under.release.releaseDigest, commit: under.release.commit, components }),
1147
+ });
1148
+ if (missing.length > 0) {
1149
+ const stop = urgentUpstreamStop(under.label ?? under.release.releaseDigest, missing);
1150
+ console.error(formatError({ message: `${stop.message} [${stop.code}]`, ...(stop.hint ? { hint: stop.hint } : {}) }));
1151
+ return stop.exitCode;
1152
+ }
1153
+ }
1154
+ // #5324: the skipped stages' gates, then the stage's own, bound to the release (or the digests promoted).
1155
+ // #5353: a stage that follows several opens once the release applied in each, and a queued stage takes one release at a time.
1156
+ let entered;
1157
+ const { gitStageLogPort } = await import("../../lifecycle/stage-log.js");
1158
+ const log = gitStageLogPort();
1159
+ if (pipeline && !args.dryRun) {
1160
+ const digest = under?.release.releaseDigest ?? promotedDigest(plan.items);
1161
+ const port = gitGateLedgerPort();
1162
+ const head = await getHeadCommit().then((sha) => (sha ? { gitSha: sha } : {}), () => ({}));
1163
+ const proof = await promoteProof(project.projectPath);
1164
+ // The order at promote: a pause (above), then a rejection, then the soak of each stage promoted from and of each canary upstream, then the gates and risk.
1165
+ // #5354: a rejected release stops here, before a soak records anything for it.
1166
+ const rejection = await pipelinePromoteRejected({ spec: pipeline, to, skipped, digest, ...(under ? { releaseDigest: under.release.releaseDigest } : {}), port, ...(proof ? { proof } : {}), ...(args.urgent ? { urgent: true } : {}) });
1167
+ if (rejection) {
1168
+ for (const line of rejection.lines ?? [])
1169
+ console.error(formatInfo(line));
1170
+ console.error(formatError({ message: `${rejection.message} [${rejection.code}]`, ...(rejection.hint ? { hint: rejection.hint } : {}) }));
1171
+ return rejection.exitCode;
1172
+ }
1173
+ // #5326: the soak of each stage promoted from holds the promotion next; it adds a wait and never stands in for a gate.
1174
+ // An urgent promote waits on it too, unless a person ends the soak through its gate.
1175
+ // #5327: then the soak of each canary stage upstream, through its own gate, so a later stage or a skip waits for the canary.
1176
+ const soak = await pipelinePromoteSoaks({
1177
+ spec: pipeline,
1178
+ from,
1179
+ to,
1180
+ ...(upstreams ? { upstreams } : {}),
1181
+ items: async (source) => source === from ? plan.items : wavesRelease ? stageReleaseItems(await readLedger(source), source, wavesRelease) : soakItemsOf(await readLedger(source), plan.items, under?.release.releaseDigest),
1182
+ digest,
1183
+ ...(under ? { releaseDigest: under.release.releaseDigest } : {}),
1184
+ port,
1185
+ read: (source) => soakCheckReader(jobSoakSources({ op: stageWavesName(pipeline, source), cwd: project.projectPath })),
1186
+ now: new Date(),
1187
+ ...head,
1188
+ ...(pipeline.defaults?.notify ? { notify: { config: pipeline.defaults.notify, source: activeProductWords().notify.source, project: pipeline.name } } : {}),
1189
+ });
1190
+ for (const line of soak.notes)
1191
+ console.error(formatInfo(line));
1192
+ if (!soak.passed) {
1193
+ console.error(formatError({ message: `${soak.message} [${soak.code}]`, hint: soak.hint }));
1194
+ // #5328: a failed check of a soak requests the rollback of the stage whose soak it is (a canary upstream, or the stage promoted from),
1195
+ // when that stage's onVerifyFail is rollback. A check that could not be read holds the soak, and is no failure to roll back for.
1196
+ const failedSoak = soakFailureOf(soak);
1197
+ if (failedSoak) {
1198
+ const current = latestPerComponent((await readLedger(failedSoak.stage)).filter((r) => r.env === failedSoak.stage && failedSoak.members.includes(r.component)));
1199
+ await requestRollbackAfterFailure({
1200
+ pipeline,
1201
+ stage: failedSoak.stage,
1202
+ failure: "soak",
1203
+ failed: { digest, label: under?.label ?? null },
1204
+ members: failedSoak.members.map((member) => ({ member, state: "applied" })),
1205
+ detail: soak.lines,
1206
+ exclude: new Set([...(under ? [under.release.releaseDigest] : []), ...[...current.values()].map((r) => r.releaseDigest).filter((d) => d !== undefined)]),
1207
+ actor: who.actor ?? "unknown",
1208
+ });
1209
+ }
1210
+ return soak.exitCode;
1211
+ }
1212
+ for (const line of soak.lines)
1213
+ console.error(formatInfo(line));
1214
+ // #5358: each agent step's answer for the release, and the gate's policy over them, before the gate.
1215
+ const { pipelinePromoteAgentSteps } = await import("../../pipeline/promote.js");
1216
+ const { gitStageAgentAnswerPort } = await import("../../pipeline/agent-steps.js");
1217
+ const { stageAgentPolicy } = await import("./pipeline-agent.js");
1218
+ const agent = await pipelinePromoteAgentSteps({
1219
+ spec: pipeline,
1220
+ to,
1221
+ ...(under ? { release: { digest: under.release.releaseDigest, label: under.label } } : {}),
1222
+ port: gitStageAgentAnswerPort(),
1223
+ policy: (answers) => stageAgentPolicy(project.projectPath, pipeline, to, answers),
1224
+ });
1225
+ if (!agent.passed) {
1226
+ console.error(formatError({ message: `${agent.message}${agent.code ? ` [${agent.code}]` : ""}`, ...(agent.hint ? { hint: agent.hint } : {}) }));
1227
+ return agent.exitCode;
1228
+ }
1229
+ for (const line of agent.lines)
1230
+ console.error(formatInfo(line));
1231
+ const release = under ? await entryRelease(under) : undefined;
1232
+ const first = pipeline.stages[0].name;
1233
+ const firstStageCommits = upstreams?.includes(first) ? new Set((await readLedger(first)).filter((r) => r.env === first).map((r) => r.gitSha)) : undefined;
1234
+ const gates = await pipelineStageEntry({
1235
+ spec: pipeline,
1236
+ to,
1237
+ skipped,
1238
+ ...(upstreams ? { upstreams } : {}),
1239
+ ...(args.allowSkip ? { allowSkip: true } : {}),
1240
+ digest,
1241
+ ...(release ? { release } : {}),
1242
+ ...(firstStageCommits ? { firstStageCommits } : {}),
1243
+ port,
1244
+ log,
1245
+ ...(args.urgent ? { urgent: true } : {}),
1246
+ ...(who.actor ? { actor: who.actor } : {}),
1247
+ ...head,
1248
+ now: new Date(),
1249
+ // #5354: the signers and roles at the commit the pipeline is read at prove who approved or rejected.
1250
+ ...(proof ? { proof } : {}),
1251
+ // #5358: the agent steps' levels are reasons of the risk the stage's gate reads.
1252
+ ...(agent.risk.length > 0 ? { agentRisk: agent.risk } : {}),
1253
+ });
1254
+ if (!gates.passed) {
1255
+ for (const line of gates.lines ?? [])
1256
+ console.error(formatInfo(line));
1257
+ const hint = gates.hint ? (gates.code === "pipeline-gate-waiting" ? `Approve it with: ${gates.hint}` : gates.hint) : undefined;
1258
+ console.error(formatError({ message: `${gates.message}${gates.code ? ` [${gates.code}]` : ""}`, ...(hint ? { hint } : {}) }));
1259
+ return gates.exitCode;
1260
+ }
1261
+ for (const line of gates.lines)
1262
+ console.error(formatInfo(line));
1263
+ entered = gates.entered;
1264
+ // #5355: an urgent entry is marked on the stage's ledger and told to the pipeline's notify.
1265
+ if (gates.urgent && under)
1266
+ await recordUrgent({ spec: pipeline, to, port: stagePort, by: who.actor ?? "unknown", reason: args.reason, release: { digest: under.release.releaseDigest, label: under.label }, approval: gates.urgent.approval, role: gates.urgent.role });
1267
+ }
1268
+ const { withStageReadVariables } = await import("../../pipeline/artifacts.js");
1269
+ let ran;
1270
+ // #5427: after the stage's gate passed, its op waves run in place of the component driver.
1271
+ const code = await withStageReadVariables(readVariables, () => waves && pipeline && under ? promoteByStageWaves(ctx, project.projectPath, pipeline, to, under) : deployPlan(ctx, "promote", plan, project, who.actor, promotionRecord, under, (run) => (ran = run)));
1272
+ // #5353: a deploy still waiting at a component's gate stays in the stage; any other end is written.
1273
+ if (entered && code !== GATED_EXIT_CODE) {
1274
+ try {
1275
+ await pipelineStageFinished(log, entered, code === 0 ? "applied" : "failed", new Date());
1276
+ }
1277
+ catch (err) {
1278
+ console.error(formatError({ message: `the deploy ended, but the stage log was not written: ${err instanceof Error ? err.message : String(err)}`, hint: "Run the same promote again: the release in the stage carries on and the line is written then." }));
1279
+ return code === 0 ? 1 : code;
1280
+ }
1281
+ }
1282
+ // #5328: a failed verify step in a stage whose onVerifyFail is rollback requests the rollback to the stage's previous release, and exits 3.
1283
+ // A failed verify is what #5339's agent trigger counts (`failedVerify`); a failed apply holds as before.
1284
+ const failedRun = ran;
1285
+ if (pipeline && !args.dryRun && failedRun?.status === "fail" && failedVerify(failedRun.results.flatMap((r) => r.records))) {
1286
+ const requested = await requestRollbackAfterFailure({
1287
+ pipeline,
1288
+ stage: to,
1289
+ failure: "verify",
1290
+ failed: { digest: stageDigest, label: under?.label ?? null },
1291
+ members: memberStatesOf(plan.items.map((i) => i.component), failedRun.results),
1292
+ detail: failureDetail(failedRun.results),
1293
+ exclude: new Set(under ? [under.release.releaseDigest] : []),
1294
+ actor: who.actor ?? "unknown",
1295
+ });
1296
+ if (requested !== undefined)
1297
+ return requested;
1298
+ }
1299
+ // #5356: the stage publishes its artifacts once the deploy applied, after the stage log says so.
1300
+ if (code !== 0 || !pipeline || args.dryRun || args.planOnly)
1301
+ return code;
1302
+ return publishAfterPromote(project.projectPath, pipeline, to, under);
1303
+ }
1304
+ /**
1305
+ * What an upstream stage other than `--from` applied of the promoted
1306
+ * components (#5326), for its soak's clock: each component's newest record
1307
+ * there, of the release when one is promoted, else of the digest promoted
1308
+ * (#5327). A component with none is left out; with none at all the soak
1309
+ * cannot count its clock and holds.
1310
+ */
1311
+ function soakItemsOf(records, items, releaseDigest) {
1312
+ const out = [];
1313
+ for (const { component, digest } of items) {
1314
+ const own = records.filter((r) => r.component === component && (releaseDigest === undefined ? r.digest === digest : r.releaseDigest === releaseDigest));
1315
+ const newest = own.sort((a, b) => Date.parse(a.timestamp) - Date.parse(b.timestamp)).at(-1);
1316
+ if (newest)
1317
+ out.push({ component, source: { timestamp: newest.timestamp } });
1318
+ }
1319
+ return out;
1320
+ }
1321
+ /** The release a promote deploys, as the stage log names it (#5353): its label, commit and when it was first cut, and the change risk its cut carries (#5387). */
1322
+ async function entryRelease(under) {
1323
+ const { readCuts } = await import("../../lifecycle/release-store.js");
1324
+ const cuts = await readCuts().then((r) => r.cuts, () => []);
1325
+ const cut = cuts.find((c) => c.releaseDigest === under.release.releaseDigest);
1326
+ // #5387: the change risk a cut of the release bound, which each stage gate with holds.risk reads.
1327
+ const risk = cuts.find((c) => c.releaseDigest === under.release.releaseDigest && c.risk)?.risk;
1328
+ return {
1329
+ releaseDigest: under.release.releaseDigest,
1330
+ commit: under.release.commit,
1331
+ ...(under.label ? { label: under.label } : {}),
1332
+ ...(cut ? { cutAt: cut.timestamp } : {}),
1333
+ ...(risk ? { risk } : {}),
1334
+ };
1335
+ }
1336
+ /**
1337
+ * The plan of a promote by a stage's op waves (#5427): what `from` applied
1338
+ * of the release, each component's newest record, which the soak of `from`
1339
+ * reads. Refused when `from` applied none of it.
1340
+ */
1341
+ function stageWavesPlan(from, to, under, items) {
1342
+ if (items.length > 0)
1343
+ return { from, to, items, notPromoted: [] };
1344
+ const name = under.label ?? under.release.releaseDigest;
1345
+ return { error: `release ${name} has not applied in "${from}": its ledger has no record of the release or of the commit it was cut from (${under.release.commit.slice(0, 12)}), so nothing of it is promoted into "${to}". Promote it into ${from} first` };
1346
+ }
1347
+ /**
1348
+ * Run stage `to`'s op waves for release `under` (#5427), once the stage's
1349
+ * gate passed: `runStageWaves` with the product's in-process hooks and
1350
+ * capabilities, as `chant run wave` runs a wave job, the spec's notify told
1351
+ * after each wave. The waves plan and apply this checkout, which must hold
1352
+ * the commit the release was cut from. Returns the exit code of the first
1353
+ * wave that did not end with 0 (3 while one waits for an approval), else 0.
1354
+ * A dry run prints the waves and runs none.
1355
+ */
1356
+ async function promoteByStageWaves(ctx, projectPath, pipeline, to, under) {
1357
+ const { args } = ctx;
1358
+ const name = under.label ?? under.release.releaseDigest;
1359
+ const { runStageWaves, stageRunSpec } = await import("../../pipeline/stage-waves.js");
1360
+ const { pipelineStageSpecFile } = await import("../../pipeline/generate.js");
1361
+ const shape = stageRunSpec(pipeline, to);
1362
+ if (args.dryRun) {
1363
+ const out = { to, releaseDigest: under.release.releaseDigest, label: under.label, specFile: pipelineStageSpecFile(pipeline, to), waves: shape.waves.map((w, i) => ({ wave: i + 1, name: w.name, runs: (w.runs ?? []).map((r) => r.target), gate: w.gate ?? "always" })) };
1364
+ if (args.json)
1365
+ console.log(JSON.stringify(out, null, 2));
1366
+ else {
1367
+ console.error(formatBold(`promote release ${name} into ${to} through its op waves`));
1368
+ for (const w of out.waves)
1369
+ console.error(` wave ${w.wave} (${w.name}): ${w.runs.join(", ") || "runs found at plan"}, gate ${w.gate}`);
1370
+ }
1371
+ return 0;
1372
+ }
1373
+ const base = promoteBase(projectPath);
1374
+ if (!base) {
1375
+ console.error(formatError({ message: `the default branch's commit cannot be read, so the gates of stage "${to}"'s waves cannot be read and nothing was applied` }));
1376
+ return 1;
1377
+ }
1378
+ // The waves plan and apply this checkout: it must hold the release's commit, and a later commit is said.
1379
+ const head = await getHeadCommit().catch(() => undefined);
1380
+ const { execFileSync } = await import("node:child_process");
1381
+ let holds = false;
1382
+ try {
1383
+ execFileSync("git", ["merge-base", "--is-ancestor", under.release.commit, "HEAD"], { cwd: projectPath, stdio: "ignore" });
1384
+ holds = true;
1385
+ }
1386
+ catch {
1387
+ holds = false;
1388
+ }
1389
+ if (!holds) {
1390
+ console.error(formatError({
1391
+ message: `release ${name} was cut from ${under.release.commit.slice(0, 12)}, which this checkout does not hold, so stage "${to}"'s waves would not apply it; nothing was applied`,
1392
+ hint: "Run the promote in a checkout of the default branch with its full history (fetch-depth: 0 on GitHub and Forgejo, GIT_DEPTH: \"0\" on GitLab).",
1393
+ }));
1394
+ return 1;
1395
+ }
1396
+ if (head && head !== under.release.commit) {
1397
+ console.error(formatWarning({ message: `release ${name} was cut from ${under.release.commit.slice(0, 12)}, and stage "${to}"'s waves plan this checkout at ${head.slice(0, 12)}; each wave's gate binds the plan made here` }));
1398
+ }
1399
+ const { activeProductWaveHook } = await import("../../op/op-waves-after-plan.js");
1400
+ const { notifyOpWave } = await import("../../op/op-waves-notify.js");
1401
+ const product = activeProductWaveHook();
1402
+ const ran = await runStageWaves({
1403
+ spec: pipeline,
1404
+ stage: to,
1405
+ base,
1406
+ cwd: projectPath,
1407
+ release: { releaseDigest: under.release.releaseDigest },
1408
+ options: {
1409
+ ...(product?.afterPlan ? { afterPlan: product.afterPlan } : {}),
1410
+ ...(product?.capabilities ? { capabilities: product.capabilities } : {}),
1411
+ ...(product?.hookExec ? { hookExec: product.hookExec } : {}),
1412
+ ...(product?.runHooks ? { runHooks: product.runHooks } : {}),
1413
+ ...(product?.hooks ? { inProcessHooks: product.hooks } : {}),
1414
+ },
1415
+ // Delivery never changes the exit code.
1416
+ afterWave: async (wave, spec) => {
1417
+ try {
1418
+ await notifyOpWave(spec, wave.wave, { result: wave.result });
1419
+ }
1420
+ catch (err) {
1421
+ console.error(formatWarning({ message: `wave ${wave.wave}'s notify was not sent: ${err instanceof Error ? err.message : String(err)}` }));
1422
+ }
1423
+ },
1424
+ });
1425
+ if (args.json)
1426
+ console.log(JSON.stringify({ to, releaseDigest: under.release.releaseDigest, label: under.label, specFile: ran.specFile, exitCode: ran.exitCode, waves: ran.waves.map((w) => ({ wave: w.wave, name: w.name, ...w.result })) }, null, 2));
1427
+ for (const w of ran.waves) {
1428
+ const r = w.result;
1429
+ console.error(formatInfo(`wave ${w.wave} (${w.name}) of ${ran.spec.name}: ${r.exitCode === 0 ? `applied ${r.applied.join(", ") || "nothing"}` : `exit ${r.exitCode}${r.failed.length > 0 ? `, failed ${r.failed.join(", ")}` : ""}`}`));
1430
+ }
1431
+ const last = ran.waves.at(-1)?.result;
1432
+ if (ran.exitCode === GATED_EXIT_CODE) {
1433
+ const approve = last?.decision?.approve;
1434
+ console.error(formatWarning({ message: `release ${name} entered stage "${to}", and wave ${ran.waves.at(-1)?.wave} of ${ran.spec.name} waits for an approval of its plan${last?.decision?.digest ? ` ${last.decision.digest}` : ""}` }));
1435
+ if (approve)
1436
+ console.error(formatInfo(`approve : ${approve}`));
1437
+ console.error(formatInfo("then run the same promote again"));
1438
+ return ran.exitCode;
1439
+ }
1440
+ if (ran.exitCode !== 0) {
1441
+ console.error(formatError({ message: `promote of release ${name} into "${to}" stopped at wave ${ran.waves.at(-1)?.wave} of ${ran.spec.name} (exit ${ran.exitCode})` }));
1442
+ return ran.exitCode;
1443
+ }
1444
+ console.error(formatSuccess(`Promoted release ${formatBold(name)} into ${to} through ${ran.waves.length} wave(s) of ${ran.spec.name}`));
1445
+ return 0;
1446
+ }
1447
+ /**
1448
+ * #5356: once a promote under a release deployed, the stage publishes the
1449
+ * artifacts it declares for that release. A promote of digests alone names
1450
+ * no release, so it publishes none and says so. A refused publish fails the
1451
+ * promote after the deploy (exit 1), naming the artifacts and never a value.
1452
+ */
1453
+ async function publishAfterPromote(projectPath, pipeline, to, under) {
1454
+ const declared = pipeline.stages.find((s) => s.name === to)?.publish;
1455
+ if (!declared || Object.keys(declared).length === 0)
1456
+ return 0;
1457
+ if (!under) {
1458
+ console.error(formatWarning({ message: `stage "${to}" publishes artifacts for the release it takes, and this promote named none, so none were published` }));
1459
+ return 0;
1460
+ }
1461
+ const { publishStageFrom, publishRefusedMessage } = await import("./pipeline-artifacts.js");
1462
+ const result = await publishStageFrom({ cwd: projectPath, spec: pipeline, stage: to, release: { digest: under.release.releaseDigest, label: under.label, gitSha: under.release.commit } });
1463
+ if (result.status === "refused") {
1464
+ console.error(formatError({ message: `${publishRefusedMessage(result)}; the release was deployed` }));
1465
+ return 1;
1466
+ }
1467
+ if (result.status === "published")
1468
+ console.error(formatInfo(`stage "${to}" published ${Object.keys(result.record.artifacts).sort().join(", ")} for release ${under.label ?? under.release.releaseDigest}`));
1469
+ return 0;
1470
+ }
1471
+ /**
1472
+ * #5328: after a failed verify or soak in `stage`, the rollback request its
1473
+ * `onVerifyFail: "rollback"` asks for (`../../pipeline/verify-rollback.ts`).
1474
+ * Returns 3 when a request was written or one stands already, and undefined
1475
+ * when the stage holds (its `onVerifyFail` is `hold`, or no rollback could
1476
+ * be requested, which it says), so the caller keeps its own exit code.
1477
+ */
1478
+ async function requestRollbackAfterFailure(input) {
1479
+ const { pipeline, stage } = input;
1480
+ if (stageOnVerifyFail(pipeline.stages.find((s) => s.name === stage)) !== "rollback")
1481
+ return undefined;
1482
+ const { readRelease, readCuts, labelsByDigest } = await import("../../lifecycle/release-store.js");
1483
+ const { readRevokedCommits, revocationOf, describeRevocation } = await import("../../lifecycle/release-revocation.js");
1484
+ const labels = await readCuts().then((c) => labelsByDigest(c.cuts), () => new Map());
1485
+ let revoked;
1486
+ try {
1487
+ revoked = await readRevokedCommits(process.cwd());
1488
+ }
1489
+ catch (err) {
1490
+ revoked = `the ci tags can't be judged: ${err instanceof Error ? err.message : String(err)}`;
1491
+ }
1492
+ const head = await getHeadCommit().catch(() => undefined);
1493
+ const outcome = await requestStageRollback({
1494
+ spec: pipeline,
1495
+ stage,
1496
+ failure: input.failure,
1497
+ failed: input.failed,
1498
+ members: input.members,
1499
+ detail: input.detail,
1500
+ records: (await readLedger(stage)).filter((r) => r.env === stage),
1501
+ exclude: input.exclude,
1502
+ check: async (digest) => {
1503
+ const release = await readRelease(digest).catch(() => null);
1504
+ if (!release)
1505
+ return { kept: false, revoked: null };
1506
+ // A release whose revocation can't be read is not restored on trust.
1507
+ if (typeof revoked === "string")
1508
+ return { kept: true, revoked };
1509
+ const revocation = revocationOf(release, revoked);
1510
+ return { kept: true, revoked: revocation ? describeRevocation(revocation) : null };
1511
+ },
1512
+ label: (digest) => labels.get(digest) ?? null,
1513
+ stages: gitStageLedgerPort(),
1514
+ gates: gitGateLedgerPort(),
1515
+ by: input.actor,
1516
+ now: new Date(),
1517
+ ...(head ? { gitSha: head } : {}),
1518
+ ...(pipeline.defaults?.notify ? { notify: { config: pipeline.defaults.notify, source: activeProductWords().notify.source } } : {}),
1519
+ });
1520
+ if (outcome.status === "hold")
1521
+ return undefined;
1522
+ for (const line of outcome.lines)
1523
+ console.error(formatInfo(line));
1524
+ if (outcome.status === "held") {
1525
+ console.error(formatWarning({ message: `stage ${stage} holds: ${outcome.reason}` }));
1526
+ return undefined;
1527
+ }
1528
+ console.error(formatError({ message: `stage ${stage} requested its rollback, which waits for an approval [pipeline-rollback-requested]`, hint: outcome.hint }));
1529
+ return outcome.exitCode;
1530
+ }
1531
+ /**
1532
+ * The signers, passkeys and role grants at the commit a promote reads its
1533
+ * pipeline at (#5354), which prove who approved or rejected at a stage's
1534
+ * gate. A trust config that can't be read proves nobody.
1535
+ */
1536
+ async function promoteProof(projectPath) {
1537
+ try {
1538
+ const { scopeSource } = await import("../../workspace/write-scope.js");
1539
+ const { policy } = scopeSource(projectPath, promoteBase(projectPath));
1540
+ return { signers: policy, roles: policy.roles };
1541
+ }
1542
+ catch {
1543
+ return undefined;
1544
+ }
1545
+ }
1546
+ /**
1547
+ * The stop a stage's ledger puts on a promote (#5355): a pause, which exits 3
1548
+ * and records the release as waiting (unless `record` is false, as on a dry
1549
+ * run), or a resume that superseded this release. Undefined when it goes on.
1550
+ */
1551
+ async function pausedOrSuperseded(input) {
1552
+ const lines = await input.port.read(input.spec.name, input.to);
1553
+ const pause = stagePaused(lines);
1554
+ if (pause) {
1555
+ if (input.record)
1556
+ await input.port.append(waitingLine({ pipeline: input.spec.name, stage: input.to, by: input.by, release: { digest: input.digest, label: input.label }, now: new Date() }));
1557
+ return {
1558
+ exitCode: 3,
1559
+ code: "pipeline-stage-paused",
1560
+ message: `${stagePausedLine(pause)}${input.record ? `; release ${input.label ?? input.digest} waits` : ""}`,
1561
+ hint: `chant stage resume ${input.to} lets the newest waiting release in.`,
1562
+ };
1563
+ }
1564
+ const resume = supersededBy(lines, input.digest);
1565
+ if (resume) {
1566
+ const admits = resume.admits ? resume.admits.label ?? resume.admits.digest : "a newer release";
1567
+ return {
1568
+ exitCode: 1,
1569
+ code: "pipeline-release-superseded",
1570
+ message: `release ${input.label ?? input.digest} waited while stage "${input.to}" was paused, and the resume at ${resume.timestamp} let ${admits} in instead`,
1571
+ hint: `Promote ${admits}: chant components promote --to ${input.to} --release ${admits}`,
1572
+ };
1573
+ }
1574
+ return undefined;
1575
+ }
1576
+ /** Mark an urgent promote on the stage's ledger and tell the pipeline's notify (#5355). */
1577
+ async function recordUrgent(input) {
1578
+ const now = new Date();
1579
+ const pushed = await input.port.append({
1580
+ version: 1,
1581
+ kind: "urgent",
1582
+ pipeline: input.spec.name,
1583
+ stage: input.to,
1584
+ by: input.by,
1585
+ reason: input.reason,
1586
+ timestamp: now.toISOString(),
1587
+ release: input.release,
1588
+ approval: { by: input.approval.resolvedBy, at: input.approval.timestamp, role: input.role, ...(input.approval.note ? { note: input.approval.note } : {}) },
1589
+ });
1590
+ if (!pushed.pushed)
1591
+ console.error(formatWarning({ message: `the urgent promote is recorded locally and did not reach the remote${pushed.pushWarning ? `: ${pushed.pushWarning}` : ""}` }));
1592
+ const { makeNotifyEvent, sendNotify } = await import("../../notify.js");
1593
+ const name = input.release.label ?? input.release.digest;
1594
+ await sendNotify(input.spec.defaults?.notify, makeNotifyEvent({
1595
+ source: "chant",
1596
+ event: "urgent",
1597
+ project: input.spec.name,
1598
+ environment: input.to,
1599
+ summary: `release ${name} promoted into ${input.to} on its urgent rule, approved by ${input.approval.resolvedBy} (${input.role}), promoted by ${input.by}: ${input.reason}`,
1600
+ digest: input.release.digest,
1601
+ reason: input.reason,
1602
+ detail: { urgent: true, stage: input.to, release: input.release, approvedBy: input.approval.resolvedBy, role: input.role, promotedBy: input.by },
1603
+ }, { now }));
1604
+ }
1605
+ /**
1606
+ * `components promote --to <stage> --pending` (#5326): the promotion into
1607
+ * `stage` that a soak holds, run again. The stage before it in the pipeline
1608
+ * read at base, and each canary stage upstream of it (#5327), names a
1609
+ * soak's gate; the newest standing pending fact of those for `stage` names
1610
+ * the release. Nothing pending, or the stage already running
1611
+ * that release, exits 0 with a line; otherwise the promote runs as `--release
1612
+ * <digest>` would, soak and gates included.
1613
+ */
1614
+ async function runPendingPromotion(ctx, to) {
1615
+ const { args } = ctx;
1616
+ if (args.release || args.component || args.digest || args.digests?.length || args.migrateFrom) {
1617
+ console.error(formatError({ message: "--pending reads the release from the soak's pending fact, so it takes only --to", hint: PROMOTE_USAGE }));
1618
+ return 1;
1619
+ }
1620
+ const projectPath = resolve(".");
1621
+ const pipeline = readPromotePipeline(projectPath, to);
1622
+ if (typeof pipeline === "number")
1623
+ return pipeline;
1624
+ const at = pipeline ? pipeline.stages.findIndex((s) => s.name === to) : -1;
1625
+ if (!pipeline || at <= 0) {
1626
+ console.error(formatInfo(`no promotion into ${to} is pending: ${pipeline ? `${to} is the pipeline's first stage` : "the member has no pipeline with that stage"}`));
1627
+ return 0;
1628
+ }
1629
+ const from = pipeline.stages[at - 1].name;
1630
+ // #5327: a canary stage upstream holds the promotion through its own soak gate too.
1631
+ const holders = [from, ...canaryStagesBefore(pipeline, to).map((s) => s.name).filter((n) => n !== from)];
1632
+ const gates = new Map(holders.map((n) => [stageSoakGate(n), n]));
1633
+ await fetchLifecycle().catch(() => false);
1634
+ const now = new Date().toISOString();
1635
+ const { pending } = await gitGateLedgerPort().read(pipeline.name);
1636
+ const standing = pending
1637
+ .filter((p) => gates.has(p.gate) && p.soak?.to === to && p.releaseDigest && !isPendingGateExpired(p, now))
1638
+ .sort((a, b) => Date.parse(a.timestamp) - Date.parse(b.timestamp))
1639
+ .at(-1);
1640
+ if (!standing?.releaseDigest) {
1641
+ console.error(formatInfo(`no promotion into ${to} is pending`));
1642
+ return 0;
1643
+ }
1644
+ if ((await readLedger(to)).some((r) => r.releaseDigest === standing.releaseDigest)) {
1645
+ console.error(formatInfo(`${to} already runs the release ${standing.releaseDigest}, so nothing is pending`));
1646
+ return 0;
1647
+ }
1648
+ console.error(formatInfo(`promoting the release ${standing.releaseDigest} into ${to}, held since ${standing.timestamp} by the soak of ${gates.get(standing.gate) ?? from}`));
1649
+ return runComponentsPromote({ ...ctx, args: { ...args, pendingPromotion: false, release: standing.releaseDigest } });
1650
+ }
1651
+ /**
1652
+ * The member's folded pipeline as the default branch has it (#5324), when it
1653
+ * has a stage `to`; undefined otherwise, and the member's `environments`
1654
+ * order applies as before. A pipeline at base that does not fold refuses
1655
+ * the promote (exit 1): its gates cannot be read, and none is skipped.
1656
+ */
1657
+ function readPromotePipeline(projectPath, to) {
1658
+ const base = promoteBase(projectPath);
1659
+ if (!base)
1660
+ return undefined;
1661
+ const read = readPipelineAt(base, projectPath);
1662
+ if (read.status === "refused") {
1663
+ console.error(formatError({ message: `the pipeline at ${base.slice(0, 12)} does not fold, so its gates cannot be read and nothing is promoted: ${read.line}` }));
1664
+ return 1;
1665
+ }
1666
+ return read.status === "folded" && read.spec.stages.some((s) => s.name === to) ? read.spec : undefined;
1016
1667
  }
1017
1668
  export async function runComponentsRollback(ctx) {
1018
1669
  const { args } = ctx;
1019
1670
  const env = args.extraPositional;
1671
+ if (env && args.rollbackRequested) {
1672
+ const who = actorOrRefuse(ctx);
1673
+ if (typeof who === "number")
1674
+ return who;
1675
+ return runRequestedRollback(ctx, env, who.actor);
1676
+ }
1020
1677
  if (!env || (!args.component && !args.release)) {
1021
- console.error(formatError({ message: "an environment and --component <name> or --release <label|digest> are required", hint: ROLLBACK_USAGE }));
1678
+ console.error(formatError({ message: "an environment and --component <name>, --release <label|digest> or --requested are required", hint: ROLLBACK_USAGE }));
1022
1679
  return 1;
1023
1680
  }
1024
1681
  if (args.component && args.release) {
@@ -1061,9 +1718,96 @@ export async function runComponentsRollback(ctx) {
1061
1718
  const under = await resolveUnderRelease(item.source.releaseDigest, env, "rollback", () => "Roll back to a release cut from a green commit; `chant release list` marks the revoked releases.");
1062
1719
  if (typeof under === "number")
1063
1720
  return under;
1064
- return deployPlan(ctx, "rollback", plan, project, who.actor, rollbackRecord, under);
1721
+ return afterRollback(ctx, project.projectPath, env, who.actor, { digest: under.release.releaseDigest, label: under.label }, await deployPlan(ctx, "rollback", plan, project, who.actor, rollbackRecord, under));
1722
+ }
1723
+ const back = item?.source.releaseDigest;
1724
+ return afterRollback(ctx, project.projectPath, env, who.actor, back ? { digest: back, label: null } : undefined, await deployPlan(ctx, "rollback", plan, project, who.actor, rollbackRecord));
1725
+ }
1726
+ /**
1727
+ * A rollback that finished pauses its stage (#5355) when the member's
1728
+ * pipeline at base sets `pauseAfterRollback` on it, and says so, so the next
1729
+ * release waits for `chant stage resume`. A dry run, or a rollback that did
1730
+ * not finish, pauses nothing. Returns the rollback's exit code.
1731
+ */
1732
+ async function afterRollback(ctx, projectPath, env, actor, release, exitCode) {
1733
+ if (exitCode !== 0 || ctx.args.dryRun)
1734
+ return exitCode;
1735
+ const base = promoteBase(projectPath);
1736
+ const read = base ? readPipelineAt(base, projectPath) : undefined;
1737
+ if (read?.status !== "folded")
1738
+ return exitCode;
1739
+ const pipeline = read.spec;
1740
+ const stage = pipeline.stages.find((s) => s.name === env);
1741
+ if (!stage?.pauseAfterRollback)
1742
+ return exitCode;
1743
+ const port = gitStageLedgerPort();
1744
+ const line = pauseLine({ pipeline: pipeline.name, stage: env, by: actor ?? "unknown", lines: await port.read(pipeline.name, env), now: new Date(), cause: "rollback", ...(release ? { release } : {}) });
1745
+ if ("refused" in line) {
1746
+ console.error(formatInfo(`stage ${env} stays paused: ${line.refused}`));
1747
+ return exitCode;
1065
1748
  }
1066
- return deployPlan(ctx, "rollback", plan, project, who.actor, rollbackRecord);
1749
+ const pushed = await port.append(line);
1750
+ console.error(formatInfo(`paused stage ${env} after the rollback: a promote into it exits 3 until chant stage resume ${env}`));
1751
+ if (!pushed.pushed)
1752
+ console.error(formatWarning({ message: `the pause is recorded locally and did not reach the remote${pushed.pushWarning ? `: ${pushed.pushWarning}` : ""}` }));
1753
+ return exitCode;
1754
+ }
1755
+ /**
1756
+ * `chant components rollback <stage> --requested` (#5328): carry out the
1757
+ * rollback a stage requested when its verify or soak failed. The newest
1758
+ * request on the stage's ledger names the release and the members; its gate
1759
+ * (`<stage>-rollback` under the pipeline's op) must pass first, on a
1760
+ * person's approval given since the request, whatever the stage's gate
1761
+ * policy. Then the members roll back as `--release` rolls them back, the
1762
+ * approval is spent, and a `rolled-back` line links the rollback to its
1763
+ * request and its failure. A dry run reads no gate and applies nothing.
1764
+ */
1765
+ async function runRequestedRollback(ctx, env, actor) {
1766
+ const { args } = ctx;
1767
+ if (args.component || args.release || args.digest) {
1768
+ console.error(formatError({ message: "--requested reads the release and the members from the stage's request, so it takes only the stage", hint: ROLLBACK_USAGE }));
1769
+ return 1;
1770
+ }
1771
+ const projectPath = resolve(".");
1772
+ const pipeline = readPromotePipeline(projectPath, env);
1773
+ if (typeof pipeline === "number")
1774
+ return pipeline;
1775
+ if (!pipeline) {
1776
+ console.error(formatError({ message: `--requested carries out a rollback a pipeline stage requested, and this member's pipeline has no stage "${env}"`, hint: ROLLBACK_USAGE }));
1777
+ return 1;
1778
+ }
1779
+ await fetchLifecycle().catch(() => false);
1780
+ const stagePort = gitStageLedgerPort();
1781
+ const request = standingRollbackRequest(await stagePort.read(pipeline.name, env));
1782
+ if (!request?.release) {
1783
+ console.error(formatInfo(`no rollback of stage ${env} is requested`));
1784
+ return 0;
1785
+ }
1786
+ const to = request.release;
1787
+ const members = (request.members ?? []).filter((m) => m.rollback === "requested").map((m) => m.member);
1788
+ console.error(formatInfo(`stage ${env} requested its rollback to release ${to.label ?? to.digest} at ${request.timestamp}, for ${members.join(", ")}`));
1789
+ if (args.dryRun)
1790
+ return runReleaseRollback(ctx, env, to.digest, actor, new Set(members));
1791
+ const port = gitGateLedgerPort();
1792
+ const head = await getHeadCommit().catch(() => undefined);
1793
+ const proof = await promoteProof(projectPath);
1794
+ const gate = await requestedRollbackGate({ spec: pipeline, stage: env, request, port, ...(proof ? { proof } : {}), now: new Date(), ...(head ? { gitSha: head } : {}) });
1795
+ if (!gate.passed) {
1796
+ console.error(formatError({ message: `${gate.message} [${gate.code}]`, hint: gate.hint }));
1797
+ return gate.exitCode;
1798
+ }
1799
+ for (const line of gate.lines)
1800
+ console.error(formatInfo(line));
1801
+ const code = await runReleaseRollback(ctx, env, to.digest, actor, new Set(members));
1802
+ if (code !== 0)
1803
+ return code;
1804
+ const now = new Date();
1805
+ await port.appendApplied?.({ version: 1, kind: "applied", op: pipeline.name, gate: stageRollbackGate(env), planDigest: to.digest, approvedAt: gate.approval.timestamp, approvedBy: gate.approval.resolvedBy, timestamp: now.toISOString(), ...(head ? { commit: head } : {}) });
1806
+ const pushed = await stagePort.append(rolledBackLine({ request, by: actor ?? "unknown", approval: gate.approval, now }));
1807
+ console.error(formatSuccess(`stage ${env} rolled back to release ${to.label ?? to.digest}, as requested at ${request.timestamp} and approved by ${gate.approval.resolvedBy}`));
1808
+ if (!pushed.pushed)
1809
+ console.error(formatWarning({ message: `the rollback is recorded locally and did not reach the remote${pushed.pushWarning ? `: ${pushed.pushWarning}` : ""}` }));
1810
+ return 0;
1067
1811
  }
1068
1812
  /**
1069
1813
  * `chant components rollback <env> --release <label|digest>` (#4035): a
@@ -1073,7 +1817,7 @@ export async function runComponentsRollback(ctx) {
1073
1817
  * and its gates bind the release's change set planned against what `env`
1074
1818
  * runs now, as `promote --release` binds them (#4045).
1075
1819
  */
1076
- async function runReleaseRollback(ctx, env, ref, actor) {
1820
+ async function runReleaseRollback(ctx, env, ref, actor, only) {
1077
1821
  const project = await loadProject(ctx, "all", env);
1078
1822
  if (typeof project === "number")
1079
1823
  return project;
@@ -1095,12 +1839,13 @@ async function runReleaseRollback(ctx, env, ref, actor) {
1095
1839
  release: under.release,
1096
1840
  label: under.label,
1097
1841
  unsettled: new Set(unsettledComponents(records, outcomes).keys()),
1842
+ ...(only ? { only } : {}),
1098
1843
  });
1099
1844
  if ("error" in plan) {
1100
1845
  console.error(formatError({ message: plan.error, hint: ROLLBACK_USAGE }));
1101
1846
  return 1;
1102
1847
  }
1103
- return deployPlan(ctx, "rollback", plan, project, actor, rollbackRecord, under);
1848
+ return afterRollback(ctx, project.projectPath, env, actor, { digest: under.release.releaseDigest, label: under.label }, await deployPlan(ctx, "rollback", plan, project, actor, rollbackRecord, under));
1104
1849
  }
1105
1850
  export async function runComponentsRedeploy(ctx) {
1106
1851
  const { args } = ctx;