From 133b0abd5605fa551582224e1fc0b20f3e6e5a49 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Feb 2026 23:10:16 +0000 Subject: [PATCH] Assert unauthorized websocket rejection in smoke test Co-authored-by: Theo Browne --- apps/t3/scripts/smoke-test.mjs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/t3/scripts/smoke-test.mjs b/apps/t3/scripts/smoke-test.mjs index 2cc67ba026..90a9dc42b8 100644 --- a/apps/t3/scripts/smoke-test.mjs +++ b/apps/t3/scripts/smoke-test.mjs @@ -53,6 +53,22 @@ async function terminateProcess(processRef, timeoutMs = 5_000) { await waitForProcessExit(processRef); } +function waitForSocketCloseCode(socket, timeoutMs = 10_000) { + return new Promise((resolve, reject) => { + const timer = setTimeout(() => { + reject(new Error("Smoke test failed: websocket close event timed out.")); + }, timeoutMs); + socket.addEventListener("close", (event) => { + clearTimeout(timer); + resolve(event.code); + }); + socket.addEventListener("error", () => { + clearTimeout(timer); + reject(new Error("Smoke test failed: websocket client error before close.")); + }); + }); +} + function waitForStartupUrl(readOutput, processRef, timeoutMs = 20_000) { return new Promise((resolve, reject) => { const finish = (callback, value) => { @@ -143,6 +159,15 @@ async function main() { throw new Error("Smoke test failed: websocket URL is missing runtime auth token."); } + const unauthorizedWsUrl = `${parsedWsUrl.origin}${parsedWsUrl.pathname}`; + const unauthorizedWs = new WebSocket(unauthorizedWsUrl); + const unauthorizedCode = await waitForSocketCloseCode(unauthorizedWs); + if (unauthorizedCode !== 4001) { + throw new Error( + `Smoke test failed: expected unauthorized close code 4001, received ${unauthorizedCode}.`, + ); + } + const ws = new WebSocket(wsUrl); await new Promise((resolve, reject) => { const timer = setTimeout(