feat: 完善日报人物来源与会议链接
This commit is contained in:
@ -7,6 +7,7 @@ from snooper_calendar import fetch_calendar_events
|
||||
class FakeCalendarClient:
|
||||
def __init__(self):
|
||||
self.calls = []
|
||||
self.native_urls = True
|
||||
|
||||
def api(self, name, data):
|
||||
self.calls.append((name, data))
|
||||
@ -31,19 +32,38 @@ class FakeCalendarClient:
|
||||
"summary": "合成早会",
|
||||
"locations": [{"name": "合成会议室 A"}],
|
||||
"isDeleted": False,
|
||||
"url": "https://example.com/a",
|
||||
"url": "https://example.com/a" if self.native_urls else "",
|
||||
},
|
||||
"event-b": {
|
||||
"summary": "合成下午会",
|
||||
"locations": [{"name": "合成会议室 B"}],
|
||||
"isDeleted": True,
|
||||
"meetingMinuteUrl": "https://example.com/minutes-b",
|
||||
"url": "https://example.com/event-b",
|
||||
"meetingMinuteUrl": (
|
||||
"https://example.com/minutes-b" if self.native_urls else ""
|
||||
),
|
||||
"url": "https://example.com/event-b" if self.native_urls else "",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_manual_meeting_link_fills_missing_url_without_overriding_native():
|
||||
client = FakeCalendarClient()
|
||||
client.native_urls = False
|
||||
events = fetch_calendar_events(
|
||||
client,
|
||||
date(2026, 9, 9),
|
||||
ZoneInfo("Asia/Shanghai"),
|
||||
meeting_links={
|
||||
"2026-09-09|合成早会": "https://example.com/manual-a",
|
||||
"2026-09-09|合成下午会": "https://example.com/manual-b",
|
||||
},
|
||||
)
|
||||
|
||||
assert events[0]["url"] == "https://example.com/manual-a"
|
||||
assert events[1]["url"] == "https://example.com/manual-b"
|
||||
|
||||
|
||||
def test_fetch_calendar_events_normalizes_and_sorts_daily_instances():
|
||||
client = FakeCalendarClient()
|
||||
tz = ZoneInfo("Asia/Shanghai")
|
||||
|
||||
@ -14,6 +14,8 @@ from snooper_summary import (
|
||||
MagpieClient,
|
||||
SummaryError,
|
||||
chunk_messages,
|
||||
drop_casual_content,
|
||||
drop_empty_meeting_section,
|
||||
escape_obsidian_tags,
|
||||
format_followup_checkboxes,
|
||||
load_previous_summary,
|
||||
@ -191,6 +193,7 @@ def test_summary_is_per_conversation_before_daily_combination():
|
||||
(DEFAULT_MODEL, "私聊摘要"),
|
||||
(DEFAULT_MODEL, "群聊摘要"),
|
||||
(DEFAULT_MODEL, "最终日度总结"),
|
||||
(DEFAULT_MODEL, "同事甲:最终日度总结"),
|
||||
])
|
||||
client = MagpieClient(DEFAULT_MODEL, session=session)
|
||||
rows = [
|
||||
@ -298,6 +301,7 @@ def test_summary_orders_chats_by_participation_private_human_and_bot():
|
||||
(DEFAULT_MODEL, "真人群摘要"),
|
||||
(DEFAULT_MODEL, "机器人群摘要"),
|
||||
(DEFAULT_MODEL, "最终日度总结"),
|
||||
(DEFAULT_MODEL, "私聊:最终日度总结"),
|
||||
])
|
||||
client = MagpieClient(DEFAULT_MODEL, session=session)
|
||||
rows = [
|
||||
@ -373,6 +377,7 @@ def test_private_chat_labels_keep_only_the_other_party():
|
||||
completions=[
|
||||
(DEFAULT_MODEL, "### 排班\n### 模型([[王五]]、[[赵六]])"),
|
||||
(DEFAULT_MODEL, "| 事项 | 负责人 | 来源 |\n| 排班 | 未明确 | [[王五]] |"),
|
||||
(DEFAULT_MODEL, "| 事项 | 负责人 | 来源 |\n| 排班 | 未明确 | [[赵六]] |"),
|
||||
]
|
||||
)
|
||||
client = MagpieClient(DEFAULT_MODEL, session=session)
|
||||
@ -404,13 +409,141 @@ 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
|
||||
assert result.endswith("| 排班 | 未明确 | [[赵六]] |")
|
||||
|
||||
|
||||
def test_private_chat_name_is_derived_from_incoming_contact():
|
||||
session = FakeSession(
|
||||
completions=[
|
||||
(DEFAULT_MODEL, "### 排班([[赵六]])"),
|
||||
(DEFAULT_MODEL, "### 排班([[赵六]])"),
|
||||
]
|
||||
)
|
||||
client = MagpieClient(DEFAULT_MODEL, session=session)
|
||||
rows = [
|
||||
synthetic_row(
|
||||
"incoming",
|
||||
chat_id="private-chat",
|
||||
chat_name="",
|
||||
chat_type=1,
|
||||
sender_id="other",
|
||||
),
|
||||
synthetic_row(
|
||||
"system",
|
||||
chat_id="private-chat",
|
||||
chat_name="",
|
||||
chat_type=1,
|
||||
sender_id="1",
|
||||
),
|
||||
synthetic_row(
|
||||
"outgoing",
|
||||
chat_id="private-chat",
|
||||
chat_name="",
|
||||
chat_type=1,
|
||||
direction="out",
|
||||
sender_id="me",
|
||||
),
|
||||
]
|
||||
_, _, _, tz = resolve_day("2026-11-03", "Asia/Shanghai")
|
||||
|
||||
result = summarize_messages(
|
||||
client,
|
||||
rows,
|
||||
date(2026, 11, 3),
|
||||
tz,
|
||||
contacts={
|
||||
"private-chat": {
|
||||
"me": "王五",
|
||||
"other": "赵六",
|
||||
"1": "系统消息",
|
||||
}
|
||||
},
|
||||
sender_types={"other": 1, "1": 2},
|
||||
)
|
||||
|
||||
first_prompt = session.post_calls[0][1]["json"]["messages"][1]["content"]
|
||||
assert '"chat_name": "赵六"' in first_prompt
|
||||
assert result == "### 排班([[赵六]])"
|
||||
|
||||
|
||||
def test_summary_uses_configured_self_name():
|
||||
session = FakeSession(
|
||||
completions=[
|
||||
(DEFAULT_MODEL, "[[王五]] 回复"),
|
||||
(DEFAULT_MODEL, "[[王五]] 与 [[赵六]] 确认"),
|
||||
]
|
||||
)
|
||||
client = MagpieClient(DEFAULT_MODEL, session=session)
|
||||
rows = [
|
||||
synthetic_row(
|
||||
"incoming",
|
||||
chat_id="private-chat",
|
||||
chat_name="赵六",
|
||||
chat_type=1,
|
||||
sender_id="other",
|
||||
),
|
||||
synthetic_row(
|
||||
"outgoing",
|
||||
chat_id="private-chat",
|
||||
chat_name="赵六",
|
||||
chat_type=1,
|
||||
direction="out",
|
||||
sender_id="me",
|
||||
),
|
||||
]
|
||||
_, _, _, tz = resolve_day("2026-11-03", "Asia/Shanghai")
|
||||
|
||||
result = summarize_messages(
|
||||
client,
|
||||
rows,
|
||||
date(2026, 11, 3),
|
||||
tz,
|
||||
contacts={"private-chat": {"me": "王五", "other": "赵六"}},
|
||||
self_name="Ben",
|
||||
)
|
||||
|
||||
participation = session.post_calls[0][1]["json"]["messages"][1]["content"]
|
||||
assert '"self_name": "Ben"' in participation
|
||||
assert result == "[[Ben]] 与 [[赵六]] 确认"
|
||||
|
||||
|
||||
def test_private_name_may_be_omitted_from_topic_headings():
|
||||
session = FakeSession(
|
||||
completions=[
|
||||
(DEFAULT_MODEL, "### 排班([[赵六]])"),
|
||||
(DEFAULT_MODEL, "最终日度总结"),
|
||||
(DEFAULT_MODEL, "仍遗漏对方"),
|
||||
]
|
||||
)
|
||||
client = MagpieClient(DEFAULT_MODEL, session=session)
|
||||
rows = [
|
||||
synthetic_row(
|
||||
"incoming",
|
||||
chat_id="private-chat",
|
||||
chat_name="赵六",
|
||||
chat_type=1,
|
||||
sender_id="other",
|
||||
)
|
||||
]
|
||||
_, _, _, tz = resolve_day("2026-11-03", "Asia/Shanghai")
|
||||
|
||||
result = summarize_messages(
|
||||
client,
|
||||
rows,
|
||||
date(2026, 11, 3),
|
||||
tz,
|
||||
contacts={"private-chat": {"other": "赵六"}},
|
||||
sender_types={"other": 1},
|
||||
)
|
||||
|
||||
assert len(session.post_calls) == 2
|
||||
assert "私聊补充" not in result
|
||||
|
||||
|
||||
def test_multiple_private_sources_are_repaired_from_conversation_summaries():
|
||||
session = FakeSession(
|
||||
completions=[
|
||||
@ -418,7 +551,7 @@ def test_multiple_private_sources_are_repaired_from_conversation_summaries():
|
||||
(DEFAULT_MODEL, "[[王五]] 私聊:模型选型"),
|
||||
(
|
||||
DEFAULT_MODEL,
|
||||
"### 数据库(未明确)\n"
|
||||
"### 数据库(对方)\n"
|
||||
"| 事项 | 来源 |\n| 数据库迁移 | [[王五]] |\n| 模型选型 | [[王五]] |",
|
||||
),
|
||||
(
|
||||
@ -763,6 +896,18 @@ def test_yaml_config_resolves_dated_output_paths(tmp_path):
|
||||
"2026-11-03.json")
|
||||
|
||||
|
||||
def test_regular_day_loads_previous_two_daily_logs(tmp_path):
|
||||
config = {"summary": str(tmp_path / "{date}.md")}
|
||||
(tmp_path / "2026-11-02.md").write_text("前一天合成日志", encoding="utf-8")
|
||||
(tmp_path / "2026-11-01.md").write_text("前两天合成日志", encoding="utf-8")
|
||||
|
||||
content, previous_missing = load_previous_summary(config, date(2026, 11, 3))
|
||||
|
||||
assert not previous_missing
|
||||
assert "【前一天 2026-11-02】\n前一天合成日志" in content
|
||||
assert "【前两天 2026-11-01】\n前两天合成日志" in content
|
||||
|
||||
|
||||
def test_monday_loads_sunday_and_previous_workday(tmp_path):
|
||||
config = {"summary": str(tmp_path / "{date}.md")}
|
||||
(tmp_path / "2026-11-01.md").write_text("周日合成日志", encoding="utf-8")
|
||||
@ -824,6 +969,41 @@ def test_heading_breaks_cover_sections_and_plain_wikilink_bodies():
|
||||
)
|
||||
|
||||
|
||||
def test_split_person_heading_is_merged():
|
||||
assert normalize_heading_breaks("### 与\n[[张三]]\n- 事项\n") == (
|
||||
"### [[张三]]\n- 事项\n"
|
||||
)
|
||||
|
||||
|
||||
def test_empty_meeting_section_is_omitted_but_fetch_error_is_kept():
|
||||
content = (
|
||||
"## 一、今日工作概览\n工作\n"
|
||||
"## 二、今日会议\n| 无 | 无 | 无 |\n"
|
||||
"## 三、关键沟通与结论\n事项\n"
|
||||
)
|
||||
|
||||
assert drop_empty_meeting_section(content, False) == (
|
||||
"## 一、今日工作概览\n工作\n## 三、关键沟通与结论\n事项\n"
|
||||
)
|
||||
assert drop_empty_meeting_section(content, False, "Timeout") == content
|
||||
|
||||
|
||||
def test_casual_sections_and_social_filler_are_removed():
|
||||
content = (
|
||||
"### 工作事项\n- 合成工作结论\n"
|
||||
"### 与赵六的闲聊\n- 寒暄和表情包\n"
|
||||
"### 其他沟通\n- 礼节性问候,无实质工作内容\n"
|
||||
"- 另一项工作信息\n"
|
||||
"## 四、前日工作延续\n"
|
||||
)
|
||||
|
||||
assert drop_casual_content(content) == (
|
||||
"### 工作事项\n- 合成工作结论\n"
|
||||
"### 其他沟通\n- 另一项工作信息\n"
|
||||
"## 四、前日工作延续\n"
|
||||
)
|
||||
|
||||
|
||||
def test_third_level_headings_are_hard_limited_without_cutting_wikilinks():
|
||||
content = (
|
||||
"### 一二三四五六七八九十([[张三]])\n"
|
||||
|
||||
Reference in New Issue
Block a user