test: share process respawn launchd assertions

This commit is contained in:
Peter Steinberger
2026-03-13 21:09:02 +00:00
parent 25eb3d5209
commit f06ae90884

View File

@@ -53,7 +53,10 @@ function clearSupervisorHints() {
} }
} }
function expectLaunchdSupervisedWithoutKickstart(params?: { launchJobLabel?: string }) { function expectLaunchdSupervisedWithoutKickstart(params?: {
launchJobLabel?: string;
detailContains?: string;
}) {
setPlatform("darwin"); setPlatform("darwin");
if (params?.launchJobLabel) { if (params?.launchJobLabel) {
process.env.LAUNCH_JOB_LABEL = 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"; process.env.OPENCLAW_LAUNCHD_LABEL = "ai.openclaw.gateway";
const result = restartGatewayProcessWithFreshPid(); const result = restartGatewayProcessWithFreshPid();
expect(result.mode).toBe("supervised"); expect(result.mode).toBe("supervised");
if (params?.detailContains) {
expect(result.detail).toContain(params.detailContains);
}
expect(scheduleDetachedLaunchdRestartHandoffMock).toHaveBeenCalledWith({ expect(scheduleDetachedLaunchdRestartHandoffMock).toHaveBeenCalledWith({
env: process.env, env: process.env,
mode: "start-after-exit", mode: "start-after-exit",
@@ -80,18 +86,10 @@ describe("restartGatewayProcessWithFreshPid", () => {
it("returns supervised when launchd hints are present on macOS (no kickstart)", () => { it("returns supervised when launchd hints are present on macOS (no kickstart)", () => {
clearSupervisorHints(); clearSupervisorHints();
setPlatform("darwin"); expectLaunchdSupervisedWithoutKickstart({
process.env.LAUNCH_JOB_LABEL = "ai.openclaw.gateway"; launchJobLabel: "ai.openclaw.gateway",
const result = restartGatewayProcessWithFreshPid(); detailContains: "launchd restart handoff",
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,
}); });
expect(triggerOpenClawRestartMock).not.toHaveBeenCalled();
expect(spawnMock).not.toHaveBeenCalled();
}); });
it("returns supervised on macOS when launchd label is set (no kickstart)", () => { it("returns supervised on macOS when launchd label is set (no kickstart)", () => {