diff options
Diffstat (limited to 'packages/cli')
| -rw-r--r-- | packages/cli/src/config/config.test.ts | 67 | ||||
| -rw-r--r-- | packages/cli/src/config/config.ts | 8 |
2 files changed, 74 insertions, 1 deletions
diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts index 39259fe1..cc0f112a 100644 --- a/packages/cli/src/config/config.test.ts +++ b/packages/cli/src/config/config.test.ts @@ -187,6 +187,73 @@ describe('loadCliConfig', () => { const config = await loadCliConfig(settings, [], 'test-session', argv); expect(config.getShowMemoryUsage()).toBe(true); }); + + it(`should leave proxy to empty by default`, async () => { + process.argv = ['node', 'script.js']; + const argv = await parseArguments(); + const settings: Settings = {}; + const config = await loadCliConfig(settings, [], 'test-session', argv); + expect(config.getProxy()).toBeFalsy(); + }); + + const proxy_url = 'http://localhost:7890'; + const testCases = [ + { + input: { + env_name: 'https_proxy', + proxy_url, + }, + expected: proxy_url, + }, + { + input: { + env_name: 'http_proxy', + proxy_url, + }, + expected: proxy_url, + }, + { + input: { + env_name: 'HTTPS_PROXY', + proxy_url, + }, + expected: proxy_url, + }, + { + input: { + env_name: 'HTTP_PROXY', + proxy_url, + }, + expected: proxy_url, + }, + ]; + testCases.forEach(({ input, expected }) => { + it(`should set proxy to ${expected} according to environment variable [${input.env_name}]`, async () => { + process.env[input.env_name] = input.proxy_url; + process.argv = ['node', 'script.js']; + const argv = await parseArguments(); + const settings: Settings = {}; + const config = await loadCliConfig(settings, [], 'test-session', argv); + expect(config.getProxy()).toBe(expected); + }); + }); + + it('should set proxy when --proxy flag is present', async () => { + process.argv = ['node', 'script.js', '--proxy', 'http://localhost:7890']; + const argv = await parseArguments(); + const settings: Settings = {}; + const config = await loadCliConfig(settings, [], 'test-session', argv); + expect(config.getProxy()).toBe('http://localhost:7890'); + }); + + it('should prioritize CLI flag over environment variable for proxy (CLI http://localhost:7890, environment variable http://localhost:7891)', async () => { + process.env['http_proxy'] = 'http://localhost:7891'; + process.argv = ['node', 'script.js', '--proxy', 'http://localhost:7890']; + const argv = await parseArguments(); + const settings: Settings = {}; + const config = await loadCliConfig(settings, [], 'test-session', argv); + expect(config.getProxy()).toBe('http://localhost:7890'); + }); }); describe('loadCliConfig telemetry', () => { diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index c7c23901..f76d6c60 100644 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -57,6 +57,7 @@ export interface CliArgs { extensions: string[] | undefined; listExtensions: boolean | undefined; ideMode: boolean | undefined; + proxy: string | undefined; } export async function parseArguments(): Promise<CliArgs> { @@ -182,7 +183,11 @@ export async function parseArguments(): Promise<CliArgs> { type: 'boolean', description: 'Run in IDE mode?', }) - + .option('proxy', { + type: 'string', + description: + 'Proxy for gemini client, like schema://user:password@host:port', + }) .version(await getCliVersion()) // This will enable the --version flag based on package.json .alias('v', 'version') .help() @@ -380,6 +385,7 @@ export async function loadCliConfig( }, checkpointing: argv.checkpointing || settings.checkpointing?.enabled, proxy: + argv.proxy || process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || |
