diff --git a/src/cli/daemon-cli/lifecycle.test.ts b/src/cli/daemon-cli/lifecycle.test.ts index 7da1935c1e2..6c1fde92ab2 100644 --- a/src/cli/daemon-cli/lifecycle.test.ts +++ b/src/cli/daemon-cli/lifecycle.test.ts @@ -230,6 +230,26 @@ describe("runDaemonRestart health checks", () => { expect(waitForGatewayHealthyRestart).toHaveBeenCalledTimes(2); }); + it("fails without killing the current runtime pid when stale detection only includes self", async () => { + const unhealthy: RestartHealthSnapshot = { + healthy: false, + staleGatewayPids: [1993], + runtime: { status: "running", pid: 1993 }, + portUsage: { port: 18789, status: "busy", listeners: [], hints: [] }, + }; + waitForGatewayHealthyRestart.mockResolvedValue(unhealthy); + + await expect(runDaemonRestart({ json: true })).rejects.toMatchObject({ + message: "Gateway restart timed out after 60s waiting for health checks.", + hints: ["openclaw gateway status --deep", "openclaw doctor"], + }); + + expect(terminateStaleGatewayPids).not.toHaveBeenCalled(); + expect(service.restart).not.toHaveBeenCalled(); + expect(waitForGatewayHealthyRestart).toHaveBeenCalledTimes(1); + expect(renderRestartDiagnostics).toHaveBeenCalledTimes(1); + }); + it("skips stale-pid retry health checks when the retry restart is only scheduled", async () => { const unhealthy: RestartHealthSnapshot = { healthy: false,