Save The Tree implementation and acceptance work in progress
Preserve production code, regression fixtures, audio assets and provenance, test infrastructure, and the original-completion plan and progress ledger. Final game and Windows acceptance remain pending; excluded local artifacts and native experiments are not part of this snapshot.
This commit is contained in:
@@ -5,6 +5,10 @@ const CommandResultType = preload("res://scripts/core/command_result.gd")
|
||||
const CommandQueueType = preload("res://scripts/core/command_queue.gd")
|
||||
const TransactionType = preload("res://scripts/core/state_transaction.gd")
|
||||
|
||||
const OWNERSHIP_FIXED := true
|
||||
|
||||
const ROLLBACK_ALIAS_FIXED := true
|
||||
|
||||
var _checks := 0
|
||||
var _failures := 0
|
||||
|
||||
@@ -20,8 +24,10 @@ func _run() -> void:
|
||||
_test_snapshot_preserves_accepted_idempotency_history()
|
||||
_test_legacy_snapshot_migrates_accepted_metadata()
|
||||
_test_transaction_commit()
|
||||
_test_executor_ownership()
|
||||
_test_validation_is_atomic()
|
||||
_test_apply_failure_rolls_back()
|
||||
_test_rollback_alias_snapshot()
|
||||
if _failures == 0:
|
||||
print("PASS: %d checks" % _checks)
|
||||
else:
|
||||
@@ -201,3 +207,66 @@ func _expect(condition: bool, label: String) -> void:
|
||||
return
|
||||
_failures += 1
|
||||
push_error(" ✗ %s" % label)
|
||||
|
||||
|
||||
func _test_executor_ownership() -> void:
|
||||
var queue = CommandQueueType.new()
|
||||
var input = _command(91, 0, 1, &"ownership-91")
|
||||
input.payload = {&"nested": {&"amount": 40}}
|
||||
_expect(queue.enqueue(input).is_success(), "ownership fixture accepted")
|
||||
var ready: Array = queue.drain_ready(0)
|
||||
var before: Dictionary = queue.create_snapshot()
|
||||
ready[0].command_id = 900
|
||||
ready[0].idempotency_key = &"changed"
|
||||
ready[0].payload[&"nested"][&"amount"] = 99
|
||||
var after: Dictionary = queue.create_snapshot()
|
||||
_expect((after == before) == OWNERSHIP_FIXED, "drained caller identity and nested payload isolation")
|
||||
var restored = CommandQueueType.new()
|
||||
_expect(restored.restore_snapshot(after) == OWNERSHIP_FIXED, "caller mutation does not corrupt restorable accepted metadata")
|
||||
_expect(queue.complete(91, CommandResultType.succeeded(91)).is_success(), "complete original accepted identity")
|
||||
_expect(queue.in_flight_count() == 0 and queue.processed_count() == 1, "original identity completes exactly once")
|
||||
var executor_queue = CommandQueueType.new()
|
||||
_expect(executor_queue.enqueue(_command(92, 0, 1, &"ownership-92")).is_success(), "executor mutation fixture accepted")
|
||||
var results: Array = executor_queue.execute_ready(0, func(command: SimulationCommand) -> CommandResult:
|
||||
command.command_id = 901
|
||||
return CommandResultType.succeeded(901, {"completed": true})
|
||||
)
|
||||
_expect(results.size() == 1 and (results[0].command_id == 92) == OWNERSHIP_FIXED, "executor cannot replace accepted result identity")
|
||||
_expect((executor_queue.in_flight_count() == 0) == OWNERSHIP_FIXED, "executor mutation does not strand accepted in-flight command")
|
||||
_expect((executor_queue.get_result_by_idempotency_key(&"ownership-92") != null) == OWNERSHIP_FIXED, "executor mutation preserves replay result")
|
||||
var mismatch_queue = CommandQueueType.new()
|
||||
mismatch_queue.enqueue(_command(93, 0, 1, &"ownership-93"))
|
||||
var mismatched: Array = mismatch_queue.execute_ready(0, func(_command_value: SimulationCommand) -> CommandResult:
|
||||
return CommandResultType.succeeded(999)
|
||||
)
|
||||
_expect((mismatched[0].command_id == 93) == OWNERSHIP_FIXED, "returned result uses the same identity as stored replay result")
|
||||
_expect(mismatch_queue.get_result_by_idempotency_key(&"ownership-93").command_id == 93, "stored result keeps accepted identity")
|
||||
print("COMMAND_OWNERSHIP_FIXED=" + str(OWNERSHIP_FIXED))
|
||||
|
||||
|
||||
func _test_rollback_alias_snapshot() -> void:
|
||||
for erase: bool in [false, true]:
|
||||
var original := {"nested": {"balance": 100}, "entries": [1, 2]}
|
||||
var target := {"value": original}
|
||||
var before := target.duplicate(true)
|
||||
var transaction = TransactionType.new()
|
||||
var mode := "erase" if erase else "set"
|
||||
_expect(transaction.stage_dictionary_erase(target, "value") if erase else transaction.stage_dictionary_set(target, "value", {"replacement": true}), mode + " alias fixture staged")
|
||||
_expect(target == before, mode + " staging preserves original nested value")
|
||||
transaction.stage_custom(
|
||||
"alias mutation followed by failure",
|
||||
func() -> bool: return true,
|
||||
func() -> bool:
|
||||
original["nested"]["balance"] = 0
|
||||
original["entries"].append(3)
|
||||
return false,
|
||||
func() -> void: pass
|
||||
)
|
||||
var result = transaction.commit()
|
||||
_expect(result.code == CommandResultType.Code.TRANSACTION_APPLY_FAILED and transaction.status == TransactionType.Status.ROLLED_BACK, mode + " failed apply rolls back")
|
||||
_expect((target == before) == ROLLBACK_ALIAS_FIXED, mode + " rollback restores staged original values instead of changed external alias")
|
||||
original["nested"]["balance"] = -1
|
||||
original["entries"].clear()
|
||||
_expect((target == before) == ROLLBACK_ALIAS_FIXED, mode + " later alias mutation cannot change rolled-back target")
|
||||
_expect(transaction.commit().code == CommandResultType.Code.TRANSACTION_CLOSED, mode + " rolled-back transaction cannot apply twice")
|
||||
print("ROLLBACK_ALIAS_FIXED=" + str(ROLLBACK_ALIAS_FIXED))
|
||||
|
||||
Reference in New Issue
Block a user