FORGE-6: the forge module's merge-check machinery and its polls go

announceHead with its mesh/merge-gate pending, the weighing of trunk and
sibling moves (passPulls, trunksMoved, siblingMoves, GateWriter) and their
files on disk, the pass's pull-passing half with its 60 s retry, and the
10-minute keep-main-rules step go. A pull request's new head is said as
pull.updated from the forge's event alone; the seat's status writes
through the client; pollRepos, pollMerged and readAllAtStart stay.

Builds: design 47 H §764 (the forge module: the merge-check machinery, its poll and timer), §762; H-A-28, H-A-100

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-20 03:54:09 +01:00
parent f85f639afe
commit 815be6bdce
19 changed files with 92 additions and 1634 deletions
+11 -28
View File
@@ -433,25 +433,16 @@ test("the two new tools are named for what mesh_search is asked, and gitea_api s
// The seat git's pull and status (design 47 *The seat git*): an open pull request answers what the forge would merge now,
// and two writes of one head's status land in order. merge-pull is the merge call's (merge-call.test.ts).
test("the seat's pull answers what the forge would merge now, and a head's statuses land in order", async () => {
test("the seat's pull answers what the forge would merge now, and its status is set on the commit", async () => {
const { seatTools } = await import("../dist/seat.js");
const { runAs } = await import("@novox/mesh-sdk/callers");
const bridge = "ace.mesh-delivery-forge-bridge";
// The head's one writer of its statuses (gate.ts), over a forge whose first write is still in flight when the next is asked.
const { GateWriter } = await import("../dist/gate.js");
// The seat's status is set through the forge's client directly (design 47 H §764; H-A-100): no chain of a head's writes.
const landed: string[] = [];
let inFlight: Promise<void> | null = null, land = () => {};
const slow = {
headChecks: async () => ({}),
setCommitStatus: async (_o: string, _r: string, _sha: string, s: { state: string; description: string }) => {
if (inFlight) { const w = inFlight; inFlight = null; await w; }
landed.push(`${s.state} ${s.description}`);
},
};
const gates = new GateWriter(slow);
const seat = seatTools(Object.assign(Object.create(client), { setCommitStatus: slow.setCommitStatus }),
{ run: async () => ({ stdout: "", code: 0 }), container: "gitea", statuses: gates, registered: () => true, judge: async () => null,
watched: () => new Map() });
const seat = seatTools(Object.assign(Object.create(client), {
setCommitStatus: async (_o: string, _r: string, _sha: string, s: { state: string; description: string }) => { landed.push(`${s.state} ${s.description}`); },
}), { run: async () => ({ stdout: "", code: 0 }), container: "gitea", registered: () => true, judge: async () => null,
watched: () => new Map() });
const call = (verb: string, args: Record<string, unknown>, caller = bridge) =>
runAs({ "mesh/caller": caller }, args, () => seat.find((t: any) => t.name === `git.${verb}`)!.run(args)) as Promise<any>;
// A read: an open pull request answers what the forge would merge now; a forge that fails is the kind failed.
@@ -466,17 +457,9 @@ test("the seat's pull answers what the forge would merge now, and a head's statu
assert.deepEqual([open.pull?.head, open.pull?.state, open.merging?.protected, open.merging?.required],
[REVIEWED, "open", true, ["mesh/merge-gate", "mesh/repo-check"]], JSON.stringify(open));
assert.equal("body" in (open.pull ?? {}), false, "never its description");
// Two writes of one head out of order (issue 456): a recheck's pending still in flight when the verdict is set through the
// seat; the verdict takes its turn after it and is what the head carries.
inFlight = new Promise<void>((r) => (land = r));
const recheck = gates.pending("novox", "mesh-catalog", REVIEWED);
const verdict = call("status", { id: "act-s", repository: "novox/mesh-catalog", commit: REVIEWED, state: "success",
context: "mesh/merge-gate", description: "passed" });
await new Promise((r) => setImmediate(r));
land();
await recheck;
assert.equal((await verdict).performed, true);
assert.equal(landed.at(-1), "success passed", `the verdict lands last: ${JSON.stringify(landed)}`);
const verdict = await call("status", { id: "act-s", repository: "novox/mesh-catalog", commit: REVIEWED, state: "success",
context: "mesh/check", description: "passed" });
assert.deepEqual([verdict.performed, landed], [true, ["success passed"]]);
// A pull request the forge does not have is the kind not-found, so a caller never reads it out of the words.
const gone = await call("pull", { repository: "novox/mesh-catalog", number: 404 });
assert.deepEqual([gone.pull, gone["error-kind"]], [undefined, "not-found"], JSON.stringify(gone));
@@ -511,10 +494,10 @@ test("every read and act of the seat git answers its contract, and an error is a
};
const run = async (_f: string, args: string[]) => args.includes("show") || args.includes("--ref") && !args.includes("append")
? { stdout: noteShown, code: noteShown ? 0 : 1 } : (noteWritten++, { stdout: "", code: 0 });
const seat = seatTools(forge as any, { run: run as any, container: "gitea", statuses: { status: async () => {} }, registered: () => true, judge: async () => null, watched: () => new Map() });
const seat = seatTools(forge as any, { run: run as any, container: "gitea", registered: () => true, judge: async () => null, watched: () => new Map() });
const call = (verb: string, args: Record<string, unknown>, over: Record<string, unknown> = {}) => {
const t = seat.find((x: any) => x.name === `git.${verb}`)!;
const wrapped = seatTools(Object.assign(Object.create(forge), over) as any, { run: run as any, container: "gitea", statuses: { status: async () => {} }, registered: () => true, judge: async () => null, watched: () => new Map() });
const wrapped = seatTools(Object.assign(Object.create(forge), over) as any, { run: run as any, container: "gitea", registered: () => true, judge: async () => null, watched: () => new Map() });
return runAs({ "mesh/caller": "ace.x" }, args, () => wrapped.find((x: any) => x.name === t.name)!.run(args)) as Promise<any>;
};
const rows: [string, string, Record<string, unknown>, Record<string, unknown>, (a: any) => unknown, unknown][] = [