2.1.0 (#317)
Co-authored-by: Quentin Torroba <quentin.torroba@mistral.ai> Co-authored-by: Michel Thomazo <michel.thomazo@mistral.ai> Co-authored-by: Clément Drouin <clement.drouin@mistral.ai> Co-authored-by: Vincent Guilloux <vincent.guilloux@mistral.ai> Co-authored-by: Clément Siriex <clement.sirieix@mistral.ai> Co-authored-by: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai> Co-authored-by: Nicolas Karolak <nicolas@karolak.fr>
This commit is contained in:
parent
9809cfc831
commit
51fecc67d9
176 changed files with 8652 additions and 4451 deletions
|
|
@ -1,6 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Generator
|
||||
import logging
|
||||
from os import environ
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -9,8 +11,23 @@ from vibe.cli.plan_offer.decide_plan_offer import (
|
|||
PlanOfferAction,
|
||||
PlanType,
|
||||
decide_plan_offer,
|
||||
resolve_api_key_for_plan,
|
||||
)
|
||||
from vibe.cli.plan_offer.ports.whoami_gateway import WhoAmIResponse
|
||||
from vibe.core.config import Backend, ProviderConfig
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mistral_api_key_env() -> Generator[str, None, None]:
|
||||
original_value = environ.get("MISTRAL_API_KEY")
|
||||
test_api_key = "test_mistral_api_key"
|
||||
environ["MISTRAL_API_KEY"] = test_api_key
|
||||
yield test_api_key
|
||||
|
||||
if original_value is not None:
|
||||
environ["MISTRAL_API_KEY"] = original_value
|
||||
else:
|
||||
del environ["MISTRAL_API_KEY"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -115,3 +132,51 @@ async def test_proposes_none_and_logs_warning_when_gateway_error_occurs(
|
|||
assert plan_type is PlanType.UNKNOWN
|
||||
assert gateway.calls == ["api-key"]
|
||||
assert "Failed to fetch plan status." in caplog.text
|
||||
|
||||
|
||||
def test_resolve_api_key_for_plan_with_mistral_backend(
|
||||
mistral_api_key_env: str,
|
||||
) -> None:
|
||||
test_api_key = mistral_api_key_env
|
||||
|
||||
provider = ProviderConfig(
|
||||
name="test_mistral",
|
||||
api_base="https://api.mistral.ai",
|
||||
backend=Backend.MISTRAL,
|
||||
api_key_env_var="MISTRAL_API_KEY",
|
||||
)
|
||||
|
||||
result = resolve_api_key_for_plan(provider)
|
||||
assert result == test_api_key
|
||||
|
||||
|
||||
def test_resolve_api_key_for_plan_with_non_mistral_backend(
|
||||
mistral_api_key_env: str,
|
||||
) -> None:
|
||||
provider = ProviderConfig(
|
||||
name="test_generic",
|
||||
api_base="https://api.generic.ai",
|
||||
backend=Backend.GENERIC,
|
||||
api_key_env_var="GENERIC_API_KEY",
|
||||
)
|
||||
|
||||
result = resolve_api_key_for_plan(provider)
|
||||
assert result == mistral_api_key_env
|
||||
|
||||
|
||||
def test_resolve_api_key_for_plan_with_missing_env_var() -> None:
|
||||
previous_api_key = environ["MISTRAL_API_KEY"]
|
||||
del environ["MISTRAL_API_KEY"]
|
||||
|
||||
provider = ProviderConfig(
|
||||
name="test_mistral",
|
||||
api_base="https://api.mistral.ai",
|
||||
backend=Backend.MISTRAL,
|
||||
api_key_env_var="MISTRAL_API_KEY",
|
||||
)
|
||||
|
||||
result = resolve_api_key_for_plan(provider)
|
||||
assert result is None
|
||||
|
||||
if previous_api_key is not None:
|
||||
environ["MISTRAL_API_KEY"] = previous_api_key
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.cli.plan_offer.adapters.fake_whoami_gateway import FakeWhoAmIGateway
|
||||
from tests.stubs.fake_backend import FakeBackend
|
||||
from vibe.cli.plan_offer.ports.whoami_gateway import WhoAmIResponse
|
||||
from vibe.cli.textual_ui.app import VibeApp
|
||||
from vibe.cli.textual_ui.widgets.messages import PlanOfferMessage
|
||||
from vibe.core.agent_loop import AgentLoop
|
||||
from vibe.core.config import SessionLoggingConfig, VibeConfig
|
||||
|
||||
|
||||
def _make_app(gateway: FakeWhoAmIGateway, config: VibeConfig | None = None) -> VibeApp:
|
||||
config = config or VibeConfig(
|
||||
session_logging=SessionLoggingConfig(enabled=False), enable_update_checks=False
|
||||
)
|
||||
agent_loop = AgentLoop(config=config, backend=FakeBackend())
|
||||
return VibeApp(agent_loop=agent_loop, plan_offer_gateway=gateway)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_app_shows_upgrade_offer_in_plan_offer_message(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("MISTRAL_API_KEY", "api-key")
|
||||
gateway = FakeWhoAmIGateway(
|
||||
WhoAmIResponse(
|
||||
is_pro_plan=False,
|
||||
advertise_pro_plan=True,
|
||||
prompt_switching_to_pro_plan=False,
|
||||
)
|
||||
)
|
||||
app = _make_app(gateway)
|
||||
|
||||
async with app.run_test() as pilot:
|
||||
await pilot.pause(0.1)
|
||||
offer = app.query_one(PlanOfferMessage)
|
||||
assert "Upgrade to" in offer.get_text()
|
||||
assert "Pro" in offer.get_text()
|
||||
assert gateway.calls == ["api-key"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_app_shows_switch_to_pro_key_offer_in_plan_offer_message(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("MISTRAL_API_KEY", "api-key")
|
||||
gateway = FakeWhoAmIGateway(
|
||||
WhoAmIResponse(
|
||||
is_pro_plan=False,
|
||||
advertise_pro_plan=False,
|
||||
prompt_switching_to_pro_plan=True,
|
||||
)
|
||||
)
|
||||
app = _make_app(gateway)
|
||||
|
||||
async with app.run_test() as pilot:
|
||||
await pilot.pause(0.1)
|
||||
offer = app.query_one(PlanOfferMessage)
|
||||
assert "Switch to your" in offer.get_text()
|
||||
assert "Pro API key" in offer.get_text()
|
||||
assert gateway.calls == ["api-key"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue