Skip to content

Commit 17d9395

Browse files
CopilotlpcoxCopilot
authored
test: add missing Gemini API target test coverage to fix CI branch coverage regression (#1662)
* test: add missing Gemini API target test coverage in cli.test.ts Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/0ed05562-3ddb-490f-9b6a-dd5cfa3bb0fc * fix: rename describe block to reflect all API target constants Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Landon Cox <landon.cox@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6a0b75d commit 17d9395

File tree

1 file changed

+74
-2
lines changed

1 file changed

+74
-2
lines changed

src/cli.test.ts

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command } from 'commander';
2-
import { parseEnvironmentVariables, parseDomains, parseDomainsFile, escapeShellArg, joinShellArgs, parseVolumeMounts, isValidIPv4, isValidIPv6, parseDnsServers, parseDnsOverHttps, validateAgentImage, isAgentImagePreset, AGENT_IMAGE_PRESETS, processAgentImageOption, processLocalhostKeyword, validateSkipPullWithBuildLocal, validateAllowHostPorts, validateAllowHostServicePorts, applyHostServicePortsConfig, parseMemoryLimit, validateFormat, validateApiProxyConfig, buildRateLimitConfig, validateRateLimitFlags, hasRateLimitOptions, collectRulesetFile, validateApiTargetInAllowedDomains, DEFAULT_OPENAI_API_TARGET, DEFAULT_ANTHROPIC_API_TARGET, DEFAULT_COPILOT_API_TARGET, emitApiProxyTargetWarnings, formatItem, program, parseAgentTimeout, applyAgentTimeout, handlePredownloadAction, resolveApiTargetsToAllowedDomains, extractGhesDomainsFromEngineApiTarget, extractGhecDomainsFromServerUrl } from './cli';
2+
import { parseEnvironmentVariables, parseDomains, parseDomainsFile, escapeShellArg, joinShellArgs, parseVolumeMounts, isValidIPv4, isValidIPv6, parseDnsServers, parseDnsOverHttps, validateAgentImage, isAgentImagePreset, AGENT_IMAGE_PRESETS, processAgentImageOption, processLocalhostKeyword, validateSkipPullWithBuildLocal, validateAllowHostPorts, validateAllowHostServicePorts, applyHostServicePortsConfig, parseMemoryLimit, validateFormat, validateApiProxyConfig, buildRateLimitConfig, validateRateLimitFlags, hasRateLimitOptions, collectRulesetFile, validateApiTargetInAllowedDomains, DEFAULT_OPENAI_API_TARGET, DEFAULT_ANTHROPIC_API_TARGET, DEFAULT_COPILOT_API_TARGET, DEFAULT_GEMINI_API_TARGET, emitApiProxyTargetWarnings, formatItem, program, parseAgentTimeout, applyAgentTimeout, handlePredownloadAction, resolveApiTargetsToAllowedDomains, extractGhesDomainsFromEngineApiTarget, extractGhecDomainsFromServerUrl } from './cli';
33
import { redactSecrets } from './redact-secrets';
44
import * as fs from 'fs';
55
import * as path from 'path';
@@ -1780,11 +1780,12 @@ describe('cli', () => {
17801780
});
17811781
});
17821782

