feat: 区分未同步与无数据日期,回补可自动联网补拉

This commit is contained in:
Benature
2026-11-28 18:02:01 +08:00
parent e34402f980
commit d14f517db2
5 changed files with 132 additions and 1 deletions

View File

@ -138,6 +138,57 @@ def test_sync_all_chats_for_day_excludes_configured_chat_before_history_pull():
assert storage.get_messages("private-b") == []
def test_sync_marks_day_synced_when_no_failures():
from snooper_history import sync_all_chats_for_day
tz = ZoneInfo("Asia/Shanghai")
start_ts = 1_792_000_000
client = FakeClient(start_ts)
client.auth = type("Auth", (), {"user_id": "self"})()
storage = Storage(url="sqlite:///:memory:")
stats = sync_all_chats_for_day(
client,
storage,
date(2026, 11, 3),
tz,
batch_size=2,
start_ts=start_ts,
end_ts=start_ts + 86_400,
)
assert stats["failed"] == 0
assert storage.is_day_synced("2026-11-03") is True
assert storage.is_day_synced("2026-11-04") is False
def test_sync_does_not_mark_day_synced_when_failures():
from snooper_history import sync_all_chats_for_day
class FailingClient(FakeClient):
def pull_history(self, chat_id, positions, **kwargs):
raise RuntimeError("合成失败")
tz = ZoneInfo("Asia/Shanghai")
start_ts = 1_792_000_000
client = FailingClient(start_ts)
client.auth = type("Auth", (), {"user_id": "self"})()
storage = Storage(url="sqlite:///:memory:")
stats = sync_all_chats_for_day(
client,
storage,
date(2026, 11, 3),
tz,
batch_size=2,
start_ts=start_ts,
end_ts=start_ts + 86_400,
)
assert stats["failed"] >= 1
assert storage.is_day_synced("2026-11-03") is False
def test_history_failure_log_identifies_chat_without_sensitive_error_body(tmp_path):
from snooper_history import (
format_history_failures,