Skip to content

Commit 8ec5c24

Browse files
fix(web): discovered SSH aliases are kept literal
A discovered ssh config Host such as `devbox:2200` was run through the manual address parser, which split it into host `devbox` and port 2200 and bypassed its config entry. Discovered hosts now keep the alias as-is and parse only the username and port override fields. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 000e536 commit 8ec5c24

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

‎apps/web/src/components/settings/AddEnvironmentDialog.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
threadJumpIndexFromCommand,
6060
} from "../../keybindings";
6161
import {
62+
parseDiscoveredDesktopSshTarget,
6263
parseManualDesktopSshTarget,
6364
parsePairingUrlFields,
6465
parseRemotePairingFields,
@@ -281,8 +282,8 @@ export function AddEnvironmentDialog({
281282
// today would pin its user and port, so later config edits never apply.
282283
let aliasTarget: DesktopSshEnvironmentTarget;
283284
try {
284-
aliasTarget = parseManualDesktopSshTarget({
285-
host: target.alias,
285+
aliasTarget = parseDiscoveredDesktopSshTarget({
286+
alias: target.alias,
286287
username: savedBackendSshUsername,
287288
port: savedBackendSshPort,
288289
});

‎apps/web/src/components/settings/ConnectionsSettings.logic.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type DesktopWslState, EnvironmentId } from "@t3tools/contracts";
22
import { describe, expect, it, vi } from "vite-plus/test";
33
import {
44
applyWslEnableSelection,
5+
parseDiscoveredDesktopSshTarget,
56
resolveAccessEnvironmentId,
67
resolveTailscaleServeBaseUrl,
78
selectQrEndpointOption,
@@ -43,6 +44,22 @@ describe("togglePairingScopeSelection", () => {
4344
});
4445
});
4546

47+
describe("parseDiscoveredDesktopSshTarget", () => {
48+
it("keeps the ssh config alias literal and applies only the override fields", () => {
49+
expect(
50+
parseDiscoveredDesktopSshTarget({ alias: "deploy@devbox:2200", username: "", port: "" }),
51+
).toEqual({
52+
alias: "deploy@devbox:2200",
53+
hostname: "deploy@devbox:2200",
54+
username: null,
55+
port: null,
56+
});
57+
expect(
58+
parseDiscoveredDesktopSshTarget({ alias: "devbox", username: " dev ", port: "2222" }),
59+
).toEqual({ alias: "devbox", hostname: "devbox", username: "dev", port: 2222 });
60+
});
61+
});
62+
4663
describe("resolveTailscaleServeBaseUrl", () => {
4764
it.each([
4865
["https://host.tail.ts.net:441/", 443, "https://host.tail.ts.net"],

‎apps/web/src/components/settings/ConnectionsSettings.logic.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ export function parseManualDesktopSshTarget(input: {
218218
throw new Error("SSH host or alias is required.");
219219
}
220220

221-
if (port !== null && (!Number.isInteger(port) || port <= 0 || port > 65_535)) {
222-
throw new Error("SSH port must be between 1 and 65535.");
223-
}
221+
assertSshPort(port);
224222

225223
return {
226224
alias: hostname,
@@ -230,6 +228,29 @@ export function parseManualDesktopSshTarget(input: {
230228
};
231229
}
232230

231+
// A discovered alias is an ssh config Host name, so it is never split into user@host:port.
232+
export function parseDiscoveredDesktopSshTarget(input: {
233+
readonly alias: string;
234+
readonly username: string;
235+
readonly port: string;
236+
}): DesktopSshEnvironmentTarget {
237+
const rawPort = input.port.trim();
238+
const port = rawPort.length > 0 ? Number.parseInt(rawPort, 10) : null;
239+
assertSshPort(port);
240+
return {
241+
alias: input.alias,
242+
hostname: input.alias,
243+
username: input.username.trim() || null,
244+
port,
245+
};
246+
}
247+
248+
function assertSshPort(port: number | null) {
249+
if (port !== null && (!Number.isInteger(port) || port <= 0 || port > 65_535)) {
250+
throw new Error("SSH port must be between 1 and 65535.");
251+
}
252+
}
253+
233254
export function parsePairingUrlFields(
234255
input: string,
235256
): { readonly host: string; readonly pairingCode: string } | null {

0 commit comments

Comments
 (0)