Skip to content

Commit 7dec553

Browse files
authored
feat(core): add workspace hydration service protocols (#1744)
1 parent 9038bc6 commit 7dec553

8 files changed

Lines changed: 136 additions & 4 deletions

File tree

packages/uipath-core/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-core"
3-
version = "0.5.21"
3+
version = "0.5.22"
44
description = "UiPath Core abstractions"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""UiPath workspace hydration shared contracts."""
2+
3+
from .protocols import AttachmentsProtocol, JobsProtocol
4+
5+
__all__ = [
6+
"AttachmentsProtocol",
7+
"JobsProtocol",
8+
]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Service protocols for workspace hydration backend interactions."""
2+
3+
from __future__ import annotations
4+
5+
from typing import Protocol, runtime_checkable
6+
from uuid import UUID
7+
8+
9+
@runtime_checkable
10+
class AttachmentsProtocol(Protocol):
11+
"""Subset of the UiPath attachments service used by workspace hydration."""
12+
13+
async def download_async(
14+
self,
15+
*,
16+
key: UUID,
17+
destination_path: str,
18+
folder_key: str | None = None,
19+
folder_path: str | None = None,
20+
) -> str:
21+
"""Download an attachment to a local path."""
22+
23+
async def upload_async(
24+
self,
25+
*,
26+
name: str,
27+
content: str | bytes | None = None,
28+
source_path: str | None = None,
29+
folder_key: str | None = None,
30+
folder_path: str | None = None,
31+
) -> UUID:
32+
"""Upload content or a local file and return its attachment key."""
33+
34+
35+
@runtime_checkable
36+
class JobsProtocol(Protocol):
37+
"""Subset of the UiPath jobs service used by workspace hydration."""
38+
39+
async def list_attachments_async(
40+
self,
41+
*,
42+
job_key: UUID,
43+
folder_key: str | None = None,
44+
folder_path: str | None = None,
45+
) -> list[str]:
46+
"""List the attachment ids linked to a job."""
47+
48+
async def link_attachment_async(
49+
self,
50+
*,
51+
job_key: UUID,
52+
attachment_key: UUID,
53+
folder_key: str | None = None,
54+
folder_path: str | None = None,
55+
) -> None:
56+
"""Link an existing attachment to a job."""

packages/uipath-core/tests/workspace/__init__.py

Whitespace-only changes.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""Structural-conformance tests for the workspace hydration protocols."""
2+
3+
from __future__ import annotations
4+
5+
from uuid import UUID, uuid4
6+
7+
from uipath.core.workspace import AttachmentsProtocol, JobsProtocol
8+
9+
10+
class _FakeAttachments:
11+
async def download_async(
12+
self,
13+
*,
14+
key: UUID,
15+
destination_path: str,
16+
folder_key: str | None = None,
17+
folder_path: str | None = None,
18+
) -> str:
19+
return destination_path
20+
21+
async def upload_async(
22+
self,
23+
*,
24+
name: str,
25+
content: str | bytes | None = None,
26+
source_path: str | None = None,
27+
folder_key: str | None = None,
28+
folder_path: str | None = None,
29+
) -> UUID:
30+
return uuid4()
31+
32+
33+
class _FakeJobs:
34+
async def list_attachments_async(
35+
self,
36+
*,
37+
job_key: UUID,
38+
folder_key: str | None = None,
39+
folder_path: str | None = None,
40+
) -> list[str]:
41+
return []
42+
43+
async def link_attachment_async(
44+
self,
45+
*,
46+
job_key: UUID,
47+
attachment_key: UUID,
48+
folder_key: str | None = None,
49+
folder_path: str | None = None,
50+
) -> None:
51+
return None
52+
53+
54+
class _NotAService:
55+
pass
56+
57+
58+
def test_attachments_service_satisfies_protocol() -> None:
59+
assert isinstance(_FakeAttachments(), AttachmentsProtocol)
60+
61+
62+
def test_jobs_service_satisfies_protocol() -> None:
63+
assert isinstance(_FakeJobs(), JobsProtocol)
64+
65+
66+
def test_unrelated_object_does_not_satisfy_protocols() -> None:
67+
assert not isinstance(_NotAService(), AttachmentsProtocol)
68+
assert not isinstance(_NotAService(), JobsProtocol)

packages/uipath-core/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.

packages/uipath-platform/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.

packages/uipath/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)