File size: 6,656 Bytes
60ac2eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Lineage Graph Extractor - Setup Test Script

This script tests your local setup to ensure everything is configured correctly.

Usage:
    python test_setup.py
"""

import os
import sys
from pathlib import Path

def test_python_version():
    """Test Python version"""
    print("Testing Python version...")
    version = sys.version_info
    if version.major >= 3 and version.minor >= 9:
        print(f"βœ“ Python {version.major}.{version.minor}.{version.micro} (OK)")
        return True
    else:
        print(f"βœ— Python {version.major}.{version.minor}.{version.micro} (Need 3.9+)")
        return False

def test_dependencies():
    """Test if required dependencies are installed"""
    print("\nTesting dependencies...")
    
    dependencies = {
        "anthropic": "Anthropic API client",
        "dotenv": "Environment variable loader (python-dotenv)"
    }
    
    all_installed = True
    for module, description in dependencies.items():
        try:
            if module == "dotenv":
                __import__("dotenv")
            else:
                __import__(module)
            print(f"βœ“ {description}")
        except ImportError:
            print(f"βœ— {description} (not installed)")
            all_installed = False
    
    if not all_installed:
        print("\nInstall missing dependencies with:")
        print("  pip install -r requirements.txt")
    
    return all_installed

def test_env_file():
    """Test if .env file exists and has required variables"""
    print("\nTesting environment configuration...")
    
    if not Path(".env").exists():
        print("βœ— .env file not found")
        print("  Copy .env.example to .env and add your API keys")
        return False
    
    print("βœ“ .env file exists")
    
    # Try to load it
    try:
        from dotenv import load_dotenv
        load_dotenv()
        
        api_key = os.getenv("ANTHROPIC_API_KEY")
        if not api_key or api_key == "your_anthropic_api_key_here":
            print("βœ— ANTHROPIC_API_KEY not set or still has default value")
            print("  Edit .env and add your actual Anthropic API key")
            return False
        
        print("βœ“ ANTHROPIC_API_KEY is set")
        return True
    except Exception as e:
        print(f"βœ— Error loading .env: {e}")
        return False

def test_agent_files():
    """Test if agent configuration files exist"""
    print("\nTesting agent configuration files...")
    
    required_files = [
        "memories/agent.md",
        "memories/tools.json",
        "memories/subagents/metadata_parser/agent.md",
        "memories/subagents/metadata_parser/tools.json",
        "memories/subagents/graph_visualizer/agent.md",
        "memories/subagents/graph_visualizer/tools.json"
    ]
    
    all_exist = True
    for file_path in required_files:
        if Path(file_path).exists():
            print(f"βœ“ {file_path}")
        else:
            print(f"βœ— {file_path} (missing)")
            all_exist = False
    
    return all_exist

def test_api_connection():
    """Test connection to Anthropic API"""
    print("\nTesting Anthropic API connection...")
    
    try:
        from anthropic import Anthropic
        from dotenv import load_dotenv
        
        load_dotenv()
        
        api_key = os.getenv("ANTHROPIC_API_KEY")
        if not api_key:
            print("βœ— API key not found")
            return False
        
        client = Anthropic(api_key=api_key)
        
        # Make a simple test request
        response = client.messages.create(
            model="claude-3-5-sonnet-20241022",
            max_tokens=100,
            messages=[{
                "role": "user",
                "content": "Hello"
            }]
        )
        
        print("βœ“ API connection successful")
        print(f"  Model: {response.model}")
        print(f"  Response: {response.content[0].text[:50]}...")
        return True
        
    except Exception as e:
        print(f"βœ— API connection failed: {e}")
        return False

def test_agent_functionality():
    """Test basic agent functionality"""
    print("\nTesting agent functionality...")
    
    try:
        from anthropic import Anthropic
        from dotenv import load_dotenv
        
        load_dotenv()
        
        client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
        
        # Load agent configuration
        with open("memories/agent.md", "r") as f:
            system_prompt = f.read()
        
        print("βœ“ Agent configuration loaded")
        
        # Test agent response
        response = client.messages.create(
            model="claude-3-5-sonnet-20241022",
            max_tokens=500,
            system=system_prompt,
            messages=[{
                "role": "user",
                "content": "What types of metadata sources can you extract lineage from?"
            }]
        )
        
        print("βœ“ Agent responds correctly")
        print(f"  Response preview: {response.content[0].text[:100]}...")
        return True
        
    except Exception as e:
        print(f"βœ— Agent test failed: {e}")
        return False

def main():
    """Run all tests"""
    print("=" * 60)
    print("Lineage Graph Extractor - Setup Test")
    print("=" * 60)
    
    results = {
        "Python version": test_python_version(),
        "Dependencies": test_dependencies(),
        "Environment file": test_env_file(),
        "Agent files": test_agent_files(),
        "API connection": test_api_connection(),
        "Agent functionality": test_agent_functionality()
    }
    
    print("\n" + "=" * 60)
    print("Test Summary")
    print("=" * 60)
    
    for test_name, passed in results.items():
        status = "βœ“ PASS" if passed else "βœ— FAIL"
        print(f"{test_name:.<40} {status}")
    
    all_passed = all(results.values())
    
    print("\n" + "=" * 60)
    if all_passed:
        print("βœ“ All tests passed! Your setup is ready.")
        print("\nNext steps:")
        print("  1. Try the integration example: python integration_example.py")
        print("  2. Read the README.md for usage examples")
        print("  3. Extract your first lineage!")
    else:
        print("βœ— Some tests failed. Please fix the issues above.")
        print("\nCommon fixes:")
        print("  - Install dependencies: pip install -r requirements.txt")
        print("  - Copy .env.example to .env and add your API key")
        print("  - Verify all files are present")
    print("=" * 60)
    
    return 0 if all_passed else 1

if __name__ == "__main__":
    sys.exit(main())