let inspectPortUsage: typeofimport("./ports-inspect.js").inspectPortUsage;
let ensurePortAvailable: typeofimport("./ports.js").ensurePortAvailable;
let handlePortError: typeofimport("./ports.js").handlePortError;
let PortInUseError: typeofimport("./ports.js").PortInUseError;
describe("ports helpers", () => {
it("ensurePortAvailable rejects when port busy", async () => { const server = net.createServer(); const address = await listenServer(server, 0); if (!address) { return;
} const port = address.port;
await expect(ensurePortAvailable(port)).rejects.toBeInstanceOf(PortInUseError);
await new Promise<void>((resolve) => server.close(() => resolve()));
});
it("handlePortError exits nicely on EADDRINUSE", async () => { const runtime = {
error: vi.fn(),
log: vi.fn(),
exit: vi.fn() as unknown as (code: number) => never,
}; // Avoid slow OS port inspection; this test only cares about messaging + exit behavior.
await handlePortError(new PortInUseError(1234, "details"), 1234, "context", runtime).catch(
() => {},
); const messages = runtime.error.mock.calls.map((call) => stripAnsi(String(call[0] ?? "")));
expect(messages.join("\n")).toContain("context failed: port 1234 is already in use.");
expect(messages.join("\n")).toContain("Resolve by stopping the process");
expect(runtime.exit).toHaveBeenCalledWith(1);
});
it("prints an OpenClaw-specific hint when port details look like another OpenClaw instance", async () => { const runtime = {
error: vi.fn(),
log: vi.fn(),
exit: vi.fn() as unknown as (code: number) => never,
};
it("falls back to ss when lsof is unavailable", async () => { const server = net.createServer(); const address = await listenServer(server, 0, "127.0.0.1"); if (!address) { return;
} const port = address.port;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.