Cover websocket responses with unknown request ids

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 00:06:20 +00:00
1 parent be2f37526f
commit 694818e5b3
1 file changed
+32
+32
View File
@@ -992,6 +992,38 @@ describe("wsNativeApi", () => {
await expect(request).resolves.toEqual([]);
});
it("ignores responses for unknown request ids", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4425");
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: "unknown-request-id",
ok: true,
result: ["ignored"],
}),
);
socket?.emitMessage(
JSON.stringify({
type: "response",
id: requestEnvelope.id,
ok: true,
result: [],
}),
);
await expect(request).resolves.toEqual([]);
});
it("dispatches provider events to subscribers and supports unsubscribe", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4409");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");