TypeScript
fix(mobile): incompatible environments now say whether to update the app or the host (#19331)
Theo Browned10621de5f8f
diff --git a/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.test.ts b/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.test.tsindex f78cecc0671..8277463dae3 100644--- a/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.test.ts+++ b/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.test.ts@@ -48,7 +48,7 @@ describe("available cloud environment presentation", () => {}),).toMatchObject({connectionState: "unsupported",- statusText: "Client not supported",+ statusText: expect.stringContaining("Update your app"),});});diff --git a/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.ts b/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.tsindex 49e1e790c50..448fab09188 100644--- a/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.ts+++ b/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.ts@@ -27,7 +27,7 @@ export function availableCloudEnvironmentPresentation(input: {connectionError: compatibilityError.message,connectionErrorTraceId: null,connectionState: "unsupported",- statusText: "Client not supported",+ statusText: compatibilityError.message,};}if (input.status?.status === "online") {diff --git a/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx b/apps/mobile/src/features/connection/CloudEnvironmentRows.tsxindex 86df2e91586..4d4dbbc424d 100644--- a/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx+++ b/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx@@ -2,10 +2,7 @@ import { AppActivityIndicator } from "../../components/AppActivityIndicator";import { ConnectionTraceId } from "./ConnectionTraceId";import { useAuth } from "@clerk/expo";import { SymbolView } from "../../components/AppSymbol";-import {- connectionStatusText,- type EnvironmentConnectionPhase,-} from "@t3tools/client-runtime/connection";+import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";import {type EnvironmentId,type EnvironmentMachineKind,@@ -26,6 +23,7 @@ import { serverEnvironment } from "../../state/server";import { availableCloudEnvironmentPresentation } from "../cloud/cloudEnvironmentPresentation";import { hasCloudPublicConfig } from "../cloud/publicConfig";import { ConnectionStatusDot } from "./ConnectionStatusDot";+import { environmentStatusText } from "./environmentStatusText";import { type RelayEnvironmentView, useConnectionController } from "./useConnectionController";interface CloudEnvironmentRowsProps {@@ -307,7 +305,7 @@ function CloudEnvironmentRowShell(props: {const shouldPulse = isRetrying;const statusText =props.statusText ??- connectionStatusText({+ environmentStatusText({phase: props.connectionState,error: props.connectionError,traceId: props.connectionErrorTraceId,diff --git a/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx b/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsxindex f4a682c6c14..ad02b885be8 100644--- a/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx+++ b/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx@@ -1,6 +1,5 @@import { ConnectionTraceId } from "./ConnectionTraceId";import { SymbolView } from "../../components/AppSymbol";-import { connectionStatusText } from "@t3tools/client-runtime/connection";import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";import { type EnvironmentId, resolveEnvironmentMachineKind } from "@t3tools/contracts";import { useAtomValue } from "@effect/atom-react";@@ -20,12 +19,13 @@ import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-typimport { serverEnvironment } from "../../state/server";import { ConnectionFormField } from "./ConnectionFormField";import { ConnectionStatusDot } from "./ConnectionStatusDot";+import { environmentStatusText } from "./environmentStatusText";function connectionStatusLabel(environment: ConnectedEnvironmentSummary): string | null {if (!environment.isEnabled && environment.connectionState !== "unsupported") {return "Off";}- return connectionStatusText({+ return environmentStatusText({phase: environment.connectionState,error: environment.connectionError,traceId: environment.connectionErrorTraceId,diff --git a/apps/mobile/src/features/connection/environmentStatusText.test.ts b/apps/mobile/src/features/connection/environmentStatusText.test.tsnew file mode 100644index 00000000000..e573138beef--- /dev/null+++ b/apps/mobile/src/features/connection/environmentStatusText.test.ts@@ -0,0 +1,39 @@+import { EnvironmentId, ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts";+import { describe, expect, it } from "vite-plus/test";++import { orchestrationProtocolCompatibilityError } from "@t3tools/client-runtime/connection";++import { environmentStatusText } from "./environmentStatusText";++function compatibilityMessage(serverProtocolVersion: number): string {+ const error = orchestrationProtocolCompatibilityError({+ environmentId: EnvironmentId.make("environment-preview"),+ label: "Studio Mac",+ platform: { os: "darwin", arch: "arm64" },+ serverVersion: "1.0.0",+ orchestrationProtocolVersion: serverProtocolVersion,+ capabilities: { repositoryIdentity: true },+ });+ if (error === null) throw new Error("expected an incompatible protocol");+ return error.message;+}++describe("environment status text", () => {+ it.each([+ ["a newer server", ORCHESTRATION_PROTOCOL_VERSION + 1, "Update your app"],+ ["an older server", ORCHESTRATION_PROTOCOL_VERSION - 1, "Update T3 Code on Studio Mac"],+ ])("tells the user what to update for %s", (_, serverProtocolVersion, guidance) => {+ const text = environmentStatusText({+ phase: "unsupported",+ error: compatibilityMessage(serverProtocolVersion),+ traceId: null,+ });+ expect(text).toContain(guidance);+ });++ it("falls back to the generic label when there is no detail", () => {+ expect(environmentStatusText({ phase: "unsupported", error: null, traceId: null })).toBe(+ "Client not supported",+ );+ });+});diff --git a/apps/mobile/src/features/connection/environmentStatusText.ts b/apps/mobile/src/features/connection/environmentStatusText.tsnew file mode 100644index 00000000000..b3340a2f22b--- /dev/null+++ b/apps/mobile/src/features/connection/environmentStatusText.ts@@ -0,0 +1,15 @@+import {+ connectionStatusText,+ type EnvironmentConnectionPresentation,+} from "@t3tools/client-runtime/connection";++/**+ * Status line for mobile environment rows. Mobile has no tooltip like web, so+ * an unsupported environment shows its compatibility detail, which says+ * whether to update the app or the host.+ */+export function environmentStatusText(connection: EnvironmentConnectionPresentation): string {+ return connection.phase === "unsupported" && connection.error !== null+ ? connection.error+ : connectionStatusText(connection);+}