Merge order on a protected trunk was the whole proof; the review asked for ancestry. The gitea module gains gitea_contains, a read-only compare of two commits (total_commits 0 is contained), and mesh-delivery asks it once per pair, off the lock like its plan ask, keeping the answer on the delivery. A forge that cannot say leaves the merge held, not covered. Merge order stays the cheap first filter. A later delivery now carries a module only when its own check passed (so a merge held without a passing check is closed only by one that passed), its walk is of its own merge commit on the same trunk, and its steps say the module reached every machine running it, not one. The words say what is known: a later merge that contains it was delivered.
66 lines
3.6 KiB
TypeScript
66 lines
3.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
|
|
// What the forge says of a commit's checks (novox/hq ADR 0239): read by mesh-delivery's `checks` verb.
|
|
|
|
test("the newest status of each context is kept, with what it said, when and by whom", async () => {
|
|
const { newestByContext } = await import("../checks.ts");
|
|
const read = newestByContext([
|
|
{ context: "mesh/merge-gate", status: "success", description: "pass: every machine composes", updated_at: "2026-10-07T10:00:00Z",
|
|
creator: { login: "mesh-admin" }, target_url: "https://forge.example/o/r/pulls/1" },
|
|
{ context: "mesh/merge-gate", status: "failure", description: "fail: 0 of 4 compose", updated_at: "2026-10-07T09:00:00Z" },
|
|
{ context: "mesh/repo-check", state: "error", description: "error: the toolchain was not there", created_at: "2026-10-07T10:01:00Z" },
|
|
{ status: "success", description: "a status with no context" },
|
|
]);
|
|
assert.deepEqual(read.map((s) => [s.context, s.state]), [["mesh/merge-gate", "success"], ["mesh/repo-check", "error"]]);
|
|
assert.equal(read[0].creator, "mesh-admin");
|
|
assert.equal(read[0].description, "pass: every machine composes");
|
|
assert.equal(read[1].created_at, "2026-10-07T10:01:00Z");
|
|
});
|
|
|
|
test("a commit merges only when every required status is a success; a warning blocks", async () => {
|
|
const { mergeableUnder } = await import("../checks.ts");
|
|
const rule = { rule_name: "main", enable_status_check: true, status_check_contexts: ["mesh/merge-gate", "mesh/repo-check"] };
|
|
const ok = mergeableUnder("main", rule, [
|
|
{ context: "mesh/merge-gate", state: "success", description: "" },
|
|
{ context: "mesh/repo-check", state: "success", description: "" },
|
|
]);
|
|
assert.equal(ok.mergeable, true);
|
|
assert.deepEqual(ok.blocking, []);
|
|
|
|
const not = mergeableUnder("main", rule, [{ context: "mesh/merge-gate", state: "warning", description: "" }]);
|
|
assert.equal(not.mergeable, false);
|
|
assert.deepEqual(not.blocking, [{ context: "mesh/merge-gate", state: "warning" }, { context: "mesh/repo-check", state: "missing" }]);
|
|
assert.match(not.says, /mesh\/repo-check \(missing\)/);
|
|
});
|
|
|
|
test("no rule requires nothing; a rule that cannot be read says nothing, never yes", async () => {
|
|
const { mergeableUnder } = await import("../checks.ts");
|
|
const none = mergeableUnder("main", null, []);
|
|
assert.equal(none.mergeable, true);
|
|
assert.equal(none.protected, false);
|
|
const off = mergeableUnder("main", { rule_name: "main", enable_status_check: false, status_check_contexts: ["mesh/merge-gate"] }, []);
|
|
assert.equal(off.mergeable, true);
|
|
assert.deepEqual(off.required, []);
|
|
const unread = mergeableUnder("main", undefined, [], "Gitea API: 500");
|
|
assert.equal(unread.mergeable, null);
|
|
assert.match(unread.says, /could not be read/);
|
|
});
|
|
|
|
// novox/hq ADR 0270: a held delivery is covered only when a later delivered merge contains it.
|
|
test("a commit is contained in another when the compare finds nothing on it the other lacks", async () => {
|
|
const { containedFrom, isCommit } = await import("../checks.ts");
|
|
for (const [compare, contains, ahead] of [
|
|
[{ total_commits: 0, commits: [] }, true, 0],
|
|
[{ total_commits: 3, commits: [{}, {}, {}] }, false, 3],
|
|
] as const) {
|
|
assert.deepEqual(containedFrom(compare), { contains, ahead });
|
|
}
|
|
for (const bad of [{}, { total_commits: "0" }, { total_commits: -1 }, null]) {
|
|
assert.throws(() => containedFrom(bad), /total_commits/);
|
|
}
|
|
assert.equal(isCommit("6aabe8e"), true);
|
|
assert.equal(isCommit("90516fc0a1b2c3d4e5f60718293a4b5c6d7e8f90"), true);
|
|
for (const bad of ["main", "6aabe8e...90516fc", "../x", "6aabe8", ""]) assert.equal(isCommit(bad), false, bad);
|
|
});
|