Files
mesh-catalog/modules/gitea/test/calls.test.ts
T
jschoubben f0bf4578a9 FORGE-2: the merge call is written in the state calls before its first merge
The key call.<call> holds by, the proved account, at, each member with
its base and state (judged, then merged with its commit as it merges, or
refused with why) and said; a call past call-retention (a setting, 30
days) is deleted on a new call's write, oldest first, with no timer.

Builds: design 47 H §766 (the state calls, call-retention); H-A-18, H-A-47 (said, deletion on each new call's write), H-A-71 (2)

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

63 lines
3.7 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
// **The call is written before its first merge** (novox/hq design 47 H §766; H-A-18, H-A-47, H-A-71): the key
// call.<call> of the state calls holds by, the proved account, at, each member with its base and its state (judged before
// the first merge, merged with its commit as it merges) and said; a call past call-retention is deleted on a new call's
// write, oldest first.
const A = "a".repeat(40), B = "b".repeat(40);
export function memory() {
const kv = new Map<string, unknown>();
return { kv, st: {
get: async (k: string) => (kv.has(k) ? { key: k, value: structuredClone(kv.get(k)), revision: 1 } : null),
put: async (k: string, v: unknown) => { kv.set(k, structuredClone(v)); return 1; },
delete: async (k: string) => { kv.delete(k); },
keys: async () => [...kv.keys()].sort(),
watch: async () => {},
} };
}
test("a merge call is kept before its first merge, each member judged, then merged with its commit", async () => {
const { mergeCall } = await import("../dist/mergecall.js");
const { Calls } = await import("../dist/calls.js");
const { runAs } = await import("@novox/mesh-sdk/callers");
const { kv, st } = memory();
const calls = new Calls(st as any);
const seenAtMerge: any[] = [];
const pulls: Record<string, any> = { 5: { head: A, merged: false }, 9: { head: B, merged: false } };
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) => {
seenAtMerge.push(structuredClone(kv.get("call.0123456789abcdef")));
pulls[n].merged = true;
},
commitParents: async () => [],
};
const args = { by: "lead@shanks", pulls: [{ repository: "novox/app", number: 5, head: A }, { repository: "novox/app", number: 9, head: B }] };
const at = new Date("2026-11-20T03:00:00Z");
await runAs({ "mesh/caller": "shanks.claude-code" }, args, () => mergeCall(forge as any, args, { registered: () => true,
watched: () => new Map([["novox/app", new Set(["main"])]]), judge: async () => null, newCall: () => "0123456789abcdef",
calls, now: () => at } as any));
const first = seenAtMerge[0];
assert.deepEqual([first.by, first.account, first.at, first.said], ["lead@shanks", "shanks.claude-code", at.toISOString(), false]);
assert.deepEqual(first.members.map((m: any) => [m.number, m.branch, m.head, m.state]), [[5, "main", A, "judged"], [9, "main", B, "judged"]]);
assert.deepEqual(seenAtMerge[1].members.map((m: any) => [m.state, m.commit]), [["merged", "5".repeat(40)], ["judged", undefined]]);
const kept = await calls.get("0123456789abcdef");
assert.deepEqual(kept?.members.map((m: any) => m.state), ["merged", "merged"]);
});
test("a call past call-retention is deleted on a new call's write, oldest first; a younger one is kept", async () => {
const { Calls } = await import("../dist/calls.js");
const { kv, st } = memory();
const calls = new Calls(st as any, () => 30);
const call = (at: string) => ({ by: "a@b", account: "x", at, members: [], said: true });
await calls.put("1111111111111111", call("2026-09-01T00:00:00Z"), new Date("2026-09-01T00:00:00Z"));
await calls.put("2222222222222222", call("2026-10-25T00:00:00Z"), new Date("2026-10-25T00:00:00Z"));
await calls.put("3333333333333333", call("2026-11-20T00:00:00Z"), new Date("2026-11-20T00:00:00Z"));
assert.deepEqual([...kv.keys()].sort(), ["call.2222222222222222", "call.3333333333333333"]);
assert.deepEqual((await calls.all()).map((c) => c.call), ["3333333333333333", "2222222222222222"], "newest first");
});