diff options
| author | Adam Malczewski <[email protected]> | 2026-10-21 19:39:47 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-10-21 19:39:47 +0900 |
| commit | 7b7d6d01cf94ecad1dcaaa4b87670d50fe15790a (patch) | |
| tree | 29bbfa52183b2a6639d96ad21d66806fb8ccea30 /src/app/surface-protocol.test.ts | |
| parent | ac43e92d174ed1f081c387944e9044643ee9efc2 (diff) | |
| download | dispatch-web-7b7d6d01cf94ecad1dcaaa4b87670d50fe15790a.tar.gz dispatch-web-7b7d6d01cf94ecad1dcaaa4b87670d50fe15790a.zip | |
fix(chat): bound live subscriptions and preserve unconfirmed input
Diffstat (limited to 'src/app/surface-protocol.test.ts')
| -rw-r--r-- | src/app/surface-protocol.test.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/app/surface-protocol.test.ts b/src/app/surface-protocol.test.ts index 5ac4f70..405e561 100644 --- a/src/app/surface-protocol.test.ts +++ b/src/app/surface-protocol.test.ts @@ -63,3 +63,34 @@ describe("conversation-scoped surface lookup", () => { expect(surfaces.surfaceSpecOp("s1", "c1")).toBeNull(); }); }); + +describe("surface subscription budget", () => { + it("bounds a large catalog and releases old slots before subscribing a replacement catalog", () => { + const live = new Set<string>(); + let peak = 0; + const surfaces = createSurfaceProtocol({ + focusedConversationId: () => "chat", + send(message) { + if (message.type === "subscribe") live.add(message.surfaceId); + if (message.type === "unsubscribe") live.delete(message.surfaceId); + peak = Math.max(peak, live.size); + }, + }); + for (const prefix of ["old", "new"]) { + surfaces.handleServerMessage({ + type: "catalog", + catalog: Array.from({ length: 339 }, (_, i) => ({ + id: `${prefix}-${i}`, + region: "inline", + title: "Surface", + scope: "global" as const, + })), + }); + expect(live.size).toBe(128); + expect([...live].every((id) => id.startsWith(prefix))).toBe(true); + } + surfaces.subscribeSurfaceOp("overflow"); + expect(live.has("overflow")).toBe(false); + expect(peak).toBe(128); + }); +}); |
