-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_search.py
More file actions
172 lines (131 loc) · 5.62 KB
/
test_search.py
File metadata and controls
172 lines (131 loc) · 5.62 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
#!/usr/bin/env python3
"""Test search functionality with a sample requirement topic"""
import asyncio
import os
import sys
from datetime import datetime
# Add project root to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from research.searcher_working import WorkingResearchPipeline
# Import EvidenceGatherer directly to avoid arena __init__.py dependencies
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), 'arena'))
from evidence_system import EvidenceGatherer
async def test_search_integration():
"""Test the complete search integration flow"""
print("🔍 Testing Search Integration")
print("=" * 50)
# Test topic - a realistic requirement
test_requirement = "implement blockchain-based user authentication"
print(f"Testing with requirement: '{test_requirement}'")
print()
# Test 1: Direct search pipeline
print("1️⃣ Testing Working Research Pipeline")
print("-" * 30)
pipeline = WorkingResearchPipeline()
try:
# Test evidence search
evidence_results = await pipeline.search_evidence(
requirement=test_requirement,
stance="oppose" # Look for problems/issues
)
print(f"✅ Found {len(evidence_results)} evidence pieces")
# Show first few results
for i, result in enumerate(evidence_results[:3], 1):
print(f" {i}. {result.get('title', 'No title')[:60]}...")
print(f" Source: {result.get('source', 'Unknown')}")
print(f" URL: {result.get('url', 'No URL')}")
print()
# Test specific site search
tech_results = pipeline.search_specific_sites(
requirement=test_requirement,
sites=["github.com", "stackoverflow.com"]
)
print(f"✅ Found {len(tech_results)} results from tech sites")
# Show usage stats
stats = pipeline.get_usage_stats()
print(f"📊 API Calls: {stats['brave_api_calls']}")
print(f"💰 Estimated Cost: ${stats['cost_estimate']:.3f}")
print()
except Exception as e:
print(f"❌ Working Research Pipeline failed: {e}")
print()
# Test 2: Evidence system integration
print("2️⃣ Testing Evidence System Integration")
print("-" * 30)
try:
# Create evidence gatherer with working search pipeline
gatherer = EvidenceGatherer()
# Test evidence gathering
evidence_objects = await gatherer.gather_evidence(
requirement=test_requirement,
stance="neutral",
max_sources=5
)
print(f"✅ Evidence Gatherer found {len(evidence_objects)} evidence objects")
# Show evidence details
for i, evidence in enumerate(evidence_objects[:3], 1):
print(f" {i}. Claim: {evidence.claim[:50]}...")
print(f" Source: {evidence.source}")
print(f" Tier: {evidence.tier.name}")
print(f" Score: {evidence.total_score:.2f}")
print(f" Relevance: {evidence.relevance_score:.2f}")
print()
except Exception as e:
print(f"❌ Evidence System failed: {e}")
print()
# Test 3: Search query generation
print("3️⃣ Testing Search Query Generation")
print("-" * 30)
# Test different stances
stances = ["support", "oppose", "neutral"]
for stance in stances:
queries = pipeline._generate_search_queries(test_requirement, stance)
print(f"📝 {stance.upper()} queries:")
for query in queries[:2]: # Show first 2
print(f" - {query}")
print()
print("🎯 Search Integration Test Complete!")
async def test_topic_to_search_flow():
"""Test how a topic flows through the search system"""
print("\n🎭 Testing Topic → Search → Evidence Flow")
print("=" * 50)
# Simulate the full flow
topics = [
"add two-factor authentication",
"implement microservices architecture",
"use GraphQL instead of REST API",
"deploy to Kubernetes cluster"
]
pipeline = WorkingResearchPipeline()
for i, topic in enumerate(topics, 1):
print(f"{i}. Topic: '{topic}'")
try:
# Search for evidence (limit to 2 results for speed)
results = await pipeline.search_evidence(topic, "neutral")
if results:
print(f" ✅ Found {len(results)} pieces of evidence")
best_result = results[0] if results else {}
print(f" 🏆 Best result: {best_result.get('title', 'No title')[:40]}...")
else:
print(" ⚠️ No results found")
except Exception as e:
print(f" ❌ Search failed: {e}")
print()
print("🔚 Topic Flow Test Complete!")
if __name__ == "__main__":
print("🚀 Starting Search Functionality Tests")
print("=" * 60)
print(f"⏰ Test started at: {datetime.now()}")
print()
# Run tests
asyncio.run(test_search_integration())
asyncio.run(test_topic_to_search_flow())
print(f"⏰ Test completed at: {datetime.now()}")
print("\n💡 Summary:")
print("- Working Research Pipeline: Uses direct Brave API or DuckDuckGo")
print("- Evidence System: Integrates with search but needs Brave wrapper fix")
print("- Topic Flow: Requirements → Search Queries → Evidence Results")
print("- Integration: Ready for debate arena usage!")
#built with love