reorganize: move all test scripts to tests/ directory
- Moved 8 root-level test scripts + 2 from bot/ to tests/ - Moved run_rocinante_test.sh runner script to tests/ - Added tests/README.md documenting each test's purpose, type, and requirements - Added test_pfp_context.py and test_rocinante_comparison.py (previously untracked)
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script for the new conversation history system.
|
||||
"""
|
||||
|
||||
from utils.conversation_history import conversation_history
|
||||
|
||||
def test_conversation_history():
|
||||
print("🧪 Testing conversation history system...\n")
|
||||
|
||||
# Test 1: Add messages to a server channel
|
||||
print("Test 1: Adding messages to server channel")
|
||||
server_id = "123456789"
|
||||
conversation_history.add_message(server_id, "Alice", "Hello Miku!", is_bot=False)
|
||||
conversation_history.add_message(server_id, "Miku", "Hi Alice! 💙", is_bot=True)
|
||||
conversation_history.add_message(server_id, "Bob", "What's up?", is_bot=False)
|
||||
conversation_history.add_message(server_id, "Miku", "Just chatting! ✨", is_bot=True)
|
||||
|
||||
recent = conversation_history.get_recent_messages(server_id)
|
||||
print(f" Recent messages: {len(recent)}")
|
||||
for author, content, is_bot in recent:
|
||||
role = "BOT" if is_bot else "USER"
|
||||
print(f" [{role}] {author}: {content}")
|
||||
|
||||
# Test 2: Format for LLM
|
||||
print("\nTest 2: Format for LLM (OpenAI messages)")
|
||||
messages = conversation_history.format_for_llm(server_id, max_messages=4)
|
||||
for msg in messages:
|
||||
print(f" {msg['role']}: {msg['content']}")
|
||||
|
||||
# Test 3: Add messages to a DM channel
|
||||
print("\nTest 3: Adding messages to DM channel")
|
||||
user_id = "987654321"
|
||||
conversation_history.add_message(user_id, "Charlie", "Can you help me?", is_bot=False)
|
||||
conversation_history.add_message(user_id, "Miku", "Of course! What do you need?", is_bot=True)
|
||||
conversation_history.add_message(user_id, "Charlie", "I need song recommendations", is_bot=False)
|
||||
|
||||
dm_messages = conversation_history.format_for_llm(user_id)
|
||||
print(f" DM messages: {len(dm_messages)}")
|
||||
for msg in dm_messages:
|
||||
print(f" {msg['role']}: {msg['content']}")
|
||||
|
||||
# Test 4: Empty message filtering
|
||||
print("\nTest 4: Empty message filtering")
|
||||
conversation_history.add_message(server_id, "Dave", "", is_bot=False) # Should be ignored
|
||||
conversation_history.add_message(server_id, "Dave", " ", is_bot=False) # Should be ignored
|
||||
conversation_history.add_message(server_id, "Dave", "Real message", is_bot=False)
|
||||
|
||||
filtered = conversation_history.get_recent_messages(server_id)
|
||||
print(f" Messages after adding empty ones: {len(filtered)}")
|
||||
print(f" Last message: {filtered[-1][1]}")
|
||||
|
||||
# Test 5: Message truncation
|
||||
print("\nTest 5: Message truncation")
|
||||
long_message = "A" * 600 # 600 chars
|
||||
conversation_history.add_message(server_id, "Eve", long_message, is_bot=False)
|
||||
truncated = conversation_history.format_for_llm(server_id, max_chars_per_message=500)
|
||||
last_msg = truncated[-1]['content']
|
||||
print(f" Original length: {len(long_message)}")
|
||||
print(f" Truncated length: {len(last_msg)}")
|
||||
print(f" Ends with '...': {last_msg.endswith('...')}")
|
||||
|
||||
# Test 6: Channel stats
|
||||
print("\nTest 6: Channel statistics")
|
||||
stats = conversation_history.get_channel_stats(server_id)
|
||||
print(f" Server stats: {stats}")
|
||||
|
||||
dm_stats = conversation_history.get_channel_stats(user_id)
|
||||
print(f" DM stats: {dm_stats}")
|
||||
|
||||
print("\n✅ All tests completed!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_conversation_history()
|
||||
@@ -1,119 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Test the error handler to ensure it correctly detects error messages."""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
# Add the bot directory to the path so we can import modules
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Directly implement the error detection function to avoid module dependencies
|
||||
def is_error_response(response_text: str) -> bool:
|
||||
"""
|
||||
Detect if a response text is an error message.
|
||||
|
||||
Args:
|
||||
response_text: The response text to check
|
||||
|
||||
Returns:
|
||||
bool: True if the response appears to be an error message
|
||||
"""
|
||||
if not response_text or not isinstance(response_text, str):
|
||||
return False
|
||||
|
||||
response_lower = response_text.lower().strip()
|
||||
|
||||
# Common error patterns
|
||||
error_patterns = [
|
||||
r'^error:?\s*\d{3}', # "Error: 502" or "Error 502"
|
||||
r'^error:?\s+', # "Error: " or "Error "
|
||||
r'^\d{3}\s+error', # "502 Error"
|
||||
r'^sorry,?\s+(there\s+was\s+)?an?\s+error', # "Sorry, an error" or "Sorry, there was an error"
|
||||
r'^sorry,?\s+the\s+response\s+took\s+too\s+long', # Timeout error
|
||||
r'connection\s+(refused|failed|error|timeout)',
|
||||
r'timed?\s*out',
|
||||
r'failed\s+to\s+(connect|respond|process)',
|
||||
r'service\s+unavailable',
|
||||
r'internal\s+server\s+error',
|
||||
r'bad\s+gateway',
|
||||
r'gateway\s+timeout',
|
||||
]
|
||||
|
||||
# Check if response matches any error pattern
|
||||
for pattern in error_patterns:
|
||||
if re.search(pattern, response_lower):
|
||||
return True
|
||||
|
||||
# Check for HTTP status codes indicating errors
|
||||
if re.match(r'^\d{3}$', response_text.strip()):
|
||||
status_code = int(response_text.strip())
|
||||
if status_code >= 400: # HTTP error codes
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
# Test cases
|
||||
test_cases = [
|
||||
# Error responses (should return True)
|
||||
("Error 502", True),
|
||||
("Error: 502", True),
|
||||
("Error: Bad Gateway", True),
|
||||
("502 Error", True),
|
||||
("Sorry, there was an error", True),
|
||||
("Sorry, an error occurred", True),
|
||||
("Sorry, the response took too long. Please try again.", True),
|
||||
("Connection refused", True),
|
||||
("Connection timeout", True),
|
||||
("Timed out", True),
|
||||
("Failed to connect", True),
|
||||
("Service unavailable", True),
|
||||
("Internal server error", True),
|
||||
("Bad gateway", True),
|
||||
("Gateway timeout", True),
|
||||
("500", True),
|
||||
("502", True),
|
||||
("503", True),
|
||||
|
||||
# Normal responses (should return False)
|
||||
("Hi! How are you doing today?", False),
|
||||
("I'm Hatsune Miku! *waves*", False),
|
||||
("That's so cool! Tell me more!", False),
|
||||
("Sorry to hear that!", False),
|
||||
("I'm sorry, but I can't help with that.", False),
|
||||
("200", False),
|
||||
("304", False),
|
||||
("The error in your code is...", False),
|
||||
]
|
||||
|
||||
def run_tests():
|
||||
print("Testing error detection...")
|
||||
print("=" * 60)
|
||||
|
||||
passed = 0
|
||||
failed = 0
|
||||
|
||||
for text, expected in test_cases:
|
||||
result = is_error_response(text)
|
||||
status = "✓" if result == expected else "✗"
|
||||
|
||||
if result == expected:
|
||||
passed += 1
|
||||
else:
|
||||
failed += 1
|
||||
print(f"{status} FAILED: '{text}' -> {result} (expected {expected})")
|
||||
|
||||
print("=" * 60)
|
||||
print(f"Tests passed: {passed}/{len(test_cases)}")
|
||||
print(f"Tests failed: {failed}/{len(test_cases)}")
|
||||
|
||||
if failed == 0:
|
||||
print("\n✓ All tests passed!")
|
||||
else:
|
||||
print(f"\n✗ {failed} test(s) failed")
|
||||
|
||||
return failed == 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = run_tests()
|
||||
exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user