Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai>
Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai>
Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai>
This commit is contained in:
Mathias Gesbert 2025-12-12 17:47:20 +01:00 committed by Mathias Gesbert
parent a340a721ea
commit 661588de0c
48 changed files with 1679 additions and 467 deletions

View file

@ -2,7 +2,7 @@ from __future__ import annotations
from collections.abc import Callable
from pathlib import Path
from typing import Any
import tomllib
import pytest
from textual.events import Resize
@ -10,9 +10,8 @@ from textual.geometry import Size
from textual.pilot import Pilot
from textual.widgets import Input
from vibe.core import config as core_config
from vibe.core.config_path import GLOBAL_CONFIG_FILE, GLOBAL_ENV_FILE
from vibe.setup.onboarding import OnboardingApp
import vibe.setup.onboarding.screens.api_key as api_key_module
from vibe.setup.onboarding.screens.api_key import ApiKeyScreen
from vibe.setup.onboarding.screens.theme_selection import THEMES, ThemeSelectionScreen
@ -31,32 +30,6 @@ async def _wait_for(
raise AssertionError(msg)
@pytest.fixture()
def onboarding_app(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> tuple[OnboardingApp, Path, dict[str, Any]]:
vibe_home = tmp_path / ".vibe"
env_file = vibe_home / ".env"
saved_updates: dict[str, Any] = {}
def record_updates(updates: dict[str, Any]) -> None:
saved_updates.update(updates)
monkeypatch.setenv("VIBE_HOME", str(vibe_home))
for module in (core_config, api_key_module):
monkeypatch.setattr(module, "GLOBAL_CONFIG_DIR", vibe_home, raising=False)
monkeypatch.setattr(module, "GLOBAL_ENV_FILE", env_file, raising=False)
monkeypatch.setattr(
core_config.VibeConfig,
"save_updates",
classmethod(lambda cls, updates: record_updates(updates)),
)
return OnboardingApp(), env_file, saved_updates
async def pass_welcome_screen(pilot: Pilot) -> None:
welcome_screen = pilot.app.get_screen("welcome")
await _wait_for(
@ -67,10 +40,8 @@ async def pass_welcome_screen(pilot: Pilot) -> None:
@pytest.mark.asyncio
async def test_ui_gets_through_the_onboarding_successfully(
onboarding_app: tuple[OnboardingApp, Path, dict[str, Any]],
) -> None:
app, env_file, config_updates = onboarding_app
async def test_ui_gets_through_the_onboarding_successfully() -> None:
app = OnboardingApp()
api_key_value = "sk-onboarding-test-key"
async with app.run_test() as pilot:
@ -88,19 +59,20 @@ async def test_ui_gets_through_the_onboarding_successfully(
assert app.return_value == "completed"
assert env_file.is_file()
env_contents = env_file.read_text(encoding="utf-8")
assert GLOBAL_ENV_FILE.path.is_file()
env_contents = GLOBAL_ENV_FILE.path.read_text(encoding="utf-8")
assert "MISTRAL_API_KEY" in env_contents
assert api_key_value in env_contents
assert config_updates.get("textual_theme") == app.theme
assert GLOBAL_CONFIG_FILE.path.is_file()
config_contents = GLOBAL_CONFIG_FILE.path.read_text(encoding="utf-8")
config_dict = tomllib.loads(config_contents)
assert config_dict.get("textual_theme") == app.theme
@pytest.mark.asyncio
async def test_ui_can_pick_a_theme_and_saves_selection(
onboarding_app: tuple[OnboardingApp, Path, dict[str, Any]],
) -> None:
app, _, config_updates = onboarding_app
async def test_ui_can_pick_a_theme_and_saves_selection(config_dir: Path) -> None:
app = OnboardingApp()
async with app.run_test() as pilot:
await pass_welcome_screen(pilot)
@ -121,4 +93,7 @@ async def test_ui_can_pick_a_theme_and_saves_selection(
await pilot.press("enter")
await _wait_for(lambda: isinstance(app.screen, ApiKeyScreen), pilot)
assert config_updates.get("textual_theme") == target_theme
assert GLOBAL_CONFIG_FILE.path.is_file()
config_contents = GLOBAL_CONFIG_FILE.path.read_text(encoding="utf-8")
config_dict = tomllib.loads(config_contents)
assert config_dict.get("textual_theme") == target_theme