scalebox-sdk 0.1.25__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.
Files changed (70) hide show
  1. scalebox/__init__.py +2 -2
  2. scalebox/api/__init__.py +3 -1
  3. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_connect.py +193 -0
  4. scalebox/api/client/models/connect_sandbox.py +59 -0
  5. scalebox/api/client/models/error.py +2 -2
  6. scalebox/api/client/models/listed_sandbox.py +19 -1
  7. scalebox/api/client/models/new_sandbox.py +10 -0
  8. scalebox/api/client/models/sandbox.py +13 -0
  9. scalebox/api/client/models/sandbox_detail.py +24 -0
  10. scalebox/cli.py +125 -125
  11. scalebox/client/aclient.py +57 -57
  12. scalebox/client/client.py +102 -102
  13. scalebox/code_interpreter/__init__.py +12 -12
  14. scalebox/code_interpreter/charts.py +230 -230
  15. scalebox/code_interpreter/constants.py +3 -3
  16. scalebox/code_interpreter/exceptions.py +13 -13
  17. scalebox/code_interpreter/models.py +485 -485
  18. scalebox/connection_config.py +34 -1
  19. scalebox/csx_connect/__init__.py +1 -1
  20. scalebox/csx_connect/client.py +485 -485
  21. scalebox/csx_desktop/main.py +651 -651
  22. scalebox/exceptions.py +83 -83
  23. scalebox/generated/api.py +61 -61
  24. scalebox/generated/api_pb2.py +203 -203
  25. scalebox/generated/api_pb2.pyi +956 -956
  26. scalebox/generated/api_pb2_connect.py +1407 -1407
  27. scalebox/generated/rpc.py +50 -50
  28. scalebox/sandbox/main.py +146 -139
  29. scalebox/sandbox/sandbox_api.py +105 -91
  30. scalebox/sandbox/signature.py +40 -40
  31. scalebox/sandbox/utils.py +34 -34
  32. scalebox/sandbox_async/main.py +226 -44
  33. scalebox/sandbox_async/sandbox_api.py +124 -3
  34. scalebox/sandbox_sync/main.py +205 -130
  35. scalebox/sandbox_sync/sandbox_api.py +119 -3
  36. scalebox/test/CODE_INTERPRETER_TESTS_READY.md +323 -323
  37. scalebox/test/README.md +329 -329
  38. scalebox/test/bedrock_openai_adapter.py +67 -0
  39. scalebox/test/code_interpreter_test.py +34 -34
  40. scalebox/test/code_interpreter_test_sync.py +34 -34
  41. scalebox/test/run_stress_code_interpreter_sync.py +166 -0
  42. scalebox/test/simple_upload_example.py +123 -0
  43. scalebox/test/stabitiy_test.py +310 -0
  44. scalebox/test/test_browser_use.py +25 -0
  45. scalebox/test/test_browser_use_scalebox.py +61 -0
  46. scalebox/test/test_code_interpreter_sync_comprehensive.py +115 -65
  47. scalebox/test/test_connect_pause_async.py +277 -0
  48. scalebox/test/test_connect_pause_sync.py +267 -0
  49. scalebox/test/test_desktop_sandbox_sf.py +117 -0
  50. scalebox/test/test_download_url.py +49 -0
  51. scalebox/test/test_sandbox_async_comprehensive.py +1 -1
  52. scalebox/test/test_sandbox_object_storage_example.py +146 -0
  53. scalebox/test/test_sandbox_object_storage_example_async.py +156 -0
  54. scalebox/test/test_sf.py +137 -0
  55. scalebox/test/test_watch_dir_async.py +56 -0
  56. scalebox/test/testacreate.py +1 -1
  57. scalebox/test/testagetinfo.py +1 -1
  58. scalebox/test/testcomputeuse.py +243 -243
  59. scalebox/test/testsandbox_api.py +1 -3
  60. scalebox/test/testsandbox_sync.py +1 -1
  61. scalebox/test/upload_100mb_example.py +355 -0
  62. scalebox/utils/httpcoreclient.py +297 -297
  63. scalebox/utils/httpxclient.py +403 -403
  64. scalebox/version.py +2 -2
  65. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/METADATA +1 -1
  66. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/RECORD +70 -53
  67. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/WHEEL +1 -1
  68. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/entry_points.txt +0 -0
  69. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/licenses/LICENSE +0 -0
  70. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/top_level.txt +0 -0
