Co-authored-by: Clément Drouin <clement.drouin@mistral.ai>
Co-authored-by: Gauthier Guinet <43207538+Gguinet@users.noreply.github.com>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai>
Co-authored-by: Stanislas <stanislas.lange@mistral.ai>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Mathias Gesbert 2026-06-08 14:59:41 +02:00 committed by GitHub
parent 3f8487f761
commit 702d0f412e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
51 changed files with 2446 additions and 502 deletions

View file

@ -7,7 +7,6 @@ import time
from unittest.mock import patch
import pytest
from textual.app import Notification
from tests.conftest import build_test_vibe_app, build_test_vibe_config
from tests.update_notifier.adapters.fake_update_cache_repository import (
@ -50,21 +49,6 @@ def build_update_test_app(
return _build
async def _wait_for_notification(
app: VibeApp, pilot, *, timeout: float = 1.0, interval: float = 0.05
) -> Notification:
loop = asyncio.get_running_loop()
deadline = loop.time() + timeout
while loop.time() < deadline:
notifications = list(app._notifications)
if notifications:
return notifications[-1]
await pilot.pause(interval)
pytest.fail("Notification not displayed")
async def _assert_no_notifications(
app: VibeApp, pilot, *, timeout: float = 1.0, interval: float = 0.05
) -> None:
@ -85,25 +69,25 @@ def vibe_config_with_update_checks_enabled() -> VibeConfig:
@pytest.mark.asyncio
async def test_ui_displays_update_notification(
async def test_ui_writes_pending_update_to_cache_without_notifying(
build_update_test_app: Callable[..., VibeApp],
) -> None:
notifier = FakeUpdateGateway(update=Update(latest_version="0.2.0"))
app = build_update_test_app(update_notifier=notifier)
repository = FakeUpdateCacheRepository()
app = build_update_test_app(
update_notifier=notifier, update_cache_repository=repository
)
async with app.run_test() as pilot:
notification = await _wait_for_notification(app, pilot, timeout=0.3)
await _assert_no_notifications(app, pilot, timeout=0.3)
assert notification.severity == "information"
assert notification.title == "Update available"
assert (
notification.message
== "0.1.0 => 0.2.0\nPlease update mistral-vibe with your package manager"
)
assert notifier.fetch_update_calls == 1
assert repository.update_cache is not None
assert repository.update_cache.latest_version == "0.2.0"
@pytest.mark.asyncio
async def test_ui_does_not_display_update_notification_when_not_available(
async def test_ui_does_not_notify_when_no_update_is_available(
build_update_test_app: Callable[..., VibeApp],
) -> None:
notifier = FakeUpdateGateway(update=None)
@ -115,7 +99,7 @@ async def test_ui_does_not_display_update_notification_when_not_available(
@pytest.mark.asyncio
async def test_ui_displays_warning_toast_when_check_fails(
async def test_ui_does_not_notify_when_gateway_errors(
build_update_test_app: Callable[..., VibeApp],
) -> None:
notifier = FakeUpdateGateway(
@ -124,13 +108,7 @@ async def test_ui_displays_warning_toast_when_check_fails(
app = build_update_test_app(update_notifier=notifier)
async with app.run_test() as pilot:
await pilot.pause(0.3)
notifications = list(app._notifications)
assert notifications
warning = notifications[-1]
assert warning.severity == "warning"
assert "forbidden" in warning.message.lower()
await _assert_no_notifications(app, pilot, timeout=0.3)
@pytest.mark.asyncio
@ -167,11 +145,11 @@ async def test_ui_does_not_show_toast_when_update_is_known_in_recent_cache_alrea
@pytest.mark.asyncio
async def test_ui_does_show_toast_when_cache_entry_is_too_old(
async def test_ui_refetches_and_updates_cache_when_cache_entry_is_too_old(
build_update_test_app: Callable[..., VibeApp],
) -> None:
timestamp_two_days_ago = int(time.time()) - 2 * 24 * 60 * 60
notifier = FakeUpdateGateway(update=Update(latest_version="0.2.0"))
notifier = FakeUpdateGateway(update=Update(latest_version="0.3.0"))
update_cache = UpdateCache(
latest_version="0.2.0", stored_at_timestamp=timestamp_two_days_ago
)
@ -181,18 +159,11 @@ async def test_ui_does_show_toast_when_cache_entry_is_too_old(
)
async with app.run_test() as pilot:
await pilot.pause(0.3)
notifications = list(app._notifications)
await _assert_no_notifications(app, pilot, timeout=0.3)
assert notifications
notification = notifications[-1]
assert notification.severity == "information"
assert notification.title == "Update available"
assert (
notification.message
== "0.1.0 => 0.2.0\nPlease update mistral-vibe with your package manager"
)
assert notifier.fetch_update_calls == 1
assert update_cache_repository.update_cache is not None
assert update_cache_repository.update_cache.latest_version == "0.3.0"
async def _wait_for_whats_new_message(
@ -339,51 +310,3 @@ async def test_ui_does_not_display_whats_new_when_file_does_not_exist(
assert repository.update_cache is not None
assert repository.update_cache.seen_whats_new_version == "1.0.0"
@pytest.mark.asyncio
async def test_ui_displays_success_notification_when_auto_update_succeeds(
build_update_test_app: Callable[..., VibeApp],
) -> None:
config = build_test_vibe_config(enable_update_checks=True, enable_auto_update=True)
notifier = FakeUpdateGateway(update=Update(latest_version="0.2.0"))
with patch("vibe.cli.update_notifier.update.UPDATE_COMMANDS", ["true"]):
app = build_update_test_app(update_notifier=notifier, config=config)
async with app.run_test() as pilot:
await pilot.pause(0.3)
notifications = list(app._notifications)
assert notifications, "No notifications displayed"
notification = notifications[-1]
assert notification.severity == "information"
assert notification.title == "Update successful"
assert (
notification.message
== "0.1.0 => 0.2.0\nVibe was updated successfully. Please restart to use the new version."
)
@pytest.mark.asyncio
async def test_ui_displays_update_notification_when_auto_update_fails(
build_update_test_app: Callable[..., VibeApp],
) -> None:
config = build_test_vibe_config(enable_update_checks=True, enable_auto_update=True)
notifier = FakeUpdateGateway(update=Update(latest_version="0.2.0"))
with patch("vibe.cli.update_notifier.update.UPDATE_COMMANDS", ["false"]):
app = build_update_test_app(update_notifier=notifier, config=config)
async with app.run_test() as pilot:
await pilot.pause(0.3)
notifications = list(app._notifications)
assert notifications
notification = notifications[-1]
assert notification.severity == "information"
assert notification.title == "Update available"
assert (
notification.message
== "0.1.0 => 0.2.0\nPlease update mistral-vibe with your package manager"
)