gitea: merge-pull merges plainly only from a watched-branches view read since the last change

An unread or stale view held no entry for a watched repository, so every
member would have merged plainly with the note no delivery: a merge that
reports success and delivers nothing. The registrations holder now keeps
the time of its last read and of the last registration-changed heard; the
merge call refuses every member ("the watched branches are not read yet")
while the view is not read since that change, and a read that fails is
said and asked again with the module's growing wait until it answers.

Builds: design 47 H2 H-A-471 (second addendum); review finding H-A-471 addendum (2)
This commit is contained in:
2026-11-22 14:14:09 +01:00
parent 319f535002
commit 7ae223d4ff
6 changed files with 129 additions and 25 deletions
+4 -1
View File
@@ -570,7 +570,10 @@ test("the first registrations are learned from the seat mesh-catalog's verb at t
const held = reg(JSON.stringify({ registrations: [{ module: "mesh-sdk" }] }));
await held.start();
assert.equal(held.written, true, "a registration held at the start");
const down = reg(new Error("no responders"));
// A failed first view is said and asked again (H-A-471, second addendum): the test's wait answers it with none.
let downAnswer: unknown = new Error("no responders");
const down = new Registrations(async () => { if (downAnswer instanceof Error) throw downAnswer; return downAnswer; }, (l) => said.push(l),
async () => { downAnswer = { registrations: [] }; });
await down.start();
assert.equal(down.written, false);
assert.match(said.join("\n"), /could not be read: no responders/, "a failed first view is said, never taken as none silently");
+48
View File
@@ -125,6 +125,54 @@ test("a member of a repository with no watched branch is merged plainly, noted n
}
});
// **A plain merge needs a view read since the last change heard** (design 47 H2 H-A-471, second addendum): while the
// watched branches are unread, or were read before a later registration-changed, every member is refused ("the watched
// branches are not read yet"), never merged with the note; a view read after the change merges the unwatched member
// plainly. A read that fails is said and asked again until it answers.
test("a member is merged plainly only from a watched-branches view read since the last registration-changed", async () => {
const { Registrations } = await import("../dist/registrations.js");
const NOT_READ = "the watched branches are not read yet";
const said: string[] = [];
const waits: number[] = [];
let answer: unknown = new Error("no responders");
const reg = new Registrations(async () => { if (answer instanceof Error) throw answer; return answer; }, (l) => said.push(l),
async (ms) => { waits.push(ms); answer = { registrations: [{ module: "app", origin: "novox/app", branches: ["main"] }] }; });
const hq = { by: "lead@shanks", pulls: [{ repository: "novox/hq", number: 799, head: B }, two.pulls[0]] };
const pulls = () => Object.assign(open(), { "novox/hq#799": { base: "main", head: B, state: "open", merged: false } });
const view = () => (reg.current ? reg.watched : null);
reg.hear({ module: "app", moved: ["watch"], version: 1, warrant: "q-1" });
// Unread: every member refused, nothing merged.
const f1 = forge(pulls());
const unread = await call(f1, hq, { watched: view });
assert.deepEqual([f1.merges, unread.members.map((m: any) => [m.state, m.why, m.note])],
[[], [["refused", NOT_READ, undefined], ["refused", NOT_READ, undefined]]], "an unread view refuses every member");
// A failed read is said and asked again until it answers; read, the view is current.
await reg.start();
assert.deepEqual([waits, reg.current], [[2_000], true]);
assert.match(said.join("\n"), /could not be read: no responders; no member is merged plainly until they are, asked again in 2s/);
assert.ok(reg.readAt && reg.changedAt && reg.readAt >= reg.changedAt, "the times of the last read and the last change are kept");
// A registration-changed heard after the read: stale, every member refused again.
reg.hear({ module: "app", moved: ["watch"], version: 2, warrant: "q-2" });
const f2 = forge(pulls());
const stale = await call(f2, hq, { watched: view });
assert.deepEqual([f2.merges, stale.members.map((m: any) => m.why)], [[], [NOT_READ, NOT_READ]], "a view read before a later change refuses");
// A change heard while a read is asked leaves the view stale.
let release!: () => void;
answer = { registrations: [{ module: "app", origin: "novox/app", branches: ["main"] }] };
const slow = new Registrations(() => new Promise((r) => { release = () => r(answer); }));
const asking = slow.start();
slow.hear({ module: "app", moved: ["watch"], version: 3, warrant: "q-3" });
release();
await asking;
assert.equal(slow.current, false, "a read asked before the change heard is not since it");
// Read again after the change: the unwatched member merges plainly with the note, the watched one as any call's.
await reg.start();
const f3 = forge(pulls());
const landed = await call(f3, hq, { watched: view });
assert.deepEqual([f3.merges, landed.members.map((m: any) => [m.state, m.note])],
[["novox/hq#799", "novox/app#5"], [["merged", "no delivery: the repository has no watched branch"], ["merged", undefined]]]);
});
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/);