Files
Lark-Snooper/tests/test_calendar.py
Benature 5edd199da7 feat: AI Notes 智能纪要链接自动获取与月记背景支持
- snooper_calendar.py: 新增 fetch_ai_notes_links(),优先从 AI Notes 会话获取纪要链接
  - 支持 docx/minutes 格式,不限制三级域名
  - 优先读本地缓存,本地无 topic 时从网络补充
  - 按链接类型区分匹配窗口:permission_change ±24h,finish_recording ±6h
  - 具体主题要求与日历事件标题匹配,通用主题(视频会议)允许匹配
  - 返回未匹配链接列表,供日报保留展示
- snooper_storage.py: 保存时从 content_data 提取 URL 和 topic 到 content
  - 递归遍历 bytes 提取 URL,避免 JSON 序列化丢失
  - 新增 _extract_links_with_topics() 同时提取 URL 和会议主题
- lark_snooper.py: 未匹配链接插入今日会议章节的相关智能纪要子章节
- snooper_monthly.py: 新增 load_previous_monthly_background(),支持前5个工作日读取上月月记
- tests/test_calendar.py: 适配 fetch_calendar_events 返回 tuple
2026-11-21 20:29:55 +08:00

84 lines
3.0 KiB
Python

from datetime import date
from zoneinfo import ZoneInfo
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))
if name == "calendars.GetUserPrimaryCalendarRequest":
return {"calendar": {"id": "calendar-synthetic"}}
assert name == "calendarevents.QueryInstanceRequest"
return {
"calendarEventInstance": [
{
"eventRefId": "event-b",
"beginTime": 1_789_000_000,
"endTime": 1_789_003_600,
},
{
"eventRefId": "event-a",
"beginTime": 1_788_000_000,
"endTime": 1_788_003_600,
},
],
"events": {
"event-a": {
"summary": "合成早会",
"locations": [{"name": "合成会议室 A"}],
"isDeleted": False,
"url": "https://example.com/a" if self.native_urls else "",
},
"event-b": {
"summary": "合成下午会",
"locations": [{"name": "合成会议室 B"}],
"isDeleted": True,
"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")
events, _ = fetch_calendar_events(client, date(2026, 9, 9), tz)
assert [event["summary"] for event in events] == ["合成早会", "合成下午会"]
assert events[0]["location"] == "合成会议室 A"
assert events[0]["url"] == "https://example.com/a"
assert events[1]["cancelled"] is True
assert events[1]["url"] == "https://example.com/minutes-b"
assert "attendees" not in events[0]
assert "description" not in events[0]
name, request = client.calls[1]
assert request["calendarIds"] == ["calendar-synthetic"]
assert request["needsBriefEvents"] is True
assert request["endTime"] - request["startTime"] == 86_400