import pytest import sys import os from unittest.mock import MagicMock, patch # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) from app import build_agent_prompt, detect_language def test_build_agent_prompt_structure(): """Verifies that the agent prompt contains the Proactivity Patch rules.""" user_msg = "What is my future?" user_lang = "English" context = "Source: doc.txt Content: Knowledge" prompt = build_agent_prompt(user_msg, user_lang, context) assert "ORACLE MANDATE" in prompt assert "DO NOT ASK FOR PERMISSION" in prompt assert user_lang in prompt assert "Knowledge" in prompt assert user_msg in prompt @patch("app.get_llm") def test_detect_language_logic(mock_get_llm): """Verifies that detect_language correctly parses model output.""" # Mocking LLM and Processor mock_model = MagicMock() mock_processor = MagicMock() mock_get_llm.return_value = (mock_model, mock_processor) # Mock generation output mock_processor.batch_decode.return_value = [" German "] detected = detect_language("Hallo wie gehts") assert detected == "German" assert mock_processor.apply_chat_template.called def test_spiritual_tool_mandate_in_german(): """Ensures German instructions are respected in prompt synthesis.""" prompt = build_agent_prompt("Hallo", "German") assert "The user speaks German" in prompt assert "Always reply to the user in German" in prompt