From 3f2f007c9af16da6027915d0b1872821ea8119bc Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 8 Mar 2026 19:41:40 +0000 Subject: [PATCH] refactor: extract gateway port diagnostics helper --- src/cli/daemon-cli/restart-health.ts | 40 +++++++++++++--------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/cli/daemon-cli/restart-health.ts b/src/cli/daemon-cli/restart-health.ts index 00b6b4e98b3..13741d2e9c4 100644 --- a/src/cli/daemon-cli/restart-health.ts +++ b/src/cli/daemon-cli/restart-health.ts @@ -242,6 +242,22 @@ export async function waitForGatewayHealthyListener(params: { return snapshot; } +function renderPortUsageDiagnostics(snapshot: GatewayPortHealthSnapshot): string[] { + const lines: string[] = []; + + if (snapshot.portUsage.status === "busy") { + lines.push(...formatPortDiagnostics(snapshot.portUsage)); + } else { + lines.push(`Gateway port ${snapshot.portUsage.port} status: ${snapshot.portUsage.status}.`); + } + + if (snapshot.portUsage.errors?.length) { + lines.push(`Port diagnostics errors: ${snapshot.portUsage.errors.join("; ")}`); + } + + return lines; +} + export function renderRestartDiagnostics(snapshot: GatewayRestartSnapshot): string[] { const lines: string[] = []; const runtimeSummary = [ @@ -257,33 +273,13 @@ export function renderRestartDiagnostics(snapshot: GatewayRestartSnapshot): stri lines.push(`Service runtime: ${runtimeSummary}`); } - if (snapshot.portUsage.status === "busy") { - lines.push(...formatPortDiagnostics(snapshot.portUsage)); - } else { - lines.push(`Gateway port ${snapshot.portUsage.port} status: ${snapshot.portUsage.status}.`); - } - - if (snapshot.portUsage.errors?.length) { - lines.push(`Port diagnostics errors: ${snapshot.portUsage.errors.join("; ")}`); - } + lines.push(...renderPortUsageDiagnostics(snapshot)); return lines; } export function renderGatewayPortHealthDiagnostics(snapshot: GatewayPortHealthSnapshot): string[] { - const lines: string[] = []; - - if (snapshot.portUsage.status === "busy") { - lines.push(...formatPortDiagnostics(snapshot.portUsage)); - } else { - lines.push(`Gateway port ${snapshot.portUsage.port} status: ${snapshot.portUsage.status}.`); - } - - if (snapshot.portUsage.errors?.length) { - lines.push(`Port diagnostics errors: ${snapshot.portUsage.errors.join("; ")}`); - } - - return lines; + return renderPortUsageDiagnostics(snapshot); } export async function terminateStaleGatewayPids(pids: number[]): Promise {