from __future__ import annotations from fastapi.testclient import TestClient from app.core.settings import get_settings from app.main import app def test_runtime_config_requires_gateway_secret_when_configured(monkeypatch): monkeypatch.setenv("INTERNAL_GATEWAY_SECRET", "test-secret") get_settings.cache_clear() client = TestClient(app) response = client.get("/api/v1/runtime/config") assert response.status_code == 401 assert response.json()["detail"] == "invalid_gateway_secret" get_settings.cache_clear() def test_runtime_config_returns_non_secret_model_configuration(monkeypatch): monkeypatch.setenv("INTERNAL_GATEWAY_SECRET", "test-secret") monkeypatch.setenv("APP_ENV", "production") monkeypatch.setenv("USE_LLM_PIPELINE", "true") monkeypatch.setenv("CLASSIFIER_MODEL", "mistralai/mistral-small-3.2-24b-instruct") monkeypatch.setenv("CORRECTOR_MODEL", "qwen/qwen3-235b-a22b-2507") monkeypatch.setenv("VERIFIER_MODEL", "mistralai/mistral-small-3.2-24b-instruct") monkeypatch.setenv("PREMIUM_REVIEW_MODEL", "qwen/qwen3-235b-a22b-thinking-2507") monkeypatch.setenv("OPENROUTER_API_KEY", "secret-value-that-must-not-leak") get_settings.cache_clear() client = TestClient(app) response = client.get( "/api/v1/runtime/config", headers={"X-Gateway-Secret": "test-secret"}, ) assert response.status_code == 200 body = response.json() assert body == { "app_env": "production", "use_llm_pipeline": True, "classifier_model": "mistralai/mistral-small-3.2-24b-instruct", "corrector_model": "qwen/qwen3-235b-a22b-2507", "verifier_model": "mistralai/mistral-small-3.2-24b-instruct", "premium_review_model": "qwen/qwen3-235b-a22b-thinking-2507", "llm_timeout_seconds": 60.0, } serialized_body = str(body) assert "OPENROUTER_API_KEY" not in serialized_body assert "secret-value-that-must-not-leak" not in serialized_body get_settings.cache_clear()