feat(memory): protect Dream cron and polish migration UX

This commit is contained in:
Xubin Ren
2026-04-04 09:01:42 +00:00
parent 6e896249c8
commit 408a61b0e1
4 changed files with 86 additions and 8 deletions
+34 -1
View File
@@ -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")