forgedock 1.61.1 → 1.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/config-schema.mjs +10 -1
- package/bin/engine/outcome-codes.mjs +4 -0
- package/bin/engine-cli.mjs +160 -18
- package/bin/env/env.mjs +6 -4
- package/bin/forge-home-check.mjs +91 -0
- package/bin/forgedock.mjs +50 -7
- package/bin/gc.mjs +2 -0
- package/bin/hooks/pre-tool-use.mjs +4 -0
- package/bin/journey.mjs +55 -5
- package/bin/lean/admission.mjs +16 -5
- package/bin/lean/batch-health.mjs +55 -16
- package/bin/lean/batch-health.test.mjs +67 -1
- package/bin/lean/batch.mjs +8 -0
- package/bin/lean/batch.test.mjs +5 -0
- package/bin/lean/ceiling.mjs +20 -0
- package/bin/lean/ceiling.test.mjs +33 -2
- package/bin/lean/ci-gate.mjs +240 -0
- package/bin/lean/ci-gate.test.mjs +227 -0
- package/bin/lean/ci-precheck.mjs +178 -0
- package/bin/lean/ci-precheck.test.mjs +149 -0
- package/bin/lean/conformance.mjs +118 -20
- package/bin/lean/conformance.test.mjs +193 -3
- package/bin/lean/context.test.mjs +7 -6
- package/bin/lean/dag.mjs +128 -0
- package/bin/lean/dag.test.mjs +131 -0
- package/bin/lean/decisions.mjs +5 -4
- package/bin/lean/decisions.test.mjs +11 -0
- package/bin/lean/delguard.mjs +84 -0
- package/bin/lean/delguard.test.mjs +104 -0
- package/bin/lean/depcache.mjs +125 -17
- package/bin/lean/depcache.test.mjs +111 -0
- package/bin/lean/design-gate.mjs +5 -5
- package/bin/lean/design-gate.test.mjs +14 -0
- package/bin/lean/effects.mjs +81 -7
- package/bin/lean/execution.mjs +81 -15
- package/bin/lean/execution.test.mjs +156 -3
- package/bin/lean/forgedock-lane-workflow.test.mjs +35 -0
- package/bin/lean/guardgate.mjs +30 -7
- package/bin/lean/guardgate.test.mjs +44 -1
- package/bin/lean/guards.test.mjs +1 -1
- package/bin/lean/heavy.test.mjs +87 -0
- package/bin/lean/hotarea.mjs +73 -0
- package/bin/lean/hotarea.test.mjs +73 -0
- package/bin/lean/issuewatch-reconcile.mjs +20 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
- package/bin/lean/lanecheck.mjs +27 -3
- package/bin/lean/lanecheck.test.mjs +47 -5
- package/bin/lean/laneconfine.mjs +83 -0
- package/bin/lean/laneconfine.test.mjs +113 -0
- package/bin/lean/lean.mjs +398 -91
- package/bin/lean/lean.test.mjs +792 -26
- package/bin/lean/live-reconcile.mjs +169 -0
- package/bin/lean/live-reconcile.test.mjs +176 -0
- package/bin/lean/orchestrate-envhold.test.mjs +245 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +39 -0
- package/bin/lean/orchestrate.mjs +207 -17
- package/bin/lean/outcomeevidence.mjs +104 -0
- package/bin/lean/outcomeevidence.test.mjs +78 -0
- package/bin/lean/page-capture.mjs +68 -0
- package/bin/lean/page-capture.test.mjs +44 -0
- package/bin/lean/pagegate.mjs +46 -7
- package/bin/lean/pagegate.test.mjs +66 -1
- package/bin/lean/postdeploy-check.mjs +18 -4
- package/bin/lean/postdeploy-check.test.mjs +32 -1
- package/bin/lean/prefilter.mjs +36 -4
- package/bin/lean/prefilter.test.mjs +31 -1
- package/bin/lean/preflight.mjs +22 -0
- package/bin/lean/preflight.test.mjs +19 -1
- package/bin/lean/probe.mjs +18 -0
- package/bin/lean/probe.test.mjs +40 -0
- package/bin/lean/prompts.mjs +41 -4
- package/bin/lean/recovery.test.mjs +20 -0
- package/bin/lean/recurrence.mjs +133 -0
- package/bin/lean/recurrence.test.mjs +99 -0
- package/bin/lean/release-config.mjs +2 -1
- package/bin/lean/release-config.test.mjs +18 -0
- package/bin/lean/release-control.mjs +4 -2
- package/bin/lean/release-control.test.mjs +15 -0
- package/bin/lean/release-merge-hold.mjs +65 -0
- package/bin/lean/release-merge-hold.test.mjs +69 -0
- package/bin/lean/release-review.mjs +26 -9
- package/bin/lean/release-review.test.mjs +53 -0
- package/bin/lean/release-status.mjs +3 -1
- package/bin/lean/release-status.test.mjs +11 -0
- package/bin/lean/release.test.mjs +26 -1
- package/bin/lean/render.mjs +8 -7
- package/bin/lean/repro-output.test.mjs +45 -0
- package/bin/lean/routing.mjs +49 -0
- package/bin/lean/routing.test.mjs +54 -1
- package/bin/lean/run-issue-placement.test.mjs +30 -1
- package/bin/lean/sandbox-actions.mjs +121 -0
- package/bin/lean/sandbox-actions.test.mjs +94 -0
- package/bin/lean/sandbox-provider.contract.test.mjs +22 -1
- package/bin/lean/sandbox-remote.mjs +3 -1
- package/bin/lean/schedd-health.mjs +14 -2
- package/bin/lean/schedd-health.test.mjs +13 -0
- package/bin/lean/schedd.mjs +43 -17
- package/bin/lean/schedd.test.mjs +61 -1
- package/bin/lean/toolchain.mjs +16 -6
- package/bin/lean/toolplace.mjs +12 -0
- package/bin/lean/weakguard.mjs +105 -0
- package/bin/lean/weakguard.test.mjs +59 -0
- package/bin/lean/winspawn.mjs +61 -0
- package/bin/lean/winspawn.test.mjs +45 -0
- package/bin/lean/worktree.mjs +3 -1
- package/bin/lean/worktree.test.mjs +11 -0
- package/bin/pool/agent.mjs +215 -15
- package/bin/pool/cache-sweep.mjs +74 -0
- package/bin/pool/cli.mjs +11 -3
- package/bin/pool/docker.mjs +33 -2
- package/bin/pool/health.mjs +38 -0
- package/bin/pool/lane-tools.mjs +23 -4
- package/bin/pool/lane-tools.test.mjs +12 -1
- package/bin/pool/router.mjs +21 -3
- package/bin/runner.mjs +37 -0
- package/bin/splash-scene.mjs +356 -0
- package/bin/win-hide-children.mjs +114 -0
- package/commands/orchestrate.md +18 -27
- package/commands/review-pr-agents/infra.md +1 -0
- package/commands/review-pr-staging.md +2 -2
- package/docs/CONFIG.md +60 -3
- package/docs/OUTCOME-CODES.md +3 -0
- package/package.json +1 -1
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +1 -1
- package/plugins/forgedock-splash/README.md +1 -1
- package/plugins/forgedock-splash/hooks/scene.ts +142 -8
- package/pool/README.md +6 -0
- package/pool/image/entrypoint.sh +1 -0
- package/scripts/acceptance-red-green.sh +8 -3
- package/scripts/acceptance-red-green.test.sh +8 -0
- package/scripts/check-spec-size.sh +3 -1
- package/scripts/gen-splash-scene.mjs +24 -0
- package/scripts/review-staging-pre.sh +8 -3
- package/scripts/review-staging-pre.test.sh +2 -0
package/bin/lean/lean.test.mjs
CHANGED
|
@@ -7,10 +7,14 @@ 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";
|
|
16
|
+
import os from "node:os";
|
|
17
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
14
18
|
import { runCore, contractHash, isProtectedLaneBranch, classifyBlock, builderFixable } from "./lean.mjs";
|
|
15
19
|
import { parseFactsComment, normaliseFacts, renderFactsRecord, FACTS_MARKER } from "./facts.mjs";
|
|
16
20
|
import { makeLedger } from "./ledger.mjs";
|
|
@@ -29,6 +33,7 @@ import { makeRunTmp, wrapLaneLimits, laneCapNotice, systemdRunAvailable, makeLea
|
|
|
29
33
|
import { retrying, ghCacheRetry, refreshAuthOnce, GH_AUTH_RE, PUSH_TRANSIENT_RE } from "./retry.mjs";
|
|
30
34
|
import { checkAdmission, hostParallelism } from "./admission.mjs";
|
|
31
35
|
import { OUTCOME_CODES, ENV_VALIDATE_TIMEOUT, ENV_VALIDATE_PLACEMENT, classifyNeedsHuman } from "../engine/outcome-codes.mjs";
|
|
36
|
+
import { parsePagesConfig } from "./pagegate.mjs";
|
|
32
37
|
import * as refactorMod from "./refactor.mjs";
|
|
33
38
|
import { readAdmission, readConformanceMode, readReviewIncomplete, readEnvConfig, readContextPack } from "../engine-cli.mjs";
|
|
34
39
|
import { prepareToolchain } from "./toolchain.mjs";
|
|
@@ -40,8 +45,22 @@ const INSTALL_PATH_RE = /\S*?[\\/](?=bin[\\/][\w.\\/-]+\.mjs)/g;
|
|
|
40
45
|
const approxTokens = (s) => rawTokens(String(s).replaceAll(INSTALL_ROOT, "<root>").replace(INSTALL_PATH_RE, "<root>/"));
|
|
41
46
|
// orchestrateFromCli opens the host lane registry (#4191): keep it in a temp dir.
|
|
42
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
|
+
}
|
|
43
60
|
|
|
44
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, "/");
|
|
45
64
|
/** #5333: the engine appends the stage-stamp rule to every builder prompt; strip it to compare against the bare template. */
|
|
46
65
|
const unstamp = (s) => String(s).replace(/\n\nStage notes: make the first line[^\n]*/, "");
|
|
47
66
|
const STAGE_MD = {
|
|
@@ -104,12 +123,15 @@ function world(o = {}) {
|
|
|
104
123
|
if (k === "pr view" && a.at(-1) === "state" && a.at(-2) === "--json") return JSON.stringify({ state: o.prState ?? "OPEN" });
|
|
105
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
|
|
106
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
|
|
107
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
|
|
108
130
|
if (k === "pr list") return JSON.stringify(w.prList);
|
|
109
131
|
if (k === "repo view") return `${o.defaultBranch ?? "main"}\n`;
|
|
110
132
|
if (k === "issue view" && a.includes("milestone")) { w.seq.push("lane"); return JSON.stringify({ milestone: o.milestone ? { title: o.milestone } : null }); }
|
|
111
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 } : {}) }); }
|
|
112
|
-
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 } : {}) });
|
|
113
135
|
if (k === "pr edit") { w.prEdits.push(a); return ""; }
|
|
114
136
|
if (k === "label create") { w.labelCreates = [...(w.labelCreates ?? []), a]; return ""; }
|
|
115
137
|
if (k === "issue comment" && w.commentErrors.length) throw new Error(w.commentErrors.shift());
|
|
@@ -148,6 +170,9 @@ function world(o = {}) {
|
|
|
148
170
|
if (a[0] === "rev-parse" && a[1] === "HEAD^{tree}") return "0".repeat(40);
|
|
149
171
|
if (a.includes("commit-tree")) return "c".repeat(40);
|
|
150
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 ""; }
|
|
151
176
|
if (a[0] === "rm" && a[1] === "--cached" && w.added) w.added = w.added.filter((f) => !a.includes(f));
|
|
152
177
|
if (a[0] === "diff" && a.includes("--diff-filter=U")) return w.conflictFiles.join("\n");
|
|
153
178
|
if (a[0] === "diff" && a[1] === "--check") return "";
|
|
@@ -205,7 +230,7 @@ function world(o = {}) {
|
|
|
205
230
|
waitCiGreen: async () => (w.waits.length ? w.waits.shift() : { rc: 0, text: `CI_GATE_HEAD: ${w.head}` }),
|
|
206
231
|
transitionLabel: async (n, s) => { w.labels.push(s); w.seq.push(`label:${s}`); },
|
|
207
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); } } } : {}),
|
|
208
|
-
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; }},
|
|
209
234
|
fileFollowups: async ({ parent, items }) => { w.followups.push({ parent, items }); if (o.followupError) throw Object.assign(new Error(o.followupError), { stdout: o.followupStdout ?? "" });
|
|
210
235
|
if (o.followupRet) return o.followupRet(w.followups.length, items);
|
|
211
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])); },
|
|
@@ -214,6 +239,11 @@ function world(o = {}) {
|
|
|
214
239
|
}
|
|
215
240
|
const run = (w, extra = {}) => runCore({ issue: 7, repo: "o/r", lane: "staging", cwd: "/repo", worktreeRoot: "/wt", dir: tmpDir("core-"), conformance: "enforce",
|
|
216
241
|
io: w.io, emitTelemetry: async (r) => w.telemetry.push(r), random: () => 0.5, ...extra });
|
|
242
|
+
/** #5728: run `fn` with a fixed, idle load average: precheck.mjs sizes its timeout retry from the real host load, so a loaded host defers the check to CI. */
|
|
243
|
+
async function atIdleLoad(fn) {
|
|
244
|
+
const real = os.loadavg; os.loadavg = () => [0.1, 0.1, 0.1]; syncBuiltinESMExports();
|
|
245
|
+
try { return await fn(); } finally { os.loadavg = real; syncBuiltinESMExports(); }
|
|
246
|
+
}
|
|
217
247
|
const builders = (w) => w.calls.filter((c) => c[0] === "runner" && c[1] === "builder");
|
|
218
248
|
const reviewers = (w) => w.calls.filter((c) => c[0] === "runner" && c[1] === "reviewer");
|
|
219
249
|
const traj = (w) => w.comments.filter((c) => c.includes("<!-- FORGE:TRAJECTORY -->"));
|
|
@@ -231,7 +261,7 @@ describe("core work-on", () => {
|
|
|
231
261
|
assert.match(w.comments[1], /^<!-- FORGE:INVESTIGATION -->\n<!-- FORGE:VALIDATE -->\n## Investigation Report\n\*\*Verdict\*\*: CONFIRMED/);
|
|
232
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");
|
|
233
263
|
assert.match(w.comments[2], /\| R1 \| foo must handle a null argument without throwing\. \| deliver \|/);
|
|
234
|
-
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
|
|
235
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`/);
|
|
236
266
|
assert.match(w.comments[4], /## Conformance Review\n\*\*Verdict:\*\* CONFORMS/);
|
|
237
267
|
assert.match(w.comments[4], /\| R1 \| implemented \| src\/foo.js:3 \| V1 \|/);
|
|
@@ -325,6 +355,19 @@ describe("core work-on", () => {
|
|
|
325
355
|
assert.ok(traj(w)[0].includes("| Close | issue closed (completed) |"));
|
|
326
356
|
});
|
|
327
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
|
+
|
|
328
371
|
it("a failed needs-human comment is recorded as an anomaly and the lane still ends needs-human (#4905)", async () => {
|
|
329
372
|
const w = world({ changed: [], result: { status: "invalid", summary: "trust me", evidence: [], tests: [] } });
|
|
330
373
|
const gh = w.io.gh;
|
|
@@ -906,6 +949,43 @@ describe("core work-on", () => {
|
|
|
906
949
|
assert.ok(!l.edits.some((e) => e.includes("--add-label") && e.includes("needs-human")), JSON.stringify(l.edits));
|
|
907
950
|
});
|
|
908
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
|
+
|
|
909
989
|
describe("#5652 in-sandbox recipe install", () => {
|
|
910
990
|
const remote = { placement: { where: "remote", reason: "mode remote" } };
|
|
911
991
|
const withTool = (tool) => ({ ...CONTRACT, validate: [...CONTRACT.validate, { id: "V2", command: `${tool} check x` }] });
|
|
@@ -920,6 +1000,16 @@ describe("core work-on", () => {
|
|
|
920
1000
|
assert.notEqual(r.code, "env.tool_missing");
|
|
921
1001
|
assert.notEqual(r.terminalReason, "needs-human");
|
|
922
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
|
+
});
|
|
923
1013
|
it("a tool with no recipe ends the lane naming it, saying no recipe exists and pointing to execution.lane_tools", async () => {
|
|
924
1014
|
const w = world({ contract: withTool("zzcheck") }); probing(w, "zzcheck", () => false);
|
|
925
1015
|
const r = await run(w, { dir: tmpDir("lean-5652b-"), ...remote });
|
|
@@ -927,6 +1017,7 @@ describe("core work-on", () => {
|
|
|
927
1017
|
const txt = w.comments.map((c) => c.body ?? c).join("\n");
|
|
928
1018
|
assert.match(txt, /lacks zzcheck, and no lane_tools recipe exists for it/);
|
|
929
1019
|
assert.match(txt, /execution\.lane_tools/);
|
|
1020
|
+
assert.match(txt, /Known recipes: .*shellcheck/);
|
|
930
1021
|
});
|
|
931
1022
|
it("a failed in-sandbox install ends the lane with the stderr tail", async () => {
|
|
932
1023
|
const w = world({ contract: withTool("promtool") }); probing(w, "promtool", () => false);
|
|
@@ -1023,7 +1114,7 @@ describe("core work-on", () => {
|
|
|
1023
1114
|
});
|
|
1024
1115
|
|
|
1025
1116
|
it("builder uses the CLI default model; reviewer is read-only Sonnet unless configured", async () => {
|
|
1026
|
-
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
|
|
1027
1118
|
assert.equal(builders(w)[0][3], null);
|
|
1028
1119
|
assert.equal(builders(w)[0][5], false);
|
|
1029
1120
|
assert.equal(reviewers(w)[0][3], "claude-sonnet-5-5");
|
|
@@ -1534,6 +1625,63 @@ describe("worktree salvage and orphaned processes (#4162)", () => {
|
|
|
1534
1625
|
assert.equal((await run(w)).terminalReason, "merged");
|
|
1535
1626
|
assert.equal(salvageRefs(w).length, 0);
|
|
1536
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
|
+
});
|
|
1537
1685
|
|
|
1538
1686
|
it("procsInDir reads cwd links from a /proc tree and skips this process and its ancestors", () => {
|
|
1539
1687
|
const root = tmpDir("proc-"), wtDir = tmpDir("wt-");
|
|
@@ -1749,6 +1897,48 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1749
1897
|
assert.equal((await runShadow(p)).terminalReason, "merged"); assert.equal(builders(p).length, 2);
|
|
1750
1898
|
});
|
|
1751
1899
|
|
|
1900
|
+
it("#5728 engine-folded G rows with no recorded result are run by the engine: a pass merges with no resume, a failure resumes once as validate_failed", async () => {
|
|
1901
|
+
const GC = { ...CONTRACT, validate: [...CONTRACT.validate, { id: "G1", command: "node --test test/bar.test.js", regression: true }, { id: "G2", command: "node --test test/baz.test.js", regression: true }] };
|
|
1902
|
+
const vrows = [{ id: "V1", command: CONTRACT.validate[0].command, exit: 0 }];
|
|
1903
|
+
const w = world({ contract: GC, validation: vrows }), ran = [];
|
|
1904
|
+
w.io.runCommand = async (a) => { ran.push(a.command); return { rc: 0, output: "" }; };
|
|
1905
|
+
const r = await runShadow(w);
|
|
1906
|
+
assert.equal(r.terminalReason, "merged"); assert.equal(builders(w).length, 2, "plan + implement: no resume for G rows");
|
|
1907
|
+
assert.ok(ran.includes("node --test test/bar.test.js") && ran.includes("node --test test/baz.test.js"), "the engine ran G1 and G2");
|
|
1908
|
+
assert.ok(w.comments.some((c) => /Validate G1, G2 had no recorded result: the engine ran them/.test(c)), "decision note");
|
|
1909
|
+
// a failing engine run is an actionable resume, never validate_missing
|
|
1910
|
+
const f = world({ contract: GC, validation: vrows, resumeValidation: [...vrows, { id: "G1", command: "x", exit: 0 }, { id: "G2", command: "x", exit: 0 }] });
|
|
1911
|
+
f.io.runCommand = async (a) => (/bar/.test(a.command) ? { rc: 1, output: "AssertionError: bar boom" } : { rc: 0, output: "" });
|
|
1912
|
+
await runShadow(f);
|
|
1913
|
+
assert.equal(builders(f).length, 3, "one resume");
|
|
1914
|
+
assert.match(builders(f)[2][4], /validate G1 .*failed \(exit 1, run by the engine: no recorded result\)[\s\S]*bar boom/);
|
|
1915
|
+
assert.doesNotMatch(builders(f)[2][4], /has no recorded result`?$|validate G1 \(`[^`]*`\) has no recorded result/);
|
|
1916
|
+
});
|
|
1917
|
+
it("#5728 a CI-verified head is not rerun for rows left to CI; with no io.runCommand the row stays validate_missing", async () => {
|
|
1918
|
+
const GC = { ...CONTRACT, validate: [...CONTRACT.validate, { id: "G1", command: "node --test test/bar.test.js", regression: true }] };
|
|
1919
|
+
const w = world({ contract: GC, validation: [{ id: "V1", command: CONTRACT.validate[0].command, exit: 0 }] });
|
|
1920
|
+
delete w.io.runCommand;
|
|
1921
|
+
const r = await runShadow(w);
|
|
1922
|
+
assert.notEqual(r.terminalReason, "merged"); assert.ok(builders(w).length >= 3, "validate_missing resumes the builder");
|
|
1923
|
+
});
|
|
1924
|
+
it("#5728 a fix resume that hits the context ceiling restarts with the failure list, not the full build prompt", async () => {
|
|
1925
|
+
const GC = { ...CONTRACT, validate: [...CONTRACT.validate, { id: "G1", command: "node --test test/bar.test.js", regression: true }] };
|
|
1926
|
+
const vrows = [{ id: "V1", command: CONTRACT.validate[0].command, exit: 0 }];
|
|
1927
|
+
const w = world({ contract: GC, validation: vrows, resumeValidation: [...vrows, { id: "G1", command: "x", exit: 0 }] });
|
|
1928
|
+
w.io.runCommand = async () => ({ rc: 1, output: "AssertionError: bar boom" });
|
|
1929
|
+
const orig = w.io.runner, seen = []; let thrown = false;
|
|
1930
|
+
w.io.runner = async (c) => {
|
|
1931
|
+
if (c.role === "builder") seen.push(c.prompt);
|
|
1932
|
+
if (c.role === "builder" && c.resume && !thrown && /^The change does not conform/.test(c.prompt)) { thrown = true; throw Object.assign(new Error("ctx"), { code: "CLI_CONTEXT", context: 130000, turns: 1, usage: null }); }
|
|
1933
|
+
return orig(c);
|
|
1934
|
+
};
|
|
1935
|
+
await runShadow(w, { dir: tmpDir("core-ctx-"), contextCeilingTokens: 120000 });
|
|
1936
|
+
assert.ok(thrown, "the fix resume hit the ceiling");
|
|
1937
|
+
const restart = seen[seen.indexOf(seen.find((x, i) => i > 1 && /validate G1/.test(x))) + 1];
|
|
1938
|
+
assert.ok(restart, "a restart followed the resume");
|
|
1939
|
+
assert.match(restart, /validate G1/); assert.match(restart, /fixing one failure/);
|
|
1940
|
+
assert.doesNotMatch(restart, /The engine froze \.forge-lean\/contract\.json/);
|
|
1941
|
+
});
|
|
1752
1942
|
it("#4328 freeze-time preflight: a validate needing a module the host lacks gets the one contract correction, before any build", async () => {
|
|
1753
1943
|
const pyC = { ...CONTRACT, validate: [{ id: "V1", command: `python3 -c "import yaml"` }] }, uvC = { ...CONTRACT, validate: [{ id: "V1", command: `uv run python -c "import yaml"` }] };
|
|
1754
1944
|
const probe = (w) => { const ran = []; w.io.probeCommand = async (a) => { ran.push(a); return { rc: /^'python3' .*'yaml'/.test(a.command) ? 3 : 0, output: "" }; }; return ran; };
|
|
@@ -2219,8 +2409,8 @@ describe("hotspot prevention (forge#4195): plan facts, build rule, unexempted gr
|
|
|
2219
2409
|
assert.equal(hotspotBuildRule(null), ""); assert.equal(hotspotBuildRule(facts([], { enabled: false })), "");
|
|
2220
2410
|
const plan = builderPlanPrompt(7) + hotspotPlanNote(facts([HOT, { ...HOT, path: "a/b.py" }, { ...HOT, path: "c/d.py" }]));
|
|
2221
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).
|
|
2222
|
-
assert.ok(approxTokens(plan) <=
|
|
2223
|
-
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)
|
|
2224
2414
|
});
|
|
2225
2415
|
|
|
2226
2416
|
it("#4519 generated_paths: both prompts name the globs (even with the gate off), and an amendment adding one blocks", async () => {
|
|
@@ -2324,7 +2514,8 @@ describe("bug lanes freeze a red-green repro_test (#4271)", () => {
|
|
|
2324
2514
|
const prev = process.env.FORGE_HOST_PARALLELISM; process.env.FORGE_HOST_PARALLELISM = "3";
|
|
2325
2515
|
try { assert.equal((await run(w, { envSetup: "make setup", precheck: { commands: ["npm run lint"] } })).terminalReason, "merged"); }
|
|
2326
2516
|
finally { if (prev === undefined) delete process.env.FORGE_HOST_PARALLELISM; else process.env.FORGE_HOST_PARALLELISM = prev; }
|
|
2327
|
-
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");
|
|
2328
2519
|
assert.match(lane.TMPDIR, /\/runs\/7-/, "the builder ran with the run TMPDIR");
|
|
2329
2520
|
assert.deepEqual(w.rgCalls.map((x) => x.env), [lane], "red-green gets the lane env, not the daemon's");
|
|
2330
2521
|
assert.deepEqual(ran.map((a) => [a.command, a.env]), [["npm run lint", lane], ["node --test test/foo.test.js", lane]]);
|
|
@@ -2348,6 +2539,35 @@ describe("bug lanes freeze a red-green repro_test (#4271)", () => {
|
|
|
2348
2539
|
assert.equal((await run(fixed, { conformance: "shadow" })).terminalReason, "merged"); assert.equal(fixed.rgCalls.length, 2);
|
|
2349
2540
|
});
|
|
2350
2541
|
|
|
2542
|
+
it("#5732 a head that failed on an absent interpreter is env.repro_unrunnable with its output, no builder resume", async () => {
|
|
2543
|
+
const w = rworld([{ base: "SKIPPED", head: "FAILED" }]);
|
|
2544
|
+
w.io.runCommand = async () => ({ rc: 1, output: "Creating virtualenv\npoetry env use: python3.11 not found" });
|
|
2545
|
+
const r = await run(w, { conformance: "enforce" });
|
|
2546
|
+
assert.equal(r.code, "env.repro_unrunnable"); assert.equal(w.merges.length, 0);
|
|
2547
|
+
assert.equal(builders(w).length, 2, "plan + implement only");
|
|
2548
|
+
assert.match(nh(w), /output tail/); assert.match(nh(w), /python3\.11 not found/);
|
|
2549
|
+
});
|
|
2550
|
+
it("#5732 a red head's output tail reaches the builder resume and the needs-human comment", async () => {
|
|
2551
|
+
const w = rworld([{ base: "SKIPPED", head: "FAILED" }]);
|
|
2552
|
+
w.io.runCommand = async () => ({ rc: 1, output: "not ok 1 - foo handles null\n AssertionError: expected 3, got undefined" });
|
|
2553
|
+
const r = await run(w, { conformance: "enforce" });
|
|
2554
|
+
assert.equal(r.code, "conformance.unimplemented"); assert.equal(builders(w).length, 3, "one resume");
|
|
2555
|
+
assert.match(builders(w)[2][4], /AssertionError: expected 3, got undefined/);
|
|
2556
|
+
assert.match(nh(w), /AssertionError: expected 3, got undefined/);
|
|
2557
|
+
});
|
|
2558
|
+
it("#5732 remote placement: a head failure with no assertion text goes to the host recovery lane; one with assertion text resumes the builder", async () => {
|
|
2559
|
+
const remote = { conformance: "enforce", placement: { where: "remote", reason: "mode remote" } };
|
|
2560
|
+
const w = rworld([{ base: "SKIPPED", head: "FAILED" }]);
|
|
2561
|
+
w.io.runCommand = async () => ({ rc: 1, output: "Traceback (most recent call last):\nOSError: [Errno 30] Read-only file system: '/sandbox/.cache'" });
|
|
2562
|
+
const r = await run(w, remote);
|
|
2563
|
+
assert.equal(r.code, ENV_VALIDATE_PLACEMENT); assert.equal(builders(w).length, 2, "no builder resume"); assert.equal(w.merges.length, 0);
|
|
2564
|
+
assert.match(nh(w), /Read-only file system/);
|
|
2565
|
+
const a = rworld([{ base: "SKIPPED", head: "FAILED" }]);
|
|
2566
|
+
a.io.runCommand = async () => ({ rc: 1, output: "E AssertionError: 0.5 != 0.4" });
|
|
2567
|
+
const ar = await run(a, remote);
|
|
2568
|
+
assert.notEqual(ar.code, ENV_VALIDATE_PLACEMENT); assert.equal(builders(a).length, 3, "a real red test resumes the builder");
|
|
2569
|
+
});
|
|
2570
|
+
|
|
2351
2571
|
it("#5080 a repro that already passes on the base ends already-fixed: the issue closes as completed citing the base, nothing merges, no resume", async () => {
|
|
2352
2572
|
for (const conformance of ["enforce", "shadow"]) {
|
|
2353
2573
|
const w = rworld([{ base: "RAN", head: "RAN" }], { changed: ["test/foo.test.js"] });
|
|
@@ -2729,8 +2949,8 @@ describe("comment templates", () => {
|
|
|
2729
2949
|
|
|
2730
2950
|
it("plan and implement prompts carry the stage templates and the contract schema within budget", () => {
|
|
2731
2951
|
const plan = builderPlanPrompt(7), impl = builderImplementPrompt();
|
|
2732
|
-
assert.ok(approxTokens(plan) <=
|
|
2733
|
-
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)
|
|
2734
2954
|
for (const h of ["### What Was Claimed", "### What We Found", "### Root Cause", "### Affected Files", "### Sibling Sweep", "### History", "### Recommendation", "### Related Issues", "### Test plan",
|
|
2735
2955
|
"investigation.md", "contract.json", "PLANNING ONLY", '"requirements"', '"deliverables"', '"preserve"', '"validate"', "verbatim", "defer", "post-deploy"]) assert.ok(plan.includes(h), h);
|
|
2736
2956
|
for (const h of ["### Approach", "### Changes", "### Acceptance Criteria Status", "### Verification", "### Notes", "implementation.md", "result.json",
|
|
@@ -2828,6 +3048,41 @@ describe("merge_wait policy", () => {
|
|
|
2828
3048
|
assert.ok(traj(w)[0].includes("carried forward across the CI fix round"));
|
|
2829
3049
|
});
|
|
2830
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
|
+
|
|
2831
3086
|
describe("#5692 CI events start the fix round before the check completes", () => {
|
|
2832
3087
|
/** `build` stays pending until the builder's fix lands; `evts` is what the router has for the head. */
|
|
2833
3088
|
const evWorld = (evts) => {
|
|
@@ -3800,6 +4055,57 @@ describe("base-sync (#4100)", () => {
|
|
|
3800
4055
|
assert.ok(!w.edits.some((e) => e.includes("needs-human")));
|
|
3801
4056
|
});
|
|
3802
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
|
+
|
|
3803
4109
|
it("a resumed run with a conflicting PR re-plans, verifies, then syncs in the same session", async () => {
|
|
3804
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()] });
|
|
3805
4111
|
const r = await run(w);
|
|
@@ -3869,6 +4175,22 @@ describe("usage limit, lease takeover, worktree setup, run tmp (#4101-#4104)", (
|
|
|
3869
4175
|
assert.equal(w.leaseWrites.at(-1).lease, null, "lease released");
|
|
3870
4176
|
});
|
|
3871
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
|
+
|
|
3872
4194
|
it("#5168 an error that is both a usage limit and auth-like stays rate_limited", async () => {
|
|
3873
4195
|
const w = world();
|
|
3874
4196
|
failFirstBuilder(w, limitErr({ authFailure: true, resetAtEpochMs: 3 * 3600 * 1000, resetAt: "8:30pm" }));
|
|
@@ -4086,10 +4408,10 @@ describe("usage limit, lease takeover, worktree setup, run tmp (#4101-#4104)", (
|
|
|
4086
4408
|
|
|
4087
4409
|
it("#4103 'already exists' on add cleans the leftover and retries; index.lock and packed-refs.lock are retried", async () => {
|
|
4088
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"]) {
|
|
4089
|
-
const w = world(); let failed = false; const removed = [];
|
|
4090
|
-
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
|
|
4091
4413
|
const g = w.io.git;
|
|
4092
|
-
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); };
|
|
4093
4415
|
const r = await run(w);
|
|
4094
4416
|
assert.equal(r.terminalReason, "merged", msg);
|
|
4095
4417
|
if (/already exists/.test(msg)) assert.deepEqual(removed, ["/wt/lean-7"]);
|
|
@@ -4197,6 +4519,18 @@ describe("host admission (#4105)", () => {
|
|
|
4197
4519
|
assert.deepEqual(w.labels, []);
|
|
4198
4520
|
});
|
|
4199
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
|
+
|
|
4200
4534
|
it("low tmp space on the run TMPDIR filesystem or on /tmp is deferred host.busy", async () => {
|
|
4201
4535
|
for (const free of [{ "/tmp": 8192, "/home/x/.forge/tmp": 512 }, { "/tmp": 100, "/home/x/.forge/tmp": 8192 }]) {
|
|
4202
4536
|
const w = withHost(world(), host({ free }));
|
|
@@ -5071,6 +5405,25 @@ describe("batch robustness (#4112-#4115)", () => {
|
|
|
5071
5405
|
await run(w2, { recover: { code: "ci.red", attempt: 1 } });
|
|
5072
5406
|
assert.ok(!w2.comments.some((c) => c.includes("FORGE:AMENDMENT-STATE")));
|
|
5073
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
|
+
});
|
|
5074
5427
|
it("#4899 recovery lane keeps enforcing a guard that was not superseded", async () => {
|
|
5075
5428
|
const mkGuard = (issue) => ({ v: 1, issue, pr: issue * 10, merge_sha: "abc1234", tests: [{ path: "src/foo.js", ids: [] }], hunks: [], why: `guard ${issue}` });
|
|
5076
5429
|
const sup = { kind: "supersedes", guard: "#4785", why: "behaviour changed on purpose" };
|
|
@@ -5095,6 +5448,40 @@ describe("batch robustness (#4112-#4115)", () => {
|
|
|
5095
5448
|
assert.ok(builders(w).length >= 2, "a failing guard still resumes the builder");
|
|
5096
5449
|
|
|
5097
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
|
+
});
|
|
5098
5485
|
it("#4899 amendment state round-trips; precheck still enforces a guard that was not superseded", () => {
|
|
5099
5486
|
const am = [{ kind: "supersedes", guard: "#1", why: "w" }];
|
|
5100
5487
|
assert.deepEqual(parseAmendmentsComment(renderAmendments([{ kind: "supersedes", target: "#1", why: "w" }], {}, { contract: "abc", amendments: am })), { contract: "abc", amendments: am });
|
|
@@ -5121,10 +5508,49 @@ describe("batch robustness (#4112-#4115)", () => {
|
|
|
5121
5508
|
assert.equal((await run(w, { dir })).terminalReason, "merged");
|
|
5122
5509
|
assert.match(builders(w)[0][4], /PLANNING ONLY[\s\S]*This is a rerun/);
|
|
5123
5510
|
assert.match(traj(w)[0], reason);
|
|
5124
|
-
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\)/);
|
|
5125
5512
|
}
|
|
5126
5513
|
assert.equal(readLog(dir, 7).filter((e) => e.event === "CONTRACT_STALE").length, 2);
|
|
5127
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
|
+
});
|
|
5128
5554
|
it("a tampered or untrusted contract comment is ignored: the rerun plans again", async () => {
|
|
5129
5555
|
for (const c of [frozenComment(CONTRACT, (b) => b.replaceAll("guard null", "guard nothing")), frozenComment(CONTRACT, (b) => b, "NONE")]) {
|
|
5130
5556
|
const w = world({ prList: [], remote: "abc\trefs/heads/feat/issue-7-lean", issueComments: [c] });
|
|
@@ -5172,6 +5598,29 @@ describe("lane resolution in core work-on (#4125)", () => {
|
|
|
5172
5598
|
}
|
|
5173
5599
|
});
|
|
5174
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
|
+
|
|
5175
5624
|
it("a missing milestone/<slug> branch fails closed with lane.branch_missing", async () => {
|
|
5176
5625
|
const w = leased(world({ milestone: "Not Yet" }));
|
|
5177
5626
|
const r = await run(w, { lane: undefined });
|
|
@@ -5598,7 +6047,7 @@ describe("lane resource ledger + teardown on every exit path (#4179)", () => {
|
|
|
5598
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; };
|
|
5599
6048
|
/** The exit teardown: the last two worktree calls are `remove --force <wt>` then `prune`; the ledger file is gone. */
|
|
5600
6049
|
const tornDown = (w, label) => {
|
|
5601
|
-
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`
|
|
5602
6051
|
assert.deepEqual(wtCalls.at(-2), ["git", "worktree", "remove", "--force", WT], `${label}: worktree removed`);
|
|
5603
6052
|
assert.deepEqual(wtCalls.at(-1), ["git", "worktree", "prune"], `${label}: then pruned`);
|
|
5604
6053
|
assert.equal(existsSync(w.ledgerFile), false, `${label}: ledger cleared`);
|
|
@@ -5708,6 +6157,39 @@ describe("lane resource ledger + teardown on every exit path (#4179)", () => {
|
|
|
5708
6157
|
tornDown(w, "dirty needs-human");
|
|
5709
6158
|
});
|
|
5710
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
|
+
|
|
5711
6193
|
it("a checkpoint that cannot push keeps the worktree and leaves worktree + branch listed in the ledger", async () => {
|
|
5712
6194
|
const msg = "remote: error: GH006: Protected branch update failed for refs/heads/x";
|
|
5713
6195
|
const w = ledgered({ dirty: true, pushErrors: [msg, msg, msg] });
|
|
@@ -5968,6 +6450,73 @@ describe("shared dependency cache wiring (#4220)", () => {
|
|
|
5968
6450
|
assert.ok(approxTokens(p) <= 2800, `builder prompt is ${approxTokens(p)} tokens`);
|
|
5969
6451
|
}
|
|
5970
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
|
+
});
|
|
5971
6520
|
});
|
|
5972
6521
|
|
|
5973
6522
|
describe("local-mode CI fix rounds at merge and declared pre-PR check commands (#4240)", () => {
|
|
@@ -6053,7 +6602,7 @@ describe("local-mode CI fix rounds at merge and declared pre-PR check commands (
|
|
|
6053
6602
|
it("#5332 a precheck round whose only non-zero result is rc 124 does not resume the builder or end ci.red, and is never self_check green", async () => {
|
|
6054
6603
|
const w = world(); const dir = tmpDir("core-");
|
|
6055
6604
|
w.io.runCommand = async () => ({ rc: 124, output: "(timed out after 1s)" });
|
|
6056
|
-
const r = await run(w, { dir, precheck: { commands: ["make slow"] } });
|
|
6605
|
+
const r = await atIdleLoad(() => run(w, { dir, precheck: { commands: ["make slow"] } }));
|
|
6057
6606
|
assert.equal(r.terminalReason, "merged");
|
|
6058
6607
|
assert.equal(builders(w).filter((b) => /declared check commands failed/.test(b[4])).length, 0, "no builder resume");
|
|
6059
6608
|
const pre = readLog(dir, 7).filter((e) => e.event === "PRECHECK_COMMANDS");
|
|
@@ -6063,7 +6612,7 @@ describe("local-mode CI fix rounds at merge and declared pre-PR check commands (
|
|
|
6063
6612
|
it("#5332 with verify.precheck_block a timed-out check ends env.validate_timeout (not ci.red) naming the command and limit", async () => {
|
|
6064
6613
|
const w = world();
|
|
6065
6614
|
w.io.runCommand = async () => ({ rc: 124, output: "(timed out after 1s)" });
|
|
6066
|
-
const r = await run(w, { precheck: { commands: ["make slow"] }, verify: { ...parseVerify({}), precheckBlock: true } });
|
|
6615
|
+
const r = await atIdleLoad(() => run(w, { precheck: { commands: ["make slow"] }, verify: { ...parseVerify({}), precheckBlock: true } }));
|
|
6067
6616
|
assert.equal(r.code, ENV_VALIDATE_TIMEOUT); assert.equal(r.terminalReason, "needs-human"); assert.equal(w.merges.length, 0);
|
|
6068
6617
|
assert.equal(builders(w).filter((b) => /declared check commands failed/.test(b[4])).length, 0);
|
|
6069
6618
|
assert.match((w.comments.find((c) => c.includes("FORGE:NEEDS_HUMAN")) ?? ""), /`make slow` \(timed out after 1 s, exit 124\)/);
|
|
@@ -7361,6 +7910,41 @@ describe("#4362 attempt triggers", () => {
|
|
|
7361
7910
|
assert.match(restart, /Its last tool call: Edit /);
|
|
7362
7911
|
});
|
|
7363
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
|
+
|
|
7364
7948
|
it("#5346: engine.context_ceiling_by_size sets the ceiling per lane size (size S here), the global one otherwise", async () => {
|
|
7365
7949
|
const w = world({ dirty: true }); const caps = []; const orig = w.io.runner;
|
|
7366
7950
|
w.io.runner = async (c) => { if (c.role === "builder") caps.push(c.contextMax ?? 0); return orig(c); };
|
|
@@ -7803,11 +8387,13 @@ describe("#4394 builder model routing", () => {
|
|
|
7803
8387
|
const isPlan = (b) => /PLANNING ONLY/.test(b[4]);
|
|
7804
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"] }] };
|
|
7805
8389
|
|
|
7806
|
-
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 () => {
|
|
7807
8391
|
const w = world({ contract: docsContract }); const dir = tmpDir("core-");
|
|
7808
8392
|
const r = await run(w, { dir, builderModel: "opus-b" });
|
|
7809
8393
|
const b = builders(w);
|
|
7810
|
-
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/);
|
|
7811
8397
|
assert.equal(b[1][3], "claude-sonnet-5-5", "the build runs on the mid model");
|
|
7812
8398
|
const [route] = events(dir, "BUILDER_ROUTE");
|
|
7813
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" });
|
|
@@ -7821,12 +8407,37 @@ describe("#4394 builder model routing", () => {
|
|
|
7821
8407
|
|
|
7822
8408
|
it("lean.builder_mid_model picks the mid model; a declared risk path routes the build to the top model", async () => {
|
|
7823
8409
|
const w1 = world(); await run(w1, { builderModel: "opus-b", builderRouting: { midModel: "haiku-mid" } });
|
|
7824
|
-
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"]);
|
|
7825
8411
|
const w2 = world(); const dir = tmpDir("core-");
|
|
7826
8412
|
await run(w2, { dir, builderModel: "opus-b", reviewTrigger: { mode: "shadow", riskPaths: ["src/**"] } });
|
|
7827
|
-
|
|
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");
|
|
7828
8417
|
const [route] = events(dir, "BUILDER_ROUTE");
|
|
7829
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"]);
|
|
7830
8441
|
});
|
|
7831
8442
|
|
|
7832
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 () => {
|
|
@@ -7850,7 +8461,7 @@ describe("#4394 builder model routing", () => {
|
|
|
7850
8461
|
assert.deepEqual(events(dir, "BUILDER_ESCALATED"), []);
|
|
7851
8462
|
});
|
|
7852
8463
|
|
|
7853
|
-
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
|
|
7854
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-");
|
|
7855
8466
|
await run(w, { dir, builderModel: "opus-b", builderRouting: { mode: "off" } });
|
|
7856
8467
|
assert.ok(builders(w).length >= 3);
|
|
@@ -8059,8 +8670,8 @@ describe("#4395 lane profile", () => {
|
|
|
8059
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/);
|
|
8060
8671
|
assert.match(p, /Read each file's ranges once .* and keep notes; don't re-read it\./);
|
|
8061
8672
|
}
|
|
8062
|
-
assert.ok(approxTokens(builderImplementPrompt()) <=
|
|
8063
|
-
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`);
|
|
8064
8675
|
});
|
|
8065
8676
|
|
|
8066
8677
|
it("runCliBackendAsync reports the first stream turn's context as baselineTokens; makeLeanRunner drops it on resume", async () => {
|
|
@@ -8072,10 +8683,13 @@ describe("#4395 lane profile", () => {
|
|
|
8072
8683
|
writeFileSync(`${d}/fake`, `#!/bin/sh\necho '${msg("m1", 5000)}'\necho '${msg("m2", 9000)}'\necho '${result}'\n`); chmodSync(`${d}/fake`, 0o755);
|
|
8073
8684
|
const r = await runCliBackendAsync({ spec: { name: "t" }, userMessage: "go", args: ["1"], cwd: d, bin: `${d}/fake`, logger: { log() {} }, stream: true });
|
|
8074
8685
|
assert.equal(r.baselineTokens, 5310);
|
|
8686
|
+
assert.equal(r.endTokens, 9310, "#5812: the last turn's context");
|
|
8075
8687
|
const fresh = await makeLeanRunner({ runCli: async () => ({ text: "", baselineTokens: 5310 }) })({ role: "builder", issue: 7, cwd: d, resume: null, system: "", prompt: "go" });
|
|
8076
8688
|
assert.equal(fresh.baselineTokens, 5310);
|
|
8077
8689
|
const resumed = await makeLeanRunner({ runCli: async () => ({ text: "", baselineTokens: 90000 }) })({ role: "builder", issue: 7, cwd: d, resume: "s-1", system: "", prompt: "go" });
|
|
8078
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");
|
|
8079
8693
|
});
|
|
8080
8694
|
});
|
|
8081
8695
|
|
|
@@ -8095,6 +8709,38 @@ describe("#4450 light lane: one builder session, derived contract, upgrade to th
|
|
|
8095
8709
|
const events = (dir, name) => readLog(dir, 7).filter((e) => e.event === name);
|
|
8096
8710
|
const ON = { light: { mode: "on", source: "text" } };
|
|
8097
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
|
+
|
|
8098
8744
|
it("nothing triggers: exactly one builder session (no plan) plus the review; the derived contract is frozen and posted", async () => {
|
|
8099
8745
|
const w = lworld(), dir = tmpDir("light-");
|
|
8100
8746
|
const r = await run(w, { dir, ...ON });
|
|
@@ -8266,8 +8912,8 @@ describe("#4450 light lane: one builder session, derived contract, upgrade to th
|
|
|
8266
8912
|
const cmds = ["node --test t1.js", "node --test t2.js", "node --test t3.js", "node --test t4.js"];
|
|
8267
8913
|
const w = lworld({ result: { ...RESULT, tests: cmds.map((command) => ({ command, result: "pass" })) } }), dir = tmpDir("light-par-");
|
|
8268
8914
|
let live = 0, max = 0;
|
|
8269
|
-
const seen = [];
|
|
8270
|
-
w.io.runCommand = async (a) => { live++; max = Math.max(max, live); seen.push(a.env?.FORGE_HOST_PARALLELISM); await new Promise((r) => setTimeout(r, 5)); live--; return { rc: 0, output: "" }; };
|
|
8915
|
+
const seen = [], first = new Set(); // #5728: only the light run of each command; the engine's later run of the derived V rows (no recorded result) is sequential, full share
|
|
8916
|
+
w.io.runCommand = async (a) => { live++; max = Math.max(max, live); if (!first.has(a.command)) { first.add(a.command); seen.push(a.env?.FORGE_HOST_PARALLELISM); } await new Promise((r) => setTimeout(r, 5)); live--; return { rc: 0, output: "" }; };
|
|
8271
8917
|
const prev = process.env.FORGE_HOST_PARALLELISM;
|
|
8272
8918
|
process.env.FORGE_HOST_PARALLELISM = "2";
|
|
8273
8919
|
try { await run(w, { dir, ...ON }); } finally { if (prev === undefined) delete process.env.FORGE_HOST_PARALLELISM; else process.env.FORGE_HOST_PARALLELISM = prev; }
|
|
@@ -8400,7 +9046,7 @@ describe("prompt budgets (#4969)", () => {
|
|
|
8400
9046
|
assert.notEqual(moved, impl);
|
|
8401
9047
|
assert.equal(approxTokens(moved), approxTokens(impl));
|
|
8402
9048
|
assert.equal(approxTokens(impl.replaceAll(INSTALL_ROOT, "C:\\fd")), approxTokens(impl));
|
|
8403
|
-
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
|
|
8404
9050
|
});
|
|
8405
9051
|
});
|
|
8406
9052
|
|
|
@@ -8838,6 +9484,31 @@ describe("design gate routing in the lane (#5330 R11, R13, R15)", () => {
|
|
|
8838
9484
|
});
|
|
8839
9485
|
});
|
|
8840
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
|
+
|
|
8841
9512
|
describe("classification record in the plan prompt (#5557)", () => {
|
|
8842
9513
|
it("asks only for the judgment fields and never for units or migrations", () => {
|
|
8843
9514
|
const p = builderPlanPrompt(7);
|
|
@@ -8980,4 +9651,99 @@ describe("#5683 monorepo sub-project dependencies are not host tools", () => {
|
|
|
8980
9651
|
const h = withWeb(world({ contract: withTool("zzcheck") })); probing(h, "zzcheck");
|
|
8981
9652
|
assert.equal((await run(h, { dir: tmpDir("lean-5683b-"), ...remote })).code, "env.tool_missing");
|
|
8982
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
|
+
});
|
|
8983
9749
|
});
|