Skip to content

Commit 2226c4f

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

File tree

4 files changed

+84
-3
lines changed

4 files changed

+84
-3
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: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from typing import Any, AsyncGenerator
2+
3+
import pytest
4+
5+
from uipath.runtime.base 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(status="success", 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(status="success", output={})
32+
33+
async def get_schema(self) -> UiPathRuntimeSchema:
34+
return UiPathRuntimeSchema(
35+
entrypoint_type="test", input_schema={}, output_schema={}
36+
)
37+
38+
async def dispose(self) -> None:
39+
pass
40+
41+
42+
class CreatorWithoutKwargs:
43+
"""Implementation without kwargs."""
44+
45+
async def new_runtime(
46+
self, entrypoint: str, runtime_id: str
47+
) -> UiPathRuntimeProtocol:
48+
return MockRuntime()
49+
50+
51+
class CreatorWithKwargs:
52+
"""Implementation with kwargs."""
53+
54+
async def new_runtime(
55+
self, entrypoint: str, runtime_id: str, **kwargs
56+
) -> UiPathRuntimeProtocol:
57+
return MockRuntime()
58+
59+
60+
@pytest.mark.asyncio
61+
async def test_protocol_works_without_kwargs():
62+
"""Test protocol works with implementation that doesn't have kwargs."""
63+
creator: UiPathRuntimeCreatorProtocol = CreatorWithoutKwargs()
64+
runtime = await creator.new_runtime("main.py", "runtime-123")
65+
assert isinstance(runtime, MockRuntime)
66+
67+
68+
@pytest.mark.asyncio
69+
async def test_protocol_works_with_kwargs_not_specified():
70+
"""Test protocol works with implementation that has kwargs."""
71+
creator: UiPathRuntimeCreatorProtocol = CreatorWithKwargs()
72+
runtime = await creator.new_runtime("main.py", "runtime-123")
73+
assert isinstance(runtime, MockRuntime)
74+
75+
76+
@pytest.mark.asyncio
77+
async def test_protocol_works_with_kwargs_specified():
78+
"""Test protocol works with implementation that has kwargs."""
79+
creator: UiPathRuntimeCreatorProtocol = CreatorWithKwargs()
80+
runtime = await creator.new_runtime("main.py", "runtime-123", timeout=30)
81+
assert isinstance(runtime, MockRuntime)

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)