test: guard windows task restart mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 04:04:01 +01:00
parent f07ac11723
commit efdd3745aa

View File

@@ -45,6 +45,14 @@ function decodeCmdPathArg(value: string): string {
return withoutQuotes.replace(/\^!/g, "!").replace(/%%/g, "%");
}
function requireFirstMockCall<T>(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");