Skip to content

Commit cf63417

Browse files
committed
Address review comments
1 parent e7f92b2 commit cf63417

File tree

4 files changed

+73
-20
lines changed

4 files changed

+73
-20
lines changed

src/remote/remote.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -741,21 +741,24 @@ export class Remote {
741741
featureSet: FeatureSet,
742742
): vscode.Disposable {
743743
return vscode.workspace.onDidChangeConfiguration((e) => {
744-
if (e.affectsConfiguration("coder.proxyLogDirectory")) {
745-
const newLogDir = this.getLogDir(featureSet);
746-
if (newLogDir !== currentLogDir) {
747-
vscode.window
748-
.showInformationMessage(
749-
"Log directory configuration changed. Reload window to apply.",
750-
"Reload",
751-
)
752-
.then((action) => {
753-
if (action === "Reload") {
754-
vscode.commands.executeCommand("workbench.action.reloadWindow");
755-
}
756-
});
757-
}
744+
if (!e.affectsConfiguration("coder.proxyLogDirectory")) {
745+
return;
758746
}
747+
const newLogDir = this.getLogDir(featureSet);
748+
if (newLogDir === currentLogDir) {
749+
return;
750+
}
751+
752+
vscode.window
753+
.showInformationMessage(
754+
"Log directory configuration changed. Reload window to apply.",
755+
"Reload",
756+
)
757+
.then((action) => {
758+
if (action === "Reload") {
759+
vscode.commands.executeCommand("workbench.action.reloadWindow");
760+
}
761+
});
759762
});
760763
}
761764

src/remote/sshProcess.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ export class SshProcessMonitor implements vscode.Disposable {
135135

136136
/**
137137
* Searches for the SSH process indefinitely until found or disposed.
138-
* Tries port-based discovery first (more accurate), falls back to hostname-based.
139-
* When found, starts monitoring.
138+
* Starts monitoring when it finds the process through the port.
140139
*/
141140
private async searchForProcess(): Promise<void> {
142141
const { pollInterval, logger, sshHost } = this.options;

src/util.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ export interface AuthorityParts {
1414
export const AuthorityPrefix = "coder-vscode";
1515

1616
// Regex patterns to find the SSH port from Remote SSH extension logs.
17-
// `ms-vscode-remote.remote-ssh`: `-> socksPort <port> ->`
17+
// `ms-vscode-remote.remote-ssh`: `-> socksPort <port> ->` or `between local port <port>`
1818
// `codeium.windsurf-remote-openssh`, `jeanp413.open-remote-ssh`, `google.antigravity-remote-openssh`: `=> <port>(socks) =>`
19-
// Windows `ms-vscode-remote.remote-ssh`: `between local port <port>`
2019
// `anysphere.remote-ssh`: `Socks port: <port>`
2120
export const RemoteSSHLogPortRegex =
22-
/(?:-> socksPort (\d+) ->|=> (\d+)\(socks\) =>|between local port (\d+)|Socks port: (\d+))/g;
21+
/(?:-> socksPort (\d+) ->|between local port (\d+)|=> (\d+)\(socks\) =>|Socks port: (\d+))/g;
2322

2423
/**
2524
* Given the contents of a Remote - SSH log file, find the most recent port
@@ -34,7 +33,11 @@ export function findPort(text: string): number | null {
3433
return null;
3534
}
3635

36+
// Get the last match, which is the most recent port.
3737
const lastMatch = allMatches.at(-1)!;
38+
// Each capture group corresponds to a different Remote SSH extension log format:
39+
// [0] full match, [1] and [2] ms-vscode-remote.remote-ssh,
40+
// [3] windsurf/open-remote-ssh/antigravity, [4] anysphere.remote-ssh
3841
const portStr = lastMatch[1] || lastMatch[2] || lastMatch[3] || lastMatch[4];
3942
if (!portStr) {
4043
return null;

test/unit/util.test.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { describe, it, expect } from "vitest";
22

3-
import { countSubstring, parseRemoteAuthority, toSafeHost } from "@/util";
3+
import {
4+
countSubstring,
5+
findPort,
6+
parseRemoteAuthority,
7+
toSafeHost,
8+
} from "@/util";
49

510
it("ignore unrelated authorities", () => {
611
const tests = [
@@ -124,3 +129,46 @@ describe("countSubstring", () => {
124129
expect(countSubstring("aa", "aaaaaa")).toBe(3);
125130
});
126131
});
132+
133+
describe("findPort", () => {
134+
it.each([[""], ["some random log text without ports"]])(
135+
"returns null for <%s>",
136+
(input) => {
137+
expect(findPort(input)).toBe(null);
138+
},
139+
);
140+
141+
it.each([
142+
[
143+
"ms-vscode-remote.remote-ssh",
144+
"[10:30:45] SSH established -> socksPort 12345 -> ready",
145+
12345,
146+
],
147+
[
148+
"ms-vscode-remote.remote-ssh[2]",
149+
"Forwarding between local port 54321 and remote",
150+
54321,
151+
],
152+
[
153+
"windsurf/open-remote-ssh/antigravity",
154+
"[INFO] Connection => 9999(socks) => target",
155+
9999,
156+
],
157+
[
158+
"anysphere.remote-ssh",
159+
"[DEBUG] Initialized Socks port: 8888 proxy",
160+
8888,
161+
],
162+
])("finds port from %s log format", (_name, input, expected) => {
163+
expect(findPort(input)).toBe(expected);
164+
});
165+
166+
it("returns most recent port when multiple matches exist", () => {
167+
const log = `
168+
[10:30:00] Starting connection -> socksPort 1111 -> initialized
169+
[10:30:05] Reconnecting => 2222(socks) => retry
170+
[10:30:10] Final connection Socks port: 3333 established
171+
`;
172+
expect(findPort(log)).toBe(3333);
173+
});
174+
});

0 commit comments

Comments
 (0)