feat: 优化周记周期与总结输出
This commit is contained in:
@ -14,6 +14,7 @@ from snooper_summary import (
|
||||
MagpieClient,
|
||||
SummaryError,
|
||||
chunk_messages,
|
||||
clean_model_output,
|
||||
drop_casual_content,
|
||||
drop_empty_meeting_section,
|
||||
escape_obsidian_tags,
|
||||
@ -116,6 +117,14 @@ def test_sanitize_wikilink_pipes_preserves_table_and_other_text():
|
||||
)
|
||||
|
||||
|
||||
def test_clean_model_output_discards_think_draft_and_keeps_final_answer():
|
||||
content = "<think>草稿\n# 重复日报</think>\n# 最终日报\n正文"
|
||||
|
||||
assert clean_model_output(content) == "# 最终日报\n正文"
|
||||
with pytest.raises(SummaryError):
|
||||
clean_model_output("<think>未闭合草稿")
|
||||
|
||||
|
||||
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
|
||||
@ -1009,17 +1018,27 @@ def test_monday_loads_sunday_and_previous_workday(tmp_path):
|
||||
assert "【上周最后工作日 2026-10-30】\n周五合成日志" in content
|
||||
|
||||
|
||||
def test_monday_missing_sunday_is_marked_even_with_workday_log(tmp_path):
|
||||
def test_monday_with_workday_log_is_not_missing_without_sunday(tmp_path):
|
||||
config = {"summary": str(tmp_path / "{date}.md")}
|
||||
(tmp_path / "2026-10-30.md").write_text("周五合成日志", encoding="utf-8")
|
||||
|
||||
content, previous_missing = load_previous_summary(config, date(2026, 11, 2))
|
||||
|
||||
assert previous_missing
|
||||
assert not previous_missing
|
||||
assert "【周日 2026-11-01】\n<日志不存在>" in content
|
||||
assert "周五合成日志" in content
|
||||
|
||||
|
||||
def test_monday_without_sunday_or_workday_log_is_missing(tmp_path):
|
||||
config = {"summary": str(tmp_path / "{date}.md")}
|
||||
|
||||
content, previous_missing = load_previous_summary(config, date(2026, 11, 2))
|
||||
|
||||
assert previous_missing
|
||||
assert "【周日 2026-11-01】\n<日志不存在>" in content
|
||||
assert "【上周最后工作日 2026-10-30】\n<日志不存在>" in content
|
||||
|
||||
|
||||
def test_previous_workday_skips_custom_holidays_and_weekends():
|
||||
holidays = {date(2026, 10, 30), date(2026, 11, 1)}
|
||||
|
||||
|
||||
@ -6,8 +6,10 @@ import pytest
|
||||
|
||||
from snooper_summary import summarize_messages
|
||||
from snooper_weekly import (
|
||||
WEEKLY_FINAL_PROMPT,
|
||||
WeeklyError,
|
||||
generate_weekly,
|
||||
iso_week_label,
|
||||
load_previous_weekly_background,
|
||||
week_bounds,
|
||||
)
|
||||
@ -15,16 +17,18 @@ from snooper_weekly import (
|
||||
|
||||
def test_week_bounds_use_monday_and_sunday():
|
||||
assert week_bounds(date(2024, 7, 4)) == (
|
||||
date(2024, 7, 1), date(2024, 7, 7)
|
||||
date(2024, 6, 30), date(2024, 7, 6)
|
||||
)
|
||||
assert iso_week_label(date(2024, 6, 30)) == "2024-W26"
|
||||
assert "# {weekly_date} 周记" in WEEKLY_FINAL_PROMPT
|
||||
|
||||
|
||||
def test_previous_weekly_background_uses_previous_monday(tmp_path):
|
||||
output = {
|
||||
"summary": str(tmp_path / "Daily" / "Msg{date}.md"),
|
||||
"weekly": str(tmp_path / "Weekly" / "Week{date}.md"),
|
||||
"summary": str(tmp_path / "Daily" / "MsgYYYY-MM-DD.md"),
|
||||
"weekly": str(tmp_path / "Weekly" / "MsgWYYYY-WW.md"),
|
||||
}
|
||||
weekly = tmp_path / "Weekly" / "Week2024-07-01.md"
|
||||
weekly = tmp_path / "Weekly" / "MsgW2024-26.md"
|
||||
weekly.parent.mkdir(parents=True)
|
||||
weekly.write_text("---\ntype: weekly\n---\n\n上周合成周记", encoding="utf-8")
|
||||
|
||||
@ -45,11 +49,11 @@ def test_generate_weekly_reads_previous_week_and_sanitizes_links(
|
||||
(daily / f"Msg{day}.md").write_text(
|
||||
f"---\nmodel: synthetic\n---\n\n# {day}\n合成进展", encoding="utf-8"
|
||||
)
|
||||
(weekly / "Week2024-07-01.md").write_text("上周合成周记", encoding="utf-8")
|
||||
(weekly / "MsgW2024-26.md").write_text("上周合成周记", encoding="utf-8")
|
||||
config = tmp_path / "config.yaml"
|
||||
config.write_text(
|
||||
f"output:\n summary: '{daily}/Msg{{date}}.md'\n"
|
||||
f" weekly: '{weekly}/Week{{date}}.md'\n",
|
||||
f"output:\n summary: '{daily}/MsgYYYY-MM-DD.md'\n"
|
||||
f" weekly: '{weekly}/MsgWYYYY-WW.md'\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
@ -76,6 +80,7 @@ def test_generate_weekly_reads_previous_week_and_sanitizes_links(
|
||||
text = output.read_text(encoding="utf-8")
|
||||
assert "[[审核群|指数内容部落]]" in text
|
||||
assert "type: weekly" in text
|
||||
assert "date:" not in text
|
||||
assert "上周合成周记" in clients[0].prompts[-1]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user