Files
mesh-lab/test/lastrun.test.ts
T
jschoubben 5d6e8fbe7a Rename mesh-control -> mesh-controller, substrate -> foundation
One name per thing, per the HQ glossary: the module/container/image/binary/repo
becomes mesh-controller, the seat the-controller, and the store+broker pair the
foundation (embedded base bundles, default template and example lock renamed with
their go:embed directives). No behaviour change — a pure vocabulary rename.

Claude-Session: https://claude.ai/code/session_01D6qtiYU3P9jk3pnAXyAFyx
2026-09-16 18:40:40 +02:00

168 lines
6.7 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { endToEnd, headOf, judge, type Receipt } from "../src/lastrun.ts";
const now = new Date("2026-08-31T12:00:00Z");
const passing = (at: string, against: Record<string, string>): Receipt =>
({ at, passed: 22, failed: 0, against, ran: [endToEnd] });
// A machine that has never run it is told so, rather than told nothing.
//
// novox/hq 04-ISSUES/005: the harness it replaces had not built for two and a half months and
// nothing said so. Silence and success must never look alike.
test("a machine that has never run the suite is told so", () => {
const said = judge(null, now, { "mesh-lab": "aaa" });
assert.equal(said.current, false);
assert.match(said.lines.join("\n"), /never run/);
});
// The one that matters: it passed, and against code nobody runs any more.
test("a run against code that has since changed is not current", () => {
const said = judge(
passing("2026-08-31T11:00:00Z", { "mesh-lab": "aaa", "mesh-controller": "bbb" }),
now,
{ "mesh-lab": "aaa", "mesh-controller": "ccc" },
);
assert.equal(said.current, false, "a run against changed code was reported as current");
const text = said.lines.join("\n");
assert.match(text, /mesh-controller\s+at bbb, now at ccc/, text);
assert.match(text, /code that has since changed/, text);
});
// Passing, recent, and against exactly this code is the only thing that counts.
test("a recent run against this code is current", () => {
const said = judge(
passing("2026-08-31T11:00:00Z", { "mesh-lab": "aaa" }),
now,
{ "mesh-lab": "aaa" },
);
assert.equal(said.current, true, said.lines.join("\n"));
assert.match(said.lines.join("\n"), /unchanged/);
});
// Old is a different complaint from moved, and says so — otherwise somebody goes looking for a
// change that did not happen.
test("a run that is merely old says that, not that something changed", () => {
const said = judge(
passing("2026-08-01T11:00:00Z", { "mesh-lab": "aaa" }),
now,
{ "mesh-lab": "aaa" },
);
assert.equal(said.current, false);
const text = said.lines.join("\n");
assert.match(text, /Nothing has changed since/, text);
assert.doesNotMatch(text, /has since changed/, text);
});
// A failed run is recorded, and does not count as coverage.
test("a run that failed is not coverage", () => {
const said = judge(
{
at: "2026-08-31T11:00:00Z",
passed: 21,
failed: 1,
against: { "mesh-lab": "aaa" },
ran: [endToEnd],
},
now,
{ "mesh-lab": "aaa" },
);
assert.equal(said.current, false);
assert.match(said.lines.join("\n"), /1 test\(s\) failed/);
assert.match(said.lines.join("\n"), /Nothing has been proven end to end since/);
});
// A repository the run never accounted for is named, rather than passing silently: a receipt that
// says nothing about something is not a receipt that clears it.
test("a repository the run did not account for is named", () => {
const said = judge(
passing("2026-08-31T11:00:00Z", { "mesh-lab": "aaa" }),
now,
{ "mesh-lab": "aaa", "mesh-host": "ddd" },
);
assert.equal(said.current, false);
assert.match(said.lines.join("\n"), /mesh-host\s+was not accounted for/);
});
// A green run of something else is not a green run of this.
//
// The suite takes paths, so it can be pointed at one quick unit file. Without recording what it
// ran, that receipt and a receipt for the real thing are the same document — which is the whole
// fault of novox/hq 04-ISSUES/005, reintroduced by the fix for it.
test("a run that raised no machines is not end-to-end coverage", () => {
const said = judge(
{
at: "2026-08-31T11:00:00Z",
passed: 6,
failed: 0,
against: { "mesh-lab": "aaa" },
ran: ["test/lastrun.test.ts"],
},
now,
{ "mesh-lab": "aaa" },
);
assert.equal(said.current, false, "a unit run was accepted as end-to-end coverage");
assert.match(said.lines.join("\n"), /raised no machines/);
});
// A receipt written before the mesh recorded what it ran claims nothing, and is read as claiming
// nothing — not as claiming everything.
test("a receipt from before this was recorded is not read as covering everything", () => {
const old = { at: "2026-08-31T11:00:00Z", passed: 22, failed: 0, against: { "mesh-lab": "aaa" } };
const said = judge(old as unknown as Receipt, now, { "mesh-lab": "aaa" });
assert.equal(said.current, false);
});
// A dirty tree is never equal to the clean commit it sits on.
//
// The run tested what was on disk. Naming the bare hash would claim coverage of code nobody can
// check out — and nothing else could tell, because the hash is identical either way.
test("a run taken against uncommitted work does not count as covering the commit", () => {
const said = judge(passing("2026-08-31T11:00:00Z", { "mesh-lab": "aaa+uncommitted" }), now, {
"mesh-lab": "aaa",
});
assert.equal(said.current, false, "a run against uncommitted work was read as covering the commit");
assert.match(said.lines.join("\n"), /aaa\+uncommitted, now at aaa/);
});
// headOf against a real repository, because the rule lives in headOf and not in judge.
//
// The first test written for this marked a hand-built receipt and passed with the marking removed
// — it checked how judge reads the value, never that anything produces it. A test that cannot fail
// when the behaviour is deleted is not defending the behaviour.
test("a repository with uncommitted work reports a commit that is marked as such", () => {
const repo = mkdtempSync(join(tmpdir(), "mesh-lab-headof-"));
try {
const git = (...args: string[]) =>
execFileSync("git", ["-C", repo, ...args], { stdio: ["ignore", "pipe", "ignore"] });
git("init", "-q");
git("config", "user.email", "test@example.invalid");
git("config", "user.name", "test");
writeFileSync(join(repo, "a"), "one\n");
git("add", "a");
git("commit", "-qm", "first");
const clean = headOf(repo);
assert.match(clean, /^[0-9a-f]+$/, `a clean tree was reported as ${clean}`);
writeFileSync(join(repo, "a"), "two\n");
assert.equal(headOf(repo), `${clean}+uncommitted`, "an uncommitted change was not marked");
} finally {
rmSync(repo, { recursive: true, force: true });
}
});
// A directory that is not a checkout is absent from the receipt, not guessed at.
test("a directory that is not a repository reports nothing", () => {
const plain = mkdtempSync(join(tmpdir(), "mesh-lab-plain-"));
try {
assert.equal(headOf(plain), "");
} finally {
rmSync(plain, { recursive: true, force: true });
}
});