| from __future__ import annotations | |
| def test_ask_survives_best_effort_tracking_failures(client, monkeypatch): | |
| from app.routes import ask | |
| def fail_tracking(*_args, **_kwargs): | |
| raise RuntimeError("tracking failure") | |
| monkeypatch.setattr(ask, "record_topic_attempt", fail_tracking) | |
| monkeypatch.setattr(ask, "record_generation", fail_tracking) | |
| monkeypatch.setattr(ask, "increment_usage", fail_tracking) | |
| response = client.post( | |
| "/ask", | |
| json={ | |
| "question": "Teach photosynthesis in exam scoring points.", | |
| "mode": "exam_answer", | |
| }, | |
| ) | |
| assert response.status_code == 200 | |
| body = response.json() | |
| assert "answer" in body | |