forgedock 1.52.0 → 1.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/engine/outcome-codes.mjs +3 -0
- package/bin/engine/telemetry-seam.mjs +4 -2
- package/bin/engine-cli.mjs +53 -16
- package/bin/experiment.mjs +58 -6
- package/bin/forge-utils.mjs +6 -2
- package/bin/forgedock.mjs +15 -1
- package/bin/lean/account-watch.mjs +28 -0
- package/bin/lean/account-watch.test.mjs +30 -0
- package/bin/lean/activation.mjs +20 -0
- package/bin/lean/activation.test.mjs +14 -1
- package/bin/lean/basered.mjs +115 -0
- package/bin/lean/basered.test.mjs +66 -0
- package/bin/lean/batch-health.mjs +40 -6
- package/bin/lean/batch-health.test.mjs +34 -1
- package/bin/lean/batch.mjs +41 -2
- package/bin/lean/batch.test.mjs +104 -2
- package/bin/lean/checkpoint-reconcile.mjs +43 -0
- package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
- package/bin/lean/conformance.e2e.test.mjs +1 -1
- package/bin/lean/conformance.mjs +195 -22
- package/bin/lean/conformance.test.mjs +152 -5
- package/bin/lean/effects.mjs +8 -4
- package/bin/lean/execution.mjs +19 -3
- package/bin/lean/execution.test.mjs +39 -0
- package/bin/lean/findinglabel.mjs +16 -0
- package/bin/lean/findinglabel.test.mjs +39 -0
- package/bin/lean/issuewatch-release.mjs +6 -2
- package/bin/lean/issuewatch-release.test.mjs +16 -0
- package/bin/lean/issuewatch.mjs +11 -1
- package/bin/lean/lanelock.mjs +14 -0
- package/bin/lean/lean.mjs +165 -34
- package/bin/lean/lean.test.mjs +289 -9
- package/bin/lean/light.mjs +48 -7
- package/bin/lean/light.test.mjs +37 -3
- package/bin/lean/limits.test.mjs +142 -9
- package/bin/lean/orchestrate-cancel.test.mjs +143 -0
- package/bin/lean/orchestrate.mjs +96 -26
- package/bin/lean/postdeploy-check.test.mjs +39 -0
- package/bin/lean/prompts.mjs +8 -7
- package/bin/lean/quota.mjs +39 -0
- package/bin/lean/recovery.test.mjs +10 -0
- package/bin/lean/relaxation.mjs +73 -0
- package/bin/lean/relaxation.test.mjs +54 -0
- package/bin/lean/release-postmerge.mjs +119 -0
- package/bin/lean/release-rehearsal.mjs +63 -0
- package/bin/lean/release-rehearsal.test.mjs +93 -0
- package/bin/lean/release-review.e2e.test.mjs +77 -0
- package/bin/lean/release-review.mjs +198 -0
- package/bin/lean/release-review.test.mjs +180 -0
- package/bin/lean/release.mjs +228 -0
- package/bin/lean/release.test.mjs +292 -0
- package/bin/lean/rotator.mjs +150 -31
- package/bin/lean/rotator.test.mjs +105 -2
- package/bin/lean/sandbox-remote.mjs +9 -2
- package/bin/lean/schedd.mjs +49 -4
- package/bin/lean/schedd.test.mjs +87 -6
- package/bin/lean/verifier.mjs +3 -2
- package/bin/lean/verify.mjs +2 -1
- package/bin/lean/verify.test.mjs +6 -0
- package/bin/pool/agent.mjs +18 -4
- package/bin/pool/router.mjs +66 -24
- package/bin/review-staging.mjs +23 -0
- package/bin/stats/conformance-outcomes.mjs +208 -0
- package/bin/stats/conformance-outcomes.test.mjs +188 -0
- package/bin/stats/depth.mjs +218 -0
- package/bin/stats/depth.test.mjs +133 -0
- package/bin/stats/experiment.mjs +7 -5
- package/bin/stats/github-source.mjs +2 -2
- package/bin/stats/index.mjs +64 -2
- package/bin/stats/local-source.mjs +11 -0
- package/bin/stats/query.mjs +69 -0
- package/bin/stats/selffiled.mjs +52 -0
- package/bin/stats/selffiled.test.mjs +71 -0
- package/commands/orchestrate.md +1 -1
- package/commands/review-pr-agents/security.md +4 -0
- package/commands/review-pr-staging.md +2 -0
- package/commands/work-on/build.md +4 -6
- package/docs/CONFIG.md +65 -8
- package/docs/ISSUE-WATCH.md +2 -0
- package/docs/OUTCOME-CODES.md +3 -0
- package/docs/STATS.md +44 -0
- package/docs/TELEMETRY.md +1 -1
- package/package.json +1 -1
- package/pool/README.md +1 -1
- package/pool/image/cs-cred +14 -1
- package/scripts/backfill-finding-labels.mjs +50 -0
- package/scripts/backfill-finding-labels.test.mjs +36 -0
- package/scripts/doctor-pipeline-state.sh +21 -6
- package/scripts/file-deferred-followups.sh +59 -251
- package/scripts/file-deferred-followups.test.sh +85 -206
- package/scripts/followup-route.mjs +12 -0
- package/scripts/owner-route-parity.test.sh +17 -1
- package/scripts/review-pr-side-effects.test.sh +40 -0
package/bin/lean/lean.test.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import { laneBackendId } from "./limits.mjs";
|
|
5
|
+
import { parseExperiment, assignArm } from "../experiment.mjs";
|
|
5
6
|
import assert from "node:assert/strict";
|
|
6
7
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
7
8
|
import { execFileSync } from "node:child_process";
|
|
@@ -79,7 +80,8 @@ function world(o = {}) {
|
|
|
79
80
|
const writeStages = (keys) => { for (const k of keys) if (w.stages[k] != null) put(`${k}.md`, w.stages[k]); };
|
|
80
81
|
w.writeStages = writeStages;
|
|
81
82
|
w.io = {
|
|
82
|
-
|
|
83
|
+
credExec: () => ({ status: 1 }), now: () => w.clock, // #5205: never the host's real cs-cred (a sandbox sets CS_CRED_BASE)
|
|
84
|
+
sleep: async (ms) => { w.clock += ms; },
|
|
83
85
|
gh: async (a, opts) => {
|
|
84
86
|
const k = a.slice(0, 2).join(" ");
|
|
85
87
|
if (opts?.env) (w.ghEnvs ??= []).push(opts.env);
|
|
@@ -141,7 +143,7 @@ function world(o = {}) {
|
|
|
141
143
|
if (a[0] === "diff" && a[1] === "--name-only") return w.changed.join("\n");
|
|
142
144
|
if (a[0] === "diff" && a[1] === "--numstat") return w.numstat ?? "";
|
|
143
145
|
if (a[0] === "ls-files") return [...new Set(["src/foo.js", "src/bar.js", "test/foo.test.js", ...w.changed])].join("\n");
|
|
144
|
-
if (a[0] === "diff") return "diff --git a/src/foo.js b/src/foo.js\n+fix";
|
|
146
|
+
if (a[0] === "diff") return w.diffText ?? "diff --git a/src/foo.js b/src/foo.js\n+fix";
|
|
145
147
|
if (a[0] === "merge-base" && a[1] === "--is-ancestor") { if ([...(o.shipped ?? []), ...(o.unusedAncestors ?? [])].includes(String(a[2]).replace(/^origin\//, ""))) return ""; throw new Error("not an ancestor"); } // #4593
|
|
146
148
|
if (a[0] === "ls-remote" && String(a.at(-1)).startsWith("refs/heads/")) { const b = a.at(-1).slice("refs/heads/".length); return (o.branchesOnOrigin ?? ["staging", "main"]).includes(b) ? `abc\trefs/heads/${b}\n` : ""; }
|
|
147
149
|
if (a[0] === "ls-remote") return w.remote;
|
|
@@ -409,7 +411,7 @@ describe("core work-on", () => {
|
|
|
409
411
|
});
|
|
410
412
|
|
|
411
413
|
it("a reviewer that judges a deferral unjustified gets the builder resumed to implement it; nothing is filed for it", async () => {
|
|
412
|
-
const k = { ...CONTRACT, preserve: [], requirements: [CONTRACT.requirements[0], { id: "R2", quote: "Existing callers of foo keep working.", disposition: "defer", why: "later", bucket: "
|
|
414
|
+
const k = { ...CONTRACT, preserve: [], requirements: [CONTRACT.requirements[0], { id: "R2", quote: "Existing callers of foo keep working.", disposition: "defer", why: "later", bucket: "owner:rotate the key" }] };
|
|
413
415
|
const rej = conf({ requirements: [{ id: "R1", status: "implemented", evidence: "src/foo.js:3", validated_by: "V1" }, { id: "R2", status: "deferred", deferral_ok: false, note: "one line in bar.js; do it now" }] }, k);
|
|
414
416
|
const w = world({ contract: k, claims: [{ id: "R1", status: "implemented" }], reviews: [rej, rej] });
|
|
415
417
|
const r = await run(w);
|
|
@@ -1089,6 +1091,16 @@ describe("conformance gate (frozen contract, precheck, structured review)", () =
|
|
|
1089
1091
|
assert.match(traj(w).join("\n"), /left open \(follow-up pending\)/);
|
|
1090
1092
|
});
|
|
1091
1093
|
|
|
1094
|
+
it("#5240 an unticked acceptance box whose requirement the review marks implemented still closes as completed, with no partial note", async () => {
|
|
1095
|
+
const body = "foo crashes on null input.\n\n- [ ] foo must handle a null argument without throwing.\n- Existing callers of foo keep working.";
|
|
1096
|
+
const w = world({ contract: CONTRACT, body, claims: [{ id: "R1", status: "implemented" }], reviews: [conf()] });
|
|
1097
|
+
const r = await run(w);
|
|
1098
|
+
assert.equal(r.terminalReason, "merged");
|
|
1099
|
+
assert.equal(w.closed.length, 1);
|
|
1100
|
+
assert.ok(!w.comments.some((c) => /Left open: partial/.test(c)));
|
|
1101
|
+
assert.doesNotMatch(traj(w).join("\n"), /left open as partial/);
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1092
1104
|
it("a tracking issue that is not open is not a tracking issue: the item stays pending and is recorded", async () => {
|
|
1093
1105
|
const k = two("defer", { why: "w" });
|
|
1094
1106
|
const w = world({ contract: k, claims: [{ id: "R1", status: "implemented" }], reviews: [conf({}, k)], issueStates: { 900: "CLOSED" } });
|
|
@@ -1715,7 +1727,7 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1715
1727
|
});
|
|
1716
1728
|
|
|
1717
1729
|
it("#4160 shadow files accepted deferrals with track(), the same as enforce, and the PR links them", async () => {
|
|
1718
|
-
const k = { ...CONTRACT, preserve: [], requirements: [CONTRACT.requirements[0], { id: "R2", quote: "Existing callers of foo keep working.", disposition: "defer", why: "w", bucket: "
|
|
1730
|
+
const k = { ...CONTRACT, preserve: [], requirements: [CONTRACT.requirements[0], { id: "R2", quote: "Existing callers of foo keep working.", disposition: "defer", why: "w", bucket: "owner:rotate the key" }] };
|
|
1719
1731
|
const w = world({ contract: k, claims: [{ id: "R1", status: "implemented" }], reviews: [conf({}, k)] });
|
|
1720
1732
|
assert.equal((await runShadow(w)).terminalReason, "merged");
|
|
1721
1733
|
assert.equal(w.followups.length, 1); assert.match(w.followups[0].items[0].key, /^R2: /);
|
|
@@ -1748,8 +1760,16 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1748
1760
|
assert.deepEqual(rs.conformance, { mode: "shadow", would: "nonconforming", risk: false });
|
|
1749
1761
|
});
|
|
1750
1762
|
|
|
1751
|
-
it("#
|
|
1763
|
+
it("#5207 shadow: an in-lane engineering deferral (bucket new-issue) resumes the builder once and is never filed", async () => {
|
|
1752
1764
|
const k = { ...CONTRACT, preserve: [], requirements: [CONTRACT.requirements[0], { id: "R2", quote: "Existing callers of foo keep working.", disposition: "defer", why: "w", bucket: "new-issue" }] };
|
|
1765
|
+
const w = world({ contract: k, claims: [{ id: "R1", status: "implemented" }], reviews: [conf({}, k), conf({}, k)] });
|
|
1766
|
+
const r = await runShadow(w);
|
|
1767
|
+
assert.equal(r.code, "conformance.unjustified_deferral"); assert.equal(w.followups.length, 0); assert.equal(w.merges.length, 0);
|
|
1768
|
+
assert.match(builders(w)[2][4], /R2 is in-lane engineering work \(bucket new-issue\): deliver it/);
|
|
1769
|
+
});
|
|
1770
|
+
|
|
1771
|
+
it("#4398 #5152 an investigation whose question is deferred closes partial (completed), carried forward in the tracking issue", async () => {
|
|
1772
|
+
const k = { ...CONTRACT, preserve: [], requirements: [CONTRACT.requirements[0], { id: "R2", quote: "Existing callers of foo keep working.", disposition: "defer", why: "w", bucket: "owner:rotate the key" }] };
|
|
1753
1773
|
const w = world({ title: "investigate(stealth): which signal is rejected", contract: k, claims: [{ id: "R1", status: "implemented" }], reviews: [conf({}, k)] });
|
|
1754
1774
|
const r = await runShadow(w);
|
|
1755
1775
|
assert.equal(r.terminalReason, "merged"); assert.equal(r.close, "partial");
|
|
@@ -1791,7 +1811,7 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1791
1811
|
const ra = await runShadow(a);
|
|
1792
1812
|
assert.equal(ra.terminalReason, "merged"); assert.equal(ra.close, undefined);
|
|
1793
1813
|
assert.deepEqual(a.closed.map((x) => x[x.indexOf("--reason") + 1]), ["completed"]);
|
|
1794
|
-
const k = { ...CONTRACT, preserve: [], requirements: [CONTRACT.requirements[0], { id: "R2", quote: "Existing callers of foo keep working.", disposition: "defer", why: "w", bucket: "
|
|
1814
|
+
const k = { ...CONTRACT, preserve: [], requirements: [CONTRACT.requirements[0], { id: "R2", quote: "Existing callers of foo keep working.", disposition: "defer", why: "w", bucket: "owner:rotate the key" }] };
|
|
1795
1815
|
const b = world({ contract: k, claims: [{ id: "R1", status: "implemented" }], reviews: [conf({}, k)] });
|
|
1796
1816
|
await runShadow(b);
|
|
1797
1817
|
assert.deepEqual(b.closed.map((x) => x[x.indexOf("--reason") + 1]), ["completed"]);
|
|
@@ -3532,6 +3552,127 @@ describe("usage limit, lease takeover, worktree setup, run tmp (#4101-#4104)", (
|
|
|
3532
3552
|
assert.equal(sent.length, 1);
|
|
3533
3553
|
});
|
|
3534
3554
|
|
|
3555
|
+
// #5205: a rotator with pick() relaunches the limited phase pinned to another account (real claude + CLAUDE_CONFIG_DIR), no pause.
|
|
3556
|
+
const smartRotator = (o = {}) => { const marked = [], picks = [];
|
|
3557
|
+
return { ...fakeRotator({ accounts: [{ n: 1 }, { n: 2 }, { n: 3 }] }), marked, picks, accountOfPid: (pid) => pid - 100, realClaude: () => "/real/claude", configDir: (n) => `/h/.claude-${n}`,
|
|
3558
|
+
markLimited: (n, until) => { marked.push([n, until]); return true; },
|
|
3559
|
+
pick: ({ exclude }) => { picks.push([...exclude.keys()]); return o.none ? { account: null, earliestReset: o.none } : { account: [1, 2, 3].find((n) => !exclude.has(n)) ?? null, earliestReset: 7e6 }; } }; };
|
|
3560
|
+
const spawnAs = (w, err, times) => { const orig = w.io.runner; const sent = []; let n = 0;
|
|
3561
|
+
w.io.runner = async (c) => { if (c.role === "builder") { const acct = c.env?.CLAUDE_CONFIG_DIR ? Number(c.env.CLAUDE_CONFIG_DIR.split("-").at(-1)) : 1;
|
|
3562
|
+
c.onSpawn?.({ pid: 100 + acct }); sent.push({ prompt: c.prompt, resume: c.resume ?? null, bin: c.bin ?? null, dir: c.env?.CLAUDE_CONFIG_DIR ?? null }); if (n++ < times) throw err; } return orig(c); }; return sent; };
|
|
3563
|
+
|
|
3564
|
+
it("#5205 3 accounts, the first limited: the phase relaunches pinned to another account with no pause, rotations = 1", async () => {
|
|
3565
|
+
const w = world(); const sleeps = []; const progress = []; const dir = tmpDir("core-");
|
|
3566
|
+
const s0 = w.io.sleep; w.io.sleep = async (ms) => { sleeps.push(ms); return s0(ms); };
|
|
3567
|
+
const sent = spawnAs(w, limitErr({ resetAtEpochMs: 3 * 3600 * 1000, resetAt: "8:30pm" }), 1);
|
|
3568
|
+
const rot = smartRotator(); w.io.rotator = rot;
|
|
3569
|
+
const r = await run(w, { dir, onProgress: (p) => progress.push(p) });
|
|
3570
|
+
assert.equal(r.terminalReason, "merged");
|
|
3571
|
+
assert.equal(r.rotations, 1);
|
|
3572
|
+
assert.deepEqual(r.limited, [{ account: 1, until: 3 * 3600 * 1000 }]);
|
|
3573
|
+
assert.deepEqual(rot.marked, [[1, 3 * 3600 * 1000]], "the limited account is marked");
|
|
3574
|
+
assert.deepEqual(rot.picks[0], [], "#5236: the preflight pick before the first spawn");
|
|
3575
|
+
assert.deepEqual(rot.picks[1], [1], "the limited account is excluded");
|
|
3576
|
+
assert.deepEqual({ ...sent[1], bin: null, dir: null }, { ...sent[0], bin: null, dir: null }, "same prompt and resume");
|
|
3577
|
+
assert.equal(sent[1].bin, "/real/claude"); assert.equal(sent[1].dir, "/h/.claude-2");
|
|
3578
|
+
assert.equal(sleeps.includes(3 * 3600 * 1000), false);
|
|
3579
|
+
assert.equal(progress.some((p) => p.event === "phase_paused"), false);
|
|
3580
|
+
const log = readLog(dir, 7);
|
|
3581
|
+
assert.equal(log.some((e) => e.event === "PHASE_RATE_LIMITED"), false);
|
|
3582
|
+
assert.ok(log.some((e) => e.event === "PHASE_ACCOUNT_ROTATED" && e.from === 1 && e.to === 2));
|
|
3583
|
+
});
|
|
3584
|
+
|
|
3585
|
+
it("#5268 the shim sets the account after exec: the first read at spawn is null, the limit-time re-read excludes the limited account", async () => {
|
|
3586
|
+
const w = world(); const sent = spawnAs(w, limitErr({ resetAtEpochMs: 3 * 3600 * 1000, resetAt: "8:30pm" }), 1);
|
|
3587
|
+
const rot = smartRotator(); let reads = 0; const real = rot.accountOfPid; rot.accountOfPid = (pid) => (++reads === 1 ? null : real(pid)); w.io.rotator = rot;
|
|
3588
|
+
const r = await run(w);
|
|
3589
|
+
assert.equal(r.terminalReason, "merged");
|
|
3590
|
+
assert.deepEqual(rot.marked, [[1, 3 * 3600 * 1000]], "the account read late is marked limited");
|
|
3591
|
+
assert.deepEqual(rot.picks[1], [1], "and excluded from the next pick");
|
|
3592
|
+
assert.equal(sent[1].dir, "/h/.claude-2");
|
|
3593
|
+
});
|
|
3594
|
+
|
|
3595
|
+
it("#5205 every account limited: rotations stop at the account count; pick none defers with tokenbaton's earliest reset", async () => {
|
|
3596
|
+
const w = world();
|
|
3597
|
+
const sent = spawnAs(w, limitErr({ resetAtEpochMs: 3 * 3600 * 1000, resetAt: "8:30pm" }), 99);
|
|
3598
|
+
w.io.rotator = smartRotator();
|
|
3599
|
+
const r = await run(w);
|
|
3600
|
+
assert.equal(r.terminalReason, "deferred"); assert.equal(r.code, "quota.exhausted"); // #5236
|
|
3601
|
+
assert.equal(sent.length, 3, "one call per account, never the limited one again");
|
|
3602
|
+
assert.equal(r.resetAtEpochMs, 7e6, "held until the earliest reset pick() reports");
|
|
3603
|
+
assert.equal(r.rotations, 2);
|
|
3604
|
+
const w2 = world(); spawnAs(w2, limitErr({ resetAtEpochMs: 3600 * 1000 }), 99); w2.io.rotator = smartRotator({ none: 5 * 3600 * 1000 });
|
|
3605
|
+
const r2 = await run(w2);
|
|
3606
|
+
assert.equal(r2.code, "quota.exhausted"); assert.equal(r2.resetAtEpochMs, 5 * 3600 * 1000, "not the limited account's own reset");
|
|
3607
|
+
});
|
|
3608
|
+
|
|
3609
|
+
it("#5236 weekly limit with a reset >1h away re-picks and continues on an account with room, no pause", async () => {
|
|
3610
|
+
const w = world(); const sleeps = []; const s0 = w.io.sleep; w.io.sleep = async (ms) => { sleeps.push(ms); return s0(ms); };
|
|
3611
|
+
const sent = spawnAs(w, limitErr({ resetAtEpochMs: 30 * 3600 * 1000, resetAt: "Nov 9, 2pm" }), 1);
|
|
3612
|
+
w.io.rotator = smartRotator();
|
|
3613
|
+
const r = await run(w);
|
|
3614
|
+
assert.equal(r.terminalReason, "merged");
|
|
3615
|
+
assert.equal(sent[1].dir, "/h/.claude-2");
|
|
3616
|
+
assert.equal(sleeps.includes(30 * 3600 * 1000), false);
|
|
3617
|
+
});
|
|
3618
|
+
|
|
3619
|
+
it("#5236 no account has room: the lane never spawns, ends quota.exhausted (not backend.auth) with the earliest reset and a QUOTA_EXHAUSTED event", async () => {
|
|
3620
|
+
const w = world(); const dir = tmpDir("core-");
|
|
3621
|
+
const sent = spawnAs(w, new Error("unused"), 0);
|
|
3622
|
+
w.io.rotator = smartRotator({ none: 5 * 3600 * 1000 });
|
|
3623
|
+
const r = await run(w, { dir });
|
|
3624
|
+
assert.equal(r.terminalReason, "deferred");
|
|
3625
|
+
assert.equal(r.code, "quota.exhausted");
|
|
3626
|
+
assert.equal(r.resetAtEpochMs, 5 * 3600 * 1000);
|
|
3627
|
+
assert.equal(sent.length, 0, "no spawn through the shim (it would fall back to the default profile)");
|
|
3628
|
+
assert.ok(readLog(dir, 7).some((e) => e.event === "QUOTA_EXHAUSTED" && e.earliestReset === 5 * 3600 * 1000));
|
|
3629
|
+
});
|
|
3630
|
+
|
|
3631
|
+
it("#5236 --pick fails (the rotator throws): the lane never falls back to the default profile, ends quota.exhausted", async () => {
|
|
3632
|
+
const w = world(); const dir = tmpDir("core-");
|
|
3633
|
+
const sent = spawnAs(w, new Error("unused"), 0);
|
|
3634
|
+
w.io.rotator = { ...smartRotator({ none: 0 }), pick: () => { throw new Error("pick failed"); } };
|
|
3635
|
+
const r = await run(w, { dir });
|
|
3636
|
+
assert.equal(r.terminalReason, "deferred"); assert.equal(r.code, "quota.exhausted");
|
|
3637
|
+
assert.equal(sent.length, 0, "no spawn under the default profile");
|
|
3638
|
+
});
|
|
3639
|
+
|
|
3640
|
+
it("#5236 a login failure while the pool is exhausted is quota.exhausted, not backend.auth; with room it stays backend.auth", async () => {
|
|
3641
|
+
const mk = () => Object.assign(new Error("Failed to authenticate. API Error: 401"), { code: "CLI_BACKEND_FAILED", authFailure: true }); // fresh: the lane marks the error it defers
|
|
3642
|
+
const w = world(); spawnAs(w, mk(), 99);
|
|
3643
|
+
const rot = smartRotator(); let calls = 0; const pick = rot.pick;
|
|
3644
|
+
rot.pick = (a) => (calls++ === 0 ? pick(a) : { account: null, earliestReset: 4 * 3600 * 1000 }); // room at the preflight, none after the failure
|
|
3645
|
+
w.io.rotator = rot;
|
|
3646
|
+
const r = await run(w);
|
|
3647
|
+
assert.equal(r.code, "quota.exhausted");
|
|
3648
|
+
const w2 = world(); spawnAs(w2, mk(), 99); w2.io.rotator = smartRotator();
|
|
3649
|
+
assert.equal((await run(w2)).code, "backend.auth");
|
|
3650
|
+
});
|
|
3651
|
+
|
|
3652
|
+
it("#5205 sandbox (CS_CRED_BASE, no rotator): cs-cred claude --limited reports the limit and re-sends at once; its failure defers as before", async () => {
|
|
3653
|
+
const w = world(); const calls = [];
|
|
3654
|
+
const sent = captureBuilders(w, limitErr({ resetAtEpochMs: 3 * 3600 * 1000, resetAt: "8:30pm" }), 1);
|
|
3655
|
+
w.io.rotator = null; w.io.env = { CS_CRED_BASE: "http://agent/sandboxes/x/creds" }; w.io.credExec = (a) => { calls.push(a); return { status: 0 }; };
|
|
3656
|
+
const r = await run(w);
|
|
3657
|
+
assert.equal(r.terminalReason, "merged"); assert.equal(r.rotations, 1);
|
|
3658
|
+
assert.deepEqual(calls, [["claude", "--limited", String(3 * 3600)]]);
|
|
3659
|
+
assert.deepEqual(sent[1], sent[0]);
|
|
3660
|
+
const w2 = world(); captureBuilders(w2, limitErr({ resetAtEpochMs: 3 * 3600 * 1000, resetAt: "8:30pm" }), 99);
|
|
3661
|
+
w2.io.rotator = null; w2.io.env = { CS_CRED_BASE: "x" }; let n = 0; w2.io.credExec = () => { n++; return { status: 1 }; };
|
|
3662
|
+
const r2 = await run(w2);
|
|
3663
|
+
assert.equal(r2.code, "rate_limited"); assert.equal(n, 1, "a 429 from the router falls through to the existing defer");
|
|
3664
|
+
});
|
|
3665
|
+
|
|
3666
|
+
it("#5205 no rotator and no sandbox: the pause path is unchanged (no cs-cred, no rotation facts)", async () => {
|
|
3667
|
+
const w = world(); const sleeps = []; let cred = 0;
|
|
3668
|
+
const s0 = w.io.sleep; w.io.sleep = async (ms) => { sleeps.push(ms); return s0(ms); };
|
|
3669
|
+
failFirstBuilder(w, limitErr({ resetAtEpochMs: 90000, resetAt: "8:30pm" }));
|
|
3670
|
+
w.io.rotator = null; w.io.env = {}; w.io.credExec = () => { cred++; return { status: 0 }; };
|
|
3671
|
+
const r = await run(w);
|
|
3672
|
+
assert.equal(r.terminalReason, "merged"); assert.ok(sleeps.includes(90000));
|
|
3673
|
+
assert.equal(cred, 0); assert.equal(r.rotations, undefined); assert.equal(r.limited, undefined);
|
|
3674
|
+
});
|
|
3675
|
+
|
|
3535
3676
|
it("#4101 a non-limit runner error is still engine-error", async () => {
|
|
3536
3677
|
const w = world(); failFirstBuilder(w, new Error("boom"));
|
|
3537
3678
|
assert.equal((await run(w)).terminalReason, "engine-error");
|
|
@@ -4224,8 +4365,12 @@ describe("batch robustness (#4112-#4115)", () => {
|
|
|
4224
4365
|
const r = await run(w);
|
|
4225
4366
|
assert.equal([r.terminalReason, r.code].join("/"), "deferred/lease.held");
|
|
4226
4367
|
});
|
|
4227
|
-
it("#
|
|
4228
|
-
|
|
4368
|
+
it("#5202 a non-ff push no other lane owns ends engine-error engine.push_diverged, never needs-human", async () => {
|
|
4369
|
+
const r = await run(ownerProbe(world({ pushErrors: [NONFF] })));
|
|
4370
|
+
assert.equal([r.terminalReason, r.code].join("/"), "engine-error/engine.push_diverged");
|
|
4371
|
+
assert.match(r.detail, /non-fast-forward.*no other lane owns feat\/issue-7-lean/s);
|
|
4372
|
+
});
|
|
4373
|
+
it("#4920 any other permanent push rejection (protected branch) stays needs-human", async () => {
|
|
4229
4374
|
assert.equal((await run(ownerProbe(world({ pushErrors: ["remote: error: GH006: Protected branch update failed"] }), { open: [{ number: 4919 }] }))).terminalReason, "needs-human");
|
|
4230
4375
|
});
|
|
4231
4376
|
it("#4920 two sandbox lanes (pid 1) get distinct lease holders, and a lease another lane wrote meanwhile defers this lane", async () => {
|
|
@@ -5424,6 +5569,37 @@ describe("local-mode CI fix rounds at merge and declared pre-PR check commands (
|
|
|
5424
5569
|
assert.ok(n >= 2, "the invariant is rerun after the builder fix round");
|
|
5425
5570
|
});
|
|
5426
5571
|
|
|
5572
|
+
it("#5239 a guard failing only on the lane tree blocks the merge (ci.red), never merges", async () => {
|
|
5573
|
+
const w = world(); const ran = [];
|
|
5574
|
+
w.io.runCommand = async ({ command, cwd }) => { ran.push(cwd); return /basered-/.test(cwd) ? { rc: 0, output: "" } : { rc: 1, output: "bare 429 at app/routers/listing_feeds.py" }; };
|
|
5575
|
+
const r = await run(w, { verify: { invariants: ["bash scripts/guard.sh"] } });
|
|
5576
|
+
assert.equal(r.terminalReason, "needs-human"); assert.equal(r.code, "ci.red");
|
|
5577
|
+
assert.equal(w.merges.length, 0);
|
|
5578
|
+
assert.ok(ran.some((c) => /basered-/.test(c)), "the guard was also run on the base");
|
|
5579
|
+
});
|
|
5580
|
+
|
|
5581
|
+
it("#5239 a guard that also fails on the base defers the lane (base.red), comments on the introducing issue, no needs-human", async () => {
|
|
5582
|
+
const w = world(); const comments = [], gh = w.io.gh, git = w.io.git;
|
|
5583
|
+
w.io.runCommand = async () => ({ rc: 1, output: "bare 429 at app/routers/listing_feeds.py" });
|
|
5584
|
+
w.io.git = async (a, o) => (a[0] === "log" && a.includes("--format=%H%x1f%s%x1f%b") ? `${"a".repeat(40)}\x1ffeat: feeds (#39805)\x1f` : git(a, o));
|
|
5585
|
+
w.io.gh = async (a, o) => {
|
|
5586
|
+
if (a[0] === "issue" && a[1] === "view" && a[2] === "39805") return "OPEN";
|
|
5587
|
+
if (a[0] === "issue" && a[1] === "comment" && a[2] === "39805") { comments.push(a.at(-1)); return ""; }
|
|
5588
|
+
return gh(a, o);
|
|
5589
|
+
};
|
|
5590
|
+
const r = await run(w, { verify: { invariants: ["bash scripts/guard.sh"] } });
|
|
5591
|
+
assert.equal(r.terminalReason, "deferred"); assert.equal(r.code, "base.red");
|
|
5592
|
+
assert.equal(w.merges.length, 0);
|
|
5593
|
+
assert.equal(comments.length, 1); assert.match(comments[0], /FORGE:BASE_RED/);
|
|
5594
|
+
assert.equal(builders(w).length, 2, "no builder fix round spent on a base failure");
|
|
5595
|
+
});
|
|
5596
|
+
|
|
5597
|
+
it("#5239 verify.guard_block false keeps a failing invariant advisory", async () => {
|
|
5598
|
+
const w = world(); w.io.runCommand = async () => ({ rc: 1, output: "x" });
|
|
5599
|
+
const r = await run(w, { verify: { invariants: ["bash scripts/guard.sh"], guardBlock: false } });
|
|
5600
|
+
assert.notEqual(r.code, "base.red"); assert.notEqual(r.code, "ci.red");
|
|
5601
|
+
});
|
|
5602
|
+
|
|
5427
5603
|
it("pre-PR: a passing set adds no builder turn; no commands configured runs nothing", async () => {
|
|
5428
5604
|
const w = world(); let n = 0;
|
|
5429
5605
|
w.io.runCommand = async () => { n++; return { rc: 0, output: "" }; };
|
|
@@ -6741,6 +6917,36 @@ describe("explorer subagent (#4391)", () => {
|
|
|
6741
6917
|
});
|
|
6742
6918
|
});
|
|
6743
6919
|
|
|
6920
|
+
describe("experiment arm overrides (#5206)", () => {
|
|
6921
|
+
const capture = (w) => { const seen = []; const inner = w.io.runner; w.io.runner = async (c) => { seen.push({ role: c.role, agents: c.agents ?? null }); return inner(c); }; return seen; };
|
|
6922
|
+
// issue 7 hashes to arm "on" under id x0 and to "off" under id x2 (assignArm, sha1 of id:issue)
|
|
6923
|
+
const exp = (id) => parseExperiment({ id, arms: "on,off", "on.lean.explore": "on", "off.lean.explore": "off" });
|
|
6924
|
+
|
|
6925
|
+
it("R1/R3: the explorer runs only in the on arm; RUN_TERMINAL carries arm and the applied overrides", async () => {
|
|
6926
|
+
assert.equal(assignArm(exp("x0"), 7), "on"); assert.equal(assignArm(exp("x2"), 7), "off");
|
|
6927
|
+
const on = world(), seenOn = capture(on), dOn = tmpDir("core-");
|
|
6928
|
+
assert.equal((await run(on, { dir: dOn, experiment: exp("x0"), explore: { model: "claude-haiku-5-5" } })).terminalReason, "merged");
|
|
6929
|
+
assert.ok(seenOn.filter((s) => s.role === "builder").every((s) => s.agents?.explorer?.model === "claude-haiku-5-5"));
|
|
6930
|
+
const tOn = readLog(dOn, 7).find((e) => e.event === "RUN_TERMINAL");
|
|
6931
|
+
assert.deepEqual([tOn.experiment, tOn.arm, tOn.arm_overrides, tOn.explore], ["x0", "on", "lean.explore=on", "on"]);
|
|
6932
|
+
const off = world(), seenOff = capture(off), dOff = tmpDir("core-");
|
|
6933
|
+
assert.equal((await run(off, { dir: dOff, experiment: exp("x2"), explore: { mode: "on" } })).terminalReason, "merged");
|
|
6934
|
+
assert.ok(seenOff.every((s) => s.agents === null));
|
|
6935
|
+
const tOff = readLog(dOff, 7).find((e) => e.event === "RUN_TERMINAL");
|
|
6936
|
+
assert.deepEqual([tOff.arm, tOff.arm_overrides, tOff.explore], ["off", "lean.explore=off", "off"]);
|
|
6937
|
+
assert.ok(readLog(dOff, 7).filter((e) => e.event === "PHASE_ATTEMPT_USAGE").every((e) => e.arm === "off" && e.arm_overrides === "lean.explore=off"));
|
|
6938
|
+
});
|
|
6939
|
+
|
|
6940
|
+
it("R4: no experiment: prompts and RUN_TERMINAL carry no arm fields", async () => {
|
|
6941
|
+
const w = world(), d = tmpDir("core-");
|
|
6942
|
+
await run(w, { dir: d, explore: { mode: "off" } });
|
|
6943
|
+
const t = readLog(d, 7).find((e) => e.event === "RUN_TERMINAL");
|
|
6944
|
+
assert.ok(!("arm" in t) && !("arm_overrides" in t) && !("experiment" in t));
|
|
6945
|
+
const x = world(); await run(x, { explore: { mode: "off" } });
|
|
6946
|
+
assert.deepEqual(builders(w).map((c) => c[4]), builders(x).map((c) => c[4]));
|
|
6947
|
+
});
|
|
6948
|
+
});
|
|
6949
|
+
|
|
6744
6950
|
describe("e2e merge gate (#4403)", () => {
|
|
6745
6951
|
const SPECS = ["src/foo.js", "test/foo.test.js", "e2e/foo.spec.ts"];
|
|
6746
6952
|
const RUN = "https://github.com/o/r/actions/runs/777/job/1";
|
|
@@ -7347,10 +7553,35 @@ describe("#4450 light lane: one builder session, derived contract, upgrade to th
|
|
|
7347
7553
|
const plan = w.calls.indexOf(builders(w)[1]);
|
|
7348
7554
|
// each fake notes w.calls.length when called, i.e. the index the next call takes: <= plan means before the plan call
|
|
7349
7555
|
assert.ok(w.over.hot.some((i) => i <= plan) && w.over.pack.some((i) => i <= plan), JSON.stringify({ plan, ...w.over }));
|
|
7350
|
-
|
|
7556
|
+
const light = w.calls.indexOf(builders(w)[0]);
|
|
7557
|
+
assert.equal(w.over.hot.filter((i) => i <= light).length, 1, "#5209: only the eligibility-signal call precedes the light session");
|
|
7558
|
+
assert.ok(w.over.hot.some((i) => i > light && i <= plan), "the upgrade recomputes the plan facts after the light session");
|
|
7351
7559
|
assert.ok(w.over.structure.length >= 1);
|
|
7352
7560
|
assert.equal(events(dir, "RUN_TERMINAL")[0].light, false);
|
|
7353
7561
|
});
|
|
7562
|
+
it("#5209 shadow mode: LIGHT_ELIGIBILITY carries signals and the hotspot reason; the lane keeps the full shape", async () => {
|
|
7563
|
+
const w = lworld(), dir = tmpDir("light-5209-shadow-");
|
|
7564
|
+
w.io.hotspots = async () => ({ enabled: true, file_lines: 2000, growth_lines: 150, files: [{ path: "src/foo.js", lines: 2400, commits_90d: 25, over: true, excluded: false, growth: 0 }] });
|
|
7565
|
+
const r = await run(w, { dir });
|
|
7566
|
+
assert.equal(r.terminalReason, "merged");
|
|
7567
|
+
const e = events(dir, "LIGHT_ELIGIBILITY")[0];
|
|
7568
|
+
assert.equal(e.mode, "shadow");
|
|
7569
|
+
assert.equal(e.verdict, "ineligible");
|
|
7570
|
+
assert.equal(e.light, false);
|
|
7571
|
+
assert.ok(e.reasons.some((x) => x.code === "hotspot" && /src\/foo\.js \(2400 lines\)/.test(x.detail)), JSON.stringify(e.reasons));
|
|
7572
|
+
const sig = e.signals.map((x) => x.code);
|
|
7573
|
+
for (const c of ["repro", "files_named", "churn_high", "hotspot", "size_none"]) assert.ok(sig.includes(c), `${c} in ${sig}`);
|
|
7574
|
+
assert.match(builders(w)[0][4], /PLANNING ONLY/, "plan call present");
|
|
7575
|
+
assert.equal(events(dir, "LIGHT_DONE").length + events(dir, "LIGHT_UPGRADE").length, 0);
|
|
7576
|
+
});
|
|
7577
|
+
it("#5209 mode on: an eligible light try still gets no hotspot build rule in its builder prompt", async () => {
|
|
7578
|
+
const w = lworld(), dir = tmpDir("light-5209-on-");
|
|
7579
|
+
w.io.hotspots = async () => ({ enabled: true, file_lines: 2000, growth_lines: 150, files: [{ path: "src/foo.js", lines: 120, commits_90d: 3, over: false, excluded: false, growth: 0 }] });
|
|
7580
|
+
await run(w, { dir, ...ON });
|
|
7581
|
+
assert.equal(events(dir, "LIGHT_ELIGIBILITY")[0].verdict, "eligible");
|
|
7582
|
+
assert.equal(events(dir, "LIGHT_DONE").length, 1);
|
|
7583
|
+
assert.ok(!/Don't grow a file over/.test(builders(w)[0][4]), "no hotspotBuildRule in the light prompt");
|
|
7584
|
+
});
|
|
7354
7585
|
it("#4451 a full lane (light off) keeps its context-pack, structure and hotspot calls", async () => {
|
|
7355
7586
|
const w = overhead(), dir = tmpDir("light-over-off-");
|
|
7356
7587
|
await run(w, { dir, light: { mode: "off" }, contextPack: { mode: "on" } });
|
|
@@ -7497,3 +7728,52 @@ describe("prompt budgets (#4969)", () => {
|
|
|
7497
7728
|
assert.ok(approxTokens(moved) <= 1650, `implement prompt from a deep checkout is ${approxTokens(moved)} of 1650 tokens`);
|
|
7498
7729
|
});
|
|
7499
7730
|
});
|
|
7731
|
+
|
|
7732
|
+
describe("#5250 intake host triage", () => {
|
|
7733
|
+
const hostBody = "## Acceptance Criteria\n\n- [ ] Measured clear rate on live production traffic is above 50%\n- [ ] Root-cause capture from a real browser is attached\n";
|
|
7734
|
+
it("an issue whose criteria are all live-production or real-browser work ends host-task with no builder run", async () => {
|
|
7735
|
+
const w = world({ body: hostBody });
|
|
7736
|
+
const r = await run(w);
|
|
7737
|
+
assert.equal(r.terminalReason, "host-task");
|
|
7738
|
+
assert.ok(w.edits.some((e) => e.includes("--add-label") && e.includes("host-task")), JSON.stringify(w.edits));
|
|
7739
|
+
assert.ok(w.comments.some((c) => String(c.body ?? c).includes("FORGE:HOST_TASK")), "FORGE:HOST_TASK comment");
|
|
7740
|
+
assert.equal(w.builderN, 0);
|
|
7741
|
+
});
|
|
7742
|
+
it("a code issue is unaffected", async () => {
|
|
7743
|
+
const w = world({ body: "## Acceptance Criteria\n\n- [ ] foo no longer breaks\n" });
|
|
7744
|
+
assert.notEqual((await run(w)).terminalReason, "host-task");
|
|
7745
|
+
});
|
|
7746
|
+
});
|
|
7747
|
+
|
|
7748
|
+
describe("#5237 relaxation gate", () => {
|
|
7749
|
+
const rescue = "diff --git a/src/foo.js b/src/foo.js\n@@ -1,0 +5,1 @@\n+ if (looksThin(page)) return true; // rescue\n";
|
|
7750
|
+
const negTest = "diff --git a/test/foo.test.js b/test/foo.test.js\n@@ -1,0 +1,1 @@\n+ assert.equal(isBenign(cookieChallenge), false);\n";
|
|
7751
|
+
const withV = (w) => {
|
|
7752
|
+
const orig = w.io.runner; w.vcalls = [];
|
|
7753
|
+
w.io.runner = async (c) => {
|
|
7754
|
+
if (c.role !== "verifier") return orig(c);
|
|
7755
|
+
w.vcalls.push(c);
|
|
7756
|
+
return { text: "```json\n{\"findings\":[]}\n```", sessionId: "ver", usage: { input_tokens: 3, output_tokens: 1 }, costUsd: 0.01, durationMs: 300, turns: 2, model: c.model };
|
|
7757
|
+
};
|
|
7758
|
+
return w;
|
|
7759
|
+
};
|
|
7760
|
+
it("relaxation without a negative test blocks (relaxation_untested) in a risk path", async () => {
|
|
7761
|
+
const w = withV(world({ contract: { ...CONTRACT, preserve: [] }, reviews: [conf(), conf(), conf()] })); w.diffText = rescue;
|
|
7762
|
+
const r = await run(w, { dir: tmpDir("relax-"), reviewTrigger: { mode: "shadow", riskPaths: ["src/**"] } });
|
|
7763
|
+
assert.equal(w.merges.length, 0); assert.equal(r.code, "conformance.unimplemented");
|
|
7764
|
+
});
|
|
7765
|
+
it("a negative test lets it through, and the verifier runs even with review.verifier off, fed the hunk", async () => {
|
|
7766
|
+
const w = withV(world({ contract: { ...CONTRACT, preserve: [] }, reviews: [conf(), conf()] })); w.diffText = rescue + negTest;
|
|
7767
|
+
const dir = tmpDir("relax-");
|
|
7768
|
+
const r = await run(w, { dir, reviewTrigger: { mode: "shadow", riskPaths: ["src/**"] } });
|
|
7769
|
+
assert.equal(r.terminalReason, "merged");
|
|
7770
|
+
assert.equal(w.vcalls.length, 1);
|
|
7771
|
+
assert.match(w.vcalls[0].prompt, /<relaxation_checks>[\s\S]*src\/foo\.js:5/);
|
|
7772
|
+
assert.ok(readLog(dir, 7).some((e) => e.event === "RELAXATION_DETECTED"));
|
|
7773
|
+
});
|
|
7774
|
+
it("no declared risk glob: no relaxation check, no verifier", async () => {
|
|
7775
|
+
const w = withV(world({ contract: { ...CONTRACT, preserve: [] }, reviews: [conf()] })); w.diffText = rescue;
|
|
7776
|
+
assert.equal((await run(w, { dir: tmpDir("relax-") })).terminalReason, "merged");
|
|
7777
|
+
assert.equal(w.vcalls.length, 0);
|
|
7778
|
+
});
|
|
7779
|
+
});
|
package/bin/lean/light.mjs
CHANGED
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
* trigger (oversized diff, repro not red on base, two test failures, risk path, public-API-shape change from #4449)
|
|
9
9
|
* moves the lane to the full pipeline. forge.yaml `lean.light` {mode: off|shadow (default)|on, max_lines: 40,
|
|
10
10
|
* max_files: 2}: off is never eligible, shadow reports the verdict without changing the lane shape, on lets an eligible
|
|
11
|
-
* issue run light (lane wiring: #4450).
|
|
11
|
+
* issue run light (lane wiring: #4450). #5209: a named non-test file over maintenance.hotspot.file_lines (scripts/hotspots.sh
|
|
12
|
+
* `over`) is a hard `hotspot` reason, and every evaluated signal (repro, named files, churn, hotspot, risk path, docs/config/
|
|
13
|
+
* chore labels, size) is recorded in `signals`, which never changes the verdict: `forgedock stats --depth` attributes lane
|
|
14
|
+
* outcomes to them. Pure: no I/O, no model call.
|
|
12
15
|
*/
|
|
13
16
|
import { riskClassOf, riskPathHits } from "./review-trigger.mjs";
|
|
14
17
|
import { classifyPath } from "./routing.mjs";
|
|
@@ -18,6 +21,8 @@ import { postDeployOnly } from "./prefilter.mjs";
|
|
|
18
21
|
|
|
19
22
|
export const LIGHT_MODES = Object.freeze(["off", "shadow", "on"]);
|
|
20
23
|
export const LIGHT_DEFAULTS = Object.freeze({ mode: "shadow", maxLines: 40, maxFiles: 2 });
|
|
24
|
+
/** #5209: commits in 90 days (scripts/hotspots.sh commits_90d) at or above which a named file records a `churn_high` signal. */
|
|
25
|
+
export const CHURN_HIGH = 20;
|
|
21
26
|
|
|
22
27
|
const posInt = (v) => { const s = String(v ?? "").trim(); return /^\d+$/.test(s) && Number(s) > 0 ? Number(s) : null; };
|
|
23
28
|
|
|
@@ -55,6 +60,17 @@ const FENCE_RE = /^\s*(```|~~~)/m;
|
|
|
55
60
|
const DECISION_LABEL_RE = /^(type[:/]\s*)?(decision|needs-decision|product-decision|rfc|adr)$/i;
|
|
56
61
|
const DECISION_TITLE_RE = /^\s*(decision|rfc|adr)[(:]/i;
|
|
57
62
|
const POST_DEPLOY_LABELS = new Set(["post-deploy", "awaiting-promotion", "awaiting-due"]);
|
|
63
|
+
const KIND_LABELS = [["label_docs", /^(type[:/]\s*)?(docs|documentation)$/i], ["label_config", /^(type[:/]\s*)?(config|configuration)$/i], ["label_chore", /^(type[:/]\s*)?chore$/i]];
|
|
64
|
+
|
|
65
|
+
/** #5209: hotspots.sh rows by path ({path, lines, commits_90d, over}); anything malformed is skipped. */
|
|
66
|
+
function hotIndex(hotspots) {
|
|
67
|
+
const m = new Map();
|
|
68
|
+
for (const h of Array.isArray(hotspots) ? hotspots : []) {
|
|
69
|
+
const p = h && typeof h === "object" ? String(h.path ?? "").trim().replace(/^\.\//, "") : "";
|
|
70
|
+
if (p) m.set(p, h);
|
|
71
|
+
}
|
|
72
|
+
return m;
|
|
73
|
+
}
|
|
58
74
|
|
|
59
75
|
/** Risk details for `files`: a built-in risk word or a declared review.risk_paths glob. */
|
|
60
76
|
function riskDetails(files, riskPaths) {
|
|
@@ -72,24 +88,49 @@ function riskDetails(files, riskPaths) {
|
|
|
72
88
|
* Light-lane eligibility of one issue: {mode, verdict, eligible, light, reasons:[{code, detail}]}.
|
|
73
89
|
* verdict: off | eligible | ineligible (a hard reason: files, size, risk_path, investigate, post_deploy, decision) |
|
|
74
90
|
* ambiguous (only soft reasons: no_repro, files_unknown). `light` is the lane shape: true only in mode on when eligible.
|
|
91
|
+
* #5209: `hotspots` are scripts/hotspots.sh `files` rows; a predicted non-test file with `over` adds the hard `hotspot`
|
|
92
|
+
* reason. `signals` lists every evaluated signal (codes: repro|no_repro, files_named, churn_high, hotspot, risk_path,
|
|
93
|
+
* label_docs|label_config|label_chore, size_S|size_M|size_L|size_none) and never changes the verdict.
|
|
75
94
|
*/
|
|
76
|
-
export function lightEligibility({ title = "", body = "", labels = [], predictedFiles = [], riskPaths = [], cfg = {} } = {}) {
|
|
95
|
+
export function lightEligibility({ title = "", body = "", labels = [], predictedFiles = [], riskPaths = [], hotspots = [], cfg = {} } = {}) {
|
|
77
96
|
const c = cfgOf(cfg);
|
|
78
|
-
if (c.mode === "off") return { mode: "off", verdict: "off", eligible: false, light: false, reasons: [] };
|
|
79
|
-
const hard = [], soft = [];
|
|
97
|
+
if (c.mode === "off") return { mode: "off", verdict: "off", eligible: false, light: false, reasons: [], signals: [] };
|
|
98
|
+
const hard = [], soft = [], signals = [];
|
|
80
99
|
const text = String(body ?? "").replace(/<!--[\s\S]*?-->/g, " ");
|
|
81
|
-
if (!FENCE_RE.test(text) && !REPRO_RE.test(text))
|
|
100
|
+
if (!FENCE_RE.test(text) && !REPRO_RE.test(text)) {
|
|
101
|
+
soft.push({ code: "no_repro", detail: "no repro, expected behaviour or code block in the body" });
|
|
102
|
+
signals.push({ code: "no_repro", detail: "no repro, expected behaviour or code block in the body" });
|
|
103
|
+
} else signals.push({ code: "repro", detail: "repro, expected behaviour or code block in the body" });
|
|
82
104
|
|
|
83
105
|
const files = uniquePaths(predictedFiles);
|
|
84
106
|
const nonTest = files.filter((f) => classifyPath(f) !== "test");
|
|
85
107
|
if (nonTest.length > c.maxFiles) hard.push({ code: "files", detail: `${nonTest.length} predicted non-test files (max ${c.maxFiles})` });
|
|
86
108
|
else if (!nonTest.length) soft.push({ code: "files_unknown", detail: "no predicted non-test files" });
|
|
109
|
+
signals.push({ code: "files_named", detail: String(nonTest.length) });
|
|
110
|
+
|
|
111
|
+
const hot = hotIndex(hotspots);
|
|
112
|
+
for (const f of nonTest) {
|
|
113
|
+
const h = hot.get(f);
|
|
114
|
+
if (!h) continue;
|
|
115
|
+
const commits = Number(h.commits_90d);
|
|
116
|
+
if (Number.isFinite(commits) && commits >= CHURN_HIGH) signals.push({ code: "churn_high", detail: `${f} (${commits} commits/90d)` });
|
|
117
|
+
if (h.over === true) {
|
|
118
|
+
const d = `${f} (${Number(h.lines) || 0} lines)`;
|
|
119
|
+
hard.push({ code: "hotspot", detail: d });
|
|
120
|
+
signals.push({ code: "hotspot", detail: d });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
87
123
|
|
|
88
124
|
const names = labelNames(labels);
|
|
89
125
|
const size = laneSize({ labels: names });
|
|
90
126
|
if (size && size !== "S") hard.push({ code: "size", detail: `size:${size}` });
|
|
127
|
+
signals.push({ code: size ? `size_${size}` : "size_none", detail: size ? `size:${size}` : "no size label" });
|
|
128
|
+
for (const [code, re] of KIND_LABELS) {
|
|
129
|
+
const n = names.find((x) => re.test(x));
|
|
130
|
+
if (n) signals.push({ code, detail: `label ${n}` });
|
|
131
|
+
}
|
|
91
132
|
|
|
92
|
-
for (const d of riskDetails(files, riskPaths)) hard.push({ code: "risk_path", detail: d });
|
|
133
|
+
for (const d of riskDetails(files, riskPaths)) { hard.push({ code: "risk_path", detail: d }); signals.push({ code: "risk_path", detail: d }); }
|
|
93
134
|
|
|
94
135
|
if (isInvestigation(title)) hard.push({ code: "investigate", detail: "investigate( issue" });
|
|
95
136
|
const pdLabel = names.find((n) => POST_DEPLOY_LABELS.has(n.toLowerCase()));
|
|
@@ -101,7 +142,7 @@ export function lightEligibility({ title = "", body = "", labels = [], predicted
|
|
|
101
142
|
|
|
102
143
|
const verdict = hard.length ? "ineligible" : soft.length ? "ambiguous" : "eligible";
|
|
103
144
|
const eligible = verdict === "eligible";
|
|
104
|
-
return { mode: c.mode, verdict, eligible, light: c.mode === "on" && eligible, reasons: sortReasons([...hard, ...soft]) };
|
|
145
|
+
return { mode: c.mode, verdict, eligible, light: c.mode === "on" && eligible, reasons: sortReasons([...hard, ...soft]), signals: sortReasons(signals) };
|
|
105
146
|
}
|
|
106
147
|
|
|
107
148
|
const lineCount = (v) => { const n = Number(v); return Number.isFinite(n) && n > 0 ? n : 0; };
|
package/bin/lean/light.test.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import assert from "node:assert/strict";
|
|
|
5
5
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
|
-
import { LIGHT_MODES, LIGHT_DEFAULTS, parseLightConfig, lightEligibility, upgradeTriggers } from "./light.mjs";
|
|
8
|
+
import { CHURN_HIGH, LIGHT_MODES, LIGHT_DEFAULTS, parseLightConfig, lightEligibility, upgradeTriggers } from "./light.mjs";
|
|
9
9
|
import { readLight } from "../engine-cli.mjs";
|
|
10
10
|
|
|
11
11
|
const ON = { mode: "on", maxLines: 40, maxFiles: 2 };
|
|
@@ -40,8 +40,9 @@ describe("parseLightConfig (#4448)", () => {
|
|
|
40
40
|
|
|
41
41
|
describe("lightEligibility rules (#4448)", () => {
|
|
42
42
|
it("accepts a well-specified size:S issue with 1-2 predicted files", () => {
|
|
43
|
-
const r = lightEligibility(issue());
|
|
43
|
+
const { signals, ...r } = lightEligibility(issue());
|
|
44
44
|
assert.deepEqual(r, { mode: "on", verdict: "eligible", eligible: true, light: true, reasons: [] });
|
|
45
|
+
assert.ok(Array.isArray(signals), "#5209 signals are recorded alongside");
|
|
45
46
|
});
|
|
46
47
|
it("repro or expected behaviour: present accepts, absent is ambiguous (never a model call)", () => {
|
|
47
48
|
for (const body of ["Repro: `x()` throws", "Expected result: 3", "```\nboom\n```", "actual output differs"]) assert.equal(lightEligibility(issue({ body })).verdict, "eligible", body);
|
|
@@ -104,7 +105,7 @@ describe("lightEligibility rules (#4448)", () => {
|
|
|
104
105
|
|
|
105
106
|
describe("lightEligibility modes (#4448)", () => {
|
|
106
107
|
it("off never returns eligible, even for a fully eligible issue", () => {
|
|
107
|
-
assert.deepEqual(lightEligibility(issue({ cfg: { mode: "off" } })), { mode: "off", verdict: "off", eligible: false, light: false, reasons: [] });
|
|
108
|
+
assert.deepEqual(lightEligibility(issue({ cfg: { mode: "off" } })), { mode: "off", verdict: "off", eligible: false, light: false, reasons: [], signals: [] });
|
|
108
109
|
});
|
|
109
110
|
it("shadow returns the verdict without changing the lane shape", () => {
|
|
110
111
|
const r = lightEligibility(issue({ cfg: { mode: "shadow" } }));
|
|
@@ -121,6 +122,39 @@ describe("lightEligibility modes (#4448)", () => {
|
|
|
121
122
|
});
|
|
122
123
|
});
|
|
123
124
|
|
|
125
|
+
describe("lightEligibility signals and the hotspot reason (#5209)", () => {
|
|
126
|
+
const sig = (r) => r.signals.map((x) => x.code);
|
|
127
|
+
const hot = (o = {}) => ({ path: "src/chunk.py", lines: 2400, commits_90d: 1, over: false, ...o });
|
|
128
|
+
it("a predicted non-test file over the hotspot limit is a hard hotspot reason; a test file or an under-limit file is not", () => {
|
|
129
|
+
const r = lightEligibility(issue({ hotspots: [hot({ over: true })] }));
|
|
130
|
+
assert.equal(r.verdict, "ineligible");
|
|
131
|
+
assert.deepEqual(codes(r), ["hotspot"]);
|
|
132
|
+
assert.equal(r.reasons[0].detail, "src/chunk.py (2400 lines)");
|
|
133
|
+
assert.ok(sig(r).includes("hotspot"));
|
|
134
|
+
assert.equal(lightEligibility(issue({ hotspots: [hot()] })).verdict, "eligible");
|
|
135
|
+
assert.equal(lightEligibility(issue({ hotspots: [hot({ path: "tests/test_chunk.py", over: true })] })).verdict, "eligible");
|
|
136
|
+
assert.equal(lightEligibility(issue({ hotspots: [null, "x", { over: true }] })).verdict, "eligible", "malformed rows are skipped");
|
|
137
|
+
});
|
|
138
|
+
it("records repro/no_repro, files_named, churn_high at CHURN_HIGH, labels and size", () => {
|
|
139
|
+
const r = lightEligibility(issue({ labels: ["Docs", "type:config", "chore", "size:S"], hotspots: [hot({ commits_90d: CHURN_HIGH })] }));
|
|
140
|
+
assert.deepEqual(sig(r).sort(), ["churn_high", "files_named", "label_chore", "label_config", "label_docs", "repro", "size_S"]);
|
|
141
|
+
assert.equal(r.signals.find((x) => x.code === "files_named").detail, "1");
|
|
142
|
+
assert.ok(!sig(lightEligibility(issue({ hotspots: [hot({ commits_90d: CHURN_HIGH - 1 })] }))).includes("churn_high"));
|
|
143
|
+
const n = lightEligibility(issue({ body: "broken", labels: ["bug"] }));
|
|
144
|
+
assert.ok(sig(n).includes("no_repro") && sig(n).includes("size_none") && !sig(n).includes("repro"));
|
|
145
|
+
assert.ok(sig(lightEligibility(issue({ labels: ["size:M"] }))).includes("size_M"));
|
|
146
|
+
assert.ok(sig(lightEligibility(issue({ predictedFiles: ["src/auth/token.py"] }))).includes("risk_path"));
|
|
147
|
+
});
|
|
148
|
+
it("signals never change the verdict, eligible or light", () => {
|
|
149
|
+
const base = lightEligibility(issue());
|
|
150
|
+
for (const o of [{ labels: ["bug", "size:S", "docs"] }, { hotspots: [hot({ commits_90d: 99 })] }]) {
|
|
151
|
+
const r = lightEligibility(issue(o));
|
|
152
|
+
assert.deepEqual([r.verdict, r.eligible, r.light, r.reasons], [base.verdict, base.eligible, base.light, base.reasons], JSON.stringify(o));
|
|
153
|
+
}
|
|
154
|
+
assert.deepEqual(lightEligibility(issue({ cfg: { mode: "off" }, hotspots: [hot({ over: true })] })).signals, []);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
124
158
|
describe("upgradeTriggers (#4448)", () => {
|
|
125
159
|
const quiet = { diff: numstat(["src/chunk.py", 30, 10], ["tests/test_chunk.py", 200]), repro: RED, testFailures: 1, cfg: ON };
|
|
126
160
|
it("no trigger on a small red-green diff", () => {
|