test_conversation_tracking.pyโข4.28 kB
#!/usr/bin/env python3
"""
Test script for conversation tracking functionality
This tests the core tracking without requiring MCP packages
"""
import os
import sys
import time
from datetime import datetime
# Add current directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_conversation_tracking():
"""Test the conversation tracking functionality"""
print("๐งช Testing Conversation Tracking System...")
try:
# Test 1: Import the logger
print("๐ฆ Testing imports...")
from interaction_logger import logger
print("โ
Interaction logger imported successfully")
# Test 2: Test session creation
print("๐ Testing session creation...")
session_id = logger.get_or_create_session()
print(f"โ
Session created: {session_id}")
# Test 3: Test client request logging
print("๐ Testing client request logging...")
logger.log_client_request("What's the weather like?")
print("โ
Client request logged successfully")
# Test 4: Test agent response logging
print("๐ค Testing agent response logging...")
logger.log_agent_response("The weather is sunny and warm.")
print("โ
Agent response logged successfully")
# Test 5: Test conversation turn logging
print("๐ Testing conversation turn logging...")
logger.log_conversation_turn(
client_request="What's the weather like?",
agent_response="The weather is sunny and warm."
)
print("โ
Conversation turn logged successfully")
# Test 6: Test custom interaction logging
print("๐ Testing custom interaction logging...")
logger.log_interaction(
interaction_type='test_interaction',
client_request="Test request",
agent_response="Test response",
metadata={'test': True, 'timestamp': datetime.utcnow().isoformat()}
)
print("โ
Custom interaction logged successfully")
# Test 7: Test error logging
print("โ Testing error logging...")
logger.log_interaction(
interaction_type='test_error',
error_message="This is a test error",
status='error'
)
print("โ
Error logged successfully")
print("\n๐ All tests passed! Conversation tracking is working correctly.")
print(f"๐ Session ID: {session_id}")
print("๐ก The system is now ready to track client-agent conversations automatically.")
return True
except Exception as e:
print(f"โ Test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_configuration():
"""Test configuration loading"""
print("\nโ๏ธ Testing Configuration...")
try:
from config import Config
print("โ
Configuration imported successfully")
print(f"๐ Environment: {Config.ENVIRONMENT}")
print(f"๐ Background Monitoring: {Config.ENABLE_BACKGROUND_MONITORING}")
print(f"โฑ๏ธ Monitoring Interval: {Config.MONITORING_INTERVAL_SECONDS} seconds")
print(f"๐ Automatic Metadata: {Config.ENABLE_AUTOMATIC_METADATA}")
return True
except Exception as e:
print(f"โ Configuration test failed: {e}")
return False
if __name__ == "__main__":
print("๐ Starting Conversation Tracking Tests...\n")
config_ok = test_configuration()
tracking_ok = test_conversation_tracking()
print("\n" + "="*50)
if config_ok and tracking_ok:
print("๐ฏ ALL TESTS PASSED!")
print("โ
Configuration: Working")
print("โ
Conversation Tracking: Working")
print("\n๐ก Your MCP server is ready to track conversations automatically!")
else:
print("โ SOME TESTS FAILED!")
if not config_ok:
print("โ Configuration: Failed")
if not tracking_ok:
print("โ Conversation Tracking: Failed")
print("\n๐ง Please check the error messages above and fix any issues.")
print("="*50)