Skip to content

Commit c9d45be

Browse files
ampagentIsaac Miller
andcommitted
Map post-approval deadline checks through typed login errors
Signed-off-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a0c095-4917-7617-9dac-e99f1ef22d41 Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
1 parent d27dfae commit c9d45be

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎lm15/login/manager.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ def login(
361361
flow = _flow(provider, chosen.id)
362362
try:
363363
result = flow.login(ctx, chosen, settings, answers)
364+
ctx.check()
364365
except LoginCancelled:
365366
self._release(provider, attempt_id)
366367
raise
@@ -391,7 +392,6 @@ def login(
391392
except LM15Error:
392393
self._release(provider, attempt_id)
393394
raise
394-
ctx.check()
395395
return self._commit(provider, attempt_id, expected, chosen, result, settings)
396396
except BaseException:
397397
# Any exit without a saved connection ends the attempt — Ctrl-C

‎tests/test_login.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,25 @@ async def run():
500500
assert reopened.store.read()["xai"]["key"] == "newer"
501501

502502

503+
def test_login_expiring_after_approval_returns_typed_error(sandbox: Path, monkeypatch) -> None:
504+
from lm15.login.flows.base import LoginResult
505+
from lm15.login.flows.xai import XaiFlow
506+
507+
clock = Clock()
508+
auth = make_auth(sandbox, clock)
509+
510+
def expired_approval(self, ctx, method, settings, answers):
511+
clock.advance(61)
512+
return LoginResult(material={"type": "api_key", "key": "late"}, label="late")
513+
514+
monkeypatch.setattr(XaiFlow, "login", expired_approval)
515+
with pytest.raises(AuthOperationError) as error:
516+
auth.login("xai", "device", ui=ScriptUI(), lifetime_s=60)
517+
assert error.value.reason == "login_expired"
518+
assert auth.status("xai").presence == "absent"
519+
assert auth.set_api_key("xai", "later").provider == "xai"
520+
521+
503522
def test_an_interrupt_ends_the_attempt_and_frees_the_slot(sandbox: Path) -> None:
504523
# Ctrl-C — a notebook's cancel — while waiting for the provider, or at
505524
# a prompt: the attempt is over, so its reservation must not block the

0 commit comments

Comments
 (0)