@intentius/chant 0.124.97 → 0.124.98

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 (223) hide show
  1. package/dist/audit/core.d.ts +29 -0
  2. package/dist/audit/core.d.ts.map +1 -1
  3. package/dist/audit/core.js +48 -11
  4. package/dist/audit/identity.d.ts +27 -0
  5. package/dist/audit/identity.d.ts.map +1 -0
  6. package/dist/audit/identity.js +36 -0
  7. package/dist/audit/report-html.d.ts +3 -1
  8. package/dist/audit/report-html.d.ts.map +1 -1
  9. package/dist/audit/report-html.js +1 -1
  10. package/dist/audit/report-model.d.ts +16 -0
  11. package/dist/audit/report-model.d.ts.map +1 -1
  12. package/dist/audit/report-model.js +5 -1
  13. package/dist/ci-agent.d.ts +17 -0
  14. package/dist/ci-agent.d.ts.map +1 -1
  15. package/dist/ci-agent.js +32 -0
  16. package/dist/ci-comment-allow.d.ts +88 -0
  17. package/dist/ci-comment-allow.d.ts.map +1 -0
  18. package/dist/ci-comment-allow.js +178 -0
  19. package/dist/ci-comment-commands.d.ts +12 -0
  20. package/dist/ci-comment-commands.d.ts.map +1 -1
  21. package/dist/ci-comment-commands.js +22 -0
  22. package/dist/ci-control.d.ts +6 -1
  23. package/dist/ci-control.d.ts.map +1 -1
  24. package/dist/ci-control.js +6 -1
  25. package/dist/ci-product.d.ts +3 -0
  26. package/dist/ci-product.d.ts.map +1 -1
  27. package/dist/ci-product.js +3 -0
  28. package/dist/cli/commands/audit.d.ts +3 -1
  29. package/dist/cli/commands/audit.d.ts.map +1 -1
  30. package/dist/cli/commands/audit.js +23 -6
  31. package/dist/cli/commands/import.d.ts +8 -1
  32. package/dist/cli/commands/import.d.ts.map +1 -1
  33. package/dist/cli/commands/import.js +31 -6
  34. package/dist/cli/handlers/agent.d.ts.map +1 -1
  35. package/dist/cli/handlers/agent.js +12 -2
  36. package/dist/cli/handlers/pr-comment.d.ts +6 -0
  37. package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
  38. package/dist/cli/handlers/pr-comment.js +12 -0
  39. package/dist/cli/handlers/promote.d.ts.map +1 -1
  40. package/dist/cli/handlers/promote.js +53 -6
  41. package/dist/cli/main.d.ts.map +1 -1
  42. package/dist/cli/main.js +29 -6
  43. package/dist/cli/parse-args.d.ts.map +1 -1
  44. package/dist/cli/parse-args.js +23 -0
  45. package/dist/cli/registry.d.ts +8 -0
  46. package/dist/cli/registry.d.ts.map +1 -1
  47. package/dist/cloud-lister/mask.d.ts +30 -1
  48. package/dist/cloud-lister/mask.d.ts.map +1 -1
  49. package/dist/cloud-lister/mask.js +66 -3
  50. package/dist/components/driver.d.ts +8 -1
  51. package/dist/components/driver.d.ts.map +1 -1
  52. package/dist/components/driver.js +1 -0
  53. package/dist/components/product-pipeline.d.ts +23 -1
  54. package/dist/components/product-pipeline.d.ts.map +1 -1
  55. package/dist/components/product-pipeline.js +40 -7
  56. package/dist/components/product-plan.d.ts +20 -0
  57. package/dist/components/product-plan.d.ts.map +1 -1
  58. package/dist/components/product-plan.js +11 -1
  59. package/dist/control/applied.d.ts +8 -1
  60. package/dist/control/applied.d.ts.map +1 -1
  61. package/dist/control/applied.js +18 -2
  62. package/dist/control/dispatch.d.ts +52 -0
  63. package/dist/control/dispatch.d.ts.map +1 -1
  64. package/dist/control/dispatch.js +140 -4
  65. package/dist/control/train.d.ts +198 -0
  66. package/dist/control/train.d.ts.map +1 -0
  67. package/dist/control/train.js +294 -0
  68. package/dist/deep-observation.js +2 -2
  69. package/dist/floor-table.data.d.ts.map +1 -1
  70. package/dist/floor-table.data.js +11 -0
  71. package/dist/graph-detail.d.ts +9 -0
  72. package/dist/graph-detail.d.ts.map +1 -1
  73. package/dist/graph-detail.js +38 -13
  74. package/dist/graph-refs.d.ts +233 -3
  75. package/dist/graph-refs.d.ts.map +1 -1
  76. package/dist/graph-refs.js +106 -15
  77. package/dist/lint/post-synth.d.ts +22 -0
  78. package/dist/lint/post-synth.d.ts.map +1 -1
  79. package/dist/lint/rules/declarable-naming-convention.d.ts +12 -0
  80. package/dist/lint/rules/declarable-naming-convention.d.ts.map +1 -1
  81. package/dist/lint/rules/declarable-naming-convention.js +38 -8
  82. package/dist/lint/rules/imported-source.d.ts +20 -0
  83. package/dist/lint/rules/imported-source.d.ts.map +1 -0
  84. package/dist/lint/rules/imported-source.js +27 -0
  85. package/dist/lint/rules/no-unused-declarable.d.ts.map +1 -1
  86. package/dist/lint/rules/no-unused-declarable.js +3 -0
  87. package/dist/op/gate.d.ts +2 -0
  88. package/dist/op/gate.d.ts.map +1 -1
  89. package/dist/op/gate.js +8 -1
  90. package/dist/pr-forge-reads.d.ts +17 -0
  91. package/dist/pr-forge-reads.d.ts.map +1 -1
  92. package/dist/pr-forge-reads.js +55 -0
  93. package/dist/release-floors.d.ts +9 -1
  94. package/dist/release-floors.d.ts.map +1 -1
  95. package/dist/release-floors.js +9 -1
  96. package/dist/repo-path.d.ts +29 -0
  97. package/dist/repo-path.d.ts.map +1 -0
  98. package/dist/repo-path.js +81 -0
  99. package/dist/sensitive-key.d.ts +23 -0
  100. package/dist/sensitive-key.d.ts.map +1 -1
  101. package/dist/sensitive-key.js +37 -0
  102. package/dist/terraform/hcl2json.d.ts +7 -0
  103. package/dist/terraform/hcl2json.d.ts.map +1 -1
  104. package/dist/terraform/hcl2json.js +7 -0
  105. package/dist/wave-runtime.mjs +352 -345
  106. package/dist/workspace/catalog-edges.d.ts +147 -0
  107. package/dist/workspace/catalog-edges.d.ts.map +1 -0
  108. package/dist/workspace/catalog-edges.js +461 -0
  109. package/dist/workspace/compose-graph.d.ts +73 -3
  110. package/dist/workspace/compose-graph.d.ts.map +1 -1
  111. package/dist/workspace/declaration.d.ts +2 -0
  112. package/dist/workspace/declaration.d.ts.map +1 -1
  113. package/dist/workspace/declaration.js +1 -0
  114. package/dist/workspace/declaration.schema.json +6 -0
  115. package/dist/workspace/discover.d.ts +134 -0
  116. package/dist/workspace/discover.d.ts.map +1 -0
  117. package/dist/workspace/discover.js +372 -0
  118. package/dist/workspace/graph-cli.d.ts +20 -0
  119. package/dist/workspace/graph-cli.d.ts.map +1 -1
  120. package/dist/workspace/graph-cli.js +178 -20
  121. package/dist/workspace/graph.schema.json +195 -2
  122. package/dist/workspace/release-train.d.ts +214 -3
  123. package/dist/workspace/release-train.d.ts.map +1 -1
  124. package/dist/workspace/release-train.js +552 -16
  125. package/dist/workspace/repo-ref.d.ts +14 -0
  126. package/dist/workspace/repo-ref.d.ts.map +1 -1
  127. package/dist/workspace/repo-ref.js +26 -1
  128. package/dist/workspace/workspace-gates.d.ts +24 -0
  129. package/dist/workspace/workspace-gates.d.ts.map +1 -1
  130. package/dist/workspace/workspace-gates.js +29 -5
  131. package/dist/workspace/workspace-ledger.d.ts +31 -5
  132. package/dist/workspace/workspace-ledger.d.ts.map +1 -1
  133. package/dist/workspace/workspace-ledger.js +2 -1
  134. package/dist/workspace/workspace-run.d.ts +14 -0
  135. package/dist/workspace/workspace-run.d.ts.map +1 -1
  136. package/dist/workspace/workspace-run.js +2 -2
  137. package/dist/yaml.d.ts.map +1 -1
  138. package/dist/yaml.js +33 -8
  139. package/package.json +1 -1
  140. package/src/audit/core.test.ts +64 -1
  141. package/src/audit/core.ts +75 -10
  142. package/src/audit/identity.test.ts +31 -0
  143. package/src/audit/identity.ts +43 -0
  144. package/src/audit/report-html.ts +4 -2
  145. package/src/audit/report-model.ts +21 -1
  146. package/src/ci-agent.test.ts +32 -0
  147. package/src/ci-agent.ts +42 -0
  148. package/src/ci-comment-allow.test.ts +380 -0
  149. package/src/ci-comment-allow.ts +184 -0
  150. package/src/ci-comment-commands.ts +25 -0
  151. package/src/ci-control.ts +42 -0
  152. package/src/ci-product.ts +3 -0
  153. package/src/cli/commands/audit-parser-notice.test.ts +74 -0
  154. package/src/cli/commands/audit.test.ts +12 -0
  155. package/src/cli/commands/audit.ts +25 -7
  156. package/src/cli/commands/import-layout.test.ts +2 -1
  157. package/src/cli/commands/import.ts +29 -6
  158. package/src/cli/handlers/agent.ts +13 -2
  159. package/src/cli/handlers/pr-comment.ts +12 -0
  160. package/src/cli/handlers/promote.test.ts +68 -0
  161. package/src/cli/handlers/promote.ts +52 -6
  162. package/src/cli/main.test.ts +5 -0
  163. package/src/cli/main.ts +29 -6
  164. package/src/cli/parse-args.ts +18 -0
  165. package/src/cli/registry.ts +8 -0
  166. package/src/cloud-lister/kubernetes.k3d.e2e.test.ts +104 -0
  167. package/src/cloud-lister/mask-references.test.ts +132 -0
  168. package/src/cloud-lister/mask.ts +68 -3
  169. package/src/components/driver.ts +9 -1
  170. package/src/components/product-pipeline.ts +57 -7
  171. package/src/components/product-plan.ts +27 -2
  172. package/src/control/applied.ts +33 -3
  173. package/src/control/dispatch.ts +156 -5
  174. package/src/control/train.test.ts +215 -0
  175. package/src/control/train.ts +413 -0
  176. package/src/deep-observation.ts +2 -2
  177. package/src/floor-table.data.ts +6 -0
  178. package/src/graph-detail.ts +37 -12
  179. package/src/graph-refs.test.ts +45 -1
  180. package/src/graph-refs.ts +321 -14
  181. package/src/lint/post-synth.ts +20 -0
  182. package/src/lint/rules/declarable-naming-convention.test.ts +35 -1
  183. package/src/lint/rules/declarable-naming-convention.ts +35 -8
  184. package/src/lint/rules/imported-source.test.ts +22 -0
  185. package/src/lint/rules/imported-source.ts +31 -0
  186. package/src/lint/rules/no-unused-declarable.test.ts +16 -0
  187. package/src/lint/rules/no-unused-declarable.ts +7 -0
  188. package/src/op/gate.ts +10 -2
  189. package/src/pr-forge-reads.ts +62 -0
  190. package/src/release-floors.ts +13 -1
  191. package/src/repo-path.test.ts +72 -0
  192. package/src/repo-path.ts +103 -0
  193. package/src/sensitive-key.ts +38 -0
  194. package/src/terraform/hcl2json.ts +8 -0
  195. package/src/workspace/application-set.e2e.test.ts +405 -0
  196. package/src/workspace/catalog-edges.ts +507 -0
  197. package/src/workspace/ci-green-workflow.test.ts +2 -2
  198. package/src/workspace/cluster-join.e2e.test.ts +150 -0
  199. package/src/workspace/compose-graph.ts +74 -5
  200. package/src/workspace/declaration.schema.json +6 -0
  201. package/src/workspace/declaration.ts +3 -0
  202. package/src/workspace/discover.e2e.test.ts +122 -0
  203. package/src/workspace/discover.test.ts +225 -0
  204. package/src/workspace/discover.ts +406 -0
  205. package/src/workspace/external-secret-catalog.e2e.test.ts +98 -0
  206. package/src/workspace/external-secret-catalog.test.ts +142 -0
  207. package/src/workspace/graph-cli.ts +207 -21
  208. package/src/workspace/graph-contract.test.ts +92 -0
  209. package/src/workspace/graph.schema.json +195 -2
  210. package/src/workspace/helm-references.e2e.test.ts +135 -0
  211. package/src/workspace/identity-annotation-catalog.e2e.test.ts +91 -0
  212. package/src/workspace/identity-annotation-catalog.test.ts +139 -0
  213. package/src/workspace/release-train-repos.test.ts +304 -0
  214. package/src/workspace/release-train.test.ts +296 -0
  215. package/src/workspace/release-train.ts +631 -16
  216. package/src/workspace/repo-ref.ts +26 -1
  217. package/src/workspace/runs-on.test.ts +45 -0
  218. package/src/workspace/workspace-gates.ts +48 -5
  219. package/src/workspace/workspace-ledger.ts +28 -5
  220. package/src/workspace/workspace-run.test.ts +1 -1
  221. package/src/workspace/workspace-run.ts +2 -2
  222. package/src/yaml.test.ts +96 -8
  223. package/src/yaml.ts +36 -8
