test(tradein/scraper-kit): assert config= at avito_detail_backfill call sites (#2310)
All checks were successful
CI / changes (pull_request) Successful in 9s
CI Trade-In / changes (pull_request) Successful in 10s
CI Trade-In / frontend-checks (pull_request) Has been skipped
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped
CI Trade-In / backend-tests (pull_request) Successful in 1m39s

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
This commit is contained in:
bot-backend 2026-07-04 01:22:50 +03:00
parent eb564cfc01
commit 116cd10046

View file

@ -109,6 +109,8 @@ async def test_backfill_empty_snapshot_marks_done() -> None:
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_backfill_processes_snapshot_to_completion() -> None: async def test_backfill_processes_snapshot_to_completion() -> None:
"""3 listings -> all fetched and enriched, mark_done called.""" """3 listings -> all fetched and enriched, mark_done called."""
from app.services.scraper_adapters import RealScraperConfig
snapshot = _make_snapshot(3) snapshot = _make_snapshot(3)
db = _mock_db(snapshot) db = _mock_db(snapshot)
runs = MagicMock() runs = MagicMock()
@ -119,7 +121,7 @@ async def test_backfill_processes_snapshot_to_completion() -> None:
with ( with (
patch(_SETTINGS, fake_settings), patch(_SETTINGS, fake_settings),
patch(_SESSION, return_value=AsyncMock()), patch(_SESSION, return_value=AsyncMock()),
patch(_SCRAPER), patch(_SCRAPER) as mock_scraper_cls,
patch(_RUNS, runs), patch(_RUNS, runs),
patch(_FETCH, mock_fetch), patch(_FETCH, mock_fetch),
patch(_SAVE, mock_save), patch(_SAVE, mock_save),
@ -136,6 +138,14 @@ async def test_backfill_processes_snapshot_to_completion() -> None:
assert mock_fetch.call_count == 3 assert mock_fetch.call_count == 3
runs.mark_done.assert_called_once() runs.mark_done.assert_called_once()
runs.mark_failed.assert_not_called() 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 @pytest.mark.asyncio