test: expand gateway auth probe coverage

This commit is contained in:
Peter Steinberger
2026-01-16 19:16:03 +00:00
parent c8003ae472
commit 624ff09314
2 changed files with 246 additions and 1 deletions

View File

@@ -91,6 +91,18 @@ describe("callGateway url resolution", () => {
expect(lastClientOptions?.url).toBe("ws://127.0.0.1:18800");
});
it("uses url override in remote mode even when remote url is missing", async () => {
loadConfig.mockReturnValue({
gateway: { mode: "remote", bind: "loopback", remote: {} },
});
resolveGatewayPort.mockReturnValue(18789);
pickPrimaryTailnetIPv4.mockReturnValue(undefined);
await callGateway({ method: "health", url: "wss://override.example/ws" });
expect(lastClientOptions?.url).toBe("wss://override.example/ws");
});
});
describe("buildGatewayConnectionDetails", () => {
@@ -313,3 +325,43 @@ describe("callGateway password resolution", () => {
expect(lastClientOptions?.password).toBe("from-env");
});
});
describe("callGateway token resolution", () => {
const originalEnvToken = process.env.CLAWDBOT_GATEWAY_TOKEN;
beforeEach(() => {
loadConfig.mockReset();
resolveGatewayPort.mockReset();
pickPrimaryTailnetIPv4.mockReset();
lastClientOptions = null;
startMode = "hello";
closeCode = 1006;
closeReason = "";
delete process.env.CLAWDBOT_GATEWAY_TOKEN;
resolveGatewayPort.mockReturnValue(18789);
pickPrimaryTailnetIPv4.mockReturnValue(undefined);
});
afterEach(() => {
if (originalEnvToken == null) {
delete process.env.CLAWDBOT_GATEWAY_TOKEN;
} else {
process.env.CLAWDBOT_GATEWAY_TOKEN = originalEnvToken;
}
});
it("uses remote token when remote mode uses url override", async () => {
process.env.CLAWDBOT_GATEWAY_TOKEN = "env-token";
loadConfig.mockReturnValue({
gateway: {
mode: "remote",
remote: { token: "remote-token" },
auth: { token: "local-token" },
},
});
await callGateway({ method: "health", url: "wss://override.example/ws" });
expect(lastClientOptions?.token).toBe("remote-token");
});
});