feat(cloud): add relay client install dialog
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
95dc1a525b
commit
c5a1419fa7
7 files changed
+337
-12
No files matched your search
@@ -29,7 +29,11 @@ import {
|
||||
} from "../environments/primary";
|
||||
|
||||
const getSavedEnvironmentSecretMock = vi.fn();
|
||||
const confirmRelayClientInstallMock = vi.fn();
|
||||
const relayClientInstallDialogHarness = vi.hoisted(() => ({
|
||||
requestConfirmation: vi.fn(),
|
||||
reportProgress: vi.fn(),
|
||||
finish: vi.fn(),
|
||||
}));
|
||||
const getRelayClientStatusMock = vi.fn();
|
||||
const installRelayClientMock = vi.fn();
|
||||
const environmentConnectionMock = {
|
||||
@@ -70,15 +74,18 @@ const withCloudServices = <A, E>(
|
||||
|
||||
vi.mock("../localApi", () => ({
|
||||
ensureLocalApi: () => ({
|
||||
dialogs: {
|
||||
confirm: confirmRelayClientInstallMock,
|
||||
},
|
||||
persistence: {
|
||||
getSavedEnvironmentSecret: getSavedEnvironmentSecretMock,
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("./relayClientInstallDialog", () => ({
|
||||
requestRelayClientInstallConfirmation: relayClientInstallDialogHarness.requestConfirmation,
|
||||
reportRelayClientInstallProgress: relayClientInstallDialogHarness.reportProgress,
|
||||
finishRelayClientInstall: relayClientInstallDialogHarness.finish,
|
||||
}));
|
||||
|
||||
vi.mock("../environments/primary", () => ({
|
||||
readPrimaryEnvironmentDescriptor: vi.fn(() => null),
|
||||
readPrimaryEnvironmentTarget: vi.fn(() => null),
|
||||
@@ -137,7 +144,7 @@ describe("web cloud link environment client", () => {
|
||||
createProofMock.mockClear();
|
||||
vi.stubEnv("VITE_T3CODE_RELAY_URL", "https://relay.example.test");
|
||||
getSavedEnvironmentSecretMock.mockResolvedValue("local-bearer");
|
||||
confirmRelayClientInstallMock.mockResolvedValue(true);
|
||||
relayClientInstallDialogHarness.requestConfirmation.mockResolvedValue(true);
|
||||
getRelayClientStatusMock.mockResolvedValue(availableRelayClient());
|
||||
installRelayClientMock.mockResolvedValue(availableRelayClient());
|
||||
vi.mocked(readPrimaryEnvironmentDescriptor).mockReturnValue(null);
|
||||
@@ -181,6 +188,10 @@ describe("web cloud link environment client", () => {
|
||||
.mockResolvedValueOnce(Response.json(validChallenge()))
|
||||
.mockResolvedValueOnce(Response.json({ malformed: true }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
installRelayClientMock.mockImplementationOnce(async (onProgress) => {
|
||||
onProgress({ type: "progress", stage: "downloading" });
|
||||
return availableRelayClient();
|
||||
});
|
||||
|
||||
yield* withCloudServices(
|
||||
linkPrimaryEnvironmentToCloud({
|
||||
@@ -188,9 +199,16 @@ describe("web cloud link environment client", () => {
|
||||
}),
|
||||
).pipe(Effect.flip);
|
||||
|
||||
expect(confirmRelayClientInstallMock).toHaveBeenCalledOnce();
|
||||
expect(relayClientInstallDialogHarness.requestConfirmation).toHaveBeenCalledWith(
|
||||
"2026.5.2",
|
||||
);
|
||||
expect(getRelayClientStatusMock).toHaveBeenCalledOnce();
|
||||
expect(installRelayClientMock).toHaveBeenCalledOnce();
|
||||
expect(relayClientInstallDialogHarness.reportProgress).toHaveBeenCalledWith({
|
||||
type: "progress",
|
||||
stage: "downloading",
|
||||
});
|
||||
expect(relayClientInstallDialogHarness.finish).toHaveBeenCalledOnce();
|
||||
expect(installRelayClientMock.mock.invocationCallOrder[0]).toBeLessThan(
|
||||
fetchMock.mock.invocationCallOrder[0]!,
|
||||
);
|
||||
|
||||
@@ -43,6 +43,11 @@ import {
|
||||
} from "../environments/primary";
|
||||
import { withPrimaryEnvironmentRequestInit } from "../environments/primary/requestInit";
|
||||
import { resolveCloudPublicConfig } from "./publicConfig";
|
||||
import {
|
||||
finishRelayClientInstall,
|
||||
reportRelayClientInstallProgress,
|
||||
requestRelayClientInstallConfirmation,
|
||||
} from "./relayClientInstallDialog";
|
||||
|
||||
export function normalizeRelayBaseUrl(value: string | null | undefined): string | null {
|
||||
const trimmed = value?.trim();
|
||||
@@ -67,9 +72,6 @@ const relayClientRpcError = (message: string) => (cause: unknown) =>
|
||||
cause,
|
||||
});
|
||||
|
||||
const RELAY_CLIENT_INSTALL_PROMPT =
|
||||
"T3 Code needs the relay client to make this environment available through T3 Cloud. Download and install it now?";
|
||||
|
||||
function ensureRelayClientAvailable(
|
||||
client: WsRpcClient,
|
||||
): Effect.Effect<void, CloudEnvironmentLinkError> {
|
||||
@@ -86,7 +88,7 @@ function ensureRelayClientAvailable(
|
||||
}
|
||||
|
||||
const confirmed = yield* Effect.tryPromise({
|
||||
try: () => ensureLocalApi().dialogs.confirm(RELAY_CLIENT_INSTALL_PROMPT),
|
||||
try: () => requestRelayClientInstallConfirmation(status.version),
|
||||
catch: relayClientRpcError("Could not confirm relay client installation."),
|
||||
});
|
||||
if (!confirmed) {
|
||||
@@ -96,9 +98,9 @@ function ensureRelayClientAvailable(
|
||||
}
|
||||
|
||||
const installed = yield* Effect.tryPromise({
|
||||
try: () => client.cloud.installRelayClient(),
|
||||
try: () => client.cloud.installRelayClient(reportRelayClientInstallProgress),
|
||||
catch: relayClientRpcError("Could not install the relay client."),
|
||||
});
|
||||
}).pipe(Effect.ensuring(Effect.sync(finishRelayClientInstall)));
|
||||
if (installed.status !== "available") {
|
||||
return yield* new CloudEnvironmentLinkError({
|
||||
message:
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
finishRelayClientInstall,
|
||||
readRelayClientInstallDialogState,
|
||||
reportRelayClientInstallProgress,
|
||||
requestRelayClientInstallConfirmation,
|
||||
resetRelayClientInstallDialogForTests,
|
||||
respondToRelayClientInstallConfirmation,
|
||||
} from "./relayClientInstallDialog";
|
||||
|
||||
describe("relay client install dialog coordinator", () => {
|
||||
beforeEach(() => {
|
||||
resetRelayClientInstallDialogForTests();
|
||||
});
|
||||
|
||||
it("moves a confirmed installation through streamed progress stages", async () => {
|
||||
const confirmation = requestRelayClientInstallConfirmation("2026.5.2");
|
||||
expect(readRelayClientInstallDialogState()).toEqual({
|
||||
status: "confirming",
|
||||
version: "2026.5.2",
|
||||
});
|
||||
|
||||
respondToRelayClientInstallConfirmation(true);
|
||||
await expect(confirmation).resolves.toBe(true);
|
||||
expect(readRelayClientInstallDialogState()).toEqual({
|
||||
status: "installing",
|
||||
version: "2026.5.2",
|
||||
stage: "checking",
|
||||
});
|
||||
|
||||
reportRelayClientInstallProgress({ type: "progress", stage: "downloading" });
|
||||
expect(readRelayClientInstallDialogState()).toEqual({
|
||||
status: "installing",
|
||||
version: "2026.5.2",
|
||||
stage: "downloading",
|
||||
});
|
||||
|
||||
finishRelayClientInstall();
|
||||
expect(readRelayClientInstallDialogState()).toEqual({ status: "idle" });
|
||||
});
|
||||
|
||||
it("returns to idle when installation is declined", async () => {
|
||||
const confirmation = requestRelayClientInstallConfirmation("2026.5.2");
|
||||
respondToRelayClientInstallConfirmation(false);
|
||||
|
||||
await expect(confirmation).resolves.toBe(false);
|
||||
expect(readRelayClientInstallDialogState()).toEqual({ status: "idle" });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
import type {
|
||||
RelayClientInstallProgressEvent,
|
||||
RelayClientInstallProgressStage,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
export type RelayClientInstallDialogState =
|
||||
| { readonly status: "idle" }
|
||||
| { readonly status: "confirming"; readonly version: string }
|
||||
| {
|
||||
readonly status: "installing";
|
||||
readonly version: string;
|
||||
readonly stage: RelayClientInstallProgressStage;
|
||||
};
|
||||
|
||||
const idleState: RelayClientInstallDialogState = { status: "idle" };
|
||||
let state: RelayClientInstallDialogState = idleState;
|
||||
let resolveConfirmation: ((confirmed: boolean) => void) | null = null;
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function publish(next: RelayClientInstallDialogState) {
|
||||
state = next;
|
||||
for (const listener of listeners) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
export function readRelayClientInstallDialogState(): RelayClientInstallDialogState {
|
||||
return state;
|
||||
}
|
||||
|
||||
export function subscribeRelayClientInstallDialog(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
export function requestRelayClientInstallConfirmation(version: string): Promise<boolean> {
|
||||
if (state.status !== "idle") {
|
||||
return Promise.reject(new Error("A relay client installation is already in progress."));
|
||||
}
|
||||
|
||||
publish({ status: "confirming", version });
|
||||
return new Promise<boolean>((resolve) => {
|
||||
resolveConfirmation = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
export function respondToRelayClientInstallConfirmation(confirmed: boolean): void {
|
||||
if (state.status !== "confirming" || !resolveConfirmation) {
|
||||
return;
|
||||
}
|
||||
|
||||
const resolve = resolveConfirmation;
|
||||
resolveConfirmation = null;
|
||||
publish(
|
||||
confirmed ? { status: "installing", version: state.version, stage: "checking" } : idleState,
|
||||
);
|
||||
resolve(confirmed);
|
||||
}
|
||||
|
||||
export function reportRelayClientInstallProgress(event: RelayClientInstallProgressEvent): void {
|
||||
if (state.status !== "installing" || event.type !== "progress") {
|
||||
return;
|
||||
}
|
||||
publish({ ...state, stage: event.stage });
|
||||
}
|
||||
|
||||
export function finishRelayClientInstall(): void {
|
||||
resolveConfirmation?.(false);
|
||||
resolveConfirmation = null;
|
||||
publish(idleState);
|
||||
}
|
||||
|
||||
export function resetRelayClientInstallDialogForTests(): void {
|
||||
finishRelayClientInstall();
|
||||
listeners.clear();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import "../../index.css";
|
||||
|
||||
import { page } from "vitest/browser";
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { render } from "vitest-browser-react";
|
||||
|
||||
import {
|
||||
finishRelayClientInstall,
|
||||
reportRelayClientInstallProgress,
|
||||
requestRelayClientInstallConfirmation,
|
||||
resetRelayClientInstallDialogForTests,
|
||||
} from "../../cloud/relayClientInstallDialog";
|
||||
import { RelayClientInstallDialog } from "./RelayClientInstallDialog";
|
||||
|
||||
describe("RelayClientInstallDialog", () => {
|
||||
beforeEach(() => {
|
||||
resetRelayClientInstallDialogForTests();
|
||||
});
|
||||
|
||||
it("confirms installation and renders streamed progress", async () => {
|
||||
render(<RelayClientInstallDialog />);
|
||||
const confirmation = requestRelayClientInstallConfirmation("2026.5.2");
|
||||
|
||||
await expect.element(page.getByText("Install relay client?")).toBeInTheDocument();
|
||||
await expect.element(page.getByText(/version 2026\.5\.2 locally/)).toBeInTheDocument();
|
||||
|
||||
await page.getByRole("button", { name: "Download and install" }).click();
|
||||
await expect(confirmation).resolves.toBe(true);
|
||||
await expect
|
||||
.element(page.getByRole("heading", { name: "Installing relay client" }))
|
||||
.toBeInTheDocument();
|
||||
|
||||
reportRelayClientInstallProgress({ type: "progress", stage: "downloading" });
|
||||
await expect
|
||||
.element(page.getByText("Downloading relay client").first())
|
||||
.toHaveTextContent("Downloading relay client");
|
||||
await expect
|
||||
.element(page.getByText("Downloading relay client").first())
|
||||
.toHaveAttribute("class", expect.stringContaining("font-medium"));
|
||||
|
||||
finishRelayClientInstall();
|
||||
await expect
|
||||
.element(page.getByRole("heading", { name: "Installing relay client" }))
|
||||
.not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,129 @@
|
||||
import { CircleCheckIcon, CircleIcon, DownloadIcon } from "lucide-react";
|
||||
import { useSyncExternalStore } from "react";
|
||||
import type { RelayClientInstallProgressStage } from "@t3tools/contracts";
|
||||
|
||||
import {
|
||||
readRelayClientInstallDialogState,
|
||||
respondToRelayClientInstallConfirmation,
|
||||
subscribeRelayClientInstallDialog,
|
||||
} from "../../cloud/relayClientInstallDialog";
|
||||
import { Button } from "../ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogPanel,
|
||||
DialogPopup,
|
||||
DialogTitle,
|
||||
} from "../ui/dialog";
|
||||
import { Spinner } from "../ui/spinner";
|
||||
|
||||
const installSteps: ReadonlyArray<{
|
||||
readonly stage: RelayClientInstallProgressStage;
|
||||
readonly label: string;
|
||||
}> = [
|
||||
{ stage: "checking", label: "Checking current installation" },
|
||||
{ stage: "waiting_for_lock", label: "Waiting for installer" },
|
||||
{ stage: "downloading", label: "Downloading relay client" },
|
||||
{ stage: "verifying", label: "Verifying download" },
|
||||
{ stage: "installing", label: "Installing relay client" },
|
||||
{ stage: "validating", label: "Validating executable" },
|
||||
{ stage: "activating", label: "Activating installation" },
|
||||
];
|
||||
|
||||
export function RelayClientInstallDialog() {
|
||||
const state = useSyncExternalStore(
|
||||
subscribeRelayClientInstallDialog,
|
||||
readRelayClientInstallDialogState,
|
||||
readRelayClientInstallDialogState,
|
||||
);
|
||||
const isConfirming = state.status === "confirming";
|
||||
const isInstalling = state.status === "installing";
|
||||
const activeStepIndex = isInstalling
|
||||
? installSteps.findIndex(({ stage }) => stage === state.stage)
|
||||
: -1;
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={state.status !== "idle"}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && isConfirming) {
|
||||
respondToRelayClientInstallConfirmation(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogPopup className="max-w-md" showCloseButton={isConfirming}>
|
||||
<DialogHeader>
|
||||
<div className="flex size-9 items-center justify-center rounded-lg border border-border/70 bg-muted/60">
|
||||
<DownloadIcon aria-hidden className="size-4.5 text-muted-foreground" />
|
||||
</div>
|
||||
<DialogTitle>
|
||||
{isInstalling ? "Installing relay client" : "Install relay client?"}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{isInstalling
|
||||
? "T3 Code is preparing this environment for secure access through T3 Cloud."
|
||||
: "T3 Code needs the relay client to make this environment available through T3 Cloud."}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogPanel scrollFade={false}>
|
||||
{isInstalling ? (
|
||||
<ol aria-label="Relay client installation progress" className="space-y-2">
|
||||
{installSteps.map((step, index) => {
|
||||
const isComplete = activeStepIndex > index;
|
||||
const isActive = activeStepIndex === index;
|
||||
return (
|
||||
<li
|
||||
key={step.stage}
|
||||
aria-current={isActive ? "step" : undefined}
|
||||
className="flex items-center gap-2.5 rounded-lg px-2 py-1.5 text-sm"
|
||||
>
|
||||
{isComplete ? (
|
||||
<CircleCheckIcon aria-hidden className="size-4 text-success" />
|
||||
) : isActive ? (
|
||||
<Spinner aria-hidden className="size-4 text-primary" />
|
||||
) : (
|
||||
<CircleIcon aria-hidden className="size-4 text-muted-foreground/55" />
|
||||
)}
|
||||
<span
|
||||
className={isActive ? "font-medium text-foreground" : "text-muted-foreground"}
|
||||
>
|
||||
{step.label}
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
<li aria-live="polite" className="sr-only">
|
||||
{activeStepIndex >= 0
|
||||
? installSteps[activeStepIndex]?.label
|
||||
: "Starting installation"}
|
||||
</li>
|
||||
</ol>
|
||||
) : (
|
||||
<div className="rounded-xl border border-border/70 bg-muted/35 p-3">
|
||||
<p className="text-sm font-medium text-foreground">Managed relay client</p>
|
||||
<p className="mt-1 text-sm leading-relaxed text-muted-foreground">
|
||||
T3 Code will download and install version{" "}
|
||||
{state.status === "confirming" ? state.version : ""} locally.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</DialogPanel>
|
||||
{isConfirming ? (
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => respondToRelayClientInstallConfirmation(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={() => respondToRelayClientInstallConfirmation(true)}>
|
||||
Download and install
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
) : null}
|
||||
</DialogPopup>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { QueryClient, useQueryClient } from "@tanstack/react-query";
|
||||
import { APP_DISPLAY_NAME } from "../branding";
|
||||
import { AppSidebarLayout } from "../components/AppSidebarLayout";
|
||||
import { CommandPalette } from "../components/CommandPalette";
|
||||
import { RelayClientInstallDialog } from "../components/cloud/RelayClientInstallDialog";
|
||||
import { SshPasswordPromptDialog } from "../components/desktop/SshPasswordPromptDialog";
|
||||
import { ProviderUpdateLaunchNotification } from "../components/ProviderUpdateLaunchNotification";
|
||||
import {
|
||||
@@ -135,6 +136,7 @@ function RootRouteView() {
|
||||
{primaryEnvironmentAuthenticated ? <AuthenticatedTracingBootstrap /> : null}
|
||||
{primaryEnvironmentAuthenticated ? <ServerStateBootstrap /> : null}
|
||||
<EnvironmentConnectionManagerBootstrap />
|
||||
<RelayClientInstallDialog />
|
||||
<SshPasswordPromptDialog />
|
||||
<HostedStaticEnvironmentBootstrap />
|
||||
{primaryEnvironmentAuthenticated ? <EventRouter /> : null}
|
||||
|
||||
Reference in new issue
Block a user