import { describe, test, expect } from 'vitest'; import { DEFAULT_OPENROUTER_MODEL, DEFAULT_SUPERVISOR_MODEL, getOpenRouterApiKey, hasOpenRouterApiKey, getGeminiApiKey, hasGeminiApiKey } from '../services/apiConfig'; describe('API Configuration & Model Defaults', () => { test('should default to latest Google Gemini 3.8 Flash model', () => { expect(DEFAULT_OPENROUTER_MODEL).toBe('google/gemini-3.8-flash'); expect(DEFAULT_SUPERVISOR_MODEL).toBe('google/gemini-3.8-flash'); }); test('should return trimmed explicit custom API key when provided', () => { const key = getOpenRouterApiKey(' sk-or-v1-custom-key-12345 '); expect(key).toBe('sk-or-v1-custom-key-12345'); }); test('should fallback to environment variable when no argument or stored setting exists', () => { const originalEnv = process.env.OPENROUTER_API_KEY; try { process.env.OPENROUTER_API_KEY = 'sk-or-v1-env-fallback-key'; const key = getOpenRouterApiKey(); expect(key).toBe('sk-or-v1-env-fallback-key'); expect(hasOpenRouterApiKey()).toBe(true); } finally { if (originalEnv !== undefined) { process.env.OPENROUTER_API_KEY = originalEnv; } else { delete process.env.OPENROUTER_API_KEY; } } }); test('should return empty string when no keys are configured', () => { const originalEnv = process.env.OPENROUTER_API_KEY; try { process.env.OPENROUTER_API_KEY = ''; const key = getOpenRouterApiKey(''); expect(key).toBe(''); } finally { if (originalEnv !== undefined) { process.env.OPENROUTER_API_KEY = originalEnv; } } }); test('should resolve Google Gemini API Key from environment or explicit argument', () => { expect(getGeminiApiKey('AIzaSyCustomKey')).toBe('AIzaSyCustomKey'); expect(hasGeminiApiKey()).toBe(true); const originalEnv = process.env.GEMINI_API_KEY; try { process.env.GEMINI_API_KEY = 'AIzaSyFallbackKey'; expect(getGeminiApiKey()).toBe('AIzaSyFallbackKey'); } finally { if (originalEnv !== undefined) { process.env.GEMINI_API_KEY = originalEnv; } } }); });