import unittest from unittest.mock import AsyncMock, patch from pathlib import Path import sys REPO_ROOT = Path(__file__).resolve().parents[1] # Samme flate modulstruktur som i Docker-runtime /app: sys.path.insert(0, str(REPO_ROOT / "opax-mcp")) sys.path.insert(0, str(REPO_ROOT / "emma")) from emma_adapter import CanonicalEmma from emma_identity import get_runtime_system_prompt class TestCanonicalEmmaPhase1B(unittest.IsolatedAsyncioTestCase): def test_runtime_prompt_contains_canonical_identity(self): """(1) Verifies the runtime prompt contains the core identity and rules.""" prompt = get_runtime_system_prompt() self.assertIn("Du er Emma", prompt) self.assertIn("HARD REGLER:", prompt) self.assertNotIn("gcp_project", prompt) self.assertNotIn("opax_url", prompt) async def test_adapter_injects_model_prompt_and_system_prompt(self): """(2) Verifies the adapter calls the injected function with correct args.""" mock_chat_fn = AsyncMock() model = "test-model-456" prompt = "test prompt 123" adapter = CanonicalEmma(chat_function=mock_chat_fn, model=model) await adapter.run(prompt) mock_chat_fn.assert_awaited_once() call_args = mock_chat_fn.call_args self.assertEqual(call_args.args[0], model) self.assertEqual(call_args.args[1], prompt) self.assertEqual(call_args.args[2], get_runtime_system_prompt()) async def test_adapter_returns_raw_response_unchanged(self): """(3) Verifies the adapter returns the original response from the chat function.""" mock_response = {"model": "test-model", "response": "test-response", "done": True} mock_chat_fn = AsyncMock(return_value=mock_response) adapter = CanonicalEmma(chat_function=mock_chat_fn, model="any-model") result = await adapter.run("any-prompt") self.assertEqual(result, mock_response) def test_adapter_has_no_memory_or_tool_execution(self): """(4) Verifies no memory or tool execution is implicitly activated.""" mock_chat_fn = AsyncMock() adapter = CanonicalEmma(chat_function=mock_chat_fn, model="any-model") self.assertFalse(hasattr(adapter, '_memory')) self.assertFalse(hasattr(adapter, '_tool_registry')) if __name__ == '__main__': unittest.main()