File size: 4,567 Bytes
59c860e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637ed9b
 
 
 
59c860e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637ed9b
 
 
 
59c860e
 
 
637ed9b
59c860e
 
 
 
 
 
 
637ed9b
 
59c860e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637ed9b
 
 
59c860e
637ed9b
 
 
 
59c860e
 
 
 
 
637ed9b
 
59c860e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Quick startup test to verify all components load correctly.
Run this before deploying to catch configuration issues early.
"""
import sys
from loguru import logger

logger.remove()
logger.add(sys.stderr, level="INFO")

def test_imports():
    """Test that all required modules can be imported."""
    try:
        logger.info("Testing imports...")
        import gradio
        import openai
        import lancedb
        from pydantic_settings import BaseSettings
        from langdetect import detect
        import diskcache
        import pandas
        logger.success("✅ All imports successful")
        return True
    except ImportError as e:
        logger.error(f"❌ Import failed: {e}")
        return False

def test_config():
    """Test configuration loading."""
    try:
        logger.info("Testing configuration...")
        from config import get_settings
        import os
        
        os.environ.setdefault("OPENAI_API_KEY", "test-key-for-validation")
        
        settings = get_settings()
        logger.info(f"LLM Model: {settings.llm_model}")
        logger.info(f"Embedding Model: {settings.embedding_model}")
        logger.info(f"Server: {settings.server_host}:{settings.server_port}")
        logger.success("✅ Configuration loaded successfully")
        return True
    except Exception as e:
        logger.error(f"❌ Config failed: {e}")
        return False

def test_vector_store():
    """Test vector store connection."""
    try:
        logger.info("Testing vector store...")
        from config import get_settings
        from database.vector_store_client import VectorStoreClient
        import os
        
        os.environ.setdefault("OPENAI_API_KEY", "test-key-for-validation")
        
        settings = get_settings()
        client = VectorStoreClient(uri=settings.lancedb_uri)
        
        count = client.count_documents()
        logger.info(f"Documents in database: {count}")
        client.close()
        logger.success("✅ Vector store accessible")
        return True
    except Exception as e:
        logger.error(f"❌ Vector store failed: {e}")
        import traceback
        logger.error(traceback.format_exc())
        return False

def test_embeddings():
    """Test embeddings client initialization."""
    try:
        logger.info("Testing embeddings client...")
        from models.embeddings import get_embeddings_client
        client = get_embeddings_client()
        logger.info(f"Model: {client.model}")
        logger.info(f"Cache available: {client.cache is not None}")
        client.close()
        logger.success("✅ Embeddings client initialized")
        return True
    except Exception as e:
        logger.error(f"❌ Embeddings client failed: {e}")
        return False

def test_agent():
    """Test agent creation."""
    try:
        logger.info("Testing agent creation...")
        from agent.a11y_agent import create_agent
        import os
        
        os.environ.setdefault("OPENAI_API_KEY", "test-key-for-validation")
        
        agent = create_agent()
        logger.info(f"Agent language: {agent.language}")
        logger.info(f"Agent model: {agent.model}")
        agent.close()
        
        logger.success("✅ Agent created successfully")
        return True
    except Exception as e:
        logger.error(f"❌ Agent creation failed: {e}")
        import traceback
        logger.error(traceback.format_exc())
        return False

def main():
    """Run all tests."""
    logger.info("=" * 60)
    logger.info("Starting Deployment Readiness Tests")
    logger.info("=" * 60)
    
    tests = [
        ("Imports", test_imports),
        ("Configuration", test_config),
        ("Vector Store", test_vector_store),
        ("Embeddings", test_embeddings),
        ("Agent", test_agent),
    ]
    
    results = []
    for name, test_func in tests:
        logger.info(f"\n--- Test: {name} ---")
        result = test_func()
        results.append((name, result))
    
    logger.info("\n" + "=" * 60)
    logger.info("Test Results Summary")
    logger.info("=" * 60)
    
    for name, result in results:
        status = "✅ PASS" if result else "❌ FAIL"
        logger.info(f"{status} - {name}")
    
    all_passed = all(result for _, result in results)
    
    if all_passed:
        logger.success("\n🎉 All tests passed! Ready for deployment.")
        return 0
    else:
        logger.error("\n⚠️ Some tests failed. Fix issues before deploying.")
        return 1

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