import fastapi import pytest from fastapi.testclient import TestClient import api def test_health_readiness_and_bearer_auth(monkeypatch): client = TestClient(api.app) assert client.get("/healthz").status_code == 200 assert client.get("/readyz").status_code == 503 monkeypatch.setenv("NAYARA_API_KEY", "test-secret") assert client.get("/v1/models").status_code == 401 response = client.get("/v1/models", headers={"Authorization": "Bearer test-secret"}) assert response.status_code == 200 assert response.json()["data"][0]["id"] == "nayara-v1" def test_chat_prompt_requires_user_message(): with pytest.raises(fastapi.HTTPException): api._chat_prompt([api.ChatMessage(role="system", content="Be concise")]) prompt = api._chat_prompt([api.ChatMessage(role="user", content="hello")]) assert prompt.endswith("<|assistant|>\n")