mirror of
https://github.com/ggozad/oterm.git
synced 2026-10-17 04:33:21 +02:00
The cassette infrastructure is unused on this branch -- no test imports vcr or marks itself with @pytest.mark.vcr, no cassette files exist, and the autouse fixture that set mock provider keys "during VCR playback" was actively fought by tests/unit/test_providers.py via repeated delenv calls. Remove pytest-recording, json_body_serializer.py, the pytest_recording_configure hook, the vcr_config fixture, and the integration marker. Narrow MessageModel.role to Literal["user", "assistant"] -- "system" and "tool" were never produced by any code path. Document in _build_pydantic_history that tool turns from prior runs don't survive reload because the message schema only stores text.
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
from pydantic_ai.messages import ModelRequest, ModelResponse, TextPart, UserPromptPart
|
|
|
|
from oterm.app.widgets.chat import ChatContainer
|
|
from oterm.types import ChatModel, MessageModel
|
|
|
|
|
|
def _container(messages):
|
|
return ChatContainer(
|
|
chat_model=ChatModel(model="m", provider="ollama"), messages=messages
|
|
)
|
|
|
|
|
|
def test_empty_history():
|
|
assert _container([])._build_pydantic_history([]) == []
|
|
|
|
|
|
def test_user_messages_become_model_requests():
|
|
msgs = [MessageModel(chat_id=1, role="user", text="hi")]
|
|
history = _container(msgs)._build_pydantic_history(msgs)
|
|
assert len(history) == 1
|
|
assert isinstance(history[0], ModelRequest)
|
|
assert isinstance(history[0].parts[0], UserPromptPart)
|
|
assert history[0].parts[0].content == "hi"
|
|
|
|
|
|
def test_assistant_messages_become_model_responses():
|
|
msgs = [MessageModel(chat_id=1, role="assistant", text="answer")]
|
|
history = _container(msgs)._build_pydantic_history(msgs)
|
|
assert len(history) == 1
|
|
assert isinstance(history[0], ModelResponse)
|
|
assert isinstance(history[0].parts[0], TextPart)
|
|
assert history[0].parts[0].content == "answer"
|
|
|
|
|
|
def test_alternating_conversation_preserved():
|
|
msgs = [
|
|
MessageModel(chat_id=1, role="user", text="q1"),
|
|
MessageModel(chat_id=1, role="assistant", text="a1"),
|
|
MessageModel(chat_id=1, role="user", text="q2"),
|
|
MessageModel(chat_id=1, role="assistant", text="a2"),
|
|
]
|
|
history = _container(msgs)._build_pydantic_history(msgs)
|
|
assert len(history) == 4
|
|
contents = [p.parts[0].content for p in history]
|
|
assert contents == ["q1", "a1", "q2", "a2"]
|