The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; |
| 2 | |
| 3 | import { readPrimaryEnvironmentTarget, resolvePrimaryEnvironmentHttpUrl } from "."; |
| 4 | |
| 5 | function installTestBrowser(url: string) { |
| 6 | vi.stubGlobal("window", { |
| 7 | location: new URL(url), |
| 8 | history: { |
| 9 | replaceState: vi.fn(), |
| 10 | }, |
| 11 | }); |
| 12 | } |
| 13 | |
| 14 | describe("environmentBootstrap", () => { |
| 15 | beforeEach(() => { |
| 16 | vi.restoreAllMocks(); |
| 17 | vi.useRealTimers(); |
| 18 | installTestBrowser("http://localhost/"); |
| 19 | }); |
| 20 | |
| 21 | afterEach(() => { |
| 22 | vi.unstubAllEnvs(); |
| 23 | vi.useRealTimers(); |
| 24 | vi.restoreAllMocks(); |
| 25 | vi.unstubAllGlobals(); |
| 26 | }); |
| 27 | |
| 28 | it("uses https descriptor urls when the primary environment uses wss", () => { |
| 29 | vi.stubEnv("VITE_HTTP_URL", "https://remote.example.com"); |
| 30 | vi.stubEnv("VITE_WS_URL", "wss://remote.example.com"); |
| 31 | |
| 32 | expect(resolvePrimaryEnvironmentHttpUrl("/.well-known/t3/environment")).toBe( |
| 33 | "https://remote.example.com/.well-known/t3/environment", |
| 34 | ); |
| 35 | }); |
| 36 | |
| 37 | it("keeps an uppercase wss scheme secure when deriving the http url", () => { |
| 38 | vi.stubEnv("VITE_WS_URL", "WSS://remote.example.com"); |
| 39 | |
| 40 | expect(readPrimaryEnvironmentTarget()?.target).toEqual({ |
| 41 | httpBaseUrl: "https://remote.example.com/", |
| 42 | wsBaseUrl: "wss://remote.example.com/", |
| 43 | }); |
| 44 | }); |
| 45 | |
| 46 | it("keeps an uppercase https scheme secure when deriving the websocket url", () => { |
| 47 | vi.stubEnv("VITE_HTTP_URL", "HTTPS://remote.example.com"); |
| 48 | |
| 49 | expect(readPrimaryEnvironmentTarget()?.target).toEqual({ |
| 50 | httpBaseUrl: "https://remote.example.com/", |
| 51 | wsBaseUrl: "wss://remote.example.com/", |
| 52 | }); |
| 53 | }); |
| 54 | |
| 55 | it("uses the vite proxy for desktop-managed loopback descriptor requests during local dev", () => { |
| 56 | vi.stubEnv("VITE_DEV_SERVER_URL", "http://127.0.0.1:5733"); |
| 57 | vi.stubGlobal("window", { |
| 58 | location: new URL("http://127.0.0.1:5733/"), |
| 59 | history: { |
| 60 | replaceState: vi.fn(), |
| 61 | }, |
| 62 | desktopBridge: { |
| 63 | getLocalEnvironmentEnabled: () => true, |
| 64 | getLocalEnvironmentBootstraps: () => [ |
| 65 | { |
| 66 | id: "primary", |
| 67 | label: "Windows", |
| 68 | httpBaseUrl: "http://127.0.0.1:3773", |
| 69 | wsBaseUrl: "ws://127.0.0.1:3773", |
| 70 | bootstrapToken: "desktop-bootstrap-token", |
| 71 | }, |
| 72 | ], |
| 73 | }, |
| 74 | }); |
| 75 | |
| 76 | expect(resolvePrimaryEnvironmentHttpUrl("/.well-known/t3/environment")).toBe( |
| 77 | "http://127.0.0.1:5733/.well-known/t3/environment", |
| 78 | ); |
| 79 | }); |
| 80 | }); |