From f06ae90884b13e68dc1a07f3a2fe0351d4e4a4f7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 21:09:02 +0000 Subject: [PATCH] test: share process respawn launchd assertions --- src/infra/process-respawn.test.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/infra/process-respawn.test.ts b/src/infra/process-respawn.test.ts index bacf4e1b24b..804dca82c22 100644 --- a/src/infra/process-respawn.test.ts +++ b/src/infra/process-respawn.test.ts @@ -53,7 +53,10 @@ function clearSupervisorHints() { } } -function expectLaunchdSupervisedWithoutKickstart(params?: { launchJobLabel?: string }) { +function expectLaunchdSupervisedWithoutKickstart(params?: { + launchJobLabel?: string; + detailContains?: string; +}) { setPlatform("darwin"); if (params?.launchJobLabel) { process.env.LAUNCH_JOB_LABEL = params.launchJobLabel; @@ -61,6 +64,9 @@ function expectLaunchdSupervisedWithoutKickstart(params?: { launchJobLabel?: str process.env.OPENCLAW_LAUNCHD_LABEL = "ai.openclaw.gateway"; const result = restartGatewayProcessWithFreshPid(); expect(result.mode).toBe("supervised"); + if (params?.detailContains) { + expect(result.detail).toContain(params.detailContains); + } expect(scheduleDetachedLaunchdRestartHandoffMock).toHaveBeenCalledWith({ env: process.env, mode: "start-after-exit", @@ -80,18 +86,10 @@ describe("restartGatewayProcessWithFreshPid", () => { it("returns supervised when launchd hints are present on macOS (no kickstart)", () => { clearSupervisorHints(); - setPlatform("darwin"); - process.env.LAUNCH_JOB_LABEL = "ai.openclaw.gateway"; - const result = restartGatewayProcessWithFreshPid(); - expect(result.mode).toBe("supervised"); - expect(result.detail).toContain("launchd restart handoff"); - expect(scheduleDetachedLaunchdRestartHandoffMock).toHaveBeenCalledWith({ - env: process.env, - mode: "start-after-exit", - waitForPid: process.pid, + expectLaunchdSupervisedWithoutKickstart({ + launchJobLabel: "ai.openclaw.gateway", + detailContains: "launchd restart handoff", }); - expect(triggerOpenClawRestartMock).not.toHaveBeenCalled(); - expect(spawnMock).not.toHaveBeenCalled(); }); it("returns supervised on macOS when launchd label is set (no kickstart)", () => {