-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_integration_simple.py
More file actions
356 lines (305 loc) · 12 KB
/
test_integration_simple.py
File metadata and controls
356 lines (305 loc) · 12 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
#!/usr/bin/env python3
"""
Simple Integration Test for TTD-DR
Tests basic integration without requiring full backend or dependencies.
"""
import sys
import os
import json
# Add the aira module to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'aira/src'))
def test_imports():
"""Test that all modules can be imported"""
print("\n=== Testing Module Imports ===")
results = []
# Test base module imports
try:
from aiq_aira.research_strategy_base import ResearchContext, ResearchStrategyType, BaseResearchStrategy
print("✅ research_strategy_base imported successfully")
results.append(True)
except ImportError as e:
print(f"❌ Failed to import research_strategy_base: {e}")
results.append(False)
# Test TTD-DR models
try:
from aiq_aira.ttd_dr.models import (
TTDDRStage, TTDDRConfig, TTDDRState, ResearchPlan,
DraftState, SearchQAPair, EvolutionVariant
)
print("✅ ttd_dr.models imported successfully")
# Test enum values
assert TTDDRStage.PLANNING.value == "planning"
assert TTDDRStage.ITERATING.value == "iterating"
assert TTDDRStage.SYNTHESIZING.value == "synthesizing"
print(" - TTDDRStage enum validated")
results.append(True)
except Exception as e:
print(f"❌ Failed with ttd_dr.models: {e}")
results.append(False)
# Test prompts
try:
from aiq_aira.ttd_dr.prompts import (
PLAN_GENERATION_PROMPT,
INITIAL_DRAFT_PROMPT,
QUESTION_GENERATION_PROMPT
)
print("✅ ttd_dr.prompts imported successfully")
assert len(PLAN_GENERATION_PROMPT) > 0
print(" - Prompts validated")
results.append(True)
except Exception as e:
print(f"❌ Failed with ttd_dr.prompts: {e}")
results.append(False)
return all(results)
def test_data_models():
"""Test data model creation and serialization"""
print("\n=== Testing Data Models ===")
from aiq_aira.ttd_dr.models import (
TTDDRConfig, TTDDRState, ResearchPlan,
DraftState, SearchQAPair, TTDDRMetrics
)
from aiq_aira.research_strategy_base import ResearchContext, ResearchResult
results = []
# Test ResearchContext
try:
context = ResearchContext(
query="Test query about AI",
collection="default",
search_web=True,
max_sources=10,
user_preferences={"format": "detailed"}
)
context_dict = context.to_dict()
assert context_dict["query"] == "Test query about AI"
assert context_dict["collection"] == "default"
print("✅ ResearchContext works correctly")
results.append(True)
except Exception as e:
print(f"❌ ResearchContext failed: {e}")
results.append(False)
# Test TTDDRConfig
try:
config = TTDDRConfig()
assert config.max_iterations == 5
assert config.convergence_threshold == 0.85
assert config.enable_evolution == True
config_dict = config.to_dict()
assert isinstance(config_dict, dict)
assert config_dict["max_iterations"] == 5
print("✅ TTDDRConfig works correctly")
results.append(True)
except Exception as e:
print(f"❌ TTDDRConfig failed: {e}")
results.append(False)
# Test ResearchPlan
try:
plan = ResearchPlan(
key_areas=["AI", "Healthcare"],
questions=["What is AI?", "How does it help?"],
expected_sections=["Introduction", "Analysis"],
search_queries=["AI healthcare applications"]
)
assert len(plan.key_areas) == 2
assert len(plan.questions) == 2
print("✅ ResearchPlan works correctly")
results.append(True)
except Exception as e:
print(f"❌ ResearchPlan failed: {e}")
results.append(False)
# Test TTDDRState
try:
from aiq_aira.ttd_dr.models import TTDDRStage
state = TTDDRState(
stage=TTDDRStage.PLANNING,
current_iteration=0,
plan=plan,
draft=DraftState(content="Initial draft", gaps=["gap1"])
)
assert state.stage == TTDDRStage.PLANNING
assert state.current_iteration == 0
print("✅ TTDDRState works correctly")
results.append(True)
except Exception as e:
print(f"❌ TTDDRState failed: {e}")
results.append(False)
# Test ResearchResult
try:
result = ResearchResult(
success=True,
final_report="Test report content",
sources=[{"url": "example.com", "content": "test"}],
metadata={"strategy": "ttd_dr"},
execution_time=45.5
)
result_dict = result.to_dict()
assert result_dict["success"] == True
assert result_dict["execution_time"] == 45.5
print("✅ ResearchResult works correctly")
results.append(True)
except Exception as e:
print(f"❌ ResearchResult failed: {e}")
results.append(False)
return all(results)
def test_strategy_types():
"""Test strategy type definitions"""
print("\n=== Testing Strategy Types ===")
from aiq_aira.research_strategy_base import ResearchStrategyType
try:
# Test all strategy types
assert ResearchStrategyType.SIMPLE_RAG.value == "simple_rag"
assert ResearchStrategyType.UDR_DYNAMIC.value == "udr_dynamic"
assert ResearchStrategyType.TTD_DR_DYNAMIC.value == "ttd_dr_dynamic"
# Test that they're different
assert ResearchStrategyType.UDR_DYNAMIC != ResearchStrategyType.TTD_DR_DYNAMIC
print("✅ All strategy types defined correctly")
print(f" - SIMPLE_RAG: {ResearchStrategyType.SIMPLE_RAG.value}")
print(f" - UDR_DYNAMIC: {ResearchStrategyType.UDR_DYNAMIC.value}")
print(f" - TTD_DR_DYNAMIC: {ResearchStrategyType.TTD_DR_DYNAMIC.value}")
return True
except Exception as e:
print(f"❌ Strategy types test failed: {e}")
return False
def test_frontend_integration():
"""Test that frontend components are in place"""
print("\n=== Testing Frontend Components ===")
results = []
# Check StrategyToggle component
toggle_path = "frontend/app/components/StrategyToggle.tsx"
if os.path.exists(toggle_path):
with open(toggle_path, 'r') as f:
content = f.read()
if 'udr' in content and 'ttd_dr' in content:
print("✅ StrategyToggle component found with both strategies")
results.append(True)
else:
print("❌ StrategyToggle missing strategy options")
results.append(False)
else:
print(f"❌ StrategyToggle component not found at {toggle_path}")
results.append(False)
# Check TTDDRProgressDisplay component
progress_path = "frontend/app/components/TTDDRProgressDisplay.tsx"
if os.path.exists(progress_path):
with open(progress_path, 'r') as f:
content = f.read()
if 'planning' in content and 'iterating' in content and 'synthesizing' in content:
print("✅ TTDDRProgressDisplay component found with all stages")
results.append(True)
else:
print("❌ TTDDRProgressDisplay missing stages")
results.append(False)
else:
print(f"❌ TTDDRProgressDisplay component not found at {progress_path}")
results.append(False)
# Check CopilotAgentDisplay integration
agent_path = "frontend/app/components/CopilotAgentDisplay.tsx"
if os.path.exists(agent_path):
with open(agent_path, 'r') as f:
content = f.read()
if 'StrategyToggle' in content and 'TTDDRProgressDisplay' in content:
print("✅ CopilotAgentDisplay integrated with new components")
results.append(True)
else:
print("❌ CopilotAgentDisplay missing component integration")
results.append(False)
else:
print(f"❌ CopilotAgentDisplay not found at {agent_path}")
results.append(False)
return all(results)
def test_backend_integration():
"""Test that backend is properly integrated"""
print("\n=== Testing Backend Integration ===")
results = []
# Check main.py updates
main_path = "backend/main.py"
if os.path.exists(main_path):
with open(main_path, 'r') as f:
content = f.read()
# Check for TTDDRIntegration import
if 'from aiq_aira.ttd_dr import TTDDRIntegration' in content:
print("✅ Backend imports TTDDRIntegration")
results.append(True)
else:
print("❌ Backend missing TTDDRIntegration import")
results.append(False)
# Check for strategy field in ResearchRequest
if 'strategy: str = Field' in content and 'ttd_dr' in content:
print("✅ ResearchRequest has strategy field")
results.append(True)
else:
print("❌ ResearchRequest missing strategy field")
results.append(False)
else:
print(f"❌ Backend main.py not found at {main_path}")
results.append(False)
results.append(False)
# Check hackathon_agent.py updates
agent_path = "aira/src/aiq_aira/hackathon_agent.py"
if os.path.exists(agent_path):
with open(agent_path, 'r') as f:
content = f.read()
# Check for ttd_dr_strategy_node
if 'async def ttd_dr_strategy_node' in content:
print("✅ Agent has ttd_dr_strategy_node")
results.append(True)
else:
print("❌ Agent missing ttd_dr_strategy_node")
results.append(False)
# Check for updated routing
if 'ttd_dr_strategy' in content and 'route_after_planner' in content:
print("✅ Agent routing updated for TTD-DR")
results.append(True)
else:
print("❌ Agent routing not updated")
results.append(False)
else:
print(f"❌ hackathon_agent.py not found at {agent_path}")
results.append(False)
results.append(False)
return all(results)
def main():
"""Run all tests"""
print("="*60)
print("TTD-DR INTEGRATION TEST")
print("="*60)
tests = [
("Module Imports", test_imports),
("Data Models", test_data_models),
("Strategy Types", test_strategy_types),
("Frontend Integration", test_frontend_integration),
("Backend Integration", test_backend_integration),
]
results = []
for name, test_func in tests:
try:
result = test_func()
results.append((name, result))
except Exception as e:
print(f"\n❌ {name} failed with exception: {e}")
import traceback
traceback.print_exc()
results.append((name, False))
# Summary
print("\n" + "="*60)
print("TEST SUMMARY")
print("="*60)
passed = sum(1 for _, result in results if result)
total = len(results)
for name, result in results:
status = "✅ PASSED" if result else "❌ FAILED"
print(f"{name:.<35} {status}")
print(f"\nTotal: {passed}/{total} tests passed")
if passed == total:
print("\n🎉 All integration tests passed successfully!")
print("\nThe TTD-DR integration is complete and ready for deployment!")
return 0
else:
print(f"\n⚠️ {total - passed} test(s) failed")
return 1
if __name__ == "__main__":
try:
exit_code = main()
sys.exit(exit_code)
except KeyboardInterrupt:
print("\n\nTest interrupted by user")
sys.exit(1)