Skip to main content
Glama

MCP Agent Tracker

by Big0290
test_orm_mapping_fix.pyโ€ข10.9 kB
#!/usr/bin/env python3 """ Test ORM Mapping Fix This script tests if the ORM mapping fix worked and the classes are now properly mapped to the database. """ import sys from datetime import datetime def test_orm_mapping(): """Test if the ORM mapping is working.""" print("=== TESTING ORM MAPPING ===\n") try: # Clear any cached imports if 'models_unified' in sys.modules: del sys.modules['models_unified'] print("โœ… Cleared cached imports") # Import the fixed version from models_unified import UnifiedInteraction, UnifiedSession, SQLALCHEMY_AVAILABLE, Base print(f"โœ… Models imported successfully") print(f" SQLAlchemy available: {SQLALCHEMY_AVAILABLE}") print(f" Base class: {Base}") if SQLALCHEMY_AVAILABLE and Base: print("โœ… SQLAlchemy ORM is available") # Check if classes have table mapping if hasattr(UnifiedInteraction, '__tablename__'): print(f" โœ… UnifiedInteraction mapped to table: {UnifiedInteraction.__tablename__}") else: print(" โŒ UnifiedInteraction not mapped to table") return False if hasattr(UnifiedSession, '__tablename__'): print(f" โœ… UnifiedSession mapped to table: {UnifiedSession.__tablename__}") else: print(" โŒ UnifiedSession not mapped to table") return False return True else: print("โŒ SQLAlchemy ORM not available") return False except Exception as e: print(f"โŒ ORM mapping test failed: {e}") return False def test_database_session_creation(): """Test if database sessions can be created with mapped classes.""" print("\n=== TESTING DATABASE SESSION CREATION ===\n") try: from models_unified import get_session_factory, UnifiedInteraction, UnifiedSession session_factory = get_session_factory() print("โœ… Session factory retrieved") with session_factory() as session: print(f"โœ… Session active: {type(session).__name__}") # Check if we can query the mapped classes try: # Test querying interactions interactions_count = session.query(UnifiedInteraction).count() print(f"โœ… Interactions query successful: {interactions_count}") # Test querying sessions sessions_count = session.query(UnifiedSession).count() print(f"โœ… Sessions query successful: {sessions_count}") return True except Exception as e: print(f"โŒ Query failed: {e}") return False except Exception as e: print(f"โŒ Database session creation test failed: {e}") return False def test_database_operations(): """Test if database operations work with mapped classes.""" print("\n=== TESTING DATABASE OPERATIONS ===\n") try: from models_unified import get_session_factory, UnifiedInteraction session_factory = get_session_factory() print("โœ… Session factory retrieved") with session_factory() as session: print(f"โœ… Session active: {type(session).__name__}") # Test creating a real interaction try: test_interaction = UnifiedInteraction( interaction_type="orm_mapping_test", client_request="Test request after ORM mapping fix", agent_response="Test response after ORM mapping fix", timestamp=datetime.now(), status="success", metadata={"test": True, "orm_mapped": True, "verified": True} ) print("โœ… Test interaction created") # Add to session session.add(test_interaction) print("โœ… Test interaction added to session") # Commit to database session.commit() print("โœ… Test interaction committed to database") # Verify it was stored stored_count = session.query(UnifiedInteraction).count() print(f"โœ… Total interactions in database: {stored_count}") # Look for our test interaction stored_interaction = session.query(UnifiedInteraction).filter_by( interaction_type="orm_mapping_test" ).first() if stored_interaction: print(f"โœ… Test interaction found in database") print(f" ID: {stored_interaction.id}") print(f" Type: {stored_interaction.interaction_type}") print(f" Timestamp: {stored_interaction.timestamp}") print("๐ŸŽ‰ ORM MAPPING IS WORKING!") return True else: print("โŒ Test interaction not found in database") return False except Exception as e: print(f"โŒ Database operations failed: {e}") return False except Exception as e: print(f"โŒ Database operations test failed: {e}") return False def test_interaction_logging(): """Test if interaction logging works with mapped classes.""" print("\n=== TESTING INTERACTION LOGGING ===\n") try: from interaction_logger import InteractionLogger logger = InteractionLogger() print("โœ… InteractionLogger created") # Test logging a real interaction print("๐Ÿ”„ Testing interaction logging...") result = logger.log_interaction( interaction_type="logger_orm_test", client_request="Test request with ORM mapped classes", agent_response="Test response with ORM mapped classes", status="success", metadata={"test": True, "orm_mapped": True, "logger_test": True} ) if result: print("โœ… Interaction logged successfully") # Verify it's in the database try: from models_unified import get_session_factory, UnifiedInteraction session_factory = get_session_factory() with session_factory() as session: count = session.query(UnifiedInteraction).count() print(f" Total interactions in database: {count}") if count > 0: print("โœ… Interactions are now being stored in real database!") # Show the real interaction real_interaction = session.query(UnifiedInteraction).filter_by( interaction_type="logger_orm_test" ).first() if real_interaction: print(f" Real interaction ID: {real_interaction.id}") print(f" Real interaction timestamp: {real_interaction.timestamp}") print("๐ŸŽ‰ INTERACTION LOGGING WITH ORM IS WORKING!") return True else: print("โŒ Real interaction not found in database") return False else: print("โŒ Still no interactions in real database") return False except Exception as e: print(f" โŒ Database verification failed: {e}") return False else: print("โŒ Interaction logging failed") return False except Exception as e: print(f"โŒ Interaction logging test failed: {e}") return False def main(): """Main test function.""" print("๐Ÿงช TESTING ORM MAPPING FIX\n") print("This script will test if the ORM mapping fix worked.\n") # Test all components tests = [ ("ORM Mapping", test_orm_mapping), ("Database Session Creation", test_database_session_creation), ("Database Operations", test_database_operations), ("Interaction Logging", test_interaction_logging) ] success_count = 0 for name, test_func in tests: try: print(f"๐Ÿงช Running: {name}") result = test_func() if result: success_count += 1 print(f" โœ… {name} passed") else: print(f" โŒ {name} failed") except Exception as e: print(f" โŒ {name} failed with error: {e}") print(f"\n๐Ÿ“Š Test Results: {success_count}/{len(tests)} tests passed") if success_count == len(tests): print("\n๐ŸŽ‰ COMPLETE SUCCESS!") print(" โ€ข ORM mapping working") print(" โ€ข Database sessions working") print(" โ€ข Database operations working") print(" โ€ข Interaction logging working") print("\n๐Ÿš€ **Your interaction tracking system is now fully functional!**") print(" โ€ข Interactions will be stored in real database") print(" โ€ข Context injection will work with real data") print(" โ€ข Conversation #107 will be properly tracked") print("\n๐Ÿงช **Test Commands:**") print("python diagnose_interaction_tracking.py") print("python test_conversation_tracking.py") print("\n๐Ÿ’ก **Expected Results:**") print("โ€ข Real SQLAlchemy sessions with mapped classes") print("โ€ข Interactions stored in real SQLite database") print("โ€ข Context injection working with actual conversation data") print("โ€ข Conversation #107 properly tracked and stored") elif success_count > 0: print("\nโš ๏ธ PARTIAL SUCCESS") print(" โ€ข Some components working, others need attention") print(" โ€ข Check the output above for specific failures") else: print("\nโŒ ALL TESTS FAILED") print(" โ€ข ORM mapping fix may not have worked") print(" โ€ข Check for syntax errors or import issues") print(" โ€ข Consider manual intervention") if __name__ == "__main__": main()

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Big0290/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server