Cover disconnect close code precedence in renderer diagnostics

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 08:09:18 +00:00
1 parent 7df0b667f8
commit dfd11e6140
1 file changed
+29
+29
View File
@@ -622,6 +622,19 @@ describe("wsNativeApi", () => {
await expect(request).rejects.toThrow("websocket disconnected (unauthorized)");
});
it("prioritizes unauthorized code over non-auth reason on disconnect", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4486");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
const request = api.todos.list();
const socket = MockWebSocket.instances[0];
await waitForCondition(() => (socket?.sentMessages.length ?? 0) > 0);
socket?.closeWith({ code: WS_CLOSE_CODES.unauthorized, reason: "not-unauthorized-reason" });
await expect(request).rejects.toThrow("websocket disconnected (unauthorized)");
});
it("maps replacement reason-only disconnects to explicit replacement errors", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4462");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
@@ -635,6 +648,22 @@ describe("wsNativeApi", () => {
await expect(request).rejects.toThrow("websocket disconnected (replaced-by-new-client)");
});
it("prioritizes replacement code over non-replacement reason on disconnect", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4487");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
const request = api.todos.list();
const socket = MockWebSocket.instances[0];
await waitForCondition(() => (socket?.sentMessages.length ?? 0) > 0);
socket?.closeWith({
code: WS_CLOSE_CODES.replacedByNewClient,
reason: "not-replacement-reason",
});
await expect(request).rejects.toThrow("websocket disconnected (replaced-by-new-client)");
});
it("reconnects after pending request is rejected by unauthorized disconnect", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4467");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");