diff --git a/src/cli.test.ts b/src/cli.test.ts index 91290b49e..e6e21aa6b 100644 --- a/src/cli.test.ts +++ b/src/cli.test.ts @@ -1,5 +1,5 @@ import { Command } from 'commander'; -import { parseEnvironmentVariables, parseDomains, parseDomainsFile, escapeShellArg, joinShellArgs, parseVolumeMounts, isValidIPv4, isValidIPv6, parseDnsServers, validateAgentImage, isAgentImagePreset, AGENT_IMAGE_PRESETS, processAgentImageOption, processLocalhostKeyword, validateSkipPullWithBuildLocal, validateAllowHostPorts, parseMemoryLimit, validateFormat, validateApiProxyConfig, buildRateLimitConfig, validateRateLimitFlags } from './cli'; +import { parseEnvironmentVariables, parseDomains, parseDomainsFile, escapeShellArg, joinShellArgs, parseVolumeMounts, isValidIPv4, isValidIPv6, parseDnsServers, validateAgentImage, isAgentImagePreset, AGENT_IMAGE_PRESETS, processAgentImageOption, processLocalhostKeyword, validateSkipPullWithBuildLocal, validateAllowHostPorts, parseMemoryLimit, validateFormat, validateApiProxyConfig, buildRateLimitConfig, validateRateLimitFlags, validateApiTargetInAllowedDomains, DEFAULT_OPENAI_API_TARGET, DEFAULT_ANTHROPIC_API_TARGET } from './cli'; import { redactSecrets } from './redact-secrets'; import * as fs from 'fs'; import * as path from 'path'; @@ -1561,4 +1561,87 @@ describe('cli', () => { expect(parseMemoryLimit('0g')).toHaveProperty('error'); }); }); + + describe('DEFAULT_OPENAI_API_TARGET and DEFAULT_ANTHROPIC_API_TARGET', () => { + it('should have correct default values', () => { + expect(DEFAULT_OPENAI_API_TARGET).toBe('api.openai.com'); + expect(DEFAULT_ANTHROPIC_API_TARGET).toBe('api.anthropic.com'); + }); + }); + + describe('validateApiTargetInAllowedDomains', () => { + it('should return null when using the default host', () => { + const result = validateApiTargetInAllowedDomains( + 'api.openai.com', + 'api.openai.com', + '--openai-api-target', + ['example.com'] + ); + expect(result).toBeNull(); + }); + + it('should return null when custom host is in allowed domains', () => { + const result = validateApiTargetInAllowedDomains( + 'custom.example.com', + 'api.openai.com', + '--openai-api-target', + ['custom.example.com', 'other.com'] + ); + expect(result).toBeNull(); + }); + + it('should return null when custom host matches a parent domain in allowed list', () => { + const result = validateApiTargetInAllowedDomains( + 'llm-router.internal.example.com', + 'api.openai.com', + '--openai-api-target', + ['example.com'] + ); + expect(result).toBeNull(); + }); + + it('should return null when custom host matches a dotted parent domain in allowed list', () => { + const result = validateApiTargetInAllowedDomains( + 'api.example.com', + 'api.openai.com', + '--openai-api-target', + ['.example.com'] + ); + expect(result).toBeNull(); + }); + + it('should return a warning when custom host is not in allowed domains', () => { + const result = validateApiTargetInAllowedDomains( + 'custom.llm-router.internal', + 'api.openai.com', + '--openai-api-target', + ['github.com', 'api.openai.com'] + ); + expect(result).not.toBeNull(); + expect(result).toContain('--openai-api-target=custom.llm-router.internal'); + expect(result).toContain('--allow-domains'); + }); + + it('should return a warning with the correct flag name and host', () => { + const result = validateApiTargetInAllowedDomains( + 'custom.anthropic-router.com', + 'api.anthropic.com', + '--anthropic-api-target', + [] + ); + expect(result).not.toBeNull(); + expect(result).toContain('--anthropic-api-target=custom.anthropic-router.com'); + }); + + it('should return null when allowed domains list is empty and using default host', () => { + const result = validateApiTargetInAllowedDomains( + 'api.anthropic.com', + 'api.anthropic.com', + '--anthropic-api-target', + [] + ); + expect(result).toBeNull(); + }); + }); + }); diff --git a/src/pid-tracker.test.ts b/src/pid-tracker.test.ts index 25a6c188b..a765d012c 100644 --- a/src/pid-tracker.test.ts +++ b/src/pid-tracker.test.ts @@ -538,7 +538,9 @@ describe('pid-tracker', () => { const pid = process.pid; const info = getProcessInfo(pid); expect(info).not.toBeNull(); - expect(info!.comm).toContain('node'); + // Modern Node.js (v17+) sets comm to 'MainThread' instead of 'node' + // via prctl(PR_SET_NAME); check cmdline instead, which reliably contains the node binary + expect(info!.cmdline).toContain('node'); }); } });