diff --git a/tradein-mvp/backend/tests/test_pipeline_browser_routing.py b/tradein-mvp/backend/tests/test_pipeline_browser_routing.py index 0bb8a636..3777a290 100644 --- a/tradein-mvp/backend/tests/test_pipeline_browser_routing.py +++ b/tradein-mvp/backend/tests/test_pipeline_browser_routing.py @@ -368,57 +368,26 @@ async def test_fetch_detail_curl_mode_no_browser_fetcher() -> None: assert result.item_id == "99887766" -# ── 6. SERP routing: browser-mode — _cffi never touched (refutes #916 concern) ─ +# ── 6. SERP routing: real _fetch_serp_html routes through browser ──────────── @pytest.mark.asyncio -async def test_fetch_serp_html_uses_browser_when_browser_set() -> None: - """SERP routing: with _browser set and _cffi=None, fetch_around routes SERP - through _browser and never dereferences _cffi (no AssertionError). - - Refutes #916 reviewer concern that _cffi assert always fires in browser-mode. - The pipeline sets scraper._browser before calling fetch_around; _fetch_serp_html - is monkey-patched at method level to verify _browser is present and _cffi is - absent at call time — proving the routing contract holds end-to-end without - a network call. - """ - from unittest.mock import AsyncMock, patch +async def test_fetch_serp_html_routes_through_browser() -> None: + """With _browser set and _cffi=None, the REAL _fetch_serp_html returns the + browser HTML and never dereferences _cffi (no AssertionError). Proves #915 + SERP routing on top of #901's browser branch.""" + from unittest.mock import AsyncMock from app.services.scrapers.avito import AvitoScraper scraper = AvitoScraper() - assert scraper._cffi is None # browser-mode: curl session never created + assert scraper._cffi is None + scraper._browser = AsyncMock() + scraper._browser.fetch = AsyncMock(return_value="
real serp listing") - mock_browser = AsyncMock() - # Non-firewall SERP HTML: avoid AvitoBlockedError (_FIREWALL_MARKERS not present) - serp_html = "