Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions apps/web/src/cloud/linkEnvironment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ import { remoteHttpClientLayer } from "@t3tools/client-runtime/rpc";
import { __resetDesktopPrimaryAuthForTests } from "../environments/primary/desktopAuth";

import {
collectCloudLinkTargets,
linkPrimaryEnvironmentToCloud,
listManagedCloudEnvironments,
normalizeRelayBaseUrl,
readPrimaryCloudLinkState,
type CloudLinkTarget,
unlinkPrimaryEnvironmentFromCloud,
Expand Down Expand Up @@ -155,48 +152,6 @@ afterEach(() => {
});

describe("web cloud link environment client", () => {
it("normalizes relay URLs and de-duplicates cloud link targets", () => {
expect(normalizeRelayBaseUrl(" https://relay.example.test/// ")).toBe(
"https://relay.example.test",
);
expect(normalizeRelayBaseUrl(" ")).toBeNull();
expect(
collectCloudLinkTargets({
primary: TARGET,
saved: [TARGET, { ...TARGET, environmentId: "environment-2" }],
}).map((target) => target.environmentId),
).toEqual(["environment-1", "environment-2"]);
});

it.effect("lists relay-managed environments through the typed relay client", () =>
Effect.gen(function* () {
const fetchMock = vi.fn().mockResolvedValue(
Response.json({
environments: [
{
environmentId: "environment-1",
label: "Desktop",
endpoint: {
httpBaseUrl: "https://desktop.example.test",
wsBaseUrl: "wss://desktop.example.test",
providerKind: "cloudflare_tunnel",
},
linkedAt: "2026-06-06T00:00:00.000Z",
},
],
}),
);
vi.stubGlobal("fetch", fetchMock);

const environments = yield* withServices(
listManagedCloudEnvironments({ clerkToken: "clerk-token" }),
);

expect(environments).toHaveLength(1);
expect(fetchMock.mock.calls[0]?.[1]?.headers.authorization).toBe("Bearer clerk-token");
}),
);

it.effect("reads primary cloud link state from the explicit target", () =>
Effect.gen(function* () {
const fetchMock = vi.fn().mockResolvedValue(
Expand Down
56 changes: 0 additions & 56 deletions apps/web/src/cloud/linkEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
WS_METHODS,
} from "@t3tools/contracts";
import {
type RelayClientEnvironmentRecord,
type RelayEnvironmentLinkResponse,
type RelayManagedEndpointProviderKind,
} from "@t3tools/contracts/relay";
Expand All @@ -33,14 +32,6 @@ import {
requestRelayClientInstallConfirmation,
} from "./relayClientInstallDialog";

export function normalizeRelayBaseUrl(value: string | null | undefined): string | null {
const trimmed = value?.trim();
if (!trimmed) {
return null;
}
return trimmed.replace(/\/+$/g, "");
}

function relayUrl(): string | null {
return resolveCloudPublicConfig().relayUrl;
}
Expand Down Expand Up @@ -194,53 +185,6 @@ export interface CloudLinkTarget {

export type CloudLinkState = EnvironmentCloudLinkStateResult;

export function collectCloudLinkTargets(input: {
readonly primary: CloudLinkTarget | null;
readonly saved: ReadonlyArray<CloudLinkTarget>;
}): ReadonlyArray<CloudLinkTarget> {
const byId = new Map<string, CloudLinkTarget>();
if (input.primary) {
byId.set(input.primary.environmentId, input.primary);
}
for (const environment of input.saved) {
if (!byId.has(environment.environmentId)) {
byId.set(environment.environmentId, environment);
}
}
return [...byId.values()];
}

export function listManagedCloudEnvironments(input: {
readonly clerkToken: string;
}): Effect.Effect<
ReadonlyArray<RelayClientEnvironmentRecord>,
CloudEnvironmentLinkError,
ManagedRelay.ManagedRelayClient
> {
return Effect.gen(function* () {
const configuredRelayUrl = relayUrl();
if (!configuredRelayUrl) {
return yield* new CloudEnvironmentLinkError({
message: "T3CODE_RELAY_URL is not configured.",
});
}
const relayClient = yield* ManagedRelay.ManagedRelayClient;
return yield* relayClient
.listEnvironments({
clerkToken: input.clerkToken,
})
.pipe(
Effect.mapError(
(cause) =>
new CloudEnvironmentLinkError({
message: "Could not list relay-managed environments.",
cause,
}),
),
);
});
}

export function readPrimaryCloudLinkState(input: {
readonly target: CloudLinkTarget;
}): Effect.Effect<CloudLinkState | null, CloudEnvironmentLinkError, HttpClient.HttpClient> {
Expand Down
Loading