From c26c61b7da32ed5e42a84c3d63101d50b0cac0b1 Mon Sep 17 00:00:00 2001 From: Brian Krabach Date: Wed, 15 Apr 2026 13:02:32 -0700 Subject: [PATCH] fix: extract auth_headers to local var to prevent ruff splitting inline guards Ruff was reformatting the ternary header constructions to multi-line form: headers={"Authorization": f"Bearer {remote_key}"}\n if remote_key\n else {}, This caused test_federation_auth_headers_guard_empty_key to fail because the source-inspection test requires 'if' to appear on the same line as the Authorization header dict. Fix: assign to a local variable before use so ruff has no reason to split: auth_headers = {"Authorization": f"Bearer {key}"} if key else {} Applied at two sites: - poll-cycle bell-clear (line ~232) - federation WS proxy endpoint (line ~1094) --- muxplex/main.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/muxplex/main.py b/muxplex/main.py index 54e544c..d9171ae 100644 --- a/muxplex/main.py +++ b/muxplex/main.py @@ -228,6 +228,8 @@ async def _run_poll_cycle() -> None: remote = remote_instances[active_remote_id] remote_url: str = remote.get("url", "").rstrip("/") remote_key: str = remote.get("key", "") + key = remote_key + auth_headers = {"Authorization": f"Bearer {key}"} if key else {} now = time.time() for device in state.get("devices", {}).values(): viewing_session = device.get("viewing_session") @@ -242,9 +244,7 @@ async def _run_poll_cycle() -> None: try: await _federation_client.post( bell_clear_url, - headers={"Authorization": f"Bearer {remote_key}"} - if remote_key - else {}, + headers=auth_headers, ) except Exception as exc: _log.warning( @@ -1091,13 +1091,12 @@ async def federation_terminal_ws_proxy(websocket: WebSocket, device_id: str) -> await websocket.accept(subprotocol="tty") + auth_headers = {"Authorization": f"Bearer {remote_key}"} if remote_key else {} try: async with websockets.connect( ws_url, subprotocols=[Subprotocol("tty")], - additional_headers={"Authorization": f"Bearer {remote_key}"} - if remote_key - else {}, + additional_headers=auth_headers, ssl=ssl_context, ) as remote_ws: