From bfea6bebc925d6de6ae8786c546c135a1b0b0a2b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 19 Apr 2026 04:14:55 +0100 Subject: [PATCH] test: share subagent cleanup lookup --- src/agents/subagent-spawn.workspace.test.ts | 40 +++++++++------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/agents/subagent-spawn.workspace.test.ts b/src/agents/subagent-spawn.workspace.test.ts index a3dbc1fc1e2..b3809d5ef1d 100644 --- a/src/agents/subagent-spawn.workspace.test.ts +++ b/src/agents/subagent-spawn.workspace.test.ts @@ -71,6 +71,20 @@ function getRegisteredRun() { | undefined; } +function findLastSessionDeleteCall() { + return hoisted.callGatewayMock.mock.calls.findLast( + ([request]) => (request as { method?: string }).method === "sessions.delete", + )?.[0] as + | { + params?: { + key?: string; + deleteTranscript?: boolean; + emitLifecycleHooks?: boolean; + }; + } + | undefined; +} + async function expectAcceptedWorkspace(params: { agentId: string; expectedWorkspaceDir: string }) { const result = await spawnSubagentDirect( { @@ -223,18 +237,7 @@ describe("spawnSubagentDirect workspace inheritance", () => { expect(result.childSessionKey).toMatch(/^agent:main:subagent:/); expect(hoisted.registerSubagentRunMock).not.toHaveBeenCalled(); - const deleteCall = hoisted.callGatewayMock.mock.calls.find( - ([request]) => (request as { method?: string }).method === "sessions.delete", - )?.[0] as - | { - params?: { - key?: string; - deleteTranscript?: boolean; - emitLifecycleHooks?: boolean; - }; - } - | undefined; - + const deleteCall = findLastSessionDeleteCall(); expect(deleteCall?.params).toMatchObject({ key: result.childSessionKey, deleteTranscript: true, @@ -291,18 +294,7 @@ describe("spawnSubagentDirect workspace inheritance", () => { runId: "run-thread-register-fail", }); - const deleteCall = hoisted.callGatewayMock.mock.calls.findLast( - ([request]) => (request as { method?: string }).method === "sessions.delete", - )?.[0] as - | { - params?: { - key?: string; - deleteTranscript?: boolean; - emitLifecycleHooks?: boolean; - }; - } - | undefined; - + const deleteCall = findLastSessionDeleteCall(); expect(deleteCall?.params).toMatchObject({ key: result.childSessionKey, deleteTranscript: true,