Files
mesh-catalog/modules/gitea/test/merge-partial.test.ts
T
jschoubben 0400d7bbe7 FORGE-5: forge_calls reads the merge calls; forge_call_say_again says one again
forge_calls answers the kept calls newest first with each member's base,
head and state; forge_call_say_again, with call and why, says a call's
merge-called again once the hand-act log took it.

Builds: design 47 H §766 (its tools); H-A-18

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 03:47:41 +01:00

68 lines
4.6 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { memory } from "./memstate.ts";
// **A member refused after every member was judged is said and raised** (novox/hq design 47 H §767; acceptance test 115;
// H-A-81): a forge that refuses the second merge gives one merge-called with the first member and `refused`, and
// merge-partial (scope delivery, id the call, urgent, resolver operator) raised; a later call landing the refused member
// clears it, and forge_partial_clear clears one by hand after the hand-act log took it.
const A = "a".repeat(40), B = "b".repeat(40);
test("the forge refusing the second merge says what landed, raises merge-partial, and a later call landing it clears it", async () => {
const { mergeCall } = await import("../dist/mergecall.js");
const { Calls } = await import("../dist/calls.js");
const { Partials, partialKey } = await import("../dist/partials.js");
const { callTools } = await import("../dist/tools/calls.js");
const { runAs } = await import("@novox/mesh-sdk/callers");
const { st } = memory();
const findings = memory();
const calls = new Calls(st as any);
const partials = new Partials(findings.st as any, calls);
const said: any[] = [];
const pulls: Record<number, any> = { 5: { head: A, merged: false, refuse: false }, 9: { head: B, merged: false, refuse: true } };
const forge = {
getPullRequest: async (_o: string, _r: string, n: number) => ({ number: n, state: "open", merged: pulls[n].merged, base: "main",
head_sha: pulls[n].head, ...(pulls[n].merged ? { merge_commit_sha: String(n).repeat(40) } : {}) }),
mergePullRequest: async (_o: string, r: string, n: number) => {
if (pulls[n].refuse) throw new Error(`Gitea API POST /repos/novox/${r}/pulls/${n}/merge: 409 merge conflict`);
pulls[n].merged = true;
},
commitParents: async () => [],
};
let clock = Date.parse("2026-11-20T03:00:00Z");
const run = (call: string, numbers: number[]) => {
const args = { by: "lead@shanks", pulls: numbers.map((n) => ({ repository: n === 5 ? "novox/app" : "novox/lib", number: n, head: pulls[n].head })) };
return runAs({ "mesh/caller": "shanks.claude-code" }, args, () => mergeCall(forge as any, args, { registered: () => true,
watched: () => new Map([["novox/app", new Set(["main"])], ["novox/lib", new Set(["main"])]]), judge: async () => null,
newCall: () => call, calls, partials, say: async (_s: string, body: unknown) => { said.push(body); },
now: () => new Date((clock += 1000)) } as any)) as Promise<any>;
};
const got = await run("00000000000000aa", [5, 9]);
assert.deepEqual(got.members.map((m: any) => m.state), ["merged", "refused"]);
assert.equal(said.length, 1);
assert.deepEqual(said[0].members.map((m: any) => m.number), [5]);
assert.deepEqual(said[0].refused.map((m: any) => [m.repository, m.number]), [["novox/lib", 9]]);
assert.match(said[0].refused[0].why, /merge conflict/);
const raised: any = findings.kv.get(partialKey("00000000000000aa"));
assert.deepEqual([raised?.kind, raised?.subject, raised?.severity, raised?.resolver], ["merge-partial", { scope: "delivery", id: "00000000000000aa" }, "urgent", "operator"]);
assert.match(raised.summary, /landed novox\/app#5 and not novox\/lib#9/);
// A later call landing the refused member clears it.
pulls[9].refuse = false;
await run("00000000000000bb", [9]);
assert.equal(findings.kv.has(partialKey("00000000000000aa")), false, "cleared by the later call");
// By hand: written in the hand-act log first, then cleared.
pulls[9] = { head: B, merged: false, refuse: true };
pulls[5] = { head: A, merged: false, refuse: false };
await run("00000000000000cc", [5, 9]);
assert.equal(findings.kv.has(partialKey("00000000000000cc")), true);
const acts: any[] = [];
const tool = callTools(calls, partials, async () => {}, async (a) => { acts.push(a); }).find((t) => t.name === "forge_partial_clear")!;
await assert.rejects(tool.run({ call: "00000000000000cc" }), /names the call .* and why/);
const failing = callTools(calls, partials, async () => {}, async () => { throw new Error("down"); }).find((t) => t.name === "forge_partial_clear")!;
await assert.rejects(failing.run({ call: "00000000000000cc", why: "dropped" }), /not recorded, so nothing was cleared/);
assert.equal(findings.kv.has(partialKey("00000000000000cc")), true);
const done: any = await runAs({ "mesh/caller": "person.jochen" }, {}, () => tool.run({ call: "00000000000000cc", why: "the lib change is dropped" }));
assert.deepEqual([done.cleared, acts[0].verb, findings.kv.has(partialKey("00000000000000cc"))], [true, "forge_partial_clear", false]);
});