vibe/tests/core/test_config_resolution.py
Mathias Gesbert e9428bce23
v2.4.1 (#475)
Co-authored-by: Quentin Torroba <quentin.torroba@mistral.ai>
Co-authored-by: Clement Sirieix <clem.sirieix@gmail.com>
Co-authored-by: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
2026-03-10 16:07:18 +01:00

82 lines
3 KiB
Python

from __future__ import annotations
from pathlib import Path
import pytest
from vibe.core.config.harness_files import (
HarnessFilesManager,
init_harness_files_manager,
reset_harness_files_manager,
)
from vibe.core.paths import VIBE_HOME
from vibe.core.trusted_folders import trusted_folders_manager
class TestResolveConfigFile:
def test_resolves_local_config_when_exists_and_folder_is_trusted(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.chdir(tmp_path)
local_config_dir = tmp_path / ".vibe"
local_config_dir.mkdir()
local_config = local_config_dir / "config.toml"
local_config.write_text('active_model = "test"', encoding="utf-8")
monkeypatch.setattr(trusted_folders_manager, "is_trusted", lambda _: True)
reset_harness_files_manager()
init_harness_files_manager("user", "project")
from vibe.core.config.harness_files import get_harness_files_manager
mgr = get_harness_files_manager()
resolved = mgr.config_file
assert resolved is not None
assert resolved == local_config
assert resolved.is_file()
assert resolved.read_text(encoding="utf-8") == 'active_model = "test"'
def test_resolves_global_config_when_folder_is_not_trusted(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.chdir(tmp_path)
local_config_dir = tmp_path / ".vibe"
local_config_dir.mkdir()
local_config = local_config_dir / "config.toml"
local_config.write_text('active_model = "test"', encoding="utf-8")
reset_harness_files_manager()
init_harness_files_manager("user", "project")
from vibe.core.config.harness_files import get_harness_files_manager
mgr = get_harness_files_manager()
assert mgr.config_file == VIBE_HOME.path / "config.toml"
def test_falls_back_to_global_config_when_local_missing(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.chdir(tmp_path)
# Ensure no local config exists
assert not (tmp_path / ".vibe" / "config.toml").exists()
reset_harness_files_manager()
init_harness_files_manager("user", "project")
from vibe.core.config.harness_files import get_harness_files_manager
mgr = get_harness_files_manager()
assert mgr.config_file == VIBE_HOME.path / "config.toml"
def test_respects_vibe_home_env_var(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
assert VIBE_HOME.path != tmp_path
monkeypatch.setenv("VIBE_HOME", str(tmp_path))
assert VIBE_HOME.path == tmp_path
def test_returns_none_when_no_sources(self) -> None:
mgr = HarnessFilesManager(sources=())
assert mgr.config_file is None
def test_user_only_returns_global_config(self) -> None:
mgr = HarnessFilesManager(sources=("user",))
assert mgr.config_file == VIBE_HOME.path / "config.toml"