"""Runtime fallback policy shared by auth/session routes. The in-process stores exist only to keep local development usable when Docker or NAS PostgreSQL is offline. Staging/prod must fail loudly instead of becoming a second source of truth. """ from __future__ import annotations from typing import NoReturn from fastapi import HTTPException, status from .config import settings def runtime_fallback_allowed() -> bool: return settings.environment == "dev" def raise_runtime_fallback_disabled(feature: str) -> NoReturn: raise HTTPException( status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=( f"{feature} persistence unavailable; runtime fallback is disabled " f"in {settings.environment}" ), ) def require_runtime_fallback_allowed(feature: str) -> None: if not runtime_fallback_allowed(): raise_runtime_fallback_disabled(feature)