TUI: honor gateway bind mode for local connection URL

This commit is contained in:
Vignesh Natarajan
2026-02-14 17:16:05 -08:00
parent 161222f6fe
commit d171686f77
2 changed files with 44 additions and 9 deletions

View File

@@ -2,6 +2,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const loadConfig = vi.fn();
const resolveGatewayPort = vi.fn();
const pickPrimaryTailnetIPv4 = vi.fn();
const pickPrimaryLanIPv4 = vi.fn();
const originalEnvToken = process.env.OPENCLAW_GATEWAY_TOKEN;
const originalEnvPassword = process.env.OPENCLAW_GATEWAY_PASSWORD;
@@ -15,13 +17,25 @@ vi.mock("../config/config.js", async (importOriginal) => {
};
});
vi.mock("../infra/tailnet.js", () => ({
pickPrimaryTailnetIPv4,
}));
vi.mock("../gateway/net.js", () => ({
pickPrimaryLanIPv4,
}));
const { resolveGatewayConnection } = await import("./gateway-chat.js");
describe("resolveGatewayConnection", () => {
beforeEach(() => {
loadConfig.mockReset();
resolveGatewayPort.mockReset();
pickPrimaryTailnetIPv4.mockReset();
pickPrimaryLanIPv4.mockReset();
resolveGatewayPort.mockReturnValue(18789);
pickPrimaryTailnetIPv4.mockReturnValue(undefined);
pickPrimaryLanIPv4.mockReturnValue(undefined);
delete process.env.OPENCLAW_GATEWAY_TOKEN;
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
});
@@ -77,4 +91,24 @@ describe("resolveGatewayConnection", () => {
password: "explicit-password",
});
});
it("uses tailnet host when local bind is tailnet", () => {
loadConfig.mockReturnValue({ gateway: { mode: "local", bind: "tailnet" } });
resolveGatewayPort.mockReturnValue(18800);
pickPrimaryTailnetIPv4.mockReturnValue("100.64.0.1");
const result = resolveGatewayConnection({});
expect(result.url).toBe("ws://100.64.0.1:18800");
});
it("uses lan host when local bind is lan", () => {
loadConfig.mockReturnValue({ gateway: { mode: "local", bind: "lan" } });
resolveGatewayPort.mockReturnValue(18800);
pickPrimaryLanIPv4.mockReturnValue("192.168.1.42");
const result = resolveGatewayConnection({});
expect(result.url).toBe("ws://192.168.1.42:18800");
});
});