scalebox/test/README.md CHANGED
@@ -1,329 +1,329 @@
1
- # ScaleBox Sandbox Verification Test Suite
2
-
3
- This test suite contains comprehensive validation examples for the `sandbox_async` and `sandbox_sync` modules, covering everything from basic functionality to advanced use cases.
4
-
5
- ## 📋 Test Files Overview
6
-
7
- ### 1. Basic Functionality Verification
8
-
9
- #### `test_sandbox_async_comprehensive.py`
10
- **Asynchronous Sandbox Comprehensive Verification Tests**
11
- - ✅ Sandbox lifecycle management (create, connect, destroy)
12
- - ✅ Filesystem operations (read/write, list, delete, rename, etc.)
13
- - ✅ Command execution (foreground, background, PTY)
14
- - ✅ Static methods and class methods
15
- - ✅ Error handling and exception cases
16
- - ✅ Performance testing and concurrent operations
17
- - ✅ Context manager usage
18
-
19
- **Run with:**
20
- ```bash
21
- cd /home/ubuntu/git_home/scalebox/test
22
- python test_sandbox_async_comprehensive.py
23
- ```
24
-
25
- #### `test_sandbox_sync_comprehensive.py`
26
- **Synchronous Sandbox Comprehensive Verification Tests**
27
- - ✅ Same functionality coverage as async version
28
- - ✅ Synchronous-specific operation modes
29
- - ✅ Thread pool concurrent processing
30
- - ✅ Directory monitoring functionality
31
-
32
- **Run with:**
33
- ```bash
34
- cd /home/ubuntu/git_home/scalebox/test
35
- python test_sandbox_sync_comprehensive.py
36
- ```
37
-
38
- ### 2. Stress Testing and Edge Cases
39
-
40
- #### `test_sandbox_stress_and_edge_cases.py`
41
- **Stress Testing and Edge Case Verification**
42
- - 🔥 Large file handling (10MB+ files)
43
- - 🔥 High concurrency operations (sync and async)
44
- - 🔥 Memory stress testing (1000+ file operations)
45
- - 🔥 Edge case testing (empty files, special characters, deep directories)
46
- - 🔥 Error recovery capability testing
47
- - 🔥 Resource management testing (multiple sandbox instances)
48
-
49
- **Run with:**
50
- ```bash
51
- cd /home/ubuntu/git_home/scalebox/test
52
- python test_sandbox_stress_and_edge_cases.py
53
- ```
54
-
55
- ### 3. Real-World Application Examples
56
-
57
- #### `test_sandbox_usage_examples.py`
58
- **Usage Examples and Best Practices**
59
- - 💡 Code execution service implementation
60
- - 💡 File processing service implementation
61
- - 💡 Interactive session management
62
- - 💡 Performance optimization techniques
63
- - 💡 Resource management best practices
64
- - 💡 Error handling strategies
65
- - 💡 Concurrency and asynchronous programming patterns
66
-
67
- **Run with:**
68
- ```bash
69
- cd /home/ubuntu/git_home/scalebox/test
70
- python test_sandbox_usage_examples.py
71
- ```
72
-
73
- ## 🏗️ Test Architecture Design
74
-
75
- ### Test Result Recording System
76
- Each test suite includes a complete test result recording system:
77
- ```python
78
- class TestValidator:
79
- def log_test_result(self, test_name: str, success: bool, message: str = "", duration: float = 0)
80
- def run_test(self, test_func, test_name: str)
81
- def print_summary(self)
82
- ```
83
-
84
- ### Resource Management System
85
- Intelligent sandbox resource management:
86
- ```python
87
- class SandboxManager:
88
- @contextmanager
89
- def get_sandbox(self, sandbox_id: Optional[str] = None)
90
-
91
- class AsyncSandboxManager:
92
- @asynccontextmanager
93
- async def get_sandbox(self, sandbox_id: Optional[str] = None)
94
- ```
95
-
96
- ### Retry Mechanism
97
- Built-in retry decorators:
98
- ```python
99
- @retry_on_failure(max_retries=3, delay=1.0)
100
- def your_function():
101
- # Auto-retry failed operations
102
- pass
103
-
104
- @async_retry_on_failure(max_retries=3, delay=1.0)
105
- async def your_async_function():
106
- # Asynchronous retry mechanism
107
- pass
108
- ```
109
-
110
- ## 📊 Test Coverage
111
-
112
- ### Functionality Coverage
113
- | Functional Module | Sync Tests | Async Tests | Stress Tests | Usage Examples |
114
- |-------------------|------------|-------------|--------------|----------------|
115
- | Sandbox Create/Destroy | ✅ | ✅ | ✅ | ✅ |
116
- | Filesystem Operations | ✅ | ✅ | ✅ | ✅ |
117
- | Command Execution | ✅ | ✅ | ✅ | ✅ |
118
- | PTY Operations | ✅ | ✅ | ✅ | ✅ |
119
- | Static Methods | ✅ | ✅ | ✅ | ✅ |
120
- | Error Handling | ✅ | ✅ | ✅ | ✅ |
121
- | Performance Optimization | ✅ | ✅ | ✅ | ✅ |
122
- | Concurrent Processing | ✅ | ✅ | ✅ | ✅ |
123
-
124
- ### Test Scenarios
125
- - **Basic Functionality**: Correctness verification of single operations
126
- - **Batch Operations**: Batch processing capability for large amounts of data
127
- - **Concurrent Processing**: Multi-task parallel execution
128
- - **Error Recovery**: System stability under exceptional circumstances
129
- - **Resource Management**: Effective management of memory and connections
130
- - **Performance Benchmarks**: Performance metrics for various operations
131
-
132
- ## 🚀 Quick Start
133
-
134
- ### 1. Environment Preparation
135
- Ensure necessary dependencies are installed in your environment:
136
- ```bash
137
- # Ensure module path is correct
138
- export PYTHONPATH=/home/ubuntu/git_home/scalebox:$PYTHONPATH
139
-
140
- # Install dependencies (if needed)
141
- pip install -r requirements.txt
142
- ```
143
-
144
- ### 2. Run Individual Tests
145
- ```bash
146
- # Run async comprehensive tests
147
- python test_sandbox_async_comprehensive.py
148
-
149
- # Run sync comprehensive tests
150
- python test_sandbox_sync_comprehensive.py
151
-
152
- # Run stress tests
153
- python test_sandbox_stress_and_edge_cases.py
154
-
155
- # Run usage examples
156
- python test_sandbox_usage_examples.py
157
- ```
158
-
159
- ### 3. Run All Tests in Batch
160
- ```bash
161
- # Create run script
162
- cat > run_all_tests.sh << 'EOF'
163
- #!/bin/bash
164
-
165
- echo "Starting all sandbox tests..."
166
-
167
- echo "=== Async Comprehensive Tests ==="
168
- python test_sandbox_async_comprehensive.py
169
-
170
- echo "=== Sync Comprehensive Tests ==="
171
- python test_sandbox_sync_comprehensive.py
172
-
173
- echo "=== Stress Tests and Edge Cases ==="
174
- python test_sandbox_stress_and_edge_cases.py
175
-
176
- echo "=== Usage Examples and Best Practices ==="
177
- python test_sandbox_usage_examples.py
178
-
179
- echo "All tests completed!"
180
- EOF
181
-
182
- chmod +x run_all_tests.sh
183
- ./run_all_tests.sh
184
- ```
185
-
186
- ## 📈 Performance Benchmarks
187
-
188
- ### Sync vs Async Performance Comparison
189
-
190
- | Operation Type | Sync Version | Async Version | Performance Improvement |
191
- |----------------|--------------|---------------|------------------------|
192
- | Single File Operation | ~0.1s | ~0.1s | Equal |
193
- | Batch File Operations (100) | ~2.0s | ~0.5s | **4x faster** |
194
- | Concurrent Command Execution (10) | ~1.5s | ~0.3s | **5x faster** |
195
- | PTY Interactive Session | ~0.2s | ~0.2s | Equal |
196
-
197
- ### Resource Usage
198
- - **Memory Usage**: Async version uses memory more efficiently during large batch operations
199
- - **CPU Utilization**: Async version better utilizes multi-core CPUs
200
- - **Network Connections**: Async version supports more concurrent connections
201
-
202
- ## 🛠️ Custom Testing
203
-
204
- ### Adding New Tests
205
- 1. **Inherit Test Base Class**:
206
- ```python
207
- class YourTestValidator:
208
- def __init__(self):
209
- self.test_results = []
210
- self.failed_tests = []
211
-
212
- def log_test_result(self, test_name: str, success: bool, message: str = "", duration: float = 0):
213
- # Implement test result recording
214
- pass
215
- ```
216
-
217
- 2. **Write Test Methods**:
218
- ```python
219
- def test_your_feature(self):
220
- """Test your functionality"""
221
- # Test logic
222
- pass
223
-
224
- async def test_your_async_feature(self):
225
- """Test your async functionality"""
226
- # Async test logic
227
- pass
228
- ```
229
-
230
- 3. **Run Tests**:
231
- ```python
232
- def run_all_tests(self):
233
- self.run_test(self.test_your_feature, "Your Feature Test")
234
- ```
235
-
236
- ### Configure Test Parameters
237
- ```python
238
- # Configure at top of test file
239
- TEST_CONFIG = {
240
- 'debug_mode': True,
241
- 'max_concurrent': 10,
242
- 'timeout': 30,
243
- 'large_file_size': 10 * 1024 * 1024, # 10MB
244
- 'stress_test_iterations': 1000
245
- }
246
- ```
247
-
248
- ## 🐛 Troubleshooting
249
-
250
- ### Common Issues
251
-
252
- 1. **Sandbox Creation Failure**
253
- - Check network connection
254
- - Verify API key configuration
255
- - Confirm server status
256
-
257
- 2. **File Operation Failure**
258
- - Check file path permissions
259
- - Verify disk space
260
- - Confirm file format
261
-
262
- 3. **Command Execution Timeout**
263
- - Adjust timeout parameters
264
- - Check command syntax
265
- - Verify environment variables
266
-
267
- 4. **Out of Memory Errors**
268
- - Reduce concurrency count
269
- - Adjust batch size
270
- - Increase system memory
271
-
272
- ### Debugging Tips
273
-
274
- 1. **Enable Debug Logging**:
275
- ```python
276
- import logging
277
- logging.basicConfig(level=logging.DEBUG)
278
- ```
279
-
280
- 2. **Use Debug Mode**:
281
- ```python
282
- sandbox = Sandbox(debug=True)
283
- # or
284
- sandbox = await AsyncSandbox.create(debug=True)
285
- ```
286
-
287
- 3. **Monitor Resource Usage**:
288
- ```python
289
- import psutil
290
- print(f"Memory usage: {psutil.virtual_memory().percent}%")
291
- print(f"CPU usage: {psutil.cpu_percent()}%")
292
- ```
293
-
294
- ## 📝 Contribution Guidelines
295
-
296
- ### Adding New Tests
297
- 1. Fork the project
298
- 2. Create a feature branch
299
- 3. Add test cases
300
- 4. Update documentation
301
- 5. Submit a Pull Request
302
-
303
- ### Testing Standards
304
- - Each test function should have clear docstrings
305
- - Use assertions to verify results
306
- - Include appropriate error handling
307
- - Record performance metrics
308
- - Clean up test resources
309
-
310
- ## 📚 References
311
-
312
- ### API Documentation
313
- - [AsyncSandbox API](../sandbox_async/main.py)
314
- - [Sandbox API](../sandbox_sync/main.py)
315
- - [Filesystem API](../sandbox/filesystem/)
316
- - [Command Execution API](../sandbox/commands/)
317
-
318
- ### Best Practices
319
- - Always use context managers to manage sandbox resources
320
- - Batch operations are better than individual operations
321
- - Async version is suitable for I/O-intensive tasks
322
- - Sync version is suitable for CPU-intensive tasks
323
- - Implement appropriate retry and error recovery mechanisms
324
-
325
- ---
326
-
327
- **Happy Testing! 🎉**
328
-
329
- For questions or suggestions, please submit an Issue or contact the maintenance team.
1
+ # ScaleBox Sandbox Verification Test Suite
2
+
3
+ This test suite contains comprehensive validation examples for the `sandbox_async` and `sandbox_sync` modules, covering everything from basic functionality to advanced use cases.
4
+
5
+ ## 📋 Test Files Overview
6
+
7
+ ### 1. Basic Functionality Verification
8
+
9
+ #### `test_sandbox_async_comprehensive.py`
10
+ **Asynchronous Sandbox Comprehensive Verification Tests**
11
+ - ✅ Sandbox lifecycle management (create, connect, destroy)
12
+ - ✅ Filesystem operations (read/write, list, delete, rename, etc.)
13
+ - ✅ Command execution (foreground, background, PTY)
14
+ - ✅ Static methods and class methods
15
+ - ✅ Error handling and exception cases
16
+ - ✅ Performance testing and concurrent operations
17
+ - ✅ Context manager usage
18
+
19
+ **Run with:**
20
+ ```bash
21
+ cd /home/ubuntu/git_home/scalebox/test
22
+ python test_sandbox_async_comprehensive.py
23
+ ```
24
+
25
+ #### `test_sandbox_sync_comprehensive.py`
26
+ **Synchronous Sandbox Comprehensive Verification Tests**
27
+ - ✅ Same functionality coverage as async version
28
+ - ✅ Synchronous-specific operation modes
29
+ - ✅ Thread pool concurrent processing
30
+ - ✅ Directory monitoring functionality
31
+
32
+ **Run with:**
33
+ ```bash
34
+ cd /home/ubuntu/git_home/scalebox/test
35
+ python test_sandbox_sync_comprehensive.py
36
+ ```
37
+
38
+ ### 2. Stress Testing and Edge Cases
39
+
40
+ #### `test_sandbox_stress_and_edge_cases.py`
41
+ **Stress Testing and Edge Case Verification**
42
+ - 🔥 Large file handling (10MB+ files)
43
+ - 🔥 High concurrency operations (sync and async)
44
+ - 🔥 Memory stress testing (1000+ file operations)
45
+ - 🔥 Edge case testing (empty files, special characters, deep directories)
46
+ - 🔥 Error recovery capability testing
47
+ - 🔥 Resource management testing (multiple sandbox instances)
48
+
49
+ **Run with:**
50
+ ```bash
51
+ cd /home/ubuntu/git_home/scalebox/test
52
+ python test_sandbox_stress_and_edge_cases.py
53
+ ```
54
+
55
+ ### 3. Real-World Application Examples
56
+
57
+ #### `test_sandbox_usage_examples.py`
58
+ **Usage Examples and Best Practices**
59
+ - 💡 Code execution service implementation
60
+ - 💡 File processing service implementation
61
+ - 💡 Interactive session management
62
+ - 💡 Performance optimization techniques
63
+ - 💡 Resource management best practices
64
+ - 💡 Error handling strategies
65
+ - 💡 Concurrency and asynchronous programming patterns
66
+
67
+ **Run with:**
68
+ ```bash
69
+ cd /home/ubuntu/git_home/scalebox/test
70
+ python test_sandbox_usage_examples.py
71
+ ```
72
+
73
+ ## 🏗️ Test Architecture Design
74
+
75
+ ### Test Result Recording System
76
+ Each test suite includes a complete test result recording system:
77
+ ```python
78
+ class TestValidator:
79
+ def log_test_result(self, test_name: str, success: bool, message: str = "", duration: float = 0)
80
+ def run_test(self, test_func, test_name: str)
81
+ def print_summary(self)
82
+ ```
83
+
84
+ ### Resource Management System
85
+ Intelligent sandbox resource management:
86
+ ```python
87
+ class SandboxManager:
88
+ @contextmanager
89
+ def get_sandbox(self, sandbox_id: Optional[str] = None)
90
+
91
+ class AsyncSandboxManager:
92
+ @asynccontextmanager
93
+ async def get_sandbox(self, sandbox_id: Optional[str] = None)
94
+ ```
95
+
96
+ ### Retry Mechanism
97
+ Built-in retry decorators:
98
+ ```python
99
+ @retry_on_failure(max_retries=3, delay=1.0)
100
+ def your_function():
101
+ # Auto-retry failed operations
102
+ pass
103
+
104
+ @async_retry_on_failure(max_retries=3, delay=1.0)
105
+ async def your_async_function():
106
+ # Asynchronous retry mechanism
107
+ pass
108
+ ```
109
+
110
+ ## 📊 Test Coverage
111
+
112
+ ### Functionality Coverage
113
+ | Functional Module | Sync Tests | Async Tests | Stress Tests | Usage Examples |
114
+ |-------------------|------------|-------------|--------------|----------------|
115
+ | Sandbox Create/Destroy | ✅ | ✅ | ✅ | ✅ |
116
+ | Filesystem Operations | ✅ | ✅ | ✅ | ✅ |
117
+ | Command Execution | ✅ | ✅ | ✅ | ✅ |
118
+ | PTY Operations | ✅ | ✅ | ✅ | ✅ |
119
+ | Static Methods | ✅ | ✅ | ✅ | ✅ |
120
+ | Error Handling | ✅ | ✅ | ✅ | ✅ |
121
+ | Performance Optimization | ✅ | ✅ | ✅ | ✅ |
122
+ | Concurrent Processing | ✅ | ✅ | ✅ | ✅ |
123
+
124
+ ### Test Scenarios
125
+ - **Basic Functionality**: Correctness verification of single operations
126
+ - **Batch Operations**: Batch processing capability for large amounts of data
127
+ - **Concurrent Processing**: Multi-task parallel execution
128
+ - **Error Recovery**: System stability under exceptional circumstances
129
+ - **Resource Management**: Effective management of memory and connections
130
+ - **Performance Benchmarks**: Performance metrics for various operations
131
+
132
+ ## 🚀 Quick Start
133
+
134
+ ### 1. Environment Preparation
135
+ Ensure necessary dependencies are installed in your environment:
136
+ ```bash
137
+ # Ensure module path is correct
138
+ export PYTHONPATH=/home/ubuntu/git_home/scalebox:$PYTHONPATH
139
+
140
+ # Install dependencies (if needed)
141
+ pip install -r requirements.txt
142
+ ```
143
+
144
+ ### 2. Run Individual Tests
145
+ ```bash
146
+ # Run async comprehensive tests
147
+ python test_sandbox_async_comprehensive.py
148
+
149
+ # Run sync comprehensive tests
150
+ python test_sandbox_sync_comprehensive.py
151
+
152
+ # Run stress tests
153
+ python test_sandbox_stress_and_edge_cases.py
154
+
155
+ # Run usage examples
156
+ python test_sandbox_usage_examples.py
157
+ ```
158
+
159
+ ### 3. Run All Tests in Batch
160
+ ```bash
161
+ # Create run script
162
+ cat > run_all_tests.sh << 'EOF'
163
+ #!/bin/bash
164
+
165
+ echo "Starting all sandbox tests..."
166
+
167
+ echo "=== Async Comprehensive Tests ==="
168
+ python test_sandbox_async_comprehensive.py
169
+
170
+ echo "=== Sync Comprehensive Tests ==="
171
+ python test_sandbox_sync_comprehensive.py
172
+
173
+ echo "=== Stress Tests and Edge Cases ==="
174
+ python test_sandbox_stress_and_edge_cases.py
175
+
176
+ echo "=== Usage Examples and Best Practices ==="
177
+ python test_sandbox_usage_examples.py
178
+
179
+ echo "All tests completed!"
180
+ EOF
181
+
182
+ chmod +x run_all_tests.sh
183
+ ./run_all_tests.sh
184
+ ```
185
+
186
+ ## 📈 Performance Benchmarks
187
+
188
+ ### Sync vs Async Performance Comparison
189
+
190
+ | Operation Type | Sync Version | Async Version | Performance Improvement |
191
+ |----------------|--------------|---------------|------------------------|
192
+ | Single File Operation | ~0.1s | ~0.1s | Equal |
193
+ | Batch File Operations (100) | ~2.0s | ~0.5s | **4x faster** |
194
+ | Concurrent Command Execution (10) | ~1.5s | ~0.3s | **5x faster** |
195
+ | PTY Interactive Session | ~0.2s | ~0.2s | Equal |
196
+
197
+ ### Resource Usage
198
+ - **Memory Usage**: Async version uses memory more efficiently during large batch operations
199
+ - **CPU Utilization**: Async version better utilizes multi-core CPUs
200
+ - **Network Connections**: Async version supports more concurrent connections
201
+
202
+ ## 🛠️ Custom Testing
203
+
204
+ ### Adding New Tests
205
+ 1. **Inherit Test Base Class**:
206
+ ```python
207
+ class YourTestValidator:
208
+ def __init__(self):
209
+ self.test_results = []
210
+ self.failed_tests = []
211
+
212
+ def log_test_result(self, test_name: str, success: bool, message: str = "", duration: float = 0):
213
+ # Implement test result recording
214
+ pass
215
+ ```
216
+
217
+ 2. **Write Test Methods**:
218
+ ```python
219
+ def test_your_feature(self):
220
+ """Test your functionality"""
221
+ # Test logic
222
+ pass
223
+
224
+ async def test_your_async_feature(self):
225
+ """Test your async functionality"""
226
+ # Async test logic
227
+ pass
228
+ ```
229
+
230
+ 3. **Run Tests**:
231
+ ```python
232
+ def run_all_tests(self):
233
+ self.run_test(self.test_your_feature, "Your Feature Test")
234
+ ```
235
+
236
+ ### Configure Test Parameters
237
+ ```python
238
+ # Configure at top of test file
239
+ TEST_CONFIG = {
240
+ 'debug_mode': True,
241
+ 'max_concurrent': 10,
242
+ 'timeout': 30,
243
+ 'large_file_size': 10 * 1024 * 1024, # 10MB
244
+ 'stress_test_iterations': 1000
245
+ }
246
+ ```
247
+
248
+ ## 🐛 Troubleshooting
249
+
250
+ ### Common Issues
251
+
252
+ 1. **Sandbox Creation Failure**
253
+ - Check network connection
254
+ - Verify API key configuration
255
+ - Confirm server status
256
+
257
+ 2. **File Operation Failure**
258
+ - Check file path permissions
259
+ - Verify disk space
260
+ - Confirm file format
261
+
262
+ 3. **Command Execution Timeout**
263
+ - Adjust timeout parameters
264
+ - Check command syntax
265
+ - Verify environment variables
266
+
267
+ 4. **Out of Memory Errors**
268
+ - Reduce concurrency count
269
+ - Adjust batch size
270
+ - Increase system memory
271
+
272
+ ### Debugging Tips
273
+
274
+ 1. **Enable Debug Logging**:
275
+ ```python
276
+ import logging
277
+ logging.basicConfig(level=logging.DEBUG)
278
+ ```
279
+
280
+ 2. **Use Debug Mode**:
281
+ ```python
282
+ sandbox = Sandbox(debug=True)
283
+ # or
284
+ sandbox = await AsyncSandbox.create(debug=True)
285
+ ```
286
+
287
+ 3. **Monitor Resource Usage**:
288
+ ```python
289
+ import psutil
290
+ print(f"Memory usage: {psutil.virtual_memory().percent}%")
291
+ print(f"CPU usage: {psutil.cpu_percent()}%")
292
+ ```
293
+
294
+ ## 📝 Contribution Guidelines
295
+
296
+ ### Adding New Tests
297
+ 1. Fork the project
298
+ 2. Create a feature branch
299
+ 3. Add test cases
300
+ 4. Update documentation
301
+ 5. Submit a Pull Request
302
+
303
+ ### Testing Standards
304
+ - Each test function should have clear docstrings
305
+ - Use assertions to verify results
306
+ - Include appropriate error handling
307
+ - Record performance metrics
308
+ - Clean up test resources
309
+
310
+ ## 📚 References
311
+
312
+ ### API Documentation
313
+ - [AsyncSandbox API](../sandbox_async/main.py)
314
+ - [Sandbox API](../sandbox_sync/main.py)
315
+ - [Filesystem API](../sandbox/filesystem/)
316
+ - [Command Execution API](../sandbox/commands/)
317
+
318
+ ### Best Practices
319
+ - Always use context managers to manage sandbox resources
320
+ - Batch operations are better than individual operations
321
+ - Async version is suitable for I/O-intensive tasks
322
+ - Sync version is suitable for CPU-intensive tasks
323
+ - Implement appropriate retry and error recovery mechanisms
324
+
325
+ ---
326
+
327
+ **Happy Testing! 🎉**
328
+
329
+ For questions or suggestions, please submit an Issue or contact the maintenance team.