diff --git a/studio/backend/routes/llama.py b/studio/backend/routes/llama.py index 6d4b2415dc..d3d247eb2b 100644 --- a/studio/backend/routes/llama.py +++ b/studio/backend/routes/llama.py @@ -44,9 +44,7 @@ _REFUSAL_MESSAGES = { "The confirmation is missing or unrecognized. Re-check for the update and " "confirm again before it runs." ), - "expired_token": ( - "The confirmation expired. Re-check for the update and confirm again." - ), + "expired_token": ("The confirmation expired. Re-check for the update and confirm again."), "stale_target": ( "The available build changed since you confirmed. Re-check for the update " "and confirm the new build before it runs." @@ -284,7 +282,9 @@ async def llama_update( return LlamaUpdateActionResponse( started = False, reason = refuse_reason, - message = _REFUSAL_MESSAGES.get(refuse_reason, _REFUSAL_MESSAGES["confirmation_required"]), + message = _REFUSAL_MESSAGES.get( + refuse_reason, _REFUSAL_MESSAGES["confirmation_required"] + ), machine = machine, installed_tag = installed_tag, latest_tag = target_tag, diff --git a/studio/backend/tests/test_update_contract.py b/studio/backend/tests/test_update_contract.py index cf84df143c..81386dc503 100644 --- a/studio/backend/tests/test_update_contract.py +++ b/studio/backend/tests/test_update_contract.py @@ -162,6 +162,7 @@ def _track_start(monkeypatch): # update_confirm token unit tests # --------------------------------------------------------------------------- # + def test_token_roundtrip_single_use(): tok, exp = _uc.mint_confirm_token("b9909") assert isinstance(tok, str) and tok @@ -193,6 +194,7 @@ def test_token_missing_refused(): # Handler-level: the swap only runs with an explicit confirmation # --------------------------------------------------------------------------- # + def test_apply_without_confirmation_is_refused_and_never_swaps(monkeypatch): calls = _track_start(monkeypatch) out = asyncio.run(rl.llama_update(request = None, current_subject = "operator")) @@ -210,8 +212,8 @@ def test_apply_with_confirmed_true_proceeds(monkeypatch): body = rl.LlamaUpdateRequest(confirmed = True) out = asyncio.run(rl.llama_update(request = body, current_subject = "operator")) assert out.started is True - assert out.machine.hostname # which machine - assert out.latest_tag == "b9909" # which version + assert out.machine.hostname # which machine + assert out.latest_tag == "b9909" # which version assert calls["n"] == 1 @@ -273,9 +275,7 @@ def test_confirm_endpoint_up_to_date_offers_no_token(monkeypatch): def test_status_reports_machine(): - out = asyncio.run( - rl.llama_update_status(force_refresh = False, current_subject = "operator") - ) + out = asyncio.run(rl.llama_update_status(force_refresh = False, current_subject = "operator")) assert out.machine.hostname assert out.machine.platform assert out.latest_tag == "b9909" @@ -285,6 +285,7 @@ def test_status_reports_machine(): # HTTP-level: auth gate + wiring + backwards-compatible bodyless POST # --------------------------------------------------------------------------- # + def _client(): from fastapi import FastAPI from fastapi.testclient import TestClient diff --git a/studio/backend/utils/update_confirm.py b/studio/backend/utils/update_confirm.py index 1735ba98c0..342ebb81ac 100644 --- a/studio/backend/utils/update_confirm.py +++ b/studio/backend/utils/update_confirm.py @@ -47,9 +47,7 @@ def _purge_expired_locked(now: float) -> None: def mint_confirm_token( - target_tag: str, - *, - ttl_seconds: int = CONFIRM_TOKEN_TTL_SECONDS, + target_tag: str, *, ttl_seconds: int = CONFIRM_TOKEN_TTL_SECONDS ) -> Tuple[str, str]: """Mint a single-use token bound to ``target_tag``. @@ -70,8 +68,7 @@ def mint_confirm_token( def consume_confirm_token( - token: Optional[str], - current_target_tag: str, + token: Optional[str], current_target_tag: str ) -> Tuple[bool, Optional[str]]: """Validate and consume a token for a swap to ``current_target_tag``.