From 3f71014b7c64a0160e9ff44134e58cdcfd9c1605 Mon Sep 17 00:00:00 2001 From: Xubin Ren Date: Wed, 25 Mar 2026 10:33:35 +0000 Subject: [PATCH] fix(agent): use configured timezone when registering cron tool Read the default timezone from the agent context when wiring the cron tool so startup no longer depends on an out-of-scope local variable. Add a regression test to ensure AgentLoop passes the configured timezone through to cron. Made-with: Cursor --- nanobot/agent/loop.py | 4 +++- tests/agent/test_loop_cron_timezone.py | 27 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/agent/test_loop_cron_timezone.py diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index 0ae4e23de..afe62ca28 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -144,7 +144,9 @@ class AgentLoop: self.tools.register(MessageTool(send_callback=self.bus.publish_outbound)) self.tools.register(SpawnTool(manager=self.subagents)) if self.cron_service: - self.tools.register(CronTool(self.cron_service, default_timezone=timezone or "UTC")) + self.tools.register( + CronTool(self.cron_service, default_timezone=self.context.timezone or "UTC") + ) async def _connect_mcp(self) -> None: """Connect to configured MCP servers (one-time, lazy).""" diff --git a/tests/agent/test_loop_cron_timezone.py b/tests/agent/test_loop_cron_timezone.py new file mode 100644 index 000000000..7738d3043 --- /dev/null +++ b/tests/agent/test_loop_cron_timezone.py @@ -0,0 +1,27 @@ +from pathlib import Path +from unittest.mock import MagicMock + +from nanobot.agent.loop import AgentLoop +from nanobot.agent.tools.cron import CronTool +from nanobot.bus.queue import MessageBus +from nanobot.cron.service import CronService + + +def test_agent_loop_registers_cron_tool_with_configured_timezone(tmp_path: Path) -> None: + bus = MessageBus() + provider = MagicMock() + provider.get_default_model.return_value = "test-model" + + loop = AgentLoop( + bus=bus, + provider=provider, + workspace=tmp_path, + model="test-model", + cron_service=CronService(tmp_path / "cron" / "jobs.json"), + timezone="Asia/Shanghai", + ) + + cron_tool = loop.tools.get("cron") + + assert isinstance(cron_tool, CronTool) + assert cron_tool._default_timezone == "Asia/Shanghai"