feat(memory): protect Dream cron and polish migration UX
This commit is contained in:
@@ -4,7 +4,7 @@ import json
|
||||
import pytest
|
||||
|
||||
from nanobot.cron.service import CronService
|
||||
from nanobot.cron.types import CronSchedule
|
||||
from nanobot.cron.types import CronJob, CronPayload, CronSchedule
|
||||
|
||||
|
||||
def test_add_job_rejects_unknown_timezone(tmp_path) -> None:
|
||||
@@ -141,3 +141,18 @@ async def test_running_service_honors_external_disable(tmp_path) -> None:
|
||||
assert called == []
|
||||
finally:
|
||||
service.stop()
|
||||
|
||||
|
||||
def test_remove_job_refuses_system_jobs(tmp_path) -> None:
|
||||
service = CronService(tmp_path / "cron" / "jobs.json")
|
||||
service.register_system_job(CronJob(
|
||||
id="dream",
|
||||
name="dream",
|
||||
schedule=CronSchedule(kind="cron", expr="0 */2 * * *", tz="UTC"),
|
||||
payload=CronPayload(kind="system_event"),
|
||||
))
|
||||
|
||||
result = service.remove_job("dream")
|
||||
|
||||
assert result == "protected"
|
||||
assert service.get_job("dream") is not None
|
||||
|
||||
@@ -4,7 +4,7 @@ from datetime import datetime, timezone
|
||||
|
||||
from nanobot.agent.tools.cron import CronTool
|
||||
from nanobot.cron.service import CronService
|
||||
from nanobot.cron.types import CronJobState, CronSchedule
|
||||
from nanobot.cron.types import CronJob, CronJobState, CronPayload, CronSchedule
|
||||
|
||||
|
||||
def _make_tool(tmp_path) -> CronTool:
|
||||
@@ -262,6 +262,39 @@ def test_list_shows_next_run(tmp_path) -> None:
|
||||
assert "(UTC)" in result
|
||||
|
||||
|
||||
def test_list_includes_protected_dream_system_job_with_memory_purpose(tmp_path) -> None:
|
||||
tool = _make_tool(tmp_path)
|
||||
tool._cron.register_system_job(CronJob(
|
||||
id="dream",
|
||||
name="dream",
|
||||
schedule=CronSchedule(kind="cron", expr="0 */2 * * *", tz="UTC"),
|
||||
payload=CronPayload(kind="system_event"),
|
||||
))
|
||||
|
||||
result = tool._list_jobs()
|
||||
|
||||
assert "- dream (id: dream, cron: 0 */2 * * * (UTC))" in result
|
||||
assert "Dream memory consolidation for long-term memory." in result
|
||||
assert "cannot be removed" in result
|
||||
|
||||
|
||||
def test_remove_protected_dream_job_returns_clear_feedback(tmp_path) -> None:
|
||||
tool = _make_tool(tmp_path)
|
||||
tool._cron.register_system_job(CronJob(
|
||||
id="dream",
|
||||
name="dream",
|
||||
schedule=CronSchedule(kind="cron", expr="0 */2 * * *", tz="UTC"),
|
||||
payload=CronPayload(kind="system_event"),
|
||||
))
|
||||
|
||||
result = tool._remove_job("dream")
|
||||
|
||||
assert "Cannot remove job `dream`." in result
|
||||
assert "Dream memory consolidation job for long-term memory" in result
|
||||
assert "cannot be removed" in result
|
||||
assert tool._cron.get_job("dream") is not None
|
||||
|
||||
|
||||
def test_add_cron_job_defaults_to_tool_timezone(tmp_path) -> None:
|
||||
tool = _make_tool_with_tz(tmp_path, "Asia/Shanghai")
|
||||
tool.set_context("telegram", "chat-1")
|
||||
|
||||
Reference in New Issue
Block a user