from __future__ import annotations

from datetime import date
import os
import sys
from pathlib import Path

import pytest

ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "src"
os.environ["JARVIS_FINANCE_WRITE_MODE"] = "test"
if str(SRC) not in sys.path:
    sys.path.insert(0, str(SRC))


@pytest.fixture
def budget_reference_date(monkeypatch: pytest.MonkeyPatch) -> date:
    """Keep budget tests anchored to their synthetic May 2026 ledger."""

    from jarvis_finance.services import budget_overview

    class ReferenceDate(date):
        @classmethod
        def today(cls) -> ReferenceDate:
            return cls(2026, 5, 31)

    monkeypatch.setattr(budget_overview, "date", ReferenceDate)
    return ReferenceDate.today()
