Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions aai_cli/core/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ def handshake_status(exc: object) -> int | None:
``.response.status_code`` — never the message text. The single classifier for
every realtime path (stream, agent, speak), so 401-vs-403 handling can't drift.
"""
# Both attributes come off an arbitrary exception via getattr, so they're untyped
# and may be anything (or absent → None); narrow to int before the membership test
# rather than coercing with int(), which would raise on a non-numeric .code.
code = getattr(exc, "code", None)
if code in _HANDSHAKE_AUTH_STATUSES:
return int(code)
if isinstance(code, int) and code in _HANDSHAKE_AUTH_STATUSES:
return code
status = getattr(getattr(exc, "response", None), "status_code", None)
if status in _HANDSHAKE_AUTH_STATUSES:
return int(status)
if isinstance(status, int) and status in _HANDSHAKE_AUTH_STATUSES:
return status
return None


Expand Down
3 changes: 3 additions & 0 deletions tests/test_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def test_handshake_status_reads_both_structured_shapes():
assert handshake_status(RuntimeError("network unreachable")) is None
# A WebSocket close code (e.g. 1008 policy violation) is not a handshake status.
assert handshake_status(types.SimpleNamespace(code=1008)) is None
# A structured but non-auth HTTP status (e.g. a 500 on the response shape) is not a
# handshake auth status either — only 401/403 qualify, on either shape.
assert handshake_status(_HandshakeRejected(500)) is None


def test_is_rejected_key_true_for_handshake_401():
Expand Down
Loading