scalebox-sdk 0.1.0__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 (157) hide show
  1. scalebox/__init__.py +80 -0
  2. scalebox/api/__init__.py +128 -0
  3. scalebox/api/client/__init__.py +8 -0
  4. scalebox/api/client/api/__init__.py +1 -0
  5. scalebox/api/client/api/sandboxes/__init__.py +0 -0
  6. scalebox/api/client/api/sandboxes/delete_sandboxes_sandbox_id.py +161 -0
  7. scalebox/api/client/api/sandboxes/get_sandboxes.py +176 -0
  8. scalebox/api/client/api/sandboxes/get_sandboxes_metrics.py +173 -0
  9. scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id.py +163 -0
  10. scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_logs.py +199 -0
  11. scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_metrics.py +214 -0
  12. scalebox/api/client/api/sandboxes/get_v2_sandboxes.py +229 -0
  13. scalebox/api/client/api/sandboxes/post_sandboxes.py +174 -0
  14. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_pause.py +165 -0
  15. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_refreshes.py +182 -0
  16. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_resume.py +190 -0
  17. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_timeout.py +194 -0
  18. scalebox/api/client/client.py +288 -0
  19. scalebox/api/client/errors.py +16 -0
  20. scalebox/api/client/models/__init__.py +81 -0
  21. scalebox/api/client/models/build_log_entry.py +79 -0
  22. scalebox/api/client/models/created_access_token.py +100 -0
  23. scalebox/api/client/models/created_team_api_key.py +166 -0
  24. scalebox/api/client/models/error.py +67 -0
  25. scalebox/api/client/models/identifier_masking_details.py +83 -0
  26. scalebox/api/client/models/listed_sandbox.py +138 -0
  27. scalebox/api/client/models/log_level.py +11 -0
  28. scalebox/api/client/models/new_access_token.py +59 -0
  29. scalebox/api/client/models/new_sandbox.py +125 -0
  30. scalebox/api/client/models/new_team_api_key.py +59 -0
  31. scalebox/api/client/models/node.py +154 -0
  32. scalebox/api/client/models/node_detail.py +152 -0
  33. scalebox/api/client/models/node_status.py +11 -0
  34. scalebox/api/client/models/node_status_change.py +61 -0
  35. scalebox/api/client/models/post_sandboxes_sandbox_id_refreshes_body.py +59 -0
  36. scalebox/api/client/models/post_sandboxes_sandbox_id_timeout_body.py +59 -0
  37. scalebox/api/client/models/resumed_sandbox.py +68 -0
  38. scalebox/api/client/models/sandbox.py +125 -0
  39. scalebox/api/client/models/sandbox_detail.py +178 -0
  40. scalebox/api/client/models/sandbox_log.py +70 -0
  41. scalebox/api/client/models/sandbox_logs.py +73 -0
  42. scalebox/api/client/models/sandbox_metric.py +110 -0
  43. scalebox/api/client/models/sandbox_state.py +9 -0
  44. scalebox/api/client/models/sandboxes_with_metrics.py +59 -0
  45. scalebox/api/client/models/team.py +83 -0
  46. scalebox/api/client/models/team_api_key.py +158 -0
  47. scalebox/api/client/models/team_user.py +68 -0
  48. scalebox/api/client/models/template.py +179 -0
  49. scalebox/api/client/models/template_build.py +117 -0
  50. scalebox/api/client/models/template_build_file_upload.py +70 -0
  51. scalebox/api/client/models/template_build_request.py +115 -0
  52. scalebox/api/client/models/template_build_request_v2.py +88 -0
  53. scalebox/api/client/models/template_build_start_v2.py +114 -0
  54. scalebox/api/client/models/template_build_status.py +11 -0
  55. scalebox/api/client/models/template_step.py +91 -0
  56. scalebox/api/client/models/template_update_request.py +59 -0
  57. scalebox/api/client/models/update_team_api_key.py +59 -0
  58. scalebox/api/client/py.typed +1 -0
  59. scalebox/api/client/types.py +46 -0
  60. scalebox/api/metadata.py +19 -0
  61. scalebox/cli.py +125 -0
  62. scalebox/client/__init__.py +0 -0
  63. scalebox/client/aclient.py +57 -0
  64. scalebox/client/api.proto +460 -0
  65. scalebox/client/buf.gen.yaml +8 -0
  66. scalebox/client/client.py +102 -0
  67. scalebox/client/requirements.txt +5 -0
  68. scalebox/code_interpreter/__init__.py +12 -0
  69. scalebox/code_interpreter/charts.py +230 -0
  70. scalebox/code_interpreter/code_interpreter_async.py +369 -0
  71. scalebox/code_interpreter/code_interpreter_sync.py +317 -0
  72. scalebox/code_interpreter/constants.py +3 -0
  73. scalebox/code_interpreter/exceptions.py +13 -0
  74. scalebox/code_interpreter/models.py +485 -0
  75. scalebox/connection_config.py +92 -0
  76. scalebox/csx_connect/__init__.py +1 -0
  77. scalebox/csx_connect/client.py +485 -0
  78. scalebox/csx_desktop/__init__.py +0 -0
  79. scalebox/csx_desktop/main.py +651 -0
  80. scalebox/exceptions.py +83 -0
  81. scalebox/generated/__init__.py +0 -0
  82. scalebox/generated/api.py +61 -0
  83. scalebox/generated/api_pb2.py +203 -0
  84. scalebox/generated/api_pb2.pyi +956 -0
  85. scalebox/generated/api_pb2_connect.py +1456 -0
  86. scalebox/generated/rpc.py +50 -0
  87. scalebox/generated/versions.py +3 -0
  88. scalebox/requirements.txt +36 -0
  89. scalebox/sandbox/__init__.py +0 -0
  90. scalebox/sandbox/commands/__init__.py +0 -0
  91. scalebox/sandbox/commands/command_handle.py +69 -0
  92. scalebox/sandbox/commands/main.py +39 -0
  93. scalebox/sandbox/filesystem/__init__.py +0 -0
  94. scalebox/sandbox/filesystem/filesystem.py +95 -0
  95. scalebox/sandbox/filesystem/watch_handle.py +60 -0
  96. scalebox/sandbox/main.py +139 -0
  97. scalebox/sandbox/sandbox_api.py +91 -0
  98. scalebox/sandbox/signature.py +40 -0
  99. scalebox/sandbox/utils.py +34 -0
  100. scalebox/sandbox_async/__init__.py +1 -0
  101. scalebox/sandbox_async/commands/command.py +307 -0
  102. scalebox/sandbox_async/commands/command_handle.py +187 -0
  103. scalebox/sandbox_async/commands/pty.py +187 -0
  104. scalebox/sandbox_async/filesystem/filesystem.py +557 -0
  105. scalebox/sandbox_async/filesystem/watch_handle.py +61 -0
  106. scalebox/sandbox_async/main.py +646 -0
  107. scalebox/sandbox_async/sandbox_api.py +365 -0
  108. scalebox/sandbox_async/utils.py +7 -0
  109. scalebox/sandbox_sync/__init__.py +2 -0
  110. scalebox/sandbox_sync/commands/__init__.py +0 -0
  111. scalebox/sandbox_sync/commands/command.py +300 -0
  112. scalebox/sandbox_sync/commands/command_handle.py +150 -0
  113. scalebox/sandbox_sync/commands/pty.py +181 -0
  114. scalebox/sandbox_sync/filesystem/__init__.py +0 -0
  115. scalebox/sandbox_sync/filesystem/filesystem.py +543 -0
  116. scalebox/sandbox_sync/filesystem/watch_handle.py +66 -0
  117. scalebox/sandbox_sync/main.py +790 -0
  118. scalebox/sandbox_sync/sandbox_api.py +356 -0
  119. scalebox/test/CODE_INTERPRETER_TESTS_READY.md +323 -0
  120. scalebox/test/README.md +329 -0
  121. scalebox/test/__init__.py +0 -0
  122. scalebox/test/aclient.py +72 -0
  123. scalebox/test/code_interpreter_centext.py +21 -0
  124. scalebox/test/code_interpreter_centext_sync.py +21 -0
  125. scalebox/test/code_interpreter_test.py +34 -0
  126. scalebox/test/code_interpreter_test_sync.py +34 -0
  127. scalebox/test/run_all_validation_tests.py +334 -0
  128. scalebox/test/run_code_interpreter_tests.sh +67 -0
  129. scalebox/test/run_tests.sh +230 -0
  130. scalebox/test/test_basic.py +78 -0
  131. scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -0
  132. scalebox/test/test_code_interpreter_e2basync_comprehensive.py +2655 -0
  133. scalebox/test/test_code_interpreter_e2bsync_comprehensive.py +3416 -0
  134. scalebox/test/test_code_interpreter_sync_comprehensive.py +3412 -0
  135. scalebox/test/test_e2b_first.py +11 -0
  136. scalebox/test/test_sandbox_async_comprehensive.py +738 -0
  137. scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -0
  138. scalebox/test/test_sandbox_sync_comprehensive.py +770 -0
  139. scalebox/test/test_sandbox_usage_examples.py +987 -0
  140. scalebox/test/testacreate.py +24 -0
  141. scalebox/test/testagetinfo.py +18 -0
  142. scalebox/test/testcodeinterpreter_async.py +508 -0
  143. scalebox/test/testcodeinterpreter_sync.py +239 -0
  144. scalebox/test/testcomputeuse.py +243 -0
  145. scalebox/test/testnovnc.py +12 -0
  146. scalebox/test/testsandbox_async.py +118 -0
  147. scalebox/test/testsandbox_sync.py +38 -0
  148. scalebox/utils/__init__.py +0 -0
  149. scalebox/utils/httpcoreclient.py +297 -0
  150. scalebox/utils/httpxclient.py +403 -0
  151. scalebox/version.py +16 -0
  152. scalebox_sdk-0.1.0.dist-info/METADATA +292 -0
  153. scalebox_sdk-0.1.0.dist-info/RECORD +157 -0
  154. scalebox_sdk-0.1.0.dist-info/WHEEL +5 -0
  155. scalebox_sdk-0.1.0.dist-info/entry_points.txt +2 -0
  156. scalebox_sdk-0.1.0.dist-info/licenses/LICENSE +21 -0
  157. scalebox_sdk-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,334 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ 统一的测试运行器 - 运行所有沙箱验证测试
