diff --git a/modules/gitea/calls.ts b/modules/gitea/calls.ts index 106f156d0..d4b4e40c9 100644 --- a/modules/gitea/calls.ts +++ b/modules/gitea/calls.ts @@ -70,16 +70,18 @@ export class Calls { /** A kept member of a call. */ export const keptMember = (m: { repository: string; number: number; branch: string; head: string; state: CallMember["state"]; - commit?: string; why?: string }): CallMember => ({ repository: m.repository, number: m.number, branch: m.branch, head: m.head, - state: m.state, ...(m.commit ? { commit: m.commit } : {}), ...(m.why ? { why: m.why } : {}) }); + commit?: string; why?: string; note?: string }): CallMember => ({ repository: m.repository, number: m.number, branch: m.branch, + head: m.head, state: m.state, ...(m.commit ? { commit: m.commit } : {}), ...(m.why ? { why: m.why } : {}), + ...(m.note ? { note: m.note } : {}) }); /** Says a seat event on its subject, under an id the bus keeps once. */ export type Say = (subject: string, body: unknown, id?: string) => Promise; /** The merge-called of a kept call (design 47 H §736, §767): its landed members, each with its base and merge commit, and its - * refused ones; undefined for a call that landed no member, which says none. */ + * refused ones; undefined for a call that landed no member, which says none. A member merged plainly, carrying the note + * no delivery (its repository has no watched branch), starts no delivery and is left out, by the kept note (H2 H-A-471). */ export function mergeCalledOf(c: KeptCall): MergeCalledEvent | undefined { - const landed = c.members.filter((m) => m.state === "merged" && m.commit); + const landed = c.members.filter((m) => m.state === "merged" && m.commit && !m.note); if (landed.length === 0) return undefined; // A member judged and not merged (a stop mid-call) is in neither: its head is an untaken head (§740). const refused = c.members.filter((m) => m.state === "refused"); diff --git a/modules/gitea/mergecall.ts b/modules/gitea/mergecall.ts index 8525d1645..051dc2328 100644 --- a/modules/gitea/mergecall.ts +++ b/modules/gitea/mergecall.ts @@ -5,7 +5,11 @@ // `already-merged` with its commit), and no run at the head's build-input fingerprint failed a `required` step (the // module's own `failed-steps`). No branch protection is judged (ADR 0682 §13). When one member is refused, none is merged // and the answer names every refused member and why; else the members are merged in the order the call names them. The -// verb answers once, at the call's end: `call` and each member's outcome. +// verb answers once, at the call's end: `call` and each member's outcome. A member whose repository has no watched branch +// (no entry, or an empty set, in the registrations' watched branches) is the forge's business alone (H2 H-A-471 and its +// addendum): judged against nothing of the module graph, merged plainly in the order named, answered and kept merged with +// the note no delivery, and left out of merge-called, so it starts no delivery. A watched repository whose base is no +// watched branch stays refused. import { randomBytes } from "node:crypto"; import { UNPROVEN, callerOf } from "@novox/mesh-sdk/callers"; @@ -50,8 +54,15 @@ export interface Member { state: MemberOutcome["state"]; commit?: string; why?: string; + /** Set on a member merged plainly, its repository having no watched branch (H-A-471). */ + note?: string; + /** Its repository has no watched branch: judged against nothing of the module graph (H-A-471). */ + plain?: boolean; } +/** The note of a member merged plainly: it starts no delivery (H-A-471). */ +export const NO_DELIVERY = "no delivery: the repository has no watched branch"; + const SHA = /^[0-9a-f]{40}$/; export const CALL = /^[0-9a-f]{16}$/; @@ -89,7 +100,13 @@ async function judgeMember(forge: CallForge, deps: CallDeps, m: Member): Promise if (pull.head_sha !== m.head) { return `head-moved: its head is ${String(pull.head_sha).slice(0, 12)}, not the ${m.head.slice(0, 12)} the caller names`; } - if (!deps.watched().get(m.repository)?.has(m.branch)) return `its base ${m.branch} is no watched branch`; + const branches = deps.watched().get(m.repository); + // A repository of no module: no build-input fingerprint and no required step judge it (H-A-471). + if (!branches || branches.size === 0) { + m.plain = true; + return ""; + } + if (!branches.has(m.branch)) return `its base ${m.branch} is no watched branch`; const failed = await deps.judge(m.head); if (failed) { return `the ${failed.step} step of ${failed.module} failed in run ${failed.run} at its build-input fingerprint ${failed.fingerprint}`; @@ -117,7 +134,7 @@ async function mergeMember(forge: CallForge, m: Member): Promise { /** A member's outcome as the answer says it. */ export const outcomeOf = (m: Member): MemberOutcome => ({ repository: m.repository, number: m.number, state: m.state, - ...(m.commit ? { commit: m.commit } : {}), ...(m.why ? { why: m.why } : {}) }); + ...(m.commit ? { commit: m.commit } : {}), ...(m.why ? { why: m.why } : {}), ...(m.note ? { note: m.note } : {}) }); /** merge-pull: one merge call (design 47 H §734, §735). */ export async function mergeCall(forge: CallForge, args: Record, deps: CallDeps): Promise { @@ -157,6 +174,7 @@ export async function mergeCall(forge: CallForge, args: Record, try { m.commit = await mergeMember(forge, m); m.state = "merged"; + if (m.plain) m.note = NO_DELIVERY; at = now().toISOString(); await keep(false); } catch (err) { diff --git a/modules/gitea/seat.ts b/modules/gitea/seat.ts index ffefb69fe..48f1dd39d 100644 --- a/modules/gitea/seat.ts +++ b/modules/gitea/seat.ts @@ -123,7 +123,7 @@ const SHA = /^[0-9a-f]{40}$/; /** The git tag of a released version, /vMAJOR.MINOR.PATCH (design 47 H2 §796; design 47 §370). */ const VERSION_TAG = /^(?:[A-Za-z0-9_][A-Za-z0-9._-]*\/)+v\d+\.\d+\.\d+$/; /** The form of the seat git's values and answers this holder answers in (design 47 H2 §780, §796). */ -const GIT_FORM = 2; +const GIT_FORM = 3; const STATES = new Set(["pending", "success", "failure", "error", "warning"]); function commitOf(name: string, raw: unknown): string { const sha = String(raw ?? "").trim(); diff --git a/modules/gitea/test/calls.test.ts b/modules/gitea/test/calls.test.ts index be2bc43eb..08da5871b 100644 --- a/modules/gitea/test/calls.test.ts +++ b/modules/gitea/test/calls.test.ts @@ -91,6 +91,15 @@ test("a call says one merge-called of what landed; none for a call that landed n assert.deepEqual(said.map((s) => s.body.members.map((x: any) => x.number)), [[1, 2]]); assert.equal(said[0].body.refused, undefined, "a member not merged after a stop is no refused member"); assert.deepEqual(await sayUnsaid(calls, say), [], "said once"); + // A member merged plainly, its repository having no watched branch, starts no delivery: the start's re-say leaves it + // out by the kept note (design 47 H2 H-A-471 addendum (2)), and a call of such members alone says none. + const noted = { ...m(4, "merged"), repository: "novox/hq", note: "no delivery: the repository has no watched branch" }; + await calls.put("00000000000000dd", { by: "lead@shanks", account: "x", at: "2026-11-20T03:02:00Z", members: [noted, m(5, "merged")], said: false } as any); + await calls.put("00000000000000ee", { by: "lead@shanks", account: "x", at: "2026-11-20T03:03:00Z", members: [noted], said: false } as any); + said.length = 0; + assert.deepEqual(await sayUnsaid(calls, say), ["00000000000000dd"]); + assert.deepEqual(said.map((s) => s.body.members.map((x: any) => x.number)), [[5]]); + assert.equal((await calls.get("00000000000000ee"))?.said, true, "kept said, with nothing to say"); }); // The merge calls' tools (design 47 H §766): forge_calls answers the calls newest first with each member's state, and diff --git a/modules/gitea/test/guard.test.ts b/modules/gitea/test/guard.test.ts index 397877407..ec6fa230a 100644 --- a/modules/gitea/test/guard.test.ts +++ b/modules/gitea/test/guard.test.ts @@ -517,8 +517,8 @@ test("every read and act of the seat git answers its contract, and an error is a ["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"]], - // 47 H2 §796: each tag names its commit, at the seat's form 2. - ["tags", "a page, each tag with its commit", { repository: "novox/app", prefix: "go/" }, {}, (a) => [a.tags, a.page, a.bound, a.more, a.form], [[{ tag: "go/v0.1.1", commit: SHA }, { tag: "go/v0.1.0", commit: OTHER }], 1, 50, undefined, 2]], + // 47 H2 §796: each tag names its commit, at the seat's form 3 (raised by H-A-471's note). + ["tags", "a page, each tag with its commit", { repository: "novox/app", prefix: "go/" }, {}, (a) => [a.tags, a.page, a.bound, a.more, a.form], [[{ tag: "go/v0.1.1", commit: SHA }, { tag: "go/v0.1.0", commit: OTHER }], 1, 50, undefined, 3]], ["tags", "forge down", { repository: "novox/app" }, { tags: down }, (a) => [a.tags, a["error-kind"]], [undefined, "failed"]], ["trees", "root", { repository: "novox/app", commit: SHA }, {}, (a) => [a.commit, a.root], [SHA, SHA]], ["trees", "forge down", { repository: "novox/app", commit: SHA }, { commitTrees: down }, (a) => [a.root, a["error-kind"]], [undefined, "failed"]], diff --git a/modules/gitea/test/merge-call.test.ts b/modules/gitea/test/merge-call.test.ts index 21024e059..3c5a065ac 100644 --- a/modules/gitea/test/merge-call.test.ts +++ b/modules/gitea/test/merge-call.test.ts @@ -83,6 +83,48 @@ test("a member refused at judging merges none and names every refused member and } }); +// **A repository of no module is merged plainly** (design 47 H2 H-A-471 and its addendum): a member whose repository has +// no watched branch (no entry, or an empty set, in the registrations' watched branches) is judged against nothing of the +// module graph (no failed required step), merged in the order named, answered merged with the note no delivery, and left +// out of merge-called; the watched members of the same call are judged and delivered as any call's. A watched +// repository whose base is unwatched stays refused (the row above). +test("a member of a repository with no watched branch is merged plainly, noted no delivery, and left out of merge-called", async () => { + const NOTE = "no delivery: the repository has no watched branch"; + const rows: { name: string; watched: Map> }[] = [ + { name: "no entry", watched: new Map([["novox/app", new Set(["main"])]]) }, + { name: "an empty set", watched: new Map([["novox/app", new Set(["main"])], ["novox/hq", new Set()]]) }, + ]; + for (const r of rows) { + const pulls = open(); + pulls["novox/hq#799"] = { base: "main", head: B, state: "open", merged: false }; + const f = forge(pulls); + const judged: string[] = []; + const said: any[] = []; + const mixed = { by: "lead@shanks", pulls: [{ repository: "novox/hq", number: 799, head: B }, two.pulls[0]] }; + const got = await call(f, mixed, { watched: () => r.watched, say: async (_s: string, body: unknown) => { said.push(body); }, + judge: async (h: string) => { judged.push(h); return { run: "main.7", module: "hq", step: "unit", fingerprint: "fp" }; } }); + assert.deepEqual(f.merges, [], `${r.name}: a refused watched member merges none`); + assert.deepEqual(judged, [A], `${r.name}: the unwatched member is judged against nothing of the module graph`); + // The watched member's failed required step refuses the call whole, the unwatched one judged plainly beside it. + assert.equal(got.members[0].state, "judged", r.name); + assert.equal(got.members[1].state, "refused", r.name); + // Without the failed step the call lands both: the unwatched noted, merge-called naming only the watched. + const f2 = forge(Object.assign(open(), { "novox/hq#799": { base: "main", head: B, state: "open", merged: false } })); + said.length = 0; + const landed = await call(f2, mixed, { watched: () => r.watched, say: async (_s: string, body: unknown) => { said.push(body); } }); + assert.deepEqual(f2.merges, ["novox/hq#799", "novox/app#5"], `${r.name}: merged in the order named`); + assert.deepEqual(landed.members.map((m: any) => [m.repository, m.state, m.note, m.why]), + [["novox/hq", "merged", NOTE, undefined], ["novox/app", "merged", undefined, undefined]], r.name); + assert.deepEqual(said.map((b) => b.members.map((m: any) => m.repository)), [["novox/app"]], `${r.name}: merge-called leaves it out`); + // A call of unwatched members alone merges and starts no delivery: no merge-called. + const f3 = forge({ "novox/hq#799": { base: "main", head: B, state: "open", merged: false } }); + said.length = 0; + const alone = await call(f3, { by: "lead@shanks", pulls: [mixed.pulls[0]] }, { watched: () => r.watched, + say: async (_s: string, body: unknown) => { said.push(body); } }); + assert.deepEqual([f3.merges, alone.members[0].state, alone.members[0].note, said], [["novox/hq#799"], "merged", NOTE, []], 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/);