feat(remote)!: make remote serve WebSocket-only and refuse older clients with CLIENT_OUTDATED

This commit is contained in:
imSp4rky
2026-12-05 09:47:22 -07:00
parent 641623590d
commit 00ad15527c
62 changed files with 657 additions and 2098 deletions
+10 -13
View File
@@ -20,10 +20,8 @@ from unshackle.core.api.handlers import SESSION_TRANSPORT_KEYS
ROUTE_NAMES = {name for name in vars(protocol) if name.endswith("_ROUTE")}
CLIENT_METHODS = {
"get": "GET",
"get_optional": "GET",
"probe": "GET",
"post": "POST",
"post_optional": "POST",
"ws_connect": "GET",
}
SERVED = {(method, path): handler for method, path, handler, _ in routes.ROUTES}
@@ -121,8 +119,8 @@ def test_the_protocol_page_lists_each_remote_route():
}
def test_the_wire_values_stay_what_older_peers_send():
"""Both halves read one record, so only this list catches a renamed value that an older peer still sends."""
def test_the_wire_values_stay_pinned():
"""Both halves read one record, so only this list catches a renamed value on the wire."""
assert {name: getattr(protocol, name) for name in ROUTE_NAMES} == {
"HEALTH_ROUTE": "/api/health",
"SERVICES_ROUTE": "/api/services",
@@ -137,14 +135,17 @@ def test_the_wire_values_stay_what_older_peers_send():
"LICENSE_ROUTE": "/api/session/{session_id}/license",
"KEYS_ROUTE": "/api/session/{session_id}/keys",
"BAD_KEY_ROUTE": "/api/session/{session_id}/keys/bad",
"LOGS_ROUTE": "/api/session/{session_id}/logs",
"PROMPT_ROUTE": "/api/session/{session_id}/prompt",
"CHANNEL_ROUTE": "/api/session/{session_id}/channel",
}
assert [m.value for m in protocol.ChannelMessage] == ["prompt", "cdm_call", "log", "status", "drain", "answer"]
assert protocol.CHANNEL_SESSION_GONE == 4404
assert [s.value for s in protocol.AuthStatus] == ["authenticating", "pending_input", "authenticated", "failed"]
assert {c.name for c in protocol.APIErrorCode} >= {"SESSION_NOT_FOUND", "SERVER_CDM_CAPPED", "SERVER_DRAINING"}
assert [s.value for s in protocol.AuthStatus] == ["authenticating", "authenticated", "failed"]
assert {c.name for c in protocol.APIErrorCode} >= {
"SESSION_NOT_FOUND",
"SERVER_CDM_CAPPED",
"SERVER_DRAINING",
"CLIENT_OUTDATED",
}
assert [k.value for k in protocol.ClientErrorKind] == [
"CONNECT",
"TIMEOUT",
@@ -177,7 +178,6 @@ def test_session_transport_keys_are_the_create_body():
"server_cdm",
"cdm_type",
"cdm_security_level",
"cdm_relay",
"cdm_system_id",
"cdm_device_type",
"service_config",
@@ -203,7 +203,7 @@ def test_session_transport_keys_are_the_create_body():
],
)
def test_the_channel_messages_keep_their_fields(shape, fields):
"""A session channel message is a JSON text frame; an older peer reads these keys."""
"""A session channel message is a JSON text frame; the other side reads these keys."""
assert keys(shape) == fields
@@ -230,9 +230,6 @@ def properties(schema: dict | None) -> set[str]:
("POST", protocol.LICENSE_ROUTE, protocol.LicenseRequest, protocol.LicenseReply),
("POST", protocol.KEYS_ROUTE, protocol.TrackKeys, None),
("POST", protocol.BAD_KEY_ROUTE, protocol.BadKeyReport, None),
("GET", protocol.LOGS_ROUTE, None, protocol.LogsReply),
("GET", protocol.PROMPT_ROUTE, None, protocol.PromptReply),
("POST", protocol.PROMPT_ROUTE, protocol.PromptAnswer, None),
("GET", protocol.SESSION_ROUTE, None, protocol.SessionInfo),
],
)