Skip to content
TypeScript

fix(web): test device hosts across selected environments (#11699)

Julius Marminge8984f8103d08
diff --git a/apps/web/src/components/settings/DeviceHostEditor.tsx b/apps/web/src/components/settings/DeviceHostEditor.tsx
new file mode 100644
index 00000000000..4ab03ad3c15
--- /dev/null
+++ b/apps/web/src/components/settings/DeviceHostEditor.tsx
@@ -0,0 +1,224 @@
+import { useState } from "react";
+import * as Option from "effect/Option";
+import type { SshDeviceHostConfig } from "@t3tools/contracts";
+import { CheckIcon, MonitorIcon, XIcon } from "lucide-react";
+import { Button } from "../ui/button";
+import { Input } from "../ui/input";
+import { Spinner } from "../ui/spinner";
+import {
+ Dialog,
+ DialogPopup,
+ DialogHeader,
+ DialogTitle,
+ DialogDescription,
+ DialogPanel,
+ DialogFooter,
+} from "../ui/dialog";
+import { DeviceHostAvailability } from "../device/DeviceHostAvailability";
+import { useHostConnectionChecks } from "./useHostConnectionChecks";
+import {
+ deviceHostConnectionKey,
+ parseDeviceHostDraft,
+ type DeviceHostCheckTarget,
+} from "./deviceHostConnectionChecks";
+
+export function DeviceHostEditor({
+ host,
+ isNew,
+ targets,
+ busy,
+ onSave,
+ onClose,
+}: {
+ host: SshDeviceHostConfig;
+ isNew: boolean;
+ targets: ReadonlyArray<DeviceHostCheckTarget>;
+ busy: boolean;
+ onSave: (host: SshDeviceHostConfig) => void;
+ onClose: () => void;
+}) {
+ const [draft, setDraft] = useState(host);
+ const { checks, testConnection } = useHostConnectionChecks(targets);
+ const results = checks[deviceHostConnectionKey(draft)];
+ const checking = Object.values(results ?? {}).some((check) => check.status === "pending");
+ const input = parseDeviceHostDraft({ ...draft, label: draft.label.trim() || draft.target });
+ const valid = Option.isSome(input);
+ const failed = Object.values(results ?? {}).filter((check) => check.status === "failed").length;
+ return (
+ <Dialog
+ open
+ onOpenChange={(open) => {
+ if (!open && !busy) onClose();
+ }}
+ >
+ <DialogPopup
+ showCloseButton={!busy}
+ render={
+ <form
+ onSubmit={(event) => {
+ event.preventDefault();
+ if (Option.isSome(input) && draft.label.trim() && !busy && !checking)
+ onSave(input.value);
+ }}
+ />
+ }
+ >
+ <DialogHeader>
+ <DialogTitle>{isNew ? "Add device host" : "Edit device host"}</DialogTitle>
+ <DialogDescription>
+ {targets.length === 1
+ ? `Connect from ${targets[0]?.label}.`
+ : `Connect from ${targets.length} selected environments.`}{" "}
+ Hosts on the same machine are skipped.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogPanel className="space-y-4">
+ <label className="block space-y-1.5 text-sm">
+ <span>Name</span>
+ <Input
+ autoFocus
+ required
+ value={draft.label}
+ disabled={busy}
+ onChange={(event) => setDraft({ ...draft, label: event.target.value })}
+ placeholder="Mac mini"
+ />
+ </label>
+ <label className="block space-y-1.5 text-sm">
+ <span>SSH target</span>
+ <Input
+ required
+ value={draft.target}
+ disabled={busy}
+ onChange={(event) => setDraft({ ...draft, target: event.target.value })}
+ placeholder="user@host or SSH alias"
+ />
+ </label>
+ <details
+ open={host.port !== undefined || host.identityFile !== undefined || undefined}
+ className="text-sm"
+ >
+ <summary className="cursor-pointer text-muted-foreground">SSH options</summary>
+ <div className="mt-3 grid grid-cols-[minmax(0,1fr)_7rem] gap-3">
+ <label className="block space-y-1.5">
+ <span>Identity file</span>
+ <Input
+ value={draft.identityFile ?? ""}
+ disabled={busy}
+ onChange={(event) => {
+ const { identityFile: _, ...rest } = draft;
+ setDraft(
+ event.target.value ? { ...rest, identityFile: event.target.value } : rest,
+ );
+ }}
+ placeholder="SSH config default"
+ />
+ </label>
+ <label className="block space-y-1.5">
+ <span>Port</span>
+ <Input
+ type="number"
+ min={1}
+ max={65535}
+ value={draft.port ?? ""}
+ disabled={busy}
+ onChange={(event) => {
+ const { port: _, ...rest } = draft;
+ setDraft(
+ event.target.value ? { ...rest, port: Number(event.target.value) } : rest,
+ );
+ }}
+ placeholder="Default"
+ />
+ </label>
+ </div>
+ <p className="mt-2 text-xs text-muted-foreground">
+ Optional. Resolved separately on each environment.
+ </p>
+ </details>
+ <div className="rounded-lg border border-border/60">
+ <div className="flex items-center justify-between gap-3 px-3 py-2.5">
+ <p role="status" className="text-xs text-muted-foreground">
+ {checking
+ ? "Checking environments…"
+ : results
+ ? failed
+ ? `${failed} of ${targets.length} failed`
+ : "Connection checks passed"
+ : "Check access before saving"}
+ </p>
+ <Button
+ type="button"
+ size="sm"
+ variant="outline"
+ disabled={busy || checking || !valid}
+ onClick={() => {
+ if (Option.isSome(input)) void testConnection(input.value);
+ }}
+ >
+ {checking ? <Spinner className="size-3" /> : null} Test connection
+ </Button>
+ </div>
+ {results ? (
+ <ul className="border-t border-border/60 divide-y divide-border/40">
+ {targets.map((target) => {
+ const result = results[target.environmentId];
+ if (!result) return null;
+ return (
+ <li key={target.environmentId} className="px-3 py-2.5 text-xs">
+ <div className="flex items-center justify-between gap-3">
+ <span className="truncate font-medium">{target.label}</span>
+ <span
+ className={`flex shrink-0 items-center gap-1.5 ${result.status === "failed" ? "text-destructive" : "text-muted-foreground"}`}
+ >
+ {result.status === "pending" ? (
+ <>
+ <Spinner className="size-3" /> Checking…
+ </>
+ ) : result.status === "local" ? (
+ <>
+ <MonitorIcon className="size-3" /> Already available locally
+ </>
+ ) : result.status === "failed" ? (
+ <>
+ <XIcon className="size-3" /> Failed
+ </>
+ ) : (
+ <>
+ <CheckIcon className="size-3" /> Connected
+ </>
+ )}
+ </span>
+ </div>
+ {result.status === "connected" ? (
+ <div className="mt-1.5">
+ <DeviceHostAvailability platforms={result.platforms} />
+ </div>
+ ) : null}
+ {result.status === "failed" ? (
+ <details className="mt-1.5 text-muted-foreground">
+ <summary className="cursor-pointer">Show error</summary>
+ <p className="mt-1 max-h-32 overflow-auto whitespace-pre-wrap break-words">
+ {result.error}
+ </p>
+ </details>
+ ) : null}
+ </li>
+ );
+ })}
+ </ul>
+ ) : null}
+ </div>
+ </DialogPanel>
+ <DialogFooter>
+ <Button type="button" variant="ghost" disabled={busy} onClick={onClose}>
+ Cancel
+ </Button>
+ <Button type="submit" disabled={busy || checking || !valid || !draft.label.trim()}>
+ {busy ? <Spinner className="size-3" /> : null} Save host
+ </Button>
+ </DialogFooter>
+ </DialogPopup>
+ </Dialog>
+ );
+}
diff --git a/apps/web/src/components/settings/DeviceHostsSettings.tsx b/apps/web/src/components/settings/DeviceHostsSettings.tsx
index c5a5f194d7c..50841ee5b53 100644
--- a/apps/web/src/components/settings/DeviceHostsSettings.tsx
+++ b/apps/web/src/components/settings/DeviceHostsSettings.tsx
@@ -1,20 +1,13 @@
import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";
import { AppleIcon, AndroidIcon } from "../Icons";
-import { DeviceHostAvailability } from "../device/DeviceHostAvailability";
import { Spinner } from "../ui/spinner";
-import type {
- DevicePlatformAvailability,
- EnvironmentId,
- SshDeviceHostConfig,
-} from "@t3tools/contracts";
-import * as Cause from "effect/Cause";
+import type { EnvironmentId, SshDeviceHostConfig } from "@t3tools/contracts";
import { randomUUID } from "../../lib/utils";
import { useState } from "react";
-import { deviceEnvironment, useDeviceState } from "../../state/device";
+import { useDeviceState } from "../../state/device";
import { serverEnvironment } from "../../state/server";
import { useAtomCommand } from "../../state/use-atom-command";
import { Button } from "../ui/button";
-import { Input } from "../ui/input";
import { MoreVertical, PlusIcon } from "lucide-react";
import { Menu, MenuTrigger, MenuPopup, MenuItem } from "../ui/menu";
import { SettingsRow } from "./settingsLayout";
@@ -22,17 +15,23 @@ import { SettingsRow } from "./settingsLayout";
import { useSettingsScope } from "./SettingsScopeContext";
import { toastManager } from "../ui/toast";
import { updateDeviceHosts } from "./deviceHostsSettings.logic";
+import { DeviceHostEditor } from "./DeviceHostEditor";
+import { useHostConnectionChecks } from "./useHostConnectionChecks";
+import { deviceHostConnectionKey } from "./deviceHostConnectionChecks";
export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null }) {
- const { scope, environments, connectedEnvironments, environment: selected } = useSettingsScope();
+ const { scope, environments, connectedEnvironments } = useSettingsScope();
const projectScope = scope.kind === "project" || scope.kind === "checkout";
const update = useAtomCommand(serverEnvironment.updateSettings, { reportFailure: false });
const [editing, setEditing] = useState<SshDeviceHostConfig | null>(null);
const [originalHost, setOriginalHost] = useState<SshDeviceHostConfig | null>(null);
const [busy, setBusy] = useState(false);
- const validPort = (port: number | undefined) =>
- port === undefined || (Number.isInteger(port) && port >= 1 && port <= 65535);
- const { checks, testConnection } = useHostConnectionChecks(props.environmentId);
+ const targets = environments.map((environment) => ({
+ environmentId: environment.environmentId,
+ label: environment.label,
+ connected: environment.connection.phase === "connected",
+ }));
+ const { checks, testConnection } = useHostConnectionChecks(targets);
const save = async (host: SshDeviceHostConfig, remove = false, original = host) => {
if (!props.environmentId || projectScope) return;
setBusy(true);
@@ -113,6 +112,24 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null
environmentId={environment.environmentId}
hosts={environment.serverConfig?.settings.deviceHosts ?? []}
busy={projectScope || busy}
+ checks={checks}
+ testConnection={async (host) => {
+ const results = await testConnection(host);
+ if (!results) return;
+ const failed = targets.filter(
+ (target) => results[target.environmentId]?.status === "failed",
+ );
+ toastManager.add({
+ type: failed.length ? "error" : "success",
+ title: failed.length
+ ? `${host.label}: ${failed.length} of ${targets.length} environments failed`
+ : `${host.label}: connection checks passed`,
+ description: failed.length
+ ? `Could not connect from ${failed.map((target) => target.label).join(", ")}.`
+ : "Connected or already available locally on each selected environment.",
+ });
+ return results;
+ }}
onEdit={(host) => {
setOriginalHost(host);
setEditing(host);
@@ -122,123 +139,15 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null
</div>
))}
{editing ? (
- <form
- className="space-y-3 border-t border-border/50 py-3"
- onSubmit={(event) => {
- event.preventDefault();
- void save(editing, false, originalHost ?? editing);
- }}
- >
- <label className="block space-y-1 text-sm">
- <span>Name</span>
- <Input
- required
- value={editing.label}
- disabled={projectScope || busy}
- onChange={(event) => setEditing({ ...editing, label: event.target.value })}
- placeholder="Mac mini"
- />
- </label>
- <label className="block space-y-1 text-sm">
- <span>SSH target</span>
- <Input
- required
- value={editing.target}
- disabled={projectScope || busy}
- onChange={(event) => setEditing({ ...editing, target: event.target.value })}
- placeholder="user@host or SSH alias"
- />
- </label>
- <label className="block space-y-1 text-sm">
- <span>Identity file, optional</span>
- <Input
- value={editing.identityFile ?? ""}
- disabled={projectScope || busy}
- onChange={(event) => {
- const { identityFile: _, ...rest } = editing;
- setEditing(
- event.target.value ? { ...rest, identityFile: event.target.value } : rest,
- );
- }}
- placeholder="~/.ssh/id_ed25519"
- />
- </label>
- <label className="block space-y-1 text-sm">
- <span>Port, optional</span>
- <Input
- type="number"
- min={1}
- max={65535}
- value={editing.port ?? ""}
- disabled={projectScope || busy}
- onChange={(event) => {
- const { port: _, ...rest } = editing;
- setEditing(
- event.target.value ? { ...rest, port: Number(event.target.value) } : rest,
- );
- }}
- placeholder="SSH config default"
- />
- </label>
- <div className="flex flex-wrap gap-2">
- <Button
- size="sm"
- type="submit"
- disabled={
- busy ||
- !editing.label.trim() ||
- !editing.target.trim() ||
- !validPort(editing.port)
- }
- >
- Save host
- </Button>
- <Button
- size="sm"
- type="button"
- variant="outline"
- disabled={
- busy ||
- !editing.label.trim() ||
- !editing.target.trim() ||
- !validPort(editing.port)
- }
- onClick={() => void testConnection(editing)}
- >
- {connectedEnvironments.length > 1
- ? `Test from ${selected?.label}`
- : "Test connection"}
- </Button>
- <Button
- size="sm"
- type="button"
- variant="ghost"
- disabled={projectScope || busy}
- onClick={() => {
- setEditing(null);
- }}
- >
- Cancel
- </Button>
- </div>
- {checks[editing.id]?.pending ? (
- <span
- role="status"
- className="inline-flex items-center gap-1.5 text-xs text-muted-foreground"
- >
- <Spinner className="size-3" />
- Checking connection…
- </span>
- ) : null}
- {checks[editing.id]?.platforms ? (
- <DeviceHostAvailability platforms={checks[editing.id]?.platforms ?? []} />
- ) : null}
- {checks[editing.id]?.error ? (
- <p role="alert" className="text-xs text-destructive">
- {checks[editing.id]?.error}
- </p>
- ) : null}
- </form>
+ <DeviceHostEditor
+ key={editing.id}
+ host={editing}
+ isNew={originalHost === null}
+ targets={targets}
+ busy={busy}
+ onSave={(host) => void save(host, false, originalHost ?? host)}
+ onClose={() => setEditing(null)}
+ />
) : null}
</>
)}
@@ -247,49 +156,24 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null
);
}
-function useHostConnectionChecks(environmentId: EnvironmentId | null) {
- const test = useAtomCommand(deviceEnvironment.testHost, { reportFailure: false });
- const [checks, setChecks] = useState<
- Record<
- string,
- { pending?: boolean; platforms?: ReadonlyArray<DevicePlatformAvailability>; error?: string }
- >
- >({});
- const setCheck = (id: string, value: (typeof checks)[string]) =>
- setChecks((current) => ({ ...current, [id]: value }));
- const testConnection = async (host: SshDeviceHostConfig) => {
- if (!environmentId || checks[host.id]?.pending) return;
- setCheck(host.id, { pending: true });
- try {
- const summary = await test({ environmentId: environmentId, input: host });
- setCheck(
- host.id,
- summary._tag === "Failure"
- ? { error: Cause.pretty(summary.cause) }
- : { platforms: summary.value.platforms },
- );
- } catch (error) {
- setCheck(host.id, { error: error instanceof Error ? error.message : String(error) });
- }
- };
- return { checks, testConnection };
-}
-
function DeviceHostList({
environmentId,
hosts,
busy,
onEdit,
onRemove,
+ checks,
+ testConnection,
}: {
environmentId: EnvironmentId;
hosts: ReadonlyArray<SshDeviceHostConfig>;
busy: boolean;
onEdit: (host: SshDeviceHostConfig) => void;
onRemove: (host: SshDeviceHostConfig) => void;
+ checks: ReturnType<typeof useHostConnectionChecks>["checks"];
+ testConnection: ReturnType<typeof useHostConnectionChecks>["testConnection"];
}) {
const { state } = useDeviceState(environmentId);
- const { checks, testConnection } = useHostConnectionChecks(environmentId);
return (
<>
{hosts.length === 0 ? (
@@ -297,17 +181,27 @@ function DeviceHostList({
) : null}
{hosts.map((host) => {
const status = state.hostStatuses[host.id];
- const check = checks[host.id];
+ const check = checks[deviceHostConnectionKey(host)]?.[environmentId];
const platforms =
- check?.platforms ?? state.hosts.find((value) => value.id === host.id)?.platforms ?? [];
- const progress = check?.pending
- ? "Checking connection…"
- : status?.status === "installing"
- ? "Installing device support…"
- : status?.status === "starting"
- ? "Connecting…"
- : null;
- const error = check?.error ?? (status?.status === "failed" ? status.detail : undefined);
+ (check?.status === "connected" ? check.platforms : undefined) ??
+ state.hosts.find((value) => value.id === host.id)?.platforms ??
+ [];
+ const progress =
+ check?.status === "pending"
+ ? "Checking connection…"
+ : status?.status === "installing"
+ ? "Installing device support…"
+ : status?.status === "starting"
+ ? "Connecting…"
+ : null;
+ const error =
+ check?.status === "failed"
+ ? check.error
+ : check?.status === "local"
+ ? undefined
+ : status?.status === "failed"
+ ? status.detail
+ : undefined;
return (
<div key={host.id} className="flex items-center gap-2 border-t border-border/50 py-2.5">
<div className="min-w-0 flex-1">
@@ -342,6 +236,9 @@ function DeviceHostList({
))}
</div>
<p className="truncate text-xs text-muted-foreground">{host.target}</p>
+ {check?.status === "local" ? (
+ <p className="mt-1 text-xs text-muted-foreground">Already available locally</p>
+ ) : null}
{error ? (
<div className="mt-1" role="status">
<details className="text-xs text-destructive">
diff --git a/apps/web/src/components/settings/deviceHostConnectionChecks.test.ts b/apps/web/src/components/settings/deviceHostConnectionChecks.test.ts
new file mode 100644
index 00000000000..f9b003812bf
--- /dev/null
+++ b/apps/web/src/components/settings/deviceHostConnectionChecks.test.ts
@@ -0,0 +1,85 @@
+import * as Option from "effect/Option";
+import { describe, expect, it } from "vite-plus/test";
+import { EnvironmentId, type DeviceHostSummary } from "@t3tools/contracts";
+import {
+ checkDeviceHostConnections,
+ parseDeviceHostDraft,
+ deviceHostConnectionKey,
+ type DeviceHostCheck,
+} from "./deviceHostConnectionChecks";
+
+const host = { id: "mac", label: "Mac mini", target: "user@mac" };
+const ids = ["a", "b", "c", "d"].map((id) => EnvironmentId.make(id));
+const targets = ids.map((environmentId, index) => ({
+ environmentId,
+ label: environmentId,
+ connected: index !== 3,
+}));
+const summary: DeviceHostSummary = {
+ id: "mac",
+ label: "Mac mini",
+ kind: "ssh",
+ platforms: [{ platform: "ios", available: true }],
+ hubInstalled: false,
+ agentDeviceInstalled: false,
+};
+
+describe("device host connection checks", () => {
+ it("starts all connected environments and retains success, local, failure, and offline results", async () => {
+ const calls: string[] = [];
+ const pending = new Map<
+ string,
+ { resolve: (value: DeviceHostSummary) => void; reject: (error: Error) => void }
+ >();
+ const results = new Map<string, DeviceHostCheck>();
+ const run = checkDeviceHostConnections(
+ targets,
+ host,
+ (environmentId) => {
+ calls.push(environmentId);
+ return new Promise((resolve, reject) => pending.set(environmentId, { resolve, reject }));
+ },
+ (environmentId, result) => results.set(environmentId, result),
+ );
+ expect(calls).toEqual(ids.slice(0, 3));
+ expect(results.get(ids[0]!)).toEqual({ status: "pending" });
+ pending.get(ids[0]!)!.resolve(summary);
+ pending.get(ids[1]!)!.resolve({ ...summary, id: "local", kind: "local" });
+ pending.get(ids[2]!)!.reject(new Error("SSH key rejected"));
+ await run;
+ expect([...results.values()]).toEqual([
+ { status: "connected", platforms: summary.platforms },
+ { status: "local" },
+ { status: "failed", error: "SSH key rejected" },
+ { status: "failed", error: "Environment disconnected" },
+ ]);
+ });
+
+ it("does not reuse results after editing a destination or SSH options", () => {
+ const key = deviceHostConnectionKey(host);
+ for (const changed of [
+ { ...host, target: "other" },
+ { ...host, port: 2222 },
+ { ...host, identityFile: "~/.ssh/other" },
+ ]) {
+ expect(deviceHostConnectionKey(changed)).not.toBe(key);
+ }
+ expect(
+ deviceHostConnectionKey({ ...host, id: "another-environment-id", label: "Renamed" }),
+ ).toBe(key);
+ });
+ it("validates SSH targets and normalizes optional identity files through the host contract", () => {
+ for (const target of ["-invalid", "user@bad host", " "]) {
+ expect(parseDeviceHostDraft({ ...host, target })._tag).toBe("None");
+ }
+ for (const port of [0, 65536, 1.5]) {
+ expect(parseDeviceHostDraft({ ...host, port })._tag).toBe("None");
+ }
+ expect(parseDeviceHostDraft({ ...host, target: " user@mac ", identityFile: " " })).toEqual(
+ Option.some(host),
+ );
+ expect(parseDeviceHostDraft({ ...host, identityFile: " ~/.ssh/device " })).toEqual(
+ Option.some({ ...host, identityFile: "~/.ssh/device" }),
+ );
+ });
+});
diff --git a/apps/web/src/components/settings/deviceHostConnectionChecks.ts b/apps/web/src/components/settings/deviceHostConnectionChecks.ts
new file mode 100644
index 00000000000..97312b67151
--- /dev/null
+++ b/apps/web/src/components/settings/deviceHostConnectionChecks.ts
@@ -0,0 +1,61 @@
+import {
+ type DeviceHostSummary,
+ type DevicePlatformAvailability,
+ type EnvironmentId,
+ SshDeviceHostConfig,
+} from "@t3tools/contracts";
+import * as Schema from "effect/Schema";
+
+export interface DeviceHostCheckTarget {
+ environmentId: EnvironmentId;
+ label: string;
+ connected: boolean;
+}
+export type DeviceHostCheck =
+ | { status: "pending" }
+ | { status: "local" }
+ | { status: "connected"; platforms: ReadonlyArray<DevicePlatformAvailability> }
+ | { status: "failed"; error: string };
+
+const decodeDeviceHostDraft = Schema.decodeUnknownOption(SshDeviceHostConfig);
+
+export function parseDeviceHostDraft(host: SshDeviceHostConfig) {
+ const { identityFile, ...rest } = host;
+ return decodeDeviceHostDraft({
+ ...rest,
+ ...(identityFile?.trim() ? { identityFile: identityFile.trim() } : {}),
+ });
+}
+
+export function deviceHostConnectionKey(host: SshDeviceHostConfig) {
+ return JSON.stringify([host.target.trim(), host.port, host.identityFile?.trim() || undefined]);
+}
+
+/** Each environment settles independently so one failure cannot hide the other results. */
+export async function checkDeviceHostConnections(
+ targets: ReadonlyArray<DeviceHostCheckTarget>,
+ host: SshDeviceHostConfig,
+ probe: (environmentId: EnvironmentId, host: SshDeviceHostConfig) => Promise<DeviceHostSummary>,
+ report: (environmentId: EnvironmentId, result: DeviceHostCheck) => void,
+) {
+ await Promise.all(
+ targets.map(async (target) => {
+ report(target.environmentId, { status: "pending" });
+ try {
+ if (!target.connected) throw new Error("Environment disconnected");
+ const result = await probe(target.environmentId, host);
+ report(
+ target.environmentId,
+ result.kind === "local"
+ ? { status: "local" }
+ : { status: "connected", platforms: result.platforms },
+ );
+ } catch (error) {
+ report(target.environmentId, {
+ status: "failed",
+ error: error instanceof Error ? error.message : String(error),
+ });
+ }
+ }),
+ );
+}
diff --git a/apps/web/src/components/settings/useHostConnectionChecks.ts b/apps/web/src/components/settings/useHostConnectionChecks.ts
new file mode 100644
index 00000000000..7d642fa62a6
--- /dev/null
+++ b/apps/web/src/components/settings/useHostConnectionChecks.ts
@@ -0,0 +1,46 @@
+import { useRef, useState } from "react";
+import * as Cause from "effect/Cause";
+import type { SshDeviceHostConfig } from "@t3tools/contracts";
+import { deviceEnvironment } from "../../state/device";
+import { useAtomCommand } from "../../state/use-atom-command";
+import {
+ checkDeviceHostConnections,
+ deviceHostConnectionKey,
+ type DeviceHostCheck,
+ type DeviceHostCheckTarget,
+} from "./deviceHostConnectionChecks";
+
+export function useHostConnectionChecks(targets: ReadonlyArray<DeviceHostCheckTarget>) {
+ const test = useAtomCommand(deviceEnvironment.testHost, { reportFailure: false });
+ const [checks, setChecks] = useState<Record<string, Record<string, DeviceHostCheck>>>({});
+ const running = useRef(new Set<string>());
+ const testConnection = async (host: SshDeviceHostConfig) => {
+ const key = deviceHostConnectionKey(host);
+ if (running.current.has(key)) return;
+ running.current.add(key);
+ setChecks((current) => ({ ...current, [key]: {} }));
+ const results: Record<string, DeviceHostCheck> = {};
+ try {
+ await checkDeviceHostConnections(
+ targets,
+ host,
+ async (environmentId, input) => {
+ const result = await test({ environmentId, input });
+ if (result._tag === "Failure") throw new Error(Cause.pretty(result.cause));
+ return result.value;
+ },
+ (environmentId, result) => {
+ results[environmentId] = result;
+ setChecks((current) => ({
+ ...current,
+ [key]: { ...current[key], [environmentId]: result },
+ }));
+ },
+ );
+ return results;
+ } finally {
+ running.current.delete(key);
+ }
+ };
+ return { checks, testConnection };
+}
diff --git a/docs/user/devices.md b/docs/user/devices.md
index 2dbe0e26007..f40d1190445 100644
--- a/docs/user/devices.md
+++ b/docs/user/devices.md
@@ -75,14 +75,16 @@ still-image stream and Android cannot show video.
## SSH device hosts
-In Settings → Integrations → Devices, select one connected environment
-and add a host under **Device hosts**. Enter an SSH alias or `user@host`, with
+In Settings → Integrations → Devices, choose the environments that should use
+the host and add it under **Device hosts**. Enter an SSH alias or `user@host`, with
an optional identity file and port. These resolve on the environment server,
so use the SSH configuration and keys available there. Password prompts are
not supported.
**Test connection** checks SSH, Node, npm, and platform tools without installing
-anything. The first device listing installs pinned device tools on the host.
+anything, with a result for each selected environment. Targets that resolve to
+the environment’s own machine are skipped, since its devices are already local.
+The first device listing installs pinned device tools on the host.
Node 22 or newer and npm must be available to non-interactive SSH commands.
T3 checks common Homebrew and Android SDK locations; custom installations need
the appropriate PATH and ANDROID_HOME on the host.