From 116cd1004680a6eae7396fe5ca0335a40d99b798 Mon Sep 17 00:00:00 2001 From: bot-backend Date: Sat, 4 Jul 2026 01:22:50 +0300 Subject: [PATCH] test(tradein/scraper-kit): assert config= at avito_detail_backfill call sites (#2310) Code-review follow-up: the Group C regression tests for the fetch_detail backconnect footgun and AvitoScraper's config requirement proved the KIT LIBRARY behavior in isolation, but nothing asserted the actual call sites in avito_detail_backfill.py still pass config=RealScraperConfig() at fetch_detail and AvitoScraper construction. Mirrors #2306's test_backfill_wave2.py:282-286 pattern -- isinstance-checks the captured call_args instead of a bare assert_called(). Verified the new assertions actually catch the regression: temporarily removed both config=RealScraperConfig() call-site args from avito_detail_backfill.py, confirmed test_backfill_processes_snapshot_to_completion fails exactly on the new assertion line, then restored (git diff was empty afterward). Refs #2310 --- .../tests/tasks/test_avito_detail_backfill.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tradein-mvp/backend/tests/tasks/test_avito_detail_backfill.py b/tradein-mvp/backend/tests/tasks/test_avito_detail_backfill.py index ff3c9b25..5183dd4a 100644 --- a/tradein-mvp/backend/tests/tasks/test_avito_detail_backfill.py +++ b/tradein-mvp/backend/tests/tasks/test_avito_detail_backfill.py @@ -109,6 +109,8 @@ async def test_backfill_empty_snapshot_marks_done() -> None: @pytest.mark.asyncio async def test_backfill_processes_snapshot_to_completion() -> None: """3 listings -> all fetched and enriched, mark_done called.""" + from app.services.scraper_adapters import RealScraperConfig + snapshot = _make_snapshot(3) db = _mock_db(snapshot) runs = MagicMock() @@ -119,7 +121,7 @@ async def test_backfill_processes_snapshot_to_completion() -> None: with ( patch(_SETTINGS, fake_settings), patch(_SESSION, return_value=AsyncMock()), - patch(_SCRAPER), + patch(_SCRAPER) as mock_scraper_cls, patch(_RUNS, runs), patch(_FETCH, mock_fetch), patch(_SAVE, mock_save), @@ -136,6 +138,14 @@ async def test_backfill_processes_snapshot_to_completion() -> None: assert mock_fetch.call_count == 3 runs.mark_done.assert_called_once() runs.mark_failed.assert_not_called() + # #2310 regression guard: kit fetch_detail silently drops the backconnect- + # on-403 retry (and kit AvitoScraper can't read avito_proxy_rotate_url at + # all) unless config=RealScraperConfig() is passed/injected at the call + # site — assert_called()/call_count alone wouldn't catch someone dropping + # that kwarg later (mirrors #2306's test_backfill_wave2.py:282-286 pattern). + _, fetch_call_kwargs = mock_fetch.call_args + assert isinstance(fetch_call_kwargs.get("config"), RealScraperConfig) + assert isinstance(mock_scraper_cls.call_args.args[0], RealScraperConfig) @pytest.mark.asyncio