From c37b2a3a0ffcaa3f75fc029a860ee917d2a74456 Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Sun, 2 Aug 2026 18:34:26 +0200 Subject: [PATCH] refactor: remove downloader compatibility aliases --- core/download/api.py | 47 ------------------------------- core/download/previews.py | 2 +- core/download/state.py | 5 ++-- core/routes/settings.py | 4 +-- tests/test_path_security.py | 19 +++++++------ tests/test_refactoring_targets.py | 2 +- tests/test_resolver_robustness.py | 12 ++++---- tests/test_unified_helpers.py | 2 +- 8 files changed, 22 insertions(+), 71 deletions(-) diff --git a/core/download/api.py b/core/download/api.py index 865f61b..9c7fd90 100644 --- a/core/download/api.py +++ b/core/download/api.py @@ -353,50 +353,3 @@ resume_download = context.resume_download start_aria2_daemon = context.start_aria2_daemon stop_aria2_daemon = context.stop_aria2_daemon write_model_resolver_metadata = context.write_model_resolver_metadata - -# Internal test and integration seams remain available from the composed module, -# while the public facade above exports only supported download operations. -Aria2Error = context.Aria2Error -_aria2_action_error_is_ok = context._aria2_action_error_is_ok -_aria2_rpc = context._aria2_rpc -_aria2_tell_status = context._aria2_tell_status -_delete_partial_download_files = context._delete_partial_download_files -_delete_python_partial_download_file = context._delete_python_partial_download_file -_delete_xet_partial_file = context._delete_xet_partial_file -_download_backend_from_settings = context._download_backend_from_settings -_download_huggingface_xet = context._download_huggingface_xet -_ensure_aria2_daemon = context._ensure_aria2_daemon -_read_aria2_version = context._read_aria2_version -_resolve_aria2c_executable = context._resolve_aria2c_executable -_resolve_download_url_for_aria2 = context._resolve_download_url_for_aria2 -_run_aria2_desired_state_worker = context._run_aria2_desired_state_worker -_schedule_aria2_idle_stop = context._schedule_aria2_idle_stop -_sanitize_download_error = context._sanitize_download_error -_json_safe_metadata = context._json_safe_metadata -_coerce_int_or_value = context._coerce_int_or_value -_coerce_size = context._coerce_size -_extract_expected_sha256 = context._extract_expected_sha256 -_metadata_source_value = context._metadata_source_value -_normalise_metadata_file_path = context._normalise_metadata_file_path -_resolve_lora_manager_model_type = context._resolve_lora_manager_model_type -build_download_headers = context.build_download_headers -build_model_resolver_metadata = context.build_model_resolver_metadata -calculate_file_sha256 = context.calculate_file_sha256 -download_file_with_aria2 = context.download_file_with_aria2 -read_completed_metadata_sha256 = context.read_completed_metadata_sha256 -_parse_aria2_int = context._parse_aria2_int -_resolve_aria2_completed_path = context._resolve_aria2_completed_path - -download_progress = context.download_progress -download_lock = context.download_lock -cancelled_downloads = context.cancelled_downloads -aria2_lock = context.aria2_lock -aria2_transfers = context.aria2_transfers -aria2_action_locks = context.aria2_action_locks -aria2_desired_states = context.aria2_desired_states -xet_transfers = context.xet_transfers -xet_transfers_lock = context.xet_transfers_lock -aria2_rpc_url = context.aria2_rpc_url -aria2_rpc_secret = context.aria2_rpc_secret -ARIA2_STATUS_RPC_RETRY_DELAY = context.ARIA2_STATUS_RPC_RETRY_DELAY -MANAGED_ARIA2_ROOT = context.MANAGED_ARIA2_ROOT diff --git a/core/download/previews.py b/core/download/previews.py index 297eb1c..3d9b04c 100644 --- a/core/download/previews.py +++ b/core/download/previews.py @@ -178,7 +178,7 @@ def _download_preview_image( *, dependencies: Any = None, ) -> bytes: - """Download an image preview, retained for compatibility with callers.""" + """Download an image preview.""" return _download_preview_asset( url, media_type="image", diff --git a/core/download/state.py b/core/download/state.py index 8741c3e..df3d18a 100644 --- a/core/download/state.py +++ b/core/download/state.py @@ -4,8 +4,7 @@ import threading from dataclasses import dataclass from typing import Any, Callable, Dict, Optional -# Shared mutable download state. The facade re-exports these same objects -# during the migration, so there is only one owner and no duplicated state. +# Shared mutable download state has a single owner in this module. download_progress: Dict[str, Dict[str, Any]] = {} download_lock = threading.Lock() cancelled_downloads: set = set() @@ -19,7 +18,7 @@ xet_transfers_lock = threading.Lock() @dataclass(frozen=True) class DownloadStateDependencies: - """State and side-effect dependencies supplied by the public facade.""" + """State and side-effect dependencies supplied by the composition layer.""" download_progress: Dict[str, Dict[str, Any]] download_lock: Any diff --git a/core/routes/settings.py b/core/routes/settings.py index d371223..e4404e7 100644 --- a/core/routes/settings.py +++ b/core/routes/settings.py @@ -12,12 +12,12 @@ from ..settings import save_settings as save_resolver_settings def _apply_backend_logging_settings(settings: dict) -> None: - """Keep the legacy helper available while delegating to the service.""" + """Apply backend logging settings through the logging service.""" apply_backend_logging_settings(backend_log_controller, settings) def _build_backend_log_export(): - """Keep the legacy helper available while delegating to the service.""" + """Build the backend log export through the logging service.""" return build_backend_log_export(backend_log_controller) diff --git a/tests/test_path_security.py b/tests/test_path_security.py index 026b6ae..6b89aa0 100644 --- a/tests/test_path_security.py +++ b/tests/test_path_security.py @@ -12,16 +12,13 @@ import requests from core.download.api import context as downloader_module from core.aria2_installer import Aria2InstallError, _safe_extract_tar from core.download.api import ( - Aria2Error, - _download_huggingface_xet, - _resolve_aria2c_executable, - _sanitize_download_error, download_file, - download_file_with_aria2, download_model, is_allowed_model_download_filename, sanitize_download_filename, ) +from core.download.aria2_backend import Aria2Error +from core.download.validation import _sanitize_download_error from core.network_utils import ( UnsafeUrlError, host_matches_domain, @@ -283,7 +280,7 @@ class PathSecurityTests(unittest.TestCase): ), patch( "core.download.api.context._schedule_aria2_idle_stop", ): - result = download_file_with_aria2( + result = downloader_module.download_file_with_aria2( "https://huggingface.co/example/resolve/main/model.safetensors", destination, "aria-no-redirect", @@ -388,7 +385,9 @@ class PathSecurityTests(unittest.TestCase): with patch("core.download.api.context.shutil.which", return_value=None): with self.assertRaises(Aria2Error): - _resolve_aria2c_executable({"aria2c_path": executable}) + downloader_module._resolve_aria2c_executable( + {"aria2c_path": executable} + ) def test_managed_aria2_executable_path_is_allowed(self): with tempfile.TemporaryDirectory() as temp_dir: @@ -397,7 +396,9 @@ class PathSecurityTests(unittest.TestCase): handle.write(b"managed executable") with patch("core.download.api.context.MANAGED_ARIA2_ROOT", Path(temp_dir)): - resolved = _resolve_aria2c_executable({"aria2c_path": executable}) + resolved = downloader_module._resolve_aria2c_executable( + {"aria2c_path": executable} + ) self.assertEqual(os.path.realpath(executable), resolved) def test_huggingface_xet_download_bypasses_signed_http_bridge(self): @@ -463,7 +464,7 @@ class PathSecurityTests(unittest.TestCase): "model.safetensors.modelresolver.json", ), ): - result = _download_huggingface_xet( + result = downloader_module._download_huggingface_xet( "https://huggingface.co/example/model/resolve/main/model.safetensors", destination, "xet-test", diff --git a/tests/test_refactoring_targets.py b/tests/test_refactoring_targets.py index 14d26f1..e709fce 100644 --- a/tests/test_refactoring_targets.py +++ b/tests/test_refactoring_targets.py @@ -796,7 +796,7 @@ class TestRefactoringTargets(unittest.IsolatedAsyncioTestCase): def test_downloader_calculate_file_sha256(self): import tempfile - from core.download.api import calculate_file_sha256 + from core.path_utils import calculate_file_sha256 with tempfile.TemporaryDirectory() as tmpdir: file_path = os.path.join(tmpdir, "test.txt") with open(file_path, "wb") as f: diff --git a/tests/test_resolver_robustness.py b/tests/test_resolver_robustness.py index d764ad3..0ce15cd 100644 --- a/tests/test_resolver_robustness.py +++ b/tests/test_resolver_robustness.py @@ -13,13 +13,11 @@ from core.download.api import ( write_model_resolver_metadata, download_model, get_progress, - _resolve_download_url_for_aria2, start_aria2_daemon, - _delete_partial_download_files, - download_progress, - download_lock, - read_completed_metadata_sha256, ) +from core.download.api import context as downloader_context +from core.download.metadata import read_completed_metadata_sha256 +from core.download.state import download_lock, download_progress from core.path_utils import get_metadata_sidecar_path from core.workflow_updater import ( convert_to_relative_path, @@ -234,7 +232,7 @@ class ModelResolverRobustnessTests(unittest.TestCase): self.assertTrue(os.path.exists(temp_aria2_path)) # Act - _delete_partial_download_files(temp_model_path) + downloader_context._delete_partial_download_files(temp_model_path) # Assert self.assertFalse(os.path.exists(temp_model_path)) @@ -407,7 +405,7 @@ class ModelResolverRobustnessTests(unittest.TestCase): "core.network_utils.validate_public_http_url", side_effect=lambda value: value, ): - resolved, _ = _resolve_download_url_for_aria2(api_url) + resolved, _ = downloader_context._resolve_download_url_for_aria2(api_url) self.assertEqual(resolved, redirect_url) self.assertEqual(mock_get.call_count, 2) diff --git a/tests/test_unified_helpers.py b/tests/test_unified_helpers.py index 8432ff9..d3bdcf8 100644 --- a/tests/test_unified_helpers.py +++ b/tests/test_unified_helpers.py @@ -703,7 +703,7 @@ class UnifiedHelpersTests(unittest.TestCase): Verifies that build_model_resolver_metadata scrubs sensitive query parameters and headers from payloads. """ import json - from core.download.api import build_model_resolver_metadata + from core.download.metadata import build_model_resolver_metadata dest_path = "dummy_model.safetensors" metadata = { "download_url": "https://civitai.com/api/download/models/123?token=sensitivetoken123&session=cookie_val",