oclaw/tests/test_gateway_cron_service.py
oliver 47813f6a94 feat(scheduler): add scheduled jobs with channel-aware delivery
Introduce persisted cron/interval jobs, gateway scheduler loop, worker turns,
and admin CRUD/edit UI. Route proactive reminders via the originating chat
channel (WhatsApp vs WeChat), harden Weixin outbound with durable queue and
PG-compatible polling, and fix chat UI to show each scheduled reminder separately.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 15:56:10 +08:00

49 lines
1.7 KiB
Python

from __future__ import annotations
import os
import tempfile
import unittest
from datetime import datetime, timedelta, timezone
from pathlib import Path
from interfaces.gateway.http_adapter import dispatch_gateway_http_method
from svc.persistence.assistant_store import reset_assistant_store_singleton
from svc.persistence.sqlite_store import SqliteStore
class GatewayCronServiceTests(unittest.TestCase):
def setUp(self) -> None:
self._tmp = tempfile.TemporaryDirectory(ignore_cleanup_errors=True)
self.db = Path(self._tmp.name) / "cron.sqlite"
os.environ["OPS_ASSISTANT_DB_PATH"] = str(self.db)
os.environ["AIA_ASSISTANT_DB_BACKEND"] = "sqlite"
reset_assistant_store_singleton()
self.store = SqliteStore(str(self.db))
t = self.store.create_tenant("default")
self.tenant_id = str(t["id"])
def tearDown(self) -> None:
reset_assistant_store_singleton()
self._tmp.cleanup()
def test_cron_add_and_list(self) -> None:
once_at = (datetime.now(timezone.utc) + timedelta(hours=2)).isoformat()
add = dispatch_gateway_http_method(
"cron.add",
{
"name": "gw job",
"schedule": once_at,
"schedule_kind": "once",
"tenant_id": self.tenant_id,
"prompt": "hello",
},
)
self.assertTrue(add.get("ok"), add)
lst = dispatch_gateway_http_method("cron.list", {"tenant_id": self.tenant_id})
self.assertTrue(lst.get("ok"), lst)
payload = lst.get("payload") or {}
self.assertGreaterEqual(len(payload.get("items") or []), 1)
if __name__ == "__main__":
unittest.main()