"""Production dispatcher invocation regression."""

from __future__ import annotations

from datetime import datetime
from pathlib import Path
from zoneinfo import ZoneInfo

import pytest

from tests.gateway._nutrition_weekly_dispatcher_cases import dispatcher_fixture


@pytest.mark.asyncio
async def test_authorized_tick_dispatches_enabled_weekly_operations_before_generic_work(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
) -> None:
    fixture = dispatcher_fixture(tmp_path, "cutoff")
    fixture.install_due(monkeypatch)

    result = await fixture.host.run_authorized(
        datetime(2026, 8, 17, 23, tzinfo=ZoneInfo("Asia/Seoul"))
    )

    assert result.success is True
    assert len(fixture.reminder.store.read()) == 1
    assert len(fixture.provider.calls) == 1
