Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Haze <hazeone@users.noreply.github.com>
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { PROVIDER_TYPES, PROVIDER_TYPE_INFO, resolveProviderApiKeyForSave } from '@/lib/providers';
|
|
import {
|
|
BUILTIN_PROVIDER_TYPES,
|
|
getProviderConfig,
|
|
getProviderEnvVar,
|
|
} from '@electron/utils/provider-registry';
|
|
|
|
describe('provider metadata', () => {
|
|
it('includes ark in the frontend provider registry', () => {
|
|
expect(PROVIDER_TYPES).toContain('ark');
|
|
|
|
expect(PROVIDER_TYPE_INFO).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: 'ark',
|
|
name: 'ByteDance Ark',
|
|
requiresApiKey: true,
|
|
defaultBaseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
|
|
showBaseUrl: true,
|
|
showModelId: true,
|
|
}),
|
|
])
|
|
);
|
|
});
|
|
|
|
it('includes ark in the backend provider registry', () => {
|
|
expect(BUILTIN_PROVIDER_TYPES).toContain('ark');
|
|
expect(getProviderEnvVar('ark')).toBe('ARK_API_KEY');
|
|
expect(getProviderConfig('ark')).toEqual({
|
|
baseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
|
|
api: 'openai-completions',
|
|
apiKeyEnv: 'ARK_API_KEY',
|
|
});
|
|
});
|
|
|
|
it('keeps builtin provider sources in sync', () => {
|
|
expect(BUILTIN_PROVIDER_TYPES).toEqual(
|
|
expect.arrayContaining(['anthropic', 'openai', 'google', 'openrouter', 'ark', 'moonshot', 'siliconflow', 'minimax-portal', 'minimax-portal-cn', 'qwen-portal', 'ollama'])
|
|
);
|
|
});
|
|
|
|
it('uses OpenAI-compatible Ollama default base URL', () => {
|
|
expect(PROVIDER_TYPE_INFO).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: 'ollama',
|
|
defaultBaseUrl: 'http://localhost:11434/v1',
|
|
requiresApiKey: false,
|
|
showBaseUrl: true,
|
|
showModelId: true,
|
|
}),
|
|
])
|
|
);
|
|
});
|
|
|
|
it('normalizes provider API keys for save flow', () => {
|
|
expect(resolveProviderApiKeyForSave('ollama', '')).toBe('ollama-local');
|
|
expect(resolveProviderApiKeyForSave('ollama', ' ')).toBe('ollama-local');
|
|
expect(resolveProviderApiKeyForSave('ollama', 'real-key')).toBe('real-key');
|
|
expect(resolveProviderApiKeyForSave('openai', '')).toBeUndefined();
|
|
expect(resolveProviderApiKeyForSave('openai', ' sk-test ')).toBe('sk-test');
|
|
});
|
|
});
|