fix: improve gateway diagnostics

This commit is contained in:
Peter Steinberger
2026-01-08 02:28:21 +01:00
parent 02ad9eccad
commit 61f5ed8bb7
21 changed files with 1037 additions and 63 deletions

View File

@@ -2,7 +2,10 @@ import net from "node:net";
import { describe, expect, it, vi } from "vitest";
import {
buildPortHints,
classifyPortListener,
ensurePortAvailable,
formatPortDiagnostics,
handlePortError,
PortInUseError,
} from "./ports.js";
@@ -33,4 +36,36 @@ describe("ports helpers", () => {
expect(runtime.error).toHaveBeenCalled();
expect(runtime.exit).toHaveBeenCalledWith(1);
});
it("classifies ssh and gateway listeners", () => {
expect(
classifyPortListener(
{ commandLine: "ssh -N -L 18789:127.0.0.1:18789 user@host" },
18789,
),
).toBe("ssh");
expect(
classifyPortListener(
{
commandLine: "node /Users/me/Projects/clawdbot/dist/entry.js gateway",
},
18789,
),
).toBe("gateway");
});
it("formats port diagnostics with hints", () => {
const diagnostics = {
port: 18789,
status: "busy" as const,
listeners: [{ pid: 123, commandLine: "ssh -N -L 18789:127.0.0.1:18789" }],
hints: buildPortHints(
[{ pid: 123, commandLine: "ssh -N -L 18789:127.0.0.1:18789" }],
18789,
),
};
const lines = formatPortDiagnostics(diagnostics);
expect(lines[0]).toContain("Port 18789 is already in use");
expect(lines.some((line) => line.includes("SSH tunnel"))).toBe(true);
});
});