forgedock 1.69.0 → 1.70.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/lean/conformance.mjs +3 -0
- package/bin/lean/conformance.test.mjs +1 -0
- package/bin/lean/issuewatch-parity.test.mjs +1 -1
- package/bin/lean/lean.test.mjs +1 -0
- package/bin/lean/release-cigreen.mjs +204 -0
- package/bin/lean/release-cigreen.test.mjs +115 -0
- package/bin/lean/release-fixloop.mjs +1 -1
- package/bin/lean/release-ledger.test.mjs +4 -4
- package/bin/lean/release-preflight.test.mjs +2 -2
- package/bin/lean/release-rehearsal.test.mjs +1 -1
- package/bin/lean/release-review.e2e.test.mjs +4 -3
- package/bin/lean/release-review.mjs +136 -56
- package/bin/lean/release-review.test.mjs +97 -12
- package/bin/lean/release-status.mjs +3 -2
- package/bin/lean/release-status.test.mjs +2 -2
- package/bin/lean/release.mjs +4 -2
- package/bin/lean/release.test.mjs +33 -12
- package/bin/review-staging.mjs +63 -21
- package/commands/review-pr-staging.md +1 -1
- package/docs/CONFIG.md +20 -0
- package/package.json +1 -1
- package/pool/image/Dockerfile +1 -1
package/bin/lean/conformance.mjs
CHANGED
|
@@ -1027,6 +1027,9 @@ export function missingTool({ rc, output } = {}, { repoHas = () => false, comman
|
|
|
1027
1027
|
const first = String(command).trim().split(/\s+/)[0] ?? "";
|
|
1028
1028
|
const fallback = INTERPRETER_RE.test(first.split("/").pop()) ? null : first;
|
|
1029
1029
|
const cmd = CMD_NOT_FOUND_RE.exec(out)?.[1] ?? (rc === 127 ? SH_NOT_FOUND_RE.exec(out)?.[1] ?? fallback : null);
|
|
1030
|
+
// an exit 127 inside an interpreter's script with no line naming the command is still the environment (a command the
|
|
1031
|
+
// script runs is missing), never an unimplemented requirement
|
|
1032
|
+
if (!cmd && rc === 127 && fallback === null) return envSignature(out) ?? { tool: "a command the script runs (exit 127)", kind: "environment" };
|
|
1030
1033
|
if (!cmd || cmd.includes("/") || local(cmd)) return envSignature(out); // #5371
|
|
1031
1034
|
return { tool: cmd, kind: "command" };
|
|
1032
1035
|
}
|
|
@@ -225,6 +225,7 @@ describe("precheck (deterministic, no reviewer)", () => {
|
|
|
225
225
|
});
|
|
226
226
|
it("an exit 127 under an interpreter is never blamed on the interpreter (Remote sandbox lacks bash)", () => {
|
|
227
227
|
assert.equal(missingTool({ rc: 127, output: "" }, { command: "bash scripts/tests/new-check.sh" })?.tool === "bash", false);
|
|
228
|
+
assert.equal(missingTool({ rc: 127, output: "PASS: first section" }, { command: "bash scripts/tests/x.sh" })?.kind, "environment", "127 inside the script is the environment, not unimplemented");
|
|
228
229
|
assert.equal(missingTool({ rc: 127, output: "boom" }, { command: "/usr/bin/python3 tools/x.py" })?.tool === "python3", false);
|
|
229
230
|
assert.deepEqual(missingTool({ rc: 127, output: "" }, { command: "jq . x.json" }), { tool: "jq", kind: "command" });
|
|
230
231
|
assert.deepEqual(missingTool({ rc: 127, output: "scripts/x.sh: line 3: yq: command not found" }, { command: "bash scripts/x.sh" }), { tool: "yq", kind: "command" });
|
|
@@ -91,7 +91,7 @@ test("#5313 a release in flight pauses the watch (no claims), the next pass resu
|
|
|
91
91
|
|
|
92
92
|
test("#5560 releaseInFlight: an unconfigured (trace-less) deploy is not the pending step after post-merge", () => {
|
|
93
93
|
const env = tmpDir("iwp-"), root = join(env, "releases"), done = { done: true };
|
|
94
|
-
relDir(env, "r20261110-120000-1", { repo: "o/r", steps: { preflight: done, "host-preflight": done, "release-pr": done, review: done, fixes: done, "mark-ready": done, rehearsal: done, promotion: done, "post-merge": done } }, 60000);
|
|
94
|
+
relDir(env, "r20261110-120000-1", { repo: "o/r", steps: { preflight: done, "host-preflight": done, "release-pr": done, "ci-green": done, review: done, fixes: done, "mark-ready": done, rehearsal: done, promotion: done, "post-merge": done } }, 60000);
|
|
95
95
|
assert.equal(releaseInFlight({ root, repo: "o/r", now: NOW }).step, null);
|
|
96
96
|
});
|
|
97
97
|
|
package/bin/lean/lean.test.mjs
CHANGED
|
@@ -3883,6 +3883,7 @@ describe("orchestrate", () => {
|
|
|
3883
3883
|
const leanIo = {
|
|
3884
3884
|
gh: async (a) => {
|
|
3885
3885
|
if (a[0] === "repo" && a[1] === "view") return "main\n";
|
|
3886
|
+
if (a[0] === "api" && a[1] === "graphql") return JSON.stringify({ data: { repository: Object.fromEntries(Object.entries(milestones).map(([n, m]) => [`i${n}`, { state: "OPEN", stateReason: null, labels: { nodes: [] }, milestone: m ? { title: m } : null, comments: { totalCount: 0 }, updatedAt: "2026-11-27T00:00:00Z" }])) } }); // #5990 gh-reader
|
|
3886
3887
|
if (a[0] === "api") return "OWNER\n"; // #4859: the author association is a REST read
|
|
3887
3888
|
if (a.includes("milestone")) return JSON.stringify({ milestone: milestones[a[2]] ? { title: milestones[a[2]] } : null });
|
|
3888
3889
|
return JSON.stringify({ body: a[2] === "1" ? "**Depends on**: #2" : "", authorAssociation: "OWNER" });
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* `ci-green` step of `forgedock release`. The default, ForgeDock-owned release flow is the v1.0 contract restored (commands/review-pr-staging.md
|
|
5
|
+
* at dcfb86bf): open-finding gate -> CI green -> ONE review pass on the green head -> verdict. CI comes first because a CI failure after the
|
|
6
|
+
* review moves the head and voids it (drift: #4358, #4360, #5212, #5567).
|
|
7
|
+
*
|
|
8
|
+
* The step runs the open-finding gate (an open review-finding issue blocks the release first), then waits for every required check of the
|
|
9
|
+
* release PR head (branch protection and rulesets of the default branch plus forge.yaml gate.required_checks; forgedock/verify, forge/deploy-gate
|
|
10
|
+
* and the gate-marker check are excluded). A failed check is rerun ONCE (reusing the #5502/#6014 attempt cap); if the rerun passes it is a flake:
|
|
11
|
+
* green, and a `flaky-test` issue is filed naming the test when the log shows it. A check still red after its rerun gets ONE fix round (`fixRound`:
|
|
12
|
+
* a CI fix in the release PR), then CI is awaited again. Timings (`ci_green_min`, `review_min`, `fix_rounds`, `review_passes`) go to `state.timing`,
|
|
13
|
+
* which release status prints and the ledger mirrors. There is no switch to turn the step off.
|
|
14
|
+
*/
|
|
15
|
+
import { ciState, requiredSet, reviewStagingJson, reviewStagingIo } from "../review-staging.mjs";
|
|
16
|
+
import { requiredChecksRead } from "./effects.mjs";
|
|
17
|
+
import { attemptGuard, classifyFailure } from "./release-flakes.mjs";
|
|
18
|
+
|
|
19
|
+
export const CI_GREEN_POLL_MS = 30_000;
|
|
20
|
+
export const CI_GREEN_MAX_WAIT_MIN = 40;
|
|
21
|
+
const SEVERITY_ORDER = ["CRITICAL", "HIGH", "MEDIUM", "LOW"];
|
|
22
|
+
const json = (s) => JSON.parse(String(s || "null"));
|
|
23
|
+
|
|
24
|
+
/** forge.yaml `release.ci_green.max_wait_min` and `release.block_severity` (lowest blocking severity; default high) -> `{ciGreen, blockSeverity}`; only set keys are returned. */
|
|
25
|
+
export function ciGreenKeys(r) {
|
|
26
|
+
const out = {};
|
|
27
|
+
const wait = Number(r?.ci_green?.max_wait_min ?? r?.ci_green_max_wait_min);
|
|
28
|
+
if (Number.isFinite(wait) && wait > 0) out.ciGreen = { maxWaitMin: Math.min(wait, 240) };
|
|
29
|
+
const sev = String(r?.block_severity ?? "").trim().toUpperCase();
|
|
30
|
+
if (SEVERITY_ORDER.includes(sev)) out.blockSeverity = sev;
|
|
31
|
+
if (/^(true|on|yes|1)$/i.test(String(r?.review_fixes ?? ""))) out.reviewFixes = true; // compatibility knob, default off: the #5212 review fix lanes and delta passes
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Set of severities that block: CRITICAL down to `config.blockSeverity` (default HIGH). */
|
|
36
|
+
export function blockSetOf(config) {
|
|
37
|
+
const at = SEVERITY_ORDER.indexOf(config?.blockSeverity);
|
|
38
|
+
return new Set(SEVERITY_ORDER.slice(0, at >= 0 ? at + 1 : 2));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `state.timing[key]`: minutes (1 decimal) added for `ms`, or a raw count with `raw`, or the value itself with `set`. */
|
|
42
|
+
export function addTiming(ctx, key, n, { raw = false, set = false } = {}) {
|
|
43
|
+
const t = (ctx.state.timing ??= {});
|
|
44
|
+
t[key] = set ? n : raw ? (t[key] ?? 0) + n : Math.round(((t[key] ?? 0) + n / 60_000) * 10) / 10;
|
|
45
|
+
ctx.save?.();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Best-effort test name from a failed log: tap `not ok`, node test runner, jest/mocha, pytest/cargo style lines. */
|
|
49
|
+
export function flakyTestName(log) {
|
|
50
|
+
const text = String(log ?? "");
|
|
51
|
+
const pats = [/^\s*not ok \d+ - (.+)$/m, /^\s*(?:✖|✗|×) (.+?)(?: \(\d[^)]*\))?\s*$/m, /^\s*● (.+)$/m, /^\s*(?:FAILED|FAIL) (\S+(?:::\S+)*)/m, /^\s*test (\S+) \.\.\. FAILED/m, /^\s*\d+\) (.+)$/m];
|
|
52
|
+
for (const re of pats) { const m = re.exec(text); if (m?.[1]?.trim()) return m[1].trim().slice(0, 120); }
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const runIdOf = (link) => /\/actions\/runs\/(\d+)/.exec(String(link ?? ""))?.[1] ?? null;
|
|
57
|
+
const bucketOf = (status, conclusion) => {
|
|
58
|
+
if (status && status !== "completed") return "pending";
|
|
59
|
+
if (["success", "neutral", "skipped"].includes(conclusion)) return "pass";
|
|
60
|
+
if (conclusion === "cancelled") return "cancel";
|
|
61
|
+
return conclusion ? "fail" : "pending";
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** Real effects of ci-green. Tests inject `ctx.io.ciGreen` with the same shape. */
|
|
65
|
+
export function realCiSeam(ctx) {
|
|
66
|
+
const { io, repo } = ctx;
|
|
67
|
+
const gh = (a) => io.gh(a);
|
|
68
|
+
return {
|
|
69
|
+
sleep: (ms) => io.sleep(ms),
|
|
70
|
+
now: () => io.now?.() ?? Date.now(),
|
|
71
|
+
// The open-finding gate first (review-staging --gate-only: bundle PR set + open review-finding issues). @returns null when it passes, else the reason.
|
|
72
|
+
openGate: async (pr) => {
|
|
73
|
+
const r = await reviewStagingJson([String(pr), "--gate-only"], { ...reviewStagingIo(), cwd: ctx.cwd ?? process.cwd(), env: process.env });
|
|
74
|
+
return r.code === 0 ? null : String((r.lines ?? []).filter(Boolean).slice(-3).join(" | ")).slice(0, 400) || `exit ${r.code}`;
|
|
75
|
+
},
|
|
76
|
+
isDraft: async (pr) => Boolean(json(await gh(["pr", "view", String(pr), "--repo", repo, "--json", "isDraft"]))?.isDraft),
|
|
77
|
+
headOf: async (pr) => String(await gh(["pr", "view", String(pr), "--repo", repo, "--json", "headRefOid", "--jq", ".headRefOid"])).trim(),
|
|
78
|
+
checks: async ({ head }) => {
|
|
79
|
+
const runs = json(await gh(["api", `repos/${repo}/commits/${head}/check-runs?per_page=100`, "--jq", "[.check_runs[] | {name, status, conclusion, link: .details_url}]"])) ?? [];
|
|
80
|
+
let statuses = [];
|
|
81
|
+
try { statuses = json(await gh(["api", `repos/${repo}/commits/${head}/status`, "--jq", "[.statuses[] | {name: .context, state, link: .target_url}]"])) ?? []; } catch { /* check runs alone */ }
|
|
82
|
+
return [
|
|
83
|
+
...runs.map((k) => ({ name: k.name, bucket: bucketOf(k.status, k.conclusion), link: k.link })),
|
|
84
|
+
...statuses.map((k) => ({ name: k.name, bucket: k.state === "success" ? "pass" : k.state === "pending" ? "pending" : "fail", link: k.link })),
|
|
85
|
+
];
|
|
86
|
+
},
|
|
87
|
+
required: async () => {
|
|
88
|
+
const read = await requiredChecksRead({ gh, repo, lane: ctx.def });
|
|
89
|
+
return requiredSet(read, ctx.config?.requiredChecks ?? []);
|
|
90
|
+
},
|
|
91
|
+
runAttempt: async (id) => { try { return json(await gh(["run", "view", id, "--repo", repo, "--json", "attempt"]))?.attempt ?? null; } catch { return null; } },
|
|
92
|
+
failedLog: async (id) => { try { return String(await gh(["run", "view", id, "--repo", repo, "--log-failed"])).slice(-20_000); } catch { return ""; } },
|
|
93
|
+
rerunFailed: (id) => gh(["run", "rerun", id, "--repo", repo, "--failed"]),
|
|
94
|
+
fileFlake: async ({ check, test, signature, tail, sha, pr }) => {
|
|
95
|
+
const title = `Flaky test: ${test ?? check}`;
|
|
96
|
+
try {
|
|
97
|
+
const hit = json(await gh(["issue", "list", "--repo", repo, "--state", "open", "--search", `"${title}" in:title`, "--json", "number,title"]))?.find((i) => i.title === title);
|
|
98
|
+
if (hit) return hit.number;
|
|
99
|
+
} catch { /* no lookup: file a new one */ }
|
|
100
|
+
const body = [`Required check \`${check}\` failed on release PR #${pr} at ${String(sha).slice(0, 7)} and passed on one rerun, so the release treated it as green and went on.`, test ? `Test: \`${test}\`` : "The log did not show a test name.", signature ? `Failure signature: ${signature}` : "", "", "```", String(tail ?? "").slice(-1200), "```"].filter((l) => l !== "").join("\n");
|
|
101
|
+
try { await gh(["label", "create", "flaky-test", "--repo", repo, "--color", "FBCA04", "--description", "A test that fails and then passes on rerun", "--force"]); } catch { /* the label is best effort */ }
|
|
102
|
+
for (const labels of [["--label", "flaky-test"], []]) {
|
|
103
|
+
try { return Number(/\/issues\/(\d+)/.exec(String(await gh(["issue", "create", "--repo", repo, "--title", title, "--body", body, ...labels])))?.[1]) || null; } catch { /* retry without the label */ }
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const ciSeamOf = (ctx) => ctx.io.ciGreen ?? (ctx.ciSeam ??= realCiSeam(ctx));
|
|
110
|
+
|
|
111
|
+
/** Per-head bookkeeping: checks already rerun, the first failure of each (test name, signature) and the flakes already filed. */
|
|
112
|
+
const headRec = (state, head) => ((state.ciGreen ??= { heads: {}, flakes: [] }).heads[head] ??= { reran: [], firstFail: {}, filed: [] });
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Wait until every required check of `pr`'s head is green. @returns
|
|
116
|
+
* `{ok: true, head, flakes}` | `{red: true, head, failing}` (still red after its one rerun) | `{blocked: true, reason}` (timed out).
|
|
117
|
+
*/
|
|
118
|
+
async function waitGreen(ctx, pr, seam) {
|
|
119
|
+
const { state } = ctx;
|
|
120
|
+
const deadline = seam.now() + (ctx.config?.ciGreen?.maxWaitMin ?? CI_GREEN_MAX_WAIT_MIN) * 60_000;
|
|
121
|
+
for (;;) {
|
|
122
|
+
const head = await seam.headOf(pr);
|
|
123
|
+
const [checks, required] = [await seam.checks({ pr, head }), await seam.required()];
|
|
124
|
+
const st = ciState(checks, required);
|
|
125
|
+
const rec = headRec(state, head);
|
|
126
|
+
if (st.green) {
|
|
127
|
+
const flakes = [];
|
|
128
|
+
for (const [check, ff] of Object.entries(rec.firstFail)) {
|
|
129
|
+
if (rec.filed.includes(check)) continue;
|
|
130
|
+
const issue = await seam.fileFlake({ check, test: ff.test, signature: ff.signature, tail: ff.tail, sha: head, pr });
|
|
131
|
+
rec.filed.push(check);
|
|
132
|
+
state.ciGreen.flakes.push({ check, test: ff.test ?? null, issue: issue ?? null, sha: head });
|
|
133
|
+
flakes.push({ check, test: ff.test ?? null, issue: issue ?? null });
|
|
134
|
+
}
|
|
135
|
+
if (flakes.length) ctx.io.print?.(`release: ci-green: ${flakes.map((f) => `${f.check} (passed on rerun${f.issue ? `, flaky-test #${f.issue}` : ""})`).join("; ")}`);
|
|
136
|
+
ctx.save?.();
|
|
137
|
+
return { ok: true, head, flakes };
|
|
138
|
+
}
|
|
139
|
+
if (st.pending.length) {
|
|
140
|
+
if (seam.now() >= deadline) return { blocked: true, reason: `required checks of #${pr} still pending after ${ctx.config?.ciGreen?.maxWaitMin ?? CI_GREEN_MAX_WAIT_MIN} min (${st.pending.join(", ")}); re-run the release once CI finishes` };
|
|
141
|
+
await seam.sleep(CI_GREEN_POLL_MS);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const fresh = st.failing.filter((n) => !rec.reran.includes(n));
|
|
145
|
+
if (!fresh.length) return { red: true, head, failing: st.failing };
|
|
146
|
+
// First failure of these checks: one rerun of each failed run, never past the attempt cap. A status context has no run: it stays red.
|
|
147
|
+
const ids = new Map();
|
|
148
|
+
for (const name of fresh) {
|
|
149
|
+
rec.reran.push(name);
|
|
150
|
+
const row = checks.find((k) => k.name === name && (k.bucket === "fail" || k.bucket === "cancel"));
|
|
151
|
+
const id = runIdOf(row?.link);
|
|
152
|
+
if (!id) continue;
|
|
153
|
+
if (row.bucket === "fail") {
|
|
154
|
+
const log = await seam.failedLog(id);
|
|
155
|
+
rec.firstFail[name] = { test: flakyTestName(log), signature: classifyFailure(log).signature ?? null, tail: log.slice(-1200) };
|
|
156
|
+
}
|
|
157
|
+
ids.set(id, name);
|
|
158
|
+
}
|
|
159
|
+
ctx.save?.();
|
|
160
|
+
let reran = 0;
|
|
161
|
+
for (const id of ids.keys()) {
|
|
162
|
+
if (!attemptGuard({ attempt: await seam.runAttempt(id) }).allow) continue;
|
|
163
|
+
await seam.rerunFailed(id);
|
|
164
|
+
reran++;
|
|
165
|
+
}
|
|
166
|
+
if (!reran) return { red: true, head, failing: st.failing };
|
|
167
|
+
ctx.io.print?.(`release: ci-green: rerunning ${[...ids.values()].join(", ")} once`);
|
|
168
|
+
await seam.sleep(CI_GREEN_POLL_MS);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Wait for CI green on `pr`; on a real red run the fix path once (unless `noFix`) and wait again. Time spent is added to `ci_green_min`.
|
|
174
|
+
* @returns `{ok, head}` | `{red, failing}` (only with `noFix` or after the fix round) | `{blocked, reason}`
|
|
175
|
+
*/
|
|
176
|
+
export async function ciGreenWait(ctx, pr, { noFix = false } = {}) {
|
|
177
|
+
const seam = ciSeamOf(ctx);
|
|
178
|
+
const t0 = Date.now();
|
|
179
|
+
try {
|
|
180
|
+
if (await seam.isDraft?.(pr)) return { ok: true, skipped: "draft" }; // host preflight mode: no Actions CI until mark-ready
|
|
181
|
+
for (;;) {
|
|
182
|
+
const w = await waitGreen(ctx, pr, seam);
|
|
183
|
+
if (!w.red || noFix) return w;
|
|
184
|
+
if (Object.values(ctx.state.fixloop?.heads ?? {}).some((h) => !h.second)) return { blocked: true, reason: `required checks of #${pr} are red again after the fix round (${w.failing.join(", ")}); the one fix round is spent` };
|
|
185
|
+
const { fixRound, seamOf } = await import("./release-review.mjs");
|
|
186
|
+
const f = await fixRound(ctx, seamOf(ctx), { pr, head: w.head, blocking: [], items: [], guards: [], ciFailing: w.failing.length });
|
|
187
|
+
if (f.blocked) return f;
|
|
188
|
+
}
|
|
189
|
+
} finally { addTiming(ctx, "ci_green_min", Date.now() - t0); }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The `ci-green` release step. A draft release PR (host preflight mode) has no Actions CI yet, so it is recorded as skipped there. */
|
|
193
|
+
export async function ciGreenStep(ctx) {
|
|
194
|
+
const pr = ctx.state?.steps?.["release-pr"]?.result?.pr;
|
|
195
|
+
if (!pr) return { blocked: true, reason: "no release PR recorded by the release-pr step" };
|
|
196
|
+
const seam = ciSeamOf(ctx);
|
|
197
|
+
const gate = await seam.openGate?.(pr); // 1. the open-finding gate: an open review-finding issue blocks the release before CI or any reviewer
|
|
198
|
+
if (gate) return { blocked: true, reason: `open-finding gate: ${gate}; merge or close the open review-finding issues, then re-run the release` };
|
|
199
|
+
if (await seam.isDraft?.(pr)) return { green: false, skipped: "draft PR: CI starts at mark-ready, host preflight runs first" };
|
|
200
|
+
const w = await ciGreenWait(ctx, pr);
|
|
201
|
+
if (w.blocked) return w;
|
|
202
|
+
if (w.red) return { blocked: true, reason: `required checks of #${pr} are red: ${w.failing.join(", ")}` };
|
|
203
|
+
return { green: true, head: w.head, flakes: w.flakes, minutes: ctx.state.timing?.ci_green_min ?? 0 };
|
|
204
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// #6164: the default ci-green step: wait for required checks, rerun a failed check once, flake = green + issue, real red = one fix round.
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { ciGreenStep, ciGreenWait, flakyTestName, blockSetOf, ciGreenKeys, addTiming } from "./release-cigreen.mjs";
|
|
7
|
+
import { RELEASE_STEPS, readReleaseConfig } from "./release.mjs";
|
|
8
|
+
|
|
9
|
+
const H = "c".repeat(40);
|
|
10
|
+
const link = (id) => `https://github.com/o/r/actions/runs/${id}/job/1`;
|
|
11
|
+
/** Seam over a script of check snapshots: `snaps[i]` is what the i-th `checks` call returns (the last repeats). */
|
|
12
|
+
function seam(snaps, o = {}) {
|
|
13
|
+
const log = []; let i = 0, t = 0;
|
|
14
|
+
return {
|
|
15
|
+
log,
|
|
16
|
+
now: () => t, sleep: async (ms) => { t += ms; log.push("sleep"); },
|
|
17
|
+
isDraft: async () => o.draft ?? false,
|
|
18
|
+
headOf: async () => H,
|
|
19
|
+
checks: async () => snaps[Math.min(i++, snaps.length - 1)],
|
|
20
|
+
required: async () => o.required ?? ["build"],
|
|
21
|
+
runAttempt: async () => o.attempt ?? 1,
|
|
22
|
+
failedLog: async () => o.log ?? "not ok 3 - parses the thing\n error: boom",
|
|
23
|
+
rerunFailed: async (id) => { log.push(`rerun:${id}`); },
|
|
24
|
+
fileFlake: async (a) => { log.push(`flake:${a.check}:${a.test}`); return 77; },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const ctx = (s, extra = {}) => ({ io: { ciGreen: s, print() {} }, repo: "o/r", def: "main", config: {}, state: { steps: { "release-pr": { done: true, result: { pr: 7 } } } }, save() {}, ...extra });
|
|
28
|
+
const row = (bucket, id = 1) => ({ name: "build", bucket, link: link(id) });
|
|
29
|
+
|
|
30
|
+
describe("ci-green step (#6164)", () => {
|
|
31
|
+
it("is a default release step between release-pr and review", () => {
|
|
32
|
+
const i = RELEASE_STEPS.indexOf("ci-green");
|
|
33
|
+
assert.equal(RELEASE_STEPS[i - 1], "release-pr"); assert.equal(RELEASE_STEPS[i + 1], "review");
|
|
34
|
+
});
|
|
35
|
+
it("waits while required checks are pending, then continues when green", async () => {
|
|
36
|
+
const s = seam([[row("pending")], [row("pending")], [row("pass")]]);
|
|
37
|
+
const r = await ciGreenStep(ctx(s));
|
|
38
|
+
assert.equal(r.green, true); assert.equal(s.log.filter((x) => x === "sleep").length, 2);
|
|
39
|
+
});
|
|
40
|
+
it("a required check that has not reported yet is pending, not green", async () => {
|
|
41
|
+
const s = seam([[], [row("pass")]]);
|
|
42
|
+
assert.equal((await ciGreenStep(ctx(s))).green, true); assert.equal(s.log.length, 1);
|
|
43
|
+
});
|
|
44
|
+
it("blocks when checks stay pending past the wait cap", async () => {
|
|
45
|
+
const r = await ciGreenStep(ctx(seam([[row("pending")]]), { config: { ciGreen: { maxWaitMin: 1 } } }));
|
|
46
|
+
assert.equal(r.blocked, true); assert.match(r.reason, /still pending after 1 min \(build\)/);
|
|
47
|
+
});
|
|
48
|
+
it("a failure that passes on one rerun is green, files a flaky-test issue naming the test, and does not block", async () => {
|
|
49
|
+
const s = seam([[row("fail", 5)], [row("pending", 5)], [row("pass", 5)]]);
|
|
50
|
+
const c = ctx(s);
|
|
51
|
+
const r = await ciGreenStep(c);
|
|
52
|
+
assert.equal(r.green, true);
|
|
53
|
+
assert.deepEqual(s.log.filter((x) => x !== "sleep"), ["rerun:5", "flake:build:parses the thing"]);
|
|
54
|
+
assert.deepEqual(r.flakes, [{ check: "build", test: "parses the thing", issue: 77 }]);
|
|
55
|
+
assert.equal(c.state.ciGreen.flakes.length, 1);
|
|
56
|
+
});
|
|
57
|
+
it("a check still red after its one rerun is real: one fix round, then wait again; green afterwards continues", async () => {
|
|
58
|
+
const s = seam([[row("fail", 5)], [row("fail", 5)], [row("pass", 6)]]);
|
|
59
|
+
const c = ctx(s, { io: { ciGreen: s, print() {}, review: {} } });
|
|
60
|
+
let fixed = 0;
|
|
61
|
+
c.fixRoundStub = () => { fixed++; c.state.fixloop = { heads: { [H]: { rounds: 1 } } }; return { head: "d".repeat(40) }; };
|
|
62
|
+
const r = await ciGreenWait(c, 7, { noFix: true });
|
|
63
|
+
assert.equal(r.red, true); assert.deepEqual(r.failing, ["build"]); assert.equal(fixed, 0, "noFix never starts a fix");
|
|
64
|
+
assert.deepEqual(s.log.filter((x) => x.startsWith("rerun")), ["rerun:5"], "rerun exactly once");
|
|
65
|
+
});
|
|
66
|
+
it("red after the fix round is spent blocks instead of fixing again", async () => {
|
|
67
|
+
const s = seam([[row("fail", 5)]]);
|
|
68
|
+
const c = ctx(s); c.state.fixloop = { heads: { [H]: { rounds: 1 } } };
|
|
69
|
+
c.state.ciGreen = { heads: { [H]: { reran: ["build"], firstFail: {}, filed: [] } }, flakes: [] };
|
|
70
|
+
const r = await ciGreenWait(c, 7);
|
|
71
|
+
assert.equal(r.blocked, true); assert.match(r.reason, /one fix round is spent/);
|
|
72
|
+
});
|
|
73
|
+
it("respects the rerun attempt cap (#6014): no rerun past it, the check stays red", async () => {
|
|
74
|
+
const s = seam([[row("fail", 5)]], { attempt: 3 });
|
|
75
|
+
const r = await ciGreenWait(ctx(s), 7, { noFix: true });
|
|
76
|
+
assert.equal(r.red, true); assert.ok(!s.log.some((x) => x.startsWith("rerun")));
|
|
77
|
+
});
|
|
78
|
+
it("a draft release PR (host preflight mode) is skipped: CI starts at mark-ready", async () => {
|
|
79
|
+
const r = await ciGreenStep(ctx(seam([[row("fail")]], { draft: true })));
|
|
80
|
+
assert.match(r.skipped, /draft/);
|
|
81
|
+
});
|
|
82
|
+
it("the open-finding gate runs first: an open review-finding issue blocks before any CI is read", async () => {
|
|
83
|
+
const s = seam([[row("pass")]]); let read = 0; const checks = s.checks; s.checks = async (a) => { read++; return checks(a); };
|
|
84
|
+
s.openGate = async () => "RESULT: BLOCK DEPLOY (open finding #12)";
|
|
85
|
+
const r = await ciGreenStep(ctx(s));
|
|
86
|
+
assert.equal(r.blocked, true); assert.match(r.reason, /^open-finding gate: .*#12/); assert.equal(read, 0);
|
|
87
|
+
s.openGate = async () => null;
|
|
88
|
+
assert.equal((await ciGreenStep(ctx(s))).green, true);
|
|
89
|
+
});
|
|
90
|
+
it("records ci_green_min in state.timing", async () => {
|
|
91
|
+
const c = ctx(seam([[row("pass")]]));
|
|
92
|
+
await ciGreenStep(c);
|
|
93
|
+
assert.equal(typeof c.state.timing.ci_green_min, "number");
|
|
94
|
+
addTiming(c, "review_passes", 2, { raw: true }); assert.equal(c.state.timing.review_passes, 2);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("helpers (#6164)", () => {
|
|
99
|
+
it("flakyTestName reads tap, node runner, jest, pytest and cargo logs", () => {
|
|
100
|
+
assert.equal(flakyTestName("ok 1 - a\nnot ok 2 - writes the file"), "writes the file");
|
|
101
|
+
assert.equal(flakyTestName(" ✖ retries once (12.3ms)"), "retries once");
|
|
102
|
+
assert.equal(flakyTestName(" ● suite › case"), "suite › case");
|
|
103
|
+
assert.equal(flakyTestName("FAILED tests/test_a.py::test_b - boom"), "tests/test_a.py::test_b");
|
|
104
|
+
assert.equal(flakyTestName("test mod::it_works ... FAILED"), "mod::it_works");
|
|
105
|
+
assert.equal(flakyTestName("no pattern here"), null);
|
|
106
|
+
});
|
|
107
|
+
it("block severity defaults to CRITICAL+HIGH; forge.yaml only tightens or loosens it", () => {
|
|
108
|
+
assert.deepEqual([...blockSetOf({})], ["CRITICAL", "HIGH"]);
|
|
109
|
+
assert.deepEqual([...blockSetOf({ blockSeverity: "CRITICAL" })], ["CRITICAL"]);
|
|
110
|
+
assert.deepEqual([...blockSetOf({ blockSeverity: "MEDIUM" })], ["CRITICAL", "HIGH", "MEDIUM"]);
|
|
111
|
+
assert.deepEqual(ciGreenKeys({ block_severity: "medium", ci_green_max_wait_min: "25" }), { blockSeverity: "MEDIUM", ciGreen: { maxWaitMin: 25 } });
|
|
112
|
+
assert.deepEqual(ciGreenKeys({}), {}, "no key switches the flow off; absent keys leave the defaults");
|
|
113
|
+
assert.deepEqual(readReleaseConfig("release:\n block_severity: critical\n").blockSeverity, "CRITICAL");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -33,7 +33,7 @@ export function collectFindings({ head, jobs = [], findings = [], guards = [] })
|
|
|
33
33
|
.map((j) => ({ name: j.name, ...classifyFailure(j.log), inputHash: j.inputHash ?? null, tail: String(j.log ?? "").slice(-LOG_TAIL) }))
|
|
34
34
|
.sort((a, b) => byText(a.name, b.name));
|
|
35
35
|
const review = findings
|
|
36
|
-
.map((f) => ({ id: f.id ?? null, title: String(f.title ?? f.id ?? "finding"), severity: String(f.severity ?? "").toUpperCase() || null, property: f.property ?? f.invariant ?? f.category ?? null, inWave: f.wave !== false, blocking: f.blocking !== false && /^(CRITICAL|HIGH)$/i.test(String(f.severity ?? "")) }))
|
|
36
|
+
.map((f) => ({ id: f.id ?? null, title: String(f.title ?? f.id ?? "finding"), severity: String(f.severity ?? "").toUpperCase() || null, property: f.property ?? f.invariant ?? f.category ?? null, inWave: f.wave !== false, filed: f.filed === true, blocking: f.blocking !== false && /^(CRITICAL|HIGH)$/i.test(String(f.severity ?? "")) }))
|
|
37
37
|
.sort((a, b) => byText(a.title, b.title) || byText(String(a.id), String(b.id)));
|
|
38
38
|
const gs = guards.map((g) => ({ name: g.name, why: String(g.why ?? "") })).sort((a, b) => byText(a.name, b.name));
|
|
39
39
|
return { head, ci, review, guards: gs };
|
|
@@ -137,13 +137,13 @@ describe("release ledger (#5550)", () => {
|
|
|
137
137
|
const g = fakeGh(), seen = [];
|
|
138
138
|
const mkIo = () => ({ print() {}, now: () => 1_700_000_000_000, runningLanes: async () => [], batches: async () => [], setParallel: async () => {}, gh: async () => { throw new Error("no gh"); }, api: g.api });
|
|
139
139
|
const step = (name, die) => async () => { if (die) throw new Error("kill -9"); seen.push(name); return {}; };
|
|
140
|
-
const all = (dieAt) => ({ preflight: step("preflight"), "host-preflight": async () => ({ skipped: true }), deploy: async () => ({ skipped: true }), "release-pr": async () => { if (dieAt === "release-pr") throw new Error("kill -9"); seen.push("release-pr"); return { pr: 7 }; }, review: step("review"), fixes: step("fixes"), "mark-ready": async () => ({ skipped: true }), rehearsal: async () => ({ skipped: true }), promotion: step("promotion"), "post-merge": step("post-merge") });
|
|
140
|
+
const all = (dieAt) => ({ preflight: step("preflight"), "host-preflight": async () => ({ skipped: true }), deploy: async () => ({ skipped: true }), "release-pr": async () => { if (dieAt === "release-pr") throw new Error("kill -9"); seen.push("release-pr"); return { pr: 7 }; }, "ci-green": step("ci-green"), review: step("review"), fixes: step("fixes"), "mark-ready": async () => ({ skipped: true }), rehearsal: async () => ({ skipped: true }), promotion: step("promotion"), "post-merge": step("post-merge") });
|
|
141
141
|
const run = (io, dieAt, root) => runRelease({ io, repo: REPO, root, mounts: DISK, id: ID, opts: {}, config: { managed: true }, branches: {}, steps: all(dieAt) });
|
|
142
142
|
await assert.rejects(() => run(mkIo(), "release-pr", tmpDir("ledgerA-")), /kill -9/);
|
|
143
143
|
assert.deepEqual(seen, ["preflight"]);
|
|
144
144
|
const out = await run(mkIo(), null, tmpDir("ledgerB-")); // host B: empty disk
|
|
145
145
|
assert.equal(out.status, "done");
|
|
146
|
-
assert.deepEqual(seen, ["preflight", "release-pr", "review", "fixes", "promotion", "post-merge"]);
|
|
146
|
+
assert.deepEqual(seen, ["preflight", "release-pr", "ci-green", "review", "fixes", "promotion", "post-merge"]);
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
149
|
|
|
@@ -165,7 +165,7 @@ describe("release fencing through the job (#5553)", () => {
|
|
|
165
165
|
throw new Error(`unexpected gh ${j}`);
|
|
166
166
|
} });
|
|
167
167
|
const skip = async () => ({ skipped: true }), ok = async () => ({});
|
|
168
|
-
const steps = (over = {}) => withStubs({ preflight: ok, "host-preflight": skip, "release-pr": async () => ({ pr: 7 }), review: ok, fixes: ok, "mark-ready": skip, rehearsal: skip, "post-merge": ok, ...over });
|
|
168
|
+
const steps = (over = {}) => withStubs({ preflight: ok, "host-preflight": skip, "release-pr": async () => ({ pr: 7 }), "ci-green": ok, review: ok, fixes: ok, "mark-ready": skip, rehearsal: skip, "post-merge": ok, ...over });
|
|
169
169
|
const go = (io, st, root) => runRelease({ io, repo: REPO, root, mounts: DISK, id: ID, opts: { merge: true }, config: { managed: true }, branches: { staging: "staging", default: "main" }, steps: st ?? steps() });
|
|
170
170
|
|
|
171
171
|
it("the job takes the lease after release-pr and the merge carries the Forge-Epoch trailer and a write-ahead intent", async () => {
|
|
@@ -215,7 +215,7 @@ describe("release fencing through the job (#5553)", () => {
|
|
|
215
215
|
for (const dieAt of RELEASE_STEPS) {
|
|
216
216
|
const g = fakeGh(), calls = [], ran = [];
|
|
217
217
|
const track = (name, fn) => async (...a) => { if (name === dieAt && !ran.includes(`die:${name}`)) { ran.push(`die:${name}`); throw new Error("kill -9"); } ran.push(name); return fn(...a); };
|
|
218
|
-
const base = { preflight: ok, "host-preflight": skip, "release-pr": async () => ({ pr: 7 }), review: ok, fixes: ok, "mark-ready": skip, rehearsal: skip, "post-merge": ok, deploy: skip };
|
|
218
|
+
const base = { preflight: ok, "host-preflight": skip, "release-pr": async () => ({ pr: 7 }), "ci-green": ok, review: ok, fixes: ok, "mark-ready": skip, rehearsal: skip, "post-merge": ok, deploy: skip };
|
|
219
219
|
const wrapped = withStubs(Object.fromEntries(Object.entries(withStubs(base)).map(([k, fn]) => [k, track(k, fn)])));
|
|
220
220
|
await assert.rejects(() => go(mkIo(g, "hostA", calls), wrapped, tmpDir("fe1-")), /kill -9/, dieAt);
|
|
221
221
|
const out = await go(mkIo(g, "hostB", calls), wrapped, tmpDir("fe2-")); // another host, empty disk
|
|
@@ -33,7 +33,7 @@ function fakeIo({ preflightOk = () => true, draft = true } = {}) {
|
|
|
33
33
|
},
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
const run = (io, config, over = {}) => runRelease({ io, repo: REPO, root: tmpDir("rel-pf-"), mounts: DISK, id: newReleaseId(), opts: {}, config, branches: { staging: "staging", default: "main" }, steps: withStubs({ review: ok, fixes: ok, promotion: ok, "post-merge": ok, ...over }) });
|
|
36
|
+
const run = (io, config, over = {}) => runRelease({ io, repo: REPO, root: tmpDir("rel-pf-"), mounts: DISK, id: newReleaseId(), opts: {}, config, branches: { staging: "staging", default: "main" }, steps: withStubs({ "ci-green": ok, review: ok, fixes: ok, promotion: ok, "post-merge": ok, ...over }) });
|
|
37
37
|
const CFG = readReleaseConfig("release:\n preflight_command: npm test\n");
|
|
38
38
|
|
|
39
39
|
describe("release host preflight (#5277)", () => {
|
|
@@ -103,7 +103,7 @@ describe("release host preflight (#5277)", () => {
|
|
|
103
103
|
headOf: async () => HEAD, runLane: async () => ({ terminalReason: "merged" }), fileFixIssue: async () => 3, failedJobs: async () => [],
|
|
104
104
|
calls: [],
|
|
105
105
|
};
|
|
106
|
-
return { io, seam, ctx: { io: Object.assign(io, { review: seam }), repo: REPO, def: "main", staging: "staging", config: CFG, save() {}, state: { steps: { review: { result: { pr: 9, marker: "FORGE:GATE_FAILURE", verdict: "X", head: "b".repeat(40), blocking: [11], ciFailing: 0 } } } } } };
|
|
106
|
+
return { io, seam, ctx: { io: Object.assign(io, { review: seam }), repo: REPO, def: "main", staging: "staging", config: { ...CFG, reviewFixes: true }, save() {}, state: { steps: { review: { result: { pr: 9, marker: "FORGE:GATE_FAILURE", verdict: "X", head: "b".repeat(40), blocking: [11], ciFailing: 0 } } } } } };
|
|
107
107
|
};
|
|
108
108
|
const red = mk(false);
|
|
109
109
|
const out = await fixStep(red.ctx);
|
|
@@ -35,7 +35,7 @@ function fakeIo({ run = { ok: true }, issues = [], body = "Bundle" } = {}) {
|
|
|
35
35
|
return io;
|
|
36
36
|
}
|
|
37
37
|
const go = async (io, config, root = tmpDir("rehearsal-"), id = newReleaseId()) => ({
|
|
38
|
-
out: await runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config, branches: { staging: "staging", default: "main" }, steps: withStubs({ review: ok, fixes: ok, "post-merge": ok }) }),
|
|
38
|
+
out: await runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config, branches: { staging: "staging", default: "main" }, steps: withStubs({ "ci-green": ok, review: ok, fixes: ok, "post-merge": ok }) }),
|
|
39
39
|
root, id,
|
|
40
40
|
});
|
|
41
41
|
const cfg = (o = {}) => ({ rehearsal: parseRehearsalConfig({ rehearsal_command: "./dry-run.sh", ...o }) });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
/**
|
|
4
|
-
* End-to-end run of `forgedock release` through the real job (preflight, release-pr, review, fixes, promotion) against an
|
|
4
|
+
* (Legacy, `release.review_fixes: true`; the default flow stops at review blockers: release-review.test.mjs.) End-to-end run of `forgedock release` through the real job (preflight, release-pr, review, fixes, promotion) against an
|
|
5
5
|
* in-memory GitHub (#5212, R1): the release PR exists, the panel runs, a HIGH finding is filed and blocks, a fix lane merges
|
|
6
6
|
* to staging, the delta review passes, and the job stops at GATE_PASS with the merge command, with no manual step. GitHub, the
|
|
7
7
|
* model and the lane process are in memory (as in conformance.e2e.test.mjs); the job, steps, state and resume are real.
|
|
@@ -29,6 +29,7 @@ function world() {
|
|
|
29
29
|
throw new Error(`unexpected gh ${j}`);
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
|
+
io.ciGreen = { now: () => 0, sleep: async () => {}, isDraft: async () => false, headOf: async () => sha(w.head), checks: async () => [], required: async () => [] }; // CI is green at once
|
|
32
33
|
io.review = {
|
|
33
34
|
pre: async ({ delta }) => ({ code: 0, lines: [], data: { pr: 7, headSha: sha(w.head), bundle: [1, 2], scopeMode: "full", contextFile: "/sd/ctx.json", launchedFile: "/sd/l", briefs: [{ domain: "security", path: "/sd/b" }], delta: delta ? { from: delta, files: ["f"] } : null } }),
|
|
34
35
|
headOf: async () => sha(w.head),
|
|
@@ -55,7 +56,7 @@ function world() {
|
|
|
55
56
|
describe("forgedock release, review to gate (e2e on in-memory GitHub)", () => {
|
|
56
57
|
it("reviews, files the blocking finding, fixes it on staging, re-reviews the delta and stops at GATE_PASS with the merge command", async () => {
|
|
57
58
|
const { w, io } = world();
|
|
58
|
-
const out = await runRelease({ io, repo: "o/r", root: tmpDir("rel-e2e-"), mounts: DISK, id: newReleaseId(), opts: {}, config: {}, branches: { staging: "staging", default: "main" } });
|
|
59
|
+
const out = await runRelease({ io, repo: "o/r", root: tmpDir("rel-e2e-"), mounts: DISK, id: newReleaseId(), opts: {}, config: { reviewFixes: true }, branches: { staging: "staging", default: "main" } });
|
|
59
60
|
assert.equal(out.status, "stopped");
|
|
60
61
|
assert.equal(out.step, "promotion");
|
|
61
62
|
assert.match(out.reason, /GATE_PASS/);
|
|
@@ -69,7 +70,7 @@ describe("forgedock release, review to gate (e2e on in-memory GitHub)", () => {
|
|
|
69
70
|
it("a killed job resumes after the review step without re-running it", async () => {
|
|
70
71
|
const { w, io } = world();
|
|
71
72
|
const root = tmpDir("rel-e2e-"), id = newReleaseId();
|
|
72
|
-
const args = { io, repo: "o/r", root, mounts: DISK, id, opts: {}, config: {}, branches: { staging: "staging", default: "main" } };
|
|
73
|
+
const args = { io, repo: "o/r", root, mounts: DISK, id, opts: {}, config: { reviewFixes: true }, branches: { staging: "staging", default: "main" } };
|
|
73
74
|
await runRelease(args);
|
|
74
75
|
const agents = w.agents.length;
|
|
75
76
|
assert.equal(openRelease(root, id, DISK).load().steps.fixes.done, true);
|