fix: harden cron session automation flows

This commit is contained in:
chengyongru
2026-06-12 18:13:25 +08:00
parent b5f9d51b5b
commit a50b3ac0f2
30 changed files with 267 additions and 56 deletions
+25 -1
View File
@@ -4,7 +4,7 @@ import time
import pytest
from nanobot.cron.service import CronService
from nanobot.cron.service import CronJobSkippedError, CronService
from nanobot.cron.types import CronJob, CronPayload, CronSchedule
@@ -296,6 +296,30 @@ async def test_run_history_records_errors(tmp_path) -> None:
assert loaded.state.run_history[0].error == "boom"
@pytest.mark.asyncio
async def test_run_history_records_skipped_jobs(tmp_path) -> None:
store_path = tmp_path / "cron" / "jobs.json"
async def skip(_):
raise CronJobSkippedError("missing session binding")
service = CronService(store_path, on_job=skip)
job = service.add_job(
name="skip",
schedule=CronSchedule(kind="every", every_ms=60_000),
message="hello",
)
await service.run_job(job.id)
loaded = service.get_job(job.id)
assert loaded is not None
assert loaded.state.last_status == "skipped"
assert loaded.state.last_error == "missing session binding"
assert len(loaded.state.run_history) == 1
assert loaded.state.run_history[0].status == "skipped"
assert loaded.state.run_history[0].error == "missing session binding"
@pytest.mark.asyncio
async def test_run_history_records_job_cancellation(tmp_path) -> None:
store_path = tmp_path / "cron" / "jobs.json"