forgedock 1.62.0 → 1.64.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 +5 -0
- package/bin/engine/outcome-codes.mjs +5 -0
- package/bin/engine-cli.mjs +109 -21
- package/bin/env/cli.mjs +18 -1
- package/bin/lean/basered.mjs +56 -11
- package/bin/lean/basered.test.mjs +58 -5
- package/bin/lean/batch-health.mjs +46 -4
- package/bin/lean/batch-health.test.mjs +55 -1
- package/bin/lean/batch.mjs +9 -1
- package/bin/lean/batch.test.mjs +74 -7
- package/bin/lean/ceiling.mjs +47 -3
- package/bin/lean/ceiling.test.mjs +32 -1
- package/bin/lean/conformance.e2e.test.mjs +32 -6
- package/bin/lean/conformance.mjs +57 -13
- package/bin/lean/conformance.test.mjs +93 -1
- package/bin/lean/execution.mjs +24 -12
- package/bin/lean/execution.test.mjs +59 -9
- package/bin/lean/forgedock-lane-workflow.test.mjs +62 -2
- package/bin/lean/issuewatch-reconcile.mjs +2 -0
- package/bin/lean/issuewatch-reconcile.test.mjs +25 -0
- package/bin/lean/issuewatch.mjs +3 -0
- package/bin/lean/lanecheck.test.mjs +13 -1
- package/bin/lean/lean.mjs +214 -32
- package/bin/lean/lean.test.mjs +406 -21
- package/bin/lean/live-execution.mjs +25 -0
- package/bin/lean/live-execution.test.mjs +35 -1
- package/bin/lean/merged-park.mjs +76 -0
- package/bin/lean/merged-park.test.mjs +64 -0
- package/bin/lean/mergetrain.mjs +357 -0
- package/bin/lean/mergetrain.test.mjs +348 -0
- package/bin/lean/orchestrate-envhold.test.mjs +62 -0
- package/bin/lean/orchestrate-stacking.test.mjs +144 -0
- package/bin/lean/orchestrate-train.test.mjs +130 -0
- package/bin/lean/orchestrate-transient-git.test.mjs +53 -0
- package/bin/lean/orchestrate.mjs +234 -17
- package/bin/lean/prompts.mjs +4 -3
- package/bin/lean/release-review.mjs +8 -1
- package/bin/lean/release-review.test.mjs +42 -2
- package/bin/lean/release-status.test.mjs +53 -1
- package/bin/lean/release.mjs +6 -3
- package/bin/lean/render.mjs +6 -1
- package/bin/lean/run-issue-placement.test.mjs +27 -3
- package/bin/lean/sandbox-provider.contract.test.mjs +6 -0
- package/bin/lean/sandbox-remote.mjs +12 -2
- package/bin/lean/sched.mjs +19 -2
- package/bin/lean/sched.test.mjs +33 -1
- package/bin/lean/schedd-health.mjs +2 -1
- package/bin/lean/schedd-health.test.mjs +7 -0
- package/bin/lean/schedd.mjs +55 -7
- package/bin/lean/schedd.test.mjs +42 -1
- package/bin/lean/stacking.mjs +140 -0
- package/bin/lean/stacking.test.mjs +98 -0
- package/bin/lean/statuscomment.mjs +14 -8
- package/bin/lean/statuscomment.test.mjs +18 -1
- package/bin/lean/validate-catalog.mjs +1 -1
- package/bin/lean/validate-catalog.test.mjs +3 -0
- package/bin/lean/worktree.mjs +8 -3
- package/bin/lean/worktree.test.mjs +18 -0
- package/bin/pool/agent.mjs +325 -46
- package/bin/pool/cache-sweep.mjs +2 -0
- package/bin/pool/cli.mjs +120 -6
- package/bin/pool/disk.mjs +43 -0
- package/bin/pool/docker.mjs +21 -5
- package/bin/pool/health.mjs +95 -0
- package/bin/pool/router.mjs +274 -27
- package/bin/runner.mjs +3 -1
- package/bin/stats/chains.mjs +101 -0
- package/bin/stats/chains.test.mjs +53 -0
- package/bin/stats/efficiency.mjs +7 -6
- package/bin/stats/efficiency.test.mjs +48 -7
- package/bin/stats/index.mjs +11 -3
- package/bin/stats/stats.test.mjs +9 -0
- package/docs/CONFIG.md +23 -1
- package/docs/OUTCOME-CODES.md +4 -0
- package/package.json +1 -1
- package/pool/README.md +10 -0
- package/pool/image/Dockerfile +2 -1
- package/pool/image/entrypoint.sh +6 -6
- package/pool/image/mirror.sh +71 -0
- package/pool/install/install-agent-linux.sh +57 -5
- package/pool/install/install-agent-macos.sh +148 -0
- package/pool/install/install-agent.ps1 +11 -0
- package/pool/install/install-agent.sh +59 -7
- package/pool/install/uninstall-agent-linux.sh +75 -0
- package/pool/install/uninstall-agent-macos.sh +60 -0
- package/pool/install/uninstall-agent.ps1 +1 -0
- package/scripts/transition-label.sh +11 -0
package/bin/lean/lean.test.mjs
CHANGED
|
@@ -230,7 +230,7 @@ function world(o = {}) {
|
|
|
230
230
|
waitCiGreen: async () => (w.waits.length ? w.waits.shift() : { rc: 0, text: `CI_GATE_HEAD: ${w.head}` }),
|
|
231
231
|
transitionLabel: async (n, s) => { w.labels.push(s); w.seq.push(`label:${s}`); },
|
|
232
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); } } } : {}),
|
|
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; }},
|
|
233
|
+
fs: { ...(o.wtExists ? { exists: async (p) => posix(p).startsWith("/wt/lean-7") || posix(p) === "/repo" } : {}), 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; }},
|
|
234
234
|
fileFollowups: async ({ parent, items }) => { w.followups.push({ parent, items }); if (o.followupError) throw Object.assign(new Error(o.followupError), { stdout: o.followupStdout ?? "" });
|
|
235
235
|
if (o.followupRet) return o.followupRet(w.followups.length, items);
|
|
236
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])); },
|
|
@@ -1102,6 +1102,185 @@ describe("core work-on", () => {
|
|
|
1102
1102
|
assert.equal(w.calls.filter((c) => c[1] === "worktree").length, 0);
|
|
1103
1103
|
});
|
|
1104
1104
|
|
|
1105
|
+
describe("stacked plan lanes (#5831)", () => {
|
|
1106
|
+
const openDep = (w) => {
|
|
1107
|
+
const gh = w.io.gh;
|
|
1108
|
+
w.io.gh = async (a) => {
|
|
1109
|
+
if (a[0] === "api" && /issues\/7$/.test(a[1])) return JSON.stringify({ body: "**Depends on**: #3", user: { login: "x" }, author_association: "OWNER" });
|
|
1110
|
+
if (a[0] === "api" && /issues\/3$/.test(a[1])) return JSON.stringify({ state: "open" });
|
|
1111
|
+
return gh(a);
|
|
1112
|
+
};
|
|
1113
|
+
return w;
|
|
1114
|
+
};
|
|
1115
|
+
/** The fake git has no merge-base: the plan's base is an ancestor of the lane and `diff` lists `changed`. */
|
|
1116
|
+
const onLane = (w, { ancestor = true, changed = "" } = {}) => {
|
|
1117
|
+
const git = w.io.git;
|
|
1118
|
+
w.io.git = async (a, opts) => {
|
|
1119
|
+
if (a[0] === "merge-base") { if (!ancestor) throw new Error("not an ancestor"); return ""; }
|
|
1120
|
+
if (a[0] === "diff" && /\.\./.test(a[2] ?? "") && a[1] === "--name-only" && !String(a[2]).includes("...")) return changed;
|
|
1121
|
+
return git(a, opts);
|
|
1122
|
+
};
|
|
1123
|
+
return w;
|
|
1124
|
+
};
|
|
1125
|
+
it("plan: true skips the dependency-open refusal, freezes the contract and ends planned with {contractHash, baseSha}: no building label, no commit, push, PR or merge", async () => {
|
|
1126
|
+
const w = openDep(world());
|
|
1127
|
+
const r = await run(w, { plan: true });
|
|
1128
|
+
assert.equal(r.terminalReason, "planned", r.detail);
|
|
1129
|
+
assert.match(r.planned.contractHash, /^[0-9a-f]{12}$/);
|
|
1130
|
+
assert.ok(r.planned.baseSha.length >= 7);
|
|
1131
|
+
assert.ok(w.comments.some((c) => c.startsWith("<!-- FORGE:CONTRACT -->")), "the contract froze");
|
|
1132
|
+
assert.equal(w.labels.some((l) => /workflow:building/.test(JSON.stringify(l))), false);
|
|
1133
|
+
assert.equal(builders(w).length, 1, "only the plan session ran; no builder");
|
|
1134
|
+
assert.equal(w.calls.some((c) => c[0] === "git" && ["commit", "push"].includes(c[1])), false);
|
|
1135
|
+
assert.equal(w.prs.length, 0); assert.equal(w.merges.length, 0);
|
|
1136
|
+
});
|
|
1137
|
+
it("without plan an open dependency still refuses (preserved)", async () => {
|
|
1138
|
+
const r = await run(openDep(world()));
|
|
1139
|
+
assert.ok(["dependency-open", "dependency-unreadable"].includes(r.terminalReason));
|
|
1140
|
+
});
|
|
1141
|
+
it("planned: the build lane reuses the plan's frozen contract instead of re-planning", async () => {
|
|
1142
|
+
const first = await (async () => { const w = openDep(world()); const r = await run(w, { plan: true }); return { w, r }; })();
|
|
1143
|
+
const comments = first.w.comments.filter((c) => c.startsWith("<!-- FORGE:CONTRACT -->")).map((body) => ({ body, author_association: "OWNER", user: { type: "Bot", login: "forge[bot]" } }));
|
|
1144
|
+
const w = world({ issueComments: comments });
|
|
1145
|
+
const r = await run(onLane(w), { planned: first.r.planned });
|
|
1146
|
+
assert.equal(r.terminalReason, "merged", r.detail);
|
|
1147
|
+
assert.equal(w.comments.filter((c) => c.startsWith("<!-- FORGE:CONTRACT -->")).length, 0, "no second contract was frozen");
|
|
1148
|
+
});
|
|
1149
|
+
for (const [name, opt] of [["the lane moved (plan base not an ancestor)", { ancestor: false }], ["the dependency's merged diff touches a deliverable path", { changed: "bin/lean/foo.mjs\nsrc/foo.mjs\n" }]]) {
|
|
1150
|
+
it(`planned: ${name} makes the plan stale and the lane re-plans`, async () => {
|
|
1151
|
+
const first = await (async () => { const w = openDep(world()); const r = await run(w, { plan: true }); return { w, r }; })();
|
|
1152
|
+
const frozen = first.w.comments.find((c) => c.startsWith("<!-- FORGE:CONTRACT -->"));
|
|
1153
|
+
const paths = (frozen.match(/"path":\s*"([^"]+)"/g) ?? []).map((m) => m.replace(/.*"([^"]+)"$/, "$1"));
|
|
1154
|
+
const changed = opt.changed ? `${paths.join("\n")}\n` : "";
|
|
1155
|
+
const comments = [{ body: frozen, author_association: "OWNER", user: { type: "Bot", login: "forge[bot]" } }];
|
|
1156
|
+
const w = world({ issueComments: comments });
|
|
1157
|
+
const r = await run(onLane(w, { ...opt, changed }), { planned: first.r.planned });
|
|
1158
|
+
assert.equal(r.terminalReason, "merged", r.detail);
|
|
1159
|
+
assert.ok(w.comments.some((c) => c.startsWith("<!-- FORGE:CONTRACT -->")), "re-planned: a new contract froze");
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
it("planned: a different contract hash makes the plan stale and the lane re-plans", async () => {
|
|
1163
|
+
const first = await (async () => { const w = openDep(world()); const r = await run(w, { plan: true }); return { w, r }; })();
|
|
1164
|
+
const comments = first.w.comments.filter((c) => c.startsWith("<!-- FORGE:CONTRACT -->")).map((body) => ({ body, author_association: "OWNER", user: { type: "Bot", login: "forge[bot]" } }));
|
|
1165
|
+
const w = world({ issueComments: comments });
|
|
1166
|
+
const r = await run(onLane(w), { planned: { ...first.r.planned, contractHash: "ffffffffffff" } });
|
|
1167
|
+
assert.equal(r.terminalReason, "merged", r.detail);
|
|
1168
|
+
assert.ok(w.comments.some((c) => c.startsWith("<!-- FORGE:CONTRACT -->")), "re-planned: a new contract froze");
|
|
1169
|
+
});
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
describe("stacked builds (#5832)", () => {
|
|
1173
|
+
const STACK = { dependency: 3, branch: "feat/issue-3-lean", sha: "a".repeat(40) };
|
|
1174
|
+
/** The dependency's issue is open; its PR is `depState`; the stacked PR's live base follows `pr edit --base`. */
|
|
1175
|
+
const stacked = (w, { depState = "OPEN", base = STACK.branch } = {}) => {
|
|
1176
|
+
const gh = w.io.gh;
|
|
1177
|
+
const st = { base, edits: [] };
|
|
1178
|
+
w.io.gh = async (a) => {
|
|
1179
|
+
if (a[0] === "api" && /issues\/7$/.test(a[1])) return JSON.stringify({ body: "**Depends on**: #3", user: { login: "x" }, author_association: "OWNER" });
|
|
1180
|
+
if (a[0] === "api" && /issues\/3$/.test(a[1])) return JSON.stringify({ state: "open" });
|
|
1181
|
+
if (a[0] === "pr" && a[1] === "list" && a.includes("--head") && a[a.indexOf("--head") + 1] === STACK.branch) return JSON.stringify([{ number: 5, state: depState }]);
|
|
1182
|
+
if (a[0] === "pr" && a[1] === "view" && a.includes("baseRefName")) return JSON.stringify({ baseRefName: st.base });
|
|
1183
|
+
if (a[0] === "pr" && a[1] === "edit" && a.includes("--base")) { st.edits.push(a[a.indexOf("--base") + 1]); st.base = a[a.indexOf("--base") + 1]; return ""; }
|
|
1184
|
+
return gh(a);
|
|
1185
|
+
};
|
|
1186
|
+
w.stack = st;
|
|
1187
|
+
return w;
|
|
1188
|
+
};
|
|
1189
|
+
it("builds while the dependency is open, opens the PR on the dependency branch, records stackedOn; merges only after the dependency merged, retargeted to the lane", async () => {
|
|
1190
|
+
const w = stacked(world(), { depState: "MERGED" });
|
|
1191
|
+
const r = await run(w, { stackedOn: STACK });
|
|
1192
|
+
assert.equal(r.terminalReason, "merged", r.detail);
|
|
1193
|
+
const create = w.prs[0];
|
|
1194
|
+
assert.equal(create[create.indexOf("--base") + 1], STACK.branch, "stacked PR base is the dependency branch");
|
|
1195
|
+
assert.deepEqual(w.stack.edits, ["staging"], "retargeted to the lane before the merge");
|
|
1196
|
+
assert.equal(w.merges.length, 1);
|
|
1197
|
+
assert.ok(w.seq.indexOf("pr") < w.seq.indexOf("merge"));
|
|
1198
|
+
});
|
|
1199
|
+
it("merge.stacked_base: never merges while the dependency is unmerged (the base stays the dependency branch)", async () => {
|
|
1200
|
+
const w = stacked(world(), { depState: "OPEN" });
|
|
1201
|
+
const r = await run(w, { stackedOn: STACK, ciMaxMinutes: 0 });
|
|
1202
|
+
assert.equal(w.merges.length, 0, "no gh pr merge");
|
|
1203
|
+
assert.equal(w.stack.base, STACK.branch, "never retargeted");
|
|
1204
|
+
assert.notEqual(r.terminalReason, "merged");
|
|
1205
|
+
});
|
|
1206
|
+
it("merge.stacked_base: a stacked PR whose live base is not the lane is refused even once the dependency merged", async () => {
|
|
1207
|
+
const w = stacked(world(), { depState: "MERGED" });
|
|
1208
|
+
const edit = w.io.gh;
|
|
1209
|
+
w.io.gh = async (a) => (a[0] === "pr" && a[1] === "edit" && a.includes("--base") ? "" : edit(a)); // the retarget silently does not take
|
|
1210
|
+
const r = await run(w, { stackedOn: STACK });
|
|
1211
|
+
assert.equal(w.merges.length, 0);
|
|
1212
|
+
assert.equal(r.code, "merge.stacked_base");
|
|
1213
|
+
});
|
|
1214
|
+
/** #5833: the dependency's PR list entry follows `dep.list`; `pr close` and `push --delete` are recorded. */
|
|
1215
|
+
const cascading = (w, list) => {
|
|
1216
|
+
const gh = w.io.gh, git = w.io.git;
|
|
1217
|
+
w.closes = []; w.deletes = []; w.merged = [];
|
|
1218
|
+
w.io.gh = async (a) => {
|
|
1219
|
+
if (a[0] === "pr" && a[1] === "list" && a.includes("--head") && a[a.indexOf("--head") + 1] === STACK.branch) return JSON.stringify(list());
|
|
1220
|
+
if (a[0] === "pr" && a[1] === "close") { w.closes.push(a.join(" ")); return ""; }
|
|
1221
|
+
return gh(a);
|
|
1222
|
+
};
|
|
1223
|
+
w.io.git = async (a, o) => {
|
|
1224
|
+
if (a[0] === "push" && a.includes("--delete")) { w.deletes.push(a.join(" ")); return ""; }
|
|
1225
|
+
return git(a, o);
|
|
1226
|
+
};
|
|
1227
|
+
return w;
|
|
1228
|
+
};
|
|
1229
|
+
it("merge.stacked_base (#5908): an open dependency PR wins over an older merged PR on the reused branch name; nothing merges or retargets", async () => {
|
|
1230
|
+
const w = cascading(stacked(world(), { depState: "OPEN" }), () => [{ number: 3, state: "MERGED" }, { number: 5, state: "OPEN", headRefOid: STACK.sha }]);
|
|
1231
|
+
const r = await run(w, { stackedOn: STACK, ciMaxMinutes: 0 });
|
|
1232
|
+
assert.equal(w.merges.length, 0, "no gh pr merge");
|
|
1233
|
+
assert.equal(w.stack.base, STACK.branch, "never retargeted");
|
|
1234
|
+
assert.notEqual(r.terminalReason, "merged");
|
|
1235
|
+
});
|
|
1236
|
+
it("cascade replan: a dependency that ended without merging drops the stacked PR and branch, defers with stack.replan, never merges", async () => {
|
|
1237
|
+
const w = cascading(stacked(world(), { depState: "CLOSED" }), () => [{ number: 5, state: "CLOSED" }]);
|
|
1238
|
+
const r = await run(w, { stackedOn: STACK });
|
|
1239
|
+
assert.equal(r.terminalReason, "deferred");
|
|
1240
|
+
assert.equal(r.code, "stack.replan");
|
|
1241
|
+
assert.equal(r.cascade, "replan");
|
|
1242
|
+
assert.deepEqual(r.cascades, ["replan"]);
|
|
1243
|
+
assert.equal(w.closes.length, 1);
|
|
1244
|
+
assert.equal(w.deletes.length, 1);
|
|
1245
|
+
assert.equal(w.merges.length, 0);
|
|
1246
|
+
});
|
|
1247
|
+
it("cascade restart: the dependency head moved and the rebase conflicts: PR and branch dropped, deferred with stack.restart from the frozen contract", async () => {
|
|
1248
|
+
const w = cascading(stacked(world(), { depState: "OPEN" }), () => [{ number: 5, state: "OPEN", headRefOid: "b".repeat(40) }]);
|
|
1249
|
+
const git = w.io.git;
|
|
1250
|
+
w.io.git = async (a, o) => { if (a[0] === "merge" && a.includes("--no-commit")) throw new Error("CONFLICT"); return git(a, o); };
|
|
1251
|
+
const r = await run(w, { stackedOn: STACK });
|
|
1252
|
+
assert.equal(r.code, "stack.restart");
|
|
1253
|
+
assert.equal(r.cascade, "restart");
|
|
1254
|
+
assert.equal(w.closes.length, 1);
|
|
1255
|
+
assert.equal(w.merges.length, 0);
|
|
1256
|
+
});
|
|
1257
|
+
it("cascade rebase: the dependency merged: retargeted to the lane, the cascade and its rework are recorded on the result", async () => {
|
|
1258
|
+
const w = cascading(stacked(world(), { depState: "MERGED" }), () => [{ number: 5, state: "MERGED" }]);
|
|
1259
|
+
const r = await run(w, { stackedOn: STACK });
|
|
1260
|
+
assert.equal(r.terminalReason, "merged", r.detail);
|
|
1261
|
+
assert.equal(r.cascade, "rebase");
|
|
1262
|
+
assert.deepEqual(r.cascades, ["rebase"]);
|
|
1263
|
+
assert.ok(Number.isFinite(r.cascade_minutes) && Number.isFinite(r.cascade_cost_usd));
|
|
1264
|
+
assert.deepEqual(w.stack.edits, ["staging"]);
|
|
1265
|
+
});
|
|
1266
|
+
it("cascade reverify: a moved dependency head with a clean rebase re-verifies, then still merges only after the dependency merged", async () => {
|
|
1267
|
+
let polls = 0;
|
|
1268
|
+
const w = cascading(stacked(world(), { depState: "OPEN" }), () => (++polls === 1 ? [{ number: 5, state: "OPEN", headRefOid: "b".repeat(40) }] : [{ number: 5, state: "MERGED" }]));
|
|
1269
|
+
const r = await run(w, { stackedOn: STACK });
|
|
1270
|
+
assert.equal(r.terminalReason, "merged", r.detail);
|
|
1271
|
+
assert.deepEqual(r.cascades, ["reverify", "rebase"]);
|
|
1272
|
+
assert.equal(r.cascade, "rebase");
|
|
1273
|
+
assert.equal(w.merges.length, 1);
|
|
1274
|
+
assert.ok(w.stack.edits.length === 1, "retargeted once, after the dependency merged");
|
|
1275
|
+
});
|
|
1276
|
+
it("without stackedOn the PR targets the lane and an open dependency still refuses (preserved)", async () => {
|
|
1277
|
+
const w = stacked(world());
|
|
1278
|
+
const r = await run(w);
|
|
1279
|
+
assert.ok(["dependency-open", "dependency-unreadable"].includes(r.terminalReason));
|
|
1280
|
+
assert.equal(w.prs.length, 0);
|
|
1281
|
+
});
|
|
1282
|
+
});
|
|
1283
|
+
|
|
1105
1284
|
it("an open PR / remote branch without a frozen contract re-plans, then verifies the existing commits; no second PR", async () => {
|
|
1106
1285
|
const w = world({ prList: [{ number: 77, headRefOid: "x" }], remote: "abc\trefs/heads/feat/issue-7-lean" });
|
|
1107
1286
|
const r = await run(w);
|
|
@@ -1330,6 +1509,16 @@ describe("conformance gate (frozen contract, precheck, structured review)", () =
|
|
|
1330
1509
|
assert.doesNotMatch(traj(w).join("\n"), /left open as partial/);
|
|
1331
1510
|
});
|
|
1332
1511
|
|
|
1512
|
+
it("#5839 merge train on: close-time records (a still-pending follow-up) hand over with a keepOpen post-merge record", async () => {
|
|
1513
|
+
const k = two("defer", { why: "w" });
|
|
1514
|
+
const w = world({ contract: k, claims: [{ id: "R1", status: "implemented" }], reviews: [conf({}, k)], issueStates: { 900: "CLOSED" } });
|
|
1515
|
+
w.io.requiredChecks = async () => ["build"]; w.io.checkStates = async () => [{ name: "build", state: "pending" }];
|
|
1516
|
+
const r = await run(w, { mergeTrain: "on", ciMaxMinutes: 5 });
|
|
1517
|
+
assert.equal(r.terminalReason, "pr-ready"); assert.equal(w.merges.length, 0);
|
|
1518
|
+
assert.equal(r.postMerge.keepOpen, true); assert.ok(r.postMerge.pendingFollowups.length >= 1);
|
|
1519
|
+
assert.ok(r.postMerge.notes.some((n) => n.marker === "FORGE:FOLLOWUP_PENDING"));
|
|
1520
|
+
});
|
|
1521
|
+
|
|
1333
1522
|
it("a tracking issue that is not open is not a tracking issue: the item stays pending and is recorded", async () => {
|
|
1334
1523
|
const k = two("defer", { why: "w" });
|
|
1335
1524
|
const w = world({ contract: k, claims: [{ id: "R1", status: "implemented" }], reviews: [conf({}, k)], issueStates: { 900: "CLOSED" } });
|
|
@@ -1625,6 +1814,23 @@ describe("worktree salvage and orphaned processes (#4162)", () => {
|
|
|
1625
1814
|
assert.equal((await run(w)).terminalReason, "merged");
|
|
1626
1815
|
assert.equal(salvageRefs(w).length, 0);
|
|
1627
1816
|
});
|
|
1817
|
+
it("5890 repo_missing: a missing repo cwd ends deferred sandbox.repo_missing with a retry, before fetch or worktree add", async () => {
|
|
1818
|
+
const w = world({ wtExists: true });
|
|
1819
|
+
w.io.fs.exists = async () => false;
|
|
1820
|
+
const r = await run(w, { dir: tmpDir("core-5890-a-") });
|
|
1821
|
+
assert.equal(r.terminalReason, "deferred");
|
|
1822
|
+
assert.equal(r.code, "sandbox.repo_missing");
|
|
1823
|
+
assert.equal(r.retryInSeconds, 120);
|
|
1824
|
+
assert.ok(!w.calls.some((c) => c[0] === "git" && (c[1] === "fetch" || c[1] === "worktree")), "no fetch or worktree call ran");
|
|
1825
|
+
});
|
|
1826
|
+
it("5890 repo_missing: a raw spawn ENOENT from worktree add maps to the same code, never engine-error", async () => {
|
|
1827
|
+
const w = world();
|
|
1828
|
+
const git0 = w.io.git;
|
|
1829
|
+
w.io.git = async (a, o) => { if (a[0] === "worktree" && a[1] === "add") throw Object.assign(new Error("spawn git ENOENT"), { code: "ENOENT", syscall: "spawn git", path: "git" }); return git0(a, o); };
|
|
1830
|
+
const r = await run(w, { dir: tmpDir("core-5890-b-") });
|
|
1831
|
+
assert.equal(r.terminalReason, "deferred");
|
|
1832
|
+
assert.equal(r.code, "sandbox.repo_missing");
|
|
1833
|
+
});
|
|
1628
1834
|
// #5825: a lane folder that is not this repo's worktree is never salvaged or written to with git
|
|
1629
1835
|
const NOT_LINKED = { ok: false, why: "the lane folder has no .git link (not a git worktree)", evidence: { worktree: WT } };
|
|
1630
1836
|
const gitIdx5825 = (w, f) => w.calls.findIndex((c) => c[0] === "git" && f(c.slice(1)));
|
|
@@ -1632,7 +1838,7 @@ describe("worktree salvage and orphaned processes (#4162)", () => {
|
|
|
1632
1838
|
const dir = tmpDir("core-5825-q-");
|
|
1633
1839
|
const w = world({ wtExists: true, salvageTrees: [T1] });
|
|
1634
1840
|
let gone = false; const moved = [];
|
|
1635
|
-
w.io.fs.exists = async (p) => !gone && p.startsWith(WT);
|
|
1841
|
+
w.io.fs.exists = async (p) => p === "/repo" || (!gone && p.startsWith(WT));
|
|
1636
1842
|
const git0 = w.io.git;
|
|
1637
1843
|
w.io.git = async (a, o) => { if (a[0] === "worktree" && a[1] === "add") gone = false; return git0(a, o); };
|
|
1638
1844
|
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"; } };
|
|
@@ -1837,13 +2043,13 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1837
2043
|
assert.equal(r.code, OUTCOME_CODES.ENV_TOOL_MISSING, conformance); assert.equal(w.merges.length, 0);
|
|
1838
2044
|
assert.equal(builders(w).length, 2, "plan + implement only"); assert.equal(reviewers(w).length, 0);
|
|
1839
2045
|
assert.match(nhBody(w), /Environment error \(not a conformance failure\): the host is missing yaml/);
|
|
1840
|
-
assert.deepEqual(ran.map((a) => [a.command, a.cwd]), [["node --test test/foo.test.js", WT]], "only the failed contract validate is rerun, in the worktree");
|
|
2046
|
+
assert.deepEqual(ran.map((a) => [a.command, posix(a.cwd)]), [["node --test test/foo.test.js", WT]], "only the failed contract validate is rerun, in the worktree");
|
|
1841
2047
|
assert.ok(ran[0].env && typeof ran[0].env === "object", "the rerun gets the lane env");
|
|
1842
2048
|
}
|
|
1843
2049
|
});
|
|
1844
2050
|
it("#5371 a remote lane whose frozen validate fails ends env.validate_placement (output tail kept); the local recovery lane keeps the real failure terminal", async () => {
|
|
1845
2051
|
const v = [{ id: "V1", command: "node --test test/foo.test.js", exit: 1 }];
|
|
1846
|
-
const rerun = async () => ({ rc: 1, output: "1
|
|
2052
|
+
const rerun = async () => ({ rc: 1, output: "connect ECONNREFUSED 127.0.0.1:5432\nTOKEN=abcd1234secretvalue\nassertion x" });
|
|
1847
2053
|
const w = world({ validation: v }); w.io.runCommand = rerun;
|
|
1848
2054
|
const r = await run(w, { conformance: "enforce", placement: { where: "remote", reason: "mode remote" } });
|
|
1849
2055
|
assert.equal(r.code, ENV_VALIDATE_PLACEMENT); assert.equal(classifyNeedsHuman(r), "recoverable"); assert.equal(w.merges.length, 0);
|
|
@@ -1857,6 +2063,29 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1857
2063
|
const ok = world({ validation: v }); ok.io.runCommand = async () => ({ rc: 0, output: "" });
|
|
1858
2064
|
assert.equal((await run(ok, { conformance: "enforce", placement: { where: "local", reason: "x" }, recover: { code: ENV_VALIDATE_PLACEMENT, attempt: 1, final: true } })).terminalReason, "merged");
|
|
1859
2065
|
});
|
|
2066
|
+
const remoteV = { conformance: "enforce", placement: { where: "remote", reason: "mode remote" } };
|
|
2067
|
+
const v5730 = [{ id: "V1", command: "node --test test/foo.test.js", exit: 1 }];
|
|
2068
|
+
it("5730: remote validate_failed with stale-artifact output resumes the builder", async () => {
|
|
2069
|
+
const stale = "listings/official/maps/maps-places/agent.md: missing or out of date (run --render-agent-md --render-page)";
|
|
2070
|
+
for (const output of [stale, "not ok 1 - foo\n AssertionError: expected 3, got 4"]) {
|
|
2071
|
+
const w = world({ validation: v5730 }); w.io.runCommand = async () => ({ rc: 1, output });
|
|
2072
|
+
const r = await run(w, remoteV);
|
|
2073
|
+
assert.notEqual(r.code, ENV_VALIDATE_PLACEMENT, output); assert.ok(builders(w).length >= 3, "the builder resumes");
|
|
2074
|
+
}
|
|
2075
|
+
});
|
|
2076
|
+
it("5730: env-signature validate_failed hand-off includes the sandbox output tail", async () => {
|
|
2077
|
+
for (const output of ["sh: 1: foo-tool: command not found\nsandbox-only-line", "connect ECONNREFUSED 127.0.0.1:5432\nsandbox-only-line"]) {
|
|
2078
|
+
const w = world({ validation: v5730 }); w.io.runCommand = async () => ({ rc: 1, output });
|
|
2079
|
+
const r = await run(w, remoteV);
|
|
2080
|
+
assert.ok([ENV_VALIDATE_PLACEMENT, "env.tool_missing"].includes(r.code), r.code);
|
|
2081
|
+
if (r.code === ENV_VALIDATE_PLACEMENT) { assert.equal(builders(w).length, 2); assert.match(nhBody(w), /Sandbox output tail/); assert.match(nhBody(w), /sandbox-only-line/); }
|
|
2082
|
+
}
|
|
2083
|
+
});
|
|
2084
|
+
it("5730: a recovery lane whose host replay fails the same way ends conformance.unimplemented, not another placement hop", async () => {
|
|
2085
|
+
const w = world({ validation: v5730 }); w.io.runCommand = async () => ({ rc: 1, output: "connect ECONNREFUSED 127.0.0.1:5432" });
|
|
2086
|
+
const r = await run(w, { ...remoteV, recover: { code: ENV_VALIDATE_PLACEMENT, attempt: 1, final: true } });
|
|
2087
|
+
assert.equal(r.code, "conformance.unimplemented"); assert.equal(w.merges.length, 0); assert.equal(builders(w).length, 3);
|
|
2088
|
+
});
|
|
1860
2089
|
it("#4906 a validate rerun that times out (rc 124) ends env.validate_timeout: recoverable, no builder resume, never conformance.unimplemented", async () => {
|
|
1861
2090
|
const v = [{ id: "V1", command: "node --test test/foo.test.js", exit: 124 }];
|
|
1862
2091
|
for (const conformance of ["shadow", "enforce"]) {
|
|
@@ -1882,7 +2111,7 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1882
2111
|
const rb = await run(bad.w, { conformance: "enforce", dir });
|
|
1883
2112
|
assert.equal(rb.terminalReason, "needs-human"); assert.equal(bad.w.merges.length, 0);
|
|
1884
2113
|
assert.match(nhBody(bad.w), /frozen command runs and fails \(exit 1\)/);
|
|
1885
|
-
assert.ok(bad.ran.some((a) => a.command === "node --test test/foo.test.js" && a.cwd === WT && a.env), "the frozen command is rerun in the worktree with the lane env");
|
|
2114
|
+
assert.ok(bad.ran.some((a) => a.command === "node --test test/foo.test.js" && posix(a.cwd) === WT && a.env), "the frozen command is rerun in the worktree with the lane env");
|
|
1886
2115
|
assert.deepEqual(readLog(dir, 7).filter((e) => e.event === "SUBSTITUTE_RERUN").map((e) => e.runs), [[{ id: "V1", rc: 1 }], [{ id: "V1", rc: 1 }]]);
|
|
1887
2116
|
const good = lane({ rc: 1, output: "no tests ran: no test files matched test/foo.test.js" });
|
|
1888
2117
|
assert.equal((await run(good.w, { conformance: "enforce" })).terminalReason, "merged");
|
|
@@ -1939,6 +2168,79 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1939
2168
|
assert.match(restart, /validate G1/); assert.match(restart, /fixing one failure/);
|
|
1940
2169
|
assert.doesNotMatch(restart, /The engine froze \.forge-lean\/contract\.json/);
|
|
1941
2170
|
});
|
|
2171
|
+
it("#5829 builder continues past 120K on a 1M model and emits tokens before and after", async () => {
|
|
2172
|
+
const w = world(), dir = tmpDir("core-ctx1m-"), orig = w.io.runner, seen = [];
|
|
2173
|
+
w.io.runner = async (c) => {
|
|
2174
|
+
if (c.role === "builder") seen.push(c.contextMax ?? 0);
|
|
2175
|
+
const r = await orig(c); return c.role === "builder" && c.contextMax > 0 ? { ...r, endTokens: 600000 } : r;
|
|
2176
|
+
};
|
|
2177
|
+
const r = await run(w, { dir, builderModel: "claude-opus-5-5[1m]", builderRouting: { mode: "off" }, contextRestartCostUsd: 10 });
|
|
2178
|
+
assert.equal(r.terminalReason, "merged");
|
|
2179
|
+
assert.equal(seen[1], 900000, "the gate lets the session run past the 500000 ceiling to the real limit");
|
|
2180
|
+
const log = readLog(dir, 7);
|
|
2181
|
+
assert.ok(log.some((e) => e.event === "CONTEXT_CONTINUED" && e.tokens_before === 500000 && e.tokens_after === 600000));
|
|
2182
|
+
assert.ok(!log.some((e) => e.event === "CONTEXT_CEILING"), "no restart");
|
|
2183
|
+
assert.equal(r.context.restarts, 0); assert.equal(r.context.continues, 1);
|
|
2184
|
+
});
|
|
2185
|
+
it("#5829 a 1M model with no explicit ceiling gets about 500K; at the real limit the builder restarts via the digest", async () => {
|
|
2186
|
+
const w = world({ dirty: true }), dir = tmpDir("core-ctxlim-"), orig = w.io.runner, seen = []; let n = 0;
|
|
2187
|
+
w.io.runner = async (c) => {
|
|
2188
|
+
if (c.role === "builder") seen.push({ contextMax: c.contextMax ?? 0, resume: c.resume ?? null, prompt: c.prompt });
|
|
2189
|
+
if (c.role === "builder" && n++ === 1) throw Object.assign(new Error("ctx"), { code: "CLI_CONTEXT", context: 950000, contextMax: 450000, turns: 80, usage: null });
|
|
2190
|
+
return orig(c);
|
|
2191
|
+
};
|
|
2192
|
+
const r = await run(w, { dir, builderModel: "claude-opus-5-5[1m]", builderRouting: { mode: "off" }, contextRestartCostUsd: 0.01 });
|
|
2193
|
+
assert.equal(seen[1].contextMax, 500000, "model-aware default ceiling");
|
|
2194
|
+
assert.equal(seen[2].resume, null); assert.match(seen[2].prompt, /The engine froze \.forge-lean\/contract\.json/);
|
|
2195
|
+
assert.equal(r.context.restarts, 1);
|
|
2196
|
+
});
|
|
2197
|
+
it("#5829 a session continued past the ceiling that reaches the real limit restarts via the digest", async () => {
|
|
2198
|
+
const w = world({ dirty: true }), dir = tmpDir("core-ctxreal-"), orig = w.io.runner, seen = []; let n = 0;
|
|
2199
|
+
w.io.runner = async (c) => {
|
|
2200
|
+
if (c.role === "builder") seen.push({ contextMax: c.contextMax ?? 0, resume: c.resume ?? null, prompt: c.prompt });
|
|
2201
|
+
if (c.role === "builder" && n++ === 1) throw Object.assign(new Error("ctx"), { code: "CLI_CONTEXT", context: 900000, contextMax: 900000, turns: 90, usage: null });
|
|
2202
|
+
return orig(c);
|
|
2203
|
+
};
|
|
2204
|
+
await run(w, { dir, builderModel: "claude-opus-5-5[1m]", builderRouting: { mode: "off" }, contextRestartCostUsd: 10 });
|
|
2205
|
+
assert.equal(seen[1].contextMax, 900000); assert.equal(seen[2].resume, null); assert.match(seen[2].prompt, /The engine froze/);
|
|
2206
|
+
assert.ok(readLog(dir, 7).some((e) => e.event === "CONTEXT_CEILING" && e.real_limit === true && e.context_tokens === 900000));
|
|
2207
|
+
});
|
|
2208
|
+
it("#5829 a session stopped at the ceiling is compacted in place and continues with tokens before and after; a failed compaction falls back to the digest restart", async () => {
|
|
2209
|
+
for (const ok of [true, false]) {
|
|
2210
|
+
const w = world({ dirty: true }), dir = tmpDir("core-ctxcompact-"), orig = w.io.runner, seen = []; let n = 0;
|
|
2211
|
+
w.io.runner = async (c) => {
|
|
2212
|
+
if (c.role === "builder") seen.push({ prompt: c.prompt, resume: c.resume ?? null });
|
|
2213
|
+
if (c.role === "builder" && c.prompt === "/compact") { if (!ok) throw new Error("compact unavailable"); return { ...(await orig(c)), endTokens: 30000 }; }
|
|
2214
|
+
if (c.role === "builder" && n++ === 1) throw Object.assign(new Error("ctx"), { code: "CLI_CONTEXT", sessionId: "sess-1", context: 130000, turns: 40, usage: null });
|
|
2215
|
+
return orig(c);
|
|
2216
|
+
};
|
|
2217
|
+
const r = await run(w, { dir, contextCeilingTokens: 120000 }), log = readLog(dir, 7);
|
|
2218
|
+
assert.equal(seen[2].prompt, "/compact"); assert.equal(seen[2].resume, "sess-1");
|
|
2219
|
+
if (ok) {
|
|
2220
|
+
assert.ok(log.some((e) => e.event === "CONTEXT_COMPACTED" && e.tokens_before === 130000 && e.tokens_after === 30000));
|
|
2221
|
+
assert.equal(seen[3].resume, "sess-1", "the same session continues"); assert.equal(r.context.restarts, 0); assert.equal(r.context.compactions, 1);
|
|
2222
|
+
} else {
|
|
2223
|
+
assert.ok(log.some((e) => e.event === "CONTEXT_COMPACT_FAILED")); assert.equal(seen[3].resume, null); assert.match(seen[3].prompt, /The engine froze/); assert.equal(r.context.restarts, 1);
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
});
|
|
2227
|
+
it("#5829 builder still kills and restarts at the ceiling on a small-window model", async () => {
|
|
2228
|
+
const w = world({ dirty: true }), dir = tmpDir("core-ctxsmall-"), orig = w.io.runner, seen = []; let n = 0;
|
|
2229
|
+
w.io.runner = async (c) => {
|
|
2230
|
+
if (c.role === "builder") seen.push({ contextMax: c.contextMax ?? 0, resume: c.resume ?? null });
|
|
2231
|
+
if (c.role === "builder" && n++ === 1) throw Object.assign(new Error("ctx"), { code: "CLI_CONTEXT", context: 130000, turns: 40, usage: null });
|
|
2232
|
+
return orig(c);
|
|
2233
|
+
};
|
|
2234
|
+
const r = await run(w, { dir, builderModel: "claude-sonnet-5-5", builderRouting: { mode: "off" }, contextCeilingTokens: 120000 });
|
|
2235
|
+
assert.equal(seen[1].contextMax, 120000); assert.equal(seen[2].resume, null);
|
|
2236
|
+
assert.ok(readLog(dir, 7).some((e) => e.event === "CONTEXT_CEILING" && e.context_tokens === 130000));
|
|
2237
|
+
assert.equal(r.context.restarts, 1); assert.equal(r.context.continues, 0);
|
|
2238
|
+
});
|
|
2239
|
+
it("#5829 lane summary reports restarts, turns and cost", async () => {
|
|
2240
|
+
const r = await run(world());
|
|
2241
|
+
assert.deepEqual(Object.keys(r.context).sort(), ["compactions", "continues", "cost_usd", "restarts", "turns"]);
|
|
2242
|
+
assert.equal(r.context.restarts, 0); assert.equal(typeof r.context.turns, "number"); assert.equal(typeof r.context.cost_usd, "number");
|
|
2243
|
+
});
|
|
1942
2244
|
it("#4328 freeze-time preflight: a validate needing a module the host lacks gets the one contract correction, before any build", async () => {
|
|
1943
2245
|
const pyC = { ...CONTRACT, validate: [{ id: "V1", command: `python3 -c "import yaml"` }] }, uvC = { ...CONTRACT, validate: [{ id: "V1", command: `uv run python -c "import yaml"` }] };
|
|
1944
2246
|
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; };
|
|
@@ -1947,7 +2249,7 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1947
2249
|
assert.equal((await run(w, { dir })).terminalReason, "merged");
|
|
1948
2250
|
assert.equal(builders(w).length, 3, "plan + one contract correction + implement");
|
|
1949
2251
|
assert.match(builders(w)[1][4], /V1: needs Python module 'yaml' \(for python3\), which this host lacks[\s\S]*repo's own toolchain/);
|
|
1950
|
-
assert.ok(ran.every((a) => a.cwd === WT && a.env && typeof a.env === "object"), "probes run in the worktree with the lane env");
|
|
2252
|
+
assert.ok(ran.every((a) => posix(a.cwd) === WT && a.env && typeof a.env === "object"), "probes run in the worktree with the lane env");
|
|
1951
2253
|
assert.deepEqual(readLog(dir, 7).filter((e) => e.event === "VALIDATE_PREFLIGHT").map((e) => [e.corrected, e.misses.map((m) => m.tool)]), [[true, []]]);
|
|
1952
2254
|
// still missing after the correction: advisory only, the lane goes on (the post-build rerun is the gate)
|
|
1953
2255
|
const dir2 = tmpDir("preflight-");
|
|
@@ -1984,7 +2286,7 @@ describe("conformance shadow mode (the default)", () => {
|
|
|
1984
2286
|
assert.match(b[1][4], /V4: running it on the base worktree stopped before any test ran: needs Python module 'httpx'[\s\S]*repo's own toolchain/);
|
|
1985
2287
|
assert.doesNotMatch(b[1][4], /V[123]:/, "RED on base is not a miss");
|
|
1986
2288
|
assert.match(b[2][4], /The engine froze/, "the correction lands before the implement builder");
|
|
1987
|
-
assert.ok(ran.every(([, cwd]) => cwd === WT));
|
|
2289
|
+
assert.ok(ran.every(([, cwd]) => posix(cwd) === WT));
|
|
1988
2290
|
const firstImpl = w.seq.indexOf("builder-resume", w.seq.indexOf("builder-resume") + 1);
|
|
1989
2291
|
assert.ok(ran.every(([, , at]) => at < firstImpl), "every run happens before the implement session");
|
|
1990
2292
|
const pf = readLog(dir, 7).filter((e) => e.event === "VALIDATE_PREFLIGHT");
|
|
@@ -2295,7 +2597,7 @@ describe("structure delta (forge#4159): undeclared package edges block, import g
|
|
|
2295
2597
|
assert.equal(builders(w).length, 3); assert.equal(reviewers(w).length, 1);
|
|
2296
2598
|
assert.match(builders(w)[2][4], /@s\/db -> @s\/core \(dependencies, packages\/db\/package\.json\)[\s\S]*add it to the contract with a reason, or remove it/);
|
|
2297
2599
|
assert.equal(builders(w)[2][2], null, "#4363: a fresh fix session");
|
|
2298
|
-
assert.deepEqual(w.structureCalls[0], { cwd: "/wt/lean-7", base: "origin/staging" });
|
|
2600
|
+
assert.deepEqual({ ...w.structureCalls[0], cwd: posix(w.structureCalls[0].cwd) }, { cwd: "/wt/lean-7", base: "origin/staging" });
|
|
2299
2601
|
const e = readLog(dir, 7).find((x) => x.event === "STRUCTURE_DELTA");
|
|
2300
2602
|
assert.equal(e.edges_added, 1);
|
|
2301
2603
|
assert.ok(readLog(dir, 7).findIndex((x) => x.event === "STRUCTURE_DELTA") < readLog(dir, 7).findIndex((x) => x.event === "CONFORMANCE"), "before the conformance review");
|
|
@@ -2408,8 +2710,8 @@ describe("hotspot prevention (forge#4195): plan facts, build rule, unexempted gr
|
|
|
2408
2710
|
assert.equal(hotspotBuildRule(facts([], { file_lines: 1000, growth_lines: 50 })).trim(), "Don't grow a file over 1000 lines by more than 50 lines. Put new code next to it.");
|
|
2409
2711
|
assert.equal(hotspotBuildRule(null), ""); assert.equal(hotspotBuildRule(facts([], { enabled: false })), "");
|
|
2410
2712
|
const plan = builderPlanPrompt(7) + hotspotPlanNote(facts([HOT, { ...HOT, path: "a/b.py" }, { ...HOT, path: "c/d.py" }]));
|
|
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).
|
|
2412
|
-
assert.ok(approxTokens(plan) <=
|
|
2713
|
+
// 2750: #5750 (outcome vs guidance rows). 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).
|
|
2714
|
+
assert.ok(approxTokens(plan) <= 2750, `plan prompt with hotspots is ${approxTokens(plan)} tokens`);
|
|
2413
2715
|
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)
|
|
2414
2716
|
});
|
|
2415
2717
|
|
|
@@ -2949,7 +3251,7 @@ describe("comment templates", () => {
|
|
|
2949
3251
|
|
|
2950
3252
|
it("plan and implement prompts carry the stage templates and the contract schema within budget", () => {
|
|
2951
3253
|
const plan = builderPlanPrompt(7), impl = builderImplementPrompt();
|
|
2952
|
-
assert.ok(approxTokens(plan) <=
|
|
3254
|
+
assert.ok(approxTokens(plan) <= 2700, `plan prompt is ${approxTokens(plan)} tokens`); // 2700: #5750 (outcome vs guidance split) on top of 2650; 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
3255
|
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)
|
|
2954
3256
|
for (const h of ["### What Was Claimed", "### What We Found", "### Root Cause", "### Affected Files", "### Sibling Sweep", "### History", "### Recommendation", "### Related Issues", "### Test plan",
|
|
2955
3257
|
"investigation.md", "contract.json", "PLANNING ONLY", '"requirements"', '"deliverables"', '"preserve"', '"validate"', "verbatim", "defer", "post-deploy"]) assert.ok(plan.includes(h), h);
|
|
@@ -2994,6 +3296,56 @@ describe("merge_wait policy", () => {
|
|
|
2994
3296
|
const w2 = world(); w2.io.requiredChecks = async () => ["build"]; w2.io.checkStates = async () => states({ build: "pending" });
|
|
2995
3297
|
assert.equal((await run(w2, { ciMaxMinutes: 5 })).terminalReason, "ci-pending");
|
|
2996
3298
|
});
|
|
3299
|
+
describe("#5836 merge train: pr-ready exit", () => {
|
|
3300
|
+
it("on, pending required checks end pr-ready with the hand-over payload and no merge", async () => {
|
|
3301
|
+
const w = world(); w.io.requiredChecks = async () => ["build"]; w.io.checkStates = async () => states({ build: "pending" });
|
|
3302
|
+
const r = await run(w, { mergeTrain: "on" });
|
|
3303
|
+
assert.equal(r.terminalReason, "pr-ready");
|
|
3304
|
+
assert.deepEqual({ pr: r.pr, head: r.head, required: r.required, policy: r.policy, lane: r.lane }, { pr: 77, head: w.head, required: ["build"], policy: "required", lane: "staging" });
|
|
3305
|
+
assert.equal(w.merges.length, 0);
|
|
3306
|
+
});
|
|
3307
|
+
it("off (default) keeps waiting: pending checks end ci-pending at the budget, never pr-ready", async () => {
|
|
3308
|
+
const w = world(); w.io.requiredChecks = async () => ["build"]; w.io.checkStates = async () => states({ build: "pending" });
|
|
3309
|
+
assert.equal((await run(w, { ciMaxMinutes: 5 })).terminalReason, "ci-pending");
|
|
3310
|
+
const w2 = world(); w2.io.requiredChecks = async () => ["build"]; w2.io.checkStates = async () => states({ build: "pending" });
|
|
3311
|
+
assert.equal((await run(w2, { ciMaxMinutes: 5, mergeTrain: "off" })).terminalReason, "ci-pending");
|
|
3312
|
+
});
|
|
3313
|
+
it("on, already-green checks are handed to the train too (#5839): one queue per base, no lane merge", async () => {
|
|
3314
|
+
const w = world(); w.io.requiredChecks = async () => ["build"]; w.io.checkStates = async () => states({ build: "success" });
|
|
3315
|
+
const r = await run(w, { mergeTrain: "on" });
|
|
3316
|
+
assert.equal(r.terminalReason, "pr-ready"); assert.equal(w.merges.length, 0);
|
|
3317
|
+
assert.deepEqual(r.postMerge, { keepOpen: false, notes: [] }); assert.equal(r.laneSide.syncs, 0);
|
|
3318
|
+
});
|
|
3319
|
+
it("off, already-green checks merge in the lane (unchanged)", async () => {
|
|
3320
|
+
const w = world(); w.io.requiredChecks = async () => ["build"]; w.io.checkStates = async () => states({ build: "success" });
|
|
3321
|
+
const r = await run(w, { mergeTrain: "off" });
|
|
3322
|
+
assert.equal(r.terminalReason, "merged");
|
|
3323
|
+
assert.deepEqual(w.merges[0].slice(-2), ["--match-head-commit", w.head]);
|
|
3324
|
+
});
|
|
3325
|
+
it("on, a conflicting PR is handed over with no base-sync (the train hands back base.conflict)", async () => {
|
|
3326
|
+
const CONFLICTING = { mergeable: "CONFLICTING", mergeStateStatus: "DIRTY" }; const w = world({ prView: [CONFLICTING, CONFLICTING] }); w.io.requiredChecks = async () => ["build"]; w.io.checkStates = async () => states({ build: "success" });
|
|
3327
|
+
const r = await run(w, { mergeTrain: "on" });
|
|
3328
|
+
assert.equal(r.terminalReason, "pr-ready"); assert.equal(w.merges.length, 0);
|
|
3329
|
+
assert.equal(r.laneSide.baseConflicts, 1);
|
|
3330
|
+
assert.ok(!w.calls.some((c) => Array.isArray(c) && c[0] === "merge" && /origin\//.test(c.join(" "))), "no lane base-sync merge");
|
|
3331
|
+
});
|
|
3332
|
+
it("on, a red check still gets the lane's own outcome (never pr-ready)", async () => {
|
|
3333
|
+
const w = world(); w.io.requiredChecks = async () => ["build"]; w.io.checkStates = async () => states({ build: "failure" });
|
|
3334
|
+
assert.notEqual((await run(w, { mergeTrain: "on" })).terminalReason, "pr-ready");
|
|
3335
|
+
assert.equal(w.merges.length, 0);
|
|
3336
|
+
});
|
|
3337
|
+
});
|
|
3338
|
+
describe("#5839 merge train: every lane kind but a split hands over", () => {
|
|
3339
|
+
const pending = (w) => { w.io.requiredChecks = async () => ["build"]; w.io.checkStates = async () => states({ build: "pending" }); return w; };
|
|
3340
|
+
it("numbered sequence files hand over with a post-merge record", async () => {
|
|
3341
|
+
const w = pending(world());
|
|
3342
|
+
w.io.sequenceCheck = async () => []; w.io.sequenceLease = { acquire: async () => ({ waitMs: 0, timedOut: false, release: () => {} }) };
|
|
3343
|
+
w.io.sequenceSnapshot = async () => [{ path: "db/0007_usage.sql", blob: "b1" }];
|
|
3344
|
+
const r = await run(w, { mergeTrain: "on", ciMaxMinutes: 5 });
|
|
3345
|
+
assert.equal(r.terminalReason, "pr-ready"); assert.equal(w.merges.length, 0);
|
|
3346
|
+
assert.equal(typeof r.postMerge.keepOpen, "boolean");
|
|
3347
|
+
});
|
|
3348
|
+
});
|
|
2997
3349
|
describe("#4624 merge-time rerun / wait / flaky branch of mergeFixRound", () => {
|
|
2998
3350
|
const RUN = (n, attempt) => `https://github.com/o/r/actions/runs/${n}/job/${attempt}`;
|
|
2999
3351
|
const NO_FIX = { ...parseVerify({}), maxRounds: 0 };
|
|
@@ -4390,7 +4742,7 @@ describe("usage limit, lease takeover, worktree setup, run tmp (#4101-#4104)", (
|
|
|
4390
4742
|
|
|
4391
4743
|
it("#4103 a leftover unregistered worktree dir is removed (only this issue's lean dir) before add", async () => {
|
|
4392
4744
|
const w = world(); const removed = [];
|
|
4393
|
-
w.io.fs.exists = async (p) => p === "/wt/lean-7"; w.io.fs.rmdir = async (p) => { removed.push(p); };
|
|
4745
|
+
w.io.fs.exists = async (p) => p === "/repo" || p === "/wt/lean-7"; w.io.fs.rmdir = async (p) => { removed.push(p); };
|
|
4394
4746
|
await run(w);
|
|
4395
4747
|
assert.deepEqual(removed, ["/wt/lean-7"]);
|
|
4396
4748
|
// a registered worktree dir is left to `git worktree remove`
|
|
@@ -4409,7 +4761,7 @@ describe("usage limit, lease takeover, worktree setup, run tmp (#4101-#4104)", (
|
|
|
4409
4761
|
it("#4103 'already exists' on add cleans the leftover and retries; index.lock and packed-refs.lock are retried", async () => {
|
|
4410
4762
|
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"]) {
|
|
4411
4763
|
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
|
|
4764
|
+
w.io.fs.exists = async (p) => p === "/repo" || 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
|
|
4413
4765
|
const g = w.io.git;
|
|
4414
4766
|
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); };
|
|
4415
4767
|
const r = await run(w);
|
|
@@ -6679,6 +7031,18 @@ describe("local-mode CI fix rounds at merge and declared pre-PR check commands (
|
|
|
6679
7031
|
assert.equal(builders(w).length, 2, "no builder fix round spent on a base failure");
|
|
6680
7032
|
});
|
|
6681
7033
|
|
|
7034
|
+
it("#5945 an env-signature base failure is not base.red and files nothing; a host verify pass skips filing", async () => {
|
|
7035
|
+
for (const hook of [false, true]) {
|
|
7036
|
+
const w = world(); const filed = [], gh = w.io.gh;
|
|
7037
|
+
w.io.runCommand = async ({ cwd }) => ({ rc: 1, output: hook ? "bare 429 at app/routers/listing_feeds.py" : "ModuleNotFoundError: No module named yaml" });
|
|
7038
|
+
if (hook) w.io.verifyBaseOnHost = async () => ({ rc: 0 });
|
|
7039
|
+
w.io.gh = async (a, o) => { if (a[0] === "issue" && ["create", "comment", "reopen"].includes(a[1]) && a.some((x) => /FORGE:BASE_RED/.test(x))) filed.push(a); return gh(a, o); };
|
|
7040
|
+
const r = await run(w, { verify: { invariants: ["bash scripts/guard.sh"] } });
|
|
7041
|
+
assert.notEqual(r.code, "base.red"); assert.equal(w.merges.length, 0);
|
|
7042
|
+
assert.equal(filed.length, 0, "no BASE_RED issue filed");
|
|
7043
|
+
}
|
|
7044
|
+
});
|
|
7045
|
+
|
|
6682
7046
|
it("#5239 verify.guard_block false keeps a failing invariant advisory", async () => {
|
|
6683
7047
|
const w = world(); w.io.runCommand = async () => ({ rc: 1, output: "x" });
|
|
6684
7048
|
const r = await run(w, { verify: { invariants: ["bash scripts/guard.sh"], guardBlock: false } });
|
|
@@ -6808,7 +7172,7 @@ describe("test map and repo facts caches (#4272)", () => {
|
|
|
6808
7172
|
});
|
|
6809
7173
|
|
|
6810
7174
|
it("neither file present: the same commands, events and prompts as without the feature", async () => {
|
|
6811
|
-
const w = world(); const ran = recorder(w); w.io.fs.exists = async (p) => p === WT;
|
|
7175
|
+
const w = world(); const ran = recorder(w); w.io.fs.exists = async (p) => p === WT || p === "/repo";
|
|
6812
7176
|
const dir = tmpDir("core-");
|
|
6813
7177
|
assert.equal((await run(w, { dir, precheck: { commands: ["true", "make lint"] } })).terminalReason, "merged");
|
|
6814
7178
|
assert.deepEqual(ran, ["true", "make lint"]);
|
|
@@ -6823,11 +7187,11 @@ describe("test map and repo facts caches (#4272)", () => {
|
|
|
6823
7187
|
it("repo-facts.json present: the builder prompts cite its path, never its content", async () => {
|
|
6824
7188
|
const w = world(); recorder(w);
|
|
6825
7189
|
w.files[FACTSF] = JSON.stringify({ version: 1, toolchain: { pm: { name: "pnpm", version: "9.9.9-SECRET" } } });
|
|
6826
|
-
w.io.fs.exists = async (p) => p === WT || p in w.files;
|
|
7190
|
+
w.io.fs.exists = async (p) => p === WT || p === "/repo" || p in w.files;
|
|
6827
7191
|
assert.equal((await run(w)).terminalReason, "merged");
|
|
6828
7192
|
const [plan, impl] = builders(w);
|
|
6829
7193
|
for (const b of [plan, impl]) { assert.ok(b[4].includes(`are cached in ${FACTSF}`)); assert.doesNotMatch(b[4], /9\.9\.9-SECRET/); }
|
|
6830
|
-
const w2 = world(); recorder(w2); w2.files["/repo/.forge/repo-facts.json"] = "{}"; w2.io.fs.exists = async (p) => p === WT || p in w2.files;
|
|
7194
|
+
const w2 = world(); recorder(w2); w2.files["/repo/.forge/repo-facts.json"] = "{}"; w2.io.fs.exists = async (p) => p === WT || p === "/repo" || p in w2.files;
|
|
6831
7195
|
assert.equal((await run(w2)).terminalReason, "merged");
|
|
6832
7196
|
assert.ok(builders(w2)[0][4].includes("are cached in /repo/.forge/repo-facts.json"));
|
|
6833
7197
|
});
|
|
@@ -6957,6 +7321,12 @@ describe("refactor:split lane routing (forge#4211)", () => {
|
|
|
6957
7321
|
const splitOk = (extra = {}) => ({ ok: true, target: "pkg/big.py", testCmd: "pytest", package: "pkg.big_parts", packageName: "big_parts", modules: { consts: ["A"], helpers: ["f", "g"] }, rest: null, verify: { ok: true, failures: [] }, grouped: true, lines: 120, ...extra });
|
|
6958
7322
|
const mod = (w, result) => ({ ...refactorMod, runSplitStep: async (ctx) => { w.splitCtx.push(ctx); if (result.ok) await ctx.callGrouper("INDEX-ONLY PROMPT", { cwd: "/tmp/empty" }); return result; } });
|
|
6959
7323
|
|
|
7324
|
+
it("#5836 merge train on: a split lane is never handed to the train (pending checks keep it waiting)", async () => {
|
|
7325
|
+
const w = splitWorld(); w.io.requiredChecks = async () => ["build"]; w.io.checkStates = async () => [{ name: "build", state: "pending" }];
|
|
7326
|
+
const r = await run(w, { mergeTrain: "on", ciMaxMinutes: 5, refactorModule: mod(w, splitOk()), precheck: { commands: ["pytest -q"] } });
|
|
7327
|
+
assert.equal(r.terminalReason, "ci-pending"); assert.equal(w.merges.length, 0);
|
|
7328
|
+
});
|
|
7329
|
+
|
|
6960
7330
|
it("a refactor:split issue never runs the builder or the reviewer: one tool-less grouping call, PR, merge", async () => {
|
|
6961
7331
|
const w = splitWorld();
|
|
6962
7332
|
const r = await run(w, { refactorModule: mod(w, splitOk()), precheck: { commands: ["pytest -q"] } });
|
|
@@ -7855,6 +8225,14 @@ describe("#4362 attempt triggers", () => {
|
|
|
7855
8225
|
assert.equal(r.firstPass, true);
|
|
7856
8226
|
});
|
|
7857
8227
|
|
|
8228
|
+
it("#5829: no ceiling configured and a builder model without a known window keeps the 120000 ceiling instead of switching it off", async () => {
|
|
8229
|
+
const w = world(); const orig = w.io.runner, caps = [];
|
|
8230
|
+
w.io.runner = async (c) => { if (c.role === "builder") caps.push(c.contextMax ?? 0); return orig(c); };
|
|
8231
|
+
assert.equal((await run(w, { dir: tmpDir("core-ctx-"), builderModel: "mystery-1", builderRouting: { mode: "off" } })).terminalReason, "merged");
|
|
8232
|
+
assert.equal(caps[0], 0, "the plan call runs uncapped");
|
|
8233
|
+
assert.equal(caps[1], 120000, "the build call carries the default ceiling");
|
|
8234
|
+
});
|
|
8235
|
+
|
|
7858
8236
|
it("#4390: context restarts are bounded; after three the call runs uncapped, and 0 disables the ceiling", async () => {
|
|
7859
8237
|
const w = world(); const dir = tmpDir("core-ctx-");
|
|
7860
8238
|
const orig = w.io.runner, caps = [];
|
|
@@ -8223,6 +8601,13 @@ describe("e2e merge gate (#4403)", () => {
|
|
|
8223
8601
|
assert.ok(w.seq.indexOf("merge") > -1);
|
|
8224
8602
|
});
|
|
8225
8603
|
|
|
8604
|
+
it("#5836 merge train on: an e2e gate keeps the lane waiting (never pr-ready)", async () => {
|
|
8605
|
+
const w = withE2e(world({ changed: SPECS, reviews: [conf({}, CONTRACT, SPECS)] }), ["pending"]);
|
|
8606
|
+
w.io.requiredChecks = async () => ["e2e"];
|
|
8607
|
+
const r = await go(w, { mergeTrain: "on", ciMaxMinutes: 5 });
|
|
8608
|
+
assert.notEqual(r.terminalReason, "pr-ready"); assert.equal(w.merges.length, 0);
|
|
8609
|
+
});
|
|
8610
|
+
|
|
8226
8611
|
it("the lane's own spec failing in e2e: builder fix round, re-review, then merged once e2e is green; no rounds left -> ci.red, nothing merged", async () => {
|
|
8227
8612
|
const w = withE2e(world({ changed: SPECS }), ["failure", "success"]);
|
|
8228
8613
|
const r = await go(w);
|
|
@@ -8671,7 +9056,7 @@ describe("#4395 lane profile", () => {
|
|
|
8671
9056
|
assert.match(p, /Read each file's ranges once .* and keep notes; don't re-read it\./);
|
|
8672
9057
|
}
|
|
8673
9058
|
assert.ok(approxTokens(builderImplementPrompt()) <= 2000, `implement prompt is ${approxTokens(builderImplementPrompt())} of 2000 tokens`); // 1900: #5760; 2000: #5752
|
|
8674
|
-
assert.ok(approxTokens(builderPlanPrompt(7)) <=
|
|
9059
|
+
assert.ok(approxTokens(builderPlanPrompt(7)) <= 2700, `plan prompt is ${approxTokens(builderPlanPrompt(7))} of 2125 tokens`);
|
|
8675
9060
|
});
|
|
8676
9061
|
|
|
8677
9062
|
it("runCliBackendAsync reports the first stream turn's context as baselineTokens; makeLeanRunner drops it on resume", async () => {
|
|
@@ -9172,7 +9557,7 @@ describe("#5347 builders open with one batch of independent reads", () => {
|
|
|
9172
9557
|
});
|
|
9173
9558
|
|
|
9174
9559
|
describe("#5347 lane: the build opens with its independent reads in one turn", () => {
|
|
9175
|
-
it("a lane whose contract names two deliverables hands the builder the opening batch; the builder's one-turn reads through the real stream parser record calls/turn >= 2", async () => {
|
|
9560
|
+
it("a lane whose contract names two deliverables hands the builder the opening batch; the builder's one-turn reads through the real stream parser record calls/turn >= 2", { skip: process.platform === "win32" && "the fake CLI is a #!/bin/sh script" }, async () => {
|
|
9176
9561
|
const { runCliBackendAsync } = await import("../runner.mjs");
|
|
9177
9562
|
const { toolStats } = await import("./toolstats.mjs");
|
|
9178
9563
|
const two = { ...CONTRACT, deliverables: [...CONTRACT.deliverables, { id: "D2", path: "src/bar.js", change: "keep callers", requirements: ["R1"] }] };
|
|
@@ -9612,9 +9997,9 @@ describe("#5592 (8) comment and label spam", () => {
|
|
|
9612
9997
|
it("start clears needs-human, needs-human:external, parked:* and remediation-queue; other labels stay", async () => {
|
|
9613
9998
|
const w = world({ issueBodies: [ISSUE_BODY], labels: [{ name: "bug" }, { name: "needs-human" }, { name: "needs-human:external" }, { name: "parked:ci.red" }, { name: "remediation-queue" }] });
|
|
9614
9999
|
await run(w);
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
assert.deepEqual(rm
|
|
10000
|
+
// #5759: one removal call per label
|
|
10001
|
+
const rm = w.edits.filter((e) => e.includes("--remove-label")).map((e) => e[e.indexOf("--remove-label") + 1]);
|
|
10002
|
+
assert.deepEqual(rm.filter((x) => /needs-human|parked:|remediation-queue/.test(x)), ["needs-human", "needs-human:external", "parked:ci.red", "remediation-queue"]);
|
|
9618
10003
|
});
|
|
9619
10004
|
|
|
9620
10005
|
it("a merged run re-reads the labels and clears a parked label added meanwhile", async () => {
|