From 37828cd4bb3972e12ae48ecb002c61e7cb29628c Mon Sep 17 00:00:00 2001 From: Alix-007 <267018309+Alix-007@users.noreply.github.com> Date: Thu, 19 Mar 2026 16:21:16 +0800 Subject: [PATCH] test(daemon): cover self-only stale pid restart failure --- src/cli/daemon-cli/lifecycle.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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,