fix: harden M3 simulator identities and wiring

This commit is contained in:
Code Queue Review
2026-05-23 04:30:01 +00:00
parent 82b1f9491e
commit c095d4d943
14 changed files with 416 additions and 18 deletions
+53
View File
@@ -1,6 +1,7 @@
import assert from "node:assert/strict";
import test from "node:test";
import { createM3Topology } from "./fixture.mjs";
import { createWiringConfig } from "./model.mjs";
import { createPatchPanelRuntime } from "./runtime.mjs";
@@ -110,3 +111,55 @@ test("runtime reports missing target endpoint as readable diagnostics", async ()
assert.equal(result.deliveryCount, 1);
assert.ok(result.diagnostics.some((diagnostic) => diagnostic.code === "target_endpoint_missing"));
});
test("runtime applies first-class DEV M3 wiring config for res_boxsimu_1 DO1 to res_boxsimu_2 DI1", async () => {
const topology = createM3Topology();
const writes = [];
const runtime = createPatchPanelRuntime({
wiringConfig: topology.wiringConfig,
endpointMap: {
res_boxsimu_2: "http://hwlab-box-simu-2.hwlab-dev.svc.cluster.local:7201"
},
configSource: "env:HWLAB_PATCH_PANEL_WIRING_CONFIG",
now: () => "2026-05-21T00:00:01.000Z",
requestJson: async (url, body) => {
writes.push({ url, body });
return {
status: 200,
json: {
accepted: true
}
};
}
});
assert.equal(runtime.status().state, "active");
assert.equal(runtime.status().metadata.configSource, "env:HWLAB_PATCH_PANEL_WIRING_CONFIG");
assert.deepEqual(runtime.status().activeConnections, [
{
fromResourceId: "res_boxsimu_1",
fromPort: "DO1",
toResourceId: "res_boxsimu_2",
toPort: "DI1"
}
]);
const result = await runtime.routeSignal({
fromResourceId: "res_boxsimu_1",
fromPort: "DO1",
value: true
});
assert.equal(result.accepted, true);
assert.equal(result.propagatedBy, "hwlab-patch-panel");
assert.equal(result.deliveryCount, 1);
assert.equal(writes.length, 1);
assert.equal(
writes[0].url,
"http://hwlab-box-simu-2.hwlab-dev.svc.cluster.local:7201/internal/ports/write"
);
assert.equal(writes[0].body.port, "DI1");
assert.equal(writes[0].body.sourceResourceId, "res_boxsimu_1");
assert.equal(writes[0].body.sourcePort, "DO1");
assert.equal(writes[0].body.propagatedBy, "hwlab-patch-panel");
});