mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-22 23:31:12 +02:00
feat(03b): add BYO custom proxy provider + bounded crawler rotation-retry
Add CustomProxyProvider (single endpoint or rotating pool via Scrapling ProxyRotator), registered as 'custom' alongside anonymous_proxies and selectable via PROXY_PROVIDER. Adds is_pool_backed to the ProxyProvider ABC + a zero-arg package helper. The web crawler does a bounded one-per-tier is_proxy_error rotation-retry gated on is_pool_backed() (single-endpoint providers no-op). Config/.env.example gain CUSTOM_PROXY_URL(S). Zero-arg getter contract unchanged for all consumers. Documents the proprietary boundary test (generic proxy infra stays Apache-2). Tests: provider, registry, crawler rotation (16). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
5c36cd3071
commit
62260125f7
12 changed files with 358 additions and 4 deletions
36
surfsense_backend/tests/unit/utils/proxy/test_registry.py
Normal file
36
surfsense_backend/tests/unit/utils/proxy/test_registry.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""Unit tests for proxy provider selection (Phase 3b).
|
||||
|
||||
``PROXY_PROVIDER`` selects the single app-wide provider; ``custom`` is now
|
||||
registered alongside ``anonymous_proxies``, and unknown values still warn and
|
||||
fall back to the default.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from app.config import Config
|
||||
from app.utils.proxy import registry
|
||||
from app.utils.proxy.providers.anonymous_proxies import AnonymousProxiesProvider
|
||||
from app.utils.proxy.providers.custom import CustomProxyProvider
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_active_provider(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Clear the process-wide provider cache so each test resolves fresh."""
|
||||
monkeypatch.setattr(registry, "_active_provider", None)
|
||||
|
||||
|
||||
def test_resolves_custom(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(Config, "PROXY_PROVIDER", "custom")
|
||||
assert isinstance(registry.get_active_provider(), CustomProxyProvider)
|
||||
|
||||
|
||||
def test_resolves_anonymous(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(Config, "PROXY_PROVIDER", "anonymous_proxies")
|
||||
assert isinstance(registry.get_active_provider(), AnonymousProxiesProvider)
|
||||
|
||||
|
||||
def test_unknown_falls_back_to_default(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(Config, "PROXY_PROVIDER", "does_not_exist")
|
||||
assert isinstance(registry.get_active_provider(), AnonymousProxiesProvider)
|
||||
Loading…
Add table
Add a link
Reference in a new issue