MMORPG_AI_NPC_MCP_CLIENT_SERVER / tests /test_dropdown_fix.py
Chris4K's picture
Upload 195 files
4c75d73 verified
#!/usr/bin/env python3
"""
Test script to verify that the private chat dropdown shows entity names instead of IDs
"""
import sys
import os
# Add the src directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
def test_dropdown_display_names():
try:
# Import required modules
from src.core.game_engine import get_game_engine
from src.facades.game_facade import GameFacade
from src.ui.interface_manager import InterfaceManager
from src.ui.huggingface_ui import HuggingFaceUI
print("🧪 Testing Private Chat Dropdown Display Names...")
# Get game instances
facade = GameFacade()
ui = HuggingFaceUI(facade)
interface_manager = InterfaceManager(facade, ui)
# Add test players
player1_id = facade.join_game('TestPlayer1')
player2_id = facade.join_game('TestPlayer2')
print(f"✅ Created players:")
print(f" - TestPlayer1: {player1_id}")
print(f" - TestPlayer2: {player2_id}")
# Move players close to each other (same position)
facade.move_player(player1_id, "right") # Move to position (1, 0)
facade.move_player(player2_id, "right") # Move to position (1, 0)
print("📍 Moved players to same position for proximity testing")
# Test proximity info and dropdown choices
proximity_html, choices, has_entities = interface_manager._get_proximity_info(player1_id)
print(f"🔍 Proximity detection result:")
print(f" - Has nearby entities: {has_entities}")
print(f" - Number of choices: {len(choices)}")
print(f" - Choices: {choices}")
# Verify that choices contain human-readable names, not IDs
if has_entities and choices:
print("\n✅ Testing dropdown choices:")
for choice in choices:
print(f" - Choice: '{choice}'")
# Check if it's a human-readable name (not a UUID-like ID)
if choice == "TestPlayer2":
print(f" ✅ Correctly shows human-readable name!")
elif len(choice) == 36 and '-' in choice: # UUID format
print(f" ❌ Still showing entity ID instead of name!")
return False
else:
print(f" ✅ Shows name: {choice}")
# Test the name-to-ID mapping
print(f"\n🗺️ Entity name-to-ID mapping:")
for name, entity_id in interface_manager.entity_name_to_id.items():
print(f" - '{name}' -> {entity_id}")
# Test chat tab creation with display name
if choices:
selected_name = choices[0] # Select first choice (should be a name)
print(f"\n💬 Testing chat tab creation with: '{selected_name}'")
# Simulate starting a chat (this should work with display names now)
chat_tabs_state = {}
current_state = {"joined": True, "player_id": player1_id}
result = interface_manager._handle_start_chat(
selected_name,
chat_tabs_state,
current_state
)
print(f"📋 Chat tab creation result:")
print(f" - Tab state: {chat_tabs_state}")
# Verify that the tab was created with the correct entity ID
if chat_tabs_state:
for entity_id, tab_info in chat_tabs_state.items():
print(f" - Entity ID: {entity_id}")
print(f" - Display name: {tab_info['name']}")
if tab_info['name'] == selected_name:
print(" ✅ Tab created successfully with correct name!")
else:
print(" ❌ Tab name mismatch!")
return False
print("\n✅ All dropdown display name tests passed!")
return True
except Exception as e:
print(f"❌ Test failed: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
success = test_dropdown_display_names()
sys.exit(0 if success else 1)