forgedock 1.61.1 → 1.62.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 +10 -1
- package/bin/engine/outcome-codes.mjs +4 -0
- package/bin/engine-cli.mjs +160 -18
- package/bin/env/env.mjs +6 -4
- package/bin/forge-home-check.mjs +91 -0
- package/bin/forgedock.mjs +50 -7
- package/bin/gc.mjs +2 -0
- package/bin/hooks/pre-tool-use.mjs +4 -0
- package/bin/journey.mjs +55 -5
- package/bin/lean/admission.mjs +16 -5
- package/bin/lean/batch-health.mjs +55 -16
- package/bin/lean/batch-health.test.mjs +67 -1
- package/bin/lean/batch.mjs +8 -0
- package/bin/lean/batch.test.mjs +5 -0
- package/bin/lean/ceiling.mjs +20 -0
- package/bin/lean/ceiling.test.mjs +33 -2
- package/bin/lean/ci-gate.mjs +240 -0
- package/bin/lean/ci-gate.test.mjs +227 -0
- package/bin/lean/ci-precheck.mjs +178 -0
- package/bin/lean/ci-precheck.test.mjs +149 -0
- package/bin/lean/conformance.mjs +118 -20
- package/bin/lean/conformance.test.mjs +193 -3
- package/bin/lean/context.test.mjs +7 -6
- package/bin/lean/dag.mjs +128 -0
- package/bin/lean/dag.test.mjs +131 -0
- package/bin/lean/decisions.mjs +5 -4
- package/bin/lean/decisions.test.mjs +11 -0
- package/bin/lean/delguard.mjs +84 -0
- package/bin/lean/delguard.test.mjs +104 -0
- package/bin/lean/depcache.mjs +125 -17
- package/bin/lean/depcache.test.mjs +111 -0
- package/bin/lean/design-gate.mjs +5 -5
- package/bin/lean/design-gate.test.mjs +14 -0
- package/bin/lean/effects.mjs +81 -7
- package/bin/lean/execution.mjs +81 -15
- package/bin/lean/execution.test.mjs +156 -3
- package/bin/lean/forgedock-lane-workflow.test.mjs +35 -0
- package/bin/lean/guardgate.mjs +30 -7
- package/bin/lean/guardgate.test.mjs +44 -1
- package/bin/lean/guards.test.mjs +1 -1
- package/bin/lean/heavy.test.mjs +87 -0
- package/bin/lean/hotarea.mjs +73 -0
- package/bin/lean/hotarea.test.mjs +73 -0
- package/bin/lean/issuewatch-reconcile.mjs +20 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
- package/bin/lean/lanecheck.mjs +27 -3
- package/bin/lean/lanecheck.test.mjs +47 -5
- package/bin/lean/laneconfine.mjs +83 -0
- package/bin/lean/laneconfine.test.mjs +113 -0
- package/bin/lean/lean.mjs +398 -91
- package/bin/lean/lean.test.mjs +792 -26
- package/bin/lean/live-reconcile.mjs +169 -0
- package/bin/lean/live-reconcile.test.mjs +176 -0
- package/bin/lean/orchestrate-envhold.test.mjs +245 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +39 -0
- package/bin/lean/orchestrate.mjs +207 -17
- package/bin/lean/outcomeevidence.mjs +104 -0
- package/bin/lean/outcomeevidence.test.mjs +78 -0
- package/bin/lean/page-capture.mjs +68 -0
- package/bin/lean/page-capture.test.mjs +44 -0
- package/bin/lean/pagegate.mjs +46 -7
- package/bin/lean/pagegate.test.mjs +66 -1
- package/bin/lean/postdeploy-check.mjs +18 -4
- package/bin/lean/postdeploy-check.test.mjs +32 -1
- package/bin/lean/prefilter.mjs +36 -4
- package/bin/lean/prefilter.test.mjs +31 -1
- package/bin/lean/preflight.mjs +22 -0
- package/bin/lean/preflight.test.mjs +19 -1
- package/bin/lean/probe.mjs +18 -0
- package/bin/lean/probe.test.mjs +40 -0
- package/bin/lean/prompts.mjs +41 -4
- package/bin/lean/recovery.test.mjs +20 -0
- package/bin/lean/recurrence.mjs +133 -0
- package/bin/lean/recurrence.test.mjs +99 -0
- package/bin/lean/release-config.mjs +2 -1
- package/bin/lean/release-config.test.mjs +18 -0
- package/bin/lean/release-control.mjs +4 -2
- package/bin/lean/release-control.test.mjs +15 -0
- package/bin/lean/release-merge-hold.mjs +65 -0
- package/bin/lean/release-merge-hold.test.mjs +69 -0
- package/bin/lean/release-review.mjs +26 -9
- package/bin/lean/release-review.test.mjs +53 -0
- package/bin/lean/release-status.mjs +3 -1
- package/bin/lean/release-status.test.mjs +11 -0
- package/bin/lean/release.test.mjs +26 -1
- package/bin/lean/render.mjs +8 -7
- package/bin/lean/repro-output.test.mjs +45 -0
- package/bin/lean/routing.mjs +49 -0
- package/bin/lean/routing.test.mjs +54 -1
- package/bin/lean/run-issue-placement.test.mjs +30 -1
- package/bin/lean/sandbox-actions.mjs +121 -0
- package/bin/lean/sandbox-actions.test.mjs +94 -0
- package/bin/lean/sandbox-provider.contract.test.mjs +22 -1
- package/bin/lean/sandbox-remote.mjs +3 -1
- package/bin/lean/schedd-health.mjs +14 -2
- package/bin/lean/schedd-health.test.mjs +13 -0
- package/bin/lean/schedd.mjs +43 -17
- package/bin/lean/schedd.test.mjs +61 -1
- package/bin/lean/toolchain.mjs +16 -6
- package/bin/lean/toolplace.mjs +12 -0
- package/bin/lean/weakguard.mjs +105 -0
- package/bin/lean/weakguard.test.mjs +59 -0
- package/bin/lean/winspawn.mjs +61 -0
- package/bin/lean/winspawn.test.mjs +45 -0
- package/bin/lean/worktree.mjs +3 -1
- package/bin/lean/worktree.test.mjs +11 -0
- package/bin/pool/agent.mjs +215 -15
- package/bin/pool/cache-sweep.mjs +74 -0
- package/bin/pool/cli.mjs +11 -3
- package/bin/pool/docker.mjs +33 -2
- package/bin/pool/health.mjs +38 -0
- package/bin/pool/lane-tools.mjs +23 -4
- package/bin/pool/lane-tools.test.mjs +12 -1
- package/bin/pool/router.mjs +21 -3
- package/bin/runner.mjs +37 -0
- package/bin/splash-scene.mjs +356 -0
- package/bin/win-hide-children.mjs +114 -0
- package/commands/orchestrate.md +18 -27
- package/commands/review-pr-agents/infra.md +1 -0
- package/commands/review-pr-staging.md +2 -2
- package/docs/CONFIG.md +60 -3
- package/docs/OUTCOME-CODES.md +3 -0
- package/package.json +1 -1
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +1 -1
- package/plugins/forgedock-splash/README.md +1 -1
- package/plugins/forgedock-splash/hooks/scene.ts +142 -8
- package/pool/README.md +6 -0
- package/pool/image/entrypoint.sh +1 -0
- package/scripts/acceptance-red-green.sh +8 -3
- package/scripts/acceptance-red-green.test.sh +8 -0
- package/scripts/check-spec-size.sh +3 -1
- package/scripts/gen-splash-scene.mjs +24 -0
- package/scripts/review-staging-pre.sh +8 -3
- package/scripts/review-staging-pre.test.sh +2 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #5709: hold a lane's merge into the integration branch while a release PR (head = that branch, base = a default branch)
|
|
3
|
+
* has CI running, so the merge does not restart the release's CI. Deterministic, no LLM; fail-open when GitHub cannot be read.
|
|
4
|
+
* Two sources: a manual hold (`release merge-hold`, state key `mergeHold` of `_active`) and a pending-checks release PR.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* #5777: report-only gate entries, never "release CI running" (mirrors CI_EXCLUDED_CHECKS of bin/review-staging.mjs).
|
|
9
|
+
* `forge/deploy-gate` stays pending until the staging review posts its marker, so counting it held every merge for the whole review.
|
|
10
|
+
*/
|
|
11
|
+
const REPORT_ONLY_CHECKS = new Set(["forgedock/verify", "forge/deploy-gate", "Check for FORGE gate markers"]);
|
|
12
|
+
|
|
13
|
+
/** A rollup entry that has not finished (check run not COMPLETED, or a status context PENDING/EXPECTED); report-only gate entries never count. */
|
|
14
|
+
export function rollupPending(entry) {
|
|
15
|
+
if (!entry) return false;
|
|
16
|
+
if (REPORT_ONLY_CHECKS.has(String(entry.context ?? entry.name ?? ""))) return false;
|
|
17
|
+
if (entry.__typename === "StatusContext" || (entry.state && !entry.status)) return /^(PENDING|EXPECTED)$/i.test(String(entry.state ?? ""));
|
|
18
|
+
return String(entry.status ?? "").toUpperCase() !== "COMPLETED";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `release.hold_merges_during_release_ci` of a parsed release policy; default true (absent policy, key or section). */
|
|
22
|
+
export function holdEnabled(policy) {
|
|
23
|
+
return policy?.release?.hold_merges_during_release_ci !== false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* #5776: a release-ledger io for lanes. `makeLeanIo` has no `api`, which the ledger reader needs, so the hold's read threw a
|
|
28
|
+
* TypeError that the fail-open catch swallowed (the manual hold never held). Read-only (GET): gh errors propagate unchanged
|
|
29
|
+
* (their `HTTP 404` text keeps the ledger's missing-file detection working).
|
|
30
|
+
* @param {(args: string[]) => Promise<string>} gh
|
|
31
|
+
*/
|
|
32
|
+
export function ledgerIoFromGh(gh) {
|
|
33
|
+
return { api: async (method, path) => JSON.parse(String(await gh(["api", "-X", method, path])) || "null") };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {object} o
|
|
38
|
+
* @param {(args: string[]) => Promise<string>} o.gh gh runner
|
|
39
|
+
* @param {string} o.repo
|
|
40
|
+
* @param {string} o.branch the branch the lane merges into (without `origin/`)
|
|
41
|
+
* @param {string[]} [o.defaults] default branch names; a release PR targets one of them
|
|
42
|
+
* @param {boolean} [o.enabled] explicit switch (false disables)
|
|
43
|
+
* @param {object|null} [o.policy] parsed release policy; `release.hold_merges_during_release_ci: false` disables
|
|
44
|
+
* @param {boolean} [o.skipReleaseCi] the release job's own fix lane (#5794): skip only the release-PR pending-CI hold; the manual hold still applies
|
|
45
|
+
* @param {() => Promise<object|null>} [o.readActive] the `_active` record, for the manual hold
|
|
46
|
+
* @returns {Promise<{held: boolean, kind?: "manual"|"release-ci", reason?: string, pr?: number}>}
|
|
47
|
+
*/
|
|
48
|
+
export async function releaseMergeHold({ gh, repo, branch, defaults = [], enabled = true, policy = null, readActive = null, skipReleaseCi = false }) {
|
|
49
|
+
if (enabled === false || !holdEnabled(policy) || !branch) return { held: false };
|
|
50
|
+
try {
|
|
51
|
+
const a = readActive ? await readActive() : null;
|
|
52
|
+
const m = a?.mergeHold;
|
|
53
|
+
if (m) return { held: true, kind: "manual", reason: `manual merge hold (${m.reason ?? "no reason"})` };
|
|
54
|
+
} catch { /* fail-open */ }
|
|
55
|
+
if (skipReleaseCi) return { held: false };
|
|
56
|
+
try {
|
|
57
|
+
const rows = JSON.parse(String(await gh(["pr", "list", "-R", repo, "--head", branch, "--state", "open", "--json", "number,baseRefName,statusCheckRollup"])) || "[]");
|
|
58
|
+
const names = new Set(defaults.filter(Boolean));
|
|
59
|
+
for (const p of Array.isArray(rows) ? rows : []) {
|
|
60
|
+
if (!names.has(p?.baseRefName)) continue;
|
|
61
|
+
if ((p.statusCheckRollup ?? []).some(rollupPending)) return { held: true, kind: "release-ci", pr: p.number, reason: `release PR #${p.number} (${branch} -> ${p.baseRefName}) has CI running` };
|
|
62
|
+
}
|
|
63
|
+
} catch { /* fail-open */ }
|
|
64
|
+
return { held: false };
|
|
65
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 { releaseMergeHold, rollupPending, holdEnabled, ledgerIoFromGh } from "./release-merge-hold.mjs";
|
|
6
|
+
import { CI_EXCLUDED_CHECKS } from "../review-staging.mjs";
|
|
7
|
+
|
|
8
|
+
const run = (rows) => async () => JSON.stringify(rows);
|
|
9
|
+
const O = (gh, extra = {}) => ({ gh, repo: "o/r", branch: "staging", defaults: ["main"], ...extra });
|
|
10
|
+
const PEND = { number: 7, baseRefName: "main", statusCheckRollup: [{ __typename: "CheckRun", status: "IN_PROGRESS" }] };
|
|
11
|
+
|
|
12
|
+
describe("release merge hold (#5709)", () => {
|
|
13
|
+
it("holds while a staging->main release PR has pending checks", async () => {
|
|
14
|
+
const r = await releaseMergeHold(O(run([PEND])));
|
|
15
|
+
assert.equal(r.held, true); assert.equal(r.kind, "release-ci"); assert.equal(r.pr, 7);
|
|
16
|
+
});
|
|
17
|
+
it("does not hold with no release PR, completed checks, or another base", async () => {
|
|
18
|
+
assert.equal((await releaseMergeHold(O(run([])))).held, false);
|
|
19
|
+
assert.equal((await releaseMergeHold(O(run([{ ...PEND, statusCheckRollup: [{ __typename: "CheckRun", status: "COMPLETED" }, { __typename: "StatusContext", state: "SUCCESS" }] }])))).held, false);
|
|
20
|
+
assert.equal((await releaseMergeHold(O(run([{ ...PEND, baseRefName: "dev" }])))).held, false);
|
|
21
|
+
});
|
|
22
|
+
it("is off when release.hold_merges_during_release_ci is false", async () => {
|
|
23
|
+
assert.equal((await releaseMergeHold(O(run([PEND]), { enabled: false }))).held, false);
|
|
24
|
+
assert.equal((await releaseMergeHold(O(run([PEND]), { policy: { release: { hold_merges_during_release_ci: false } } }))).held, false);
|
|
25
|
+
assert.equal((await releaseMergeHold(O(run([PEND]), { policy: { release: { hold_merges_during_release_ci: true } } }))).held, true);
|
|
26
|
+
assert.equal(holdEnabled(null), true); assert.equal(holdEnabled({ schema: 1 }), true); assert.equal(holdEnabled({ release: {} }), true);
|
|
27
|
+
});
|
|
28
|
+
it("#5794 skipReleaseCi lets the release fix lane past a pending release PR; the manual hold and the default still hold", async () => {
|
|
29
|
+
assert.equal((await releaseMergeHold(O(run([PEND]), { skipReleaseCi: true }))).held, false);
|
|
30
|
+
assert.equal((await releaseMergeHold(O(run([PEND]), { skipReleaseCi: false }))).held, true);
|
|
31
|
+
const m = await releaseMergeHold(O(run([PEND]), { skipReleaseCi: true, readActive: async () => ({ mergeHold: { reason: "r" } }) }));
|
|
32
|
+
assert.equal(m.held, true); assert.equal(m.kind, "manual");
|
|
33
|
+
});
|
|
34
|
+
it("holds on a manual hold and fails open on read errors", async () => {
|
|
35
|
+
const m = await releaseMergeHold(O(run([]), { readActive: async () => ({ mergeHold: { reason: "r" } }) }));
|
|
36
|
+
assert.equal(m.held, true); assert.equal(m.kind, "manual");
|
|
37
|
+
const f = await releaseMergeHold(O(async () => { throw new Error("gh down"); }, { readActive: async () => { throw new Error("x"); } }));
|
|
38
|
+
assert.equal(f.held, false);
|
|
39
|
+
});
|
|
40
|
+
it("#5776 the manual hold is read through a gh-backed ledger io (no io.api needed)", async () => {
|
|
41
|
+
const { readActive } = await import("./release-ledger.mjs");
|
|
42
|
+
const b64 = (o) => Buffer.from(JSON.stringify(o)).toString("base64");
|
|
43
|
+
const mk = (gh) => ({ readActive: () => readActive({ io: ledgerIoFromGh(gh), repo: "o/r", credential: "driver" }) });
|
|
44
|
+
const ok = async (a) => { assert.equal(a[0], "api"); assert.match(a[3], /^repos\/o\/r\/contents\/.*active\.json\?ref=/); return JSON.stringify({ content: b64({ mergeHold: { reason: "r" } }) }); };
|
|
45
|
+
const m = await releaseMergeHold(O(run([]), mk(ok)));
|
|
46
|
+
assert.equal(m.held, true); assert.equal(m.kind, "manual");
|
|
47
|
+
const missing = async () => { throw new Error("gh api GET x failed: HTTP 404"); };
|
|
48
|
+
assert.equal((await releaseMergeHold(O(run([]), mk(missing)))).held, false);
|
|
49
|
+
});
|
|
50
|
+
it("rollupPending reads check runs and status contexts", () => {
|
|
51
|
+
assert.equal(rollupPending({ __typename: "StatusContext", state: "PENDING" }), true);
|
|
52
|
+
assert.equal(rollupPending({ __typename: "CheckRun", status: "QUEUED" }), true);
|
|
53
|
+
assert.equal(rollupPending({ __typename: "CheckRun", status: "COMPLETED" }), false);
|
|
54
|
+
});
|
|
55
|
+
it("#5777: the always-pending forge/deploy-gate status and other report-only gate checks do not hold a merge", async () => {
|
|
56
|
+
const gate = { __typename: "StatusContext", context: "forge/deploy-gate", state: "PENDING" };
|
|
57
|
+
const done = { __typename: "CheckRun", name: "ci", status: "COMPLETED" };
|
|
58
|
+
assert.equal(rollupPending(gate), false);
|
|
59
|
+
assert.equal((await releaseMergeHold(O(run([{ ...PEND, statusCheckRollup: [gate, done] }])))).held, false);
|
|
60
|
+
const others = [{ __typename: "CheckRun", name: "forgedock/verify", status: "IN_PROGRESS" }, { __typename: "CheckRun", name: "Check for FORGE gate markers", status: "QUEUED" }];
|
|
61
|
+
assert.equal((await releaseMergeHold(O(run([{ ...PEND, statusCheckRollup: [gate, ...others, done] }])))).held, false);
|
|
62
|
+
for (const n of CI_EXCLUDED_CHECKS) {
|
|
63
|
+
assert.equal(rollupPending({ __typename: "CheckRun", name: n, status: "IN_PROGRESS" }), false, n);
|
|
64
|
+
assert.equal(rollupPending({ __typename: "StatusContext", context: n, state: "PENDING" }), false, n);
|
|
65
|
+
}
|
|
66
|
+
const real = await releaseMergeHold(O(run([{ ...PEND, statusCheckRollup: [gate, { __typename: "CheckRun", name: "ci", status: "IN_PROGRESS" }] }])));
|
|
67
|
+
assert.equal(real.held, true); assert.equal(real.kind, "release-ci");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -23,6 +23,7 @@ import { laneEnv } from "./release-credentials.mjs";
|
|
|
23
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). */
|
|
24
24
|
export const MAX_DELTA_PASSES = 2;
|
|
25
25
|
const REVIEW_MS = 45 * 60_000, LANE_MS = 3 * 60 * 60_000;
|
|
26
|
+
const CI_WAIT_MS = 10 * 60_000, CI_POLL_MS = 60_000; // #5779: bounded fail-late CI wait of the fix step
|
|
26
27
|
const ROOT = fileURLToPath(new URL("../..", import.meta.url));
|
|
27
28
|
const SEVERE = new Set(["CRITICAL", "HIGH"]);
|
|
28
29
|
const MANUAL = "use the manual path: forgedock review-staging <PR> (commands/review-pr-staging.md)";
|
|
@@ -251,8 +252,11 @@ export async function fixStep(ctx) {
|
|
|
251
252
|
r = s.r;
|
|
252
253
|
continue;
|
|
253
254
|
}
|
|
254
|
-
|
|
255
|
+
// #5779: with blocking findings in hand the fix round starts now (completed runs go into the brief); else the wait is bounded
|
|
256
|
+
const jobs = r.ciFailing > 0 ? await seam.failedJobs({ pr: r.pr, head: r.head, wait: !r.blocking?.length }) : [];
|
|
257
|
+
const rec = collectFindings({ head: r.head, jobs, findings: r.items ?? [], guards: r.guards ?? [] });
|
|
255
258
|
const b = blockingOf(rec);
|
|
259
|
+
if (!b.ci.length && !b.review.length && !b.guards.length && !r.blocking?.length && jobs.pending?.length) return blocked(`required checks of #${r.pr} still running (${jobs.pending.join(", ")}), with no failure to fix yet; re-run the release once CI finishes`);
|
|
256
260
|
if (!b.ci.length && !b.review.length && !b.guards.length && !r.blocking?.length && !(r.ciFailing > 0)) return blocked(`${r.verdict} with neither a blocking finding nor red CI to fix`);
|
|
257
261
|
const hashesNow = Object.fromEntries(rec.ci.map((j) => [j.name, j.inputHash ?? inputHash(j.name, r.head)]));
|
|
258
262
|
const brief = compileBrief(rec, { commands: ctx.config?.preflight ? [ctx.config.preflight.command] : [], rerunChecks: jobsToRerun(hashesNow, ctx.state.fixloop?.hashes ?? {}) });
|
|
@@ -299,9 +303,11 @@ export async function fixStep(ctx) {
|
|
|
299
303
|
const seamOf = (ctx) => ctx.io.review ?? (ctx.seam ??= realSeam(ctx));
|
|
300
304
|
|
|
301
305
|
/** Real effects of the review steps: the review-staging library, the engine runner, the filing scripts, gh and a lane process. */
|
|
302
|
-
export function realSeam({ repo, def, env = process.env, laneStrip = [], cwd = process.cwd(), makeRunner = null, gh: ghIn = null }) {
|
|
306
|
+
export function realSeam({ repo, def, env = process.env, laneStrip = [], cwd = process.cwd(), makeRunner = null, gh: ghIn = null, io = null, spawn: spawnIn = spawn }) {
|
|
307
|
+
const sleep = io?.sleep ?? ((ms) => new Promise((res) => setTimeout(res, ms))), now = io?.now ?? (() => Date.now());
|
|
308
|
+
const say = io?.print ?? ((m) => process.stderr.write(`${m}\n`));
|
|
303
309
|
const rs = { ...reviewStagingIo(), cwd, env };
|
|
304
|
-
const
|
|
310
|
+
const sandboxEnv = laneEnv(env, laneStrip); // #5561: reviewer, fix and lane sandboxes never see the driver token
|
|
305
311
|
const sd = env.FORGE_SCRATCHPAD || join(cwd, ".forge-scratch");
|
|
306
312
|
let runner = null, shimEnv = null;
|
|
307
313
|
// Reviewer briefs say `forgedock ...`: pin that name to this release job's own build, whatever is installed globally.
|
|
@@ -310,7 +316,7 @@ export function realSeam({ repo, def, env = process.env, laneStrip = [], cwd = p
|
|
|
310
316
|
const dir = mkdtempSync(join(tmpdir(), "release-forgedock-"));
|
|
311
317
|
writeFileSync(join(dir, "forgedock"), `#!/bin/sh\nexec "${process.execPath}" "${join(ROOT, "bin", "forgedock.mjs")}" "$@"\n`, { mode: 0o755 });
|
|
312
318
|
process.once("exit", () => rmSync(dir, { recursive: true, force: true }));
|
|
313
|
-
return (shimEnv = { ...
|
|
319
|
+
return (shimEnv = { ...sandboxEnv, PATH: `${dir}${delimiter}${sandboxEnv.PATH ?? ""}` });
|
|
314
320
|
};
|
|
315
321
|
const gh = ghIn ?? ((args, input) => execFileSync("gh", args, { encoding: "utf8", input, maxBuffer: 64 << 20, env }));
|
|
316
322
|
return {
|
|
@@ -339,16 +345,25 @@ export function realSeam({ repo, def, env = process.env, laneStrip = [], cwd = p
|
|
|
339
345
|
return v.state === "CLOSED" && (v.labels ?? []).some((l) => l.name === "workflow:merged");
|
|
340
346
|
} catch { return false; }
|
|
341
347
|
},
|
|
342
|
-
// fail-late (#5567): wait until every CI run on `head` finished, then read the log of each
|
|
343
|
-
|
|
348
|
+
// fail-late (#5567): wait (bounded, CI_WAIT_MS, a line per poll) until every CI run on `head` finished, then read the log of each
|
|
349
|
+
// failed one. #5779: a run that never completes (a stale run on a shared sha) used to idle the job silently for an hour; the
|
|
350
|
+
// unfinished ones are now returned as `.pending`, and `wait: false` (blocking findings already in hand) lists once, no wait.
|
|
351
|
+
failedJobs: async ({ head, wait = true }) => {
|
|
344
352
|
const list = () => JSON.parse(gh(["run", "list", "-R", repo, "--commit", head, "--json", "databaseId,name,status,conclusion", "--limit", "50"]));
|
|
353
|
+
const open = (rs) => rs.filter((x) => x.status !== "completed").map((x) => x.name);
|
|
345
354
|
let runs = list();
|
|
346
|
-
for (
|
|
347
|
-
|
|
355
|
+
for (const until = now() + CI_WAIT_MS; wait && open(runs).length && now() < until;) {
|
|
356
|
+
say(`release: waiting on ${open(runs).length} CI run(s) at ${head.slice(0, 7)}: ${open(runs).join(", ")} (gives up in ${Math.ceil((until - now()) / 60_000)} min)`);
|
|
357
|
+
await sleep(Math.min(CI_POLL_MS, Math.max(0, until - now())));
|
|
358
|
+
runs = list();
|
|
359
|
+
}
|
|
360
|
+
if (open(runs).length) say(`release: ${open(runs).length} CI run(s) at ${head.slice(0, 7)} still running, going on without them: ${open(runs).join(", ")}`);
|
|
361
|
+
const jobs = runs.filter((x) => x.status === "completed").map((x) => {
|
|
348
362
|
let log = "";
|
|
349
363
|
if (x.conclusion === "failure") { try { log = gh(["run", "view", String(x.databaseId), "-R", repo, "--log-failed"]).slice(-20_000); } catch { /* no log: unknown class */ } }
|
|
350
364
|
return { name: x.name, conclusion: x.conclusion, log };
|
|
351
365
|
});
|
|
366
|
+
return Object.assign(jobs, { pending: open(runs) });
|
|
352
367
|
},
|
|
353
368
|
// #5567: findings that do not block (or lie outside the wave) are filed for the next plan, labelled so the release never picks them up
|
|
354
369
|
async fileDeferred({ pr, items }) {
|
|
@@ -388,7 +403,9 @@ export function realSeam({ repo, def, env = process.env, laneStrip = [], cwd = p
|
|
|
388
403
|
runLane: ({ issue, lane }) => new Promise((resolve) => {
|
|
389
404
|
const dir = mkdtempSync(join(tmpdir(), "release-lane-"));
|
|
390
405
|
const rf = join(dir, "result.json");
|
|
391
|
-
|
|
406
|
+
// #5794: FORGE_RELEASE_FIX_LANE marks the release job's own fix lane so its merge is not held on the release PR's CI
|
|
407
|
+
// #5785: `lane` is the lane name; the child gets the sandbox env (a string env leaves it without PATH or auth)
|
|
408
|
+
const child = spawnIn(process.execPath, [join(ROOT, "bin", "forgedock.mjs"), "run-issue", String(issue), "--lane", lane, "--result-file", rf], { cwd, env: { ...sandboxEnv, FORGE_RELEASE_FIX_LANE: "1" }, stdio: "ignore" });
|
|
392
409
|
const timer = setTimeout(() => child.kill("SIGTERM"), LANE_MS);
|
|
393
410
|
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); };
|
|
394
411
|
child.on("error", done); child.on("exit", done);
|
|
@@ -4,6 +4,7 @@ import { describe, it } from "node:test";
|
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { reviewStep, fixStep, missingReviewers, SPEC_PANEL, MAX_DELTA_PASSES, realSeam, withIntegrityMarker, TEST_GATE_SKIP_NO_TESTS, testGatePrompt, integrationTestCount, resolveSkillName } from "./release-review.mjs";
|
|
6
6
|
import { readFileSync } from "node:fs";
|
|
7
|
+
import { EventEmitter } from "node:events";
|
|
7
8
|
import { reviewStagingJson } from "../review-staging.mjs";
|
|
8
9
|
|
|
9
10
|
const H1 = "a".repeat(40), H2 = "b".repeat(40);
|
|
@@ -59,6 +60,19 @@ describe("reviewStep", () => {
|
|
|
59
60
|
assert.deepEqual(real, Object.keys(fakeSeam()).filter((k) => !["log", "agents", "gateSaved", "agentCalls"].includes(k)).sort());
|
|
60
61
|
});
|
|
61
62
|
|
|
63
|
+
it("realSeam.runLane spawns the fix lane with the sandbox env, not the lane name (#5785)", async () => {
|
|
64
|
+
let seen = null;
|
|
65
|
+
const spawn = (cmd, args, opts) => { seen = { args, opts }; const c = new EventEmitter(); c.kill = () => {}; setImmediate(() => c.emit("exit", 0)); return c; };
|
|
66
|
+
const real = realSeam({ repo: "o/r", def: "main", env: { PATH: "/usr/bin", HOME: "/h", FORGE_DRIVER_TOKEN: "secret" }, cwd: "/tmp", spawn });
|
|
67
|
+
await real.runLane({ issue: 9, lane: "staging" });
|
|
68
|
+
assert.equal(seen.args[seen.args.indexOf("--lane") + 1], "staging");
|
|
69
|
+
assert.equal(typeof seen.opts.env, "object");
|
|
70
|
+
assert.equal(seen.opts.env.PATH, "/usr/bin");
|
|
71
|
+
assert.equal(seen.opts.env.HOME, "/h");
|
|
72
|
+
assert.ok(!("FORGE_DRIVER_TOKEN" in seen.opts.env));
|
|
73
|
+
assert.equal(seen.opts.env.FORGE_RELEASE_FIX_LANE, "1", "#5794 marks the release fix lane");
|
|
74
|
+
});
|
|
75
|
+
|
|
62
76
|
it("runs the briefs and the spec panel in parallel, then test gate, finalize and summary in order", async () => {
|
|
63
77
|
const s = fakeSeam();
|
|
64
78
|
const r = await reviewStep(ctx(s));
|
|
@@ -191,6 +205,45 @@ describe("fixStep", () => {
|
|
|
191
205
|
assert.equal(calls.length, 1);
|
|
192
206
|
});
|
|
193
207
|
|
|
208
|
+
// #5779: a stale run stuck in_progress on the release head sha made failedJobs sleep 60x60s silently after BLOCK DEPLOY
|
|
209
|
+
const stuckGh = (calls = []) => (args) => {
|
|
210
|
+
calls.push(args);
|
|
211
|
+
if (args[0] === "run" && args[1] === "list") return JSON.stringify([{ databaseId: 1, name: "Shell Compatibility", status: "in_progress", conclusion: "" }, { databaseId: 2, name: "CI", status: "completed", conclusion: "failure" }]);
|
|
212
|
+
if (args[0] === "run" && args[1] === "view") return "boom";
|
|
213
|
+
throw new Error(`unexpected gh ${args.join(" ")}`);
|
|
214
|
+
};
|
|
215
|
+
const within = (p, ms = 3000) => Promise.race([p, new Promise((_, rej) => setTimeout(() => rej(new Error(`still waiting after ${ms}ms`)), ms).unref())]);
|
|
216
|
+
|
|
217
|
+
it("realSeam.failedJobs with a run that never completes: bounded wait, progress lines, pending reported (#5779)", async () => {
|
|
218
|
+
let t = 0;
|
|
219
|
+
const sleeps = [], printed = [];
|
|
220
|
+
const io = { now: () => t, sleep: async (ms) => { sleeps.push(ms); t += ms; }, print: (m) => printed.push(m) };
|
|
221
|
+
const seam = realSeam({ repo: "o/r", def: "main", env: {}, cwd: "/tmp", gh: stuckGh(), io });
|
|
222
|
+
const jobs = await within(seam.failedJobs({ pr: 7, head: H1 }));
|
|
223
|
+
assert.deepEqual(jobs.map((j) => j.name), ["CI"]);
|
|
224
|
+
assert.deepEqual(jobs.pending, ["Shell Compatibility"]);
|
|
225
|
+
assert.ok(sleeps.length > 0 && sleeps.length <= 15, `sleeps ${sleeps.length}`);
|
|
226
|
+
assert.ok(printed.some((m) => /waiting on 1 CI run.*Shell Compatibility/.test(m)), printed.join("\n"));
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("review -> BLOCK DEPLOY -> fixes: a stuck CI run does not stop the fix issue and lane (#5779)", async () => {
|
|
230
|
+
const printed = [], sleeps = [];
|
|
231
|
+
const seam = realSeam({ repo: "o/r", def: "main", env: {}, cwd: "/tmp", gh: stuckGh(), io: { now: () => 0, sleep: async (ms) => { sleeps.push(ms); }, print: (m) => printed.push(m) } });
|
|
232
|
+
const s = fakeSeam({ heads: [H2] });
|
|
233
|
+
const c = ctx({ ...s, failedJobs: seam.failedJobs }, { review: { result: { ...failed, ciFailing: 1 } } });
|
|
234
|
+
await within(fixStep(c));
|
|
235
|
+
assert.deepEqual(s.log.filter((e) => e[0] === "fix-issue" || e[0] === "lane").map((e) => e[0]), ["fix-issue", "lane"]);
|
|
236
|
+
assert.equal(sleeps.length, 0); // blocking findings: no wait at all, the completed runs go into the brief
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("no finding and only a still-running CI run: blocks with a typed pending reason, no lane (#5779)", async () => {
|
|
240
|
+
const s = fakeSeam();
|
|
241
|
+
s.failedJobs = async () => Object.assign([], { pending: ["Shell Compatibility"] });
|
|
242
|
+
const r = await fixStep(ctx(s, { review: { result: { ...failed, blocking: [], filed: [], ciFailing: 1 } } }));
|
|
243
|
+
assert.match(r.reason, /still running.*Shell Compatibility/);
|
|
244
|
+
assert.equal(s.log.filter((e) => e[0] === "lane").length, 0);
|
|
245
|
+
});
|
|
246
|
+
|
|
194
247
|
it("a blocking finding and red CI together get ONE lane on one consolidated issue", async () => {
|
|
195
248
|
const s = fakeSeam({ heads: [H2] });
|
|
196
249
|
await fixStep(ctx(s, { review: { result: { ...failed, ciFailing: 1 } } }));
|
|
@@ -72,6 +72,8 @@ export async function collectStatus({ io, repo, id, config = {}, local, gateStat
|
|
|
72
72
|
steps, pr,
|
|
73
73
|
lease: lease ? { holder: unk(lease.holder), epoch: unk(lease.epoch), heartbeat_age_s: hb ?? "unknown" } : "unknown",
|
|
74
74
|
hold: active ? !!(active.holds?.[id] ?? active.holds?.["*"] ?? active.cancelled?.[id]) : "unknown",
|
|
75
|
+
merge_hold: active ? (active.mergeHold ? { reason: active.mergeHold.reason ?? null, actor: active.mergeHold.actor ?? null, at: active.mergeHold.at ?? null } : null) : "unknown",
|
|
76
|
+
merge_hold_release_ci: pr?.ci && !TERMINAL.includes(status) && pr.ci.pending > 0 ? { pr: pr.number, pending: pr.ci.pending } : null, // #5709: lanes hold merges into the integration branch while this runs
|
|
75
77
|
intake: active?.intake ? (active.intake.paused ? "paused" : "open") : "unknown",
|
|
76
78
|
cut_sha: unk(state.release?.snapshot),
|
|
77
79
|
review: verdict ? { verdict, head: pr?.head ?? "unknown" } : "unknown",
|
|
@@ -120,7 +122,7 @@ const show = (v) => (typeof v === "object" && v !== null ? Object.entries(v).map
|
|
|
120
122
|
|
|
121
123
|
export function renderReleaseStatus(s) {
|
|
122
124
|
if (!s) return "no active release";
|
|
123
|
-
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}`;
|
|
125
|
+
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}${s.merge_hold && s.merge_hold !== "unknown" ? ` merge_hold=yes (${s.merge_hold.reason ?? "no reason"})` : s.merge_hold_release_ci ? ` merge_hold=release-ci (PR #${s.merge_hold_release_ci.pr}, ${s.merge_hold_release_ci.pending} pending)` : ""} intake=${s.intake}`;
|
|
124
126
|
const lines = [head];
|
|
125
127
|
if (s.reason) lines.push(` rejected: ${s.reason}`);
|
|
126
128
|
if (s.steps.length) {
|
|
@@ -198,6 +198,17 @@ describe("release status / explain (#5554)", () => {
|
|
|
198
198
|
assert.throws(() => parseNextAction("forgedock release status x --bogus"), /unknown option/);
|
|
199
199
|
});
|
|
200
200
|
|
|
201
|
+
it("#5709: status shows the active manual merge hold, else a pending release-CI hold", async () => {
|
|
202
|
+
const active = { lease: { holder: "h", epoch: 2, release: ID }, holds: [], mergeHold: { reason: "release CI", actor: "o", at: "T" } };
|
|
203
|
+
const s = await collectStatus(base(fakeIo({ active })));
|
|
204
|
+
assert.deepEqual(s.merge_hold, { reason: "release CI", actor: "o", at: "T" });
|
|
205
|
+
assert.match(renderReleaseStatus(s).split("\n")[0], /hold=no {2}merge_hold=yes \(release CI\) {2}intake=/);
|
|
206
|
+
const ci = await collectStatus(base(fakeIo({ checks: [{ name: "unit", conclusion: null }] })));
|
|
207
|
+
assert.equal(ci.merge_hold, null); assert.deepEqual(ci.merge_hold_release_ci, { pr: 7, pending: 1 });
|
|
208
|
+
assert.match(renderReleaseStatus(ci).split("\n")[0], /merge_hold=release-ci \(PR #7, 1 pending\)/);
|
|
209
|
+
const none = await collectStatus(base(fakeIo()));
|
|
210
|
+
assert.equal(none.merge_hold, null); assert.equal(none.merge_hold_release_ci, null); assert.doesNotMatch(renderReleaseStatus(none), /merge_hold/);
|
|
211
|
+
});
|
|
201
212
|
it("R1: no active release prints `no active release`", async () => {
|
|
202
213
|
const io = fakeIo({ active: {} });
|
|
203
214
|
assert.equal(await releaseFromCli(["status", "--repo", REPO], { io, cwd: managedDir, env: { FORGEDOCK_RELEASE_DIR: join(managedDir, "rel") }, deps: {} }), 1);
|
|
@@ -6,7 +6,7 @@ import { readFileSync, existsSync } from "node:fs";
|
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
8
|
import { releaseFromCli, readReleaseConfig, openRelease, newReleaseId } from "./release.mjs";
|
|
9
|
-
import { reviewStep, fixStep } from "./release-review.mjs";
|
|
9
|
+
import { reviewStep, fixStep, realSeam } from "./release-review.mjs";
|
|
10
10
|
import { postMergeStep } from "./release-postmerge.mjs";
|
|
11
11
|
|
|
12
12
|
const DISK = [{ mount: "/", type: "ext4" }]; // CI /tmp can be tmpfs, which assertDiskPath refuses
|
|
@@ -208,6 +208,31 @@ describe("release job (#5211)", () => {
|
|
|
208
208
|
assert.deepEqual(ran, ["preflight", "release-pr"]); // preflight/release-pr not run again
|
|
209
209
|
});
|
|
210
210
|
|
|
211
|
+
it("#5779: resuming a release stuck after a BLOCK DEPLOY review reaches the fix step despite a CI run that never completes", async () => {
|
|
212
|
+
const root = tmp(), id = newReleaseId(), io = fakeIo(), mod = await import("./release.mjs");
|
|
213
|
+
const at = new Date(io.now()).toISOString();
|
|
214
|
+
const review = { pr: 7, head: HEAD, verdict: "BLOCK DEPLOY", marker: "FORGE:GATE_FAILURE", blocking: [101], filed: [101], ciFailing: 1, items: [] };
|
|
215
|
+
openRelease(root, id, DISK).save({ v: 1, id, repo: REPO, startedAt: at, held: [], steps: { preflight: { done: true, at, result: {} }, "release-pr": { done: true, at, result: { pr: 7, head: HEAD } }, review: { done: true, at, result: review } } });
|
|
216
|
+
const stuckGh = (a) => {
|
|
217
|
+
if (a[0] === "run" && a[1] === "list") return JSON.stringify([{ databaseId: 1, name: "Shell Compatibility", status: "in_progress", conclusion: "" }, { databaseId: 2, name: "CI", status: "completed", conclusion: "failure" }]);
|
|
218
|
+
if (a[0] === "run" && a[1] === "view") return "boom";
|
|
219
|
+
throw new Error(`unexpected gh ${a.join(" ")}`);
|
|
220
|
+
};
|
|
221
|
+
const waits = [], log = [];
|
|
222
|
+
const real = realSeam({ repo: REPO, def: "main", env: {}, cwd: "/tmp", gh: stuckGh, io: { now: () => 0, sleep: async (ms) => { waits.push(ms); }, print: () => {} } });
|
|
223
|
+
io.review = {
|
|
224
|
+
failedJobs: real.failedJobs, headOf: async () => HEAD, issueMerged: async () => false,
|
|
225
|
+
fileDeferred: async () => [], fileFixIssue: async () => { log.push("fix-issue"); return 200; },
|
|
226
|
+
runLane: async () => { log.push("lane"); return { terminalReason: "merged" }; },
|
|
227
|
+
pre: async () => ({ code: 1, data: null, lines: ["stopped"] }), // ends the delta review right after the fix lane
|
|
228
|
+
};
|
|
229
|
+
const timer = new Promise((_, rej) => setTimeout(() => rej(new Error("still waiting after 5000ms")), 5000).unref());
|
|
230
|
+
const out = await Promise.race([mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config: {}, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ "post-merge": ok }) }), timer]);
|
|
231
|
+
assert.deepEqual(log, ["fix-issue", "lane"]);
|
|
232
|
+
assert.deepEqual(waits, []);
|
|
233
|
+
assert.equal(out.step, "fixes"); // reached the fix step and ran it, not stopped at review
|
|
234
|
+
});
|
|
235
|
+
|
|
211
236
|
it("unfinished steps return a blocked result that names the manual path; the job exits blocked", async () => {
|
|
212
237
|
for (const r of [await reviewStep({}), await fixStep({})]) { assert.equal(r.blocked, true); assert.match(r.reason, /manual path/); }
|
|
213
238
|
const io = fakeIo(), root = tmp();
|
package/bin/lean/render.mjs
CHANGED
|
@@ -121,11 +121,12 @@ const escl = (v) => line(v).replace(/</g, "<");
|
|
|
121
121
|
/** Canonical contract JSON: stable, and `<` escaped so builder text can never open an HTML/FORGE comment. */
|
|
122
122
|
export const contractJson = (c) => JSON.stringify(c, null, 1).replace(/</g, "\\u003c");
|
|
123
123
|
// #4265: an optional ", issue S" records the hash of the issue scope (conformance.mjs scopeText) the contract was planned from.
|
|
124
|
-
|
|
124
|
+
// #5811: an optional ", base B" records the lane base it was planned against (a recovery reuses it only on the same base).
|
|
125
|
+
const CONTRACT_BLOCK_RE = /<summary>contract\.json \(sha256 ([0-9a-f]{12})(?:, issue ([0-9a-f]{12}))?(?:, base ([\w./-]+))?\)<\/summary>\s*```json\n([\s\S]*?)\n```/;
|
|
125
126
|
|
|
126
127
|
/** FORGE:CONTRACT body: readable tables plus the frozen JSON and its hash (read back on a rerun). */
|
|
127
|
-
export function renderContract(c, hash, { compact = false, scope = null } = {}) {
|
|
128
|
-
const json = `<details><summary>contract.json (sha256 ${hash}${scope ? `, issue ${scope}` : ""})</summary>\n\n\`\`\`json\n${contractJson(c)}\n\`\`\`\n</details>`;
|
|
128
|
+
export function renderContract(c, hash, { compact = false, scope = null, base = null } = {}) {
|
|
129
|
+
const json = `<details><summary>contract.json (sha256 ${hash}${scope ? `, issue ${scope}` : ""}${scope && base && /^[\w./-]+$/.test(base) ? `, base ${base}` : ""})</summary>\n\n\`\`\`json\n${contractJson(c)}\n\`\`\`\n</details>`;
|
|
129
130
|
if (compact) return `## Builder Contract (frozen \`${hash}\`)\n\n${c.requirements.length} requirement(s), ${(c.deliverables ?? []).length} deliverable(s); the tables are omitted because the contract is large.\n\n${json}`;
|
|
130
131
|
const disp = (r) => `${r.disposition === "post-deploy" && /\[type:(?:e2e|manual)\]/i.test(String(r.quote ?? "")) ? "post-deploy, transferred to the epic (not met)" : r.disposition}${r.verify === "out_of_band" ? `, verified out of band${r.evidence ? ` (${escl(r.evidence)})` : ""}` : ""}${r.tracked ? ` → ${r.tracked}` : ["defer", "post-deploy"].includes(r.disposition) ? " (filed after review accepts it)" : ""}${r.why ? ` (${escl(r.why)})` : ""}`;
|
|
131
132
|
const req = c.requirements.map((r) => `| ${esc(r.id)} | ${esc(r.quote)} | ${esc(disp(r))} |`).join("\n");
|
|
@@ -136,11 +137,11 @@ export function renderContract(c, hash, { compact = false, scope = null } = {})
|
|
|
136
137
|
? `\n\n### Test plan\n| Requirement | Proof | Level | Repro | Regression | Env | Command |\n| --- | --- | --- | --- | --- | --- | --- |\n${c.test_plan.map((t) => `| ${esc(t?.requirement)} | ${esc(t?.proof)} | ${esc(t?.level)} | ${esc(/^no-repro$/i.test(String(t?.repro ?? "").trim()) ? `no-repro: ${t?.reason ?? ""}` : t?.repro)} | ${esc(Array.isArray(t?.regression) ? t.regression.join("; ") : t?.regression)} | ${esc(Array.isArray(t?.env) ? t.env.join("; ") : t?.env)} | \`${esc(t?.command).replace(/`/g, "'")}\` |`).join("\n")}` : "";
|
|
137
138
|
return `## Builder Contract (frozen \`${hash}\`)\n\n### Requirements\n| Id | From the issue | Disposition |\n| --- | --- | --- |\n${req}\n\n### Deliverables\n${del ? `| Id | Path | Change | Requirements |\n| --- | --- | --- | --- |\n${del}` : "None."}\n\n### Preserve\n${(c.preserve ?? []).map((p) => `- ${escl(p.id)}: ${escl(p.what)}`).join("\n") || "None."}\n\n### Validate\n${(c.validate ?? []).map((v) => `- ${escl(v.id)}: \`${escl(v.command).replace(/`/g, "'")}\``).join("\n") || NR}${tp}${dec}\n\n${json}`;
|
|
138
139
|
}
|
|
139
|
-
/** {contract, hash, scope, text} from a FORGE:CONTRACT comment body (scope null
|
|
140
|
+
/** {contract, hash, scope, base, text} from a FORGE:CONTRACT comment body (scope null pre-#4265, base null pre-#5811), or null. */
|
|
140
141
|
export function parseContractComment(body) {
|
|
141
142
|
const m = CONTRACT_BLOCK_RE.exec(String(body ?? ""));
|
|
142
143
|
if (!m) return null;
|
|
143
|
-
try { return { hash: m[1], scope: m[2] ?? null,
|
|
144
|
+
try { return { hash: m[1], scope: m[2] ?? null, base: m[3] ?? null, text: m[4], contract: JSON.parse(m[4]) }; } catch { return null; }
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
/** Typed amendments, posted visibly before review. */
|
|
@@ -184,7 +185,7 @@ export function renderShadowReview({ would, failures = [], review, contract, deg
|
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
// ---- PR body ----
|
|
187
|
-
export function renderPrBody({ issue, investigation, contract, implementation, result, gitFiles = [], tracked = [] }) {
|
|
188
|
+
export function renderPrBody({ issue, investigation, contract, implementation, result, gitFiles = [], tracked = [], visual = "" }) {
|
|
188
189
|
const root = section(investigation, "Root Cause") || line(norm(result).root_cause);
|
|
189
190
|
const dels = contract?.deliverables ?? [];
|
|
190
191
|
const deliver = dels.length ? ["| File | Change | Requirements |", "| --- | --- | --- |", ...dels.map((d) => `| ${esc(d.path)} | ${esc(d.change)} | ${esc((d.requirements ?? []).join(", "))} |`)].join("\n")
|
|
@@ -194,7 +195,7 @@ export function renderPrBody({ issue, investigation, contract, implementation, r
|
|
|
194
195
|
// #4404: requirements measured outside the lane; the change delivers their instrumentation, the named job the result
|
|
195
196
|
const oob = (contract?.requirements ?? []).filter((r) => r?.verify === "out_of_band");
|
|
196
197
|
const outOfBand = oob.length ? `\n\n## Verified out of band\n${oob.map((r) => `- ${escl(r.id)}: ${escl(r.quote)} (job ${r.evidence ? `\`${escl(r.evidence).replace(/`/g, "'")}\`` : "not named"})`).join("\n")}` : "";
|
|
197
|
-
return `## Root cause\n${root}\n\n## Deliverables\n${deliver}\n\n## Verification\n${verify}${remaining}${outOfBand}${visualSection(implementation)}\n\nCloses #${issue}`;
|
|
198
|
+
return `## Root cause\n${root}\n\n## Deliverables\n${deliver}\n\n## Verification\n${verify}${remaining}${outOfBand}${visual ? `\n\n${visual}` : visualSection(implementation)}\n\nCloses #${issue}`;
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
// ---- trajectory ----
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// #5732: a repro HEAD=FAILED carries the failing run's output, and an absent interpreter is the environment, not a red test.
|
|
4
|
+
// Imports only exports that exist on the base, so on the base this file loads and fails by assertion.
|
|
5
|
+
import { describe, it } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { reproFailures, reproEnvMiss } from "./conformance.mjs";
|
|
8
|
+
|
|
9
|
+
// The recorded AlterLab #41002 repro_test shape (bare test invocation)
|
|
10
|
+
const C41002 = { repro_test: { path: "services/api/tests/test_admin_scraping_kpis_41002.py", id: "test_list_and_detail_success_rate_match_with_tier_cap",
|
|
11
|
+
command: "cd services/api && poetry run pytest -q -p no:cacheprovider tests/test_admin_scraping_kpis_41002.py::test_list_and_detail_success_rate_match_with_tier_cap" } };
|
|
12
|
+
const PYTEST_FAIL = ["F [100%]",
|
|
13
|
+
" def test_list_and_detail_success_rate_match_with_tier_cap():", "> assert detail.success_rate == listing.success_rate",
|
|
14
|
+
"E AssertionError: 0.5 != 0.4", "FAILED tests/test_admin_scraping_kpis_41002.py::test_list_and_detail_success_rate_match_with_tier_cap", "1 failed in 0.31s"].join("\n");
|
|
15
|
+
|
|
16
|
+
describe("#5732 repro output and env classification", () => {
|
|
17
|
+
it("#5732 repro_red_green failure carries the head output tail", () => {
|
|
18
|
+
const [f] = reproFailures(C41002, { base: "SKIPPED", head: "FAILED", headOutput: PYTEST_FAIL });
|
|
19
|
+
assert.equal(f.kind, "repro_red_green");
|
|
20
|
+
assert.match(f.detail, /got BASE=SKIPPED HEAD=FAILED/);
|
|
21
|
+
assert.match(f.detail, /output tail/);
|
|
22
|
+
assert.match(f.detail, /AssertionError: 0\.5 != 0\.4/);
|
|
23
|
+
});
|
|
24
|
+
it("#5732 the tail is the last 20 lines, and the base run's output is shown too", () => {
|
|
25
|
+
const long = Array.from({ length: 30 }, (_, i) => `line ${i + 1}`).join("\n");
|
|
26
|
+
const [f] = reproFailures(C41002, { base: "RAN", head: "RAN", headOutput: "1 passed", baseOutput: long });
|
|
27
|
+
assert.equal(f.kind, "repro_base_green");
|
|
28
|
+
assert.match(f.detail, /base output tail \(last 20 lines\)/);
|
|
29
|
+
assert.match(f.detail, /line 30/);
|
|
30
|
+
assert.doesNotMatch(f.detail, /line 10\n/);
|
|
31
|
+
});
|
|
32
|
+
it("#5732 no output, no tail", () => {
|
|
33
|
+
assert.doesNotMatch(reproFailures(C41002, { base: "SKIPPED", head: "FAILED" })[0].detail, /output tail/);
|
|
34
|
+
});
|
|
35
|
+
it("#5732 interpreter-missing head is env", () => {
|
|
36
|
+
assert.ok(reproEnvMiss({ rc: 1, output: "poetry env use: python3.11 not found" }, {}));
|
|
37
|
+
assert.ok(reproEnvMiss({ rc: 1, output: "\nCould not find the python executable python3.11\n" }, {}));
|
|
38
|
+
assert.equal(reproEnvMiss({ rc: 1, output: PYTEST_FAIL }, {}), null, "a real assertion failure stays the change's");
|
|
39
|
+
});
|
|
40
|
+
it("#5732 an env-classified head is repro_env, with the output tail", () => {
|
|
41
|
+
const [f] = reproFailures(C41002, { base: "SKIPPED", head: "UNRUNNABLE", headOutput: "poetry env use: python3.11 not found" });
|
|
42
|
+
assert.equal(f.kind, "repro_env");
|
|
43
|
+
assert.match(f.detail, /python3\.11 not found/);
|
|
44
|
+
});
|
|
45
|
+
});
|
package/bin/lean/routing.mjs
CHANGED
|
@@ -72,3 +72,52 @@ export function routeBuilder({ contract = null, riskPaths = [], cfg = {}, topMod
|
|
|
72
72
|
export function shouldEscalate(route, escalated, trigger) {
|
|
73
73
|
return route?.tier === "mid" && !escalated && ESCALATE_TRIGGERS.includes(trigger);
|
|
74
74
|
}
|
|
75
|
+
|
|
76
|
+
/** `size:L` / `size/L` labels mark a large issue before any contract exists (the same label budget.mjs laneSize reads). */
|
|
77
|
+
const LARGE_LABEL_RE = /^size[:/]\s*L$/i;
|
|
78
|
+
/** Risk words too common in issue prose to flag a title on their own (model sessions, context tokens); paths still count them. */
|
|
79
|
+
const TITLE_NOISY = new Set(["session", "sessions", "token", "tokens"]);
|
|
80
|
+
const titleRisk = (title) => String(title ?? "").split(/\s+/).map((w) => (TITLE_NOISY.has(w.toLowerCase().replace(/[^a-z]/g, "")) ? null : riskClassOf(w))).find(Boolean) ?? null;
|
|
81
|
+
const labelNames = (labels) => (Array.isArray(labels) ? labels : []).map((l) => String(l?.name ?? l ?? "").trim()).filter(Boolean);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* #5810: the provisional route of the pre-contract sessions (investigation, plan, contract, light build), from the
|
|
85
|
+
* signals known before any contract: the issue title and labels, the file paths the issue names, and whether an earlier
|
|
86
|
+
* attempt exists. Same classes and tiers as routeBuilder plus `unscoped` (no named file, no risk or size signal: mid).
|
|
87
|
+
* Top tier: a risk word in the title (bar session/token), a label or a named path (or a declared review.risk_paths hit), a `size:L` label,
|
|
88
|
+
* more than SMALL_MAX_FILES named non-test code files, or a prior attempt (resume, salvage, recovery). `reason` says why.
|
|
89
|
+
*/
|
|
90
|
+
export function provisionalRoute({ title = "", labels = [], namedFiles = [], prior = false, riskPaths = [], cfg = {}, topModel = null } = {}) {
|
|
91
|
+
const c = parseBuilderRouting(cfg);
|
|
92
|
+
const paths = [...new Set((Array.isArray(namedFiles) ? namedFiles : []).map((p) => String(p ?? "").trim()).filter(Boolean))];
|
|
93
|
+
const names = labelNames(labels);
|
|
94
|
+
const declared = new Set(riskPathHits(paths, riskPaths));
|
|
95
|
+
const risk = [
|
|
96
|
+
...(titleRisk(title) ? [`title:${titleRisk(title)}`] : []),
|
|
97
|
+
...names.filter((l) => riskClassOf(l)).map((l) => `label:${l}`),
|
|
98
|
+
...paths.filter((p) => riskClassOf(p) || declared.has(p)),
|
|
99
|
+
];
|
|
100
|
+
const kinds = paths.map(classifyPath);
|
|
101
|
+
const [cls, reason] = risk.length ? ["risk", "risk signal in the issue"]
|
|
102
|
+
: names.some((l) => LARGE_LABEL_RE.test(l)) ? ["large", "size:L label"]
|
|
103
|
+
: kinds.filter((k) => k !== "test").length > SMALL_MAX_FILES && kinds.some((k) => k === "code") ? ["large", `${paths.length} named files`]
|
|
104
|
+
: prior ? ["large", "prior attempt"]
|
|
105
|
+
: !paths.length ? ["unscoped", "no named files, no risk or size signal"]
|
|
106
|
+
: kinds.every((k) => k !== "code") ? ["docs-config-test", "named files are docs, config or tests"] : ["small", "few named code files"];
|
|
107
|
+
const tier = c.mode === "on" && !["risk", "large"].includes(cls) ? "mid" : "top";
|
|
108
|
+
return { mode: c.mode, class: cls, tier, model: tier === "mid" ? c.midModel : topModel, risk, reason: c.mode === "on" ? reason : "routing off" };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* #5810: the post-contract route, floored by the provisional one: a risk signal the issue carried keeps the build on the
|
|
113
|
+
* top tier even when the contract's paths look safe (never a silent downgrade below risk policy). Any other contract
|
|
114
|
+
* route stands; `change` records upgrade / downgrade / same against the provisional tier.
|
|
115
|
+
*/
|
|
116
|
+
export function floorRoute(route, pre, topModel = null) {
|
|
117
|
+
if (!route) return route;
|
|
118
|
+
const floored = pre?.class === "risk" && route.tier === "mid";
|
|
119
|
+
const r = floored ? { ...route, class: "risk", tier: "top", model: topModel, risk: [...new Set([...(route.risk ?? []), ...(pre.risk ?? [])])], floor: "pre_route_risk" } : route;
|
|
120
|
+
if (!pre) return r;
|
|
121
|
+
const change = pre.tier === r.tier ? "same" : r.tier === "top" ? "upgrade" : "downgrade";
|
|
122
|
+
return { ...r, pre: { class: pre.class, tier: pre.tier }, change };
|
|
123
|
+
}
|
|
@@ -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 { parseBuilderRouting, classifyPath, routeBuilder, shouldEscalate, ESCALATE_TRIGGERS, DEFAULT_MID_MODEL } from "./routing.mjs";
|
|
5
|
+
import { parseBuilderRouting, classifyPath, routeBuilder, shouldEscalate, provisionalRoute, floorRoute, ESCALATE_TRIGGERS, DEFAULT_MID_MODEL } from "./routing.mjs";
|
|
6
6
|
|
|
7
7
|
const contract = (...paths) => ({ deliverables: paths.map((path, i) => ({ id: `D${i + 1}`, path, change: "x", requirements: ["R1"] })) });
|
|
8
8
|
|
|
@@ -65,3 +65,56 @@ describe("routeBuilder (#4394)", () => {
|
|
|
65
65
|
assert.equal(shouldEscalate(null, false, "precheck"), false);
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
describe("provisionalRoute (#5810)", () => {
|
|
70
|
+
const pre = (o = {}) => provisionalRoute({ topModel: "opus-b", ...o });
|
|
71
|
+
it("no named files and no risk or size signal: unscoped, mid tier, with a reason", () => {
|
|
72
|
+
const r = pre({ title: "Refactor foo parsing", labels: [{ name: "bug" }] });
|
|
73
|
+
assert.deepEqual([r.class, r.tier, r.model], ["unscoped", "mid", DEFAULT_MID_MODEL]);
|
|
74
|
+
assert.match(r.reason, /no named files/);
|
|
75
|
+
});
|
|
76
|
+
it("named docs/tests and few code files route mid; many code files are large (top)", () => {
|
|
77
|
+
assert.deepEqual([pre({ namedFiles: ["docs/a.md", "test/a.test.js"] }).class, pre({ namedFiles: ["docs/a.md"] }).tier], ["docs-config-test", "mid"]);
|
|
78
|
+
assert.deepEqual([pre({ namedFiles: ["src/a.js", "src/a.test.js"] }).class, pre({ namedFiles: ["src/a.js"] }).tier], ["small", "mid"]);
|
|
79
|
+
const big = pre({ namedFiles: ["src/a.js", "src/b.js", "src/c.js"] });
|
|
80
|
+
assert.deepEqual([big.class, big.tier, big.model], ["large", "top", "opus-b"]);
|
|
81
|
+
});
|
|
82
|
+
it("risk domains start top: title word, label, named path, declared risk_paths glob", () => {
|
|
83
|
+
for (const o of [{ title: "Fix stripe checkout double charge" }, { labels: [{ name: "security" }] }, { namedFiles: ["src/auth/login.js"] }, { namedFiles: ["lib/x.js"], riskPaths: ["lib/**"] }]) {
|
|
84
|
+
const r = pre(o);
|
|
85
|
+
assert.deepEqual([r.class, r.tier, r.model], ["risk", "top", "opus-b"], JSON.stringify(o));
|
|
86
|
+
assert.ok(r.risk.length);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
it("session/token in a title alone is not a risk signal (common prose); in a path it still is", () => {
|
|
90
|
+
assert.equal(pre({ title: "Route the builder before the first session; count tokens" }).tier, "mid");
|
|
91
|
+
assert.equal(pre({ namedFiles: ["src/session/store.js"] }).class, "risk");
|
|
92
|
+
});
|
|
93
|
+
it("a size:L label or a prior attempt starts top; routing off keeps top", () => {
|
|
94
|
+
assert.deepEqual([pre({ labels: ["size:L"] }).class, pre({ labels: ["size:L"] }).tier], ["large", "top"]);
|
|
95
|
+
assert.deepEqual([pre({ prior: true }).reason, pre({ prior: true }).tier], ["prior attempt", "top"]);
|
|
96
|
+
const off = pre({ cfg: { mode: "off" } });
|
|
97
|
+
assert.deepEqual([off.tier, off.model, off.reason], ["top", "opus-b", "routing off"]);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("floorRoute (#5810)", () => {
|
|
102
|
+
const top = "opus-b";
|
|
103
|
+
it("a contract route may upgrade the provisional tier", () => {
|
|
104
|
+
const r = floorRoute(routeBuilder({ contract: contract("src/a.js", "src/b.js", "src/c.js"), topModel: top }), provisionalRoute({ topModel: top }), top);
|
|
105
|
+
assert.deepEqual([r.tier, r.change, r.pre.tier], ["top", "upgrade", "mid"]);
|
|
106
|
+
});
|
|
107
|
+
it("an issue risk signal floors a mid contract route at top (never a silent downgrade below risk policy)", () => {
|
|
108
|
+
const r = floorRoute(routeBuilder({ contract: contract("docs/a.md"), topModel: top }), provisionalRoute({ title: "Billing docs", topModel: top }), top);
|
|
109
|
+
assert.deepEqual([r.class, r.tier, r.model, r.floor, r.change], ["risk", "top", top, "pre_route_risk", "same"]);
|
|
110
|
+
assert.ok(r.risk.includes("title:payments"));
|
|
111
|
+
});
|
|
112
|
+
it("a non-risk top provisional route (large, prior attempt) may still route the build mid, as before", () => {
|
|
113
|
+
const r = floorRoute(routeBuilder({ contract: contract("docs/a.md"), topModel: top }), provisionalRoute({ prior: true, topModel: top }), top);
|
|
114
|
+
assert.deepEqual([r.tier, r.change, r.floor], ["mid", "downgrade", undefined]);
|
|
115
|
+
});
|
|
116
|
+
it("no provisional route (resumed past the contract): the contract route unchanged", () => {
|
|
117
|
+
const base = routeBuilder({ contract: contract("docs/a.md"), topModel: top });
|
|
118
|
+
assert.deepEqual(floorRoute(base, null, top), base);
|
|
119
|
+
});
|
|
120
|
+
});
|