diff --git a/tests/clients/test_tui_app.py b/tests/clients/test_tui_app.py index b83ab1c..f534887 100644 --- a/tests/clients/test_tui_app.py +++ b/tests/clients/test_tui_app.py @@ -25,6 +25,32 @@ settings_module._tui_settings = None +@pytest.fixture(autouse=True) +def mock_tui_api(monkeypatch: pytest.MonkeyPatch) -> None: + """Mock the backend REST api so TUI tests never hit a live server. + + Every test mounts NaviCodeTui, whose _startup worker calls api.create_session / + api.get_session and whose _refresh_sessions worker calls api.list_sessions. + Without a server these raise and _ctx.session_id stays None, which breaks any + test that asserts on the session. Tests that assert on stop_session still + monkeypatch it per-test with their own call-tracking list. + """ + import clients.terminal.api as api_module + + def fake_create_session(profile_id: str | None = None) -> dict: + return {"session_id": "test-session", "profile_id": profile_id or "navi_code"} + + def fake_get_session(session_id: str) -> dict: + return {"session_id": session_id, "profile_id": "navi_code"} + + def fake_list_sessions() -> list[dict]: + return [] + + 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) + + @pytest.mark.anyio async def test_tui_mounts_widgets() -> None: """The TUI app mounts chat, status, and input widgets."""