Skip to content

Commit fbd752b

Browse files
0xNykteknium1
authored andcommitted
test(cron): add cross-timezone naive timestamp regression
Cherry-picked from PR #1308 by 0xNyk. Adds an end-to-end regression test covering a Hermes timezone far behind system local time (Pacific/Midway, UTC-11) to ensure legacy naive cron timestamps are still recognized as due under large timezone mismatches.
1 parent 6d2cfc2 commit fbd752b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/test_timezone.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,34 @@ def test_ensure_aware_due_job_not_skipped_when_system_ahead(self, tmp_path, monk
328328
"Overdue job was skipped — _ensure_aware likely shifted absolute time"
329329
)
330330

331+
def test_get_due_jobs_naive_cross_timezone(self, tmp_path, monkeypatch):
332+
"""Naive past timestamps must be detected as due even when Hermes tz
333+
is behind system local tz — the scenario that triggered #806."""
334+
import cron.jobs as jobs_module
335+
monkeypatch.setattr(jobs_module, "CRON_DIR", tmp_path / "cron")
336+
monkeypatch.setattr(jobs_module, "JOBS_FILE", tmp_path / "cron" / "jobs.json")
337+
monkeypatch.setattr(jobs_module, "OUTPUT_DIR", tmp_path / "cron" / "output")
338+
339+
# Use a Hermes timezone far behind UTC so that the numeric wall time
340+
# of the naive timestamp exceeds _hermes_now's wall time — this would
341+
# have caused a false "not due" with the old replace(tzinfo=...) approach.
342+
os.environ["HERMES_TIMEZONE"] = "Pacific/Midway" # UTC-11
343+
hermes_time.reset_cache()
344+
345+
from cron.jobs import create_job, load_jobs, save_jobs, get_due_jobs
346+
create_job(prompt="Cross-tz job", schedule="every 1h")
347+
jobs = load_jobs()
348+
349+
# Force a naive past timestamp (system-local wall time, 10 min ago)
350+
naive_past = (datetime.now() - timedelta(minutes=10)).isoformat()
351+
jobs[0]["next_run_at"] = naive_past
352+
save_jobs(jobs)
353+
354+
due = get_due_jobs()
355+
assert len(due) == 1, (
356+
"Naive past timestamp should be due regardless of Hermes timezone"
357+
)
358+
331359
def test_create_job_stores_tz_aware_timestamps(self, tmp_path, monkeypatch):
332360
"""New jobs store timezone-aware created_at and next_run_at."""
333361
import cron.jobs as jobs_module

0 commit comments

Comments
 (0)