Skip to content

Commit c8f0853

Browse files
t3dotggclaude
andcommitted
fix(connections): adding a paired address again keeps its pairing
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9915d17 commit c8f0853

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎packages/client-runtime/src/connection/onboarding.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ import {
3535
import * as Persistence from "../platform/persistence.ts";
3636
import * as EnvironmentRegistry from "./registry.ts";
3737
import { orchestrationProtocolCompatibilityError } from "./compatibility.ts";
38-
import { connectionRoutes, hasRelayRoute, routeEntry, sshTargetKey } from "./routes.ts";
38+
import {
39+
connectionRoutes,
40+
hasRelayRoute,
41+
isLearned,
42+
routeEntry,
43+
routeHttpBaseUrl,
44+
sshTargetKey,
45+
} from "./routes.ts";
3946

4047
export interface PairingConnectionInput {
4148
readonly pairingUrl?: string;
@@ -174,6 +181,17 @@ export const addT3ConnectRoute = Effect.fn("clientRuntime.connection.onboarding.
174181
if (entry === undefined || !hasRelayRoute(entry)) return null;
175182
const address = resolveRemoteAddressWithoutCredential(input);
176183
if (address === null) return null;
184+
// An address the user already saved keeps how it signs in, so a paired
185+
// token is never swapped for T3 Connect.
186+
const base = (url: string) => url.replace(/\/+$/, "");
187+
if (
188+
connectionRoutes(entry).some(
189+
(route) =>
190+
!isLearned(route) && base(routeHttpBaseUrl(route) ?? "") === base(address.httpBaseUrl),
191+
)
192+
) {
193+
return environmentId;
194+
}
177195
if (
178196
address.httpBaseUrl.startsWith("http:") &&
179197
typeof globalThis.location !== "undefined" &&

‎packages/client-runtime/src/connection/registry.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,29 @@ describe("EnvironmentRegistry routes", () => {
20502050
}),
20512051
);
20522052

2053+
it.effect("keeps a paired address's token when it is added again without a code", () =>
2054+
Effect.gen(function* () {
2055+
const harness = yield* makeHarness(
2056+
[LAN_TARGET, RELAY_TARGET],
2057+
[LAN_PROFILE],
2058+
[[LAN_TARGET.connectionId, BEARER_CREDENTIAL]],
2059+
);
2060+
yield* Effect.gen(function* () {
2061+
const added = yield* addT3ConnectRoute({
2062+
host: "192.168.1.10:3773",
2063+
expectedEnvironmentId: RELAY_TARGET.environmentId,
2064+
}).pipe(Effect.provide(layerDescriptorHttp(RELAY_TARGET.environmentId)));
2065+
expect(added).toBe(RELAY_TARGET.environmentId);
2066+
expect(routesOf(yield* Ref.get(harness.storedTargets), RELAY_TARGET.environmentId)).toEqual(
2067+
[LAN_TARGET, RELAY_TARGET],
2068+
);
2069+
expect((yield* Ref.get(harness.storedProfiles)).get(LAN_TARGET.connectionId)).toEqual(
2070+
LAN_PROFILE,
2071+
);
2072+
}).pipe(Effect.provide(harness.layer), Effect.scoped);
2073+
}),
2074+
);
2075+
20532076
it.effect("refuses a codeless address that reaches a different machine", () =>
20542077
Effect.gen(function* () {
20552078
const harness = yield* makeHarness([RELAY_TARGET]);

0 commit comments

Comments
 (0)