From 7fc31cecb4533b9ee3b37dbc9f097ae47cb958b3 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Sat, 31 Oct 2026 23:16:43 +0000 Subject: [PATCH 1/3] fix(mobile): Retry now on a switched-off environment switches it back on On mobile, the "Retry now" button in the connection notice on the terminal, review and file preview screens did nothing for an environment that was switched off: the connection supervisor ignores retries while the environment is disabled. A new useRetryEnvironment hook switches a disabled environment back on instead of retrying it, matching the web fix in #24691, and the three screens use it. A hook test covers both cases. Co-Authored-By: Claude Opus 5.5 --- .../connection/useRetryEnvironment.test.tsx | 108 ++++++++++++++++++ .../connection/useRetryEnvironment.ts | 17 +++ .../files/WorkspaceFilePreviewError.tsx | 5 +- .../src/features/review/ReviewSheet.tsx | 5 +- .../terminal/ThreadTerminalRouteScreen.tsx | 4 +- apps/mobile/vite.config.ts | 1 + 6 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 apps/mobile/src/features/connection/useRetryEnvironment.test.tsx create mode 100644 apps/mobile/src/features/connection/useRetryEnvironment.ts diff --git a/apps/mobile/src/features/connection/useRetryEnvironment.test.tsx b/apps/mobile/src/features/connection/useRetryEnvironment.test.tsx new file mode 100644 index 0000000000000..da94dedf2e78a --- /dev/null +++ b/apps/mobile/src/features/connection/useRetryEnvironment.test.tsx @@ -0,0 +1,108 @@ +import { RegistryContext } from "@effect/atom-react"; +import { EnvironmentId } from "@t3tools/contracts"; +import { + EnvironmentRegistry, + PrimaryConnectionTarget, + type ConnectionCatalogEntry, +} from "@t3tools/client-runtime/connection"; +import * as Effect from "effect/Effect"; +import * as Option from "effect/Option"; +import * as SubscriptionRef from "effect/SubscriptionRef"; +import { AtomRegistry } from "effect/reactivity"; +import { act, useLayoutEffect } from "react"; +import { createRoot } from "react-dom/client"; +import { describe, expect, it } from "@effect/vitest"; +import { vi } from "vite-plus/test"; + +const fixture = vi.hoisted(() => ({ + environment: undefined as + | Pick< + EnvironmentRegistry.EnvironmentRegistry["Service"], + "entries" | "retryNow" | "setEnabled" + > + | undefined, +})); + +vi.mock("../../connection/runtime", async () => { + const { Atom } = await import("effect/reactivity"); + const Layer = await import("effect/Layer"); + const { EnvironmentRegistry } = await import("@t3tools/client-runtime/connection"); + return { + connectionAtomRuntime: Atom.runtime( + Layer.suspend(() => + Layer.succeed( + EnvironmentRegistry.EnvironmentRegistry, + fixture.environment as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"], + ), + ), + ), + }; +}); + +import { useRetryEnvironment } from "./useRetryEnvironment"; + +const environmentId = EnvironmentId.make("retry-environment"); + +describe("useRetryEnvironment", () => { + it.effect.each([ + { enabled: false, retries: 0 }, + { enabled: true, retries: 1 }, + ])("Retry now with the environment enabled: $enabled", ({ enabled, retries }) => + Effect.gen(function* () { + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; + const target = new PrimaryConnectionTarget({ + environmentId, + label: "Retry", + httpBaseUrl: "https://retry.test", + wsBaseUrl: "wss://retry.test", + }); + const entries = yield* SubscriptionRef.make< + ReadonlyMap + >(new Map([[environmentId, { target, profile: Option.none(), enabled }]])); + let retryCount = 0; + fixture.environment = { + entries, + retryNow: () => + Effect.sync(() => { + retryCount += 1; + }), + setEnabled: (id, next) => + SubscriptionRef.update(entries, (current) => + new Map(current).set(id, { ...current.get(id)!, enabled: next }), + ), + }; + + const registry = AtomRegistry.make(); + const root = createRoot(document.createElement("div")); + using _mounted = { + [Symbol.dispose]() { + act(() => root.unmount()); + registry.dispose(); + }, + }; + let retryEnvironment!: ReturnType; + function Probe() { + const value = useRetryEnvironment(); + useLayoutEffect(() => { + retryEnvironment = value; + }); + return null; + } + yield* Effect.promise(async () => { + await act(async () => + root.render( + + + , + ), + ); + await act(async () => { + await retryEnvironment(environmentId); + }); + }); + + const entry = (yield* SubscriptionRef.get(entries)).get(environmentId); + expect({ enabled: entry?.enabled, retries: retryCount }).toEqual({ enabled: true, retries }); + }), + ); +}); diff --git a/apps/mobile/src/features/connection/useRetryEnvironment.ts b/apps/mobile/src/features/connection/useRetryEnvironment.ts new file mode 100644 index 0000000000000..b5d8edc749230 --- /dev/null +++ b/apps/mobile/src/features/connection/useRetryEnvironment.ts @@ -0,0 +1,17 @@ +import { useAtomValue } from "@effect/atom-react"; +import type { EnvironmentId } from "@t3tools/contracts"; + +import { environmentCatalog } from "../../connection/catalog"; +import { useAtomCommand } from "../../state/use-atom-command"; + +export function useRetryEnvironment() { + const catalog = useAtomValue(environmentCatalog.catalogValueAtom); + const retryNow = useAtomCommand(environmentCatalog.retryNow, "environment retry"); + const setEnabled = useAtomCommand(environmentCatalog.setEnabled, "environment toggle"); + + return (environmentId: EnvironmentId) => + // A retry does nothing while the environment is switched off. + catalog.entries.get(environmentId)?.enabled === false + ? setEnabled({ environmentId, enabled: true }) + : retryNow(environmentId); +} diff --git a/apps/mobile/src/features/files/WorkspaceFilePreviewError.tsx b/apps/mobile/src/features/files/WorkspaceFilePreviewError.tsx index 63c3e7be0c65e..eccac90d9abea 100644 --- a/apps/mobile/src/features/files/WorkspaceFilePreviewError.tsx +++ b/apps/mobile/src/features/files/WorkspaceFilePreviewError.tsx @@ -2,11 +2,10 @@ import type { EnvironmentId } from "@t3tools/contracts"; import { View } from "react-native"; import { EmptyState } from "../../components/ui/EmptyState"; -import { environmentCatalog } from "../../connection/catalog"; import type { AssetUrlFailureReason } from "../../state/asset-url-state"; -import { useAtomCommand } from "../../state/use-atom-command"; import { useEnvironmentPresentation } from "../../state/presentation"; import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice"; +import { useRetryEnvironment } from "../connection/useRetryEnvironment"; export function WorkspaceFilePreviewError(props: { readonly environmentId: EnvironmentId | null; @@ -15,7 +14,7 @@ export function WorkspaceFilePreviewError(props: { }) { const { environmentId, onRetry } = props; const environment = useEnvironmentPresentation(environmentId); - const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry"); + const retryEnvironment = useRetryEnvironment(); const retryConnection = () => { if (environmentId !== null) void retryEnvironment(environmentId); onRetry(); diff --git a/apps/mobile/src/features/review/ReviewSheet.tsx b/apps/mobile/src/features/review/ReviewSheet.tsx index 08a2fe5795889..2f9cf41f25751 100644 --- a/apps/mobile/src/features/review/ReviewSheet.tsx +++ b/apps/mobile/src/features/review/ReviewSheet.tsx @@ -31,12 +31,11 @@ import { SymbolView } from "../../components/ui/AppSymbol"; import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader"; import { ScreenContent } from "../../components/ui/ScreenContent"; import { cn } from "../../lib/cn"; -import { environmentCatalog } from "../../connection/catalog"; import { useEnvironmentPresentation } from "../../state/presentation"; -import { useAtomCommand } from "../../state/use-atom-command"; import { useUniwindTheme } from "../../lib/useUniwindTheme"; import { useThreadDraftForThread } from "../../state/use-thread-composer-state"; import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice"; +import { useRetryEnvironment } from "../connection/useRetryEnvironment"; import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider"; import { useAdaptiveWorkspaceLayout, @@ -435,7 +434,7 @@ export function ReviewSheet(props: ReviewSheetProps) { const headerIcon = String(useUniwindTheme()["--color-icon"]); const { environmentId, threadId } = props.route.params; const environment = useEnvironmentPresentation(environmentId); - const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry"); + const retryEnvironment = useRetryEnvironment(); const isEnvironmentReady = environment.presentation?.connection.phase === "connected"; const { draftMessage, draftContext } = useThreadDraftForThread({ environmentId, threadId }); const reviewCache = useReviewCacheForThread({ environmentId, threadId }); diff --git a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx index 016b75cfb3056..f09ce5cf428a0 100644 --- a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx +++ b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx @@ -40,7 +40,6 @@ import { LoadingScreen } from "../../components/LoadingScreen"; import { ScreenContent } from "../../components/ui/ScreenContent"; import { Button } from "../../components/ui/Button"; import { IconButton } from "../../components/ui/IconButton"; -import { environmentCatalog } from "../../connection/catalog"; import { useEnvironmentPresentation } from "../../state/presentation"; import { terminalEnvironment } from "../../state/terminal"; import { environmentSession, readEnvironmentScope } from "../../state/session"; @@ -64,6 +63,7 @@ import { import { useThreadSelection } from "../../state/use-thread-selection"; import { useSelectedThreadProjection } from "../../state/use-thread-detail"; import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice"; +import { useRetryEnvironment } from "../connection/useRetryEnvironment"; import { TerminalSurface, type TerminalSurfaceHandle } from "./NativeTerminalSurface"; import { getMobileTerminalTheme } from "./terminalTheme"; import { useTerminalExitNavigation } from "./useTerminalExitNavigation"; @@ -400,7 +400,7 @@ function ThreadTerminal(props: { const navigation = useNavigation(); const writeTerminal = useAtomCommand(terminalEnvironment.write, "terminal write"); const clearTerminal = useAtomCommand(terminalEnvironment.clear, "terminal clear"); - const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry"); + const retryEnvironment = useRetryEnvironment(); const selectedThreadDetail = useSelectedThreadProjection(); const selectedThreadDetailWorktreePath = selectedThreadDetail?.projection.thread.worktreePath ?? null; diff --git a/apps/mobile/vite.config.ts b/apps/mobile/vite.config.ts index b64dc1c4e2a12..b6b3a7a380d12 100644 --- a/apps/mobile/vite.config.ts +++ b/apps/mobile/vite.config.ts @@ -38,6 +38,7 @@ const reactTests = [ "src/features/threads/use-thread-list-now.test.tsx", "src/features/home/home-list-options.test.tsx", "src/features/workspace/useSearchScrollRestoration.test.tsx", + "src/features/connection/useRetryEnvironment.test.tsx", "src/features/connection/ConnectionsNewRouteScreen.test.tsx", ]; From 10a7f2ad10d1e2108cb360f4d586f23d2a574360 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Tue, 10 Nov 2026 10:52:51 +0000 Subject: [PATCH 2/3] fix(mobile): Reconnect on a switched-off environment switches it back on The floating "not connected" pill and the other Reconnect controls called retryNow, which does nothing while the environment is switched off. They now use useRetryEnvironment, the same helper as Retry now on the terminal, review and file preview, so they switch the environment back on. Co-Authored-By: Claude Opus 5.5 --- .../connection/useConnectionController.ts | 4 - .../use-remote-environment-registry.test.tsx | 129 ++++++++++++++++++ .../state/use-remote-environment-registry.ts | 4 +- apps/mobile/vite.config.ts | 1 + 4 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 apps/mobile/src/state/use-remote-environment-registry.test.tsx diff --git a/apps/mobile/src/features/connection/useConnectionController.ts b/apps/mobile/src/features/connection/useConnectionController.ts index 626892d447569..64deaaf8d1e72 100644 --- a/apps/mobile/src/features/connection/useConnectionController.ts +++ b/apps/mobile/src/features/connection/useConnectionController.ts @@ -38,7 +38,6 @@ export function useConnectionController() { const updateBearer = useAtomCommand(updateBearerConnection, { reportFailure: false }); const registerEnvironment = useAtomCommand(environmentCatalog.register, "environment register"); const removeEnvironmentMutation = useAtomCommand(environmentCatalog.remove, "environment remove"); - const retryEnvironmentMutation = useAtomCommand(environmentCatalog.retryNow, "environment retry"); const setEnvironmentEnabledMutation = useAtomCommand( environmentCatalog.setEnabled, "environment toggle", @@ -84,8 +83,6 @@ export function useConnectionController() { ); const removeEnvironment = (environmentId: EnvironmentId) => removeEnvironmentMutation(environmentId); - const retryEnvironment = (environmentId: EnvironmentId) => - retryEnvironmentMutation(environmentId); const setEnvironmentEnabled = (environmentId: EnvironmentId, enabled: boolean) => setEnvironmentEnabledMutation({ environmentId, enabled }); const updateEnvironment = ( @@ -111,7 +108,6 @@ export function useConnectionController() { connectPairingUrl, connectRelayEnvironment, removeEnvironment, - retryEnvironment, setEnvironmentEnabled, updateEnvironment, refreshRelayEnvironments, diff --git a/apps/mobile/src/state/use-remote-environment-registry.test.tsx b/apps/mobile/src/state/use-remote-environment-registry.test.tsx new file mode 100644 index 0000000000000..84276393944e2 --- /dev/null +++ b/apps/mobile/src/state/use-remote-environment-registry.test.tsx @@ -0,0 +1,129 @@ +import { RegistryContext } from "@effect/atom-react"; +import { EnvironmentId } from "@t3tools/contracts"; +import { + EnvironmentRegistry, + EnvironmentSupervisor, + AVAILABLE_CONNECTION_STATE, + PrimaryConnectionTarget, + type SupervisorConnectionState, + type PreparedConnection, + type ConnectionCatalogEntry, + type NetworkStatus, +} from "@t3tools/client-runtime/connection"; +import type { RpcSession } from "@t3tools/client-runtime/rpc"; +import * as Effect from "effect/Effect"; +import * as Option from "effect/Option"; +import * as Stream from "effect/Stream"; +import * as SubscriptionRef from "effect/SubscriptionRef"; +import { AtomRegistry } from "effect/reactivity"; +import { act } from "react"; +import { createRoot } from "react-dom/client"; +import { expect, it } from "@effect/vitest"; +import { vi } from "vite-plus/test"; + +const fixture = vi.hoisted(() => ({ + environment: undefined as EnvironmentRegistry.EnvironmentRegistry["Service"] | undefined, +})); + +vi.mock("react-native", () => ({})); +vi.mock("@react-navigation/native", () => ({ useNavigation: () => ({}) })); +vi.mock("../features/cloud/publicConfig", () => ({ hasCloudPublicConfig: () => false })); +vi.mock("../connection/runtime", async () => { + const { Atom } = await import("effect/reactivity"); + const Layer = await import("effect/Layer"); + const { EnvironmentRegistry } = await import("@t3tools/client-runtime/connection"); + return { + connectionAtomRuntime: Atom.runtime( + Layer.suspend(() => + Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, fixture.environment!), + ), + ), + }; +}); + +import { useRemoteConnections } from "./use-remote-environment-registry"; + +const environmentId = EnvironmentId.make("switched-off-environment"); + +it.effect("Reconnect switches a switched-off environment back on", () => + Effect.gen(function* () { + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; + const target = new PrimaryConnectionTarget({ + environmentId, + label: "Switched off", + httpBaseUrl: "https://off.test", + wsBaseUrl: "wss://off.test", + }); + const entries = yield* SubscriptionRef.make>( + new Map([[environmentId, { target, profile: Option.none(), enabled: false }]]), + ); + const state = yield* SubscriptionRef.make( + AVAILABLE_CONNECTION_STATE, + ); + const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({ + target, + state, + session: yield* SubscriptionRef.make(Option.none()), + prepared: yield* SubscriptionRef.make(Option.none()), + connect: Effect.void, + disconnect: Effect.void, + retryNow: Effect.void, + }); + const environment = { + entries, + networkStatus: yield* SubscriptionRef.make("online"), + followStream: (_id, stream) => + Stream.provideService(stream, EnvironmentSupervisor.EnvironmentSupervisor, supervisor), + // Like the real supervisor, a retry does nothing while the environment is switched off. + retryNow: () => Effect.void, + setEnabled: (id, enabled) => + Effect.gen(function* () { + yield* SubscriptionRef.update(entries, (current) => + new Map(current).set(id, { ...current.get(id)!, enabled }), + ); + yield* SubscriptionRef.update(state, (current): SupervisorConnectionState => ({ + ...current, + desired: enabled, + phase: enabled ? "connecting" : "available", + })); + }), + } satisfies Pick< + EnvironmentRegistry.EnvironmentRegistry["Service"], + "entries" | "networkStatus" | "followStream" | "retryNow" | "setEnabled" + >; + fixture.environment = + environment as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]; + + const registry = AtomRegistry.make(); + const root = createRoot(document.createElement("div")); + using _mounted = { + [Symbol.dispose]() { + act(() => root.unmount()); + registry.dispose(); + }, + }; + let connections!: ReturnType; + function Probe() { + connections = useRemoteConnections(); + return null; + } + yield* Effect.promise(async () => { + await act(async () => + root.render( + + + , + ), + ); + expect(connections.connectedEnvironments).toMatchObject([ + { environmentId, isEnabled: false, connectionState: "available" }, + ]); + await act(async () => { + await connections.onReconnectEnvironment(environmentId); + }); + expect(connections.connectedEnvironments).toMatchObject([ + { environmentId, isEnabled: true, connectionState: "connecting" }, + ]); + }); + }), +); diff --git a/apps/mobile/src/state/use-remote-environment-registry.ts b/apps/mobile/src/state/use-remote-environment-registry.ts index c75456461bf64..61b0cc2536a53 100644 --- a/apps/mobile/src/state/use-remote-environment-registry.ts +++ b/apps/mobile/src/state/use-remote-environment-registry.ts @@ -9,6 +9,7 @@ import { runAtomCommand } from "@t3tools/client-runtime/state/runtime"; import { hasCloudPublicConfig } from "../features/cloud/publicConfig"; import { useConnectionController } from "../features/connection/useConnectionController"; +import { useRetryEnvironment } from "../features/connection/useRetryEnvironment"; import { environmentPresentations } from "./presentation"; import { useWorkspaceConnectionState, useWorkspaceEnvironments } from "./workspace"; import type { SavedRemoteConnection } from "../lib/connection"; @@ -166,8 +167,7 @@ export function useRemoteConnections() { const onConnectPress = (pairingUrl?: string, expectedEnvironmentId?: EnvironmentId) => pairEnvironment(pairingUrl ?? connectionPairingUrl, expectedEnvironmentId); - const onReconnectEnvironment = (environmentId: EnvironmentId) => - controller.retryEnvironment(environmentId); + const onReconnectEnvironment = useRetryEnvironment(); const onSetEnvironmentEnabled = (environmentId: EnvironmentId, enabled: boolean) => controller.setEnvironmentEnabled(environmentId, enabled); const onUpdateEnvironment = ( diff --git a/apps/mobile/vite.config.ts b/apps/mobile/vite.config.ts index d499b4a804d3e..71b4c96648b4a 100644 --- a/apps/mobile/vite.config.ts +++ b/apps/mobile/vite.config.ts @@ -8,6 +8,7 @@ const reactTests = [ "src/features/threads/new-task-flow-provider.test.tsx", "src/features/layout/workspace/workspace-tabs-state.test.ts", "src/state/use-thread-pr.demand.test.tsx", + "src/state/use-remote-environment-registry.test.tsx", "src/features/threads/git/GitBranchesSheet.occupancy.test.tsx", "src/features/files/useFileTreeEntries.test.tsx", "src/features/projects/AddProjectScreen.test.ts", From 0e8284b2e65beeb73124da0d835611c934947111 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Tue, 10 Nov 2026 11:29:55 +0000 Subject: [PATCH 3/3] test(mobile): drop the Reconnect test that repeats the retry hook's case The Reconnect pill now calls useRetryEnvironment directly, so its switched-off case is the one useRetryEnvironment.test.tsx already covers. Co-Authored-By: Claude Opus 5.5 --- .../use-remote-environment-registry.test.tsx | 129 ------------------ apps/mobile/vite.config.ts | 1 - 2 files changed, 130 deletions(-) delete mode 100644 apps/mobile/src/state/use-remote-environment-registry.test.tsx diff --git a/apps/mobile/src/state/use-remote-environment-registry.test.tsx b/apps/mobile/src/state/use-remote-environment-registry.test.tsx deleted file mode 100644 index 84276393944e2..0000000000000 --- a/apps/mobile/src/state/use-remote-environment-registry.test.tsx +++ /dev/null @@ -1,129 +0,0 @@ -import { RegistryContext } from "@effect/atom-react"; -import { EnvironmentId } from "@t3tools/contracts"; -import { - EnvironmentRegistry, - EnvironmentSupervisor, - AVAILABLE_CONNECTION_STATE, - PrimaryConnectionTarget, - type SupervisorConnectionState, - type PreparedConnection, - type ConnectionCatalogEntry, - type NetworkStatus, -} from "@t3tools/client-runtime/connection"; -import type { RpcSession } from "@t3tools/client-runtime/rpc"; -import * as Effect from "effect/Effect"; -import * as Option from "effect/Option"; -import * as Stream from "effect/Stream"; -import * as SubscriptionRef from "effect/SubscriptionRef"; -import { AtomRegistry } from "effect/reactivity"; -import { act } from "react"; -import { createRoot } from "react-dom/client"; -import { expect, it } from "@effect/vitest"; -import { vi } from "vite-plus/test"; - -const fixture = vi.hoisted(() => ({ - environment: undefined as EnvironmentRegistry.EnvironmentRegistry["Service"] | undefined, -})); - -vi.mock("react-native", () => ({})); -vi.mock("@react-navigation/native", () => ({ useNavigation: () => ({}) })); -vi.mock("../features/cloud/publicConfig", () => ({ hasCloudPublicConfig: () => false })); -vi.mock("../connection/runtime", async () => { - const { Atom } = await import("effect/reactivity"); - const Layer = await import("effect/Layer"); - const { EnvironmentRegistry } = await import("@t3tools/client-runtime/connection"); - return { - connectionAtomRuntime: Atom.runtime( - Layer.suspend(() => - Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, fixture.environment!), - ), - ), - }; -}); - -import { useRemoteConnections } from "./use-remote-environment-registry"; - -const environmentId = EnvironmentId.make("switched-off-environment"); - -it.effect("Reconnect switches a switched-off environment back on", () => - Effect.gen(function* () { - (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; - const target = new PrimaryConnectionTarget({ - environmentId, - label: "Switched off", - httpBaseUrl: "https://off.test", - wsBaseUrl: "wss://off.test", - }); - const entries = yield* SubscriptionRef.make>( - new Map([[environmentId, { target, profile: Option.none(), enabled: false }]]), - ); - const state = yield* SubscriptionRef.make( - AVAILABLE_CONNECTION_STATE, - ); - const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({ - target, - state, - session: yield* SubscriptionRef.make(Option.none()), - prepared: yield* SubscriptionRef.make(Option.none()), - connect: Effect.void, - disconnect: Effect.void, - retryNow: Effect.void, - }); - const environment = { - entries, - networkStatus: yield* SubscriptionRef.make("online"), - followStream: (_id, stream) => - Stream.provideService(stream, EnvironmentSupervisor.EnvironmentSupervisor, supervisor), - // Like the real supervisor, a retry does nothing while the environment is switched off. - retryNow: () => Effect.void, - setEnabled: (id, enabled) => - Effect.gen(function* () { - yield* SubscriptionRef.update(entries, (current) => - new Map(current).set(id, { ...current.get(id)!, enabled }), - ); - yield* SubscriptionRef.update(state, (current): SupervisorConnectionState => ({ - ...current, - desired: enabled, - phase: enabled ? "connecting" : "available", - })); - }), - } satisfies Pick< - EnvironmentRegistry.EnvironmentRegistry["Service"], - "entries" | "networkStatus" | "followStream" | "retryNow" | "setEnabled" - >; - fixture.environment = - environment as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]; - - const registry = AtomRegistry.make(); - const root = createRoot(document.createElement("div")); - using _mounted = { - [Symbol.dispose]() { - act(() => root.unmount()); - registry.dispose(); - }, - }; - let connections!: ReturnType; - function Probe() { - connections = useRemoteConnections(); - return null; - } - yield* Effect.promise(async () => { - await act(async () => - root.render( - - - , - ), - ); - expect(connections.connectedEnvironments).toMatchObject([ - { environmentId, isEnabled: false, connectionState: "available" }, - ]); - await act(async () => { - await connections.onReconnectEnvironment(environmentId); - }); - expect(connections.connectedEnvironments).toMatchObject([ - { environmentId, isEnabled: true, connectionState: "connecting" }, - ]); - }); - }), -); diff --git a/apps/mobile/vite.config.ts b/apps/mobile/vite.config.ts index 71b4c96648b4a..d499b4a804d3e 100644 --- a/apps/mobile/vite.config.ts +++ b/apps/mobile/vite.config.ts @@ -8,7 +8,6 @@ const reactTests = [ "src/features/threads/new-task-flow-provider.test.tsx", "src/features/layout/workspace/workspace-tabs-state.test.ts", "src/state/use-thread-pr.demand.test.tsx", - "src/state/use-remote-environment-registry.test.tsx", "src/features/threads/git/GitBranchesSheet.occupancy.test.tsx", "src/features/files/useFileTreeEntries.test.tsx", "src/features/projects/AddProjectScreen.test.ts",