You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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": []})