/** * model-routing — 어려운 질문만 hard_model로, provider가 맞을 때만. */ import { test, describe } from 'node:test'; import assert from 'node:assert/strict'; import { getConfig } from '../src/config/config'; import { decideRoute } from '../src/gateway/chat/model-routing'; function withConfig(cfg: any, fn: () => void) { const c: any = getConfig(); const orig = c.getConfig; c.getConfig = () => cfg; try { fn(); } finally { c.getConfig = orig; } } const base = (activeProvider: string, routing: any) => ({ llm: { provider: activeProvider }, models: { routing } }); describe('decideRoute', () => { test('활성 provider와 routing.provider가 같으면 어려운 질문을 hard_model로', () => { withConfig(base('anthropic', { enabled: true, provider: 'anthropic', hard_model: 'claude-sonnet-5-5' }), () => { const r = decideRoute('이 알고리즘 시간 복잡도를 단계별로 따져줘'); assert.equal(r.model, 'claude-sonnet-5-5'); }); }); test('provider가 다르면 라우팅하지 않는다(엉뚱한 백엔드에 모델 이름 금지)', () => { withConfig(base('anthropic', { enabled: true, provider: 'ollama', hard_model: 'kimi-k2.6:cloud' }), () => { assert.deepEqual(decideRoute('깊이 분석해줘 이 계약서'), {}); }); }); test('routing.provider가 없는 옛 설정은 ollama로 본다', () => { withConfig(base('ollama', { enabled: true, hard_model: 'kimi-k2.6:cloud' }), () => { assert.equal(decideRoute('행렬 고유값 구하는 법').model, 'kimi-k2.6:cloud'); }); withConfig(base('google', { enabled: true, hard_model: 'kimi-k2.6:cloud' }), () => { assert.deepEqual(decideRoute('행렬 고유값 구하는 법'), {}); }); }); test('실시간 조회 턴·이미지 턴·꺼짐 상태는 제외', () => { withConfig(base('anthropic', { enabled: true, provider: 'anthropic', hard_model: 'claude-sonnet-5-5' }), () => { assert.deepEqual(decideRoute('깊이 분석해줘', { skip: true }), {}); assert.deepEqual(decideRoute('깊이 분석해줘', { hasImages: true }), {}); }); withConfig(base('anthropic', { enabled: false, provider: 'anthropic', hard_model: 'claude-sonnet-5-5' }), () => { assert.deepEqual(decideRoute('깊이 분석해줘'), {}); }); }); });