From cdd070749bd3130eae7c7137857595446db97bfa Mon Sep 17 00:00:00 2001 From: jsahn Date: Tue, 20 Oct 2026 14:06:25 +0900 Subject: [PATCH] Backfill guard: a past week's digest only takes papers published by its end Backfilling an old week used to sweep in undigested papers published later (stamping them into the wrong week and removing them from the next Monday's digest); regular weekly runs are unaffected since the collection window already ends at week_end. Co-Authored-By: Claude Fable 5 --- sebrief/pipeline.py | 5 +++++ tests/test_pipeline.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/sebrief/pipeline.py b/sebrief/pipeline.py index 80f0285..f88da92 100644 --- a/sebrief/pipeline.py +++ b/sebrief/pipeline.py @@ -86,6 +86,11 @@ def build_payload(week: str, settings: Settings, store: Store) -> WeekPayload: run_safely("store", lambda: store.upsert_papers(papers), None, gaps) pending = run_safely("store", lambda: store.pending_papers(week), [], gaps) + # 과거 주를 소급 생성할 때, 그 주가 끝난 뒤 발행됐지만 아직 다이제스트에 안 실린 논문이 + # 과거 주차로 끌려 들어가(그리고 digest_week가 찍혀 다음 월요일 다이제스트에서 사라지는) 것을 + # 막는다. 정규 주간 실행은 수집 창이 week_end에서 끝나 아무것도 걸러지지 않는다. + pending = [p for p in pending if p.published_date is None or p.published_date <= week_end] + if len(pending) > settings.max_papers: # The cap only ever drops papers that have not been published yet. Papers already stamped # with THIS week (--force re-run) must stay: dropping one would erase it from the published diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 15f08cd..c1aa4f1 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -84,6 +84,18 @@ def test_build_payload_invalid_feed_spec_is_a_gap(env): assert any("invalid feed spec" in g for g in payload.data_gaps) +def test_backfill_excludes_papers_published_after_the_week(env): + # 과거 주 소급 생성: 그 주 이후에 발행된 미소화 논문은 과거 다이제스트로 끌려가면 안 된다 + from datetime import date + + in_week = make_paper("10.1/inweek", published_date=date(2026, 9, 2)) + later = make_paper("10.1/later", published_date=date(2026, 9, 20)) # W36 이후 발행 + undated = make_paper("10.1/undated", published_date=None) + env["store"].pending = [in_week, later, undated] + payload = build_payload(WEEK, env["settings"], env["store"]) # WEEK = 2026-W35 (…~09-06) + assert [p.doi for p in payload.papers] == ["10.1/inweek", "10.1/undated"] + + def test_build_payload_caps_papers_and_notes_rollover(env): env["store"].pending = [make_paper(f"10.1/p{i}") for i in range(5)] env["settings"] = env["settings"].model_copy(update={"max_papers": 3})