v2.14.0 (#743)
Co-authored-by: Alexis Tacnet <alexis@mistral.ai> Co-authored-by: Clément Drouin <clement.drouin@mistral.ai> Co-authored-by: Guillaume LE GOFF <guillaume.lgf@gmail.com> Co-authored-by: Lucas Marandat <31749711+lucasmrdt@users.noreply.github.com> Co-authored-by: Maxime Dolores <maxime.dolores@ext.mistral.ai> Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai> Co-authored-by: Quentin <quentin.torroba@mistral.ai> Co-authored-by: Val <102326092+vdeva@users.noreply.github.com> Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com> Co-authored-by: p.vezia <166131032+le-codeur-rapide@users.noreply.github.com> Co-authored-by: Hiba Chaabnia <Hiba-Chaabnia@users.noreply.github.com> Co-authored-by: Nikhil Bhima <nikhilbhima@users.noreply.github.com> Co-authored-by: Nkipohcs <Nkipohcs@users.noreply.github.com> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
ad0d5c9520
commit
3f8487f761
197 changed files with 10819 additions and 2830 deletions
|
|
@ -18,12 +18,15 @@ from tests.browser_sign_in.stubs import (
|
|||
noop_sleep,
|
||||
)
|
||||
from vibe.setup.auth import (
|
||||
BrowserSignInAttemptStarted,
|
||||
BrowserSignInError,
|
||||
BrowserSignInErrorCode,
|
||||
BrowserSignInEvent,
|
||||
BrowserSignInPollResult,
|
||||
BrowserSignInProcess,
|
||||
BrowserSignInService,
|
||||
BrowserSignInStatus,
|
||||
BrowserSignInStatusChanged,
|
||||
)
|
||||
|
||||
TEST_NOW = datetime(2026, 3, 16, tzinfo=UTC)
|
||||
|
|
@ -69,7 +72,7 @@ def build_test_service(
|
|||
@pytest.mark.asyncio
|
||||
async def test_authenticate_returns_api_key_after_pending_poll() -> None:
|
||||
opened_urls: list[str] = []
|
||||
statuses: list[BrowserSignInStatus] = []
|
||||
events: list[BrowserSignInEvent] = []
|
||||
gateway, service = build_test_service(
|
||||
poll_results=[
|
||||
BrowserSignInPollResult(status="pending"),
|
||||
|
|
@ -78,17 +81,23 @@ async def test_authenticate_returns_api_key_after_pending_poll() -> None:
|
|||
open_browser=lambda url: opened_urls.append(url) or True,
|
||||
)
|
||||
|
||||
api_key = await service.authenticate(status_callback=statuses.append)
|
||||
api_key = await service.authenticate(event_callback=events.append)
|
||||
|
||||
code_verifier = gateway.exchange_requests[0].code_verifier
|
||||
assert gateway.code_challenges == [build_code_challenge(code_verifier)]
|
||||
assert api_key == "sk-browser-key"
|
||||
assert opened_urls == [TEST_SIGN_IN_URL]
|
||||
assert statuses == [
|
||||
BrowserSignInStatus.OPENING_BROWSER,
|
||||
BrowserSignInStatus.WAITING_FOR_BROWSER_SIGN_IN,
|
||||
BrowserSignInStatus.EXCHANGING,
|
||||
BrowserSignInStatus.COMPLETED,
|
||||
assert events == [
|
||||
BrowserSignInAttemptStarted(
|
||||
sign_in_url=TEST_SIGN_IN_URL,
|
||||
expires_at=build_sign_in_process(TEST_NOW).expires_at,
|
||||
),
|
||||
BrowserSignInStatusChanged(status=BrowserSignInStatus.OPENING_BROWSER),
|
||||
BrowserSignInStatusChanged(
|
||||
status=BrowserSignInStatus.WAITING_FOR_BROWSER_SIGN_IN
|
||||
),
|
||||
BrowserSignInStatusChanged(status=BrowserSignInStatus.EXCHANGING),
|
||||
BrowserSignInStatusChanged(status=BrowserSignInStatus.COMPLETED),
|
||||
]
|
||||
assert gateway.polled_urls == [TEST_POLL_URL, TEST_POLL_URL]
|
||||
assert gateway.exchange_requests[0].exchange_token == "exchange-1"
|
||||
|
|
@ -115,7 +124,6 @@ async def test_start_attempt_returns_attempt_without_opening_browser() -> None:
|
|||
@pytest.mark.asyncio
|
||||
async def test_complete_attempt_returns_api_key_without_opening_browser() -> None:
|
||||
opened_urls: list[str] = []
|
||||
statuses: list[BrowserSignInStatus] = []
|
||||
gateway, service = build_test_service(
|
||||
poll_results=[
|
||||
BrowserSignInPollResult(status="pending"),
|
||||
|
|
@ -125,15 +133,10 @@ async def test_complete_attempt_returns_api_key_without_opening_browser() -> Non
|
|||
)
|
||||
attempt = await service.start_attempt()
|
||||
|
||||
api_key = await service.complete_attempt(attempt, status_callback=statuses.append)
|
||||
api_key = await service.complete_attempt(attempt)
|
||||
|
||||
assert api_key == "sk-browser-key"
|
||||
assert opened_urls == []
|
||||
assert statuses == [
|
||||
BrowserSignInStatus.WAITING_FOR_BROWSER_SIGN_IN,
|
||||
BrowserSignInStatus.EXCHANGING,
|
||||
BrowserSignInStatus.COMPLETED,
|
||||
]
|
||||
assert gateway.polled_urls == [TEST_POLL_URL, TEST_POLL_URL]
|
||||
assert gateway.exchange_requests[0].exchange_token == "exchange-1"
|
||||
|
||||
|
|
@ -241,10 +244,19 @@ async def test_authenticate_raises_on_unknown_poll_state() -> None:
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_authenticate_raises_when_browser_cannot_be_opened() -> None:
|
||||
events: list[BrowserSignInEvent] = []
|
||||
_, service = build_test_service(poll_results=[], open_browser=lambda _: False)
|
||||
|
||||
with pytest.raises(BrowserSignInError, match="open browser"):
|
||||
await service.authenticate()
|
||||
await service.authenticate(event_callback=events.append)
|
||||
|
||||
assert events == [
|
||||
BrowserSignInAttemptStarted(
|
||||
sign_in_url=TEST_SIGN_IN_URL,
|
||||
expires_at=build_sign_in_process(TEST_NOW).expires_at,
|
||||
),
|
||||
BrowserSignInStatusChanged(status=BrowserSignInStatus.OPENING_BROWSER),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue