Files
qtalker---/backend/tests/test_frontend_serving.py
Indiana cd9fc49eed fix: prevent app crash when frontend build is missing
StaticFiles defaults to check_dir=True, which raises at import time if
frontend/dist/assets is missing on restart — taking down /healthz and
/auth/* along with the frontend. Pass check_dir=False so the mount never
crashes the app, and make the SPA fallback return a clear 503 instead of
an unhandled 500 when index.html is absent.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013PphXq1s43DNRj1uWKGXof
2026-07-20 17:52:43 +00:00

27 lines
851 B
Python

import pytest
@pytest.mark.asyncio
async def test_unknown_path_serves_spa_index(client):
response = await client.get("/some/client/side/route")
assert response.status_code == 200
assert '<div id="root">' in response.text
@pytest.mark.asyncio
async def test_auth_routes_still_work_alongside_spa_fallback(client):
response = await client.post(
"/auth/register", json={"username": "frontendcheck", "password": "spookyspooky"}
)
assert response.status_code == 201
@pytest.mark.asyncio
async def test_missing_frontend_build_returns_clear_error(client, monkeypatch, tmp_path):
import app.main as main_module
monkeypatch.setattr(main_module, "FRONTEND_DIST", tmp_path)
response = await client.get("/some/route")
assert response.status_code == 503
assert "npm run build" in response.json()["detail"]