From 3ec99a54625bb4b4d17254ea535924532174c005 Mon Sep 17 00:00:00 2001 From: zlt Date: Thu, 10 Sep 2026 09:31:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E9=B2=9C=E5=BA=A6=E5=8F=AA=E7=AE=A1?= =?UTF-8?q?=E3=80=8C=E4=BB=8A=E5=A4=A9=E8=AF=A5=E7=94=A8=E5=93=AA=E4=BB=BD?= =?UTF-8?q?=E3=80=8D=EF=BC=9A=E6=98=BE=E5=BC=8F=E6=8C=87=E5=AE=9A=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=98=AF=E5=A4=8D=E7=9B=98=E5=8F=96=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E9=82=A3=E4=BB=BD=EF=BC=8C=E4=B8=8D=E5=8F=97=E4=BB=8A=E5=A4=A9?= =?UTF-8?q?=E7=9A=84=E7=95=8C=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plan.py | 7 ++++--- test_plan_snapshot.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/plan.py b/plan.py index 61e920a..81993bd 100644 --- a/plan.py +++ b/plan.py @@ -946,9 +946,10 @@ def from_snapshot(date: str | None = None, top: int = 20, obs_top: int = 10, full_main, full_obs = snap.get("main"), snap.get("observe") if not isinstance(full_main, list) or not isinstance(full_obs, list): raise RuntimeError(f"快照缺全量主榜或观察档: {path}") - ok, why = snapshot_fresh_enough(snap) - if not ok: - raise StaleSnapshot(why) + if not date: # 只有「要今天该用的那份」才谈新鲜度 + ok, why = snapshot_fresh_enough(snap) + if not ok: + raise StaleSnapshot(why) data = {k: v for k, v in snap.items() # 前三个是落盘那次的裁剪结果与参数,与本次请求无关; diff --git a/test_plan_snapshot.py b/test_plan_snapshot.py index 039463b..bce21c1 100644 --- a/test_plan_snapshot.py +++ b/test_plan_snapshot.py @@ -148,6 +148,17 @@ def test_freshness_guard(): t("守卫用的是专门的异常类型,调用方接得住", issubclass(plan.StaleSnapshot, RuntimeError)) + # 新鲜度只管「今天该用哪份」。复盘要看 09-08 那天的计划,拿的就该是那天那份旧快照 + import glob as _g, os as _o + fs = sorted(_g.glob(_o.path.join(config.PLAN_SNAPSHOT_DIR, "plan_*.json"))) + if fs: + ds = _o.path.basename(fs[-1])[len("plan_"):-len(".json")] + try: + plan.from_snapshot(ds, 5, 3, 2) + t("显式指定日期不受今天的新鲜度约束(复盘要拿历史那份)", True) + except plan.StaleSnapshot as e: + t("显式指定日期不受今天的新鲜度约束(复盘要拿历史那份)", False, e) + def test_api_falls_back(): print("[接口回落:读不到快照不能让接口挂掉]")