FORGE-1: merge-pull is one merge call, every member judged before any is merged
merge-pull takes pulls and by, refuses a call with no proved caller, judges each member (its head, its base a watched branch, not merged already, no required step failed at its fingerprint) and no branch protection, merges none when one is refused, else merges in the order named and answers the call and each member's outcome once. The seat's branch answers no protection. The seen-expiry test no longer depends on today's date. Builds: design 47 H §734, §735, §764 (the single-pull form; merge-pull's protection judgement); ADR 0682 §13; H-A-21, H-A-22, H-A-24, H-A-47 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -109,7 +109,8 @@ test("a seen key past 30 days is deleted at the next step-ended, a younger one k
|
||||
const now = new Date("2026-11-11T12:00:00Z");
|
||||
const old = (n: number) => new Date(Date.parse("2026-10-01T00:00:00Z") - n * 60000).toISOString();
|
||||
await st.put(seenKey(C1, "old"), { v: 1, commit: C1, module: "old", fingerprints: ["x"], at: old(0) });
|
||||
await st.put(seenKey(C2, "young"), { v: 1, commit: C2, module: "young", fingerprints: ["x"], at: "2026-10-20T00:00:00Z" });
|
||||
// Younger than 30 days both before the step-ended and before the tool's own clock, today's: kept by both.
|
||||
await st.put(seenKey(C2, "young"), { v: 1, commit: C2, module: "young", fingerprints: ["x"], at: new Date(Date.now() - 86_400_000).toISOString() });
|
||||
await f.stepEnded(ended(C3, "passed"));
|
||||
assert.equal(kv.has(seenKey(C1, "old")), false, "past 30 days: deleted at the next step-ended");
|
||||
assert.equal(kv.has(seenKey(C2, "young")), true, "younger: kept");
|
||||
|
||||
@@ -431,15 +431,12 @@ test("the two new tools are named for what mesh_search is asked, and gitea_api s
|
||||
assert.ok("refused" in judgeApiCall("PATCH", "/repos/a/b/pulls/7", { base: "x" }));
|
||||
});
|
||||
|
||||
// **merge-pull judges the head it is asked at and no check** (design 47 *The seat git*, §314): merge-pull merges the
|
||||
// head it is named into a base that takes no push, whatever its statuses say, and an id said again after the merge is
|
||||
// answered performed.
|
||||
test("merge-pull merges the head the caller names, and refuses one at whose fingerprint a required step failed", async () => {
|
||||
// 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 () => {
|
||||
const { seatTools } = await import("../dist/seat.js");
|
||||
const { runAs } = await import("@novox/mesh-sdk/callers");
|
||||
const bridge = "ace.mesh-delivery-forge-bridge";
|
||||
let registered = true;
|
||||
let failedStep: { run: string; module: string; step: string; fingerprint: string } | null = null;
|
||||
// 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");
|
||||
const landed: string[] = [];
|
||||
@@ -453,48 +450,10 @@ test("merge-pull merges the head the caller names, and refuses one at whose fing
|
||||
};
|
||||
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: () => registered, judge: async () => failedStep });
|
||||
{ run: async () => ({ stdout: "", code: 0 }), container: "gitea", statuses: gates, 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>;
|
||||
const merge = (extra: Record<string, unknown> = {}, caller?: string) =>
|
||||
call("merge-pull", { id: "act-1", repository: "novox/mesh-catalog", number: 7, head: REVIEWED, ...extra }, caller);
|
||||
const rows: { name: string; set: () => void; caller?: string; extra?: Record<string, unknown>; want: RegExp | "merged" | "held"; loud?: boolean; kind?: string }[] = [
|
||||
{ name: "no registration written yet", set: () => { registered = false; }, want: /no module is registered yet/, kind: "no-registrations" },
|
||||
{ name: "a head that moved", set: () => { state.head = MOVED; }, want: /its head is 3c4d5e6f7a8b, not the abc1234def56/, kind: "head-moved" },
|
||||
{ name: "a base no rule guards", set: () => { state.rules = []; }, want: /guarded by no protection rule/, kind: "unprotected" },
|
||||
{ name: "a base whose protection was removed after the last branch-moved", set: () => { state.rules = [protectedMain()]; state.rules = []; }, want: /guarded by no protection rule/, kind: "unprotected" },
|
||||
{ name: "a base that takes a push", set: () => { state.rules = [{ rule_name: "main", enable_push: true }]; }, want: /guarded by no protection rule/, kind: "unprotected" },
|
||||
{ name: "a required step failed at the head's fingerprint", set: () => { failedStep = { run: "main.7.nats", module: "nats", step: "unit", fingerprint: "fp-1" }; },
|
||||
want: /the unit step of nats failed in run main\.7\.nats/, kind: "policy-failed" },
|
||||
{ name: "a failed check", set: () => { state.statuses = [{ context: "mesh/check", state: "failure", description: "fail" }]; }, want: "merged" },
|
||||
{ name: "no status at all", set: () => { state.statuses = []; }, want: "merged" },
|
||||
{ name: "a check of another trunk", set: () => { state.statuses = judgedAt(MOVED); }, want: "merged" },
|
||||
{ name: "the id said again after the merge", set: () => { state.merged = true; }, want: "held" },
|
||||
{ name: "a pull request merged at another head", set: () => { state.merged = true; state.head = MOVED; }, want: /merged at 3c4d5e6f7a8b, not the abc1234def56/ },
|
||||
{ name: "a closed pull request", set: () => { state.prState = "closed"; }, want: /it is closed/, kind: "git-refused" },
|
||||
{ name: "a fast-forward", set: () => { state.parents = [REVIEWED]; }, want: "merged" },
|
||||
{ name: "the merge read back fails", set: () => { state.commitsFail = 502; }, want: "merged" },
|
||||
{ name: "the forge merged another head", set: () => { state.landed = MOVED; }, want: /WAS merged .*the forge merged 3c4d5e6f7a8b, not the abc1234def56/, loud: true },
|
||||
];
|
||||
for (const r of rows) {
|
||||
registered = true; failedStep = null; state.merged = false; state.head = REVIEWED; state.statuses = judgedAt(TRUNK); state.sent = [];
|
||||
state.rules = [protectedMain()]; state.prState = "open"; state.parents = null; state.commitsFail = 0; state.landed = "";
|
||||
r.set();
|
||||
const got = await merge(r.extra, r.caller);
|
||||
if (r.want === "merged") {
|
||||
assert.equal(got.performed, true, `${r.name}: ${JSON.stringify(got)}`);
|
||||
assert.equal(got["merge-commit"], state.mergeCommit, r.name);
|
||||
assert.equal(state.sent.find((s) => s.path.endsWith("/pulls/7/merge"))?.body.head_commit_id, REVIEWED, r.name);
|
||||
} else if (r.want === "held") {
|
||||
assert.deepEqual([got.performed, got.held], [true, true], r.name);
|
||||
assert.deepEqual(writes(), [], `${r.name}: nothing merged again`);
|
||||
} else {
|
||||
assert.match(String(got.refused ?? got.error), r.want, r.name);
|
||||
if (r.kind) assert.equal(got["refused-kind"], r.kind, r.name);
|
||||
if (r.kind === "policy-failed") assert.deepEqual([got.run, got.module, got.step], ["main.7.nats", "nats", "unit"], r.name);
|
||||
assert.deepEqual(writes(), r.loud ? ["POST /repos/novox/mesh-catalog/pulls/7/merge"] : [], `${r.name}: what was merged`);
|
||||
}
|
||||
}
|
||||
// A read: an open pull request answers what the forge would merge now; a forge that fails is the kind failed.
|
||||
state.merged = false; state.head = REVIEWED; state.rules = [protectedMain()];
|
||||
const pull = await call("pull", { repository: "novox/mesh-catalog", number: 7 });
|
||||
@@ -552,10 +511,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 });
|
||||
const seat = seatTools(forge as any, { run: run as any, container: "gitea", statuses: { status: async () => {} }, 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 });
|
||||
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() });
|
||||
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][] = [
|
||||
@@ -563,9 +522,7 @@ test("every read and act of the seat git answers its contract, and an error is a
|
||||
["pull", "by merge commit", { repository: "novox/app", "merge-commit": OTHER }, {}, (a) => [a.pull.state, a.pull["merge-commit"], a.merging], ["merged", OTHER, undefined]],
|
||||
["pull", "unknown", { repository: "novox/app", number: 404 }, {}, (a) => [a.pull, a["error-kind"]], [undefined, "not-found"]],
|
||||
["pull", "forge down", { repository: "novox/app", number: 9 }, { getPullRequest: down }, (a) => [a.pull, a["error-kind"]], [undefined, "failed"]],
|
||||
["branch", "a branch a rule guards", { repository: "novox/app", branch: "main" }, { branchHead: async () => SHA, appliedProtection: async () => ({ rule_name: "main", enable_push: false }) }, (a) => [a.head, a.protected], [SHA, true]],
|
||||
["branch", "a branch no rule guards", { repository: "novox/app", branch: "scratch" }, { branchHead: async () => SHA, appliedProtection: async () => null }, (a) => [a.head, a.protected], [SHA, false]],
|
||||
["branch", "a rule that takes a push", { repository: "novox/app", branch: "main" }, { branchHead: async () => SHA, appliedProtection: async () => ({ rule_name: "main", enable_push: true }) }, (a) => [a.protected], [false]],
|
||||
["branch", "a branch's head, no protection read (ADR 0682 §13)", { repository: "novox/app", branch: "main" }, { branchHead: async () => SHA, appliedProtection: async () => { throw new Error("read"); } }, (a) => [a.head, a.protected, a.error], [SHA, undefined, undefined]],
|
||||
["branch", "no such branch", { repository: "novox/app", branch: "nope" }, { branchHead: gone }, (a) => [a.head, a["error-kind"]], [undefined, "not-found"]],
|
||||
["open-pulls", "one", {}, {}, (a) => [a.pulls.length, a.pulls[0].required], [1, ["mesh/check"]]],
|
||||
["open-pulls", "forge down", {}, { openPulls: down }, (a) => [a.pulls, a["error-kind"]], [undefined, "failed"]],
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
|
||||
// **One merge call, every member judged before any is merged** (novox/hq design 47 H §734, §735; ADR 0682 §13; H-A-21,
|
||||
// H-A-22, H-A-47): the seat git's merge-pull takes pulls and by, judges each member (its head, its base a watched branch,
|
||||
// not merged already, no required step failed at its fingerprint) and no branch protection, merges none when one is
|
||||
// refused, else merges them in the order named, and answers the call and each member's outcome once.
|
||||
|
||||
const A = "a".repeat(40), B = "b".repeat(40), MOVED = "c".repeat(40);
|
||||
const CALL = "0123456789abcdef";
|
||||
|
||||
interface FakePull { base: string; head: string; state: string; merged: boolean; merge?: string; refuse?: string }
|
||||
|
||||
/** A forge of pull requests by `<repository>#<number>`, recording each merge asked. It has no protection API: a call that
|
||||
* read a branch's protection would throw. */
|
||||
function forge(pulls: Record<string, FakePull>) {
|
||||
const merges: string[] = [];
|
||||
const key = (o: string, r: string, n: number) => `${o}/${r}#${n}`;
|
||||
return {
|
||||
merges,
|
||||
getPullRequest: async (o: string, r: string, n: number) => {
|
||||
const p = pulls[key(o, r, n)];
|
||||
if (!p) throw new Error(`Gitea API GET /repos/${o}/${r}/pulls/${n}: 404 {}`);
|
||||
return { number: n, title: "", state: p.state, merged: p.merged, base: p.base, head: "b", head_sha: p.head,
|
||||
...(p.merged ? { merge_commit_sha: p.merge ?? "m".repeat(40) } : {}) } as any;
|
||||
},
|
||||
mergePullRequest: async (o: string, r: string, n: number, _m: string, _d: boolean, head: string) => {
|
||||
const p = pulls[key(o, r, n)];
|
||||
merges.push(key(o, r, n));
|
||||
if (p.refuse) throw new Error(`Gitea API POST /repos/${o}/${r}/pulls/${n}/merge: 409 ${p.refuse}`);
|
||||
assert.equal(head, p.head);
|
||||
p.merged = true;
|
||||
p.merge = `${n}`.repeat(40).slice(0, 40);
|
||||
},
|
||||
commitParents: async (_o: string, _r: string, sha: string) => [sha, "x"],
|
||||
};
|
||||
}
|
||||
|
||||
const watched = new Map([["novox/app", new Set(["main"])], ["novox/lib", new Set(["main"])]]);
|
||||
|
||||
async function call(f: ReturnType<typeof forge>, args: Record<string, unknown>, over: Record<string, unknown> = {}, caller = "person.jochen") {
|
||||
const { mergeCall } = await import("../dist/mergecall.js");
|
||||
const { runAs } = await import("@novox/mesh-sdk/callers");
|
||||
const deps = { registered: () => true, watched: () => watched, judge: async () => null, newCall: () => CALL, ...over };
|
||||
return runAs({ "mesh/caller": caller }, args, () => mergeCall(f as any, args, deps as any)) as Promise<any>;
|
||||
}
|
||||
|
||||
const two = { by: "lead@shanks", pulls: [{ repository: "novox/app", number: 5, head: A }, { repository: "novox/lib", number: 9, head: B }] };
|
||||
const open = (): Record<string, FakePull> => ({ "novox/app#5": { base: "main", head: A, state: "open", merged: false },
|
||||
"novox/lib#9": { base: "main", head: B, state: "open", merged: false } });
|
||||
|
||||
test("a merge call merges its members in the order named and answers each with its merge commit; one pull request is a list of one", async () => {
|
||||
const f = forge(open());
|
||||
const got = await call(f, two);
|
||||
assert.equal(got.call, CALL);
|
||||
assert.deepEqual(f.merges, ["novox/app#5", "novox/lib#9"]);
|
||||
assert.deepEqual(got.members.map((m: any) => [m.repository, m.number, m.state, m.commit]),
|
||||
[["novox/app", 5, "merged", "5".repeat(40)], ["novox/lib", 9, "merged", "9".repeat(40)]]);
|
||||
const one = forge(open());
|
||||
const single = await call(one, { by: "lead@shanks", pulls: [two.pulls[0]] });
|
||||
assert.deepEqual([one.merges, single.members.length, single.members[0].state], [["novox/app#5"], 1, "merged"]);
|
||||
});
|
||||
|
||||
test("a member refused at judging merges none and names every refused member and why", async () => {
|
||||
const rows: { name: string; set: (p: Record<string, FakePull>) => void; over?: Record<string, unknown>; why: RegExp }[] = [
|
||||
{ name: "the second member's head moved", set: (p) => { p["novox/lib#9"].head = MOVED; }, why: /head-moved: its head is cccccccccccc, not the bbbbbbbbbbbb/ },
|
||||
{ name: "already merged", set: (p) => { Object.assign(p["novox/lib#9"], { merged: true, merge: "e".repeat(40) }); }, why: /already-merged: .* as e{40}/ },
|
||||
{ name: "closed", set: (p) => { p["novox/lib#9"].state = "closed"; }, why: /is closed/ },
|
||||
{ name: "a base no registration watches", set: (p) => { p["novox/lib#9"].base = "feat/x"; }, why: /its base feat\/x is no watched branch/ },
|
||||
{ name: "a required step failed at its head's fingerprint",
|
||||
set: () => {}, over: { judge: async (h: string) => (h === B ? { run: "main.7", module: "lib", step: "unit", fingerprint: "fp" } : null) },
|
||||
why: /the unit step of lib failed in run main\.7 at its build-input fingerprint fp/ },
|
||||
];
|
||||
for (const r of rows) {
|
||||
const pulls = open();
|
||||
r.set(pulls);
|
||||
const f = forge(pulls);
|
||||
const got = await call(f, two, r.over);
|
||||
assert.deepEqual(f.merges, [], `${r.name}: nothing merged`);
|
||||
assert.equal(got.members[0].state, "judged", r.name);
|
||||
assert.equal(got.members[1].state, "refused", r.name);
|
||||
assert.match(got.members[1].why, r.why, r.name);
|
||||
}
|
||||
});
|
||||
|
||||
test("a call is refused whole with no proved caller, no by, no registration or no pull request", async () => {
|
||||
const f = forge(open());
|
||||
await assert.rejects(call(f, two, {}, ""), /proved no caller account/);
|
||||
await assert.rejects(call(f, { pulls: two.pulls }), /by is the caller as who@node/);
|
||||
await assert.rejects(call(f, two, { registered: () => false }), /no module is registered yet/);
|
||||
await assert.rejects(call(f, { by: "lead@shanks", pulls: [] }), /one or more members/);
|
||||
await assert.rejects(call(f, { by: "lead@shanks", pulls: [two.pulls[0], two.pulls[0]] }), /named twice/);
|
||||
assert.deepEqual(f.merges, []);
|
||||
});
|
||||
|
||||
test("the forge refusing a member after every member was judged stops the call: the landed member merged, the rest refused", async () => {
|
||||
const pulls = open();
|
||||
pulls["novox/lib#9"].refuse = "merge conflict";
|
||||
const three = { by: "lead@shanks", pulls: [...two.pulls, { repository: "novox/app", number: 6, head: A }] };
|
||||
pulls["novox/app#6"] = { base: "main", head: A, state: "open", merged: false };
|
||||
const f = forge(pulls);
|
||||
const got = await call(f, three);
|
||||
assert.deepEqual(f.merges, ["novox/app#5", "novox/lib#9"], "the third is never asked");
|
||||
assert.deepEqual(got.members.map((m: any) => m.state), ["merged", "refused", "refused"]);
|
||||
assert.match(got.members[1].why, /the forge refused the merge: .*merge conflict/);
|
||||
});
|
||||
Reference in New Issue
Block a user