Files
mesh-catalog/modules/mesh-catalog/test/heard.test.ts
T
jschoubben 35ff67bda0
mesh/delivery-group group feat/774-l3-reland rejected: composed together: the checker's verdict at the members' heads (b48c90fea31f): integration: mesh-self-ch…
mesh/delivery closed: a newer head of the same pull request
mesh/check failed: integration: mesh-self-check/cmd/mesh-self-check.TestTheSelfCheckWholeRunsOnTheBus: the run answered {Run:doctor-1793351737-1 At:20…
Design 47's last milestones: the keeper, self-check, healers, hand-acts, provisioner, vault, artifact sweep, disk readings, credential forms (issues 774, 1952, 1953, 1954, 1955)
One commit with exactly the tree of the reviewed head 35b4509c0a, on main 12c2574c9d, so two compiled programs added and removed on the branch leave no trace in history (issue 1577).
2026-10-30 02:21:51 +01:00

86 lines
4.5 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { answerOf, builtFrom, placeable, BUILDER, BUILDS_SINCE_TOOL, BUILDS_STATE, MANIFESTS_STATE } from "../heard.js";
// A walk's build as the build seat says it (mesh-controller's link.BuildResult), here mailu's of novox/hq issue 712.
const walkBuild = {
id: "build-1791997333800041716",
repository: "http://novox.internal:20000/novox/mesh-catalog.git",
path: "modules/mailu",
ref: "main",
on: "shanks",
trunk: "main",
"on-trunk": true,
branches: ["main"],
module: "mailu",
commit: "e1c8965ddbf1cf9af9cf1eed7a72ae9ffa6d5a87",
manifest: { module: "mailu", unhealthy: { severity: "urgent", why: "mail stops" } },
made: [{ name: "code", kind: "bundle", reference: "artifact-store://mailu/code/blobs/sha256:d041" }],
};
test("the catalogue takes builds from the builder's log, and hears no controller event (ADR 0571 clause 9)", async () => {
const manifest = JSON.parse(await readFile(new URL("../module.json", import.meta.url), "utf8"));
assert.deepEqual(manifest.consumes, []);
assert.ok(manifest.invokes.includes(`${BUILDER}.${BUILDS_SINCE_TOOL}`), "the builder's tool is not invoked");
for (const read of [BUILDS_STATE, MANIFESTS_STATE]) assert.ok(manifest.reads.includes(read), `${read} is not read`);
// A log entry is placed as a build: done with its manifest, made and against; failed passed over; queued not taken in.
const entry = { event: "build.ended", module: "mailu", fp: "fp1", repository: walkBuild.repository, directory: "modules/mailu",
commit: walkBuild.commit, ref: "main", at: "2026-10-29T20:00:00Z", outcome: "done", manifest: "ab", against: ["img@sha256:1"],
made: walkBuild.made };
const done = builtFrom(entry, walkBuild.manifest, false);
assert.deepEqual(placeable(done!), { placed: "yes", module: "mailu", commit: walkBuild.commit });
assert.deepEqual([done!.path, done!.against, done!.replay], ["modules/mailu", ["img@sha256:1"], false]);
assert.equal(placeable(builtFrom({ ...entry, outcome: "failed" }, {}, true)!).placed, "no");
assert.equal(builtFrom({ ...entry, outcome: "queued" }, {}, true), undefined);
// The tool's answer is read bare or as the runtime wraps it.
const bare = { since: "x", builds: [entry] };
for (const raw of [bare, { output: JSON.stringify(bare) }, { content: [{ text: JSON.stringify(bare) }] }]) {
assert.equal(answerOf<typeof bare>(raw).builds[0].module, "mailu");
}
});
test("a walk's build is placed, under its module and commit", () => {
assert.deepEqual(placeable(walkBuild), { placed: "yes", module: "mailu", commit: walkBuild.commit });
// A walk that took the check's build of the same key says so, and is placed all the same (ADR 0350 §2).
assert.equal(placeable({ ...walkBuild, reused: "the check's build" } as never).placed, "yes");
});
test("a merge check, a try, a dry run and a failure are passed over without a fault", () => {
for (const [body, why] of [
[{ ...walkBuild, "check-outcome": { verdict: "passed" } }, "merge check"],
[{ ...walkBuild, check: { try: true } }, "merge check or a try"],
[{ ...walkBuild, "dry-run": true }, "dry run"],
[{ ...walkBuild, failed: "exit status 1" }, "failed"],
] as const) {
const placing = placeable(body);
assert.equal(placing.placed, "no");
if (placing.placed === "no") {
assert.match(placing.why, new RegExp(why));
assert.equal(placing.fault, false);
}
}
});
test("an outcome that names no module or commit is said as the builder's fault", () => {
const placing = placeable({ repository: walkBuild.repository, commit: walkBuild.commit });
assert.equal(placing.placed, "no");
if (placing.placed === "no") assert.equal(placing.fault, true);
});
test("a branch built through the build verb is passed over; a commit on the trunk, or from a seat that names none, is placed (ADR 0238)", () => {
const branch = { ...walkBuild, ref: "feature", "on-trunk": false, branches: ["feature"] };
const placing = placeable(branch);
assert.equal(placing.placed, "no");
if (placing.placed === "no") {
assert.match(placing.why, /not on its repository's trunk main/);
assert.equal(placing.fault, false);
}
// On the trunk by its branches although the seat did not set on-trunk.
assert.equal(placeable({ ...branch, branches: ["feature", "main"] }).placed, "yes");
// A seat older than the rule says no trunk: placed, as the controller lets it through.
const { trunk, "on-trunk": _on, branches, ...older } = walkBuild;
assert.equal(placeable(older).placed, "yes");
});