"""Unit tests: app factory edge cases (no live DB needed).""" from __future__ import annotations from fastapi.testclient import TestClient import app.main as main_mod def test_create_app_warns_and_serves_api_only_without_static_dir( monkeypatch, tmp_path ) -> None: """If the frontend directory is missing, the API still boots (PLAN §7).""" monkeypatch.setattr( main_mod.settings, "static_dir", str(tmp_path / "definitely-missing") ) app2 = main_mod.create_app() client = TestClient(app2) # /api still works… assert client.get("/api/health").status_code == 200 # …but the static mount is absent (no index page). assert client.get("/").status_code == 404 def test_create_app_wires_caching_middleware() -> None: """Phase 33: the app factory always attaches the cache-busting middleware (by name) — even when the static dir is missing, so the /api/* no-touch guarantee holds in every environment.""" app2 = main_mod.create_app() # ``mw.cls`` is starlette's opaque ``_MiddlewareFactory`` protocol — # reach for ``__name__`` the same way starlette's own __repr__ does. middleware_names = [getattr(mw.cls, "__name__", "") for mw in app2.user_middleware] assert "CachingMiddleware" in middleware_names