import json import httpx import pytest from app.llm.ollama import OllamaProvider def test_ollama_classify_mock(monkeypatch): fake = { "message": { "content": json.dumps( { "type": "task", "sphere": "life", "project_id": "life-trip", "proj_label": "개인 › 여행 — 한국", "tone": "coral", "due_text": "~6/14", "when_text": "오늘 저녁", "extra": "가격 추적", "reason": "구매 행동이라 작업입니다.", "confidence": 0.9, } ) } } class R: status_code = 200 def raise_for_status(self): pass def json(self): return fake monkeypatch.setattr(httpx, "post", lambda *a, **k: R()) c = OllamaProvider().classify_capture("비행기 티켓 사기", {"projects": []}) assert c.type == "task" and c.sphere == "life" assert c.model.startswith("ollama:") def test_ollama_raises_on_error(monkeypatch): # phase-16+: 휴리스틱 폴백 제거 → 미가용 시 예외 전파(실 LLM 전용). def boom(*a, **k): raise httpx.ConnectError("no ollama") monkeypatch.setattr(httpx, "post", boom) with pytest.raises(httpx.ConnectError): OllamaProvider().classify_capture("수요일 11시 자전거 수리", {"projects": []})