Add gdlint and gdformat scripts
This commit is contained in:
@@ -5,6 +5,7 @@ extends SceneTree
|
||||
|
||||
const TestHelper = preload("res://tests/helpers/TestHelper.gd")
|
||||
|
||||
|
||||
func _initialize():
|
||||
# Wait for autoloads to initialize
|
||||
await process_frame
|
||||
@@ -15,11 +16,13 @@ func _initialize():
|
||||
# Exit after tests complete
|
||||
quit()
|
||||
|
||||
|
||||
func run_tests():
|
||||
TestHelper.print_test_header("Migration Compatibility")
|
||||
test_migration_compatibility()
|
||||
TestHelper.print_test_footer("Migration Compatibility")
|
||||
|
||||
|
||||
func test_migration_compatibility():
|
||||
TestHelper.print_step("Old Save File Compatibility")
|
||||
var old_save_data = {
|
||||
@@ -28,7 +31,8 @@ func test_migration_compatibility():
|
||||
"current_score": 0,
|
||||
"games_played": 5,
|
||||
"total_score": 450,
|
||||
"grid_state": {
|
||||
"grid_state":
|
||||
{
|
||||
"grid_size": {"x": 8, "y": 8},
|
||||
"tile_types_count": 5,
|
||||
"active_gem_types": [0, 1, 2, 3, 4],
|
||||
@@ -53,7 +57,9 @@ func test_migration_compatibility():
|
||||
print("New checksum format: %s" % new_checksum)
|
||||
|
||||
# The checksums should be different (old system broken)
|
||||
TestHelper.assert_not_equal(old_checksum, new_checksum, "Old and new checksum formats should be different")
|
||||
TestHelper.assert_not_equal(
|
||||
old_checksum, new_checksum, "Old and new checksum formats should be different"
|
||||
)
|
||||
print("Old checksum: %s" % old_checksum)
|
||||
print("New checksum: %s" % new_checksum)
|
||||
|
||||
@@ -71,7 +77,11 @@ func test_migration_compatibility():
|
||||
|
||||
var second_checksum = _calculate_new_checksum(reloaded_data)
|
||||
|
||||
TestHelper.assert_equal(first_checksum, second_checksum, "New system should be self-consistent across save/load cycles")
|
||||
TestHelper.assert_equal(
|
||||
first_checksum,
|
||||
second_checksum,
|
||||
"New system should be self-consistent across save/load cycles"
|
||||
)
|
||||
print("Consistent checksum: %s" % first_checksum)
|
||||
|
||||
TestHelper.print_step("Migration Strategy Verification")
|
||||
@@ -80,6 +90,7 @@ func test_migration_compatibility():
|
||||
print("✓ Files with version < current: Recalculate checksum after migration")
|
||||
print("✓ Files with current version: Use new checksum validation")
|
||||
|
||||
|
||||
# Simulate old checksum calculation (before the fix)
|
||||
func _calculate_old_checksum(data: Dictionary) -> String:
|
||||
# Old broken checksum (without normalization)
|
||||
@@ -88,6 +99,7 @@ func _calculate_old_checksum(data: Dictionary) -> String:
|
||||
var old_string = JSON.stringify(data_copy) # Direct JSON without normalization
|
||||
return str(old_string.hash())
|
||||
|
||||
|
||||
# Implement new checksum calculation (the fixed version with normalization)
|
||||
func _calculate_new_checksum(data: Dictionary) -> String:
|
||||
# Calculate deterministic checksum EXCLUDING the checksum field itself
|
||||
@@ -97,6 +109,7 @@ func _calculate_new_checksum(data: Dictionary) -> String:
|
||||
var checksum_string = _create_deterministic_string(data_copy)
|
||||
return str(checksum_string.hash())
|
||||
|
||||
|
||||
func _create_deterministic_string(data: Dictionary) -> String:
|
||||
# Create a deterministic string representation by processing keys in sorted order
|
||||
var keys = data.keys()
|
||||
@@ -116,6 +129,7 @@ func _create_deterministic_string(data: Dictionary) -> String:
|
||||
parts.append(key_str + ":" + value_str)
|
||||
return "{" + ",".join(parts) + "}"
|
||||
|
||||
|
||||
func _create_deterministic_array_string(arr: Array) -> String:
|
||||
var parts = []
|
||||
for item in arr:
|
||||
@@ -128,6 +142,7 @@ func _create_deterministic_array_string(arr: Array) -> String:
|
||||
parts.append(_normalize_value_for_checksum(item))
|
||||
return "[" + ",".join(parts) + "]"
|
||||
|
||||
|
||||
func _normalize_value_for_checksum(value) -> String:
|
||||
"""
|
||||
CRITICAL FIX: Normalize values for consistent checksum calculation
|
||||
|
||||
Reference in New Issue
Block a user