Cover renderer recovery after transient websocket send failures

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 07:51:36 +00:00
1 parent b1c96a56e6
commit 3421e53f96
1 file changed
+29
+29
View File
@@ -207,6 +207,35 @@ describe("wsNativeApi", () => {
);
});
it("recovers after a transient websocket send failure", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4480");
MockWebSocket.failSend = true;
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
await expect(api.todos.list()).rejects.toThrow(
"Failed to send runtime request 'todos.list': mock send failure",
);
MockWebSocket.failSend = false;
const secondRequest = api.todos.list();
const socket = MockWebSocket.instances[0];
await waitForCondition(() => (socket?.sentMessages.length ?? 0) > 0);
const requestEnvelope = JSON.parse(socket?.sentMessages[0] ?? "{}") as {
id: string;
};
socket?.emitMessage(
JSON.stringify({
type: "response",
id: requestEnvelope.id,
ok: true,
result: [],
}),
);
await expect(secondRequest).resolves.toEqual([]);
});
it("sends app.health requests to runtime", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4411");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");