vibe/tests/cli/plan_offer/test_plan_offer_in_app.py
Mathias Gesbert d33db9fff8 2.0.0
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: Thaddee Tyl <thaddee.tyl@gmail.com>
Co-Authored-By: David Brochart <david.brochart@gmail.com>
Co-Authored-By: Joseph Guhlin <joseph.guhlin@gmail.com>
Co-Authored-By: Thomas Kenbeek <thomaskenbeek@gmail.com>
Co-Authored-By: Remenby31 <baptiste.cruvellier31@gmail.com>
2026-01-27 16:44:55 +01:00

63 lines
2.1 KiB
Python

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"]