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 { BearerConnectionTarget } from "@t3tools/client-runtime/connection"; |
| 2 | import type { Discovery } from "@t3tools/client-runtime/relay"; |
| 3 | import { EnvironmentId } from "@t3tools/contracts"; |
| 4 | import * as Option from "effect/Option"; |
| 5 | import { describe, expect, it, vi } from "vite-plus/test"; |
| 6 | |
| 7 | import { render } from "../../../test/render"; |
| 8 | |
| 9 | const testState = vi.hoisted(() => ({ |
| 10 | discovered: [] as Array<Discovery.RelayDiscoveredEnvironment>, |
| 11 | })); |
| 12 | |
| 13 | vi.mock(import("~/state/environments"), async (original) => ({ |
| 14 | ...(await original()), |
| 15 | useRelayEnvironmentDiscovery: (() => ({ |
| 16 | environments: new Map( |
| 17 | testState.discovered.map((environment) => [ |
| 18 | environment.environment.environmentId, |
| 19 | environment, |
| 20 | ]), |
| 21 | ), |
| 22 | refreshing: false, |
| 23 | offline: false, |
| 24 | error: Option.none(), |
| 25 | })) as never, |
| 26 | })); |
| 27 | vi.mock(import("~/state/use-atom-command"), async (original) => ({ |
| 28 | ...(await original()), |
| 29 | useAtomCommand: (() => () => Promise.resolve({ _tag: "Success" })) as never, |
| 30 | })); |
| 31 | |
| 32 | import { CloudEnvironmentConnectRows } from "./CloudEnvironmentConnectList"; |
| 33 | |
| 34 | function discovered( |
| 35 | environmentId: EnvironmentId, |
| 36 | label: string, |
| 37 | ): Discovery.RelayDiscoveredEnvironment { |
| 38 | return { |
| 39 | environment: { |
| 40 | environmentId, |
| 41 | label, |
| 42 | endpoint: { |
| 43 | httpBaseUrl: `https://${environmentId}.relay.test`, |
| 44 | wsBaseUrl: `wss://${environmentId}.relay.test`, |
| 45 | providerKind: "t3_relay", |
| 46 | }, |
| 47 | linkedAt: "2026-10-01T00:00:00.000Z", |
| 48 | }, |
| 49 | availability: "online", |
| 50 | status: Option.none(), |
| 51 | error: Option.none(), |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | function saved(environmentId: EnvironmentId, label: string, connectionId: string) { |
| 56 | return { |
| 57 | environmentId, |
| 58 | entry: { target: new BearerConnectionTarget({ environmentId, label, connectionId }) }, |
| 59 | connection: { phase: "connected", error: null, traceId: null }, |
| 60 | relayManaged: false, |
| 61 | serverConfig: null, |
| 62 | } as const; |
| 63 | } |
| 64 | |
| 65 | const primaryEnvironmentId = EnvironmentId.make("primary"); |
| 66 | const wslEnvironmentId = EnvironmentId.make("wsl-ubuntu"); |
| 67 | const laptopEnvironmentId = EnvironmentId.make("laptop"); |
| 68 | |
| 69 | function setup(discoveredEnvironments: Array<Discovery.RelayDiscoveredEnvironment>) { |
| 70 | testState.discovered = discoveredEnvironments; |
| 71 | } |
| 72 | |
| 73 | describe("CloudEnvironmentConnectRows", () => { |
| 74 | it("does not offer a T3 Connect route for the desktop's own WSL backend", async () => { |
| 75 | setup([ |
| 76 | discovered(primaryEnvironmentId, "This PC"), |
| 77 | discovered(wslEnvironmentId, "Ubuntu (WSL)"), |
| 78 | discovered(laptopEnvironmentId, "Laptop"), |
| 79 | ]); |
| 80 | await using screen = await render( |
| 81 | <CloudEnvironmentConnectRows |
| 82 | primaryEnvironmentId={primaryEnvironmentId} |
| 83 | savedEnvironments={[ |
| 84 | saved(wslEnvironmentId, "Ubuntu (WSL)", "local:wsl:Ubuntu"), |
| 85 | saved(laptopEnvironmentId, "Laptop", "lan-laptop"), |
| 86 | ]} |
| 87 | />, |
| 88 | ); |
| 89 | |
| 90 | await expect.element(screen.getByText("Laptop")).toBeInTheDocument(); |
| 91 | await expect.element(screen.getByText("Ubuntu (WSL)")).not.toBeInTheDocument(); |
| 92 | await expect.element(screen.getByRole("button", { name: "Add route" })).toBeInTheDocument(); |
| 93 | }); |
| 94 | |
| 95 | it("shows the empty state when the desktop's own WSL backend is the only saved environment", async () => { |
| 96 | setup([ |
| 97 | discovered(primaryEnvironmentId, "This PC"), |
| 98 | discovered(wslEnvironmentId, "Ubuntu (WSL)"), |
| 99 | ]); |
| 100 | await using screen = await render( |
| 101 | <CloudEnvironmentConnectRows |
| 102 | primaryEnvironmentId={primaryEnvironmentId} |
| 103 | savedEnvironments={[saved(wslEnvironmentId, "Ubuntu (WSL)", "local:wsl:Ubuntu")]} |
| 104 | empty={<p>No environments</p>} |
| 105 | />, |
| 106 | ); |
| 107 | |
| 108 | await expect.element(screen.getByText("No environments")).toBeInTheDocument(); |
| 109 | }); |
| 110 | }); |