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

+15
View File
@@ -157,6 +157,21 @@ def test_add_job_rejects_missing_cron_expression(tmp_path, expr: str | None) ->
assert service.list_jobs(include_disabled=True) == []
@pytest.mark.parametrize("every_ms", [None, 0, -60_000])
def test_add_job_rejects_non_positive_interval(tmp_path, every_ms: int | None) -> None:
service = CronService(tmp_path / "cron" / "jobs.json")
with pytest.raises(ValueError, match="requires a positive 'every_ms'"):
service.add_job(
name="never runs",
schedule=CronSchedule(kind="every", every_ms=every_ms),
message="hello",
**_bound_chat(),
)
assert service.list_jobs(include_disabled=True) == []
def test_add_job_rejects_invalid_cron_expression_before_persisting(tmp_path) -> None:
service = CronService(tmp_path / "cron" / "jobs.json")