4
+
5
+ 这个脚本会依次运行所有的验证测试,并生成综合报告。
6
+ 支持选择性运行特定测试套件,并提供详细的性能和结果统计。
7
+ """
8
+
9
+ import asyncio
10
+ import logging
11
+ import os
12
+ import sys
13
+ import time
14
+ import traceback
15
+ from pathlib import Path
16
+ from typing import Any, Dict, List
17
+
18
+ # 添加项目根目录到Python路径
19
+ project_root = Path(__file__).parent.parent
20
+ sys.path.insert(0, str(project_root))
21
+
22
+ # 配置日志
23
+ logging.basicConfig(
24
+ level=logging.INFO,
25
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
26
+ handlers=[
27
+ logging.StreamHandler(),
28
+ logging.FileHandler("/home/ubuntu/git_home/scalebox/test/test_results.log"),
29
+ ],
30
+ )
31
+ logger = logging.getLogger(__name__)
32
+
33
+
34
+ class TestSuiteRunner:
35
+ """测试套件运行器"""
36
+
37
+ def __init__(self):
38
+ self.results: Dict[str, Dict[str, Any]] = {}
39
+ self.total_start_time = time.time()
40
+
41
+ def run_test_module(self, module_name: str, description: str) -> Dict[str, Any]:
42
+ """运行单个测试模块"""
43
+ logger.info(f"\n{'='*60}")
44
+ logger.info(f"开始运行: {description}")
45
+ logger.info(f"模块: {module_name}")
46
+ logger.info(f"{'='*60}")
47
+
48
+ start_time = time.time()
49
+ result = {
50
+ "module": module_name,
51
+ "description": description,
52
+ "success": False,
53
+ "duration": 0,
54
+ "error": None,
55
+ "details": {},
56
+ }
57
+
58
+ try:
59
+ if module_name == "test_sandbox_async_comprehensive":
60
+ from test_sandbox_async_comprehensive import AsyncSandboxValidator
61
+
62
+ validator = AsyncSandboxValidator()
63
+ asyncio.run(validator.run_all_tests())
64
+ result["details"] = {
65
+ "total_tests": len(validator.test_results),
66
+ "passed": sum(1 for r in validator.test_results if r["success"]),
67
+ "failed": len(validator.failed_tests),
68
+ "test_results": validator.test_results,
69
+ }
70
+
71
+ elif module_name == "test_sandbox_sync_comprehensive":
72
+ from test_sandbox_sync_comprehensive import SandboxValidator
73
+
74
+ validator = SandboxValidator()
75
+ validator.run_all_tests()
76
+ result["details"] = {
77
+ "total_tests": len(validator.test_results),
78
+ "passed": sum(1 for r in validator.test_results if r["success"]),
79
+ "failed": len(validator.failed_tests),
80
+ "test_results": validator.test_results,
81
+ }
82
+
83
+ elif module_name == "test_sandbox_stress_and_edge_cases":
84
+ from test_sandbox_stress_and_edge_cases import StressTestValidator
85
+
86
+ validator = StressTestValidator()
87
+ validator.run_all_tests()
88
+ result["details"] = {
89
+ "total_tests": len(validator.test_results),
90
+ "passed": sum(1 for r in validator.test_results if r["success"]),
91
+ "failed": len(validator.failed_tests),
92
+ "test_results": validator.test_results,
93
+ }
94
+
95
+ elif module_name == "test_sandbox_usage_examples":
96
+ # 使用示例不返回测试结果,只是演示
97
+ import test_sandbox_usage_examples
98
+
99
+ test_sandbox_usage_examples.main()
100
+ result["details"] = {
101
+ "total_tests": 1,
102
+ "passed": 1,
103
+ "failed": 0,
104
+ "note": "Usage examples completed successfully",
105
+ }
106
+
107
+ result["success"] = True
108
+
109
+ except Exception as e:
110
+ result["error"] = str(e)
111
+ result["traceback"] = traceback.format_exc()
112
+ logger.error(f"测试模块 {module_name} 运行失败: {e}")
113
+ logger.error(f"详细错误信息:\n{traceback.format_exc()}")
114
+
115
+ result["duration"] = time.time() - start_time
116
+
117
+ # 打印模块结果摘要
118
+ if result["success"]:
119
+ logger.info(f"✅ {description} - 完成")
120
+ if "total_tests" in result["details"]:
121
+ logger.info(f" 总测试: {result['details']['total_tests']}")
122
+ logger.info(f" 通过: {result['details']['passed']}")
123
+ logger.info(f" 失败: {result['details']['failed']}")
124
+ logger.info(f" 耗时: {result['duration']:.3f}秒")
125
+ else:
126
+ logger.error(f"❌ {description} - 失败")
127
+ logger.error(f" 错误: {result['error']}")
128
+ logger.error(f" 耗时: {result['duration']:.3f}秒")
129
+
130
+ return result
131
+
132
+ def run_all_tests(self, selected_tests: List[str] = None) -> Dict[str, Any]:
133
+ """运行所有或选定的测试"""
134
+ logger.info("ScaleBox 沙箱验证测试套件")
135
+ logger.info(f"开始时间: {time.strftime('%Y-%m-%d %H:%M:%S')}")
136
+
137
+ # 定义所有测试套件
138
+ test_suites = [
139
+ {
140
+ "module": "test_sandbox_async_comprehensive",
141
+ "description": "AsyncSandbox 综合功能验证",
142
+ },
143
+ {
144
+ "module": "test_sandbox_sync_comprehensive",
145
+ "description": "Sandbox 综合功能验证",
146
+ },
147
+ {
148
+ "module": "test_sandbox_stress_and_edge_cases",
149
+ "description": "压力测试和边界条件验证",
150
+ },
151
+ {
152
+ "module": "test_sandbox_usage_examples",
153
+ "description": "使用示例和最佳实践演示",
154
+ },
155
+ ]
156
+
157
+ # 过滤选定的测试
158
+ if selected_tests:
159
+ test_suites = [
160
+ suite for suite in test_suites if suite["module"] in selected_tests
161
+ ]
162
+
163
+ logger.info(f"将运行 {len(test_suites)} 个测试套件")
164
+
165
+ # 运行所有测试套件
166
+ for suite in test_suites:
167
+ result = self.run_test_module(suite["module"], suite["description"])
168
+ self.results[suite["module"]] = result
169
+
170
+ # 生成综合报告
171
+ total_duration = time.time() - self.total_start_time
172
+ return self.generate_final_report(total_duration)
173
+
174
+ def generate_final_report(self, total_duration: float) -> Dict[str, Any]:
175
+ """生成最终测试报告"""
176
+ logger.info(f"\n{'='*80}")
177
+ logger.info("ScaleBox 沙箱验证测试 - 最终报告")
178
+ logger.info(f"{'='*80}")
179
+
180
+ # 统计总体结果
181
+ total_suites = len(self.results)
182
+ successful_suites = sum(1 for r in self.results.values() if r["success"])
183
+ failed_suites = total_suites - successful_suites
184
+
185
+ total_tests = sum(
186
+ r["details"].get("total_tests", 0) for r in self.results.values()
187
+ )
188
+ total_passed = sum(r["details"].get("passed", 0) for r in self.results.values())
189
+ total_failed = sum(r["details"].get("failed", 0) for r in self.results.values())
190
+
191
+ logger.info(f"测试套件统计:")
192
+ logger.info(f" 总套件数: {total_suites}")
193
+ logger.info(f" 成功套件: {successful_suites}")
194
+ logger.info(f" 失败套件: {failed_suites}")
195
+ logger.info(f" 套件成功率: {(successful_suites/total_suites*100):.1f}%")
196
+
197
+ logger.info(f"\n测试用例统计:")
198
+ logger.info(f" 总测试数: {total_tests}")
199
+ logger.info(f" 通过测试: {total_passed}")
200
+ logger.info(f" 失败测试: {total_failed}")
201
+ logger.info(
202
+ f" 测试成功率: {(total_passed/total_tests*100):.1f}%"
203
+ if total_tests > 0
204
+ else " 测试成功率: N/A"
205
+ )
206
+
207
+ logger.info(f"\n性能统计:")
208
+ logger.info(f" 总运行时间: {total_duration:.3f}秒")
209
+
210
+ # 详细结果
211
+ logger.info(f"\n详细结果:")
212
+ for module, result in self.results.items():
213
+ status = "✅ 成功" if result["success"] else "❌ 失败"
214
+ logger.info(f" {result['description']}: {status}")
215
+ logger.info(f" 模块: {module}")
216
+ logger.info(f" 耗时: {result['duration']:.3f}秒")
217
+
218
+ if "total_tests" in result["details"]:
219
+ logger.info(
220
+ f" 测试: {result['details']['passed']}/{result['details']['total_tests']}"
221
+ )
222
+
223
+ if not result["success"] and result["error"]:
224
+ logger.info(f" 错误: {result['error']}")
225
+
226
+ # 失败的测试详情
227
+ if failed_suites > 0:
228
+ logger.info(f"\n失败的测试套件:")
229
+ for module, result in self.results.items():
230
+ if not result["success"]:
231
+ logger.info(f" ❌ {result['description']}")
232
+ logger.info(f" 错误: {result['error']}")
233
+
234
+ # 性能对比(如果有同步和异步测试结果)
235
+ if (
236
+ "test_sandbox_async_comprehensive" in self.results
237
+ and "test_sandbox_sync_comprehensive" in self.results
238
+ ):
239
+ async_duration = self.results["test_sandbox_async_comprehensive"][
240
+ "duration"
241
+ ]
242
+ sync_duration = self.results["test_sandbox_sync_comprehensive"]["duration"]
243
+
244
+ logger.info(f"\n同步 vs 异步性能对比:")
245
+ logger.info(f" 异步版本耗时: {async_duration:.3f}秒")
246
+ logger.info(f" 同步版本耗时: {sync_duration:.3f}秒")
247
+
248
+ if async_duration > 0 and sync_duration > 0:
249
+ if async_duration < sync_duration:
250
+ speedup = sync_duration / async_duration
251
+ logger.info(f" 异步版本快 {speedup:.1f}x")
252
+ else:
253
+ speedup = async_duration / sync_duration
254
+ logger.info(f" 同步版本快 {speedup:.1f}x")
255
+
256
+ logger.info(f"\n{'='*80}")
257
+ logger.info(f"测试完成时间: {time.strftime('%Y-%m-%d %H:%M:%S')}")
258
+ logger.info(f"{'='*80}")
259
+
260
+ # 返回汇总报告
261
+ summary = {
262
+ "total_suites": total_suites,
263
+ "successful_suites": successful_suites,
264
+ "failed_suites": failed_suites,
265
+ "suite_success_rate": (
266
+ (successful_suites / total_suites * 100) if total_suites > 0 else 0
267
+ ),
268
+ "total_tests": total_tests,
269
+ "total_passed": total_passed,
270
+ "total_failed": total_failed,
271
+ "test_success_rate": (
272
+ (total_passed / total_tests * 100) if total_tests > 0 else 0
273
+ ),
274
+ "total_duration": total_duration,
275
+ "results": self.results,
276
+ }
277
+
278
+ return summary
279
+
280
+
281
+ def main():
282
+ """主函数"""
283
+ import argparse
284
+
285
+ parser = argparse.ArgumentParser(description="ScaleBox 沙箱验证测试套件")
286
+ parser.add_argument(
287
+ "--tests",
288
+ nargs="+",
289
+ choices=[
290
+ "test_sandbox_async_comprehensive",
291
+ "test_sandbox_sync_comprehensive",
292
+ "test_sandbox_stress_and_edge_cases",
293
+ "test_sandbox_usage_examples",
294
+ ],
295
+ help="选择要运行的测试套件",
296
+ )
297
+ parser.add_argument("--log-level", default="INFO", help="日志级别")
298
+ parser.add_argument("--output", help="输出报告到文件")
299
+
300
+ args = parser.parse_args()
301
+
302
+ # 设置日志级别
303
+ logging.getLogger().setLevel(getattr(logging, args.log_level.upper()))
304
+
305
+ try:
306
+ # 运行测试
307
+ runner = TestSuiteRunner()
308
+ summary = runner.run_all_tests(args.tests)
309
+
310
+ # 保存报告到文件
311
+ if args.output:
312
+ import json
313
+
314
+ with open(args.output, "w", encoding="utf-8") as f:
315
+ json.dump(summary, f, indent=2, ensure_ascii=False, default=str)
316
+ logger.info(f"测试报告已保存到: {args.output}")
317
+
318
+ # 根据测试结果设置退出码
319
+ if summary["failed_suites"] > 0:
320
+ sys.exit(1)
321
+ else:
322
+ sys.exit(0)
323
+
324
+ except KeyboardInterrupt:
325
+ logger.info("用户中断测试")
326
+ sys.exit(2)
327
+ except Exception as e:
328
+ logger.error(f"测试运行器出现异常: {e}")
329
+ logger.error(traceback.format_exc())
330
+ sys.exit(3)
331
+
332
+
333
+ if __name__ == "__main__":
334
+ main()
@@ -0,0 +1,67 @@
1
+ #!/bin/bash
2
+
3
+ # Code Interpreter 测试运行脚本
4
+
5
+ echo "=========================================="
6
+ echo "Code Interpreter 测试套件"
7
+ echo "=========================================="
8
+
9
+ # 检查Python版本
10
+ echo "🐍 Python版本:"
11
+ python3 --version
12
+
13
+ echo ""
14
+ echo "📋 可用的测试选项:"
15
+ echo "1. 简单同步测试 (testcodeinterpreter_sync.py)"
16
+ echo "2. 简单异步测试 (testcodeinterpreter_async.py)"
17
+ echo "3. 综合同步测试 (test_code_interpreter_sync_comprehensive.py)"
18
+ echo "4. 综合异步测试 (test_code_interpreter_async_comprehensive.py)"
19
+ echo "5. 运行所有测试"
20
+ echo ""
21
+
22
+ # 询问用户选择
23
+ echo "请选择要运行的测试 (1-5),或按 Enter 运行简单同步测试:"
24
+ read choice
25
+
26
+ case $choice in
27
+ 1)
28
+ echo "🚀 运行简单同步测试..."
29
+ python3 testcodeinterpreter_sync.py
30
+ ;;
31
+ 2)
32
+ echo "🚀 运行简单异步测试..."
33
+ python3 testcodeinterpreter_async.py
34
+ ;;
35
+ 3)
36
+ echo "🚀 运行综合同步测试..."
37
+ python3 test_code_interpreter_sync_comprehensive.py
38
+ ;;
39
+ 4)
40
+ echo "🚀 运行综合异步测试..."
41
+ python3 test_code_interpreter_async_comprehensive.py
42
+ ;;
43
+ 5)
44
+ echo "🚀 运行所有测试..."
45
+ echo ""
46
+ echo "--- 简单同步测试 ---"
47
+ python3 testcodeinterpreter_sync.py
48
+ echo ""
49
+ echo "--- 简单异步测试 ---"
50
+ python3 testcodeinterpreter_async.py
51
+ echo ""
52
+ echo "--- 综合同步测试 ---"
53
+ python3 test_code_interpreter_sync_comprehensive.py
54
+ echo ""
55
+ echo "--- 综合异步测试 ---"
56
+ python3 test_code_interpreter_async_comprehensive.py
57
+ ;;
58
+ *)
59
+ echo "🚀 运行默认的简单同步测试..."
60
+ python3 testcodeinterpreter_sync.py
61
+ ;;
62
+ esac
63
+
64
+ echo ""
65
+ echo "=========================================="
66
+ echo "测试完成!"
67
+ echo "=========================================="
@@ -0,0 +1,230 @@
1
+ #!/bin/bash
2
+
3
+ # ScaleBox 沙箱验证测试运行脚本
4
+ # 这个脚本提供了一个简单的方式来运行所有验证测试
5
+
6
+ set -e # 出错时立即退出
7
+
8
+ # 颜色定义
9
+ RED='\033[0;31m'
10
+ GREEN='\033[0;32m'
11
+ YELLOW='\033[1;33m'
12
+ BLUE='\033[0;34m'
13
+ NC='\033[0m' # No Color
14
+
15
+ # 打印带颜色的消息
16
+ print_info() {
17
+ echo -e "${BLUE}[INFO]${NC} $1"
18
+ }
19
+
20
+ print_success() {
21
+ echo -e "${GREEN}[SUCCESS]${NC} $1"
22
+ }
23
+
24
+ print_warning() {
25
+ echo -e "${YELLOW}[WARNING]${NC} $1"
26
+ }
27
+
28
+ print_error() {
29
+ echo -e "${RED}[ERROR]${NC} $1"
30
+ }
31
+
32
+ # 检查Python环境
33
+ check_python_env() {
34
+ print_info "检查Python环境..."
35
+
36
+ if ! command -v python3 &> /dev/null; then
37
+ print_error "Python3 未安装"
38
+ exit 1
39
+ fi
40
+
41
+ # 检查必要的模块是否可以导入
42
+ if ! python3 -c "import sys; sys.path.insert(0, '/home/ubuntu/git_home/scalebox'); import scalebox" 2>/dev/null; then
43
+ print_warning "ScaleBox模块路径可能有问题,但继续尝试运行测试"
44
+ else
45
+ print_success "Python环境检查通过"
46
+ fi
47
+ }
48
+
49
+ # 运行单个测试
50
+ run_single_test() {
51
+ local test_name=$1
52
+ local description=$2
53
+
54
+ print_info "开始运行: $description"
55
+ echo "========================================================"
56
+
57
+ if python3 "$test_name"; then
58
+ print_success "$description 完成"
59
+ return 0
60
+ else
61
+ print_error "$description 失败"
62
+ return 1
63
+ fi
64
+ }
65
+
66
+ # 显示使用帮助
67
+ show_help() {
68
+ echo "ScaleBox 沙箱验证测试运行脚本"
69
+ echo ""
70
+ echo "用法: $0 [选项]"
71
+ echo ""
72
+ echo "选项:"
73
+ echo " -h, --help 显示此帮助信息"
74
+ echo " -a, --async-only 仅运行异步测试"
75
+ echo " -s, --sync-only 仅运行同步测试"
76
+ echo " -S, --stress-only 仅运行压力测试"
77
+ echo " -u, --usage-only 仅运行使用示例"
78
+ echo " -q, --quick 快速测试(跳过压力测试)"
79
+ echo " -v, --verbose 详细输出"
80
+ echo ""
81
+ echo "示例:"
82
+ echo " $0 运行所有测试"
83
+ echo " $0 --async-only 仅运行异步测试"
84
+ echo " $0 --quick 运行除压力测试外的所有测试"
85
+ echo ""
86
+ }
87
+
88
+ # 主函数
89
+ main() {
90
+ local run_async=true
91
+ local run_sync=true
92
+ local run_stress=true
93
+ local run_usage=true
94
+ local verbose=false
95
+
96
+ # 解析命令行参数
97
+ while [[ $# -gt 0 ]]; do
98
+ case $1 in
99
+ -h|--help)
100
+ show_help
101
+ exit 0
102
+ ;;
103
+ -a|--async-only)
104
+ run_sync=false
105
+ run_stress=false
106
+ run_usage=false
107
+ shift
108
+ ;;
109
+ -s|--sync-only)
110
+ run_async=false
111
+ run_stress=false
112
+ run_usage=false
113
+ shift
114
+ ;;
115
+ -S|--stress-only)
116
+ run_async=false
117
+ run_sync=false
118
+ run_usage=false
119
+ shift
120
+ ;;
121
+ -u|--usage-only)
122
+ run_async=false
123
+ run_sync=false
124
+ run_stress=false
125
+ shift
126
+ ;;
127
+ -q|--quick)
128
+ run_stress=false
129
+ shift
130
+ ;;
131
+ -v|--verbose)
132
+ verbose=true
133
+ shift
134
+ ;;
135
+ *)
136
+ print_error "未知选项: $1"
137
+ show_help
138
+ exit 1
139
+ ;;
140
+ esac
141
+ done
142
+
143
+ # 设置详细输出
144
+ if [ "$verbose" = true ]; then
145
+ set -x
146
+ fi
147
+
148
+ print_info "ScaleBox 沙箱验证测试开始"
149
+ print_info "开始时间: $(date)"
150
+
151
+ # 检查环境
152
+ check_python_env
153
+
154
+ # 切换到测试目录
155
+ cd "$(dirname "$0")"
156
+
157
+ local total_tests=0
158
+ local failed_tests=0
159
+ local start_time=$(date +%s)
160
+
161
+ # 运行异步测试
162
+ if [ "$run_async" = true ]; then
163
+ ((total_tests++))
164
+ if ! run_single_test "test_sandbox_async_comprehensive.py" "AsyncSandbox 综合功能验证"; then
165
+ ((failed_tests++))
166
+ fi
167
+ echo ""
168
+ fi
169
+
170
+ # 运行同步测试
171
+ if [ "$run_sync" = true ]; then
172
+ ((total_tests++))
173
+ if ! run_single_test "test_sandbox_sync_comprehensive.py" "Sandbox 综合功能验证"; then
174
+ ((failed_tests++))
175
+ fi
176
+ echo ""
177
+ fi
178
+
179
+ # 运行压力测试
180
+ if [ "$run_stress" = true ]; then
181
+ ((total_tests++))
182
+ print_warning "压力测试可能需要较长时间..."
183
+ if ! run_single_test "test_sandbox_stress_and_edge_cases.py" "压力测试和边界条件验证"; then
184
+ ((failed_tests++))
185
+ fi
186
+ echo ""
187
+ fi
188
+
189
+ # 运行使用示例
190
+ if [ "$run_usage" = true ]; then
191
+ ((total_tests++))
192
+ if ! run_single_test "test_sandbox_usage_examples.py" "使用示例和最佳实践演示"; then
193
+ ((failed_tests++))
194
+ fi
195
+ echo ""
196
+ fi
197
+
198
+ # 生成最终报告
199
+ local end_time=$(date +%s)
200
+ local duration=$((end_time - start_time))
201
+
202
+ echo "========================================================"
203
+ print_info "ScaleBox 沙箱验证测试 - 最终报告"
204
+ echo "========================================================"
205
+
206
+ print_info "测试统计:"
207
+ echo " 总测试套件: $total_tests"
208
+ echo " 成功套件: $((total_tests - failed_tests))"
209
+ echo " 失败套件: $failed_tests"
210
+
211
+ if [ $total_tests -gt 0 ]; then
212
+ local success_rate=$(( (total_tests - failed_tests) * 100 / total_tests ))
213
+ echo " 成功率: ${success_rate}%"
214
+ fi
215
+
216
+ echo " 总耗时: ${duration}秒"
217
+ echo " 完成时间: $(date)"
218
+
219
+ # 根据结果设置退出状态
220
+ if [ $failed_tests -eq 0 ]; then
221
+ print_success "所有测试都通过了!"
222
+ exit 0
223
+ else
224
+ print_error "有 $failed_tests 个测试套件失败"
225
+ exit 1
226
+ fi
227
+ }
228
+
229
+ # 运行主函数
230
+ main "$@"