fix: harden cron tool contract and repeat guard
This commit is contained in:
@@ -7,7 +7,6 @@ import pytest
|
||||
from nanobot.agent.tools.cron import CronTool
|
||||
from nanobot.cron.service import CronService
|
||||
from nanobot.cron.types import CronJob, CronJobState, CronPayload, CronSchedule
|
||||
from tests.test_openai_api import pytest_plugins
|
||||
|
||||
|
||||
def _make_tool(tmp_path) -> CronTool:
|
||||
@@ -346,6 +345,47 @@ def test_add_job_can_disable_delivery(tmp_path) -> None:
|
||||
assert job.payload.deliver is False
|
||||
|
||||
|
||||
def test_cron_schema_advertises_action_specific_requirements(tmp_path) -> None:
|
||||
tool = _make_tool(tmp_path)
|
||||
|
||||
assert tool.parameters["required"] == ["action"]
|
||||
assert tool.parameters["oneOf"] == [
|
||||
{
|
||||
"properties": {
|
||||
"action": {"enum": ["add"]},
|
||||
"message": {"type": "string", "minLength": 1},
|
||||
},
|
||||
"required": ["action", "message"],
|
||||
},
|
||||
{
|
||||
"properties": {"action": {"enum": ["list"]}},
|
||||
"required": ["action"],
|
||||
},
|
||||
{
|
||||
"properties": {"action": {"enum": ["remove"]}},
|
||||
"required": ["action", "job_id"],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_validate_params_requires_message_only_for_add(tmp_path) -> None:
|
||||
tool = _make_tool(tmp_path)
|
||||
|
||||
assert "message is required when action='add'" in tool.validate_params({"action": "add"})
|
||||
assert tool.validate_params({"action": "list"}) == []
|
||||
assert "job_id is required when action='remove'" in tool.validate_params({"action": "remove"})
|
||||
|
||||
|
||||
def test_add_job_empty_message_returns_actionable_error(tmp_path) -> None:
|
||||
tool = _make_tool(tmp_path)
|
||||
tool.set_context("telegram", "chat-1")
|
||||
|
||||
result = tool._add_job(None, "", 60, None, None, None)
|
||||
|
||||
assert "action='add' requires a non-empty 'message'" in result
|
||||
assert "Retry including message=" in result
|
||||
|
||||
|
||||
def test_list_excludes_disabled_jobs(tmp_path) -> None:
|
||||
tool = _make_tool(tmp_path)
|
||||
job = tool._cron.add_job(
|
||||
|
||||
Reference in New Issue
Block a user