feat: 图片下载与数据目录本地化
- 新增 download_images.py: 批量下载消息图片到 downloads/images/ - 数据库移至 downloads/messages.db,SnifferStorage 默认使用项目目录 - 图片默认保存到 downloads/images/,支持 --out-dir 自定义 - .gitignore 排除 downloads/ 避免提交二进制文件 - 补充腾讯会议号过滤 prompt - 补充 Obsidian 文档 is_read frontmatter
This commit is contained in:
@ -20,9 +20,11 @@ from snooper_summary import (
|
||||
format_followup_checkboxes,
|
||||
load_previous_summary,
|
||||
normalize_heading_breaks,
|
||||
normalize_self_name,
|
||||
previous_workday,
|
||||
require_efund_model,
|
||||
resolve_day,
|
||||
sanitize_wikilink_pipes,
|
||||
shorten_headings,
|
||||
summarize_messages,
|
||||
write_summary,
|
||||
@ -66,6 +68,22 @@ class FakeSession:
|
||||
})
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fake_membership_filter(monkeypatch):
|
||||
"""Keep legacy CLI tests offline; membership behavior has dedicated tests."""
|
||||
def identity(client, rows):
|
||||
return rows, {
|
||||
"included": len(rows),
|
||||
"excluded_before_join": 0,
|
||||
"excluded_unknown": 0,
|
||||
"excluded_chats": 0,
|
||||
}
|
||||
|
||||
monkeypatch.setattr(
|
||||
"snooper_membership.filter_rows_with_membership", identity
|
||||
)
|
||||
|
||||
|
||||
def synthetic_row(
|
||||
msg_id="m1",
|
||||
content="合成消息",
|
||||
@ -90,6 +108,32 @@ def synthetic_row(
|
||||
)
|
||||
|
||||
|
||||
def test_sanitize_wikilink_pipes_preserves_table_and_other_text():
|
||||
content = "| [[审核群|指数内容部落]] | 普通|文本 |\n[[人物|称呼]]"
|
||||
|
||||
assert sanitize_wikilink_pipes(content) == (
|
||||
"| [[审核群|指数内容部落]] | 普通|文本 |\n[[人物|称呼]]"
|
||||
)
|
||||
|
||||
|
||||
def test_system_only_private_chat_does_not_require_a_person_name():
|
||||
row = synthetic_row(chat_type=1, chat_name="", content="[系统消息]")
|
||||
row.msg_type = 6
|
||||
row.msg_type_name = "SYSTEM"
|
||||
session = FakeSession()
|
||||
_, _, _, tz = resolve_day("2026-11-03", "Asia/Shanghai")
|
||||
|
||||
result = summarize_messages(
|
||||
MagpieClient(DEFAULT_MODEL, session=session),
|
||||
[row],
|
||||
date(2026, 11, 3),
|
||||
tz,
|
||||
)
|
||||
|
||||
assert "本日未收到消息" in result
|
||||
assert session.post_calls == []
|
||||
|
||||
|
||||
def test_model_policy_checks_actual_model_after_optional_routing_prefix():
|
||||
assert require_efund_model(DEFAULT_MODEL) == DEFAULT_MODEL
|
||||
assert require_efund_model("EFundGPT-other") == "EFundGPT-other"
|
||||
@ -216,8 +260,8 @@ def test_summary_is_per_conversation_before_daily_combination():
|
||||
|
||||
result = summarize_messages(client, rows, date(2026, 11, 3), tz)
|
||||
|
||||
assert result == "最终日度总结"
|
||||
assert len(session.post_calls) == 3
|
||||
assert result == "同事甲:最终日度总结"
|
||||
assert len(session.post_calls) == 4
|
||||
prompts = [
|
||||
kwargs["json"]["messages"][1]["content"]
|
||||
for _, kwargs in session.post_calls
|
||||
@ -343,7 +387,7 @@ def test_summary_orders_chats_by_participation_private_human_and_bot():
|
||||
},
|
||||
)
|
||||
|
||||
assert result == "最终日度总结"
|
||||
assert result == "私聊:最终日度总结"
|
||||
prompts = [
|
||||
kwargs["json"]["messages"][1]["content"]
|
||||
for _, kwargs in session.post_calls
|
||||
@ -409,7 +453,7 @@ def test_private_chat_labels_keep_only_the_other_party():
|
||||
)
|
||||
|
||||
final_prompt = session.post_calls[1][1]["json"]["messages"][1]["content"]
|
||||
assert "### 排班" in final_prompt
|
||||
assert "### 排班([[赵六]])" in final_prompt
|
||||
assert "### 模型([[赵六]])" in final_prompt
|
||||
assert "私聊:" not in final_prompt
|
||||
assert "[[王五]] 与 [[赵六]]" not in final_prompt
|
||||
@ -470,6 +514,10 @@ def test_private_chat_name_is_derived_from_incoming_contact():
|
||||
assert result == "### 排班([[赵六]])"
|
||||
|
||||
|
||||
def test_generic_self_references_use_configured_self_name():
|
||||
assert normalize_self_name("当前用户与本人;伦伦本人", "Ben", set()) == "Ben与Ben;伦伦本人"
|
||||
|
||||
|
||||
def test_summary_uses_configured_self_name():
|
||||
session = FakeSession(
|
||||
completions=[
|
||||
@ -511,7 +559,7 @@ def test_summary_uses_configured_self_name():
|
||||
assert result == "[[Ben]] 与 [[赵六]] 确认"
|
||||
|
||||
|
||||
def test_private_name_may_be_omitted_from_topic_headings():
|
||||
def test_missing_human_private_summary_is_restored_with_chat_name():
|
||||
session = FakeSession(
|
||||
completions=[
|
||||
(DEFAULT_MODEL, "### 排班([[赵六]])"),
|
||||
@ -540,8 +588,9 @@ def test_private_name_may_be_omitted_from_topic_headings():
|
||||
sender_types={"other": 1},
|
||||
)
|
||||
|
||||
assert len(session.post_calls) == 2
|
||||
assert "私聊补充" not in result
|
||||
assert len(session.post_calls) == 3
|
||||
assert "### 排班([[赵六]])" in result
|
||||
assert result.count("### 排班([[赵六]])") == 1
|
||||
|
||||
|
||||
def test_multiple_private_sources_are_repaired_from_conversation_summaries():
|
||||
@ -676,6 +725,30 @@ def test_summary_applies_heading_normalization_to_model_output():
|
||||
assert "### 合成事项\n- 张三 确认。" in result
|
||||
|
||||
|
||||
def test_person_named_group_allows_missing_members_and_count_suffix():
|
||||
session = FakeSession(
|
||||
completions=[
|
||||
(DEFAULT_MODEL, "[[吴九, [[李四]], 王五等8人]]:讨论需求"),
|
||||
(DEFAULT_MODEL, "[[吴九, [[李四]], 王五等8人]]:已确认需求"),
|
||||
]
|
||||
)
|
||||
client = MagpieClient(DEFAULT_MODEL, session=session)
|
||||
group_name = "吴九, 李四, 王五等8人"
|
||||
rows = [synthetic_row(chat_id="group-a", chat_name=group_name)]
|
||||
_, _, _, tz = resolve_day("2026-11-03", "Asia/Shanghai")
|
||||
|
||||
result = summarize_messages(
|
||||
client,
|
||||
rows,
|
||||
date(2026, 11, 3),
|
||||
tz,
|
||||
contacts={"group-a": {"u1": "吴九", "u2": "李四", "sender-test": "吴九"}},
|
||||
)
|
||||
|
||||
assert result == "吴九, 李四, 王五等8人:已确认需求"
|
||||
assert "[[吴九, [[李四]], 王五等8人]]" not in result
|
||||
|
||||
|
||||
def test_previous_day_summary_is_used_for_continuity():
|
||||
session = FakeSession(completions=[
|
||||
(DEFAULT_MODEL, "今日摘要"),
|
||||
@ -699,6 +772,22 @@ def test_previous_day_summary_is_used_for_continuity():
|
||||
assert "今日未见延续" in final_prompt
|
||||
|
||||
|
||||
def test_bare_group_name_heading_becomes_topic_heading():
|
||||
session = FakeSession(
|
||||
completions=[
|
||||
(DEFAULT_MODEL, "### [[项目群]]"),
|
||||
(DEFAULT_MODEL, "### [[项目群]]"),
|
||||
]
|
||||
)
|
||||
client = MagpieClient(DEFAULT_MODEL, session=session)
|
||||
rows = [synthetic_row(chat_id="group-a", chat_name="项目群")]
|
||||
_, _, _, tz = resolve_day("2026-11-03", "Asia/Shanghai")
|
||||
|
||||
result = summarize_messages(client, rows, date(2026, 11, 3), tz)
|
||||
|
||||
assert result == "### 沟通事项:[[项目群]]"
|
||||
|
||||
|
||||
def test_summary_enriches_names_and_requests_obsidian_wikilinks():
|
||||
session = FakeSession(completions=[
|
||||
(DEFAULT_MODEL, "张三确认了事项"),
|
||||
@ -735,8 +824,8 @@ def test_summary_enriches_names_and_requests_obsidian_wikilinks():
|
||||
assert "不通过通讯录强行补全本名" in system_prompt
|
||||
assert "[[会话名]]" in system_prompt
|
||||
assert "#tag" in system_prompt
|
||||
assert "[[张三]]" not in final_prompt
|
||||
assert "[[张三]]" not in result
|
||||
assert "[[张三]]确认了事项" in final_prompt
|
||||
assert "[[张三]]确认了事项" in result
|
||||
assert "Wikilink" in final_prompt
|
||||
|
||||
|
||||
@ -1142,6 +1231,7 @@ def test_cli_end_to_end_with_synthetic_db_and_fake_magpie(
|
||||
no_contacts=True,
|
||||
no_fetch=True,
|
||||
no_calendar=True,
|
||||
no_card_images=True,
|
||||
)
|
||||
assert cmd_summarize(args) == 0
|
||||
output_text = output.read_text(encoding="utf-8")
|
||||
@ -1304,6 +1394,7 @@ def test_cli_summarize_prefetches_before_reading(tmp_path, monkeypatch):
|
||||
no_contacts=True,
|
||||
no_fetch=False,
|
||||
no_calendar=True,
|
||||
no_card_images=True,
|
||||
force_fetch=False,
|
||||
)
|
||||
|
||||
@ -1320,7 +1411,7 @@ def test_cli_summarize_prefetches_before_reading(tmp_path, monkeypatch):
|
||||
assert output.read_text(encoding="utf-8") == (
|
||||
"---\nversion: 0.1.0.dev0+test\n"
|
||||
f"model: {DEFAULT_MODEL}\nis_read: false\n"
|
||||
"tags:\n- no_previous_day_log\n---\n\n# 合成总结\n")
|
||||
"tags:\n- no_previous_day_log\n- no_previous_weekly\n---\n\n# 合成总结\n")
|
||||
|
||||
|
||||
def test_cli_model_failure_happens_before_storage_is_opened(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user