From bf7b5d94420b2cee7dc7dc1c794dabc15d577b74 Mon Sep 17 00:00:00 2001 From: agent_coder Date: Mon, 6 Jul 2026 18:08:51 +0300 Subject: [PATCH] =?UTF-8?q?test(render):=20#30=20=D1=8D=D1=82=D0=B0=D0=BF?= =?UTF-8?q?=203=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E=20=E2=80=94=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BB=D0=BE=D1=87=D0=B5=D0=BD=20over-fetch=20fork=20(RSS?= =?UTF-8?q?=20limit*2=20vs=20HTML=20limit)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Развилка history_limit=limit*2 (RSS) vs limit (HTML) невидима голдену (golden-фейк игнорирует аргумент limit и всегда отдаёт полный корпус → оба пути тримятся до GOLDEN_LIMIT одинаково). test_rss_overfetches_history_html_does_not спаит tg_cache.cached_get_chat_history, гоняет оба форматтера с N=7 и ассертит: RSS форвардит limit=2*N, HTML форвардит limit=N. Мутационно проверено — красит при унификации в любую сторону. Полный сюит 366 passed, golden не менялся. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/test_stage3_enrich.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_stage3_enrich.py b/tests/test_stage3_enrich.py index d349018..7846238 100644 --- a/tests/test_stage3_enrich.py +++ b/tests/test_stage3_enrich.py @@ -180,6 +180,36 @@ async def test_rss_feed_does_not_enrich_replies(monkeypatch): assert client.calls == [], "RSS must NOT call get_messages (enrich_replies=False)" +# --------------------------------------------------------------------------- # +# History over-fetch fork: RSS over-fetches limit*2 (headroom for grouping/trim), +# HTML fetches exactly limit. This is a REAL behavioral fork that the golden oracle +# CANNOT see (its fake_get_chat_history ignores the limit kwarg and returns the whole +# corpus, so both paths trim to GOLDEN_LIMIT identically). A refactor that accidentally +# unified the two would pass every golden test — so lock the forwarded limit here. +# --------------------------------------------------------------------------- # +@pytest.mark.asyncio +async def test_rss_overfetches_history_html_does_not(monkeypatch): + N = 7 + seen = {} + + async def fake_get_chat(client, channel): + return SimpleNamespace(title="Test", username="testchan", id=-1001234567890) + + async def spy_get_history(client, channel, limit=20): + seen.setdefault("limits", []).append(limit) + return [] + + monkeypatch.setattr("tg_cache.cached_get_chat", fake_get_chat, raising=False) + monkeypatch.setattr("tg_cache.cached_get_chat_history", spy_get_history, raising=False) + + await generate_channel_rss("testchan", client=SimpleNamespace(), limit=N) + assert seen["limits"] == [2 * N], f"RSS must over-fetch history limit*2, got {seen['limits']}" + + seen["limits"] = [] + await generate_channel_html("testchan", client=SimpleNamespace(), limit=N) + assert seen["limits"] == [N], f"HTML must fetch history limit (no over-fetch), got {seen['limits']}" + + # --------------------------------------------------------------------------- # # Shared error handling in _prepare_feed_posts, verified through BOTH formatters. # The golden oracle cannot see these paths (§3.9/§3.10 are error branches), so they