Skip to content

Commit 935c55b

Browse files
fix(clients): disable incompatible environments during discovery (pingdotgg#11990)
1 parent 7a368fe commit 935c55b

17 files changed

Lines changed: 636 additions & 33 deletions

‎apps/mobile/src/features/cloud/cloudEnvironmentPresentation.test.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EnvironmentId } from "@t3tools/contracts";
1+
import { EnvironmentId, ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts";
22
import type { RelayEnvironmentStatusResponse } from "@t3tools/contracts/relay";
33
import { describe, expect, it } from "vite-plus/test";
44

@@ -24,6 +24,32 @@ function relayStatus(
2424
}
2525

2626
describe("available cloud environment presentation", () => {
27+
it("shows an incompatible discovered server before any connection attempt", () => {
28+
const onlineStatus = relayStatus("online");
29+
const status = {
30+
...onlineStatus,
31+
descriptor: {
32+
environmentId: onlineStatus.environmentId,
33+
label: "Preview server",
34+
platform: { os: "darwin", arch: "arm64" },
35+
serverVersion: "2.0.0",
36+
orchestrationProtocolVersion: ORCHESTRATION_PROTOCOL_VERSION + 1,
37+
capabilities: { repositoryIdentity: true },
38+
},
39+
} satisfies RelayEnvironmentStatusResponse;
40+
expect(
41+
availableCloudEnvironmentPresentation({
42+
isStatusPending: false,
43+
status,
44+
statusError: null,
45+
statusErrorTraceId: null,
46+
}),
47+
).toMatchObject({
48+
connectionState: "unsupported",
49+
statusText: "Client not supported",
50+
});
51+
});
52+
2753
it("presents an online unsaved environment as available, not connected", () => {
2854
expect(
2955
availableCloudEnvironmentPresentation({

‎apps/mobile/src/features/cloud/cloudEnvironmentPresentation.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { RelayEnvironmentStatusResponse } from "@t3tools/contracts/relay";
2-
import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2+
import {
3+
orchestrationProtocolCompatibilityError,
4+
type EnvironmentConnectionPhase,
5+
} from "@t3tools/client-runtime/connection";
36

47
export interface AvailableCloudEnvironmentPresentation {
58
readonly connectionError: string | null;
@@ -14,6 +17,18 @@ export function availableCloudEnvironmentPresentation(input: {
1417
readonly statusError: string | null;
1518
readonly statusErrorTraceId: string | null;
1619
}): AvailableCloudEnvironmentPresentation {
20+
const compatibilityError =
21+
input.status?.descriptor === undefined
22+
? null
23+
: orchestrationProtocolCompatibilityError(input.status.descriptor);
24+
if (compatibilityError !== null) {
25+
return {
26+
connectionError: compatibilityError.message,
27+
connectionErrorTraceId: null,
28+
connectionState: "unsupported",
29+
statusText: "Client not supported",
30+
};
31+
}
1732
if (input.status?.status === "online") {
1833
return {
1934
connectionError: null,

‎apps/mobile/src/features/connection/CloudEnvironmentRows.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,25 @@ function ConnectedCloudEnvironmentRow(props: {
219219
const serverConfig = useAtomValue(
220220
serverEnvironment.configValueAtom(props.environment.environmentId),
221221
);
222-
const enabled = props.environment.isEnabled;
222+
const unsupported = props.environment.connectionState === "unsupported";
223+
const enabled = props.environment.isEnabled && !unsupported;
223224
return (
224225
<Pressable
225226
accessibilityHint="Long press to remove from this device"
226227
onLongPress={props.onRemove}
227228
>
228229
<CloudEnvironmentRowShell
229230
borderTop={props.borderTop}
230-
connectionError={enabled ? props.environment.connectionError : null}
231+
connectionError={enabled || unsupported ? props.environment.connectionError : null}
231232
connectionErrorTraceId={enabled ? props.environment.connectionErrorTraceId : null}
232-
connectionState={enabled ? props.environment.connectionState : "available"}
233+
connectionState={enabled || unsupported ? props.environment.connectionState : "available"}
233234
errorExpanded={props.errorExpanded}
234235
label={props.environment.environmentLabel}
235236
machine={resolveEnvironmentMachineKind(serverConfig)}
236237
onValueChange={props.onSetEnabled}
237238
onToggleError={props.onToggleError}
238-
{...(enabled ? {} : { statusText: "Off" })}
239+
disabled={unsupported}
240+
{...(enabled || unsupported ? {} : { statusText: "Off" })}
239241
value={enabled}
240242
/>
241243
</Pressable>
@@ -270,6 +272,7 @@ function CloudEnvironmentRow(props: {
270272
}
271273
}}
272274
onToggleError={props.onToggleError}
275+
disabled={presentation.connectionState === "unsupported"}
273276
statusText={presentation.statusText}
274277
value={false}
275278
/>

‎apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { serverEnvironment } from "../../state/server";
1919
import { ConnectionStatusDot } from "./ConnectionStatusDot";
2020

2121
function connectionStatusLabel(environment: ConnectedEnvironmentSummary): string | null {
22-
if (!environment.isEnabled) {
22+
if (!environment.isEnabled && environment.connectionState !== "unsupported") {
2323
return "Off";
2424
}
2525
return connectionStatusText({
@@ -46,10 +46,12 @@ export function ConnectionEnvironmentRow(props: {
4646
const serverConfig = useAtomValue(
4747
serverEnvironment.configValueAtom(props.environment.environmentId),
4848
);
49-
const enabled = props.environment.isEnabled;
49+
const unsupported = props.environment.connectionState === "unsupported";
50+
const enabled = props.environment.isEnabled && !unsupported;
5051
const statusLabel = connectionStatusLabel(props.environment);
5152
const statusTraceId = enabled ? props.environment.connectionErrorTraceId : null;
52-
const hasConnectionFailure = enabled && props.environment.connectionError !== null;
53+
const hasConnectionFailure =
54+
(enabled || unsupported) && props.environment.connectionError !== null;
5355
const isRetrying =
5456
enabled &&
5557
(props.environment.connectionState === "connecting" ||
@@ -77,7 +79,7 @@ export function ConnectionEnvironmentRow(props: {
7779
onPress={props.onToggle}
7880
>
7981
<ConnectionStatusDot
80-
state={enabled ? props.environment.connectionState : "available"}
82+
state={enabled || unsupported ? props.environment.connectionState : "available"}
8183
pulse={isRetrying}
8284
size={8}
8385
/>
@@ -133,6 +135,7 @@ export function ConnectionEnvironmentRow(props: {
133135
</View>
134136

135137
<ThemedSwitch
138+
disabled={unsupported}
136139
onValueChange={(next) => props.onSetEnabled(props.environment.environmentId, next)}
137140
value={enabled}
138141
/>

‎apps/mobile/src/state/use-remote-environment-registry.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,16 @@ export function useRemoteConnections() {
128128
const error = Cause.squash(result.cause);
129129
const message =
130130
error instanceof Error ? error.message : "Failed to pair with the environment.";
131-
setPendingConnectionError(message);
131+
if (
132+
error !== null &&
133+
typeof error === "object" &&
134+
"reason" in error &&
135+
error.reason === "unsupported"
136+
) {
137+
Alert.alert("Client not supported", message);
138+
} else {
139+
setPendingConnectionError(message);
140+
}
132141
} else {
133142
appAtomRegistry.set(connectionPairingUrlAtom, "");
134143
}

‎apps/web/src/components/cloud/CloudEnvironmentConnectList.test.tsx‎

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Discovery } from "@t3tools/client-runtime/relay";
22
import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";
3-
import { EnvironmentId } from "@t3tools/contracts";
3+
import { EnvironmentId, ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts";
44
import * as Option from "effect/Option";
55
import { AsyncResult } from "effect/unstable/reactivity";
66
import { act, useState, type ButtonHTMLAttributes, type ReactNode } from "react";
@@ -178,6 +178,84 @@ describe("cloud onboarding discovery", () => {
178178
expect(renderer!.root.findByType("button").children).toEqual(["Add"]);
179179
});
180180

181+
it("keeps incompatible discoveries unselected until the user enables a compatible server", async () => {
182+
const base = linkedMachines.get(newMachineId)!;
183+
const entry = (protocolVersion: number) => ({
184+
...base,
185+
status: Option.some({
186+
environmentId: newMachineId,
187+
endpoint: base.environment.endpoint,
188+
status: "online" as const,
189+
checkedAt: "2026-09-15T00:00:00Z",
190+
descriptor: {
191+
environmentId: newMachineId,
192+
label: base.environment.label,
193+
platform: { os: "linux" as const, arch: "x64" as const },
194+
serverVersion: "1.0.0",
195+
orchestrationProtocolVersion: protocolVersion,
196+
capabilities: { repositoryIdentity: true },
197+
},
198+
}),
199+
});
200+
discovery.listEnvironments.mockResolvedValue(
201+
new Map([[newMachineId, entry(ORCHESTRATION_PROTOCOL_VERSION + 1)]]),
202+
);
203+
const onSelectionChange = vi.fn();
204+
const autoSelectedComputers = new Set<EnvironmentId>();
205+
function Setup() {
206+
const [selectedIds, setSelectedIds] = useState<ReadonlySet<EnvironmentId>>(
207+
new Set([newMachineId]),
208+
);
209+
return (
210+
<CloudEnvironmentConnectRows
211+
primaryEnvironmentId={null}
212+
savedEnvironments={[]}
213+
showSavedEnvironments
214+
selection={{
215+
autoSelectedComputers,
216+
selectedIds,
217+
onChange: (id, checked) => {
218+
onSelectionChange(id, checked);
219+
setSelectedIds((current) => {
220+
const next = new Set(current);
221+
if (checked) next.add(id);
222+
else next.delete(id);
223+
return next;
224+
});
225+
},
226+
}}
227+
/>
228+
);
229+
}
230+
await act(async () => {
231+
renderer = create(<Setup />);
232+
});
233+
expect(discovery.register).not.toHaveBeenCalled();
234+
expect(onSelectionChange).toHaveBeenCalledWith(newMachineId, false);
235+
expect(renderer!.root.findByType("input").props.checked).toBe(false);
236+
expect(renderer!.root.findByType("input").props.disabled).toBe(true);
237+
expect(renderer!.root.findAllByType("span").flatMap((span) => span.children)).toContain(
238+
"Client not supported",
239+
);
240+
await act(async () => {
241+
await renderer!.root.findByType("input").props.onChange({ target: { checked: true } });
242+
});
243+
expect(discovery.register).not.toHaveBeenCalled();
244+
await act(async () =>
245+
publish({
246+
...discovery.state!,
247+
environments: new Map([[newMachineId, entry(ORCHESTRATION_PROTOCOL_VERSION)]]),
248+
}),
249+
);
250+
expect(discovery.register).not.toHaveBeenCalled();
251+
expect(renderer!.root.findByType("input").props.checked).toBe(false);
252+
expect(renderer!.root.findByType("input").props.disabled).toBe(false);
253+
await act(async () => {
254+
await renderer!.root.findByType("input").props.onChange({ target: { checked: true } });
255+
});
256+
expect(discovery.register).toHaveBeenCalledTimes(1);
257+
});
258+
181259
it("connects and selects discovered computers by default without overwriting deselection", async () => {
182260
discovery.listEnvironments.mockResolvedValue(linkedMachines);
183261
const autoSelectedComputers = new Set<EnvironmentId>();

‎apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx‎

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import {
33
type EnvironmentConnectionPresentation,
44
RelayConnectionRegistration,
55
RelayConnectionTarget,
6+
orchestrationProtocolCompatibilityError,
67
} from "@t3tools/client-runtime/connection";
78
import {
89
isAtomCommandInterrupted,
910
squashAtomCommandFailure,
1011
} from "@t3tools/client-runtime/state/runtime";
1112
import type { EnvironmentId } from "@t3tools/contracts";
12-
import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay";
13+
import type {
14+
RelayClientEnvironmentRecord,
15+
RelayEnvironmentStatusResponse,
16+
} from "@t3tools/contracts/relay";
1317
import * as Option from "effect/Option";
1418
import { type ReactNode, useCallback, useEffect, useEffectEvent, useState } from "react";
1519

@@ -29,6 +33,13 @@ import { presentSavedCloudEnvironmentConnection } from "./cloudEnvironmentConnec
2933

3034
const EMPTY_DISCOVERY_REFRESH_INTERVAL_MS = 5_000;
3135

36+
function discoveredCompatibilityError(
37+
status: Option.Option<RelayEnvironmentStatusResponse> | undefined,
38+
) {
39+
const descriptor = status === undefined ? undefined : Option.getOrNull(status)?.descriptor;
40+
return descriptor === undefined ? null : orchestrationProtocolCompatibilityError(descriptor);
41+
}
42+
3243
export interface SavedCloudEnvironmentConnection {
3344
readonly environmentId: EnvironmentId;
3445
readonly connection: EnvironmentConnectionPresentation;
@@ -119,6 +130,12 @@ export function CloudEnvironmentConnectRows({
119130
}, [refreshRelayEnvironments, refreshWhileEmpty, onDiscoveryReady]);
120131

121132
const connectEnvironment = async (environment: RelayClientEnvironmentRecord) => {
133+
if (
134+
discoveredCompatibilityError(
135+
environmentsState.environments.get(environment.environmentId)?.status,
136+
) !== null
137+
)
138+
return false;
122139
setConnectingEnvironmentIds((current) => new Set([...current, environment.environmentId]));
123140
const result = await connectRelayEnvironment(environment);
124141
setConnectingEnvironmentIds((current) => {
@@ -166,8 +183,17 @@ export function CloudEnvironmentConnectRows({
166183
const selectNewComputers = useEffectEvent(() => {
167184
const seen = selection?.autoSelectedComputers;
168185
if (!selection || !seen) return;
169-
for (const { environment } of visibleEnvironments) {
186+
for (const { environment, status, availability } of visibleEnvironments) {
170187
const id = environment.environmentId;
188+
if (availability === "checking") continue;
189+
if (
190+
discoveredCompatibilityError(status) !== null ||
191+
savedById.get(id)?.connection.phase === "unsupported"
192+
) {
193+
seen.add(id);
194+
if (selection.selectedIds.has(id)) selection.onChange(id, false);
195+
continue;
196+
}
171197
if (seen.has(id)) continue;
172198
seen.add(id);
173199
selection.onChange(id, true);
@@ -265,11 +291,20 @@ export function CloudEnvironmentConnectRows({
265291
return empty;
266292
}
267293

268-
return visibleEnvironments.map(({ environment, availability, error }) => {
294+
return visibleEnvironments.map(({ environment, availability, error, status }) => {
269295
const savedEnvironment = savedById.get(environment.environmentId);
270-
const savedConnection = savedEnvironment
271-
? presentSavedCloudEnvironmentConnection(savedEnvironment.connection)
272-
: null;
296+
const compatibilityError = discoveredCompatibilityError(status);
297+
const unsupported =
298+
compatibilityError !== null || savedEnvironment?.connection.phase === "unsupported";
299+
const savedConnection = unsupported
300+
? presentSavedCloudEnvironmentConnection({
301+
phase: "unsupported",
302+
error: compatibilityError?.message ?? savedEnvironment?.connection.error ?? null,
303+
traceId: null,
304+
})
305+
: savedEnvironment
306+
? presentSavedCloudEnvironmentConnection(savedEnvironment.connection)
307+
: null;
273308
const dotClassName = savedConnection
274309
? savedConnection.tone === "connected"
275310
? "bg-success"
@@ -302,9 +337,10 @@ export function CloudEnvironmentConnectRows({
302337
className="flex cursor-pointer items-center gap-3 rounded-lg border border-border bg-background px-3 py-2.5 has-disabled:cursor-default"
303338
>
304339
<Checkbox
305-
checked={selection.selectedIds.has(environment.environmentId)}
306-
disabled={connectingEnvironmentIds.has(environment.environmentId)}
340+
checked={!unsupported && selection.selectedIds.has(environment.environmentId)}
341+
disabled={unsupported || connectingEnvironmentIds.has(environment.environmentId)}
307342
onCheckedChange={async (checked) => {
343+
if (unsupported) return;
308344
selection.onChange(environment.environmentId, checked);
309345
if (checked && !savedEnvironment) {
310346
const connected = await connectEnvironment(environment);

0 commit comments

Comments
 (0)