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.
This commit is contained in:
Som Samantray authored and GitHub committed 2026-10-20 01:09:09 -04:00
1 parent 756bdec19b
commit 2b8e0da2f3
2 files changed
+21 -2

No files matched your search

@@ -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
@@ -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}))