scalebox-sdk 0.1.4__py3-none-any.whl → 0.1.25__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scalebox/__init__.py +1 -1
- scalebox/api/__init__.py +128 -128
- scalebox/api/client/__init__.py +8 -8
- scalebox/api/client/api/sandboxes/get_sandboxes.py +5 -3
- scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_metrics.py +2 -2
- scalebox/api/client/api/sandboxes/post_sandboxes.py +2 -2
- scalebox/api/client/client.py +288 -288
- scalebox/api/client/models/listed_sandbox.py +11 -9
- scalebox/api/client/models/new_sandbox.py +1 -1
- scalebox/api/client/models/sandbox.py +125 -125
- scalebox/api/client/models/sandbox_state.py +1 -0
- scalebox/api/client/types.py +46 -46
- scalebox/code_interpreter/code_interpreter_async.py +370 -369
- scalebox/code_interpreter/code_interpreter_sync.py +318 -317
- scalebox/connection_config.py +92 -92
- scalebox/csx_desktop/main.py +12 -12
- scalebox/generated/api_pb2_connect.py +17 -66
- scalebox/sandbox_async/commands/command.py +307 -307
- scalebox/sandbox_async/commands/command_handle.py +187 -187
- scalebox/sandbox_async/commands/pty.py +187 -187
- scalebox/sandbox_async/filesystem/filesystem.py +557 -557
- scalebox/sandbox_async/filesystem/watch_handle.py +61 -61
- scalebox/sandbox_async/main.py +647 -646
- scalebox/sandbox_async/sandbox_api.py +365 -365
- scalebox/sandbox_async/utils.py +7 -7
- scalebox/sandbox_sync/__init__.py +2 -2
- scalebox/sandbox_sync/commands/command.py +300 -300
- scalebox/sandbox_sync/commands/command_handle.py +150 -150
- scalebox/sandbox_sync/commands/pty.py +181 -181
- scalebox/sandbox_sync/filesystem/filesystem.py +543 -543
- scalebox/sandbox_sync/filesystem/watch_handle.py +66 -66
- scalebox/sandbox_sync/main.py +789 -790
- scalebox/sandbox_sync/sandbox_api.py +356 -356
- scalebox/test/CODE_INTERPRETER_TESTS_READY.md +256 -256
- scalebox/test/README.md +164 -164
- scalebox/test/aclient.py +72 -72
- scalebox/test/code_interpreter_centext.py +21 -21
- scalebox/test/code_interpreter_centext_sync.py +21 -21
- scalebox/test/code_interpreter_test.py +1 -1
- scalebox/test/code_interpreter_test_sync.py +1 -1
- scalebox/test/run_all_validation_tests.py +334 -334
- scalebox/test/test_basic.py +78 -78
- scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -2653
- scalebox/test/{test_code_interpreter_e2bsync_comprehensive.py → test_code_interpreter_execcode.py} +328 -392
- scalebox/test/test_code_interpreter_sync_comprehensive.py +3416 -3412
- scalebox/test/test_csx_desktop_examples.py +130 -0
- scalebox/test/test_sandbox_async_comprehensive.py +736 -738
- scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -778
- scalebox/test/test_sandbox_sync_comprehensive.py +779 -770
- scalebox/test/test_sandbox_usage_examples.py +987 -987
- scalebox/test/testacreate.py +24 -24
- scalebox/test/testagetinfo.py +18 -18
- scalebox/test/testcodeinterpreter_async.py +508 -508
- scalebox/test/testcodeinterpreter_sync.py +239 -239
- scalebox/test/testcomputeuse.py +2 -2
- scalebox/test/testnovnc.py +12 -12
- scalebox/test/testsandbox_api.py +15 -0
- scalebox/test/testsandbox_async.py +202 -118
- scalebox/test/testsandbox_sync.py +71 -38
- scalebox/version.py +2 -2
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/METADATA +104 -103
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/RECORD +66 -66
- scalebox/test/test_code_interpreter_e2basync_comprehensive.py +0 -2655
- scalebox/test/test_e2b_first.py +0 -11
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/WHEEL +0 -0
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/entry_points.txt +0 -0
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/licenses/LICENSE +0 -0
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import time
|
|
4
|
+
from typing import Callable, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# 确保可以从项目根导入 scalebox
|
|
8
|
+
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
9
|
+
if PROJECT_ROOT not in sys.path:
|
|
10
|
+
sys.path.insert(0, PROJECT_ROOT)
|
|
11
|
+
|
|
12
|
+
from scalebox.csx_desktop.main import Sandbox as DesktopSandbox # noqa: E402
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CsxDesktopValidator:
|
|
16
|
+
def __init__(self) -> None:
|
|
17
|
+
self.desktop: Optional[DesktopSandbox] = None
|
|
18
|
+
self.success_count = 0
|
|
19
|
+
self.fail_count = 0
|
|
20
|
+
|
|
21
|
+
def log_test_result(self, name: str, success: bool, error: Optional[Exception] = None) -> None:
|
|
22
|
+
if success:
|
|
23
|
+
self.success_count += 1
|
|
24
|
+
print(f"✅ {name}")
|
|
25
|
+
else:
|
|
26
|
+
self.fail_count += 1
|
|
27
|
+
print(f"❌ {name}: {error}")
|
|
28
|
+
|
|
29
|
+
def run_test(self, fn: Callable[[], None], name: str) -> None:
|
|
30
|
+
try:
|
|
31
|
+
fn()
|
|
32
|
+
self.log_test_result(name, True)
|
|
33
|
+
except Exception as e:
|
|
34
|
+
self.log_test_result(name, False, e)
|
|
35
|
+
|
|
36
|
+
# ======================== 桌面沙箱基础 ========================
|
|
37
|
+
|
|
38
|
+
def test_desktop_creation_and_stream(self) -> None:
|
|
39
|
+
print("创建桌面沙箱...")
|
|
40
|
+
# 可根据需要设置 template/timeout/debug 等参数
|
|
41
|
+
self.desktop = DesktopSandbox(template="desktop", timeout=1800, debug=True)
|
|
42
|
+
assert self.desktop is not None
|
|
43
|
+
|
|
44
|
+
print("启动VNC流...")
|
|
45
|
+
self.desktop.stream.start()
|
|
46
|
+
url = self.desktop.stream.get_url(auto_connect=True)
|
|
47
|
+
print(f"VNC URL: {url}")
|
|
48
|
+
time.sleep(2)
|
|
49
|
+
|
|
50
|
+
def test_mouse_operations(self) -> None:
|
|
51
|
+
assert self.desktop is not None
|
|
52
|
+
width, height = self.desktop.get_screen_size()
|
|
53
|
+
print(f"屏幕: {width}x{height}")
|
|
54
|
+
|
|
55
|
+
cx, cy = width // 2, height // 2
|
|
56
|
+
self.desktop.move_mouse(cx, cy)
|
|
57
|
+
x, y = self.desktop.get_cursor_position()
|
|
58
|
+
print(f"光标: ({x}, {y})")
|
|
59
|
+
|
|
60
|
+
self.desktop.left_click(cx, cy)
|
|
61
|
+
self.desktop.right_click(min(cx + 100, width - 1), cy)
|
|
62
|
+
self.desktop.double_click(cx, min(cy + 100, height - 1))
|
|
63
|
+
self.desktop.drag((cx, cy), (min(cx + 120, width - 1), cy))
|
|
64
|
+
self.desktop.scroll("down", 1)
|
|
65
|
+
self.desktop.scroll("up", 1)
|
|
66
|
+
|
|
67
|
+
def test_keyboard_and_terminal(self) -> None:
|
|
68
|
+
assert self.desktop is not None
|
|
69
|
+
print("启动终端并执行命令...")
|
|
70
|
+
self.desktop.launch("xfce4-terminal")
|
|
71
|
+
time.sleep(2)
|
|
72
|
+
|
|
73
|
+
win = self.desktop.get_current_window_id()
|
|
74
|
+
print(f"当前窗口: {win}")
|
|
75
|
+
|
|
76
|
+
self.desktop.write("echo 'Hello from csx_desktop' && uname -a")
|
|
77
|
+
self.desktop.press("enter")
|
|
78
|
+
time.sleep(1)
|
|
79
|
+
|
|
80
|
+
# 新建标签页
|
|
81
|
+
self.desktop.press("ctrl+shift+t")
|
|
82
|
+
time.sleep(0.5)
|
|
83
|
+
self.desktop.write("ls -la ~")
|
|
84
|
+
self.desktop.press("enter")
|
|
85
|
+
|
|
86
|
+
def test_app_launch_and_navigation(self) -> None:
|
|
87
|
+
assert self.desktop is not None
|
|
88
|
+
print("启动文件管理器...")
|
|
89
|
+
# 尝试启动 Thunar(常见于 XFCE)
|
|
90
|
+
self.desktop.launch("thunar")
|
|
91
|
+
time.sleep(2)
|
|
92
|
+
|
|
93
|
+
# 通过键盘导航示例
|
|
94
|
+
self.desktop.press("tab")
|
|
95
|
+
self.desktop.press("down")
|
|
96
|
+
self.desktop.press("down")
|
|
97
|
+
self.desktop.press("enter")
|
|
98
|
+
time.sleep(1)
|
|
99
|
+
|
|
100
|
+
def cleanup(self) -> None:
|
|
101
|
+
if self.desktop is None:
|
|
102
|
+
return
|
|
103
|
+
print("停止VNC流并清理...")
|
|
104
|
+
try:
|
|
105
|
+
self.desktop.stream.stop()
|
|
106
|
+
except Exception as e:
|
|
107
|
+
print(f"停止VNC流失败: {e}")
|
|
108
|
+
# 如果需要,可在此添加更多清理逻辑(如关闭应用、结束会话等)
|
|
109
|
+
|
|
110
|
+
def print_summary(self) -> None:
|
|
111
|
+
total = self.success_count + self.fail_count
|
|
112
|
+
print("\n===== csx_desktop 示例汇总 =====")
|
|
113
|
+
print(f"总计: {total}, 成功: {self.success_count}, 失败: {self.fail_count}")
|
|
114
|
+
|
|
115
|
+
def run_all(self) -> None:
|
|
116
|
+
self.run_test(self.test_desktop_creation_and_stream, "创建桌面沙箱并启动VNC流")
|
|
117
|
+
self.run_test(self.test_mouse_operations, "鼠标操作示例")
|
|
118
|
+
self.run_test(self.test_keyboard_and_terminal, "键盘与终端示例")
|
|
119
|
+
self.run_test(self.test_app_launch_and_navigation, "应用启动与导航示例")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
if __name__ == "__main__":
|
|
123
|
+
validator = CsxDesktopValidator()
|
|
124
|
+
try:
|
|
125
|
+
validator.run_all()
|
|
126
|
+
finally:
|
|
127
|
+
validator.cleanup()
|
|
128
|
+
validator.print_summary()
|
|
129
|
+
|
|
130
|
+
|