feat: implement conversation state management and persistence, enhance sidebar UI
This commit is contained in:
34
tests/test_conversation_manager.py
Normal file
34
tests/test_conversation_manager.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from conversation_manager import ConversationManager
|
||||
|
||||
|
||||
def test_conversation_manager_persists_history(tmp_path: Path) -> None:
|
||||
manager = ConversationManager(storage_dir=tmp_path, conversation_id="test")
|
||||
manager.append_message("user", "Hello there!")
|
||||
manager.append_message("assistant", "General Kenobi.")
|
||||
|
||||
conversation_file = tmp_path / "test.json"
|
||||
assert conversation_file.exists()
|
||||
|
||||
data = json.loads(conversation_file.read_text(encoding="utf-8"))
|
||||
assert len(data["messages"]) == 2
|
||||
assert data["messages"][0]["content"] == "Hello there!"
|
||||
|
||||
reloaded = ConversationManager(storage_dir=tmp_path, conversation_id="test")
|
||||
assert [msg["content"] for msg in reloaded.messages] == [
|
||||
"Hello there!",
|
||||
"General Kenobi.",
|
||||
]
|
||||
|
||||
|
||||
def test_conversation_manager_rejects_invalid_role(tmp_path: Path) -> None:
|
||||
manager = ConversationManager(storage_dir=tmp_path, conversation_id="invalid")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
manager.append_message("narrator", "This should fail.")
|
||||
Reference in New Issue
Block a user