forgedock 1.54.1 → 1.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/engine/events.mjs +1 -0
- package/bin/engine/events.test.mjs +5 -1
- package/bin/engine/outcome-codes.mjs +3 -0
- package/bin/engine-cli.mjs +126 -34
- package/bin/forgedock.mjs +54 -2
- package/bin/gc-schedule.mjs +83 -0
- package/bin/gc.mjs +56 -8
- package/bin/help-text.mjs +1 -1
- package/bin/hooks/pre-tool-use.mjs +1 -0
- package/bin/init-detect.mjs +73 -2
- package/bin/labels.json +5 -0
- package/bin/lean/admission.mjs +21 -1
- package/bin/lean/baselines.mjs +43 -0
- package/bin/lean/baselines.test.mjs +33 -0
- package/bin/lean/batch-health.mjs +43 -6
- package/bin/lean/batch-health.test.mjs +41 -1
- package/bin/lean/batch.mjs +41 -4
- package/bin/lean/batch.test.mjs +106 -3
- package/bin/lean/conformance.mjs +131 -12
- package/bin/lean/conformance.test.mjs +172 -3
- package/bin/lean/depcache.mjs +23 -2
- package/bin/lean/depcache.test.mjs +22 -0
- package/bin/lean/docsgate.mjs +137 -0
- package/bin/lean/docsgate.test.mjs +78 -0
- package/bin/lean/effects.mjs +31 -2
- package/bin/lean/enumerating.mjs +39 -13
- package/bin/lean/enumerating.test.mjs +20 -0
- package/bin/lean/execution.test.mjs +3 -3
- package/bin/lean/fastforward.mjs +93 -0
- package/bin/lean/fastforward.test.mjs +73 -0
- package/bin/lean/guardgate.mjs +38 -7
- package/bin/lean/guardgate.test.mjs +39 -0
- package/bin/lean/issuewatch-install.mjs +92 -0
- package/bin/lean/issuewatch-install.test.mjs +31 -0
- package/bin/lean/issuewatch-parity.mjs +33 -3
- package/bin/lean/issuewatch-parity.test.mjs +30 -5
- package/bin/lean/issuewatch-reconcile.mjs +123 -0
- package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
- package/bin/lean/issuewatch-verify.mjs +51 -9
- package/bin/lean/issuewatch.mjs +153 -33
- package/bin/lean/issuewatch.test.mjs +243 -22
- package/bin/lean/lean.mjs +381 -75
- package/bin/lean/lean.test.mjs +437 -20
- package/bin/lean/light.mjs +11 -3
- package/bin/lean/light.test.mjs +27 -0
- package/bin/lean/lightlane.mjs +8 -3
- package/bin/lean/lightlane.test.mjs +20 -0
- package/bin/lean/mechfix.mjs +21 -2
- package/bin/lean/mechfix.test.mjs +28 -1
- package/bin/lean/orchestrate-children.test.mjs +10 -0
- package/bin/lean/orchestrate-owned.test.mjs +73 -0
- package/bin/lean/orchestrate.mjs +28 -4
- package/bin/lean/overlap.mjs +20 -0
- package/bin/lean/overlap.test.mjs +49 -0
- package/bin/lean/pagegate.mjs +152 -0
- package/bin/lean/pagegate.test.mjs +77 -0
- package/bin/lean/parked-relabel.mjs +32 -0
- package/bin/lean/parked-relabel.test.mjs +45 -0
- package/bin/lean/phaseledger.mjs +17 -2
- package/bin/lean/postdeploy-check.mjs +27 -0
- package/bin/lean/postdeploy-check.test.mjs +13 -1
- package/bin/lean/postrun.mjs +32 -0
- package/bin/lean/postrun.test.mjs +41 -0
- package/bin/lean/preflight.mjs +46 -0
- package/bin/lean/preflight.test.mjs +30 -1
- package/bin/lean/prompts.mjs +36 -6
- package/bin/lean/recovery.test.mjs +16 -0
- package/bin/lean/release.mjs +23 -2
- package/bin/lean/release.test.mjs +28 -1
- package/bin/lean/render.mjs +17 -6
- package/bin/lean/reproquality.mjs +116 -0
- package/bin/lean/reproquality.test.mjs +85 -0
- package/bin/lean/review-trigger.mjs +8 -3
- package/bin/lean/sandbox-budget.test.mjs +27 -0
- package/bin/lean/schedd.mjs +40 -11
- package/bin/lean/schedd.test.mjs +12 -1
- package/bin/lean/testadequacy.mjs +97 -0
- package/bin/lean/testadequacy.test.mjs +92 -0
- package/bin/lean/testsandbox.mjs +202 -0
- package/bin/lean/testsandbox.test.mjs +157 -0
- package/bin/lean/toolplace.mjs +5 -2
- package/bin/lean/toolplace.test.mjs +6 -0
- package/bin/lean/verify.mjs +6 -1
- package/bin/lean/verify.test.mjs +18 -2
- package/bin/lean/warmtree.mjs +77 -0
- package/bin/lean/warmtree.test.mjs +81 -0
- package/bin/stats/conformance-outcomes.mjs +12 -2
- package/bin/stats/depth.mjs +24 -1
- package/bin/stats/depth.test.mjs +21 -1
- package/bin/stats/index.mjs +5 -2
- package/bin/stats/query.mjs +2 -1
- package/commands/cleanup.md +18 -0
- package/commands/fd-introspect.md +19 -0
- package/commands/milestone.md +5 -1
- package/commands/pipeline-health/phase-2-metrics.md +4 -0
- package/commands/recover-orphans.md +31 -1
- package/commands/review-pr-staging.md +9 -0
- package/commands/review-pr.md +2 -0
- package/docs/CONFIG.md +26 -1
- package/docs/EVENTS.md +1 -0
- package/docs/ISSUE-WATCH.md +12 -3
- package/docs/eval/adversarial-bench.md +1 -1
- package/docs/eval/published/adversarial-2026-11-11.md +58 -0
- package/package.json +1 -1
- package/scripts/bench-lightlane.mjs +3 -2
- package/scripts/hotspots.sh +7 -4
- package/scripts/hotspots.test.sh +12 -0
- package/scripts/recover-orphans-stateless.test.sh +79 -0
- package/scripts/transition-label.sh +2 -0
- package/templates/workflows/forgedock-reopen-clean.yml +33 -0
|
@@ -6,7 +6,7 @@ import { mkdirSync, writeFileSync, readFileSync, utimesSync } from "node:fs";
|
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
8
|
import { loadWatches, validateWatch, planClaims, tick, runWatch, formatStatus, formatClaimPlan } from "./issuewatch.mjs";
|
|
9
|
-
import { isPullRequest, closingPrIssues, releaseInFlight, watchLiveness, DEFAULT_SKIP_LABELS } from "./issuewatch-parity.mjs";
|
|
9
|
+
import { isPullRequest, closingPrIssues, releaseInFlight, watchLiveness, listWatches, alertDeadWatches, DEFAULT_SKIP_LABELS } from "./issuewatch-parity.mjs";
|
|
10
10
|
|
|
11
11
|
const NOW = Date.parse("2026-11-10T12:00:00Z");
|
|
12
12
|
const iss = (n, o = {}) => ({ number: n, title: `t${n}`, body: "", labels: [], milestone: null, author: { login: "me" }, createdAt: "2026-11-09T00:00:00Z", ...o });
|
|
@@ -86,17 +86,18 @@ test("#5313 a release in flight pauses the watch (no claims), the next pass resu
|
|
|
86
86
|
writeFileSync(join(env, "releases", "r20261110-110000-9", "state.json"), JSON.stringify({ repo: "o/r", status: "done", steps: {} })); // the job ends
|
|
87
87
|
s = await pass();
|
|
88
88
|
assert.equal(s.paused, null); assert.deepEqual(io.batchOps[0], ["start", [1]]);
|
|
89
|
-
assert.match(formatStatus(s, watch, io.now()), /state:
|
|
89
|
+
assert.match(formatStatus(s, watch, io.now()), /state: exited \(single pass/);
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
test("#5313 watchLiveness: a fresh heartbeat runs, an old one is
|
|
92
|
+
test("#5313 watchLiveness: a fresh heartbeat runs, an old one is dead, a finished watch is done", () => {
|
|
93
93
|
const beat = (ms) => new Date(NOW - ms).toISOString();
|
|
94
94
|
assert.equal(watchLiveness({ phase: "running", heartbeat: beat(1000), heartbeatEveryMs: 300000 }, NOW).state, "running");
|
|
95
|
-
assert.equal(watchLiveness({ phase: "running", heartbeat: beat(3600000), heartbeatEveryMs: 300000 }, NOW).state, "
|
|
95
|
+
assert.equal(watchLiveness({ phase: "running", heartbeat: beat(3600000), heartbeatEveryMs: 300000 }, NOW).state, "dead");
|
|
96
96
|
assert.equal(watchLiveness({ phase: "running", heartbeat: beat(1000), paused: { reason: "release r1 in flight" } }, NOW).state, "paused");
|
|
97
97
|
assert.equal(watchLiveness({ phase: "done", heartbeat: beat(9e9) }, NOW).state, "done");
|
|
98
98
|
assert.equal(watchLiveness(null, NOW).state, "unknown");
|
|
99
|
-
assert.match(formatStatus({ ...state(), heartbeat: beat(3600000), heartbeatEveryMs: 300000 }, validateWatch("w", {}), NOW), /state:
|
|
99
|
+
assert.match(formatStatus({ ...state(), heartbeat: beat(3600000), heartbeatEveryMs: 300000 }, validateWatch("w", {}), NOW), /state: DEAD/);
|
|
100
|
+
assert.equal(watchLiveness({ phase: "exited", exitReason: "crashed: x", heartbeat: beat(1000) }, NOW).state, "exited");
|
|
100
101
|
});
|
|
101
102
|
|
|
102
103
|
test("#5313 a batch that reported between the settle check and the add is never added to: a new batch starts", async () => {
|
|
@@ -125,3 +126,27 @@ test("#5313 the follow-up rules and skip reasons show in the --dry-run plan: def
|
|
|
125
126
|
assert.match(out, /skip #3: skip label epic/);
|
|
126
127
|
assert.match(out, /skip #4: pull request/);
|
|
127
128
|
});
|
|
129
|
+
|
|
130
|
+
test("#5442 a design:needed issue is skipped with design_pending, whatever skip_labels says; design:approved lifts it", async () => {
|
|
131
|
+
const io = bind(fakeIo(tmpDir("iwp-"), [iss(1), iss(2, { labels: lbl("design:needed") }), iss(3, { labels: lbl("design:needed", "design:approved") })]));
|
|
132
|
+
for (const cfg of [{}, { mode: "batch" }, { mode: "batch", skip_labels: [] }]) {
|
|
133
|
+
const plan = await planClaims({ watch: validateWatch("w", cfg), repo: "o/r", io, state: state() });
|
|
134
|
+
assert.deepEqual(plan.claim.map((c) => c.number).sort(), [1, 3]);
|
|
135
|
+
assert.ok(plan.skip.some((s) => s.number === 2 && /^design_pending/.test(s.reason)));
|
|
136
|
+
assert.match(formatClaimPlan(plan), /skip #2: design_pending/);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("#5465 a killed watch shows DEAD within 3 heartbeats and the watchdog alerts once per dead heartbeat", async () => {
|
|
141
|
+
const root = tmpDir("iw-"), now = Date.parse("2026-11-11T14:00:00Z"), dir = join(root, "o__r", "w");
|
|
142
|
+
mkdirSync(dir, { recursive: true });
|
|
143
|
+
const beat = (ms) => new Date(now - ms).toISOString();
|
|
144
|
+
writeFileSync(join(dir, "status.json"), JSON.stringify({ ...state(), heartbeat: beat(3 * 300000 + 120000), heartbeatEveryMs: 300000 }));
|
|
145
|
+
const sent = [], emit = async (type, data) => { sent.push([type, data]); };
|
|
146
|
+
assert.equal(listWatches(root, now)[0].live.state, "dead");
|
|
147
|
+
assert.equal((await alertDeadWatches({ root, now, emit })).length, 1);
|
|
148
|
+
await alertDeadWatches({ root, now, emit });
|
|
149
|
+
assert.equal(sent.length, 1); assert.equal(sent[0][0], "watch.dead"); assert.equal(sent[0][1].watch, "w");
|
|
150
|
+
writeFileSync(join(dir, "status.json"), JSON.stringify({ ...state(), heartbeat: beat(1000), heartbeatEveryMs: 300000 }));
|
|
151
|
+
assert.equal((await alertDeadWatches({ root, now, emit })).length, 0);
|
|
152
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #5467: reconcile an issue-watch's claims with the batch result and the issue labels. Each claim is `merged | needs-human(code) |
|
|
5
|
+
* parked(code) | running | stranded`. A final batch result leaves `inflight` at once (a long-lived batch that has not reported must not
|
|
6
|
+
* keep it for hours); a mechanical park (`needs-human` row with a terminal code) gets one budgeted `run-issue --recover` lane, and only
|
|
7
|
+
* when that fails becomes `needs-human` with the reason stated; a needs-human/parked claim a person cleared (label gone, plus a trusted
|
|
8
|
+
* FORGE:DECISION or a newer comment) is released so the next pass re-claims it. `status --stuck` lists the old claims. Gh, the clock and the
|
|
9
|
+
* lane launch are injected; the state callbacks (`fail`, `settle`, `release`) belong to the caller.
|
|
10
|
+
*/
|
|
11
|
+
import { classifyNeedsHuman, REMEDIATION_QUEUE_LABEL } from "../engine/outcome-codes.mjs";
|
|
12
|
+
|
|
13
|
+
const HOUR_MS = 3600_000;
|
|
14
|
+
const MERGED = new Set(["merged", "done", "complete", "completed", "closed"]);
|
|
15
|
+
const NEEDS_HUMAN_LABEL = "needs-human";
|
|
16
|
+
export const STUCK_HOURS = 24;
|
|
17
|
+
|
|
18
|
+
/** `{kind, code}` for one batch result row; `running` when there is no final row. Pure. */
|
|
19
|
+
export function classifyClaim(row) {
|
|
20
|
+
if (!row || typeof row !== "object") return { kind: "running", code: null };
|
|
21
|
+
const outcome = String(row.outcome ?? row.terminalReason ?? "");
|
|
22
|
+
if (MERGED.has(outcome)) return { kind: "merged", code: null };
|
|
23
|
+
if (outcome === "needs-human") {
|
|
24
|
+
const code = typeof row.code === "string" && row.code !== "" ? row.code : null;
|
|
25
|
+
// a code a person must settle (HUMAN_CODES) stays needs-human; any other code is a mechanical park the engine's own lanes already gave up on
|
|
26
|
+
return code && classifyNeedsHuman(row) !== "human" && code !== "unclassified" ? { kind: "parked", code } : { kind: "needs-human", code };
|
|
27
|
+
}
|
|
28
|
+
if (outcome === "" || outcome === "pending" || outcome === "running") return { kind: "running", code: null };
|
|
29
|
+
return { kind: "stranded", code: outcome };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Settle every inflight claim whose batch result is final. `results` is state.json `results` of the watch's batch. Merged claims go to
|
|
34
|
+
* `settle` (verified once closed), the rest to `fail`; `state.outcomes[n]` keeps the classification. @returns {number[]} the issues settled.
|
|
35
|
+
*/
|
|
36
|
+
export function reconcileClaims({ state, results, now, fail, settle }) {
|
|
37
|
+
state.outcomes ??= {};
|
|
38
|
+
const done = [];
|
|
39
|
+
for (const n of [...state.inflight]) {
|
|
40
|
+
const c = classifyClaim(results?.[n]);
|
|
41
|
+
if (c.kind === "running") continue;
|
|
42
|
+
state.outcomes[n] = { ...c, at: now };
|
|
43
|
+
(c.kind === "merged" ? settle : fail)(n);
|
|
44
|
+
done.push(n);
|
|
45
|
+
}
|
|
46
|
+
return done;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const labelsOf = (v) => (v?.labels ?? []).map((l) => String(l?.name ?? l));
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* One remediation lane per parked claim, at most `watch.max_remediations` per watch. A launched lane is polled each pass: exit 0 hands
|
|
53
|
+
* the issue to verification, any other exit makes it `needs-human` with the reason in a comment. A restarted watch re-launches a
|
|
54
|
+
* running lane (run-issue resumes from GitHub) without spending budget again.
|
|
55
|
+
*/
|
|
56
|
+
export async function remediateStep({ watch, repo, io, state, handles, lanes = {}, now, settle, fail }) {
|
|
57
|
+
if (!io.remediate) return;
|
|
58
|
+
state.remediated ??= {};
|
|
59
|
+
const key = (n) => `remediate:${n}`;
|
|
60
|
+
for (const [n, o] of Object.entries(state.outcomes ?? {})) {
|
|
61
|
+
if (o.kind !== "parked" || state.remediated[n]) continue;
|
|
62
|
+
if (Object.keys(state.remediated).length >= (watch.max_remediations ?? 10)) break;
|
|
63
|
+
state.remediated[n] = { code: o.code, at: now, status: "running" };
|
|
64
|
+
handles.set(key(n), io.remediate(Number(n), state.lanes?.[n] ?? lanes[n], o.code));
|
|
65
|
+
}
|
|
66
|
+
for (const [n, r] of Object.entries(state.remediated)) {
|
|
67
|
+
if (r.status !== "running") continue;
|
|
68
|
+
let h = handles.get(key(n));
|
|
69
|
+
if (!h) { handles.set(key(n), io.remediate(Number(n), state.lanes?.[n] ?? lanes[n], r.code)); continue; }
|
|
70
|
+
const res = h.poll();
|
|
71
|
+
if (!res) continue;
|
|
72
|
+
handles.delete(key(n));
|
|
73
|
+
if (res.code === 0) { r.status = "done"; settle(Number(n)); continue; }
|
|
74
|
+
r.status = "failed";
|
|
75
|
+
const reason = `remediation lane for \`${r.code}\` exited ${res.code}`;
|
|
76
|
+
state.outcomes[n] = { kind: "needs-human", code: r.code, at: now, reason };
|
|
77
|
+
try {
|
|
78
|
+
await io.gh(["issue", "edit", String(n), "-R", repo, "--add-label", NEEDS_HUMAN_LABEL, "--remove-label", REMEDIATION_QUEUE_LABEL]);
|
|
79
|
+
await io.gh(["issue", "comment", String(n), "-R", repo, "--body", `## Needs human\nissue-watch ${watch.name} remediated this parked issue once (${reason}); a person has to take it from here.`]);
|
|
80
|
+
} catch { /* the label/comment retry is the next human pass; the state already records the reason */ }
|
|
81
|
+
fail(Number(n));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A needs-human/parked claim whose block a person cleared (no `needs-human`/`parked:*` label, a trusted FORGE:DECISION or a comment newer
|
|
87
|
+
* than the outcome) is released through `release(n)` so the next pass selects it again. A claim under remediation is left alone.
|
|
88
|
+
* @returns {number[]} the issues released.
|
|
89
|
+
*/
|
|
90
|
+
export async function reclaimStep({ repo, io, state, trusted, release }) {
|
|
91
|
+
const out = [];
|
|
92
|
+
for (const [n, o] of Object.entries(state.outcomes ?? {})) {
|
|
93
|
+
if (!["needs-human", "parked"].includes(o.kind) || state.remediated?.[n]?.status === "running") continue;
|
|
94
|
+
let v;
|
|
95
|
+
try { v = JSON.parse(String(await io.gh(["issue", "view", n, "-R", repo, "--json", "state,labels,comments"]))); } catch { continue; }
|
|
96
|
+
if (v.state === "CLOSED" || labelsOf(v).some((l) => l === NEEDS_HUMAN_LABEL || l.startsWith("parked:"))) continue;
|
|
97
|
+
const cleared = (v.comments ?? []).some((c) => trusted(c) && (/FORGE:DECISION/.test(String(c.body ?? "")) || Date.parse(c.createdAt) > o.at));
|
|
98
|
+
if (!cleared) continue;
|
|
99
|
+
release(Number(n));
|
|
100
|
+
delete state.outcomes[n]; delete state.remediated?.[n];
|
|
101
|
+
out.push(Number(n));
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Counts of the claims by reconciled kind: `{merged, "needs-human", parked, running, stranded}`. */
|
|
107
|
+
export function claimCounts(state) {
|
|
108
|
+
const c = { merged: (state.merged ?? []).length, "needs-human": 0, parked: 0, running: (state.inflight ?? []).length, stranded: 0 };
|
|
109
|
+
for (const o of Object.values(state.outcomes ?? {})) if (o.kind in c && o.kind !== "merged" && o.kind !== "running") c[o.kind]++;
|
|
110
|
+
return c;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** `[{issue, ageHours, why}]` of claims older than `hours` with no merged issue, oldest first. */
|
|
114
|
+
export function stuckClaims(state, now, hours = STUCK_HOURS) {
|
|
115
|
+
const merged = new Set([...(state.merged ?? []), ...(state.verified ?? [])]);
|
|
116
|
+
return (state.claimed ?? []).filter((n) => !merged.has(n)).map((n) => {
|
|
117
|
+
const at = state.claimedAt?.[n] ?? state.started ?? now, o = state.outcomes?.[n], r = state.remediated?.[n];
|
|
118
|
+
const why = o ? `${o.kind}${o.code ? ` (${o.code})` : ""}${o.reason ? `: ${o.reason}` : ""}${r ? `; remediation ${r.status}` : ""}` : state.inflight?.includes(n) ? "running in its lane" : "no batch result";
|
|
119
|
+
return { issue: n, ageHours: Math.floor((now - at) / HOUR_MS), why };
|
|
120
|
+
}).filter((r) => r.ageHours >= hours).sort((a, b) => b.ageHours - a.ageHours);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export const formatStuck = (rows, hours = STUCK_HOURS) => rows.length ? rows.map((r) => `#${r.issue} claimed ${r.ageHours}h ago, no merged PR: ${r.why}`).join("\n") : `no claims older than ${hours}h without a merged PR`;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { test } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { classifyClaim, reconcileClaims, claimCounts, stuckClaims, formatStuck } from "./issuewatch-reconcile.mjs";
|
|
6
|
+
|
|
7
|
+
test("classifyClaim: merged, parked (terminal code), needs-human, running, stranded", () => {
|
|
8
|
+
assert.deepEqual(classifyClaim({ outcome: "merged" }), { kind: "merged", code: null });
|
|
9
|
+
assert.deepEqual(classifyClaim({ outcome: "needs-human", code: "conformance.unimplemented" }), { kind: "parked", code: "conformance.unimplemented" });
|
|
10
|
+
assert.equal(classifyClaim({ outcome: "needs-human" }).kind, "needs-human");
|
|
11
|
+
assert.equal(classifyClaim(undefined).kind, "running");
|
|
12
|
+
assert.deepEqual(classifyClaim({ outcome: "engine-error" }), { kind: "stranded", code: "engine-error" });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("reconcileClaims settles merged, fails the rest, leaves running claims inflight", () => {
|
|
16
|
+
const state = { inflight: [1, 2, 3], merged: [] };
|
|
17
|
+
const settled = [], failed = [];
|
|
18
|
+
const done = reconcileClaims({ state, results: { 1: { outcome: "merged" }, 2: { outcome: "needs-human", code: "ci.red" } }, now: 5, fail: (n) => failed.push(n), settle: (n) => settled.push(n) });
|
|
19
|
+
assert.deepEqual(done, [1, 2]); assert.deepEqual(settled, [1]); assert.deepEqual(failed, [2]);
|
|
20
|
+
assert.equal(state.outcomes[2].kind, "parked");
|
|
21
|
+
assert.equal(claimCounts({ ...state, inflight: [3] }).parked, 1);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("stuckClaims lists only old unmerged claims with the reason", () => {
|
|
25
|
+
const now = 100 * 3600_000;
|
|
26
|
+
const s = { claimed: [1, 2, 3], merged: [3], inflight: [1], claimedAt: { 1: 0, 2: 99 * 3600_000, 3: 0 }, outcomes: {} };
|
|
27
|
+
const rows = stuckClaims(s, now, 24);
|
|
28
|
+
assert.deepEqual(rows.map((r) => r.issue), [1]);
|
|
29
|
+
assert.match(formatStuck(rows), /#1 claimed 100h ago, no merged PR: running in its lane/);
|
|
30
|
+
});
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
* Merge verification for `forgedock issue-watch`: an issue the watch claimed counts as verified only when its result
|
|
5
5
|
* checks out after it closed, not because it closed. Checks, in order: a PR from `feat/issue-<n>-lean` merged into the
|
|
6
6
|
* issue's lane; the PR does not carry `review-degraded`; the issue's latest trusted FORGE:REVIEW passed (enforced
|
|
7
|
-
* `CONFORMS`, shadow `would PASS`, or a `review.trigger` skip;
|
|
7
|
+
* `CONFORMS`, shadow `would PASS`, or a `review.trigger` skip; an enforced NONCONFORMING/BLOCK/FAIL fails; a shadow
|
|
8
|
+
* `would BLOCK` is advisory, as its label says: the lane merges by design, so it is recorded in the evidence, not reopened); every required check of the
|
|
8
9
|
* lane is green on the merged head; the merge commit is on the lane; no check on the merge commit failed
|
|
9
|
-
* (`forgedock/verify` is report-only
|
|
10
|
+
* (`forgedock/verify` is report-only; a `cancelled`/`stale` check, superseded by a newer run, is resolved against the newest
|
|
11
|
+
* descendant run of the same check on the lane). A failure reopens the issue with `needs-human` and the evidence; nothing is
|
|
10
12
|
* reverted, a human decides. No LLM calls.
|
|
11
13
|
*/
|
|
12
14
|
import { isTrustedIssueComment } from "./prefilter.mjs";
|
|
@@ -14,6 +16,8 @@ import { requiredChecksFor } from "./effects.mjs";
|
|
|
14
16
|
|
|
15
17
|
export const VERIFY_MARKER = "FORGE:WATCH_VERIFY";
|
|
16
18
|
const OK_STATES = new Set(["success", "neutral", "skipped"]);
|
|
19
|
+
const SUPERSEDED_STATES = new Set(["cancelled", "stale"]);
|
|
20
|
+
const DESCENDANTS_READ = 10;
|
|
17
21
|
const REPORT_ONLY_CHECKS = new Set(["forgedock/verify"]);
|
|
18
22
|
const labelNames = (x) => new Set((x?.labels ?? []).map((l) => (typeof l === "string" ? l : l?.name)).filter(Boolean));
|
|
19
23
|
|
|
@@ -38,11 +42,39 @@ export async function checkStates({ gh, repo, sha }) {
|
|
|
38
42
|
return [...runs.values()].map(({ name, state }) => ({ name, state }));
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Settle superseded (`cancelled`/`stale`) checks of `sha` against the lane's newer commits: per check name the newest
|
|
47
|
+
* descendant that ran it decides. Returns `{green: [evidence], red: [name=state@sha], pending: [name]}`; a name no descendant
|
|
48
|
+
* has run yet is pending. Unreadable descendants = none.
|
|
49
|
+
*/
|
|
50
|
+
async function resolveSuperseded({ gh, repo, lane, sha, names }) {
|
|
51
|
+
const out = { green: [], red: [], pending: [] };
|
|
52
|
+
if (!names.length) return out;
|
|
53
|
+
let desc = [];
|
|
54
|
+
try { desc = String(await gh(["api", `repos/${repo}/compare/${sha}...${lane}`, "--jq", ".commits[].sha"])).split("\n").map((x) => x.trim()).filter(Boolean).reverse().slice(0, DESCENDANTS_READ); } catch { desc = []; }
|
|
55
|
+
const open = new Set(names);
|
|
56
|
+
for (const d of desc) {
|
|
57
|
+
if (!open.size) break;
|
|
58
|
+
const at = await checkStates({ gh, repo, sha: d });
|
|
59
|
+
for (const n of [...open]) {
|
|
60
|
+
const x = at.find((c) => c.name === n);
|
|
61
|
+
if (!x || SUPERSEDED_STATES.has(x.state)) continue;
|
|
62
|
+
open.delete(n);
|
|
63
|
+
if (OK_STATES.has(x.state)) out.green.push(`${n} superseded by a ${x.state} run on ${d.slice(0, 12)}`);
|
|
64
|
+
else if (x.state === "pending") out.pending.push(n);
|
|
65
|
+
else out.red.push(`${n}=${x.state} on ${d.slice(0, 12)}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
out.pending.push(...open);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The latest trusted FORGE:REVIEW's verdict: pass | shadow-block | block | null (no review record). An unrecognised verdict is a block. */
|
|
42
73
|
export function reviewVerdict(comments = []) {
|
|
43
74
|
const body = String(comments.filter((c) => isTrustedIssueComment(c) && /<!--\s*FORGE:REVIEW\b/.test(String(c?.body ?? ""))).at(-1)?.body ?? "");
|
|
44
75
|
if (!body) return null;
|
|
45
|
-
if (
|
|
76
|
+
if (/\*\*Verdict:\*\*\s*(?:NON-?CONFORM|BLOCK|FAIL)/i.test(body)) return "block";
|
|
77
|
+
if (/would BLOCK/i.test(body)) return "shadow-block";
|
|
46
78
|
if (/\*\*Verdict:\*\*\s*CONFORMS|would PASS|Skipped by `review\.trigger/.test(body)) return "pass";
|
|
47
79
|
return "block";
|
|
48
80
|
}
|
|
@@ -64,14 +96,21 @@ export async function verifyMerge({ gh, repo, lane, issue, comments, requiredChe
|
|
|
64
96
|
if (pr.baseRefName !== lane) return fail(`PR #${pr.number} targets ${pr.baseRefName}, not ${lane}`, { pr: pr.number });
|
|
65
97
|
if (labelNames(pr).has("review-degraded")) return fail(`PR #${pr.number} merged with an incomplete review (review-degraded)`, { pr: pr.number });
|
|
66
98
|
const verdict = reviewVerdict(comments);
|
|
67
|
-
if (verdict !== "pass") return fail(verdict === "block" ? "the latest FORGE:REVIEW did not pass (
|
|
68
|
-
ev.push("FORGE:REVIEW passed");
|
|
99
|
+
if (verdict !== "pass" && verdict !== "shadow-block") return fail(verdict === "block" ? "the latest FORGE:REVIEW did not pass (enforced NONCONFORMING)" : "no trusted FORGE:REVIEW on the issue", { pr: pr.number });
|
|
100
|
+
ev.push(verdict === "pass" ? "FORGE:REVIEW passed" : "FORGE:REVIEW shadow `would BLOCK` (advisory: shadow mode does not enforce; see the review comment)");
|
|
69
101
|
let required = [];
|
|
70
102
|
try { required = (await requiredChecks(lane)) ?? []; } catch { required = []; }
|
|
71
103
|
if (required.length && pr.headRefOid) {
|
|
72
104
|
const at = await checkStates({ gh, repo, sha: pr.headRefOid });
|
|
73
105
|
const stateOf = (n) => at.find((x) => x.name === n)?.state ?? "missing";
|
|
74
|
-
|
|
106
|
+
let bad = required.filter((n) => !OK_STATES.has(stateOf(n)));
|
|
107
|
+
const sup = bad.filter((n) => SUPERSEDED_STATES.has(stateOf(n)));
|
|
108
|
+
if (sup.length && sha) {
|
|
109
|
+
const r = await resolveSuperseded({ gh, repo, lane, sha, names: sup });
|
|
110
|
+
bad = bad.filter((n) => !sup.includes(n) || r.pending.includes(n) || r.red.some((x) => x.startsWith(`${n}=`)));
|
|
111
|
+
if (r.pending.length) return { status: "pending", evidence: [...ev, `required check(s) cancelled on the head, no newer ${lane} run finished: ${r.pending.join(", ")}`], pr: pr.number, sha };
|
|
112
|
+
ev.push(...r.green);
|
|
113
|
+
}
|
|
75
114
|
if (bad.length) return fail(`required check(s) not green on the merged head ${pr.headRefOid.slice(0, 12)}: ${bad.map((n) => `${n}=${stateOf(n)}`).join(", ")}`, { pr: pr.number });
|
|
76
115
|
ev.push(`required checks green on the head: ${required.join(", ")}`);
|
|
77
116
|
} else ev.push("no required checks on the lane");
|
|
@@ -82,9 +121,12 @@ export async function verifyMerge({ gh, repo, lane, issue, comments, requiredChe
|
|
|
82
121
|
if (rel !== "behind" && rel !== "identical") return fail(`merge commit ${sha.slice(0, 12)} is not on ${lane} (compare: ${rel})`, { pr: pr.number, sha });
|
|
83
122
|
ev.push(`merge commit is on ${lane}`);
|
|
84
123
|
const post = (await checkStates({ gh, repo, sha })).filter((x) => !REPORT_ONLY_CHECKS.has(x.name));
|
|
85
|
-
const red = post.filter((x) => !OK_STATES.has(x.state) && x.state !== "pending");
|
|
124
|
+
const red = post.filter((x) => !OK_STATES.has(x.state) && x.state !== "pending" && !SUPERSEDED_STATES.has(x.state));
|
|
86
125
|
if (red.length) return fail(`${lane} CI red on the merge commit: ${red.map((x) => `${x.name}=${x.state}`).join(", ")}`, { pr: pr.number, sha });
|
|
87
|
-
const
|
|
126
|
+
const sup = await resolveSuperseded({ gh, repo, lane, sha, names: post.filter((x) => SUPERSEDED_STATES.has(x.state)).map((x) => x.name) });
|
|
127
|
+
if (sup.red.length) return fail(`${lane} CI red: a cancelled check on the merge commit was superseded by a failing run: ${sup.red.join(", ")}`, { pr: pr.number, sha });
|
|
128
|
+
ev.push(...sup.green);
|
|
129
|
+
const pending = [...post.filter((x) => x.state === "pending"), ...sup.pending.map((name) => ({ name }))];
|
|
88
130
|
if (pending.length) return { status: "pending", evidence: [...ev, `${lane} CI pending: ${pending.map((x) => x.name).join(", ")}`], pr: pr.number, sha };
|
|
89
131
|
ev.push(post.length ? `${lane} CI green on the merge commit (${post.length} check(s))` : "no CI ran on the merge commit");
|
|
90
132
|
return { status: "verified", evidence: ev, pr: pr.number, sha };
|