extends MainLoop # Test to verify that existing save files with old checksum format can be migrated # This ensures backward compatibility with the checksum fix func _initialize(): test_migration_compatibility() func _finalize(): pass func test_migration_compatibility(): print("=== MIGRATION COMPATIBILITY TEST ===") # Test 1: Simulate old save file format (with problematic checksums) print("\n--- Test 1: Old Save File Compatibility ---") var old_save_data = { "_version": 1, "high_score": 150, "current_score": 0, "games_played": 5, "total_score": 450, "grid_state": { "grid_size": {"x": 8, "y": 8}, "tile_types_count": 5, "active_gem_types": [0, 1, 2, 3, 4], "grid_layout": [] } } # Create old checksum (without normalization) var old_checksum = _calculate_old_checksum(old_save_data) old_save_data["_checksum"] = old_checksum print("Old checksum format: %s" % old_checksum) # Simulate JSON round-trip (causes the type conversion issue) var json_string = JSON.stringify(old_save_data) var json = JSON.new() json.parse(json_string) var loaded_data = json.data # Calculate new checksum with fixed algorithm var new_checksum = _calculate_new_checksum(loaded_data) print("New checksum format: %s" % new_checksum) # The checksums should be different (old system broken) if old_checksum != new_checksum: print("✅ Confirmed: Old and new checksum formats are different") print(" This is expected - old checksums were broken by JSON serialization") else: print("⚠️ Unexpected: Checksums are the same (might indicate test issue)") # Test 2: Verify new system is self-consistent print("\n--- Test 2: New System Self-Consistency ---") # Remove old checksum and recalculate loaded_data.erase("_checksum") var first_checksum = _calculate_new_checksum(loaded_data) loaded_data["_checksum"] = first_checksum # Simulate another save/load cycle json_string = JSON.stringify(loaded_data) json = JSON.new() json.parse(json_string) var reloaded_data = json.data var second_checksum = _calculate_new_checksum(reloaded_data) if first_checksum == second_checksum: print("✅ New system is self-consistent across save/load cycles") print(" Checksum: %s" % first_checksum) else: print("❌ CRITICAL: New system is still inconsistent!") print(" First: %s, Second: %s" % [first_checksum, second_checksum]) # Test 3: Verify migration strategy print("\n--- Test 3: Migration Strategy ---") print("Recommendation: Use version-based checksum handling") print("- Files without _checksum: Allow (backward compatibility)") print("- Files with version < current: Recalculate checksum after migration") print("- Files with current version: Use new checksum validation")