feat: 重构 Reminder Notification 系统并更新应用包名

This commit is contained in:
qzl
2026-03-30 18:36:57 +08:00
parent 9fb2a6857b
commit 91bf3c3f96
90 changed files with 5133 additions and 3017 deletions
@@ -0,0 +1,96 @@
from __future__ import annotations
import asyncio
from typing import Any
import pytest
from core.runtime import cli
class _FakeScheduler:
def __init__(self) -> None:
self.started = False
self.shutdown_called = False
self.jobs: list[dict[str, Any]] = []
def add_job(self, func: Any, **kwargs: Any) -> None:
self.jobs.append({"func": func, **kwargs})
def start(self) -> None:
self.started = True
def shutdown(self, *, wait: bool) -> None:
self.shutdown_called = True
self.shutdown_wait = wait
class _StopEvent:
async def wait(self) -> None:
raise asyncio.CancelledError
@pytest.mark.asyncio
async def test_run_automation_scheduler_forever_uses_async_scheduler(
monkeypatch: pytest.MonkeyPatch,
) -> None:
fake_scheduler = _FakeScheduler()
dispatch_limits: list[int] = []
async def _fake_scan(*, limit: int) -> None:
dispatch_limits.append(limit)
monkeypatch.setattr(cli, "AsyncIOScheduler", lambda: fake_scheduler)
monkeypatch.setattr(cli, "run_automation_scheduler_scan", _fake_scan)
monkeypatch.setattr(cli.asyncio, "Event", lambda: _StopEvent())
settings = cli.config.automation_scheduler
old_enabled = settings.enabled
old_interval = settings.interval_seconds
old_limit = settings.batch_limit
settings.enabled = True
settings.interval_seconds = 9
settings.batch_limit = 7
try:
with pytest.raises(asyncio.CancelledError):
await cli.run_automation_scheduler_forever()
finally:
settings.enabled = old_enabled
settings.interval_seconds = old_interval
settings.batch_limit = old_limit
assert fake_scheduler.started is True
assert fake_scheduler.shutdown_called is True
assert len(fake_scheduler.jobs) == 1
assert fake_scheduler.jobs[0]["max_instances"] == 1
assert fake_scheduler.jobs[0]["coalesce"] is True
scan_job = fake_scheduler.jobs[0]["func"]
await scan_job()
assert dispatch_limits == [7]
@pytest.mark.asyncio
async def test_run_automation_scheduler_forever_disabled_noop(
monkeypatch: pytest.MonkeyPatch,
) -> None:
settings = cli.config.automation_scheduler
old_enabled = settings.enabled
settings.enabled = False
called = False
def _unexpected_scheduler() -> _FakeScheduler:
nonlocal called
called = True
return _FakeScheduler()
monkeypatch.setattr(cli, "AsyncIOScheduler", _unexpected_scheduler)
try:
await cli.run_automation_scheduler_forever()
finally:
settings.enabled = old_enabled
assert called is False