mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 20:54:33 +00:00
refactor(cli): dedupe restart health probe setup tests
This commit is contained in:
@@ -46,6 +46,26 @@ async function inspectUnknownListenerFallback(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function inspectAmbiguousOwnershipWithProbe(
|
||||||
|
probeResult: Awaited<ReturnType<typeof probeGateway>>,
|
||||||
|
) {
|
||||||
|
const service = {
|
||||||
|
readRuntime: vi.fn(async () => ({ status: "running", pid: 8000 })),
|
||||||
|
} as unknown as GatewayService;
|
||||||
|
|
||||||
|
inspectPortUsage.mockResolvedValue({
|
||||||
|
port: 18789,
|
||||||
|
status: "busy",
|
||||||
|
listeners: [{ commandLine: "" }],
|
||||||
|
hints: [],
|
||||||
|
});
|
||||||
|
classifyPortListener.mockReturnValue("unknown");
|
||||||
|
probeGateway.mockResolvedValue(probeResult);
|
||||||
|
|
||||||
|
const { inspectGatewayRestart } = await import("./restart-health.js");
|
||||||
|
return inspectGatewayRestart({ service, port: 18789 });
|
||||||
|
}
|
||||||
|
|
||||||
describe("inspectGatewayRestart", () => {
|
describe("inspectGatewayRestart", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
inspectPortUsage.mockReset();
|
inspectPortUsage.mockReset();
|
||||||
@@ -159,25 +179,11 @@ describe("inspectGatewayRestart", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("uses a local gateway probe when ownership is ambiguous", async () => {
|
it("uses a local gateway probe when ownership is ambiguous", async () => {
|
||||||
const service = {
|
const snapshot = await inspectAmbiguousOwnershipWithProbe({
|
||||||
readRuntime: vi.fn(async () => ({ status: "running", pid: 8000 })),
|
|
||||||
} as unknown as GatewayService;
|
|
||||||
|
|
||||||
inspectPortUsage.mockResolvedValue({
|
|
||||||
port: 18789,
|
|
||||||
status: "busy",
|
|
||||||
listeners: [{ commandLine: "" }],
|
|
||||||
hints: [],
|
|
||||||
});
|
|
||||||
classifyPortListener.mockReturnValue("unknown");
|
|
||||||
probeGateway.mockResolvedValue({
|
|
||||||
ok: true,
|
ok: true,
|
||||||
close: null,
|
close: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { inspectGatewayRestart } = await import("./restart-health.js");
|
|
||||||
const snapshot = await inspectGatewayRestart({ service, port: 18789 });
|
|
||||||
|
|
||||||
expect(snapshot.healthy).toBe(true);
|
expect(snapshot.healthy).toBe(true);
|
||||||
expect(probeGateway).toHaveBeenCalledWith(
|
expect(probeGateway).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({ url: "ws://127.0.0.1:18789" }),
|
expect.objectContaining({ url: "ws://127.0.0.1:18789" }),
|
||||||
@@ -185,25 +191,11 @@ describe("inspectGatewayRestart", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("treats auth-closed probe as healthy gateway reachability", async () => {
|
it("treats auth-closed probe as healthy gateway reachability", async () => {
|
||||||
const service = {
|
const snapshot = await inspectAmbiguousOwnershipWithProbe({
|
||||||
readRuntime: vi.fn(async () => ({ status: "running", pid: 8000 })),
|
|
||||||
} as unknown as GatewayService;
|
|
||||||
|
|
||||||
inspectPortUsage.mockResolvedValue({
|
|
||||||
port: 18789,
|
|
||||||
status: "busy",
|
|
||||||
listeners: [{ commandLine: "" }],
|
|
||||||
hints: [],
|
|
||||||
});
|
|
||||||
classifyPortListener.mockReturnValue("unknown");
|
|
||||||
probeGateway.mockResolvedValue({
|
|
||||||
ok: false,
|
ok: false,
|
||||||
close: { code: 1008, reason: "auth required" },
|
close: { code: 1008, reason: "auth required" },
|
||||||
});
|
});
|
||||||
|
|
||||||
const { inspectGatewayRestart } = await import("./restart-health.js");
|
|
||||||
const snapshot = await inspectGatewayRestart({ service, port: 18789 });
|
|
||||||
|
|
||||||
expect(snapshot.healthy).toBe(true);
|
expect(snapshot.healthy).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user