from __future__ import annotations

from pathlib import Path

import pytest

from jarvis_finance.config.settings import load_settings


def test_runtime_default_outside_repo(tmp_path: Path) -> None:
    repo = tmp_path / "repo"
    repo.mkdir()
    (repo / "pyproject.toml").write_text("[project]\nname='demo'\n")
    settings = load_settings(repo_root=repo, environ={})
    assert "jarvis_runtime/finance-system" in settings.runtime_paths.base_dir.as_posix()
    assert not settings.runtime_paths.base_dir.as_posix().startswith(repo.as_posix())


def test_runtime_inside_repo_is_blocked(tmp_path: Path) -> None:
    repo = tmp_path / "repo"
    repo.mkdir()
    (repo / "pyproject.toml").write_text("[project]\nname='demo'\n")
    with pytest.raises(ValueError, match="outside the Git repository"):
        load_settings(repo_root=repo, environ={"JARVIS_FINANCE_RUNTIME_DIR": str(repo / "runtime")})
