mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 06:16:37 +00:00
* feat(droid-provider): support ollama cloud anthropic compatible api * fix(droid-provider): move ollama.com to anthropic block to prevent model inference override * fix(droid-provider): move pathname-based generic checks before host-based anthropic check * test(proxy): cover ollama cloud native routing boundaries --------- Co-authored-by: Tam Nhu Tran <kaitran.ntt@gmail.com>
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'bun:test';
|
|
import { resolveOpenAICompatProfileConfig } from '../../../src/proxy/profile-router';
|
|
|
|
describe('resolveOpenAICompatProfileConfig', () => {
|
|
it('detects generic OpenAI-compatible profiles from base URL and provider hint', () => {
|
|
const result = resolveOpenAICompatProfileConfig('hf', '/tmp/hf.settings.json', {
|
|
ANTHROPIC_BASE_URL: 'https://router.huggingface.co/v1',
|
|
ANTHROPIC_AUTH_TOKEN: 'hf_token',
|
|
ANTHROPIC_MODEL: 'openai/gpt-oss-120b:fastest',
|
|
CCS_DROID_PROVIDER: 'generic-chat-completion-api',
|
|
});
|
|
|
|
expect(result).not.toBeNull();
|
|
expect(result?.provider).toBe('generic-chat-completion-api');
|
|
expect(result?.profileName).toBe('hf');
|
|
});
|
|
|
|
it('detects official OpenAI-style endpoints', () => {
|
|
const result = resolveOpenAICompatProfileConfig('openai', '/tmp/openai.settings.json', {
|
|
ANTHROPIC_BASE_URL: 'https://api.openai.com/v1',
|
|
ANTHROPIC_AUTH_TOKEN: 'sk-openai',
|
|
ANTHROPIC_MODEL: 'gpt-4.1',
|
|
CCS_OPENAI_PROXY_INSECURE: 'true',
|
|
});
|
|
|
|
expect(result?.provider).toBe('openai');
|
|
expect(result?.model).toBe('gpt-4.1');
|
|
expect(result?.insecure).toBe(true);
|
|
});
|
|
|
|
it('ignores Anthropic-compatible profiles', () => {
|
|
const result = resolveOpenAICompatProfileConfig('glm', '/tmp/glm.settings.json', {
|
|
ANTHROPIC_BASE_URL: 'https://api.z.ai/api/anthropic',
|
|
ANTHROPIC_AUTH_TOKEN: 'glm-key',
|
|
ANTHROPIC_MODEL: 'glm-5',
|
|
});
|
|
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it('prefers OpenAI-compatible URL inference over stale anthropic provider hints', () => {
|
|
const result = resolveOpenAICompatProfileConfig('q', '/tmp/q.settings.json', {
|
|
ANTHROPIC_BASE_URL: 'https://dashscope-us.aliyuncs.com/compatible-mode/v1',
|
|
ANTHROPIC_AUTH_TOKEN: 'q-token',
|
|
ANTHROPIC_MODEL: 'qwen3.6-plus',
|
|
CCS_DROID_PROVIDER: 'anthropic',
|
|
});
|
|
|
|
expect(result).not.toBeNull();
|
|
expect(result?.provider).toBe('generic-chat-completion-api');
|
|
expect(result?.model).toBe('qwen3.6-plus');
|
|
});
|
|
|
|
it('does not proxy bare ollama.com profiles that are anthropic-native', () => {
|
|
const result = resolveOpenAICompatProfileConfig(
|
|
'ollama-cloud',
|
|
'/tmp/ollama-cloud.settings.json',
|
|
{
|
|
ANTHROPIC_BASE_URL: 'https://ollama.com',
|
|
ANTHROPIC_AUTH_TOKEN: 'ollama-token',
|
|
ANTHROPIC_MODEL: 'qwen3-coder-plus',
|
|
}
|
|
);
|
|
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it('still proxies explicit ollama.com chat-completions endpoints', () => {
|
|
const result = resolveOpenAICompatProfileConfig(
|
|
'ollama-cloud-chat-completions',
|
|
'/tmp/ollama-cloud-chat-completions.settings.json',
|
|
{
|
|
ANTHROPIC_BASE_URL: 'https://ollama.com/v1/chat/completions',
|
|
ANTHROPIC_AUTH_TOKEN: 'ollama-token',
|
|
ANTHROPIC_MODEL: 'qwen3-coder-plus',
|
|
}
|
|
);
|
|
|
|
expect(result).not.toBeNull();
|
|
expect(result?.provider).toBe('generic-chat-completion-api');
|
|
});
|
|
});
|