|
1 | 1 | 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, DEFAULT_GEMINI_API_TARGET, emitApiProxyTargetWarnings, emitCliProxyStatusLogs, 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, emitCliProxyStatusLogs, warnClassicPATWithCopilotModel, formatItem, program, parseAgentTimeout, applyAgentTimeout, handlePredownloadAction, resolveApiTargetsToAllowedDomains, extractGhesDomainsFromEngineApiTarget, extractGhecDomainsFromServerUrl } from './cli'; |
3 | 3 | import { redactSecrets } from './redact-secrets'; |
4 | 4 | import * as fs from 'fs'; |
5 | 5 | import * as path from 'path'; |
@@ -2112,6 +2112,46 @@ describe('cli', () => { |
2112 | 2112 | }); |
2113 | 2113 | }); |
2114 | 2114 |
|
| 2115 | + describe('warnClassicPATWithCopilotModel', () => { |
| 2116 | + it('should emit warnings when classic PAT and COPILOT_MODEL are both set', () => { |
| 2117 | + const warns: string[] = []; |
| 2118 | + warnClassicPATWithCopilotModel(true, true, (msg) => warns.push(msg)); |
| 2119 | + expect(warns.length).toBeGreaterThan(0); |
| 2120 | + expect(warns[0]).toContain('COPILOT_MODEL'); |
| 2121 | + expect(warns.some(w => w.includes('classic PAT'))).toBe(true); |
| 2122 | + }); |
| 2123 | + |
| 2124 | + it('should not warn when token is not a classic PAT', () => { |
| 2125 | + const warns: string[] = []; |
| 2126 | + warnClassicPATWithCopilotModel(false, true, (msg) => warns.push(msg)); |
| 2127 | + expect(warns).toHaveLength(0); |
| 2128 | + }); |
| 2129 | + |
| 2130 | + it('should not warn when COPILOT_MODEL is not set', () => { |
| 2131 | + const warns: string[] = []; |
| 2132 | + warnClassicPATWithCopilotModel(true, false, (msg) => warns.push(msg)); |
| 2133 | + expect(warns).toHaveLength(0); |
| 2134 | + }); |
| 2135 | + |
| 2136 | + it('should not warn when neither condition holds', () => { |
| 2137 | + const warns: string[] = []; |
| 2138 | + warnClassicPATWithCopilotModel(false, false, (msg) => warns.push(msg)); |
| 2139 | + expect(warns).toHaveLength(0); |
| 2140 | + }); |
| 2141 | + |
| 2142 | + it('should mention /models endpoint in warning', () => { |
| 2143 | + const warns: string[] = []; |
| 2144 | + warnClassicPATWithCopilotModel(true, true, (msg) => warns.push(msg)); |
| 2145 | + expect(warns.some(w => w.includes('/models'))).toBe(true); |
| 2146 | + }); |
| 2147 | + |
| 2148 | + it('should mention exit code 1 in warning', () => { |
| 2149 | + const warns: string[] = []; |
| 2150 | + warnClassicPATWithCopilotModel(true, true, (msg) => warns.push(msg)); |
| 2151 | + expect(warns.some(w => w.includes('exit code 1'))).toBe(true); |
| 2152 | + }); |
| 2153 | + }); |
| 2154 | + |
2115 | 2155 | describe('resolveApiTargetsToAllowedDomains', () => { |
2116 | 2156 | it('should add copilot-api-target option to allowed domains', () => { |
2117 | 2157 | const domains: string[] = ['github.com']; |
|
0 commit comments