fix(cron): reject conflicting schedule fields
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
b1d54b2ca2
commit
835cac0ae7
2 files changed
+19
No files matched your search
@@ -181,6 +181,14 @@ class CronTool(Tool):
|
|||||||
if err := self._validate_timezone(tz):
|
if err := self._validate_timezone(tz):
|
||||||
return err
|
return err
|
||||||
|
|
||||||
|
schedule_count = sum(
|
||||||
|
value is not None for value in (every_seconds, cron_expr, at)
|
||||||
|
)
|
||||||
|
if schedule_count != 1:
|
||||||
|
return ToolResult.error(
|
||||||
|
"Error: exactly one of every_seconds, cron_expr, or at is required"
|
||||||
|
)
|
||||||
|
|
||||||
# Build schedule
|
# Build schedule
|
||||||
delete_after = False
|
delete_after = False
|
||||||
if every_seconds:
|
if every_seconds:
|
||||||
|
|||||||
@@ -384,6 +384,17 @@ def test_add_at_job_accepts_future_datetime(tmp_path) -> None:
|
|||||||
assert job.state.next_run_at_ms is not None
|
assert job.state.next_run_at_ms is not None
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_job_rejects_multiple_schedule_fields(tmp_path) -> None:
|
||||||
|
tool = _make_tool(tmp_path)
|
||||||
|
with request_context(
|
||||||
|
RequestContext(channel="telegram", chat_id="chat-1", session_key="telegram:chat-1")
|
||||||
|
):
|
||||||
|
result = tool._add_job(None, "Morning standup", 60, "0 8 * * *", None, None)
|
||||||
|
|
||||||
|
assert result == "Error: exactly one of every_seconds, cron_expr, or at is required"
|
||||||
|
assert tool._cron.list_jobs() == []
|
||||||
|
|
||||||
|
|
||||||
def test_add_job_binds_current_session_key(tmp_path) -> None:
|
def test_add_job_binds_current_session_key(tmp_path) -> None:
|
||||||
tool = _make_tool(tmp_path)
|
tool = _make_tool(tmp_path)
|
||||||
with request_context(
|
with request_context(
|
||||||
|
|||||||
Reference in new issue
Block a user