-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_production.py
More file actions
288 lines (240 loc) · 8.94 KB
/
Copy pathvalidate_production.py
File metadata and controls
288 lines (240 loc) · 8.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
"""
生产环境验证脚本
快速检查所有生产级功能是否正常
"""
import sys
import os
def test_imports():
"""测试所有模块是否可以导入"""
print("="*60)
print("Testing Module Imports")
print("="*60)
# 首先检查是否已安装
try:
import openspace_openhands_evolution
print("✅ Package is installed")
installed = True
except ImportError:
print("❌ Package not installed")
print("\n💡 Solution: Run 'pip install -e .' to install the package")
print(" Or add the project directory to PYTHONPATH")
installed = False
return False
modules = [
('openspace_openhands_evolution.orchestrator', 'Orchestrator'),
('openspace_openhands_evolution.execution_engine', 'Execution Engine'),
('openspace_openhands_evolution.llm_integration', 'LLM Integration'),
('openspace_openhands_evolution.production_engine', 'Production Engine'),
('openspace_openhands_evolution.monitor', 'Monitor System'),
('openspace_openhands_evolution.governance', 'Governance'),
]
failed = []
for module_name, description in modules:
try:
__import__(module_name)
print(f"✅ {description:30s} - OK")
except ImportError as e:
print(f"❌ {description:30s} - FAILED: {e}")
failed.append(module_name)
print()
if failed:
print(f"⚠️ {len(failed)} module(s) failed to import")
return False
else:
print("✅ All modules imported successfully!")
return True
def test_dependencies():
"""测试关键依赖是否安装"""
print("\n" + "="*60)
print("Testing Dependencies")
print("="*60)
packages = [
('openai', 'OpenAI SDK (optional)'),
('anthropic', 'Anthropic SDK (optional)'),
('yaml', 'PyYAML'),
('pydantic', 'Pydantic'),
]
missing_optional = []
missing_required = []
for package, description in packages:
try:
__import__(package.replace('-', '_'))
print(f"✅ {description:30s} - Installed")
except ImportError:
if 'optional' in description:
print(f"⚠️ {description:30s} - Not installed (optional)")
missing_optional.append(package)
else:
print(f"❌ {description:30s} - MISSING")
missing_required.append(package)
print()
if missing_required:
print(f"❌ Required packages missing: {', '.join(missing_required)}")
print(f" Install with: pip install {' '.join(missing_required)}")
return False
else:
print("✅ All required dependencies installed!")
if missing_optional:
print(f"ℹ️ Optional packages not installed: {', '.join(missing_optional)}")
return True
def test_execution_sandbox():
"""测试执行沙箱"""
print("\n" + "="*60)
print("Testing Execution Sandbox")
print("="*60)
try:
import asyncio
from openspace_openhands_evolution.execution_engine import ExecutionSandbox
async def test():
sandbox = ExecutionSandbox(timeout=5)
# 测试 Python 执行
result = await sandbox.execute_python("print('Hello from sandbox!')")
if result['success']:
print("✅ Python execution - OK")
print(f" Output: {result['stdout'].strip()}")
else:
print(f"❌ Python execution - FAILED: {result['stderr']}")
return False
# 测试文件写入
success = sandbox.write_file("test.txt", "Test content")
if success:
print("✅ File write - OK")
else:
print("❌ File write - FAILED")
return False
# 测试文件读取
content = sandbox.read_file("test.txt")
if content == "Test content":
print("✅ File read - OK")
else:
print("❌ File read - FAILED")
return False
sandbox.cleanup()
return True
success = asyncio.run(test())
return success
except Exception as e:
print(f"❌ Execution sandbox test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_llm_router():
"""测试 LLM 路由器(不实际调用 API)"""
print("\n" + "="*60)
print("Testing LLM Router")
print("="*60)
try:
from openspace_openhands_evolution.llm_integration import LLMRouter
# 测试 Ollama(不需要 API key)
try:
config = {
"provider": "ollama",
"model": "llama2",
"base_url": "http://localhost:11434"
}
router = LLMRouter(config)
print("✅ Ollama provider - Initialized")
print(" Note: Requires Ollama running at localhost:11434")
except Exception as e:
print(f"⚠️ Ollama provider - Not available: {e}")
# 测试 OpenAI(需要 API key)
api_key = os.getenv('OPENAI_API_KEY', '')
if api_key and api_key != 'your-api-key-here':
try:
config = {
"provider": "openai",
"model": "gpt-4",
"api_key": api_key
}
router = LLMRouter(config)
print("✅ OpenAI provider - Configured")
except Exception as e:
print(f"⚠️ OpenAI provider - Config error: {e}")
else:
print("⚠️ OpenAI provider - No API key configured")
print(" Set OPENAI_API_KEY environment variable to enable")
# 测试 Anthropic(需要 API key)
api_key = os.getenv('ANTHROPIC_API_KEY', '')
if api_key and api_key != 'your-api-key-here':
try:
config = {
"provider": "anthropic",
"model": "claude-3-opus-20240229",
"api_key": api_key
}
router = LLMRouter(config)
print("✅ Anthropic provider - Configured")
except Exception as e:
print(f"⚠️ Anthropic provider - Config error: {e}")
else:
print("⚠️ Anthropic provider - No API key configured")
print(" Set ANTHROPIC_API_KEY environment variable to enable")
print("\n✅ LLM Router - Working")
return True
except Exception as e:
print(f"❌ LLM Router test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_version():
"""测试版本号"""
print("\n" + "="*60)
print("Version Check")
print("="*60)
try:
from openspace_openhands_evolution import __version__
print(f"✅ Version: {__version__}")
if __version__ == "1.0.0":
print("✅ Production version confirmed!")
return True
else:
print(f"⚠️ Expected version 1.0.0, got {__version__}")
return False
except Exception as e:
print(f"❌ Version check failed: {e}")
return False
def main():
"""运行所有测试"""
print("\n" + "🔍"*30)
print("OpenSpace-OpenHands-Evolution Production Validation")
print("🔍"*30 + "\n")
tests = [
("Module Imports", test_imports),
("Dependencies", test_dependencies),
("Execution Sandbox", test_execution_sandbox),
("LLM Router", test_llm_router),
("Version", test_version),
]
results = {}
for name, test_func in tests:
try:
results[name] = test_func()
except Exception as e:
print(f"\n❌ {name} test crashed: {e}")
results[name] = False
# 总结
print("\n" + "="*60)
print("VALIDATION SUMMARY")
print("="*60)
for name, passed in results.items():
status = "✅ PASS" if passed else "❌ FAIL"
print(f"{status:10s} - {name}")
total = len(results)
passed = sum(1 for v in results.values() if v)
print("\n" + "-"*60)
print(f"Total: {passed}/{total} tests passed")
print("-"*60)
if passed == total:
print("\n🎉 ALL TESTS PASSED!")
print("\n✅ Project is PRODUCTION READY!")
print("\nNext steps:")
print(" 1. Configure your API keys in config.yaml")
print(" 2. Run: openspace-evolution")
print(" 3. Or: openspace-evolution run \"Your task\"")
return 0
else:
print(f"\n⚠️ {total - passed} test(s) failed")
print("\nPlease fix the issues above before using in production.")
return 1
if __name__ == "__main__":
sys.exit(main())