Co-authored-by: Clément Drouin <clement.drouin@mistral.ai>
Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai>
Co-authored-by: Guillaume LE GOFF <guillaume.lgf@gmail.com>
Co-authored-by: Mert Unsal <mertunsal1905@gmail.com>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
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: maximevoisin-pm <maxime.voisin@mistral.ai>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Mathias Gesbert 2026-05-27 17:10:40 +02:00 committed by GitHub
parent adb1ca74ce
commit cf3f4ca58f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
143 changed files with 3457 additions and 1351 deletions

View file

@ -101,22 +101,15 @@ async def _terminate_process(proc: asyncio.subprocess.Process) -> None:
await proc.wait()
def _build_env(
vibe_home_dir: Path, *, include_api_key: bool, enable_browser_sign_in: bool = False
) -> dict[str, str]:
def _build_env(vibe_home_dir: Path, *, include_api_key: bool) -> dict[str, str]:
env = os.environ.copy()
env["PYTHONUNBUFFERED"] = "1"
env["VIBE_HOME"] = str(vibe_home_dir)
vibe_home_dir.mkdir(parents=True, exist_ok=True)
config_lines = ["enable_telemetry = false"]
if enable_browser_sign_in:
config_lines.append("enable_experimental_browser_sign_in = true")
config_file = vibe_home_dir / "config.toml"
if not config_file.exists():
config_file.write_text("\n".join(config_lines) + "\n")
elif enable_browser_sign_in:
config_file.write_text(config_file.read_text() + config_lines[-1] + "\n")
config_file.write_text("enable_telemetry = false\n")
if include_api_key:
env["MISTRAL_API_KEY"] = "mock"
@ -144,15 +137,10 @@ async def _connect_and_initialize(
*,
vibe_home_dir: Path,
include_api_key: bool,
enable_browser_sign_in: bool = False,
terminal_auth: bool = False,
delegated_browser_auth: bool = False,
) -> tuple[asyncio.subprocess.Process, Any, Any]:
env = _build_env(
vibe_home_dir,
include_api_key=include_api_key,
enable_browser_sign_in=enable_browser_sign_in,
)
env = _build_env(vibe_home_dir, include_api_key=include_api_key)
proc = await _spawn_vibe_acp(env)
try:
@ -219,7 +207,7 @@ async def test_vibe_acp_bootstraps_default_files(vibe_home_dir: Path) -> None:
@pytest.mark.asyncio
async def test_vibe_acp_initialize_exposes_browser_auth(vibe_home_dir: Path) -> None:
proc, initialize_response, _conn = await _connect_and_initialize(
vibe_home_dir=vibe_home_dir, include_api_key=True, enable_browser_sign_in=True
vibe_home_dir=vibe_home_dir, include_api_key=True
)
try:
@ -238,10 +226,7 @@ async def test_vibe_acp_initialize_exposes_delegated_browser_auth_when_supported
vibe_home_dir: Path,
) -> None:
proc, initialize_response, _conn = await _connect_and_initialize(
vibe_home_dir=vibe_home_dir,
include_api_key=True,
enable_browser_sign_in=True,
delegated_browser_auth=True,
vibe_home_dir=vibe_home_dir, include_api_key=True, delegated_browser_auth=True
)
try:
@ -266,10 +251,7 @@ async def test_vibe_acp_initialize_exposes_terminal_auth_when_supported(
vibe_home_dir: Path,
) -> None:
proc, initialize_response, _conn = await _connect_and_initialize(
vibe_home_dir=vibe_home_dir,
include_api_key=True,
enable_browser_sign_in=True,
terminal_auth=True,
vibe_home_dir=vibe_home_dir, include_api_key=True, terminal_auth=True
)
try:

View file

