Co-authored-by: Clément Drouin <clement.drouin@mistral.ai>
Co-authored-by: Laure Hugo <201583486+laure0303@users.noreply.github.com>
Co-authored-by: Paul VEZIA <166131032+le-codeur-rapide@users.noreply.github.com>
Co-authored-by: Peter Evers <peter.evers@mistral.ai>
Co-authored-by: Jules YZERD <newtonlormont@gmail.com>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Mathias Gesbert 2026-06-30 15:03:21 +02:00 committed by GitHub
parent d50704e694
commit 4e495f658d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
130 changed files with 1042 additions and 552 deletions

View file

@ -1,11 +1,14 @@
from __future__ import annotations
from pathlib import Path
import tomllib
import pytest
from vibe.core.config.fingerprint import create_file_fingerprint
from vibe.core.config.layer import UntrustedLayerError
from vibe.core.config.layers.project import ProjectConfigLayer
from vibe.core.config.patch import AddOperationPatch, ConfigPatch, ReplaceOperationPatch
from vibe.core.config.types import MISSING_BACKING_STORE_DATA_FINGERPRINT
from vibe.core.paths._vibe_home import GlobalPath
from vibe.core.trusted_folders import trusted_folders_manager
@ -300,3 +303,53 @@ async def test_walk_stops_at_vibe_home_parent(
layer = ProjectConfigLayer(path=subdir)
data = await layer.load()
assert data.model_extra == {}
@pytest.mark.asyncio
async def test_apply_persists_to_discovered_file(tmp_working_directory: Path) -> None:
trusted_folders_manager.add_trusted(tmp_working_directory)
config_path = tmp_working_directory / ".vibe" / "config.toml"
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.write_text('active_model = "old"\n')
layer = ProjectConfigLayer(path=tmp_working_directory)
await layer.load()
fingerprint = layer.fingerprint
assert isinstance(fingerprint, str)
await layer.apply(
ConfigPatch(
ReplaceOperationPatch(path="/active_model", value="new"),
AddOperationPatch(path="/default_agent", value="plan"),
fingerprint=fingerprint,
)
)
with config_path.open("rb") as file:
assert tomllib.load(file) == {"active_model": "new", "default_agent": "plan"}
assert layer.fingerprint == create_file_fingerprint(file)
@pytest.mark.asyncio
async def test_apply_creates_file_when_none_discovered(
tmp_working_directory: Path,
) -> None:
# No .vibe/config.toml exists; the layer is still trusted (nothing to distrust).
layer = ProjectConfigLayer(path=tmp_working_directory)
await layer.load()
assert layer.fingerprint == MISSING_BACKING_STORE_DATA_FINGERPRINT
await layer.apply(
ConfigPatch(
AddOperationPatch(path="/active_model", value="created"),
fingerprint=MISSING_BACKING_STORE_DATA_FINGERPRINT,
)
)
created_path = tmp_working_directory / ".vibe" / "config.toml"
with created_path.open("rb") as file:
assert tomllib.load(file) == {"active_model": "created"}
assert layer.fingerprint == create_file_fingerprint(file)
assert layer.is_file_discovered
assert layer.config_file_path == created_path