From 4eeb87d476982c731fdaf4fa995ffa4d3986c8e8 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Feb 2026 23:56:50 +0000 Subject: [PATCH] Cover agent write and kill lifecycle in runtime integration tests Co-authored-by: Theo Browne --- apps/t3/src/runtimeApiServer.test.ts | 84 ++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 6742dd3823..c3113e5ce9 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -940,6 +940,90 @@ describe("runtimeApiServer", () => { client.socket.close(); }); + it("supports agent.write and agent.kill lifecycle", async () => { + const server = await startRuntimeApiServer({ + port: 0, + launchCwd: process.cwd(), + }); + servers.push(server); + + const client = await connectClient(server.wsUrl); + await client.nextMessage(); + + const spawnResponse = await sendRequest( + client.socket, + client.nextMessage, + "agent-spawn-2", + "agent.spawn", + { + command: "bash", + args: ["-lc", "cat"], + cwd: process.cwd(), + }, + ); + expect(spawnResponse.ok).toBe(true); + if (!spawnResponse.ok) { + throw new Error("Expected agent.spawn response to succeed."); + } + const sessionId = String(spawnResponse.result); + + const waitForAgentEvent = async (channel: string) => { + const message = await client.nextMessage(); + if (message.type !== "event") { + return waitForAgentEvent(channel); + } + if (message.channel !== channel) { + return waitForAgentEvent(channel); + } + + const payload = message.payload as { + sessionId?: string; + }; + if (payload.sessionId !== sessionId) { + return waitForAgentEvent(channel); + } + + return message; + }; + + const writeResponse = await sendRequest( + client.socket, + client.nextMessage, + "agent-write-1", + "agent.write", + { + sessionId, + data: "runtime-write-test\n", + }, + ); + expect(writeResponse.ok).toBe(true); + + const outputEvent = await waitForAgentEvent(WS_EVENT_CHANNELS.agentOutput); + const outputPayload = outputEvent.payload as { + data: string; + }; + expect(outputPayload.data).toContain("runtime-write-test"); + + const killResponse = await sendRequest( + client.socket, + client.nextMessage, + "agent-kill-1", + "agent.kill", + sessionId, + ); + expect(killResponse.ok).toBe(true); + + const exitEvent = await waitForAgentEvent(WS_EVENT_CHANNELS.agentExit); + const exitPayload = exitEvent.payload as { + code: number | null; + signal: string | null; + }; + expect(exitPayload.code === null || typeof exitPayload.code === "number").toBe(true); + expect(exitPayload.signal === null || typeof exitPayload.signal === "string").toBe(true); + + client.socket.close(); + }); + it("reports runtime health metadata", async () => { const server = await startRuntimeApiServer({ port: 0,