"""Schedule runner: one-time push rollback on execution failure."""

from types import SimpleNamespace

from server.background.schedule_runner import rollback_schedule_after_failed_run


def test_once_failure_restores_enabled_and_last_run_at():
    prev = None
    schedule = SimpleNamespace(last_run_at="now", enabled=False)
    rollback_schedule_after_failed_run(schedule, prev, "once")
    assert schedule.last_run_at is prev
    assert schedule.enabled is True


def test_cron_failure_restores_last_run_at_only():
    prev = None
    schedule = SimpleNamespace(last_run_at="now", enabled=True)
    rollback_schedule_after_failed_run(schedule, prev, "cron")
    assert schedule.last_run_at is prev
    assert schedule.enabled is True
