import { test } from "node:test"; import assert from "node:assert/strict"; import { busNotKept, runningFrom, streamsFrom, written, type Seen } from "./integration/bus-kept.ts"; /** * The judgement of the bed that raises genesis past its broker step (novox/hq ADR 0333 ยง5, issue 590): * exactly one bus container, it is mesh-broker-nats, a stream written before the step is still there, and * the first node is still connected. Held here without a lab, so the bed's verdict is the judgement's and * not whatever a bed happened to compare. */ const UPSTREAM = "nats@sha256:" + "b".repeat(64); const MODULES = "192.0.2.10:5000/nats@sha256:" + "c".repeat(64); const PORTS = "127.0.0.1:8222->8222/tcp, 0.0.0.0:5671->4222/tcp"; function jsz(streams: Array<[string, string, number, number]>): string { return JSON.stringify({ account_details: [{ name: "MESH", stream_detail: streams.map(([name, created, messages, last]) => ({ name, created, state: { messages, last_seq: last } })) }] }); } const before: Seen = { running: runningFrom(`mesh-store\tpostgres@sha256:aa\t0.0.0.0:5432->5432/tcp\nmesh-broker-nats\t${UPSTREAM}\t${PORTS}\n` + "mesh-controller\t192.0.2.10:5000/mesh-controller@sha256:dd\t\n"), streams: streamsFrom(jsz([["KV_mesh-controller_lease", "2026-10-13T00:10:00Z", 3, 7], ["EMPTY", "2026-10-13T00:10:01Z", 0, 0]])), }; const kept: Seen = { running: runningFrom(`mesh-store\tpostgres@sha256:aa\t0.0.0.0:5432->5432/tcp\nmesh-broker-nats\t${MODULES}\t${PORTS}\n` + "mesh-controller\t192.0.2.10:5000/mesh-controller@sha256:dd\t\n"), streams: streamsFrom(jsz([["KV_mesh-controller_lease", "2026-10-13T00:10:00Z", 3, 9]])), }; const SAID = "broker โ€” the foundation's bus, adopted as the nats module\n restarting mesh-broker-nats โ€” once, onto the nats module's image"; const HERE = "anchor here last 3s ago"; test("a bus adopted in place is kept: one bus, the module's image, its streams, the node connected", () => { assert.deepEqual(busNotKept(before, kept, HERE, SAID), []); }); test("only a stream holding something counts as written before the step", () => { assert.deepEqual(written(before).map((s) => s.name), ["KV_mesh-controller_lease"]); }); test("a second bus beside the first is not kept: the fault genesis had before ADR 0333", () => { const two: Seen = { ...kept, running: [...kept.running, { name: "mesh-broker", image: UPSTREAM, ports: "0.0.0.0:5671->4222/tcp" }] }; const wrong = busNotKept(before, two, HERE, SAID); assert.equal(wrong.length, 1); assert.match(wrong[0] as string, /2 bus containers.*mesh-broker \(/); }); test("a bus under another name, or none, is not kept", () => { const renamed: Seen = { ...kept, running: kept.running.map((r) => r.name === "mesh-broker-nats" ? { ...r, name: "nats-server" } : r) }; assert.ok(busNotKept(before, renamed, HERE, SAID).some((w) => /mesh-broker-nats does not run/.test(w))); const none: Seen = { ...kept, running: kept.running.filter((r) => r.name !== "mesh-broker-nats") }; assert.ok(busNotKept(before, none, HERE, SAID).some((w) => /0 bus containers/.test(w))); }); test("a bus still on the bundle's image was not adopted", () => { const same: Seen = { ...kept, running: before.running }; assert.ok(busNotKept(before, same, HERE, SAID).some((w) => /still runs .* the image the bundle raised/.test(w))); assert.ok(busNotKept(before, kept, HERE, "broker โ€” adopted").some((w) => /did not say the bus restarts/.test(w))); }); test("a stream gone or made again is not kept", () => { const gone: Seen = { ...kept, streams: [] }; assert.ok(busNotKept(before, gone, HERE, SAID).some((w) => /KV_mesh-controller_lease .* is gone/.test(w))); const again: Seen = { ...kept, streams: streamsFrom(jsz([["KV_mesh-controller_lease", "2026-10-13T00:40:00Z", 1, 1]])) }; assert.ok(busNotKept(before, again, HERE, SAID).some((w) => /was made again/.test(w))); }); test("a node the mesh has not heard from since the step is not connected", () => { assert.ok(busNotKept(before, kept, "anchor out of touch 4m", SAID).some((w) => /has not heard from the first node/.test(w))); assert.ok(busNotKept(before, kept, "", SAID).some((w) => /no record/.test(w))); });