75 lines
3.5 KiB
TypeScript
75 lines
3.5 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
|
|
import { BUILD_EVENTS, placeable } 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 hears no retired build seat, and what the mesh held (issue 712, issue 1887 E2)", async () => {
|
|
for (const retired of ["node-build-agent.built", "mesh-build-machine.built"]) {
|
|
assert.ok(!(BUILD_EVENTS as readonly string[]).includes(retired), `${retired} is still heard`);
|
|
}
|
|
assert.ok(BUILD_EVENTS.includes("mesh-controller.built-before"));
|
|
// Subscribing is not enough: the mesh grants and routes only what the manifest consumes.
|
|
const manifest = JSON.parse(await readFile(new URL("../module.json", import.meta.url), "utf8"));
|
|
for (const heard of BUILD_EVENTS) assert.ok(manifest.consumes.includes(heard), `${heard} is not consumed`);
|
|
});
|
|
|
|
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");
|
|
});
|