forgedock 1.56.0 → 1.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/config-schema.mjs +1 -1
- package/bin/engine/outcome-codes.mjs +2 -1
- package/bin/engine/phases.mjs +4 -3
- package/bin/engine-cli.mjs +48 -12
- package/bin/forgedock.mjs +52 -3
- package/bin/gc.mjs +43 -6
- package/bin/help-text.mjs +4 -2
- package/bin/lean/batch-health.mjs +5 -1
- package/bin/lean/batch-health.test.mjs +7 -1
- package/bin/lean/batch.mjs +7 -2
- package/bin/lean/batch.test.mjs +45 -0
- package/bin/lean/conformance.e2e.test.mjs +3 -2
- package/bin/lean/conformance.mjs +118 -20
- package/bin/lean/conformance.test.mjs +172 -3
- package/bin/lean/decisions.mjs +98 -1
- package/bin/lean/decisions.test.mjs +30 -1
- package/bin/lean/depcache.mjs +124 -13
- package/bin/lean/depcache.test.mjs +121 -3
- package/bin/lean/design-gate.mjs +144 -0
- package/bin/lean/design-gate.test.mjs +169 -0
- package/bin/lean/effects-cap.test.mjs +17 -0
- package/bin/lean/effects.mjs +58 -13
- package/bin/lean/heavy.mjs +25 -8
- package/bin/lean/hostload.test.mjs +28 -0
- package/bin/lean/intake.mjs +97 -0
- package/bin/lean/intake.test.mjs +105 -0
- package/bin/lean/interfaces.mjs +181 -0
- package/bin/lean/interfaces.test.mjs +192 -0
- package/bin/lean/issuewatch-install.mjs +52 -12
- package/bin/lean/issuewatch-install.test.mjs +50 -0
- package/bin/lean/issuewatch-parity.mjs +16 -3
- package/bin/lean/issuewatch-parity.test.mjs +32 -0
- package/bin/lean/issuewatch-reconcile.mjs +29 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +21 -0
- package/bin/lean/issuewatch.mjs +34 -3
- package/bin/lean/issuewatch.test.mjs +49 -1
- package/bin/lean/lanecheck.test.mjs +15 -4
- package/bin/lean/lean.mjs +110 -24
- package/bin/lean/lean.test.mjs +183 -4
- package/bin/lean/orchestrate-blocked.test.mjs +18 -2
- package/bin/lean/orchestrate-owned.test.mjs +14 -5
- package/bin/lean/orchestrate.mjs +26 -4
- package/bin/lean/orphan-pr.mjs +3 -2
- package/bin/lean/orphan-pr.test.mjs +8 -1
- package/bin/lean/pagegate.mjs +35 -12
- package/bin/lean/pagegate.test.mjs +39 -1
- package/bin/lean/preflight.mjs +35 -1
- package/bin/lean/preflight.test.mjs +27 -1
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/reap.test.mjs +39 -0
- package/bin/lean/recovery.test.mjs +28 -3
- package/bin/lean/release-config.mjs +169 -0
- package/bin/lean/release-config.test.mjs +132 -0
- package/bin/lean/release-control.mjs +171 -0
- package/bin/lean/release-control.test.mjs +167 -0
- package/bin/lean/release-deploy.mjs +209 -0
- package/bin/lean/release-deploy.test.mjs +217 -0
- package/bin/lean/release-fence.mjs +50 -0
- package/bin/lean/release-fence.test.mjs +105 -0
- package/bin/lean/release-flakes.mjs +139 -0
- package/bin/lean/release-flakes.test.mjs +116 -0
- package/bin/lean/release-gates.mjs +230 -0
- package/bin/lean/release-gates.test.mjs +146 -0
- package/bin/lean/release-ledger.mjs +176 -0
- package/bin/lean/release-ledger.test.mjs +226 -0
- package/bin/lean/release-minutes.mjs +102 -0
- package/bin/lean/release-minutes.test.mjs +107 -0
- package/bin/lean/release-nightly.mjs +75 -0
- package/bin/lean/release-nightly.test.mjs +48 -0
- package/bin/lean/release-postmerge.mjs +8 -2
- package/bin/lean/release-review.e2e.test.mjs +1 -0
- package/bin/lean/release-review.mjs +54 -7
- package/bin/lean/release-review.test.mjs +76 -7
- package/bin/lean/release-status.mjs +300 -0
- package/bin/lean/release-status.test.mjs +220 -0
- package/bin/lean/release-unitmap.mjs +35 -0
- package/bin/lean/release-unitmap.test.mjs +41 -0
- package/bin/lean/release-verify.mjs +221 -0
- package/bin/lean/release-verify.test.mjs +176 -0
- package/bin/lean/release.mjs +244 -22
- package/bin/lean/release.test.mjs +44 -0
- package/bin/lean/render.mjs +3 -1
- package/bin/lean/run-issue-placement.test.mjs +82 -0
- package/bin/lean/sandbox-remote.mjs +16 -0
- package/bin/lean/schedd.mjs +1 -1
- package/bin/lean/seam.mjs +115 -0
- package/bin/lean/seam.test.mjs +118 -0
- package/bin/lean/selftest-journey.mjs +40 -2
- package/bin/lean/selftest-journey.test.mjs +43 -3
- package/bin/lean/statuscomment.mjs +168 -0
- package/bin/lean/statuscomment.test.mjs +133 -0
- package/bin/lean/ui-quality.mjs +57 -0
- package/bin/lean/ui-quality.test.mjs +55 -0
- package/bin/lean/visual-gate.test.mjs +63 -0
- package/bin/pool/agent.mjs +16 -2
- package/bin/pool/router.mjs +5 -1
- package/bin/review-staging.mjs +5 -3
- package/bin/stats/card.mjs +117 -0
- package/bin/stats/card.test.mjs +109 -0
- package/bin/stats/conformance-outcomes.test.mjs +2 -1
- package/bin/stats/depth.mjs +1 -1
- package/bin/stats/gh-retry.test.mjs +152 -0
- package/bin/stats/github-source.mjs +147 -14
- package/bin/stats/index.mjs +35 -2
- package/bin/stats/stats.test.mjs +31 -3
- package/bin/vendor/js-yaml/LICENSE +21 -0
- package/bin/vendor/js-yaml/PIN.md +7 -0
- package/bin/vendor/js-yaml/js-yaml.mjs +3851 -0
- package/commands/design-render-critique-loop.md +2 -0
- package/commands/design.md +2 -0
- package/commands/issue.md +1 -1
- package/commands/milestone.md +1 -1
- package/commands/review-pr-agents/frontend.md +1 -0
- package/commands/review-pr-staging.md +5 -0
- package/docs/CONFIG.md +95 -2
- package/docs/ISSUE-WATCH.md +7 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +10 -0
- package/docs/design/visual-gate.md +25 -0
- package/docs/eval/adversarial-bench.md +2 -2
- package/docs/eval/corpus/adversarial-v1.json +3 -3
- package/docs/site/start-a-new-project.md +7 -0
- package/docs/spec/forge-protocol-v1.md +31 -0
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/scripts/acceptance-red-green.sh +15 -1
- package/scripts/acceptance-red-green.test.sh +12 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +4 -1
- package/scripts/bootstrap-create.mjs +8 -2
- package/scripts/ci-local/scoping.mjs +19 -0
- package/scripts/ci-local.test.sh +16 -3
- package/scripts/fixtures/ci-local/gha-dorny/.github/workflows/ci.yml +4 -0
- package/scripts/plan-validate-live.mjs +9 -6
- package/scripts/review-prepare.sh +7 -1
- package/scripts/review-roster.sh +5 -2
- package/scripts/review-roster.test.sh +9 -0
- package/scripts/visual-gate.mjs +64 -0
- package/templates/bootstrap/technical-spike.md +17 -0
- package/templates/contracts/seam-check.mjs +236 -0
|
@@ -10,7 +10,7 @@
|
|
|
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 } from "node:os";
|
|
13
|
+
import { tmpdir, homedir } 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";
|
|
@@ -68,6 +68,41 @@ const sessionFailure = (e) => {
|
|
|
68
68
|
const failureNote = (failures) => (failures.size ? `; session failures: ${[...failures].map(([d, f]) => `${d} (${f})`).join("; ")}` : "");
|
|
69
69
|
const headMoved = (lines) => /head moved since/.test((lines ?? []).join("\n"));
|
|
70
70
|
|
|
71
|
+
/** #5516: commands/test-gate.md missing-config guard output, verbatim markers (consumed by review-staging-post.sh test-gate). */
|
|
72
|
+
export const TEST_GATE_SKIP_NO_TESTS = "ADVISORY: verification.integration_tests is not configured in forge.yaml.\nNo tests to run. Emitting SKIP verdict.\n<!-- FORGE:TEST_GATE:SKIP|reason=no-tests-configured -->\n<!-- FORGE:TEST_GATE:RESULT=SKIP -->\n";
|
|
73
|
+
/** #5516: the gate session's prompt names the exact Skill to invoke (prefixed on a plugin install). */
|
|
74
|
+
export const testGatePrompt = (skill, bundle, def) =>
|
|
75
|
+
`Invoke the Skill "${skill}" with args: --prs "${(bundle ?? []).join(" ")}" --base ${def}\n\nPrint the complete gate output, ending with its FORGE:TEST_GATE:RESULT= marker. If the Skill cannot be invoked, say so and print no marker.`;
|
|
76
|
+
/** #5516: count of `verification.integration_tests` entries in forge.yaml text; null when it cannot be read (the gate session then runs). */
|
|
77
|
+
export function integrationTestCount(raw) {
|
|
78
|
+
const lines = String(raw ?? "").split("\n");
|
|
79
|
+
const v = lines.findIndex((l) => /^verification:\s*(#.*)?$/.test(l));
|
|
80
|
+
if (v < 0) return 0;
|
|
81
|
+
let n = null;
|
|
82
|
+
for (let i = v + 1; i < lines.length && !/^\S/.test(lines[i]); i++) {
|
|
83
|
+
const m = /^(\s+)integration_tests:\s*(.*)$/.exec(lines[i]);
|
|
84
|
+
if (!m) continue;
|
|
85
|
+
const inline = m[2].replace(/#.*$/, "").trim();
|
|
86
|
+
if (inline === "[]" || inline === "null" || inline === "~") return 0;
|
|
87
|
+
if (inline) return null; // a flow sequence or anchor: not parsed here
|
|
88
|
+
n = 0;
|
|
89
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
90
|
+
const l = lines[j];
|
|
91
|
+
if (!l.trim() || /^\s*#/.test(l)) continue;
|
|
92
|
+
const ind = /^(\s*)/.exec(l)[1].length;
|
|
93
|
+
if (ind <= m[1].length && !/^\s*-/.test(l)) break;
|
|
94
|
+
if (ind < m[1].length) break;
|
|
95
|
+
if (/^\s*-\s/.test(l) && ind <= m[1].length + 2) n++;
|
|
96
|
+
}
|
|
97
|
+
return n;
|
|
98
|
+
}
|
|
99
|
+
return n ?? 0;
|
|
100
|
+
}
|
|
101
|
+
/** #5516: `forgedock:<name>` when ForgeDock is installed as a Claude Code plugin under `configDir`, else the bare name. */
|
|
102
|
+
export function resolveSkillName(name, { configDir, read = (p) => readFileSync(p, "utf8") } = {}) {
|
|
103
|
+
try { return /"forgedock(@[^"]*)?"\s*:/.test(read(join(configDir, "plugins", "installed_plugins.json"))) ? `forgedock:${name}` : name; } catch { return name; }
|
|
104
|
+
}
|
|
105
|
+
|
|
71
106
|
/** One review round at the current head: dispatch, test gate, head check, finalize. @returns {{moved: string}|{fail}|{ok}} */
|
|
72
107
|
async function reviewRound({ seam, pr, def, delta }) {
|
|
73
108
|
const pre = await seam.pre({ pr, delta });
|
|
@@ -85,7 +120,11 @@ async function reviewRound({ seam, pr, def, delta }) {
|
|
|
85
120
|
const failures = new Map();
|
|
86
121
|
const attempt = (domain, note) => send(domain, note).catch((e) => { failures.set(domain, sessionFailure(e)); return null; });
|
|
87
122
|
await Promise.all(agents.map((a) => attempt(a.domain)));
|
|
88
|
-
|
|
123
|
+
// #5516: the missing-config guard of commands/test-gate.md is deterministic, so no session decides it; otherwise the gate
|
|
124
|
+
// session gets a full tool set (Skill, Task, Bash) and the resolved skill name, never a bare `/test-gate`.
|
|
125
|
+
const plan = await seam.testGatePlan();
|
|
126
|
+
const gate = plan.clusters === 0 ? { text: TEST_GATE_SKIP_NO_TESTS }
|
|
127
|
+
: await seam.runAgent({ role: "release-test-gate", issue: pr, fullSession: true, prompt: testGatePrompt(plan.skill, m.bundle, def) });
|
|
89
128
|
const gateFile = seam.saveTestGate(pr, gate?.text ?? "");
|
|
90
129
|
|
|
91
130
|
// The head moved while the panel ran: finalize would refuse, and must never run at the moved head. Delta from what was reviewed.
|
|
@@ -126,7 +165,7 @@ async function runReview({ seam, pr, def, delta = null }) {
|
|
|
126
165
|
if ((st.notes ?? []).length) await seam.addNotes(pr, st.notes);
|
|
127
166
|
const sum = await seam.summary({ pr, filed });
|
|
128
167
|
if (!sum.data) return blocked(`the gate summary was not posted (exit ${sum.code}): ${(sum.lines ?? []).slice(-1).join("").slice(0, 200)}`);
|
|
129
|
-
return { pr, head: st.head, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly), filed, blocking, delta: st.delta?.from ?? null };
|
|
168
|
+
return { pr, head: st.head, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly), ciPendingOnly: Boolean(sum.data.ciPendingOnly), filed, blocking, delta: st.delta?.from ?? null };
|
|
130
169
|
}
|
|
131
170
|
|
|
132
171
|
/** Review step. @returns {{pr, head, verdict, marker, filed, blocking}|{blocked: true, reason: string}} */
|
|
@@ -147,13 +186,15 @@ export async function fixStep(ctx) {
|
|
|
147
186
|
if (!r.blocking?.length && r.ciFailing > 0 && r.ciCancelOnly) {
|
|
148
187
|
const sum = await seam.summary({ pr: r.pr, filed: r.filed ?? [] });
|
|
149
188
|
if (!sum.data) return blocked(`the gate summary was not posted (exit ${sum.code}) after rerunning the cancelled checks of #${r.pr}`);
|
|
150
|
-
r = { ...r, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly) };
|
|
189
|
+
r = { ...r, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly), ciPendingOnly: Boolean(sum.data.ciPendingOnly) };
|
|
151
190
|
ctx.state.steps.review = { ...ctx.state.steps.review, result: r };
|
|
152
191
|
ctx.save();
|
|
153
192
|
if (r.marker === "FORGE:GATE_PASS") break;
|
|
154
193
|
if (r.ciCancelOnly) return blocked(`required checks of #${r.pr} still cancelled after a rerun, with no failure to fix`);
|
|
155
194
|
round--; continue;
|
|
156
195
|
}
|
|
196
|
+
// Required checks that are only still pending (#5519) have not failed: no CI issue or lane, the release re-runs once CI finishes.
|
|
197
|
+
if (!r.blocking?.length && r.ciFailing > 0 && r.ciPendingOnly) return blocked(`required checks of #${r.pr} still pending, with no failure to fix; re-run the release once CI finishes`);
|
|
157
198
|
// Blocking findings are already filed issues; red CI has none, so it gets one issue naming the failing checks.
|
|
158
199
|
const issues = [...(r.blocking ?? [])];
|
|
159
200
|
if (r.ciFailing > 0) {
|
|
@@ -211,10 +252,16 @@ export function realSeam({ repo, def, env = process.env, cwd = process.cwd(), ma
|
|
|
211
252
|
readFile: (p) => readFileSync(p, "utf8"),
|
|
212
253
|
markLaunched: (file, domains, head) => { appendFileSync(file, domains.map((d) => `${d}\n`).join("")); writeFileSync(`${file}.head`, `${head}\n`); },
|
|
213
254
|
saveTestGate: (pr, text) => { mkdirSync(sd, { recursive: true }); const f = join(sd, `${pr}_test_gate_output.txt`); writeFileSync(f, text); return f; },
|
|
214
|
-
runAgent: async ({ role, issue, prompt }) => {
|
|
255
|
+
runAgent: async ({ role, issue, prompt, fullSession = false }) => {
|
|
215
256
|
runner ??= makeRunner ? makeRunner() : (await import("./effects.mjs")).makeLeanRunner();
|
|
216
|
-
// not readOnly: each reviewer posts its own PR comment
|
|
217
|
-
return runner({ role, issue, cwd, env: pinnedEnv(), prompt, system: "You are an isolated reviewer of one release PR. Do only what the prompt asks.", maxMs: REVIEW_MS, idleMs: 10 * 60_000 });
|
|
257
|
+
// not readOnly: each reviewer posts its own PR comment; the test gate (#5516) needs Skill/Task, so a full session
|
|
258
|
+
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 });
|
|
259
|
+
},
|
|
260
|
+
testGatePlan: async () => {
|
|
261
|
+
let raw = null;
|
|
262
|
+
try { raw = readFileSync(env.FORGE_CONFIG || join(cwd, "forge.yaml"), "utf8"); } catch { raw = null; }
|
|
263
|
+
const clusters = raw == null ? null : integrationTestCount(raw);
|
|
264
|
+
return { clusters, skill: resolveSkillName("test-gate", { configDir: env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude") }) };
|
|
218
265
|
},
|
|
219
266
|
// closed by a merged fix: state CLOSED with the workflow:merged label (a read failure is "not merged", so the lane runs)
|
|
220
267
|
issueMerged: async (issue) => {
|
|
@@ -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, MAX_FIX_ROUNDS, realSeam, withIntegrityMarker } from "./release-review.mjs";
|
|
5
|
+
import { reviewStep, fixStep, missingReviewers, SPEC_PANEL, MAX_DELTA_PASSES, MAX_FIX_ROUNDS, realSeam, withIntegrityMarker, TEST_GATE_SKIP_NO_TESTS, testGatePrompt, integrationTestCount, resolveSkillName } from "./release-review.mjs";
|
|
6
6
|
import { readFileSync } from "node:fs";
|
|
7
7
|
import { reviewStagingJson } from "../review-staging.mjs";
|
|
8
8
|
|
|
@@ -11,19 +11,20 @@ const manifest = (head, delta = null) => ({ pr: 7, headSha: head, bundle: [1, 2]
|
|
|
11
11
|
const fin = (extra = {}) => ({ code: 0, data: { head: H1, toFile: [], notes: [], ...extra }, lines: [] });
|
|
12
12
|
|
|
13
13
|
/** Seam fake: `heads` is what headOf answers in turn; `fins` what finalize answers in turn. */
|
|
14
|
-
function fakeSeam({ heads = [H1], fins = [fin()], summary, lanes = [] } = {}) {
|
|
15
|
-
const log = [], agents = [];
|
|
14
|
+
function fakeSeam({ heads = [H1], fins = [fin()], summary, lanes = [], gatePlan = { clusters: 1, skill: "forgedock:test-gate" } } = {}) {
|
|
15
|
+
const log = [], agents = [], gateSaved = [], agentCalls = [];
|
|
16
16
|
let h = 0, f = 0, l = 0, n = 100;
|
|
17
17
|
return {
|
|
18
|
-
log, agents,
|
|
18
|
+
log, agents, gateSaved, agentCalls,
|
|
19
19
|
pre: async (a) => { log.push(["pre", a.delta]); return { code: 0, data: manifest(a.delta ? heads[heads.length - 1] : H1, a.delta ? { from: a.delta, files: ["x"] } : null), lines: [] }; },
|
|
20
20
|
finalize: async () => { log.push(["finalize"]); return fins[Math.min(f++, fins.length - 1)]; },
|
|
21
21
|
summary: async (a) => { log.push(["summary", a.filed]); return summary ?? { code: 0, data: { verdict: "APPROVE FOR DEPLOY", marker: "FORGE:GATE_PASS", ciFailing: 0 }, lines: [] }; },
|
|
22
22
|
headOf: async () => heads[Math.min(h++, heads.length - 1)],
|
|
23
23
|
readFile: (p) => `brief ${p}`,
|
|
24
24
|
markLaunched: (file, domains) => log.push(["launched", domains]),
|
|
25
|
-
saveTestGate: () => "/sd/7_test_gate_output.txt",
|
|
26
|
-
|
|
25
|
+
saveTestGate: (pr, text) => { gateSaved.push(text); return "/sd/7_test_gate_output.txt"; },
|
|
26
|
+
testGatePlan: async () => gatePlan,
|
|
27
|
+
runAgent: async (a) => { agentCalls.push(a); agents.push(a.role + (a.prompt.includes("findings block required") ? ":reask" : "")); return { text: "ok" }; },
|
|
27
28
|
fileIssue: async ({ item }) => { log.push(["file", item.title]); return n++; },
|
|
28
29
|
fileCiIssue: async () => { log.push(["ci-issue"]); return n++; },
|
|
29
30
|
issueMerged: async () => false,
|
|
@@ -53,7 +54,7 @@ describe("reviewStep", () => {
|
|
|
53
54
|
|
|
54
55
|
it("realSeam exposes every effect the steps use, matching the fake seam", () => {
|
|
55
56
|
const real = Object.keys(realSeam({ repo: "o/r", def: "main", env: {}, cwd: "/tmp" })).sort();
|
|
56
|
-
assert.deepEqual(real, Object.keys(fakeSeam()).filter((k) =>
|
|
57
|
+
assert.deepEqual(real, Object.keys(fakeSeam()).filter((k) => !["log", "agents", "gateSaved", "agentCalls"].includes(k)).sort());
|
|
57
58
|
});
|
|
58
59
|
|
|
59
60
|
it("runs the briefs and the spec panel in parallel, then test gate, finalize and summary in order", async () => {
|
|
@@ -206,6 +207,16 @@ describe("fixStep", () => {
|
|
|
206
207
|
assert.ok(!s2.log.some((e) => e[0] === "ci-issue" || e[0] === "lane"));
|
|
207
208
|
});
|
|
208
209
|
|
|
210
|
+
it("only pending CI (#5519): blocks without a CI issue or lane; a real failure alongside still files", async () => {
|
|
211
|
+
const s = fakeSeam();
|
|
212
|
+
const r = await fixStep(ctx(s, { review: { result: { ...failed, blocking: [], filed: [], ciFailing: 1, ciPendingOnly: true } } }));
|
|
213
|
+
assert.match(r.reason, /still pending/);
|
|
214
|
+
assert.deepEqual(s.log, []);
|
|
215
|
+
const s2 = fakeSeam();
|
|
216
|
+
await fixStep(ctx(s2, { review: { result: { ...failed, blocking: [], filed: [], ciFailing: 2, ciPendingOnly: false } } }));
|
|
217
|
+
assert.ok(s2.log.some((e) => e[0] === "ci-issue"));
|
|
218
|
+
});
|
|
219
|
+
|
|
209
220
|
it("blocks when the verdict is not a pass but there is nothing to fix", async () => {
|
|
210
221
|
assert.match((await fixStep(ctx(fakeSeam(), { review: { result: { ...failed, blocking: [], ciFailing: 0 } } }))).reason, /nothing to fix|neither/);
|
|
211
222
|
});
|
|
@@ -319,3 +330,61 @@ describe("withIntegrityMarker (filing release findings through issue-create.sh)"
|
|
|
319
330
|
assert.match(out, /FORGE:BODY-INTEGRITY:fix-auto-spawned-schedd-review-finding -->/);
|
|
320
331
|
});
|
|
321
332
|
});
|
|
333
|
+
|
|
334
|
+
describe("#5516 release test gate", () => {
|
|
335
|
+
it("no integration_tests configured: no gate session, and the saved output carries the guard's SKIP marker", async () => {
|
|
336
|
+
const s = fakeSeam({ gatePlan: { clusters: 0, skill: "forgedock:test-gate" } });
|
|
337
|
+
await reviewStep(ctx(s));
|
|
338
|
+
assert.ok(!s.agents.includes("release-test-gate"), "no session decides a deterministic SKIP");
|
|
339
|
+
assert.equal(s.gateSaved.length, 1);
|
|
340
|
+
assert.match(s.gateSaved[0], /FORGE:TEST_GATE:RESULT=SKIP/);
|
|
341
|
+
assert.match(s.gateSaved[0], /reason=no-tests-configured/);
|
|
342
|
+
});
|
|
343
|
+
it("before the fix the gate output had no marker (finalize failed closed); the SKIP output has exactly one RESULT marker", () => {
|
|
344
|
+
assert.equal((TEST_GATE_SKIP_NO_TESTS.match(/FORGE:TEST_GATE:RESULT=(BLOCK|PASS|SKIP)/g) ?? []).length, 1);
|
|
345
|
+
});
|
|
346
|
+
it("clusters configured: the gate runs in a full session and the prompt names the resolved skill", async () => {
|
|
347
|
+
const s = fakeSeam({ gatePlan: { clusters: 2, skill: "forgedock:test-gate" } });
|
|
348
|
+
await reviewStep(ctx(s));
|
|
349
|
+
const g = s.agentCalls.find((a) => a.role === "release-test-gate");
|
|
350
|
+
assert.ok(g && g.fullSession === true, "Skill/Task/Bash available to the gate session");
|
|
351
|
+
assert.match(g.prompt, /Invoke the Skill "forgedock:test-gate" with args: --prs "1 2" --base main/);
|
|
352
|
+
assert.ok(!/^\/test-gate/.test(g.prompt));
|
|
353
|
+
const reviewers = s.agentCalls.filter((a) => a.role !== "release-test-gate");
|
|
354
|
+
assert.ok(reviewers.every((a) => !a.fullSession), "reviewers keep the lean session");
|
|
355
|
+
});
|
|
356
|
+
it("an unreadable config (clusters null) still runs the gate session, never a SKIP", async () => {
|
|
357
|
+
const s = fakeSeam({ gatePlan: { clusters: null, skill: "test-gate" } });
|
|
358
|
+
await reviewStep(ctx(s));
|
|
359
|
+
assert.ok(s.agents.includes("release-test-gate"));
|
|
360
|
+
});
|
|
361
|
+
it("integrationTestCount reads the verification block", () => {
|
|
362
|
+
assert.equal(integrationTestCount("project:\n repo: x\n"), 0);
|
|
363
|
+
assert.equal(integrationTestCount("verification:\n integration_tests: []\n"), 0);
|
|
364
|
+
assert.equal(integrationTestCount("verification:\n test_gate:\n posture: blocking\n"), 0);
|
|
365
|
+
assert.equal(integrationTestCount("verification:\n integration_tests:\n - cluster: api\n command: pytest\n - cluster: web\n command: npm test\n test_services:\n api: c\n"), 2);
|
|
366
|
+
assert.equal(integrationTestCount("verification:\n integration_tests: [{cluster: a}]\n"), null);
|
|
367
|
+
});
|
|
368
|
+
it("resolveSkillName: prefixed on a plugin install, bare otherwise", () => {
|
|
369
|
+
assert.equal(resolveSkillName("test-gate", { configDir: "/c", read: () => '{"plugins":{"forgedock@forgedock":[{}]}}' }), "forgedock:test-gate");
|
|
370
|
+
assert.equal(resolveSkillName("test-gate", { configDir: "/c", read: () => '{"plugins":{}}' }), "test-gate");
|
|
371
|
+
assert.equal(resolveSkillName("test-gate", { configDir: "/c", read: () => { throw new Error("ENOENT"); } }), "test-gate");
|
|
372
|
+
});
|
|
373
|
+
it("testGatePrompt", () => {
|
|
374
|
+
assert.match(testGatePrompt("test-gate", [5, 6], "main"), /Skill "test-gate" with args: --prs "5 6" --base main/);
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
describe("#5516 makeLeanRunner fullSession", () => {
|
|
379
|
+
it("fullSession drops the lean minimal flags (slash commands/Skill stay available); the default keeps them", async () => {
|
|
380
|
+
const { makeLeanRunner } = await import("./effects.mjs");
|
|
381
|
+
const seen = [];
|
|
382
|
+
const runCli = async (o) => { seen.push(o.sessionFlags); return { text: "", usage: null, costUsd: 0, durationMs: 0, turns: 0, sessionId: "s" }; };
|
|
383
|
+
const base = { role: "release-test-gate", issue: 1, cwd: process.cwd(), prompt: "p", system: "" };
|
|
384
|
+
await makeLeanRunner({ runCli, probe: () => false })({ ...base });
|
|
385
|
+
await makeLeanRunner({ runCli, probe: () => false })({ ...base, fullSession: true });
|
|
386
|
+
const [lean, full] = seen;
|
|
387
|
+
assert.deepEqual(full, [], "no --disable-slash-commands / tool restriction for the gate session");
|
|
388
|
+
if (lean.length) assert.ok(lean.some((f) => /slash|tools|mcp/i.test(f)), `lean flags restrict the session: ${lean.join(" ")}`);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* `forgedock release status [<id>] [--watch] [--json]` and `release explain <id | #issue | PR>` (#5554, epic #5549 Phase 0):
|
|
5
|
+
* read-only views of a release over the ledger (when `release.managed`) or the local cache, plus GitHub. No GitHub write is made.
|
|
6
|
+
* Output carries no host name or wall clock (only recorded timestamps), so a second host prints the same bytes. JSON schemas
|
|
7
|
+
* `forgedock.release.status/v1` and `forgedock.release.explain/v1`; both carry `next_actions[]`, the exact commands an agent may run.
|
|
8
|
+
* `explain #N` traces the rules that exist today (classification record, skip labels, risk/forces, priority, theme_map, `Depends on`
|
|
9
|
+
* closure, recorded release set, lane); the wave planner (#5559) registers into PLANNER_RULES, until then `planner: not installed`. Effects (`io`, `gateState`, local cache) are injected, so it is unit-testable.
|
|
10
|
+
*/
|
|
11
|
+
import { readLedger, readActiveView as readActive } from "./release-ledger.mjs";
|
|
12
|
+
import { parseForgeYaml } from "../forge-utils.mjs";
|
|
13
|
+
import { VERBS, LANES } from "./release-control.mjs";
|
|
14
|
+
import { priorityOf, classifyTheme, closure } from "./issuewatch-release.mjs";
|
|
15
|
+
|
|
16
|
+
export const STATUS_SCHEMA = "forgedock.release.status/v1";
|
|
17
|
+
export const EXPLAIN_SCHEMA = "forgedock.release.explain/v1";
|
|
18
|
+
export const TERMINAL = ["done", "refused", "blocked", "cancelled"];
|
|
19
|
+
export const SKIP_LABELS = ["epic", "needs-human", "post-deploy", "workflow:merged", "awaiting-promotion", "host-task"];
|
|
20
|
+
const STEPS = ["preflight", "host-preflight", "release-pr", "review", "fixes", "mark-ready", "rehearsal", "promotion", "post-merge"];
|
|
21
|
+
/** The verbs `release <verb>` runs (#5556, `release-control.mjs`): the one source for what `next_actions[]` may name. */
|
|
22
|
+
export const CONTROL_VERBS = VERBS;
|
|
23
|
+
const OK = ["success", "neutral", "skipped"];
|
|
24
|
+
const ACTION_FLAGS = ["--repo", "--merge", "--watch", "--resume", "--json", "--interval", "--reason", "--force", "--mode", "--issue", "--until"];
|
|
25
|
+
const unk = (v) => (v === undefined || v === null || v === "" ? "unknown" : v);
|
|
26
|
+
const json = (s) => JSON.parse(String(s || "null"));
|
|
27
|
+
|
|
28
|
+
/** Planner rules (#5559 fills this): each `({issue, state}) => ({rule, config_key, result, detail, would_change})`. */
|
|
29
|
+
export const PLANNER_RULES = [];
|
|
30
|
+
export const registerPlannerRule = (fn) => { PLANNER_RULES.push(fn); };
|
|
31
|
+
|
|
32
|
+
/** The release id of `_active`'s lease (managed), else the newest local one. */
|
|
33
|
+
async function pickId({ io, repo, config, local }) {
|
|
34
|
+
if (config?.managed && io.api) {
|
|
35
|
+
const active = await readActive({ io, repo, credential: "driver" });
|
|
36
|
+
return active.lease?.release ?? active.release ?? null;
|
|
37
|
+
}
|
|
38
|
+
return local.ids().sort().at(-1) ?? null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function ciSummary(io, repo, head) {
|
|
42
|
+
try {
|
|
43
|
+
const runs = json(await io.gh(["api", `repos/${repo}/commits/${head}/check-runs`, "--jq", "[.check_runs[] | {name, conclusion}]"])) ?? [];
|
|
44
|
+
return { total: runs.length, failed: runs.filter((c) => c.conclusion && !OK.includes(c.conclusion)).length, pending: runs.filter((c) => !c.conclusion).length };
|
|
45
|
+
} catch { return null; }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The release `id` (default: the active one) as `{schema, ...}`; `null` when there is none. A field the ledger does not hold is `"unknown"`. */
|
|
49
|
+
export async function collectStatus({ io, repo, id, config = {}, local, gateState }) {
|
|
50
|
+
id ??= await pickId({ io, repo, config, local });
|
|
51
|
+
if (!id) return null;
|
|
52
|
+
const ctx = { io, repo, credential: "driver" }, managed = !!(config.managed && io.api);
|
|
53
|
+
const led = managed ? await readLedger(ctx, id) : null;
|
|
54
|
+
if (led?.rejected) return { schema: STATUS_SCHEMA, id, repo, source: "ledger", status: "rejected", reason: led.rejected, steps: [], next_actions: [`forgedock release explain ${id} --repo ${repo}`] };
|
|
55
|
+
const state = led?.state ?? local.load(id);
|
|
56
|
+
if (!state) return null;
|
|
57
|
+
const active = managed ? await readActive(ctx) : null;
|
|
58
|
+
const steps = STEPS.map((step) => ({ step, done: !!state.steps?.[step]?.done, at: state.steps?.[step]?.at ?? null }));
|
|
59
|
+
const stopped = Object.entries(state.steps ?? {}).find(([, v]) => v && v.done === false)?.[0];
|
|
60
|
+
const next = stopped ?? STEPS.find((st) => !state.steps?.[st]) ?? null;
|
|
61
|
+
const prRes = state.steps?.["release-pr"]?.result, pr = prRes?.pr ? { number: prRes.pr, head: prRes.head ?? null, gate: null, ci: null } : null;
|
|
62
|
+
if (pr?.head && gateState) { try { pr.gate = await gateState({ io, repo, pr: pr.number, head: pr.head }); } catch { pr.gate = null; } }
|
|
63
|
+
if (pr?.head) pr.ci = await ciSummary(io, repo, pr.head);
|
|
64
|
+
const status = state.status ?? "running";
|
|
65
|
+
const lease = active?.lease;
|
|
66
|
+
const hb = lease?.heartbeat_at ? Math.max(0, Math.round((io.now() - Date.parse(lease.heartbeat_at)) / 1000)) : null;
|
|
67
|
+
const w = state.wave;
|
|
68
|
+
const marker = pr?.gate?.marker, verdict = marker ? (marker === "pass" ? "GATE_PASS" : "GATE_FAILURE") : state.steps?.review?.result?.verdict;
|
|
69
|
+
const out = {
|
|
70
|
+
schema: STATUS_SCHEMA, id, repo, source: led ? "ledger" : "local", status, next_step: TERMINAL.includes(status) ? null : next,
|
|
71
|
+
wave: w ? `${w.n}/${w.of ?? w.m}` : "unknown", lane: unk(state.lane ?? w?.lane),
|
|
72
|
+
steps, pr,
|
|
73
|
+
lease: lease ? { holder: unk(lease.holder), epoch: unk(lease.epoch), heartbeat_age_s: hb ?? "unknown" } : "unknown",
|
|
74
|
+
hold: active ? !!(active.holds?.[id] ?? active.holds?.["*"] ?? active.cancelled?.[id]) : "unknown",
|
|
75
|
+
intake: active?.intake ? (active.intake.paused ? "paused" : "open") : "unknown",
|
|
76
|
+
cut_sha: unk(state.release?.snapshot),
|
|
77
|
+
review: verdict ? { verdict, head: pr?.head ?? "unknown" } : "unknown",
|
|
78
|
+
merge_sha: unk(state.steps?.promotion?.result?.sha ?? state.merge_sha),
|
|
79
|
+
deploy: state.deploy ? { run: unk(state.deploy.run), stage: unk(state.deploy.stage), attempt: unk(state.deploy.attempt) } : "unknown",
|
|
80
|
+
rollback_target: unk(state.rollback?.target), auto_rollback: state.rollback?.armed === undefined ? "unknown" : state.rollback.armed ? "armed" : "off",
|
|
81
|
+
release: state.release ? { snapshot: state.release.snapshot ?? null, branch: state.release.branch ?? null, issues: issueNumbers(state), picks: (state.release.picks ?? []).length } : null,
|
|
82
|
+
};
|
|
83
|
+
out.next_actions = nextActions(out);
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const issueNumbers = (state) => (state.release?.issues ?? []).map((i) => (typeof i === "object" ? i.number : i)).filter((n) => n != null).sort((a, b) => a - b);
|
|
88
|
+
|
|
89
|
+
function nextActions(s) {
|
|
90
|
+
const r = `--repo ${s.repo}`, out = [];
|
|
91
|
+
if (!TERMINAL.includes(s.status)) {
|
|
92
|
+
out.push(`forgedock release --resume ${s.id} ${r}`);
|
|
93
|
+
if (s.pr?.gate?.marker === "pass") out.push(`forgedock release --resume ${s.id} ${r} --merge`);
|
|
94
|
+
out.push(s.hold === true ? `forgedock release resume ${s.id} ${r} --reason <reason>` : `forgedock release hold ${s.id} ${r} --reason <reason>`);
|
|
95
|
+
out.push(`forgedock release cancel ${s.id} ${r} --reason <reason>`);
|
|
96
|
+
for (const n of s.release?.issues ?? []) out.push(`forgedock release lane #${n} ${r} --force <${LANES.join("|")}> --reason <reason>`);
|
|
97
|
+
}
|
|
98
|
+
if (s.pr) out.push(`forgedock release explain ${s.pr.number} ${r}`);
|
|
99
|
+
out.push(`forgedock release explain ${s.id} ${r}`, `forgedock release status ${s.id} ${r} --json`);
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Parse a `next_actions[]` command under the release CLI grammar; mutating verbs need `--reason`. Throws on anything else. */
|
|
104
|
+
export function parseNextAction(cmd) {
|
|
105
|
+
const t = String(cmd).split(/\s+/);
|
|
106
|
+
if (t[0] !== "forgedock" || t[1] !== "release") throw new Error(`not a release command: ${cmd}`);
|
|
107
|
+
const verb = [...CONTROL_VERBS, "status", "explain", "verify"].includes(t[2]) ? t[2] : null;
|
|
108
|
+
if (t[2] && !t[2].startsWith("--") && !verb) throw new Error(`unknown verb ${t[2]}: ${cmd}`);
|
|
109
|
+
const flags = t.filter((x) => x.startsWith("--"));
|
|
110
|
+
const bad = flags.find((f) => !ACTION_FLAGS.includes(f));
|
|
111
|
+
if (bad) throw new Error(`unknown option ${bad}: ${cmd}`);
|
|
112
|
+
if (CONTROL_VERBS.includes(verb) && !flags.includes("--reason")) throw new Error(`${verb} needs --reason: ${cmd}`);
|
|
113
|
+
if (!verb && !flags.includes("--resume")) throw new Error(`no verb or --resume: ${cmd}`);
|
|
114
|
+
if (verb === "lane" && !flags.includes("--force")) throw new Error(`lane needs --force: ${cmd}`);
|
|
115
|
+
return { verb, flags };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const show = (v) => (typeof v === "object" && v !== null ? Object.entries(v).map(([k, x]) => `${k}=${x}`).join(" ") : String(v));
|
|
119
|
+
|
|
120
|
+
export function renderReleaseStatus(s) {
|
|
121
|
+
if (!s) return "no active release";
|
|
122
|
+
const head = `${s.id} ${s.repo} status=${s.status}${s.next_step ? ` next=${s.next_step}` : ""} source=${s.source} hold=${s.hold === true ? "yes" : s.hold === false ? "no" : s.hold} intake=${s.intake}`;
|
|
123
|
+
const lines = [head];
|
|
124
|
+
if (s.reason) lines.push(` rejected: ${s.reason}`);
|
|
125
|
+
if (s.steps.length) {
|
|
126
|
+
lines.push(` wave: ${s.wave} lane: ${s.lane}`, ` lease: ${show(s.lease)}`, ` cut: ${s.cut_sha}`);
|
|
127
|
+
for (const st of s.steps) lines.push(` ${st.done ? "[x]" : "[ ]"} ${st.step}${st.at ? ` ${st.at}` : ""}`);
|
|
128
|
+
lines.push(s.pr ? ` PR #${s.pr.number} head ${s.pr.head ?? "unknown"} gate marker=${s.pr.gate?.marker ?? "none"} deploy-gate=${s.pr.gate?.deployGate ?? "none"} ci: ${s.pr.ci ? show(s.pr.ci) : "unknown"}` : " PR: unknown");
|
|
129
|
+
lines.push(` review: ${show(s.review)}`, ` merge: ${s.merge_sha}`, ` deploy: ${show(s.deploy)}`, ` rollback: target=${s.rollback_target} auto=${s.auto_rollback}`);
|
|
130
|
+
if (s.release) lines.push(` release set: ${s.release.issues.map((n) => `#${n}`).join(" ") || "(none recorded)"} picks=${s.release.picks}`);
|
|
131
|
+
}
|
|
132
|
+
lines.push(" next:", ...s.next_actions.map((a) => ` ${a}`));
|
|
133
|
+
return lines.join("\n");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Poll `collect` until the release is terminal (or `maxPolls`); a poll is printed only when its output changed. */
|
|
137
|
+
export async function watchStatus({ collect, print, sleep, asJson = false, intervalMs = 10_000, maxPolls = Infinity }) {
|
|
138
|
+
let last = null, prev;
|
|
139
|
+
for (let n = 0; n < maxPolls; n++) {
|
|
140
|
+
last = await collect();
|
|
141
|
+
const text = asJson ? JSON.stringify(last) : renderReleaseStatus(last);
|
|
142
|
+
if (text !== prev) print(text);
|
|
143
|
+
prev = text;
|
|
144
|
+
if (!last || TERMINAL.includes(last.status)) break;
|
|
145
|
+
await sleep(intervalMs);
|
|
146
|
+
}
|
|
147
|
+
return last;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let stepNo = 0;
|
|
151
|
+
const item = (rule, config_key, result, detail, would_change = []) => ({ step: ++stepNo, rule, config_key, result, detail, would_change });
|
|
152
|
+
const resetSteps = () => { stepNo = 0; };
|
|
153
|
+
const res = (ok) => (ok === null ? "n/a" : ok ? "pass" : "fail");
|
|
154
|
+
|
|
155
|
+
/** The `FORGE:CLASSIFY` record of an issue (latest comment carrying it): `{files, confidence, source, set_by}` or `null`. */
|
|
156
|
+
function classificationOf(comments) {
|
|
157
|
+
const c = (comments ?? []).map((x) => String(x?.body ?? "")).filter((b) => b.includes("FORGE:CLASSIFY")).at(-1);
|
|
158
|
+
if (!c) return null;
|
|
159
|
+
const body = c.replace(/<!--[^>]*-->/g, "");
|
|
160
|
+
let rec = null;
|
|
161
|
+
try { rec = JSON.parse(body.slice(body.indexOf("{"), body.lastIndexOf("}") + 1)); } catch { /* key: value lines */ }
|
|
162
|
+
if (!rec) { rec = {}; for (const m of body.matchAll(/^\s*([a-z_]+):\s*(.+)$/gm)) rec[m[1]] = m[2].trim(); if (typeof rec.files === "string") rec.files = rec.files.split(/\s*,\s*/); }
|
|
163
|
+
return { files: rec.files ?? "unknown", confidence: rec.confidence ?? "unknown", source: rec.source ?? "unknown", set_by: rec.set_by ?? rec.who ?? "unknown" };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const hasLabel = (names, r) => names.includes(r.label);
|
|
167
|
+
|
|
168
|
+
/** `explain #N`: the ordered rule trace for one issue. `watch`: issue_watch config; `policy`: {skip_labels, min_confidence, risk_rules[], forces[]}; `controls`: controls.jsonl entries (`{verb, after, actor}`); `lanes`: `_active.lanes` (`{<issue>: {force, actor}}`). */
|
|
169
|
+
export async function explainIssue({ io, repo, number, state, watch = {}, policy = {}, controls = [], lanes = {}, planner = PLANNER_RULES }) {
|
|
170
|
+
resetSteps();
|
|
171
|
+
const issue = json(await io.gh(["issue", "view", String(number), "--repo", repo, "--json", "number,title,body,labels,comments,createdAt"]));
|
|
172
|
+
const open = json(await io.gh(["issue", "list", "--repo", repo, "--state", "open", "--limit", "500", "--json", "number,title,body,labels,createdAt"])) ?? [];
|
|
173
|
+
const names = (issue.labels ?? []).map((l) => (typeof l === "string" ? l : l?.name)).filter(Boolean);
|
|
174
|
+
const trace = [];
|
|
175
|
+
const cls = classificationOf(issue.comments);
|
|
176
|
+
trace.push(item("classification", "FORGE:CLASSIFY", cls ? "pass" : "n/a", cls ? `files ${show(cls.files)}; confidence ${cls.confidence}; source ${cls.source}; set by ${cls.set_by}` : "classification: absent"));
|
|
177
|
+
const skipList = policy.skip_labels ?? SKIP_LABELS, skip = names.filter((l) => skipList.includes(l));
|
|
178
|
+
trace.push(item("skip_labels", "plan.skip_labels", res(skip.length === 0), skip.length ? `labelled ${skip.join(", ")}` : "no skip label", skip.length ? [`remove label ${skip.join(", ")}`] : []));
|
|
179
|
+
const min = policy.min_confidence, conf = Number(cls?.confidence);
|
|
180
|
+
trace.push(item("min_confidence", "classify.min_confidence", min === undefined || !cls || Number.isNaN(conf) ? "n/a" : res(conf >= min), min === undefined ? "no minimum configured" : cls ? `confidence ${cls.confidence} vs minimum ${min}` : "no classification to compare", conf < min ? ["raise confidence or lower classify.min_confidence"] : []));
|
|
181
|
+
for (const [key, rules] of [["risk.rules", policy.risk_rules ?? []], ["forces", policy.forces ?? []]]) {
|
|
182
|
+
if (!rules.length) trace.push(item(key, key, "n/a", "no rules configured"));
|
|
183
|
+
rules.forEach((r, i) => { const hit = hasLabel(names, r); trace.push(item(key, `${key}[${i}]`, res(!hit), hit ? `label ${r.label} fires${r.lane ? ` -> lane ${r.lane}` : ""}` : `label ${r.label} absent`, hit ? [`remove label ${r.label} or edit ${key}[${i}]`] : [])); });
|
|
184
|
+
}
|
|
185
|
+
const prio = priorityOf(issue);
|
|
186
|
+
trace.push(item("priority", "issue_watch.watches.<name>.immediate", prio !== null ? "pass" : "n/a", prio ? `priority ${prio}` : "no P0-P3 label (weighs as P3)"));
|
|
187
|
+
const theme = classifyTheme(issue, watch.theme_map ?? {});
|
|
188
|
+
trace.push(item("theme", "issue_watch.watches.<name>.theme_map", res(!!theme), theme ? `theme ${theme.theme} via ${theme.via}` : "no theme rule matches", theme ? [] : ["add a theme_map rule (label:, scope: or path:) in forge.yaml"]));
|
|
189
|
+
const byNum = new Map(open.map((i) => [i.number, i])); byNum.set(issue.number, issue);
|
|
190
|
+
const prereq = closure(issue, byNum).filter((i) => i.number !== issue.number).map((i) => i.number);
|
|
191
|
+
trace.push(item("depends_on", "release.managed", res(prereq.length === 0), prereq.length ? `open prerequisites ${prereq.map((n) => `#${n}`).join(", ")} must ship first` : "no open prerequisite", prereq.length ? [`close or ship ${prereq.map((n) => `#${n}`).join(", ")}`] : []));
|
|
192
|
+
const member = (state ? issueNumbers(state) : []).includes(issue.number);
|
|
193
|
+
trace.push(item("release_set", "release.mode", res(member), state ? (member ? `in the recorded release set of ${state.id}` : `not in the recorded release set of ${state.id}`) : "no release recorded", member || skip.length ? [] : ["include it in the next release cut"]));
|
|
194
|
+
if (planner.length) for (const fn of planner) { const p = fn({ issue, state }); trace.push(item(p.rule, p.config_key, p.result, p.detail ?? "", p.would_change ?? [])); }
|
|
195
|
+
else trace.push(item("planner", "release.planner", "n/a", "planner: not installed"));
|
|
196
|
+
const lastLane = controls.filter((c) => c.verb === "lane" && c.after?.[number] !== undefined).at(-1);
|
|
197
|
+
const rec = lanes[number] ?? (lastLane ? { force: lastLane.after[number], actor: lastLane.actor } : null);
|
|
198
|
+
const ctl = rec ? { lane: rec.force, actor: rec.actor } : null;
|
|
199
|
+
const planned = member ? "release" : skip.length ? "excluded" : "pool";
|
|
200
|
+
const lane = ctl?.lane ?? planned;
|
|
201
|
+
trace.push(item("lane", "controls.jsonl lane | plan lane", "n/a", ctl ? `lane ${lane} (control decision${ctl.actor ? ` by ${ctl.actor}` : ""})` : `lane ${lane} (plan)`, [`label or config key above, or: forgedock release lane #${number} --force <${LANES.join("|")}> --reason <reason>`]));
|
|
202
|
+
return { schema: EXPLAIN_SCHEMA, kind: "issue", repo, issue: number, lane, classification: cls ?? "absent", trace, would_change: trace.flatMap((t) => t.would_change), next_actions: [`forgedock release status --repo ${repo} --json`] };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** `explain <PR>`: every required check and its outcome at the head, the deploy gate, and any exemption (demotion) from `controls`. */
|
|
206
|
+
export async function explainPr({ io, repo, pr, gateState, policy = {}, exemptions = {} }) {
|
|
207
|
+
resetSteps();
|
|
208
|
+
const head = json(await io.gh(["pr", "view", String(pr), "--repo", repo, "--json", "headRefOid"]))?.headRefOid;
|
|
209
|
+
const g = await gateState({ io, repo, pr, head });
|
|
210
|
+
const checks = json(await io.gh(["api", `repos/${repo}/commits/${head}/check-runs`, "--jq", "[.check_runs[] | {name, conclusion}]"])) ?? [];
|
|
211
|
+
const byName = new Map(checks.map((c) => [c.name, c]));
|
|
212
|
+
const names = (policy.required_checks ?? checks.map((c) => c.name)).slice().sort();
|
|
213
|
+
const exempt = (n) => exemptions?.[n] ?? null; // `_active.exemptions[check]` = {mode, issue, reason, actor, at, until}, as `release exempt` writes it (#5556)
|
|
214
|
+
const live = (e) => e && e.until && Date.parse(e.until) > io.now();
|
|
215
|
+
const trace = [
|
|
216
|
+
item("gate_marker", "release.gate", res(g.marker === "pass"), `FORGE:GATE_PASS marker: ${g.marker ?? "none"}`),
|
|
217
|
+
item("deploy_gate", "forge/deploy-gate", res(g.deployGate === "success"), `forge/deploy-gate: ${g.deployGate ?? "none"}`),
|
|
218
|
+
];
|
|
219
|
+
const demoted = [];
|
|
220
|
+
for (const n of names) {
|
|
221
|
+
const c = byName.get(n), concl = c?.conclusion ?? null, ex = exempt(n);
|
|
222
|
+
const ok = concl ? OK.includes(concl) : null;
|
|
223
|
+
if (live(ex) && ok !== true) {
|
|
224
|
+
demoted.push({ check: n, mode: unk(ex.mode), actor: unk(ex.actor), expires: unk(ex.until), reason: unk(ex.reason), issue: unk(ex.issue) });
|
|
225
|
+
trace.push(item(`check:${n}`, "branches.required_checks", "n/a", `${concl ?? "missing"}; demoted (${unk(ex.mode)}) by ${unk(ex.actor)} until ${unk(ex.until)}: ${unk(ex.reason)} (issue ${unk(ex.issue)})`));
|
|
226
|
+
} else trace.push(item(`check:${n}`, "branches.required_checks", ok === null ? "fail" : res(ok), c ? `${concl ?? "pending"}` : "missing", ok === true ? [] : [`make ${n} pass, or demote it: forgedock release exempt ${n} --mode skip --issue <issue> --until 24h --reason <reason>`]));
|
|
227
|
+
}
|
|
228
|
+
return { schema: EXPLAIN_SCHEMA, kind: "pr", repo, pr, head, decision: trace.every((t) => t.result !== "fail") ? "pass" : "hold", demoted, trace, would_change: trace.flatMap((t) => t.would_change), next_actions: [`forgedock release explain ${pr} --repo ${repo} --json`] };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function renderExplain(e) {
|
|
232
|
+
const lines = [e.kind === "issue" ? `#${e.issue} lane=${e.lane}` : e.kind === "pr" ? `PR #${e.pr} head ${e.head} decision=${e.decision}` : `${e.id} status=${e.status}`];
|
|
233
|
+
e.trace.forEach((t) => lines.push(` ${t.step}. ${t.result === "pass" ? "pass" : t.result === "fail" ? "FAIL" : "n/a "} ${t.rule} [${t.config_key}] ${t.detail}`));
|
|
234
|
+
if (e.would_change?.length) lines.push(" would change:", ...e.would_change.map((w) => ` - ${w}`));
|
|
235
|
+
lines.push(" next:", ...e.next_actions.map((a) => ` ${a}`));
|
|
236
|
+
return lines.join("\n");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const ruleList = (v) => (Array.isArray(v) ? v : v ? [v] : []).map((r) => (typeof r === "string" ? { label: r.replace(/^\s*label:\s*/, "").trim() } : r)).filter((r) => r?.label);
|
|
240
|
+
const strList = (v) => (Array.isArray(v) ? v : v ? [v] : []).map(String);
|
|
241
|
+
|
|
242
|
+
/** `{policy, watch}` read from forge.yaml (`plan.skip_labels`, `classify.min_confidence`, `risk.rules`, `forces`, `branches.required_checks`, `issue_watch` theme_map); a key that is absent stays undefined. */
|
|
243
|
+
export function policyFromYaml(raw) {
|
|
244
|
+
let y = {}; try { y = parseForgeYaml(String(raw ?? "")) ?? {}; } catch { y = {}; }
|
|
245
|
+
const mc = y.classify?.min_confidence === undefined ? undefined : Number(y.classify.min_confidence);
|
|
246
|
+
const watches = Object.values(y.issue_watch?.watches ?? {}).filter((w) => w && typeof w === "object");
|
|
247
|
+
return {
|
|
248
|
+
policy: {
|
|
249
|
+
skip_labels: y.plan?.skip_labels === undefined ? undefined : strList(y.plan.skip_labels),
|
|
250
|
+
min_confidence: Number.isNaN(mc) ? undefined : mc,
|
|
251
|
+
risk_rules: ruleList(y.risk?.rules), forces: ruleList(y.forces?.rules ?? y.forces),
|
|
252
|
+
required_checks: y.branches?.required_checks === undefined ? undefined : strList(y.branches.required_checks),
|
|
253
|
+
},
|
|
254
|
+
watch: watches.find((w) => w.theme_map) ?? {},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const flag = (argv, f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : null; };
|
|
259
|
+
|
|
260
|
+
/** `release status|explain ...`; @returns the exit code (0 found, 1 nothing found). `deps`: {io, config, local, gateState, watch, maxPolls}. */
|
|
261
|
+
export async function statusFromCli(argv, deps) {
|
|
262
|
+
const { io } = deps, verb = argv[0], rest = argv.slice(1);
|
|
263
|
+
const known = ["--repo", "--json", "--watch", "--interval"];
|
|
264
|
+
const bad = rest.find((a) => a.startsWith("--") && !known.includes(a));
|
|
265
|
+
if (bad) throw new Error(`unknown option ${bad}; usage: forgedock release ${verb} ${verb === "status" ? "[<id>] [--watch] [--interval s] [--json]" : "<id | #issue | PR>"} [--repo owner/repo] [--json]`);
|
|
266
|
+
const asJson = rest.includes("--json"), arg = rest.find((a, i) => !a.startsWith("--") && !["--repo", "--interval"].includes(rest[i - 1]));
|
|
267
|
+
const repo = flag(rest, "--repo") ?? json(await io.gh(["repo", "view", "--json", "nameWithOwner"])).nameWithOwner;
|
|
268
|
+
const base = { io, repo, config: deps.config, local: deps.local, gateState: deps.gateState };
|
|
269
|
+
const none = (s) => s ?? { schema: STATUS_SCHEMA, id: null, repo, status: "no active release", next_actions: [] };
|
|
270
|
+
const show1 = (s) => (asJson ? JSON.stringify(none(s)) : arg && !s ? `no release ${arg}` : renderReleaseStatus(s));
|
|
271
|
+
if (verb === "status") {
|
|
272
|
+
const collect = () => collectStatus({ ...base, id: arg });
|
|
273
|
+
if (rest.includes("--watch")) {
|
|
274
|
+
const secs = flag(rest, "--interval") === null ? 10 : Number(flag(rest, "--interval"));
|
|
275
|
+
if (!(secs > 0)) throw new Error("--interval needs a positive number of seconds");
|
|
276
|
+
const s = await watchStatus({ collect, print: io.print, sleep: io.sleep, asJson, intervalMs: secs * 1000, maxPolls: deps.maxPolls });
|
|
277
|
+
return s ? 0 : 1;
|
|
278
|
+
}
|
|
279
|
+
const s = await collect();
|
|
280
|
+
io.print(show1(s));
|
|
281
|
+
return s ? 0 : 1;
|
|
282
|
+
}
|
|
283
|
+
if (!arg) throw new Error("release explain needs <id | #issue | PR>");
|
|
284
|
+
const act = deps.config?.managed && io.api ? await readActive({ io, repo, credential: "driver" }) : {};
|
|
285
|
+
const controls = act.controls ?? [], lanes = act.lanes ?? {}, exemptions = act.exemptions ?? {};
|
|
286
|
+
let out;
|
|
287
|
+
if (arg.startsWith("#")) {
|
|
288
|
+
const s = await collectStatus({ ...base }).catch(() => null);
|
|
289
|
+
out = await explainIssue({ io, repo, number: Number(arg.slice(1)), state: s ? { id: s.id, release: s.release } : null, watch: deps.watch, policy: deps.policy, controls, lanes });
|
|
290
|
+
} else if (/^\d+$/.test(arg) || /\/pull\/\d+/.test(arg)) {
|
|
291
|
+
out = await explainPr({ io, repo, pr: Number(/\d+$/.exec(arg)[0]), gateState: deps.gateState, policy: deps.policy, exemptions });
|
|
292
|
+
} else {
|
|
293
|
+
const s = await collectStatus({ ...base, id: arg });
|
|
294
|
+
if (!s) { io.print(`no release ${arg}`); return 1; }
|
|
295
|
+
resetSteps();
|
|
296
|
+
out = { schema: EXPLAIN_SCHEMA, kind: "release", id: s.id, repo, status: s.status, trace: s.steps.map((st) => item(st.step, "release.steps", st.done ? "pass" : "n/a", st.done ? `done ${st.at ?? ""}`.trim() : "not done")), would_change: s.next_step ? [`run step ${s.next_step}`] : [], next_actions: s.next_actions };
|
|
297
|
+
}
|
|
298
|
+
io.print(asJson ? JSON.stringify(out) : renderExplain(out));
|
|
299
|
+
return 0;
|
|
300
|
+
}
|