fix(cron): normalize partial job records

This commit is contained in:
helix4u 2026-05-09 00:25:30 -06:00 committed by kshitij
parent f2afa68a4a
commit e407376c50
6 changed files with 122 additions and 11 deletions

View file

@ -207,6 +207,26 @@ class TestJobCRUD:
jobs = list_jobs()
assert len(jobs) == 2
def test_list_jobs_normalizes_partial_legacy_records(self, tmp_cron_dir):
save_jobs([
{
"id": "abc123deadbe",
"name": None,
"prompt": None,
"schedule_display": None,
"schedule": {"kind": "interval", "minutes": 60, "display": "every 60m"},
"enabled": True,
}
])
jobs = list_jobs()
assert jobs[0]["id"] == "abc123deadbe"
assert jobs[0]["name"] == "abc123deadbe"
assert jobs[0]["prompt"] == ""
assert jobs[0]["schedule_display"] == "every 60m"
assert jobs[0]["state"] == "scheduled"
def test_remove_job(self, tmp_cron_dir):
job = create_job(prompt="Temp job", schedule="30m")
assert remove_job(job["id"]) is True

View file

@ -1788,6 +1788,11 @@ class TestBuildJobPromptSilentHint:
result = _build_job_prompt(job)
assert "[SILENT]" in result
def test_hint_present_when_legacy_prompt_is_null(self):
job = {"id": "abc123deadbe", "name": None, "prompt": None}
result = _build_job_prompt(job)
assert "[SILENT]" in result
def test_delivery_guidance_present(self):
"""Cron hint tells agents their final response is auto-delivered."""
job = {"prompt": "Generate a report"}

View file

@ -122,6 +122,28 @@ class TestUnifiedCronjobTool:
assert listing["jobs"][0]["name"] == "Server Check"
assert listing["jobs"][0]["state"] == "scheduled"
def test_list_handles_partial_legacy_job_records(self):
from cron.jobs import save_jobs
save_jobs([
{
"id": "abc123deadbe",
"name": None,
"prompt": None,
"schedule_display": None,
"schedule": {"kind": "interval", "minutes": 60, "display": "every 60m"},
"repeat": {"times": None, "completed": 0},
"enabled": True,
}
])
listing = json.loads(cronjob(action="list"))
assert listing["success"] is True
assert listing["jobs"][0]["name"] == "abc123deadbe"
assert listing["jobs"][0]["prompt_preview"] == ""
assert listing["jobs"][0]["schedule"] == "every 60m"
def test_pause_and_resume(self):
created = json.loads(cronjob(action="create", prompt="Check", schedule="every 1h"))
job_id = created["job_id"]