-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_features.py
More file actions
380 lines (291 loc) · 11.4 KB
/
Copy pathvalidate_features.py
File metadata and controls
380 lines (291 loc) · 11.4 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/usr/bin/env python3
"""
Feature Validation Script for Agentic Code Generator.
Tests all implemented features without pytest dependencies.
"""
import os
import sys
import time
import tempfile
from pathlib import Path
# Add project to path
sys.path.insert(0, str(Path(__file__).parent))
from agentic_codegen.core.main import CodeGenerator
from agentic_codegen.utils.run_history import get_run_history_manager
from agentic_codegen.utils.collaborative_workspace import get_workspace_manager
from agentic_codegen.utils.logger import get_logger
logger = get_logger(__name__)
def test_basic_conversion():
"""Test basic Python to C++ conversion."""
print("🧪 Testing Basic Conversion...")
try:
generator = CodeGenerator()
test_code = """
def add_numbers(a, b):
return a + b
result = add_numbers(5, 3)
print(f"Result: {result}")
"""
# Skip validation for now due to compile() issue
cpp_code, metadata = generator.convert(test_code, input_file="test_conversion.py")
if cpp_code and metadata.get("success"):
print("✅ Basic conversion works")
print(f" Generated {len(cpp_code)} characters of C++ code")
return True
else:
print("❌ Basic conversion failed")
print(f" Error: {metadata}")
return False
except Exception as e:
print(f"❌ Basic conversion failed with exception: {e}")
return False
def test_agent_system():
"""Test that agents are properly initialized."""
print("🧪 Testing Agent System...")
try:
generator = CodeGenerator()
orchestrator = generator.orchestrator
# Check required agents exist
required_agents = ["analyzer", "translator", "optimizer", "verifier", "refiner"]
missing_agents = []
for agent_name in required_agents:
if not hasattr(orchestrator, agent_name):
missing_agents.append(agent_name)
if missing_agents:
print(f"❌ Missing agents: {missing_agents}")
return False
print("✅ All required agents are present")
print(f" Model: {orchestrator.model}")
print(f" Max iterations: {orchestrator.max_iterations}")
return True
except Exception as e:
print(f"❌ Agent system test failed: {e}")
return False
def test_run_history():
"""Test run history tracking."""
print("🧪 Testing Run History...")
try:
history_manager = get_run_history_manager()
# Get recent runs
runs = history_manager.get_run_history(limit=5)
print(f"✅ Run history accessible ({len(runs)} recent runs)")
# Get statistics
stats = history_manager.get_run_statistics(days=7)
print(f"✅ Statistics available: {stats.get('total_runs', 0)} runs in last 7 days")
return True
except Exception as e:
print(f"❌ Run history test failed: {e}")
return False
def test_batch_processing():
"""Test batch processing capabilities."""
print("🧪 Testing Batch Processing...")
try:
generator = CodeGenerator()
# Create temporary test files
with tempfile.TemporaryDirectory() as tmp_dir:
# Create test files
test_files = []
for i in range(2):
file_path = Path(tmp_dir) / f"test_{i}.py"
with open(file_path, "w") as f:
f.write(f"def func_{i}(): return {i * 10}")
test_files.append(str(file_path))
# Create output directory
output_dir = Path(tmp_dir) / "output"
output_dir.mkdir()
# Test batch conversion
results = generator.convert_directory(
input_dir=tmp_dir, output_dir=str(output_dir), target_language="cpp"
)
print(f"✅ Batch processing completed: {len(results)} files processed")
# Check output files
cpp_files = list(output_dir.glob("*.cpp"))
print(f" Generated {len(cpp_files)} C++ files")
return len(results) > 0
except Exception as e:
print(f"❌ Batch processing test failed: {e}")
return False
def test_collaborative_features():
"""Test collaborative workspace features."""
print("🧪 Testing Collaborative Features...")
try:
workspace_manager = get_workspace_manager()
# Test workspace creation
workspace_id = workspace_manager.create_workspace(
name="Test Validation Workspace",
description="Workspace for validation testing",
created_by="validation_user",
)
if workspace_id:
print("✅ Workspace creation works")
else:
print("❌ Workspace creation failed")
return False
# Test code sharing
code_id = workspace_manager.share_code(
workspace_id=workspace_id,
user_id="validation_user",
title="Validation Test Code",
description="Code for testing validation",
python_code="def test(): return 42",
target_languages=["cpp"],
tags=["test", "validation"],
)
if code_id:
print("✅ Code sharing works")
else:
print("❌ Code sharing failed")
return False
# Test workspace stats
stats = workspace_manager.get_workspace_stats(workspace_id)
if stats:
print("✅ Workspace statistics work")
print(f" Members: {stats['total_members']}")
print(f" Codes: {stats['total_codes']}")
else:
print("❌ Workspace statistics failed")
return False
return True
except Exception as e:
print(f"❌ Collaborative features test failed: {e}")
return False
def test_web_interface_imports():
"""Test that web interface can be imported."""
print("🧪 Testing Web Interface Imports...")
try:
from agentic_codegen.ui.web_interface import create_interface
print("✅ Web interface imports successfully")
return True
except Exception as e:
print(f"❌ Web interface import failed: {e}")
return False
def test_parallel_processing():
"""Test parallel processing with multiple workers."""
print("🧪 Testing Parallel Processing...")
try:
generator = CodeGenerator()
with tempfile.TemporaryDirectory() as tmp_dir:
# Create multiple test files
for i in range(4):
file_path = Path(tmp_dir) / f"parallel_test_{i}.py"
with open(file_path, "w") as f:
f.write(
f"""
def compute_{i}(x):
result = 0
for j in range(x):
result += j * {i + 1}
return result
print(f"Result {i}: {{compute_{i}({100 + i})}}")
"""
)
output_dir = Path(tmp_dir) / "parallel_output"
output_dir.mkdir()
# Time the parallel processing
start_time = time.time()
results = generator.convert_directory(
input_dir=tmp_dir,
output_dir=str(output_dir),
max_workers=2, # Use 2 workers for testing
)
processing_time = time.time() - start_time
print(f"✅ Parallel processing completed in {processing_time:.2f}s")
print(f" Processed {len(results)} files with 2 workers")
return processing_time < 60 # Should complete reasonably fast
except Exception as e:
print(f"❌ Parallel processing test failed: {e}")
return False
def test_error_handling():
"""Test error handling and recovery."""
print("🧪 Testing Error Handling...")
try:
generator = CodeGenerator()
# Test with invalid Python code
invalid_code = "def broken_function(\n return 'syntax error'"
try:
cpp_code, metadata = generator.convert(invalid_code)
if not metadata.get("success", True):
print("✅ Error handling works for invalid code")
return True
else:
print("❌ Error handling failed - invalid code was accepted")
return False
except Exception:
print("✅ Error handling works - exception properly caught")
return True
except Exception as e:
print(f"❌ Error handling test failed: {e}")
return False
def test_configuration():
"""Test configuration management."""
print("🧪 Testing Configuration...")
try:
generator = CodeGenerator()
# Check that generator has required components
checks = [
("config", generator.config),
("client", generator.client),
("orchestrator", generator.orchestrator),
]
failed_checks = []
for name, component in checks:
if component is None:
failed_checks.append(name)
if failed_checks:
print(f"❌ Configuration missing: {failed_checks}")
return False
print("✅ Configuration properly initialized")
print(f" Model: {generator.orchestrator.model}")
print(f" Max iterations: {generator.orchestrator.max_iterations}")
return True
except Exception as e:
print(f"❌ Configuration test failed: {e}")
return False
def run_all_tests():
"""Run all validation tests."""
print("🚀 Agentic Code Generator Feature Validation")
print("=" * 50)
tests = [
("Basic Conversion", test_basic_conversion),
("Agent System", test_agent_system),
("Run History", test_run_history),
("Batch Processing", test_batch_processing),
("Collaborative Features", test_collaborative_features),
("Web Interface", test_web_interface_imports),
("Parallel Processing", test_parallel_processing),
("Error Handling", test_error_handling),
("Configuration", test_configuration),
]
results = []
for test_name, test_func in tests:
print(f"\n🔍 {test_name}")
try:
result = test_func()
results.append(result)
status = "✅ PASSED" if result else "❌ FAILED"
print(f" {status}")
except Exception as e:
print(f" ❌ FAILED with exception: {e}")
results.append(False)
# Summary
passed = sum(results)
total = len(results)
print(f"\n📊 Validation Summary: {passed}/{total} tests passed")
if passed == total:
print("🎉 ALL FEATURES VALIDATED SUCCESSFULLY!")
print(" The Agentic Code Generator is ready for production use.")
return True
elif passed >= total * 0.8: # 80% success rate
print("⚠️ MOST FEATURES WORKING - Minor issues detected.")
print(" The core functionality is solid, but some features need attention.")
return True
else:
print("❌ SIGNIFICANT ISSUES DETECTED")
print(" Core functionality needs improvement before production use.")
return False
if __name__ == "__main__":
print("Starting Agentic Code Generator Feature Validation...")
print("Note: This test validates core features without external API calls.")
print("For full functionality testing, ensure GROQ_API_KEY is set.\n")
success = run_all_tests()
sys.exit(0 if success else 1)