fix(k1): harden live handoff and camera recovery
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { after, before, test } from "node:test";
|
||||
|
||||
import { createServer } from "vite";
|
||||
|
||||
let server;
|
||||
let viewerSettingsTargetIdentity;
|
||||
|
||||
before(async () => {
|
||||
server = await createServer({
|
||||
appType: "custom",
|
||||
logLevel: "silent",
|
||||
server: { middlewareMode: true },
|
||||
});
|
||||
({ viewerSettingsTargetIdentity } = await server.ssrLoadModule(
|
||||
"/src/core/observation/viewerSettingsTarget.ts",
|
||||
));
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await server?.close();
|
||||
});
|
||||
|
||||
function runtimeState({ acquisitionId, sessionId = "session-a", deviceId = "device-a" }) {
|
||||
return {
|
||||
phase: "connected",
|
||||
sourceMode: "idle",
|
||||
activeDevice: {
|
||||
pluginId: "xgrids-k1",
|
||||
modelId: "lixel-k1",
|
||||
instanceId: "instance-a",
|
||||
displayName: "K1",
|
||||
},
|
||||
deviceSession: { sessionId, deviceId },
|
||||
acquisition: acquisitionId
|
||||
? {
|
||||
acquisitionId,
|
||||
deviceId,
|
||||
deviceSessionId: sessionId,
|
||||
compatibilityProfileId: "profile-a",
|
||||
controlMode: "live",
|
||||
state: "streaming",
|
||||
stateRevision: 1,
|
||||
operatorInstructions: [],
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
test("new acquisition on the same control session keeps the viewer settings target stable", () => {
|
||||
const beforeStart = viewerSettingsTargetIdentity(runtimeState({}));
|
||||
const firstRun = viewerSettingsTargetIdentity(runtimeState({ acquisitionId: "acquisition-a" }));
|
||||
const secondRun = viewerSettingsTargetIdentity(runtimeState({ acquisitionId: "acquisition-b" }));
|
||||
|
||||
assert.equal(firstRun, beforeStart);
|
||||
assert.equal(secondRun, beforeStart);
|
||||
});
|
||||
|
||||
test("temporary loss of control authority does not reapply settings within one device session", () => {
|
||||
const authoritative = runtimeState({ acquisitionId: "acquisition-a" });
|
||||
const authorityUnavailable = {
|
||||
...authoritative,
|
||||
activeDevice: null,
|
||||
phase: "starting",
|
||||
};
|
||||
|
||||
assert.equal(
|
||||
viewerSettingsTargetIdentity(authorityUnavailable),
|
||||
viewerSettingsTargetIdentity(authoritative),
|
||||
);
|
||||
});
|
||||
|
||||
test("a new control session or device produces a new viewer settings target", () => {
|
||||
const original = viewerSettingsTargetIdentity(runtimeState({ acquisitionId: "acquisition-a" }));
|
||||
|
||||
assert.notEqual(
|
||||
viewerSettingsTargetIdentity(runtimeState({ sessionId: "session-b" })),
|
||||
original,
|
||||
);
|
||||
assert.notEqual(
|
||||
viewerSettingsTargetIdentity(runtimeState({ deviceId: "device-b" })),
|
||||
original,
|
||||
);
|
||||
});
|
||||
|
||||
test("an unconfigured runtime uses the local target", () => {
|
||||
assert.equal(viewerSettingsTargetIdentity(null), "local-runtime");
|
||||
});
|
||||
Reference in New Issue
Block a user