@@ -0,0 +1,304 @@
1
+ /**
2
+ * A release train across repositories (#5119): `repo` members' releases are
3
+ * read at their pinned revisions, and the control repo promotes the train
4
+ * one member repository at a time. Each member repository is a temp repo
5
+ * behind a local bare remote, the read runs a stand-in chant that prints
6
+ * the releases document from the fetched `chant/lifecycle`, and the
7
+ * dispatcher is a fake. Nothing reaches a forge.
8
+ */
9
+
10
+ import { execFileSync } from "node:child_process";
11
+ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
12
+ import { tmpdir } from "node:os";
13
+ import { join } from "node:path";
14
+ import { afterAll, describe, expect, test } from "vitest";
15
+ import { gitControlAppliedLedger, recordControlApplied, type ControlAppliedRecord } from "../control/applied";
16
+ import type { TrainDispatch } from "../control/train";
17
+ import { CACHE_DIR_ENV } from "./graph-cache";
18
+ import { RELEASES_SCHEMA_ID } from "./releases";
19
+ import { readWorkspaceRuns } from "./workspace-ledger";
20
+ import {
21
+ appendReleaseTrain,
22
+ pickTrain,
23
+ promoteTrain,
24
+ readMemberReleases,
25
+ readReleaseTrains,
26
+ readRepoReleases,
27
+ trainDigest,
28
+ trainsWithPromotions,
29
+ type ReleaseTrainRecord,
30
+ type TrainMember,
31
+ } from "./release-train";
32
+
33
+ const scratch: string[] = [];
34
+ afterAll(() => {
35
+ for (const d of scratch) rmSync(d, { recursive: true, force: true });
36
+ });
37
+ function tmp(): string {
38
+ const d = realpathSync(mkdtempSync(join(tmpdir(), "chant-5119-")));
39
+ scratch.push(d);
40
+ return d;
41
+ }
42
+ const git = (cwd: string, ...args: string[]) =>
43
+ execFileSync("git", ["-c", "user.email=t@example.com", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...args], { cwd, encoding: "utf-8" }).trim();
44
+
45
+ const REL = (c: string) => `jcs1-sha256:${c.repeat(64)}`;
46
+
47
+ /**
48
+ * A member repository behind a local bare remote: a workspace at `main`,
49
+ * and a `chant/lifecycle` branch holding the releases document its chant
50
+ * would print. Returns the bare URL, the pinned revision, and its working copy.
51
+ */
52
+ function memberRepo(name: string, releases: Array<{ releaseDigest: string; label: string | null; cuts: number }>): { url: string; rev: string; work: string } {
53
+ const work = tmp();
54
+ git(work, "init", "-q", "-b", "main");
55
+ writeFileSync(join(work, "chant.workspace.json"), JSON.stringify({ name, schema: 1, members: [] }));
56
+ git(work, "add", "-A");
57
+ git(work, "commit", "-q", "-m", "init");
58
+ const rev = git(work, "rev-parse", "HEAD");
59
+ writeReleases(work, rev, releases);
60
+ const bare = join(tmp(), `${name}.git`);
61
+ git(work, "clone", "-q", "--bare", work, bare);
62
+ git(work, "remote", "add", "origin", bare);
63
+ return { url: bare, rev, work };
64
+ }
65
+
66
+ /** Commit the releases document onto `chant/lifecycle`, on top of what it holds, without touching the working tree. */
67
+ function writeReleases(work: string, rev: string, releases: Array<{ releaseDigest: string; label: string | null; cuts: number }>): void {
68
+ const doc = {
69
+ $schema: RELEASES_SCHEMA_ID,
70
+ contract: 1,
71
+ chant: "0.0.0",
72
+ member: null,
73
+ releases: releases.map((r, i) => ({ releaseDigest: r.releaseDigest, commit: rev, label: r.label, cuts: Array.from({ length: r.cuts }, (_, k) => ({ timestamp: `2026-11-1${i}T0${k}:00:00Z` })), targets: {}, environments: [], revoked: null })),
74
+ reason: null,
75
+ };
76
+ const blob = execFileSync("git", ["hash-object", "-w", "--stdin"], { cwd: work, input: JSON.stringify(doc), encoding: "utf-8" }).trim();
77
+ const tree = execFileSync("git", ["mktree"], { cwd: work, input: `100644 blob ${blob}\treleases.json\n`, encoding: "utf-8" }).trim();
78
+ let parent: string[] = [];
79
+ try {
80
+ parent = ["-p", git(work, "rev-parse", "--verify", "-q", "refs/heads/chant/lifecycle")];
81
+ } catch {
82
+ parent = [];
83
+ }
84
+ const commit = git(work, "commit-tree", tree, ...parent, "-m", "releases");
85
+ git(work, "update-ref", "refs/heads/chant/lifecycle", commit);
86
+ }
87
+
88
+ /** The stand-in for the member repository's own `chant release list --json`: the document on the branch it reads, which only the fetched ledger holds. */
89
+ function fakeChant(): string[] {
90
+ const script = join(tmp(), "chant.mjs");
91
+ writeFileSync(
92
+ script,
93
+ [
94
+ 'import { execFileSync } from "node:child_process";',
95
+ 'if (process.argv.slice(2).join(" ") !== "release list --json") process.exit(64);',
96
+ 'process.stdout.write(execFileSync("git", ["show", "chant/lifecycle:releases.json"], { encoding: "utf-8" }));',
97
+ ].join("\n"),
98
+ );
99
+ return [process.execPath, script];
100
+ }
101
+
102
+ function orgWorkspace(members: unknown[]): string {
103
+ const root = tmp();
104
+ git(root, "init", "-q", "-b", "main");
105
+ writeFileSync(join(root, "chant.workspace.json"), JSON.stringify({ name: "acme", schema: 1, scope: "org", members }));
106
+ git(root, "add", "-A");
107
+ git(root, "commit", "-q", "-m", "init");
108
+ return root;
109
+ }
110
+
111
+ describe("a train pins repo members, read at their pinned revisions", () => {
112
+ test("an org workspace with two repo members, each with a cut release, records a train naming both", async () => {
113
+ const api = memberRepo("api", [{ releaseDigest: REL("a"), label: "a2", cuts: 1 }, { releaseDigest: REL("0"), label: null, cuts: 0 }]);
114
+ const web = memberRepo("web", [{ releaseDigest: REL("b"), label: null, cuts: 2 }]);
115
+ const root = orgWorkspace([
116
+ { name: "api", kind: "repo", repo: { url: api.url, rev: api.rev } },
117
+ { name: "web", kind: "repo", repo: { url: web.url, rev: web.rev } },
118
+ ]);
119
+ const cache = tmp();
120
+ const command = fakeChant();
121
+ const env = { ...process.env, [CACHE_DIR_ENV]: cache };
122
+ const offered = await readMemberReleases(root, { readRepo: (m, ref, at) => readRepoReleases(m, ref, at, { env, command }) });
123
+ expect(offered.map((m) => [m.member, m.problem, m.releases.map((r) => r.releaseDigest)])).toEqual([
124
+ ["api", undefined, [REL("a")]],
125
+ ["web", undefined, [REL("b")]],
126
+ ]);
127
+ const picked = pickTrain(offered);
128
+ if (!("members" in picked)) throw new Error(picked.problems.join("; "));
129
+ expect(picked.members).toEqual([
130
+ { member: "api", releaseDigest: REL("a"), commit: api.rev, label: "a2", repo: { url: api.url, rev: api.rev } },
131
+ { member: "web", releaseDigest: REL("b"), commit: web.rev, label: null, repo: { url: web.url, rev: web.rev } },
132
+ ]);
133
+ // The ledger moves apart from the pinned revision: a release cut since is read the next time.
134
+ writeReleases(api.work, api.rev, [{ releaseDigest: REL("d"), label: "a3", cuts: 1 }]);
135
+ git(api.work, "push", "-q", "origin", "chant/lifecycle");
136
+ const again = await readRepoReleases("api", { url: api.url, rev: api.rev, workspace: "." }, root, { env, command });
137
+ expect(again.releases.map((r) => r.label)).toEqual(["a3"]);
138
+ // The same picks give the same digest, whatever the members' kinds.
139
+ expect(trainDigest(picked.members)).toBe(trainDigest(picked.members.map(({ repo: _r, ...m }) => m)));
140
+ });
141
+
142
+ test("a member with no release, a read that fails, and an org workspace with no members each refuse the train", async () => {
143
+ const api = memberRepo("api", []);
144
+ const root = orgWorkspace([
145
+ { name: "api", kind: "repo", repo: { url: api.url, rev: api.rev } },
146
+ { name: "gone", kind: "repo", repo: { url: join(tmp(), "nothing.git"), rev: api.rev } },
147
+ ]);
148
+ const env = { ...process.env, [CACHE_DIR_ENV]: tmp() };
149
+ const command = fakeChant();
150
+ const picked = pickTrain(await readMemberReleases(root, { readRepo: (m, ref, at) => readRepoReleases(m, ref, at, { env, command }) }));
151
+ expect("problems" in picked && picked.problems).toEqual([
152
+ `member api has no release; cut one with chant release cut in ${api.url}`,
153
+ expect.stringMatching(/^member gone: could not fetch /),
154
+ ]);
155
+ expect(pickTrain(await readMemberReleases(orgWorkspace([])))).toEqual({ problems: ["the workspace declares no chant or repo member, so a train has nothing to pin"] });
156
+ });
157
+ });
158
+
159
+ // ── The control repo's promote ───────────────────────────────────────────────
160
+
161
+ const member = (name: string, c: string): TrainMember => ({ member: name, releaseDigest: REL(c), commit: c.repeat(40), label: null, repo: { url: `https://github.com/acme/${name}`, rev: c.repeat(40) } });
162
+
163
+ async function recordTrain(cwd: string, members: TrainMember[]): Promise<ReleaseTrainRecord> {
164
+ const record: ReleaseTrainRecord = { version: 1, id: "train-6f1c2d4e-0000-4000-8000-00000000000a", env: "prod", timestamp: "2026-11-15T00:00:00Z", actor: "alice", members, trainDigest: trainDigest(members) };
165
+ await appendReleaseTrain(cwd, record);
166
+ return record;
167
+ }
168
+
169
+ /** web consumes what api produces, so api goes first. */
170
+ const readLinks = async () => [{ consumer: "web", producer: "api", status: "declared" }] as never;
171
+
172
+ function fakeDispatcher(sent: Array<{ repo: string; d: TrainDispatch }>, refuse?: string) {
173
+ return async (m: { name: string; repo: string }, d: TrainDispatch) => {
174
+ if (m.name === refuse) throw new Error("HTTP 404");
175
+ sent.push({ repo: m.repo, d });
176
+ };
177
+ }
178
+
179
+ async function answer(cwd: string, d: TrainDispatch, outcome: ControlAppliedRecord["outcome"], over: Partial<TrainDispatch> = {}): Promise<void> {
180
+ await recordControlApplied(gitControlAppliedLedger({ cwd }), { member: d.member, op: "deploy", sha: d.commit, outcome, train: { train: d.train, run: d.run, env: over.env ?? d.env, releaseDigest: over.releaseDigest ?? d.releaseDigest } });
181
+ }
182
+
183
+ describe("the control repo promotes a train one member repository at a time", () => {
184
+ test("dispatches the first member only; its applied dispatches the second, and a failed stops the train where it failed", async () => {
185
+ const cwd = orgWorkspace([]);
186
+ const train = await recordTrain(cwd, [member("web", "b"), member("api", "a")]);
187
+ const sent: Array<{ repo: string; d: TrainDispatch }> = [];
188
+ const q = { cwd, env: "prod", readLinks, dispatch: fakeDispatcher(sent) };
189
+
190
+ const started = await promoteTrain(q);
191
+ if (started.kind !== "ran") throw new Error(started.kind);
192
+ expect(sent).toEqual([{ repo: "https://github.com/acme/api", d: { member: "api", env: "prod", train: train.id, run: started.record.id, releaseDigest: REL("a"), commit: "a".repeat(40) } }]);
193
+ expect(started.record).toMatchObject({ status: "dispatched", train: { id: train.id, digest: train.trainDigest } });
194
+ expect(started.record.steps.map((s) => [s.member, s.status, s.repo])).toEqual([
195
+ ["api", "dispatched", "https://github.com/acme/api"],
196
+ ["web", "not-run", "https://github.com/acme/web"],
197
+ ]);
198
+
199
+ // A second start refuses while the first is in flight; a continue before an answer writes nothing.
200
+ expect(await promoteTrain(q)).toMatchObject({ kind: "refused", message: expect.stringMatching(/is in flight and waits on api/) });
201
+ expect(await promoteTrain({ ...q, continue: true })).toMatchObject({ kind: "waiting", member: "api" });
202
+ expect((await readWorkspaceRuns(cwd, "prod")).records).toHaveLength(1);
203
+ expect(sent).toHaveLength(1);
204
+
205
+ await answer(cwd, sent[0]!.d, "applied");
206
+ const second = await promoteTrain({ ...q, continue: true });
207
+ if (second.kind !== "ran") throw new Error(second.kind);
208
+ expect(second.record.id).toBe(started.record.id);
209
+ expect(sent.map((s) => s.d.member)).toEqual(["api", "web"]);
210
+ expect(second.record.steps.map((s) => [s.member, s.status, s.outcome])).toEqual([
211
+ ["api", "ok", "applied"],
212
+ ["web", "dispatched", undefined],
213
+ ]);
214
+
215
+ await answer(cwd, sent[1]!.d, "failed");
216
+ const stopped = await promoteTrain({ ...q, continue: true });
217
+ if (stopped.kind !== "ran") throw new Error(stopped.kind);
218
+ expect(stopped.record.status).toBe("fail");
219
+ expect(stopped.record.steps.map((s) => [s.member, s.status, s.outcome])).toEqual([
220
+ ["api", "ok", "applied"],
221
+ ["web", "fail", "failed"],
222
+ ]);
223
+ expect(stopped.record.steps[1]!.reason).toBe(`web's run ended failed at ${"b".repeat(12)}`);
224
+ expect(await promoteTrain({ ...q, continue: true })).toMatchObject({ kind: "idle" });
225
+ expect(sent).toHaveLength(2);
226
+
227
+ // The read behold draws a train from: one promotion, its newest line.
228
+ const listed = trainsWithPromotions((await readReleaseTrains(cwd, "prod")).records, (await readWorkspaceRuns(cwd, "prod")).records);
229
+ expect(listed[0]!.promotions).toHaveLength(1);
230
+ expect(listed[0]!.promotions[0]).toMatchObject({ run: started.record.id, status: "fail" });
231
+ expect(listed[0]!.promotions[0]!.members).toEqual([
232
+ { member: "api", status: "ok", memberRun: null, repo: "https://github.com/acme/api", outcome: "applied" },
233
+ { member: "web", status: "fail", memberRun: null, repo: "https://github.com/acme/web", outcome: "failed", reason: `web's run ended failed at ${"b".repeat(12)}` },
234
+ ]);
235
+ });
236
+
237
+ test("unchanged passes like applied; a run that waits at its own gate ends the train gated; the last member's pass ends it ok", async () => {
238
+ const cwd = orgWorkspace([]);
239
+ await recordTrain(cwd, [member("api", "a"), member("web", "b")]);
240
+ const sent: Array<{ repo: string; d: TrainDispatch }> = [];
241
+ const q = { cwd, env: "prod", readLinks, dispatch: fakeDispatcher(sent) };
242
+ await promoteTrain(q);
243
+ await answer(cwd, sent[0]!.d, "unchanged");
244
+ await promoteTrain({ ...q, continue: true });
245
+ await answer(cwd, sent[1]!.d, "waiting");
246
+ const gated = await promoteTrain({ ...q, continue: true });
247
+ if (gated.kind !== "ran") throw new Error(gated.kind);
248
+ expect([gated.record.status, gated.record.steps.map((s) => s.status)]).toEqual(["gated", ["ok", "gated"]]);
249
+ expect(gated.record.steps[1]!.reason).toMatch(/waits at its own gate/);
250
+
251
+ // Promoted again, a new run starts from the first member, and passes through both.
252
+ const again = await promoteTrain(q);
253
+ if (again.kind !== "ran") throw new Error(again.kind);
254
+ expect(again.record.id).not.toBe(gated.record.id);
255
+ await answer(cwd, sent[2]!.d, "unchanged");
256
+ await promoteTrain({ ...q, continue: true });
257
+ await answer(cwd, sent[3]!.d, "applied");
258
+ const done = await promoteTrain({ ...q, continue: true });
259
+ if (done.kind !== "ran") throw new Error(done.kind);
260
+ expect([done.record.status, done.record.steps.map((s) => s.status)]).toEqual(["ok", ["ok", "ok"]]);
261
+ });
262
+
263
+ test("an answer for another release, or another environment, fails the step; an answer for another run is not this run's", async () => {
264
+ const cwd = orgWorkspace([]);
265
+ await recordTrain(cwd, [member("api", "a"), member("web", "b")]);
266
+ const sent: Array<{ repo: string; d: TrainDispatch }> = [];
267
+ const q = { cwd, env: "prod", readLinks, dispatch: fakeDispatcher(sent) };
268
+ await promoteTrain(q);
269
+ await answer(cwd, { ...sent[0]!.d, run: "ws-6f1c2d4e-0000-4000-8000-0000000000ff" }, "applied");
270
+ expect(await promoteTrain({ ...q, continue: true })).toMatchObject({ kind: "waiting", member: "api" });
271
+ await answer(cwd, sent[0]!.d, "applied", { releaseDigest: REL("c") });
272
+ const out = await promoteTrain({ ...q, continue: true });
273
+ if (out.kind !== "ran") throw new Error(out.kind);
274
+ expect(out.record.status).toBe("fail");
275
+ expect(out.record.steps[0]!.reason).toBe(`api answered for release ${REL("c")} in prod, and the train pins ${REL("a")} in prod`);
276
+ expect(sent).toHaveLength(1);
277
+ });
278
+
279
+ test("a dispatch the forge does not take fails the step; --gate, and a train of both kinds, are refused", async () => {
280
+ const cwd = orgWorkspace([]);
281
+ await recordTrain(cwd, [member("api", "a"), member("web", "b")]);
282
+ const sent: Array<{ repo: string; d: TrainDispatch }> = [];
283
+ const refused = await promoteTrain({ cwd, env: "prod", readLinks, dispatch: fakeDispatcher(sent, "api") });
284
+ if (refused.kind !== "ran") throw new Error(refused.kind);
285
+ expect([refused.record.status, refused.record.steps.map((s) => s.status)]).toEqual(["fail", ["fail", "not-run"]]);
286
+ expect(refused.record.steps[0]!.reason).toBe("the dispatch into https://github.com/acme/api was not taken: HTTP 404");
287
+ expect(await promoteTrain({ cwd, env: "prod", readLinks, gate: "train-prod", dispatch: fakeDispatcher(sent) })).toMatchObject({ kind: "refused", message: expect.stringMatching(/each keeps its own gate/) });
288
+
289
+ const mixed = orgWorkspace([]);
290
+ const { repo: _r, ...local } = member("db", "c");
291
+ await recordTrain(mixed, [member("api", "a"), local]);
292
+ expect(await promoteTrain({ cwd: mixed, env: "prod", readLinks, dispatch: fakeDispatcher(sent) })).toMatchObject({ kind: "refused", message: expect.stringMatching(/pins repo members \(api\) and chant members \(db\)/) });
293
+ expect(sent).toEqual([]);
294
+ });
295
+
296
+ test("the order is the declaration's links, producers first", async () => {
297
+ const cwd = orgWorkspace([
298
+ { name: "web", kind: "repo", repo: { url: "https://github.com/acme/web", rev: "b".repeat(40) }, links: [{ member: "api", output: "url" }] },
299
+ { name: "api", kind: "repo", repo: { url: "https://github.com/acme/api", rev: "a".repeat(40) } },
300
+ ]);
301
+ await recordTrain(cwd, [member("web", "b"), member("api", "a")]);
302
+ expect(await promoteTrain({ cwd, env: "prod", dryRun: true })).toMatchObject({ kind: "planned", order: ["api", "web"] });
303
+ });
304
+ });
@@ -0,0 +1,296 @@
1
+ /**
2
+ * Release trains (#4037): the train digest, a train's promote across two
3
+ * members under one workspace gate, and the read that lists each train with
4
+ * the runs that promoted it. The ledger is a real `chant/lifecycle` branch
5
+ * in a temp repo; each member's `chant components promote` is a fake that
6
+ * answers as the real one does.
7
+ */
8
+ import { describe, test, expect, afterEach } from "vitest";
9
+ import { spawnSync } from "node:child_process";
10
+ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import { WORKSPACE_GATE_ENV, WORKSPACE_RUN_ENV } from "../op/workspace-run-env";
14
+ import { writeLedgerFiles } from "../lifecycle/git";
15
+ import type { WorkspaceGraph } from "./compose-graph";
16
+ import type { MemberOpResult } from "./workspace-run";
17
+ import { readWorkspaceRuns } from "./workspace-ledger";
18
+ import { approveWorkspaceGate, readWorkspaceGate, workspaceGateDigest, workspaceGateStandsIn, type WorkspaceGateApproval } from "./workspace-gates";
19
+ import {
20
+ appendReleaseTrain,
21
+ findTrain,
22
+ pickTrain,
23
+ promoteTrain,
24
+ readReleaseTrains,
25
+ releaseCovers,
26
+ trainDigest,
27
+ trainsWithPromotions,
28
+ type MemberReleasePlan,
29
+ type ReleaseTrainRecord,
30
+ type TrainMember,
31
+ } from "./release-train";
32
+
33
+ const REL_API = `jcs1-sha256:${"a".repeat(64)}`;
34
+ const REL_WEB = `jcs1-sha256:${"b".repeat(64)}`;
35
+ const REL_WEB2 = `jcs1-sha256:${"c".repeat(64)}`;
36
+ const CS_API = `jcs1-sha256:${"1".repeat(64)}`;
37
+ const CS_WEB = `jcs1-sha256:${"2".repeat(64)}`;
38
+ const CS_WEB_MOVED = `jcs1-sha256:${"3".repeat(64)}`;
39
+
40
+ const rel = (member: string, releaseDigest: string, label: string | null = null): TrainMember => ({ member, releaseDigest, commit: "c".repeat(40), label });
41
+
42
+ describe("the train digest", () => {
43
+ test("covers each member's release digest, so the same picks give the same digest whatever the order, label or commit", () => {
44
+ const a = trainDigest([rel("api", REL_API, "v1"), rel("web", REL_WEB)]);
45
+ expect(a).toMatch(/^jcs1-sha256:[0-9a-f]{64}$/);
46
+ expect(trainDigest([{ ...rel("web", REL_WEB, "v9"), commit: "d".repeat(40) }, rel("api", REL_API)])).toBe(a);
47
+ expect(trainDigest([rel("api", REL_API), rel("web", REL_WEB2)])).not.toBe(a);
48
+ expect(trainDigest([rel("api", REL_API)])).not.toBe(a);
49
+ });
50
+
51
+ test("an empty train is refused", () => {
52
+ expect(pickTrain([])).toEqual({ problems: ["the workspace declares no chant or repo member, so a train has nothing to pin"] });
53
+ });
54
+
55
+ test("a train is found by id or digest, else the newest is taken", () => {
56
+ const t = (id: string, members: TrainMember[]) => ({ version: 1 as const, id, env: "prod", timestamp: id, actor: "a", members, trainDigest: trainDigest(members) });
57
+ const one = t("train-1", [rel("api", REL_API)]);
58
+ const two = t("train-2", [rel("api", REL_API), rel("web", REL_WEB)]);
59
+ expect(findTrain([one, two])).toBe(two);
60
+ expect(findTrain([one, two], "train-1")).toBe(one);
61
+ expect(findTrain([one, two], one.trainDigest)).toBe(one);
62
+ expect(findTrain([one, two], "nope")).toBeNull();
63
+ });
64
+ });
65
+
66
+ describe("release covers", () => {
67
+ const plan = (over: Partial<MemberReleasePlan> = {}): MemberReleasePlan => ({ env: "prod", releaseDigest: REL_API, label: null, op: "release", gates: ["prod-release", "dba"], changeSet: CS_API, empty: false, components: ["api"], ...over });
68
+
69
+ test("one per release gate, bound to the member's change set, the environment and the release", () => {
70
+ expect(releaseCovers("api", "prod", plan())).toEqual([
71
+ { member: "api", op: "release", gate: "prod-release", planDigest: CS_API, environment: "prod", releaseDigest: REL_API },
72
+ { member: "api", op: "release", gate: "dba", planDigest: CS_API, environment: "prod", releaseDigest: REL_API },
73
+ ]);
74
+ });
75
+
76
+ test("none for an empty change set, or for a promote that declares no gate", () => {
77
+ expect(releaseCovers("api", "prod", plan({ empty: true }))).toEqual([]);
78
+ expect(releaseCovers("api", "prod", plan({ gates: [], changeSet: null, empty: null }))).toEqual([]);
79
+ });
80
+
81
+ test("an approval stands in for a release gate only for the release it covers", () => {
82
+ const covers = releaseCovers("api", "prod", plan({ gates: ["prod-release"] }));
83
+ const approval: WorkspaceGateApproval = { version: 1, kind: "approval", gate: "train-prod", digest: workspaceGateDigest(covers), covers, approvedBy: "alice", timestamp: "2026-11-15T00:00:00Z" };
84
+ const q = { op: "release", gate: "prod-release", planDigest: CS_API, environment: "prod", releaseDigest: REL_API };
85
+ const ctx = { member: "api", optedIn: true, approvals: [approval] };
86
+ expect(workspaceGateStandsIn(q, ctx)).toBe(approval);
87
+ expect(workspaceGateStandsIn({ ...q, releaseDigest: REL_WEB }, ctx)).toBeNull();
88
+ expect(workspaceGateStandsIn({ ...q, environment: "staging" }, ctx)).toBeNull();
89
+ expect(workspaceGateStandsIn(q, { ...ctx, optedIn: false })).toBeNull();
90
+ // A cover that names no release never stands in for a gate bound to one.
91
+ const plain = [{ member: "api", op: "release", gate: "prod-release", planDigest: CS_API, environment: "prod" }];
92
+ expect(workspaceGateStandsIn(q, { ...ctx, approvals: [{ ...approval, covers: plain, digest: workspaceGateDigest(plain) }] })).toBeNull();
93
+ });
94
+
95
+ test("a cover with no release hashes as it did before releases were added", () => {
96
+ const plain = [{ member: "api", op: "deploy", gate: "approve", planDigest: CS_API }];
97
+ expect(workspaceGateDigest(plain)).toBe(workspaceGateDigest([{ ...plain[0]!, releaseDigest: undefined } as never]));
98
+ });
99
+ });
100
+
101
+ // ── Against a real chant/lifecycle branch ────────────────────────────────────
102
+
103
+ const dirs: string[] = [];
104
+ afterEach(() => {
105
+ for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
106
+ });
107
+
108
+ function git(args: string[], cwd: string): string {
109
+ const r = spawnSync("git", args, { cwd, encoding: "utf-8" });
110
+ if (r.status !== 0) throw new Error(`git ${args.join(" ")}: ${r.stderr}`);
111
+ return r.stdout;
112
+ }
113
+
114
+ function repo(): string {
115
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), "chant-train-")));
116
+ dirs.push(dir);
117
+ git(["init", "-q", "-b", "main"], dir);
118
+ git(["config", "user.email", "test@chant.dev"], dir);
119
+ git(["config", "user.name", "Test"], dir);
120
+ writeFileSync(join(dir, "README.md"), "x\n");
121
+ git(["add", "."], dir);
122
+ git(["commit", "-q", "-m", "init"], dir);
123
+ return dir;
124
+ }
125
+
126
+ function member(name: string) {
127
+ return { name, dir: name, kind: "chant", status: "composed", reason: null, chant: null, irVersion: 1, live: false };
128
+ }
129
+
130
+ /** api produces what web reads. */
131
+ function graph(): WorkspaceGraph {
132
+ return {
133
+ version: 1,
134
+ workspace: { name: "acme", root: "." },
135
+ members: [member("web"), member("api")],
136
+ nodes: [],
137
+ edges: [],
138
+ groups: { byMember: {} },
139
+ exports: [],
140
+ imports: [],
141
+ links: [{ consumer: "web", producer: "api", output: "url", kind: "depends-on", origin: "declared", resolves: "source", status: "resolved", label: "exact", input: null, reason: null }],
142
+ collectors: [],
143
+ records: [],
144
+ } as unknown as WorkspaceGraph;
145
+ }
146
+
147
+ async function recordTrain(cwd: string, members: TrainMember[]): Promise<ReleaseTrainRecord> {
148
+ const record: ReleaseTrainRecord = { version: 1, id: `train-${members.map((m) => m.releaseDigest.slice(-1)).join("")}`, env: "prod", timestamp: "2026-11-15T00:00:00Z", actor: "alice", members, trainDigest: trainDigest(members) };
149
+ await appendReleaseTrain(cwd, record);
150
+ return record;
151
+ }
152
+
153
+ interface Seen {
154
+ member: string;
155
+ argv: string[];
156
+ env: Record<string, string>;
157
+ }
158
+
159
+ /**
160
+ * Each member's `chant components promote --release`: `--plan-only` prints
161
+ * the change set it would bind; a promote passes when the workspace gate it
162
+ * runs under has an approval, as an opted-in member's release gate would,
163
+ * and else exits 3 at its own gate.
164
+ */
165
+ function fakePromote(cwd: string, seen: Seen[], opts: { changeSets?: Record<string, string>; fail?: string } = {}) {
166
+ const changeSets = { api: CS_API, web: CS_WEB, ...opts.changeSets };
167
+ return async (m: { name: string; dir: string }, argv: string[], env: Record<string, string>): Promise<MemberOpResult> => {
168
+ seen.push({ member: m.name, argv, env });
169
+ const release = argv[argv.indexOf("--release") + 1]!;
170
+ if (argv.includes("--plan-only")) {
171
+ const plan: MemberReleasePlan = { env: "prod", releaseDigest: release, label: null, op: "release", gates: ["prod-release"], changeSet: changeSets[m.name as "api" | "web"]!, empty: false, components: [m.name] };
172
+ return { exitCode: 0, stdout: JSON.stringify(plan, null, 2), stderr: "" };
173
+ }
174
+ if (opts.fail === m.name) return { exitCode: 1, stdout: "", stderr: "apply failed\n" };
175
+ const gate = env[WORKSPACE_GATE_ENV];
176
+ const approved = gate ? (await readWorkspaceGate(cwd, gate)).approvals.some((a) => a.covers.some((c) => c.member === m.name && c.releaseDigest === release && c.planDigest === changeSets[m.name as "api" | "web"])) : false;
177
+ if (gate && !approved) {
178
+ return { exitCode: 3, stdout: JSON.stringify({ run: { gate: { op: "release", gate: "prod-release", planDigest: changeSets[m.name as "api" | "web"], environment: "prod" } }, recorded: [] }), stderr: "" };
179
+ }
180
+ if (gate === undefined) return { exitCode: 0, stdout: JSON.stringify({ recorded: [{ runId: `run-${m.name}` }] }), stderr: "" };
181
+ await writeLedgerFiles([{ path: `_members/${m.name}/prod/releases.jsonl`, content: `${JSON.stringify({ component: m.name, releaseDigest: release })}\n` }], `fake promote ${m.name}`, { cwd });
182
+ return { exitCode: 0, stdout: JSON.stringify({ recorded: [{ runId: `run-${m.name}` }] }), stderr: "" };
183
+ };
184
+ }
185
+
186
+ describe("a train of two members promotes together", () => {
187
+ test("a line written before the digest gets it computed on read", async () => {
188
+ const cwd = repo();
189
+ const members = [rel("api", REL_API), rel("web", REL_WEB)];
190
+ const older: ReleaseTrainRecord = { version: 1, id: "train-old", env: "prod", timestamp: "t", actor: "a", members };
191
+ await appendReleaseTrain(cwd, older);
192
+ const { records } = await readReleaseTrains(cwd, "prod");
193
+ expect(records[0]!.trainDigest).toBe(trainDigest(members));
194
+ });
195
+
196
+ test("under one workspace gate: nothing deploys before the approval, then both promote, producer first", async () => {
197
+ const cwd = repo();
198
+ const train = await recordTrain(cwd, [rel("web", REL_WEB, "w1"), rel("api", REL_API, "a1")]);
199
+ const seen: Seen[] = [];
200
+ const run = () => promoteTrain({ cwd, env: "prod", gate: "train-prod", readGraph: async () => ({ graph: graph(), failed: false }), runMember: fakePromote(cwd, seen) });
201
+
202
+ const planned = await promoteTrain({ cwd, env: "prod", dryRun: true, readGraph: async () => ({ graph: graph(), failed: false }), runMember: fakePromote(cwd, seen) });
203
+ expect(planned).toMatchObject({ kind: "planned", order: ["api", "web"] });
204
+ expect(seen).toEqual([]);
205
+
206
+ const first = await run();
207
+ if (first.kind !== "ran") throw new Error(first.kind);
208
+ expect(first.record.status).toBe("gated");
209
+ expect(seen.map((s) => [s.member, s.argv.includes("--plan-only")])).toEqual([["api", true], ["web", true]]);
210
+ expect(seen[0]!.argv).toEqual(["components", "promote", "--to", "prod", "--release", REL_API, "--plan-only", "--json"]);
211
+ expect(first.pending).toMatchObject({ gate: "train-prod", train: { id: train.id, digest: train.trainDigest } });
212
+ expect(first.pending!.covers).toEqual([
213
+ { member: "api", op: "release", gate: "prod-release", planDigest: CS_API, environment: "prod", releaseDigest: REL_API },
214
+ { member: "web", op: "release", gate: "prod-release", planDigest: CS_WEB, environment: "prod", releaseDigest: REL_WEB },
215
+ ]);
216
+ expect(first.record.steps.map((s) => [s.member, s.status])).toEqual([["api", "gated"], ["web", "gated"]]);
217
+ expect(git(["ls-tree", "-r", "--name-only", "chant/lifecycle"], cwd)).not.toMatch(/releases\.jsonl/);
218
+
219
+ // Asking again before the approval records no second fact.
220
+ seen.length = 0;
221
+ const again = await run();
222
+ if (again.kind !== "ran") throw new Error(again.kind);
223
+ expect(again.record.status).toBe("gated");
224
+ expect(again.pending!.digest).toBe(first.pending!.digest);
225
+ expect((await readWorkspaceGate(cwd, "train-prod")).pending).toHaveLength(1);
226
+ expect(seen.every((s) => s.argv.includes("--plan-only"))).toBe(true);
227
+
228
+ const approval = await approveWorkspaceGate(cwd, { gate: "train-prod", approvedBy: "alice", timestamp: "2026-11-15T01:00:00Z" });
229
+ expect(approval.train).toEqual({ id: train.id, digest: train.trainDigest });
230
+
231
+ seen.length = 0;
232
+ const done = await run();
233
+ if (done.kind !== "ran") throw new Error(done.kind);
234
+ expect(done.record.status).toBe("ok");
235
+ expect(done.approved).toBe(approval.digest);
236
+ const deploys = seen.filter((s) => !s.argv.includes("--plan-only"));
237
+ expect(deploys.map((s) => s.member)).toEqual(["api", "web"]);
238
+ expect(deploys.every((s) => s.env[WORKSPACE_GATE_ENV] === "train-prod" && s.env[WORKSPACE_RUN_ENV] === done.record.id)).toBe(true);
239
+ expect(done.record.steps.map((s) => [s.target, s.status, s.memberRun])).toEqual([
240
+ ["api/components promote", "ok", "run-api"],
241
+ ["web/components promote", "ok", "run-web"],
242
+ ]);
243
+ expect(done.record.train).toEqual({ id: train.id, digest: train.trainDigest });
244
+ expect(git(["show", "chant/lifecycle:_members/api/prod/releases.jsonl"], cwd)).toContain(REL_API);
245
+ expect(git(["show", "chant/lifecycle:_members/web/prod/releases.jsonl"], cwd)).toContain(REL_WEB);
246
+
247
+ // The read a lane draws a train from: the train, then each run that promoted it, member by member.
248
+ const listed = trainsWithPromotions((await readReleaseTrains(cwd, "prod")).records, (await readWorkspaceRuns(cwd, "prod")).records);
249
+ expect(listed).toHaveLength(1);
250
+ expect(listed[0]!.trainDigest).toBe(train.trainDigest);
251
+ expect(listed[0]!.promotions.map((p) => p.status)).toEqual(["gated", "gated", "ok"]);
252
+ expect(listed[0]!.promotions.at(-1)!.members).toEqual([
253
+ { member: "api", status: "ok", memberRun: "run-api" },
254
+ { member: "web", status: "ok", memberRun: "run-web" },
255
+ ]);
256
+ });
257
+
258
+ test("a member whose change set moved since the approval asks for a new one, and nothing deploys", async () => {
259
+ const cwd = repo();
260
+ await recordTrain(cwd, [rel("api", REL_API), rel("web", REL_WEB)]);
261
+ const seen: Seen[] = [];
262
+ const readGraph = async () => ({ graph: graph(), failed: false });
263
+ const first = await promoteTrain({ cwd, env: "prod", gate: "train-prod", readGraph, runMember: fakePromote(cwd, seen) });
264
+ if (first.kind !== "ran") throw new Error(first.kind);
265
+ await approveWorkspaceGate(cwd, { gate: "train-prod", approvedBy: "alice", timestamp: "2026-11-15T01:00:00Z" });
266
+ seen.length = 0;
267
+ const moved = await promoteTrain({ cwd, env: "prod", gate: "train-prod", readGraph, runMember: fakePromote(cwd, seen, { changeSets: { web: CS_WEB_MOVED } }) });
268
+ if (moved.kind !== "ran") throw new Error(moved.kind);
269
+ expect(moved.record.status).toBe("gated");
270
+ expect(moved.pending!.digest).not.toBe(first.pending!.digest);
271
+ expect(moved.pending!.covers.find((c) => c.member === "web")!.planDigest).toBe(CS_WEB_MOVED);
272
+ expect(seen.every((s) => s.argv.includes("--plan-only"))).toBe(true);
273
+ });
274
+
275
+ test("without a workspace gate, each member's own gates apply, and a failed producer stops its consumer", async () => {
276
+ const cwd = repo();
277
+ await recordTrain(cwd, [rel("web", REL_WEB), rel("api", REL_API)]);
278
+ const seen: Seen[] = [];
279
+ const out = await promoteTrain({ cwd, env: "prod", readGraph: async () => ({ graph: graph(), failed: false }), runMember: fakePromote(cwd, seen, { fail: "api" }) });
280
+ if (out.kind !== "ran") throw new Error(out.kind);
281
+ expect(seen.map((s) => s.member)).toEqual(["api"]);
282
+ expect(seen[0]!.env[WORKSPACE_GATE_ENV]).toBeUndefined();
283
+ expect(out.record.status).toBe("fail");
284
+ expect(out.record.steps.map((s) => s.status)).toEqual(["fail", "not-run"]);
285
+ expect(out.pending).toBeNull();
286
+ });
287
+
288
+ test("refuses with no train, a train named that does not exist, or a member the graph does not compose", async () => {
289
+ const cwd = repo();
290
+ const readGraph = async () => ({ graph: graph(), failed: false });
291
+ expect(await promoteTrain({ cwd, env: "prod", readGraph })).toMatchObject({ kind: "refused", message: expect.stringMatching(/no release train is recorded for prod/) });
292
+ await recordTrain(cwd, [rel("api", REL_API), rel("db", REL_WEB)]);
293
+ expect(await promoteTrain({ cwd, env: "prod", train: "train-x", readGraph })).toMatchObject({ kind: "refused", message: "no release train train-x is recorded for prod" });
294
+ expect(await promoteTrain({ cwd, env: "prod", readGraph })).toMatchObject({ kind: "refused", message: expect.stringMatching(/pins db, which the workspace graph does not compose/) });
295
+ });
296
+ });