hermes-web-cli/test_recent_sessions.py

45 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""
Test script for hermes-web-cli recent sessions functionality.
This script simulates the .dspy file execution to verify it works correctly.
"""
import sys
import os
import json
# Add the module directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'hermes_web_cli'))
try:
from hermes_web_cli.init import get_recent_sessions
def test_recent_sessions():
"""Test the get_recent_sessions function."""
print("Testing get_recent_sessions function...")
sessions = get_recent_sessions(limit=5)
print(f"Retrieved {len(sessions)} recent sessions:")
for i, session in enumerate(sessions, 1):
print(f" {i}. Session ID: {session.get('session_id')}")
print(f" Service: {session.get('service_name')}")
print(f" Last Message: {session.get('last_message')[:50]}...")
print(f" Created: {session.get('created_at')[:19]}")
print()
# Test the .dspy file output format
result = {
"status": "success",
"data": sessions,
"total": len(sessions)
}
print("Expected .dspy output format:")
print(json.dumps(result, indent=2, ensure_ascii=False))
return True
except Exception as e:
print(f"Error during testing: {e}")
return False
if __name__ == "__main__":
success = test_recent_sessions()
sys.exit(0 if success else 1)