fix(cron): reject non-positive every_seconds intervals

A negative every_seconds created a job with no next run and still reported 'Created job', so it silently never fired. every_seconds=0 passed the exactly-one-schedule check but then fell through the truthiness test to the misleading 'either every_seconds, cron_expr, or at is required' error. Declare minimum=1 in the tool schema, check every_seconds explicitly, and have CronService refuse every schedules without a positive every_ms, matching the WebUI parser.
This commit is contained in:
bob authored and Xubin Ren committed 2026-10-03 19:28:39 +08:00
1 parent e2cd6908c7
commit b5f539292d
4 files changed
+46 -2

No files matched your search

+23
View File
@@ -343,6 +343,29 @@ def test_add_job_rejects_multiple_schedule_fields(tmp_path) -> None:
assert tool._cron.list_jobs() == []
@pytest.mark.parametrize("every_seconds", [0, -60])
def test_add_job_rejects_non_positive_interval(tmp_path, every_seconds: int) -> 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", every_seconds, None, None, None)
assert result == "Error: every_seconds must be a positive integer"
assert tool._cron.list_jobs(include_disabled=True) == []
@pytest.mark.parametrize("every_seconds", [0, -60])
def test_validate_params_rejects_non_positive_interval(tmp_path, every_seconds: int) -> None:
tool = _make_tool(tmp_path)
errors = tool.validate_params(
{"action": "add", "message": "Morning standup", "every_seconds": every_seconds}
)
assert any("every_seconds" in error for error in errors)
def test_add_job_binds_current_session_key(tmp_path) -> None:
tool = _make_tool(tmp_path)
with request_context(