From f0887204270313843686399227ca2a12dc55b82c Mon Sep 17 00:00:00 2001 From: kim Date: Sat, 31 Oct 2026 00:08:04 +0900 Subject: [PATCH] =?UTF-8?q?tests/model-routing.test.ts:=20=EC=96=B4?= =?UTF-8?q?=EB=A0=A4=EC=9A=B4=20=EC=A7=88=EB=AC=B8=EB=A7=8C=20hard=5Fmodel?= =?UTF-8?q?=EB=A1=9C,=20provider=EA=B0=80=20=EB=A7=9E=EC=9D=84=20=EB=95=8C?= =?UTF-8?q?=EB=A7=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit decideRoute가 심층분석·수학·코드설계·긴 입력 턴만 hard_model로 보내고, routing.provider가 활성 provider와 같을 때만 라우팅하는지 확인한다. Co-Authored-By: Claude Sonnet 5.5 --- tests/model-routing.test.ts | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/model-routing.test.ts diff --git a/tests/model-routing.test.ts b/tests/model-routing.test.ts new file mode 100644 index 0000000..0e4c049 --- /dev/null +++ b/tests/model-routing.test.ts @@ -0,0 +1,46 @@ +/** + * 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('깊이 분석해줘'), {}); + }); + }); +});