Files
mesh-lab/test/warm.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

62 lines
3.0 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { judge, type Warm } from "../src/warm.ts";
const at = "2026-08-31T20:00:00Z";
const built = { "mesh-lab": "aaa", "mesh-host": "bbb", "mesh-controller": "ccc" };
const warm = (over: Partial<Warm> = {}): Warm =>
({ scenario: "two-nodes", instanceId: "mlab-two-nodes-1", images: [], against: built, at, ...over });
// The check this exists for: a mesh warmed against code that has since moved would pass today's
// tests against yesterday's binaries, and the result would say nothing about it.
//
// Same fault as novox/hq 04-ISSUES/005, one level down — a green result standing for a run
// against something other than what is in front of you.
test("a warm mesh built from code that has moved is refused", () => {
const said = judge(warm(), "two-nodes", ["mlab-two-nodes-1"], true,
{ ...built, "mesh-host": "moved" });
assert.equal(said.use, "raise");
assert.match(said.use === "raise" ? said.why : "", /mesh-host was at bbb.*now at moved/);
});
test("a warm mesh built from the same code is used", () => {
const said = judge(warm(), "two-nodes", ["mlab-two-nodes-1"], true, built);
assert.equal(said.use, "restore");
});
// Each refusal is named, because each is a different thing being wrong.
test("every reason to raise instead says which reason it was", () => {
const cases: [string, ReturnType<typeof judge>][] = [
["nothing kept", judge(null, "two-nodes", [], true, built)],
["another scenario", judge(warm({ scenario: "first-node" }), "two-nodes",
["mlab-two-nodes-1"], true, built)],
["not standing", judge(warm(), "two-nodes", [], true, built)],
["no snapshot", judge(warm(), "two-nodes", ["mlab-two-nodes-1"], false, built)],
];
for (const [what, said] of cases) {
assert.equal(said.use, "raise", what);
assert.ok(said.use === "raise" && said.why.length > 10,
`${what} was refused without saying why: ${JSON.stringify(said)}`);
}
});
// A repository the warm record never accounted for is a difference, not a match.
test("a repository that was not recorded when it was warmed is refused", () => {
const said = judge(warm({ against: { "mesh-lab": "aaa" } }), "two-nodes",
["mlab-two-nodes-1"], true, built);
assert.equal(said.use, "raise");
});
// A repository the current run cannot see is not a repository that agrees.
//
// **Found by testing the guard rather than trusting it.** The first version walked only the
// repositories the current environment names, so running without that environment compared
// nothing and called a stale mesh usable. The mesh had genuinely moved; the check had looked at
// neither side.
test("a repository this run cannot locate is refused, not passed over", () => {
const said = judge(warm(), "two-nodes", ["mlab-two-nodes-1"], true, { "mesh-lab": "aaa" });
assert.equal(said.use, "raise");
assert.match(said.use === "raise" ? said.why : "",
/nothing says where it is now|so nothing can say whether it moved/);
});