























@@ -14,7 +14,51 @@ vi.mock("./health.js", () => ({
1414healthCommand: vi.fn(),
1515}));
161617-import { probeGatewayMemoryStatus } from "./doctor-gateway-health.js";
17+import { checkGatewayHealth, probeGatewayMemoryStatus } from "./doctor-gateway-health.js";
18+19+describe("checkGatewayHealth", () => {
20+const cfg = {} as OpenClawConfig;
21+22+beforeEach(() => {
23+callGateway.mockReset();
24+});
25+26+it("uses a lightweight status RPC for the restart liveness gate", async () => {
27+callGateway.mockResolvedValueOnce({ ok: true }).mockResolvedValueOnce({});
28+const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
29+30+await expect(
31+checkGatewayHealth({ runtime: runtime as never, cfg, timeoutMs: 3000 }),
32+).resolves.toEqual({ healthOk: true });
33+34+expect(callGateway).toHaveBeenNthCalledWith(1, {
35+method: "status",
36+params: { includeChannelSummary: false },
37+timeoutMs: 3000,
38+config: cfg,
39+});
40+expect(callGateway).toHaveBeenNthCalledWith(2, {
41+method: "channels.status",
42+params: { probe: true, timeoutMs: 5000 },
43+timeoutMs: 6000,
44+});
45+expect(runtime.error).not.toHaveBeenCalled();
46+});
47+48+it("does not run follow-up channel probes when liveness fails", async () => {
49+callGateway.mockRejectedValueOnce(new Error("gateway timeout after 3000ms"));
50+const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
51+52+await expect(
53+checkGatewayHealth({ runtime: runtime as never, cfg, timeoutMs: 3000 }),
54+).resolves.toEqual({ healthOk: false });
55+56+expect(callGateway).toHaveBeenCalledTimes(1);
57+expect(runtime.error).toHaveBeenCalledWith(
58+expect.stringContaining("Health check failed: Error: gateway timeout after 3000ms"),
59+);
60+});
61+});
18621963describe("probeGatewayMemoryStatus", () => {
2064const cfg = {} as OpenClawConfig;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。