🐛 Pass proxy settings to the model CLI so gateways behind a proxy are reachable
This commit is contained in:
parent
1290f1f6ad
commit
3f8f3f925b
@ -3,6 +3,7 @@ import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { executeCommand, type CommandExecutor } from '../process.js';
|
||||
import { RuntimeError } from '../types.js';
|
||||
import { PROXY_VARIABLES } from '../sandbox.js';
|
||||
import { localCredentialEnv } from './codebuddy.js';
|
||||
|
||||
/**
|
||||
@ -67,6 +68,8 @@ export async function askClaude(
|
||||
env: {
|
||||
PATH: process.env.PATH,
|
||||
HOME: home,
|
||||
// The host's egress proxy, if any: the model gateway may only be reachable through it.
|
||||
...Object.fromEntries(PROXY_VARIABLES.flatMap(key => (process.env[key] ? [[key, process.env[key]]] : []))),
|
||||
// The operator's settings only when this call signs in with the operator's login.
|
||||
...(input.home ? await localCredentialEnv(input.home) : {}),
|
||||
...modelEnv,
|
||||
|
||||
@ -46,6 +46,25 @@ describe('asking the local Claude CLI', () => {
|
||||
expect(seen!.env).not.toHaveProperty('WF_DEV_AUTH_TOKEN');
|
||||
expect(existsSync(seen!.cwd!)).toBe(false);
|
||||
});
|
||||
it('carries the host egress proxy so a gateway behind it stays reachable', async () => {
|
||||
const saved = { https: process.env.https_proxy, token: process.env.WF_DEV_AUTH_TOKEN };
|
||||
process.env.https_proxy = 'http://127.0.0.1:7890';
|
||||
process.env.WF_DEV_AUTH_TOKEN = 'must-not-leak';
|
||||
try {
|
||||
let seen: Command | undefined;
|
||||
await askClaude(input, async command => {
|
||||
seen = command;
|
||||
return { exitCode: 0, stdout: JSON.stringify({ structured_output: {} }), stderr: '', durationMs: 1 };
|
||||
});
|
||||
expect(seen!.env).toMatchObject({ https_proxy: 'http://127.0.0.1:7890' });
|
||||
expect(seen!.env).not.toHaveProperty('WF_DEV_AUTH_TOKEN');
|
||||
} finally {
|
||||
if (saved.https === undefined) delete process.env.https_proxy;
|
||||
else process.env.https_proxy = saved.https;
|
||||
if (saved.token === undefined) delete process.env.WF_DEV_AUTH_TOKEN;
|
||||
else process.env.WF_DEV_AUTH_TOKEN = saved.token;
|
||||
}
|
||||
});
|
||||
it('passes a named model and server-held credential environment to the CLI', async () => {
|
||||
let seen: Command | undefined;
|
||||
await askClaude(
|
||||
|
||||
@ -42,7 +42,20 @@ export function webListener(env = process.env) {
|
||||
|
||||
const inherited = () =>
|
||||
Object.fromEntries(
|
||||
['PATH', 'HOME', 'TMPDIR', 'LANG', 'TERM', 'HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY']
|
||||
// Proxy variables in both spellings: macOS proxy tools usually export the lowercase ones.
|
||||
[
|
||||
'PATH',
|
||||
'HOME',
|
||||
'TMPDIR',
|
||||
'LANG',
|
||||
'TERM',
|
||||
'HTTP_PROXY',
|
||||
'HTTPS_PROXY',
|
||||
'NO_PROXY',
|
||||
'http_proxy',
|
||||
'https_proxy',
|
||||
'no_proxy',
|
||||
]
|
||||
.filter(key => process.env[key])
|
||||
.map(key => [key, process.env[key]]),
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user