


















@@ -18,6 +18,8 @@ const note = vi.hoisted(() => vi.fn());
1818const sleep = vi.hoisted(() => vi.fn(async () => {}));
1919const healthCommand = vi.hoisted(() => vi.fn(async () => {}));
2020const inspectPortUsage = vi.hoisted(() => vi.fn());
21+const formatPortDiagnostics = vi.hoisted(() => vi.fn(() => ["Port 18789 is already in use."]));
22+const isExpectedGatewayListeners = vi.hoisted(() => vi.fn(() => false));
2123const readLastGatewayErrorLine = vi.hoisted(() => vi.fn(async () => null));
2224const readGatewayRestartHandoffSync = vi.hoisted(() =>
2325vi.fn<() => GatewayRestartHandoff | null>(() => null),
@@ -83,7 +85,8 @@ vi.mock("../daemon/systemd.js", async () => {
83858486vi.mock("../infra/ports.js", () => ({
8587 inspectPortUsage,
86-formatPortDiagnostics: vi.fn(() => []),
88+ formatPortDiagnostics,
89+ isExpectedGatewayListeners,
8790}));
88918992vi.mock("../infra/restart-handoff.js", async () => {
@@ -157,6 +160,7 @@ describe("maybeRepairGatewayDaemon", () => {
157160listeners: [],
158161hints: [],
159162});
163+isExpectedGatewayListeners.mockReturnValue(false);
160164});
161165162166afterEach(() => {
@@ -319,6 +323,41 @@ describe("maybeRepairGatewayDaemon", () => {
319323expect(readGatewayRestartHandoffSync).not.toHaveBeenCalled();
320324});
321325326+it("suppresses busy-port note for expected Gateway listeners", async () => {
327+setPlatform("linux");
328+const listeners = [{ pid: 5001, commandLine: "openclaw-gateway", address: "0.0.0.0:18789" }];
329+inspectPortUsage.mockResolvedValue({
330+port: 18789,
331+status: "busy",
332+ listeners,
333+hints: [],
334+});
335+isExpectedGatewayListeners.mockReturnValue(true);
336+337+await runNonInteractiveRepair();
338+339+expect(isExpectedGatewayListeners).toHaveBeenCalledWith(listeners, 18789);
340+expect(formatPortDiagnostics).not.toHaveBeenCalled();
341+expect(note).not.toHaveBeenCalledWith(expect.any(String), "Gateway port");
342+});
343+344+it("keeps busy-port note for unexpected Gateway listeners", async () => {
345+setPlatform("linux");
346+inspectPortUsage.mockResolvedValue({
347+port: 18789,
348+status: "busy",
349+listeners: [
350+{ pid: 5001, commandLine: "openclaw-gateway", address: "0.0.0.0:18789" },
351+{ pid: 5002, commandLine: "openclaw-gateway", address: "127.0.0.1:18789" },
352+],
353+hints: ["Multiple listeners detected"],
354+});
355+356+await runNonInteractiveRepair();
357+358+expect(note).toHaveBeenCalledWith("Port 18789 is already in use.", "Gateway port");
359+});
360+322361it("skips start verification when a stopped service start is only scheduled", async () => {
323362service.readRuntime.mockResolvedValue({ status: "stopped" });
324363await runScheduledGatewayRepairAndExpectVerificationSkipped("Start gateway service now?");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。