diff --git a/src/infra/gateway-watch-tmux.test.ts b/src/infra/gateway-watch-tmux.test.ts index 3da4336e629..6089779acbb 100644 --- a/src/infra/gateway-watch-tmux.test.ts +++ b/src/infra/gateway-watch-tmux.test.ts @@ -26,13 +26,22 @@ function requireRecord(value: unknown, label: string): Record { function spawnCall(mock: unknown, callIndex: number) { const calls = (mock as { mock?: { calls?: Array> } }).mock?.calls ?? []; - const call = calls.at(callIndex); + const call = calls[callIndex]; if (!call) { throw new Error(`Expected spawn call ${callIndex + 1}`); } return call; } +function spawnShellCommand(mock: unknown, callIndex: number): string { + const call = spawnCall(mock, callIndex); + const args = call[1]; + if (!Array.isArray(args) || typeof args[6] !== "string") { + throw new Error(`Expected spawn call ${callIndex + 1} shell command`); + } + return args[6]; +} + function expectSpawn(mock: unknown, callIndex: number, command: string, args: Array) { const call = spawnCall(mock, callIndex); expect(call[0]).toBe(command); @@ -110,7 +119,7 @@ describe("gateway-watch tmux wrapper", () => { }); expect(code).toBe(0); - const command = spawnSync.mock.calls.at(1)?.[1]?.[6] as string; + const command = spawnShellCommand(spawnSync, 1); expect(command).toContain("'OPENCLAW_RUN_NODE_CPU_PROF_DIR=.artifacts/gateway-watch-profiles'"); expect(command).toContain("'OPENCLAW_TRACE_SYNC_IO=0'"); expect(command).not.toContain("--benchmark"); @@ -142,7 +151,7 @@ describe("gateway-watch tmux wrapper", () => { }); expect(code).toBe(0); - const command = spawnSync.mock.calls.at(1)?.[1]?.[6] as string; + const command = spawnShellCommand(spawnSync, 1); expect(command).toContain("'OPENCLAW_TRACE_SYNC_IO=1'"); expect(command).toContain( "'OPENCLAW_RUN_NODE_OUTPUT_LOG=.artifacts/gateway-watch-profiles/gateway-watch-output.log'", @@ -174,7 +183,7 @@ describe("gateway-watch tmux wrapper", () => { }); expect(code).toBe(0); - const command = spawnSync.mock.calls.at(1)?.[1]?.[6] as string; + const command = spawnShellCommand(spawnSync, 1); expect(command).toContain("'OPENCLAW_RUN_NODE_CPU_PROF_DIR=.artifacts/gateway-watch-profiles'"); expect(command).not.toContain("--benchmark-no-force"); expect(command).toContain("'gateway'");