The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(cron): keep two DST fall-back invariants (due gate, real elapsed timers)
teknium13cf26c82b455
diff --git a/tests/cron/test_due_scan_dst_fold.py b/tests/cron/test_due_scan_dst_fold.pyindex 5fbe2f2d5f8..0b57069393f 100644--- a/tests/cron/test_due_scan_dst_fold.py+++ b/tests/cron/test_due_scan_dst_fold.py@@ -28,15 +28,12 @@ def _instant(hour, minute):return datetime(2026, 11, 1, hour, minute, tzinfo=timezone.utc).astimezone(NEW_YORK)-def _job(next_run_at, *, kind="interval", expr=None):- schedule = {"kind": kind, "minutes": 60}- if expr is not None:- schedule["expr"] = expr+def _job(next_run_at):return {"id": "dst-job","name": "dst-job","prompt": "fixture",- "schedule": schedule,+ "schedule": {"kind": "interval", "minutes": 60},"next_run_at": next_run_at.isoformat(),"last_run_at": None,"enabled": True,@@ -62,49 +59,16 @@ def test_fold_one_interval_is_not_due_during_fold_zero(dst_cron_store, monkeypatassert _due_at(monkeypatch, now, scheduled) == []-def test_interval_runs_when_due_in_either_fold(dst_cron_store, monkeypatch):- first_fold_now = _instant(5, 1)- first_fold_slot = _instant(5, 0)- second_fold_now = _instant(6, 1)- second_fold_slot = _instant(6, 0)+def test_fold_hour_timers_measure_real_elapsed_time(dst_cron_store, monkeypatch):+ """Claim ages and re-run delays count real seconds across the repeated hour."""+ from cron import unreachable_retry- assert first_fold_now.fold == first_fold_slot.fold == 0- assert second_fold_now.fold == second_fold_slot.fold == 1- assert _due_at(monkeypatch, first_fold_now, first_fold_slot) == ["dst-job"]- assert _due_at(monkeypatch, second_fold_now, second_fold_slot) == ["dst-job"]+ now = _instant(6, 2) # 01:02 EST, fold=1+ claimed = _instant(5, 58) # 01:58 EDT, fold=0: four real minutes earlier+ assert jobs._claim_is_live({"at": claimed.isoformat(), "by": "peer-host:1"}, now, 300)--def test_cron_future_occurrence_is_not_due_in_prior_fold(dst_cron_store, monkeypatch):- now = _instant(5, 31) # 01:31 EDT, fold=0- scheduled = _instant(6, 30) # 01:30 EST, fold=1- assert scheduled.timestamp() > now.timestamp()-- monkeypatch.setattr(jobs, "_hermes_now", lambda: now)- jobs.save_jobs([_job(scheduled, kind="cron", expr="30 1 * * *")])- assert jobs.get_due_jobs() == []---def test_hourly_interval_does_not_recur_each_minute_during_fallback(dst_cron_store, monkeypatch):- """A one-hour cadence remains hourly across both occurrences of local 01:00."""- from datetime import timedelta-- start = datetime(2026, 11, 1, 4, 0, tzinfo=timezone.utc) # 00:00 EDT- initial_now = (start - timedelta(hours=1)).astimezone(NEW_YORK)- monkeypatch.setattr(jobs, "_hermes_now", lambda: initial_now)- job = jobs.create_job(- prompt="fixture", schedule="every 60m", model="fixture", deliver="local")- fired_at = []-- for elapsed_minutes in range(181):- now = (start + timedelta(minutes=elapsed_minutes)).astimezone(NEW_YORK)- monkeypatch.setattr(jobs, "_hermes_now", lambda now=now: now)- due = jobs.get_due_jobs()- if due:- fired_at.append(now.timestamp())- assert [row["id"] for row in due] == [job["id"]]- assert jobs.claim_job_for_fire(job["id"]) is True- assert jobs.mark_job_run(job["id"], success=True) is True-- assert fired_at == [- (start + timedelta(hours=offset)).timestamp() for offset in range(4)- ]+ monkeypatch.setattr(unreachable_retry, "_hermes_now", lambda: now)+ job = _job(_instant(9, 0)) # natural next run 04:00 EST, well past the ladder+ assert unreachable_retry.plan_retry(job) is True+ retry_at = datetime.fromisoformat(job["next_run_at"])+ assert retry_at.timestamp() - now.timestamp() == unreachable_retry.RETRY_DELAYS_SECONDS[0]diff --git a/tests/cron/test_misfire_catchup.py b/tests/cron/test_misfire_catchup.pyindex dd2659bc0e0..a786b6075ca 100644--- a/tests/cron/test_misfire_catchup.py+++ b/tests/cron/test_misfire_catchup.py@@ -8,8 +8,7 @@ gateway housekeeping, claims and fires those jobs after a grace window."""import threading-from datetime import datetime, timedelta, timezone-from zoneinfo import ZoneInfo+from datetime import timedeltaimport pytest@@ -67,27 +66,6 @@ def _park_in_past(job_id, minutes):class TestFireOverdueJobs:- def test_future_fold_one_slot_is_not_overdue_in_fold_zero(self, tmp_cron_dir, monkeypatch):- """A repeated-hour slot stays future in the external-provider backstop too."""- import hermes_time-- monkeypatch.setenv("HERMES_TIMEZONE", "America/New_York")- hermes_time.reset_cache()- try:- zone = ZoneInfo("America/New_York")- now = datetime(2026, 11, 1, 5, 40, tzinfo=timezone.utc).astimezone(zone)- next_run = datetime(2026, 11, 1, 6, 0, tzinfo=timezone.utc).astimezone(zone)- monkeypatch.setattr("cron.jobs._hermes_now", lambda: now)- create_job(prompt="p", schedule="every 1h")- rows = load_jobs()- rows[0]["next_run_at"] = next_run.isoformat()- save_jobs(rows)-- assert now.fold == 0 and next_run.fold == 1- assert fire_overdue_jobs(RecordingProvider(), now=now) == 0- finally:- hermes_time.reset_cache()-def test_noop_for_builtin_provider(self, tmp_cron_dir):"""The in-process ticker self-heals past-due jobs — the sweep mustnever double-dispatch under it."""