48 lines
2.5 KiB
TypeScript
48 lines
2.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import { test } from "node:test";
|
|
|
|
const server = fs.readFileSync(new URL("../server/index.ts", import.meta.url), "utf8");
|
|
const protocol = fs.readFileSync(new URL("../shared/protocol.ts", import.meta.url), "utf8");
|
|
const client = fs.readFileSync(new URL("../client/main.ts", import.meta.url), "utf8");
|
|
|
|
test("server uses one lifecycle tail for every session lifecycle operation", () => {
|
|
assert.match(server, /\["newSession", "loadSession", "deleteSession", "renameSession"\]\.includes\(parsed\.type\)/);
|
|
assert.match(server, /const previous = attachmentTails\.get\(ws\) \|\| Promise\.resolve\(\)/);
|
|
assert.match(server, /const handle = clients\.get\(ws\);/);
|
|
});
|
|
|
|
test("server uses broker-owned runtimes and detaches sockets without stopping work", () => {
|
|
assert.match(server, /SessionBroker/);
|
|
assert.match(server, /runtime\.attach\(sink\)/);
|
|
assert.match(server, /current\.detach\(\)/);
|
|
assert.doesNotMatch(server, /type ClientRuntime/);
|
|
assert.doesNotMatch(server, /setupSessionEvents/);
|
|
assert.doesNotMatch(server, /pendingChoices/);
|
|
assert.doesNotMatch(server, /abort\(\)\.catch\(.*disconnect/i);
|
|
assert.doesNotMatch(server, /canonicalKey/);
|
|
assert.doesNotMatch(server, /sessionManagerForResumePath/);
|
|
});
|
|
|
|
test("server canonicalizes managers before runtime factory creation", () => {
|
|
assert.match(server, /keyForContext: \(context: Readonly<RuntimeContext>\): string => context\.sessionManager\.getSessionId\(\)/);
|
|
assert.match(server, /runtimeForManager\(sessionManager: SessionManager\)/);
|
|
assert.match(server, /broker\.getOrCreate\(\{ sessionManager \}\)/);
|
|
});
|
|
|
|
test("server resets broker runtimes before closing sockets on credential changes", () => {
|
|
assert.match(server, /for \(const ws of clients\.keys\(\)\) ws\.close[\s\S]*await broker\?\.disposeAll\(\)/);
|
|
});
|
|
|
|
test("protocol and client correlate prompt acceptance with a stable runtime", () => {
|
|
assert.match(protocol, /type: "prompt"; text: string; requestId: string/);
|
|
assert.match(protocol, /type: "promptAccepted"; requestId: string/);
|
|
assert.match(protocol, /type: "promptRejected"; requestId: string; message: string/);
|
|
assert.match(protocol, /type: "ready"; runtimeId: string; sessionId: string/);
|
|
assert.match(client, /pendingPrompt/);
|
|
assert.match(client, /pendingPrompt\.runtimeId === brokerRuntimeId/);
|
|
assert.match(client, /promptAccepted/);
|
|
assert.match(client, /promptRejected/);
|
|
assert.match(client, /if \(awaitingSnapshot\) \{[\s\S]*pendingChoice = null/);
|
|
});
|