Files
pikasTech-HWLAB/internal/patchpanel/model.test.mjs
T
2026-05-21 14:40:31 +00:00

53 lines
1.8 KiB
JavaScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import { createMvpTopology } from "./fixture.mjs";
import { createPatchPanel } from "./model.mjs";
test("MVP topology includes two box simulators, two gateway simulators, and one patch panel", () => {
const topology = createMvpTopology();
assert.equal(topology.services.boxes.length, 2);
assert.equal(topology.services.gateways.length, 2);
assert.equal(topology.services.patchPanel.serviceId, "hwlab-patch-panel");
assert.equal(topology.constraints.patchPanelIsOnlyCrossDeviceChannel, true);
for (const box of topology.services.boxes) {
assert.equal(box.serviceId, "hwlab-box-simu");
assert.equal(box.constraints.localLoopbackEnabled, false);
assert.equal(box.constraints.crossDevicePropagation, "patch-panel-only");
}
});
test("patch panel routes cross-device signals and records deliveries", () => {
const topology = createMvpTopology();
const patchPanel = createPatchPanel({
wiringConfig: topology.wiringConfig,
now: () => "2026-01-01T00:00:01.000Z"
});
const result = patchPanel.routeSignal({
fromResourceId: "res_boxsim_alpha",
fromPort: "uart0",
value: "boot>"
});
assert.equal(result.accepted, true);
assert.equal(result.propagatedBy, "hwlab-patch-panel");
assert.deepEqual(result.deliveries, [
{
resourceId: "res_boxsim_beta",
port: "uart0",
value: "boot>",
sourceResourceId: "res_boxsim_alpha",
sourcePort: "uart0",
observedAt: "2026-01-01T00:00:01.000Z"
}
]);
});
test("static dry-run fixture matches generated MVP topology", async () => {
const raw = await readFile(new URL("../../fixtures/mvp-topology/topology.json", import.meta.url), "utf8");
assert.deepEqual(JSON.parse(raw), createMvpTopology());
});