Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai>
Co-authored-by: Guillaume LE GOFF <guillaume.lgf@gmail.com>
Co-authored-by: Hdandria <henri.dandria@mistral.ai>
Co-authored-by: Ivana Dunisijevic <ivana.dunisijevic@mistral.ai>
Co-authored-by: Jean Burellier <sheplu@users.noreply.github.com>
Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai>
Co-authored-by: Mert Unsal <mert.unsal@mistral.ai>
Co-authored-by: Michel Thomazo <51709227+michelTho@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: Val <102326092+vdeva@users.noreply.github.com>
Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com>
Co-authored-by: renovate-mistral[bot] <253709520+renovate-mistral[bot]@users.noreply.github.com>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Clément Drouin 2026-06-19 11:01:24 +02:00 committed by GitHub
parent 564a14365e
commit 6bedf271ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
223 changed files with 10533 additions and 6947 deletions

View file

@ -4,10 +4,12 @@ import os
from pathlib import Path
from dotenv import dotenv_values
import keyring
from keyring.errors import KeyringError
import pytest
from vibe.acp.acp_agent_loop import VibeAcpAgentLoop
from vibe.acp.exceptions import InvalidRequestError
from vibe.acp.exceptions import InternalError, InvalidRequestError
from vibe.core.config import (
DEFAULT_MISTRAL_API_ENV_KEY,
ProviderConfig,
@ -18,6 +20,15 @@ from vibe.setup.auth import AuthStateKind
from vibe.setup.onboarding.context import OnboardingContext
@pytest.fixture(autouse=True)
def disable_keyring(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(keyring, "get_password", lambda service, username: None)
monkeypatch.setattr(
keyring, "set_password", lambda service, username, password: None
)
monkeypatch.setattr(keyring, "delete_password", lambda service, username: None)
def build_mistral_provider(
*, api_key_env_var: str = DEFAULT_MISTRAL_API_ENV_KEY
) -> ProviderConfig:
@ -127,7 +138,7 @@ class TestACPAuthStatus:
}
@pytest.mark.asyncio
async def test_returns_combined_source_when_process_env_existed_before_dotenv(
async def test_returns_process_env_when_process_env_existed_before_dotenv(
self, config_dir: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv(DEFAULT_MISTRAL_API_ENV_KEY, "process-key")
@ -138,7 +149,25 @@ class TestACPAuthStatus:
assert response == {
"authenticated": True,
"authState": AuthStateKind.VIBE_HOME_ENV_FILE_OVERRIDES_PROCESS_ENV.value,
"authState": AuthStateKind.PROCESS_ENV.value,
"signOutAvailable": False,
}
@pytest.mark.asyncio
async def test_returns_keyring_when_key_only_exists_in_keyring(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
monkeypatch.setattr(
keyring, "get_password", lambda service, username: "keyring-key"
)
acp_agent_loop = build_acp_agent_loop(build_mistral_provider())
response = await acp_agent_loop.ext_method("auth/status", {})
assert response == {
"authenticated": True,
"authState": AuthStateKind.OS_KEYRING.value,
"signOutAvailable": True,
}
@ -213,23 +242,58 @@ class TestACPAuthSignOut:
assert os.environ[DEFAULT_MISTRAL_API_ENV_KEY] == "process-key"
@pytest.mark.asyncio
async def test_removes_dotenv_key_and_restores_process_env_key(
async def test_refuses_dotenv_key_when_process_env_key_exists(
self, config_dir: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv(DEFAULT_MISTRAL_API_ENV_KEY, "process-key")
write_env_file(config_dir, f"{DEFAULT_MISTRAL_API_ENV_KEY}=file-key\n")
acp_agent_loop = build_acp_agent_loop(build_mistral_provider())
with pytest.raises(InvalidRequestError, match=AuthStateKind.PROCESS_ENV.value):
await acp_agent_loop.ext_method("auth/signOut", {})
assert (
dotenv_values(config_dir / ".env")[DEFAULT_MISTRAL_API_ENV_KEY]
== "file-key"
)
assert os.environ[DEFAULT_MISTRAL_API_ENV_KEY] == "process-key"
@pytest.mark.asyncio
async def test_removes_keyring_key(self, monkeypatch: pytest.MonkeyPatch) -> None:
deleted: list[str] = []
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
monkeypatch.setattr(
keyring, "get_password", lambda service, username: "keyring-key"
)
monkeypatch.setattr(
keyring,
"delete_password",
lambda service, username: deleted.append(username),
)
acp_agent_loop = build_acp_agent_loop(build_mistral_provider())
response = await acp_agent_loop.ext_method("auth/signOut", {})
assert response == {}
assert DEFAULT_MISTRAL_API_ENV_KEY not in dotenv_values(config_dir / ".env")
assert os.environ[DEFAULT_MISTRAL_API_ENV_KEY] == "process-key"
assert await acp_agent_loop.ext_method("auth/status", {}) == {
"authenticated": True,
"authState": AuthStateKind.PROCESS_ENV.value,
"signOutAvailable": False,
}
assert deleted == [DEFAULT_MISTRAL_API_ENV_KEY]
@pytest.mark.asyncio
async def test_surfaces_internal_error_when_keyring_delete_fails(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
monkeypatch.setattr(
keyring, "get_password", lambda service, username: "keyring-key"
)
def _failed(service: str, username: str) -> None:
raise KeyringError("delete failed")
monkeypatch.setattr(keyring, "delete_password", _failed)
acp_agent_loop = build_acp_agent_loop(build_mistral_provider())
with pytest.raises(InternalError, match="Failed to sign out"):
await acp_agent_loop.ext_method("auth/signOut", {})
@pytest.mark.asyncio
async def test_refuses_unsupported_provider_key(