Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
test(cron): cover rejected updates and legacy interval recovery
Xubin Rend8c3b3cab5fe
diff --git a/tests/cron/test_cron_service.py b/tests/cron/test_cron_service.pyindex a3b4d414f..324184b04 100644--- a/tests/cron/test_cron_service.py+++ b/tests/cron/test_cron_service.py@@ -1247,7 +1247,14 @@ def test_update_job_rejects_system_job(tmp_path) -> None:assert service.get_job("dream").name == "dream"-def test_update_job_validates_schedule(tmp_path) -> None:+ "schedule,error",+ [+ (CronSchedule(kind="cron", expr="0 9 * * *", tz="Bad/Zone"), "unknown timezone"),+ (CronSchedule(kind="every", every_ms=0), "positive 'every_ms'"),+ ],+)+def test_update_job_validates_schedule(tmp_path, schedule, error) -> None:service = CronService(tmp_path / "cron" / "jobs.json")job = service.add_job(name="validate",@@ -1255,11 +1262,12 @@ def test_update_job_validates_schedule(tmp_path) -> None:message="hello",**_bound_chat(),)- with pytest.raises(ValueError, match="unknown timezone"):- service.update_job(- job.id,- schedule=CronSchedule(kind="cron", expr="0 9 * * *", tz="Bad/Zone"),- )+ action_path = service.store_path.with_name("action.jsonl")+ before = action_path.read_bytes()+ with pytest.raises(ValueError, match=error):+ service.update_job(job.id, schedule=schedule)+ assert action_path.read_bytes() == before+ assert service.get_job(job.id).schedule.every_ms == 60_000@pytest.mark.asynciodiff --git a/tests/cron/test_cron_tool_list.py b/tests/cron/test_cron_tool_list.pyindex 5c968f622..e410cbc64 100644--- a/tests/cron/test_cron_tool_list.py+++ b/tests/cron/test_cron_tool_list.py@@ -1,5 +1,6 @@"""Tests for CronTool._list_jobs() output formatting."""+import jsonfrom datetime import datetime, timedelta, timezonefrom types import SimpleNamespacefrom zoneinfo import ZoneInfo@@ -366,6 +367,42 @@ def test_validate_params_rejects_non_positive_interval(tmp_path, every_seconds:assert any("every_seconds" in error for error in errors)+async def test_legacy_zero_interval_job_can_be_listed_repaired_and_removed(tmp_path) -> None:+ tool = _make_tool(tmp_path)+ store_path = tool._cron.store_path+ store_path.parent.mkdir(parents=True)+ # Older versions accepted and persisted zero-interval jobs that never ran.+ store_path.write_text(json.dumps({+ "version": 1,+ "jobs": [{+ "id": "legacy-zero",+ "name": "Legacy reminder",+ "enabled": True,+ "schedule": {"kind": "every", "everyMs": 0},+ "payload": {"kind": "agent_turn", "message": "hello", **_bound_chat()},+ }],+ }), encoding="utf-8")++ assert "Legacy reminder" in await tool.execute(action="list")+ renamed = tool._cron.update_job("legacy-zero", name="Repair me")+ assert isinstance(renamed, CronJob)+ assert renamed.schedule.every_ms == 0+ repaired = tool._cron.update_job(+ "legacy-zero", schedule=CronSchedule(kind="every", every_ms=60_000),+ )+ assert isinstance(repaired, CronJob)+ assert repaired.state.next_run_at_ms is not None++ reloaded = _make_tool(tmp_path)+ assert "Repair me" in await reloaded.execute(action="list")+ with request_context(RequestContext(+ channel="websocket", chat_id="chat-1", session_key="websocket:chat-1",+ )):+ await reloaded.execute(action="remove", job_id="legacy-zero")+ assert _make_tool(tmp_path)._cron.list_jobs(include_disabled=True) == []++def test_add_job_binds_current_session_key(tmp_path) -> None:tool = _make_tool(tmp_path)with request_context(