Skip to content

Commit 33d12be

Browse files
committed
fix: suppress cached no-valid-output lag
1 parent 0538859 commit 33d12be

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

quantclass_sync_internal/data_query.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,16 @@ def get_products_overview(
211211
and freshness_anchor is not None
212212
and (today - freshness_anchor).days <= _STALE_GRACE_DAYS
213213
)
214+
if (
215+
cache_fresh
216+
and last_status == "skipped"
217+
and last_reason == REASON_NO_VALID_OUTPUT
218+
and last_date == cached_api_date
219+
and _parse_date(local_date) is not None
220+
):
221+
ref_date = _parse_date(local_date)
214222
# 无有效缓存时,A 股产品用交易日历找最近交易日,避免周末误报
215-
if _is_a_stock_product(product) and trading_calendar:
223+
elif _is_a_stock_product(product) and trading_calendar:
216224
trading_ref = _last_trading_day(trading_calendar, today)
217225
ref_date = cached_api_date if cache_fresh else (trading_ref or today)
218226
else:

tests/test_data_query.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,35 @@ def test_overview_same_api_date_after_check_updates_keeps_no_valid_output_suppre
408408
self.assertEqual(overview[0]["days_behind"], 0)
409409
self.assertEqual(overview[0]["status_color"], "green")
410410

411+
def test_overview_cached_api_date_after_no_valid_output_is_not_pending(self):
412+
"""更新后仅依赖缓存 API 日期时,same-date no_valid_output 仍不应显示落后。"""
413+
self._write_timestamp("coin-cap", "2026-03-10")
414+
update_api_latest_dates(self.log_dir, {"coin-cap": "2026-03-11"})
415+
report = _new_report("test", mode="network")
416+
_append_result(
417+
report,
418+
product="coin-cap",
419+
status="skipped",
420+
reason_code="no_valid_output",
421+
error="同步未产生可用输出,已跳过状态推进。",
422+
date_time="2026-03-11",
423+
)
424+
_update_product_last_status(self.log_dir, report)
425+
426+
import unittest.mock
427+
with unittest.mock.patch(
428+
"quantclass_sync_internal.data_query.report_dir_path",
429+
return_value=self.log_dir,
430+
):
431+
overview = get_products_overview(
432+
self.data_root,
433+
["coin-cap"],
434+
today=date(2026, 3, 13),
435+
)
436+
437+
self.assertEqual(overview[0]["days_behind"], 0)
438+
self.assertEqual(overview[0]["status_color"], "green")
439+
411440
def test_overview_preserves_green_after_sync_when_api_cache_exists(self):
412441
"""同步结果为 up_to_date 时,若保留 API 缓存字段,总览仍应显示绿色。"""
413442
self._write_timestamp("coin-cap", "2026-03-11")

0 commit comments

Comments
 (0)