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/); });