"""Tests for config.py data directory resolution."""

from __future__ import annotations

from pathlib import Path
from unittest.mock import patch

from syke.config import PROJECT_ROOT, _default_data_dir, _is_source_install


def test_is_source_install_true():
    """Returns True when pyproject.toml exists at PROJECT_ROOT (i.e., this repo)."""
    assert _is_source_install() is True


def test_env_var_overrides_everything(tmp_path, monkeypatch):
    """SYKE_DATA_DIR env var takes priority over all other logic."""
    target = tmp_path / "custom"
    monkeypatch.setenv("SYKE_DATA_DIR", str(target))
    result = _default_data_dir()
    assert result == target.resolve()


def test_source_install_returns_project_data(monkeypatch):
    """Source install (pyproject.toml present) returns PROJECT_ROOT/data."""
    monkeypatch.delenv("SYKE_DATA_DIR", raising=False)
    # _is_source_install should be True in this repo
    result = _default_data_dir()
    assert result == PROJECT_ROOT / "data"


def test_pip_install_returns_home_syke_data(monkeypatch):
    """Pip install (no pyproject.toml) returns ~/.syke/data."""
    monkeypatch.delenv("SYKE_DATA_DIR", raising=False)
    with patch("syke.config._is_source_install", return_value=False):
        result = _default_data_dir()
    assert result == Path.home() / ".syke" / "data"
