From e33e0e42dd12130bda357180b83aff0cd1e5d4b0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 04:12:40 +0000 Subject: [PATCH] Cover client socket shutdown on runtime close Co-authored-by: Theo Browne --- apps/t3/src/runtimeApiServer.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 9b117f1f4d..ca66b34af4 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -226,6 +226,27 @@ describe("runtimeApiServer", () => { ]); }); + it("terminates connected websocket clients when runtime closes", async () => { + const server = await startRuntimeApiServer({ + port: 0, + launchCwd: process.cwd(), + }); + servers.push(server); + + const client = await connectClient(server.wsUrl); + await client.nextMessage(); + + const closed = withTimeout( + new Promise<{ code: number }>((resolve) => { + client.socket.once("close", (code) => resolve({ code })); + }), + ); + + await server.close(); + const closeEvent = await closed; + expect([1000, 1001, 1005, 1006]).toContain(closeEvent.code); + }); + it("rejects startup when launchCwd does not exist", async () => { const missingPath = path.join(process.cwd(), `missing-launch-cwd-${Date.now()}`); await expect(