From ec402cfb243455dfdbf3783a24c4000f025daf41 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 10:28:14 +0000 Subject: [PATCH] Cover cyclic error payload fallback safety in renderer diagnostics Co-authored-by: Theo Browne --- apps/renderer/src/wsNativeApi.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/apps/renderer/src/wsNativeApi.test.ts b/apps/renderer/src/wsNativeApi.test.ts index 2a9241874c..f66ea194b5 100644 --- a/apps/renderer/src/wsNativeApi.test.ts +++ b/apps/renderer/src/wsNativeApi.test.ts @@ -253,6 +253,20 @@ describe("wsNativeApi", () => { ); }); + it("falls back safely when send throw payload contains cyclic error references", async () => { + setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4520"); + MockWebSocket.failSend = true; + const cyclicError: { error?: unknown } = {}; + cyclicError.error = cyclicError; + MockWebSocket.failSendError = cyclicError; + const { getOrCreateWsNativeApi } = await import("./wsNativeApi"); + const api = getOrCreateWsNativeApi(); + + await expect(api.todos.list()).rejects.toThrow( + "Failed to send runtime request 'todos.list': unknown websocket failure", + ); + }); + it("recovers after a transient websocket send failure", async () => { setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4480"); MockWebSocket.failSend = true; @@ -2315,6 +2329,18 @@ describe("wsNativeApi", () => { await expect(api.todos.list()).rejects.toThrow("Failed to connect to local t3 runtime."); }); + it("falls back safely when constructor throw payload contains cyclic error references", async () => { + setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4521"); + MockWebSocket.failConstruct = true; + const cyclicError: { error?: unknown } = {}; + cyclicError.error = cyclicError; + MockWebSocket.failConstructError = cyclicError; + const { getOrCreateWsNativeApi } = await import("./wsNativeApi"); + const api = getOrCreateWsNativeApi(); + + await expect(api.todos.list()).rejects.toThrow("Failed to connect to local t3 runtime."); + }); + it("recovers after websocket construction failure on next request", async () => { setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4427"); MockWebSocket.failConstruct = true;