import pytest fastapi = pytest.importorskip("fastapi") from fastapi.testclient import TestClient # noqa: E402 from app import app # noqa: E402 def test_root_serves_ui_without_redirect() -> None: client = TestClient(app) response = client.get("/", follow_redirects=False) assert response.status_code == 200 assert "text/html" in response.headers["content-type"] def test_api_chat_valid_request() -> None: client = TestClient(app) response = client.post( "/api/chat", json={ "message": "Give me a risk reward mechanic for stamina.", "project_context": "Tactical fantasy RPG.", "mode": "balance", "retrieval_k": 0, }, ) assert response.status_code == 200 body = response.json() assert set(body) == {"answer", "citations", "retrieved_chunks", "warnings"} assert "No approved source context" in body["answer"] def test_api_chat_rejects_empty_message() -> None: client = TestClient(app) response = client.post( "/api/chat", json={"message": " ", "project_context": "", "mode": "balance", "retrieval_k": 4}, ) assert response.status_code == 422 def test_api_chat_rejects_bad_mode_and_k() -> None: client = TestClient(app) response = client.post( "/api/chat", json={ "message": "Test", "project_context": "", "mode": "bad_mode", "retrieval_k": 20, }, ) assert response.status_code == 422