Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Comprehensive test of the world events auto-refresh fix | |
| """ | |
| import sys | |
| import os | |
| import time | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | |
| try: | |
| 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 | |
| except ImportError as e: | |
| print(f"Import error: {e}") | |
| print("Make sure to run this from the project root directory") | |
| sys.exit(1) | |
| def test_complete_functionality(): | |
| """Test the complete world events functionality""" | |
| print("🔧 WORLD EVENTS AUTO-REFRESH FIX VERIFICATION") | |
| print("=" * 60) | |
| # Test 1: Verify GameFacade has get_world_events method | |
| print("\n1️⃣ Testing GameFacade.get_world_events()...") | |
| try: | |
| facade = GameFacade() | |
| if hasattr(facade, 'get_world_events'): | |
| print("✅ GameFacade.get_world_events() method exists") | |
| # Test calling the method | |
| events = facade.get_world_events() | |
| print(f"✅ Method returns {len(events)} events") | |
| if events: | |
| print(" Sample events:") | |
| for i, event in enumerate(events[-3:], 1): | |
| print(f" {i}. {event}") | |
| else: | |
| print("❌ GameFacade.get_world_events() method missing") | |
| return False | |
| except Exception as e: | |
| print(f"❌ Error testing GameFacade: {e}") | |
| return False | |
| # Test 2: Verify world events can be added | |
| print("\n2️⃣ Testing world event creation...") | |
| try: | |
| # Get the game world through the engine | |
| engine = get_game_engine() | |
| game_world = engine.get_world() | |
| initial_count = len(game_world.world_events) | |
| game_world.add_world_event("🧪 Test event - Auto-refresh fix verification") | |
| game_world.add_world_event("🔄 Testing auto-refresh functionality") | |
| game_world.add_world_event("✨ World events should now display properly") | |
| final_count = len(game_world.world_events) | |
| added_count = final_count - initial_count | |
| print(f"✅ Added {added_count} test events (total: {final_count})") | |
| # Verify through facade | |
| facade_events = facade.get_world_events() | |
| print(f"✅ GameFacade retrieves {len(facade_events)} events") | |
| except Exception as e: | |
| print(f"❌ Error adding world events: {e}") | |
| return False | |
| # Test 3: Test auto-refresh method | |
| print("\n3️⃣ Testing _auto_refresh_game_state method...") | |
| try: | |
| # Create UI components | |
| ui = HuggingFaceUI(facade) | |
| interface_manager = InterfaceManager(facade, ui) | |
| # Test auto-refresh with mock state | |
| mock_state = {"joined": True, "player_id": "test-player"} | |
| # This should not throw an error about mismatched outputs | |
| result = interface_manager._auto_refresh_game_state(mock_state, True) | |
| if isinstance(result, tuple) and len(result) == 8: | |
| print(f"✅ Auto-refresh returns correct number of outputs: {len(result)}") | |
| print("✅ Timer configuration matches method return values") | |
| else: | |
| print(f"❌ Auto-refresh returns {len(result) if isinstance(result, tuple) else 'non-tuple'} outputs, expected 8") | |
| return False | |
| except Exception as e: | |
| print(f"❌ Error testing auto-refresh: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| # Test 4: Create a real player to test full functionality | |
| print("\n4️⃣ Testing with real player...") | |
| try: | |
| test_player_id = facade.join_game("AutoRefreshTester") | |
| if test_player_id: | |
| print(f"✅ Created test player: {test_player_id}") | |
| # Test auto-refresh with real player | |
| real_state = {"joined": True, "player_id": test_player_id} | |
| result = interface_manager._auto_refresh_game_state(real_state, True) | |
| if len(result) == 8: | |
| print("✅ Auto-refresh works with real player") | |
| # Check if world_events data is in the result | |
| world_events_update = result[7] # 8th element (0-indexed) | |
| if hasattr(world_events_update, 'value'): | |
| print("✅ World events data included in auto-refresh result") | |
| if "Test event" in str(world_events_update.value): | |
| print("✅ Test events are being retrieved correctly") | |
| else: | |
| print("⚠️ World events update object has no value attribute") | |
| # Clean up | |
| facade.leave_game(test_player_id) | |
| print("✅ Test player removed") | |
| else: | |
| print("❌ Could not create test player") | |
| return False | |
| except Exception as e: | |
| print(f"❌ Error testing with real player: {e}") | |
| return False | |
| print("\n🎉 ALL TESTS PASSED!") | |
| print("\n📋 SUMMARY:") | |
| print("✅ GameFacade.get_world_events() method exists and works") | |
| print("✅ World events can be created and retrieved") | |
| print("✅ Auto-refresh method returns 8 outputs (matching timer config)") | |
| print("✅ Timer configuration includes world_events in outputs list") | |
| print("✅ World events data is properly included in auto-refresh cycle") | |
| print("\n🌐 The fix is working! Check the browser at http://localhost:7866") | |
| print(" Join the game and watch the 'World Events' panel update automatically!") | |
| return True | |
| if __name__ == "__main__": | |
| success = test_complete_functionality() | |
| if success: | |
| print("\n🚀 Fix verification complete - world events auto-refresh is working!") | |
| else: | |
| print("\n❌ Fix verification failed - there may be remaining issues") | |
| sys.exit(1) | |