"""Query mode helpers (the SSE contract itself lives in test_conversations_api.py).""" from types import SimpleNamespace from app.models import MessageRole from app.modes.query import _topic_transcript def _msg(role: MessageRole, content: str) -> SimpleNamespace: return SimpleNamespace(role=role, content=content) def test_topic_transcript_needs_prior_context() -> None: # A first message alone has no earlier context: the topic fallback is a # no-op, so a first-message miss stays a genuine no-answer. conversation = SimpleNamespace(messages=[]) assert _topic_transcript(conversation, "Wie beantrage ich Urlaub?") == "" def test_topic_transcript_includes_history_and_current() -> None: conversation = SimpleNamespace( messages=[ _msg(MessageRole.user, "Wie beantrage ich Urlaub?"), _msg(MessageRole.assistant, "Über das Personalportal."), ] ) transcript = _topic_transcript(conversation, "Und was war meine erste Frage?") assert "Urlaub" in transcript assert "erste Frage" in transcript assert transcript.count("User:") == 2 def test_topic_transcript_does_not_duplicate_the_current_message() -> None: # The current message may already be persisted as the last stored turn. conversation = SimpleNamespace( messages=[ _msg(MessageRole.user, "Erste Frage."), _msg(MessageRole.assistant, "Antwort."), _msg(MessageRole.user, "Zweite Frage."), ] ) transcript = _topic_transcript(conversation, "Zweite Frage.") assert transcript.count("Zweite Frage.") == 1