From 753fdcf0cc1ede163b64e0aaf6abd268e6680ea0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 29 Oct 2026 23:07:59 +0000 Subject: [PATCH 1/4] test(web): remote open uses a saved SSH route that is not in use Reproduces pingdotgg/t3code#27203: when a saved environment is connected over its Tailscale route and also has a saved SSH route, editor links use the advertised MagicDNS host instead of the SSH route's alias, bypassing the user's ~/.ssh/config Host block. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/remoteOpen.test.ts | 90 ++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/apps/web/src/remoteOpen.test.ts b/apps/web/src/remoteOpen.test.ts index 365ec4a3d50af..4dbe394b6fcac 100644 --- a/apps/web/src/remoteOpen.test.ts +++ b/apps/web/src/remoteOpen.test.ts @@ -1,12 +1,44 @@ import { + BearerConnectionProfile, + BearerConnectionTarget, + type EnvironmentPresentation, PrimaryConnectionTarget, RelayConnectionTarget, + SshConnectionProfile, SshConnectionTarget, } from "@t3tools/client-runtime/connection"; import { buildRemoteOpenUrl, EnvironmentId } from "@t3tools/contracts"; -import { describe, expect, it } from "vite-plus/test"; +import * as Option from "effect/Option"; +import { AtomRegistry } from "effect/reactivity"; +import { describe, expect, it, vi } from "vite-plus/test"; -import { resolveRemoteOpenState } from "./remoteOpen"; +import { resolveRemoteOpenState, useRemoteOpenState } from "./remoteOpen"; + +const atomMocks = vi.hoisted(() => ({ + registry: null as AtomRegistry.AtomRegistry | null, + presentation: null as EnvironmentPresentation | null, +})); + +vi.mock(import("@effect/atom-react"), async (importOriginal) => ({ + ...(await importOriginal()), + useAtomValue: ((atom: Parameters[0]) => + atomMocks.registry!.get(atom)) as never, +})); + +vi.mock(import("./state/presentation"), async () => { + const { Atom } = await import("effect/reactivity"); + return { + environmentPresentations: { + presentationAtom: () => Atom.make(() => atomMocks.presentation), + }, + } as never; +}); + +function setup(presentation: EnvironmentPresentation) { + atomMocks.registry = AtomRegistry.make(); + atomMocks.presentation = presentation; + vi.stubGlobal("window", {}); +} const environmentId = EnvironmentId.make("environment-1"); @@ -143,6 +175,60 @@ describe("resolveRemoteOpenState", () => { }); }); +describe("useRemoteOpenState", () => { + it("uses a saved SSH route's alias while a Tailscale route is in use", () => { + setup({ + entry: { + target: new BearerConnectionTarget({ environmentId, label: "sol", connectionId: "ts-1" }), + profile: Option.some( + new BearerConnectionProfile({ + connectionId: "ts-1", + environmentId, + label: "sol", + httpBaseUrl: "https://sol.tail1234.ts.net", + wsBaseUrl: "wss://sol.tail1234.ts.net", + network: "tailscale", + }), + ), + alternateRoutes: [ + { + target: new SshConnectionTarget({ environmentId, label: "sol", connectionId: "ssh-1" }), + profile: Option.some( + new SshConnectionProfile({ + connectionId: "ssh-1", + environmentId, + label: "sol", + target: { + alias: "sol-alias", + hostname: "sol.tail1234.ts.net", + username: null, + port: null, + }, + }), + ), + }, + ], + enabled: true, + }, + connection: { phase: "connected", error: null, traceId: null }, + serverConfig: { + remoteOpenTargets: [ + { kind: "tailscale", host: "sol.tail1234.ts.net", username: "server-user" }, + ], + } as never, + }); + + const state = useRemoteOpenState(environmentId); + vi.unstubAllGlobals(); + + expect(state).toEqual({ mode: "remote-links", host: { kind: "ssh-alias", host: "sol-alias" } }); + if (state.mode !== "remote-links") throw new Error("Expected a remote link"); + expect( + buildRemoteOpenUrl({ editor: "zed", ...state.host, absolutePath: "/work/project" }), + ).toBe("zed://ssh/sol-alias/work/project"); + }); +}); + describe("buildRemoteOpenUrl", () => { it("roots Windows paths", () => { expect( From c238b4ef8dfef0bfe0458f4d083d49009bf6e6d0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 29 Oct 2026 23:12:00 +0000 Subject: [PATCH 2/4] fix(web): remote open uses the environment's saved SSH route With a Tailscale route in use and an SSH route saved as an alternate, editor links fell back to the advertised MagicDNS host and server username, bypassing the user's ~/.ssh/config Host block. resolveRemoteOpenState now takes the environment's routes and uses the first saved SSH route's alias (the in-use route comes first), so the choice is tested without atom mocks. Fixes pingdotgg/t3code#27203 Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/ChatMarkdown.tsx | 2 +- apps/web/src/remoteOpen.test.ts | 131 +++++++++-------------- apps/web/src/remoteOpen.ts | 26 +++-- 3 files changed, 66 insertions(+), 93 deletions(-) diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index 6a8f80d6d1071..926d810aa6a34 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -556,7 +556,7 @@ function useChatMarkdownState({ target !== null && resolveRemoteOpenState({ target, - sshTarget: null, + routes: [], remoteOpenTargets: undefined, isDesktopRenderer: window.desktopBridge !== undefined, }).mode !== "local-exec" diff --git a/apps/web/src/remoteOpen.test.ts b/apps/web/src/remoteOpen.test.ts index 4dbe394b6fcac..a738acde47e3b 100644 --- a/apps/web/src/remoteOpen.test.ts +++ b/apps/web/src/remoteOpen.test.ts @@ -1,7 +1,6 @@ import { BearerConnectionProfile, BearerConnectionTarget, - type EnvironmentPresentation, PrimaryConnectionTarget, RelayConnectionTarget, SshConnectionProfile, @@ -9,36 +8,9 @@ import { } from "@t3tools/client-runtime/connection"; import { buildRemoteOpenUrl, EnvironmentId } from "@t3tools/contracts"; import * as Option from "effect/Option"; -import { AtomRegistry } from "effect/reactivity"; -import { describe, expect, it, vi } from "vite-plus/test"; +import { describe, expect, it } from "vite-plus/test"; -import { resolveRemoteOpenState, useRemoteOpenState } from "./remoteOpen"; - -const atomMocks = vi.hoisted(() => ({ - registry: null as AtomRegistry.AtomRegistry | null, - presentation: null as EnvironmentPresentation | null, -})); - -vi.mock(import("@effect/atom-react"), async (importOriginal) => ({ - ...(await importOriginal()), - useAtomValue: ((atom: Parameters[0]) => - atomMocks.registry!.get(atom)) as never, -})); - -vi.mock(import("./state/presentation"), async () => { - const { Atom } = await import("effect/reactivity"); - return { - environmentPresentations: { - presentationAtom: () => Atom.make(() => atomMocks.presentation), - }, - } as never; -}); - -function setup(presentation: EnvironmentPresentation) { - atomMocks.registry = AtomRegistry.make(); - atomMocks.presentation = presentation; - vi.stubGlobal("window", {}); -} +import { resolveRemoteOpenState } from "./remoteOpen"; const environmentId = EnvironmentId.make("environment-1"); @@ -50,6 +22,18 @@ const primaryTarget = (httpBaseUrl: string) => wsBaseUrl: httpBaseUrl.replace("http", "ws"), }); +const sshRoute = (target: { readonly alias: string; readonly username: string | null }) => ({ + target: new SshConnectionTarget({ environmentId, label: "sol", connectionId: "ssh-1" }), + profile: Option.some( + new SshConnectionProfile({ + connectionId: "ssh-1", + environmentId, + label: "sol", + target: { ...target, hostname: "sol.tail1234.ts.net", port: null }, + }), + ), +}); + const TAILSCALE_TARGETS = [ { kind: "tailscale", host: "sol.tail1234.ts.net" }, { kind: "mdns", host: "sol.local" }, @@ -60,7 +44,7 @@ describe("resolveRemoteOpenState", () => { expect( resolveRemoteOpenState({ target: primaryTarget("http://127.0.0.1:8000"), - sshTarget: null, + routes: [], isDesktopRenderer: false, remoteOpenTargets: TAILSCALE_TARGETS, }), @@ -71,7 +55,7 @@ describe("resolveRemoteOpenState", () => { expect( resolveRemoteOpenState({ target: primaryTarget("https://sol.tail1234.ts.net"), - sshTarget: null, + routes: [], isDesktopRenderer: false, remoteOpenTargets: TAILSCALE_TARGETS, }), @@ -86,7 +70,7 @@ describe("resolveRemoteOpenState", () => { expect( resolveRemoteOpenState({ target: primaryTarget("http://172.29.112.1:14369"), - sshTarget: null, + routes: [], isDesktopRenderer: true, remoteOpenTargets: TAILSCALE_TARGETS, }), @@ -96,7 +80,7 @@ describe("resolveRemoteOpenState", () => { it("leaves a bare desktop SSH alias for the editor to resolve through SSH config", () => { const state = resolveRemoteOpenState({ target: new SshConnectionTarget({ environmentId, label: "sol", connectionId: "ssh-1" }), - sshTarget: { alias: "sol", username: null }, + routes: [sshRoute({ alias: "sol", username: null })], isDesktopRenderer: true, remoteOpenTargets: [ { kind: "tailscale", host: "sol.tail1234.ts.net", username: "server-user" }, @@ -126,7 +110,7 @@ describe("resolveRemoteOpenState", () => { ])("keeps one login username in editor links for $alias (username: '$username')", (sshTarget) => { const state = resolveRemoteOpenState({ target: new SshConnectionTarget({ environmentId, label: "server", connectionId: "ssh-1" }), - sshTarget, + routes: [sshRoute(sshTarget)], isDesktopRenderer: true, remoteOpenTargets: TAILSCALE_TARGETS, }); @@ -148,7 +132,7 @@ describe("resolveRemoteOpenState", () => { it("uses the advertised login username in editor links over a relay", () => { const state = resolveRemoteOpenState({ target: new RelayConnectionTarget({ environmentId, label: "server" }), - sshTarget: null, + routes: [], isDesktopRenderer: false, remoteOpenTargets: [ { kind: "tailscale", host: "server.tail1234.ts.net", username: "admin-user" }, @@ -166,61 +150,42 @@ describe("resolveRemoteOpenState", () => { expect( resolveRemoteOpenState({ target: new RelayConnectionTarget({ environmentId, label: "sol" }), - sshTarget: null, + routes: [], isDesktopRenderer: false, remoteOpenTargets, }), ).toEqual({ mode: "remote-unavailable" }); } }); -}); - -describe("useRemoteOpenState", () => { it("uses a saved SSH route's alias while a Tailscale route is in use", () => { - setup({ - entry: { - target: new BearerConnectionTarget({ environmentId, label: "sol", connectionId: "ts-1" }), - profile: Option.some( - new BearerConnectionProfile({ - connectionId: "ts-1", - environmentId, - label: "sol", - httpBaseUrl: "https://sol.tail1234.ts.net", - wsBaseUrl: "wss://sol.tail1234.ts.net", - network: "tailscale", - }), - ), - alternateRoutes: [ - { - target: new SshConnectionTarget({ environmentId, label: "sol", connectionId: "ssh-1" }), - profile: Option.some( - new SshConnectionProfile({ - connectionId: "ssh-1", - environmentId, - label: "sol", - target: { - alias: "sol-alias", - hostname: "sol.tail1234.ts.net", - username: null, - port: null, - }, - }), - ), - }, - ], - enabled: true, - }, - connection: { phase: "connected", error: null, traceId: null }, - serverConfig: { - remoteOpenTargets: [ - { kind: "tailscale", host: "sol.tail1234.ts.net", username: "server-user" }, - ], - } as never, + const target = new BearerConnectionTarget({ + environmentId, + label: "sol", + connectionId: "ts-1", + }); + const state = resolveRemoteOpenState({ + target, + routes: [ + { + target, + profile: Option.some( + new BearerConnectionProfile({ + connectionId: "ts-1", + environmentId, + label: "sol", + httpBaseUrl: "https://sol.tail1234.ts.net", + wsBaseUrl: "wss://sol.tail1234.ts.net", + network: "tailscale", + }), + ), + }, + sshRoute({ alias: "sol-alias", username: null }), + ], + isDesktopRenderer: false, + remoteOpenTargets: [ + { kind: "tailscale", host: "sol.tail1234.ts.net", username: "server-user" }, + ], }); - - const state = useRemoteOpenState(environmentId); - vi.unstubAllGlobals(); - expect(state).toEqual({ mode: "remote-links", host: { kind: "ssh-alias", host: "sol-alias" } }); if (state.mode !== "remote-links") throw new Error("Expected a remote link"); expect( diff --git a/apps/web/src/remoteOpen.ts b/apps/web/src/remoteOpen.ts index 741f6f3c60cde..8de7c0eebe601 100644 --- a/apps/web/src/remoteOpen.ts +++ b/apps/web/src/remoteOpen.ts @@ -1,4 +1,8 @@ -import type { ConnectionTarget } from "@t3tools/client-runtime/connection"; +import { + connectionRoutes, + type ConnectionRoute, + type ConnectionTarget, +} from "@t3tools/client-runtime/connection"; import { REMOTE_CAPABLE_EDITOR_IDS, type EditorId, @@ -50,7 +54,8 @@ function parseHostname(url: string): string | null { export function resolveRemoteOpenState(input: { readonly target: ConnectionTarget | null; - readonly sshTarget: { readonly alias: string; readonly username: string | null } | null; + /** The environment's saved routes, in-use route first. */ + readonly routes: ReadonlyArray; readonly remoteOpenTargets: ReadonlyArray | undefined; readonly isDesktopRenderer: boolean; }): RemoteOpenState { @@ -71,13 +76,18 @@ export function resolveRemoteOpenState(input: { return LOCAL_EXEC; } - if (input.sshTarget !== null && input.sshTarget.alias.length > 0) { - const { alias } = input.sshTarget; + const sshTarget = input.routes.flatMap((route) => { + const profile = Option.getOrNull(route.profile); + return profile?._tag === "SshConnectionProfile" && profile.target.alias.length > 0 + ? [profile.target] + : []; + })[0]; + if (sshTarget !== undefined) { + const { alias } = sshTarget; const userSeparator = alias.lastIndexOf("@"); const host = userSeparator === -1 ? alias : alias.slice(userSeparator + 1); const username = - input.sshTarget.username?.trim() || - (userSeparator === -1 ? null : alias.slice(0, userSeparator)); + sshTarget.username?.trim() || (userSeparator === -1 ? null : alias.slice(0, userSeparator)); return { mode: "remote-links", host: { @@ -112,12 +122,10 @@ const remoteOpenResolutionAtom = Atom.family((environmentId: EnvironmentId) => if (entry === null) { return UNRESOLVED_REMOTE_OPEN; } - const profile = Option.getOrNull(entry.profile); const next: RemoteOpenResolution = { state: resolveRemoteOpenState({ target: entry.target, - sshTarget: - profile !== null && profile._tag === "SshConnectionProfile" ? profile.target : null, + routes: connectionRoutes(entry), remoteOpenTargets: presentation?.serverConfig?.remoteOpenTargets, isDesktopRenderer: window.desktopBridge !== undefined, }), From 194948a4eaa18bd56a19344c39aa230c83d8d0ca Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 29 Oct 2026 23:18:21 +0000 Subject: [PATCH 3/4] fix(web): describe remote-open routes by saved order Co-Authored-By: Claude Opus 5.5 --- apps/web/src/remoteOpen.test.ts | 2 +- apps/web/src/remoteOpen.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/remoteOpen.test.ts b/apps/web/src/remoteOpen.test.ts index a738acde47e3b..79fc3019222ec 100644 --- a/apps/web/src/remoteOpen.test.ts +++ b/apps/web/src/remoteOpen.test.ts @@ -157,7 +157,7 @@ describe("resolveRemoteOpenState", () => { ).toEqual({ mode: "remote-unavailable" }); } }); - it("uses a saved SSH route's alias while a Tailscale route is in use", () => { + it("uses a saved SSH route's alias when a Tailscale route is preferred", () => { const target = new BearerConnectionTarget({ environmentId, label: "sol", diff --git a/apps/web/src/remoteOpen.ts b/apps/web/src/remoteOpen.ts index 8de7c0eebe601..f018bf054d3e7 100644 --- a/apps/web/src/remoteOpen.ts +++ b/apps/web/src/remoteOpen.ts @@ -54,7 +54,7 @@ function parseHostname(url: string): string | null { export function resolveRemoteOpenState(input: { readonly target: ConnectionTarget | null; - /** The environment's saved routes, in-use route first. */ + /** The environment's saved routes, preferred route first. */ readonly routes: ReadonlyArray; readonly remoteOpenTargets: ReadonlyArray | undefined; readonly isDesktopRenderer: boolean; From 01d774658719ee58962d38739c23f9f3f33a9aef Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 03:08:24 +0000 Subject: [PATCH 4/4] refactor(web): find the saved SSH route with a plain loop AI-assisted; verified with the tests and tools listed above. --- apps/web/src/remoteOpen.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/web/src/remoteOpen.ts b/apps/web/src/remoteOpen.ts index f018bf054d3e7..ab56bcd476084 100644 --- a/apps/web/src/remoteOpen.ts +++ b/apps/web/src/remoteOpen.ts @@ -52,6 +52,16 @@ function parseHostname(url: string): string | null { } } +function firstSshTarget(routes: ReadonlyArray) { + for (const route of routes) { + const profile = Option.getOrNull(route.profile); + if (profile?._tag === "SshConnectionProfile" && profile.target.alias.length > 0) { + return profile.target; + } + } + return null; +} + export function resolveRemoteOpenState(input: { readonly target: ConnectionTarget | null; /** The environment's saved routes, preferred route first. */ @@ -76,13 +86,8 @@ export function resolveRemoteOpenState(input: { return LOCAL_EXEC; } - const sshTarget = input.routes.flatMap((route) => { - const profile = Option.getOrNull(route.profile); - return profile?._tag === "SshConnectionProfile" && profile.target.alias.length > 0 - ? [profile.target] - : []; - })[0]; - if (sshTarget !== undefined) { + const sshTarget = firstSshTarget(input.routes); + if (sshTarget !== null) { const { alias } = sshTarget; const userSeparator = alias.lastIndexOf("@"); const host = userSeparator === -1 ? alias : alias.slice(userSeparator + 1);