Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): restore full-page remote connection management
Xubin Ren94c137511a48
diff --git a/docs/guides/remote-instances.md b/docs/guides/remote-instances.mdindex 703d7c20d..1e4d5fb81 100644--- a/docs/guides/remote-instances.md+++ b/docs/guides/remote-instances.md@@ -255,11 +255,12 @@ opens upward and shows the computer name, recent hosts, and **Manage connectionsWith the sidebar collapsed, the icon still opens the same menu. A check marksthe host you are viewing; a separate green dot marks an established connection.Saved but disconnected hosts stay gray, and connecting or failed hosts have-distinct progress/error indicators. **Manage connections…** opens a side panel+distinct progress/error indicators. **Manage connections…** opens a full page in+the main content area beside the existing sidebar,without switching to Local, changing the route, or disconnecting the server.-Closing it returns to the same view and draft. The panel uses the same connection+**Back** returns to the same view and draft. The page uses the same connectionstates with text labels, so color is never the only way to distinguish them.-Selecting a host in the panel switches only after its view is ready; a failed+Selecting a host on the page switches only after its view is ready; a failedattempt leaves the original host selected. Remoteconnection setup is hidden inside the embedded remote view, and connecting backto the same gateway is rejected rather than creating a nested local session.diff --git a/webui/src/App.tsx b/webui/src/App.tsxindex 48701b228..7ef310c24 100644--- a/webui/src/App.tsx+++ b/webui/src/App.tsx@@ -1114,6 +1114,8 @@ function Shell({const remoteConnections = useRemoteConnections();const localActive = remoteConnections?.localActive !== false;const managingConnections = remoteConnections?.managing === true;+ const remoteConnectionsRef = useRef(remoteConnections);+ remoteConnectionsRef.current = remoteConnections;const { client, getToken } = useClient();const { theme, toggle } = useTheme();const {@@ -1275,6 +1277,9 @@ function Shell({const navigate = useCallback((route: ShellRoute, options?: { replace?: boolean }) => {const leave = () => {+ // Navigating the local sidebar is an explicit choice of a local view.+ // Merely opening global connection management does not switch hosts.+ if (remoteConnectionsRef.current?.managing) remoteConnectionsRef.current.selectLocal();setActiveKey(route.activeKey);setView(route.view);setSettingsInitialSection(route.settingsSection);@@ -2707,11 +2712,11 @@ function Shell({const sidebarProps = {sessions: sidebarTopicSessions,temporarySessions: temporarySessionList,- activeKey: view === "chat"+ activeKey: !managingConnections && view === "chat"? (temporaryChatActive ? activeKey : activeSidebarKey): null,loading,- newChatActive: view === "chat" && activeKey === null,+ newChatActive: !managingConnections && view === "chat" && activeKey === null,onNewChat,onSelect: onSelectSidebarItem,onCloseTemporaryChat,@@ -2737,7 +2742,7 @@ function Shell({onOpenSkills,onSettingsIntent,onOpenSearch: onOpenSessionSearch,- activeUtility: view === "apps" || view === "automations" || view === "skills" || view === "channels" ? view : null,+ activeUtility: !managingConnections && (view === "apps" || view === "automations" || view === "skills" || view === "channels") ? view : null,onToggleArchived,pinnedKeys: sidebarPinnedTabKeys,archivedKeys: sidebarArchivedTabKeys,@@ -2766,7 +2771,7 @@ function Shell({return (<ThemeProvider theme={theme}>- <StarPrompt ready={localActive && !loading && !sidebarStateLoading} />+ <StarPrompt ready={localActive && !managingConnections && !loading && !sidebarStateLoading} /><divclassName={cn("relative h-full w-full overflow-hidden",@@ -2887,13 +2892,15 @@ function Shell({"relative flex h-full min-w-0 flex-1 flex-col overflow-hidden bg-background",)}>+ <div className={cn("absolute inset-0 flex flex-col", managingConnections && "hidden")}+ aria-hidden={managingConnections || undefined} {...(managingConnections ? { inert: "" } : {})}>{(view === "chat" || chatVisited) && <divclassName={cn("absolute inset-0 flex flex-col",view !== "chat" && "hidden",)}>- <ThreadVisibilityContext.Provider value={localActive && view === "chat"}>+ <ThreadVisibilityContext.Provider value={localActive && !managingConnections && view === "chat"}><Suspense fallback={<StartupShell embedded />}><PaneWorkbenchpanes={renderedWorkbenchPanes}@@ -3069,6 +3076,14 @@ function Shell({</Suspense>}</div>)}+ </div>+ {managingConnections && <div className="absolute inset-0 flex flex-col">+ <RemoteConnectionsPage+ mainNavigationExpanded={showMainSidebar && hostSidebarOpen}+ hostChromeInset={showHostChrome}+ onBackToChat={() => remoteConnections?.closeManagement()}+ />+ </div>}</main></div>diff --git a/webui/src/components/remote/RemoteConnectionsPage.tsx b/webui/src/components/remote/RemoteConnectionsPage.tsxindex 6f8d2b04a..ecfde0272 100644--- a/webui/src/components/remote/RemoteConnectionsPage.tsx+++ b/webui/src/components/remote/RemoteConnectionsPage.tsx@@ -24,10 +24,9 @@ const emptyProfile = (): Omit<RemoteProfile, "id" | "connected"> => ({});/** The page is a server directory. Add/edit/first-use verification share one dialog. */-export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChromeInset = false, inPanel = false, onBackToChat }: {+export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChromeInset = false, onBackToChat }: {mainNavigationExpanded?: boolean;hostChromeInset?: boolean;- inPanel?: boolean;onBackToChat: () => void;}) {const { t } = useTranslation();@@ -60,6 +59,8 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChroconst optionsId = useId();const statusId = useId();const refresh = connections?.refresh;+ const page = useRef<HTMLDivElement>(null);+ useEffect(() => { if (connections?.managing) page.current?.focus({ preventScroll: true }); }, [connections?.managing]);// Keep confirmation content intact during Radix's exit animation.useEffect(() => { if (removing) lastRemoval.current = removing; }, [removing]);@@ -247,18 +248,17 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChrosetError(""); setErrorCode(""); setSSHOptions(true);};- return <div className="flex min-h-0 flex-1 flex-col overflow-hidden bg-settings-canvas">+ return <div ref={page} tabIndex={-1} role="region" aria-label={t("remote.title")} className="flex min-h-0 flex-1 flex-col overflow-hidden bg-settings-canvas outline-none"><div className="min-w-0 flex-1 overflow-y-auto [scrollbar-gutter:stable]"><div data-settings-section="remote" data-main-navigation-expanded={mainNavigationExpanded}className={cn("settings-grid settings-feature-page mx-auto w-full animate-in fade-in-0 slide-in-from-bottom-1 py-6 duration-200 ease-out motion-reduce:animate-none sm:py-8 lg:py-12",- hostChromeInset && "pt-[4.25rem] sm:pt-[4.25rem] lg:pt-[4.75rem]",- inPanel && "px-6 py-4 sm:py-4 lg:py-4 [--settings-margin:0px] [--settings-inset:16px]")}>- {!inPanel && <div className="settings-feature-header mb-7">- <Button variant="ghost" size="sm" className="touch-target mb-4 gap-1 lg:hidden" onClick={onBackToChat}>- <ChevronLeft className="h-4 w-4" />{t("settings.backToChat")}+ hostChromeInset && "pt-[4.25rem] sm:pt-[4.25rem] lg:pt-[4.75rem]")}>+ <div className="settings-feature-header mb-7">+ <Button variant="ghost" size="sm" className={cn("touch-target mb-4 gap-1", !connections.managing && "lg:hidden")} onClick={onBackToChat}>+ <ChevronLeft className="h-4 w-4" />{t(connections.managing ? "remote.back" : "settings.backToChat")}</Button><h1 className="text-[24px] font-normal leading-tight tracking-normal text-foreground sm:text-[28px]">{t("remote.title")}</h1>- </div>}+ </div><div className="settings-stack"><p className="settings-list-inset text-[13px] leading-6 text-muted-foreground">{t("remote.description")}</p>{directory?.available && <>diff --git a/webui/src/components/remote/RemoteInstances.tsx b/webui/src/components/remote/RemoteInstances.tsxindex 9a81f1cf0..26bac669f 100644--- a/webui/src/components/remote/RemoteInstances.tsx+++ b/webui/src/components/remote/RemoteInstances.tsx@@ -2,13 +2,11 @@ import { createContext, useContext, useEffect, useLayoutEffect, useRef, useStateimport { Loader2, PlugZap } from "lucide-react";import { useTranslation } from "react-i18next";import { Button } from "@/components/ui/button";-import { Sheet, SheetContent, SheetTitle } from "@/components/ui/sheet";import { needsRemoteSetup, type RemoteDirectory } from "@/lib/remote-instances";import { useHostSessions } from "./useHostSessions";import { HostNavigationContext, HostSwitcher, RemoteHostMenu, type HostPicker } from "./HostSwitcher";import { useSidebarHostBridge } from "./useSidebarHostBridge";import { readPairReturn, subscribePairReturn } from "@/lib/remote-pair-return";-import { RemoteConnectionsPage } from "./RemoteConnectionsPage";import type { HostConnectionState } from "./HostConnectionStatus";const RemoteContext = createContext<{@@ -17,6 +15,7 @@ const RemoteContext = createContext<{activeHostId: string | null;hostStates: Record<string, HostConnectionState>;managing: boolean;+ closeManagement: () => void;selectLocal: () => void;openHostIds: string[];directory: RemoteDirectory | null;@@ -35,7 +34,6 @@ export function RemoteInstances({ children }: { children: ReactNode }) {const [managing, setManaging] = useState(false);const managementOpen = useRef(false);const managementConnect = useRef(false);- const managementPanel = useRef<HTMLDivElement>(null);const legacyFooter = useRef<HTMLDivElement>(null);const returnedPair = useSyncExternalStore(subscribePairReturn, readPairReturn);const returnLocal = hosts.local;@@ -59,7 +57,10 @@ export function RemoteInstances({ children }: { children: ReactNode }) {const restoreFocus = () => {const fallback = legacyFooter.current?.querySelector<HTMLElement>("[data-host-switcher]");if (activeHostId.current && fallback) fallback.focus({ preventScroll: true });- else if (activeHostId.current) bridge.focus(activeHostId.current);+ else if (activeHostId.current) {+ frameNodes.current.get(activeHostId.current)?.focus({ preventScroll: true });+ bridge.focus(activeHostId.current);+ }else restoreLocalFocus();};const available = directory?.available === true || hosts.directoryError;@@ -101,23 +102,30 @@ export function RemoteInstances({ children }: { children: ReactNode }) {kind: "shell", name: selected?.name || t("remote.localShort"), hostname: selected?.hostname || directory?.machine_name || "nanobot",localName: directory?.machine_name || "nanobot", currentId: selected?.id || null, recentIds: hosts.recentIds,profiles: (directory?.profiles || []).map(({ id, name, host }) => ({ id, name, host, state: hostStates[id] })),- pending, error: message, offline: !!offline, select: (id) => { if (id) switchHost(id); else hosts.local(); },+ pending, error: message, offline: !!offline,+ select: (id) => {+ if (!id) selectLocal();+ else if (managing) void connect(id).catch(() => {});+ else switchHost(id);+ },manage,cancel: hosts.cancel, clearError: hosts.clearError, restoreFocus: () => { if (!managing) restoreFocus(); },};useEffect(() => { if (selected) document.title = `${selected.name} · nanobot`; }, [selected]);useEffect(() => {const rememberFocus = (event: FocusEvent) => {- if (event.target instanceof HTMLElement && localPanel.current?.contains(event.target)+ if (!managementOpen.current && event.target instanceof HTMLElement && localPanel.current?.contains(event.target)&& !event.target.closest("[data-host-switcher]")) lastLocalFocus.current = event.target;};document.addEventListener("focusin", rememberFocus);return () => document.removeEventListener("focusin", rememberFocus);}, []);useLayoutEffect(() => {- if (selected) frameNodes.current.get(selected.id)?.focus({ preventScroll: true });+ if (managing) return;+ if (selected) restoreFocus();else restoreLocalFocus();- }, [selected]);+ // Focus only on view changes, not on directory refreshes.+ }, [selected, managing]);useEffect(() => {if (!selected) return;const stop = (event: KeyboardEvent) => event.stopPropagation();@@ -127,19 +135,19 @@ export function RemoteInstances({ children }: { children: ReactNode }) {}, [selected]);return <RemoteContext.Provider value={{ available, localActive: !selected, directory,- activeHostId: selected?.id || null, hostStates, managing, selectLocal,+ activeHostId: selected?.id || null, hostStates, managing, closeManagement: () => changeManagement(false), selectLocal,openHostIds: frames.map((frame) => frame.connection.id),directoryError: hosts.directoryError, refresh: hosts.refresh, connect, disconnect: hosts.disconnect, cancel: hosts.cancel }}><HostNavigationContext.Provider value={bridge.embedded || (available || selected ? picker : null)}><div className="flex h-full min-h-0 flex-col bg-background"><div className="relative min-h-0 flex-1 overflow-hidden">- <div ref={localPanel} data-host-view="local" aria-hidden={!!selected} {...(selected ? { inert: "" } : {})}- style={{ visibility: selected ? "hidden" : "visible" }}- className={`absolute inset-0 transition-opacity duration-150 motion-reduce:transition-none ${selected ? "invisible pointer-events-none opacity-0" : "visible opacity-100"}`}>+ <div ref={localPanel} data-host-view="local" aria-hidden={!!selected && !managing} {...(selected && !managing ? { inert: "" } : {})}+ style={{ visibility: selected && !managing ? "hidden" : "visible" }}+ className={`absolute inset-0 transition-opacity duration-150 motion-reduce:transition-none ${selected && !managing ? "invisible pointer-events-none opacity-0" : "visible opacity-100"}`}>{children}</div>{frames.map((frame) => {- const active = selected?.id === frame.connection.id;+ const active = !managing && selected?.id === frame.connection.id;return <div key={`${frame.connection.id}:${frame.connection.gateway_id}:${frame.connection.view_id || ""}`} data-host-view={frame.connection.id} aria-hidden={!active || offline}{...(!active || offline ? { inert: "" } : {})} style={{ visibility: active ? "visible" : "hidden" }}className={`absolute inset-0 transition-opacity duration-150 motion-reduce:transition-none ${active ? "visible opacity-100" : "invisible pointer-events-none opacity-0"}`}>@@ -150,7 +158,7 @@ export function RemoteInstances({ children }: { children: ReactNode }) {onLoad={() => { bridge.initialize(frame.connection.id); hosts.loaded(frame.connection.id); }} /></div>;})}- {selected && (offline || !activeFrame?.loaded) && <div className="absolute inset-0 flex flex-col items-center justify-center gap-3 bg-background px-6 text-center">+ {!managing && selected && (offline || !activeFrame?.loaded) && <div className="absolute inset-0 flex flex-col items-center justify-center gap-3 bg-background px-6 text-center">{offline ? <PlugZap className="h-7 w-7 text-muted-foreground" /> : <Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />}<p className="max-w-full break-words text-xs text-muted-foreground">{selected.name} · {selected.hostname}</p><p className="font-medium">{t(offline ? "remote.offline" : "remote.opening")}</p>@@ -165,18 +173,10 @@ export function RemoteInstances({ children }: { children: ReactNode }) {</div>{/* Older remote bundles cannot host the control. Keep an explicit exitin a compact bottom strip, never cover their sidebar controls. */}- {selected && (!bridge.readyIds.includes(selected.id) || offline) && <div ref={legacyFooter} data-testid="legacy-host-footer" className="flex shrink-0 items-center border-t border-border/50 bg-sidebar px-2.5 py-1">+ {!managing && selected && (!bridge.readyIds.includes(selected.id) || offline) && <div ref={legacyFooter} data-testid="legacy-host-footer" className="flex shrink-0 items-center border-t border-border/50 bg-sidebar px-2.5 py-1"><div className="flex w-52 min-w-0"><HostSwitcher /></div></div>}<RemoteHostMenu picker={picker} anchor={bridge.anchor} onClose={bridge.close} />- <Sheet open={managing} onOpenChange={changeManagement}>- <SheetContent ref={managementPanel} aria-describedby={undefined} className="w-full gap-0 overflow-hidden bg-settings-canvas outline-none sm:max-w-xl"- onOpenAutoFocus={(event) => { event.preventDefault(); managementPanel.current?.focus(); }}- onCloseAutoFocus={(event) => { event.preventDefault(); restoreFocus(); }}>- <div className="shrink-0 px-6 pb-2 pt-7 pr-12"><SheetTitle className="text-xl font-medium">{t("remote.title")}</SheetTitle></div>- <RemoteConnectionsPage inPanel onBackToChat={() => changeManagement(false)} />- </SheetContent>- </Sheet></div></HostNavigationContext.Provider></RemoteContext.Provider>;diff --git a/webui/src/tests/app-layout.test.tsx b/webui/src/tests/app-layout.test.tsxindex e357d986a..b2dbe8ce2 100644--- a/webui/src/tests/app-layout.test.tsx+++ b/webui/src/tests/app-layout.test.tsx@@ -683,7 +683,7 @@ describe("App layout", () => {expect(window.location.hash).toBe("#/channels");});- it("opens management over the current view while keeping the standalone deep link", async () => {+ it("opens management in the main content area while keeping the standalone deep link", async () => {requestMutationSpy.mockResolvedValue({ hosts: [], files: [], incomplete: false });mockFetchRoutes({"/api/settings": baseSettingsPayload(),@@ -698,6 +698,8 @@ describe("App layout", () => {fireEvent.pointerDown(await within(sidebar).findByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false });fireEvent.click(await screen.findByRole("menuitem", { name: "Manage connections…" }));expect(await screen.findByRole("heading", { name: "Remote connections" })).toBeVisible();+ expect(screen.getByRole("main")).toContainElement(screen.getByRole("region", { name: "Remote connections" }));+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();expect(sidebar).toBeVisible();fireEvent.click(await screen.findByRole("button", { name: "Connect to remote nanobot" }));fireEvent.pointerDown(screen.getByRole("button", { name: "Other ways" }), { button: 0, ctrlKey: false });@@ -707,7 +709,7 @@ describe("App layout", () => {expect(window.location.hash).toBe(originalHash);expect(document.title).toBe(originalTitle);fireEvent.click(screen.getByRole("button", { name: "Cancel" }));- fireEvent.click(within(screen.getByRole("dialog", { name: "Remote connections" })).getByRole("button", { name: "Close" }));+ fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));fireEvent.click(within(sidebar).getByRole("button", { name: "New topic" }));expect(window.location.hash).toBe("#/new");expect(screen.queryByRole("textbox", { name: "SSH address" })).not.toBeInTheDocument();@@ -720,6 +722,22 @@ describe("App layout", () => {expect(within(sidebar).queryByRole("button", { name: "Remote connections" })).not.toBeInTheDocument();});+ it("lets sidebar navigation leave the management page without a second dismissal", async () => {+ mockFetchRoutes({+ "/api/settings": baseSettingsPayload(),+ "/api/remote-instances": { available: true, profiles: [] },+ });+ render(<App />);+ const sidebar = await screen.findByRole("navigation", { name: "Sidebar navigation" });+ fireEvent.pointerDown(await within(sidebar).findByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false });+ fireEvent.click(await screen.findByRole("menuitem", { name: "Manage connections…" }));+ expect(await screen.findByRole("region", { name: "Remote connections" })).toBeVisible();+ fireEvent.click(within(sidebar).getByRole("button", { name: "Apps" }));+ expect(await screen.findByRole("heading", { name: "Apps" })).toBeVisible();+ expect(screen.queryByRole("region", { name: "Remote connections" })).not.toBeInTheDocument();+ expect(window.location.hash).toBe("#/apps");+ });+it("closes the mobile sidebar when managing connections from its host menu", async () => {const user = userEvent.setup();requestMutationSpy.mockResolvedValue({ hosts: [], files: [], incomplete: false });@@ -739,7 +757,8 @@ describe("App layout", () => {fireEvent.pointerDown(await within(sheet).findByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false });fireEvent.click(await screen.findByRole("menuitem", { name: "Manage connections…" }));await waitFor(() => expect(sheet).not.toBeInTheDocument());- expect(screen.getByRole("dialog", { name: "Remote connections" })).toBeVisible();+ expect(screen.getByRole("main")).toContainElement(screen.getByRole("region", { name: "Remote connections" }));+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();expect(await screen.findByRole("heading", { name: "Remote connections" })).toBeVisible();expect(window.location.hash).not.toBe("#/remote");expect(screen.queryByRole("button", { name: "Remote connections" })).not.toBeInTheDocument();diff --git a/webui/src/tests/remote-instances.test.tsx b/webui/src/tests/remote-instances.test.tsxindex 387a40017..5a00c734c 100644--- a/webui/src/tests/remote-instances.test.tsx+++ b/webui/src/tests/remote-instances.test.tsx@@ -1,7 +1,7 @@import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";import { useEffect, useState } from "react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-import { RemoteInstances } from "@/components/remote/RemoteInstances";+import { RemoteInstances, useRemoteConnections } from "@/components/remote/RemoteInstances";import { RemoteConnectionsPage } from "@/components/remote/RemoteConnectionsPage";import { Sidebar } from "@/components/Sidebar";import { HOST_BRIDGE } from "@/components/remote/host-bridge";@@ -34,6 +34,7 @@ const profile = { id: "3b968d52-081d-4898-9970-ff0a1fc93817", name: "Team serverconst connection: RemoteConnection = { ...profile, hostname: "team-host", gateway_id: "gateway-1", url: "http://127.0.0.1:23456/#/?bootstrapSecret=private-secret" };const noop = () => {};function LocalShell({ collapsed = false, initialRemote = false }) {+ const connections = useRemoteConnections();const [remotePage, setRemotePage] = useState(initialRemote);useEffect(() => {const route = () => setRemotePage(window.location.hash === "#/remote");@@ -42,12 +43,14 @@ function LocalShell({ collapsed = false, initialRemote = false }) {}, []);return <><Sidebar collapsed={collapsed} sessions={[]} activeKey={null} loading={false} newChatActive={false}- onNewChat={() => { window.location.hash = "/new"; setRemotePage(false); }} onSelect={noop} onRequestDelete={noop} onTogglePin={noop}+ onNewChat={() => { if (connections?.managing) connections.selectLocal(); window.location.hash = "/new"; setRemotePage(false); }} onSelect={noop} onRequestDelete={noop} onTogglePin={noop}onRequestRename={noop} onToggleArchive={noop} onToggleGroup={noop}onRequestRenameProject={noop} onNewChatInProject={noop} onOpenSettings={noop}onOpenApps={noop} onOpenSkills={noop} onOpenAutomations={noop} onOpenChannels={noop}onOpenSearch={noop} onToggleArchived={noop} />- <main>{remotePage ? <RemoteConnectionsPage onBackToChat={() => setRemotePage(false)} /> : <><p>Local conversations</p><textarea aria-label="Local draft" /></>}</main>+ <main><div hidden={connections?.managing} aria-hidden={connections?.managing || undefined}>+ {remotePage ? <RemoteConnectionsPage onBackToChat={() => setRemotePage(false)} /> : <><p>Local conversations</p><textarea aria-label="Local draft" /></>}+ </div>{connections?.managing && <RemoteConnectionsPage onBackToChat={connections.closeManagement} />}</main></>;}const view = (collapsed = false, initialRemote = false) => render(<RemoteInstances><LocalShell collapsed={collapsed} initialRemote={initialRemote} /></RemoteInstances>);@@ -96,7 +99,10 @@ describe("remote instance UX", () => {const originalHash = window.location.hash;mocks.request.mockClear();await openDirectory();- const panel = screen.getByRole("dialog", { name: "Remote connections" });+ const panel = screen.getByRole("region", { name: "Remote connections" });+ expect(screen.getByRole("main")).toContainElement(panel);+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();+ expect(frame).not.toBeVisible();const current = within(panel).getByRole("button", { name: "Team server [email protected]" });expect(current).toHaveAttribute("aria-current", "true");expect(within(current).getByRole("status")).toHaveTextContent("Connected");@@ -105,7 +111,7 @@ describe("remote instance UX", () => {expect(readSelectedRemote()?.id).toBe(profile.id);expect(window.location.hash).toBe(originalHash);expect(document.title).toBe(originalTitle);- fireEvent.click(within(panel).getByRole("button", { name: "Close" }));+ fireEvent.click(within(panel).getByRole("button", { name: "Back", exact: true }));await waitFor(() => expect(panel).not.toBeInTheDocument());expect(screen.getByTitle("nanobot on Team server")).toBe(frame);expect(frame).toBeVisible();@@ -114,14 +120,15 @@ describe("remote instance UX", () => {expect(mocks.request).not.toHaveBeenCalled();});- it("retains a local draft when management is opened and dismissed with Escape", async () => {+ it("retains a local draft when returning from the management page", async () => {view();const draft = screen.getByRole("textbox", { name: "Local draft" });draft.focus();fireEvent.change(draft, { target: { value: "Keep this unsent draft" } });await openDirectory();- fireEvent.keyDown(screen.getByRole("dialog"), { key: "Escape" });- await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());+ expect(screen.queryByRole("textbox", { name: "Local draft" })).not.toBeInTheDocument();+ fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));+ await waitFor(() => expect(screen.queryByRole("region", { name: "Remote connections" })).not.toBeInTheDocument());expect(screen.getByRole("textbox", { name: "Local draft" })).toBe(draft);expect(draft).toHaveValue("Keep this unsent draft");expect(draft).toHaveFocus();@@ -134,7 +141,7 @@ describe("remote instance UX", () => {view();await chooseHost("Team server [email protected]");await openDirectory();- fireEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Close" }));+ fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));await act(async () => finish(connection));const frame = await readyRemote();expect(frame).toBeVisible();@@ -154,6 +161,34 @@ describe("remote instance UX", () => {expect(mocks.request.mock.calls.some(([action]) => action === "remote.disconnect")).toBe(false);});+ it("keeps the management page open if an earlier host switch finishes behind it", async () => {+ let finish!: (value: RemoteConnection) => void;+ mocks.request.mockImplementation(() => new Promise((resolve) => { finish = resolve; }));+ view();+ await chooseHost("Team server [email protected]");+ await openDirectory();+ await act(async () => finish(connection));+ const frame = await readyRemote();+ expect(frame).not.toBeVisible();+ expect(screen.getByRole("region", { name: "Remote connections" })).toBeVisible();+ fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));+ expect(frame).toBeVisible();+ expect(readSelectedRemote()?.id).toBe(profile.id);+ });++ it("treats local sidebar navigation as an explicit host choice without disconnecting the server", async () => {+ view();+ await chooseHost("Team server [email protected]");+ const frame = await readyRemote();+ await openDirectory();+ fireEvent.click(screen.getByRole("button", { name: "New topic" }));+ expect(screen.queryByRole("region", { name: "Remote connections" })).not.toBeInTheDocument();+ expect(screen.getByText("Local conversations")).toBeVisible();+ expect(readSelectedRemote()).toBeNull();+ expect(frame).toBeInTheDocument();+ expect(mocks.request.mock.calls.some(([action]) => action === "remote.disconnect")).toBe(false);+ });+it.each([{ connected: false, connection_error: "disconnected", label: "Disconnected" },{ connected: true, connection_error: "", label: "Connected" },@@ -165,7 +200,7 @@ describe("remote instance UX", () => {const row = screen.getByRole("button", { name: "Team server [email protected]" });expect(row).not.toHaveAttribute("aria-current");expect(within(row).getByRole("status")).toHaveTextContent(label);- fireEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Close" }));+ fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));fireEvent.pointerDown(screen.getByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false });const item = await screen.findByRole("menuitem", { name: "Team server [email protected]" });expect(within(item).getByRole("status")).toHaveTextContent(label);@@ -185,7 +220,7 @@ describe("remote instance UX", () => {expect(readSelectedRemote()?.id).toBe(profile.id);fireEvent.click(within(screen.getByRole("dialog", { name: "Connect to a server" })).getByRole("button", { name: "Cancel" }));expect(within(screen.getByRole("button", { name: "Other server [email protected]" })).getByRole("status")).toHaveTextContent("Connection error");- expect(screen.getByRole("dialog", { name: "Remote connections" })).toBeVisible();+ expect(screen.getByRole("region", { name: "Remote connections" })).toBeVisible();});it("lets directory users cancel a cold connection before it takes over", async () => {@@ -452,7 +487,8 @@ describe("remote instance UX", () => {expect(screen.queryByRole("button", { name: "Remote connections" })).not.toBeInTheDocument();expect(screen.queryByText("This machine")).not.toBeInTheDocument();await openDirectory();- expect(screen.getByRole("dialog", { name: "Remote connections" })).toContainElement(screen.getByText("Team server"));+ expect(screen.getByRole("main")).toContainElement(screen.getByText("Team server"));+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();expect(document.querySelector('nav')).toBeVisible();expect(window.location.hash).toBe("#/new");expect(screen.getByText("Local nanobot")).toBeInTheDocument();@@ -838,7 +874,7 @@ describe("remote instance UX", () => {mocks.request.mockImplementation(() => new Promise<RemoteConnection>((resolve) => { finish = resolve; }));view(); await openDirectory();fireEvent.click(screen.getByRole("button", { name: "Team server [email protected]" }));- fireEvent.click(within(screen.getByRole("dialog", { name: "Remote connections" })).getByRole("button", { name: "Close" }));+ fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));await act(async () => { finish?.(connection); });expect(screen.getByText("Local conversations")).toBeVisible();expect(screen.queryByTitle("nanobot on Team server")).not.toBeInTheDocument();@@ -855,7 +891,7 @@ describe("remote instance UX", () => {fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: "[email protected]" } });fireEvent.click(screen.getByRole("button", { name: "Connect" }));fireEvent.click(screen.getByRole("button", { name: "Cancel" }));- fireEvent.click(within(screen.getByRole("dialog", { name: "Remote connections" })).getByRole("button", { name: "Close" }));+ fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));await act(async () => { finish?.({ id: profile.id }); });expect(mocks.request).toHaveBeenCalledTimes(1);expect(screen.getByText("Local conversations")).toBeVisible();@@ -1070,7 +1106,7 @@ describe("remote instance UX", () => {expect(screen.queryByRole("button", { name: "Reconnect" })).not.toBeInTheDocument();fireEvent.click(screen.getByRole("button", { name: "Manage connections…" }));expect(readSelectedRemote()?.id).toBe(profile.id);- expect(screen.getByRole("dialog", { name: "Remote connections" })).toBeVisible();+ expect(screen.getByRole("region", { name: "Remote connections" })).toBeVisible();expect(mocks.request.mock.calls.filter(([action]) => action === "remote.disconnect")).toHaveLength(0);});