From 6b2bd27c41dd56a986b65f75fba8e9927f8359db Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 12:47:25 +0000 Subject: [PATCH] Cover max-length unknown websocket method errors end-to-end Co-authored-by: Theo Browne --- apps/t3/scripts/smoke-test.mjs | 50 ++++++++++++++++++++++++++++ apps/t3/src/runtimeApiServer.test.ts | 27 +++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/apps/t3/scripts/smoke-test.mjs b/apps/t3/scripts/smoke-test.mjs index 6449450979..af1ccb2f81 100644 --- a/apps/t3/scripts/smoke-test.mjs +++ b/apps/t3/scripts/smoke-test.mjs @@ -2637,6 +2637,56 @@ async function main() { ); }); + await new Promise((resolve, reject) => { + const timer = setTimeout( + () => + reject( + new Error("Smoke test failed: max-length unknown-method websocket request timed out."), + ), + 20_000, + ); + const onMessage = (event) => { + const message = parseWsMessage(event.data); + if (!message) { + return; + } + + if (message.type !== "response" || message.id !== "smoke-unknown-method-max-length") { + return; + } + + ws.removeEventListener("message", onMessage); + clearTimeout(timer); + + if ( + message.ok !== false || + message.error?.code !== "request_failed" || + typeof message.error?.message !== "string" || + !message.error.message.includes("Unknown API method") + ) { + reject( + new Error( + `Smoke test failed: expected structured max-length unknown-method error response, got ${JSON.stringify( + message, + )}.`, + ), + ); + return; + } + + resolve(); + }; + + ws.addEventListener("message", onMessage); + ws.send( + JSON.stringify({ + type: "request", + id: "smoke-unknown-method-max-length", + method: "m".repeat(WS_METHOD_MAX_CHARS), + }), + ); + }); + const invalidShellEditorResponse = await sendWsRequest(ws, { id: "smoke-shell-invalid-editor", method: "shell.openInEditor", diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index d2e5b0a4e5..6d4060a38f 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -1827,6 +1827,33 @@ describe("runtimeApiServer", () => { client.socket.close(); }); + it("returns structured errors for unknown methods at max method length", async () => { + const server = await startRuntimeApiServer({ + port: 0, + launchCwd: process.cwd(), + }); + servers.push(server); + + const client = await connectClient(server.wsUrl); + await client.nextMessage(); + + const maxLengthUnknownMethod = "m".repeat(WS_METHOD_MAX_CHARS); + const response = await sendRequest( + client.socket, + client.nextMessage, + "unknown-max-method-1", + maxLengthUnknownMethod, + ); + expect(response.ok).toBe(false); + if (response.ok) { + throw new Error("Expected max-length unknown method to fail."); + } + expect(response.error?.code).toBe("request_failed"); + expect(response.error?.message).toContain("Unknown API method"); + + client.socket.close(); + }); + it("returns structured errors for invalid shell.openInEditor payloads", async () => { const server = await startRuntimeApiServer({ port: 0,