forgedock 1.61.2 → 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 +159 -17
- 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 +85 -9
- package/bin/lean/conformance.test.mjs +155 -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 +72 -4
- package/bin/lean/execution.mjs +41 -7
- package/bin/lean/execution.test.mjs +99 -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 +376 -79
- package/bin/lean/lean.test.mjs +710 -22
- 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 +40 -3
- 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/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 +210 -14
- 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/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
package/bin/lean/lean.test.mjs
CHANGED
|
@@ -7,9 +7,11 @@ import { laneBackendId } from "./limits.mjs";
|
|
|
7
7
|
import { parseExperiment, assignArm } from "../experiment.mjs";
|
|
8
8
|
import assert from "node:assert/strict";
|
|
9
9
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
10
|
+
import { CHECKS_CLI } from "./prompts.mjs"; // #5727
|
|
10
11
|
import { normaliseDecision, writeDecisionIndex } from "./decisions.mjs"; // #5338
|
|
11
12
|
import { execFileSync } from "node:child_process";
|
|
12
13
|
import { writeFileSync, existsSync, readFileSync, mkdirSync, symlinkSync, readdirSync, chmodSync } from "node:fs";
|
|
14
|
+
import * as nodeFs from "node:fs";
|
|
13
15
|
import { join } from "node:path";
|
|
14
16
|
import os from "node:os";
|
|
15
17
|
import { syncBuiltinESMExports } from "node:module";
|
|
@@ -31,6 +33,7 @@ import { makeRunTmp, wrapLaneLimits, laneCapNotice, systemdRunAvailable, makeLea
|
|
|
31
33
|
import { retrying, ghCacheRetry, refreshAuthOnce, GH_AUTH_RE, PUSH_TRANSIENT_RE } from "./retry.mjs";
|
|
32
34
|
import { checkAdmission, hostParallelism } from "./admission.mjs";
|
|
33
35
|
import { OUTCOME_CODES, ENV_VALIDATE_TIMEOUT, ENV_VALIDATE_PLACEMENT, classifyNeedsHuman } from "../engine/outcome-codes.mjs";
|
|
36
|
+
import { parsePagesConfig } from "./pagegate.mjs";
|
|
34
37
|
import * as refactorMod from "./refactor.mjs";
|
|
35
38
|
import { readAdmission, readConformanceMode, readReviewIncomplete, readEnvConfig, readContextPack } from "../engine-cli.mjs";
|
|
36
39
|
import { prepareToolchain } from "./toolchain.mjs";
|
|
@@ -42,8 +45,22 @@ const INSTALL_PATH_RE = /\S*?[\\/](?=bin[\\/][\w.\\/-]+\.mjs)/g;
|
|
|
42
45
|
const approxTokens = (s) => rawTokens(String(s).replaceAll(INSTALL_ROOT, "<root>").replace(INSTALL_PATH_RE, "<root>/"));
|
|
43
46
|
// orchestrateFromCli opens the host lane registry (#4191): keep it in a temp dir.
|
|
44
47
|
process.env.FORGEDOCK_SCHED_DIR = tmpDir("lean-sched-");
|
|
48
|
+
// The fake world keys its files by POSIX paths ("/wt/lean-7"); on a win32 host path.join/dirname would turn them into
|
|
49
|
+
// "\wt\lean-7" and every full-lane test would miss them. Keep POSIX-rooted inputs POSIX; real Windows paths are untouched.
|
|
50
|
+
if (process.platform === "win32") {
|
|
51
|
+
const pathMod = (await import("node:path")).default;
|
|
52
|
+
const posixy = (p) => typeof p === "string" && p.startsWith("/") && !p.includes("\\");
|
|
53
|
+
const { join: wJoin, dirname: wDirname } = pathMod;
|
|
54
|
+
pathMod.join = (...a) => (posixy(a[0]) ? pathMod.posix.join(...a) : wJoin(...a));
|
|
55
|
+
pathMod.dirname = (p) => (posixy(p) ? pathMod.posix.dirname(p) : wDirname(p));
|
|
56
|
+
// Tests isolate ~/.forge by setting HOME; win32 os.homedir() reads USERPROFILE, so honour HOME as POSIX does
|
|
57
|
+
const realHome = os.homedir; os.homedir = () => process.env.HOME || realHome();
|
|
58
|
+
syncBuiltinESMExports();
|
|
59
|
+
}
|
|
45
60
|
|
|
46
61
|
const WT = "/wt/lean-7";
|
|
62
|
+
/** Windows: `path.join` yields backslashes; the fake fs keys are POSIX paths. */
|
|
63
|
+
const posix = (p) => String(p).replace(/\\/g, "/");
|
|
47
64
|
/** #5333: the engine appends the stage-stamp rule to every builder prompt; strip it to compare against the bare template. */
|
|
48
65
|
const unstamp = (s) => String(s).replace(/\n\nStage notes: make the first line[^\n]*/, "");
|
|
49
66
|
const STAGE_MD = {
|
|
@@ -106,12 +123,15 @@ function world(o = {}) {
|
|
|
106
123
|
if (k === "pr view" && a.at(-1) === "state" && a.at(-2) === "--json") return JSON.stringify({ state: o.prState ?? "OPEN" });
|
|
107
124
|
if (a[0] === "api" && a.includes("PATCH") && a.some((x) => /\/comments\/9000$/.test(x))) { statusLogical(w, a[a.indexOf("-f") + 1].replace(/^body=/, "")); w.statusPatches.push(a); return "{}"; } // #5592: the one FORGE:STATUS comment
|
|
108
125
|
if (a[0] === "api" && a.includes("PATCH")) { w.patches.push(a); return "{}"; }
|
|
126
|
+
if (a[0] === "api" && o.activeJson && a.some((x) => /contents\/active\.json\?ref=/.test(x))) return JSON.stringify({ content: Buffer.from(JSON.stringify(o.activeJson)).toString("base64") }); // #5776: the _active ledger read
|
|
127
|
+
if (a[0] === "api" && o.ghApi) { const r = o.ghApi(a); if (r != null) return r; } // #5751: subject search and PR file lists
|
|
109
128
|
if (a[0] === "api") return a.some((x) => /\/comments$/.test(x)) ? (w.issueComments ?? []).map((c) => JSON.stringify(c)).join("\n") : "";
|
|
129
|
+
if (k === "pr list" && a.some((x) => /statusCheckRollup/.test(x))) return JSON.stringify(typeof o.releasePrs === "function" ? o.releasePrs(w) : (o.releasePrs ?? [])); // #5709: release PR lookup
|
|
110
130
|
if (k === "pr list") return JSON.stringify(w.prList);
|
|
111
131
|
if (k === "repo view") return `${o.defaultBranch ?? "main"}\n`;
|
|
112
132
|
if (k === "issue view" && a.includes("milestone")) { w.seq.push("lane"); return JSON.stringify({ milestone: o.milestone ? { title: o.milestone } : null }); }
|
|
113
133
|
if (k === "issue view" && o.issueBodies && a[2] === "7" && a.some((x) => String(x).startsWith("number,title,body,state,comments"))) { const b = o.issueBodies.length > 1 ? o.issueBodies.shift() : o.issueBodies[0]; return JSON.stringify({ number: 7, title: o.title ?? "foo breaks", body: b, state: "OPEN", comments: o.viewComments ?? [], ...(o.labels ? { labels: o.labels } : {}) }); }
|
|
114
|
-
if (k === "issue view") return JSON.stringify({ number: Number(a[2]), title: a[2] === "7" && o.title ? o.title : "foo breaks", body: a[2] === "7" && o.body ? o.body : ISSUE_BODY, state: w.issueStates?.[a[2]] ?? "OPEN", comments: [], ...(o.labels && a[2] === "7" ? { labels: o.labels } : {}) });
|
|
134
|
+
if (k === "issue view") return JSON.stringify({ number: Number(a[2]), title: a[2] === "7" && o.title ? o.title : "foo breaks", body: a[2] === "7" && o.body ? o.body : ISSUE_BODY, state: w.issueStates?.[a[2]] ?? "OPEN", comments: a[2] === "7" ? (o.viewComments ?? []) : [], ...(o.labels && a[2] === "7" ? { labels: o.labels } : {}) });
|
|
115
135
|
if (k === "pr edit") { w.prEdits.push(a); return ""; }
|
|
116
136
|
if (k === "label create") { w.labelCreates = [...(w.labelCreates ?? []), a]; return ""; }
|
|
117
137
|
if (k === "issue comment" && w.commentErrors.length) throw new Error(w.commentErrors.shift());
|
|
@@ -150,6 +170,9 @@ function world(o = {}) {
|
|
|
150
170
|
if (a[0] === "rev-parse" && a[1] === "HEAD^{tree}") return "0".repeat(40);
|
|
151
171
|
if (a.includes("commit-tree")) return "c".repeat(40);
|
|
152
172
|
if (a[0] === "diff" && a.includes("--diff-filter=A")) return (w.added ?? []).join("\0"); // #4590: files the branch added vs the base
|
|
173
|
+
if (a[0] === "diff-index" && a.includes("--cached")) return (w.stagedDeletions ?? []).map((p) => `D\0${p}\0`).join(""); // #5819: the checkpoint's staged deletions
|
|
174
|
+
if (a[0] === "ls-tree" && w.stagedDeletions) return a.slice(a.indexOf("--") + 1).filter((p) => !(w.laneAdded ?? []).includes(p)).join("\0"); // #5819: on the base unless the lane added it
|
|
175
|
+
if (a[0] === "checkout" && a.includes("HEAD") && w.stagedDeletions) { w.restoredPaths = [...(w.restoredPaths ?? []), ...a.slice(a.indexOf("--") + 1)]; return ""; }
|
|
153
176
|
if (a[0] === "rm" && a[1] === "--cached" && w.added) w.added = w.added.filter((f) => !a.includes(f));
|
|
154
177
|
if (a[0] === "diff" && a.includes("--diff-filter=U")) return w.conflictFiles.join("\n");
|
|
155
178
|
if (a[0] === "diff" && a[1] === "--check") return "";
|
|
@@ -207,7 +230,7 @@ function world(o = {}) {
|
|
|
207
230
|
waitCiGreen: async () => (w.waits.length ? w.waits.shift() : { rc: 0, text: `CI_GATE_HEAD: ${w.head}` }),
|
|
208
231
|
transitionLabel: async (n, s) => { w.labels.push(s); w.seq.push(`label:${s}`); },
|
|
209
232
|
...(o.procs ? { proc: { inDir: async () => o.procs, alive: (pid) => w.alive.has(pid), kill: (pid, sig) => { w.kills.push([pid, sig]); w.seq.push(`kill-${sig}`); if (sig === "SIGKILL" || !o.stubborn) w.alive.delete(pid); } } } : {}),
|
|
210
|
-
fs: { ...(o.wtExists ? { exists: async (p) => p.startsWith("/wt/lean-7") } : {}), stat: async (p) => (p in w.files ? { mtimeMs: w.mtimes[p] ?? 1 } : null), read: async (p) => { if (!(p in w.files)) throw new Error("ENOENT"); return w.files[p]; }, append: async (p, t) => { w.files[p] = (w.files[p] ?? "") + t; }, write: async (p, t) => { w.files[p] = t; }},
|
|
233
|
+
fs: { ...(o.wtExists ? { exists: async (p) => posix(p).startsWith("/wt/lean-7") } : {}), stat: async (p) => (posix(p) in w.files ? { mtimeMs: w.mtimes[posix(p)] ?? 1 } : null), read: async (p) => { if (!(posix(p) in w.files)) throw new Error("ENOENT"); return w.files[posix(p)]; }, append: async (p, t) => { w.files[posix(p)] = (w.files[posix(p)] ?? "") + t; }, write: async (p, t) => { w.files[posix(p)] = t; }},
|
|
211
234
|
fileFollowups: async ({ parent, items }) => { w.followups.push({ parent, items }); if (o.followupError) throw Object.assign(new Error(o.followupError), { stdout: o.followupStdout ?? "" });
|
|
212
235
|
if (o.followupRet) return o.followupRet(w.followups.length, items);
|
|
213
236
|
if (w.followups.length <= (o.followupFailTimes ?? 0)) throw new Error("DEFERRED_LOOKUP=FAILED"); if (w.followups.length <= (o.followupMissingTimes ?? 0)) return {}; return Object.fromEntries(items.filter((i) => !(o.followupSkip ?? []).some((q) => JSON.stringify(i).includes(q))).map((i) => [i.key, o.followupIssue ?? 900])); },
|
|
@@ -238,7 +261,7 @@ describe("core work-on", () => {
|
|
|
238
261
|
assert.match(w.comments[1], /^<!-- FORGE:INVESTIGATION -->\n<!-- FORGE:VALIDATE -->\n## Investigation Report\n\*\*Verdict\*\*: CONFIRMED/);
|
|
239
262
|
assert.match(w.comments[2], /^<!-- FORGE:CONTRACT -->\n<!-- FORGE:PLAN -->\n## Builder Contract \(frozen `[0-9a-f]{12}`\)/, "PLAN stays as an alias marker");
|
|
240
263
|
assert.match(w.comments[2], /\| R1 \| foo must handle a null argument without throwing\. \| deliver \|/);
|
|
241
|
-
assert.match(w.comments[2], /<summary>contract\.json \(sha256 [0-9a-f]{12}, issue [0-9a-f]{12}\)<\/summary>/);
|
|
264
|
+
assert.match(w.comments[2], /<summary>contract\.json \(sha256 [0-9a-f]{12}, issue [0-9a-f]{12}, base staging\)<\/summary>/); // #5811: the base it was planned on
|
|
242
265
|
assert.match(w.comments[3], /## Implementation Complete\n\*\*Branch:\*\* `feat\/issue-7-lean`\n\*\*Files changed:\*\*\n- `src\/foo.js`\n- `test\/foo.test.js`/);
|
|
243
266
|
assert.match(w.comments[4], /## Conformance Review\n\*\*Verdict:\*\* CONFORMS/);
|
|
244
267
|
assert.match(w.comments[4], /\| R1 \| implemented \| src\/foo.js:3 \| V1 \|/);
|
|
@@ -332,6 +355,19 @@ describe("core work-on", () => {
|
|
|
332
355
|
assert.ok(traj(w)[0].includes("| Close | issue closed (completed) |"));
|
|
333
356
|
});
|
|
334
357
|
|
|
358
|
+
it("#5734 builder already-fixed with a trusted prod-failure decision does not close and goes needs-human", async () => {
|
|
359
|
+
const dec = { authorAssociation: "OWNER", author: { login: "op" }, url: "https://github.com/o/r/issues/7#issuecomment-5",
|
|
360
|
+
body: "<!-- FORGE:DECISION -->\nRequeue: verified failing in prod after #40727 went live: Reddit success rate ~0%." };
|
|
361
|
+
const w = world({ changed: [], viewComments: [dec], result: { status: "already-fixed", summary: "PR #40727 is an ancestor", evidence: ["a.js:1"], tests: [] } });
|
|
362
|
+
const r = await run(w);
|
|
363
|
+
assert.equal(r.terminalReason, "needs-human");
|
|
364
|
+
assert.equal(w.closed.length, 0);
|
|
365
|
+
assert.ok(w.comments.some((c) => c.includes("FORGE:NEEDS_HUMAN") && c.includes("failing in production") && c.includes("issuecomment-5")));
|
|
366
|
+
const w2 = world({ changed: [], viewComments: [{ ...dec, authorAssociation: "NONE", author: { login: "rando" } }], result: { status: "already-fixed", summary: "done", evidence: ["a.js:1"], tests: [] } });
|
|
367
|
+
assert.equal((await run(w2)).terminalReason, "invalid", "an untrusted author's claim does not block the close");
|
|
368
|
+
assert.equal(w2.closed.length, 1);
|
|
369
|
+
});
|
|
370
|
+
|
|
335
371
|
it("a failed needs-human comment is recorded as an anomaly and the lane still ends needs-human (#4905)", async () => {
|
|
336
372
|
const w = world({ changed: [], result: { status: "invalid", summary: "trust me", evidence: [], tests: [] } });
|
|
337
373
|
const gh = w.io.gh;
|
|
@@ -913,6 +949,43 @@ describe("core work-on", () => {
|
|
|
913
949
|
assert.ok(!l.edits.some((e) => e.includes("--add-label") && e.includes("needs-human")), JSON.stringify(l.edits));
|
|
914
950
|
});
|
|
915
951
|
|
|
952
|
+
describe("#5727 frozen forgedock install paths", () => {
|
|
953
|
+
const remote = { placement: { where: "remote", reason: "mode remote" } };
|
|
954
|
+
const H41009 = "/home/dev/.local/lib/node_modules/forgedock/bin/lean/checks.mjs"; // #41009's frozen V5 names the host install
|
|
955
|
+
const STALE = existsSync(H41009) ? "/opt/absent-5727/lib/node_modules/forgedock/bin/lean/checks.mjs" : H41009; // on that host itself, an equally stale path
|
|
956
|
+
const V5 = `node ${STALE} --base origin/staging`;
|
|
957
|
+
const contract = { ...CONTRACT, validate: [...CONTRACT.validate, { id: "V5", command: V5 }] };
|
|
958
|
+
const stale = (cmd) => (String(cmd).includes(STALE) ? { rc: 1, output: `node:internal/modules/cjs/loader\nError: Cannot find module '${STALE}'\n code: 'MODULE_NOT_FOUND'` } : { rc: 0, output: "" });
|
|
959
|
+
it("#5727 remote preflight runs a stale forgedock checks path as this install's path", async () => {
|
|
960
|
+
const w = world({ contract }); const seen = [];
|
|
961
|
+
w.io.probeCommand = async (a) => { seen.push(a.command); return stale(a.command); };
|
|
962
|
+
w.io.preflightRun = async (a) => { seen.push(a.command); return stale(a.command); };
|
|
963
|
+
const r = await run(w, { dir: tmpDir("lean-5727a-"), ...remote });
|
|
964
|
+
assert.notEqual(r.code, "env.tool_missing", r.detail);
|
|
965
|
+
assert.notEqual(r.terminalReason, "needs-human", r.detail);
|
|
966
|
+
assert.ok(builders(w).length >= 2, "the builder implements");
|
|
967
|
+
assert.ok(seen.some((c) => c.includes(CHECKS_CLI)), JSON.stringify(seen));
|
|
968
|
+
assert.ok(!seen.some((c) => c.includes(STALE)), "no runner saw the stale path");
|
|
969
|
+
});
|
|
970
|
+
it("#5727 a frozen contract carries no absolute forgedock install path", async () => {
|
|
971
|
+
const w = world({ contract });
|
|
972
|
+
await run(w, { dir: tmpDir("lean-5727b-") });
|
|
973
|
+
const posted = w.comments.find((x) => x.includes("FORGE:CONTRACT"));
|
|
974
|
+
assert.ok(posted, "contract posted");
|
|
975
|
+
assert.doesNotMatch(posted, /\/forgedock\/bin\//);
|
|
976
|
+
assert.match(posted, /\$FORGEDOCK_CHECKS_CLI --base origin\/staging/);
|
|
977
|
+
});
|
|
978
|
+
it("#5727 light-lane and precheck runners receive the resolved forgedock path", async () => {
|
|
979
|
+
const w = world({ contract }); const ran = [];
|
|
980
|
+
w.io.preflightRun = async (a) => { ran.push(a.command); return stale(a.command); }; // a local (host) placement runs it too
|
|
981
|
+
const r = await run(w, { dir: tmpDir("lean-5727c-"), placement: { where: "local", reason: "x" } });
|
|
982
|
+
assert.notEqual(r.code, "env.tool_missing", r.detail);
|
|
983
|
+
const v5 = ran.filter((c) => /--base origin\/staging/.test(c));
|
|
984
|
+
assert.ok(v5.length >= 1, JSON.stringify(ran));
|
|
985
|
+
assert.ok(v5.every((c) => c.includes(CHECKS_CLI) && !c.includes("$FORGEDOCK")), JSON.stringify(v5));
|
|
986
|
+
});
|
|
987
|
+
});
|
|
988
|
+
|
|
916
989
|
describe("#5652 in-sandbox recipe install", () => {
|
|
917
990
|
const remote = { placement: { where: "remote", reason: "mode remote" } };
|
|
918
991
|
const withTool = (tool) => ({ ...CONTRACT, validate: [...CONTRACT.validate, { id: "V2", command: `${tool} check x` }] });
|
|
@@ -927,6 +1000,16 @@ describe("core work-on", () => {
|
|
|
927
1000
|
assert.notEqual(r.code, "env.tool_missing");
|
|
928
1001
|
assert.notEqual(r.terminalReason, "needs-human");
|
|
929
1002
|
});
|
|
1003
|
+
it("#5764 a python3 miss maps to the python recipe: installed in the sandbox and re-probed, no needs-human", async () => {
|
|
1004
|
+
const w = world({ contract: withTool("python3") }); let ok = false; const cmds = [];
|
|
1005
|
+
const base = w.io.runCommand;
|
|
1006
|
+
w.io.runCommand = async (a) => { if (/apt-get install/.test(a.command) && /python3 python3-venv/.test(a.command)) { cmds.push(a.command); ok = true; return { rc: 0 }; } return base(a); };
|
|
1007
|
+
probing(w, "python3", () => ok);
|
|
1008
|
+
const r = await run(w, { dir: tmpDir("lean-5764a-"), ...remote });
|
|
1009
|
+
assert.equal(cmds.length, 1);
|
|
1010
|
+
assert.notEqual(r.code, "env.tool_missing");
|
|
1011
|
+
assert.doesNotMatch(w.comments.map((c) => c.body ?? c).join("\n"), /no lane_tools recipe/);
|
|
1012
|
+
});
|
|
930
1013
|
it("a tool with no recipe ends the lane naming it, saying no recipe exists and pointing to execution.lane_tools", async () => {
|
|
931
1014
|
const w = world({ contract: withTool("zzcheck") }); probing(w, "zzcheck", () => false);
|
|
932
1015
|
const r = await run(w, { dir: tmpDir("lean-5652b-"), ...remote });
|
|
@@ -934,6 +1017,7 @@ describe("core work-on", () => {
|
|
|
934
1017
|
const txt = w.comments.map((c) => c.body ?? c).join("\n");
|
|
935
1018
|
assert.match(txt, /lacks zzcheck, and no lane_tools recipe exists for it/);
|
|
936
1019
|
assert.match(txt, /execution\.lane_tools/);
|
|
1020
|
+
assert.match(txt, /Known recipes: .*shellcheck/);
|
|
937
1021
|
});
|
|
938
1022
|
it("a failed in-sandbox install ends the lane with the stderr tail", async () => {
|
|
939
1023
|
const w = world({ contract: withTool("promtool") }); probing(w, "promtool", () => false);
|
|
@@ -1030,7 +1114,7 @@ describe("core work-on", () => {
|
|
|
1030
1114
|
});
|
|
1031
1115
|
|
|
1032
1116
|
it("builder uses the CLI default model; reviewer is read-only Sonnet unless configured", async () => {
|
|
1033
|
-
const w = world(); await run(w);
|
|
1117
|
+
const w = world(); await run(w, { builderRouting: { mode: "off" } }); // #5810: routing on starts the plan on the provisional tier
|
|
1034
1118
|
assert.equal(builders(w)[0][3], null);
|
|
1035
1119
|
assert.equal(builders(w)[0][5], false);
|
|
1036
1120
|
assert.equal(reviewers(w)[0][3], "claude-sonnet-5-5");
|
|
@@ -1541,6 +1625,63 @@ describe("worktree salvage and orphaned processes (#4162)", () => {
|
|
|
1541
1625
|
assert.equal((await run(w)).terminalReason, "merged");
|
|
1542
1626
|
assert.equal(salvageRefs(w).length, 0);
|
|
1543
1627
|
});
|
|
1628
|
+
// #5825: a lane folder that is not this repo's worktree is never salvaged or written to with git
|
|
1629
|
+
const NOT_LINKED = { ok: false, why: "the lane folder has no .git link (not a git worktree)", evidence: { worktree: WT } };
|
|
1630
|
+
const gitIdx5825 = (w, f) => w.calls.findIndex((c) => c[0] === "git" && f(c.slice(1)));
|
|
1631
|
+
it("#5825 a leftover lane folder without a .git link is quarantined (no git salvage in it) and a fresh registered worktree is added", async () => {
|
|
1632
|
+
const dir = tmpDir("core-5825-q-");
|
|
1633
|
+
const w = world({ wtExists: true, salvageTrees: [T1] });
|
|
1634
|
+
let gone = false; const moved = [];
|
|
1635
|
+
w.io.fs.exists = async (p) => !gone && p.startsWith(WT);
|
|
1636
|
+
const git0 = w.io.git;
|
|
1637
|
+
w.io.git = async (a, o) => { if (a[0] === "worktree" && a[1] === "add") gone = false; return git0(a, o); };
|
|
1638
|
+
w.io.confine = { verify: async () => (moved.length ? { ok: true } : NOT_LINKED), quarantine: async ({ wt }) => { moved.push(wt); gone = true; return "/wt/.quarantine/lean-7-1"; } };
|
|
1639
|
+
assert.equal((await run(w, { dir })).terminalReason, "merged");
|
|
1640
|
+
assert.deepEqual(moved, [WT]);
|
|
1641
|
+
const add = gitIdx5825(w, (a) => a[0] === "worktree" && a[1] === "add");
|
|
1642
|
+
assert.ok(add > 0, "a fresh worktree is added");
|
|
1643
|
+
assert.ok(!w.calls.slice(0, add).some((c) => c[0] === "git" && ["add", "write-tree", "commit-tree"].includes(c[1])), "nothing is staged in the unlinked folder");
|
|
1644
|
+
assert.equal(salvageRefs(w).length, 0);
|
|
1645
|
+
const q = readLog(dir, 7).find((e) => e.event === "WORKTREE_QUARANTINED");
|
|
1646
|
+
assert.equal(q.to, "/wt/.quarantine/lean-7-1"); assert.match(q.why, /no \.git link/);
|
|
1647
|
+
});
|
|
1648
|
+
|
|
1649
|
+
it("#5825 a lane folder git does not resolve to its own worktree stops engine-error before any git write, with evidence", async () => {
|
|
1650
|
+
const dir = tmpDir("core-5825-s-");
|
|
1651
|
+
const w = world({ dirty: true });
|
|
1652
|
+
w.io.confine = { verify: async () => ({ ok: false, why: "git resolves the lane folder to toplevel /repo, not the lane worktree", evidence: { worktree: WT, toplevel: "/repo", common_dir: "/repo/.git", repo_common_dir: "/repo/.git" } }), quarantine: async () => null };
|
|
1653
|
+
const r = await run(w, { dir });
|
|
1654
|
+
assert.equal(r.terminalReason, "engine-error");
|
|
1655
|
+
const add = gitIdx5825(w, (a) => a[0] === "worktree" && a[1] === "add");
|
|
1656
|
+
assert.ok(add >= 0);
|
|
1657
|
+
assert.ok(!w.calls.slice(add + 1).some((c) => c[0] === "git" && ["add", "commit", "push", "rm", "reset", "checkout"].includes(c[1])), "no git write after the worktree add");
|
|
1658
|
+
assert.equal(builders(w).length, 0, "no builder session starts");
|
|
1659
|
+
const ev = readLog(dir, 7);
|
|
1660
|
+
const nc = ev.find((e) => e.event === "WORKTREE_NOT_CONFINED");
|
|
1661
|
+
assert.equal(nc.toplevel, "/repo"); assert.equal(nc.at, "lane start");
|
|
1662
|
+
assert.equal(ev.find((e) => e.event === "RUN_TERMINAL").reason, "engine-error");
|
|
1663
|
+
});
|
|
1664
|
+
|
|
1665
|
+
it("#5825 a lane folder that loses its link mid-run: the checkpoint stages and pushes nothing, the lane ends engine-error", async () => {
|
|
1666
|
+
const dir = tmpDir("core-5825-c-");
|
|
1667
|
+
const w = world({ dirty: true, waits: [{ rc: 1, text: "lint failed" }] });
|
|
1668
|
+
w.io.confine = { verify: async () => (builders(w).length ? NOT_LINKED : { ok: true }), quarantine: async () => null };
|
|
1669
|
+
const r = await run(w, { dir, mergeWait: "all" });
|
|
1670
|
+
assert.equal(r.terminalReason, "engine-error");
|
|
1671
|
+
const first = w.calls.findIndex((c) => c[0] === "runner" && c[1] === "builder");
|
|
1672
|
+
assert.ok(!w.calls.slice(first).some((c) => c[0] === "git" && ["add", "commit", "push"].includes(c[1]) && !c.includes("--delete")), "no add/commit/push once the link is gone");
|
|
1673
|
+
assert.ok(readLog(dir, 7).some((e) => e.event === "WORKTREE_NOT_CONFINED"));
|
|
1674
|
+
});
|
|
1675
|
+
|
|
1676
|
+
it("#5825 lane child processes and lane git calls carry GIT_CEILING_DIRECTORIES = the worktree parent", async () => {
|
|
1677
|
+
const w = world(); const envs = [];
|
|
1678
|
+
const git0 = w.io.git;
|
|
1679
|
+
w.io.git = async (a, o) => { if (o?.cwd === WT) { envs.push([a.join(" "), o.env ?? {}]); } return git0(a, o); };
|
|
1680
|
+
assert.equal((await run(w)).terminalReason, "merged");
|
|
1681
|
+
assert.deepEqual(envs.filter(([, e]) => e.GIT_CEILING_DIRECTORIES?.split(":")[0] !== "/wt").map(([a]) => a), [], "every lane git call is ceiled");
|
|
1682
|
+
assert.ok(envs.length > 0);
|
|
1683
|
+
assert.ok(w.envs.filter(Boolean).every((e) => e.GIT_CEILING_DIRECTORIES?.split(":")[0] === "/wt"), "every runner session is ceiled");
|
|
1684
|
+
});
|
|
1544
1685
|
|
|
1545
1686
|
it("procsInDir reads cwd links from a /proc tree and skips this process and its ancestors", () => {
|
|
1546
1687
|
const root = tmpDir("proc-"), wtDir = tmpDir("wt-");
|
|
@@ -2268,8 +2409,8 @@ describe("hotspot prevention (forge#4195): plan facts, build rule, unexempted gr
|
|
|
2268
2409
|
assert.equal(hotspotBuildRule(null), ""); assert.equal(hotspotBuildRule(facts([], { enabled: false })), "");
|
|
2269
2410
|
const plan = builderPlanPrompt(7) + hotspotPlanNote(facts([HOT, { ...HOT, path: "a/b.py" }, { ...HOT, path: "c/d.py" }]));
|
|
2270
2411
|
// 2650: #5557 (classification record line) on top of the base's growth. 1850: #4404 (verify out_of_band) and #4396 (split size rule) grew the plan prompt to ~1803 tokens on CI paths; 1900: #4589 (check timeout is not a block, one block-rule line). 2050: #4724 (deferred-row bucket rule). 1675 (hotspot case): #5284 (rubric prod_parity clause). 2375/1825: #5345 (self-check and pitfall lines).
|
|
2271
|
-
assert.ok(approxTokens(plan) <=
|
|
2272
|
-
assert.ok(approxTokens(builderImplementPrompt() + hotspotBuildRule(facts([]))) <=
|
|
2412
|
+
assert.ok(approxTokens(plan) <= 2700, `plan prompt with hotspots is ${approxTokens(plan)} tokens`);
|
|
2413
|
+
assert.ok(approxTokens(builderImplementPrompt() + hotspotBuildRule(facts([]))) <= 2025, `implement prompt with the hotspot rule is ${approxTokens(builderImplementPrompt() + hotspotBuildRule(facts([])))} of 2025 tokens`); // 2025: #5752 (mechanism supersedes, negative examples, outcome evidence) // 1600: #4591 (never hand-name migration files) and #4596 (i18n translate rule), one line each; 1650: #4726 (e2e rule) // 1925: #5760 (CI budget rule)
|
|
2273
2414
|
});
|
|
2274
2415
|
|
|
2275
2416
|
it("#4519 generated_paths: both prompts name the globs (even with the gate off), and an amendment adding one blocks", async () => {
|
|
@@ -2373,7 +2514,8 @@ describe("bug lanes freeze a red-green repro_test (#4271)", () => {
|
|
|
2373
2514
|
const prev = process.env.FORGE_HOST_PARALLELISM; process.env.FORGE_HOST_PARALLELISM = "3";
|
|
2374
2515
|
try { assert.equal((await run(w, { envSetup: "make setup", precheck: { commands: ["npm run lint"] } })).terminalReason, "merged"); }
|
|
2375
2516
|
finally { if (prev === undefined) delete process.env.FORGE_HOST_PARALLELISM; else process.env.FORGE_HOST_PARALLELISM = prev; }
|
|
2376
|
-
const lane = { UV_CACHE_DIR: "/c/uv", TMPDIR: w.envs[0].TMPDIR, FORGE_HOST_PARALLELISM: "3", FORGE_LANE_WORKTREE: "1", PATH: "/rt/toolchain/bin:/usr/bin" };
|
|
2517
|
+
const lane = { UV_CACHE_DIR: "/c/uv", TMPDIR: w.envs[0].TMPDIR, FORGE_HOST_PARALLELISM: "3", FORGE_LANE_WORKTREE: "1", GIT_CEILING_DIRECTORIES: w.envs[0].GIT_CEILING_DIRECTORIES, FORGEDOCK_CHECKS_CLI: CHECKS_CLI, FORGEDOCK_ENTRY_CLI: FORGEDOCK_CLI, PATH: "/rt/toolchain/bin:/usr/bin" };
|
|
2518
|
+
assert.equal(lane.GIT_CEILING_DIRECTORIES.split(":")[0], "/wt", "#5825: lane children are ceiled at the worktree parent");
|
|
2377
2519
|
assert.match(lane.TMPDIR, /\/runs\/7-/, "the builder ran with the run TMPDIR");
|
|
2378
2520
|
assert.deepEqual(w.rgCalls.map((x) => x.env), [lane], "red-green gets the lane env, not the daemon's");
|
|
2379
2521
|
assert.deepEqual(ran.map((a) => [a.command, a.env]), [["npm run lint", lane], ["node --test test/foo.test.js", lane]]);
|
|
@@ -2807,8 +2949,8 @@ describe("comment templates", () => {
|
|
|
2807
2949
|
|
|
2808
2950
|
it("plan and implement prompts carry the stage templates and the contract schema within budget", () => {
|
|
2809
2951
|
const plan = builderPlanPrompt(7), impl = builderImplementPrompt();
|
|
2810
|
-
assert.ok(approxTokens(plan) <=
|
|
2811
|
-
assert.ok(approxTokens(impl) <=
|
|
2952
|
+
assert.ok(approxTokens(plan) <= 2650, `plan prompt is ${approxTokens(plan)} tokens`); // 2550: first-pass check-id + dependency-block rule; 2500: #5445 (Test plan heading); 2475: staging; 2375: #5432 (duplicate rule); 2075: #5284 (prod_parity plan line); 2050: #4769 (activation-row rule); 2000: #4730 (owner-step remainder); 1950: #4724 (deferred-row bucket rule) // 2325: #5333 (git stash rule + stage stamp line)
|
|
2953
|
+
assert.ok(approxTokens(impl) <= 2000, `implement prompt is ${approxTokens(impl)} of 2000 tokens`); // 2000: #5752 // 1650: #4726 e2e rule; 1550: #4596 i18n translate rule // 1850: #5333 (git stash rule + stage stamp) // 1900: #5760 (CI budget rule)
|
|
2812
2954
|
for (const h of ["### What Was Claimed", "### What We Found", "### Root Cause", "### Affected Files", "### Sibling Sweep", "### History", "### Recommendation", "### Related Issues", "### Test plan",
|
|
2813
2955
|
"investigation.md", "contract.json", "PLANNING ONLY", '"requirements"', '"deliverables"', '"preserve"', '"validate"', "verbatim", "defer", "post-deploy"]) assert.ok(plan.includes(h), h);
|
|
2814
2956
|
for (const h of ["### Approach", "### Changes", "### Acceptance Criteria Status", "### Verification", "### Notes", "implementation.md", "result.json",
|
|
@@ -2906,6 +3048,41 @@ describe("merge_wait policy", () => {
|
|
|
2906
3048
|
assert.ok(traj(w)[0].includes("carried forward across the CI fix round"));
|
|
2907
3049
|
});
|
|
2908
3050
|
|
|
3051
|
+
describe("#5768 a validate with no row after a merge-time CI fix round is re-run, not parked", () => {
|
|
3052
|
+
const ciWorld = (o) => {
|
|
3053
|
+
const w = world(o); w.reran = []; w.ran = [];
|
|
3054
|
+
w.io.requiredChecks = async () => ["build"];
|
|
3055
|
+
w.io.rerunFailedJobs = async (id) => { w.reran.push(id); };
|
|
3056
|
+
w.io.checkStates = async () => [{ name: "build", state: w.fixed ? "success" : "failure", url: RUN(77, w.reran.length + 1) }];
|
|
3057
|
+
w.io.failedLogs = async () => { w.fixed = true; return "boom"; };
|
|
3058
|
+
return w;
|
|
3059
|
+
};
|
|
3060
|
+
const fixRun = (w, dir) => run(w, { dir, verify: { ...parseVerify({}), maxRounds: 1 } });
|
|
3061
|
+
|
|
3062
|
+
it("re-runs the unrecorded validate once on the fix head, records the row and merges", async () => {
|
|
3063
|
+
const w = ciWorld({ validation: [], resumeValidation: [] }), dir = tmpDir("core-");
|
|
3064
|
+
const base = w.io.runCommand; w.io.runCommand = async (a) => { w.ran.push(a.command); return base ? base(a) : { rc: 0, output: "" }; };
|
|
3065
|
+
const r = await fixRun(w, dir);
|
|
3066
|
+
assert.equal(r.terminalReason, "merged", r.reason);
|
|
3067
|
+
const written = JSON.parse(w.files[`${WT}/.forge-lean/result.json`]);
|
|
3068
|
+
assert.ok(written.validation.some((x) => x.id === "V1" && x.rerun === true && x.exit === 0), "the re-run row is recorded");
|
|
3069
|
+
assert.ok(traj(w)[0].includes("the engine re-ran"));
|
|
3070
|
+
});
|
|
3071
|
+
|
|
3072
|
+
it("carries the recorded row forward and re-runs only the validate that has none", async () => {
|
|
3073
|
+
const contract = { ...CONTRACT, validate: [...CONTRACT.validate, { id: "V2", command: "node test/second.test.js" }] };
|
|
3074
|
+
const v1 = [{ id: "V1", command: "node --test test/foo.test.js", exit: 0 }];
|
|
3075
|
+
const w = ciWorld({ contract, validation: v1, resumeValidation: [] }), dir = tmpDir("core-");
|
|
3076
|
+
const base = w.io.runCommand; w.io.runCommand = async (a) => { w.ran.push(a.command); return base ? base(a) : { rc: 0, output: "" }; };
|
|
3077
|
+
const r = await fixRun(w, dir);
|
|
3078
|
+
assert.equal(r.terminalReason, "merged", r.reason);
|
|
3079
|
+
const written = JSON.parse(w.files[`${WT}/.forge-lean/result.json`]);
|
|
3080
|
+
assert.deepEqual(written.validation.map((x) => [x.id, x.carried === true, x.rerun === true]), [["V1", true, false], ["V2", false, true]]);
|
|
3081
|
+
assert.equal(w.ran.filter((c) => /second/.test(c)).length >= 1, true, "V2 was re-run by the engine");
|
|
3082
|
+
assert.equal(w.ran.filter((c) => /second/.test(c) === false && /foo/.test(c)).length, 0, "V1 was not re-run");
|
|
3083
|
+
});
|
|
3084
|
+
});
|
|
3085
|
+
|
|
2909
3086
|
describe("#5692 CI events start the fix round before the check completes", () => {
|
|
2910
3087
|
/** `build` stays pending until the builder's fix lands; `evts` is what the router has for the head. */
|
|
2911
3088
|
const evWorld = (evts) => {
|
|
@@ -3878,6 +4055,57 @@ describe("base-sync (#4100)", () => {
|
|
|
3878
4055
|
assert.ok(!w.edits.some((e) => e.includes("needs-human")));
|
|
3879
4056
|
});
|
|
3880
4057
|
|
|
4058
|
+
const RELEASE_PENDING = [{ number: 40, baseRefName: "main", statusCheckRollup: [{ __typename: "CheckRun", status: "IN_PROGRESS" }] }];
|
|
4059
|
+
it("#5709 merge.held_release: holds while the release PR CI runs, merges after it ends", async () => {
|
|
4060
|
+
let polls = 0, mergesWhileHeld = 0;
|
|
4061
|
+
const w = world({ releasePrs: (ww) => { mergesWhileHeld += ww.merges.length; return ++polls <= 3 ? RELEASE_PENDING : []; } });
|
|
4062
|
+
const progress = [];
|
|
4063
|
+
const r = await run(w, { onProgress: (p) => progress.push(p) });
|
|
4064
|
+
assert.equal(r.terminalReason, "merged");
|
|
4065
|
+
assert.ok(polls >= 4, "re-checked until the release PR finished");
|
|
4066
|
+
assert.equal(mergesWhileHeld, 0, "no merge into staging while held");
|
|
4067
|
+
assert.equal(w.merges.length, 1);
|
|
4068
|
+
assert.ok(progress.some((p) => p.phase === "merge" && /merge\.held_release: release PR #40/.test(p.detail ?? "")), "merge.held_release recorded");
|
|
4069
|
+
});
|
|
4070
|
+
it("#5776 the manual merge hold holds a lane whose io has no api (gh-backed ledger read)", async () => {
|
|
4071
|
+
const w = world({ releasePrs: [], activeJson: { mergeHold: { reason: "freeze" } } });
|
|
4072
|
+
assert.equal(w.io.api, undefined);
|
|
4073
|
+
const progress = [];
|
|
4074
|
+
const r = await run(w, { ciMaxMinutes: 1, onProgress: (p) => progress.push(p) });
|
|
4075
|
+
assert.equal(r.terminalReason, "ci-pending");
|
|
4076
|
+
assert.equal(w.merges.length, 0, "no merge while the manual hold is set");
|
|
4077
|
+
assert.ok(progress.some((p) => /manual merge hold \(freeze\)/.test(p.detail ?? "")));
|
|
4078
|
+
assert.equal((await run(world({ releasePrs: [], activeJson: {} }))).terminalReason, "merged");
|
|
4079
|
+
});
|
|
4080
|
+
it("#5709 a persistent hold ends ci-pending without pushing to the base", async () => {
|
|
4081
|
+
const w = world({ releasePrs: RELEASE_PENDING });
|
|
4082
|
+
const r = await run(w, { ciMaxMinutes: 1 });
|
|
4083
|
+
assert.equal(r.terminalReason, "ci-pending");
|
|
4084
|
+
assert.equal(w.merges.length, 0);
|
|
4085
|
+
});
|
|
4086
|
+
it("#5794 the release fix lane (FORGE_RELEASE_FIX_LANE=1) merges past a pending release PR; other lanes stay held", async () => {
|
|
4087
|
+
const w = world({ releasePrs: RELEASE_PENDING });
|
|
4088
|
+
w.io.env = { ...process.env, FORGE_RELEASE_FIX_LANE: "1" };
|
|
4089
|
+
assert.equal((await run(w, { ciMaxMinutes: 1 })).terminalReason, "merged");
|
|
4090
|
+
assert.equal(w.merges.length, 1);
|
|
4091
|
+
const h = world({ releasePrs: RELEASE_PENDING });
|
|
4092
|
+
h.io.env = { ...process.env, FORGE_RELEASE_FIX_LANE: "" };
|
|
4093
|
+
assert.equal((await run(h, { ciMaxMinutes: 1 })).terminalReason, "ci-pending");
|
|
4094
|
+
assert.equal(h.merges.length, 0);
|
|
4095
|
+
});
|
|
4096
|
+
it("#5709 no release PR, or the hold disabled, leaves merge behaviour unchanged", async () => {
|
|
4097
|
+
assert.equal((await run(world({ releasePrs: [] }))).terminalReason, "merged");
|
|
4098
|
+
const w = world({ releasePrs: RELEASE_PENDING });
|
|
4099
|
+
assert.equal((await run(w, { holdMergesDuringReleaseCi: false })).terminalReason, "merged");
|
|
4100
|
+
assert.equal(w.merges.length, 1);
|
|
4101
|
+
});
|
|
4102
|
+
it("#5709 release.hold_merges_during_release_ci: false in .forge/release.yaml disables the held_release wait", async () => {
|
|
4103
|
+
const w = world({ releasePrs: RELEASE_PENDING });
|
|
4104
|
+
const g = w.io.git; w.io.git = async (a, o) => (a[0] === "show" && /\.forge\/release\.yaml$/.test(a.at(-1)) ? "schema: 1\nrelease: {hold_merges_during_release_ci: false}\n" : g(a, o));
|
|
4105
|
+
assert.equal((await run(w)).terminalReason, "merged");
|
|
4106
|
+
assert.equal(w.merges.length, 1);
|
|
4107
|
+
});
|
|
4108
|
+
|
|
3881
4109
|
it("a resumed run with a conflicting PR re-plans, verifies, then syncs in the same session", async () => {
|
|
3882
4110
|
const w = world({ prList: [{ number: 77, headRefOid: "x" }], remote: "abc\trefs/heads/feat/issue-7-lean", prView: [CONFLICTING, OKSTATE], mergeResults: ["conflict"], reviews: [ok(), ok()] });
|
|
3883
4111
|
const r = await run(w);
|
|
@@ -3947,6 +4175,22 @@ describe("usage limit, lease takeover, worktree setup, run tmp (#4101-#4104)", (
|
|
|
3947
4175
|
assert.equal(w.leaseWrites.at(-1).lease, null, "lease released");
|
|
3948
4176
|
});
|
|
3949
4177
|
|
|
4178
|
+
it("#5762 a CLI exit that never reached the API defers backend.cli_failed with the result text and account", async () => {
|
|
4179
|
+
const w = world(); projector(w, null);
|
|
4180
|
+
const cliErr = Object.assign(new Error("claude CLI exited with status 1. Output: {\"duration_api_ms\":0"), { code: "CLI_BACKEND_FAILED", cliFailed: true, cliResult: "spawn EAGAIN", cliIsError: true });
|
|
4181
|
+
const orig = w.io.runner; w.io.runner = async (c) => { if (c.role === "builder") throw cliErr; return orig(c); };
|
|
4182
|
+
const prev = process.env.TOKENBATON_ACCOUNT; process.env.TOKENBATON_ACCOUNT = "3";
|
|
4183
|
+
let r; try { r = await run(w); } finally { if (prev === undefined) delete process.env.TOKENBATON_ACCOUNT; else process.env.TOKENBATON_ACCOUNT = prev; }
|
|
4184
|
+
assert.equal(r.terminalReason, "deferred");
|
|
4185
|
+
assert.equal(r.code, "backend.cli_failed");
|
|
4186
|
+
assert.equal(r.retryInSeconds, 120);
|
|
4187
|
+
assert.equal(r.backendId, undefined, "no account hold");
|
|
4188
|
+
assert.match(r.detail, /account 3/);
|
|
4189
|
+
assert.match(r.detail, /spawn EAGAIN/);
|
|
4190
|
+
assert.equal(r.cliResult, "spawn EAGAIN");
|
|
4191
|
+
assert.equal(r.account, "3");
|
|
4192
|
+
});
|
|
4193
|
+
|
|
3950
4194
|
it("#5168 an error that is both a usage limit and auth-like stays rate_limited", async () => {
|
|
3951
4195
|
const w = world();
|
|
3952
4196
|
failFirstBuilder(w, limitErr({ authFailure: true, resetAtEpochMs: 3 * 3600 * 1000, resetAt: "8:30pm" }));
|
|
@@ -4164,10 +4408,10 @@ describe("usage limit, lease takeover, worktree setup, run tmp (#4101-#4104)", (
|
|
|
4164
4408
|
|
|
4165
4409
|
it("#4103 'already exists' on add cleans the leftover and retries; index.lock and packed-refs.lock are retried", async () => {
|
|
4166
4410
|
for (const msg of ["fatal: '/wt/lean-7' already exists", "fatal: Unable to create '/r/.git/index.lock': File exists.", "error: cannot lock ref: Unable to create '/r/.git/packed-refs.lock': File exists", "fatal: could not lock config file /r/.git/config: File exists"]) {
|
|
4167
|
-
const w = world(); let failed = false; const removed = [];
|
|
4168
|
-
w.io.fs.exists = async (p) => failed && p === "/wt/lean-7"; w.io.fs.rmdir = async (p) => { removed.push(p); };
|
|
4411
|
+
const w = world(); let failed = false, gone = false; const removed = [];
|
|
4412
|
+
w.io.fs.exists = async (p) => failed && !gone && p === "/wt/lean-7"; w.io.fs.rmdir = async (p) => { removed.push(p); gone = true; }; // #5825: a removed leftover is gone until the add
|
|
4169
4413
|
const g = w.io.git;
|
|
4170
|
-
w.io.git = async (a, o2) => { if (a[0] === "worktree" && a[1] === "add" && !failed) { failed = true; throw Object.assign(new Error(msg), { stderr: msg }); } return g(a, o2); };
|
|
4414
|
+
w.io.git = async (a, o2) => { if (a[0] === "worktree" && a[1] === "add" && !failed) { failed = true; throw Object.assign(new Error(msg), { stderr: msg }); } if (a[0] === "worktree" && a[1] === "add") gone = false; return g(a, o2); };
|
|
4171
4415
|
const r = await run(w);
|
|
4172
4416
|
assert.equal(r.terminalReason, "merged", msg);
|
|
4173
4417
|
if (/already exists/.test(msg)) assert.deepEqual(removed, ["/wt/lean-7"]);
|
|
@@ -4275,6 +4519,18 @@ describe("host admission (#4105)", () => {
|
|
|
4275
4519
|
assert.deepEqual(w.labels, []);
|
|
4276
4520
|
});
|
|
4277
4521
|
|
|
4522
|
+
it("ramping lanes are subtracted: deferred host.busy with the projected numbers; a passed admission is recorded (#5845)", async () => {
|
|
4523
|
+
const w = withHost(world(), { ...host({ mem: 6000 }), rampingMb: () => 4096, rampingLanes: () => 2, laneFootprintMb: () => 2048 });
|
|
4524
|
+
const r = await run(w);
|
|
4525
|
+
assert.equal(r.terminalReason, "deferred"); assert.equal(r.code, "host.busy");
|
|
4526
|
+
assert.equal(r.detail, "host busy: projected mem 1.9G (free 5.9G − ramping 4G) < need 4G; retry in 60s");
|
|
4527
|
+
assert.equal(w.ghCalls, 0);
|
|
4528
|
+
let recorded = 0;
|
|
4529
|
+
const ok = withHost(world(), { ...host(), recordAdmission: () => { recorded++; }, rampingMb: () => 0, rampingLanes: () => 0 });
|
|
4530
|
+
assert.equal((await run(ok)).terminalReason, "merged");
|
|
4531
|
+
assert.equal(recorded, 1);
|
|
4532
|
+
});
|
|
4533
|
+
|
|
4278
4534
|
it("low tmp space on the run TMPDIR filesystem or on /tmp is deferred host.busy", async () => {
|
|
4279
4535
|
for (const free of [{ "/tmp": 8192, "/home/x/.forge/tmp": 512 }, { "/tmp": 100, "/home/x/.forge/tmp": 8192 }]) {
|
|
4280
4536
|
const w = withHost(world(), host({ free }));
|
|
@@ -5149,6 +5405,25 @@ describe("batch robustness (#4112-#4115)", () => {
|
|
|
5149
5405
|
await run(w2, { recover: { code: "ci.red", attempt: 1 } });
|
|
5150
5406
|
assert.ok(!w2.comments.some((c) => c.includes("FORGE:AMENDMENT-STATE")));
|
|
5151
5407
|
});
|
|
5408
|
+
it("#5773 a structured decision does not make the frozen contract stale; a requeue neither renumbers a re-added row nor drops the decision", async () => {
|
|
5409
|
+
const dir = tmpDir("decision-5773-");
|
|
5410
|
+
const Q = "Existing callers of foo keep working.";
|
|
5411
|
+
const add = (why) => ({ kind: "add-requirement", requirement: { id: "R2", quote: Q, disposition: "post-deploy" }, why });
|
|
5412
|
+
const state = { contract: contractHash(contractJson(CONTRACT)), amendments: [add("live run"), add("same row, other why")] };
|
|
5413
|
+
const am = { body: `<!-- FORGE:AMENDMENT -->\n${renderAmendments([{ kind: "add-requirement", target: "R2", why: "live run" }], {}, state)}`, author_association: "OWNER", user: { type: "User", login: "op" } };
|
|
5414
|
+
const dec = { body: `<!-- FORGE:DECISION {"requirement":"R3","disposition":"post-deploy","quote":"${Q}"} -->\n**R3 is tracked post-deploy by the orchestrator.**`, author_association: "OWNER", user: { type: "User", login: "op" } };
|
|
5415
|
+
const w = world({ prList: [], remote: "abc\trefs/heads/feat/issue-7-lean", issueComments: [frozenComment(), am, dec], viewComments: [{ body: dec.body, authorAssociation: "OWNER", author: { login: "op" } }],
|
|
5416
|
+
reviews: [conf({}, { ...CONTRACT, requirements: [...CONTRACT.requirements, { id: "R2", quote: Q, disposition: "defer" }] })] });
|
|
5417
|
+
const out = await run(w, { dir });
|
|
5418
|
+
assert.match(traj(w)[0], /frozen contract [0-9a-f]{12} recovered from the issue/);
|
|
5419
|
+
assert.doesNotMatch(builders(w)[0][4], /PLANNING ONLY/);
|
|
5420
|
+
assert.equal(readLog(dir, 7).filter((e) => e.event === "CONTRACT_STALE").length, 0);
|
|
5421
|
+
assert.ok(!w.comments.some((c) => c.includes("renumbered")), "a replayed add-requirement is not renumbered");
|
|
5422
|
+
const posted = w.comments.filter((c) => c.includes("FORGE:AMENDMENT-STATE")).at(-1);
|
|
5423
|
+
if (posted) assert.equal(parseAmendmentsComment(posted).amendments.filter((a) => a.kind === "add-requirement").length, 1);
|
|
5424
|
+
assert.match(traj(w)[0], /FORGE:DECISION applied to the amended contract: R2/);
|
|
5425
|
+
assert.equal(out.terminalReason, "merged", traj(w)[0]);
|
|
5426
|
+
});
|
|
5152
5427
|
it("#4899 recovery lane keeps enforcing a guard that was not superseded", async () => {
|
|
5153
5428
|
const mkGuard = (issue) => ({ v: 1, issue, pr: issue * 10, merge_sha: "abc1234", tests: [{ path: "src/foo.js", ids: [] }], hunks: [], why: `guard ${issue}` });
|
|
5154
5429
|
const sup = { kind: "supersedes", guard: "#4785", why: "behaviour changed on purpose" };
|
|
@@ -5173,6 +5448,40 @@ describe("batch robustness (#4112-#4115)", () => {
|
|
|
5173
5448
|
assert.ok(builders(w).length >= 2, "a failing guard still resumes the builder");
|
|
5174
5449
|
|
|
5175
5450
|
});
|
|
5451
|
+
it("#5752 a broken weak guard (literal-presence test) does not block the lane and is recorded as a review note", async () => {
|
|
5452
|
+
const weakBody = `import assert from "node:assert/strict";\nimport { readFileSync } from "node:fs";\nconst src = readFileSync("src/x.js", "utf8");\nassert.match(src, /LEGACY_FLAG/);\n`;
|
|
5453
|
+
const dir = tmpDir("guard-weak-");
|
|
5454
|
+
const w = world({ prList: [] });
|
|
5455
|
+
const g = w.io.git; w.io.git = async (a, o) => (a[0] === "show" && /:src\/foo\.js$/.test(a.at(-1)) ? weakBody : g(a, o));
|
|
5456
|
+
w.io.runCommand = async (a) => ({ rc: String(a?.cwd).includes("guardbase-") ? 0 : 1, output: "guard test failed" });
|
|
5457
|
+
// the guard copy lands in the fake worktree (/wt/lean-7): keep those writes in memory so the test runs on any host
|
|
5458
|
+
const inWt = (p) => /^[\/]wt[\/]/.test(String(p).replace(/^[A-Za-z]:/, ""));
|
|
5459
|
+
const guardFs = { ...nodeFs, mkdirSync: (p, o) => (inWt(p) ? undefined : nodeFs.mkdirSync(p, o)), writeFileSync: (p, d, o) => (inWt(p) ? undefined : nodeFs.writeFileSync(p, d, o)), rmSync: (p, o) => (inWt(p) ? undefined : nodeFs.rmSync(p, o)) };
|
|
5460
|
+
const r = await run(w, { dir, guardFs, loadGuards: async () => [{ v: 1, issue: 9, pr: 90, merge_sha: "abc1234", tests: [{ path: "src/foo.js", ids: [] }], hunks: [], why: "guard 9" }] });
|
|
5461
|
+
const text = JSON.stringify([w.comments, w.calls.filter((c) => c[0] === "runner")]);
|
|
5462
|
+
assert.doesNotMatch(text, /conformance\.guard_broken/, "a weak guard is never a guard_broken failure");
|
|
5463
|
+
assert.ok(r.terminalReason === "merged" || !/guard #9/.test(JSON.stringify(w.comments.filter((c) => /NEEDS_HUMAN/.test(c)))), "the guard is not why the lane stops");
|
|
5464
|
+
const weakEv = readLog(dir, 7).filter((e) => e.event === "guard_weak");
|
|
5465
|
+
assert.ok(weakEv.length >= 1 && weakEv.every((e) => e.guard === "#9" && e.test === "src/foo.js"));
|
|
5466
|
+
assert.deepEqual([...new Set(readLog(dir, 7).filter((e) => e.event === "guard_run").map((e) => `${e.broken}/${e.weak}`))], ["0/1"]);
|
|
5467
|
+
assert.match(traj(w).at(-1), /Weak guard #9 broken \(review note, not a park\)/);
|
|
5468
|
+
});
|
|
5469
|
+
it("#5752 a declared outcome-evidence area touched without a before/after result row blocks with a clear reason", async () => {
|
|
5470
|
+
const w = world({ prList: [] });
|
|
5471
|
+
await run(w, { outcomeEvidenceConfig: { paths: { core: ["src/**"] }, corpus: { core: ["corpus/**"] } } });
|
|
5472
|
+
assert.ok(builders(w).length >= 2, "the missing evidence resumes the builder");
|
|
5473
|
+
assert.match(JSON.stringify(w.calls.filter((c) => c[0] === "runner")), /outcome-evidence area 'core'.{0,200}src\/foo\.js.{0,200}no before\/after measurement/);
|
|
5474
|
+
const off = world({ prList: [] });
|
|
5475
|
+
await run(off);
|
|
5476
|
+
assert.doesNotMatch(JSON.stringify([off.comments, off.calls.filter((c) => c[0] === "runner")]), /outcome_evidence_missing|outcome-evidence area/, "no outcome_evidence config: no new check");
|
|
5477
|
+
});
|
|
5478
|
+
it("#5752 the builder prompt carries the negative-examples rule and the mechanism supersedes amendment", async () => {
|
|
5479
|
+
const w = world({ prList: [] });
|
|
5480
|
+
await run(w);
|
|
5481
|
+
const p = JSON.stringify(builders(w));
|
|
5482
|
+
assert.match(p, /ships negative examples/);
|
|
5483
|
+
assert.match(p, /"kind\\":\\"supersedes\\",\\"mechanism\\"/);
|
|
5484
|
+
});
|
|
5176
5485
|
it("#4899 amendment state round-trips; precheck still enforces a guard that was not superseded", () => {
|
|
5177
5486
|
const am = [{ kind: "supersedes", guard: "#1", why: "w" }];
|
|
5178
5487
|
assert.deepEqual(parseAmendmentsComment(renderAmendments([{ kind: "supersedes", target: "#1", why: "w" }], {}, { contract: "abc", amendments: am })), { contract: "abc", amendments: am });
|
|
@@ -5199,10 +5508,49 @@ describe("batch robustness (#4112-#4115)", () => {
|
|
|
5199
5508
|
assert.equal((await run(w, { dir })).terminalReason, "merged");
|
|
5200
5509
|
assert.match(builders(w)[0][4], /PLANNING ONLY[\s\S]*This is a rerun/);
|
|
5201
5510
|
assert.match(traj(w)[0], reason);
|
|
5202
|
-
assert.match(w.comments.find((x) => x.includes("<!-- FORGE:CONTRACT -->")), /\(sha256 [0-9a-f]{12}, issue [0-9a-f]{12}\)/);
|
|
5511
|
+
assert.match(w.comments.find((x) => x.includes("<!-- FORGE:CONTRACT -->")), /\(sha256 [0-9a-f]{12}, issue [0-9a-f]{12}, base staging\)/);
|
|
5203
5512
|
}
|
|
5204
5513
|
assert.equal(readLog(dir, 7).filter((e) => e.event === "CONTRACT_STALE").length, 2);
|
|
5205
5514
|
});
|
|
5515
|
+
// #5811: a recovery that ended before its first commit has no branch to resume; the frozen contract still skips the plan session
|
|
5516
|
+
const withScopeBase = (scope, base) => frozenComment(CONTRACT, (b) => b.replace(/\(sha256 ([0-9a-f]{12})\)/, `(sha256 $1, issue ${scope}${base ? `, base ${base}` : ""})`));
|
|
5517
|
+
it("#5811 a recovery without a branch reuses a frozen contract of the same issue scope and base: routing comes before any builder session", async () => {
|
|
5518
|
+
const dir = tmpDir("reuse-5811-");
|
|
5519
|
+
const w = world({ prList: [], issueComments: [withScopeBase(scoped(), "staging")] });
|
|
5520
|
+
assert.equal((await run(w, { dir, recover: { code: "env.tool_missing", attempt: 1 } })).terminalReason, "merged");
|
|
5521
|
+
const b = builders(w);
|
|
5522
|
+
assert.equal(b.length, 1, "no pre-contract session: only the implement session runs");
|
|
5523
|
+
assert.doesNotMatch(b[0][4], /PLANNING ONLY/);
|
|
5524
|
+
assert.match(b[0][4], /The engine froze[\s\S]*Recovery pass \(env\.tool_missing\)/);
|
|
5525
|
+
assert.ok(!w.comments.some((c) => c.includes("<!-- FORGE:CONTRACT -->")), "the contract is not re-frozen");
|
|
5526
|
+
const ev = readLog(dir, 7).map((e) => e.event);
|
|
5527
|
+
assert.ok(ev.includes("CONTRACT_REUSED") && !ev.includes("CONTRACT_FROZEN") && !ev.includes("CONTRACT_STALE"));
|
|
5528
|
+
const route = ev.indexOf("BUILDER_ROUTE"), first = ev.indexOf("FIRST_SESSION");
|
|
5529
|
+
assert.ok(route >= 0 && (first < 0 || route < first), `BUILDER_ROUTE precedes the first session: ${ev.join(",")}`);
|
|
5530
|
+
});
|
|
5531
|
+
it("#5811 an edited issue, another base or a contract without a recorded base re-plans a recovery without a branch", async () => {
|
|
5532
|
+
const dir = tmpDir("reuse-5811-stale-");
|
|
5533
|
+
for (const [c, reason] of [[withScopeBase(scoped("foo crashes; old scope."), "staging"), /issue scope [0-9a-f]{12} -> [0-9a-f]{12}/],
|
|
5534
|
+
[withScopeBase(scoped(), "milestone/other"), /base milestone\/other -> staging/], [withScopeBase(scoped(), null), /no branch to resume/]]) {
|
|
5535
|
+
const w = world({ prList: [], issueComments: [c] });
|
|
5536
|
+
assert.equal((await run(w, { dir, recover: { code: "env.tool_missing", attempt: 1 } })).terminalReason, "merged");
|
|
5537
|
+
assert.match(builders(w)[0][4], /PLANNING ONLY/);
|
|
5538
|
+
assert.match(traj(w)[0], reason);
|
|
5539
|
+
assert.match(w.comments.find((x) => x.includes("<!-- FORGE:CONTRACT -->")), /\(sha256 [0-9a-f]{12}, issue [0-9a-f]{12}, base staging\)/, "the new contract records its base");
|
|
5540
|
+
}
|
|
5541
|
+
assert.equal(readLog(dir, 7).filter((e) => e.event === "CONTRACT_REUSED").length, 0);
|
|
5542
|
+
});
|
|
5543
|
+
it("#5811 a resumed branch rejects a contract frozen on another base; a legacy contract without a base still resumes", async () => {
|
|
5544
|
+
const other = world({ prList: [], remote: "abc refs/heads/feat/issue-7-lean", issueComments: [withScopeBase(scoped(), "milestone/other")] });
|
|
5545
|
+
assert.equal((await run(other)).terminalReason, "merged");
|
|
5546
|
+
assert.match(builders(other)[0][4], /PLANNING ONLY/);
|
|
5547
|
+
const legacy = world({ prList: [], remote: "abc refs/heads/feat/issue-7-lean", issueComments: [withScopeBase(scoped(), null)] });
|
|
5548
|
+
assert.equal((await run(legacy, { recover: { code: "ci.red", attempt: 1 } })).terminalReason, "merged");
|
|
5549
|
+
assert.equal(builders(legacy).length, 1);
|
|
5550
|
+
const round = parseContractComment(renderContract(CONTRACT, "0123456789ab", { scope: "ba5eba5eba5e", base: "milestone/m-1" }));
|
|
5551
|
+
assert.equal(round.base, "milestone/m-1"); assert.equal(round.scope, "ba5eba5eba5e");
|
|
5552
|
+
assert.equal(parseContractComment(renderContract(CONTRACT, "0123456789ab", { scope: "ba5eba5eba5e" })).base, null);
|
|
5553
|
+
});
|
|
5206
5554
|
it("a tampered or untrusted contract comment is ignored: the rerun plans again", async () => {
|
|
5207
5555
|
for (const c of [frozenComment(CONTRACT, (b) => b.replaceAll("guard null", "guard nothing")), frozenComment(CONTRACT, (b) => b, "NONE")]) {
|
|
5208
5556
|
const w = world({ prList: [], remote: "abc\trefs/heads/feat/issue-7-lean", issueComments: [c] });
|
|
@@ -5250,6 +5598,29 @@ describe("lane resolution in core work-on (#4125)", () => {
|
|
|
5250
5598
|
}
|
|
5251
5599
|
});
|
|
5252
5600
|
|
|
5601
|
+
it("#5846 a transient lane read in runCore defers lane.unresolved instead of lane-refused", async () => {
|
|
5602
|
+
const w = leased(world({ milestone: "M1", branchesOnOrigin: ["staging", "milestone/m1"] }));
|
|
5603
|
+
const gh = w.io.gh;
|
|
5604
|
+
w.io.gh = async (a, opts) => { if (a[0] === "issue" && a[1] === "view" && a.includes("milestone")) throw new Error("spawn UNKNOWN"); return gh(a, opts); };
|
|
5605
|
+
const r = await run(w, { lane: undefined });
|
|
5606
|
+
assert.deepEqual([r.terminalReason, r.code], ["deferred", "lane.unresolved"]);
|
|
5607
|
+
assert.ok(r.retryInSeconds > 0);
|
|
5608
|
+
assert.match(r.detail, /cannot read the milestone of #7/);
|
|
5609
|
+
assert.deepEqual(touched(w), nothing);
|
|
5610
|
+
});
|
|
5611
|
+
|
|
5612
|
+
it("#5846 genuine lane refusals stay lane-refused with their own codes", async () => {
|
|
5613
|
+
const cases = [
|
|
5614
|
+
[{ milestone: "M1", branchesOnOrigin: ["staging", "milestone/m1"] }, { lane: "staging" }, "lane.mismatch"],
|
|
5615
|
+
[{}, { lane: "main" }, "lane.default_branch"],
|
|
5616
|
+
[{ milestone: "Not Yet" }, { lane: undefined }, "lane.branch_missing"],
|
|
5617
|
+
];
|
|
5618
|
+
for (const [o, extra, code] of cases) {
|
|
5619
|
+
const r = await run(leased(world(o)), extra);
|
|
5620
|
+
assert.deepEqual([r.terminalReason, r.code], ["lane-refused", code]);
|
|
5621
|
+
}
|
|
5622
|
+
});
|
|
5623
|
+
|
|
5253
5624
|
it("a missing milestone/<slug> branch fails closed with lane.branch_missing", async () => {
|
|
5254
5625
|
const w = leased(world({ milestone: "Not Yet" }));
|
|
5255
5626
|
const r = await run(w, { lane: undefined });
|
|
@@ -5676,7 +6047,7 @@ describe("lane resource ledger + teardown on every exit path (#4179)", () => {
|
|
|
5676
6047
|
const gitIdx = (w, pred) => { let i = -1; w.calls.forEach((c, k) => { if (c[0] === "git" && pred(c.slice(1))) i = k; }); return i; };
|
|
5677
6048
|
/** The exit teardown: the last two worktree calls are `remove --force <wt>` then `prune`; the ledger file is gone. */
|
|
5678
6049
|
const tornDown = (w, label) => {
|
|
5679
|
-
const wtCalls = w.calls.filter((c) => c[0] === "git" && c[1] === "worktree");
|
|
6050
|
+
const wtCalls = w.calls.filter((c) => c[0] === "git" && c[1] === "worktree").map((c) => c.map(posix)); // Windows: path.resolve yields `\wt\lean-7`
|
|
5680
6051
|
assert.deepEqual(wtCalls.at(-2), ["git", "worktree", "remove", "--force", WT], `${label}: worktree removed`);
|
|
5681
6052
|
assert.deepEqual(wtCalls.at(-1), ["git", "worktree", "prune"], `${label}: then pruned`);
|
|
5682
6053
|
assert.equal(existsSync(w.ledgerFile), false, `${label}: ledger cleared`);
|
|
@@ -5786,6 +6157,39 @@ describe("lane resource ledger + teardown on every exit path (#4179)", () => {
|
|
|
5786
6157
|
tornDown(w, "dirty needs-human");
|
|
5787
6158
|
});
|
|
5788
6159
|
|
|
6160
|
+
it("#5819 a checkpoint whose staged diff deletes tracked files outside the deliverables is refused: restored, nothing pushed, engine-error with evidence", async () => {
|
|
6161
|
+
const w = ledgered({ dirty: true, waits: [{ rc: 1, text: "lint failed" }] });
|
|
6162
|
+
const dir = tmpDir("core-5819-");
|
|
6163
|
+
w.stagedDeletions = ["packages/adapters/src/index.ts", "packages/adapters/migrations/0001.sql", "src/foo.js"]; // src/foo.js is a deliverable
|
|
6164
|
+
const r = await run(w, { mergeWait: "all", dir });
|
|
6165
|
+
assert.equal(r.terminalReason, "engine-error");
|
|
6166
|
+
const commit = gitIdx(w, (a) => a[0] === "commit" && a.some((x) => /checkpoint after exit \(needs-human\)/.test(x)));
|
|
6167
|
+
assert.ok(commit > 0, "the remaining changes are committed locally");
|
|
6168
|
+
const pushAfter = w.calls.slice(commit).filter((c) => c[0] === "git" && c[1] === "push" && !c.includes("--delete"));
|
|
6169
|
+
assert.deepEqual(pushAfter, [], "nothing is pushed after the refused checkpoint");
|
|
6170
|
+
assert.deepEqual(w.restoredPaths, ["packages/adapters/src/index.ts", "packages/adapters/migrations/0001.sql"], "only the non-deliverable deletions are checked out again");
|
|
6171
|
+
assert.ok(w.calls.some((c) => c[0] === "git" && c[1] === "reset" && c.includes("packages/adapters/src/index.ts") && !c.includes("src/foo.js")), "and unstaged");
|
|
6172
|
+
const ev = readLog(dir, 7);
|
|
6173
|
+
const refused = ev.find((e) => e.event === "CHECKPOINT_DELETIONS_REFUSED");
|
|
6174
|
+
assert.equal(refused.foreign, 2); assert.equal(refused.deleted, 3); assert.equal(refused.restored, true);
|
|
6175
|
+
const term = ev.find((e) => e.event === "RUN_TERMINAL");
|
|
6176
|
+
assert.equal(term.reason, "engine-error"); assert.equal(term.code, "engine.error");
|
|
6177
|
+
assert.ok(ev.some((e) => e.event === "TERMINAL_OVERRIDDEN" && e.from === "needs-human"));
|
|
6178
|
+
assert.ok(ev.some((e) => e.event === "TEARDOWN_KEPT"), "the worktree is kept for inspection");
|
|
6179
|
+
});
|
|
6180
|
+
|
|
6181
|
+
it("#5819 deletions listed as deliverables (and files the lane added itself) still checkpoint and push", async () => {
|
|
6182
|
+
const w = ledgered({ dirty: true, waits: [{ rc: 1, text: "lint failed" }] });
|
|
6183
|
+
w.stagedDeletions = ["src/foo.js", "src/lane-scratch.js"]; w.laneAdded = ["src/lane-scratch.js"];
|
|
6184
|
+
const r = await run(w, { mergeWait: "all" });
|
|
6185
|
+
assert.equal(r.terminalReason, "needs-human");
|
|
6186
|
+
const commit = gitIdx(w, (a) => a[0] === "commit" && a.some((x) => /checkpoint after exit \(needs-human\)/.test(x)));
|
|
6187
|
+
const push = gitIdx(w, (a) => a[0] === "push" && a.includes("feat/issue-7-lean") && !a.includes("--delete"));
|
|
6188
|
+
assert.ok(commit > 0 && push > commit, `commit ${commit} < push ${push}`);
|
|
6189
|
+
assert.equal(w.restoredPaths, undefined, "nothing restored");
|
|
6190
|
+
tornDown(w, "deliverable deletion");
|
|
6191
|
+
});
|
|
6192
|
+
|
|
5789
6193
|
it("a checkpoint that cannot push keeps the worktree and leaves worktree + branch listed in the ledger", async () => {
|
|
5790
6194
|
const msg = "remote: error: GH006: Protected branch update failed for refs/heads/x";
|
|
5791
6195
|
const w = ledgered({ dirty: true, pushErrors: [msg, msg, msg] });
|
|
@@ -6046,6 +6450,73 @@ describe("shared dependency cache wiring (#4220)", () => {
|
|
|
6046
6450
|
assert.ok(approxTokens(p) <= 2800, `builder prompt is ${approxTokens(p)} tokens`);
|
|
6047
6451
|
}
|
|
6048
6452
|
});
|
|
6453
|
+
|
|
6454
|
+
const nh5804 = (w) => w.comments.find((c) => c.includes("FORGE:NEEDS_HUMAN")) ?? "";
|
|
6455
|
+
it("#5804 a dependency install that fails tool-not-found ends env.tool_missing before the first session, naming the tool", async () => {
|
|
6456
|
+
for (const [row, tool] of [[{ status: "failed", eco: "pnpm", dir: ".", key: "k", ms: 3, reason: "tool not found: spawn pnpm ENOENT" }, "pnpm"],
|
|
6457
|
+
[{ status: "failed", eco: "poetry", dir: ".", key: "k", ms: 3, reason: "no python satisfying the declared range \">=3.12\" was found", code: "env.tool_missing" }, "poetry"]]) {
|
|
6458
|
+
const dir = tmpDir("deps-5804-");
|
|
6459
|
+
const w = world(); depsIo(w, { results: [row] });
|
|
6460
|
+
const r = await run(w, { dir });
|
|
6461
|
+
assert.equal(r.code, OUTCOME_CODES.ENV_TOOL_MISSING, tool);
|
|
6462
|
+
assert.equal(w.calls.filter((c) => c[0] === "runner").length, 0, "no builder session");
|
|
6463
|
+
assert.equal(w.merges.length, 0);
|
|
6464
|
+
const log = readLog(dir, 7);
|
|
6465
|
+
assert.equal(log.filter((e) => e.event === "FIRST_SESSION").length, 0);
|
|
6466
|
+
assert.deepEqual(log.find((e) => e.event === "PREFLIGHT_TOOL_MISSING")?.tools, [tool]);
|
|
6467
|
+
assert.match(nh5804(w), new RegExp(`the host is missing ${tool}, so validate command\\(s\\) could not run`), "the validate-time evidence line orchestrate classifies");
|
|
6468
|
+
assert.match(nh5804(w), /env\.tool_missing: dependency install stopped/);
|
|
6469
|
+
}
|
|
6470
|
+
});
|
|
6471
|
+
|
|
6472
|
+
it("#5804 a tool-not-found install that settles after the plan started still ends before implement", async () => {
|
|
6473
|
+
const w = world(); depsIo(w);
|
|
6474
|
+
let release;
|
|
6475
|
+
const gate = new Promise((r) => { release = r; });
|
|
6476
|
+
w.io.deps.prepare = async () => { await gate; return [{ status: "failed", eco: "pnpm", key: "k", ms: 5, reason: "tool not found: spawn pnpm ENOENT" }]; };
|
|
6477
|
+
const inner = w.io.runner;
|
|
6478
|
+
w.io.runner = async (c) => { release(); return inner(c); };
|
|
6479
|
+
const r = await run(w, { dir: tmpDir("deps-5804-late-"), contextWaitSeconds: 0 });
|
|
6480
|
+
assert.equal(r.code, OUTCOME_CODES.ENV_TOOL_MISSING);
|
|
6481
|
+
assert.equal(builders(w).length, 1, "the plan session only, no implement");
|
|
6482
|
+
assert.match(nh5804(w), /ended before the builder implemented/);
|
|
6483
|
+
});
|
|
6484
|
+
|
|
6485
|
+
it("#5804 an install failure that is not tool-not-found keeps the overlap: the builder runs and the gate judges it", async () => {
|
|
6486
|
+
const dir = tmpDir("deps-5804-other-");
|
|
6487
|
+
const w = world(); depsIo(w, { results: [{ status: "failed", eco: "npm", dir: ".", key: "k", ms: 3, reason: "install failed: ERESOLVE" }] });
|
|
6488
|
+
await run(w, { dir });
|
|
6489
|
+
assert.ok(builders(w).length >= 2, "plan and implement ran");
|
|
6490
|
+
assert.equal(readLog(dir, 7).filter((e) => e.event === "PREFLIGHT_TOOL_MISSING").length, 0);
|
|
6491
|
+
});
|
|
6492
|
+
|
|
6493
|
+
it("#5804 a tool missing for an unrelated sub-project is only logged: the lane continues and merges; a named sub-project path fails fast", async () => {
|
|
6494
|
+
const row = { status: "failed", eco: "poetry", dir: "services/worker", key: "k", ms: 3, reason: "tool not found: spawn poetry ENOENT" };
|
|
6495
|
+
const dir = tmpDir("deps-5804-sub-");
|
|
6496
|
+
const w = world(); depsIo(w, { results: [row] });
|
|
6497
|
+
const r = await run(w, { dir });
|
|
6498
|
+
assert.equal(r.terminalReason, "merged", "changes under src/ never need the worker's poetry");
|
|
6499
|
+
assert.ok(builders(w).length >= 2, "plan and implement ran");
|
|
6500
|
+
assert.equal(readLog(dir, 7).filter((e) => e.event === "PREFLIGHT_TOOL_MISSING").length, 0);
|
|
6501
|
+
const w2 = world({ body: `${ISSUE_BODY}\n\nThe handler in services/worker/app/main.py calls foo.` }); depsIo(w2, { results: [row] });
|
|
6502
|
+
const r2 = await run(w2, { dir: tmpDir("deps-5804-sub2-") });
|
|
6503
|
+
assert.equal(r2.code, OUTCOME_CODES.ENV_TOOL_MISSING);
|
|
6504
|
+
assert.equal(w2.calls.filter((c) => c[0] === "runner").length, 0, "no builder session");
|
|
6505
|
+
});
|
|
6506
|
+
|
|
6507
|
+
it("#5804 a resumed lane whose frozen contract declares an env tool the host lacks ends env.tool_missing before any session", async () => {
|
|
6508
|
+
const contract = { ...CONTRACT, test_plan: [{ requirement: "R1", proof: "the pytest case no longer errors at collection", level: "unit", level_reason: "cheapest level that observes it", repro: "no-repro", reason: "env-only", command: "node --test test/foo.test.js", env: ["pytest"] }] };
|
|
6509
|
+
const h = contractHash(contractJson(contract));
|
|
6510
|
+
const fc = { body: `<!-- FORGE:CONTRACT -->\n<!-- FORGE:PLAN -->\n${renderContract(contract, h)}`, author_association: "OWNER", user: { type: "User", login: "op" } };
|
|
6511
|
+
const dir = tmpDir("deps-5804-env-");
|
|
6512
|
+
const w = world({ prList: [], remote: "abc\trefs/heads/feat/issue-7-lean", lastSubject: "wip(forge): checkpoint after idle timeout", issueComments: [fc] });
|
|
6513
|
+
w.io.runCommand = async ({ command }) => (/pytest --version/.test(command) ? { rc: 1, output: "" } : { rc: 0, output: "" });
|
|
6514
|
+
const r = await run(w, { dir });
|
|
6515
|
+
assert.equal(r.code, OUTCOME_CODES.ENV_TOOL_MISSING);
|
|
6516
|
+
assert.equal(w.calls.filter((c) => c[0] === "runner").length, 0, "no builder session");
|
|
6517
|
+
assert.equal(readLog(dir, 7).filter((e) => e.event === "FIRST_SESSION").length, 0);
|
|
6518
|
+
assert.match(nh5804(w), /This host lacks pytest, which the contract's test plan declares in env/);
|
|
6519
|
+
});
|
|
6049
6520
|
});
|
|
6050
6521
|
|
|
6051
6522
|
describe("local-mode CI fix rounds at merge and declared pre-PR check commands (#4240)", () => {
|
|
@@ -7439,6 +7910,41 @@ describe("#4362 attempt triggers", () => {
|
|
|
7439
7910
|
assert.match(restart, /Its last tool call: Edit /);
|
|
7440
7911
|
});
|
|
7441
7912
|
|
|
7913
|
+
it("#5812: a planning session above the hand-off bound is not resumed: the build starts fresh from a bounded digest", async () => {
|
|
7914
|
+
const lane = (planTokens, opts = {}) => {
|
|
7915
|
+
const w = world({ dirty: true }); const seen = []; const orig = w.io.runner;
|
|
7916
|
+
w.io.runner = async (c) => {
|
|
7917
|
+
if (c.role === "builder") seen.push({ resume: c.resume ?? null, prompt: c.prompt, contextMax: c.contextMax ?? 0 });
|
|
7918
|
+
const r = await orig(c);
|
|
7919
|
+
return c.role === "builder" && seen.length === 1 ? { ...r, endTokens: planTokens, text: "planned.\nBuild reads: src/foo.js:1-20", toolUses: [{ msg: "m1", name: "Read", path: "src/bar.js" }] } : r;
|
|
7920
|
+
};
|
|
7921
|
+
return { w, seen, go: async () => { const dir = tmpDir("core-route-"); const r = await run(w, { dir, contextCeilingTokens: 120000, ...opts }); return { r, log: readLog(dir, 7) }; } };
|
|
7922
|
+
};
|
|
7923
|
+
const big = lane(96000);
|
|
7924
|
+
const { r, log } = await big.go();
|
|
7925
|
+
assert.equal(r.terminalReason, "merged");
|
|
7926
|
+
const build = big.seen[1];
|
|
7927
|
+
assert.equal(build.resume, null, "the build does not inherit the planning transcript");
|
|
7928
|
+
assert.match(build.prompt, /The engine froze \.forge-lean\/contract\.json/);
|
|
7929
|
+
assert.match(build.prompt, /Route hand-off: planning ran in a separate session \(it ended at about 96000 context tokens\)/);
|
|
7930
|
+
assert.match(build.prompt, /Deliverables:\n- src\/foo\.js: guard null/);
|
|
7931
|
+
assert.match(build.prompt, /Files planning read .*:\n- src\/bar\.js/);
|
|
7932
|
+
assert.match(build.prompt, /Planning's build reads:\nsrc\/foo\.js:1-20/);
|
|
7933
|
+
assert.equal(build.contextMax, 120000, "the ceiling still applies");
|
|
7934
|
+
const ho = log.find((e) => e.event === "ROUTE_HANDOFF");
|
|
7935
|
+
assert.deepEqual([ho.mode, ho.plan_tokens, ho.bound], ["digest", 96000, 40000]);
|
|
7936
|
+
assert.ok(ho.digest_bytes > 0 && ho.digest_bytes <= 32 * 1024, "the digest is bounded");
|
|
7937
|
+
assert.ok(!log.some((e) => e.event === "CONTEXT_CEILING"));
|
|
7938
|
+
const small = lane(20000);
|
|
7939
|
+
await small.go();
|
|
7940
|
+
assert.equal(small.seen[1].resume, "sess-1", "a planning session under the bound is resumed (its cache is cheaper)");
|
|
7941
|
+
assert.doesNotMatch(small.seen[1].prompt, /Route hand-off/);
|
|
7942
|
+
const off = lane(96000, { routeHandoffTokens: 0 });
|
|
7943
|
+
const offRun = await off.go();
|
|
7944
|
+
assert.equal(off.seen[1].resume, "sess-1", "0 turns the hand-off off");
|
|
7945
|
+
assert.equal(offRun.log.find((e) => e.event === "ROUTE_HANDOFF").mode, "resume");
|
|
7946
|
+
});
|
|
7947
|
+
|
|
7442
7948
|
it("#5346: engine.context_ceiling_by_size sets the ceiling per lane size (size S here), the global one otherwise", async () => {
|
|
7443
7949
|
const w = world({ dirty: true }); const caps = []; const orig = w.io.runner;
|
|
7444
7950
|
w.io.runner = async (c) => { if (c.role === "builder") caps.push(c.contextMax ?? 0); return orig(c); };
|
|
@@ -7881,11 +8387,13 @@ describe("#4394 builder model routing", () => {
|
|
|
7881
8387
|
const isPlan = (b) => /PLANNING ONLY/.test(b[4]);
|
|
7882
8388
|
const docsContract = { ...CONTRACT, deliverables: [{ id: "D1", path: "docs/foo.md", change: "document null", requirements: ["R1"] }, { id: "D2", path: "test/foo.test.js", change: "test", requirements: ["R1"] }] };
|
|
7883
8389
|
|
|
7884
|
-
it("a docs/test-only contract builds on the mid model; the plan
|
|
8390
|
+
it("a docs/test-only contract builds on the mid model; the plan runs on the provisional tier; RUN_TERMINAL and the result carry the route", async () => {
|
|
7885
8391
|
const w = world({ contract: docsContract }); const dir = tmpDir("core-");
|
|
7886
8392
|
const r = await run(w, { dir, builderModel: "opus-b" });
|
|
7887
8393
|
const b = builders(w);
|
|
7888
|
-
assert.ok(isPlan(b[0])); assert.equal(b[0][3], "
|
|
8394
|
+
assert.ok(isPlan(b[0])); assert.equal(b[0][3], "claude-sonnet-5-5", "#5810: an unscoped, risk-free issue plans on the mid tier");
|
|
8395
|
+
const [pre] = events(dir, "BUILDER_PREROUTE");
|
|
8396
|
+
assert.deepEqual([pre.class, pre.tier, pre.model], ["unscoped", "mid", "claude-sonnet-5-5"]); assert.match(pre.reason, /no named files/);
|
|
7889
8397
|
assert.equal(b[1][3], "claude-sonnet-5-5", "the build runs on the mid model");
|
|
7890
8398
|
const [route] = events(dir, "BUILDER_ROUTE");
|
|
7891
8399
|
assert.deepEqual({ mode: route.mode, class: route.class, tier: route.tier, model: route.model }, { mode: "on", class: "docs-config-test", tier: "mid", model: "claude-sonnet-5-5" });
|
|
@@ -7899,12 +8407,37 @@ describe("#4394 builder model routing", () => {
|
|
|
7899
8407
|
|
|
7900
8408
|
it("lean.builder_mid_model picks the mid model; a declared risk path routes the build to the top model", async () => {
|
|
7901
8409
|
const w1 = world(); await run(w1, { builderModel: "opus-b", builderRouting: { midModel: "haiku-mid" } });
|
|
7902
|
-
assert.deepEqual(builders(w1).slice(0, 2).map((b) => b[3]), ["
|
|
8410
|
+
assert.deepEqual(builders(w1).slice(0, 2).map((b) => b[3]), ["haiku-mid", "haiku-mid"]);
|
|
7903
8411
|
const w2 = world(); const dir = tmpDir("core-");
|
|
7904
8412
|
await run(w2, { dir, builderModel: "opus-b", reviewTrigger: { mode: "shadow", riskPaths: ["src/**"] } });
|
|
7905
|
-
|
|
8413
|
+
const b2 = builders(w2);
|
|
8414
|
+
assert.equal(b2.filter(isPlan).length, 1, "#5810: the upgrade does not rerun the pre-contract plan");
|
|
8415
|
+
assert.equal(b2[0][3], "claude-sonnet-5-5", "the issue named no risk path: provisional mid");
|
|
8416
|
+
assert.ok(b2.slice(1).every((b) => b[3] === "opus-b"), "the contract hit a risk path: every later builder call on the top model");
|
|
7906
8417
|
const [route] = events(dir, "BUILDER_ROUTE");
|
|
7907
8418
|
assert.equal(route.class, "risk"); assert.equal(route.tier, "top"); assert.deepEqual(route.risk, ["src/foo.js"]);
|
|
8419
|
+
assert.deepEqual([route.pre_tier, route.pre_class, route.change], ["mid", "unscoped", "upgrade"]);
|
|
8420
|
+
});
|
|
8421
|
+
|
|
8422
|
+
it("#5810: a risk-domain issue plans on the top tier and the risk floor keeps a docs-only contract's build there", async () => {
|
|
8423
|
+
const w = world({ contract: docsContract, title: "foo breaks billing totals" }); const dir = tmpDir("core-");
|
|
8424
|
+
const r = await run(w, { dir, builderModel: "opus-b" });
|
|
8425
|
+
assert.ok(builders(w).every((b) => b[3] === "opus-b"), "plan and build on the top model");
|
|
8426
|
+
const [pre] = events(dir, "BUILDER_PREROUTE");
|
|
8427
|
+
assert.deepEqual([pre.class, pre.tier, pre.model, pre.risk], ["risk", "top", "opus-b", ["title:payments"]]);
|
|
8428
|
+
const [route] = events(dir, "BUILDER_ROUTE");
|
|
8429
|
+
assert.deepEqual([route.class, route.tier, route.floor, route.change], ["risk", "top", "pre_route_risk", "same"]);
|
|
8430
|
+
assert.equal(r.builderRoute.tier, "top");
|
|
8431
|
+
assert.match(traj(w)[0], /Pre-contract sessions provisionally routed to the top tier \(risk: risk signal in the issue\)/);
|
|
8432
|
+
});
|
|
8433
|
+
|
|
8434
|
+
it("#5810: a size:L issue plans on the top tier; the contract route may still build mid", async () => {
|
|
8435
|
+
const w = world({ contract: docsContract, labels: [{ name: "size:L" }] }); const dir = tmpDir("core-");
|
|
8436
|
+
await run(w, { dir, builderModel: "opus-b" });
|
|
8437
|
+
const b = builders(w);
|
|
8438
|
+
assert.equal(b[0][3], "opus-b"); assert.equal(b[1][3], "claude-sonnet-5-5");
|
|
8439
|
+
const [route] = events(dir, "BUILDER_ROUTE");
|
|
8440
|
+
assert.deepEqual([route.pre_class, route.tier, route.change], ["large", "mid", "downgrade"]);
|
|
7908
8441
|
});
|
|
7909
8442
|
|
|
7910
8443
|
it("a failed precheck on the mid tier escalates: BUILDER_ESCALATED, the fix round runs on the top model, RUN_TERMINAL records it", async () => {
|
|
@@ -7928,7 +8461,7 @@ describe("#4394 builder model routing", () => {
|
|
|
7928
8461
|
assert.deepEqual(events(dir, "BUILDER_ESCALATED"), []);
|
|
7929
8462
|
});
|
|
7930
8463
|
|
|
7931
|
-
it("builder_routing off: plan, build and the resume keep builderModel; the class is still recorded on the top tier", async () => {
|
|
8464
|
+
it("builder_routing off: plan, build and the resume keep builderModel; the class is still recorded on the top tier", async () => { // #5810: the pre-route is top too
|
|
7932
8465
|
const w = world({ reviews: [conf({ verdict: "NONCONFORMING", requirements: [{ id: "R1", status: "partial", evidence: "the foo module", validated_by: "V1", note: "x" }] }), ok()] }); const dir = tmpDir("core-");
|
|
7933
8466
|
await run(w, { dir, builderModel: "opus-b", builderRouting: { mode: "off" } });
|
|
7934
8467
|
assert.ok(builders(w).length >= 3);
|
|
@@ -8137,8 +8670,8 @@ describe("#4395 lane profile", () => {
|
|
|
8137
8670
|
assert.match(p, /One turn, many calls: when several reads, greps, git show\/log\/blame or gh calls do not depend on each other, issue them all in the same turn/);
|
|
8138
8671
|
assert.match(p, /Read each file's ranges once .* and keep notes; don't re-read it\./);
|
|
8139
8672
|
}
|
|
8140
|
-
assert.ok(approxTokens(builderImplementPrompt()) <=
|
|
8141
|
-
assert.ok(approxTokens(builderPlanPrompt(7)) <=
|
|
8673
|
+
assert.ok(approxTokens(builderImplementPrompt()) <= 2000, `implement prompt is ${approxTokens(builderImplementPrompt())} of 2000 tokens`); // 1900: #5760; 2000: #5752
|
|
8674
|
+
assert.ok(approxTokens(builderPlanPrompt(7)) <= 2650, `plan prompt is ${approxTokens(builderPlanPrompt(7))} of 2125 tokens`);
|
|
8142
8675
|
});
|
|
8143
8676
|
|
|
8144
8677
|
it("runCliBackendAsync reports the first stream turn's context as baselineTokens; makeLeanRunner drops it on resume", async () => {
|
|
@@ -8150,10 +8683,13 @@ describe("#4395 lane profile", () => {
|
|
|
8150
8683
|
writeFileSync(`${d}/fake`, `#!/bin/sh\necho '${msg("m1", 5000)}'\necho '${msg("m2", 9000)}'\necho '${result}'\n`); chmodSync(`${d}/fake`, 0o755);
|
|
8151
8684
|
const r = await runCliBackendAsync({ spec: { name: "t" }, userMessage: "go", args: ["1"], cwd: d, bin: `${d}/fake`, logger: { log() {} }, stream: true });
|
|
8152
8685
|
assert.equal(r.baselineTokens, 5310);
|
|
8686
|
+
assert.equal(r.endTokens, 9310, "#5812: the last turn's context");
|
|
8153
8687
|
const fresh = await makeLeanRunner({ runCli: async () => ({ text: "", baselineTokens: 5310 }) })({ role: "builder", issue: 7, cwd: d, resume: null, system: "", prompt: "go" });
|
|
8154
8688
|
assert.equal(fresh.baselineTokens, 5310);
|
|
8155
8689
|
const resumed = await makeLeanRunner({ runCli: async () => ({ text: "", baselineTokens: 90000 }) })({ role: "builder", issue: 7, cwd: d, resume: "s-1", system: "", prompt: "go" });
|
|
8156
8690
|
assert.equal(resumed.baselineTokens, null);
|
|
8691
|
+
const ended = await makeLeanRunner({ runCli: async () => ({ text: "", endTokens: 9310, toolUses: [{ name: "Read", path: "a.js" }] }) })({ role: "builder", issue: 7, cwd: d, resume: "s-1", system: "", prompt: "go" });
|
|
8692
|
+
assert.deepEqual([ended.endTokens, ended.toolUses], [9310, [{ name: "Read", path: "a.js" }]], "#5812: passed through for the route hand-off");
|
|
8157
8693
|
});
|
|
8158
8694
|
});
|
|
8159
8695
|
|
|
@@ -8173,6 +8709,38 @@ describe("#4450 light lane: one builder session, derived contract, upgrade to th
|
|
|
8173
8709
|
const events = (dir, name) => readLog(dir, 7).filter((e) => e.event === name);
|
|
8174
8710
|
const ON = { light: { mode: "on", source: "text" } };
|
|
8175
8711
|
|
|
8712
|
+
it("#5751 recurrence: an issue matching two earlier merged fixes on its path skips the light lane, gets the design note and records the reason", async () => {
|
|
8713
|
+
const DESIGN = { why_failed: "#10 and #11 guarded one caller each", disposition: "replace", outcome: { metric: "null-input crashes in foo tests", target: "0" } };
|
|
8714
|
+
const ghApi = (a) => {
|
|
8715
|
+
const j = a.join(" ");
|
|
8716
|
+
if (j.includes("search/issues")) return [10, 11].map((n) => JSON.stringify({ number: n, title: `fix foo null ${n}`, pr: true, merged: true })).join("\n");
|
|
8717
|
+
if (/pulls\/1[01]\/files/.test(j)) return "src/foo.js\n";
|
|
8718
|
+
return null;
|
|
8719
|
+
};
|
|
8720
|
+
const w = lworld({ ghApi, body: `${BODY}\n\nRecurs #10`, contract: { ...CONTRACT, test_plan: TEST_PLAN, repro_test: RT, design: DESIGN } }), dir = tmpDir("light-");
|
|
8721
|
+
await run(w, { dir, ...ON });
|
|
8722
|
+
const rec = events(dir, "RECURRENCE");
|
|
8723
|
+
assert.equal(rec.length, 1);
|
|
8724
|
+
assert.deepEqual(rec[0].fixes.sort(), [10, 11]);
|
|
8725
|
+
assert.match(rec[0].reason, /^recurrence: 2 earlier merged fix\(es\) on the same symptom and area/);
|
|
8726
|
+
assert.equal(events(dir, "LIGHT_DONE").length, 0, "a recurrence never takes the light lane");
|
|
8727
|
+
const plan = builders(w).find((c) => /PLANNING ONLY/.test(c[4]));
|
|
8728
|
+
assert.ok(plan, "the full lane's plan session ran");
|
|
8729
|
+
assert.match(plan[4], /DESIGN LANE \(#5751\)/);
|
|
8730
|
+
assert.match(plan[4], /#10 fix foo null 10/);
|
|
8731
|
+
assert.ok(w.comments.some((c) => c.includes("<!-- FORGE:RECURRENCE -->") && /Routed to a design lane: recurrence: 2/.test(c)), "the reason is posted on the issue");
|
|
8732
|
+
assert.ok(!readLog(dir, 7).some((e) => JSON.stringify(e).includes("design_missing")), "a contract with a design block passes the design check");
|
|
8733
|
+
});
|
|
8734
|
+
|
|
8735
|
+
it("#5751 recurrence: no matching history keeps the light lane and the plan prompt unchanged", async () => {
|
|
8736
|
+
const w = lworld(), dir = tmpDir("light-");
|
|
8737
|
+
await run(w, { dir, ...ON });
|
|
8738
|
+
assert.equal(events(dir, "RECURRENCE").length, 0);
|
|
8739
|
+
assert.equal(events(dir, "LIGHT_ELIGIBILITY")[0].verdict, "eligible");
|
|
8740
|
+
assert.ok(builders(w).length >= 1 && !/PLANNING ONLY/.test(builders(w)[0][4]), "the light try ran (no plan call first)");
|
|
8741
|
+
assert.ok(!builders(w).some((c) => /DESIGN LANE/.test(c[4])));
|
|
8742
|
+
});
|
|
8743
|
+
|
|
8176
8744
|
it("nothing triggers: exactly one builder session (no plan) plus the review; the derived contract is frozen and posted", async () => {
|
|
8177
8745
|
const w = lworld(), dir = tmpDir("light-");
|
|
8178
8746
|
const r = await run(w, { dir, ...ON });
|
|
@@ -8478,7 +9046,7 @@ describe("prompt budgets (#4969)", () => {
|
|
|
8478
9046
|
assert.notEqual(moved, impl);
|
|
8479
9047
|
assert.equal(approxTokens(moved), approxTokens(impl));
|
|
8480
9048
|
assert.equal(approxTokens(impl.replaceAll(INSTALL_ROOT, "C:\\fd")), approxTokens(impl));
|
|
8481
|
-
assert.ok(approxTokens(moved) <=
|
|
9049
|
+
assert.ok(approxTokens(moved) <= 2000, `implement prompt from a deep checkout is ${approxTokens(moved)} of 2000 tokens`); // 1900: #5760; 2000: #5752
|
|
8482
9050
|
});
|
|
8483
9051
|
});
|
|
8484
9052
|
|
|
@@ -8916,6 +9484,31 @@ describe("design gate routing in the lane (#5330 R11, R13, R15)", () => {
|
|
|
8916
9484
|
});
|
|
8917
9485
|
});
|
|
8918
9486
|
|
|
9487
|
+
describe("spec-only page gate failures end design.spec_required (#5729)", () => {
|
|
9488
|
+
const PAGE = "web/src/app/(site)/contact/page.tsx";
|
|
9489
|
+
const brief = { design_spec: "FORGE:DESIGN_SPEC", seo: Object.fromEntries(["intent", "icp", "title", "h1", "meta", "structured_data", "links_in", "links_out", "gsc_baseline", "measure_by"].map((k) => [k, "x"])), geo: { surfaces: "llms.txt", agent_question: "q" } };
|
|
9490
|
+
const pc = { ...CONTRACT, page_gate: brief, deliverables: [{ id: "D1", path: PAGE, change: "repoint the link", requirements: ["R1"] }] };
|
|
9491
|
+
const pagesConfig = { ...parsePagesConfig(undefined, { hasAppPages: true }), require: ["design"] };
|
|
9492
|
+
const link = (h, x = "") => `<Link href="${h}"${x}>Book a demo</Link>`;
|
|
9493
|
+
const mk = (diff) => { const w = world({ contract: pc, changed: [PAGE, "test/foo.test.js"], reviews: [conf({}, pc, [PAGE, "test/foo.test.js"])] }); w.diffText = `+++ b/${PAGE}\n${diff}`; return w; };
|
|
9494
|
+
it("spec-only precheck failures end design.spec_required with no resume for 5729", async () => {
|
|
9495
|
+
const w = mk(`-${link("/contact")}\n+${link("/contact")}<Badge />\n`), r = await run(w, { pagesConfig });
|
|
9496
|
+
assert.equal(r.terminalReason, "needs-human");
|
|
9497
|
+
assert.equal(r.code, OUTCOME_CODES.DESIGN_SPEC_REQUIRED);
|
|
9498
|
+
assert.ok(w.comments.some((c) => c.includes("FORGE:NEEDS_HUMAN") && /recovery lane was spent/.test(c)));
|
|
9499
|
+
assert.ok(!builders(w).some((c) => /resume|conformance\.unimplemented/i.test(c[4] ?? "")), "no builder resume");
|
|
9500
|
+
assert.equal(classifyNeedsHuman({ outcome: "needs-human", code: r.code }), "terminal", "no recovery lane");
|
|
9501
|
+
});
|
|
9502
|
+
it("replay of #40917 spends no resume or recovery for 5729", async () => {
|
|
9503
|
+
const w = mk(`-${link("https://calendly.com/x", ' target="_self"')}\n+${link("/contact", ' target="_blank"')}\n`), r = await run(w, { pagesConfig });
|
|
9504
|
+
assert.equal(r.code, OUTCOME_CODES.DESIGN_SPEC_REQUIRED); // only the screenshot row is left, and it is terminal too
|
|
9505
|
+
const note = w.comments.find((c) => c.includes("FORGE:NEEDS_HUMAN")) ?? "";
|
|
9506
|
+
assert.ok(!/is a public page but the issue has no approved/.test(note), "no spec row for a copy edit");
|
|
9507
|
+
assert.match(note, /visual check/);
|
|
9508
|
+
assert.ok(!builders(w).some((c) => /conformance\.unimplemented/i.test(c[4] ?? "")), "no builder resume");
|
|
9509
|
+
});
|
|
9510
|
+
});
|
|
9511
|
+
|
|
8919
9512
|
describe("classification record in the plan prompt (#5557)", () => {
|
|
8920
9513
|
it("asks only for the judgment fields and never for units or migrations", () => {
|
|
8921
9514
|
const p = builderPlanPrompt(7);
|
|
@@ -9058,4 +9651,99 @@ describe("#5683 monorepo sub-project dependencies are not host tools", () => {
|
|
|
9058
9651
|
const h = withWeb(world({ contract: withTool("zzcheck") })); probing(h, "zzcheck");
|
|
9059
9652
|
assert.equal((await run(h, { dir: tmpDir("lean-5683b-"), ...remote })).code, "env.tool_missing");
|
|
9060
9653
|
});
|
|
9654
|
+
it("#5764 forgedock (the engine CLI that runs the lane in the sandbox) is never a remote tool miss", async () => {
|
|
9655
|
+
const remote = { placement: { where: "remote", reason: "mode remote" } };
|
|
9656
|
+
const w = world({ contract: { ...CONTRACT, validate: [...CONTRACT.validate, { id: "V2", command: "forgedock check" }] } });
|
|
9657
|
+
w.io.probeCommand = async (a) => ({ rc: /forgedock/.test(a.command) ? 127 : 0, output: /forgedock/.test(a.command) ? "sh: 1: forgedock: not found" : "" });
|
|
9658
|
+
const r = await run(w, { dir: tmpDir("lean-5764d-"), ...remote });
|
|
9659
|
+
assert.notEqual(r.code, "env.tool_missing");
|
|
9660
|
+
assert.doesNotMatch(w.comments.map((c) => c.body ?? c).join("\n"), /Remote sandbox lacks/);
|
|
9661
|
+
});
|
|
9662
|
+
it("#5764 a vite miss with a tracked package.json and a ruff miss with a tracked pyproject are prepared in the sandbox, never given a recipe", async () => {
|
|
9663
|
+
const remote = { placement: { where: "remote", reason: "mode remote" } };
|
|
9664
|
+
const withTool = (tool) => ({ ...CONTRACT, validate: [...CONTRACT.validate, { id: "V2", command: `${tool} check x` }] });
|
|
9665
|
+
const probing = (w, tool) => { w.io.probeCommand = async (a) => ({ rc: new RegExp(tool).test(JSON.stringify(a)) ? 127 : 0, output: "" }); };
|
|
9666
|
+
const installs = (w) => { const base = w.io.runCommand; const seen = []; w.io.runCommand = async (a) => { if (/apt-get install|tar -xz/.test(a.command)) seen.push(a.command); return base(a); }; return seen; };
|
|
9667
|
+
const w = withWeb(world({ contract: withTool("vite") })); probing(w, "vite"); const seen = installs(w); w.io.deps = { prepare: async () => [] };
|
|
9668
|
+
const r = await run(w, { dir: tmpDir("lean-5764b-"), ...remote });
|
|
9669
|
+
assert.notEqual(r.code, "env.tool_missing"); assert.equal(seen.length, 0);
|
|
9670
|
+
const g = world({ contract: withTool("ruff") }); probing(g, "ruff"); const seen2 = installs(g); g.io.deps = { prepare: async () => [] };
|
|
9671
|
+
const gi = g.io.git; g.io.git = async (a, ...x) => (a[0] === "ls-files" && !a.includes(".forge-lean/") ? `${await gi(a, ...x)}\napi/pyproject.toml` : gi(a, ...x));
|
|
9672
|
+
g.files[`${WT}/api/pyproject.toml`] = '[project]\ndependencies = ["ruff>=0.4"]\n';
|
|
9673
|
+
const r2 = await run(g, { dir: tmpDir("lean-5764c-"), ...remote });
|
|
9674
|
+
assert.notEqual(r2.code, "env.tool_missing"); assert.equal(seen2.length, 0);
|
|
9675
|
+
assert.doesNotMatch(g.comments.map((c) => c.body ?? c).join("\n"), /no lane_tools recipe/);
|
|
9676
|
+
});
|
|
9677
|
+
});
|
|
9678
|
+
|
|
9679
|
+
describe("#5820 required CI checks run in the lane before the PR opens", () => {
|
|
9680
|
+
const ciJob = (key, name, cmd) => ({ id: `gha:ci:${key}`, source: "github-actions", name, workflow: ".github/workflows/ci.yml", steps: [{ name: cmd, command: cmd, cwd: ".", kind: "check" }], services: [], needs: [] });
|
|
9681
|
+
const ciPlan = { version: 1, repo: WT, jobs: [ciJob("lint", "Lint", "pnpm lint"), ciJob("unit", "Unit tests", "pnpm vitest run"), ciJob("e2e", "E2E", "pnpm playwright test")] };
|
|
9682
|
+
const isCi = (c) => /ci-local\.sh' run/.test(c);
|
|
9683
|
+
/** A world whose ci-local plan is `ciPlan` and whose base requires `required`; `ciRun(command, n)` answers each derived run. */
|
|
9684
|
+
const ciWorld = ({ required = ["Lint", "E2E"], ciRun = () => ({ rc: 0, output: "CI_LOCAL_RESULT: PASS" }), plan = async () => ciPlan } = {}) => {
|
|
9685
|
+
const w = world(); w.ran = []; let n = 0, reqCalls = 0;
|
|
9686
|
+
w.io.ciLocalPlan = plan;
|
|
9687
|
+
w.io.requiredChecks = async () => (reqCalls++ ? [] : required); // the first read is the precheck's; the merge policy then sees none
|
|
9688
|
+
w.io.runCommand = async ({ command }) => { w.ran.push(command); w.seq.push(isCi(command) ? "ci-precheck" : "check"); return isCi(command) ? ciRun(command, n++) : { rc: 0, output: "" }; };
|
|
9689
|
+
return w;
|
|
9690
|
+
};
|
|
9691
|
+
|
|
9692
|
+
it("a failing required job goes back to the builder as a precheck fix round with its log, then the PR opens green", async () => {
|
|
9693
|
+
let fixed = false;
|
|
9694
|
+
const w = ciWorld({ ciRun: () => (fixed ? { rc: 0, output: "CI_LOCAL_RESULT: PASS" } : { rc: 1, output: "src/foo.js:3 no-unused-vars\nCI_LOCAL_FAIL: gha:ci:lint | step: pnpm lint | exit 1\nCI_LOCAL_RESULT: FAIL" }) });
|
|
9695
|
+
const inner = w.io.runner;
|
|
9696
|
+
w.io.runner = async (c) => { if (/declared check commands failed/.test(c.prompt)) fixed = true; return inner(c); };
|
|
9697
|
+
const dir = tmpDir("core-");
|
|
9698
|
+
const r = await run(w, { dir });
|
|
9699
|
+
assert.equal(r.terminalReason, "merged");
|
|
9700
|
+
const log = readLog(dir, 7);
|
|
9701
|
+
const plan = log.find((e) => e.event === "CI_PRECHECK_PLAN");
|
|
9702
|
+
assert.equal(plan.source, "required");
|
|
9703
|
+
assert.deepEqual(plan.commands.map((c) => [c.job, c.why, c.steps]), [["gha:ci:lint", 'required check "Lint"', ["pnpm lint"]]]);
|
|
9704
|
+
assert.match(plan.skipped.find((s) => s.job === "gha:ci:e2e").reason, /^heavy \(e2e\)/, "the required e2e job stays CI-only");
|
|
9705
|
+
assert.ok(`${WT}/.forge-lean/ci-precheck/gha_ci_lint.json` in w.files, "the one-job ci-local plan is written");
|
|
9706
|
+
const res = log.filter((e) => e.event === "CI_PRECHECK_RESULT");
|
|
9707
|
+
assert.deepEqual(res.map((e) => [e.round, e.green, e.results.map((x) => x.status)]), [[0, false, ["fail"]], [1, true, ["pass"]]]);
|
|
9708
|
+
const fix = builders(w).filter((b) => /declared check commands failed/.test(b[4]));
|
|
9709
|
+
assert.equal(fix.length, 1); assert.match(fix[0][4], /CI job "Lint"/); assert.match(fix[0][4], /no-unused-vars/);
|
|
9710
|
+
assert.ok(w.seq.indexOf("ci-precheck") < w.seq.indexOf("pr"), "the precheck runs before the PR");
|
|
9711
|
+
assert.ok(log.findIndex((e) => e.event === "CI_PRECHECK_PLAN") < log.findIndex((e) => e.event === "PR_OPENED"));
|
|
9712
|
+
});
|
|
9713
|
+
|
|
9714
|
+
it("green: no fix round, the PR opens; no required checks falls back to the lint and unit jobs", async () => {
|
|
9715
|
+
const w = ciWorld({ required: [] }); const dir = tmpDir("core-");
|
|
9716
|
+
const r = await run(w, { dir });
|
|
9717
|
+
assert.equal(r.terminalReason, "merged");
|
|
9718
|
+
const log = readLog(dir, 7);
|
|
9719
|
+
const plan = log.find((e) => e.event === "CI_PRECHECK_PLAN");
|
|
9720
|
+
assert.equal(plan.source, "fallback"); assert.deepEqual(plan.commands.map((c) => c.job), ["gha:ci:lint", "gha:ci:unit"]);
|
|
9721
|
+
assert.equal(w.ran.filter(isCi).length, 2);
|
|
9722
|
+
assert.deepEqual(log.filter((e) => e.event === "CI_PRECHECK_RESULT").map((e) => e.green), [true]);
|
|
9723
|
+
assert.equal(builders(w).filter((b) => /declared check commands failed/.test(b[4])).length, 0);
|
|
9724
|
+
assert.equal(w.prs.length, 1);
|
|
9725
|
+
});
|
|
9726
|
+
|
|
9727
|
+
it("unrunnable (ci-local degraded, or no planner) is recorded with its reason and never blocks the PR", async () => {
|
|
9728
|
+
const w = ciWorld({ ciRun: () => ({ rc: 2, output: "CI_LOCAL_RESULT: DEGRADED reason=budget_exhausted" }) }); const dir = tmpDir("core-");
|
|
9729
|
+
const r = await run(w, { dir, verify: { ...parseVerify({}), precheckBlock: true } });
|
|
9730
|
+
assert.equal(r.terminalReason, "merged");
|
|
9731
|
+
const res = readLog(dir, 7).filter((e) => e.event === "CI_PRECHECK_RESULT");
|
|
9732
|
+
assert.deepEqual(res.map((e) => e.results.map((x) => [x.status, x.reason])), [[["unrunnable", "budget_exhausted"]]]);
|
|
9733
|
+
assert.equal(builders(w).filter((b) => /declared check commands failed/.test(b[4])).length, 0, "no fix round for an unrunnable job");
|
|
9734
|
+
const t = traj(w).join("\n"); assert.match(t, /CI precheck job Lint unrunnable locally \(budget_exhausted\)/);
|
|
9735
|
+
|
|
9736
|
+
const w2 = ciWorld({ plan: async () => { throw new Error("yq not found"); } }); const dir2 = tmpDir("core-");
|
|
9737
|
+
const r2 = await run(w2, { dir: dir2 });
|
|
9738
|
+
assert.equal(r2.terminalReason, "merged"); assert.equal(w2.ran.filter(isCi).length, 0);
|
|
9739
|
+
const p2 = readLog(dir2, 7).find((e) => e.event === "CI_PRECHECK_PLAN");
|
|
9740
|
+
assert.match(p2.unrunnable[0].reason, /CI check plan unavailable: yq not found/);
|
|
9741
|
+
});
|
|
9742
|
+
|
|
9743
|
+
it("lean.ci_precheck off runs nothing and logs no plan", async () => {
|
|
9744
|
+
const w = ciWorld(); const dir = tmpDir("core-");
|
|
9745
|
+
await run(w, { dir, precheck: { ci: { mode: "off", include: [], exclude: [], maxJobs: 8 } } });
|
|
9746
|
+
assert.equal(w.ran.filter(isCi).length, 0);
|
|
9747
|
+
assert.equal(readLog(dir, 7).filter((e) => /^CI_PRECHECK/.test(e.event)).length, 0);
|
|
9748
|
+
});
|
|
9061
9749
|
});
|