From a8835d293a9fe9fbff40842546a7f6dfa14ed7e8 Mon Sep 17 00:00:00 2001 From: "diana.grecu" Date: Mon, 23 Nov 2026 12:56:50 +0200 Subject: [PATCH 1/2] fix(debug): bump pysignalr to 1.3.3 to keep negotiate cookies on the WebSocket upgrade --- packages/uipath/pyproject.toml | 4 +- .../cli/test_signalr_negotiate_cookies.py | 50 +++++++++++++++++++ packages/uipath/uv.lock | 10 ++-- 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 packages/uipath/tests/cli/test_signalr_negotiate_cookies.py diff --git a/packages/uipath/pyproject.toml b/packages/uipath/pyproject.toml index 658811719..12e317d26 100644 --- a/packages/uipath/pyproject.toml +++ b/packages/uipath/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath" -version = "2.15.5" +version = "2.15.6" description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools." readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.11" @@ -19,7 +19,7 @@ dependencies = [ "truststore>=0.10.1", "mockito>=1.5.4", "pydantic-function-models>=0.1.11", - "pysignalr==1.3.0", + "pysignalr==1.3.3", "python-socketio>=5.16.2, <6.0.0", "coverage>=7.8.2", "mermaid-builder==0.0.3", diff --git a/packages/uipath/tests/cli/test_signalr_negotiate_cookies.py b/packages/uipath/tests/cli/test_signalr_negotiate_cookies.py new file mode 100644 index 000000000..ee900fa04 --- /dev/null +++ b/packages/uipath/tests/cli/test_signalr_negotiate_cookies.py @@ -0,0 +1,50 @@ +import asyncio + +from aiohttp import WSMsgType, web +from aiohttp.test_utils import TestServer +from pysignalr.client import SignalRClient + +RECORD_SEPARATOR = "\x1e" + + +async def test_websocket_upgrade_sends_the_negotiate_cookie() -> None: + upgrade_cookies: list[str | None] = [] + + async def negotiate(request: web.Request) -> web.Response: + response = web.json_response({"connectionId": "conn-1", "negotiateVersion": 0}) + response.set_cookie("affinity", "backend-1") + return response + + async def websocket(request: web.Request) -> web.WebSocketResponse: + upgrade_cookies.append(request.headers.get("Cookie")) + ws = web.WebSocketResponse() + await ws.prepare(request) + async for message in ws: + if message.type == WSMsgType.TEXT and '"protocol"' in message.data: + await ws.send_str("{}" + RECORD_SEPARATOR) + return ws + + app = web.Application() + app.router.add_post("/hub/negotiate", negotiate) + app.router.add_get("/hub", websocket) + server = TestServer(app) + await server.start_server() + + # aiohttp's default cookie jar ignores cookies from IP-address hosts. + url = str(server.make_url("/hub")).replace("127.0.0.1", "localhost") + client = SignalRClient(url, connection_timeout=1) + opened = asyncio.Event() + + async def on_open() -> None: + opened.set() + + client.on_open(on_open) + run_task = asyncio.create_task(client.run()) + try: + await asyncio.wait_for(opened.wait(), timeout=5) + finally: + run_task.cancel() + await asyncio.gather(run_task, return_exceptions=True) + await server.close() + + assert upgrade_cookies == ["affinity=backend-1"] diff --git a/packages/uipath/uv.lock b/packages/uipath/uv.lock index ffe6b8ab7..4dd829d57 100644 --- a/packages/uipath/uv.lock +++ b/packages/uipath/uv.lock @@ -2196,7 +2196,7 @@ wheels = [ [[package]] name = "pysignalr" -version = "1.3.0" +version = "1.3.3" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "aiohttp" }, @@ -2204,9 +2204,9 @@ dependencies = [ { name = "orjson" }, { name = "websockets" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/93/a6/ac80bd4972604c6930050e8b0eba41d6fde41cb3286087be0188a8865f55/pysignalr-1.3.0.tar.gz", hash = "sha256:ca2e4372f213d82148fa2f060f0fefd096f1f66fca1107ac05e76ec6abd4cf52", size = 16790, upload-time = "2025-04-29T21:23:38.931Z" } +sdist = { url = "https://files.pythonhosted.org/packages/61/90/991c2069ea98b6328a87a2380dea6c957cbe81b7954eddbcbf0bff5d62d6/pysignalr-1.3.3.tar.gz", hash = "sha256:d5bb0676f087a06e0ae8177b5791bf060f0f6546658707bb7de290c92da3052b", size = 239016, upload-time = "2026-10-17T15:55:51.267Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/2f/54/74e35563927ab8538e1bd1404b35027861434aecf2bcc945ff30c188e56d/pysignalr-1.3.0-py3-none-any.whl", hash = "sha256:423c91b0d1dc8387f37118ac2d1dc87ed6b9e01993a04612eab8452193f40344", size = 19966, upload-time = "2025-04-29T21:23:37.513Z" }, + { url = "https://files.pythonhosted.org/packages/59/ea/dc88c56f80c0dfc3649948b1a768592a6e61b27623e88cce655da4ffc609/pysignalr-1.3.3-py3-none-any.whl", hash = "sha256:5012af69a812eb0b8d725b1b8ca075ec1cc8633706da4239012ab7a76b83b23b", size = 23014, upload-time = "2026-10-17T15:55:50.23Z" }, ] [[package]] @@ -2720,7 +2720,7 @@ wheels = [ [[package]] name = "uipath" -version = "2.15.5" +version = "2.15.6" source = { editable = "." } dependencies = [ { name = "applicationinsights" }, @@ -2794,7 +2794,7 @@ requires-dist = [ { name = "pathlib", specifier = ">=1.0.1" }, { name = "pydantic-function-models", specifier = ">=0.1.11" }, { name = "pyjwt", specifier = ">=2.15.0,<3.0.0" }, - { name = "pysignalr", specifier = "==1.3.0" }, + { name = "pysignalr", specifier = "==1.3.3" }, { name = "python-dotenv", specifier = ">=1.2.2,<2.0.0" }, { name = "python-socketio", specifier = ">=5.16.2,<6.0.0" }, { name = "pyyaml", specifier = ">=6.0,<7.0" }, From 194a9dc0d1034e08bce81688d134cd350f3b43ce Mon Sep 17 00:00:00 2001 From: "diana.grecu" Date: Mon, 23 Nov 2026 13:20:44 +0200 Subject: [PATCH 2/2] fix(debug): keep hub completions for SendCommand on pysignalr 1.3.3 --- .../uipath/src/uipath/_cli/_debug/_bridge.py | 9 +- .../tests/cli/test_signalr_debug_hub.py | 106 ++++++++++++++++++ .../cli/test_signalr_negotiate_cookies.py | 50 --------- 3 files changed, 114 insertions(+), 51 deletions(-) create mode 100644 packages/uipath/tests/cli/test_signalr_debug_hub.py delete mode 100644 packages/uipath/tests/cli/test_signalr_negotiate_cookies.py diff --git a/packages/uipath/src/uipath/_cli/_debug/_bridge.py b/packages/uipath/src/uipath/_cli/_debug/_bridge.py index 4571ec1a1..9e094b1c8 100644 --- a/packages/uipath/src/uipath/_cli/_debug/_bridge.py +++ b/packages/uipath/src/uipath/_cli/_debug/_bridge.py @@ -760,7 +760,11 @@ async def _send(self, event_name: str, data: dict[str, Any]) -> None: serialized_data = serialize_object(data) data_json = json.dumps(serialized_data) arguments: list[Any] = [event_name, data_json] - await self._client.send(method="SendCommand", arguments=arguments) + await self._client.send( + method="SendCommand", + arguments=arguments, + on_invocation=self._handle_send_completion, + ) logger.debug(f"Sent command: {event_name}") except Exception as e: logger.error(f"Error sending command {event_name} to SignalR hub: {e}") @@ -893,6 +897,9 @@ async def _handle_error(self, error: Any) -> None: """Handle SignalR error.""" logger.error(f"SignalR error: {error}") + async def _handle_send_completion(self, message: Any) -> None: + """Receive the hub's completion for SendCommand; errors go to _handle_error.""" + def get_remote_debug_bridge(context: UiPathRuntimeContext) -> UiPathDebugProtocol: """Factory to get SignalR debug bridge for remote debugging.""" diff --git a/packages/uipath/tests/cli/test_signalr_debug_hub.py b/packages/uipath/tests/cli/test_signalr_debug_hub.py new file mode 100644 index 000000000..a792e2c74 --- /dev/null +++ b/packages/uipath/tests/cli/test_signalr_debug_hub.py @@ -0,0 +1,106 @@ +import asyncio +import json +from collections.abc import AsyncIterator +from typing import Any + +import pytest +from aiohttp import WSMsgType, web +from aiohttp.test_utils import TestServer +from pysignalr.client import SignalRClient + +from uipath._cli._debug._bridge import SignalRDebugBridge + +RECORD_SEPARATOR = "\x1e" + + +class _Hub: + def __init__(self) -> None: + self.upgrade_cookies: list[str | None] = [] + self.invocations: list[dict[str, Any]] = [] + + async def negotiate(self, request: web.Request) -> web.Response: + response = web.json_response({"connectionId": "conn-1", "negotiateVersion": 0}) + response.set_cookie("affinity", "backend-1") + return response + + async def websocket(self, request: web.Request) -> web.WebSocketResponse: + self.upgrade_cookies.append(request.headers.get("Cookie")) + ws = web.WebSocketResponse() + await ws.prepare(request) + async for message in ws: + if message.type != WSMsgType.TEXT: + continue + for record in filter(None, message.data.split(RECORD_SEPARATOR)): + frame = json.loads(record) + if "protocol" in frame: + await ws.send_str("{}" + RECORD_SEPARATOR) + elif frame.get("type") == 1: + self.invocations.append(frame) + if "invocationId" in frame: + completion = { + "type": 3, + "invocationId": frame["invocationId"], + "error": "command rejected", + } + await ws.send_str(json.dumps(completion) + RECORD_SEPARATOR) + return ws + + +@pytest.fixture +async def hub() -> AsyncIterator[tuple[_Hub, str]]: + state = _Hub() + app = web.Application() + app.router.add_post("/hub/negotiate", state.negotiate) + app.router.add_get("/hub", state.websocket) + server = TestServer(app) + await server.start_server() + # aiohttp's default cookie jar ignores cookies from IP-address hosts. + yield state, str(server.make_url("/hub")).replace("127.0.0.1", "localhost") + await server.close() + + +async def test_websocket_upgrade_sends_the_negotiate_cookie( + hub: tuple[_Hub, str], +) -> None: + state, url = hub + client = SignalRClient(url, connection_timeout=1) + opened = asyncio.Event() + + async def on_open() -> None: + opened.set() + + client.on_open(on_open) + run_task = asyncio.create_task(client.run()) + try: + await asyncio.wait_for(opened.wait(), timeout=5) + finally: + run_task.cancel() + await asyncio.gather(run_task, return_exceptions=True) + + assert state.upgrade_cookies == ["affinity=backend-1"] + + +async def test_hub_side_send_error_reaches_the_error_handler( + hub: tuple[_Hub, str], monkeypatch: pytest.MonkeyPatch +) -> None: + state, url = hub + bridge = SignalRDebugBridge(hub_url=url) + errors: list[Any] = [] + + async def record_error(error: Any) -> None: + errors.append(error) + + monkeypatch.setattr(bridge, "_handle_error", record_error) + await bridge.connect() + try: + await bridge._send("OnExecutionStarted", {"job": "1"}) + for _ in range(50): + if errors: + break + await asyncio.sleep(0.05) + finally: + await bridge.disconnect() + + assert state.invocations[0]["target"] == "SendCommand" + assert "invocationId" in state.invocations[0] + assert [error.error for error in errors] == ["command rejected"] diff --git a/packages/uipath/tests/cli/test_signalr_negotiate_cookies.py b/packages/uipath/tests/cli/test_signalr_negotiate_cookies.py deleted file mode 100644 index ee900fa04..000000000 --- a/packages/uipath/tests/cli/test_signalr_negotiate_cookies.py +++ /dev/null @@ -1,50 +0,0 @@ -import asyncio - -from aiohttp import WSMsgType, web -from aiohttp.test_utils import TestServer -from pysignalr.client import SignalRClient - -RECORD_SEPARATOR = "\x1e" - - -async def test_websocket_upgrade_sends_the_negotiate_cookie() -> None: - upgrade_cookies: list[str | None] = [] - - async def negotiate(request: web.Request) -> web.Response: - response = web.json_response({"connectionId": "conn-1", "negotiateVersion": 0}) - response.set_cookie("affinity", "backend-1") - return response - - async def websocket(request: web.Request) -> web.WebSocketResponse: - upgrade_cookies.append(request.headers.get("Cookie")) - ws = web.WebSocketResponse() - await ws.prepare(request) - async for message in ws: - if message.type == WSMsgType.TEXT and '"protocol"' in message.data: - await ws.send_str("{}" + RECORD_SEPARATOR) - return ws - - app = web.Application() - app.router.add_post("/hub/negotiate", negotiate) - app.router.add_get("/hub", websocket) - server = TestServer(app) - await server.start_server() - - # aiohttp's default cookie jar ignores cookies from IP-address hosts. - url = str(server.make_url("/hub")).replace("127.0.0.1", "localhost") - client = SignalRClient(url, connection_timeout=1) - opened = asyncio.Event() - - async def on_open() -> None: - opened.set() - - client.on_open(on_open) - run_task = asyncio.create_task(client.run()) - try: - await asyncio.wait_for(opened.wait(), timeout=5) - finally: - run_task.cancel() - await asyncio.gather(run_task, return_exceptions=True) - await server.close() - - assert upgrade_cookies == ["affinity=backend-1"]