| author | |
| committer | |
| log | bf1c1b09756a56a0600faf52561f0fb4ae94e355 |
| tree | 2c218fedcbc60d5bd3e2467166e3e9e5cdc400ab |
| parent | c7e93f520bbd1ba4b795a5fb1aad14778aa1d047 |
| signature | Signed by PGP key B5690EEEBB952194 |
2 files changed, 0 insertions(+), 101 deletions(-)
apps/web/src/cloud/linkEnvironment.test.ts-45| ... | @@ -26,10 +26,7 @@ import { remoteHttpClientLayer } from "@t3tools/client-runtime/rpc"; | ... | @@ -26,10 +26,7 @@ import { remoteHttpClientLayer } from "@t3tools/client-runtime/rpc"; |
| 26 | import { __resetDesktopPrimaryAuthForTests } from "../environments/primary/desktopAuth"; | 26 | import { __resetDesktopPrimaryAuthForTests } from "../environments/primary/desktopAuth"; |
| 27 | 27 | ||
| 28 | import { | 28 | import { |
| 29 | collectCloudLinkTargets, | ||
| 30 | linkPrimaryEnvironmentToCloud, | 29 | linkPrimaryEnvironmentToCloud, |
| 31 | listManagedCloudEnvironments, | ||
| 32 | normalizeRelayBaseUrl, | ||
| 33 | readPrimaryCloudLinkState, | 30 | readPrimaryCloudLinkState, |
| 34 | type CloudLinkTarget, | 31 | type CloudLinkTarget, |
| 35 | unlinkPrimaryEnvironmentFromCloud, | 32 | unlinkPrimaryEnvironmentFromCloud, |
| ... | @@ -155,48 +152,6 @@ afterEach(() => { | ... | @@ -155,48 +152,6 @@ afterEach(() => { |
| 155 | }); | 152 | }); |
| 156 | 153 | ||
| 157 | describe("web cloud link environment client", () => { | 154 | describe("web cloud link environment client", () => { |
| 158 | it("normalizes relay URLs and de-duplicates cloud link targets", () => { | ||
| 159 | expect(normalizeRelayBaseUrl(" https://relay.example.test/// ")).toBe( | ||
| 160 | "https://relay.example.test", | ||
| 161 | ); | ||
| 162 | expect(normalizeRelayBaseUrl(" ")).toBeNull(); | ||
| 163 | expect( | ||
| 164 | collectCloudLinkTargets({ | ||
| 165 | primary: TARGET, | ||
| 166 | saved: [TARGET, { ...TARGET, environmentId: "environment-2" }], | ||
| 167 | }).map((target) => target.environmentId), | ||
| 168 | ).toEqual(["environment-1", "environment-2"]); | ||
| 169 | }); | ||
| 170 | |||
| 171 | it.effect("lists relay-managed environments through the typed relay client", () => | ||
| 172 | Effect.gen(function* () { | ||
| 173 | const fetchMock = vi.fn().mockResolvedValue( | ||
| 174 | Response.json({ | ||
| 175 | environments: [ | ||
| 176 | { | ||
| 177 | environmentId: "environment-1", | ||
| 178 | label: "Desktop", | ||
| 179 | endpoint: { | ||
| 180 | httpBaseUrl: "https://desktop.example.test", | ||
| 181 | wsBaseUrl: "wss://desktop.example.test", | ||
| 182 | providerKind: "cloudflare_tunnel", | ||
| 183 | }, | ||
| 184 | linkedAt: "2026-06-06T00:00:00.000Z", | ||
| 185 | }, | ||
| 186 | ], | ||
| 187 | }), | ||
| 188 | ); | ||
| 189 | vi.stubGlobal("fetch", fetchMock); | ||
| 190 | |||
| 191 | const environments = yield* withServices( | ||
| 192 | listManagedCloudEnvironments({ clerkToken: "clerk-token" }), | ||
| 193 | ); | ||
| 194 | |||
| 195 | expect(environments).toHaveLength(1); | ||
| 196 | expect(fetchMock.mock.calls[0]?.[1]?.headers.authorization).toBe("Bearer clerk-token"); | ||
| 197 | }), | ||
| 198 | ); | ||
| 199 | |||
| 200 | it.effect("reads primary cloud link state from the explicit target", () => | 155 | it.effect("reads primary cloud link state from the explicit target", () => |
| 201 | Effect.gen(function* () { | 156 | Effect.gen(function* () { |
| 202 | const fetchMock = vi.fn().mockResolvedValue( | 157 | const fetchMock = vi.fn().mockResolvedValue( |
apps/web/src/cloud/linkEnvironment.ts-56| ... | @@ -16,7 +16,6 @@ import { | ... | @@ -16,7 +16,6 @@ import { |
| 16 | WS_METHODS, | 16 | WS_METHODS, |
| 17 | } from "@t3tools/contracts"; | 17 | } from "@t3tools/contracts"; |
| 18 | import { | 18 | import { |
| 19 | type RelayClientEnvironmentRecord, | ||
| 20 | type RelayEnvironmentLinkResponse, | 19 | type RelayEnvironmentLinkResponse, |
| 21 | type RelayManagedEndpointProviderKind, | 20 | type RelayManagedEndpointProviderKind, |
| 22 | } from "@t3tools/contracts/relay"; | 21 | } from "@t3tools/contracts/relay"; |
| ... | @@ -33,14 +32,6 @@ import { | ... | @@ -33,14 +32,6 @@ import { |
| 33 | requestRelayClientInstallConfirmation, | 32 | requestRelayClientInstallConfirmation, |
| 34 | } from "./relayClientInstallDialog"; | 33 | } from "./relayClientInstallDialog"; |
| 35 | 34 | ||
| 36 | export function normalizeRelayBaseUrl(value: string | null | undefined): string | null { | ||
| 37 | const trimmed = value?.trim(); | ||
| 38 | if (!trimmed) { | ||
| 39 | return null; | ||
| 40 | } | ||
| 41 | return trimmed.replace(/\/+$/g, ""); | ||
| 42 | } | ||
| 43 | |||
| 44 | function relayUrl(): string | null { | 35 | function relayUrl(): string | null { |
| 45 | return resolveCloudPublicConfig().relayUrl; | 36 | return resolveCloudPublicConfig().relayUrl; |
| 46 | } | 37 | } |
| ... | @@ -194,53 +185,6 @@ export interface CloudLinkTarget { | ... | @@ -194,53 +185,6 @@ export interface CloudLinkTarget { |
| 194 | 185 | ||
| 195 | export type CloudLinkState = EnvironmentCloudLinkStateResult; | 186 | export type CloudLinkState = EnvironmentCloudLinkStateResult; |
| 196 | 187 | ||
| 197 | export function collectCloudLinkTargets(input: { | ||
| 198 | readonly primary: CloudLinkTarget | null; | ||
| 199 | readonly saved: ReadonlyArray<CloudLinkTarget>; | ||
| 200 | }): ReadonlyArray<CloudLinkTarget> { | ||
| 201 | const byId = new Map<string, CloudLinkTarget>(); | ||
| 202 | if (input.primary) { | ||
| 203 | byId.set(input.primary.environmentId, input.primary); | ||
| 204 | } | ||
| 205 | for (const environment of input.saved) { | ||
| 206 | if (!byId.has(environment.environmentId)) { | ||
| 207 | byId.set(environment.environmentId, environment); | ||
| 208 | } | ||
| 209 | } | ||
| 210 | return [...byId.values()]; | ||
| 211 | } | ||
| 212 | |||
| 213 | export function listManagedCloudEnvironments(input: { | ||
| 214 | readonly clerkToken: string; | ||
| 215 | }): Effect.Effect< | ||
| 216 | ReadonlyArray<RelayClientEnvironmentRecord>, | ||
| 217 | CloudEnvironmentLinkError, | ||
| 218 | ManagedRelay.ManagedRelayClient | ||
| 219 | > { | ||
| 220 | return Effect.gen(function* () { | ||
| 221 | const configuredRelayUrl = relayUrl(); | ||
| 222 | if (!configuredRelayUrl) { | ||
| 223 | return yield* new CloudEnvironmentLinkError({ | ||
| 224 | message: "T3CODE_RELAY_URL is not configured.", | ||
| 225 | }); | ||
| 226 | } | ||
| 227 | const relayClient = yield* ManagedRelay.ManagedRelayClient; | ||
| 228 | return yield* relayClient | ||
| 229 | .listEnvironments({ | ||
| 230 | clerkToken: input.clerkToken, | ||
| 231 | }) | ||
| 232 | .pipe( | ||
| 233 | Effect.mapError( | ||
| 234 | (cause) => | ||
| 235 | new CloudEnvironmentLinkError({ | ||
| 236 | message: "Could not list relay-managed environments.", | ||
| 237 | cause, | ||
| 238 | }), | ||
| 239 | ), | ||
| 240 | ); | ||
| 241 | }); | ||
| 242 | } | ||
| 243 | |||
| 244 | export function readPrimaryCloudLinkState(input: { | 188 | export function readPrimaryCloudLinkState(input: { |
| 245 | readonly target: CloudLinkTarget; | 189 | readonly target: CloudLinkTarget; |
| 246 | }): Effect.Effect<CloudLinkState | null, CloudEnvironmentLinkError, HttpClient.HttpClient> { | 190 | }): Effect.Effect<CloudLinkState | null, CloudEnvironmentLinkError, HttpClient.HttpClient> { |