|
| 1 | +"""Protocol conformance for uipath-runtime protocol implementations. |
| 2 | +
|
| 3 | +Every protocol-annotated assignment below is a typed boundary: mypy verifies |
| 4 | +the implementation against the protocol surface of the installed |
| 5 | +uipath-runtime version. A dependency bump that adds or changes protocol |
| 6 | +members fails typecheck on these lines until the implementations catch up. |
| 7 | +
|
| 8 | +The wiring mirrors UiPathLangGraphRuntimeFactory._create_runtime_instance, |
| 9 | +so the exact production composition is what gets checked. Deliberately |
| 10 | +construction-only: no runtime behavior is exercised here. |
| 11 | +""" |
| 12 | + |
| 13 | +from typing import TypedDict |
| 14 | + |
| 15 | +from langgraph.checkpoint.sqlite.aio import AsyncSqliteSaver |
| 16 | +from langgraph.graph import END, START, StateGraph |
| 17 | +from uipath.platform.resume_triggers import UiPathResumeTriggerHandler |
| 18 | +from uipath.runtime import ( |
| 19 | + UiPathResumableRuntime, |
| 20 | + UiPathResumableStorageProtocol, |
| 21 | + UiPathResumeTriggerProtocol, |
| 22 | + UiPathRuntimeContext, |
| 23 | + UiPathRuntimeFactoryProtocol, |
| 24 | + UiPathRuntimeProtocol, |
| 25 | +) |
| 26 | + |
| 27 | +from uipath_langchain.runtime.factory import UiPathLangGraphRuntimeFactory |
| 28 | +from uipath_langchain.runtime.runtime import UiPathLangGraphRuntime |
| 29 | +from uipath_langchain.runtime.storage import SqliteResumableStorage |
| 30 | + |
| 31 | + |
| 32 | +class _State(TypedDict, total=False): |
| 33 | + value: str |
| 34 | + |
| 35 | + |
| 36 | +async def test_langgraph_wiring_satisfies_runtime_protocols() -> None: |
| 37 | + graph = StateGraph(_State) |
| 38 | + graph.add_node("noop", lambda state: state) |
| 39 | + graph.add_edge(START, "noop") |
| 40 | + graph.add_edge("noop", END) |
| 41 | + |
| 42 | + async with AsyncSqliteSaver.from_conn_string(":memory:") as memory: |
| 43 | + compiled_graph = graph.compile(checkpointer=memory) |
| 44 | + |
| 45 | + delegate: UiPathRuntimeProtocol = UiPathLangGraphRuntime( |
| 46 | + graph=compiled_graph, |
| 47 | + runtime_id="protocol-conformance-test", |
| 48 | + entrypoint="test", |
| 49 | + ) |
| 50 | + storage: UiPathResumableStorageProtocol = SqliteResumableStorage(memory) |
| 51 | + trigger_manager: UiPathResumeTriggerProtocol = UiPathResumeTriggerHandler() |
| 52 | + |
| 53 | + runtime: UiPathRuntimeProtocol = UiPathResumableRuntime( |
| 54 | + delegate=delegate, |
| 55 | + storage=storage, |
| 56 | + trigger_manager=trigger_manager, |
| 57 | + runtime_id="protocol-conformance-test", |
| 58 | + ) |
| 59 | + |
| 60 | + assert runtime is not None |
| 61 | + |
| 62 | + |
| 63 | +def test_langgraph_factory_satisfies_factory_protocol() -> None: |
| 64 | + factory: UiPathRuntimeFactoryProtocol = UiPathLangGraphRuntimeFactory( |
| 65 | + context=UiPathRuntimeContext() |
| 66 | + ) |
| 67 | + |
| 68 | + assert factory is not None |
0 commit comments