v2.18.0 (#843)
Co-authored-by: Clément Drouin <clement.drouin@mistral.ai> Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai> Co-authored-by: Cyprien <courtot.c@gmail.com> Co-authored-by: Guillaume LE GOFF <guillaume.lgf@gmail.com> Co-authored-by: Jean Burellier <sheplu@users.noreply.github.com> Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com> Co-authored-by: Mathias Gesbert <mathias.gesbert@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: Vincent G <10739306+VinceOPS@users.noreply.github.com> Co-authored-by: josephine-delas <57808586+josephine-delas@users.noreply.github.com> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
725d3a56ce
commit
e607ccbb00
242 changed files with 7372 additions and 1974 deletions
|
|
@ -8,6 +8,7 @@ from tests.conftest import build_test_vibe_config
|
|||
from vibe.core.config import MissingAPIKeyError, ProviderConfig, resolve_api_key
|
||||
from vibe.core.llm.backend.mistral import MistralBackend
|
||||
from vibe.core.types import Backend
|
||||
from vibe.core.utils.keyring import clear_api_key_keyring_cache
|
||||
|
||||
|
||||
def test_resolve_returns_env_value_without_consulting_keyring(
|
||||
|
|
@ -34,6 +35,40 @@ def test_resolve_falls_back_to_keyring_when_env_unset(
|
|||
assert resolve_api_key("CUSTOM_API_KEY") == "keyring-key"
|
||||
|
||||
|
||||
def test_resolve_caches_keyring_lookup_for_env_key(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
calls: list[tuple[str, str]] = []
|
||||
monkeypatch.delenv("CUSTOM_API_KEY", raising=False)
|
||||
|
||||
def _get_password(service: str, username: str) -> str:
|
||||
calls.append((service, username))
|
||||
return "keyring-key"
|
||||
|
||||
monkeypatch.setattr(keyring, "get_password", _get_password)
|
||||
|
||||
assert resolve_api_key("CUSTOM_API_KEY") == "keyring-key"
|
||||
assert resolve_api_key("CUSTOM_API_KEY") == "keyring-key"
|
||||
assert calls == [("ai.mistral.vibe", "CUSTOM_API_KEY")]
|
||||
|
||||
|
||||
def test_resolve_caches_empty_keyring_lookup_for_env_key(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
calls: list[tuple[str, str]] = []
|
||||
monkeypatch.delenv("CUSTOM_API_KEY", raising=False)
|
||||
|
||||
def _get_password(service: str, username: str) -> None:
|
||||
calls.append((service, username))
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(keyring, "get_password", _get_password)
|
||||
|
||||
assert resolve_api_key("CUSTOM_API_KEY") is None
|
||||
assert resolve_api_key("CUSTOM_API_KEY") is None
|
||||
assert calls == [("ai.mistral.vibe", "CUSTOM_API_KEY"), ("vibe", "CUSTOM_API_KEY")]
|
||||
|
||||
|
||||
def test_resolve_returns_none_when_env_unset_and_keyring_empty(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
|
|
@ -56,6 +91,24 @@ def test_resolve_returns_none_when_keyring_raises(
|
|||
assert resolve_api_key("CUSTOM_API_KEY") is None
|
||||
|
||||
|
||||
def test_resolve_does_not_cache_keyring_errors(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
calls = 0
|
||||
monkeypatch.delenv("CUSTOM_API_KEY", raising=False)
|
||||
|
||||
def _sometimes_unavailable(service: str, username: str) -> str:
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
raise KeyringError("temporary failure")
|
||||
return "keyring-key"
|
||||
|
||||
monkeypatch.setattr(keyring, "get_password", _sometimes_unavailable)
|
||||
|
||||
assert resolve_api_key("CUSTOM_API_KEY") is None
|
||||
assert resolve_api_key("CUSTOM_API_KEY") == "keyring-key"
|
||||
assert calls == 2
|
||||
|
||||
|
||||
def test_resolve_returns_none_for_empty_env_key(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
|
|
@ -123,7 +176,7 @@ def test_vibe_code_api_key_resolves_from_keyring(
|
|||
assert config.vibe_code_api_key == "keyring-key"
|
||||
|
||||
|
||||
def test_vibe_code_api_key_empty_when_unresolved(
|
||||
def test_vibe_code_api_key_reuses_cached_keyring_value(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.delenv("MISTRAL_API_KEY", raising=False)
|
||||
|
|
@ -132,7 +185,21 @@ def test_vibe_code_api_key_empty_when_unresolved(
|
|||
)
|
||||
config = build_test_vibe_config()
|
||||
|
||||
# Nothing resolves the key anymore; the property must return "" (not None).
|
||||
monkeypatch.setattr(keyring, "get_password", lambda service, username: None)
|
||||
|
||||
assert config.vibe_code_api_key == "keyring-key"
|
||||
|
||||
|
||||
def test_vibe_code_api_key_empty_when_cache_cleared_and_unresolved(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.delenv("MISTRAL_API_KEY", raising=False)
|
||||
monkeypatch.setattr(
|
||||
keyring, "get_password", lambda service, username: "keyring-key"
|
||||
)
|
||||
config = build_test_vibe_config()
|
||||
|
||||
clear_api_key_keyring_cache()
|
||||
monkeypatch.setattr(keyring, "get_password", lambda service, username: None)
|
||||
|
||||
assert config.vibe_code_api_key == ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue