feat: implement conversation state management and persistence, enhance sidebar UI

This commit is contained in:
Melvin Ragusa
2025-10-25 18:22:07 +02:00
parent f5afb00a5b
commit da57c43e69
5 changed files with 536 additions and 28 deletions

View 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.")