import { test } from "node:test"; import assert from "node:assert/strict"; import { machineName, machinePrefix, networkName, newInstanceId, instanceIdOf } from "../src/lifecycle/names.ts"; test("network names fit incus's 15-character limit", () => { const id = newInstanceId("the-ordinary-shape", new Date("2026-08-24T22:15:00Z")); for (const segment of ["hosting", "isp-home", "isp-mobile", "home", "devices", "cafe"]) { const name = networkName(id, segment); assert.ok(name.length <= 15, `${name} is ${name.length} chars`); } }); test("network names are unique per (instance, segment)", () => { const a = newInstanceId("x", new Date("2026-08-24T22:15:00Z")); const b = newInstanceId("x", new Date("2026-08-24T23:15:00Z")); const names = new Set([ networkName(a, "home"), networkName(a, "cafe"), networkName(b, "home"), networkName(b, "cafe"), ]); assert.equal(names.size, 4, "two instances of one declaration must not share a network"); }); test("machine names round-trip to their instance id", () => { const id = newInstanceId("bootstrap-single", new Date("2026-08-24T22:15:00Z")); const name = machineName(id, "anchor"); assert.equal(instanceIdOf(name, "anchor"), id); assert.ok(name.startsWith(machinePrefix(id))); }); test("instance ids are sortable by time", () => { const early = newInstanceId("x", new Date("2026-08-24T09:00:00Z")); const late = newInstanceId("x", new Date("2026-08-24T21:00:00Z")); assert.ok(early < late, `${early} should sort before ${late}`); });