diff --git a/src/infra/windows-task-restart.test.ts b/src/infra/windows-task-restart.test.ts index fe584660310..fe6e8cc7fda 100644 --- a/src/infra/windows-task-restart.test.ts +++ b/src/infra/windows-task-restart.test.ts @@ -45,6 +45,14 @@ function decodeCmdPathArg(value: string): string { return withoutQuotes.replace(/\^!/g, "!").replace(/%%/g, "%"); } +function requireFirstMockCall(mock: { mock: { calls: T[][] } }, label: string): T[] { + const call = mock.mock.calls.at(0); + if (!call) { + throw new Error(`expected ${label} call`); + } + return call; +} + afterEach(() => { envSnapshot.restore(); for (const scriptPath of createdScriptPaths) { @@ -96,10 +104,10 @@ describe("relaunchGatewayScheduledTask", () => { expect(result.method).toBe("schtasks"); expect(result.tried).toContain('schtasks /Run /TN "OpenClaw Gateway (work)"'); expect(result.tried).toContain(`cmd.exe /d /s /c ${seenCommandArg}`); - const spawnCall = spawnMock.mock.calls[0]; - expect(spawnCall?.[0]).toBe("cmd.exe"); - expect(spawnCall?.[1]).toStrictEqual(["/d", "/s", "/c", seenCommandArg]); - expect(spawnCall?.[2]).toStrictEqual({ + const spawnCall = requireFirstMockCall(spawnMock, "restart helper spawn"); + expect(spawnCall[0]).toBe("cmd.exe"); + expect(spawnCall[1]).toStrictEqual(["/d", "/s", "/c", seenCommandArg]); + expect(spawnCall[2]).toStrictEqual({ detached: true, stdio: "ignore", windowsHide: true, @@ -182,10 +190,7 @@ describe("relaunchGatewayScheduledTask", () => { relaunchGatewayScheduledTask({ OPENCLAW_PROFILE: "work" }); expect(spawnMock).toHaveBeenCalledOnce(); - const spawnCall = spawnMock.mock.calls[0]; - if (!spawnCall) { - throw new Error("expected restart helper spawn call"); - } + const spawnCall = requireFirstMockCall(spawnMock, "restart helper spawn"); const commandArgs = spawnCall[1]; if (!Array.isArray(commandArgs)) { throw new Error("expected cmd.exe argument array");