scalebox-sdk 0.1.24__py3-none-any.whl → 1.0.1__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 +2 -2
- scalebox/api/__init__.py +130 -128
- scalebox/api/client/__init__.py +8 -8
- 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/api/sandboxes/post_sandboxes_sandbox_id_connect.py +193 -0
- scalebox/api/client/client.py +288 -288
- scalebox/api/client/models/connect_sandbox.py +59 -0
- scalebox/api/client/models/error.py +2 -2
- scalebox/api/client/models/listed_sandbox.py +19 -1
- scalebox/api/client/models/new_sandbox.py +10 -0
- scalebox/api/client/models/sandbox.py +138 -125
- scalebox/api/client/models/sandbox_detail.py +24 -0
- scalebox/api/client/types.py +46 -46
- scalebox/cli.py +125 -125
- scalebox/client/aclient.py +57 -57
- scalebox/client/client.py +102 -102
- scalebox/code_interpreter/__init__.py +12 -12
- scalebox/code_interpreter/charts.py +230 -230
- scalebox/code_interpreter/constants.py +3 -3
- scalebox/code_interpreter/exceptions.py +13 -13
- scalebox/code_interpreter/models.py +485 -485
- scalebox/connection_config.py +34 -1
- scalebox/csx_connect/__init__.py +1 -1
- scalebox/csx_connect/client.py +485 -485
- scalebox/csx_desktop/main.py +651 -651
- scalebox/exceptions.py +83 -83
- scalebox/generated/api.py +61 -61
- scalebox/generated/api_pb2.py +203 -203
- scalebox/generated/api_pb2.pyi +956 -956
- scalebox/generated/api_pb2_connect.py +1407 -1407
- scalebox/generated/rpc.py +50 -50
- scalebox/sandbox/main.py +146 -139
- scalebox/sandbox/sandbox_api.py +105 -91
- scalebox/sandbox/signature.py +40 -40
- scalebox/sandbox/utils.py +34 -34
- 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 +228 -46
- scalebox/sandbox_async/sandbox_api.py +124 -3
- 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 +3 -3
- scalebox/sandbox_sync/filesystem/watch_handle.py +66 -66
- scalebox/sandbox_sync/main.py +208 -133
- scalebox/sandbox_sync/sandbox_api.py +119 -3
- scalebox/test/CODE_INTERPRETER_TESTS_READY.md +323 -323
- scalebox/test/README.md +329 -329
- scalebox/test/bedrock_openai_adapter.py +67 -0
- scalebox/test/code_interpreter_test.py +34 -34
- scalebox/test/code_interpreter_test_sync.py +34 -34
- scalebox/test/run_stress_code_interpreter_sync.py +166 -0
- scalebox/test/simple_upload_example.py +123 -0
- scalebox/test/stabitiy_test.py +310 -0
- scalebox/test/test_browser_use.py +25 -0
- scalebox/test/test_browser_use_scalebox.py +61 -0
- scalebox/test/test_code_interpreter_sync_comprehensive.py +115 -65
- scalebox/test/test_connect_pause_async.py +277 -0
- scalebox/test/test_connect_pause_sync.py +267 -0
- scalebox/test/test_desktop_sandbox_sf.py +117 -0
- scalebox/test/test_download_url.py +49 -0
- scalebox/test/test_sandbox_async_comprehensive.py +1 -1
- scalebox/test/test_sandbox_object_storage_example.py +146 -0
- scalebox/test/test_sandbox_object_storage_example_async.py +156 -0
- scalebox/test/test_sf.py +137 -0
- scalebox/test/test_watch_dir_async.py +56 -0
- scalebox/test/testacreate.py +1 -1
- scalebox/test/testagetinfo.py +1 -1
- scalebox/test/testcomputeuse.py +243 -243
- scalebox/test/testsandbox_api.py +13 -0
- scalebox/test/testsandbox_sync.py +1 -1
- scalebox/test/upload_100mb_example.py +355 -0
- scalebox/utils/httpcoreclient.py +297 -297
- scalebox/utils/httpxclient.py +403 -403
- scalebox/version.py +2 -2
- {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/METADATA +1 -1
- {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/RECORD +87 -69
- {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/WHEEL +1 -1
- {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/entry_points.txt +0 -0
- {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/licenses/LICENSE +0 -0
- {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
稳定性测试脚本 - 并发执行CodeInterpreter验证测试
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import concurrent.futures
|
|
7
|
+
import time
|
|
8
|
+
import json
|
|
9
|
+
import logging
|
|
10
|
+
import threading
|
|
11
|
+
from typing import List, Dict, Any
|
|
12
|
+
import sys
|
|
13
|
+
import argparse
|
|
14
|
+
|
|
15
|
+
# 导入原始测试代码
|
|
16
|
+
from code_interpreter_validator import CodeInterpreterValidator
|
|
17
|
+
|
|
18
|
+
# 配置日志
|
|
19
|
+
logging.basicConfig(
|
|
20
|
+
level=logging.INFO,
|
|
21
|
+
format='%(asctime)s - %(levelname)s - [%(threadName)s] - %(message)s'
|
|
22
|
+
)
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class StabilityTester:
|
|
27
|
+
"""稳定性测试器"""
|
|
28
|
+
|
|
29
|
+
def __init__(self, concurrency: int = 10):
|
|
30
|
+
self.concurrency = concurrency
|
|
31
|
+
self.results = []
|
|
32
|
+
self.lock = threading.Lock()
|
|
33
|
+
self.test_counter = 0
|
|
34
|
+
self.total_tests = 0
|
|
35
|
+
|
|
36
|
+
def get_test_methods(self) -> List[str]:
|
|
37
|
+
"""获取所有测试方法"""
|
|
38
|
+
validator = CodeInterpreterValidator()
|
|
39
|
+
test_methods = []
|
|
40
|
+
|
|
41
|
+
# 获取所有以test_开头的方法
|
|
42
|
+
for method_name in dir(validator):
|
|
43
|
+
if method_name.startswith('test_') and callable(getattr(validator, method_name)):
|
|
44
|
+
test_methods.append(method_name)
|
|
45
|
+
|
|
46
|
+
self.total_tests = len(test_methods)
|
|
47
|
+
logger.info(f"发现 {self.total_tests} 个测试方法")
|
|
48
|
+
return test_methods
|
|
49
|
+
|
|
50
|
+
def run_single_test(self, test_name: str) -> Dict[str, Any]:
|
|
51
|
+
"""运行单个测试"""
|
|
52
|
+
thread_name = threading.current_thread().name
|
|
53
|
+
test_id = 0
|
|
54
|
+
|
|
55
|
+
with self.lock:
|
|
56
|
+
self.test_counter += 1
|
|
57
|
+
test_id = self.test_counter
|
|
58
|
+
|
|
59
|
+
logger.info(f"[线程 {thread_name}] 开始执行测试 {test_id}/{self.total_tests}: {test_name}")
|
|
60
|
+
|
|
61
|
+
start_time = time.time()
|
|
62
|
+
success = False
|
|
63
|
+
error_message = ""
|
|
64
|
+
duration = 0
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
# 为每个测试创建独立的验证器实例
|
|
68
|
+
validator = CodeInterpreterValidator()
|
|
69
|
+
|
|
70
|
+
# 运行沙箱创建测试
|
|
71
|
+
validator.test_code_interpreter_creation()
|
|
72
|
+
|
|
73
|
+
# 运行目标测试
|
|
74
|
+
test_method = getattr(validator, test_name)
|
|
75
|
+
test_method()
|
|
76
|
+
|
|
77
|
+
duration = time.time() - start_time
|
|
78
|
+
success = True
|
|
79
|
+
logger.info(f"[线程 {thread_name}] ✅ 测试通过: {test_name} ({duration:.3f}s)")
|
|
80
|
+
|
|
81
|
+
except Exception as e:
|
|
82
|
+
duration = time.time() - start_time
|
|
83
|
+
error_message = str(e)
|
|
84
|
+
logger.error(f"[线程 {thread_name}] ❌ 测试失败: {test_name} - {error_message} ({duration:.3f}s)")
|
|
85
|
+
|
|
86
|
+
finally:
|
|
87
|
+
# 清理资源
|
|
88
|
+
try:
|
|
89
|
+
if 'validator' in locals():
|
|
90
|
+
validator.cleanup()
|
|
91
|
+
except Exception as cleanup_error:
|
|
92
|
+
logger.warning(f"[线程 {thread_name}] 清理资源时出错: {cleanup_error}")
|
|
93
|
+
|
|
94
|
+
result = {
|
|
95
|
+
'test_id': test_id,
|
|
96
|
+
'test_name': test_name,
|
|
97
|
+
'thread_name': thread_name,
|
|
98
|
+
'success': success,
|
|
99
|
+
'error_message': error_message,
|
|
100
|
+
'duration': duration,
|
|
101
|
+
'timestamp': time.time()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
with self.lock:
|
|
105
|
+
self.results.append(result)
|
|
106
|
+
|
|
107
|
+
return result
|
|
108
|
+
|
|
109
|
+
def run_concurrent_tests(self) -> Dict[str, Any]:
|
|
110
|
+
"""运行并发测试"""
|
|
111
|
+
test_methods = self.get_test_methods()
|
|
112
|
+
|
|
113
|
+
if not test_methods:
|
|
114
|
+
logger.error("未发现测试方法")
|
|
115
|
+
return {}
|
|
116
|
+
|
|
117
|
+
logger.info(f"开始稳定性测试,并发数: {self.concurrency}")
|
|
118
|
+
logger.info(f"总测试数: {len(test_methods)}")
|
|
119
|
+
|
|
120
|
+
start_time = time.time()
|
|
121
|
+
|
|
122
|
+
# 使用线程池执行并发测试
|
|
123
|
+
with concurrent.futures.ThreadPoolExecutor(
|
|
124
|
+
max_workers=self.concurrency,
|
|
125
|
+
thread_name_prefix='TestWorker'
|
|
126
|
+
) as executor:
|
|
127
|
+
|
|
128
|
+
# 提交所有测试任务
|
|
129
|
+
future_to_test = {
|
|
130
|
+
executor.submit(self.run_single_test, test_name): test_name
|
|
131
|
+
for test_name in test_methods
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# 等待所有测试完成
|
|
135
|
+
completed = 0
|
|
136
|
+
for future in concurrent.futures.as_completed(future_to_test):
|
|
137
|
+
test_name = future_to_test[future]
|
|
138
|
+
try:
|
|
139
|
+
future.result()
|
|
140
|
+
except Exception as exc:
|
|
141
|
+
logger.error(f"测试 {test_name} 生成异常: {exc}")
|
|
142
|
+
completed += 1
|
|
143
|
+
logger.info(f"测试进度: {completed}/{len(test_methods)}")
|
|
144
|
+
|
|
145
|
+
total_duration = time.time() - start_time
|
|
146
|
+
|
|
147
|
+
# 生成测试报告
|
|
148
|
+
report = self.generate_report(total_duration)
|
|
149
|
+
|
|
150
|
+
return report
|
|
151
|
+
|
|
152
|
+
def generate_report(self, total_duration: float) -> Dict[str, Any]:
|
|
153
|
+
"""生成测试报告"""
|
|
154
|
+
successful_tests = [r for r in self.results if r['success']]
|
|
155
|
+
failed_tests = [r for r in self.results if not r['success']]
|
|
156
|
+
|
|
157
|
+
total_tests = len(self.results)
|
|
158
|
+
success_count = len(successful_tests)
|
|
159
|
+
failure_count = len(failed_tests)
|
|
160
|
+
success_rate = (success_count / total_tests * 100) if total_tests > 0 else 0
|
|
161
|
+
|
|
162
|
+
# 计算统计信息
|
|
163
|
+
durations = [r['duration'] for r in self.results]
|
|
164
|
+
avg_duration = sum(durations) / len(durations) if durations else 0
|
|
165
|
+
max_duration = max(durations) if durations else 0
|
|
166
|
+
min_duration = min(durations) if durations else 0
|
|
167
|
+
|
|
168
|
+
report = {
|
|
169
|
+
'summary': {
|
|
170
|
+
'total_tests': total_tests,
|
|
171
|
+
'successful_tests': success_count,
|
|
172
|
+
'failed_tests': failure_count,
|
|
173
|
+
'success_rate': round(success_rate, 2),
|
|
174
|
+
'total_duration': round(total_duration, 3),
|
|
175
|
+
'concurrency': self.concurrency,
|
|
176
|
+
'avg_duration_per_test': round(avg_duration, 3),
|
|
177
|
+
'max_duration': round(max_duration, 3),
|
|
178
|
+
'min_duration': round(min_duration, 3)
|
|
179
|
+
},
|
|
180
|
+
'successful_tests': [
|
|
181
|
+
{
|
|
182
|
+
'test_name': r['test_name'],
|
|
183
|
+
'duration': round(r['duration'], 3),
|
|
184
|
+
'thread': r['thread_name']
|
|
185
|
+
} for r in successful_tests
|
|
186
|
+
],
|
|
187
|
+
'failed_tests': [
|
|
188
|
+
{
|
|
189
|
+
'test_name': r['test_name'],
|
|
190
|
+
'error': r['error_message'],
|
|
191
|
+
'duration': round(r['duration'], 3),
|
|
192
|
+
'thread': r['thread_name']
|
|
193
|
+
} for r in failed_tests
|
|
194
|
+
],
|
|
195
|
+
'execution_timeline': [
|
|
196
|
+
{
|
|
197
|
+
'test_id': r['test_id'],
|
|
198
|
+
'test_name': r['test_name'],
|
|
199
|
+
'thread': r['thread_name'],
|
|
200
|
+
'success': r['success'],
|
|
201
|
+
'duration': round(r['duration'], 3),
|
|
202
|
+
'timestamp': r['timestamp']
|
|
203
|
+
} for r in self.results
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return report
|
|
208
|
+
|
|
209
|
+
def print_detailed_report(self, report: Dict[str, Any]):
|
|
210
|
+
"""打印详细报告"""
|
|
211
|
+
summary = report['summary']
|
|
212
|
+
|
|
213
|
+
print("\n" + "=" * 80)
|
|
214
|
+
print("🚀 CODEINTERPRETER 稳定性测试报告")
|
|
215
|
+
print("=" * 80)
|
|
216
|
+
|
|
217
|
+
print(f"\n📊 测试摘要:")
|
|
218
|
+
print(f" 总测试数: {summary['total_tests']}")
|
|
219
|
+
print(f" 通过测试: {summary['successful_tests']} ✅")
|
|
220
|
+
print(f" 失败测试: {summary['failed_tests']} ❌")
|
|
221
|
+
print(f" 成功率: {summary['success_rate']}%")
|
|
222
|
+
print(f" 总执行时间: {summary['total_duration']}s")
|
|
223
|
+
print(f" 并发数: {summary['concurrency']}")
|
|
224
|
+
print(f" 平均测试时间: {summary['avg_duration_per_test']}s")
|
|
225
|
+
print(f" 最长测试时间: {summary['max_duration']}s")
|
|
226
|
+
print(f" 最短测试时间: {summary['min_duration']}s")
|
|
227
|
+
|
|
228
|
+
# 打印成功测试
|
|
229
|
+
if report['successful_tests']:
|
|
230
|
+
print(f"\n✅ 通过的测试 ({len(report['successful_tests'])}):")
|
|
231
|
+
for test in report['successful_tests']:
|
|
232
|
+
print(f" - {test['test_name']} ({test['duration']}s) [{test['thread']}]")
|
|
233
|
+
|
|
234
|
+
# 打印失败测试
|
|
235
|
+
if report['failed_tests']:
|
|
236
|
+
print(f"\n❌ 失败的测试 ({len(report['failed_tests'])}):")
|
|
237
|
+
for test in report['failed_tests']:
|
|
238
|
+
print(f" - {test['test_name']}")
|
|
239
|
+
print(f" 错误: {test['error']}")
|
|
240
|
+
print(f" 时间: {test['duration']}s")
|
|
241
|
+
print(f" 线程: {test['thread']}")
|
|
242
|
+
|
|
243
|
+
# 打印执行时间线
|
|
244
|
+
print(f"\n⏰ 执行时间线:")
|
|
245
|
+
for execution in sorted(report['execution_timeline'], key=lambda x: x['timestamp']):
|
|
246
|
+
status = "✅" if execution['success'] else "❌"
|
|
247
|
+
print(f" {status} [{execution['thread']}] {execution['test_name']} ({execution['duration']}s)")
|
|
248
|
+
|
|
249
|
+
print("\n" + "=" * 80)
|
|
250
|
+
|
|
251
|
+
# 保存详细报告到文件
|
|
252
|
+
timestamp = time.strftime("%Y%m%d_%H%M%S")
|
|
253
|
+
filename = f"stability_test_report_{timestamp}.json"
|
|
254
|
+
with open(filename, 'w', encoding='utf-8') as f:
|
|
255
|
+
json.dump(report, f, ensure_ascii=False, indent=2)
|
|
256
|
+
print(f"📄 详细报告已保存至: {filename}")
|
|
257
|
+
print("=" * 80)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def main():
|
|
261
|
+
"""主函数"""
|
|
262
|
+
parser = argparse.ArgumentParser(description='CodeInterpreter稳定性测试')
|
|
263
|
+
parser.add_argument(
|
|
264
|
+
'--concurrency',
|
|
265
|
+
type=int,
|
|
266
|
+
default=10,
|
|
267
|
+
help='并发线程数 (默认: 10)'
|
|
268
|
+
)
|
|
269
|
+
parser.add_argument(
|
|
270
|
+
'--log-level',
|
|
271
|
+
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR'],
|
|
272
|
+
default='INFO',
|
|
273
|
+
help='日志级别 (默认: INFO)'
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
args = parser.parse_args()
|
|
277
|
+
|
|
278
|
+
# 设置日志级别
|
|
279
|
+
logging.getLogger().setLevel(getattr(logging, args.log_level))
|
|
280
|
+
|
|
281
|
+
logger.info(f"启动稳定性测试,并发数: {args.concurrency}")
|
|
282
|
+
|
|
283
|
+
tester = StabilityTester(concurrency=args.concurrency)
|
|
284
|
+
|
|
285
|
+
try:
|
|
286
|
+
report = tester.run_concurrent_tests()
|
|
287
|
+
tester.print_detailed_report(report)
|
|
288
|
+
|
|
289
|
+
# 根据成功率返回适当的退出码
|
|
290
|
+
success_rate = report['summary']['success_rate']
|
|
291
|
+
if success_rate >= 95:
|
|
292
|
+
logger.info(f"🎉 测试成功! 成功率: {success_rate}%")
|
|
293
|
+
sys.exit(0)
|
|
294
|
+
elif success_rate >= 80:
|
|
295
|
+
logger.warning(f"⚠️ 测试基本通过,但有改进空间。成功率: {success_rate}%")
|
|
296
|
+
sys.exit(0)
|
|
297
|
+
else:
|
|
298
|
+
logger.error(f"💥 测试失败! 成功率: {success_rate}%")
|
|
299
|
+
sys.exit(1)
|
|
300
|
+
|
|
301
|
+
except KeyboardInterrupt:
|
|
302
|
+
logger.info("测试被用户中断")
|
|
303
|
+
sys.exit(1)
|
|
304
|
+
except Exception as e:
|
|
305
|
+
logger.error(f"测试执行出错: {e}")
|
|
306
|
+
sys.exit(1)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
if __name__ == "__main__":
|
|
310
|
+
main()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import asyncio, openai
|
|
2
|
+
from browser_use import Agent, BrowserProfile
|
|
3
|
+
|
|
4
|
+
# 指向本地 adapter
|
|
5
|
+
openai.base_url = "http://localhost:8000/v1/"
|
|
6
|
+
openai.api_key = "dummy"
|
|
7
|
+
|
|
8
|
+
TASK = (
|
|
9
|
+
"打开 https://www.baidu.com,"
|
|
10
|
+
"输入“今日天气”并搜索,"
|
|
11
|
+
"把第一条结果的标题复制出来。"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
async def main():
|
|
15
|
+
agent = Agent(
|
|
16
|
+
task=TASK,
|
|
17
|
+
browser_profile=BrowserProfile(headless=False),
|
|
18
|
+
model="gpt-4" # 欺骗 browser-use
|
|
19
|
+
)
|
|
20
|
+
result = await agent.run()
|
|
21
|
+
print("---------- 最终结果 ----------")
|
|
22
|
+
print(result)
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import os
|
|
3
|
+
# from browser_use import Agent, BrowserProfile
|
|
4
|
+
from scalebox.sandbox_async.main import AsyncSandbox
|
|
5
|
+
|
|
6
|
+
# 设置环境变量,避免浏览器启动问题
|
|
7
|
+
os.environ['BROWSER_USE_DISABLE_TELEMETRY'] = '1'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async def main():
|
|
11
|
+
sandbox = await (AsyncSandbox.create(
|
|
12
|
+
timeout=3600,
|
|
13
|
+
template="browser-use-headless",
|
|
14
|
+
))
|
|
15
|
+
proc = await sandbox.commands.run("echo hello from async")
|
|
16
|
+
print("exit_code =", proc.exit_code)
|
|
17
|
+
print("stdout =", proc.stdout)
|
|
18
|
+
|
|
19
|
+
# try:
|
|
20
|
+
# # 配置浏览器参数 - 使用更稳定的配置
|
|
21
|
+
# browser_profile = BrowserProfile(
|
|
22
|
+
# # 设置浏览器窗口大小
|
|
23
|
+
# viewport_width=1200,
|
|
24
|
+
# viewport_height=800,
|
|
25
|
+
# # 在服务器环境必须使用无头模式
|
|
26
|
+
# headless=True,
|
|
27
|
+
# # 禁用沙盒,提高容器兼容性
|
|
28
|
+
# sandbox=False,
|
|
29
|
+
# # 增加超时时间
|
|
30
|
+
# browser_launch_timeout=60000, # 60秒
|
|
31
|
+
# # 禁用GPU加速(服务器环境推荐)
|
|
32
|
+
# gpu_acceleration=False,
|
|
33
|
+
# )
|
|
34
|
+
#
|
|
35
|
+
# # 定义需要 agent 执行的任务
|
|
36
|
+
# task = """
|
|
37
|
+
# 请打开百度首页 (https://www.baidu.com),在搜索框中输入"今日天气",然后进行搜索。
|
|
38
|
+
# 请等待搜索结果页面加载完成。
|
|
39
|
+
# """
|
|
40
|
+
#
|
|
41
|
+
# # 创建 Agent 实例
|
|
42
|
+
# agent = Agent(
|
|
43
|
+
# task=task,
|
|
44
|
+
# browser_profile=browser_profile,
|
|
45
|
+
# )
|
|
46
|
+
#
|
|
47
|
+
# print("开始执行浏览器自动化任务...")
|
|
48
|
+
#
|
|
49
|
+
# # 运行 Agent
|
|
50
|
+
# result = await agent.run()
|
|
51
|
+
# print(f"任务执行完成: {result}")
|
|
52
|
+
#
|
|
53
|
+
# except Exception as e:
|
|
54
|
+
# print(f"执行过程中出现错误: {e}")
|
|
55
|
+
# # 打印更详细的错误信息
|
|
56
|
+
# import traceback
|
|
57
|
+
# traceback.print_exc()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
asyncio.run(main())
|
|
@@ -106,8 +106,9 @@ result = {"x": x, "y": y}
|
|
|
106
106
|
print(result)
|
|
107
107
|
"""
|
|
108
108
|
|
|
109
|
-
execution = self.sandbox.run_code(code,
|
|
109
|
+
execution = self.sandbox.run_code(code,envs={"CI_TEST": "sync_test1"})
|
|
110
110
|
print(execution.to_json())
|
|
111
|
+
# time.sleep(1000)
|
|
111
112
|
assert isinstance(execution, Execution)
|
|
112
113
|
assert execution.error is None
|
|
113
114
|
assert len(execution.logs.stdout) > 0
|
|
@@ -147,7 +148,7 @@ print(f"标准差: {std_val:.3f}")
|
|
|
147
148
|
}
|
|
148
149
|
"""
|
|
149
150
|
|
|
150
|
-
execution = self.sandbox.run_code(code
|
|
151
|
+
execution = self.sandbox.run_code(code)
|
|
151
152
|
print(execution.to_json())
|
|
152
153
|
assert execution.error is None
|
|
153
154
|
assert any("圆的面积" in line for line in execution.logs.stdout)
|
|
@@ -197,7 +198,7 @@ result = {
|
|
|
197
198
|
print(f"\\n处理结果: {json.dumps(result, indent=2)}")
|
|
198
199
|
"""
|
|
199
200
|
|
|
200
|
-
execution = self.sandbox.run_code(code
|
|
201
|
+
execution = self.sandbox.run_code(code)
|
|
201
202
|
print(execution.to_json())
|
|
202
203
|
assert execution.error is None
|
|
203
204
|
assert any("原始数据" in line for line in execution.logs.stdout)
|
|
@@ -799,6 +800,55 @@ print("生成HTML格式结果")
|
|
|
799
800
|
from IPython.display import HTML
|
|
800
801
|
HTML(html_content)
|
|
801
802
|
"""
|
|
803
|
+
# code = """
|
|
804
|
+
# import sys
|
|
805
|
+
# try:
|
|
806
|
+
# import matplotlib
|
|
807
|
+
# matplotlib.use('Agg') # Non-interactive backend
|
|
808
|
+
# import matplotlib.pyplot as plt
|
|
809
|
+
# import numpy as np
|
|
810
|
+
# from IPython.display import display
|
|
811
|
+
#
|
|
812
|
+
# print("✅ All imports successful")
|
|
813
|
+
#
|
|
814
|
+
# # Generate a simple plot
|
|
815
|
+
# x = np.linspace(0, 2 * np.pi, 100)
|
|
816
|
+
# y = np.sin(x)
|
|
817
|
+
#
|
|
818
|
+
# fig, ax = plt.subplots(figsize=(8, 6))
|
|
819
|
+
# ax.plot(x, y, 'b-', linewidth=2, label='sin(x)')
|
|
820
|
+
# ax.set_xlabel('X axis')
|
|
821
|
+
# ax.set_ylabel('Y axis')
|
|
822
|
+
# ax.set_title('Sine Wave - Test Plot')
|
|
823
|
+
# ax.legend()
|
|
824
|
+
# ax.grid(True, alpha=0.3)
|
|
825
|
+
#
|
|
826
|
+
# plt.tight_layout()
|
|
827
|
+
#
|
|
828
|
+
# # 🎯 KEY: Save to bytes and display as Image
|
|
829
|
+
# import io
|
|
830
|
+
# from IPython.display import Image
|
|
831
|
+
#
|
|
832
|
+
# buf = io.BytesIO()
|
|
833
|
+
# plt.savefig(buf, format='png', bbox_inches='tight', dpi=100)
|
|
834
|
+
# buf.seek(0)
|
|
835
|
+
# plt.close(fig)
|
|
836
|
+
#
|
|
837
|
+
# # Display the image data
|
|
838
|
+
# display(Image(data=buf.getvalue()))
|
|
839
|
+
# #
|
|
840
|
+
# # print("SUCCESS: Plot generated and displayed")
|
|
841
|
+
# # "plot_created"
|
|
842
|
+
#
|
|
843
|
+
# except ImportError as e:
|
|
844
|
+
# print(f"SKIP: matplotlib not available - {e}")
|
|
845
|
+
# "matplotlib_not_installed"
|
|
846
|
+
# except Exception as e:
|
|
847
|
+
# print(f"ERROR: {e}")
|
|
848
|
+
# import traceback
|
|
849
|
+
# traceback.print_exc()
|
|
850
|
+
# "error_occurred"
|
|
851
|
+
# """
|
|
802
852
|
|
|
803
853
|
execution = self.sandbox.run_code(code, language="python")
|
|
804
854
|
print(execution.to_json())
|
|
@@ -3292,68 +3342,68 @@ print(f"\\n完成 {len(results)} 个API调用")
|
|
|
3292
3342
|
self.test_file_operations_simulation, "File Operations Simulation"
|
|
3293
3343
|
)
|
|
3294
3344
|
|
|
3295
|
-
# 性能测试
|
|
3296
|
-
self.run_test(
|
|
3297
|
-
|
|
3298
|
-
)
|
|
3299
|
-
self.run_test(
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
)
|
|
3303
|
-
|
|
3304
|
-
# 结果格式测试
|
|
3305
|
-
self.run_test(self.test_text_result, "Text Result Format")
|
|
3306
|
-
self.run_test(self.test_html_result, "HTML Result Format")
|
|
3307
|
-
self.run_test(self.test_markdown_result, "Markdown Result Format")
|
|
3308
|
-
self.run_test(self.test_svg_result, "SVG Result Format")
|
|
3309
|
-
self.run_test(self.test_image_results, "Image Result Formats (PNG/JPEG)")
|
|
3310
|
-
self.run_test(self.test_latex_result, "LaTeX Result Format")
|
|
3311
|
-
self.run_test(self.test_json_data_result, "JSON Data Result Format")
|
|
3312
|
-
self.run_test(self.test_javascript_result, "JavaScript Result Format")
|
|
3313
|
-
self.run_test(self.test_chart_data_result, "Chart Data Result Format")
|
|
3314
|
-
self.run_test(self.test_mixed_format_result, "Mixed Format Result")
|
|
3315
|
-
|
|
3316
|
-
# R语言测试
|
|
3317
|
-
self.run_test(
|
|
3318
|
-
|
|
3319
|
-
)
|
|
3320
|
-
self.run_test(self.test_r_language_data_analysis, "R Language Data Analysis")
|
|
3321
|
-
self.run_test(self.test_r_language_visualization, "R Language Visualization")
|
|
3322
|
-
self.run_test(self.test_r_language_statistics, "R Language Statistics")
|
|
3323
|
-
self.run_test(
|
|
3324
|
-
|
|
3325
|
-
)
|
|
3326
|
-
|
|
3327
|
-
# Node.js/JavaScript 测试
|
|
3328
|
-
self.run_test(self.test_nodejs_basic_execution, "Node.js Basic Execution")
|
|
3329
|
-
self.run_test(self.test_nodejs_async_promises, "Node.js Async Promises")
|
|
3330
|
-
self.run_test(self.test_nodejs_data_processing, "Node.js Data Processing")
|
|
3331
|
-
self.run_test(self.test_nodejs_chart_data, "Node.js Chart Data Generation")
|
|
3332
|
-
self.run_test(self.test_nodejs_context_management, "Node.js Context Management")
|
|
3333
|
-
|
|
3334
|
-
# Bash 测试
|
|
3335
|
-
self.run_test(self.test_bash_basic_execution, "Bash Basic Execution")
|
|
3336
|
-
self.run_test(self.test_bash_file_operations, "Bash File Operations")
|
|
3337
|
-
self.run_test(self.test_bash_pipelines_and_grep, "Bash Pipelines and Grep")
|
|
3338
|
-
# self.run_test(self.test_bash_env_and_exit_codes, "Bash Env and Exit Codes")
|
|
3339
|
-
self.run_test(self.test_bash_context_management, "Bash Context Management")
|
|
3340
|
-
|
|
3341
|
-
# IJAVA 测试
|
|
3342
|
-
self.run_test(self.test_ijava_basic_execution, "IJAVA Basic Execution")
|
|
3343
|
-
self.run_test(self.test_ijava_oop_features, "IJAVA OOP Features")
|
|
3344
|
-
self.run_test(self.test_ijava_collections, "IJAVA Collections")
|
|
3345
|
-
self.run_test(self.test_ijava_file_io, "IJAVA File I/O")
|
|
3346
|
-
self.run_test(self.test_ijava_context_management, "IJAVA Context Management")
|
|
3347
|
-
|
|
3348
|
-
# Deno 测试
|
|
3349
|
-
self.run_test(self.test_deno_basic_execution, "Deno Basic Execution")
|
|
3350
|
-
self.run_test(self.test_deno_typescript_features, "Deno TypeScript Features")
|
|
3351
|
-
self.run_test(self.test_deno_async_await, "Deno Async/Await")
|
|
3352
|
-
self.run_test(self.test_deno_file_operations, "Deno File Operations")
|
|
3353
|
-
self.run_test(self.test_deno_context_management, "Deno Context Management")
|
|
3354
|
-
|
|
3355
|
-
# 高级功能测试
|
|
3356
|
-
self.run_test(self.test_web_request_simulation, "Web Request Simulation")
|
|
3345
|
+
# # 性能测试
|
|
3346
|
+
# self.run_test(
|
|
3347
|
+
# self.test_performance_simple_calculations, "Performance Simple Calculations"
|
|
3348
|
+
# )
|
|
3349
|
+
# self.run_test(
|
|
3350
|
+
# self.test_performance_concurrent_simulation,
|
|
3351
|
+
# "Performance Concurrent Simulation",
|
|
3352
|
+
# )
|
|
3353
|
+
|
|
3354
|
+
# # 结果格式测试
|
|
3355
|
+
# self.run_test(self.test_text_result, "Text Result Format")
|
|
3356
|
+
# self.run_test(self.test_html_result, "HTML Result Format")
|
|
3357
|
+
# self.run_test(self.test_markdown_result, "Markdown Result Format")
|
|
3358
|
+
# self.run_test(self.test_svg_result, "SVG Result Format")
|
|
3359
|
+
# self.run_test(self.test_image_results, "Image Result Formats (PNG/JPEG)")
|
|
3360
|
+
# self.run_test(self.test_latex_result, "LaTeX Result Format")
|
|
3361
|
+
# self.run_test(self.test_json_data_result, "JSON Data Result Format")
|
|
3362
|
+
# self.run_test(self.test_javascript_result, "JavaScript Result Format")
|
|
3363
|
+
# self.run_test(self.test_chart_data_result, "Chart Data Result Format")
|
|
3364
|
+
# self.run_test(self.test_mixed_format_result, "Mixed Format Result")
|
|
3365
|
+
#
|
|
3366
|
+
# # R语言测试
|
|
3367
|
+
# self.run_test(
|
|
3368
|
+
# self.test_r_language_basic_execution, "R Language Basic Execution"
|
|
3369
|
+
# )
|
|
3370
|
+
# self.run_test(self.test_r_language_data_analysis, "R Language Data Analysis")
|
|
3371
|
+
# self.run_test(self.test_r_language_visualization, "R Language Visualization")
|
|
3372
|
+
# self.run_test(self.test_r_language_statistics, "R Language Statistics")
|
|
3373
|
+
# self.run_test(
|
|
3374
|
+
# self.test_r_language_context_management, "R Language Context Management"
|
|
3375
|
+
# )
|
|
3376
|
+
#
|
|
3377
|
+
# # Node.js/JavaScript 测试
|
|
3378
|
+
# self.run_test(self.test_nodejs_basic_execution, "Node.js Basic Execution")
|
|
3379
|
+
# self.run_test(self.test_nodejs_async_promises, "Node.js Async Promises")
|
|
3380
|
+
# self.run_test(self.test_nodejs_data_processing, "Node.js Data Processing")
|
|
3381
|
+
# self.run_test(self.test_nodejs_chart_data, "Node.js Chart Data Generation")
|
|
3382
|
+
# self.run_test(self.test_nodejs_context_management, "Node.js Context Management")
|
|
3383
|
+
#
|
|
3384
|
+
# # Bash 测试
|
|
3385
|
+
# self.run_test(self.test_bash_basic_execution, "Bash Basic Execution")
|
|
3386
|
+
# self.run_test(self.test_bash_file_operations, "Bash File Operations")
|
|
3387
|
+
# self.run_test(self.test_bash_pipelines_and_grep, "Bash Pipelines and Grep")
|
|
3388
|
+
# # self.run_test(self.test_bash_env_and_exit_codes, "Bash Env and Exit Codes")
|
|
3389
|
+
# self.run_test(self.test_bash_context_management, "Bash Context Management")
|
|
3390
|
+
#
|
|
3391
|
+
# # IJAVA 测试
|
|
3392
|
+
# self.run_test(self.test_ijava_basic_execution, "IJAVA Basic Execution")
|
|
3393
|
+
# self.run_test(self.test_ijava_oop_features, "IJAVA OOP Features")
|
|
3394
|
+
# self.run_test(self.test_ijava_collections, "IJAVA Collections")
|
|
3395
|
+
# self.run_test(self.test_ijava_file_io, "IJAVA File I/O")
|
|
3396
|
+
# self.run_test(self.test_ijava_context_management, "IJAVA Context Management")
|
|
3397
|
+
#
|
|
3398
|
+
# # Deno 测试
|
|
3399
|
+
# self.run_test(self.test_deno_basic_execution, "Deno Basic Execution")
|
|
3400
|
+
# # self.run_test(self.test_deno_typescript_features, "Deno TypeScript Features")
|
|
3401
|
+
# self.run_test(self.test_deno_async_await, "Deno Async/Await")
|
|
3402
|
+
# self.run_test(self.test_deno_file_operations, "Deno File Operations")
|
|
3403
|
+
# self.run_test(self.test_deno_context_management, "Deno Context Management")
|
|
3404
|
+
#
|
|
3405
|
+
# # 高级功能测试
|
|
3406
|
+
# self.run_test(self.test_web_request_simulation, "Web Request Simulation")
|
|
3357
3407
|
|
|
3358
3408
|
def cleanup(self):
|
|
3359
3409
|
"""清理资源"""
|