scalebox-sdk 0.1.12__py3-none-any.whl → 0.1.13__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.
Files changed (34) hide show
  1. scalebox/__init__.py +1 -1
  2. scalebox/test/aclient.py +72 -72
  3. scalebox/test/code_interpreter_centext.py +21 -21
  4. scalebox/test/code_interpreter_centext_sync.py +21 -21
  5. scalebox/test/code_interpreter_test.py +34 -34
  6. scalebox/test/code_interpreter_test_sync.py +34 -34
  7. scalebox/test/run_all_validation_tests.py +334 -334
  8. scalebox/test/test_basic.py +78 -78
  9. scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -2653
  10. scalebox/test/test_code_interpreter_e2basync_comprehensive.py +2655 -2655
  11. scalebox/test/test_code_interpreter_e2bsync_comprehensive.py +3416 -3416
  12. scalebox/test/test_code_interpreter_execcode.py +3352 -0
  13. scalebox/test/test_code_interpreter_sync_comprehensive.py +3416 -3412
  14. scalebox/test/test_csx_desktop_examples.py +130 -0
  15. scalebox/test/test_e2b_first.py +11 -11
  16. scalebox/test/test_sandbox_async_comprehensive.py +736 -738
  17. scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -778
  18. scalebox/test/test_sandbox_sync_comprehensive.py +779 -770
  19. scalebox/test/test_sandbox_usage_examples.py +987 -987
  20. scalebox/test/testacreate.py +24 -24
  21. scalebox/test/testagetinfo.py +18 -18
  22. scalebox/test/testcodeinterpreter_async.py +508 -508
  23. scalebox/test/testcodeinterpreter_sync.py +239 -239
  24. scalebox/test/testcomputeuse.py +245 -243
  25. scalebox/test/testnovnc.py +12 -12
  26. scalebox/test/testsandbox_async.py +202 -118
  27. scalebox/test/testsandbox_sync.py +71 -38
  28. scalebox/version.py +2 -2
  29. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/METADATA +1 -1
  30. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/RECORD +34 -32
  31. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/WHEEL +0 -0
  32. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/entry_points.txt +0 -0
  33. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/licenses/LICENSE +0 -0
  34. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.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
+
@@ -1,11 +1,11 @@
1
- from dotenv import load_dotenv
2
-
3
- load_dotenv()
4
- from e2b_code_interpreter import Sandbox
5
-
6
- sbx = Sandbox.create() # By default the sandbox is alive for 5 minutes
7
- execution = sbx.run_code("print('hello world')") # Execute Python inside the sandbox
8
- print(execution)
9
-
10
- files = sbx.files.list("/")
11
- print(files)
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv()
4
+ from e2b_code_interpreter import Sandbox
5
+
6
+ sbx = Sandbox.create() # By default the sandbox is alive for 5 minutes
7
+ execution = sbx.run_code("print('hello world')") # Execute Python inside the sandbox
8
+ print(execution)
9
+
10
+ files = sbx.files.list("/")
11
+ print(files)