From 2b8e0da2f35620fb83fb032397c08be483d0f241 Mon Sep 17 00:00:00 2001 From: Som Samantray <92726151+SomSamantray@users.noreply.github.com> Date: Tue, 20 Oct 2026 10:39:09 +0530 Subject: [PATCH] fix(direct-download): clarify required search mirror (#1454) Direct Download now tells users who configure only a Z-Library mirror that they need an Anna's Archive mirror for search. Z-Library, LibGen, and Welib mirrors download results found through Anna's Archive. Fixes #1408. Validation: the Direct mode browser check, 18 focused tests, Ruff, formatting, and backend/test type checks passed. The CI-style Python suite passed 3,569 tests; `tests/core/test_hardlink.py::TestSameFilesystem::test_string_paths` was excluded because this container reports different `st_dev` values for a file and its parent directory. AI disclosure: OpenAI Codex assisted with diagnosis, implementation, and validation. --- .../direct_download/registry.py | 5 +++-- .../test_source_availability.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/shelfmark/release_sources/direct_download/registry.py b/shelfmark/release_sources/direct_download/registry.py index bb8e422f..9324f709 100644 --- a/shelfmark/release_sources/direct_download/registry.py +++ b/shelfmark/release_sources/direct_download/registry.py @@ -38,8 +38,9 @@ def get_unavailable_reason( return "Direct Download is disabled. Enable the source in Settings." if not enabled_providers(providers): return ( - "Direct Download is not configured. Enable and configure at least one " - "download provider in Settings." + "Direct Download is not configured. Add at least one Anna's Archive mirror URL in " + "Settings. Z-Library, LibGen, and Welib mirrors only download results found through " + "Anna's Archive." ) return None diff --git a/tests/direct_download/test_source_availability.py b/tests/direct_download/test_source_availability.py index 079f43ea..3a86ec6c 100644 --- a/tests/direct_download/test_source_availability.py +++ b/tests/direct_download/test_source_availability.py @@ -2,6 +2,7 @@ from types import SimpleNamespace import pytest +from shelfmark.core import mirrors from shelfmark.core.config import config from shelfmark.release_sources.direct_download import DirectDownloadSource, SearchUnavailableError from shelfmark.release_sources.direct_download import annas_archive as aa @@ -41,6 +42,23 @@ def test_direct_download_source_is_unavailable_without_aa_mirrors(monkeypatch): source.get_record("md5-abc") +def test_direct_download_explains_aa_requirement_when_only_zlib_is_configured(monkeypatch): + monkeypatch.setattr(config, "get", _fake_config_get({"DIRECT_DOWNLOAD_ENABLED": True})) + monkeypatch.setattr( + mirrors, + "_get_config", + lambda: {"AA_BASE_URL": "auto", "ZLIB_MIRROR_URLS": ["https://z-library.sk"]}, + ) + + assert mirrors.has_zlib_mirror_configuration() is True + assert mirrors.has_aa_mirror_configuration() is False + + source = DirectDownloadSource() + + with pytest.raises(SearchUnavailableError, match="Anna's Archive mirror"): + source.search(SimpleNamespace(), SimpleNamespace()) + + def test_direct_download_source_is_available_when_enabled_and_configured(monkeypatch): monkeypatch.setattr(config, "get", _fake_config_get({"DIRECT_DOWNLOAD_ENABLED": True}))