forgedock 1.59.2 → 1.60.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/engine/outcome-codes.mjs +3 -3
- package/bin/engine-cli.mjs +50 -10
- package/bin/labels.json +5 -0
- package/bin/lean/batch.mjs +21 -2
- package/bin/lean/batch.test.mjs +116 -1
- package/bin/lean/conformance.mjs +19 -6
- package/bin/lean/conformance.test.mjs +37 -3
- package/bin/lean/depcache.mjs +34 -15
- package/bin/lean/depcache.test.mjs +100 -1
- package/bin/lean/design-gate.mjs +15 -10
- package/bin/lean/design-gate.test.mjs +21 -0
- package/bin/lean/effects.mjs +18 -2
- package/bin/lean/execution.mjs +23 -5
- package/bin/lean/execution.test.mjs +81 -1
- package/bin/lean/gatewatch.test.mjs +5 -5
- package/bin/lean/issuewatch-triage.mjs +68 -0
- package/bin/lean/issuewatch-triage.test.mjs +98 -0
- package/bin/lean/issuewatch.mjs +34 -6
- package/bin/lean/issuewatch.test.mjs +11 -0
- package/bin/lean/lanelock.mjs +5 -4
- package/bin/lean/lean.mjs +144 -21
- package/bin/lean/lean.test.mjs +180 -6
- package/bin/lean/orchestrate-cancel.test.mjs +33 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +41 -0
- package/bin/lean/orchestrate-recovering.test.mjs +42 -0
- package/bin/lean/orchestrate.mjs +23 -10
- package/bin/lean/pagegate.mjs +50 -12
- package/bin/lean/pagegate.test.mjs +38 -1
- package/bin/lean/phaseledger.mjs +65 -2
- package/bin/lean/phaseledger.test.mjs +70 -2
- package/bin/lean/preflight.mjs +67 -3
- package/bin/lean/preflight.test.mjs +37 -1
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/recovery.test.mjs +11 -6
- package/bin/lean/release-classify.mjs +143 -0
- package/bin/lean/release-classify.test.mjs +130 -0
- package/bin/lean/release-conductor.mjs +163 -0
- package/bin/lean/release-conductor.test.mjs +194 -0
- package/bin/lean/release-config.mjs +60 -8
- package/bin/lean/release-config.test.mjs +43 -1
- package/bin/lean/release-control.mjs +22 -5
- package/bin/lean/release-control.test.mjs +22 -0
- package/bin/lean/release-credentials.mjs +40 -0
- package/bin/lean/release-credentials.test.mjs +42 -0
- package/bin/lean/release-deploy.mjs +3 -3
- package/bin/lean/release-deploy.test.mjs +8 -0
- package/bin/lean/release-docs.test.mjs +93 -0
- package/bin/lean/release-fence.mjs +2 -0
- package/bin/lean/release-gate.mjs +88 -0
- package/bin/lean/release-gate.test.mjs +116 -0
- package/bin/lean/release-gates.mjs +5 -1
- package/bin/lean/release-ledger.mjs +47 -1
- package/bin/lean/release-ledger.test.mjs +33 -1
- package/bin/lean/release-mergeback.mjs +148 -0
- package/bin/lean/release-mergeback.test.mjs +129 -0
- package/bin/lean/release-p0.mjs +193 -0
- package/bin/lean/release-p0.test.mjs +127 -0
- package/bin/lean/release-plan.mjs +267 -0
- package/bin/lean/release-plan.test.mjs +202 -0
- package/bin/lean/release-preflight.mjs +16 -0
- package/bin/lean/release-regate.mjs +141 -0
- package/bin/lean/release-regate.test.mjs +149 -0
- package/bin/lean/release-review.mjs +5 -3
- package/bin/lean/release-rollback.mjs +277 -0
- package/bin/lean/release-rollback.test.mjs +245 -0
- package/bin/lean/release-snapshot.mjs +48 -9
- package/bin/lean/release-snapshot.test.mjs +43 -1
- package/bin/lean/release-start.mjs +164 -0
- package/bin/lean/release-start.test.mjs +171 -0
- package/bin/lean/release-status.mjs +6 -2
- package/bin/lean/release-train.mjs +159 -0
- package/bin/lean/release-train.test.mjs +139 -0
- package/bin/lean/release.mjs +127 -5
- package/bin/lean/release.test.mjs +80 -0
- package/bin/lean/sandbox-remote.mjs +2 -0
- package/bin/lean/schedd-load.test.mjs +82 -0
- package/bin/lean/schedd.mjs +67 -31
- package/bin/lean/schedd.test.mjs +80 -1
- package/bin/lean/validate-catalog.mjs +110 -0
- package/bin/lean/validate-catalog.test.mjs +55 -0
- package/bin/pool/agent.mjs +12 -1
- package/bin/pool/lane-tools.mjs +146 -0
- package/bin/pool/lane-tools.test.mjs +26 -0
- package/bin/pool/router.mjs +3 -1
- package/bin/pool/warm.mjs +14 -3
- package/docs/CONFIG.md +225 -1
- package/docs/ISSUE-WATCH.md +1 -0
- package/docs/design/visual-gate.md +10 -0
- package/docs/eval/adversarial-bench.md +1 -0
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/scripts/acceptance-red-green.sh +5 -2
- package/scripts/acceptance-red-green.test.sh +11 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +2 -1
- package/templates/github-actions/forge-conductor.scopes.json +7 -0
- package/templates/github-actions/forge-conductor.yml +57 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { buildPlan, rollSet, approvalOf, honouredLanes, forecastPlan, planFromCli, stableJson, EXCLUSION_KEYS } from "./release-plan.mjs";
|
|
6
|
+
import { deriveFacts } from "./release-classify.mjs";
|
|
7
|
+
import { resolvePath } from "./release-unitmap.mjs";
|
|
8
|
+
|
|
9
|
+
const POLICY = {
|
|
10
|
+
schema: 1,
|
|
11
|
+
trust: { actors: ["owner"] },
|
|
12
|
+
units: {
|
|
13
|
+
api: { paths: ["services/api/**"] }, worker: { paths: ["services/worker/**"] }, cron: { paths: ["services/cron/**"] },
|
|
14
|
+
web: { paths: ["web/**"], hosts: ["h1", "h2"] }, edge: { paths: ["edge/**"], hosts: ["h1", "h2"], single_host_ok: true },
|
|
15
|
+
legacy: { paths: ["legacy/**"], service_pipeline: false },
|
|
16
|
+
},
|
|
17
|
+
couplings: [{ paths: ["shared/**"], affects: ["api", "worker", "cron", "web"] }],
|
|
18
|
+
contracts: [{ producer: "api", consumers: ["web"], paths: ["contracts/strict/**"] }, { producer: "worker", consumers: ["cron"], paths: ["contracts/add/**"], additive_only: true }],
|
|
19
|
+
forces: [{ paths: ["infra/**"], pipeline: "full", reason: "infra" }],
|
|
20
|
+
classify: { min_confidence: 0.6 },
|
|
21
|
+
plan: { max_issues: 60 },
|
|
22
|
+
lanes: { train: { train_max_units: 3, train_max_issues: 15, units_max: 3 } },
|
|
23
|
+
};
|
|
24
|
+
const POLICY_SHA = "p".repeat(64), LIVE = "a".repeat(40);
|
|
25
|
+
|
|
26
|
+
const rec = (o) => ({ type: "bug", severity: "P2", exists_in: "live", confidence: 0.9, files: [], ...o });
|
|
27
|
+
let created = 0;
|
|
28
|
+
const mk = (n, o = {}) => ({
|
|
29
|
+
number: n, title: `t${n}`, body: o.body ?? "", labels: (o.labels ?? []).map((name) => ({ name })), createdAt: `2026-01-${String(1 + (created++ % 28)).padStart(2, "0")}T00:00:00Z`, updatedAt: `2026-02-01T00:00:${String(n % 60).padStart(2, "0")}Z`,
|
|
30
|
+
comments: o.rec === null ? [] : [{ author: { login: "bot" }, body: `<!-- FORGE:CLASSIFY -->\n\`\`\`json\n${JSON.stringify(rec(o.rec ?? {}))}\n\`\`\`` }],
|
|
31
|
+
});
|
|
32
|
+
const train = (n, file, extra = {}) => mk(n, { rec: { files: [file], ...extra } });
|
|
33
|
+
|
|
34
|
+
function fixture() {
|
|
35
|
+
created = 0;
|
|
36
|
+
const f = [
|
|
37
|
+
mk(1, { labels: ["epic"] }), mk(2, { labels: ["needs-human"] }), mk(3, { labels: ["parked:q3"] }), mk(4, { labels: ["hold"] }),
|
|
38
|
+
mk(5, { labels: ["design:needed"] }), mk(6, { rec: { ready: false } }), mk(7, { rec: null }), mk(8, { rec: { confidence: 0.1 } }),
|
|
39
|
+
mk(9, { body: "Depends on #2", rec: { files: ["services/api/a.py"] } }),
|
|
40
|
+
mk(10, { body: "Depends on #11", rec: { files: ["services/api/a.py"] } }), mk(11, { body: "Depends on #10", rec: { files: ["services/api/b.py"] } }),
|
|
41
|
+
mk(12, { rec: { severity: "P0", files: ["services/api/a.py"] } }),
|
|
42
|
+
train(13, "services/api/ok.py"), train(14, "services/api/st.py", { exists_in: "staging-only" }),
|
|
43
|
+
train(15, "infra/migrations/001.sql"), train(16, "contracts/strict/x.proto"), train(17, "shared/util.py"), train(18, "shared/billing.py"),
|
|
44
|
+
mk(19, { rec: { type: "feature", files: ["services/api/feat.py"] } }), mk(20, { rec: { type: "infra", files: ["infra/ci.yml"] } }),
|
|
45
|
+
mk(21, { rec: { type: "chore", files: ["services/worker/c.py"] } }), mk(22, { rec: { type: "docs", files: ["docs/readme.md"] } }),
|
|
46
|
+
mk(23, { body: "Depends on #19", rec: { files: ["services/worker/b.py"] } }),
|
|
47
|
+
mk(24, { rec: { type: "bug", files: ["services/cron/x.py"] } }), mk(25, { rec: { type: "bug", files: ["web/x.ts"] } }),
|
|
48
|
+
mk(26, { body: "depends on #1", rec: { files: ["services/api/z.py"] } }),
|
|
49
|
+
mk(27, { labels: ["design:needed", "design:approved"], rec: { files: ["services/api/d.py"] } }),
|
|
50
|
+
mk(28, { rec: { files: ["contracts/add/x.proto"] } }),
|
|
51
|
+
];
|
|
52
|
+
for (let n = 29; n <= 46; n++) f.push(train(n, `services/${["api", "worker"][n % 2]}/f${n}.py`));
|
|
53
|
+
f.push({ ...mk(47, {}), pullRequest: true }, mk(48, { labels: ["release-plan"] }));
|
|
54
|
+
return f;
|
|
55
|
+
}
|
|
56
|
+
const run = (over = {}) => buildPlan({ issues: fixture(), policy: POLICY, policySha: POLICY_SHA, liveSha: LIVE, now: Date.parse("2026-03-01T00:00:00Z"), ...over });
|
|
57
|
+
const excl = (p) => Object.fromEntries(p.excluded.map((e) => [e.number, e.key]));
|
|
58
|
+
|
|
59
|
+
describe("buildPlan (#5559)", () => {
|
|
60
|
+
it("plans or excludes every candidate with a key, never a PR or the tracking issue", () => {
|
|
61
|
+
const p = run(), ex = excl(p), planned = Object.keys(p.issues).map(Number);
|
|
62
|
+
const cands = fixture().filter((i) => !i.pullRequest && !i.labels.some((l) => l.name === "release-plan")).map((i) => i.number);
|
|
63
|
+
assert.ok(cands.length >= 40);
|
|
64
|
+
assert.deepEqual([...planned, ...Object.keys(ex).map(Number)].sort((a, b) => a - b), cands);
|
|
65
|
+
for (const k of Object.values(ex)) assert.ok(EXCLUSION_KEYS.includes(k), k);
|
|
66
|
+
assert.deepEqual({ 1: ex[1], 2: ex[2], 3: ex[3], 4: ex[4], 5: ex[5], 6: ex[6], 7: ex[7], 8: ex[8], 9: ex[9], 10: ex[10], 11: ex[11], 12: ex[12], 26: ex[26] },
|
|
67
|
+
{ 1: "epic", 2: "plan.skip_labels", 3: "plan.skip_labels", 4: "plan.skip_labels", 5: "design_gate", 6: "ready_no", 7: "unclassified", 8: "unclassified", 9: "dependency_open", 10: "dependency_cycle", 11: "dependency_cycle", 12: "p0", 26: "dependency_open" });
|
|
68
|
+
assert.equal(ex[47], undefined); assert.equal(ex[48], undefined);
|
|
69
|
+
});
|
|
70
|
+
it("assigns lanes: first match wins and the reason is recorded", () => {
|
|
71
|
+
const { issues: l } = run();
|
|
72
|
+
assert.equal(l[13].lane, "train");
|
|
73
|
+
for (const n of [14, 15, 16, 17, 18]) assert.equal(l[n].lane, "release", `#${n}`);
|
|
74
|
+
assert.match(l[14].reason, /staging-only/); assert.match(l[15].reason, /migrations/); assert.match(l[16].reason, /contract/); assert.match(l[17].reason, /units_max/); assert.match(l[18].reason, /risk high/);
|
|
75
|
+
for (const n of [19, 20, 21]) assert.equal(l[n].lane, "release");
|
|
76
|
+
assert.equal(l[22].docs_only, true); assert.deepEqual(l[22].units, []);
|
|
77
|
+
assert.equal(l[23].lane, "release"); assert.match(l[23].reason, /#19/); // a bug depending on a feature moves to the release wave
|
|
78
|
+
assert.equal(l[19].lane, "release"); // a feature never moves earlier
|
|
79
|
+
assert.equal(l[27].lane, "train"); assert.equal(l[28].lane, "release"); assert.deepEqual(l[28].atomic.order, ["worker", "cron"]);
|
|
80
|
+
});
|
|
81
|
+
it("orders trains before the release wave, dependencies first, and overflows train waves", () => {
|
|
82
|
+
const p = run(), ids = p.waves.map((w) => w.id);
|
|
83
|
+
assert.equal(ids.at(-1), "release");
|
|
84
|
+
assert.ok(ids.filter((i) => i.startsWith("train-")).length >= 2);
|
|
85
|
+
assert.ok(p.waves.filter((w) => w.lane === "train").every((w) => w.issues.length <= 15 && w.units.length <= 3));
|
|
86
|
+
const pos = (n) => p.waves.findIndex((w) => w.issues.includes(n));
|
|
87
|
+
assert.ok(pos(19) <= pos(23));
|
|
88
|
+
const rel = p.waves.at(-1).issues; assert.ok(rel.indexOf(19) < rel.indexOf(23));
|
|
89
|
+
});
|
|
90
|
+
it("is byte-identical for the same inputs and unaffected by input order", () => {
|
|
91
|
+
const a = stableJson(run()), shuffled = fixture().reverse();
|
|
92
|
+
assert.equal(stableJson(run({ issues: shuffled })), a);
|
|
93
|
+
assert.equal(stableJson(run()), a);
|
|
94
|
+
});
|
|
95
|
+
it("any change to the snapshot, policy sha or live sha yields a new hash", () => {
|
|
96
|
+
const base = run().plan_hash, f = fixture();
|
|
97
|
+
assert.notEqual(run({ policySha: "q".repeat(64) }).plan_hash, base);
|
|
98
|
+
assert.notEqual(run({ liveSha: "b".repeat(40) }).plan_hash, base);
|
|
99
|
+
assert.notEqual(run({ issues: f.map((i) => (i.number === 13 ? { ...i, body: "edited" } : i)) }).plan_hash, base);
|
|
100
|
+
assert.notEqual(run({ issues: f.map((i) => (i.number === 13 ? { ...i, updatedAt: "2027-01-01T00:00:00Z" } : i)) }).plan_hash, base);
|
|
101
|
+
});
|
|
102
|
+
it("caps the plan at plan.max_issues in wave order and keeps dependents behind their dependencies", () => {
|
|
103
|
+
const p = run({ policy: { ...POLICY, plan: { max_issues: 10 } } });
|
|
104
|
+
assert.equal(Object.keys(p.issues).length, 10);
|
|
105
|
+
assert.ok(p.excluded.some((e) => e.key === "max_issues"));
|
|
106
|
+
});
|
|
107
|
+
it("runs the injectable investigation seam before declaring an issue unclassified", () => {
|
|
108
|
+
const p = run({ investigate: (i) => (i.number === 7 ? { type: "bug", exists_in: "live", confidence: 0.9, files: ["services/api/q.py"], severity: "P2" } : null) });
|
|
109
|
+
assert.ok(p.issues[7]); assert.equal(excl(p)[8], "unclassified");
|
|
110
|
+
});
|
|
111
|
+
it("honours an unexpired trusted lane --force and ignores expired or untrusted ones", () => {
|
|
112
|
+
const now = Date.parse("2026-03-01T00:00:00Z"), at = new Date(now - 3_600_000).toISOString();
|
|
113
|
+
const lanes = { 13: { force: "release", actor: "owner", at }, 14: { force: "train", actor: "owner", at: new Date(now - 90_000_000).toISOString() }, 24: { force: "exclude", actor: "owner", at }, 25: { force: "release", actor: "mallory", at } };
|
|
114
|
+
assert.deepEqual(Object.keys(honouredLanes(lanes, POLICY, now)), ["13", "24"]);
|
|
115
|
+
const p = run({ lanes, now });
|
|
116
|
+
assert.equal(p.issues[13].lane, "release"); assert.equal(p.issues[13].forced, true);
|
|
117
|
+
assert.equal(p.issues[14].lane, "release"); assert.equal(excl(p)[24], "lane_force_exclude"); assert.equal(p.issues[25].lane, "train");
|
|
118
|
+
assert.notEqual(p.plan_hash, run({ now }).plan_hash);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("rollSet (#5559)", () => {
|
|
123
|
+
it("shared paths roll the full coupling set; contracts are atomic, producer first", () => {
|
|
124
|
+
assert.deepEqual(rollSet(POLICY, ["shared/x.py"]).units, ["api", "cron", "web", "worker"]);
|
|
125
|
+
const c = rollSet(POLICY, ["contracts/strict/a.proto"]);
|
|
126
|
+
assert.deepEqual(c.contract.order, ["api", "web"]); assert.equal(c.contract.atomic, true); assert.equal(c.contract.release_only, true);
|
|
127
|
+
const add = rollSet(POLICY, ["contracts/add/a.proto"]);
|
|
128
|
+
assert.equal(add.contract.release_only, false); assert.equal(add.contract.order[0], "worker");
|
|
129
|
+
});
|
|
130
|
+
it("forces, service_pipeline: false and two-host units", () => {
|
|
131
|
+
assert.equal(rollSet(POLICY, ["infra/x.yml"]).pipeline, "full");
|
|
132
|
+
assert.equal(rollSet(POLICY, ["legacy/x.py"]).pipeline, "full");
|
|
133
|
+
assert.equal(rollSet(POLICY, ["services/api/x.py"]).pipeline, "service");
|
|
134
|
+
assert.equal(rollSet(POLICY, ["docs/x.md"]).pipeline, "none");
|
|
135
|
+
assert.deepEqual(rollSet(POLICY, ["web/a.ts"]).hosts, { web: ["h1", "h2"] });
|
|
136
|
+
assert.deepEqual(rollSet(POLICY, ["edge/a.ts"]).hosts, { edge: ["h1"] });
|
|
137
|
+
});
|
|
138
|
+
it("property: the rolled set is a superset of every unit the files affect (I4, planning side)", () => {
|
|
139
|
+
const corpus = ["services/api/a.py", "services/worker/b.py", "services/cron/c.py", "web/x.ts", "edge/e.ts", "legacy/l.py", "shared/s.py", "shared/billing.py", "contracts/strict/a", "contracts/add/b", "infra/migrations/1.sql", "infra/ci.yml", "docs/a.md", "README.md"];
|
|
140
|
+
for (let mask = 1; mask < 1 << 8; mask++) for (let shift = 0; shift < corpus.length; shift++) {
|
|
141
|
+
const files = corpus.filter((_, i) => mask & (1 << ((i + shift) % 8)) && (i + shift) % 2 === 0 || mask & (1 << ((i + shift) % 8)) && i % 3 === 0);
|
|
142
|
+
const rolled = new Set(rollSet(POLICY, files).units);
|
|
143
|
+
for (const u of deriveFacts(POLICY, files).units) assert.ok(rolled.has(u), `${u} from ${files}`);
|
|
144
|
+
for (const f of files) { const r = resolvePath(POLICY, f); for (const u of [...r.units, ...r.affects, ...r.contracts.flatMap((c) => [c.producer, ...c.consumers])]) assert.ok(rolled.has(u), `${u} from ${f}`); }
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("approval (#5559, I2)", () => {
|
|
150
|
+
const dec = (plan, author) => ({ author, body: `<!-- FORGE:DECISION plan ${plan.plan_hash} -->` });
|
|
151
|
+
it("binds to the hash for a trusted actor and goes stale on any edit", () => {
|
|
152
|
+
const p = run(), d = [dec(p, "owner")];
|
|
153
|
+
assert.deepEqual(approvalOf(p, d, POLICY), { state: "approved", by: "owner", ignored: [] });
|
|
154
|
+
assert.equal(approvalOf(run({ policySha: "q".repeat(64) }), d, POLICY).state, "stale");
|
|
155
|
+
assert.equal(approvalOf(run({ liveSha: "c".repeat(40) }), d, POLICY).state, "stale");
|
|
156
|
+
assert.equal(approvalOf(run({ issues: fixture().map((i) => (i.number === 13 ? { ...i, body: "edited" } : i)) }), d, POLICY).state, "stale");
|
|
157
|
+
assert.equal(approvalOf(run({ policy: POLICY }), d, POLICY).state, "approved");
|
|
158
|
+
});
|
|
159
|
+
it("ignores a decision from a non-trusted actor", () => {
|
|
160
|
+
const p = run(), a = approvalOf(p, [dec(p, "mallory")], POLICY);
|
|
161
|
+
assert.equal(a.state, "none"); assert.deepEqual(a.ignored, ["mallory"]);
|
|
162
|
+
assert.equal(approvalOf(p, [dec(p, "owner")], { ...POLICY, trust: {} }).state, "none");
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe("forecast and planFromCli (#5559)", () => {
|
|
167
|
+
const io = (w = {}) => {
|
|
168
|
+
const calls = [];
|
|
169
|
+
return { calls, now: () => Date.parse("2026-03-01T00:00:00Z"), print: (l) => calls.push(["print", l]), gh: async (a) => { calls.push(["gh", a]); return a[0] === "issue" ? JSON.stringify(w.issues ?? fixture()) : JSON.stringify({ nameWithOwner: "o/r" }); },
|
|
170
|
+
api: async (...a) => { calls.push(["api", a]); return { tree: { sha: "t" }, sha: "c" }; }, rehearse: async () => ({ ok: true, output: LIVE }) };
|
|
171
|
+
};
|
|
172
|
+
const pol = { ...POLICY, deploy: { live_release_command: "echo live" } };
|
|
173
|
+
it("forecasts minutes per wave and applies on_exceed", () => {
|
|
174
|
+
const p = run(), f = forecastPlan(p, [{ lane: "train", minutes: 10 }, { lane: "release", minutes: 40 }], { remaining: 30, cfg: { onExceed: "hold" } });
|
|
175
|
+
assert.equal(f.forecast, 10 * p.waves.filter((w) => w.lane === "train").length + 40); assert.equal(f.action, "hold");
|
|
176
|
+
assert.equal(forecastPlan(p, [], {}).forecast, null);
|
|
177
|
+
});
|
|
178
|
+
it("makes zero GitHub writes with managed off and prints the plan", async () => {
|
|
179
|
+
const i = io();
|
|
180
|
+
assert.equal(await planFromCli(["--repo", "o/r"], { io: i, policy: pol, policySha: POLICY_SHA }), 0);
|
|
181
|
+
assert.equal(i.calls.filter((c) => c[0] === "api").length, 0);
|
|
182
|
+
assert.ok(i.calls.filter((c) => c[0] === "gh").every((c) => c[1][0] === "issue" || c[1][0] === "repo"));
|
|
183
|
+
assert.match(i.calls.find((c) => c[0] === "print")[1], /^release plan [0-9a-f]{12}/);
|
|
184
|
+
assert.ok(i.calls.some((c) => c[0] === "print" && /call p0: #12/.test(c[1])));
|
|
185
|
+
});
|
|
186
|
+
it("persists through the ledger writer only when managed", async () => {
|
|
187
|
+
const seen = [], ledger = async (r) => { seen.push(r.id); };
|
|
188
|
+
await planFromCli(["--repo", "o/r", "--json"], { io: io(), policy: pol, policySha: POLICY_SHA, managed: true, newId: "r20260301-000000-1", ledger });
|
|
189
|
+
assert.deepEqual(seen, ["r20260301-000000-1"]);
|
|
190
|
+
await planFromCli(["--repo", "o/r", "--json"], { io: io(), policy: pol, policySha: POLICY_SHA, managed: false, newId: "r20260301-000000-2", ledger });
|
|
191
|
+
assert.equal(seen.length, 1);
|
|
192
|
+
});
|
|
193
|
+
it("--issues narrows the candidates, --json is stable, a missing policy refuses", async () => {
|
|
194
|
+
const i = io();
|
|
195
|
+
await planFromCli(["--repo", "o/r", "--issues", "13,14", "--json"], { io: i, policy: pol, policySha: POLICY_SHA });
|
|
196
|
+
const out = JSON.parse(i.calls.find((c) => c[0] === "print")[1]);
|
|
197
|
+
assert.deepEqual(Object.keys(out.issues), ["13", "14"]); assert.equal(out.approval.state, "none"); assert.equal(out.live_sha, LIVE);
|
|
198
|
+
const j = io();
|
|
199
|
+
assert.equal(await planFromCli(["--repo", "o/r"], { io: j, policy: null, policySha: null }), 1);
|
|
200
|
+
await assert.rejects(planFromCli(["--lane", "bogus", "--repo", "o/r"], { io: j, policy: pol, policySha: POLICY_SHA }), /--lane/);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -35,6 +35,22 @@ export async function runHostPreflight(ctx, { head, pr }) {
|
|
|
35
35
|
return kept;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
const shq = (f) => `'${String(f).replace(/'/g, `'\\''`)}'`;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Targeted preflight (#5566): runs `preflight.command` with `{files}` replaced by the quoted target set. A command without `{files}`
|
|
42
|
+
* is not targeted, so it covers nothing: the caller counts that as unvalidated. Files no blocker issue (the caller decides).
|
|
43
|
+
* @returns {Promise<{ok, head, command, covered: string[], code}>}
|
|
44
|
+
*/
|
|
45
|
+
export async function runTargetedPreflight(ctx, { head, target }) {
|
|
46
|
+
const cfg = ctx.config?.preflight;
|
|
47
|
+
if (!cfg) return { ok: false, head, covered: [], why: "no release.preflight_command configured" };
|
|
48
|
+
const targeted = cfg.command.includes("{files}");
|
|
49
|
+
const command = cfg.command.split("{files}").join(target.map(shq).join(" "));
|
|
50
|
+
const run = await ctx.io.rehearse(command, { timeout: cfg.timeoutMs });
|
|
51
|
+
return { ok: !!run.ok, head, command, covered: run.ok && targeted ? [...target] : [], code: run.code ?? null };
|
|
52
|
+
}
|
|
53
|
+
|
|
38
54
|
const stopOf = (r) => ({ stopped: true, why: `release preflight failed at ${r.head} (release-blocker #${r.issue}); fix it, then resume`, ...r });
|
|
39
55
|
|
|
40
56
|
/** Step before `release-pr`: preflight on the staging head, so no release PR is opened on a failing head. */
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Gate-only fix lane (#5584, epic #5549 N5, rule R4): `forgedock release control regate <id> --ref <fix> --reason ...`
|
|
5
|
+
* re-evaluates the gates of an already-deployed release sha with the gate code of the fix ref, without a merge cycle.
|
|
6
|
+
* `classifyGateOnly` decides from the changed paths whether the fix is limited to gate artifacts; anything that ships in an
|
|
7
|
+
* image (app, migration, image path, a workflow hunk outside `gates.workflow_steps`) is the normal lane. `regatePlan` refuses
|
|
8
|
+
* closed (no recorded live record/rollback target, a run-set freeze with migration evidence, not gate-only); `regateDispatch`
|
|
9
|
+
* sends the one fenced dispatch (`forge_epoch`, never `override_freeze`, I26) and records the gate-script sha. Nothing here
|
|
10
|
+
* runs unless the verb is called.
|
|
11
|
+
*/
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import { buildDispatchArgs } from "./release-control.mjs";
|
|
14
|
+
import { fenced } from "./release-fence.mjs";
|
|
15
|
+
import { acquireLease } from "./release-ledger.mjs";
|
|
16
|
+
import { parseGatesConfig } from "./release-gates.mjs";
|
|
17
|
+
import { MIGRATION_PATHS } from "./release-config.mjs";
|
|
18
|
+
|
|
19
|
+
export const IMAGE_PATH = /(^|\/)(Dockerfile[^/]*|[^/]*\.dockerfile|docker-compose[^/]*\.ya?ml|\.dockerignore)$/i;
|
|
20
|
+
export const WORKFLOW_PATH = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
21
|
+
|
|
22
|
+
const reOf = (g) => new RegExp(`^${g.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "\u0000").replace(/\*\*/g, "\u0001").replace(/\*/g, "[^/]*").replace(/\u0000/g, "(?:.*/)?").replace(/\u0001/g, ".*")}$`);
|
|
23
|
+
export const releaseRegateMatchesAny = (path, globs) => globs.some((g) => reOf(g).test(path));
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string[]} changedPaths files changed between the failed release sha and the candidate fix
|
|
27
|
+
* @param {object} policy release policy (`gates.paths`, `gates.workflow_steps`)
|
|
28
|
+
* @param {{workflowSteps?: Record<string, Array<string|null>>}} [o] per workflow file, the step name (null: outside any step) of each changed hunk
|
|
29
|
+
* @returns {{gateOnly: boolean, offenders: {path: string, kind: string}[]}}
|
|
30
|
+
*/
|
|
31
|
+
export function classifyGateOnly(changedPaths, policy, { workflowSteps = {} } = {}) {
|
|
32
|
+
const cfg = parseGatesConfig(policy), offenders = [];
|
|
33
|
+
for (const path of changedPaths) {
|
|
34
|
+
let kind = null;
|
|
35
|
+
if (releaseRegateMatchesAny(path, MIGRATION_PATHS)) kind = "migration";
|
|
36
|
+
else if (IMAGE_PATH.test(path)) kind = "image";
|
|
37
|
+
else if (WORKFLOW_PATH.test(path)) {
|
|
38
|
+
const steps = workflowSteps[path];
|
|
39
|
+
if (!Array.isArray(steps) || !steps.length || steps.some((s) => s == null || !cfg.workflowSteps.includes(s))) kind = "workflow-hunk";
|
|
40
|
+
} else if (!releaseRegateMatchesAny(path, cfg.paths)) kind = "app";
|
|
41
|
+
if (kind) offenders.push({ path, kind });
|
|
42
|
+
}
|
|
43
|
+
return { gateOnly: !!changedPaths.length && !offenders.length, offenders };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The step name each changed hunk of workflow `file` (between `base` and `ref`) lies in; null for a line outside any named step. */
|
|
47
|
+
export function hunkSteps(io, base, ref, file) {
|
|
48
|
+
const diff = String(io.git(["diff", "-U0", `${base}..${ref}`, "--", file]));
|
|
49
|
+
const lines = String(io.git(["show", `${ref}:${file}`])).split("\n");
|
|
50
|
+
const indent = (l) => l.length - l.trimStart().length;
|
|
51
|
+
const items = [];
|
|
52
|
+
lines.forEach((l, i) => {
|
|
53
|
+
if (!/^\s*-\s/.test(l)) return;
|
|
54
|
+
const ind = indent(l);
|
|
55
|
+
let end = i + 1;
|
|
56
|
+
while (end < lines.length && (!lines[end].trim() || lines[end].trim().startsWith("#") || indent(lines[end]) > ind || (indent(lines[end]) === ind && !/^\s*-\s/.test(lines[end])))) end++;
|
|
57
|
+
let name = null;
|
|
58
|
+
for (let j = i; j < end; j++) { const m = new RegExp(`^\\s{${j === i ? ind : ind + 2}}(?:-\\s+)?name:\\s*["']?(.+?)["']?\\s*$`).exec(lines[j]); if (m) { name = m[1]; break; } }
|
|
59
|
+
if (name) items.push({ start: i, end, name });
|
|
60
|
+
});
|
|
61
|
+
const out = [];
|
|
62
|
+
for (const m of diff.matchAll(/^@@ -\S+ \+(\d+)(?:,(\d+))? @@/gm)) {
|
|
63
|
+
const c = Number(m[1]), d = m[2] === undefined ? 1 : Number(m[2]);
|
|
64
|
+
const from = Math.max(c - 1, 0), to = d === 0 ? from : c - 2 + d; // 0-based inclusive; a pure deletion maps to the line it follows
|
|
65
|
+
for (let ln = from; ln <= to; ln++) out.push(items.filter((it) => it.start <= ln && ln < it.end).pop()?.name ?? null);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const rev = (io, r) => String(io.git(["rev-parse", "--verify", `${r}^{commit}`])).trim();
|
|
71
|
+
|
|
72
|
+
/** sha1 over `path blob` of each changed gate path at `ref`: identifies the gate code that evaluates. */
|
|
73
|
+
export function gateScriptSha(io, ref, paths) {
|
|
74
|
+
const lines = [...paths].sort().map((p) => { let b = "deleted"; try { b = String(io.git(["rev-parse", `${ref}:${p}`])).trim(); } catch { /* deleted at ref */ } return `${p} ${b}`; });
|
|
75
|
+
return createHash("sha1").update(lines.join("\n")).digest("hex");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Every refusal happens before anything is written or dispatched.
|
|
80
|
+
* `ctx`: {io, repo, policy, state}; `args`: {ref, gateFixRef?}.
|
|
81
|
+
* @returns {{refuse: string} | {plan: {sha, refName, ref, gateSha, gateFixRef, workflow, changed}}}
|
|
82
|
+
*/
|
|
83
|
+
export async function regatePlan({ io, repo, policy, state }, { ref, gateFixRef = null }) {
|
|
84
|
+
const d = state?.deploy;
|
|
85
|
+
if (!d?.target?.sha || !d.merge) return { refuse: "no recorded live record/rollback target for this release (I9); nothing to re-evaluate" };
|
|
86
|
+
if (!ref) return { refuse: "--ref <fix branch or sha> is required" };
|
|
87
|
+
const workflow = policy?.verify?.workflow;
|
|
88
|
+
if (!workflow) return { refuse: "policy verify.workflow is not set; nothing to dispatch" };
|
|
89
|
+
let refSha, changed;
|
|
90
|
+
try {
|
|
91
|
+
refSha = rev(io, ref);
|
|
92
|
+
changed = String(io.git(["diff", "--name-only", `${d.merge}..${refSha}`])).split("\n").filter(Boolean);
|
|
93
|
+
} catch (e) { return { refuse: `cannot diff ${String(d.merge).slice(0, 8)}..${ref}: ${String(e?.message ?? e).split("\n")[0]}` }; }
|
|
94
|
+
const name = policy?.deploy?.freeze_variable;
|
|
95
|
+
if (name) {
|
|
96
|
+
let v = ""; try { v = String(await io.gh(["variable", "get", name, "--repo", repo])).trim(); } catch { /* unset */ }
|
|
97
|
+
if (v && !d.freezeBefore) { // set during the deploy: the run froze it
|
|
98
|
+
let mig;
|
|
99
|
+
try { mig = String(io.git(["diff", "--name-only", `${d.target.sha}..${d.merge}`, "--", ...MIGRATION_PATHS])).split("\n").filter(Boolean); } catch { mig = ["(unreadable)"]; }
|
|
100
|
+
if (mig.length) return { refuse: `${name} was set by the run and migration evidence exists (${mig[0]}); a human decides with override_freeze (I26)` };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let workflowSteps = {};
|
|
104
|
+
try { for (const f of changed.filter((p) => WORKFLOW_PATH.test(p))) workflowSteps[f] = hunkSteps(io, d.merge, refSha, f); } catch { workflowSteps = {}; }
|
|
105
|
+
const c = classifyGateOnly(changed, policy, { workflowSteps });
|
|
106
|
+
if (!c.gateOnly) return { refuse: `not a gate-only fix; use the normal lane (${c.offenders.slice(0, 3).map((o) => `${o.path}: ${o.kind}`).join(", ") || "no changed paths"})` };
|
|
107
|
+
if ((state.regates ?? []).some((r) => r.ref === refSha)) return { refuse: `${refSha.slice(0, 8)} was already re-evaluated for this release` };
|
|
108
|
+
return { plan: { sha: d.merge, refName: ref, ref: refSha, gateSha: gateScriptSha(io, refSha, changed), gateFixRef, workflow, changed } };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The lease that fences the dispatch (own epoch, `forge_epoch` input); no `io.api`: unmanaged, no fence. */
|
|
112
|
+
async function takeFence(ctx, holder) {
|
|
113
|
+
if (!ctx.io.api) return { fence: null };
|
|
114
|
+
const lctx = { io: ctx.io, repo: ctx.repo, credential: "driver" };
|
|
115
|
+
const l = await acquireLease(lctx, { holder, release: ctx.state.id, issue: ctx.state.steps?.["release-pr"]?.result?.pr, ttlS: 300, now: ctx.io.now() });
|
|
116
|
+
if (!l.ok) return { refused: l.refused ?? "lease lost the race" };
|
|
117
|
+
const record = async (rec) => { const a = (ctx.state.intents ??= []); const i = a.findIndex((x) => x.key === rec.key); if (i < 0) a.push(rec); else a[i] = rec; ctx.save?.(); };
|
|
118
|
+
return { fence: { lctx, lease: l.lease, record, now: () => new Date(ctx.io.now()).toISOString() } };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* One fenced dispatch of the verification workflow at the fix ref for the same release sha. LIVE_CHECK (I28) is the
|
|
123
|
+
* workflow's and the caller's: the live record is not touched here.
|
|
124
|
+
* @returns {Promise<{ok: true, entry} | {refused: string}>}
|
|
125
|
+
*/
|
|
126
|
+
export async function regateDispatch(ctx, plan, { actor, host }) {
|
|
127
|
+
const { io, repo, state } = ctx;
|
|
128
|
+
const f = ctx.fence ? { fence: ctx.fence } : await takeFence(ctx, io.holder ?? `host-${process.pid}`);
|
|
129
|
+
if (f.refused) return { refused: f.refused };
|
|
130
|
+
const inputs = { sha: plan.sha, regate: "true", gate_sha: plan.gateSha, ...(plan.gateFixRef ? { gate_fix_ref: plan.gateFixRef } : {}) };
|
|
131
|
+
let epoch = null;
|
|
132
|
+
const r = await fenced(f.fence, { action: "dispatch", key: `${state.id}:regate:${f.fence?.lease?.epoch ?? 0}:${plan.ref}` }, (e) => {
|
|
133
|
+
epoch = e;
|
|
134
|
+
return io.gh(buildDispatchArgs({ workflow: plan.workflow, repo, ref: plan.refName, inputs: { ...inputs, ...(e != null ? { forge_epoch: e } : {}) } }));
|
|
135
|
+
});
|
|
136
|
+
if (r.refused) return { refused: `dispatch ${r.refused}` };
|
|
137
|
+
const entry = { at: new Date(io.now?.() ?? Date.now()).toISOString(), ref: plan.ref, sha: plan.sha, gate_sha: plan.gateSha, ...(plan.gateFixRef ? { gate_fix_ref: plan.gateFixRef } : {}), workflow: plan.workflow, actor, host: host ?? null, forge_epoch: epoch };
|
|
138
|
+
(state.regates ??= []).push(entry);
|
|
139
|
+
ctx.save?.();
|
|
140
|
+
return { ok: true, entry };
|
|
141
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { classifyGateOnly, hunkSteps, gateScriptSha } from "./release-regate.mjs";
|
|
6
|
+
import { runControl, VERBS } from "./release-control.mjs";
|
|
7
|
+
import { gateRecord, parseGatesConfig } from "./release-gates.mjs";
|
|
8
|
+
|
|
9
|
+
const POLICY = { gates: { workflow_steps: ["Smoke"] }, verify: { workflow: "verify-release.yml" }, deploy: { freeze_variable: "DEPLOY_FREEZE" } };
|
|
10
|
+
const WF = ".github/workflows/deploy.yml";
|
|
11
|
+
const WF_TEXT = ["name: d", "jobs:", " j:", " steps:", " - name: Build", " run: make", " - name: Smoke", " run: ./s.sh", ""].join("\n");
|
|
12
|
+
|
|
13
|
+
describe("classifyGateOnly (#5584)", () => {
|
|
14
|
+
it("a gate-path-only diff is gate-only", () => {
|
|
15
|
+
const r = classifyGateOnly(["scripts/deploy/a.sh", "scripts/lib/b.sh", "scripts/prod-smoke-test.sh", "tests/gates/x.json"], POLICY);
|
|
16
|
+
assert.equal(r.gateOnly, true);
|
|
17
|
+
});
|
|
18
|
+
it("an app path, a migration path and an image path each flip it", () => {
|
|
19
|
+
for (const [p, kind] of [["src/app.ts", "app"], ["db/migrations/001.sql", "migration"], ["scripts/deploy/migrations/2.sql", "migration"], ["docker/Dockerfile.api", "image"], ["Dockerfile", "image"]]) {
|
|
20
|
+
const r = classifyGateOnly(["scripts/deploy/a.sh", p], POLICY);
|
|
21
|
+
assert.equal(r.gateOnly, false, p);
|
|
22
|
+
assert.deepEqual(r.offenders, [{ path: p, kind }]);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
it("a workflow file qualifies only when every hunk lies in a listed step", () => {
|
|
26
|
+
assert.equal(classifyGateOnly([WF], POLICY, { workflowSteps: { [WF]: ["Smoke"] } }).gateOnly, true);
|
|
27
|
+
assert.equal(classifyGateOnly([WF], POLICY, { workflowSteps: { [WF]: ["Smoke", "Build"] } }).gateOnly, false);
|
|
28
|
+
assert.equal(classifyGateOnly([WF], POLICY, { workflowSteps: { [WF]: [null] } }).gateOnly, false);
|
|
29
|
+
assert.equal(classifyGateOnly([WF], POLICY).gateOnly, false);
|
|
30
|
+
});
|
|
31
|
+
it("custom gates.paths replace the default allowlist; no changes is not gate-only", () => {
|
|
32
|
+
assert.equal(classifyGateOnly(["ops/x.sh"], { gates: { paths: ["ops/**"] } }).gateOnly, true);
|
|
33
|
+
assert.equal(classifyGateOnly(["scripts/deploy/a.sh"], { gates: { paths: ["ops/**"] } }).gateOnly, false);
|
|
34
|
+
assert.equal(classifyGateOnly([], POLICY).gateOnly, false);
|
|
35
|
+
assert.ok(parseGatesConfig({}).paths.includes("scripts/deploy/**"));
|
|
36
|
+
});
|
|
37
|
+
it("hunkSteps maps changed lines to step names", () => {
|
|
38
|
+
const io = { git: (a) => (a[0] === "diff" ? "@@ -8 +8 @@\n-x\n+y\n@@ -6,0 +6,1 @@\n+z\n@@ -5 +5 @@\n+q\n" : WF_TEXT) };
|
|
39
|
+
assert.deepEqual(hunkSteps(io, "a", "b", WF), ["Smoke", "Build", "Build"]);
|
|
40
|
+
});
|
|
41
|
+
it("a gate record keeps a valid gate_sha", () => {
|
|
42
|
+
assert.equal(gateRecord({ gate: "g", outcome: "pass", gate_sha: "abcdef1" }).gate_sha, "abcdef1");
|
|
43
|
+
assert.equal(gateRecord({ gate: "g", outcome: "pass", gate_sha: "zz" }).gate_sha, undefined);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// A tiny in-memory GitHub for the control path, as in release-control.test.mjs.
|
|
48
|
+
function world({ changed = ["scripts/prod-smoke-test.sh"], deploy = { target: { sha: "t0" }, merge: "m1" }, freezeVar = "", migrations = "" } = {}) {
|
|
49
|
+
const w = { active: { epoch: 1, lease: { holder: "A", epoch: 1, release: "r20260101-000000-1", issue: 9 } }, controls: "", comments: [], gh: [], files: {}, sha: 0, saved: 0 };
|
|
50
|
+
w.state = { id: "r20260101-000000-1", deploy, steps: { "release-pr": { result: { pr: 9 } } } };
|
|
51
|
+
w.rel = { load: () => w.state, save: () => { w.saved++; } };
|
|
52
|
+
w.io = {
|
|
53
|
+
now: () => 1_700_000_000_000, holder: "h", print: () => {},
|
|
54
|
+
git: (a) => {
|
|
55
|
+
if (a[0] === "rev-parse") return a[a.length - 1].includes(":") ? "b10b" : "f1f1f1f1";
|
|
56
|
+
if (a[0] === "diff" && a.includes("--name-only")) return a.includes("--") ? migrations : changed.join("\n");
|
|
57
|
+
throw new Error(`git ${a.join(" ")}`);
|
|
58
|
+
},
|
|
59
|
+
gh: async (a) => { w.gh.push(a); if (a[0] === "variable") { if (!freezeVar) throw new Error("not set"); return freezeVar; } return ""; },
|
|
60
|
+
api: async (method, path, body) => {
|
|
61
|
+
if (method === "GET" && /git\/ref\/heads\/_active$/.test(path)) return { object: { sha: "h0" } };
|
|
62
|
+
if (method === "GET" && /contents\/active\.json/.test(path)) return { content: Buffer.from(JSON.stringify(w.active)).toString("base64") };
|
|
63
|
+
if (method === "GET" && /contents\/controls\.jsonl/.test(path)) return { content: Buffer.from(w.controls).toString("base64") };
|
|
64
|
+
if (method === "GET" && /git\/commits\//.test(path)) return { tree: { sha: "t0" } };
|
|
65
|
+
if (method === "POST" && /git\/trees/.test(path)) { for (const t of body.tree) w.files[t.path] = t.content; return { sha: "t1" }; }
|
|
66
|
+
if (method === "POST" && /git\/commits/.test(path)) return { sha: `c${++w.sha}` };
|
|
67
|
+
if (method === "PATCH" && /git\/refs/.test(path)) { w.active = JSON.parse(w.files["active.json"]); w.controls = w.files["controls.jsonl"] ?? w.controls; return {}; }
|
|
68
|
+
if (method === "POST" && /issues\/\d+\/comments/.test(path)) { w.comments.push(body.body); return { id: w.comments.length }; }
|
|
69
|
+
throw new Error(`unrouted ${method} ${path}`);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
return w;
|
|
73
|
+
}
|
|
74
|
+
const RID = "r20260101-000000-1";
|
|
75
|
+
const run = (w, argv, extra = {}) => runControl("regate", [RID, "--reason", "fix smoke", ...argv], { io: w.io, repo: "o/r", actor: "op", host: "h1", now: 1_700_000_000_000, policy: POLICY, rel: w.rel, ...extra });
|
|
76
|
+
const auditLine = (w) => w.controls.trim().split("\n").map((l) => JSON.parse(l)).filter((l) => l.verb === "regate").pop();
|
|
77
|
+
const dispatches = (w) => w.gh.filter((a) => a[0] === "workflow");
|
|
78
|
+
|
|
79
|
+
describe("regate verb (#5584)", () => {
|
|
80
|
+
it("is a control verb", () => assert.ok(VERBS.includes("regate")));
|
|
81
|
+
it("replay of 11-12: one fenced dispatch at the fix ref for the same sha, no merge", async () => {
|
|
82
|
+
const w = world();
|
|
83
|
+
const r = await run(w, ["--ref", "fix/smoke"]);
|
|
84
|
+
assert.equal(r.ok, true, r.error);
|
|
85
|
+
const d = dispatches(w);
|
|
86
|
+
assert.equal(d.length, 1);
|
|
87
|
+
assert.deepEqual(d[0].slice(0, 7), ["workflow", "run", "verify-release.yml", "--repo", "o/r", "--ref", "fix/smoke"]);
|
|
88
|
+
const inputs = Object.fromEntries(d[0].filter((x) => x.includes("=")).map((x) => x.split("=")));
|
|
89
|
+
assert.equal(inputs.sha, "m1");
|
|
90
|
+
assert.equal(inputs.regate, "true");
|
|
91
|
+
assert.match(inputs.forge_epoch, /^\d+$/);
|
|
92
|
+
assert.equal(inputs.override_freeze, undefined);
|
|
93
|
+
assert.equal(w.gh.filter((a) => a[0] === "pr").length, 0, "no merge");
|
|
94
|
+
assert.equal(w.state.regates.length, 1);
|
|
95
|
+
assert.equal(w.state.regates[0].gate_sha, inputs.gate_sha);
|
|
96
|
+
});
|
|
97
|
+
it("the audit entry carries the gate-script sha and the actor", async () => {
|
|
98
|
+
const w = world();
|
|
99
|
+
const r = await run(w, ["--ref", "fix/smoke"]);
|
|
100
|
+
const line = auditLine(w);
|
|
101
|
+
assert.equal(line.verb, "regate");
|
|
102
|
+
assert.equal(line.actor, "op");
|
|
103
|
+
assert.match(line.after.gate_sha, /^[0-9a-f]{40}$/);
|
|
104
|
+
assert.equal(line.after.gate_sha, r.entry.after.gate_sha);
|
|
105
|
+
assert.equal(line.after.gate_sha, gateScriptSha(w.io, "f1f1f1f1", ["scripts/prod-smoke-test.sh"]));
|
|
106
|
+
});
|
|
107
|
+
it("gate_fix_ref rides the dispatch for a hotfix and is recorded", async () => {
|
|
108
|
+
const w = world();
|
|
109
|
+
const r = await run(w, ["--ref", "fix/smoke", "--gate-fix-ref", "hotfix/9"]);
|
|
110
|
+
assert.equal(r.ok, true, r.error);
|
|
111
|
+
assert.ok(dispatches(w)[0].includes("gate_fix_ref=hotfix/9"));
|
|
112
|
+
assert.equal(w.state.regates[0].gate_fix_ref, "hotfix/9");
|
|
113
|
+
assert.equal(auditLine(w).after.gate_fix_ref, "hotfix/9");
|
|
114
|
+
});
|
|
115
|
+
it("refuses with no recorded live record/rollback target", async () => {
|
|
116
|
+
const w = world({ deploy: null });
|
|
117
|
+
const r = await run(w, ["--ref", "fix/smoke"]);
|
|
118
|
+
assert.equal(r.ok, false);
|
|
119
|
+
assert.match(r.error, /no recorded live record/);
|
|
120
|
+
assert.equal(dispatches(w).length, 0);
|
|
121
|
+
assert.equal(w.controls, "");
|
|
122
|
+
});
|
|
123
|
+
it("refuses a run-set freeze with migration evidence, never sending override_freeze", async () => {
|
|
124
|
+
const w = world({ freezeVar: "1", migrations: "db/migrations/9.sql" });
|
|
125
|
+
const r = await run(w, ["--ref", "fix/smoke"]);
|
|
126
|
+
assert.equal(r.ok, false);
|
|
127
|
+
assert.match(r.error, /migration evidence/);
|
|
128
|
+
assert.equal(dispatches(w).length, 0);
|
|
129
|
+
const pre = world({ freezeVar: "1", migrations: "db/migrations/9.sql", deploy: { target: { sha: "t0" }, merge: "m1", freezeBefore: "1" } });
|
|
130
|
+
assert.equal((await run(pre, ["--ref", "fix/smoke"])).ok, true, "a freeze set before the deploy is not the run's");
|
|
131
|
+
});
|
|
132
|
+
it("refuses a non-gate-only fix and a repeated ref", async () => {
|
|
133
|
+
const w = world({ changed: ["scripts/prod-smoke-test.sh", "src/app.ts"] });
|
|
134
|
+
assert.match((await run(w, ["--ref", "f"])).error, /not a gate-only fix/);
|
|
135
|
+
const w2 = world();
|
|
136
|
+
assert.equal((await run(w2, ["--ref", "f"])).ok, true);
|
|
137
|
+
assert.match((await run(w2, ["--ref", "f"])).error, /already re-evaluated/);
|
|
138
|
+
assert.match((await run(world(), [])).error, /--ref/);
|
|
139
|
+
assert.match((await runControl("regate", [RID, "--ref", "f"], { io: w.io, repo: "o/r", rel: w.rel })).error, /--reason/);
|
|
140
|
+
});
|
|
141
|
+
it("a hold refuses the dispatch (fenced) after the audit line", async () => {
|
|
142
|
+
const w = world();
|
|
143
|
+
w.active.holds = { [RID]: { reason: "incident" } };
|
|
144
|
+
const r = await run(w, ["--ref", "fix/smoke"]);
|
|
145
|
+
assert.equal(r.ok, false);
|
|
146
|
+
assert.match(r.error, /held/);
|
|
147
|
+
assert.equal(dispatches(w).length, 0);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -18,6 +18,7 @@ import { reviewStagingJson, reviewStagingIo, CI_EXCLUDED_CHECKS } from "../revie
|
|
|
18
18
|
import { pickFixes, recut, revertLast } from "./release-snapshot.mjs";
|
|
19
19
|
import { parseFixConfig, collectFindings, blockingOf, compileBrief, roundsAt, recordRound, secondPush, secondPushOf, holdForOwner, jobsToRerun, inputHash, deferredOf } from "./release-fixloop.mjs";
|
|
20
20
|
import { coStartCi } from "./release-preflight.mjs";
|
|
21
|
+
import { laneEnv } from "./release-credentials.mjs";
|
|
21
22
|
|
|
22
23
|
/** Delta passes after a head move: past it the job blocks for the manual path. Fix rounds are `ci.fix.max_rounds` (release-fixloop.mjs, default 1, #5567). */
|
|
23
24
|
export const MAX_DELTA_PASSES = 2;
|
|
@@ -298,8 +299,9 @@ export async function fixStep(ctx) {
|
|
|
298
299
|
const seamOf = (ctx) => ctx.io.review ?? (ctx.seam ??= realSeam(ctx));
|
|
299
300
|
|
|
300
301
|
/** Real effects of the review steps: the review-staging library, the engine runner, the filing scripts, gh and a lane process. */
|
|
301
|
-
export function realSeam({ repo, def, env = process.env, cwd = process.cwd(), makeRunner = null, gh: ghIn = null }) {
|
|
302
|
+
export function realSeam({ repo, def, env = process.env, laneStrip = [], cwd = process.cwd(), makeRunner = null, gh: ghIn = null }) {
|
|
302
303
|
const rs = { ...reviewStagingIo(), cwd, env };
|
|
304
|
+
const lane = laneEnv(env, laneStrip); // #5561: reviewer, fix and lane sandboxes never see the driver token
|
|
303
305
|
const sd = env.FORGE_SCRATCHPAD || join(cwd, ".forge-scratch");
|
|
304
306
|
let runner = null, shimEnv = null;
|
|
305
307
|
// Reviewer briefs say `forgedock ...`: pin that name to this release job's own build, whatever is installed globally.
|
|
@@ -308,7 +310,7 @@ export function realSeam({ repo, def, env = process.env, cwd = process.cwd(), ma
|
|
|
308
310
|
const dir = mkdtempSync(join(tmpdir(), "release-forgedock-"));
|
|
309
311
|
writeFileSync(join(dir, "forgedock"), `#!/bin/sh\nexec "${process.execPath}" "${join(ROOT, "bin", "forgedock.mjs")}" "$@"\n`, { mode: 0o755 });
|
|
310
312
|
process.once("exit", () => rmSync(dir, { recursive: true, force: true }));
|
|
311
|
-
return (shimEnv = { ...
|
|
313
|
+
return (shimEnv = { ...lane, PATH: `${dir}${delimiter}${lane.PATH ?? ""}` });
|
|
312
314
|
};
|
|
313
315
|
const gh = ghIn ?? ((args, input) => execFileSync("gh", args, { encoding: "utf8", input, maxBuffer: 64 << 20, env }));
|
|
314
316
|
return {
|
|
@@ -386,7 +388,7 @@ export function realSeam({ repo, def, env = process.env, cwd = process.cwd(), ma
|
|
|
386
388
|
runLane: ({ issue, lane }) => new Promise((resolve) => {
|
|
387
389
|
const dir = mkdtempSync(join(tmpdir(), "release-lane-"));
|
|
388
390
|
const rf = join(dir, "result.json");
|
|
389
|
-
const child = spawn(process.execPath, [join(ROOT, "bin", "forgedock.mjs"), "run-issue", String(issue), "--lane", lane, "--result-file", rf], { cwd, env, stdio: "ignore" });
|
|
391
|
+
const child = spawn(process.execPath, [join(ROOT, "bin", "forgedock.mjs"), "run-issue", String(issue), "--lane", lane, "--result-file", rf], { cwd, env: lane, stdio: "ignore" });
|
|
390
392
|
const timer = setTimeout(() => child.kill("SIGTERM"), LANE_MS);
|
|
391
393
|
const done = () => { clearTimeout(timer); let r = null; try { r = JSON.parse(readFileSync(rf, "utf8")); } catch { /* no result */ } rmSync(dir, { recursive: true, force: true }); resolve(r); };
|
|
392
394
|
child.on("error", done); child.on("exit", done);
|