diff --git a/apps/t3/scripts/smoke-test.mjs b/apps/t3/scripts/smoke-test.mjs index 68174a8032..a3edf299d9 100644 --- a/apps/t3/scripts/smoke-test.mjs +++ b/apps/t3/scripts/smoke-test.mjs @@ -2197,6 +2197,14 @@ async function main() { "wrong-token-key-while-connected", ); + const wrongPathWhileConnectedWs = new WebSocket( + `${parsedWsUrl.origin}/unexpected?token=${runtimeAuthTokenParam}`, + ); + await waitForUnauthorizedCloseWithoutMessages( + wrongPathWhileConnectedWs, + "wrong-path-while-connected", + ); + await new Promise((resolve, reject) => { const timer = setTimeout( () => reject(new Error("Smoke test failed: post-unauthorized websocket health request timed out.")), diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index b78cd72f8b..07746f946d 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -1483,6 +1483,49 @@ describe("runtimeApiServer", () => { expect([1000, 1005]).toContain(closed.code); }); + it("does not evict authorized client when wrong-path client connects", async () => { + const server = await startRuntimeApiServer({ + port: 0, + launchCwd: process.cwd(), + authToken: "secret-token", + }); + servers.push(server); + + const authorizedClient = await connectClient(server.wsUrl); + await authorizedClient.nextMessage(); + + const authorizedClose = new Promise<{ code: number }>((resolve) => { + authorizedClient.socket.once("close", (code) => resolve({ code })); + }); + + const authorizedUrl = new URL(server.wsUrl); + const wrongPathClient = new WebSocket( + `${authorizedUrl.origin}/unexpected?token=secret-token`, + ); + const wrongPathClose = await withTimeout( + new Promise<{ code: number; reason: string }>((resolve, reject) => { + wrongPathClient.once("close", (code, reason) => + resolve({ code, reason: reason.toString() }), + ); + wrongPathClient.once("error", (error) => reject(error)); + }), + ); + expect(wrongPathClose.code).toBe(WS_CLOSE_CODES.unauthorized); + expect(wrongPathClose.reason).toBe(WS_CLOSE_REASONS.unauthorized); + + const response = await sendRequest( + authorizedClient.socket, + authorizedClient.nextMessage, + "todos-auth-wrong-path-1", + "todos.list", + ); + expect(response.ok).toBe(true); + + authorizedClient.socket.close(); + const closed = await withTimeout(authorizedClose); + expect([1000, 1005]).toContain(closed.code); + }); + it("returns a bootstrap payload even when codex cannot initialize", async () => { const originalPath = process.env.PATH; process.env.PATH = "";