forgedock 1.67.0 → 1.69.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/config-schema.mjs +1 -0
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine-cli.mjs +103 -21
- package/bin/engine.mjs +10 -0
- package/bin/forgedock.mjs +17 -1
- package/bin/help-text.mjs +1 -0
- package/bin/lean/admission.mjs +21 -0
- package/bin/lean/admission.test.mjs +30 -0
- package/bin/lean/advisory.test.mjs +39 -15
- package/bin/lean/amendment-schema.mjs +3 -4
- package/bin/lean/attempts.mjs +34 -31
- package/bin/lean/attempts.test.mjs +33 -19
- package/bin/lean/basered.mjs +26 -0
- package/bin/lean/batch-health.mjs +17 -12
- package/bin/lean/batch-health.test.mjs +39 -11
- package/bin/lean/batch.mjs +11 -1
- package/bin/lean/batch.test.mjs +51 -2
- package/bin/lean/capsample.mjs +25 -0
- package/bin/lean/ci-gate.mjs +2 -90
- package/bin/lean/ci-gate.test.mjs +1 -127
- package/bin/lean/ci-precheck.mjs +25 -8
- package/bin/lean/ci-precheck.test.mjs +24 -0
- package/bin/lean/clear-breaker.test.mjs +4 -3
- package/bin/lean/commentstate.mjs +10 -5
- package/bin/lean/commentstate.test.mjs +12 -1
- package/bin/lean/conformance.e2e.test.mjs +9 -6
- package/bin/lean/conformance.mjs +62 -197
- package/bin/lean/conformance.test.mjs +46 -376
- package/bin/lean/depcache.mjs +102 -10
- package/bin/lean/depcache.test.mjs +105 -0
- package/bin/lean/docsgate.mjs +0 -32
- package/bin/lean/docsgate.test.mjs +2 -23
- package/bin/lean/effects-cap.test.mjs +9 -1
- package/bin/lean/effects-killtree.test.mjs +35 -0
- package/bin/lean/effects.mjs +57 -25
- package/bin/lean/engine-readmit.test.mjs +35 -0
- package/bin/lean/envgap.mjs +111 -0
- package/bin/lean/envgap.test.mjs +64 -0
- package/bin/lean/execution.mjs +13 -4
- package/bin/lean/execution.test.mjs +33 -0
- package/bin/lean/failure-census.mjs +170 -0
- package/bin/lean/failure-census.test.mjs +59 -0
- package/bin/lean/failure-stop.mjs +12 -1
- package/bin/lean/failure-stop.test.mjs +14 -1
- package/bin/lean/guardgate.test.mjs +2 -3
- package/bin/lean/heavy.mjs +33 -4
- package/bin/lean/heavy.test.mjs +38 -6
- package/bin/lean/hostconfig.mjs +54 -0
- package/bin/lean/hostconfig.test.mjs +67 -0
- package/bin/lean/hotarea.mjs +0 -36
- package/bin/lean/hotarea.test.mjs +1 -22
- package/bin/lean/issuewatch-verify.mjs +19 -4
- package/bin/lean/issuewatch.mjs +21 -4
- package/bin/lean/issuewatch.test.mjs +48 -1
- package/bin/lean/lane-audit-gap.mjs +66 -0
- package/bin/lean/lane-audit-gap.test.mjs +59 -0
- package/bin/lean/lane-audit-llm.mjs +52 -0
- package/bin/lean/lane-audit-llm.test.mjs +57 -0
- package/bin/lean/lane-audit-query.mjs +47 -0
- package/bin/lean/lane-audit-query.test.mjs +44 -0
- package/bin/lean/lane-audit-signatures.mjs +33 -0
- package/bin/lean/lane-audit.mjs +110 -0
- package/bin/lean/lane-audit.test.mjs +97 -0
- package/bin/lean/lane-recovery.test.mjs +33 -0
- package/bin/lean/lanecheck.mjs +5 -3
- package/bin/lean/lanecheck.test.mjs +6 -0
- package/bin/lean/lean.mjs +247 -152
- package/bin/lean/lean.test.mjs +502 -206
- package/bin/lean/limits.mjs +17 -0
- package/bin/lean/limits.test.mjs +15 -1
- package/bin/lean/live-execution.mjs +24 -2
- package/bin/lean/live-execution.test.mjs +62 -0
- package/bin/lean/orchestrate-attempts.test.mjs +17 -9
- package/bin/lean/orchestrate-dispatch-placement.test.mjs +81 -0
- package/bin/lean/orchestrate-envhold.test.mjs +62 -1
- package/bin/lean/orchestrate-heldroot.test.mjs +72 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +59 -1
- package/bin/lean/orchestrate-overload-recovery.test.mjs +37 -0
- package/bin/lean/orchestrate-pause.test.mjs +53 -1
- package/bin/lean/orchestrate-reconcile.test.mjs +17 -0
- package/bin/lean/orchestrate-relaunch-gates.test.mjs +57 -0
- package/bin/lean/orchestrate-stacking.test.mjs +10 -0
- package/bin/lean/orchestrate.mjs +215 -42
- package/bin/lean/postdeploy-check.test.mjs +1 -3
- package/bin/lean/precheck.mjs +20 -0
- package/bin/lean/preflight.mjs +110 -14
- package/bin/lean/preflight.test.mjs +64 -4
- package/bin/lean/prompts.mjs +11 -21
- package/bin/lean/recurrence.mjs +6 -148
- package/bin/lean/recurrence.test.mjs +11 -147
- package/bin/lean/release-deploy.mjs +35 -5
- package/bin/lean/release-deploy.test.mjs +50 -3
- package/bin/lean/release-flakes.mjs +48 -2
- package/bin/lean/release-flakes.test.mjs +45 -1
- package/bin/lean/release-ledger.mjs +19 -1
- package/bin/lean/release-ledger.test.mjs +23 -0
- package/bin/lean/release-preflight.mjs +28 -0
- package/bin/lean/release-preflight.test.mjs +42 -1
- package/bin/lean/release-review.mjs +40 -5
- package/bin/lean/release-review.test.mjs +43 -2
- package/bin/lean/release.mjs +45 -15
- package/bin/lean/release.test.mjs +32 -0
- package/bin/lean/retry.mjs +1 -1
- package/bin/lean/retry.test.mjs +6 -1
- package/bin/lean/rotator.mjs +9 -0
- package/bin/lean/rotator.test.mjs +11 -1
- package/bin/lean/sandbox-remote.mjs +51 -13
- package/bin/lean/schedd.mjs +13 -8
- package/bin/lean/schedd.test.mjs +65 -5
- package/bin/lean/selfreview.mjs +1 -1
- package/bin/lean/statuscomment.mjs +4 -1
- package/bin/lean/validate-catalog.mjs +108 -0
- package/bin/lean/validate-catalog.test.mjs +46 -1
- package/bin/lean/verify.mjs +1 -1
- package/bin/pool/affinity.test.mjs +91 -0
- package/bin/pool/agent.mjs +247 -23
- package/bin/pool/cache-sweep.mjs +31 -10
- package/bin/pool/ci-autoscale.mjs +160 -0
- package/bin/pool/cli.mjs +56 -9
- package/bin/pool/docker.mjs +5 -0
- package/bin/pool/engine-placement.test.mjs +94 -0
- package/bin/pool/image-manifest.mjs +24 -0
- package/bin/pool/image-manifest.test.mjs +20 -0
- package/bin/pool/lane-target.mjs +41 -0
- package/bin/pool/lane-tools.mjs +29 -5
- package/bin/pool/lane-tools.test.mjs +36 -7
- package/bin/pool/mirror-seed.mjs +15 -11
- package/bin/pool/project-layer.mjs +142 -0
- package/bin/pool/project-layer.test.mjs +73 -0
- package/bin/pool/router.mjs +106 -36
- package/bin/pool/version.mjs +72 -2
- package/bin/review-staging.mjs +11 -3
- package/bin/runner.mjs +59 -11
- package/bin/stats/release.mjs +7 -0
- package/bin/stats/release.test.mjs +20 -0
- package/bin/stats/scorecard.mjs +187 -0
- package/bin/stats/scorecard.test.mjs +89 -0
- package/bin/stats/tool-parks.mjs +29 -0
- package/bin/stats/tool-parks.test.mjs +21 -0
- package/docs/CONFIG.md +41 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +17 -0
- package/package.json +1 -1
- package/pool/image/Dockerfile +15 -3
- package/pool/image/manifest.json +25 -0
- package/pool/image/mirror.sh +11 -2
- package/pool/install/install-agent.ps1 +11 -4
- package/scripts/ci-local/adapters/github-actions.mjs +8 -0
- package/scripts/ci-local/cli.mjs +1 -1
- package/scripts/ci-local/plan.mjs +3 -2
- package/scripts/ci-local.test.sh +14 -2
- package/scripts/failure-census.mjs +67 -0
- package/scripts/review-finalize.sh +5 -5
- package/scripts/review-finalize.test.sh +8 -1
- package/scripts/verify-phase-trail.sh +11 -0
- package/scripts/verify-phase-trail.test.sh +9 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { parseFlakeConfig, classifyFailure, detectSameShaFlip, flakeEntry, planRerun, repeatedFlakes, fileFlakeIssue, canQuarantine, activeQuarantines, shouldWriteMarker, isUnskippable, recordFlakes, UNSKIPPABLE_CLASSES } from "./release-flakes.mjs";
|
|
5
|
+
import { parseFlakeConfig, classifyFailure, detectSameShaFlip, flakeEntry, planRerun, attemptGuard, RERUN_ATTEMPT_CAP, repeatedFlakes, fileFlakeIssue, canQuarantine, activeQuarantines, shouldWriteMarker, isUnskippable, recordFlakes, UNSKIPPABLE_CLASSES } from "./release-flakes.mjs";
|
|
6
6
|
import { rerunInfraFlakes } from "./release.mjs";
|
|
7
7
|
|
|
8
8
|
const NOW = Date.parse("2026-11-12T00:00:00Z"), DAY = 86_400_000;
|
|
@@ -129,3 +129,47 @@ describe("quarantineReport (#5710)", async () => {
|
|
|
129
129
|
assert.deepEqual(quarantineReport(all, { mode: "off" }, now), []);
|
|
130
130
|
});
|
|
131
131
|
});
|
|
132
|
+
|
|
133
|
+
import { test as t6014 } from "node:test";
|
|
134
|
+
import assert6014 from "node:assert/strict";
|
|
135
|
+
t6014("#6014: attempt cap refuses a third rerun, records attempt and forfeited reuse", () => {
|
|
136
|
+
assert6014.equal(RERUN_ATTEMPT_CAP, 2);
|
|
137
|
+
assert6014.equal(attemptGuard({ attempt: 2 }).allow, true);
|
|
138
|
+
assert6014.equal(attemptGuard({ attempt: 3 }).allow, false);
|
|
139
|
+
assert6014.equal(attemptGuard({ attempt: 5 }).allow, false);
|
|
140
|
+
assert6014.equal(attemptGuard({ attempt: null }).allow, true);
|
|
141
|
+
const [a, b] = planRerun({ jobs: [{ key: "x", class: "infra", attempt: 3 }, { key: "y", class: "infra", attempt: 2 }], budgetMin: 30 });
|
|
142
|
+
assert6014.equal(a.rerun, false); assert6014.match(a.why, /attempt 3/);
|
|
143
|
+
assert6014.equal(b.rerun, true);
|
|
144
|
+
const e = flakeEntry({ check: "c", kind: "infra", at: "t", rerun: true, attempt: 2, reuseForfeited: true });
|
|
145
|
+
assert6014.equal(e.attempt, 2); assert6014.match(e.reuse_forfeited, /reuse forfeited/);
|
|
146
|
+
assert6014.equal("attempt" in flakeEntry({ check: "c", kind: "infra", at: "t" }), false);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("classifyFailedStep and deploy-class reruns (#6015)", async () => {
|
|
150
|
+
const { classifyFailedStep, isDeployWorkflow } = await import("./release-flakes.mjs");
|
|
151
|
+
const L = (step, msg) => `deploy\t${step}\t2026-01-01T00:00:00Z ${msg}`;
|
|
152
|
+
it("names the class and transience of the failed step", () => {
|
|
153
|
+
const k = (o) => { const r = classifyFailedStep(o); return [r.class, r.transient]; };
|
|
154
|
+
assert.deepEqual(k({ log: L("Decrypt secrets", "sops: failed to decrypt") }), ["secrets", false]);
|
|
155
|
+
assert.deepEqual(k({ log: L("Deploy via SSH", "ssh: connect to host h port 22: Connection timed out ETIMEDOUT") }), ["ssh", false]);
|
|
156
|
+
assert.deepEqual(k({ log: L("Migration Rehearsal", "ECONNRESET") }), ["rehearsal", false]);
|
|
157
|
+
assert.deepEqual(k({ log: L("Run migrations", "failed") }), ["migration", false]);
|
|
158
|
+
assert.deepEqual(k({ log: L("Pull images", "ECONNRESET") }), ["infra", true]);
|
|
159
|
+
assert.deepEqual(k({ log: L("Build", "tsc error") }), ["deterministic", false]);
|
|
160
|
+
assert.deepEqual(k({ log: "", reason: "LIVE_CHECK failed" }), ["live-check", false]);
|
|
161
|
+
assert.deepEqual(k({ log: "", reason: "the run set DEPLOY_FREEZE" }), ["freeze", false]);
|
|
162
|
+
assert.equal(classifyFailedStep({ steps: [{ name: "Deploy via SSH", conclusion: "failure" }], log: "" }).step, "Deploy via SSH");
|
|
163
|
+
});
|
|
164
|
+
it("matches no deploy class for ordinary CI names", () => {
|
|
165
|
+
assert.equal(isDeployWorkflow("Migration Rehearsal"), true); assert.equal(isDeployWorkflow("Deploy production"), true);
|
|
166
|
+
assert.equal(isDeployWorkflow("unit"), false); assert.equal(isDeployWorkflow("lint"), false);
|
|
167
|
+
});
|
|
168
|
+
it("rerunInfraFlakes skips deploy-class runs", async () => {
|
|
169
|
+
const calls = [];
|
|
170
|
+
const io = { now: () => NOW, api: async () => ({}), gh: async (a) => { calls.push(a); return a[1] === "list" ? JSON.stringify([{ databaseId: 5, name: "Deploy production" }]) : "Unable to upload artifact"; } };
|
|
171
|
+
const fence = { lctx: { io, repo: "o/r", credential: "driver" }, lease: { holder: "A", epoch: 1, release: "r1" }, record: async () => {}, now: () => "t" };
|
|
172
|
+
const r = await rerunInfraFlakes({ io, repo: "o/r", head: "abc", fence, policy: { ci: { rerun_budget_min: 30 } } });
|
|
173
|
+
assert.deepEqual(r.reran, []); assert.match(r.skipped[0].why, /deploy-class/); assert.equal(calls.filter((c) => c[1] === "rerun").length, 0);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -221,6 +221,24 @@ export async function recordTrain(ctx, rec, now = Date.now()) {
|
|
|
221
221
|
return updateActive(ctx, ["train"], (active) => ({ patch: { train: { ...(active.train ?? {}), [rec.release ?? "-"]: { ...rec, lane: "train", rollout_invalidated: true, at } } }, control: { at, verb: "train", lane: "train", release: rec.release ?? null, state: rec.state ?? null, units: rec.units?.length ?? 0, rollout_invalidated: true } }));
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
const CAUSES = ["regression", "flake", "runner"];
|
|
225
|
+
/** #6013: append one snapshot round `{n, pr, head, outcome, cause, startedAt, endedAt}` to `state.rounds` (n is assigned, cause normalised). */
|
|
226
|
+
export function recordReleaseRound(state, r) {
|
|
227
|
+
state.rounds ??= [];
|
|
228
|
+
const round = { n: state.rounds.length + 1, pr: r.pr ?? null, head: r.head ?? null, outcome: r.outcome ?? null, cause: CAUSES.includes(r.cause) ? r.cause : null, startedAt: r.startedAt ?? null, endedAt: r.endedAt ?? null };
|
|
229
|
+
state.rounds.push(round);
|
|
230
|
+
return round;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** `{rounds, snapshots, wallMin, causes}` derived from `state.rounds`; wall time is first start -> last end. */
|
|
234
|
+
export function roundStats(rounds = []) {
|
|
235
|
+
const list = Array.isArray(rounds) ? rounds : [];
|
|
236
|
+
const t = list.flatMap((r) => [Date.parse(r.startedAt), Date.parse(r.endedAt)]).filter(Number.isFinite);
|
|
237
|
+
const causes = { regression: 0, flake: 0, runner: 0 };
|
|
238
|
+
for (const r of list) if (r.cause in causes) causes[r.cause]++;
|
|
239
|
+
return { rounds: list, snapshots: list.length, wallMin: t.length ? Math.round((Math.max(...t) - Math.min(...t)) / 600) / 100 : 0, causes };
|
|
240
|
+
}
|
|
241
|
+
|
|
224
242
|
/**
|
|
225
243
|
* #5718: release state for `forgedock stats --release-ledger`. One record per managed release started at or after `sinceMs`:
|
|
226
244
|
* `{id, pr, startedAt, status, live, deployAttempts}` (read-only; a release without a readable state is skipped). The id
|
|
@@ -237,7 +255,7 @@ export async function releaseRecords(ctx, { sinceMs = 0 } = {}) {
|
|
|
237
255
|
const pr = s.steps?.["release-pr"]?.result?.pr ?? s.pr ?? null;
|
|
238
256
|
const phase = String(s.deploy?.phase ?? "");
|
|
239
257
|
out.push({ id, pr: pr == null ? null : Number(pr), startedAt: s.startedAt ?? null, status: s.status ?? null,
|
|
240
|
-
live: ["live", "done"].includes(String(s.status ?? "").toLowerCase()) || phase.startsWith("LIVE"), deployAttempts: Number(s.deploy?.attempts) || 0 });
|
|
258
|
+
live: ["live", "done"].includes(String(s.status ?? "").toLowerCase()) || phase.startsWith("LIVE"), deployAttempts: Number(s.deploy?.attempts) || 0, ...(Array.isArray(s.rounds) ? roundStats(redactDeep(s.rounds)) : {}) });
|
|
241
259
|
}
|
|
242
260
|
return out;
|
|
243
261
|
}
|
|
@@ -256,3 +256,26 @@ describe("recordSync (#5566)", async () => {
|
|
|
256
256
|
assert.equal(line.milestones, 1);
|
|
257
257
|
});
|
|
258
258
|
});
|
|
259
|
+
|
|
260
|
+
describe("release ledger rounds (#6013)", () => {
|
|
261
|
+
it("records rounds with count, wall time and cause, redacted on write and read back", async () => {
|
|
262
|
+
const { recordReleaseRound, roundStats } = await import("./release-ledger.mjs");
|
|
263
|
+
const gh = fakeGh(), ctx = ctxOf(gh);
|
|
264
|
+
const state = { status: "running" };
|
|
265
|
+
recordReleaseRound(state, { pr: 9, head: "a1", outcome: "fail", cause: "regression", startedAt: "2026-11-01T10:00:00Z", endedAt: "2026-11-01T10:30:00Z" });
|
|
266
|
+
recordReleaseRound(state, { pr: 10, head: "b2", outcome: "pass", cause: "bogus", startedAt: "2026-11-01T11:00:00Z", endedAt: "2026-11-01T11:45:00Z" });
|
|
267
|
+
assert.deepEqual(state.rounds.map((r) => r.n), [1, 2]);
|
|
268
|
+
assert.equal(state.rounds[1].cause, null, "unknown cause is not recorded");
|
|
269
|
+
const s = roundStats(state.rounds);
|
|
270
|
+
assert.equal(s.snapshots, 2);
|
|
271
|
+
assert.equal(s.wallMin, 105);
|
|
272
|
+
assert.deepEqual(s.causes, { regression: 1, flake: 0, runner: 0 });
|
|
273
|
+
assert.equal(roundStats(undefined).snapshots, 0);
|
|
274
|
+
state.rounds[0].head = "ghp_" + "a".repeat(36);
|
|
275
|
+
await createReleaseLedger(ctx, ID, state);
|
|
276
|
+
const back = (await readLedger(ctx, ID)).state;
|
|
277
|
+
assert.equal(back.rounds.length, 2);
|
|
278
|
+
assert.ok(!JSON.stringify(back).includes("ghp_aaaa"), "secrets are redacted");
|
|
279
|
+
assert.equal(roundStats(back.rounds).snapshots, 2);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* retries. With no command set every function here is a no-op. No model call. Effects go through `ctx.io`.
|
|
8
8
|
*/
|
|
9
9
|
import { fileBlocker, tail } from "./release-rehearsal.mjs";
|
|
10
|
+
import { classifyFailure } from "./release-flakes.mjs";
|
|
10
11
|
import { fenced } from "./release-fence.mjs";
|
|
11
12
|
|
|
12
13
|
export const PREFLIGHT_TIMEOUT_MS = 20 * 60_000;
|
|
@@ -62,6 +63,33 @@ export async function hostPreflightStep(ctx) {
|
|
|
62
63
|
return !r.ok && r.blocking ? stopOf(r) : r;
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
const BAD = new Set(["failure", "timed_out", "cancelled", "action_required", "startup_failure"]);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Staging-health gate (#6013): before a snapshot is cut, every check-run of the staging head must be finished and green. Names ALL
|
|
70
|
+
* failed checks of the run (class: regression|runner via classifyFailure; a flake is a failure a rerun cleared, recorded by the
|
|
71
|
+
* round ledger) and pending ones (staging is behind). `config.allowRedStaging` proceeds with a recorded warning. No model call.
|
|
72
|
+
* Failed checks that the staging branch protection does not require are reported as `parityGap` (lane-check parity).
|
|
73
|
+
* @returns {{ok: true, head, warning?: string, failed?: object[]}|{refused: string, head, failed: object[], pending: string[]}}
|
|
74
|
+
*/
|
|
75
|
+
export async function stagingHealthStep(ctx) {
|
|
76
|
+
const { io, repo, staging, config } = ctx;
|
|
77
|
+
const head = String(await io.gh(["api", `repos/${repo}/commits/${staging}`, "--jq", ".sha"])).trim();
|
|
78
|
+
const runs = await io.gh(["api", `repos/${repo}/commits/${head}/check-runs?per_page=100`, "--jq", "[.check_runs[]|{name,status,conclusion,text:((.output.title//\"\")+\" \"+(.output.summary//\"\"))}]"]).then((t) => { try { const v = json(t); return Array.isArray(v) ? v.filter((c) => c && typeof c.status === "string") : []; } catch { return []; } }, () => []);
|
|
79
|
+
const failed = (runs ?? []).filter((c) => c.status === "completed" && BAD.has(c.conclusion))
|
|
80
|
+
.map((c) => ({ name: c.name, conclusion: c.conclusion, cause: classifyFailure(c.text).class === "infra" ? "runner" : "regression" }))
|
|
81
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
82
|
+
const pending = (runs ?? []).filter((c) => c.status !== "completed").map((c) => c.name).sort();
|
|
83
|
+
if (!failed.length && !pending.length) return { ok: true, head };
|
|
84
|
+
// Lane-check parity (R3): a check red on staging that lane merges do not require is a gap the lane gate let through.
|
|
85
|
+
const req = await io.gh(["api", `repos/${repo}/branches/${staging}/protection/required_status_checks`, "--jq", "[.contexts[]?, .checks[]?.context]"]).then((t) => { try { const v = json(t); return Array.isArray(v) ? v : null; } catch { return null; } }, () => null);
|
|
86
|
+
const parityGap = req ? failed.map((f) => f.name).filter((n) => !req.includes(n)) : [];
|
|
87
|
+
const what = [failed.length ? `failed: ${failed.map((f) => `${f.name} (${f.cause})`).join(", ")}` : "", pending.length ? `pending: ${pending.join(", ")}` : ""].filter(Boolean).join("; ");
|
|
88
|
+
const gap = parityGap.length ? ` lane-check parity gap (not required for lane merges): ${parityGap.join(", ")}` : "";
|
|
89
|
+
if (config?.allowRedStaging) return { ok: true, head, failed, parityGap, warning: `staging ${staging}@${head} is not green (${what}); release.allow_red_staging is set` };
|
|
90
|
+
return { refused: `staging ${staging}@${head} is not green (${what}); fix every failure against ${staging} in one batch, then resume.${gap}`, head, failed, pending, parityGap };
|
|
91
|
+
}
|
|
92
|
+
|
|
65
93
|
/** Step after `fixes`: preflight on the final head, then mark the draft release PR ready so Actions CI runs once on it. */
|
|
66
94
|
export async function markReadyStep(ctx) {
|
|
67
95
|
if (!ctx.config.preflight) return { skipped: true };
|
|
@@ -4,7 +4,7 @@ import { describe, it } from "node:test";
|
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
6
6
|
import { runRelease, withStubs, readReleaseConfig, newReleaseId } from "./release.mjs";
|
|
7
|
-
import { parsePreflightConfig, markReadyStep, coStartCi } from "./release-preflight.mjs";
|
|
7
|
+
import { parsePreflightConfig, markReadyStep, coStartCi, stagingHealthStep } from "./release-preflight.mjs";
|
|
8
8
|
import { fixStep } from "./release-review.mjs";
|
|
9
9
|
|
|
10
10
|
const DISK = [{ mount: "/", type: "ext4" }];
|
|
@@ -128,3 +128,44 @@ describe("co-start CI (#5567)", () => {
|
|
|
128
128
|
assert.ok(calls.some((c) => c.startsWith("pr ready")) && calls.some((c) => c.startsWith("workflow run full.yml")));
|
|
129
129
|
});
|
|
130
130
|
});
|
|
131
|
+
|
|
132
|
+
describe("staging-health gate (#6013)", () => {
|
|
133
|
+
const checks = (list) => ({ ...fakeIo(), gh: async (a) => (a[1].includes("/check-runs") ? JSON.stringify(list) : `${HEAD}\n`) });
|
|
134
|
+
const ctxOf = (io, config = {}) => ({ io, repo: REPO, staging: "staging", config });
|
|
135
|
+
const red = [
|
|
136
|
+
{ name: "black", status: "completed", conclusion: "failure", text: "would reformat" },
|
|
137
|
+
{ name: "suite", status: "completed", conclusion: "failure", text: "ECONNRESET while pulling image" },
|
|
138
|
+
{ name: "lint", status: "completed", conclusion: "success", text: "" },
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
it("refuses a red head naming every failed check with its cause", async () => {
|
|
142
|
+
const r = await stagingHealthStep(ctxOf(checks(red)));
|
|
143
|
+
assert.match(r.refused, /black \(regression\)/);
|
|
144
|
+
assert.match(r.refused, /suite \(runner\)/);
|
|
145
|
+
assert.equal(r.failed.length, 2);
|
|
146
|
+
});
|
|
147
|
+
it("R3: names failed checks that lane merges do not require as a parity gap", async () => {
|
|
148
|
+
const io = { ...fakeIo(), gh: async (a) => (a[1].includes("/check-runs") ? JSON.stringify(red) : a[1].includes("required_status_checks") ? JSON.stringify(["suite"]) : `${HEAD}\n`) };
|
|
149
|
+
const r = await stagingHealthStep(ctxOf(io));
|
|
150
|
+
assert.deepEqual(r.parityGap, ["black"]);
|
|
151
|
+
assert.match(r.refused, /parity gap.*black/);
|
|
152
|
+
});
|
|
153
|
+
it("proceeds on green; refuses pending; override proceeds with a warning", async () => {
|
|
154
|
+
assert.equal((await stagingHealthStep(ctxOf(checks([{ name: "a", status: "completed", conclusion: "success" }])))).ok, true);
|
|
155
|
+
const pend = await stagingHealthStep(ctxOf(checks([{ name: "slow", status: "in_progress", conclusion: null }])));
|
|
156
|
+
assert.match(pend.refused, /pending: slow/);
|
|
157
|
+
const o = await stagingHealthStep(ctxOf(checks(red), { allowRedStaging: true }));
|
|
158
|
+
assert.equal(o.ok, true);
|
|
159
|
+
assert.match(o.warning, /allow_red_staging/);
|
|
160
|
+
assert.equal(readReleaseConfig("release:\n allow_red_staging: true\n").allowRedStaging, true);
|
|
161
|
+
});
|
|
162
|
+
it("N known failures resolve in 2 rounds: gate refuses once, then the cut proceeds", async () => {
|
|
163
|
+
let fixed = false, cuts = 0;
|
|
164
|
+
const io = { ...fakeIo(), gh: async (a) => (a[1].includes("/check-runs") ? JSON.stringify(fixed ? [] : red) : `${HEAD}\n`) };
|
|
165
|
+
const one = await stagingHealthStep(ctxOf(io));
|
|
166
|
+
assert.equal(one.failed.length, 2); // round 1: all failures named together, no snapshot cut
|
|
167
|
+
fixed = true; // one batched fix merged
|
|
168
|
+
if ((await stagingHealthStep(ctxOf(io))).ok) cuts++; // round 2
|
|
169
|
+
assert.equal(cuts, 1);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { execFileSync, spawn } from "node:child_process";
|
|
12
12
|
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, appendFileSync, rmSync } from "node:fs";
|
|
13
|
-
import { tmpdir, homedir } from "node:os";
|
|
13
|
+
import { tmpdir, homedir, cpus } from "node:os";
|
|
14
14
|
import { delimiter, join } from "node:path";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
16
|
import { runHostPreflight } from "./release-preflight.mjs";
|
|
17
|
+
import { lowerPriority } from "./hostload.mjs";
|
|
17
18
|
import { reviewStagingJson, reviewStagingIo, CI_EXCLUDED_CHECKS } from "../review-staging.mjs";
|
|
18
19
|
import { pickFixes, recut, revertLast } from "./release-snapshot.mjs";
|
|
19
20
|
import { parseFixConfig, collectFindings, blockingOf, compileBrief, roundsAt, recordRound, secondPush, secondPushOf, holdForOwner, jobsToRerun, inputHash, deferredOf } from "./release-fixloop.mjs";
|
|
@@ -106,6 +107,30 @@ export function resolveSkillName(name, { configDir, read = (p) => readFileSync(p
|
|
|
106
107
|
try { return /"forgedock(@[^"]*)?"\s*:/.test(read(join(configDir, "plugins", "installed_plugins.json"))) ? `forgedock:${name}` : name; } catch { return name; }
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
/** #6098: default reviewer fan-out on this host: max(2, cores / 2). */
|
|
111
|
+
export const defaultReviewParallel = (cores = cpus().length || 1) => Math.max(2, Math.floor(cores / 2));
|
|
112
|
+
/** #6098: forge.yaml `review.max_parallel` (a positive integer) read from raw text; null when absent or invalid. */
|
|
113
|
+
export function reviewMaxParallel(raw) {
|
|
114
|
+
const lines = String(raw ?? "").split("\n");
|
|
115
|
+
const at = lines.findIndex((l) => /^review:\s*(#.*)?$/.test(l));
|
|
116
|
+
if (at < 0) return null;
|
|
117
|
+
for (let i = at + 1; i < lines.length; i++) {
|
|
118
|
+
const l = lines[i];
|
|
119
|
+
if (!l.trim() || /^\s*#/.test(l)) continue;
|
|
120
|
+
if (/^\S/.test(l)) break;
|
|
121
|
+
const m = /^\s+max_parallel:\s*["']?(\d+)["']?\s*(#.*)?$/.exec(l);
|
|
122
|
+
if (m) return Number(m[1]) > 0 ? Number(m[1]) : null;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
/** #6098: run `fn` over `items` with at most `cap` in flight; the rest queue. Results keep the input order; a rejection rejects the batch. */
|
|
127
|
+
export async function mapLimit(items, cap, fn) {
|
|
128
|
+
const n = Math.max(1, Math.floor(Number(cap)) || 1), out = new Array(items.length);
|
|
129
|
+
let next = 0;
|
|
130
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => { for (;;) { const i = next++; if (i >= items.length) return; out[i] = await fn(items[i], i); } }));
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
109
134
|
/** One review round at the current head: dispatch, test gate, head check, finalize. @returns {{moved: string}|{fail}|{ok}} */
|
|
110
135
|
async function reviewRound({ seam, pr, def, delta }) {
|
|
111
136
|
const pre = await seam.pre({ pr, delta });
|
|
@@ -122,7 +147,8 @@ async function reviewRound({ seam, pr, def, delta }) {
|
|
|
122
147
|
const send = (domain, note = "") => seam.runAgent({ role: `release-review-${domain}`, issue: pr, prompt: note ? `${prompts.get(domain)}\n\n${note}` : prompts.get(domain) });
|
|
123
148
|
const failures = new Map();
|
|
124
149
|
const attempt = (domain, note) => send(domain, note).catch((e) => { failures.set(domain, sessionFailure(e)); return null; });
|
|
125
|
-
|
|
150
|
+
const cap = Math.max(1, Math.floor(Number(seam.maxParallel?.()) || 0)) || defaultReviewParallel(); // #6098: queue beyond the cap, never every reviewer at once
|
|
151
|
+
await mapLimit(agents, cap, (a) => attempt(a.domain));
|
|
126
152
|
// #5516: the missing-config guard of commands/test-gate.md is deterministic, so no session decides it; otherwise the gate
|
|
127
153
|
// session gets a full tool set (Skill, Task, Bash) and the resolved skill name, never a bare `/test-gate`.
|
|
128
154
|
const plan = await seam.testGatePlan();
|
|
@@ -138,7 +164,7 @@ async function reviewRound({ seam, pr, def, delta }) {
|
|
|
138
164
|
const missing = missingReviewers(fin.lines).filter((d) => prompts.has(d));
|
|
139
165
|
if (!missing.length) return { fail: `finalize stopped (exit ${fin.code}): ${(fin.lines ?? []).slice(-2).join(" | ").slice(0, 300)}${failureNote(failures)}` };
|
|
140
166
|
// once: the same brief with the note the spec prescribes; a second miss is a degraded panel
|
|
141
|
-
await
|
|
167
|
+
await mapLimit(missing, cap, (d) => attempt(d, "structured findings block required: post your findings comment again, ending with the REVIEW-FINDINGS-START/END block."));
|
|
142
168
|
fin = await seam.finalize({ pr, testGateOutput: gateFile });
|
|
143
169
|
if (fin.code !== 0 || !fin.data) {
|
|
144
170
|
if (headMoved(fin.lines)) return { moved: m.headSha };
|
|
@@ -260,7 +286,10 @@ export async function fixStep(ctx) {
|
|
|
260
286
|
continue;
|
|
261
287
|
}
|
|
262
288
|
// #5779: with blocking findings in hand the fix round starts now (completed runs go into the brief); else the wait is bounded
|
|
263
|
-
const
|
|
289
|
+
const seen = r.ciFailing > 0 ? await seam.failedJobs({ pr: r.pr, head: r.head, wait: !r.blocking?.length }) : [];
|
|
290
|
+
// #6013: failures the staging-health gate named earlier ride along in the same brief, so all fixes are dispatched together.
|
|
291
|
+
const known = (ctx.state.knownFailures ?? []).filter((k) => !seen.some((j) => j.name === k.name)).map((k) => ({ name: k.name, conclusion: "failure", log: `failed on staging (${k.cause})` }));
|
|
292
|
+
const jobs = Object.assign([...seen, ...known], { pending: seen.pending });
|
|
264
293
|
const rec = collectFindings({ head: r.head, jobs, findings: r.items ?? [], guards: r.guards ?? [] });
|
|
265
294
|
const b = blockingOf(rec);
|
|
266
295
|
if (!b.ci.length && !b.review.length && !b.guards.length && !r.blocking?.length && jobs.pending?.length) return blocked(`required checks of #${r.pr} still running (${jobs.pending.join(", ")}), with no failure to fix yet; re-run the release once CI finishes`);
|
|
@@ -310,6 +339,8 @@ export async function fixStep(ctx) {
|
|
|
310
339
|
const seamOf = (ctx) => ctx.io.review ?? (ctx.seam ??= realSeam(ctx));
|
|
311
340
|
|
|
312
341
|
/** Real effects of the review steps: the review-staging library, the engine runner, the filing scripts, gh and a lane process. */
|
|
342
|
+
/** #6098: CPU niceness of reviewer processes (ionice idle class is applied alongside). */
|
|
343
|
+
export const REVIEW_NICE = 19;
|
|
313
344
|
export function realSeam({ repo, def, env = process.env, laneStrip = [], cwd = process.cwd(), makeRunner = null, gh: ghIn = null, io = null, spawn: spawnIn = spawn }) {
|
|
314
345
|
const sleep = io?.sleep ?? ((ms) => new Promise((res) => setTimeout(res, ms))), now = io?.now ?? (() => Date.now());
|
|
315
346
|
const say = io?.print ?? ((m) => process.stderr.write(`${m}\n`));
|
|
@@ -334,10 +365,14 @@ export function realSeam({ repo, def, env = process.env, laneStrip = [], cwd = p
|
|
|
334
365
|
readFile: (p) => readFileSync(p, "utf8"),
|
|
335
366
|
markLaunched: (file, domains, head) => { appendFileSync(file, domains.map((d) => `${d}\n`).join("")); writeFileSync(`${file}.head`, `${head}\n`); },
|
|
336
367
|
saveTestGate: (pr, text) => { mkdirSync(sd, { recursive: true }); const f = join(sd, `${pr}_test_gate_output.txt`); writeFileSync(f, text); return f; },
|
|
368
|
+
maxParallel: () => { // #6098
|
|
369
|
+
try { return reviewMaxParallel(readFileSync(env.FORGE_CONFIG || join(cwd, "forge.yaml"), "utf8")) ?? defaultReviewParallel(); } catch { return defaultReviewParallel(); }
|
|
370
|
+
},
|
|
337
371
|
runAgent: async ({ role, issue, prompt, fullSession = false }) => {
|
|
338
372
|
runner ??= makeRunner ? makeRunner() : (await import("./effects.mjs")).makeLeanRunner();
|
|
339
373
|
// not readOnly: each reviewer posts its own PR comment; the test gate (#5516) needs Skill/Task, so a full session
|
|
340
|
-
return runner({ role, issue, cwd, env: pinnedEnv(), prompt, fullSession, system: "You are an isolated reviewer of one release PR. Do only what the prompt asks.", maxMs: REVIEW_MS, idleMs: 10 * 60_000
|
|
374
|
+
return runner({ role, issue, cwd, env: pinnedEnv(), prompt, fullSession, system: "You are an isolated reviewer of one release PR. Do only what the prompt asks.", maxMs: REVIEW_MS, idleMs: 10 * 60_000,
|
|
375
|
+
onSpawn: (child) => lowerPriority(child?.pid, { level: REVIEW_NICE }) }); // #6098: reviewers run at nice 19 / ionice idle on the orchestrator host
|
|
341
376
|
},
|
|
342
377
|
testGatePlan: async () => {
|
|
343
378
|
let raw = null;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { reviewStep, fixStep, missingReviewers, SPEC_PANEL, MAX_DELTA_PASSES, realSeam, withIntegrityMarker, TEST_GATE_SKIP_NO_TESTS, testGatePrompt, integrationTestCount, resolveSkillName } from "./release-review.mjs";
|
|
5
|
+
import { reviewStep, fixStep, missingReviewers, SPEC_PANEL, MAX_DELTA_PASSES, realSeam, withIntegrityMarker, TEST_GATE_SKIP_NO_TESTS, testGatePrompt, integrationTestCount, resolveSkillName, mapLimit, reviewMaxParallel, defaultReviewParallel, REVIEW_NICE } from "./release-review.mjs";
|
|
6
6
|
import { readFileSync } from "node:fs";
|
|
7
7
|
import { EventEmitter } from "node:events";
|
|
8
8
|
import { reviewStagingJson, classifyChecks, cancelOnlyChecks } from "../review-staging.mjs";
|
|
@@ -12,7 +12,7 @@ const manifest = (head, delta = null) => ({ pr: 7, headSha: head, bundle: [1, 2]
|
|
|
12
12
|
const fin = (extra = {}) => ({ code: 0, data: { head: H1, toFile: [], notes: [], ...extra }, lines: [] });
|
|
13
13
|
|
|
14
14
|
/** Seam fake: `heads` is what headOf answers in turn; `fins` what finalize answers in turn. */
|
|
15
|
-
function fakeSeam({ heads = [H1], fins = [fin()], summary, lanes = [], jobs = [], gatePlan = { clusters: 1, skill: "forgedock:test-gate" } } = {}) {
|
|
15
|
+
function fakeSeam({ heads = [H1], fins = [fin()], summary, lanes = [], jobs = [], gatePlan = { clusters: 1, skill: "forgedock:test-gate" }, maxParallel = 2 } = {}) {
|
|
16
16
|
const log = [], agents = [], gateSaved = [], agentCalls = [];
|
|
17
17
|
let h = 0, f = 0, l = 0, n = 100;
|
|
18
18
|
return {
|
|
@@ -25,6 +25,7 @@ function fakeSeam({ heads = [H1], fins = [fin()], summary, lanes = [], jobs = []
|
|
|
25
25
|
markLaunched: (file, domains) => log.push(["launched", domains]),
|
|
26
26
|
saveTestGate: (pr, text) => { gateSaved.push(text); return "/sd/7_test_gate_output.txt"; },
|
|
27
27
|
testGatePlan: async () => gatePlan,
|
|
28
|
+
maxParallel: () => maxParallel,
|
|
28
29
|
runAgent: async (a) => { agentCalls.push(a); agents.push(a.role + (a.prompt.includes("findings block required") ? ":reask" : "")); return { text: "ok" }; },
|
|
29
30
|
fileIssue: async ({ item }) => { log.push(["file", item.title]); return n++; },
|
|
30
31
|
failedJobs: async () => jobs,
|
|
@@ -37,6 +38,35 @@ function fakeSeam({ heads = [H1], fins = [fin()], summary, lanes = [], jobs = []
|
|
|
37
38
|
}
|
|
38
39
|
const ctx = (seam, steps = {}) => ({ io: { review: seam }, repo: "o/r", def: "main", staging: "staging", state: { steps: { "release-pr": { result: { pr: 7 } }, ...steps } }, save() {} });
|
|
39
40
|
|
|
41
|
+
describe("#6098 reviewer fan-out is capped and niced", () => {
|
|
42
|
+
it("mapLimit never has more than the cap in flight and keeps order", async () => {
|
|
43
|
+
let live = 0, peak = 0;
|
|
44
|
+
const out = await mapLimit([1, 2, 3, 4, 5, 6, 7, 8], 3, async (x) => { live++; peak = Math.max(peak, live); await new Promise((r) => setTimeout(r, 5)); live--; return x * 2; });
|
|
45
|
+
assert.equal(peak, 3); assert.deepEqual(out, [2, 4, 6, 8, 10, 12, 14, 16]);
|
|
46
|
+
});
|
|
47
|
+
it("review.max_parallel is read from forge.yaml; the default is max(2, cores/2)", () => {
|
|
48
|
+
assert.equal(reviewMaxParallel("a: 1\nreview:\n depth:\n x: 1\n max_parallel: 3 # cap\nother:\n max_parallel: 9\n"), 3);
|
|
49
|
+
assert.equal(reviewMaxParallel("other:\n max_parallel: 9\n"), null);
|
|
50
|
+
assert.equal(reviewMaxParallel("review:\n max_parallel: 0\n"), null);
|
|
51
|
+
assert.equal(defaultReviewParallel(4), 2); assert.equal(defaultReviewParallel(2), 2); assert.equal(defaultReviewParallel(16), 8);
|
|
52
|
+
});
|
|
53
|
+
it("the panel never runs more reviewers at once than the cap", async () => {
|
|
54
|
+
const s = fakeSeam({ maxParallel: 2 });
|
|
55
|
+
let live = 0, peak = 0;
|
|
56
|
+
s.runAgent = async (a) => { live++; peak = Math.max(peak, live); await new Promise((r) => setTimeout(r, 5)); live--; return { text: "ok" }; };
|
|
57
|
+
await reviewStep(ctx(s));
|
|
58
|
+
assert.ok(SPEC_PANEL.length + 1 > 2, "the panel is larger than the cap");
|
|
59
|
+
assert.equal(peak, 2);
|
|
60
|
+
});
|
|
61
|
+
it("reviewer processes are lowered to nice 19 / ionice idle on spawn", async () => {
|
|
62
|
+
let spec = null;
|
|
63
|
+
const real = realSeam({ repo: "o/r", def: "main", env: {}, cwd: "/tmp", makeRunner: () => async (a) => { spec = a; return { text: "" }; } });
|
|
64
|
+
await real.runAgent({ role: "release-review-security", issue: 7, prompt: "p" });
|
|
65
|
+
assert.equal(typeof spec.onSpawn, "function"); assert.equal(REVIEW_NICE, 19);
|
|
66
|
+
assert.equal(spec.onSpawn({ pid: -1 }), false); // an invalid pid is a no-op, never a throw
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
40
70
|
describe("reviewStep", () => {
|
|
41
71
|
it("reviewer sessions run the release job's own forgedock build", async () => {
|
|
42
72
|
let seen = null;
|
|
@@ -166,6 +196,17 @@ describe("fixStep", () => {
|
|
|
166
196
|
assert.equal(c.state.fixloop.heads[H2].rounds, 1, "the round is counted per head sha");
|
|
167
197
|
});
|
|
168
198
|
|
|
199
|
+
it("#6013: failures the staging-health gate named ride in the one fix brief with the release-PR round's failures", async () => {
|
|
200
|
+
const s = fakeSeam({ heads: [H2], jobs: [{ name: "lint", conclusion: "failure", log: "bad" }] });
|
|
201
|
+
let brief = "";
|
|
202
|
+
s.fileFixIssue = async (a) => { brief = a.brief; return 100; };
|
|
203
|
+
const c = ctx(s, { review: { result: { ...failed, ciFailing: 1 } } });
|
|
204
|
+
c.state.knownFailures = [{ name: "black", cause: "regression" }, { name: "lint", cause: "regression" }];
|
|
205
|
+
await fixStep(c);
|
|
206
|
+
assert.match(brief, /ci:black/);
|
|
207
|
+
assert.equal((brief.match(/ci:lint/g) ?? []).length, 1);
|
|
208
|
+
});
|
|
209
|
+
|
|
169
210
|
it("is bounded: one round (ci.fix.max_rounds default 1), then HELD with an owner ask for a non-flake, non-regression failure", async () => {
|
|
170
211
|
const bad = { code: 0, data: { verdict: "BLOCK DEPLOY", marker: "FORGE:GATE_FAILURE", ciFailing: 0 }, lines: [] };
|
|
171
212
|
const s = fakeSeam({ heads: [H2], summary: bad, fins: [fin({ toFile: [{ title: "x", severity: "CRITICAL" }] })] });
|
package/bin/lean/release.mjs
CHANGED
|
@@ -26,14 +26,14 @@ import { budgetReportLine, releaseRuns, detectBudget, readCiPolicy } from "./ci-
|
|
|
26
26
|
import { parseNightlyConfig, readNightly, blocksRelease, fileNightlyRed } from "./release-nightly.mjs";
|
|
27
27
|
import { parseBudgetConfig, applyOnExceed, waveReport, trailingMedian, historyFromRoot, gateHistoryFromRoot, releaseMinutes } from "./release-minutes.mjs";
|
|
28
28
|
import { cutSnapshot, writeRecord, checkChain, verifyRelease, defaultBehind, DEFAULT_PATTERN } from "./release-snapshot.mjs";
|
|
29
|
-
import { createReleaseLedger, writeRelease, readLedger, acquireLease, heartbeat } from "./release-ledger.mjs";
|
|
29
|
+
import { createReleaseLedger, writeRelease, readLedger, acquireLease, heartbeat, recordReleaseRound } from "./release-ledger.mjs";
|
|
30
30
|
import { fenced, epochTrailer } from "./release-fence.mjs";
|
|
31
31
|
import { holdCheck, exemptionsSection, runControl, VERBS as CONTROL_VERBS } from "./release-control.mjs";
|
|
32
|
-
import { parseFlakeConfig, classifyFailure, planRerun, flakeEntry, recordFlakes, readFlakes } from "./release-flakes.mjs";
|
|
32
|
+
import { parseFlakeConfig, classifyFailure, planRerun, flakeEntry, recordFlakes, readFlakes, isDeployWorkflow } from "./release-flakes.mjs";
|
|
33
33
|
import { readActive } from "./release-ledger.mjs";
|
|
34
34
|
import { statusFromCli, policyFromYaml } from "./release-status.mjs";
|
|
35
35
|
import { parseFixConfig } from "./release-fixloop.mjs";
|
|
36
|
-
import { hostPreflightStep, markReadyStep, parsePreflightConfig } from "./release-preflight.mjs";
|
|
36
|
+
import { hostPreflightStep, markReadyStep, stagingHealthStep, parsePreflightConfig } from "./release-preflight.mjs";
|
|
37
37
|
import { roleRefusal } from "./release-credentials.mjs";
|
|
38
38
|
import { mergeGuard } from "./release-gate.mjs";
|
|
39
39
|
|
|
@@ -130,7 +130,7 @@ const snapshotKeys = (r) => {
|
|
|
130
130
|
export const isSnapshot = (config) => config?.mode === "snapshot";
|
|
131
131
|
|
|
132
132
|
/** `{rehearsal}` / `{preflight}` only when configured, so the config of a repo without them keeps its shape. */
|
|
133
|
-
const optKeys = (r) => { const rehearsal = parseRehearsalConfig(r), preflight = parsePreflightConfig(r); return { ...(rehearsal ? { rehearsal } : {}), ...(preflight ? { preflight } : {}) }; };
|
|
133
|
+
const optKeys = (r) => { const rehearsal = parseRehearsalConfig(r), preflight = parsePreflightConfig(r); return { ...(r?.allow_red_staging === true || String(r?.allow_red_staging).toLowerCase() === "true" ? { allowRedStaging: true } : {}), ...(rehearsal ? { rehearsal } : {}), ...(preflight ? { preflight } : {}) }; };
|
|
134
134
|
|
|
135
135
|
const json = (s) => JSON.parse(String(s || "null"));
|
|
136
136
|
|
|
@@ -143,10 +143,26 @@ export async function bundleList({ io, repo, head, base }) {
|
|
|
143
143
|
|
|
144
144
|
const bundleBody = (list) => `## Release bundle\n\n${list.length ? list.map((p) => `- #${p.number} ${p.title}`).join("\n") : "_No merged PRs found since the last release._"}\n`;
|
|
145
145
|
|
|
146
|
+
/** #6013: one `state.rounds` entry per distinct head and outcome (a resume does not double-count). */
|
|
147
|
+
function noteRound(ctx, r) {
|
|
148
|
+
const { state, io } = ctx;
|
|
149
|
+
if ((state.rounds ?? []).some((x) => x.head === r.head && x.outcome === r.outcome)) return;
|
|
150
|
+
const at = new Date(io.now?.() ?? Date.now()).toISOString();
|
|
151
|
+
recordReleaseRound(state, { ...r, startedAt: at, endedAt: at });
|
|
152
|
+
ctx.save();
|
|
153
|
+
}
|
|
154
|
+
|
|
146
155
|
async function preflightStep(ctx) {
|
|
147
156
|
const { io, repo, state, staging } = ctx;
|
|
148
157
|
// Snapshot mode: lanes keep merging to staging; the release is cut from a fixed SHA, so nothing is refused or held (#5276).
|
|
149
|
-
|
|
158
|
+
const health = await stagingHealthStep(ctx);
|
|
159
|
+
if (health.refused) {
|
|
160
|
+
state.knownFailures = health.failed;
|
|
161
|
+
noteRound(ctx, { head: health.head, outcome: "red-staging", cause: health.failed.some((f) => f.cause === "regression") || !health.failed.length ? "regression" : "runner" });
|
|
162
|
+
ctx.save(); return { refused: health.refused, failed: health.failed }; }
|
|
163
|
+
state.knownFailures = health.failed ?? [];
|
|
164
|
+
const warn = health.warning ? { warning: health.warning } : {};
|
|
165
|
+
if (isSnapshot(ctx.config)) return { snapshot: true, held: 0, ...warn };
|
|
150
166
|
const lanes = await io.runningLanes(repo);
|
|
151
167
|
if (lanes.length) return { refused: `lanes of ${repo} are running (${lanes.map((l) => `${l.batch}#${l.issue}`).join(", ")}); wait or cancel them` };
|
|
152
168
|
const open = json(await io.gh(["pr", "list", "--repo", repo, "--base", staging, "--state", "open", "--json", "number"])) ?? [];
|
|
@@ -159,7 +175,7 @@ async function preflightStep(ctx) {
|
|
|
159
175
|
ctx.save();
|
|
160
176
|
await io.setParallel(b.id, 1);
|
|
161
177
|
}
|
|
162
|
-
return { held: state.held.length };
|
|
178
|
+
return { held: state.held.length, ...warn };
|
|
163
179
|
}
|
|
164
180
|
|
|
165
181
|
/** Restore every held batch to its recorded K; best effort, recorded as it goes. */
|
|
@@ -185,14 +201,15 @@ async function snapshotPrStep(ctx) {
|
|
|
185
201
|
}
|
|
186
202
|
const { branch } = state.release;
|
|
187
203
|
const found = json(await io.gh(["pr", "list", "--repo", repo, "--base", def, "--head", branch, "--state", "open", "--json", "number,headRefOid,url"]))?.[0];
|
|
188
|
-
if (found) return { pr: found.number, head: found.headRefOid, url: found.url, reused: true, branch };
|
|
204
|
+
if (found) { noteRound(ctx, { pr: found.number, head: found.headRefOid, outcome: "cut" }); return { pr: found.number, head: found.headRefOid, url: found.url, reused: true, branch }; }
|
|
189
205
|
const list = state.releaseBundle ?? [];
|
|
190
|
-
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", branch, "--title", `Release: ${branch} -> ${def}`, "--body", bundleBody(list) + await exemptionBody(ctx)])).trim();
|
|
206
|
+
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", branch, "--title", `Release: ${branch} -> ${def}`, "--body", bundleBody(list) + await exemptionBody(ctx) + await scorecardBody(ctx)])).trim();
|
|
191
207
|
const n = Number(/\/pull\/(\d+)/.exec(url)?.[1]);
|
|
192
208
|
if (!Number.isSafeInteger(n)) throw new Error(`gh pr create returned no PR url: ${url}`);
|
|
193
209
|
state.steps["release-pr"] = { done: false, result: { pr: n } }; // writeRecord reads the PR number from here
|
|
194
210
|
await writeRecord(ctx);
|
|
195
211
|
const v = json(await io.gh(["pr", "view", String(n), "--repo", repo, "--json", "headRefOid"]));
|
|
212
|
+
noteRound(ctx, { pr: n, head: v?.headRefOid, outcome: "cut" });
|
|
196
213
|
return { pr: n, head: v?.headRefOid, url, reused: false, bundle: list.length, branch };
|
|
197
214
|
}
|
|
198
215
|
|
|
@@ -202,13 +219,23 @@ async function releasePrStep(ctx) {
|
|
|
202
219
|
const found = json(await io.gh(["pr", "list", "--repo", repo, "--base", def, "--head", staging, "--state", "open", "--json", "number,headRefOid,url"]))?.[0];
|
|
203
220
|
if (found) return { pr: found.number, head: found.headRefOid, url: found.url, reused: true };
|
|
204
221
|
const list = await bundleList({ io, repo, head: staging, base: def });
|
|
205
|
-
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", staging, "--title", `Release: ${staging} -> ${def}`, "--body", bundleBody(list) + await exemptionBody(ctx), ...(ctx.config.preflight ? ["--draft"] : [])])).trim();
|
|
222
|
+
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", staging, "--title", `Release: ${staging} -> ${def}`, "--body", bundleBody(list) + await exemptionBody(ctx) + await scorecardBody(ctx), ...(ctx.config.preflight ? ["--draft"] : [])])).trim();
|
|
206
223
|
const n = Number(/\/pull\/(\d+)/.exec(url)?.[1]);
|
|
207
224
|
if (!Number.isSafeInteger(n)) throw new Error(`gh pr create returned no PR url: ${url}`);
|
|
208
225
|
const v = json(await io.gh(["pr", "view", String(n), "--repo", repo, "--json", "headRefOid"]));
|
|
209
226
|
return { pr: n, head: v?.headRefOid, url, reused: false, bundle: list.length };
|
|
210
227
|
}
|
|
211
228
|
|
|
229
|
+
/** The per-release scorecard (#6084) as a PR-body section with its regressions line; "" on any error (never blocks the PR). */
|
|
230
|
+
async function scorecardBody({ io, repo, state }) {
|
|
231
|
+
try {
|
|
232
|
+
const sc = io.scorecard ? await io.scorecard({ repo, release: state.release?.version ?? state.id }) : await (await import("../stats/scorecard.mjs")).gatherScorecard({ repo, release: state.release?.version ?? state.id }, { gh: io.gh, useCache: false });
|
|
233
|
+
if (!sc) return "";
|
|
234
|
+
const { renderScorecard } = await import("../stats/scorecard.mjs");
|
|
235
|
+
return `\n\n${renderScorecard(sc)}\n`;
|
|
236
|
+
} catch { return ""; }
|
|
237
|
+
}
|
|
238
|
+
|
|
212
239
|
/** The live operator exemptions as a PR-body section (#5568, I20); "" when unmanaged, none, or `_active` is unreadable. */
|
|
213
240
|
async function exemptionBody({ io, repo, config }) {
|
|
214
241
|
if (!config.managed || !io.api) return "";
|
|
@@ -255,21 +282,23 @@ export async function rerunInfraFlakes({ io, repo, head, fence, policy }) {
|
|
|
255
282
|
const cfg = parseFlakeConfig(policy);
|
|
256
283
|
if (!fence?.lctx || !(cfg.rerunBudgetMin > 0)) return out;
|
|
257
284
|
const prior = await readFlakes(fence.lctx), done = prior.filter((f) => f.rerun).map((f) => `${f.sha}:${f.check}`);
|
|
258
|
-
const runs = json(await io.gh(["run", "list", "--repo", repo, "--commit", head, "--status", "failure", "--json", "databaseId,name", "--limit", "20"])) ?? [];
|
|
285
|
+
const runs = json(await io.gh(["run", "list", "--repo", repo, "--commit", head, "--status", "failure", "--json", "databaseId,name,attempt", "--limit", "20"])) ?? [];
|
|
259
286
|
const at = new Date(io.now?.() ?? Date.now()).toISOString(), entries = [];
|
|
260
287
|
let spentMin = 0;
|
|
261
288
|
for (const r of runs) {
|
|
289
|
+
if (isDeployWorkflow(r.name)) { out.skipped.push({ name: r.name, why: "deploy-class: handled by release-deploy recover" }); continue; } // #6015: never a log-regex rerun
|
|
262
290
|
const log = String(await io.gh(["run", "view", String(r.databaseId), "--repo", repo, "--log-failed"]).catch(() => "")).slice(-20_000);
|
|
263
291
|
const c = classifyFailure(log);
|
|
264
|
-
const [d] = planRerun({ jobs: [{ key: `${head}:${r.name}`, name: r.name, class: c.class }], done, spentMin, budgetMin: cfg.rerunBudgetMin });
|
|
292
|
+
const [d] = planRerun({ jobs: [{ key: `${head}:${r.name}`, name: r.name, class: c.class, attempt: r.attempt }], done, spentMin, budgetMin: cfg.rerunBudgetMin });
|
|
265
293
|
if (d.rerun) {
|
|
266
294
|
const f = await fenced(fence, { action: "rerun", key: `rerun-failed:${r.databaseId}` }, () => io.gh(["run", "rerun", String(r.databaseId), "--repo", repo, "--failed"]));
|
|
267
295
|
if (f.refused) { out.skipped.push({ name: r.name, why: f.refused }); continue; }
|
|
268
296
|
out.reran.push(r.name);
|
|
269
|
-
} else out.skipped.push({ name: r.name, why: d.why });
|
|
270
|
-
entries.push(flakeEntry({ check: r.name, signature: c.signature, kind: c.class === "infra" ? "infra" : "decision", sha: head, runIds: [r.databaseId], at, rerun: d.rerun }));
|
|
297
|
+
} else out.skipped.push({ name: r.name, why: d.why, ...(d.capped ? { capped: true } : {}) });
|
|
298
|
+
entries.push(flakeEntry({ check: r.name, signature: c.signature, kind: c.class === "infra" ? "infra" : "decision", sha: head, runIds: [r.databaseId], at, rerun: d.rerun, attempt: r.attempt, reuseForfeited: d.rerun }));
|
|
271
299
|
}
|
|
272
|
-
|
|
300
|
+
// #6014: a rerun entry carries the attempt count and the forfeited reuse; a cap refusal is a visible decision entry, never an infra one
|
|
301
|
+
await recordFlakes(fence.lctx, entries.filter((e) => e.kind === "infra" || e.attempt != null && !e.rerun && out.skipped.some((s) => s.capped && s.name === e.check)));
|
|
273
302
|
} catch { /* best effort */ }
|
|
274
303
|
return out;
|
|
275
304
|
}
|
|
@@ -309,7 +338,8 @@ async function promotionStep(ctx) {
|
|
|
309
338
|
if (gate.deployGate === "failure" && ctx.config.managed && io.git) { // #5568: policy loaded lazily (release-config imports this module)
|
|
310
339
|
const { readPolicy } = await import("./release-config.mjs");
|
|
311
340
|
const policy = readPolicy({ io, defaultBranch: ctx.def }).policy;
|
|
312
|
-
await rerunInfraFlakes({ io, repo, head, fence: ctx.fence, policy });
|
|
341
|
+
const rr = await rerunInfraFlakes({ io, repo, head, fence: ctx.fence, policy });
|
|
342
|
+
if (rr.reran.length) noteRound(ctx, { pr, head, outcome: "rerun-flake", cause: "flake" }); // #6013: a rerun that clears an infra failure is a flake round
|
|
313
343
|
}
|
|
314
344
|
const cmd = `gh pr merge ${pr} --repo ${repo} --merge --match-head-commit ${head}`;
|
|
315
345
|
if (!opts.merge && !ctx.config.autoMerge) { io.print(`GATE_PASS on #${pr}. Merge when ready:\n ${cmd}`); return { stopped: true, why: "GATE_PASS; promotion is opt-in (--merge or release.auto_merge)", cmd, head, gate }; }
|
|
@@ -42,6 +42,7 @@ function fakeIo(world = {}) {
|
|
|
42
42
|
throw new Error(`unexpected gh ${j}`);
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
|
+
if (w.scorecard) io.scorecard = w.scorecard;
|
|
45
46
|
return io;
|
|
46
47
|
}
|
|
47
48
|
const ok = async () => ({ ok: true });
|
|
@@ -191,6 +192,19 @@ describe("release job (#5211)", () => {
|
|
|
191
192
|
assert.ok(create && create.includes("--head") && create.includes("staging") && create.includes("main"));
|
|
192
193
|
});
|
|
193
194
|
|
|
195
|
+
it("#6084: the release PR body carries the scorecard with regressions; a scorecard failure still creates the PR", async () => {
|
|
196
|
+
const body = (c) => c[c.indexOf("--body") + 1];
|
|
197
|
+
const sc = { release: "v2", against: "v1", minN: 10, values: { first_pass_rate: 0.5 }, previous: { first_pass_rate: 0.9 }, verdicts: { first_pass_rate: "regressed" }, regressions: ["first_pass_rate"] };
|
|
198
|
+
const a = await promote({ releasePr: [], scorecard: async () => sc });
|
|
199
|
+
const withCard = body(a.io.calls.find((c) => c[1] === "create"));
|
|
200
|
+
assert.match(withCard, /Release scorecard v2/);
|
|
201
|
+
assert.match(withCard, /Regressions vs v1: first-pass merge rate/);
|
|
202
|
+
const b = await promote({ releasePr: [], scorecard: async () => { throw new Error("boom"); } });
|
|
203
|
+
const create = b.io.calls.find((c) => c[1] === "create");
|
|
204
|
+
assert.ok(create);
|
|
205
|
+
assert.doesNotMatch(body(create), /scorecard/i);
|
|
206
|
+
});
|
|
207
|
+
|
|
194
208
|
it("R5: a killed job resumes from the last completed step", async () => {
|
|
195
209
|
const io = fakeIo(), root = tmp(), id = newReleaseId();
|
|
196
210
|
const mod = await import("./release.mjs");
|
|
@@ -594,3 +608,21 @@ describe("release start|go routing (#5571)", () => {
|
|
|
594
608
|
await assert.rejects(releaseFromCli(["start", "--wave", "x"], opts([], [])), /--wave/);
|
|
595
609
|
});
|
|
596
610
|
});
|
|
611
|
+
|
|
612
|
+
describe("preflight staging-health gate (#6013)", () => {
|
|
613
|
+
const snap = { mode: "snapshot" };
|
|
614
|
+
const world = (runs) => ({ pm: (a) => (a[0] === "api" && /check-runs/.test(a[1]) ? JSON.stringify(runs) : undefined) });
|
|
615
|
+
it("refuses a snapshot cut on a red staging head and proceeds when green", async () => {
|
|
616
|
+
const mod = await import("./release.mjs");
|
|
617
|
+
const root = tmp(), id = newReleaseId();
|
|
618
|
+
const base = (io) => ({ io, repo: REPO, root, mounts: DISK, id, opts: {}, config: snap, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ "release-pr": ok, review: ok, fixes: ok, promotion: ok, "post-merge": ok }) });
|
|
619
|
+
const reds = await mod.runRelease(base(fakeIo(world([{ name: "black", status: "completed", conclusion: "failure", text: "" }]))));
|
|
620
|
+
assert.equal(reds.status, "refused");
|
|
621
|
+
assert.match(JSON.stringify(reds), /black/);
|
|
622
|
+
const saved = JSON.parse(readFileSync(join(root, id, "state.json"), "utf8").toString());
|
|
623
|
+
assert.equal(saved.rounds[0].outcome, "red-staging");
|
|
624
|
+
assert.equal(saved.rounds[0].cause, "regression");
|
|
625
|
+
const green = await mod.runRelease({ ...base(fakeIo(world([{ name: "black", status: "completed", conclusion: "success", text: "" }]))), id: newReleaseId() });
|
|
626
|
+
assert.notEqual(green.status, "refused");
|
|
627
|
+
});
|
|
628
|
+
});
|
package/bin/lean/retry.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
export const PUSH_TRANSIENT_RE = /remote unpack failed|index-pack failed|RPC failed|unexpected disconnect|early EOF|the remote end hung up|HTTP\/?\s?5\d\d|returned error: 5\d\d|\b50[0234]\b|internal server error|bad gateway|service unavailable|gateway time-?out|connection (?:reset|timed out|refused)|timed out|could not resolve host|broken pipe|ETIMEDOUT|ECONNRESET|temporarily unavailable|\[remote rejected\][^\n]*\(failed\)|unable to write file|unable to create temporary object|unpacker error|failed to write object/i;
|
|
6
6
|
export const PUSH_PERMANENT_RE = /protected branch|GH006|GH013|repository rule violations|permission (?:denied|to .* denied)|denied to|\b403\b|authentication failed|not allowed|hook declined|pre-receive hook declined|\[rejected\]|non-fast-forward|fetch first/i;
|
|
7
|
-
export const GH_TRANSIENT_RE = /HTTP 5\d\d|\b50[0234]\b|secondary rate limit|rate limit exceeded|abuse detection|something went wrong|internal server error|bad gateway|service unavailable|ETIMEDOUT|ECONNRESET|connection reset|timed out|\bEOF\b|temporarily unavailable/i;
|
|
7
|
+
export const GH_TRANSIENT_RE = /HTTP 5\d\d|\b50[0234]\b|secondary rate limit|rate limit exceeded|abuse detection|something went wrong|internal server error|bad gateway|service unavailable|ETIMEDOUT|ECONNRESET|connection reset|timed out|\bEOF\b|temporarily unavailable|stream error|received from peer|error connecting to|check your internet connection|no such host|TLS handshake timeout|i\/o timeout|network is unreachable|connection refused|EAI_AGAIN|ENETUNREACH|ECONNREFUSED/i; // 2026-11-26: gh's network-failure texts (a lossy link dropped a merge into engine-error)
|
|
8
8
|
/** #4507: gh failing to parse its own input: a torn HTTP cache entry (JSON) or a half-written config (YAML). */
|
|
9
9
|
export const GH_PARSE_RE = /invalid character .{0,40}looking for|unexpected end of JSON input|cannot unmarshal|yaml: line \d+|yaml: unmarshal/i;
|
|
10
10
|
export const MERGE_TRANSIENT_RE = new RegExp(`${GH_TRANSIENT_RE.source}|${GH_PARSE_RE.source}|base branch was modified|head branch was modified|mergeability.*unknown|try again`, "i");
|