1783-
describe('DEFAULT_OPENAI_API_TARGET and DEFAULT_ANTHROPIC_API_TARGET', () => {
1783+
describe('DEFAULT_*_API_TARGET constants', () => {
17841784
it('should have correct default values', () => {
17851785
expect(DEFAULT_OPENAI_API_TARGET).toBe('api.openai.com');
17861786
expect(DEFAULT_ANTHROPIC_API_TARGET).toBe('api.anthropic.com');
17871787
expect(DEFAULT_COPILOT_API_TARGET).toBe('api.githubcopilot.com');
1788+
expect(DEFAULT_GEMINI_API_TARGET).toBe('generativelanguage.googleapis.com');
17881789
});
17891790
});
17901791

@@ -1988,6 +1989,55 @@ describe('cli', () => {
19881989
expect(warnings[1]).toContain('--anthropic-api-target=anthropic.internal');
19891990
expect(warnings[2]).toContain('--copilot-api-target=copilot.internal');
19901991
});
1992+
1993+
it('should emit warning for custom Gemini target not in allowed domains', () => {
1994+
const warnings: string[] = [];
1995+
emitApiProxyTargetWarnings(
1996+
{ enableApiProxy: true, geminiApiTarget: 'custom.gemini-router.internal' },
1997+
['github.com'],
1998+
(msg) => warnings.push(msg)
1999+
);
2000+
expect(warnings).toHaveLength(1);
2001+
expect(warnings[0]).toContain('--gemini-api-target=custom.gemini-router.internal');
2002+
});
2003+
2004+
it('should emit no warnings when custom Gemini target is in allowed domains', () => {
2005+
const warnings: string[] = [];
2006+
emitApiProxyTargetWarnings(
2007+
{ enableApiProxy: true, geminiApiTarget: 'gemini.example.com' },
2008+
['example.com'],
2009+
(msg) => warnings.push(msg)
2010+
);
2011+
expect(warnings).toHaveLength(0);
2012+
});
2013+
2014+
it('should use default Gemini target when geminiApiTarget is undefined', () => {
2015+
const warnings: string[] = [];
2016+
emitApiProxyTargetWarnings(
2017+
{ enableApiProxy: true, geminiApiTarget: undefined },
2018+
['github.com'],
2019+
(msg) => warnings.push(msg)
2020+
);
2021+
// Default target is not in 'github.com' but since it IS the default, no warning is emitted
2022+
expect(warnings).toHaveLength(0);
2023+
});
2024+
2025+
it('should emit warnings for all four custom targets when none are in allowed domains', () => {
2026+
const warnings: string[] = [];
2027+
emitApiProxyTargetWarnings(
2028+
{
2029+
enableApiProxy: true,
2030+
openaiApiTarget: 'openai.internal',
2031+
anthropicApiTarget: 'anthropic.internal',
2032+
copilotApiTarget: 'copilot.internal',
2033+
geminiApiTarget: 'gemini.internal',
2034+
},
2035+
['github.com'],
2036+
(msg) => warnings.push(msg)
2037+
);
2038+
expect(warnings).toHaveLength(4);
2039+
expect(warnings[3]).toContain('--gemini-api-target=gemini.internal');
2040+
});
19912041
});
19922042

19932043
describe('resolveApiTargetsToAllowedDomains', () => {
@@ -2117,6 +2167,28 @@ describe('cli', () => {
21172167
// Whitespace-only and empty values are filtered out
21182168
expect(domains).toHaveLength(0);
21192169
});
2170+
2171+
it('should add gemini-api-target option to allowed domains', () => {
2172+
const domains: string[] = ['github.com'];
2173+
resolveApiTargetsToAllowedDomains({ geminiApiTarget: 'custom.gemini.internal' }, domains);
2174+
expect(domains).toContain('custom.gemini.internal');
2175+
expect(domains).toContain('https://custom.gemini.internal');
2176+
});
2177+
2178+
it('should read GEMINI_API_TARGET from env when flag not set', () => {
2179+
const domains: string[] = [];
2180+
const env = { GEMINI_API_TARGET: 'env.gemini.internal' };
2181+
resolveApiTargetsToAllowedDomains({}, domains, env);
2182+
expect(domains).toContain('env.gemini.internal');
2183+
});
2184+
2185+
it('should prefer geminiApiTarget option over GEMINI_API_TARGET env var', () => {
2186+
const domains: string[] = [];
2187+
const env = { GEMINI_API_TARGET: 'env.gemini.internal' };
2188+
resolveApiTargetsToAllowedDomains({ geminiApiTarget: 'flag.gemini.internal' }, domains, env);
2189+
expect(domains).toContain('flag.gemini.internal');
2190+
expect(domains).not.toContain('env.gemini.internal');
2191+
});
21202192
});
21212193

21222194
describe('formatItem', () => {

0 commit comments

Comments
 (0)