-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate_server.py
More file actions
148 lines (108 loc) · 4.14 KB
/
Copy pathvalidate_server.py
File metadata and controls
148 lines (108 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""Validate the server module: imports, app creation, and API structure.
Run with: uv run python scripts/validate_server.py
"""
from __future__ import annotations
import sys
def _check(label: str, fn):
"""Run a check function and report pass/fail."""
try:
fn()
print(f" PASS {label}")
return True
except Exception as e:
print(f" FAIL {label}: {e}")
return False
def check_model_imports():
"""Verify plain data classes import without Textual dependency."""
from uipath.dev.models.data import ChatData, LogData, TraceData
assert LogData is not None
assert TraceData is not None
assert ChatData is not None
def check_server_import():
"""Verify UiPathDeveloperServer imports."""
from uipath.dev.server import UiPathDeveloperServer
assert UiPathDeveloperServer is not None
def check_serializers():
"""Verify serializers produce valid dicts."""
from datetime import datetime
from uipath.dev.models.data import LogData, TraceData
from uipath.dev.server.serializers import serialize_log, serialize_trace
log = LogData(
run_id="test-1", level="INFO", message="hello", timestamp=datetime.now()
)
result = serialize_log(log)
assert isinstance(result, dict)
assert result["run_id"] == "test-1"
assert "timestamp" in result
trace = TraceData(
run_id="test-1",
span_name="agent",
span_id="span-1",
timestamp=datetime.now(),
)
result = serialize_trace(trace)
assert isinstance(result, dict)
assert result["span_name"] == "agent"
def check_ws_protocol():
"""Verify WebSocket protocol enums."""
from uipath.dev.server.ws.protocol import ClientCommand, ServerEvent
assert ServerEvent.RUN_UPDATED.value == "run.updated"
assert ServerEvent.LOG.value == "log"
assert ServerEvent.TRACE.value == "trace"
assert ServerEvent.CHAT.value == "chat"
assert ClientCommand.SUBSCRIBE.value == "subscribe"
assert ClientCommand.CHAT_MESSAGE.value == "chat.message"
def check_connection_manager():
"""Verify ConnectionManager instantiates."""
from uipath.dev.server.ws.manager import ConnectionManager
mgr = ConnectionManager()
assert mgr is not None
def check_frontend_build_module():
"""Verify frontend_build module loads and functions exist."""
from uipath.dev.server.frontend_build import (
ensure_frontend_built,
needs_build,
)
assert callable(needs_build)
assert callable(ensure_frontend_built)
def check_app_factory():
"""Verify FastAPI app can be created (with a mock server)."""
from unittest.mock import MagicMock
from uipath.dev.server.app import create_app
mock_server = MagicMock()
mock_server.run_service = MagicMock()
mock_server.connection_manager = MagicMock()
mock_server.runtime_factory = MagicMock()
mock_server.runtime_factory.list_entrypoints.return_value = []
app = create_app(mock_server)
assert app is not None
assert app.title == "UiPath Developer Server"
# Verify routes are registered
route_paths = [getattr(route, "path", "") for route in app.routes]
assert "/api/entrypoints" in route_paths
assert "/api/runs" in route_paths
def main():
"""Run server module validation checks."""
print("=" * 60)
print("Server Module Validation")
print("=" * 60)
checks = [
("Plain data model imports (no Textual dep)", check_model_imports),
("UiPathDeveloperServer import", check_server_import),
("Serializers produce valid JSON dicts", check_serializers),
("WebSocket protocol enums", check_ws_protocol),
("ConnectionManager instantiation", check_connection_manager),
("Frontend build module loads", check_frontend_build_module),
("FastAPI app factory creates app with routes", check_app_factory),
]
results = [_check(label, fn) for label, fn in checks]
print("=" * 60)
passed = sum(results)
total = len(results)
print(f"Results: {passed}/{total} passed")
if passed < total:
sys.exit(1)
else:
print("All checks passed!")
if __name__ == "__main__":
main()