test(gateway): cover helper registries
This commit is contained in:
41
src/gateway/server-bridge-subscriptions.test.ts
Normal file
41
src/gateway/server-bridge-subscriptions.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { createBridgeSubscriptionManager } from "./server-bridge-subscriptions.js";
|
||||
|
||||
describe("bridge subscription manager", () => {
|
||||
test("routes events to subscribed nodes", () => {
|
||||
const manager = createBridgeSubscriptionManager();
|
||||
const sent: Array<{
|
||||
nodeId: string;
|
||||
event: string;
|
||||
payloadJSON?: string | null;
|
||||
}> = [];
|
||||
const sendEvent = (evt: {
|
||||
nodeId: string;
|
||||
event: string;
|
||||
payloadJSON?: string | null;
|
||||
}) => sent.push(evt);
|
||||
|
||||
manager.subscribe("node-a", "main");
|
||||
manager.subscribe("node-b", "main");
|
||||
manager.sendToSession("main", "chat", { ok: true }, sendEvent);
|
||||
|
||||
expect(sent).toHaveLength(2);
|
||||
expect(sent.map((s) => s.nodeId).sort()).toEqual(["node-a", "node-b"]);
|
||||
expect(sent[0].event).toBe("chat");
|
||||
});
|
||||
|
||||
test("unsubscribeAll clears session mappings", () => {
|
||||
const manager = createBridgeSubscriptionManager();
|
||||
const sent: string[] = [];
|
||||
const sendEvent = (evt: { nodeId: string; event: string }) =>
|
||||
sent.push(`${evt.nodeId}:${evt.event}`);
|
||||
|
||||
manager.subscribe("node-a", "main");
|
||||
manager.subscribe("node-a", "secondary");
|
||||
manager.unsubscribeAll("node-a");
|
||||
manager.sendToSession("main", "tick", {}, sendEvent);
|
||||
manager.sendToSession("secondary", "tick", {}, sendEvent);
|
||||
|
||||
expect(sent).toEqual([]);
|
||||
});
|
||||
});
|
||||
18
src/gateway/server-chat-registry.test.ts
Normal file
18
src/gateway/server-chat-registry.test.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { createChatRunRegistry } from "./server-chat.js";
|
||||
|
||||
describe("chat run registry", () => {
|
||||
test("queues and removes runs per session", () => {
|
||||
const registry = createChatRunRegistry();
|
||||
|
||||
registry.add("s1", { sessionKey: "main", clientRunId: "c1" });
|
||||
registry.add("s1", { sessionKey: "main", clientRunId: "c2" });
|
||||
|
||||
expect(registry.peek("s1")?.clientRunId).toBe("c1");
|
||||
expect(registry.shift("s1")?.clientRunId).toBe("c1");
|
||||
expect(registry.peek("s1")?.clientRunId).toBe("c2");
|
||||
|
||||
expect(registry.remove("s1", "c2")?.clientRunId).toBe("c2");
|
||||
expect(registry.peek("s1")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user