Skip to content
TypeScript

fix(web): device setup lets you through with only a remote device host (#20077)

Julius Marminged10969557eab
diff --git a/apps/web/src/components/device/DevicePanel.tsx b/apps/web/src/components/device/DevicePanel.tsx
index 7e6804043f4..b584b4031e2 100644
--- a/apps/web/src/components/device/DevicePanel.tsx
+++ b/apps/web/src/components/device/DevicePanel.tsx
@@ -20,7 +20,7 @@ import { deviceEnvironment, useDeviceState } from "~/state/device";
import { formatEnvironmentQueryError } from "~/state/query";
import { useAtomCommand } from "~/state/use-atom-command";
import { DeviceLoadingView } from "./DeviceLoadingView";
-import { DeviceSetup } from "./DeviceSetup";
+import { DeviceSetup, deviceHubReadiness } from "./DeviceSetup";
import { DeviceWorkspace } from "./DeviceWorkspace";
import { PreviewPanelShell, type PreviewPanelMode } from "../preview/PreviewPanelShell";
@@ -138,12 +138,7 @@ export function DevicePanel(props: {
const bootingDevices =
state.bootingDevices?.filter((device) => device.threadId === threadId) ?? [];
- const hostReady = Object.values(state.hostStatuses).some((host) => host.status === "ready");
- const hostBusy =
- !hostReady &&
- Object.values(state.hostStatuses).some(
- (host) => host.status === "installing" || host.status === "starting",
- );
+ const { ready: hostReady, busy: hostBusy } = deviceHubReadiness(state);
const unavailablePlatforms = state.hosts.flatMap((host) =>
host.platforms
.filter((platform) => !platform.available)
diff --git a/apps/web/src/components/device/DeviceSetup.tsx b/apps/web/src/components/device/DeviceSetup.tsx
index 67c30525861..2c9dc5cb26f 100644
--- a/apps/web/src/components/device/DeviceSetup.tsx
+++ b/apps/web/src/components/device/DeviceSetup.tsx
@@ -3,7 +3,7 @@ import type { DevicePlatform, DeviceServiceState, EnvironmentId } from "@t3tools
import { Check } from "lucide-react";
import { Check as CheckGlyph, CircleAlert } from "lucide";
import { AuthSettingsWriteScope } from "@t3tools/contracts";
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { Button } from "~/components/ui/button";
import { DialogClose } from "~/components/ui/dialog";
@@ -23,20 +23,42 @@ export const deviceHubDescription =
export const agentDeviceDescription =
"Allow new agent sessions in this environment to start and control local and remote devices, with required tools set up automatically.";
+/**
+ * `hostStatus` only tracks this machine. A machine without simulator tooling never
+ * starts its own hub, so setup and the panel must also count remote device hosts.
+ */
+export function deviceHubReadiness(state: DeviceServiceState) {
+ const statuses = Object.values(state.hostStatuses).map((host) => host.status);
+ const ready = state.hostStatus === "ready" || statuses.includes("ready");
+ const busy =
+ !ready &&
+ [state.hostStatus, ...statuses].some(
+ (status) => status === "installing" || status === "starting",
+ );
+ return { ready, busy };
+}
+
export function platformSetupStatus(state: DeviceServiceState, platform: DevicePlatform) {
- const availability = state.hosts
- .flatMap((host) => host.platforms)
- .find((candidate) => candidate.platform === platform);
- if (!availability?.available) {
+ const availabilities = state.hosts.flatMap((host) =>
+ host.platforms
+ .filter((candidate) => candidate.platform === platform)
+ .map((candidate) => ({ ...candidate, host })),
+ );
+ const supportingHosts = availabilities
+ .filter((candidate) => candidate.available)
+ .map((candidate) => candidate.host);
+ if (supportingHosts.length === 0) {
return {
ready: false,
- message: availability?.reason ?? `${platformName(platform)} support was not detected.`,
+ message: availabilities[0]?.reason ?? `${platformName(platform)} support was not detected.`,
};
}
- if (
- state.hostStatus === "ready" &&
- !state.devices.some((device) => device.platform === platform)
- ) {
+ const readyHosts = supportingHosts.filter(
+ (host) =>
+ state.hostStatuses[host.id]?.status === "ready" ||
+ (host.kind === "local" && state.hostStatus === "ready"),
+ );
+ if (readyHosts.length > 0 && !state.devices.some((device) => device.platform === platform)) {
return {
ready: false,
message:
@@ -45,12 +67,16 @@ export function platformSetupStatus(state: DeviceServiceState, platform: DeviceP
: "The Android SDK is installed, but no virtual device exists. Create one in Android Studio → Device Manager.",
};
}
+ const remoteHost = supportingHosts.every((host) => host.kind !== "local")
+ ? supportingHosts[0]
+ : undefined;
+ const location = remoteHost ? ` on ${remoteHost.label}` : "";
return {
ready: true,
message:
platform === "ios"
- ? "Xcode and iOS Simulator are available."
- : "The Android SDK and Emulator are available.",
+ ? `Xcode and iOS Simulator are available${location}.`
+ : `The Android SDK and Emulator are available${location}.`,
};
}
@@ -65,11 +91,16 @@ export function DeviceSetup(props: {
const [pending, setPending] = useState<"hub" | "check" | "agent" | "complete" | null>(null);
const [step, setStep] = useState(0);
const enabled = props.state.hostStatus !== "disabled";
- const busy = props.state.hostStatus === "installing" || props.state.hostStatus === "starting";
+ const { ready, busy } = deviceHubReadiness(props.state);
const localPlatformsUnavailable = props.state.hosts.some(
(host) => host.kind === "local" && !host.platforms.some((platform) => platform.available),
);
+ // Remote hosts report platforms only after a probe, like the Device panel's refresh on open.
+ useEffect(() => {
+ if (enabled) void list({ environmentId: props.environmentId, input: {} });
+ }, [enabled, list, props.environmentId]);
+
const update = async (
kind: NonNullable<typeof pending>,
input: { enabled?: boolean; agentAccessEnabled?: boolean; onboardingCompleted?: boolean },
@@ -181,15 +212,12 @@ export function DeviceSetup(props: {
</Button>
)}
{step < 2 ? (
- <Button
- disabled={props.state.hostStatus !== "ready" || pending !== null}
- onClick={() => setStep(step + 1)}
- >
+ <Button disabled={!ready || pending !== null} onClick={() => setStep(step + 1)}>
Continue
</Button>
) : (
<Button
- disabled={!canConfigure || props.state.hostStatus !== "ready" || pending !== null}
+ disabled={!canConfigure || !ready || pending !== null}
onClick={() => void update("complete", { onboardingCompleted: true })}
>
{pending === "complete" ? "Saving…" : "Done"}
@@ -209,7 +237,7 @@ export function DeviceHubSetupStatus({
readonly pending: boolean;
readonly compact?: boolean;
}) {
- if (!pending && state.hostStatus !== "ready") return null;
+ if (!pending && !deviceHubReadiness(state).ready) return null;
return (
<p role="status" className="flex items-center gap-2 text-xs text-muted-foreground">
{pending ? <Spinner size="xs" /> : <Check className="size-3 text-success" />}
@@ -278,7 +306,7 @@ export function AgentDeviceSetupStatus(props: {
}
if (
props.state.agentAccessEnabled &&
- props.state.hostStatus === "ready" &&
+ deviceHubReadiness(props.state).ready &&
props.state.hosts.some((host) => host.agentDeviceInstalled)
) {
return (
diff --git a/apps/web/src/components/settings/IntegrationsSettings.test.tsx b/apps/web/src/components/settings/IntegrationsSettings.test.tsx
index bdcfb2ca9db..8e1edfcb90e 100644
--- a/apps/web/src/components/settings/IntegrationsSettings.test.tsx
+++ b/apps/web/src/components/settings/IntegrationsSettings.test.tsx
@@ -68,7 +68,7 @@ vi.mock("./SettingsScopeContext", () => ({
}));
import { IntegrationsSettingsPanel } from "./IntegrationsSettings";
-import { platformSetupStatus } from "../device/DeviceSetup";
+import { deviceHubReadiness, platformSetupStatus } from "../device/DeviceSetup";
let renderer: ReactTestRenderer | undefined;
@@ -163,4 +163,48 @@ describe("device setup guidance", () => {
});
expect(platformSetupStatus(state, "android").message).toBe("Android Emulator is missing.");
});
+
+ it("counts a remote device host when this machine has no simulator tooling", () => {
+ const state = deviceState({
+ hostStatus: "idle",
+ hostStatuses: { macmini: { status: "ready" } },
+ hosts: [
+ {
+ ...deviceState().hosts[0]!,
+ platforms: [
+ { platform: "ios", available: false, reason: "Xcode was not found." },
+ { platform: "android", available: false, reason: "Android SDK was not found." },
+ ],
+ },
+ {
+ id: "macmini",
+ kind: "ssh",
+ label: "Mac Mini",
+ hubInstalled: true,
+ agentDeviceInstalled: true,
+ platforms: [
+ { platform: "ios", available: true },
+ { platform: "android", available: false, reason: "Android SDK was not found." },
+ ],
+ },
+ ],
+ devices: [
+ {
+ hostId: "macmini",
+ id: "iphone",
+ platform: "ios",
+ name: "iPhone 16 Pro",
+ version: "iOS 27.0",
+ booted: true,
+ physical: false,
+ },
+ ],
+ });
+ expect(deviceHubReadiness(state).ready).toBe(true);
+ expect(platformSetupStatus(state, "ios")).toEqual({
+ ready: true,
+ message: "Xcode and iOS Simulator are available on Mac Mini.",
+ });
+ expect(platformSetupStatus(state, "android").ready).toBe(false);
+ });
});
diff --git a/apps/web/src/components/settings/IntegrationsSettings.tsx b/apps/web/src/components/settings/IntegrationsSettings.tsx
index c375ee910a1..ddad15727b5 100644
--- a/apps/web/src/components/settings/IntegrationsSettings.tsx
+++ b/apps/web/src/components/settings/IntegrationsSettings.tsx
@@ -58,6 +58,7 @@ import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"
import {
AgentDeviceSetupStatus,
DeviceHubSetupStatus,
+ deviceHubReadiness,
PlatformStatus,
platformSetupStatus,
deviceHubDescription,
@@ -691,7 +692,7 @@ function DeviceIntegrationControls({
const [pending, setPending] = useState<
"hub" | "check" | "agent" | "update-hub" | "update-agent" | null
>(null);
- const busy = state.hostStatus === "installing" || state.hostStatus === "starting";
+ const { ready: hubReady, busy } = deviceHubReadiness(state);
const localPlatformsUnavailable = state.hosts.some(
(host) => host.kind === "local" && !host.platforms.some((platform) => platform.available),
);
@@ -701,7 +702,7 @@ function DeviceIntegrationControls({
if (
enabled &&
!platformsRevealed &&
- (state.hostStatus === "ready" || localPlatformsUnavailable) &&
+ (hubReady || localPlatformsUnavailable) &&
pending !== "hub"
) {
setPlatformsRevealed(true);