from __future__ import annotations

import os
import tempfile
from pathlib import Path

import pytest


_TEST_HOME = Path(tempfile.mkdtemp(prefix="recoil-api-tests-home-"))
os.environ["HOME"] = str(_TEST_HOME)


@pytest.fixture(autouse=True)
def _hermetic_proposals_root(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
    """Keep proposal-route tests from writing to ~/.recoil/proposals."""
    from recoil.api import proposals_routes

    monkeypatch.setattr(proposals_routes, "_PROPOSALS_ROOT", tmp_path / "proposals")
