vibe/tests/core/test_environment_layer.py
Guillaume LE GOFF cafb6d4147
v2.15.0 (#773)
Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com>
Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai>
Co-authored-by: Maxime Dolores <maxime.dolores@ext.mistral.ai>
Co-authored-by: Nelson PROIA <144663685+Nelson-PROIA@users.noreply.github.com>
Co-authored-by: Paul VEZIA <166131032+le-codeur-rapide@users.noreply.github.com>
Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai>
Co-authored-by: Quentin <quentin.torroba@mistral.ai>
Co-authored-by: Val <102326092+vdeva@users.noreply.github.com>
Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
2026-06-12 13:16:04 +02:00

68 lines
2.1 KiB
Python

from __future__ import annotations
import os
from unittest.mock import patch
import pytest
from vibe.core.config.layers.environment import EnvironmentLayer
from vibe.core.config.vibe_schema import VibeConfigSchema
@pytest.mark.asyncio
async def test_reads_env_vars() -> None:
env = {
"MISTRAL_API_KEY": "test-key",
"VIBE_ACTIVE_MODEL": "mistral-large",
"VIBE_VIM_KEYBINDINGS": "true",
"VIBE_ENABLE_TELEMETRY": "0",
"VIBE_UNKNOWN_VAR": "ignored",
"VIBE_SESSION_LOGGING__ENABLED": "false",
"VIBE_SESSION_LOGGING__SESSION_PREFIX": "mysession",
"VIBE_API_TIMEOUT": ".12",
}
with patch.dict(os.environ, env, clear=True):
layer = EnvironmentLayer(schema=VibeConfigSchema)
data = await layer.load()
assert data.model_dump() == {
"active_model": "mistral-large",
"vim_keybindings": True,
"enable_telemetry": False,
"session_logging": {"enabled": False, "session_prefix": "mysession"},
"api_timeout": 0.12,
}
assert layer.name == "environment"
@pytest.mark.asyncio
async def test_no_vars_set_returns_empty() -> None:
with patch.dict(os.environ, {}, clear=True):
data = await EnvironmentLayer(schema=VibeConfigSchema).load()
assert data.model_dump() == {}
@pytest.mark.asyncio
async def test_fingerprint_changes_when_env_changes() -> None:
with patch.dict(os.environ, {"VIBE_ACTIVE_MODEL": "first-model"}, clear=True):
layer = EnvironmentLayer(schema=VibeConfigSchema)
data1 = await layer.load()
fp1 = layer.fingerprint
os.environ["VIBE_ACTIVE_MODEL"] = "second-model"
data2 = await layer.load(force=True)
fp2 = layer.fingerprint
assert data1.model_dump() == {"active_model": "first-model"}
assert data2.model_dump() == {"active_model": "second-model"}
assert isinstance(fp1, str)
assert fp1
assert isinstance(fp2, str)
assert fp2
assert fp1 != fp2
@pytest.mark.asyncio
async def test_always_trusted() -> None:
assert await EnvironmentLayer(schema=VibeConfigSchema).resolve_trust() is True