codenuk_backend_mine/services/ai-analysis-service/test_analyze.py
2025-10-24 13:02:49 +05:30

70 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""
Test script to debug the analyze function
"""
import sys
import os
import tempfile
import shutil
from pathlib import Path
# Add current directory to path
sys.path.insert(0, '.')
# Import the AI analysis components
import importlib.util
# Load the ai-analyze.py module
spec = importlib.util.spec_from_file_location("ai_analyze", "ai-analyze.py")
ai_analyze_module = importlib.util.module_from_spec(spec)
sys.modules["ai_analyze"] = ai_analyze_module
spec.loader.exec_module(ai_analyze_module)
from ai_analyze import EnhancedGitHubAnalyzer, get_memory_config
async def test_analyze():
try:
print("🔍 Testing AI Analysis...")
# Get API key
api_key = os.getenv('ANTHROPIC_API_KEY')
if not api_key:
print("❌ ANTHROPIC_API_KEY not found")
return False
print("✅ API key found")
# Initialize analyzer
config = get_memory_config()
analyzer = EnhancedGitHubAnalyzer(api_key, config)
print("✅ Analyzer initialized")
# Test with simple files
test_dir = "/tmp/test-repo"
if not os.path.exists(test_dir):
os.makedirs(test_dir)
with open(f"{test_dir}/hello.py", "w") as f:
f.write('print("Hello World")')
with open(f"{test_dir}/math.py", "w") as f:
f.write('def add(a, b): return a + b')
print(f"🔍 Testing analysis of {test_dir}")
# Test analyze_repository_with_memory
analysis = await analyzer.analyze_repository_with_memory(test_dir)
print("✅ Analysis completed")
print(f"📊 Results: {analysis.total_files} files, {analysis.total_lines} lines")
return True
except Exception as e:
print(f"❌ Error: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
import asyncio
asyncio.run(test_analyze())