Add ws adapter test for structured error responses

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-09 23:13:30 +00:00
1 parent 8bd155f790
commit 2cb6ed9615
1 file changed
+27
+27
View File
@@ -150,4 +150,31 @@ describe("wsNativeApi", () => {
await expect(request).resolves.toEqual([]);
});
it("rejects request when runtime responds with structured error", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4402");
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);
const requestEnvelope = JSON.parse(socket?.sentMessages[0] ?? "{}") as {
id: string;
};
socket?.emitMessage(
JSON.stringify({
type: "response",
id: requestEnvelope.id,
ok: false,
error: {
code: "request_failed",
message: "boom",
},
}),
);
await expect(request).rejects.toThrow("boom");
});
});