From e07b8698d76b640bb7d67d8011fc4d3e39a8a929 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Mon, 23 Feb 2026 13:41:26 -0500 Subject: [PATCH] CLI: fix restart-health type checks in tests --- src/cli/daemon-cli/restart-health.test.ts | 17 +++++++++++++---- src/cli/daemon-cli/restart-health.ts | 11 +++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cli/daemon-cli/restart-health.test.ts b/src/cli/daemon-cli/restart-health.test.ts index c438e9a0ea8..2dfb5cf5967 100644 --- a/src/cli/daemon-cli/restart-health.test.ts +++ b/src/cli/daemon-cli/restart-health.test.ts @@ -1,18 +1,27 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import type { GatewayService } from "../../daemon/service.js"; +import type { PortListenerKind, PortUsage } from "../../infra/ports.js"; -const inspectPortUsage = vi.hoisted(() => vi.fn()); -const classifyPortListener = vi.hoisted(() => vi.fn(() => "gateway")); +const inspectPortUsage = vi.hoisted(() => vi.fn<(port: number) => Promise>()); +const classifyPortListener = vi.hoisted(() => + vi.fn<(_listener: unknown, _port: number) => PortListenerKind>(() => "gateway"), +); vi.mock("../../infra/ports.js", () => ({ - classifyPortListener: (...args: unknown[]) => classifyPortListener(...args), + classifyPortListener: (listener: unknown, port: number) => classifyPortListener(listener, port), formatPortDiagnostics: vi.fn(() => []), - inspectPortUsage: (...args: unknown[]) => inspectPortUsage(...args), + inspectPortUsage: (port: number) => inspectPortUsage(port), })); describe("inspectGatewayRestart", () => { beforeEach(() => { inspectPortUsage.mockReset(); + inspectPortUsage.mockResolvedValue({ + port: 0, + status: "free", + listeners: [], + hints: [], + }); classifyPortListener.mockReset(); classifyPortListener.mockReturnValue("gateway"); }); diff --git a/src/cli/daemon-cli/restart-health.ts b/src/cli/daemon-cli/restart-health.ts index 575fdee7ec9..3eb46c54210 100644 --- a/src/cli/daemon-cli/restart-health.ts +++ b/src/cli/daemon-cli/restart-health.ts @@ -61,11 +61,10 @@ export async function inspectGatewayRestart(params: { ) : []; const running = runtime.status === "running"; + const runtimePid = runtime.pid; const ownsPort = - runtime.pid != null - ? portUsage.listeners.some((listener) => - listenerOwnedByRuntimePid({ listener, runtimePid: runtime.pid }), - ) + runtimePid != null + ? portUsage.listeners.some((listener) => listenerOwnedByRuntimePid({ listener, runtimePid })) : gatewayListeners.length > 0 || (portUsage.status === "busy" && portUsage.listeners.length === 0); const healthy = running && ownsPort; @@ -77,10 +76,10 @@ export async function inspectGatewayRestart(params: { if (!running) { return true; } - if (runtime.pid == null) { + if (runtimePid == null) { return true; } - return !listenerOwnedByRuntimePid({ listener, runtimePid: runtime.pid }); + return !listenerOwnedByRuntimePid({ listener, runtimePid }); }) .map((listener) => listener.pid as number), ),