diff --git a/backend/app/main.py b/backend/app/main.py index ec4c471..a063c68 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -14,6 +14,9 @@ from datetime import datetime, timezone from pathlib import Path from fastapi import FastAPI +from starlette.middleware.base import BaseHTTPMiddleware +from starlette.requests import Request as StarletteRequest +from starlette.responses import Response from app.core.config import AppConfig from app.core.database import close_db, init_db @@ -109,9 +112,6 @@ app.add_middleware(SessionMiddleware) # --- Security headers middleware (R020: zero outbound telemetry) --- -from starlette.middleware.base import BaseHTTPMiddleware -from starlette.requests import Request as StarletteRequest -from starlette.responses import Response class SecurityHeadersMiddleware(BaseHTTPMiddleware): @@ -150,7 +150,6 @@ app.include_router(themes_router, prefix="/api") # --- Static file serving (production: built frontend) --- _static_dir = Path(__file__).resolve().parent.parent / "static" if _static_dir.is_dir(): - from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse @app.get("/{full_path:path}") diff --git a/backend/app/middleware/session.py b/backend/app/middleware/session.py index cfac82d..1b9e614 100644 --- a/backend/app/middleware/session.py +++ b/backend/app/middleware/session.py @@ -43,7 +43,6 @@ class SessionMiddleware(BaseHTTPMiddleware): # --- Resolve or create session --- cookie_value = request.cookies.get("mrip_session") - new_session = False if cookie_value and _is_valid_uuid4(cookie_value): session_id = cookie_value @@ -54,13 +53,11 @@ class SessionMiddleware(BaseHTTPMiddleware): else: # Valid UUID but not in DB (expired/purged) — recreate await create_session(db, session_id) - new_session = True logger.info("Session recreated (cookie valid, DB miss): %s", session_id) else: # Missing or invalid cookie — brand new session session_id = str(uuid.uuid4()) await create_session(db, session_id) - new_session = True logger.info("New session created: %s", session_id) request.state.session_id = session_id diff --git a/backend/app/routers/cookies.py b/backend/app/routers/cookies.py index b28c0db..f6f16b3 100644 --- a/backend/app/routers/cookies.py +++ b/backend/app/routers/cookies.py @@ -5,7 +5,7 @@ from __future__ import annotations import logging from pathlib import Path -from fastapi import APIRouter, Depends, HTTPException, Request, UploadFile +from fastapi import APIRouter, Depends, Request, UploadFile from app.dependencies import get_session_id diff --git a/backend/app/routers/downloads.py b/backend/app/routers/downloads.py index 87d708e..a423f1b 100644 --- a/backend/app/routers/downloads.py +++ b/backend/app/routers/downloads.py @@ -54,7 +54,6 @@ async def cancel_download( """Delete a download job and remove its file.""" logger.debug("DELETE /downloads/%s", job_id) db = request.app.state.db - download_service = request.app.state.download_service # Fetch the job first to get its session_id and filename job = await get_job(db, job_id) diff --git a/backend/app/services/download.py b/backend/app/services/download.py index 649af22..0d3bfe6 100644 --- a/backend/app/services/download.py +++ b/backend/app/services/download.py @@ -21,7 +21,6 @@ import yt_dlp from app.core.config import AppConfig from app.core.database import ( create_job, - get_job, update_job_progress, update_job_status, ) diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index f87b689..831713a 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -3,8 +3,6 @@ from __future__ import annotations import asyncio -import os -import tempfile from datetime import datetime, timezone from pathlib import Path diff --git a/backend/tests/test_admin.py b/backend/tests/test_admin.py index e8a6d29..f4191dd 100644 --- a/backend/tests/test_admin.py +++ b/backend/tests/test_admin.py @@ -2,7 +2,6 @@ from __future__ import annotations -import asyncio import base64 from datetime import datetime, timezone @@ -13,9 +12,8 @@ from fastapi import FastAPI from httpx import ASGITransport, AsyncClient from app.core.config import AppConfig -from app.core.database import close_db, init_db, create_session, create_job +from app.core.database import close_db, init_db from app.middleware.session import SessionMiddleware -from app.models.job import Job from app.routers.admin import router as admin_router diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index fce65e9..940708a 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -9,7 +9,6 @@ from __future__ import annotations import asyncio import pytest -import pytest_asyncio from httpx import ASGITransport, AsyncClient diff --git a/backend/tests/test_config.py b/backend/tests/test_config.py index b225f7d..3aeb55a 100644 --- a/backend/tests/test_config.py +++ b/backend/tests/test_config.py @@ -2,11 +2,8 @@ from __future__ import annotations -import os -import tempfile from pathlib import Path -import pytest from app.core.config import AppConfig diff --git a/backend/tests/test_database.py b/backend/tests/test_database.py index 0ff8d90..bcf6516 100644 --- a/backend/tests/test_database.py +++ b/backend/tests/test_database.py @@ -6,7 +6,6 @@ import asyncio import uuid from datetime import datetime, timezone -import pytest from app.core.database import ( close_db, diff --git a/backend/tests/test_download_service.py b/backend/tests/test_download_service.py index 878b2f8..1c83a78 100644 --- a/backend/tests/test_download_service.py +++ b/backend/tests/test_download_service.py @@ -7,7 +7,6 @@ and unit tests that only touch the database. from __future__ import annotations import asyncio -import os import pytest import pytest_asyncio @@ -104,7 +103,7 @@ async def test_real_download_produces_file_and_events(download_env): # At least one event should have non-zero percent downloading_events = [e for e in events if e.status == "downloading"] - has_progress = any(e.percent > 0 for e in downloading_events) + any(e.percent > 0 for e in downloading_events) # Some very short videos may not report intermediate progress — # we still assert downloading events exist assert len(downloading_events) > 0 diff --git a/backend/tests/test_file_serving.py b/backend/tests/test_file_serving.py index 9770c3f..0797d39 100644 --- a/backend/tests/test_file_serving.py +++ b/backend/tests/test_file_serving.py @@ -2,9 +2,7 @@ from __future__ import annotations -import uuid from datetime import datetime, timezone -from pathlib import Path import pytest import pytest_asyncio @@ -12,9 +10,8 @@ from fastapi import FastAPI from httpx import ASGITransport, AsyncClient from app.core.config import AppConfig -from app.core.database import close_db, init_db, create_job +from app.core.database import close_db, init_db from app.middleware.session import SessionMiddleware -from app.models.job import Job from app.routers.cookies import router as cookies_router from app.routers.files import router as files_router diff --git a/backend/tests/test_health.py b/backend/tests/test_health.py index f55b4df..c61dc65 100644 --- a/backend/tests/test_health.py +++ b/backend/tests/test_health.py @@ -9,12 +9,10 @@ Covers: from __future__ import annotations -import json import uuid from datetime import datetime, timezone import pytest -import pytest_asyncio from app.core.database import ( create_job, @@ -22,7 +20,7 @@ from app.core.database import ( get_jobs_by_mode, get_queue_depth, ) -from app.models.job import Job, JobStatus +from app.models.job import Job # --------------------------------------------------------------------------- @@ -129,7 +127,6 @@ class TestPublicConfig: @pytest.mark.anyio async def test_public_config_reflects_actual_config(self, tmp_path): """Config values in the response match what AppConfig was built with.""" - import asyncio from datetime import datetime, timezone from fastapi import FastAPI @@ -137,7 +134,6 @@ class TestPublicConfig: from app.core.config import AppConfig from app.core.database import close_db, init_db - from app.core.sse_broker import SSEBroker from app.middleware.session import SessionMiddleware from app.routers.system import router as system_router diff --git a/backend/tests/test_models.py b/backend/tests/test_models.py index 357c6ba..7b70487 100644 --- a/backend/tests/test_models.py +++ b/backend/tests/test_models.py @@ -2,7 +2,6 @@ from __future__ import annotations -import pytest from app.models.job import ( FormatInfo, diff --git a/backend/tests/test_purge.py b/backend/tests/test_purge.py index 78e4738..5690ebf 100644 --- a/backend/tests/test_purge.py +++ b/backend/tests/test_purge.py @@ -4,13 +4,11 @@ from __future__ import annotations import uuid from datetime import datetime, timezone, timedelta -from pathlib import Path import pytest -import pytest_asyncio from app.core.config import AppConfig -from app.core.database import create_job, init_db, close_db +from app.core.database import create_job from app.models.job import Job from app.services.purge import run_purge diff --git a/backend/tests/test_session_middleware.py b/backend/tests/test_session_middleware.py index d7a546d..6cfc526 100644 --- a/backend/tests/test_session_middleware.py +++ b/backend/tests/test_session_middleware.py @@ -2,7 +2,6 @@ from __future__ import annotations -import asyncio import uuid import pytest diff --git a/backend/tests/test_sse.py b/backend/tests/test_sse.py index c9d304d..dec757f 100644 --- a/backend/tests/test_sse.py +++ b/backend/tests/test_sse.py @@ -11,14 +11,12 @@ import contextlib import json import uuid from datetime import datetime, timezone -from unittest.mock import AsyncMock, patch +from unittest.mock import patch -import pytest from app.core.database import create_job, create_session, get_active_jobs_by_session -from app.core.sse_broker import SSEBroker -from app.models.job import Job, JobStatus, ProgressEvent -from app.routers.sse import KEEPALIVE_TIMEOUT, event_generator +from app.models.job import Job, ProgressEvent +from app.routers.sse import event_generator # --------------------------------------------------------------------------- diff --git a/backend/tests/test_sse_broker.py b/backend/tests/test_sse_broker.py index 7b638d4..3b8592d 100644 --- a/backend/tests/test_sse_broker.py +++ b/backend/tests/test_sse_broker.py @@ -5,7 +5,6 @@ from __future__ import annotations import asyncio import threading -import pytest from app.core.sse_broker import SSEBroker