from __future__ import annotations from datetime import datetime from app.services.scheduler_center_core.ai_pmo_cadence import AIPMOCadenceScheduler def test_should_emit_executive_brief_honors_send_time_and_cycle() -> None: config = { "enabled": True, "send_time": "08:30", "send_cycle": "workdays", "timezone": "Asia/Shanghai", } assert ( AIPMOCadenceScheduler._should_emit_executive_brief( now=datetime(2026, 3, 30, 9, 0, 0), config=config, last_snapshot_at=None, ) is True ) assert ( AIPMOCadenceScheduler._should_emit_executive_brief( now=datetime(2026, 3, 30, 8, 0, 0), config=config, last_snapshot_at=None, ) is False ) assert ( AIPMOCadenceScheduler._should_emit_executive_brief( now=datetime(2026, 4, 4, 9, 0, 0), config=config, last_snapshot_at=None, ) is False ) def test_should_emit_executive_brief_skips_when_today_snapshot_already_exists() -> None: config = { "enabled": True, "send_time": "08:30", "send_cycle": "daily", "timezone": "Asia/Shanghai", } assert ( AIPMOCadenceScheduler._should_emit_executive_brief( now=datetime(2026, 3, 30, 9, 0, 0), config=config, last_snapshot_at=datetime(2026, 3, 30, 8, 45, 0), ) is False ) assert ( AIPMOCadenceScheduler._should_emit_executive_brief( now=datetime(2026, 3, 30, 9, 0, 0), config={ **config, "enabled": False, }, last_snapshot_at=None, ) is False )