Spaces:
Sleeping
Sleeping
File size: 5,223 Bytes
2ae7490 | 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 | #!/usr/bin/env python3
"""
Verification script for Grant Analyst setup.
Tests that all core components can be imported and initialized.
Run this before deployment to catch configuration issues.
"""
import sys
from pathlib import Path
# Add src to path for local development
sys.path.insert(0, str(Path(__file__).parent / "src"))
def test_imports():
"""Test that core modules can be imported."""
print("Testing imports...")
try:
from analyzer.config import get_settings
print("β Config module imported")
except Exception as e:
print(f"β Failed to import config: {e}")
return False
try:
from analyzer.models import Grant, QARequest, SearchFilters
print("β Models module imported")
except Exception as e:
print(f"β Failed to import models: {e}")
return False
try:
from analyzer.llm_client import LLMClient
print("β LLM client module imported")
except Exception as e:
print(f"β Failed to import LLM client: {e}")
return False
try:
from analyzer.search.service import search_grants
print("β Search service module imported")
except Exception as e:
print(f"β Failed to import search service: {e}")
return False
try:
from analyzer.qa_service import stream_answer
print("β QA service module imported")
except Exception as e:
print(f"β Failed to import QA service: {e}")
return False
return True
def test_config():
"""Test that config can be loaded."""
print("\nTesting configuration...")
try:
from analyzer.config import get_settings
settings = get_settings()
print(f"β Settings loaded successfully")
print(f" ENV: {settings.ENV}")
print(f" LLM_PROVIDER: {settings.LLM_PROVIDER}")
print(f" LLM_MODEL_QA: {settings.LLM_MODEL_QA}")
print(f" MAX_QUERY_CHARS: {settings.MAX_QUERY_CHARS}")
print(f" ALLOWED_ORIGINS: {settings.ALLOWED_ORIGINS}")
if settings.ENV != "dev" and not settings.ALLOWED_ORIGINS:
print(" β Warning: ALLOWED_ORIGINS not set for non-dev environment")
return True
except Exception as e:
print(f"β Config validation failed: {e}")
return False
def test_models():
"""Test that Pydantic models work."""
print("\nTesting Pydantic models...")
try:
from analyzer.models import Grant, QARequest, dict_to_grant
# Test Grant model
grant_dict = {
"id": "test-123",
"title": "Test Grant",
"url": "https://example.com",
"open_date": "2025-01-01",
"close_date": "2025-12-31",
}
grant = dict_to_grant(grant_dict)
print(f"β Grant model validation works")
print(f" Created grant: {grant.id} - {grant.title}")
# Test QARequest model
request = QARequest(query="Test query", session_id="test-session")
print(f"β QARequest model validation works")
return True
except Exception as e:
print(f"β Model validation failed: {e}")
return False
def test_legacy_compatibility():
"""Test that legacy code still works."""
print("\nTesting legacy compatibility...")
try:
from analyzer.config import load_config
import warnings
# Should work but emit deprecation warning
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
config = load_config()
if w:
print(f"β Legacy load_config() works (with deprecation warning)")
else:
print(f"β Legacy load_config() works")
# Check that it has expected attributes
assert hasattr(config, 'provider')
assert hasattr(config, 'model')
print(f" Config provider: {config.provider}")
return True
except Exception as e:
print(f"β Legacy compatibility failed: {e}")
return False
def main():
"""Run all verification tests."""
print("=" * 60)
print("Grant Analyst Setup Verification")
print("=" * 60)
tests = [
("Imports", test_imports),
("Configuration", test_config),
("Models", test_models),
("Legacy Compatibility", test_legacy_compatibility),
]
results = []
for name, test_func in tests:
try:
result = test_func()
results.append((name, result))
except Exception as e:
print(f"\nβ {name} test crashed: {e}")
results.append((name, False))
print("\n" + "=" * 60)
print("Summary")
print("=" * 60)
for name, passed in results:
status = "β PASS" if passed else "β FAIL"
print(f"{status}: {name}")
all_passed = all(result for _, result in results)
if all_passed:
print("\nβ All verification tests passed!")
print("The refactored codebase is ready to use.")
return 0
else:
print("\nβ Some tests failed. Please fix the issues above.")
return 1
if __name__ == "__main__":
sys.exit(main())
|