|
1 | | -import { generateDockerCompose, subnetsOverlap, writeConfigs, startContainers, stopContainers, fastKillAgentContainer, isAgentExternallyKilled, resetAgentExternallyKilled, AGENT_CONTAINER_NAME, cleanup, runAgentCommand, validateIdNotInSystemRange, getSafeHostUid, getSafeHostGid, getRealUserHome, extractGhHostFromServerUrl, readGitHubPathEntries, mergeGitHubPathEntries, readEnvFile, MIN_REGULAR_UID, ACT_PRESET_BASE_IMAGE } from './docker-manager'; |
| 1 | +import { generateDockerCompose, subnetsOverlap, writeConfigs, startContainers, stopContainers, fastKillAgentContainer, isAgentExternallyKilled, resetAgentExternallyKilled, AGENT_CONTAINER_NAME, cleanup, runAgentCommand, validateIdNotInSystemRange, getSafeHostUid, getSafeHostGid, getRealUserHome, extractGhHostFromServerUrl, readGitHubPathEntries, mergeGitHubPathEntries, readEnvFile, MIN_REGULAR_UID, ACT_PRESET_BASE_IMAGE, stripScheme } from './docker-manager'; |
2 | 2 | import { WrapperConfig } from './types'; |
3 | 3 | import * as fs from 'fs'; |
4 | 4 | import * as path from 'path'; |
@@ -295,6 +295,28 @@ describe('docker-manager', () => { |
295 | 295 | }); |
296 | 296 | }); |
297 | 297 |
|
| 298 | + describe('stripScheme', () => { |
| 299 | + it('should strip https:// prefix', () => { |
| 300 | + expect(stripScheme('https://my-gateway.example.com')).toBe('my-gateway.example.com'); |
| 301 | + }); |
| 302 | + |
| 303 | + it('should strip http:// prefix', () => { |
| 304 | + expect(stripScheme('http://my-gateway.example.com')).toBe('my-gateway.example.com'); |
| 305 | + }); |
| 306 | + |
| 307 | + it('should preserve bare hostname', () => { |
| 308 | + expect(stripScheme('api.openai.com')).toBe('api.openai.com'); |
| 309 | + }); |
| 310 | + |
| 311 | + it('should normalize URL with path to hostname only', () => { |
| 312 | + expect(stripScheme('https://my-gateway.example.com/some-path')).toBe('my-gateway.example.com'); |
| 313 | + }); |
| 314 | + |
| 315 | + it('should not strip scheme-like substrings in the middle', () => { |
| 316 | + expect(stripScheme('api.https.example.com')).toBe('api.https.example.com'); |
| 317 | + }); |
| 318 | + }); |
| 319 | + |
298 | 320 | describe('generateDockerCompose', () => { |
299 | 321 | const mockConfig: WrapperConfig = { |
300 | 322 | allowedDomains: ['github.com', 'npmjs.org'], |
@@ -2439,6 +2461,22 @@ describe('docker-manager', () => { |
2439 | 2461 | expect(env.ANTHROPIC_API_TARGET).toBe('custom.anthropic-router.internal'); |
2440 | 2462 | }); |
2441 | 2463 |
|
| 2464 | + it('should strip https:// scheme from API target values (gh-aw#25137)', () => { |
| 2465 | + const configWithProxy = { |
| 2466 | + ...mockConfig, |
| 2467 | + enableApiProxy: true, |
| 2468 | + anthropicApiKey: 'sk-ant-test-key', |
| 2469 | + anthropicApiTarget: 'https://my-gateway.example.com', |
| 2470 | + openaiApiKey: 'sk-openai-test', |
| 2471 | + openaiApiTarget: 'https://openai-router.internal', |
| 2472 | + }; |
| 2473 | + const result = generateDockerCompose(configWithProxy, mockNetworkConfigWithProxy); |
| 2474 | + const proxy = result.services['api-proxy']; |
| 2475 | + const env = proxy.environment as Record<string, string>; |
| 2476 | + expect(env.ANTHROPIC_API_TARGET).toBe('my-gateway.example.com'); |
| 2477 | + expect(env.OPENAI_API_TARGET).toBe('openai-router.internal'); |
| 2478 | + }); |
| 2479 | + |
2442 | 2480 | it('should not set ANTHROPIC_API_TARGET in api-proxy when anthropicApiTarget is not provided', () => { |
2443 | 2481 | const configWithProxy = { ...mockConfig, enableApiProxy: true, anthropicApiKey: 'sk-ant-test-key' }; |
2444 | 2482 | const result = generateDockerCompose(configWithProxy, mockNetworkConfigWithProxy); |
|
0 commit comments