The open-source AI voice studio. Clone, dictate, create.
fix(backend): break the app<->routes import cycle that aborts the test suite
Serge Simono3e240a9ef199
diff --git a/backend/app.py b/backend/app.pyindex ea8411cb..c7a4029b 100644--- a/backend/app.py+++ b/backend/app.py@@ -105,28 +105,18 @@ if not os.environ.get("MIOPEN_LOG_LEVEL"):import torchfrom fastapi import FastAPIfrom fastapi.middleware.cors import CORSMiddleware-from urllib.parse import quotefrom . import __version__, config, databasefrom .services import tts, transcribe, llmfrom .database import get_dbfrom .utils.platform_detect import get_backend_typefrom .utils.progress import get_progress_manager+# Re-exported for backwards compatibility with callers importing it from here.+from .utils.http import safe_content_disposition as safe_content_dispositionfrom .services.task_queue import create_background_task, init_queuefrom .routes import register_routers-def safe_content_disposition(disposition_type: str, filename: str) -> str:- """Build a Content-Disposition header safe for non-ASCII filenames.-- Uses RFC 5987 ``filename*`` parameter so browsers can decode UTF-8- filenames while the ``filename`` fallback stays ASCII-only.- """- ascii_name = "".join(c for c in filename if c.isascii() and (c.isalnum() or c in " -_.")).strip() or "download"- utf8_name = quote(filename, safe="")- return f"{disposition_type}; filename=\"{ascii_name}\"; filename*=UTF-8''{utf8_name}"--def create_app() -> FastAPI:"""Create and configure the FastAPI application."""from .mcp_server.server import build_mcp_server, compose_lifespandiff --git a/backend/routes/history.py b/backend/routes/history.pyindex 694d35be..4b7e2222 100644--- a/backend/routes/history.py+++ b/backend/routes/history.py@@ -8,7 +8,7 @@ from sqlalchemy.orm import Sessionfrom .. import config, modelsfrom ..services import export_import, history-from ..app import safe_content_disposition+from ..utils.http import safe_content_dispositionfrom ..database import Generation as DBGeneration, VoiceProfile as DBVoiceProfile, get_dbrouter = APIRouter()diff --git a/backend/routes/profiles.py b/backend/routes/profiles.pyindex 68e5f2af..b5658dea 100644--- a/backend/routes/profiles.py+++ b/backend/routes/profiles.py@@ -12,7 +12,7 @@ from fastapi.responses import FileResponse, StreamingResponsefrom sqlalchemy.orm import Sessionfrom .. import config, models-from ..app import safe_content_disposition+from ..utils.http import safe_content_dispositionfrom ..database import VoiceProfile as DBVoiceProfile, get_dbfrom ..services import channels, export_import, personality, profilesfrom ..services.profiles import _profile_to_responsediff --git a/backend/routes/stories.py b/backend/routes/stories.pyindex 73757d34..0c6237a8 100644--- a/backend/routes/stories.py+++ b/backend/routes/stories.py@@ -8,7 +8,7 @@ from sqlalchemy.orm import Sessionfrom .. import database, modelsfrom ..services import stories-from ..app import safe_content_disposition+from ..utils.http import safe_content_dispositionfrom ..database import get_dbrouter = APIRouter()diff --git a/backend/tests/test_profile_duplicate_names.py b/backend/tests/test_profile_duplicate_names.pyindex 55ee8587..1a9b5672 100644--- a/backend/tests/test_profile_duplicate_names.py+++ b/backend/tests/test_profile_duplicate_names.py@@ -12,13 +12,9 @@ from pathlib import Pathfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker-# Add parent directory to path to import backend modules-import sys-sys.path.insert(0, str(Path(__file__).parent.parent))--from database import Base, VoiceProfile as DBVoiceProfile-from models import VoiceProfileCreate-from profiles import create_profile, update_profile+from backend.database import Base, VoiceProfile as DBVoiceProfile+from backend.models import VoiceProfileCreate+from backend.services.profiles import create_profile, update_profile@pytest.fixturediff --git a/backend/utils/http.py b/backend/utils/http.pynew file mode 100644index 00000000..d29a72bb--- /dev/null+++ b/backend/utils/http.py@@ -0,0 +1,19 @@+"""HTTP header helpers shared by the download routes.++Lives here rather than in ``app`` so route modules can use it without+importing the application module — ``app`` builds the FastAPI instance at+import time, which registers those same routers and closes an import cycle.+"""++from urllib.parse import quote+++def safe_content_disposition(disposition_type: str, filename: str) -> str:+ """Build a Content-Disposition header safe for non-ASCII filenames.++ Uses RFC 5987 ``filename*`` parameter so browsers can decode UTF-8+ filenames while the ``filename`` fallback stays ASCII-only.+ """+ ascii_name = "".join(c for c in filename if c.isascii() and (c.isalnum() or c in " -_.")).strip() or "download"+ utf8_name = quote(filename, safe="")+ return f"{disposition_type}; filename=\"{ascii_name}\"; filename*=UTF-8''{utf8_name}"