fixed tests
This commit is contained in:
@@ -72,13 +72,13 @@ from app.utils.external_logging import (
|
||||
ExternalLogHandler,
|
||||
create_external_log_handler,
|
||||
)
|
||||
from app.utils.json_formatter import JSONFormatter
|
||||
from app.utils.logging_compat import get_logger
|
||||
from app.utils.rate_limiter import GlobalRateLimiter
|
||||
from app.utils.runtime_state import ApplicationState, RuntimeState
|
||||
from app.utils.scheduler_lock import release_scheduler_lock
|
||||
from app.utils.session_cache import InMemorySessionCache, NoOpSessionCache
|
||||
from app.utils.setup_state import is_setup_complete_cached, set_setup_complete_cache
|
||||
from app.utils.json_formatter import JSONFormatter
|
||||
from app.utils.logging_compat import get_logger
|
||||
|
||||
log = get_logger("bangui")
|
||||
|
||||
@@ -125,8 +125,15 @@ def _configure_logging(log_level: str, log_file: str | None, settings: Settings
|
||||
level: int = logging.getLevelName(log_level.upper())
|
||||
handlers: list[logging.Handler] = [logging.StreamHandler(sys.stdout)]
|
||||
if log_file:
|
||||
os.makedirs(os.path.dirname(log_file), exist_ok=True)
|
||||
handlers.append(logging.FileHandler(log_file))
|
||||
try:
|
||||
os.makedirs(os.path.dirname(log_file), exist_ok=True)
|
||||
handlers.append(logging.FileHandler(log_file))
|
||||
except (PermissionError, OSError) as exc:
|
||||
log.warning(
|
||||
"log_file_directory_not_created",
|
||||
log_file=log_file,
|
||||
error=str(exc),
|
||||
)
|
||||
|
||||
# Suppress verbose third-party library logs that emit plain text
|
||||
# through the standard library logging module.
|
||||
@@ -163,9 +170,7 @@ def _update_session_cache(app: FastAPI, settings: Settings) -> None:
|
||||
settings: The effective application settings.
|
||||
"""
|
||||
cache_enabled = settings.session_cache_enabled and settings.session_cache_ttl_seconds > 0.0
|
||||
app.state.session_cache = (
|
||||
InMemorySessionCache() if cache_enabled else NoOpSessionCache()
|
||||
)
|
||||
app.state.session_cache = InMemorySessionCache() if cache_enabled else NoOpSessionCache()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
@@ -811,12 +816,12 @@ async def _request_validation_error_handler(
|
||||
# the guard without being explicitly allowed.
|
||||
_EXACT_ALLOWED: frozenset[str] = frozenset(
|
||||
{
|
||||
"/api/v1/setup", # GET/POST /api/v1/setup
|
||||
"/api/v1/health", # Health check endpoint (combined)
|
||||
"/api/v1/health/live", # Kubernetes liveness probe
|
||||
"/api/v1/setup", # GET/POST /api/v1/setup
|
||||
"/api/v1/health", # Health check endpoint (combined)
|
||||
"/api/v1/health/live", # Kubernetes liveness probe
|
||||
"/api/v1/health/ready", # Kubernetes readiness probe
|
||||
"/api/docs", # Swagger UI
|
||||
"/api/redoc", # ReDoc
|
||||
"/api/docs", # Swagger UI
|
||||
"/api/redoc", # ReDoc
|
||||
"/api/openapi.json", # OpenAPI schema
|
||||
},
|
||||
)
|
||||
@@ -971,9 +976,7 @@ def _enforce_single_worker() -> None:
|
||||
"See Docs/Deployment.md § Single-Worker Requirement."
|
||||
)
|
||||
except ValueError as e:
|
||||
raise RuntimeError(
|
||||
f"WEB_CONCURRENCY must be an integer, got: {web_concurrency}"
|
||||
) from e
|
||||
raise RuntimeError(f"WEB_CONCURRENCY must be an integer, got: {web_concurrency}") from e
|
||||
|
||||
# Check explicit BANGUI_WORKERS override (discouraged, still enforced)
|
||||
bangui_workers = os.environ.get("BANGUI_WORKERS")
|
||||
@@ -990,9 +993,7 @@ def _enforce_single_worker() -> None:
|
||||
"See Docs/Deployment.md § Single-Worker Requirement."
|
||||
)
|
||||
except ValueError as e:
|
||||
raise RuntimeError(
|
||||
f"BANGUI_WORKERS must be an integer, got: {bangui_workers}"
|
||||
) from e
|
||||
raise RuntimeError(f"BANGUI_WORKERS must be an integer, got: {bangui_workers}") from e
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -1165,7 +1166,6 @@ def create_app(settings: Settings | None = None) -> FastAPI:
|
||||
# stack is a security-critical defect that must not slip through silently.
|
||||
_assert_middleware_order(app)
|
||||
|
||||
|
||||
# --- Exception handlers ---
|
||||
#
|
||||
# Exception handlers are registered from most specific to least specific. FastAPI evaluates
|
||||
|
||||
Reference in New Issue
Block a user