From 42a60e3e745aa1a06d3118e2ef73cfb6dffcc4e0 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 25 Sep 2026 11:41:16 -0400 Subject: [PATCH] test: the patreon ingester tests run phase 3's seen-marking before counting post keys (#4436) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LVjrnpQjRgHdvq95rASoiR --- tests/test_patreon_ingester.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/test_patreon_ingester.py b/tests/test_patreon_ingester.py index b986e53..7ff79c7 100644 --- a/tests/test_patreon_ingester.py +++ b/tests/test_patreon_ingester.py @@ -239,8 +239,8 @@ async def test_tick_downloads_unseen_and_marks_seen(source_id, sync_engine, tmp_ # plan #704: structured run_stats carry the real counts. assert result.run_stats["downloaded_count"] == 2 assert result.posts_processed == 1 - # The media wait for phase 3 to import them; only the post key is in yet. - assert _count_ledger(sync_engine, source_id) == 1 + # The media and the post record both wait for phase 3 to import them (#4436). + assert _count_ledger(sync_engine, source_id) == 0 result.mark_seen_after_import() # 2 media keys + 1 synthetic post key (body/links recaptured per post). assert _count_ledger(sync_engine, source_id) == 3 @@ -648,8 +648,10 @@ async def test_recovery_tier2_disk_still_skips(source_id, sync_engine, tmp_path) assert result.files_downloaded == 0 assert downloader.download_calls == 0 assert result.written_paths == [] - # Disk-skip reconciles the media key + the synthetic post key (recovery - # recaptures the body/links per post) = 2. + # Disk-skip reconciles the media key at once; the synthetic post key + # (recovery recaptures the body/links per post) waits for phase 3 (#4436). + assert _count_ledger(sync_engine, source_id) == 1 + result.mark_seen_after_import() assert _count_ledger(sync_engine, source_id) == 2 @@ -1203,7 +1205,10 @@ async def test_tick_captures_media_less_post_once(source_id, sync_engine, tmp_pa assert result.success is True assert len(result.post_record_paths) == 1 assert downloader.post_records == 1 - # The synthetic `post:ptext` key was marked seen (gates re-capture). + # The synthetic `post:ptext` key is marked once phase 3 has upserted the + # record (#4436), and then gates re-capture. + assert _count_ledger(sync_engine, source_id) == 0 + result.mark_seen_after_import() assert _count_ledger(sync_engine, source_id) == 1 # Second walk: already recorded → gated, no re-write, no new ledger row. @@ -1543,6 +1548,7 @@ async def test_revisits_do_not_feed_the_body_drift_canary( url="https://patreon.com/ingest", mode="tick", revisit_days=30, ) assert first.success is True + first.mark_seen_after_import() # phase 3 ran # Second walk: every post is a revisit, and every body comes back empty. client2 = _FakeClient([(None, posts)], published=published, empty_body=True)