diff --git a/tests/clients/test_tui_themes.py b/tests/clients/test_tui_themes.py index 2ea6f4f..0d1eef1 100644 --- a/tests/clients/test_tui_themes.py +++ b/tests/clients/test_tui_themes.py @@ -24,6 +24,44 @@ settings_module._tui_settings = None +@pytest.fixture(autouse=True) +def mock_tui_api(monkeypatch: pytest.MonkeyPatch) -> None: + """Mock the backend REST api so these tests never hit a live server. + + The mount worker resolves a session and replays its history through + ``load_history``. Against a live backend that replay lands a moment after + the test injected its stream events and wipes the chat, so a theme test + that looks for the streaming bubble finds none — pass/fail depended on + whether a Navi server happened to listen on 8099. + """ + import clients.terminal.api as api_module + + async def fake_create_session(profile_id: str | None = None) -> dict: + return {"session_id": "test-session", "profile_id": profile_id or "navi_code"} + + async def fake_get_session(session_id: str) -> dict: + return {"session_id": session_id, "profile_id": "navi_code"} + + async def fake_list_sessions() -> list[dict]: + return [] + + async def fake_get_profile_model(profile_id: str) -> str | None: + return "configured-model" + + async def fake_list_terminals(session_id: str) -> list[dict]: + return [] + + async def fake_get_todos(session_id: str) -> dict: + return {"tasks": []} + + monkeypatch.setattr(api_module, "create_session", fake_create_session) + monkeypatch.setattr(api_module, "get_session", fake_get_session) + monkeypatch.setattr(api_module, "list_sessions", fake_list_sessions) + monkeypatch.setattr(api_module, "get_profile_model", fake_get_profile_model) + monkeypatch.setattr(api_module, "list_terminals", fake_list_terminals) + monkeypatch.setattr(api_module, "get_todos", fake_get_todos) + + @pytest.mark.anyio async def test_themes_command_opens_picker() -> None: async with NaviCodeTui(new_session=True).run_test() as pilot: