"""Small debug helper to exercise /chat/health with a mocked RAG pipeline. This script is only intended for local developer debugging and should not be used in CI. Keep imports at top to satisfy linters. """ import os from unittest.mock import MagicMock import src.routes.main_routes as main_routes from app import app as flask_app # Ensure imports use package layout os.environ["PYTEST_RUNNING"] = "1" # Create mock health data mock_health_data = { "pipeline": "unhealthy", "components": { "search_service": {"status": "unhealthy", "error": "DB"}, "llm_service": {"status": "unhealthy", "error": "API unreachable"}, "vector_db": {"status": "unhealthy"}, }, } mock_pipeline = MagicMock() mock_pipeline.health_check.return_value = mock_health_data # Patch get_rag_pipeline orig_get = main_routes.get_rag_pipeline main_routes.get_rag_pipeline = lambda: mock_pipeline os.environ["OPENROUTER_API_KEY"] = "test_key" client = flask_app.test_client() resp = client.get("/chat/health") print("status", resp.status_code) print("body", resp.get_data(as_text=True)) # restore main_routes.get_rag_pipeline = orig_get