feat: add patch panel runtime sync

This commit is contained in:
HWLAB Code Queue
2026-05-21 18:36:39 +00:00
parent eba24b72c0
commit b1f4e6e52d
14 changed files with 1583 additions and 45 deletions
+25 -5
View File
@@ -1,20 +1,40 @@
#!/usr/bin/env node
import { createMvpTopology } from "../../internal/patchpanel/fixture.mjs";
import { createPatchPanel } from "../../internal/patchpanel/model.mjs";
import {
createPatchPanelRuntime,
createPatchPanelRuntimeFromFile
} from "../../internal/patchpanel/runtime.mjs";
import { createHealth } from "../../internal/sim/model.mjs";
import { createJsonServer, listen, parsePort, readJson } from "../../internal/sim/http.mjs";
const port = parsePort(process.env.PORT, 7301);
const wiringConfigPath = process.env.HWLAB_WIRING_CONFIG_PATH;
const topology = createMvpTopology();
const patchPanel = createPatchPanel({ wiringConfig: topology.wiringConfig });
const runtime = wiringConfigPath
? await createPatchPanelRuntimeFromFile({ path: wiringConfigPath })
: createPatchPanelRuntime({
wiringConfig: topology.wiringConfig,
configSource: "internal:mvp-topology"
});
const routes = new Map();
routes.set("GET /health/live", () =>
createHealth({ serviceId: "hwlab-patch-panel", name: "hwlab-patch-panel" })
);
routes.set("GET /status", () => patchPanel.status());
routes.set("GET /wiring", () => patchPanel.wiringConfig);
routes.set("POST /signals/route", async ({ req }) => patchPanel.routeSignal(await readJson(req)));
routes.set("GET /status", () => runtime.status());
routes.set("GET /diagnostics", () => runtime.diagnostics());
routes.set("GET /wiring", () => runtime.wiringConfig);
routes.set("POST /wiring/apply", async ({ req }) => runtime.applyConfig(await readJson(req)));
routes.set("POST /wiring/reload", async ({ req }) => {
const body = await readJson(req);
const path = body.path ?? wiringConfigPath;
if (!path) {
throw new Error("wiring reload requires body.path or HWLAB_WIRING_CONFIG_PATH");
}
return runtime.reloadFromFile(path);
});
routes.set("POST /signals/route", async ({ req }) => runtime.routeSignal(await readJson(req)));
routes.set("POST /sync/tick", async ({ req }) => runtime.tick(await readJson(req)));
listen(createJsonServer({ routes }), port);