Skip to content

Commit b57e81d

Browse files
abdulsalamgsclaude
andcommitted
fix(client-runtime): only jump ahead of routes of the same kind
VPN and tailnet routes share a rank, so comparing ranks let a newly paired tailnet route jump ahead of a saved VPN route. Compare kinds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4a1fef2 commit b57e81d

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ describe("connection routes", () => {
9292
const pasted = direct("lan-2", "http://192.168.1.11:3773/");
9393
expect(upsertRoute([LAN, TAILNET], pasted)).toEqual([pasted, LAN, TAILNET]);
9494
});
95+
96+
it("keeps a newly paired route behind a different kind of the same rank", () => {
97+
const vpn = direct("vpn", "http://100.101.102.103:3773/");
98+
const pasted = direct("ts-2", "http://[fd7a:115c:a1e0::2]:3773/");
99+
expect(upsertRoute([vpn, TAILNET], pasted)).toEqual([vpn, pasted, TAILNET]);
100+
});
95101
});
96102

97103
describe("learned routes", () => {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ export function insertRoute(
117117
route: ConnectionRoute,
118118
{ aheadOfSameKind = false }: { readonly aheadOfSameKind?: boolean } = {},
119119
): ReadonlyArray<ConnectionRoute> {
120-
const rank = ROUTE_KIND_RANK[connectionRouteKind(route)];
120+
const kind = connectionRouteKind(route);
121+
const rank = ROUTE_KIND_RANK[kind];
121122
const index = routes.findIndex((existing) => {
122-
const existingRank = ROUTE_KIND_RANK[connectionRouteKind(existing)];
123-
return aheadOfSameKind ? existingRank >= rank : existingRank > rank;
123+
const existingKind = connectionRouteKind(existing);
124+
return ROUTE_KIND_RANK[existingKind] > rank || (aheadOfSameKind && existingKind === kind);
124125
});
125126
return index === -1
126127
? [...routes, route]

0 commit comments

Comments
 (0)