From c4b7956430822d7c07194d4603ae2a12ff342cf0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 06:03:55 +0000 Subject: [PATCH] Assert malformed websocket tolerance and unknown agent controls Co-authored-by: Theo Browne --- apps/t3/scripts/smoke-test.mjs | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/apps/t3/scripts/smoke-test.mjs b/apps/t3/scripts/smoke-test.mjs index 76d1dcb6f9..891b91e1d5 100644 --- a/apps/t3/scripts/smoke-test.mjs +++ b/apps/t3/scripts/smoke-test.mjs @@ -1640,6 +1640,24 @@ async function main() { ws.send(encodedBinaryRequest); }); + ws.send("not-json"); + ws.send(JSON.stringify({ foo: "bar" })); + const postMalformedHealthResponse = await sendWsRequest(ws, { + id: "smoke-health-after-malformed", + method: "app.health", + }); + if ( + postMalformedHealthResponse.ok !== true || + postMalformedHealthResponse.result?.status !== "ok" || + postMalformedHealthResponse.result?.launchCwd !== appRoot + ) { + throw new Error( + `Smoke test failed: expected healthy response after malformed websocket messages, got ${JSON.stringify( + postMalformedHealthResponse, + )}.`, + ); + } + const bootstrapResponse = await sendWsRequest(ws, { id: "smoke-bootstrap", method: "app.bootstrap", @@ -1918,6 +1936,40 @@ async function main() { throw new Error("Smoke test failed: unexpected writable agent exit payload."); } + const unknownAgentWriteResponse = await sendWsRequest(ws, { + id: "smoke-agent-write-unknown-session", + method: "agent.write", + params: { + sessionId: "missing-agent-session", + data: "ping\n", + }, + }); + if ( + unknownAgentWriteResponse.ok !== false || + unknownAgentWriteResponse.error?.code !== "request_failed" || + typeof unknownAgentWriteResponse.error?.message !== "string" || + !unknownAgentWriteResponse.error.message.includes("No session") + ) { + throw new Error( + `Smoke test failed: expected structured unknown-session agent.write error, got ${JSON.stringify( + unknownAgentWriteResponse, + )}.`, + ); + } + + const unknownAgentKillResponse = await sendWsRequest(ws, { + id: "smoke-agent-kill-unknown-session", + method: "agent.kill", + params: "missing-agent-session", + }); + if (unknownAgentKillResponse.ok !== true) { + throw new Error( + `Smoke test failed: expected successful unknown-session agent.kill no-op, got ${JSON.stringify( + unknownAgentKillResponse, + )}.`, + ); + } + const duplicateTokenWhileConnectedWs = new WebSocket( `${parsedWsUrl.origin}${parsedWsUrl.pathname}?token=${encodeURIComponent( parsedWsUrl.searchParams.get("token") ?? "",