forgedock 1.59.2 → 1.60.0
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.
- package/bin/engine/outcome-codes.mjs +3 -3
- package/bin/engine-cli.mjs +50 -10
- package/bin/labels.json +5 -0
- package/bin/lean/batch.mjs +21 -2
- package/bin/lean/batch.test.mjs +116 -1
- package/bin/lean/conformance.mjs +12 -5
- package/bin/lean/conformance.test.mjs +30 -2
- package/bin/lean/depcache.mjs +34 -15
- package/bin/lean/depcache.test.mjs +100 -1
- package/bin/lean/design-gate.mjs +15 -10
- package/bin/lean/design-gate.test.mjs +21 -0
- package/bin/lean/effects.mjs +18 -2
- package/bin/lean/execution.mjs +23 -5
- package/bin/lean/execution.test.mjs +81 -1
- package/bin/lean/gatewatch.test.mjs +5 -5
- package/bin/lean/issuewatch-triage.mjs +68 -0
- package/bin/lean/issuewatch-triage.test.mjs +98 -0
- package/bin/lean/issuewatch.mjs +34 -6
- package/bin/lean/issuewatch.test.mjs +11 -0
- package/bin/lean/lanelock.mjs +5 -4
- package/bin/lean/lean.mjs +123 -17
- package/bin/lean/lean.test.mjs +154 -6
- package/bin/lean/orchestrate-cancel.test.mjs +33 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +41 -0
- package/bin/lean/orchestrate-recovering.test.mjs +42 -0
- package/bin/lean/orchestrate.mjs +23 -10
- package/bin/lean/pagegate.mjs +50 -12
- package/bin/lean/pagegate.test.mjs +38 -1
- package/bin/lean/phaseledger.mjs +65 -2
- package/bin/lean/phaseledger.test.mjs +70 -2
- package/bin/lean/preflight.mjs +5 -2
- package/bin/lean/preflight.test.mjs +7 -0
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/recovery.test.mjs +11 -6
- package/bin/lean/release-classify.mjs +143 -0
- package/bin/lean/release-classify.test.mjs +130 -0
- package/bin/lean/release-conductor.mjs +163 -0
- package/bin/lean/release-conductor.test.mjs +194 -0
- package/bin/lean/release-config.mjs +60 -8
- package/bin/lean/release-config.test.mjs +43 -1
- package/bin/lean/release-control.mjs +22 -5
- package/bin/lean/release-control.test.mjs +22 -0
- package/bin/lean/release-credentials.mjs +40 -0
- package/bin/lean/release-credentials.test.mjs +42 -0
- package/bin/lean/release-deploy.mjs +3 -3
- package/bin/lean/release-deploy.test.mjs +8 -0
- package/bin/lean/release-docs.test.mjs +93 -0
- package/bin/lean/release-fence.mjs +2 -0
- package/bin/lean/release-gate.mjs +88 -0
- package/bin/lean/release-gate.test.mjs +116 -0
- package/bin/lean/release-gates.mjs +5 -1
- package/bin/lean/release-ledger.mjs +47 -1
- package/bin/lean/release-ledger.test.mjs +33 -1
- package/bin/lean/release-mergeback.mjs +148 -0
- package/bin/lean/release-mergeback.test.mjs +129 -0
- package/bin/lean/release-p0.mjs +193 -0
- package/bin/lean/release-p0.test.mjs +127 -0
- package/bin/lean/release-plan.mjs +267 -0
- package/bin/lean/release-plan.test.mjs +202 -0
- package/bin/lean/release-preflight.mjs +16 -0
- package/bin/lean/release-regate.mjs +141 -0
- package/bin/lean/release-regate.test.mjs +149 -0
- package/bin/lean/release-review.mjs +5 -3
- package/bin/lean/release-rollback.mjs +277 -0
- package/bin/lean/release-rollback.test.mjs +245 -0
- package/bin/lean/release-snapshot.mjs +48 -9
- package/bin/lean/release-snapshot.test.mjs +43 -1
- package/bin/lean/release-start.mjs +164 -0
- package/bin/lean/release-start.test.mjs +171 -0
- package/bin/lean/release-status.mjs +6 -2
- package/bin/lean/release-train.mjs +159 -0
- package/bin/lean/release-train.test.mjs +139 -0
- package/bin/lean/release.mjs +127 -5
- package/bin/lean/release.test.mjs +80 -0
- package/bin/lean/sandbox-remote.mjs +2 -0
- package/bin/lean/schedd-load.test.mjs +82 -0
- package/bin/lean/schedd.mjs +67 -31
- package/bin/lean/schedd.test.mjs +80 -1
- package/bin/lean/validate-catalog.mjs +94 -0
- package/bin/lean/validate-catalog.test.mjs +42 -0
- package/bin/pool/agent.mjs +4 -1
- package/bin/pool/lane-tools.mjs +115 -0
- package/bin/pool/lane-tools.test.mjs +26 -0
- package/bin/pool/warm.mjs +1 -1
- package/docs/CONFIG.md +225 -1
- package/docs/ISSUE-WATCH.md +1 -0
- package/docs/design/visual-gate.md +10 -0
- package/docs/eval/adversarial-bench.md +1 -0
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +2 -1
- package/templates/github-actions/forge-conductor.scopes.json +7 -0
- package/templates/github-actions/forge-conductor.yml +57 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { startRelease, startFromCli, goFromCli, cutAllowed, flagPolicyOutcome, milestonePlan, recordActivation, orderWaves, PLAN_DECISION } from "./release-start.mjs";
|
|
6
|
+
import { approvalOf } from "./release-plan.mjs";
|
|
7
|
+
|
|
8
|
+
const HASH = "a".repeat(64);
|
|
9
|
+
const plan = { plan_hash: HASH, waves: [
|
|
10
|
+
{ id: "release", lane: "release", issues: [3], units: ["web"] },
|
|
11
|
+
{ id: "train-1", lane: "train", issues: [1], units: ["api"] },
|
|
12
|
+
{ id: "train-2", lane: "train", issues: [2], units: ["api"] },
|
|
13
|
+
] };
|
|
14
|
+
const policy = { trust: { actors: ["owner"] } };
|
|
15
|
+
const mk = (over = {}) => {
|
|
16
|
+
const log = [], out = [], state = {};
|
|
17
|
+
const runners = {
|
|
18
|
+
build: async (w) => { log.push(`build:${w.id}`); return { ok: true }; },
|
|
19
|
+
train: async (w) => { log.push(`train:${w.id}`); return { status: "live" }; },
|
|
20
|
+
release: async (w, o) => { log.push(`release:${w.id}:${o.soak}`); return { status: "done" }; },
|
|
21
|
+
verify: async () => ({ verified: true }),
|
|
22
|
+
mergeback: async () => ({ validated: true }),
|
|
23
|
+
...over.runners,
|
|
24
|
+
};
|
|
25
|
+
return { log, out, state, ctx: { io: { print: (l) => out.push(l) }, plan, state, save: () => {}, managed: true, approval: { state: "approved" }, policy, runners, ...over.ctx } };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe("startRelease", () => {
|
|
29
|
+
it("replays plan, approval, two trains, then the release wave with only the approval as input", async () => {
|
|
30
|
+
const { ctx, log, state } = mk();
|
|
31
|
+
const r = await startRelease(ctx);
|
|
32
|
+
assert.equal(r.status, "done");
|
|
33
|
+
assert.deepEqual(log, ["build:release", "train:train-1", "train:train-2", "release:release:full"]);
|
|
34
|
+
assert.deepEqual(Object.values(state.waves).map((w) => w.state), ["WAVE_DONE", "WAVE_DONE", "WAVE_DONE"]);
|
|
35
|
+
assert.equal(orderWaves(plan)[2].id, "release");
|
|
36
|
+
});
|
|
37
|
+
it("refuses to CUT the release wave before the last train is WAVE_DONE; building is allowed", () => {
|
|
38
|
+
const st = { waves: { "train-1": { state: "WAVE_DONE" }, "train-2": { state: "LIVE" } } };
|
|
39
|
+
assert.equal(cutAllowed(st, plan, plan.waves[0]).ok, false);
|
|
40
|
+
assert.match(cutAllowed(st, plan, plan.waves[0]).reason, /train-2/);
|
|
41
|
+
st.waves["train-2"].state = "WAVE_DONE";
|
|
42
|
+
assert.equal(cutAllowed(st, plan, plan.waves[0]).ok, true);
|
|
43
|
+
});
|
|
44
|
+
it("stops a train that is live but not verified, so the release wave is never cut", async () => {
|
|
45
|
+
const { ctx, log } = mk({ runners: { verify: async () => ({ verified: false }) } });
|
|
46
|
+
const r = await startRelease(ctx);
|
|
47
|
+
assert.equal(r.status, "stopped");
|
|
48
|
+
assert.ok(!log.some((l) => l.startsWith("release:")));
|
|
49
|
+
});
|
|
50
|
+
it("a build before the trains deploy does not CUT (release runner is not called)", async () => {
|
|
51
|
+
const { ctx, log } = mk({ ctx: { wave: "release" }, runners: {} });
|
|
52
|
+
const r = await startRelease(ctx);
|
|
53
|
+
assert.equal(r.status, "refused");
|
|
54
|
+
assert.deepEqual(log, ["build:release"]);
|
|
55
|
+
});
|
|
56
|
+
it("resumes after a crash mid-wave without repeating a completed wave", async () => {
|
|
57
|
+
const { ctx, log, state } = mk({ runners: { train: async (w) => { log.push(`train:${w.id}`); if (w.id === "train-2" && !state.crashed) { state.crashed = 1; throw new Error("crash"); } return { status: "live" }; } } });
|
|
58
|
+
await assert.rejects(startRelease(ctx), /crash/);
|
|
59
|
+
log.length = 0;
|
|
60
|
+
const r = await startRelease(ctx);
|
|
61
|
+
assert.equal(r.status, "done");
|
|
62
|
+
assert.deepEqual(log, ["train:train-2", "release:release:full"]);
|
|
63
|
+
});
|
|
64
|
+
it("a recorded LIVE wave is verified, not redeployed", async () => {
|
|
65
|
+
const { ctx, log, state } = mk();
|
|
66
|
+
state.waves = { "train-1": { state: "LIVE" } };
|
|
67
|
+
await startRelease(ctx);
|
|
68
|
+
assert.ok(!log.includes("train:train-1"));
|
|
69
|
+
});
|
|
70
|
+
it("does nothing and writes nothing when unmanaged", async () => {
|
|
71
|
+
const { ctx, log } = mk({ ctx: { managed: false } });
|
|
72
|
+
assert.equal((await startRelease(ctx)).status, "unmanaged");
|
|
73
|
+
assert.deepEqual(log, []);
|
|
74
|
+
});
|
|
75
|
+
it("waits for approval", async () => {
|
|
76
|
+
const { ctx, log } = mk({ ctx: { approval: { state: "stale" } } });
|
|
77
|
+
assert.equal((await startRelease(ctx)).status, "awaiting-approval");
|
|
78
|
+
assert.deepEqual(log, []);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("flag policy", () => {
|
|
83
|
+
const info = { feature: true, added: [], offKeys: ["new_flag"] };
|
|
84
|
+
for (const [mode, action] of [["require", "error"], ["warn", "warn"], ["off", "none"]]) {
|
|
85
|
+
it(`missing rollout key under ${mode} => ${action}`, () => assert.equal(flagPolicyOutcome({ features: { flag_policy: mode } }, "release", info).action, action));
|
|
86
|
+
}
|
|
87
|
+
it("a present rollout key and a non-feature wave need nothing", () => {
|
|
88
|
+
assert.equal(flagPolicyOutcome({ features: { flag_policy: "require" } }, "release", { feature: true, added: ["k"] }).action, "none");
|
|
89
|
+
assert.equal(flagPolicyOutcome({ features: { flag_policy: "require" } }, "release", { feature: false }).action, "none");
|
|
90
|
+
});
|
|
91
|
+
it("a lane's own flag_policy wins", () => assert.equal(flagPolicyOutcome({ features: { flag_policy: "require" }, lanes: { release: { flag_policy: "off" } } }, "release", info).action, "none"));
|
|
92
|
+
it("require refuses the wave; warn runs it with a WARN", async () => {
|
|
93
|
+
const rollouts = async () => info;
|
|
94
|
+
const a = mk({ ctx: { policy: { ...policy, features: { flag_policy: "require" } } }, runners: { rollouts } });
|
|
95
|
+
assert.equal((await startRelease(a.ctx)).status, "refused");
|
|
96
|
+
const b = mk({ ctx: { policy: { ...policy, features: { flag_policy: "warn" } } }, runners: { rollouts } });
|
|
97
|
+
assert.equal((await startRelease(b.ctx)).status, "done");
|
|
98
|
+
assert.ok(b.out.some((l) => l.startsWith("WARN")));
|
|
99
|
+
});
|
|
100
|
+
it("a default-off key stays off after deploy and activation is its own record", async () => {
|
|
101
|
+
const { ctx, state } = mk({ runners: { rollouts: async () => ({ feature: true, added: ["new_flag"], offKeys: ["new_flag"] }) } });
|
|
102
|
+
await startRelease(ctx);
|
|
103
|
+
assert.deepEqual(state.waves.release.keepOff, ["new_flag"]);
|
|
104
|
+
assert.equal(state.activations, undefined);
|
|
105
|
+
recordActivation(state, "new_flag", "owner", "t");
|
|
106
|
+
assert.equal(state.activations[0].key, "new_flag");
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe("milestone lane", () => {
|
|
111
|
+
it("refuses without --milestone and builds one full release wave on the milestone branch", () => {
|
|
112
|
+
assert.throws(() => milestonePlan(plan), /--milestone/);
|
|
113
|
+
const m = milestonePlan(plan, "v2");
|
|
114
|
+
assert.equal(m.waves.length, 1);
|
|
115
|
+
assert.deepEqual([m.waves[0].base, m.waves[0].pipeline, m.waves[0].lane], ["milestone/v2", "full", "release"]);
|
|
116
|
+
});
|
|
117
|
+
it("start --lane milestone without --milestone throws", async () => {
|
|
118
|
+
await assert.rejects(startFromCli(["--lane", "milestone"], { io: { print() {} }, managed: true }), /--milestone/);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("startFromCli / goFromCli", () => {
|
|
123
|
+
const io = () => { const out = []; return { out, print: (l) => out.push(l) }; };
|
|
124
|
+
it("go posts the typed approval bound to the plan hash; start --approve then runs", async () => {
|
|
125
|
+
const posted = [], i = io();
|
|
126
|
+
const ledger = { read: async () => ({ state: { plan }, head: "h" }), write: async () => ({ ok: true, sha: "h2" }) };
|
|
127
|
+
assert.equal(await goFromCli(["r1"], { io: i, ledger, post: async (b) => posted.push(b), managed: true }), 0);
|
|
128
|
+
assert.deepEqual(posted, [PLAN_DECISION(HASH)]);
|
|
129
|
+
const comments = [];
|
|
130
|
+
const m = mk();
|
|
131
|
+
const code = await startFromCli(["--plan", "r1", "--approve"], { io: i, managed: true, policy, ledger, decisions: async () => comments.map((c) => ({ author: "owner", body: c })), post: async (b) => comments.push(b), runners: m.ctx.runners });
|
|
132
|
+
assert.equal(code, 0);
|
|
133
|
+
assert.equal(m.log.at(-1), "release:release:full");
|
|
134
|
+
assert.equal(approvalOf(plan, comments.map((b) => ({ author: "owner", body: b })), policy).state, "approved");
|
|
135
|
+
});
|
|
136
|
+
it("go and start write nothing when unmanaged", async () => {
|
|
137
|
+
const i = io(); let wrote = 0;
|
|
138
|
+
const ledger = { read: async () => { wrote++; }, write: async () => { wrote++; } };
|
|
139
|
+
assert.equal(await goFromCli(["r1"], { io: i, ledger, post: async () => { wrote++; }, managed: false }), 0);
|
|
140
|
+
assert.equal(await startFromCli([], { io: i, managed: false, ledger }), 0);
|
|
141
|
+
assert.equal(wrote, 0);
|
|
142
|
+
});
|
|
143
|
+
it("a refused wave lease stops the run before any effect", async () => {
|
|
144
|
+
const b = mk({ ctx: { takeFence: async () => ({ refused: "lease lost" }) } });
|
|
145
|
+
const r = await startRelease(b.ctx);
|
|
146
|
+
assert.deepEqual([r.status, r.reason], ["refused", "lease lost"]);
|
|
147
|
+
assert.ok(!b.log.some((l) => l.startsWith("train:")));
|
|
148
|
+
});
|
|
149
|
+
it("each wave takes its own fence and the effect runs under it", async () => {
|
|
150
|
+
const taken = [], recorded = [];
|
|
151
|
+
const fence = { lctx: { io: { api: async () => ({}) } }, lease: { epoch: 1 }, record: async (r) => recorded.push(r), now: () => "t" };
|
|
152
|
+
const { ctx } = mk({ ctx: { takeFence: async (st) => { taken.push(st); return { fence }; } } });
|
|
153
|
+
ctx.fence = null;
|
|
154
|
+
await startRelease(ctx).catch(() => null); // the fence gate reads the ledger, which this fake io does not serve; only the per-wave take is asserted
|
|
155
|
+
assert.equal(taken.length, 1);
|
|
156
|
+
assert.equal(taken[0], ctx.state);
|
|
157
|
+
});
|
|
158
|
+
it("prints activation_missing for a kept-off key until `go --activate` records it", async () => {
|
|
159
|
+
const { ctx, state, out } = mk({ runners: { rollouts: async () => ({ feature: true, added: ["new_flag"], offKeys: ["new_flag"] }) } });
|
|
160
|
+
state.id = "r1"; state.plan = plan;
|
|
161
|
+
await startRelease(ctx);
|
|
162
|
+
assert.ok(out.some((l) => l.startsWith("activation_missing: default-off new_flag")));
|
|
163
|
+
const posted = []; let written = null;
|
|
164
|
+
const ledger = { read: async () => ({ state, head: "h" }), write: async (_i, st) => { written = st; return { ok: true, sha: "h2" }; } };
|
|
165
|
+
const i = { print() {} };
|
|
166
|
+
assert.equal(await goFromCli(["r1", "--activate", "other"], { io: i, ledger, post: async (b) => posted.push(b), managed: true }), 1);
|
|
167
|
+
assert.equal(await goFromCli(["r1", "--activate", "new_flag"], { io: i, ledger, post: async (b) => posted.push(b), managed: true, actor: "owner" }), 0);
|
|
168
|
+
assert.equal(written.activations[0].key, "new_flag");
|
|
169
|
+
assert.deepEqual(posted, ["<!-- FORGE:DECISION activate new_flag -->"]);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -77,6 +77,7 @@ export async function collectStatus({ io, repo, id, config = {}, local, gateStat
|
|
|
77
77
|
review: verdict ? { verdict, head: pr?.head ?? "unknown" } : "unknown",
|
|
78
78
|
merge_sha: unk(state.steps?.promotion?.result?.sha ?? state.merge_sha),
|
|
79
79
|
deploy: state.deploy ? { run: unk(state.deploy.run), stage: unk(state.deploy.stage), attempt: unk(state.deploy.attempt) } : "unknown",
|
|
80
|
+
waiting_host: state.conductorWaiting ?? [], // #5564: host-only items the conductor left for a host driver
|
|
80
81
|
rollback_target: unk(state.rollback?.target), auto_rollback: state.rollback?.armed === undefined ? "unknown" : state.rollback.armed ? "armed" : "off",
|
|
81
82
|
release: state.release ? { snapshot: state.release.snapshot ?? null, branch: state.release.branch ?? null, issues: issueNumbers(state), picks: (state.release.picks ?? []).length } : null,
|
|
82
83
|
};
|
|
@@ -129,6 +130,7 @@ export function renderReleaseStatus(s) {
|
|
|
129
130
|
lines.push(` review: ${show(s.review)}`, ` merge: ${s.merge_sha}`, ` deploy: ${show(s.deploy)}`, ` rollback: target=${s.rollback_target} auto=${s.auto_rollback}`);
|
|
130
131
|
if (s.release) lines.push(` release set: ${s.release.issues.map((n) => `#${n}`).join(" ") || "(none recorded)"} picks=${s.release.picks}`);
|
|
131
132
|
}
|
|
133
|
+
if (s.waiting_host?.length) lines.push(` waiting on a host: ${s.waiting_host.join(", ")}`);
|
|
132
134
|
lines.push(" next:", ...s.next_actions.map((a) => ` ${a}`));
|
|
133
135
|
return lines.join("\n");
|
|
134
136
|
}
|
|
@@ -166,7 +168,7 @@ function classificationOf(comments) {
|
|
|
166
168
|
const hasLabel = (names, r) => names.includes(r.label);
|
|
167
169
|
|
|
168
170
|
/** `explain #N`: the ordered rule trace for one issue. `watch`: issue_watch config; `policy`: {skip_labels, min_confidence, risk_rules[], forces[]}; `controls`: controls.jsonl entries (`{verb, after, actor}`); `lanes`: `_active.lanes` (`{<issue>: {force, actor}}`). */
|
|
169
|
-
export async function explainIssue({ io, repo, number, state, watch = {}, policy = {}, controls = [], lanes = {}, planner = PLANNER_RULES }) {
|
|
171
|
+
export async function explainIssue({ io, repo, number, state, watch = {}, policy = {}, controls = [], lanes = {}, planner = PLANNER_RULES, plan = null }) {
|
|
170
172
|
resetSteps();
|
|
171
173
|
const issue = json(await io.gh(["issue", "view", String(number), "--repo", repo, "--json", "number,title,body,labels,comments,createdAt"]));
|
|
172
174
|
const open = json(await io.gh(["issue", "list", "--repo", repo, "--state", "open", "--limit", "500", "--json", "number,title,body,labels,createdAt"])) ?? [];
|
|
@@ -191,7 +193,9 @@ export async function explainIssue({ io, repo, number, state, watch = {}, policy
|
|
|
191
193
|
trace.push(item("depends_on", "release.managed", res(prereq.length === 0), prereq.length ? `open prerequisites ${prereq.map((n) => `#${n}`).join(", ")} must ship first` : "no open prerequisite", prereq.length ? [`close or ship ${prereq.map((n) => `#${n}`).join(", ")}`] : []));
|
|
192
194
|
const member = (state ? issueNumbers(state) : []).includes(issue.number);
|
|
193
195
|
trace.push(item("release_set", "release.mode", res(member), state ? (member ? `in the recorded release set of ${state.id}` : `not in the recorded release set of ${state.id}`) : "no release recorded", member || skip.length ? [] : ["include it in the next release cut"]));
|
|
194
|
-
|
|
196
|
+
const inPlan = plan?.issues?.[number], cut = plan?.excluded?.find((x) => x.number === number); // #5559: a computed plan (release-plan.mjs buildPlan) answers for the issue
|
|
197
|
+
if (plan) trace.push(item("planner", "release.plan", cut ? "fail" : inPlan ? "pass" : "n/a", cut ? `excluded [${cut.key}]: ${cut.detail}` : inPlan ? `planned in ${inPlan.lane} lane: ${inPlan.reason}` : "not a candidate of this plan", cut ? [`resolve ${cut.key}`] : []));
|
|
198
|
+
else if (planner.length) for (const fn of planner) { const p = fn({ issue, state }); trace.push(item(p.rule, p.config_key, p.result, p.detail ?? "", p.would_change ?? [])); }
|
|
195
199
|
else trace.push(item("planner", "release.planner", "n/a", "planner: not installed"));
|
|
196
200
|
const lastLane = controls.filter((c) => c.verb === "lane" && c.after?.[number] !== undefined).at(-1);
|
|
197
201
|
const rec = lanes[number] ?? (lastLane ? { force: lastLane.after[number], actor: lastLane.actor } : null);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* The service-scoped bug-fix train lane (#5570, epic #5549 Phase 5; I3, I4, Q9): a wave of single-service bug fixes branches from what
|
|
5
|
+
* is live (`laneStartGuard`, #5565), is re-checked against its real diff at CUT (`recomputeAtCut`: widening demotes the wave to the
|
|
6
|
+
* release lane or ejects the issue, narrowing is accepted), lands on the default branch with `Forge-Lane`/`Forge-Release`/`Forge-Epoch`
|
|
7
|
+
* trailers, then deploys through the `service` pipeline with the merge sha and unit set. The roll-set comes from `rollSet` (#5559),
|
|
8
|
+
* never from the classification record. Rung 1 of the ladder (#5563) runs on failure with the previous per-unit digests recorded first.
|
|
9
|
+
* A web/edge unit keeps the wave in VERIFYING until the injected `ctx.purge({units, sha})` seam reports `{ok: true}`.
|
|
10
|
+
*/
|
|
11
|
+
import { readTarget, deployStep } from "./release-deploy.mjs";
|
|
12
|
+
import { runRollback, takeFence } from "./release-rollback.mjs";
|
|
13
|
+
import { claimDeploy, releaseDeploy, recordTrain } from "./release-ledger.mjs";
|
|
14
|
+
import { buildDispatchArgs } from "./release-control.mjs";
|
|
15
|
+
import { fenced, laneTrailers } from "./release-fence.mjs";
|
|
16
|
+
import { laneStartGuard } from "./release-p0.mjs";
|
|
17
|
+
import { rollSet } from "./release-plan.mjs";
|
|
18
|
+
import { matchesAny } from "./release-unitmap.mjs";
|
|
19
|
+
import { MIGRATION_PATHS } from "./release-config.mjs";
|
|
20
|
+
|
|
21
|
+
const json = (s) => { try { return JSON.parse(String(s ?? "")); } catch { return null; } };
|
|
22
|
+
const noMigration = (m) => !m || m === "none" || m === "false";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* CUT-time recompute of one issue from its real diff against its classification record `{units, migrations, contract}`.
|
|
26
|
+
* @returns {{action: "keep"|"demote"|"eject", units: string[], migrations: boolean, contract: boolean, pipeline: string, widened: string[], narrowed: string[], why?: string}}
|
|
27
|
+
* Widening by a migration, a contract file or a pipeline that forces `full` demotes the wave; a new unit ejects the issue.
|
|
28
|
+
*/
|
|
29
|
+
export function recomputeAtCut(policy, record, diff) {
|
|
30
|
+
const files = diff ?? [];
|
|
31
|
+
const roll = rollSet(policy, files);
|
|
32
|
+
const migrations = files.some((f) => matchesAny(MIGRATION_PATHS, f));
|
|
33
|
+
const contract = roll.contract.atomic;
|
|
34
|
+
const had = new Set(record?.units ?? []);
|
|
35
|
+
const widened = [], narrowed = [];
|
|
36
|
+
for (const u of roll.units) if (!had.has(u)) widened.push(`unit:${u}`);
|
|
37
|
+
for (const u of had) if (!roll.units.includes(u)) narrowed.push(`unit:${u}`);
|
|
38
|
+
if (migrations && noMigration(record?.migrations)) widened.push("migration");
|
|
39
|
+
if (contract && !record?.contract) widened.push("contract");
|
|
40
|
+
if (!migrations && !noMigration(record?.migrations)) narrowed.push("migration");
|
|
41
|
+
const base = { units: roll.units, migrations, contract, pipeline: roll.pipeline, widened, narrowed };
|
|
42
|
+
if (widened.includes("migration") || widened.includes("contract") || roll.pipeline === "full") {
|
|
43
|
+
return { ...base, action: "demote", why: roll.pipeline === "full" && !widened.length ? `the diff forces the full pipeline (${roll.forced.join(", ") || roll.no_service.join(", ")})` : `diff widened past the record: ${widened.join(", ")}` };
|
|
44
|
+
}
|
|
45
|
+
if (widened.length) return { ...base, action: "eject", why: `diff widened past the record: ${widened.join(", ")}` };
|
|
46
|
+
return { ...base, action: "keep" };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** `train/<date>-<n>` from `branches.train` (placeholders `<date>`, `<n>`; default pattern when unset). */
|
|
50
|
+
export function trainBranch(policy, date, n) {
|
|
51
|
+
const name = String(policy?.branches?.train || "train/<date>-<n>").replace("<date>", date).replace("<n>", String(n));
|
|
52
|
+
return /^[A-Za-z0-9._/-]+$/.test(name) && !name.includes("..") ? name : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Units in dispatch order: contract producer first (atomic), then the rest sorted. */
|
|
56
|
+
const dispatchOrder = (roll) => [...roll.contract.order, ...roll.units.filter((u) => !roll.contract.order.includes(u))];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Run a train wave. `ctx`: {io, repo, def, state, save, config: {deploy, ...}, policy, actor, host, purge?, date, n};
|
|
60
|
+
* `wave`: [{issue, pr, record}]. @returns {Promise<{status: "live"|"verifying"|"demoted"|"rolled-back"|"refused"|"queued"|"blocked"|"stopped", reason?, branch?, ejected?, units?, rollback?}>}
|
|
61
|
+
*/
|
|
62
|
+
export async function runReleaseTrain(ctx, wave) {
|
|
63
|
+
const { io, state, policy } = ctx;
|
|
64
|
+
const L = { claimDeploy, releaseDeploy, takeFence, recordTrain, deployStep, runRollback, ...(ctx.ledger ?? {}) }; // overridable for tests
|
|
65
|
+
const d = ctx.config.deploy, pipe = d?.pipelines?.service;
|
|
66
|
+
if (!pipe?.workflow) return { status: "refused", reason: "deploy.pipelines.service is not configured" };
|
|
67
|
+
const name = trainBranch(policy, ctx.date, ctx.n);
|
|
68
|
+
if (!name) return { status: "refused", reason: "invalid train branch name" };
|
|
69
|
+
// CUT: recompute each issue from its PR's real files before anything is created (I3, I4)
|
|
70
|
+
const kept = [], ejected = [];
|
|
71
|
+
for (const w of wave) {
|
|
72
|
+
const files = (json(await io.gh(["pr", "view", String(w.pr), "--repo", ctx.repo, "--json", "files"]))?.files ?? []).map((f) => f.path);
|
|
73
|
+
const r = recomputeAtCut(policy, w.record, files);
|
|
74
|
+
if (r.action === "demote") return { status: "demoted", reason: `#${w.issue}: ${r.why}; the wave moves to the release lane` };
|
|
75
|
+
if (r.action === "eject") ejected.push({ issue: w.issue, reason: r.why }); else kept.push({ ...w, files });
|
|
76
|
+
}
|
|
77
|
+
if (!kept.length) return { status: "demoted", reason: "every issue was ejected at CUT", ejected };
|
|
78
|
+
const files = [...new Set(kept.flatMap((w) => w.files))].sort();
|
|
79
|
+
const roll = rollSet(policy, files);
|
|
80
|
+
const units = dispatchOrder(roll);
|
|
81
|
+
const g = await laneStartGuard({ ...ctx, deploy: d, release: state.id }, "train");
|
|
82
|
+
if (g.refused) return { status: "refused", reason: g.refused };
|
|
83
|
+
const live = await readTarget(io, d.live_release_command);
|
|
84
|
+
const tr = (state.train ??= {});
|
|
85
|
+
Object.assign(tr, { branch: name, live: g.live, units, order: roll.contract.order, previous: Object.fromEntries(units.map((u) => [u, live?.images?.[u] ?? null])), state: "CREATED" }); // frozen rollback inputs (#5560)
|
|
86
|
+
ctx.save();
|
|
87
|
+
io.git(["push", "--quiet", "origin", `${g.live}:refs/heads/${name}`]);
|
|
88
|
+
for (const w of kept) {
|
|
89
|
+
io.git(["fetch", "--quiet", "origin", `+refs/heads/${name}:refs/remotes/origin/${name}`]);
|
|
90
|
+
const tip = io.git(["rev-parse", `refs/remotes/origin/${name}`]).trim();
|
|
91
|
+
const f = await fenced(ctx.fence, { action: "merge", key: `train:${name}:${w.pr}` }, async () => {
|
|
92
|
+
await io.gh(["pr", "edit", String(w.pr), "--repo", ctx.repo, "--base", name]);
|
|
93
|
+
return io.gh(["pr", "merge", String(w.pr), "--repo", ctx.repo, "--merge"]);
|
|
94
|
+
});
|
|
95
|
+
if (f.refused) return { status: "refused", branch: name, reason: f.refused };
|
|
96
|
+
tr.merged = [...(tr.merged ?? []), w.pr]; tr.tip = tip; ctx.save();
|
|
97
|
+
}
|
|
98
|
+
io.git(["fetch", "--quiet", "origin", `+refs/heads/${name}:refs/remotes/origin/${name}`]);
|
|
99
|
+
const regen = (policy?.contracts ?? []).filter((c) => c.regenerate && files.some((f) => matchesAny(c.paths, f)));
|
|
100
|
+
if (regen.length) { // contract wave: regenerate artefacts before the push so they are in the wave
|
|
101
|
+
io.git(["checkout", "-q", "-B", name, `origin/${name}`]);
|
|
102
|
+
for (const c of regen) {
|
|
103
|
+
const r = await io.rehearse(c.regenerate, { timeout: 600_000 });
|
|
104
|
+
if (!r?.ok) return { status: "refused", branch: name, reason: `contracts regenerate failed for ${c.producer}: ${String(r?.output ?? "").slice(-200)}` };
|
|
105
|
+
}
|
|
106
|
+
if (String(io.git(["status", "--porcelain"]) ?? "").trim()) { io.git(["add", "-A"]); io.git(["commit", "-q", "-m", `chore(train): regenerate contract artefacts for ${name}`]); io.git(["push", "--quiet", "origin", name]); }
|
|
107
|
+
}
|
|
108
|
+
const lctx = io.api ? { io, repo: ctx.repo, credential: "driver" } : null;
|
|
109
|
+
const dctx = { ...ctx, staging: ctx.def, git: io.git, config: { ...ctx.config, deployPipeline: "service", trainDispatch: { units } } };
|
|
110
|
+
try { buildDispatchArgs({ workflow: pipe.workflow, repo: ctx.repo, ref: ctx.def, inputs: { ...(pipe.inputs ?? {}), merge_sha: "0".repeat(40), units: units.join(",") } }); } catch (e) { return { status: "refused", branch: name, reason: e.message }; }
|
|
111
|
+
if (io.api) {
|
|
112
|
+
const fl = await L.takeFence(dctx, io.holder ?? `host-${process.pid}`);
|
|
113
|
+
if (fl.refused) return { status: "refused", reason: fl.refused };
|
|
114
|
+
dctx.fence = fl.fence;
|
|
115
|
+
}
|
|
116
|
+
if (lctx) {
|
|
117
|
+
const c = await L.claimDeploy(lctx, { release: state.id, actor: ctx.actor, reason: `train ${name}`, now: io.now?.() });
|
|
118
|
+
if (c.queued) return { status: "queued", branch: name, reason: c.queued };
|
|
119
|
+
if (c.lost) return { status: "refused", reason: "could not claim the deploy slot in the ledger" };
|
|
120
|
+
}
|
|
121
|
+
try { // landing: merge-then-deploy, the merge carries the lane trailers
|
|
122
|
+
const url = String(await io.gh(["pr", "create", "--repo", ctx.repo, "--base", ctx.def, "--head", name, "--title", `train: land ${name} on ${ctx.def}`, "--body", `Landing PR for train wave ${name}.`]) ?? "");
|
|
123
|
+
const pr = Number(/\/pull\/(\d+)/.exec(url)?.[1]) || null;
|
|
124
|
+
const head = io.git(["rev-parse", `refs/remotes/origin/${name}`]).trim();
|
|
125
|
+
const m = await fenced(dctx.fence, { action: "merge", key: `train:land:${name}:${head}` }, (epoch) => io.gh(["pr", "merge", String(pr), "--repo", ctx.repo, "--merge", "--match-head-commit", head, "--body", laneTrailers({ lane: "train", release: state.id, epoch })]));
|
|
126
|
+
if (m.refused) return { status: "refused", branch: name, reason: m.refused };
|
|
127
|
+
const v = json(await io.gh(["pr", "view", String(pr), "--repo", ctx.repo, "--json", "state,mergeCommit"]));
|
|
128
|
+
const sha = v?.mergeCommit?.oid;
|
|
129
|
+
if (!sha) return { status: "stopped", branch: name, reason: `landing PR #${pr} has no merge commit yet` };
|
|
130
|
+
Object.assign(tr, { landingPr: pr, merge: sha, state: "LANDED" });
|
|
131
|
+
state.steps["release-pr"] = { done: true, result: { pr, issues: kept.map((w) => w.issue) } };
|
|
132
|
+
state.steps["post-merge"] = { done: true, result: { merge: sha } };
|
|
133
|
+
state.lane = "train"; ctx.save();
|
|
134
|
+
if (lctx) await L.recordTrain(lctx, { release: state.id, state: "LANDED", branch: name, merge: sha, units }, io.now?.()); // also notes the rollout record is invalidated
|
|
135
|
+
const out = await L.deployStep(dctx);
|
|
136
|
+
if (out.blocked || out.stopped) {
|
|
137
|
+
const rolled = state.deploy?.target && state.deploy?.runId && !out.stopped;
|
|
138
|
+
const reason = out.reason ?? out.why;
|
|
139
|
+
if (!rolled) return { status: out.blocked ? "blocked" : "stopped", branch: name, reason };
|
|
140
|
+
const rb = await L.runRollback({ ...dctx, policy, actor: ctx.actor, host: ctx.host, trainDigests: tr.previous }, { reason, to: "flag" });
|
|
141
|
+
tr.rollback = { rung: rb.rung, ok: rb.ok, digests: tr.previous }; tr.state = "ROLLED_BACK"; ctx.save();
|
|
142
|
+
return { status: "rolled-back", branch: name, reason, rollback: rb };
|
|
143
|
+
}
|
|
144
|
+
if (out.skipped) return { status: "refused", reason: "deploy.pipelines is empty; nothing to deploy" };
|
|
145
|
+
const edge = units.filter((u) => ["web", "edge"].includes(policy?.units?.[u]?.surface));
|
|
146
|
+
if (edge.length) {
|
|
147
|
+
const p = ctx.purge ? await ctx.purge({ units: edge, sha }) : null;
|
|
148
|
+
if (!p?.ok) {
|
|
149
|
+
tr.state = "VERIFYING"; tr.verifying = ctx.purge ? `purge for ${edge.join(", ")} did not report success${p?.reason ? `: ${p.reason}` : ""}` : `no purge seam configured for web/edge unit(s) ${edge.join(", ")}`; ctx.save();
|
|
150
|
+
return { status: "verifying", branch: name, reason: tr.verifying, units, ...(ejected.length ? { ejected } : {}) };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
tr.state = "LIVE"; ctx.save();
|
|
154
|
+
if (lctx) await L.recordTrain(lctx, { release: state.id, state: "LIVE", branch: name, merge: sha, units }, io.now?.());
|
|
155
|
+
return { status: "live", branch: name, units, landingPr: pr, ...(ejected.length ? { ejected } : {}) };
|
|
156
|
+
} finally {
|
|
157
|
+
if (lctx) await L.releaseDeploy(lctx, state.id).catch(() => null);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { recomputeAtCut, runReleaseTrain, trainBranch } from "./release-train.mjs";
|
|
6
|
+
import { rollSet } from "./release-plan.mjs";
|
|
7
|
+
import { laneTrailers } from "./release-fence.mjs";
|
|
8
|
+
|
|
9
|
+
const policy = {
|
|
10
|
+
branches: { train: "train/<date>-<n>" },
|
|
11
|
+
units: { api: { paths: ["svc/api/**"] }, web: { paths: ["svc/web/**"], surface: "web" }, worker: { paths: ["svc/worker/**"] }, fx: { paths: ["svc/fx/**"], service_pipeline: false } },
|
|
12
|
+
couplings: [{ paths: ["shared/**"], affects: ["api", "web", "worker"] }],
|
|
13
|
+
contracts: [{ producer: "api", consumers: ["web"], paths: ["contract/**"], additive_only: true, regenerate: "make gen" }],
|
|
14
|
+
};
|
|
15
|
+
const rec = { units: ["api"], migrations: "none", contract: false };
|
|
16
|
+
|
|
17
|
+
describe("recomputeAtCut (I3)", () => {
|
|
18
|
+
it("keeps an unchanged diff", () => assert.equal(recomputeAtCut(policy, rec, ["svc/api/a.js"]).action, "keep"));
|
|
19
|
+
it("demotes a migration file", () => { const r = recomputeAtCut(policy, rec, ["svc/api/a.js", "svc/api/migrations/001.sql"]); assert.equal(r.action, "demote"); assert.ok(r.widened.includes("migration")); });
|
|
20
|
+
it("demotes a contract file", () => assert.equal(recomputeAtCut(policy, rec, ["contract/x.json"]).action, "demote"));
|
|
21
|
+
it("ejects a new unit", () => { const r = recomputeAtCut(policy, rec, ["svc/api/a.js", "svc/worker/w.js"]); assert.equal(r.action, "eject"); assert.deepEqual(r.widened, ["unit:worker"]); });
|
|
22
|
+
it("demotes when the diff forces the full pipeline", () => assert.equal(recomputeAtCut(policy, { ...rec, units: ["fx"] }, ["svc/fx/a.js"]).action, "demote"));
|
|
23
|
+
it("accepts narrowing", () => { const r = recomputeAtCut(policy, { ...rec, units: ["api", "worker"] }, ["svc/api/a.js"]); assert.equal(r.action, "keep"); assert.deepEqual(r.narrowed, ["unit:worker"]); });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("roll-set property (I4)", () => {
|
|
27
|
+
it("the recomputed unit set covers every unit owning or coupled to a file; shared yields the full consumer set", () => {
|
|
28
|
+
const corpus = ["svc/api/a.js", "svc/web/b.js", "svc/worker/c.js", "shared/x.js", "docs/readme.md"];
|
|
29
|
+
for (const f of corpus) {
|
|
30
|
+
const r = recomputeAtCut(policy, { units: [] }, [f]);
|
|
31
|
+
const want = [...Object.entries(policy.units).filter(([, u]) => u.paths.some((p) => f.startsWith(p.replace("**", "")))).map(([id]) => id), ...(f.startsWith("shared/") ? ["api", "web", "worker"] : [])];
|
|
32
|
+
for (const u of want) assert.ok(r.units.includes(u), `${f} -> ${u}`);
|
|
33
|
+
}
|
|
34
|
+
assert.deepEqual(recomputeAtCut(policy, { units: [] }, ["shared/x.js"]).units, ["api", "web", "worker"]);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("trailers and branch", () => {
|
|
39
|
+
it("laneTrailers carries lane, release and epoch", () => assert.equal(laneTrailers({ lane: "train", release: "r1", epoch: 7 }), "Forge-Lane: train\nForge-Release: r1\nForge-Epoch: 7"));
|
|
40
|
+
it("trainBranch expands the pattern and rejects bad names", () => { assert.equal(trainBranch(policy, "2026-11-13", 2), "train/2026-11-13-2"); assert.equal(trainBranch({ branches: { train: "a b" } }, "d", 1), null); });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** Fake io: a wave of PRs with the given files; records every git/gh call. Live == default (rev-parse returns one sha). */
|
|
44
|
+
function world({ files = { 11: ["svc/api/a.js"] }, dirty = false, regenOk = true } = {}) {
|
|
45
|
+
const calls = { git: [], gh: [], rehearse: [] };
|
|
46
|
+
const A = "a".repeat(40), B = "b".repeat(40);
|
|
47
|
+
const io = {
|
|
48
|
+
git: (a) => { calls.git.push(a); if (a[0] === "rev-parse") return `${A}\n`; if (a[0] === "status") return dirty ? " M gen.json" : ""; return ""; },
|
|
49
|
+
gh: async (a) => {
|
|
50
|
+
calls.gh.push(a);
|
|
51
|
+
if (a[0] === "pr" && a[1] === "view" && a.includes("files")) return JSON.stringify({ files: (files[a[2]] ?? []).map((path) => ({ path })) });
|
|
52
|
+
if (a[0] === "pr" && a[1] === "create") return "https://github.com/o/r/pull/99";
|
|
53
|
+
if (a[0] === "pr" && a[1] === "view") return JSON.stringify({ state: "MERGED", mergeCommit: { oid: B } });
|
|
54
|
+
return "";
|
|
55
|
+
},
|
|
56
|
+
rehearse: async (c) => { calls.rehearse.push(c); return c === "live" ? { ok: true, output: JSON.stringify({ sha: A, units: { api: "sha256:old-api", web: "sha256:old-web" } }) } : { ok: c === "make gen" ? regenOk : true, output: "" }; },
|
|
57
|
+
now: () => 0, sleep: async () => {},
|
|
58
|
+
};
|
|
59
|
+
return { io, calls };
|
|
60
|
+
}
|
|
61
|
+
const mkctx = (w, extra = {}, pol = policy) => {
|
|
62
|
+
const state = { id: "rel-1", steps: {} };
|
|
63
|
+
const seen = { deploy: [], rollback: [] };
|
|
64
|
+
const ctx = { io: w.io, repo: "o/r", def: "main", state, save() {}, policy: pol, date: "2026-11-13", n: 1, config: { deploy: { live_release_command: "live", pipelines: { service: { workflow: "svc.yml", inputs: {} } } } }, ...extra };
|
|
65
|
+
ctx.ledger = { deployStep: async (c) => { seen.deploy.push(c); return extra.deployResult ?? {}; }, ...(extra.ledger ?? {}) };
|
|
66
|
+
return { state, ctx, seen };
|
|
67
|
+
};
|
|
68
|
+
const wave = [{ issue: 5, pr: 11, record: rec }];
|
|
69
|
+
|
|
70
|
+
describe("runReleaseTrain", () => {
|
|
71
|
+
it("demotes at CUT before creating any branch", async () => {
|
|
72
|
+
const w = world({ files: { 11: ["svc/api/migrations/1.sql"] } }); const { ctx } = mkctx(w);
|
|
73
|
+
const r = await runReleaseTrain(ctx, wave);
|
|
74
|
+
assert.equal(r.status, "demoted");
|
|
75
|
+
assert.ok(!w.calls.git.some((a) => a[0] === "push"));
|
|
76
|
+
});
|
|
77
|
+
it("ejects a widened issue and demotes when none remain", async () => {
|
|
78
|
+
const w = world({ files: { 11: ["svc/api/a.js", "svc/worker/w.js"] } }); const { ctx } = mkctx(w);
|
|
79
|
+
const r = await runReleaseTrain(ctx, wave);
|
|
80
|
+
assert.equal(r.status, "demoted"); assert.equal(r.ejected[0].issue, 5);
|
|
81
|
+
});
|
|
82
|
+
it("creates train/<date>-<n> from live, lands with the lane trailers and dispatches merge sha + units", async () => {
|
|
83
|
+
const w = world(); const { ctx, state, seen } = mkctx(w);
|
|
84
|
+
const r = await runReleaseTrain(ctx, wave);
|
|
85
|
+
assert.equal(r.status, "live");
|
|
86
|
+
assert.deepEqual(w.calls.git.find((a) => a[0] === "push"), ["push", "--quiet", "origin", `${"a".repeat(40)}:refs/heads/train/2026-11-13-1`]);
|
|
87
|
+
const merge = w.calls.gh.find((a) => a[1] === "merge" && a.includes("--body"));
|
|
88
|
+
assert.equal(merge[merge.indexOf("--body") + 1], "Forge-Lane: train\nForge-Release: rel-1");
|
|
89
|
+
assert.equal(state.lane, "train"); assert.deepEqual(state.train.previous, { api: "sha256:old-api" });
|
|
90
|
+
assert.equal(state.steps["post-merge"].result.merge, "b".repeat(40));
|
|
91
|
+
assert.deepEqual(seen.deploy[0].config.trainDispatch, { units: ["api"] });
|
|
92
|
+
assert.equal(seen.deploy[0].config.deployPipeline, "service");
|
|
93
|
+
});
|
|
94
|
+
it("a contract wave orders the producer first and runs regenerate before the push", async () => {
|
|
95
|
+
const w = world({ files: { 11: ["contract/x.json"] }, dirty: true });
|
|
96
|
+
const { ctx, state } = mkctx(w);
|
|
97
|
+
const r = await runReleaseTrain(ctx, [{ issue: 5, pr: 11, record: { units: ["api", "web"], migrations: "none", contract: true } }]);
|
|
98
|
+
assert.deepEqual(state.train.order, ["api", "web"]); assert.deepEqual(state.train.units, ["api", "web"]);
|
|
99
|
+
assert.ok(w.calls.rehearse.includes("make gen"));
|
|
100
|
+
const ci = w.calls.git.findIndex((a) => a[0] === "commit"), pi = w.calls.git.findIndex((a, i) => a[0] === "push" && i > ci);
|
|
101
|
+
assert.ok(ci >= 0 && pi > ci, "regenerate commit precedes the push");
|
|
102
|
+
assert.equal(r.status, "verifying"); // web is a web surface and no purge seam is set
|
|
103
|
+
});
|
|
104
|
+
it("a failing regenerate refuses", async () => {
|
|
105
|
+
const w = world({ files: { 11: ["contract/x.json"] }, regenOk: false }); const { ctx } = mkctx(w);
|
|
106
|
+
const r = await runReleaseTrain(ctx, [{ issue: 5, pr: 11, record: { units: ["api", "web"], contract: true } }]);
|
|
107
|
+
assert.equal(r.status, "refused");
|
|
108
|
+
});
|
|
109
|
+
it("on a deploy failure invokes rung 1 (flag) with the recorded digests", async () => {
|
|
110
|
+
const w = world(); const calls = [];
|
|
111
|
+
const { ctx, state } = mkctx(w, { deployResult: { blocked: true, reason: "smoke failed" } });
|
|
112
|
+
state.deploy = { target: { sha: "a".repeat(40) }, runId: 7, merge: "b".repeat(40) };
|
|
113
|
+
ctx.ledger.runRollback = async (c, a) => { calls.push({ digests: c.trainDigests, to: a.to }); return { rung: "flag", ok: true }; };
|
|
114
|
+
const r = await runReleaseTrain(ctx, wave);
|
|
115
|
+
assert.equal(r.status, "rolled-back");
|
|
116
|
+
assert.deepEqual(calls, [{ digests: { api: "sha256:old-api" }, to: "flag" }]);
|
|
117
|
+
});
|
|
118
|
+
it("refuses without deploy.pipelines.service", async () => {
|
|
119
|
+
const w = world(); const { ctx } = mkctx(w); ctx.config.deploy.pipelines = {};
|
|
120
|
+
assert.equal((await runReleaseTrain(ctx, wave)).status, "refused");
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe("web wave purge gate", () => {
|
|
125
|
+
const webWave = [{ issue: 5, pr: 11, record: { units: ["web"], migrations: "none", contract: false } }];
|
|
126
|
+
const run = (purge) => { const w = world({ files: { 11: ["svc/web/a.js"] } }); const m = mkctx(w, { purge }); return runReleaseTrain(m.ctx, webWave).then((r) => ({ r, state: m.state })); };
|
|
127
|
+
it("without a purge seam stays VERIFYING and never reaches live", async () => {
|
|
128
|
+
const { r, state } = await run(undefined);
|
|
129
|
+
assert.equal(r.status, "verifying"); assert.match(r.reason, /no purge seam/); assert.equal(state.train.state, "VERIFYING");
|
|
130
|
+
});
|
|
131
|
+
it("a failing purge stays VERIFYING with the reason", async () => {
|
|
132
|
+
const { r } = await run(async () => ({ ok: false, reason: "cdn 503" }));
|
|
133
|
+
assert.equal(r.status, "verifying"); assert.match(r.reason, /cdn 503/);
|
|
134
|
+
});
|
|
135
|
+
it("a successful purge proceeds to live", async () => {
|
|
136
|
+
let got; const { r, state } = await run(async (a) => { got = a; return { ok: true }; });
|
|
137
|
+
assert.equal(r.status, "live"); assert.deepEqual(got.units, ["web"]); assert.equal(state.train.state, "LIVE");
|
|
138
|
+
});
|
|
139
|
+
});
|