Skip to content

Commit b8a9afa

Browse files
committed
refactor: generalize remote environment helpers
1 parent 7e9e8f1 commit b8a9afa

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { getProxyForUrl } from "../api/proxy";
22

33
import type { WorkspaceConfiguration } from "vscode";
44

5+
// Remote-SSH inherits this extension host's process environment only for
6+
// processes it starts after these values are applied. This is best-effort for
7+
// settings like remote.SSH.useLocalServer, where an existing local server may
8+
// already be running with an older environment.
9+
510
export type SshProxyEnvironment = Partial<
611
Record<"HTTP_PROXY" | "HTTPS_PROXY" | "NO_PROXY", string>
712
>;

src/remote/remote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import {
6161
import { vscodeProposed } from "../vscodeProposed";
6262
import { WorkspaceMonitor } from "../workspace/workspaceMonitor";
6363

64-
import { applySshProxyEnvironment } from "./proxyEnvironment";
64+
import { applySshProxyEnvironment } from "./environment";
6565
import {
6666
SshConfig,
6767
type SshValues,
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { spawnSync } from "node:child_process";
12
import { describe, it, expect, beforeEach, vi } from "vitest";
23

34
import {
45
applySshProxyEnvironment,
56
getSshProxyEnvironment,
6-
} from "@/remote/proxyEnvironment";
7+
} from "@/remote/environment";
78

89
import { MockConfigurationProvider } from "../../mocks/testHelpers";
910

@@ -125,4 +126,29 @@ describe("applySshProxyEnvironment", () => {
125126
https_proxy: "http://old-https-proxy.example.com:8080",
126127
});
127128
});
129+
130+
it("propagates proxy variables to child processes", () => {
131+
const cfg = new MockConfigurationProvider();
132+
cfg.set("http.proxy", proxy);
133+
const applied = applySshProxyEnvironment("https://coder.example.com", cfg);
134+
135+
try {
136+
const result = spawnSync(
137+
process.execPath,
138+
[
139+
"-e",
140+
"process.stdout.write(JSON.stringify({ http: process.env.HTTP_PROXY || process.env.http_proxy, https: process.env.HTTPS_PROXY || process.env.https_proxy }))",
141+
],
142+
{ encoding: "utf8" },
143+
);
144+
145+
expect(result.status).toBe(0);
146+
expect(JSON.parse(result.stdout)).toEqual({
147+
http: proxy,
148+
https: proxy,
149+
});
150+
} finally {
151+
applied.dispose();
152+
}
153+
});
128154
});

0 commit comments

Comments
 (0)