gitea: merge-pull merges a repository with no watched branch plainly
The operator wants the merge call to work for a repository of no module, such as hq. 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 at a fingerprint), merged in the order named, answered and kept merged with the note "no delivery: the repository has no watched branch", and left out of merge-called by that kept note, at the call and at the start's re-say, so it starts no delivery. A group mixing it with watched members judges and delivers those as before. A watched repository whose base is unwatched stays refused. The holder answers at the seat git's form 3. Builds: design 47 H2 H-A-471 and its addendum (1), (2)
This commit is contained in:
@@ -70,16 +70,18 @@ export class Calls {
|
|||||||
|
|
||||||
/** A kept member of a call. */
|
/** A kept member of a call. */
|
||||||
export const keptMember = (m: { repository: string; number: number; branch: string; head: string; state: CallMember["state"];
|
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,
|
commit?: string; why?: string; note?: string }): CallMember => ({ repository: m.repository, number: m.number, branch: m.branch,
|
||||||
state: m.state, ...(m.commit ? { commit: m.commit } : {}), ...(m.why ? { why: m.why } : {}) });
|
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. */
|
/** Says a seat event on its subject, under an id the bus keeps once. */
|
||||||
export type Say = (subject: string, body: unknown, id?: string) => Promise<void>;
|
export type Say = (subject: string, body: unknown, id?: string) => Promise<void>;
|
||||||
|
|
||||||
/** The merge-called of a kept call (design 47 H §736, §767): its landed members, each with its base and merge commit, and its
|
/** 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 {
|
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;
|
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).
|
// 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");
|
const refused = c.members.filter((m) => m.state === "refused");
|
||||||
|
|||||||
@@ -5,7 +5,11 @@
|
|||||||
// `already-merged` with its commit), and no run at the head's build-input fingerprint failed a `required` step (the
|
// `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
|
// 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
|
// 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 { randomBytes } from "node:crypto";
|
||||||
import { UNPROVEN, callerOf } from "@novox/mesh-sdk/callers";
|
import { UNPROVEN, callerOf } from "@novox/mesh-sdk/callers";
|
||||||
@@ -50,8 +54,15 @@ export interface Member {
|
|||||||
state: MemberOutcome["state"];
|
state: MemberOutcome["state"];
|
||||||
commit?: string;
|
commit?: string;
|
||||||
why?: 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}$/;
|
const SHA = /^[0-9a-f]{40}$/;
|
||||||
export const CALL = /^[0-9a-f]{16}$/;
|
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) {
|
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`;
|
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);
|
const failed = await deps.judge(m.head);
|
||||||
if (failed) {
|
if (failed) {
|
||||||
return `the ${failed.step} step of ${failed.module} failed in run ${failed.run} at its build-input fingerprint ${failed.fingerprint}`;
|
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<string> {
|
|||||||
|
|
||||||
/** A member's outcome as the answer says it. */
|
/** A member's outcome as the answer says it. */
|
||||||
export const outcomeOf = (m: Member): MemberOutcome => ({ repository: m.repository, number: m.number, state: m.state,
|
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). */
|
/** merge-pull: one merge call (design 47 H §734, §735). */
|
||||||
export async function mergeCall(forge: CallForge, args: Record<string, unknown>, deps: CallDeps): Promise<MergePullAnswer> {
|
export async function mergeCall(forge: CallForge, args: Record<string, unknown>, deps: CallDeps): Promise<MergePullAnswer> {
|
||||||
@@ -157,6 +174,7 @@ export async function mergeCall(forge: CallForge, args: Record<string, unknown>,
|
|||||||
try {
|
try {
|
||||||
m.commit = await mergeMember(forge, m);
|
m.commit = await mergeMember(forge, m);
|
||||||
m.state = "merged";
|
m.state = "merged";
|
||||||
|
if (m.plain) m.note = NO_DELIVERY;
|
||||||
at = now().toISOString();
|
at = now().toISOString();
|
||||||
await keep(false);
|
await keep(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ const SHA = /^[0-9a-f]{40}$/;
|
|||||||
/** The git tag of a released version, <directory>/vMAJOR.MINOR.PATCH (design 47 H2 §796; design 47 §370). */
|
/** The git tag of a released version, <directory>/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+$/;
|
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). */
|
/** 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"]);
|
const STATES = new Set(["pending", "success", "failure", "error", "warning"]);
|
||||||
function commitOf(name: string, raw: unknown): string {
|
function commitOf(name: string, raw: unknown): string {
|
||||||
const sha = String(raw ?? "").trim();
|
const sha = String(raw ?? "").trim();
|
||||||
|
|||||||
@@ -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.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.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");
|
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
|
// The merge calls' tools (design 47 H §766): forge_calls answers the calls newest first with each member's state, and
|
||||||
|
|||||||
@@ -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"]],
|
["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", "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"]],
|
["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.
|
// 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, 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, 3]],
|
||||||
["tags", "forge down", { repository: "novox/app" }, { tags: down }, (a) => [a.tags, a["error-kind"]], [undefined, "failed"]],
|
["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", "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"]],
|
["trees", "forge down", { repository: "novox/app", commit: SHA }, { commitTrees: down }, (a) => [a.root, a["error-kind"]], [undefined, "failed"]],
|
||||||
|
|||||||
@@ -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<string, Set<string>> }[] = [
|
||||||
|
{ 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<string>()]]) },
|
||||||
|
];
|
||||||
|
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 () => {
|
test("a call is refused whole with no proved caller, no by, no registration or no pull request", async () => {
|
||||||
const f = forge(open());
|
const f = forge(open());
|
||||||
await assert.rejects(call(f, two, {}, ""), /proved no caller account/);
|
await assert.rejects(call(f, two, {}, ""), /proved no caller account/);
|
||||||
|
|||||||
Reference in New Issue
Block a user