|
| 1 | +"""Integration test: UiPathDebugRuntime must not block under DetachedDebugBridge. |
| 2 | +
|
| 3 | +If this ever hangs or times out, the detached path has regressed — the scenario |
| 4 | +this bridge exists to enable has broken. |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | +import asyncio |
| 10 | +from typing import Any, AsyncGenerator |
| 11 | + |
| 12 | +import pytest |
| 13 | + |
| 14 | +from uipath.runtime import ( |
| 15 | + UiPathExecuteOptions, |
| 16 | + UiPathRuntimeResult, |
| 17 | + UiPathRuntimeStatus, |
| 18 | + UiPathStreamNotSupportedError, |
| 19 | + UiPathStreamOptions, |
| 20 | +) |
| 21 | +from uipath.runtime.debug import DetachedDebugBridge, UiPathDebugRuntime |
| 22 | +from uipath.runtime.events import UiPathRuntimeEvent, UiPathRuntimeStateEvent |
| 23 | +from uipath.runtime.schema import UiPathRuntimeSchema |
| 24 | + |
| 25 | + |
| 26 | +class TrivialStreamingRuntime: |
| 27 | + """Streams one state event then a final successful result.""" |
| 28 | + |
| 29 | + async def dispose(self) -> None: |
| 30 | + pass |
| 31 | + |
| 32 | + async def execute( |
| 33 | + self, |
| 34 | + input: dict[str, Any] | None = None, |
| 35 | + options: UiPathExecuteOptions | None = None, |
| 36 | + ) -> UiPathRuntimeResult: |
| 37 | + return UiPathRuntimeResult( |
| 38 | + status=UiPathRuntimeStatus.SUCCESSFUL, |
| 39 | + output={"mode": "execute"}, |
| 40 | + ) |
| 41 | + |
| 42 | + async def stream( |
| 43 | + self, |
| 44 | + input: dict[str, Any] | None = None, |
| 45 | + options: UiPathStreamOptions | None = None, |
| 46 | + ) -> AsyncGenerator[UiPathRuntimeEvent, None]: |
| 47 | + yield UiPathRuntimeStateEvent(node_name="node-1", payload={"i": 0}) |
| 48 | + yield UiPathRuntimeResult( |
| 49 | + status=UiPathRuntimeStatus.SUCCESSFUL, |
| 50 | + output={"done": True}, |
| 51 | + ) |
| 52 | + |
| 53 | + async def get_schema(self) -> UiPathRuntimeSchema: |
| 54 | + raise NotImplementedError() |
| 55 | + |
| 56 | + |
| 57 | +class NonStreamingRuntime: |
| 58 | + """Raises UiPathStreamNotSupportedError — forces the execute() fallback path.""" |
| 59 | + |
| 60 | + def __init__(self) -> None: |
| 61 | + self.execute_called = False |
| 62 | + |
| 63 | + async def dispose(self) -> None: |
| 64 | + pass |
| 65 | + |
| 66 | + async def execute( |
| 67 | + self, |
| 68 | + input: dict[str, Any] | None = None, |
| 69 | + options: UiPathExecuteOptions | None = None, |
| 70 | + ) -> UiPathRuntimeResult: |
| 71 | + self.execute_called = True |
| 72 | + return UiPathRuntimeResult( |
| 73 | + status=UiPathRuntimeStatus.SUCCESSFUL, |
| 74 | + output={"mode": "execute"}, |
| 75 | + ) |
| 76 | + |
| 77 | + async def stream( |
| 78 | + self, |
| 79 | + input: dict[str, Any] | None = None, |
| 80 | + options: UiPathStreamOptions | None = None, |
| 81 | + ) -> AsyncGenerator[UiPathRuntimeEvent, None]: |
| 82 | + raise UiPathStreamNotSupportedError("nope") |
| 83 | + yield # pragma: no cover — makes this an async generator |
| 84 | + |
| 85 | + async def get_schema(self) -> UiPathRuntimeSchema: |
| 86 | + raise NotImplementedError() |
| 87 | + |
| 88 | + |
| 89 | +@pytest.mark.asyncio |
| 90 | +async def test_debug_runtime_streams_to_completion_under_detached_bridge(): |
| 91 | + """The detached bridge must not block the runtime's startup wait-for-resume gate.""" |
| 92 | + debug_runtime = UiPathDebugRuntime( |
| 93 | + delegate=TrivialStreamingRuntime(), |
| 94 | + debug_bridge=DetachedDebugBridge(), |
| 95 | + ) |
| 96 | + |
| 97 | + try: |
| 98 | + result = await asyncio.wait_for(debug_runtime.execute({}), timeout=5.0) |
| 99 | + finally: |
| 100 | + await debug_runtime.dispose() |
| 101 | + |
| 102 | + assert isinstance(result, UiPathRuntimeResult) |
| 103 | + assert result.status == UiPathRuntimeStatus.SUCCESSFUL |
| 104 | + assert result.output == {"done": True} |
| 105 | + |
| 106 | + |
| 107 | +@pytest.mark.asyncio |
| 108 | +async def test_debug_runtime_execute_fallback_completes_under_detached_bridge(): |
| 109 | + """Fallback path (stream-unsupported delegates) must also not block.""" |
| 110 | + delegate = NonStreamingRuntime() |
| 111 | + debug_runtime = UiPathDebugRuntime( |
| 112 | + delegate=delegate, |
| 113 | + debug_bridge=DetachedDebugBridge(), |
| 114 | + ) |
| 115 | + |
| 116 | + try: |
| 117 | + result = await asyncio.wait_for(debug_runtime.execute({}), timeout=5.0) |
| 118 | + finally: |
| 119 | + await debug_runtime.dispose() |
| 120 | + |
| 121 | + assert delegate.execute_called is True |
| 122 | + assert result.status == UiPathRuntimeStatus.SUCCESSFUL |
0 commit comments