@intentius/chant 0.124.89 → 0.124.91

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 (185) hide show
  1. package/dist/actor.d.ts +5 -3
  2. package/dist/actor.d.ts.map +1 -1
  3. package/dist/actor.js +7 -5
  4. package/dist/audit/core.d.ts.map +1 -1
  5. package/dist/audit/core.js +11 -1
  6. package/dist/ci-comment-commands.d.ts +18 -2
  7. package/dist/ci-comment-commands.d.ts.map +1 -1
  8. package/dist/ci-comment-commands.js +30 -2
  9. package/dist/ci-job-guard.d.ts +42 -45
  10. package/dist/ci-job-guard.d.ts.map +1 -1
  11. package/dist/ci-job-guard.js +206 -3
  12. package/dist/ci-note-commands.d.ts +41 -1
  13. package/dist/ci-note-commands.d.ts.map +1 -1
  14. package/dist/ci-note-commands.js +64 -5
  15. package/dist/ci-product.d.ts +50 -1
  16. package/dist/ci-product.d.ts.map +1 -1
  17. package/dist/ci-product.js +52 -6
  18. package/dist/cli/handlers/pr-comment.d.ts +13 -1
  19. package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
  20. package/dist/cli/handlers/pr-comment.js +90 -1
  21. package/dist/cli/handlers/pr-notes.d.ts.map +1 -1
  22. package/dist/cli/handlers/pr-notes.js +23 -1
  23. package/dist/cli/handlers/pr.d.ts +2 -2
  24. package/dist/cli/handlers/pr.d.ts.map +1 -1
  25. package/dist/cli/handlers/pr.js +41 -20
  26. package/dist/cli/handlers/run-wave.d.ts.map +1 -1
  27. package/dist/cli/handlers/run-wave.js +154 -4
  28. package/dist/cli/main.d.ts.map +1 -1
  29. package/dist/cli/main.js +17 -0
  30. package/dist/cli/parse-args.d.ts.map +1 -1
  31. package/dist/cli/parse-args.js +28 -0
  32. package/dist/cli/registry.d.ts +12 -1
  33. package/dist/cli/registry.d.ts.map +1 -1
  34. package/dist/components/pr-checks.d.ts +39 -1
  35. package/dist/components/pr-checks.d.ts.map +1 -1
  36. package/dist/components/pr-checks.js +45 -2
  37. package/dist/components/pr-pipeline.d.ts +11 -3
  38. package/dist/components/pr-pipeline.d.ts.map +1 -1
  39. package/dist/components/pr-pipeline.js +20 -7
  40. package/dist/components/product-pipeline.d.ts +54 -2
  41. package/dist/components/product-pipeline.d.ts.map +1 -1
  42. package/dist/components/product-pipeline.js +63 -6
  43. package/dist/components/product-plan.d.ts +92 -2
  44. package/dist/components/product-plan.d.ts.map +1 -1
  45. package/dist/components/product-plan.js +172 -22
  46. package/dist/floor-table.data.d.ts.map +1 -1
  47. package/dist/floor-table.data.js +37 -23
  48. package/dist/lexicon-module.d.ts +2 -0
  49. package/dist/lexicon-module.d.ts.map +1 -1
  50. package/dist/lexicon-module.js +6 -2
  51. package/dist/lexicon.d.ts +82 -4
  52. package/dist/lexicon.d.ts.map +1 -1
  53. package/dist/lifecycle/gate-applied.d.ts +9 -0
  54. package/dist/lifecycle/gate-applied.d.ts.map +1 -1
  55. package/dist/op/apply-status.d.ts +84 -0
  56. package/dist/op/apply-status.d.ts.map +1 -0
  57. package/dist/op/apply-status.js +106 -0
  58. package/dist/op/before-merge-decide.d.ts +102 -0
  59. package/dist/op/before-merge-decide.d.ts.map +1 -0
  60. package/dist/op/before-merge-decide.js +142 -0
  61. package/dist/op/before-merge-done.d.ts +56 -0
  62. package/dist/op/before-merge-done.d.ts.map +1 -0
  63. package/dist/op/before-merge-done.js +69 -0
  64. package/dist/op/before-merge-store.d.ts +20 -0
  65. package/dist/op/before-merge-store.d.ts.map +1 -0
  66. package/dist/op/before-merge-store.js +48 -0
  67. package/dist/op/before-merge.d.ts +150 -0
  68. package/dist/op/before-merge.d.ts.map +1 -0
  69. package/dist/op/before-merge.js +207 -0
  70. package/dist/op/follow-on-run.d.ts +117 -0
  71. package/dist/op/follow-on-run.d.ts.map +1 -0
  72. package/dist/op/follow-on-run.js +154 -0
  73. package/dist/op/follow-on-store.d.ts +17 -0
  74. package/dist/op/follow-on-store.d.ts.map +1 -0
  75. package/dist/op/follow-on-store.js +54 -0
  76. package/dist/op/gate.d.ts +6 -0
  77. package/dist/op/gate.d.ts.map +1 -1
  78. package/dist/op/gate.js +10 -1
  79. package/dist/op/index.d.ts +3 -1
  80. package/dist/op/index.d.ts.map +1 -1
  81. package/dist/op/index.js +1 -0
  82. package/dist/op/op-waves-after-plan.d.ts +13 -0
  83. package/dist/op/op-waves-after-plan.d.ts.map +1 -1
  84. package/dist/op/op-waves-evidence-jobs.d.ts +4 -1
  85. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
  86. package/dist/op/op-waves-evidence-jobs.js +10 -2
  87. package/dist/op/op-waves-follow-on.d.ts +162 -0
  88. package/dist/op/op-waves-follow-on.d.ts.map +1 -0
  89. package/dist/op/op-waves-follow-on.js +355 -0
  90. package/dist/op/op-waves-run.d.ts +146 -6
  91. package/dist/op/op-waves-run.d.ts.map +1 -1
  92. package/dist/op/op-waves-run.js +871 -99
  93. package/dist/op/op-waves-split.d.ts +122 -0
  94. package/dist/op/op-waves-split.d.ts.map +1 -0
  95. package/dist/op/op-waves-split.js +166 -0
  96. package/dist/op/op-waves.d.ts +20 -0
  97. package/dist/op/op-waves.d.ts.map +1 -1
  98. package/dist/op/op-waves.js +15 -1
  99. package/dist/op/schedule-overdue.d.ts +15 -1
  100. package/dist/op/schedule-overdue.d.ts.map +1 -1
  101. package/dist/op/schedule-overdue.js +18 -2
  102. package/dist/op/stage-hooks.d.ts +36 -1
  103. package/dist/op/stage-hooks.d.ts.map +1 -1
  104. package/dist/op/stage-hooks.js +17 -3
  105. package/dist/op/wave-stop.d.ts +4 -1
  106. package/dist/op/wave-stop.d.ts.map +1 -1
  107. package/dist/op/wave-stop.js +4 -2
  108. package/dist/planned-files.d.ts +16 -8
  109. package/dist/planned-files.d.ts.map +1 -1
  110. package/dist/planned-files.js +12 -8
  111. package/dist/pr-post.d.ts +6 -0
  112. package/dist/pr-post.d.ts.map +1 -1
  113. package/dist/pr-post.js +7 -5
  114. package/dist/release-floors.d.ts +9 -1
  115. package/dist/release-floors.d.ts.map +1 -1
  116. package/dist/release-floors.js +27 -19
  117. package/dist/wave-blocked.d.ts +7 -1
  118. package/dist/wave-blocked.d.ts.map +1 -1
  119. package/dist/wave-blocked.js +7 -2
  120. package/dist/wave-runtime.mjs +364 -351
  121. package/package.json +1 -1
  122. package/src/actor.test.ts +14 -1
  123. package/src/actor.ts +8 -6
  124. package/src/audit/core.ts +13 -1
  125. package/src/audit/first-load.test.ts +101 -0
  126. package/src/ci-comment-commands.test.ts +63 -0
  127. package/src/ci-comment-commands.ts +43 -4
  128. package/src/ci-image.test.ts +1 -2
  129. package/src/ci-job-guard.before-merge.test.ts +148 -0
  130. package/src/ci-job-guard.follow-on-record.test.ts +137 -0
  131. package/src/ci-job-guard.follow-on.test.ts +144 -0
  132. package/src/ci-job-guard.ts +221 -3
  133. package/src/ci-note-commands.test.ts +76 -1
  134. package/src/ci-note-commands.ts +96 -7
  135. package/src/ci-product.ts +65 -6
  136. package/src/cli/handlers/pr-comment.ts +85 -2
  137. package/src/cli/handlers/pr-notes.ts +30 -6
  138. package/src/cli/handlers/pr.ts +34 -17
  139. package/src/cli/handlers/run-wave.ts +144 -4
  140. package/src/cli/main.ts +17 -0
  141. package/src/cli/parse-args.ts +20 -0
  142. package/src/cli/registry.ts +12 -1
  143. package/src/components/pr-checks.ts +66 -2
  144. package/src/components/pr-pipeline.ts +21 -9
  145. package/src/components/product-pipeline.apply-status.test.ts +50 -0
  146. package/src/components/product-pipeline.ts +117 -9
  147. package/src/components/product-plan-names.test.ts +135 -0
  148. package/src/components/product-plan.test.ts +23 -5
  149. package/src/components/product-plan.ts +248 -25
  150. package/src/floor-table.data.ts +37 -23
  151. package/src/lexicon-module.ts +6 -2
  152. package/src/lexicon.ts +78 -1
  153. package/src/lifecycle/gate-applied.ts +7 -0
  154. package/src/op/apply-status.test.ts +83 -0
  155. package/src/op/apply-status.ts +132 -0
  156. package/src/op/before-merge-decide.ts +190 -0
  157. package/src/op/before-merge-done.ts +99 -0
  158. package/src/op/before-merge-store.ts +44 -0
  159. package/src/op/before-merge.test.ts +201 -0
  160. package/src/op/before-merge.ts +266 -0
  161. package/src/op/follow-on-run.ts +206 -0
  162. package/src/op/follow-on-store.ts +54 -0
  163. package/src/op/gate.ts +16 -1
  164. package/src/op/index.ts +5 -0
  165. package/src/op/op-waves-after-plan.ts +13 -0
  166. package/src/op/op-waves-evidence-jobs.ts +11 -3
  167. package/src/op/op-waves-follow-on-record.test.ts +152 -0
  168. package/src/op/op-waves-follow-on.test.ts +247 -0
  169. package/src/op/op-waves-follow-on.ts +385 -0
  170. package/src/op/op-waves-render-spec.test.ts +1 -2
  171. package/src/op/op-waves-run.ts +971 -93
  172. package/src/op/op-waves-split-product.test.ts +288 -0
  173. package/src/op/op-waves-split-step.test.ts +298 -0
  174. package/src/op/op-waves-split.test.ts +196 -0
  175. package/src/op/op-waves-split.ts +189 -0
  176. package/src/op/op-waves.ts +28 -3
  177. package/src/op/schedule-overdue.test.ts +29 -1
  178. package/src/op/schedule-overdue.ts +27 -3
  179. package/src/op/stage-hooks.ts +52 -4
  180. package/src/op/wave-stop.ts +5 -3
  181. package/src/planned-files.test.ts +33 -0
  182. package/src/planned-files.ts +26 -10
  183. package/src/pr-post.ts +13 -5
  184. package/src/release-floors.ts +31 -19
  185. package/src/wave-blocked.ts +9 -4
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Op waves before merge (#4984): the record that lets an open pull
3
+ * request's head run the waves.
4
+ *
5
+ * Maintainer decision (2026-11-10): waves before merge. The Op waves
6
+ * workflow gets a before-merge mode. The comment job (GitHub, Forgejo) or
7
+ * the note poll (GitLab) decides `/<product> apply` on an open pull
8
+ * request (./before-merge-decide.ts), writes the decided head here, and
9
+ * starts the waves workflow on the default branch for that head. Each wave
10
+ * job's guard (../ci-job-guard.ts) admits the run only when the head, the
11
+ * pull request and the digest it was started with are the ones recorded
12
+ * here. Per-wave runners, cloud identities and evidence stay as they are.
13
+ *
14
+ * The record is `_waves/<op>.before-merge.json` on `chant/lifecycle`, at the
15
+ * top of the branch whatever the member, so the guard reads it at one path.
16
+ * It keeps one decision per head, the newest {@link BEFORE_MERGE_KEPT}.
17
+ * Each decision's digest is sha256 over its fields in a fixed order
18
+ * ({@link beforeMergeDigest}); the run carries it, and the guard computes
19
+ * it again, so a decision edited by hand after it was made reads as no
20
+ * decision.
21
+ *
22
+ * A run carries the decision in three variables: GitHub and Forgejo map
23
+ * them from the `workflow_dispatch` inputs `pr`, `head` and `digest`; on
24
+ * GitLab they are the variables of the pipeline the poll starts.
25
+ */
26
+ import { createHash } from "node:crypto";
27
+ import { CHANT_EXIT } from "../exit-codes.js";
28
+ /** The variable a before-merge run carries the pull request in. */
29
+ export const BEFORE_MERGE_PR_ENV = "CHANT_BEFORE_MERGE_PR";
30
+ /** The variable a before-merge run carries the decided head in. */
31
+ export const BEFORE_MERGE_HEAD_ENV = "CHANT_BEFORE_MERGE_HEAD";
32
+ /** The variable a before-merge run carries the decision's digest in. */
33
+ export const BEFORE_MERGE_DIGEST_ENV = "CHANT_BEFORE_MERGE_DIGEST";
34
+ /**
35
+ * The variable a wave job's command reads its base from (#4984): set by the
36
+ * step that checks out the decided head, to the default branch's commit the
37
+ * run started at, so the gate policy, holds and spec render come from the
38
+ * default branch and never from the pull request.
39
+ */
40
+ export const WAVES_BASE_ENV = "CHANT_WAVES_BASE";
41
+ /** The `workflow_dispatch` inputs of a waves workflow with a before-merge mode, and the variables they map to. */
42
+ export const BEFORE_MERGE_INPUTS = { pr: BEFORE_MERGE_PR_ENV, head: BEFORE_MERGE_HEAD_ENV, digest: BEFORE_MERGE_DIGEST_ENV };
43
+ /** The directory of the decisions on `chant/lifecycle`, beside the wave stops. */
44
+ export const BEFORE_MERGE_DIR = "_waves";
45
+ /** How many heads' decisions the file keeps. */
46
+ export const BEFORE_MERGE_KEPT = 50;
47
+ /** The decisions file of op `op`. */
48
+ export function beforeMergeFile(op) {
49
+ return `${op}.before-merge.json`;
50
+ }
51
+ /** Its path from the top of `chant/lifecycle`, as the guard reads it. */
52
+ export function beforeMergePath(op) {
53
+ return `${BEFORE_MERGE_DIR}/${beforeMergeFile(op)}`;
54
+ }
55
+ const SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
56
+ const OP = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/;
57
+ const DIGEST = /^sha256:[0-9a-f]{64}$/;
58
+ const PR = /^[1-9][0-9]{0,9}$/;
59
+ /** The words the digest is taken over, in order. The guard's `node -e` program builds the same array. */
60
+ export function beforeMergeDigestInput(op, d) {
61
+ return JSON.stringify(["chant-before-merge/1", op, d.pr, d.head, d.base, d.through ?? 0, d.at, d.by]);
62
+ }
63
+ /** sha256 over {@link beforeMergeDigestInput}, as `sha256:<hex>`. */
64
+ export function beforeMergeDigest(op, d) {
65
+ return `sha256:${createHash("sha256").update(beforeMergeDigestInput(op, d)).digest("hex")}`;
66
+ }
67
+ /** Read a decisions file; anything that is not one reads as no decisions, and a malformed entry is dropped. */
68
+ export function parseBeforeMerge(text) {
69
+ let doc;
70
+ try {
71
+ doc = JSON.parse(text ?? "null");
72
+ }
73
+ catch {
74
+ return { version: 1, heads: {} };
75
+ }
76
+ const heads = {};
77
+ const given = doc && typeof doc === "object" && doc.version === 1 ? doc.heads : undefined;
78
+ if (given && typeof given === "object") {
79
+ for (const [head, r] of Object.entries(given)) {
80
+ const v = r;
81
+ if (!SHA.test(head) || !v || v.head !== head || !Number.isInteger(v.pr) || v.pr < 1)
82
+ continue;
83
+ if (typeof v.base !== "string" || !SHA.test(v.base) || typeof v.at !== "string" || typeof v.by !== "string" || typeof v.digest !== "string")
84
+ continue;
85
+ if (v.through !== undefined && (!Number.isInteger(v.through) || v.through < 1))
86
+ continue;
87
+ heads[head] = { pr: v.pr, head, base: v.base, ...(v.through !== undefined ? { through: v.through } : {}), at: v.at, by: v.by, digest: v.digest };
88
+ }
89
+ }
90
+ return { version: 1, heads };
91
+ }
92
+ /** The file's text: the newest {@link BEFORE_MERGE_KEPT} decisions, by head. */
93
+ export function renderBeforeMerge(file) {
94
+ const newest = Object.entries(file.heads).sort((a, b) => b[1].at.localeCompare(a[1].at)).slice(0, BEFORE_MERGE_KEPT);
95
+ return `${JSON.stringify({ version: 1, heads: Object.fromEntries(newest.sort((a, b) => a[0].localeCompare(b[0]))) }, null, 2)}\n`;
96
+ }
97
+ /** The run's decision variables from the environment. */
98
+ export function beforeMergeRunFromEnv(env = process.env) {
99
+ const v = (k) => {
100
+ const s = env[k]?.trim();
101
+ return s ? s : undefined;
102
+ };
103
+ const pr = v(BEFORE_MERGE_PR_ENV);
104
+ const head = v(BEFORE_MERGE_HEAD_ENV);
105
+ const digest = v(BEFORE_MERGE_DIGEST_ENV);
106
+ return { ...(pr ? { pr } : {}), ...(head ? { head } : {}), ...(digest ? { digest } : {}) };
107
+ }
108
+ /** Whether a run names a decision at all: any of the three variables set. */
109
+ export function isBeforeMergeRun(run) {
110
+ return run.pr !== undefined || run.head !== undefined || run.digest !== undefined;
111
+ }
112
+ const shown = (v) => (v === undefined || v === "" ? "none" : JSON.stringify(v));
113
+ /**
114
+ * What stops a run that names a decision, one line each: a variable that is
115
+ * not what it should be, no decision for the head, a decision for another
116
+ * pull request, another digest, or a decision whose fields no longer give
117
+ * its digest. Empty: the run is the one decided. The guard's `node -e`
118
+ * program gives the same lines.
119
+ */
120
+ export function beforeMergeProblems(op, run, record) {
121
+ const p = [];
122
+ if (!run.pr || !PR.test(run.pr))
123
+ p.push(`before merge: the run's pull request ${shown(run.pr)} is not a number`);
124
+ if (!run.head || !SHA.test(run.head))
125
+ p.push(`before merge: the run's head ${shown(run.head)} is not a commit sha`);
126
+ if (!run.digest || !DIGEST.test(run.digest))
127
+ p.push(`before merge: the run's digest ${shown(run.digest)} is not a sha256 digest`);
128
+ if (p.length > 0)
129
+ return p;
130
+ const head = run.head.slice(0, 12);
131
+ if (!record)
132
+ return [`before merge: no decision on chant/lifecycle names head ${head} of ${op}, so this run applies nothing`];
133
+ if (record.pr !== Number(run.pr))
134
+ p.push(`before merge: the decision for head ${head} is pull request ${record.pr}'s, not ${run.pr}'s`);
135
+ if (record.digest !== run.digest)
136
+ p.push(`before merge: the run carries digest ${run.digest}, and the decision for head ${head} has ${record.digest}`);
137
+ if (beforeMergeDigest(op, record) !== record.digest)
138
+ p.push(`before merge: the decision for head ${head} was changed after it was made: its fields give another digest`);
139
+ return p;
140
+ }
141
+ /** The job after the last wave of a before-merge run (#4984). */
142
+ export const BEFORE_MERGE_DONE_JOB = "before-merge-done";
143
+ /** The variable the done job hands the merge token to `--merge-token-env` in. */
144
+ export const BEFORE_MERGE_TOKEN_ENV = "CHANT_MERGE_TOKEN";
145
+ /** Check the mode's options for `forge`; throws with the reason. */
146
+ export function assertOpWavesBeforeMerge(forge, bm) {
147
+ if (bm.merge !== undefined && bm.merge !== "auto" && bm.merge !== "manual")
148
+ throw new Error(`beforeMerge.merge is auto or manual, not ${JSON.stringify(bm.merge)}`);
149
+ if (bm.mergeTokenSecret !== undefined && !/^[A-Za-z_][A-Za-z0-9_]*$/.test(bm.mergeTokenSecret))
150
+ throw new Error(`beforeMerge.mergeTokenSecret ${JSON.stringify(bm.mergeTokenSecret)} is not a variable name`);
151
+ if (bm.gate !== undefined && !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(bm.gate))
152
+ throw new Error(`beforeMerge.gate ${JSON.stringify(bm.gate)} is not a lock file name`);
153
+ if (bm.merge === "auto" && forge !== "github" && !bm.mergeTokenSecret) {
154
+ throw new Error(`beforeMerge.merge auto on ${forge} needs mergeTokenSecret: ${forge === "forgejo" ? "Forgejo refuses a merge made with the job's own token" : "GitLab's job token cannot merge"}`);
155
+ }
156
+ }
157
+ /**
158
+ * The done job's command, through the product's bin: `chant run wave --op
159
+ * <op> --wave <last wave> --merge auto|manual --forge <forge>`. It names the
160
+ * op and the wave count rather than the spec file, which a spec rendered at
161
+ * run time (#4982) leaves uncommitted.
162
+ */
163
+ export function beforeMergeDoneCommand(spec, forge, bm, bin) {
164
+ const words = (bin ?? "").split(/\s+/).filter(Boolean);
165
+ return [
166
+ ...(words.length > 0 ? words : ["chant"]),
167
+ "run", "wave", "--op", spec.name, "--wave", String(spec.waves.length),
168
+ "--merge", bm.merge ?? "manual",
169
+ "--forge", forge,
170
+ ...(bm.gate ? ["--gate", bm.gate] : []),
171
+ ...(bm.merge === "auto" && bm.mergeTokenSecret ? ["--merge-token-env", BEFORE_MERGE_TOKEN_ENV] : []),
172
+ ].join(" ");
173
+ }
174
+ /**
175
+ * The lines that check out the decided head (#4984), right after the
176
+ * default branch's checkout and before any of the change's code: nothing
177
+ * on a push run; else fetch the pull request's head ref, stop (exit 9,
178
+ * chant's `misplaced`) unless it is still the decided head, keep the
179
+ * default branch's commit as {@link WAVES_BASE_ENV} for the command, and
180
+ * check the head out. One shell block, so on GitLab it sits among the
181
+ * script's lines. With `checkout: false` (#4987) it fetches and checks the
182
+ * head and keeps the base, and leaves the default branch checked out: the
183
+ * gate and record jobs of a split wave read the head's commit and notes
184
+ * and run none of its code.
185
+ */
186
+ export function beforeMergeCheckoutScript(forge, product, opts = {}) {
187
+ const ref = forge === "gitlab" ? `refs/merge-requests/\${${BEFORE_MERGE_PR_ENV}}/head` : `refs/pull/\${${BEFORE_MERGE_PR_ENV}}/head`;
188
+ const what = forge === "gitlab" ? `!$${BEFORE_MERGE_PR_ENV}` : `pull request $${BEFORE_MERGE_PR_ENV}`;
189
+ const keep = forge === "gitlab" ? `${WAVES_BASE_ENV}="$(git rev-parse HEAD)"; export ${WAVES_BASE_ENV}` : `echo "${WAVES_BASE_ENV}=$(git rev-parse HEAD)" >> "$GITHUB_ENV"`;
190
+ return [
191
+ `if [ -n "\${${BEFORE_MERGE_HEAD_ENV}:-}" ]; then`,
192
+ ` git fetch -q --no-tags origin "+${ref}:refs/remotes/chant/before-merge-head" || { echo "${product}: could not fetch the head of ${what}" >&2; exit 1; }`,
193
+ ' now="$(git rev-parse refs/remotes/chant/before-merge-head)"',
194
+ ` if [ "$now" != "$${BEFORE_MERGE_HEAD_ENV}" ]; then echo "${product}: ${what} moved to $(printf %.12s "$now") after its head $(printf %.12s "$${BEFORE_MERGE_HEAD_ENV}") was decided, so nothing is applied; comment the apply again" >&2; exit ${CHANT_EXIT.misplaced}; fi`,
195
+ ` ${keep}`,
196
+ ...(opts.checkout === false ? [] : [` git checkout -q --detach "$${BEFORE_MERGE_HEAD_ENV}" || exit 1`]),
197
+ "fi",
198
+ ].join("\n");
199
+ }
200
+ /** Whether `op` names a decisions file and `sha` a commit. */
201
+ export function beforeMergeKeyProblem(op, sha) {
202
+ if (!OP.test(op))
203
+ return `the op name ${JSON.stringify(op)} is not a decisions file name`;
204
+ if (!SHA.test(sha))
205
+ return `${JSON.stringify(sha)} is not a commit sha`;
206
+ return undefined;
207
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * What a follow-on run of a `rest` wave carries (#4992), kept free of
3
+ * imports so the job guard (../ci-job-guard.ts) reads it without the waves
4
+ * runner.
5
+ *
6
+ * Maintainer decision (2026-11-10): before merge a `rest` wave's waves run
7
+ * one per run. The record job of the last rendered wave, when the plan found
8
+ * another wave, starts the waves workflow again for it (./op-waves-follow-on.ts).
9
+ * The new run carries the wave in {@link OP_WAVES_WAVE_ENV}, beside the
10
+ * before-merge decision's three variables (./before-merge.ts), or, for a
11
+ * push's run, the pushed commit in {@link OP_WAVES_COMMIT_ENV}. The rest
12
+ * wave's jobs default the wave to their own number, so a run that is no
13
+ * follow-on reads the same; the jobs of the waves before it do not run.
14
+ *
15
+ * #4998: before it starts a follow-on, the record job records it on
16
+ * `chant/lifecycle`, at {@link followOnPath}: one entry per chain, keyed by
17
+ * the decided head (before merge) or the pushed commit, naming the wave it
18
+ * started, the run that started it, the decision or the commit, and the
19
+ * outcomes of every run of the chain so far. Each follow-on replaces the
20
+ * entry, so it names the wave the newest record job started. The guard
21
+ * admits a follow-on only for that wave ({@link followOnRecordProblems}),
22
+ * so a wave started by hand past it, or an earlier wave run again after
23
+ * the chain went on, is refused.
24
+ */
25
+ /** The wave the rest wave's jobs run: their own number, or a later one in a follow-on run. */
26
+ export declare const OP_WAVES_WAVE_ENV = "CHANT_WAVES_WAVE";
27
+ /** The commit a push's follow-on run goes on with: the pushed commit the first run applied. */
28
+ export declare const OP_WAVES_COMMIT_ENV = "CHANT_WAVES_COMMIT";
29
+ /** The `workflow_dispatch` inputs a follow-on adds (GitHub, Forgejo), and the variables they map to. */
30
+ export declare const FOLLOW_ON_INPUTS: Readonly<Record<"wave" | "commit", string>>;
31
+ /** What a run says about a follow-on, from its variables. Unset or empty: none. */
32
+ export interface FollowOnRun {
33
+ wave?: string;
34
+ commit?: string;
35
+ }
36
+ /** The run's follow-on variables from the environment. */
37
+ export declare function followOnRunFromEnv(env?: Record<string, string | undefined>): FollowOnRun;
38
+ /**
39
+ * What stops a job that sees follow-on variables, one line each, and what
40
+ * it checked. `rest` is the rest wave's number when the job is one of its
41
+ * jobs. A job of the rest wave reads its own number when the run is no
42
+ * follow-on. A follow-on's wave comes after the rest wave's; a follow-on of
43
+ * a decided head carries no commit (the head is what it checks out), and a
44
+ * push's names the commit. The job guard's `node -e` program gives the same
45
+ * lines.
46
+ */
47
+ export declare function followOnProblems(rest: number | undefined, run: FollowOnRun, beforeMerge: boolean): {
48
+ problems: string[];
49
+ checked?: string;
50
+ };
51
+ /** The directory of the follow-on records on `chant/lifecycle` (#4998): beside the before-merge decisions, `_waves`. */
52
+ export declare const FOLLOW_ON_DIR = "_waves";
53
+ /** How many chains' records the file keeps. */
54
+ export declare const FOLLOW_ON_KEPT = 50;
55
+ /** The follow-on records file of op `op`. */
56
+ export declare function followOnFile(op: string): string;
57
+ /** Its path from the top of `chant/lifecycle`, as the guard reads it. */
58
+ export declare function followOnPath(op: string): string;
59
+ /** One run's outcome as a chain carries it: a wave outcome file's member, with the wave and the time it was written. */
60
+ export interface FollowOnOutcome {
61
+ status: string;
62
+ by?: string;
63
+ wave: number;
64
+ at: string;
65
+ }
66
+ /** The record of the newest follow-on of one chain (#4998). */
67
+ export interface FollowOnRecord {
68
+ /** The decided head a before-merge chain applies, or the commit a push's chain goes on with. */
69
+ key: string;
70
+ /** The wave of the follow-on the record job started. */
71
+ wave: number;
72
+ /** The wave the run that started it ran. */
73
+ from: number;
74
+ /** The id of the run that started it (GitHub and Forgejo `GITHUB_RUN_ID`, GitLab `CI_PIPELINE_ID`). */
75
+ run: string;
76
+ /** That run's page, when the forge names it. */
77
+ url?: string;
78
+ /** When the record job wrote it, ISO 8601. */
79
+ at: string;
80
+ /** Before merge: the decision's pull request and digest. */
81
+ pr?: number;
82
+ digest?: string;
83
+ /** A push's chain: the pushed commit, the same as `key`. */
84
+ commit?: string;
85
+ /** Every run's outcomes so far, by member: the newest of each. */
86
+ outcomes: Record<string, FollowOnOutcome>;
87
+ }
88
+ /** Where the rest wave's record job reads and writes a chain's record (./follow-on-store.ts: `chant/lifecycle`, or memory). */
89
+ export interface FollowOnChainPort {
90
+ /** The record of the chain keyed `key`, as the remote has it; undefined when there is none. */
91
+ read(op: string, key: string): Promise<FollowOnRecord | undefined>;
92
+ /** Replace the chain's record and push it, so the follow-on's guard reads it. */
93
+ write(op: string, record: FollowOnRecord): Promise<void>;
94
+ }
95
+ /** The follow-on records file: one entry per chain, by its key. */
96
+ export interface FollowOnFile {
97
+ version: 1;
98
+ chains: Record<string, FollowOnRecord>;
99
+ }
100
+ /**
101
+ * Read a follow-on records file; anything that is not one reads as no
102
+ * records, a malformed entry is dropped, and so is a malformed outcome. The
103
+ * guard's `node -e` program checks an entry the same way.
104
+ */
105
+ export declare function parseFollowOn(text: string | null): FollowOnFile;
106
+ /** The file's text: the newest {@link FOLLOW_ON_KEPT} chains, by key. */
107
+ export declare function renderFollowOn(file: FollowOnFile): string;
108
+ /**
109
+ * What stops a follow-on run (#4998) that {@link followOnProblems} let
110
+ * through, one line each: no record for its chain, a record that started
111
+ * another wave, or, before merge, one started for another decision. `key`
112
+ * is the run's decided head, or a push's commit; `digest` the run's
113
+ * decision digest before merge. Empty: the newest record job of the chain
114
+ * started this wave. The guard's `node -e` program gives the same lines.
115
+ */
116
+ export declare function followOnRecordProblems(op: string, wave: string, key: string, digest: string | undefined, record: FollowOnRecord | null | undefined): string[];
117
+ //# sourceMappingURL=follow-on-run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"follow-on-run.d.ts","sourceRoot":"","sources":["../../src/op/follow-on-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,qBAAqB,CAAC;AAEpD,+FAA+F;AAC/F,eAAO,MAAM,mBAAmB,uBAAuB,CAAC;AAExD,wGAAwG;AACxG,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,QAAQ,EAAE,MAAM,CAAC,CAA4D,CAAC;AAEtI,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,0DAA0D;AAC1D,wBAAgB,kBAAkB,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAAG,WAAW,CAIrG;AAKD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,GAAG;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAiB3I;AAED,wHAAwH;AACxH,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,+CAA+C;AAC/C,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,6CAA6C;AAC7C,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,yEAAyE;AACzE,wBAAgB,YAAY,CAAC,EA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Y,CAmC/D;AAED,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAGzD;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,EAAE,CAQ7J"}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * What a follow-on run of a `rest` wave carries (#4992), kept free of
3
+ * imports so the job guard (../ci-job-guard.ts) reads it without the waves
4
+ * runner.
5
+ *
6
+ * Maintainer decision (2026-11-10): before merge a `rest` wave's waves run
7
+ * one per run. The record job of the last rendered wave, when the plan found
8
+ * another wave, starts the waves workflow again for it (./op-waves-follow-on.ts).
9
+ * The new run carries the wave in {@link OP_WAVES_WAVE_ENV}, beside the
10
+ * before-merge decision's three variables (./before-merge.ts), or, for a
11
+ * push's run, the pushed commit in {@link OP_WAVES_COMMIT_ENV}. The rest
12
+ * wave's jobs default the wave to their own number, so a run that is no
13
+ * follow-on reads the same; the jobs of the waves before it do not run.
14
+ *
15
+ * #4998: before it starts a follow-on, the record job records it on
16
+ * `chant/lifecycle`, at {@link followOnPath}: one entry per chain, keyed by
17
+ * the decided head (before merge) or the pushed commit, naming the wave it
18
+ * started, the run that started it, the decision or the commit, and the
19
+ * outcomes of every run of the chain so far. Each follow-on replaces the
20
+ * entry, so it names the wave the newest record job started. The guard
21
+ * admits a follow-on only for that wave ({@link followOnRecordProblems}),
22
+ * so a wave started by hand past it, or an earlier wave run again after
23
+ * the chain went on, is refused.
24
+ */
25
+ /** The wave the rest wave's jobs run: their own number, or a later one in a follow-on run. */
26
+ export const OP_WAVES_WAVE_ENV = "CHANT_WAVES_WAVE";
27
+ /** The commit a push's follow-on run goes on with: the pushed commit the first run applied. */
28
+ export const OP_WAVES_COMMIT_ENV = "CHANT_WAVES_COMMIT";
29
+ /** The `workflow_dispatch` inputs a follow-on adds (GitHub, Forgejo), and the variables they map to. */
30
+ export const FOLLOW_ON_INPUTS = { wave: OP_WAVES_WAVE_ENV, commit: OP_WAVES_COMMIT_ENV };
31
+ /** The run's follow-on variables from the environment. */
32
+ export function followOnRunFromEnv(env = process.env) {
33
+ const wave = env[OP_WAVES_WAVE_ENV]?.trim();
34
+ const commit = env[OP_WAVES_COMMIT_ENV]?.trim();
35
+ return { ...(wave ? { wave } : {}), ...(commit ? { commit } : {}) };
36
+ }
37
+ const SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
38
+ const WAVE = /^[1-9][0-9]{0,5}$/;
39
+ /**
40
+ * What stops a job that sees follow-on variables, one line each, and what
41
+ * it checked. `rest` is the rest wave's number when the job is one of its
42
+ * jobs. A job of the rest wave reads its own number when the run is no
43
+ * follow-on. A follow-on's wave comes after the rest wave's; a follow-on of
44
+ * a decided head carries no commit (the head is what it checks out), and a
45
+ * push's names the commit. The job guard's `node -e` program gives the same
46
+ * lines.
47
+ */
48
+ export function followOnProblems(rest, run, beforeMerge) {
49
+ const { wave, commit } = run;
50
+ if (rest === undefined) {
51
+ if (wave === undefined && commit === undefined)
52
+ return { problems: [] };
53
+ return { problems: [`follow-on: the run names wave ${wave ?? "none"} and commit ${commit ?? "none"}, and this job is none of the rest wave's, which alone runs in a follow-on`] };
54
+ }
55
+ if (wave === undefined || wave === String(rest)) {
56
+ if (commit === undefined)
57
+ return { problems: [] };
58
+ return { problems: [`follow-on: the run names the commit ${commit} and no wave after wave ${rest}, so it is no follow-on`] };
59
+ }
60
+ if (!WAVE.test(wave) || Number(wave) <= rest)
61
+ return { problems: [`follow-on: the run's wave ${JSON.stringify(wave)} is no wave after wave ${rest}`] };
62
+ if (beforeMerge) {
63
+ if (commit !== undefined)
64
+ return { problems: [`follow-on: a follow-on of a decided head checks out that head, and the run names the commit ${commit} too`] };
65
+ return { problems: [], checked: `follow-on wave ${wave}` };
66
+ }
67
+ if (commit === undefined || !SHA.test(commit))
68
+ return { problems: [`follow-on: a push's follow-on names the commit it goes on with, and the run's ${commit === undefined ? "none" : JSON.stringify(commit)} is not a commit sha`] };
69
+ return { problems: [], checked: `follow-on wave ${wave} at ${commit.slice(0, 12)}` };
70
+ }
71
+ /** The directory of the follow-on records on `chant/lifecycle` (#4998): beside the before-merge decisions, `_waves`. */
72
+ export const FOLLOW_ON_DIR = "_waves";
73
+ /** How many chains' records the file keeps. */
74
+ export const FOLLOW_ON_KEPT = 50;
75
+ /** The follow-on records file of op `op`. */
76
+ export function followOnFile(op) {
77
+ return `${op}.follow-on.json`;
78
+ }
79
+ /** Its path from the top of `chant/lifecycle`, as the guard reads it. */
80
+ export function followOnPath(op) {
81
+ return `${FOLLOW_ON_DIR}/${followOnFile(op)}`;
82
+ }
83
+ const isWhole = (v, min) => Number.isInteger(v) && v >= min;
84
+ /**
85
+ * Read a follow-on records file; anything that is not one reads as no
86
+ * records, a malformed entry is dropped, and so is a malformed outcome. The
87
+ * guard's `node -e` program checks an entry the same way.
88
+ */
89
+ export function parseFollowOn(text) {
90
+ let doc;
91
+ try {
92
+ doc = JSON.parse(text ?? "null");
93
+ }
94
+ catch {
95
+ return { version: 1, chains: {} };
96
+ }
97
+ const chains = {};
98
+ const given = doc && typeof doc === "object" && doc.version === 1 ? doc.chains : undefined;
99
+ if (given && typeof given === "object") {
100
+ for (const [key, r] of Object.entries(given)) {
101
+ const v = r;
102
+ if (!SHA.test(key) || !v || typeof v !== "object" || v.key !== key || !isWhole(v.wave, 2) || !isWhole(v.from, 1) || typeof v.run !== "string" || typeof v.at !== "string")
103
+ continue;
104
+ if ((v.digest !== undefined && typeof v.digest !== "string") || (v.pr !== undefined && !isWhole(v.pr, 1)) || (v.commit !== undefined && (typeof v.commit !== "string" || !SHA.test(v.commit))))
105
+ continue;
106
+ if (!v.outcomes || typeof v.outcomes !== "object")
107
+ continue;
108
+ const outcomes = {};
109
+ for (const [member, o] of Object.entries(v.outcomes)) {
110
+ if (!o || typeof o.status !== "string" || !isWhole(o.wave, 1) || typeof o.at !== "string" || (o.by !== undefined && typeof o.by !== "string"))
111
+ continue;
112
+ outcomes[member] = { status: o.status, ...(o.by !== undefined ? { by: o.by } : {}), wave: o.wave, at: o.at };
113
+ }
114
+ chains[key] = {
115
+ key,
116
+ wave: v.wave,
117
+ from: v.from,
118
+ run: v.run,
119
+ ...(typeof v.url === "string" ? { url: v.url } : {}),
120
+ at: v.at,
121
+ ...(v.pr !== undefined ? { pr: v.pr } : {}),
122
+ ...(v.digest !== undefined ? { digest: v.digest } : {}),
123
+ ...(v.commit !== undefined ? { commit: v.commit } : {}),
124
+ outcomes,
125
+ };
126
+ }
127
+ }
128
+ return { version: 1, chains };
129
+ }
130
+ /** The file's text: the newest {@link FOLLOW_ON_KEPT} chains, by key. */
131
+ export function renderFollowOn(file) {
132
+ const newest = Object.entries(file.chains).sort((a, b) => b[1].at.localeCompare(a[1].at)).slice(0, FOLLOW_ON_KEPT);
133
+ return `${JSON.stringify({ version: 1, chains: Object.fromEntries(newest.sort((a, b) => a[0].localeCompare(b[0]))) }, null, 2)}\n`;
134
+ }
135
+ /**
136
+ * What stops a follow-on run (#4998) that {@link followOnProblems} let
137
+ * through, one line each: no record for its chain, a record that started
138
+ * another wave, or, before merge, one started for another decision. `key`
139
+ * is the run's decided head, or a push's commit; `digest` the run's
140
+ * decision digest before merge. Empty: the newest record job of the chain
141
+ * started this wave. The guard's `node -e` program gives the same lines.
142
+ */
143
+ export function followOnRecordProblems(op, wave, key, digest, record) {
144
+ const what = digest !== undefined ? "head" : "commit";
145
+ const short = key.slice(0, 12);
146
+ if (!record)
147
+ return [`follow-on: no record job of ${op} started a follow-on for ${what} ${short}, so this run applies nothing`];
148
+ const p = [];
149
+ if (String(record.wave) !== wave)
150
+ p.push(`follow-on: the newest record job of ${op} for ${what} ${short} started wave ${record.wave}, and this run names wave ${wave}`);
151
+ if (digest !== undefined && record.digest !== digest)
152
+ p.push(`follow-on: wave ${record.wave} of ${what} ${short} was started for the decision with digest ${record.digest ?? "none"}, and the run carries ${digest}`);
153
+ return p;
154
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The follow-on records on `chant/lifecycle` (#4998): read and written
3
+ * through the ledger's git, at `_waves/<op>.follow-on.json` from the top of
4
+ * the branch (./follow-on-run.ts says what a record is). Kept apart so the
5
+ * generators and the guard load no git code.
6
+ */
7
+ import { type FollowOnChainPort, type FollowOnFile } from "./follow-on-run.js";
8
+ export type { FollowOnChainPort } from "./follow-on-run.js";
9
+ /** The port over `chant/lifecycle`: fetched, written and pushed again when another writer pushed first, up to three times. */
10
+ export declare function gitFollowOnChainPort(opts?: {
11
+ cwd?: string;
12
+ }): FollowOnChainPort;
13
+ /** A port held in memory, for tests and for a caller that keeps the records itself. */
14
+ export declare function memoryFollowOnChainPort(initial?: Record<string, FollowOnFile>): FollowOnChainPort & {
15
+ files: Record<string, FollowOnFile>;
16
+ };
17
+ //# sourceMappingURL=follow-on-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"follow-on-store.d.ts","sourceRoot":"","sources":["../../src/op/follow-on-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAA8D,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAExI,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,8HAA8H;AAC9H,wBAAgB,oBAAoB,CAAC,IAAI,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,iBAAiB,CA0BnF;AAED,uFAAuF;AACvF,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAM,GAAG,iBAAiB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CAAE,CAW/I"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The follow-on records on `chant/lifecycle` (#4998): read and written
3
+ * through the ledger's git, at `_waves/<op>.follow-on.json` from the top of
4
+ * the branch (./follow-on-run.ts says what a record is). Kept apart so the
5
+ * generators and the guard load no git code.
6
+ */
7
+ import { fetchLifecycleStatus, pushLifecycleStatus, readBlobBySha, readPathSha, writeBlobToPath } from "../lifecycle/git.js";
8
+ import { FOLLOW_ON_DIR, followOnFile, parseFollowOn, renderFollowOn } from "./follow-on-run.js";
9
+ /** The port over `chant/lifecycle`: fetched, written and pushed again when another writer pushed first, up to three times. */
10
+ export function gitFollowOnChainPort(opts = {}) {
11
+ const where = { ...opts, ledgerPrefix: "" };
12
+ return {
13
+ async read(op, key) {
14
+ const fetched = await fetchLifecycleStatus(opts);
15
+ if (fetched.status === "unreachable")
16
+ throw new Error("chant/lifecycle could not be fetched, so the follow-on records cannot be read");
17
+ const blob = await readPathSha(FOLLOW_ON_DIR, followOnFile(op), where);
18
+ if (!blob)
19
+ return undefined;
20
+ return parseFollowOn(await readBlobBySha(blob, opts)).chains[key];
21
+ },
22
+ async write(op, record) {
23
+ for (let attempt = 1; attempt <= 3; attempt++) {
24
+ const fetched = await fetchLifecycleStatus(opts);
25
+ if (fetched.status === "unreachable")
26
+ throw new Error("chant/lifecycle could not be fetched, so the follow-on was not recorded");
27
+ const blob = await readPathSha(FOLLOW_ON_DIR, followOnFile(op), where);
28
+ const file = parseFollowOn(blob ? await readBlobBySha(blob, opts) : null);
29
+ const next = { version: 1, chains: { ...file.chains, [record.key]: record } };
30
+ await writeBlobToPath(FOLLOW_ON_DIR, followOnFile(op), renderFollowOn(next), `Follow on ${op}: wave ${record.wave} at ${record.key.slice(0, 12)}, started by run ${record.run}`, { ...where, expectPriorPathSha: blob });
31
+ const pushed = await pushLifecycleStatus(opts);
32
+ if (pushed.status === "stale")
33
+ continue;
34
+ if (pushed.status === "failed")
35
+ throw new Error(`could not push the follow-on record to chant/lifecycle (${pushed.stderr.trim()})`);
36
+ return;
37
+ }
38
+ throw new Error("chant/lifecycle kept moving, so the follow-on was not recorded");
39
+ },
40
+ };
41
+ }
42
+ /** A port held in memory, for tests and for a caller that keeps the records itself. */
43
+ export function memoryFollowOnChainPort(initial = {}) {
44
+ const files = { ...initial };
45
+ return {
46
+ files,
47
+ async read(op, key) {
48
+ return files[op]?.chains[key];
49
+ },
50
+ async write(op, record) {
51
+ files[op] = parseFollowOn(renderFollowOn({ version: 1, chains: { ...(files[op]?.chains ?? {}), [record.key]: record } }));
52
+ },
53
+ };
54
+ }
package/dist/op/gate.d.ts CHANGED
@@ -112,6 +112,12 @@ export interface GateLedgerPort {
112
112
  pushed: boolean;
113
113
  pushWarning?: string;
114
114
  }>;
115
+ /**
116
+ * The finished lines of `_gates/<op>/applied.jsonl` (#4994), oldest first,
117
+ * which say an apply under an approval ended. Absent on a port that keeps
118
+ * none.
119
+ */
120
+ readFinished?(op: string): Promise<FinishedGateRecord[]>;
115
121
  /**
116
122
  * Store a file a held request carries, such as a migration's proof, at
117
123
  * `_gates/<op>/requests/<digest>.json` (#4623), once, before the pending
@@ -1 +1 @@
1
- {"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/op/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,EASL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAA2D,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAGrJ,OAAO,EAAqB,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACzH,OAAO,EAEL,KAAK,eAAe,EAAE,KAAK,sBAAsB,EAAE,KAAK,cAAc,EACvE,MAAM,eAA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AsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAO9F"}
package/dist/op/gate.js CHANGED
@@ -36,7 +36,7 @@ import { activeProductWords, approveLine, isChantWords } from "../ci-product-wor
36
36
  import { appendGateResolution, appendPendingGate, isPendingGateExpired, latestPendingGate, latestResolutionForPlan, readGateLedger, resolveApprovalUrl, DEFAULT_GATE_EXPIRY, } from "../lifecycle/gate-ledger.js";
37
37
  import { describePlanDigest, samePlanDigest } from "../lifecycle/plan-digest.js";
38
38
  import { isModelAuthored } from "../lifecycle/gate-origin.js";
39
- import { appliedGatePath, isApprovalSpent, parseAppliedGateLines } from "../lifecycle/gate-applied.js";
39
+ import { appliedGatePath, isApprovalSpent, parseAppliedGateFile, parseAppliedGateLines } from "../lifecycle/gate-applied.js";
40
40
  import { gatedRequestAttachmentPath } from "../lifecycle/gated-request-digest.js";
41
41
  import { sortedJsonReplacer } from "../utils.js";
42
42
  import { gateContextDigest } from "./gate-approval.js";
@@ -109,6 +109,12 @@ export function gitGateLedgerPort(opts) {
109
109
  const text = await readBlobFromPath(dir, file, opts);
110
110
  return text ? parseAppliedGateLines(text) : [];
111
111
  },
112
+ async readFinished(op) {
113
+ await requireLifecycleLedger(opts);
114
+ const { dir, file } = appliedGatePath(op);
115
+ const text = await readBlobFromPath(dir, file, opts);
116
+ return text ? parseAppliedGateFile(text).finished.map((f) => ({ ...f, op: f.op || op })) : [];
117
+ },
112
118
  async appendApplied(record) {
113
119
  return appendAppliedFileLine(record.op, record, `Applied under ${record.gate}`);
114
120
  },
@@ -207,6 +213,9 @@ export function memoryGateLedgerPort(seed = {}) {
207
213
  finished.push(record);
208
214
  return { pushed: true };
209
215
  },
216
+ async readFinished(op) {
217
+ return finished.filter((f) => f.op === op);
218
+ },
210
219
  async storeRequestAttachment(op, digest, text) {
211
220
  if (!attachments.has(`${op}/${digest}`))
212
221
  attachments.set(`${op}/${digest}`, text);