"""Tests for the APScheduler bootstrap helper."""

from __future__ import annotations

import pytest

from cerbero_bite.runtime.scheduler import JobSpec, build_scheduler


async def _noop() -> None:
    return None


def test_build_scheduler_registers_all_jobs() -> None:
    specs = [
        JobSpec(name="entry", cron="0 14 * * MON", coro_factory=_noop),
        JobSpec(name="monitor", cron="0 2,14 * * *", coro_factory=_noop),
        JobSpec(name="health", cron="*/5 * * * *", coro_factory=_noop),
    ]
    sched = build_scheduler(specs)
    job_ids = {j.id for j in sched.get_jobs()}
    assert job_ids == {"entry", "monitor", "health"}


def test_build_scheduler_rejects_malformed_cron() -> None:
    with pytest.raises(ValueError, match="cron must have 5 fields"):
        build_scheduler([JobSpec(name="x", cron="0 14 * *", coro_factory=_noop)])
