forgedock 1.57.0 → 1.58.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 +1 -1
- package/bin/engine-cli.mjs +2 -2
- package/bin/help-text.mjs +1 -1
- package/bin/lean/conformance.mjs +30 -3
- package/bin/lean/conformance.test.mjs +74 -0
- package/bin/lean/decisions.mjs +12 -0
- package/bin/lean/decisions.test.mjs +9 -0
- package/bin/lean/issuewatch-parity.mjs +4 -1
- package/bin/lean/issuewatch-parity.test.mjs +6 -0
- package/bin/lean/lean.mjs +41 -6
- package/bin/lean/lean.test.mjs +34 -1
- package/bin/lean/recovery.test.mjs +3 -3
- package/bin/lean/release-config.mjs +18 -7
- package/bin/lean/release-config.test.mjs +23 -0
- package/bin/lean/release-control.mjs +26 -3
- package/bin/lean/release-control.test.mjs +24 -0
- package/bin/lean/release-deploy.mjs +209 -0
- package/bin/lean/release-deploy.test.mjs +217 -0
- package/bin/lean/release-gates.mjs +230 -0
- package/bin/lean/release-gates.test.mjs +146 -0
- package/bin/lean/release-ledger.mjs +16 -0
- package/bin/lean/release-ledger.test.mjs +3 -3
- package/bin/lean/release-minutes.mjs +12 -2
- package/bin/lean/release-minutes.test.mjs +8 -0
- package/bin/lean/release-status.mjs +300 -0
- package/bin/lean/release-status.test.mjs +220 -0
- package/bin/lean/release-verify.mjs +221 -0
- package/bin/lean/release-verify.test.mjs +176 -0
- package/bin/lean/release.mjs +70 -6
- package/bin/lean/release.test.mjs +5 -1
- package/docs/CONFIG.md +20 -1
- package/package.json +1 -1
- package/scripts/ci-local/scoping.mjs +19 -0
- package/scripts/ci-local.test.sh +13 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Verification of a deployed release (#5562, epic #5549 Phase 3, invariants I19/I22): the VERIFYING stage between LIVE_CHECK and LIVE.
|
|
5
|
+
* Layers in order: (1) repo workflow results (smoke, edge gate, convergence), (2) the configured verification workflow, dispatched
|
|
6
|
+
* through `fenced()`, (3) the SLI soak against an injected read-only metric source, (4) each issue's `[check:id]`, (5) flag-gated
|
|
7
|
+
* features verified in the off state. Only then is `FORGE:VERIFIED <deploy sha>` written on each issue and the issue closed (I19).
|
|
8
|
+
* An input this module cannot read blocks (I5). Verification only reads production: every probe is an injected `io.metrics` or a
|
|
9
|
+
* default-branch check command, and the module has no write path of its own (I22, enforced by a static scan in the test).
|
|
10
|
+
* Rationale: devdocs/decisions/5562-release-verify.md.
|
|
11
|
+
*/
|
|
12
|
+
import { fenced } from "./release-fence.mjs";
|
|
13
|
+
import { runFor, finished, BOUNDS } from "./release-deploy.mjs";
|
|
14
|
+
import { INFRA_SIGNATURES } from "./release-flakes.mjs";
|
|
15
|
+
|
|
16
|
+
/** Soak minutes by risk class (design 6.4); `lanes.<lane>.soak_min` (a number or a map by class) overrides. */
|
|
17
|
+
export const SOAK_MIN = { low: 10, medium: 20, full: 30, p0: 15 };
|
|
18
|
+
const KEYS = ["workflow", "results", "slis", "post_deploy_checks_file", "flags", "close_requires"];
|
|
19
|
+
const TRANSPORT = /identity|unauthori[sz]ed|\b40[13]\b|ECONN|ETIMEDOUT|timed? ?out|certificate|\bdns\b|transport|\b50[234]\b/i;
|
|
20
|
+
const json = (s) => JSON.parse(String(s || "null"));
|
|
21
|
+
const blocked = (reason, extra = {}) => ({ blocked: true, reason, ...extra });
|
|
22
|
+
const hold = (reason, kind) => blocked(`${reason} (owner ask: decide rollback or fix; label needs-agent when no host is attached)`, { hold: { kind, label: "needs-agent" } });
|
|
23
|
+
const sameSha = (a, b) => !!a && !!b && (a.startsWith(b) || b.startsWith(a));
|
|
24
|
+
const short = (sha) => String(sha).slice(0, 8);
|
|
25
|
+
|
|
26
|
+
export const verifiedMarker = (sha) => `<!-- FORGE:VERIFIED ${sha} -->`;
|
|
27
|
+
/** True when a comment names the deploy sha in a `FORGE:VERIFIED <sha>` marker (the prod-watch `fp=` form never matches). */
|
|
28
|
+
export function hasVerified(comments, sha) {
|
|
29
|
+
return (comments ?? []).some((c) => [...String(c?.body ?? c ?? "").matchAll(/<!--\s*FORGE:VERIFIED\s+([0-9a-f]{7,64})\s*-->/gi)].some((m) => sameSha(m[1], sha)));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const verifyConfigured = (v) => !!v && KEYS.some((k) => v[k] != null && !(Array.isArray(v[k]) && !v[k].length));
|
|
33
|
+
|
|
34
|
+
/** Risk class of a release: p0 lane, a full-pipeline release, else medium. */
|
|
35
|
+
export const riskClass = (lane, pipeline) => (lane === "p0" ? "p0" : pipeline === "full" ? "full" : "medium");
|
|
36
|
+
|
|
37
|
+
export function soakMinutes(risk, override) {
|
|
38
|
+
const o = override && typeof override === "object" ? override[risk] : override;
|
|
39
|
+
return typeof o === "number" && o > 0 ? o : SOAK_MIN[risk] ?? SOAK_MIN.medium;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** SLI breaches of `{baseline, current}` readings beyond tolerance (default 20%); `worse: "lower"` for rates where a drop is bad. */
|
|
43
|
+
export function sliBreaches(slis, readings) {
|
|
44
|
+
return slis.filter((s) => {
|
|
45
|
+
const { baseline, current } = readings[s.name];
|
|
46
|
+
const tol = typeof s.tolerance === "number" ? s.tolerance : 0.2, abs = s.abs ?? 0;
|
|
47
|
+
return s.worse === "lower" ? current < baseline * (1 - tol) - abs : current > baseline * (1 + tol) + abs;
|
|
48
|
+
}).map((s) => ({ sli: s.name, ...readings[s.name] }));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** An emitted rollback trigger is recorded once and handed to the ladder's sink (#5563) when one is attached. */
|
|
52
|
+
function rollbackResult(ctx, st, reason) {
|
|
53
|
+
if (!st.rollback) { st.rollback = { reason }; ctx.save(); ctx.rollbackTrigger?.({ reason, sha: ctx.state.deploy?.merge }); }
|
|
54
|
+
return blocked(`${reason}; rollback trigger emitted to the ladder (#5563)`, { rollback: st.rollback });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function layerResults(ctx, v, sha, st, b) {
|
|
58
|
+
const { io, repo } = ctx;
|
|
59
|
+
for (const w of v.results ?? []) {
|
|
60
|
+
let run;
|
|
61
|
+
try { run = (json(await io.gh(["run", "list", "--repo", repo, "--workflow", w.workflow, "--commit", sha, "--json", "databaseId,status,conclusion", "--limit", "5"])) ?? []).find((r) => r.conclusion !== "skipped"); }
|
|
62
|
+
catch (e) { return blocked(`cannot read ${w.workflow} results (I5): ${String(e?.message ?? e).split("\n")[0]}`); }
|
|
63
|
+
if (!run || run.status !== "completed") return blocked(`${w.workflow} (${w.kind}) has no completed run for ${short(sha)}; resume once it finishes`);
|
|
64
|
+
if (run.conclusion === "success") continue;
|
|
65
|
+
if (w.kind === "convergence") { (st.convergence ??= []).push(`${w.workflow} run ${run.databaseId} ${run.conclusion}`); continue; }
|
|
66
|
+
let log = null; try { log = String(await io.gh(["run", "view", String(run.databaseId), "--repo", repo, "--log-failed"])); } catch { /* unreadable log */ }
|
|
67
|
+
if (log == null || TRANSPORT.test(log) || INFRA_SIGNATURES.some(([, re]) => re.test(log))) { // identity/transport: not evidence about the release
|
|
68
|
+
if (log != null && st.reverifies < 1) { st.reverifies += 1; ctx.save(); await io.sleep(b.pollMs); return layerResults(ctx, v, sha, st, b); }
|
|
69
|
+
return hold(`${w.workflow} (${w.kind}) run ${run.databaseId} failed on identity/transport after ${st.reverifies} re-verify; no blind rollback`, "verify-transport");
|
|
70
|
+
}
|
|
71
|
+
return rollbackResult(ctx, st, `${w.workflow} (${w.kind}) run ${run.databaseId} concluded ${run.conclusion}`);
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function layerWorkflow(ctx, v, sha, st, b) {
|
|
77
|
+
const r = await runFor(ctx, { workflow: v.workflow, sha, inputs: {}, key: `verify:${sha}`, startPolls: 1, b });
|
|
78
|
+
if (r.err) return blocked(r.err);
|
|
79
|
+
const stageS = ctx.config.deploy?.stage_timeout_s ?? BOUNDS.defaultStageS;
|
|
80
|
+
const done = await finished(ctx, v.workflow, sha, Math.ceil(stageS * 1000 / b.runPollMs), b);
|
|
81
|
+
if (!done) return blocked(`${v.workflow} run ${r.run.databaseId} did not finish within stage_timeout_s; resume (never redispatched)`);
|
|
82
|
+
return done.conclusion === "success" ? null : rollbackResult(ctx, st, `${v.workflow} run ${done.databaseId} concluded ${done.conclusion}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function layerSoak(ctx, v, sha, st) {
|
|
86
|
+
const { io } = ctx, slis = v.slis ?? [];
|
|
87
|
+
if (!io.metrics) { st.sli = "skipped (no host)"; return null; }
|
|
88
|
+
if (!slis.length) { st.sli = "skipped (no slis configured)"; return null; }
|
|
89
|
+
const min = soakMinutes(ctx.config.verifyRisk ?? "medium", ctx.config.verifySoak);
|
|
90
|
+
st.soakStart ??= io.now(); ctx.save();
|
|
91
|
+
const wait = st.soakStart + min * 60_000 - io.now();
|
|
92
|
+
if (wait > 0) await io.sleep(wait);
|
|
93
|
+
const readings = {};
|
|
94
|
+
for (const s of slis) {
|
|
95
|
+
let r; try { r = await io.metrics({ sli: s, minutes: min, sha }); } catch (e) { return blocked(`cannot read SLI ${s.name} (I5): ${String(e?.message ?? e).split("\n")[0]}`); }
|
|
96
|
+
if (![r?.baseline, r?.current].every(Number.isFinite)) return blocked(`SLI ${s.name} returned no baseline/current (I5)`);
|
|
97
|
+
readings[s.name] = { baseline: r.baseline, current: r.current };
|
|
98
|
+
}
|
|
99
|
+
const bad = sliBreaches(slis, readings);
|
|
100
|
+
if (bad.length) return rollbackResult(ctx, st, `SLI breach over ${min} min: ${bad.map((x) => `${x.sli} ${x.current} vs baseline ${x.baseline}`).join(", ")}`);
|
|
101
|
+
st.sli = `pass (${min} min soak, ${slis.length} sli)`;
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function readIssue(ctx, n) {
|
|
106
|
+
return json(await ctx.io.gh(["issue", "view", String(n), "--repo", ctx.repo, "--json", "state,body,comments"])) ?? {};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Windowed checks are follow-ups on the rollup issue and never block the close. */
|
|
110
|
+
async function followUp(ctx, st, id, issue, entry, sha) {
|
|
111
|
+
const key = `${issue}:${id}`;
|
|
112
|
+
if (st.followups.includes(key)) return;
|
|
113
|
+
try {
|
|
114
|
+
const [roll] = json(await ctx.io.gh(["issue", "list", "--repo", ctx.repo, "--state", "open", "--search", "FORGE:POSTDEPLOY_ROLLUP in:body", "--json", "number", "--limit", "1"])) ?? [];
|
|
115
|
+
if (roll) await ctx.io.gh(["issue", "comment", String(roll.number), "--repo", ctx.repo, "--body", `- [ ] [check:${id}] windowed (${entry.for}) for #${issue} at deploy ${short(sha)}`]);
|
|
116
|
+
} catch { /* a follow-up that cannot be filed does not block the close */ }
|
|
117
|
+
st.followups.push(key); ctx.save();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function layerChecks(ctx, v, sha, st, issues) {
|
|
121
|
+
if (!v.post_deploy_checks_file || !issues.length) return null;
|
|
122
|
+
const want = [];
|
|
123
|
+
for (const n of issues) {
|
|
124
|
+
let info; try { info = await readIssue(ctx, n); } catch (e) { return blocked(`cannot read issue #${n} (I5): ${String(e?.message ?? e).split("\n")[0]}`); }
|
|
125
|
+
for (const m of String(info.body ?? "").matchAll(/\[check:([\w.-]+)\]/g)) want.push([n, m[1]]);
|
|
126
|
+
}
|
|
127
|
+
if (!want.length) return null;
|
|
128
|
+
let table; // the registry comes from the default branch, never the working tree (I13)
|
|
129
|
+
try { table = json(ctx.io.git(["show", `origin/${ctx.def}:${v.post_deploy_checks_file}`])); } catch (e) { return blocked(`cannot read ${v.post_deploy_checks_file} from origin/${ctx.def} (I13, I5): ${String(e?.message ?? e).split("\n")[0]}`); }
|
|
130
|
+
for (const [n, id] of want) {
|
|
131
|
+
const entry = table?.[id];
|
|
132
|
+
if (!entry?.run) return blocked(`#${n} names [check:${id}] but ${v.post_deploy_checks_file} has no such check`);
|
|
133
|
+
if (entry.for) { await followUp(ctx, st, id, n, entry, sha); continue; }
|
|
134
|
+
if (st.checks[id] === "pass") continue; // each check runs once
|
|
135
|
+
const r = await ctx.io.rehearse(entry.run, { timeout: (entry.timeout ?? 120) * 1000 });
|
|
136
|
+
if (!r?.ok) return hold(`post-deploy check ${id} (#${n}) failed: ${String(r?.output ?? "").trim().slice(-200)}`, "check");
|
|
137
|
+
st.checks[id] = "pass"; ctx.save();
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function layerFlags(ctx, v, st) {
|
|
143
|
+
for (const f of v.flags ?? []) {
|
|
144
|
+
if (st.flags[f.flag] === "off") continue;
|
|
145
|
+
const r = await ctx.io.rehearse(f.off_command, { timeout: 120_000 }); // observes the off state; activation is never performed
|
|
146
|
+
if (!r?.ok) return hold(`flag ${f.flag} could not be verified in the off state: ${String(r?.output ?? "").trim().slice(-200)}`, "flag");
|
|
147
|
+
st.flags[f.flag] = "off"; ctx.save();
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** CLOSING guard (I19): with `mode: verified` an issue closes only when a `FORGE:VERIFIED` names the deploy sha; `deployed` is the opt-out. */
|
|
153
|
+
export async function closeIssues(ctx, { issues, sha, mode = "verified" }) {
|
|
154
|
+
const { io, repo } = ctx, closed = [], refused = [];
|
|
155
|
+
for (const n of issues) {
|
|
156
|
+
let info; try { info = await readIssue(ctx, n); } catch (e) { refused.push({ issue: n, why: `unreadable: ${String(e?.message ?? e).split("\n")[0]}` }); continue; }
|
|
157
|
+
if (String(info.state).toUpperCase() === "CLOSED") continue;
|
|
158
|
+
if (mode !== "deployed" && !hasVerified(info.comments, sha)) { refused.push({ issue: n, why: `no FORGE:VERIFIED ${short(sha)}` }); continue; }
|
|
159
|
+
const key = `${ctx.fence?.lease?.release ?? ctx.state.id ?? "-"}:verify:${ctx.fence?.lease?.epoch ?? 0}:close:${n}`;
|
|
160
|
+
const f = await fenced(ctx.fence, { action: "close", key }, () => io.gh(["issue", "close", String(n), "--repo", repo, "--comment", `Released and verified at ${short(sha)}.`]));
|
|
161
|
+
if (f.refused) refused.push({ issue: n, why: f.refused }); else closed.push(n);
|
|
162
|
+
}
|
|
163
|
+
return { closed, refused };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Issue numbers of the release (the release record, else the release-PR step). */
|
|
167
|
+
export function releaseIssues(state) {
|
|
168
|
+
const raw = state.release?.issues ?? state.steps?.["release-pr"]?.result?.issues ?? [];
|
|
169
|
+
return raw.map((i) => Number(i?.number ?? i)).filter(Number.isInteger);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Run the layers (resumable: `state.verify` records each passed layer, so a resume re-runs none and redispatches nothing).
|
|
174
|
+
* @returns {Promise<{verified: true, outcome, sli, closed}|{blocked: true, reason, hold?, rollback?}>}
|
|
175
|
+
*/
|
|
176
|
+
export async function verifyStep(ctx, sha) {
|
|
177
|
+
const v = ctx.config.verify, { io } = ctx;
|
|
178
|
+
const st = (ctx.state.verify ??= { layers: {}, reverifies: 0, checks: {}, flags: {}, followups: [] });
|
|
179
|
+
const b = { ...BOUNDS, ...(ctx.config.deployBounds ?? {}) };
|
|
180
|
+
const issues = releaseIssues(ctx.state);
|
|
181
|
+
const layers = [
|
|
182
|
+
["results", () => layerResults(ctx, v, sha, st, b), !!v.results?.length],
|
|
183
|
+
["workflow", () => layerWorkflow(ctx, v, sha, st, b), !!v.workflow],
|
|
184
|
+
["sli", () => layerSoak(ctx, v, sha, st), true],
|
|
185
|
+
["checks", () => layerChecks(ctx, v, sha, st, issues), true],
|
|
186
|
+
["flags", () => layerFlags(ctx, v, st), !!v.flags?.length],
|
|
187
|
+
];
|
|
188
|
+
for (const [name, run, on] of layers) {
|
|
189
|
+
if (!on || st.layers[name]) continue;
|
|
190
|
+
const r = await run();
|
|
191
|
+
if (r) return r;
|
|
192
|
+
st.layers[name] = "pass"; ctx.save();
|
|
193
|
+
}
|
|
194
|
+
io.print?.(`release verify ${short(sha)}: sli: ${st.sli ?? "n/a"}`);
|
|
195
|
+
if (st.convergence?.length) {
|
|
196
|
+
st.outcome = "released-with-convergence-failures";
|
|
197
|
+
if (!st.repair) {
|
|
198
|
+
st.repair = true; ctx.save();
|
|
199
|
+
await io.gh(["issue", "create", "--repo", ctx.repo, "--title", `released-with-convergence-failures: ${short(sha)}`, "--body", `Deploy and smoke are green; convergence failed (no rollback):\n${st.convergence.map((c) => `- ${c}`).join("\n")}`]);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
for (const n of issues) { // every layer passed: the evidence comment, then the guarded close
|
|
203
|
+
const info = await readIssue(ctx, n).catch(() => null);
|
|
204
|
+
if (info && !hasVerified(info.comments, sha)) await io.gh(["issue", "comment", String(n), "--repo", ctx.repo, "--body", `${verifiedMarker(sha)}\nrelease verified at ${short(sha)} (${Object.keys(st.layers).join(", ")}).`]);
|
|
205
|
+
}
|
|
206
|
+
const c = await closeIssues(ctx, { issues, sha, mode: v.close_requires ?? "verified" });
|
|
207
|
+
if (c.refused.length) return blocked(`CLOSING refused (I19): ${c.refused.map((r) => `#${r.issue} ${r.why}`).join("; ")}`);
|
|
208
|
+
return { verified: true, outcome: st.outcome ?? "verified", sli: st.sli ?? null, closed: c.closed };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** `forgedock release verify <id>`: re-run the verification of a deployed release from its local record. */
|
|
212
|
+
export async function verifyReleaseById({ io, state, save, def, policy, lane }) {
|
|
213
|
+
const sha = state?.deploy?.merge;
|
|
214
|
+
if (!sha || !["LIVE_CHECKED", "VERIFYING", "LIVE"].includes(state.deploy.phase)) return blocked("release has not passed LIVE_CHECK; nothing to verify yet");
|
|
215
|
+
const pipeline = policy?.lanes?.[lane]?.pipeline ?? "full";
|
|
216
|
+
const config = { deploy: policy?.deploy, verify: policy?.verify, verifyRisk: riskClass(lane, pipeline), verifySoak: policy?.lanes?.[lane]?.soak_min };
|
|
217
|
+
if (!verifyConfigured(config.verify)) return blocked("verify policy is not configured (.forge/release.yaml verify)");
|
|
218
|
+
const r = await verifyStep({ io, repo: state.repo, def, config, state, save }, sha);
|
|
219
|
+
io.print(r.verified ? `release verify ${state.id}: ${r.outcome}; sli: ${r.sli ?? "n/a"}; closed ${r.closed.length} issue(s)` : `release verify ${state.id}: blocked: ${r.reason}`);
|
|
220
|
+
return r;
|
|
221
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
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 { readFileSync } from "node:fs";
|
|
6
|
+
import { verifyStep, closeIssues, hasVerified, verifiedMarker, soakMinutes, sliBreaches, verifyConfigured, verifyReleaseById, SOAK_MIN } from "./release-verify.mjs";
|
|
7
|
+
import { validatePolicy } from "./release-config.mjs";
|
|
8
|
+
|
|
9
|
+
const SHA = "a".repeat(40);
|
|
10
|
+
const TABLE = { smoke1: { run: "check smoke1", timeout: 5 }, win1: { run: "check win1", for: "7d" } };
|
|
11
|
+
|
|
12
|
+
/** World: `runs` by workflow, `issues` by number {state, body, comments[]}; records every gh call and rehearsed command. */
|
|
13
|
+
function world(o = {}) {
|
|
14
|
+
const w = { runs: {}, issues: { 7: { state: "OPEN", body: "does X [check:smoke1]", comments: [] } }, gh: [], ran: [], logs: {}, rollups: [{ number: 99 }], metrics: undefined, table: TABLE, checkOk: true, ...o };
|
|
15
|
+
const io = {
|
|
16
|
+
print: () => {}, sleep: async () => {}, now: () => 1_000,
|
|
17
|
+
git: (a) => { if (w.table == null) throw new Error("no such file"); return JSON.stringify(w.table); },
|
|
18
|
+
rehearse: async (cmd) => { w.ran.push(cmd); return { ok: w.checkOk, output: "boom" }; },
|
|
19
|
+
gh: async (a) => {
|
|
20
|
+
w.gh.push(a.join(" "));
|
|
21
|
+
if (a[0] === "run" && a[1] === "list") { if (w.unreadable) throw new Error("HTTP 502"); const r = w.runs[a[a.indexOf("--workflow") + 1]]; return JSON.stringify(r ? [r] : []); }
|
|
22
|
+
if (a[0] === "run" && a[1] === "view") return w.logs[a[2]] ?? "";
|
|
23
|
+
if (a[0] === "workflow") { const wf = a[2]; w.runs[wf] ??= w.dispatchRun ?? { databaseId: 50, status: "completed", conclusion: "success" }; return ""; }
|
|
24
|
+
if (a[0] === "issue" && a[1] === "view") { const i = w.issues[a[2]]; if (!i) throw new Error("not found"); return JSON.stringify(i); }
|
|
25
|
+
if (a[0] === "issue" && a[1] === "list") return JSON.stringify(w.rollups);
|
|
26
|
+
if (a[0] === "issue" && a[1] === "comment") { const i = w.issues[a[2]]; if (i) i.comments.push({ body: a[a.indexOf("--body") + 1] }); return ""; }
|
|
27
|
+
if (a[0] === "issue" && (a[1] === "close" || a[1] === "create")) { if (a[1] === "close") w.issues[a[2]].state = "CLOSED"; return ""; }
|
|
28
|
+
throw new Error(`unexpected gh ${a.join(" ")}`);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
if (w.metrics) io.metrics = w.metrics;
|
|
32
|
+
return { w, io };
|
|
33
|
+
}
|
|
34
|
+
const ok = { databaseId: 5, status: "completed", conclusion: "success" };
|
|
35
|
+
const mk = (io, verify, over = {}) => ({ io, repo: "o/r", def: "main", config: { verify, verifyRisk: "full", deployBounds: { pollMs: 1, runPollMs: 1 } }, state: { id: "r1", repo: "o/r", release: { issues: [7] }, deploy: { merge: SHA, phase: "VERIFYING" } }, save() {}, ...over });
|
|
36
|
+
|
|
37
|
+
describe("release verify (#5562)", () => {
|
|
38
|
+
it("defaults: soak minutes by risk class, overridable; verifyConfigured is off for an empty block", () => {
|
|
39
|
+
assert.deepEqual(SOAK_MIN, { low: 10, medium: 20, full: 30, p0: 15 });
|
|
40
|
+
assert.equal(soakMinutes("p0"), 15); assert.equal(soakMinutes("full", 45), 45); assert.equal(soakMinutes("low", { low: 3 }), 3);
|
|
41
|
+
assert.equal(verifyConfigured({}), false); assert.equal(verifyConfigured({ slis: [] }), false); assert.equal(verifyConfigured({ close_requires: "verified" }), true);
|
|
42
|
+
});
|
|
43
|
+
it("the policy schema accepts the verify layer keys", () => {
|
|
44
|
+
const r = validatePolicy({ schema: 1, verify: { workflow: "v.yml", results: [{ workflow: "smoke.yml", kind: "smoke" }], flags: [{ flag: "F", off_command: "x" }], slis: [], close_requires: "verified" } });
|
|
45
|
+
assert.ok(!JSON.stringify(r).includes("verify."), JSON.stringify(r));
|
|
46
|
+
});
|
|
47
|
+
it("layer 1: green results pass; an unreadable source blocks (I5); a missing run blocks", async () => {
|
|
48
|
+
const v = { results: [{ workflow: "smoke.yml", kind: "smoke" }], close_requires: "deployed" };
|
|
49
|
+
let { w, io } = world({ runs: { "smoke.yml": ok } });
|
|
50
|
+
assert.equal((await verifyStep(mk(io, v), SHA)).verified, true);
|
|
51
|
+
({ w, io } = world({ unreadable: true }));
|
|
52
|
+
assert.match((await verifyStep(mk(io, v), SHA)).reason, /cannot read smoke.yml results \(I5\)/);
|
|
53
|
+
({ io } = world({ runs: {} }));
|
|
54
|
+
assert.match((await verifyStep(mk(io, v), SHA)).reason, /no completed run/);
|
|
55
|
+
});
|
|
56
|
+
it("layer 1: a real smoke failure emits the rollback trigger once", async () => {
|
|
57
|
+
const v = { results: [{ workflow: "smoke.yml", kind: "smoke" }] };
|
|
58
|
+
const { io } = world({ runs: { "smoke.yml": { databaseId: 5, status: "completed", conclusion: "failure" } }, logs: { 5: "assertion failed: /health returned wrong body" } });
|
|
59
|
+
const trig = []; const c = mk(io, v, { rollbackTrigger: (t) => trig.push(t) });
|
|
60
|
+
const r = await verifyStep(c, SHA); const r2 = await verifyStep(c, SHA);
|
|
61
|
+
assert.ok(r.rollback); assert.ok(r2.rollback); assert.equal(trig.length, 1);
|
|
62
|
+
});
|
|
63
|
+
it("smoke identity/transport failure: one re-verify, then hold, never a rollback", async () => {
|
|
64
|
+
const v = { results: [{ workflow: "smoke.yml", kind: "smoke" }] };
|
|
65
|
+
const { w, io } = world({ runs: { "smoke.yml": { databaseId: 5, status: "completed", conclusion: "failure" } }, logs: { 5: "HTTP 401 unauthorized" } });
|
|
66
|
+
const c = mk(io, v), trig = []; c.rollbackTrigger = (t) => trig.push(t);
|
|
67
|
+
const r = await verifyStep(c, SHA);
|
|
68
|
+
assert.equal(r.hold?.label, "needs-agent"); assert.equal(c.state.verify.reverifies, 1); assert.equal(trig.length, 0); assert.equal(r.rollback, undefined);
|
|
69
|
+
assert.equal(w.gh.filter((g) => g.startsWith("run list")).length, 2, "exactly one re-verify read");
|
|
70
|
+
});
|
|
71
|
+
it("a convergence failure with smoke green is released-with-convergence-failures: repair issue, no rollback", async () => {
|
|
72
|
+
const v = { results: [{ workflow: "smoke.yml", kind: "smoke" }, { workflow: "conv.yml", kind: "convergence" }], close_requires: "deployed" };
|
|
73
|
+
const { w, io } = world({ runs: { "smoke.yml": ok, "conv.yml": { databaseId: 6, status: "completed", conclusion: "failure" } } });
|
|
74
|
+
const r = await verifyStep(mk(io, v), SHA);
|
|
75
|
+
assert.equal(r.outcome, "released-with-convergence-failures");
|
|
76
|
+
assert.equal(w.gh.filter((g) => g.startsWith("issue create")).length, 1);
|
|
77
|
+
});
|
|
78
|
+
it("layer 2: the verification workflow is dispatched once through fenced() and its failure triggers rollback", async () => {
|
|
79
|
+
const v = { workflow: "verify.yml", close_requires: "deployed" };
|
|
80
|
+
let { w, io } = world();
|
|
81
|
+
const calls = []; const fence = { lctx: { io: { api: async () => ({ content: Buffer.from(JSON.stringify({ epoch: 3, lease: { holder: "h", epoch: 3 } })).toString("base64") }) }, repo: "o/r" }, lease: { holder: "h", epoch: 3, release: "r" }, now: () => "t", record: async (r) => calls.push(r) };
|
|
82
|
+
const c = mk(io, v, { fence });
|
|
83
|
+
assert.equal((await verifyStep(c, SHA)).verified, true);
|
|
84
|
+
assert.equal(w.gh.filter((g) => g.startsWith("workflow run")).length, 1);
|
|
85
|
+
assert.ok(calls.some((i) => i.action === "dispatch" && i.epoch === 3 && /verify:/.test(i.key)));
|
|
86
|
+
({ w, io } = world({ dispatchRun: { databaseId: 50, status: "completed", conclusion: "failure" } }));
|
|
87
|
+
assert.ok((await verifyStep(mk(io, v), SHA)).rollback);
|
|
88
|
+
});
|
|
89
|
+
it("layer 2: a dispatch intent already recorded is never repeated on resume", async () => {
|
|
90
|
+
const { w, io } = world();
|
|
91
|
+
const c = mk(io, { workflow: "verify.yml" }, { state: { id: "r1", release: { issues: [] }, deploy: { merge: SHA }, intents: [{ action: "dispatch", key: `r1:deploy:0:verify:${SHA}` }] } });
|
|
92
|
+
const r = await verifyStep(c, SHA);
|
|
93
|
+
assert.match(r.reason, /already recorded/); assert.equal(w.gh.filter((g) => g.startsWith("workflow run")).length, 0);
|
|
94
|
+
});
|
|
95
|
+
it("layer 3: an SLI breach in a fixture series emits the rollback trigger; within tolerance passes", async () => {
|
|
96
|
+
const slis = [{ name: "5xx", tolerance: 0.1 }, { name: "success", worse: "lower", tolerance: 0.05 }];
|
|
97
|
+
const series = (cur) => async ({ sli }) => ({ baseline: 100, current: cur[sli.name] });
|
|
98
|
+
let { io } = world({ metrics: series({ "5xx": 150, success: 100 }) });
|
|
99
|
+
const trig = []; const c = mk(io, { slis, close_requires: "deployed" }); c.rollbackTrigger = (t) => trig.push(t);
|
|
100
|
+
const r = await verifyStep(c, SHA);
|
|
101
|
+
assert.match(r.reason, /SLI breach over 30 min: 5xx 150/); assert.equal(trig.length, 1);
|
|
102
|
+
({ io } = world({ metrics: series({ "5xx": 105, success: 97 }) }));
|
|
103
|
+
const ok2 = await verifyStep(mk(io, { slis, close_requires: "deployed" }), SHA);
|
|
104
|
+
assert.equal(ok2.verified, true); assert.match(ok2.sli, /pass \(30 min soak, 2 sli\)/);
|
|
105
|
+
assert.deepEqual(sliBreaches([{ name: "a" }], { a: { baseline: 10, current: 13 } }).map((x) => x.sli), ["a"]);
|
|
106
|
+
});
|
|
107
|
+
it("layer 3: no metric source skips and says so; an unreadable metric blocks (I5)", async () => {
|
|
108
|
+
const v = { slis: [{ name: "5xx" }], close_requires: "deployed" };
|
|
109
|
+
let { io } = world();
|
|
110
|
+
const lines = []; io.print = (l) => lines.push(l);
|
|
111
|
+
const r = await verifyStep(mk(io, v), SHA);
|
|
112
|
+
assert.equal(r.sli, "skipped (no host)"); assert.ok(lines.some((l) => l.includes("sli: skipped (no host)")));
|
|
113
|
+
({ io } = world({ metrics: async () => { throw new Error("prometheus down"); } }));
|
|
114
|
+
assert.match((await verifyStep(mk(io, v), SHA)).reason, /cannot read SLI 5xx \(I5\)/);
|
|
115
|
+
});
|
|
116
|
+
it("layer 4: each check runs once, from the default branch; an unreadable registry blocks; windowed checks become follow-ups", async () => {
|
|
117
|
+
const v = { post_deploy_checks_file: ".forge/post-deploy-checks.json", close_requires: "deployed" };
|
|
118
|
+
let { w, io } = world({ issues: { 7: { state: "OPEN", body: "[check:smoke1] [check:win1]", comments: [] }, 8: { state: "OPEN", body: "[check:smoke1]", comments: [] } } });
|
|
119
|
+
const c = mk(io, v); c.state.release.issues = [7, 8];
|
|
120
|
+
assert.equal((await verifyStep(c, SHA)).verified, true);
|
|
121
|
+
assert.deepEqual(w.ran, ["check smoke1"], "smoke1 runs once for two issues; windowed win1 never runs");
|
|
122
|
+
assert.ok(w.gh.some((g) => g.startsWith("issue comment 99") && g.includes("[check:win1]")));
|
|
123
|
+
({ io } = world({ table: null }));
|
|
124
|
+
assert.match((await verifyStep(mk(io, v), SHA)).reason, /cannot read .* from origin\/main \(I13, I5\)/);
|
|
125
|
+
({ io } = world({ checkOk: false }));
|
|
126
|
+
assert.equal((await verifyStep(mk(io, v), SHA)).hold?.kind, "check");
|
|
127
|
+
});
|
|
128
|
+
it("layer 5: a flag-gated feature is verified off and never activated", async () => {
|
|
129
|
+
const { w, io } = world();
|
|
130
|
+
const r = await verifyStep(mk(io, { flags: [{ flag: "NEW_UI", off_command: "flag-state NEW_UI off" }], close_requires: "deployed" }), SHA);
|
|
131
|
+
assert.equal(r.verified, true); assert.deepEqual(w.ran, ["flag-state NEW_UI off"]);
|
|
132
|
+
const bad = world({ checkOk: false });
|
|
133
|
+
assert.equal((await verifyStep(mk(bad.io, { flags: [{ flag: "NEW_UI", off_command: "x" }] }), SHA)).hold?.kind, "flag");
|
|
134
|
+
});
|
|
135
|
+
it("I19: close is refused without FORGE:VERIFIED naming the deploy sha, allowed with it; deployed mode opts out", async () => {
|
|
136
|
+
const { w, io } = world({ issues: { 7: { state: "OPEN", body: "", comments: [{ body: verifiedMarker("b".repeat(40)) }] } } });
|
|
137
|
+
const c = mk(io, {});
|
|
138
|
+
let r = await closeIssues(c, { issues: [7], sha: SHA });
|
|
139
|
+
assert.equal(r.closed.length, 0); assert.match(r.refused[0].why, /no FORGE:VERIFIED/); assert.ok(!w.gh.some((g) => g.startsWith("issue close")));
|
|
140
|
+
w.issues[7].comments.push({ body: verifiedMarker(SHA) });
|
|
141
|
+
r = await closeIssues(c, { issues: [7], sha: SHA }); assert.deepEqual(r.closed, [7]);
|
|
142
|
+
w.issues[7].state = "OPEN"; w.issues[7].comments = [];
|
|
143
|
+
assert.deepEqual((await closeIssues(c, { issues: [7], sha: SHA, mode: "deployed" })).closed, [7]);
|
|
144
|
+
assert.equal(hasVerified([{ body: "<!-- FORGE:VERIFIED fp=abc123 -->" }], SHA), false);
|
|
145
|
+
});
|
|
146
|
+
it("end to end: verified issue gets the marker comment then closes; resume repeats no dispatch, check or comment", async () => {
|
|
147
|
+
const v = { workflow: "verify.yml", post_deploy_checks_file: "f.json" };
|
|
148
|
+
const { w, io } = world();
|
|
149
|
+
const c = mk(io, v);
|
|
150
|
+
const r = await verifyStep(c, SHA);
|
|
151
|
+
assert.equal(r.verified, true); assert.deepEqual(r.closed, [7]);
|
|
152
|
+
assert.ok(hasVerified(w.issues[7].comments, SHA));
|
|
153
|
+
const before = w.gh.filter((g) => /^(workflow run|issue comment)/.test(g)).length, ran = w.ran.length;
|
|
154
|
+
w.issues[7].state = "OPEN"; await verifyStep(c, SHA);
|
|
155
|
+
assert.equal(w.gh.filter((g) => /^(workflow run|issue comment)/.test(g)).length, before); assert.equal(w.ran.length, ran);
|
|
156
|
+
});
|
|
157
|
+
it("verifyReleaseById refuses before LIVE_CHECK and runs the layers after it", async () => {
|
|
158
|
+
const { io } = world();
|
|
159
|
+
assert.match((await verifyReleaseById({ io, state: { id: "r1", deploy: { phase: "DEPLOYING" } }, save() {}, def: "main", policy: {} })).reason, /LIVE_CHECK/);
|
|
160
|
+
const state = { id: "r1", repo: "o/r", release: { issues: [] }, deploy: { phase: "LIVE", merge: SHA } };
|
|
161
|
+
assert.equal((await verifyReleaseById({ io, state, save() {}, def: "main", policy: { verify: { close_requires: "deployed" } }, lane: "p0" })).verified, true);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
/** I22 scanner: write verbs against production in a module's source. */
|
|
166
|
+
const WRITE_VERBS = [/\bssh\s/, /\bscp\s/, /\bsystemctl\b/, /\bdocker\s+(run|exec|rm|stop|restart|kill|compose|build|push|cp)\b/, /\b(INSERT\s+INTO|UPDATE\s+\w+\s+SET|DELETE\s+FROM|DROP\s+TABLE|ALTER\s+TABLE|TRUNCATE)\b/i, /\bkubectl\s+(apply|delete|scale|rollout)\b/];
|
|
167
|
+
const writeVerbs = (src) => WRITE_VERBS.filter((re) => re.test(src)).map(String);
|
|
168
|
+
|
|
169
|
+
describe("release verify I22: no write path to production", () => {
|
|
170
|
+
it("the module has no write verbs", () => {
|
|
171
|
+
assert.deepEqual(writeVerbs(readFileSync(new URL("./release-verify.mjs", import.meta.url), "utf8")), []);
|
|
172
|
+
});
|
|
173
|
+
it("the scan fails on a seeded violation", () => {
|
|
174
|
+
for (const bad of ["await sh('ssh prod systemctl restart api')", "run(`docker exec app sh`)", "q('DELETE FROM users')"]) assert.ok(writeVerbs(bad).length, bad);
|
|
175
|
+
});
|
|
176
|
+
});
|
package/bin/lean/release.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* live in release-review.mjs / release-postmerge.mjs (stubs that block until their parts land). Promotion is opt-in: without
|
|
9
9
|
* `--merge` or forge.yaml `release.auto_merge: true` the job stops at GATE_PASS and prints the merge command.
|
|
10
10
|
*/
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync } from "node:fs";
|
|
12
12
|
import { execFileSync } from "node:child_process";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
import { join } from "node:path";
|
|
@@ -18,19 +18,22 @@ import { ghRunner } from "./issuewatch.mjs";
|
|
|
18
18
|
import { parseForgeYaml } from "../forge-utils.mjs";
|
|
19
19
|
import { reviewStep, fixStep } from "./release-review.mjs";
|
|
20
20
|
import { postMergeStep } from "./release-postmerge.mjs";
|
|
21
|
+
import { deployStep } from "./release-deploy.mjs";
|
|
22
|
+
import { riskClass } from "./release-verify.mjs";
|
|
21
23
|
import { rehearsalStep, parseRehearsalConfig } from "./release-rehearsal.mjs";
|
|
22
24
|
import { budgetReportLine, releaseRuns, detectBudget, readCiPolicy } from "./ci-budget.mjs";
|
|
23
25
|
import { parseNightlyConfig, readNightly, blocksRelease, fileNightlyRed } from "./release-nightly.mjs";
|
|
24
|
-
import { parseBudgetConfig, applyOnExceed, waveReport, trailingMedian, historyFromRoot, releaseMinutes } from "./release-minutes.mjs";
|
|
26
|
+
import { parseBudgetConfig, applyOnExceed, waveReport, trailingMedian, historyFromRoot, gateHistoryFromRoot, releaseMinutes } from "./release-minutes.mjs";
|
|
25
27
|
import { cutSnapshot, writeRecord, checkChain, verifyRelease, DEFAULT_PATTERN } from "./release-snapshot.mjs";
|
|
26
28
|
import { createReleaseLedger, writeRelease, readLedger, acquireLease, heartbeat } from "./release-ledger.mjs";
|
|
27
29
|
import { fenced, epochTrailer } from "./release-fence.mjs";
|
|
28
30
|
import { holdCheck, exemptionsSection, VERBS as CONTROL_VERBS } from "./release-control.mjs";
|
|
29
31
|
import { parseFlakeConfig, classifyFailure, planRerun, flakeEntry, recordFlakes, readFlakes } from "./release-flakes.mjs";
|
|
30
32
|
import { readActive } from "./release-ledger.mjs";
|
|
33
|
+
import { statusFromCli, policyFromYaml } from "./release-status.mjs";
|
|
31
34
|
import { hostPreflightStep, markReadyStep, parsePreflightConfig } from "./release-preflight.mjs";
|
|
32
35
|
|
|
33
|
-
export const RELEASE_STEPS = ["preflight", "host-preflight", "release-pr", "review", "fixes", "mark-ready", "rehearsal", "promotion", "post-merge"];
|
|
36
|
+
export const RELEASE_STEPS = ["preflight", "host-preflight", "release-pr", "review", "fixes", "mark-ready", "rehearsal", "promotion", "post-merge", "deploy"];
|
|
34
37
|
const ID_RE = /^r\d{8}-\d{6}-\d+$/;
|
|
35
38
|
const BLOCKED_EXIT = 3;
|
|
36
39
|
|
|
@@ -299,7 +302,7 @@ async function promotionStep(ctx) {
|
|
|
299
302
|
return { merged: true, head, gate };
|
|
300
303
|
}
|
|
301
304
|
|
|
302
|
-
const OPTIONAL_STEPS = ["host-preflight", "mark-ready"];
|
|
305
|
+
const OPTIONAL_STEPS = ["host-preflight", "mark-ready", "deploy"];
|
|
303
306
|
|
|
304
307
|
const STEP_FNS = {
|
|
305
308
|
preflight: preflightStep,
|
|
@@ -311,6 +314,7 @@ const STEP_FNS = {
|
|
|
311
314
|
rehearsal: (ctx) => rehearsalStep(ctx),
|
|
312
315
|
promotion: promotionStep,
|
|
313
316
|
"post-merge": (ctx) => postMergeStep(ctx),
|
|
317
|
+
deploy: (ctx) => deployStep(ctx),
|
|
314
318
|
};
|
|
315
319
|
|
|
316
320
|
/** The step table with `over` replacing steps by name (tests stub the steps that need a real repo). */
|
|
@@ -383,6 +387,15 @@ export async function runRelease({ io, repo, opts = {}, config = {}, branches =
|
|
|
383
387
|
if (lctx) { // #5569: Actions minutes of this release (sum of ceil per job), mirrored to the ledger below
|
|
384
388
|
try { const m = await releaseMinutes({ gh: (a) => io.gh(a), repo, sinceMs: Date.parse(state.startedAt) }); if (m) state.minutes = { runs: m.runs, total: m.minutes }; } catch { /* best effort */ }
|
|
385
389
|
}
|
|
390
|
+
{ // #5583: with a catalogue, the deploy-telemetry JSON lines of this release (FORGE_GATE_TELEMETRY file) are kept next to state.minutes; no catalogue, no write
|
|
391
|
+
const tf = process.env.FORGE_GATE_TELEMETRY;
|
|
392
|
+
try {
|
|
393
|
+
if (tf && existsSync(tf) && existsSync(join(process.cwd(), ".forge/gates.yaml"))) {
|
|
394
|
+
const recs = (await import("./release-gates.mjs")).parseTelemetry(readFileSync(tf, "utf8"));
|
|
395
|
+
if (recs.length) state.gates = [...(state.gates ?? []), ...recs];
|
|
396
|
+
}
|
|
397
|
+
} catch { /* best effort */ }
|
|
398
|
+
}
|
|
386
399
|
state.status = out.status; ctx.save();
|
|
387
400
|
if (lctx) await mirror(state);
|
|
388
401
|
return out;
|
|
@@ -419,7 +432,7 @@ export function realReleaseIo({ env = process.env, exec = execFileSync, print =
|
|
|
419
432
|
}
|
|
420
433
|
|
|
421
434
|
const flag = (argv, f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : null; };
|
|
422
|
-
export const RELEASE_USAGE = "usage: forgedock release [--repo owner/repo] [--merge] [--watch] [--resume <id>] | forgedock release verify <sha> [--repo owner/repo] | forgedock release check-config [--ref <git ref>] | forgedock release init | forgedock release control <hold|resume|cancel|lane|exempt|freeze|unfreeze> ... --reason <text> [--repo owner/repo] [--json] (the verbs also work as `forgedock release <verb>`) | forgedock release report";
|
|
435
|
+
export const RELEASE_USAGE = "usage: forgedock release [--repo owner/repo] [--merge] [--watch] [--resume <id>] | forgedock release verify <sha | release id> [--repo owner/repo] | forgedock release status [<id>] [--watch] [--interval s] [--json] | forgedock release explain <id | #issue | PR> [--json] | forgedock release check-config [--ref <git ref>] | forgedock release init | forgedock release control <hold|resume|cancel|lane|exempt|freeze|unfreeze> ... --reason <text> [--repo owner/repo] [--json] (the verbs also work as `forgedock release <verb>`) | forgedock release gates [check [--base <ref>] | demote] [--since 30d] [--json] | forgedock release gates record <release-id> --file <jsonl> | forgedock release report";
|
|
423
436
|
|
|
424
437
|
/** `forgedock release ...`; @returns the process exit code (0 done or stopped at GATE_PASS, 1 refused, 3 blocked on a manual step). */
|
|
425
438
|
export async function releaseFromCli(argv, deps = {}) {
|
|
@@ -430,7 +443,34 @@ export async function releaseFromCli(argv, deps = {}) {
|
|
|
430
443
|
for (const l of waveReport(historyFromRoot(releaseRoot(env)), parseBudgetConfig(y.budget)).lines) io.print(l);
|
|
431
444
|
return 0;
|
|
432
445
|
}
|
|
446
|
+
if (argv[0] === "verify" && ID_RE.test(String(argv[1] ?? ""))) { // #5562: a release id re-runs the deploy verification; a sha keeps the snapshot-chain check
|
|
447
|
+
const { verifyReleaseById } = await import("./release-verify.mjs");
|
|
448
|
+
const { readPolicy } = await import("./release-config.mjs");
|
|
449
|
+
const def = readBranches(cwd).default || "main", rel = openRelease(releaseRoot(env), argv[1]), state = rel.load();
|
|
450
|
+
if (!state) throw new Error(`no release ${argv[1]} in ${releaseRoot(env)}`);
|
|
451
|
+
const r = await verifyReleaseById({ io, state, save: () => rel.save(state), def, policy: readPolicy({ io, defaultBranch: def, cwd }).policy, lane: flag(argv, "--lane") ?? state.lane });
|
|
452
|
+
return r.verified ? 0 : BLOCKED_EXIT;
|
|
453
|
+
}
|
|
454
|
+
if (argv[0] === "gates") { // #5583: catalogue, telemetry report, admission check; release-gates is loaded lazily
|
|
455
|
+
const g = await import("./release-gates.mjs");
|
|
456
|
+
const { readPolicy } = await import("./release-config.mjs");
|
|
457
|
+
const defaultBranch = readBranches(cwd).default || "main", root = releaseRoot(env);
|
|
458
|
+
if (argv[1] === "record") { // merge a deploy-telemetry JSON-lines file into the release state; no catalogue, no write
|
|
459
|
+
const id = argv[2], file = flag(argv, "--file");
|
|
460
|
+
if (!id || !file || !existsSync(join(cwd, g.GATES_PATH))) { io.print(`release gates record: needs <release-id>, --file and ${g.GATES_PATH}`); return 1; }
|
|
461
|
+
const rel = openRelease(root, id), st = rel.load();
|
|
462
|
+
if (!st) { io.print(`release gates record: no release ${id}`); return 1; }
|
|
463
|
+
const recs = g.parseTelemetry(readFileSync(file, "utf8"));
|
|
464
|
+
rel.save({ ...st, gates: [...(st.gates ?? []), ...recs] });
|
|
465
|
+
io.print(`release gates record: ${recs.length} record(s) into ${id}`);
|
|
466
|
+
return 0;
|
|
467
|
+
}
|
|
468
|
+
const policy = readPolicy({ io, defaultBranch, cwd }).policy;
|
|
469
|
+
const repo = flag(argv, "--repo") ?? (argv[1] === "demote" ? JSON.parse(String(await io.gh(["repo", "view", "--json", "nameWithOwner"]))).nameWithOwner : undefined);
|
|
470
|
+
return g.gatesFromCli(argv.slice(1), { io, cwd, defaultBranch, policy, repo, history: gateHistoryFromRoot(root) });
|
|
471
|
+
}
|
|
433
472
|
if (argv[0] === "verify") return verifyFromCli(argv.slice(1), { io, cwd });
|
|
473
|
+
if (argv[0] === "status" || argv[0] === "explain") return statusCli(argv, { io, cwd, env, deps });
|
|
434
474
|
if (argv[0] === "check-config" || argv[0] === "init") { // #5551: policy file, loaded lazily (release-config imports this module)
|
|
435
475
|
const { checkConfigFromCli, initFromCli } = await import("./release-config.mjs");
|
|
436
476
|
return (argv[0] === "init" ? initFromCli : checkConfigFromCli)(argv.slice(1), { io, cwd });
|
|
@@ -443,8 +483,12 @@ export async function releaseFromCli(argv, deps = {}) {
|
|
|
443
483
|
return controlFromCli(cv, argv.slice(argv[0] === "control" ? 2 : 1), { io, policy, actor: deps.actor, host: deps.host });
|
|
444
484
|
}
|
|
445
485
|
if (argv[0] === "control") throw new Error(`unknown control verb ${argv[1] ?? ""}; ${RELEASE_USAGE}`);
|
|
446
|
-
const unknown = argv.filter((a, i) => a.startsWith("--") && !["--repo", "--merge", "--watch", "--resume", "--lane"].includes(a) && !(argv[i - 1] === "--resume" || argv[i - 1] === "--repo" || argv[i - 1] === "--lane"));
|
|
486
|
+
const unknown = argv.filter((a, i) => a.startsWith("--") && !["--repo", "--merge", "--watch", "--resume", "--lane", "--interval"].includes(a) && !(argv[i - 1] === "--resume" || argv[i - 1] === "--repo" || argv[i - 1] === "--lane" || argv[i - 1] === "--interval"));
|
|
447
487
|
if (unknown.length) throw new Error(`unknown option ${unknown[0]}; ${RELEASE_USAGE}`);
|
|
488
|
+
if (argv.includes("--watch")) { // the bare flag delegates to the status loop (#5554)
|
|
489
|
+
const pick = (f) => (flag(argv, f) ? [f, flag(argv, f)] : []);
|
|
490
|
+
return statusCli(["status", ...(flag(argv, "--resume") ? [flag(argv, "--resume")] : []), "--watch", ...pick("--repo"), ...pick("--interval")], { io, cwd, env, deps });
|
|
491
|
+
}
|
|
448
492
|
const root = releaseRoot(env);
|
|
449
493
|
const resume = flag(argv, "--resume");
|
|
450
494
|
let id = resume ?? newReleaseId(io.now());
|
|
@@ -452,6 +496,17 @@ export async function releaseFromCli(argv, deps = {}) {
|
|
|
452
496
|
let raw = ""; try { raw = readFileSync(join(cwd, "forge.yaml"), "utf8"); } catch { /* no forge.yaml: defaults */ }
|
|
453
497
|
const config = readReleaseConfig(raw);
|
|
454
498
|
if (config.managed) config.ciPolicy = readCiPolicy(cwd);
|
|
499
|
+
if (config.managed) { // #5560: deploy stages come from the default-branch policy only (I13)
|
|
500
|
+
const { readPolicy } = await import("./release-config.mjs");
|
|
501
|
+
const pol = readPolicy({ io, defaultBranch: readBranches(cwd).default || "main", cwd }).policy;
|
|
502
|
+
if (pol?.deploy) config.deploy = pol.deploy;
|
|
503
|
+
config.deployPipeline = pol?.lanes?.[flag(argv, "--lane")]?.pipeline ?? "full"; // service/hotfix lanes dispatch with unit inputs
|
|
504
|
+
if (pol?.verify) { // #5562: verification layers; risk class picks the soak minutes
|
|
505
|
+
config.verify = pol.verify;
|
|
506
|
+
config.verifyRisk = riskClass(flag(argv, "--lane"), config.deployPipeline);
|
|
507
|
+
config.verifySoak = pol.lanes?.[flag(argv, "--lane")]?.soak_min;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
455
510
|
if (resume) {
|
|
456
511
|
const st = openRelease(root, resume).load();
|
|
457
512
|
if (!st && !config.managed) throw new Error(`no release ${resume} in ${root}`); // managed: the ledger may hold it (another host)
|
|
@@ -479,3 +534,12 @@ async function verifyFromCli(argv, { io, cwd }) {
|
|
|
479
534
|
io.print(r.ok ? `release verify ${full}: ok (snapshot + ${r.picks} cherry-pick(s), PR #${r.pr})` : `release verify ${full}: FAILED: ${r.why}`);
|
|
480
535
|
return r.ok ? 0 : 1;
|
|
481
536
|
}
|
|
537
|
+
|
|
538
|
+
/** `release status|explain` (#5554): read-only; the local cache and the gate read are handed to release-status.mjs. */
|
|
539
|
+
function statusCli(argv, { io, cwd, env, deps }) {
|
|
540
|
+
let raw = ""; try { raw = readFileSync(join(cwd, "forge.yaml"), "utf8"); } catch { /* defaults */ }
|
|
541
|
+
const root = releaseRoot(env);
|
|
542
|
+
const local = { load: (id) => (ID_RE.test(String(id)) ? openRelease(root, id).load() : null), ids: () => { try { return readdirSync(root).filter((d) => ID_RE.test(d)); } catch { return []; } } };
|
|
543
|
+
const { policy, watch } = policyFromYaml(raw);
|
|
544
|
+
return statusFromCli(argv, { io, config: readReleaseConfig(raw), local, gateState, watch: deps.watch ?? watch, policy: deps.policy ?? policy, maxPolls: deps.maxPolls });
|
|
545
|
+
}
|
|
@@ -226,7 +226,7 @@ describe("release job (#5211)", () => {
|
|
|
226
226
|
assert.equal(readReleaseConfig("release:\n managed: true\n").managed, true);
|
|
227
227
|
const apiCalls = [], ghCalls = [], io = { print() {}, now: () => 1_700_000_000_000, runningLanes: async () => [], batches: async () => [], setParallel: async () => {}, gh: async (a) => { ghCalls.push(a); return ""; }, api: async (...a) => { apiCalls.push(a); return {}; } };
|
|
228
228
|
const ok = async () => ({});
|
|
229
|
-
const out = await (await import("./release.mjs")).runRelease({ io, repo: REPO, root: tmp(), mounts: DISK, id: newReleaseId(), opts: {}, config: {}, branches: {}, steps: { preflight: ok, "host-preflight": ok, "release-pr": ok, review: ok, fixes: ok, "mark-ready": ok, rehearsal: ok, promotion: ok, "post-merge": ok } });
|
|
229
|
+
const out = await (await import("./release.mjs")).runRelease({ io, repo: REPO, root: tmp(), mounts: DISK, id: newReleaseId(), opts: {}, config: {}, branches: {}, steps: { preflight: ok, "host-preflight": ok, "release-pr": ok, review: ok, fixes: ok, "mark-ready": ok, rehearsal: ok, promotion: ok, "post-merge": ok, deploy: async () => ({ skipped: true }) } });
|
|
230
230
|
assert.equal(out.status, "done");
|
|
231
231
|
assert.deepEqual(apiCalls, []);
|
|
232
232
|
assert.deepEqual(ghCalls, []);
|
|
@@ -444,6 +444,10 @@ describe("snapshot releases (#5276)", () => {
|
|
|
444
444
|
assert.equal(create[create.indexOf("--head") + 1], "staging");
|
|
445
445
|
});
|
|
446
446
|
|
|
447
|
+
it("#5562: `release verify <id>` is routed to the deploy verification, not the sha check", async () => {
|
|
448
|
+
const io = { gh: async () => { throw new Error("gh must not be called"); }, print() {}, git: () => "", now: () => 0 };
|
|
449
|
+
await assert.rejects(releaseFromCli(["verify", "r20260101-000000-1"], { io, cwd: tmp(), env: { ...process.env, FORGEDOCK_RELEASE_DIR: tmp() } }), /no release r20260101-000000-1/);
|
|
450
|
+
});
|
|
447
451
|
it("R10: `release verify <sha>` exits 0 for a head that is the snapshot, 1 for a PR without a record", async () => {
|
|
448
452
|
const rec = { v: 1, snapshot: S, picks: [] };
|
|
449
453
|
const mk = (body) => { const io = fakeIo({ pm: (a) => (a[0] === "api" ? JSON.stringify([{ number: 9, body }]) : undefined) }); io.git = gitFake(); io.git = ((g) => (a, o) => (a[0] === "rev-parse" && !a[1].startsWith("refs/") ? `${S}\n` : g(a, o)))(io.git); return io; };
|