Skip to content

Commit abeb0db

Browse files
committed
fix: add factory new runtime kwargs
1 parent 01ec08b commit abeb0db

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-runtime"
3-
version = "0.3.4"
3+
version = "0.4.0"
44
description = "Runtime abstractions and interfaces for building agents and automation scripts in the UiPath ecosystem"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

src/uipath/runtime/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class UiPathRuntimeCreatorProtocol(Protocol):
2121
"""Protocol for creating a UiPath runtime given an entrypoint."""
2222

2323
async def new_runtime(
24-
self, entrypoint: str, runtime_id: str
24+
self, entrypoint: str, runtime_id: str, **kwargs
2525
) -> UiPathRuntimeProtocol:
2626
"""Create a new runtime instance."""
2727
...

tests/test_factory.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from typing import Any, AsyncGenerator
2+
3+
import pytest
4+
5+
from uipath.runtime import (
6+
UiPathExecuteOptions,
7+
UiPathRuntimeEvent,
8+
UiPathRuntimeProtocol,
9+
UiPathRuntimeResult,
10+
UiPathRuntimeSchema,
11+
UiPathStreamOptions,
12+
)
13+
from uipath.runtime.factory import UiPathRuntimeCreatorProtocol
14+
15+
16+
class MockRuntime:
17+
"""Mock runtime that implements UiPathRuntimeProtocol."""
18+
19+
async def execute(
20+
self,
21+
input: dict[str, Any] | None = None,
22+
options: UiPathExecuteOptions | None = None,
23+
) -> UiPathRuntimeResult:
24+
return UiPathRuntimeResult(output={})
25+
26+
async def stream(
27+
self,
28+
input: dict[str, Any] | None = None,
29+
options: UiPathStreamOptions | None = None,
30+
) -> AsyncGenerator[UiPathRuntimeEvent, None]:
31+
yield UiPathRuntimeResult(output={})
32+
33+
async def get_schema(self) -> UiPathRuntimeSchema:
34+
return UiPathRuntimeSchema(
35+
filePath="agent.json",
36+
type="agent",
37+
uniqueId="unique-id",
38+
input={},
39+
output={},
40+
)
41+
42+
async def dispose(self) -> None:
43+
pass
44+
45+
46+
class CreatorWithKwargs:
47+
"""Implementation with kwargs."""
48+
49+
async def new_runtime(
50+
self, entrypoint: str, runtime_id: str, **kwargs
51+
) -> UiPathRuntimeProtocol:
52+
return MockRuntime()
53+
54+
55+
@pytest.mark.asyncio
56+
async def test_protocol_works_with_kwargs_not_specified():
57+
"""Test protocol works with implementation that has kwargs."""
58+
creator: UiPathRuntimeCreatorProtocol = CreatorWithKwargs()
59+
runtime = await creator.new_runtime("main.py", "runtime-123")
60+
assert isinstance(runtime, MockRuntime)
61+
62+
63+
@pytest.mark.asyncio
64+
async def test_protocol_works_with_kwargs_specified():
65+
"""Test protocol works with implementation that has kwargs."""
66+
creator: UiPathRuntimeCreatorProtocol = CreatorWithKwargs()
67+
runtime = await creator.new_runtime("main.py", "runtime-123", timeout=30)
68+
assert isinstance(runtime, MockRuntime)

tests/test_registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def discover_runtimes(self) -> list[UiPathRuntimeProtocol]:
6363
return []
6464

6565
async def new_runtime(
66-
self, entrypoint: str, runtime_id: str
66+
self, entrypoint: str, runtime_id: str, **kwargs
6767
) -> UiPathRuntimeProtocol:
6868
return cast(UiPathRuntimeProtocol, MockRuntime(f"functions-{entrypoint}"))
6969

@@ -85,7 +85,7 @@ async def discover_runtimes(self) -> list[UiPathRuntimeProtocol]:
8585
return []
8686

8787
async def new_runtime(
88-
self, entrypoint: str, runtime_id: str
88+
self, entrypoint: str, runtime_id: str, **kwargs
8989
) -> UiPathRuntimeProtocol:
9090
return cast(UiPathRuntimeProtocol, MockRuntime(f"langgraph-{entrypoint}"))
9191

@@ -107,7 +107,7 @@ async def discover_runtimes(self) -> list[UiPathRuntimeProtocol]:
107107
return []
108108

109109
async def new_runtime(
110-
self, entrypoint: str, runtime_id: str
110+
self, entrypoint: str, runtime_id: str, **kwargs
111111
) -> UiPathRuntimeProtocol:
112112
return cast(UiPathRuntimeProtocol, MockRuntime(f"llamaindex-{entrypoint}"))
113113

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)