mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-02 09:22:36 +00:00
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
28 lines
808 B
Python
28 lines
808 B
Python
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"
|