feat: 历史同步优化与消息已读属性
- 历史同步: 本地缓存优先、断点续传、按月批量同步 - 新增 sync_monthly.py: 支持逐月往前推进同步 - 消息表新增 is_read 字段,默认 false - Obsidian 文档 frontmatter 自动补充 is_read: false - 新增 migrate_add_is_read.py / migrate_obsidian_is_read.py 迁移脚本 - 总结 prompt 补充: 不记录腾讯会议号 - 历史同步失败时记录日志到 ~/.larkx/logs/history-failures.jsonl
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import json
|
||||
import stat
|
||||
from datetime import date
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
@ -134,3 +136,57 @@ def test_sync_all_chats_for_day_excludes_configured_chat_before_history_pull():
|
||||
assert stats["saved"] == 1
|
||||
assert [call[0] for call in client.history_calls] == ["group-a"]
|
||||
assert storage.get_messages("private-b") == []
|
||||
|
||||
|
||||
def test_history_failure_log_identifies_chat_without_sensitive_error_body(tmp_path):
|
||||
from snooper_history import (
|
||||
format_history_failures,
|
||||
sync_all_chats_for_day,
|
||||
write_history_failures,
|
||||
)
|
||||
|
||||
class FailingClient(FakeClient):
|
||||
def pull_history(self, chat_id, positions, **kwargs):
|
||||
if chat_id == "group-a":
|
||||
raise RuntimeError("敏感合成上游响应正文")
|
||||
return super().pull_history(chat_id, positions, **kwargs)
|
||||
|
||||
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:")
|
||||
target_day = date(2026, 11, 3)
|
||||
|
||||
stats = sync_all_chats_for_day(
|
||||
client,
|
||||
storage,
|
||||
target_day,
|
||||
tz,
|
||||
batch_size=2,
|
||||
start_ts=start_ts,
|
||||
end_ts=start_ts + 86_400,
|
||||
)
|
||||
|
||||
assert stats["failed"] == 1
|
||||
assert stats["failures"] == [
|
||||
{
|
||||
"chat_id": "group-a",
|
||||
"chat_name": "合成群",
|
||||
"error_type": "RuntimeError",
|
||||
}
|
||||
]
|
||||
assert "合成群 (group-a): RuntimeError" in format_history_failures(
|
||||
stats["failures"]
|
||||
)
|
||||
log_path = write_history_failures(
|
||||
target_day, stats["failures"], tmp_path / "history-failures.jsonl"
|
||||
)
|
||||
record = json.loads(log_path.read_text(encoding="utf-8"))
|
||||
assert record["date"] == "2026-11-03"
|
||||
assert record["logged_at"].endswith("+00:00")
|
||||
assert record["chat_id"] == "group-a"
|
||||
assert record["chat_name"] == "合成群"
|
||||
assert record["error_type"] == "RuntimeError"
|
||||
assert "敏感合成上游响应正文" not in log_path.read_text(encoding="utf-8")
|
||||
assert stat.S_IMODE(log_path.stat().st_mode) == 0o600
|
||||
|
||||
Reference in New Issue
Block a user