Files
stack/tests/prisma/test_llm_full.py
kert 641f366b03
Some checks failed
CI / skinny-install (aco) (push) Successful in 1m17s
CI / skinny-install (api) (push) Successful in 40s
CI / skinny-install (bcda) (push) Successful in 42s
CI / skinny-install (conf) (push) Successful in 35s
CI / skinny-install (perf) (push) Successful in 45s
CI / skinny-install (pfs) (push) Successful in 39s
CI / skinny-install (bib) (push) Successful in 33s
CI / skinny-install (bls) (push) Successful in 33s
CI / skinny-install (ccw) (push) Successful in 38s
CI / skinny-install (cli) (push) Successful in 40s
CI / skinny-install (cms) (push) Successful in 38s
CI / skinny-install (opps) (push) Successful in 44s
CI / skinny-install (rex) (push) Successful in 40s
CI / lint-test (push) Failing after 11m38s
Deploy / build-scan-report (push) Failing after 5m44s
test: deep exercising tests for iom, oig, sync, flow, llm, droplet +
purge stale host-zotero.sqlite

62 new tests that actually exercise module logic with mocked deps.
Deleted host-zotero.sqlite (stale schema causing false drift errors).
All HOST_DB refs now point at the live zotero.sqlite. Tracks #353.
2026-04-17 11:51:13 -04:00

83 lines
2.3 KiB
Python

"""Full tests for prisma.llm — LLM provider abstraction."""
from __future__ import annotations
from unittest.mock import patch
import pytest
from prisma.llm import LLMCall, LLMMessage, LLMResult, LLMTool, make_provider
class TestLLMMessage:
def test_user(self):
m = LLMMessage(role="user", content="hello")
assert m.role == "user"
assert m.content == "hello"
def test_system(self):
m = LLMMessage(role="system", content="you are helpful")
assert m.role == "system"
class TestLLMCall:
def test_basic(self):
call = LLMCall(
messages=[LLMMessage(role="user", content="test")],
max_tokens=100,
)
assert len(call.messages) == 1
assert call.max_tokens == 100
def test_with_tools(self):
tool = LLMTool(
name="classify",
description="classify an item",
schema={"type": "object", "properties": {}},
)
call = LLMCall(
messages=[LLMMessage(role="user", content="test")],
max_tokens=100,
tools=[tool],
)
assert len(call.tools) == 1
class TestLLMResult:
def test_basic(self):
r = LLMResult(
text="pong", tool_calls=[], usage={"input_tokens": 5, "output_tokens": 1}
)
assert r.text == "pong"
assert r.usage["input_tokens"] == 5
def test_with_tool_calls(self):
r = LLMResult(
text="",
tool_calls=[{"name": "classify", "input": {"decision": "include"}}],
usage={"input_tokens": 10, "output_tokens": 20},
)
assert len(r.tool_calls) == 1
class TestMakeProvider:
@patch.dict(
"os.environ",
{"PRISMA_LLM_PROVIDER": "anthropic", "ANTHROPIC_API_KEY": "test-key"},
)
def test_anthropic(self):
try:
provider = make_provider()
assert provider is not None
except ModuleNotFoundError:
pytest.skip("anthropic not installed in this env")
@patch.dict(
"os.environ", {"PRISMA_LLM_PROVIDER": "", "ANTHROPIC_API_KEY": ""}, clear=False
)
def test_missing_provider(self):
try:
make_provider()
except (RuntimeError, ValueError, KeyError, ModuleNotFoundError):
pass