@ -0,0 +1,270 @@
from __future__ import annotations
import os
from pathlib import Path
from dotenv import dotenv_values
import pytest
from vibe.acp.acp_agent_loop import VibeAcpAgentLoop
from vibe.acp.exceptions import InvalidRequestError
from vibe.core.config import (
DEFAULT_MISTRAL_API_ENV_KEY,
ProviderConfig,
load_dotenv_values,
)
from vibe.core.types import Backend
from vibe.setup.auth import AuthStateKind
from vibe.setup.onboarding.context import OnboardingContext
def build_mistral_provider(
*, api_key_env_var: str = DEFAULT_MISTRAL_API_ENV_KEY
) -> ProviderConfig:
return ProviderConfig(
name="mistral",
api_base="https://api.mistral.ai/v1",
api_key_env_var=api_key_env_var,
browser_auth_base_url="https://console.mistral.ai",
browser_auth_api_base_url="https://console.mistral.ai/api",
backend=Backend.MISTRAL,
)
def build_generic_provider(
*, name: str = "custom", api_key_env_var: str = "CUSTOM_API_KEY"
) -> ProviderConfig:
return ProviderConfig(
name=name,
api_base="https://custom.example/v1",
api_key_env_var=api_key_env_var,
backend=Backend.GENERIC,
)
def build_acp_agent_loop(
provider: ProviderConfig,
*,
environ_before_dotenv_load: dict[str, str] | None = None,
) -> VibeAcpAgentLoop:
return VibeAcpAgentLoop(
onboarding_context_loader=lambda: OnboardingContext(provider=provider),
environ_before_dotenv_load=environ_before_dotenv_load,
)
def write_env_file(config_dir: Path, content: str) -> None:
(config_dir / ".env").write_text(content, encoding="utf-8")
class TestACPAuthStatus:
@pytest.mark.asyncio
async def test_returns_signed_out_when_no_key_source(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
acp_agent_loop = build_acp_agent_loop(build_mistral_provider())
response = await acp_agent_loop.ext_method("auth/status", {})
assert response == {
"authenticated": False,
"authState": AuthStateKind.SIGNED_OUT.value,
"signOutAvailable": False,
}
@pytest.mark.asyncio
async def test_returns_sign_out_available_for_default_dotenv_key(
self, config_dir: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
write_env_file(config_dir, f"{DEFAULT_MISTRAL_API_ENV_KEY}=file-key\n")
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.VIBE_HOME_ENV_FILE.value,
"signOutAvailable": True,
}
@pytest.mark.asyncio
async def test_uses_startup_env_snapshot_for_dotenv_key(
self, config_dir: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
write_env_file(config_dir, f"{DEFAULT_MISTRAL_API_ENV_KEY}=file-key\n")
environ_before_dotenv_load = os.environ.copy()
load_dotenv_values()
acp_agent_loop = build_acp_agent_loop(
build_mistral_provider(),
environ_before_dotenv_load=environ_before_dotenv_load,
)
await acp_agent_loop.ext_method("auth/status", {})
response = await acp_agent_loop.ext_method("auth/status", {})
assert response == {
"authenticated": True,
"authState": AuthStateKind.VIBE_HOME_ENV_FILE.value,
"signOutAvailable": True,
}
@pytest.mark.asyncio
async def test_returns_process_env_when_key_only_exists_before_dotenv(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv(DEFAULT_MISTRAL_API_ENV_KEY, "process-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.PROCESS_ENV.value,
"signOutAvailable": False,
}
@pytest.mark.asyncio
async def test_returns_combined_source_when_process_env_existed_before_dotenv(
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())
response = await acp_agent_loop.ext_method("auth/status", {})
assert response == {
"authenticated": True,
"authState": AuthStateKind.VIBE_HOME_ENV_FILE_OVERRIDES_PROCESS_ENV.value,
"signOutAvailable": False,
}
@pytest.mark.asyncio
async def test_returns_auth_not_required_for_provider_without_env_key(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
acp_agent_loop = build_acp_agent_loop(
build_generic_provider(name="llamacpp", api_key_env_var="")
)
response = await acp_agent_loop.ext_method("auth/status", {})
assert response == {
"authenticated": True,
"authState": AuthStateKind.AUTH_NOT_REQUIRED.value,
"signOutAvailable": False,
}
@pytest.mark.asyncio
async def test_returns_unsupported_provider_for_custom_key_setup(
self, config_dir: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv("CUSTOM_API_KEY", raising=False)
write_env_file(config_dir, "CUSTOM_API_KEY=file-key\n")
acp_agent_loop = build_acp_agent_loop(build_generic_provider())
response = await acp_agent_loop.ext_method("auth/status", {})
assert response == {
"authenticated": True,
"authState": AuthStateKind.UNSUPPORTED_PROVIDER.value,
"signOutAvailable": False,
}
class TestACPAuthSignOut:
@pytest.mark.asyncio
async def test_removes_default_dotenv_key(
self, config_dir: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
write_env_file(
config_dir, f"{DEFAULT_MISTRAL_API_ENV_KEY}=file-key\nOTHER_KEY=other\n"
)
acp_agent_loop = build_acp_agent_loop(build_mistral_provider())
response = await acp_agent_loop.ext_method("auth/signOut", {})
env_values = dotenv_values(config_dir / ".env")
assert response == {}
assert DEFAULT_MISTRAL_API_ENV_KEY not in env_values
assert env_values["OTHER_KEY"] == "other"
assert DEFAULT_MISTRAL_API_ENV_KEY not in os.environ
assert await acp_agent_loop.ext_method("auth/status", {}) == {
"authenticated": False,
"authState": AuthStateKind.SIGNED_OUT.value,
"signOutAvailable": False,
}
@pytest.mark.asyncio
async def test_refuses_process_env_key(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv(DEFAULT_MISTRAL_API_ENV_KEY, "process-key")
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 os.environ[DEFAULT_MISTRAL_API_ENV_KEY] == "process-key"
@pytest.mark.asyncio
async def test_refuses_combined_dotenv_and_process_env_key(
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.VIBE_HOME_ENV_FILE_OVERRIDES_PROCESS_ENV.value,
):
await acp_agent_loop.ext_method("auth/signOut", {})
assert dotenv_values(config_dir / ".env")[DEFAULT_MISTRAL_API_ENV_KEY] == (
"file-key"
)
@pytest.mark.asyncio
async def test_refuses_unsupported_provider_key(
self, config_dir: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv("CUSTOM_API_KEY", raising=False)
write_env_file(config_dir, "CUSTOM_API_KEY=file-key\n")
acp_agent_loop = build_acp_agent_loop(build_generic_provider())
with pytest.raises(
InvalidRequestError, match=AuthStateKind.UNSUPPORTED_PROVIDER.value
):
await acp_agent_loop.ext_method("auth/signOut", {})
assert dotenv_values(config_dir / ".env")["CUSTOM_API_KEY"] == "file-key"
@pytest.mark.asyncio
async def test_refuses_auth_not_required(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
acp_agent_loop = build_acp_agent_loop(
build_generic_provider(name="llamacpp", api_key_env_var="")
)
with pytest.raises(
InvalidRequestError, match=AuthStateKind.AUTH_NOT_REQUIRED.value
):
await acp_agent_loop.ext_method("auth/signOut", {})
@pytest.mark.asyncio
async def test_refuses_signed_out_state(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv(DEFAULT_MISTRAL_API_ENV_KEY, raising=False)
acp_agent_loop = build_acp_agent_loop(build_mistral_provider())
with pytest.raises(InvalidRequestError, match=AuthStateKind.SIGNED_OUT.value):
await acp_agent_loop.ext_method("auth/signOut", {})

View file

@ -55,17 +55,11 @@ def build_unsupported_provider() -> ProviderConfig:
class MutableOnboardingContextLoader:
def __init__(
self, provider: ProviderConfig, *, enable_browser_sign_in: bool = True
) -> None:
def __init__(self, provider: ProviderConfig) -> None:
self.provider = provider
self.enable_browser_sign_in = enable_browser_sign_in
def __call__(self) -> OnboardingContext:
return OnboardingContext(
provider=self.provider,
enable_experimental_browser_sign_in=self.enable_browser_sign_in,
)
return OnboardingContext(provider=self.provider)
class FakeBrowserSignInService:
@ -122,16 +116,13 @@ class InMemoryApiKeyPersister:
def build_acp_agent(
*,
provider: ProviderConfig | None = None,
enable_browser_sign_in: bool = True,
browser_sign_in: FakeBrowserSignInService | None = None,
api_key_persister: InMemoryApiKeyPersister | None = None,
) -> tuple[VibeAcpAgentLoop, MutableOnboardingContextLoader, InMemoryApiKeyPersister]:
provider = provider or build_mistral_provider()
browser_sign_in = browser_sign_in or FakeBrowserSignInService()
api_key_persister = api_key_persister or InMemoryApiKeyPersister()
context_loader = MutableOnboardingContextLoader(
provider, enable_browser_sign_in=enable_browser_sign_in
)
context_loader = MutableOnboardingContextLoader(provider)
return (
VibeAcpAgentLoop(
@ -213,42 +204,6 @@ class TestACPAuthenticate:
):
await acp_agent_loop.authenticate("browser-auth")
@pytest.mark.asyncio
async def test_authenticate_rejects_browser_sign_in_when_flag_disabled(
self,
) -> None:
browser_sign_in = FakeBrowserSignInService(api_key="api-key")
acp_agent_loop, _, api_key_persister = build_acp_agent(
browser_sign_in=browser_sign_in, enable_browser_sign_in=False
)
with pytest.raises(
InvalidRequestError,
match="Browser sign-in is not available for the configured provider.",
):
await acp_agent_loop.authenticate("browser-auth")
assert api_key_persister.saved == []
assert browser_sign_in.close_count == 0
@pytest.mark.asyncio
async def test_authenticate_rejects_delegated_browser_sign_in_when_flag_disabled(
self,
) -> None:
browser_sign_in = FakeBrowserSignInService()
acp_agent_loop, _, api_key_persister = build_acp_agent(
browser_sign_in=browser_sign_in, enable_browser_sign_in=False
)
with pytest.raises(
InvalidRequestError,
match="Browser sign-in is not available for the configured provider.",
):
await acp_agent_loop.authenticate("browser-auth-delegated")
assert api_key_persister.saved == []
assert browser_sign_in.close_count == 0
@pytest.mark.asyncio
async def test_authenticate_surfaces_start_failures(self) -> None:
browser_sign_in = FakeBrowserSignInService(
@ -318,7 +273,7 @@ class TestACPAuthenticate:
assert api_key_persister.saved == [(start_provider, "api-key")]
@pytest.mark.asyncio
async def test_authenticate_delegated_completion_allows_flag_disabled_after_start(
async def test_authenticate_delegated_completion_uses_started_provider(
self,
) -> None:
provider = build_mistral_provider()
@ -330,7 +285,7 @@ class TestACPAuthenticate:
attempt_id = require_auth_meta(start_response, "browser-auth-delegated")[
"attemptId"
]
context_loader.enable_browser_sign_in = False
context_loader.provider = build_unsupported_provider()
await acp_agent_loop.authenticate(
"browser-auth-delegated", action="complete", attemptId=attempt_id

View file

@ -35,13 +35,10 @@ def build_mistral_provider() -> ProviderConfig:
)
def build_acp_agent_loop(
*, provider: ProviderConfig | None = None, enable_browser_sign_in: bool = True
) -> VibeAcpAgentLoop:
def build_acp_agent_loop(*, provider: ProviderConfig | None = None) -> VibeAcpAgentLoop:
return VibeAcpAgentLoop(
onboarding_context_loader=lambda: OnboardingContext(
provider=provider or build_mistral_provider(),
enable_experimental_browser_sign_in=enable_browser_sign_in,
provider=provider or build_mistral_provider()
)
)
@ -65,7 +62,7 @@ class TestACPInitialize:
),
)
assert response.agent_info == Implementation(
name="@mistralai/mistral-vibe", title="Mistral Vibe", version="2.11.0"
name="@mistralai/mistral-vibe", title="Mistral Vibe", version="2.11.1"
)
assert response.auth_methods is not None
@ -97,7 +94,7 @@ class TestACPInitialize:
),
)
assert response.agent_info == Implementation(
name="@mistralai/mistral-vibe", title="Mistral Vibe", version="2.11.0"
name="@mistralai/mistral-vibe", title="Mistral Vibe", version="2.11.1"
)
assert response.auth_methods is not None
@ -143,16 +140,6 @@ class TestACPInitialize:
assert delegated_browser_auth_method.name == BROWSER_AUTH_NAME
assert delegated_browser_auth_method.description == BROWSER_AUTH_DESCRIPTION
@pytest.mark.asyncio
async def test_initialize_omits_browser_auth_when_experimental_flag_disabled(
self,
) -> None:
acp_agent_loop = build_acp_agent_loop(enable_browser_sign_in=False)
response = await acp_agent_loop.initialize(protocol_version=PROTOCOL_VERSION)
assert response.auth_methods == []
@pytest.mark.asyncio
async def test_initialize_omits_browser_auth_when_provider_unsupported(
self,