Capture current source, content data, tests, asset licenses, and original-specification traceability. Original implementation remains incomplete. The accepted matching UI generation passed 154 suites and 12,253 checks, with eight rendered staff-contract screens reviewed. Latest native Windows and full-original acceptance remain outstanding.
172 lines
8.2 KiB
GDScript
172 lines
8.2 KiB
GDScript
extends SceneTree
|
|
|
|
# Actual 53-key recurrence plus text edge cases. No environment variables required.
|
|
# Full Runtime state/event/suffix equivalence remains a separate required gate.
|
|
const CommandType = preload("res://scripts/core/command.gd")
|
|
const QueueType = preload("res://scripts/core/command_queue.gd")
|
|
const ResultType = preload("res://scripts/core/command_result.gd")
|
|
const OBSERVED_KEYS: Array[String] = [
|
|
"guest.auto_queue.guest-auto-00000023.692",
|
|
"pixel_view.command.0044",
|
|
"pixel_view.command.0043",
|
|
"pixel_view.command.0042",
|
|
"pixel_view.command.0041",
|
|
"pixel_view.command.0013",
|
|
"pixel_view.command.0012",
|
|
"pixel_view.command.0011",
|
|
"pixel_view.command.0010",
|
|
"pixel_view.command.0009",
|
|
"pixel_view.command.0008",
|
|
"pixel_view.command.0004",
|
|
"pixel_view.command.0006",
|
|
"pixel_view.command.0007",
|
|
"pixel_view.command.0040",
|
|
"pixel_view.command.0039",
|
|
"pixel_view.command.0037",
|
|
"pixel_view.command.0036",
|
|
"pixel_view.command.0035",
|
|
"pixel_view.command.0034",
|
|
"pixel_view.command.0033",
|
|
"pixel_view.command.0029",
|
|
"pixel_view.command.0028",
|
|
"pixel_view.command.0027",
|
|
"pixel_view.command.0025",
|
|
"pixel_view.command.0024",
|
|
"pixel_view.command.0023",
|
|
"pixel_view.command.0022",
|
|
"pixel_view.command.0021",
|
|
"pixel_view.command.0020",
|
|
"pixel_view.command.0019",
|
|
"pixel_view.command.0017",
|
|
"pixel_view.command.0018",
|
|
"pixel_view.command.0016",
|
|
"pixel_view.command.0014",
|
|
"pixel_view.command.0015",
|
|
"pixel_view.command.0026",
|
|
"guest.auto_queue.guest-auto-00000024.692",
|
|
"guest.auto_queue.guest-auto-00000019.697",
|
|
"pixel_view.command.0005",
|
|
"guest.auto_queue.guest-auto-00000021.662",
|
|
"guest.auto_queue.guest-auto-00000026.722",
|
|
"guest.auto_queue.guest-auto-00000022.726",
|
|
"guest.auto_queue.guest-auto-00000022.662",
|
|
"pixel_view.command.0032",
|
|
"pixel_view.command.0031",
|
|
"pixel_view.command.0030",
|
|
"pixel_view.command.0001",
|
|
"pixel_view.command.0038",
|
|
"pixel_view.command.0002",
|
|
"guest.auto_queue.guest-auto-00000019.632",
|
|
"guest.auto_queue.guest-auto-00000020.632",
|
|
"pixel_view.command.0003",
|
|
]
|
|
var checks := 0
|
|
var failures := 0
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
func _run() -> void:
|
|
print("Command Queue snapshot key-order regression")
|
|
var input: Array[String] = OBSERVED_KEYS.duplicate()
|
|
input.append_array(["A", "a", "a10", "a2", "alpha", "Alpha", "あ", "🌳"])
|
|
var sorted_text: Array[String] = input.duplicate()
|
|
sorted_text.sort()
|
|
var reference := PackedByteArray()
|
|
var reference_final := PackedByteArray()
|
|
for iteration: int in range(2):
|
|
var insertion: Array[String] = input.duplicate()
|
|
if iteration == 1:
|
|
insertion.reverse()
|
|
var queue := QueueType.new()
|
|
for key: String in insertion:
|
|
var identity := sorted_text.find(key) + 1
|
|
_expect(queue.enqueue(_command(identity, identity % 3, identity % 4, key)).is_success(), "accept unique actual/text fixture key")
|
|
var initially_ready := queue.drain_ready(0)
|
|
for index: int in range(initially_ready.size()):
|
|
if index % 2 == 0:
|
|
var command: SimulationCommand = initially_ready[index]
|
|
_expect(queue.complete(command.command_id, _result(command.command_id)).is_success(), "retain processed fixture result")
|
|
var snapshot := queue.create_snapshot()
|
|
var snapshot_bytes := var_to_bytes(snapshot)
|
|
_expect(not snapshot["pending"].is_empty() and not snapshot["in_flight"].is_empty() and not snapshot["processed"].is_empty(),
|
|
"fixture simultaneously covers pending, in-flight and retained results")
|
|
_assert_text_snapshot(snapshot, sorted_text)
|
|
if iteration == 0:
|
|
reference = snapshot_bytes
|
|
_expect(snapshot_bytes == reference, "complete typed snapshot ignores keyed command insertion order")
|
|
_expect(var_to_bytes(queue.create_snapshot()) == snapshot_bytes, "snapshot query is stable and read-only")
|
|
var reversed_source := snapshot.duplicate(true)
|
|
var reverse_keys: Array[String] = sorted_text.duplicate()
|
|
reverse_keys.reverse()
|
|
var raw_map: Dictionary = {}
|
|
for index: int in range(reverse_keys.size()):
|
|
var key: String = reverse_keys[index]
|
|
var raw_key: Variant = StringName(key) if index % 2 == 0 else key
|
|
raw_map[raw_key] = snapshot["idempotency"][key]
|
|
reversed_source["idempotency"] = raw_map
|
|
var restored := QueueType.new()
|
|
_expect(restored.restore_snapshot(reversed_source), "valid reordered mixed String/StringName saved map restores")
|
|
var restored_snapshot := restored.create_snapshot()
|
|
_assert_text_snapshot(restored_snapshot, sorted_text)
|
|
_expect(var_to_bytes(restored_snapshot) == snapshot_bytes, "all saved fields and map output bytes agree after restore")
|
|
for key: String in sorted_text:
|
|
_expect(queue.has_idempotency_key(StringName(key)) and restored.has_idempotency_key(StringName(key)), "every actual/text key remains available")
|
|
var before := queue.get_result_by_idempotency_key(StringName(key))
|
|
var after := restored.get_result_by_idempotency_key(StringName(key))
|
|
if before == null:
|
|
_expect(after == null, "unprocessed key does not invent a result")
|
|
else:
|
|
_expect(after != null and var_to_bytes(before.to_dictionary()) == var_to_bytes(after.to_dictionary()), "retained replay result agrees completely")
|
|
var duplicate := restored.enqueue(_command(10000 + sorted_text.find(key), 10, 0, key))
|
|
_expect(duplicate.code == ResultType.Code.DUPLICATE_IDEMPOTENCY_KEY and int(duplicate.details.get("original_command_id", 0)) == sorted_text.find(key) + 1,
|
|
"restored mapping rejects duplicates with the original command ID")
|
|
_expect(var_to_bytes(restored.create_snapshot()) == snapshot_bytes, "rejected duplicate lookups preserve every saved field")
|
|
var owned := queue.create_snapshot()
|
|
owned["idempotency"].clear()
|
|
owned["accepted"].clear()
|
|
_expect(var_to_bytes(queue.create_snapshot()) == snapshot_bytes, "returned containers cannot corrupt accepted/idempotency state")
|
|
var original_drained := _finish(queue, snapshot)
|
|
var restored_drained := _finish(restored, restored_snapshot)
|
|
_expect(var_to_bytes(original_drained) == var_to_bytes(restored_drained), "restored queue executes every pending command in the same tick/priority/ID order")
|
|
var final_bytes := var_to_bytes(queue.create_snapshot())
|
|
_expect(final_bytes == var_to_bytes(restored.create_snapshot()), "all final retained result/accepted/idempotency bytes agree")
|
|
if iteration == 0:
|
|
reference_final = final_bytes
|
|
_expect(final_bytes == reference_final, "both insertion orders preserve complete processed history")
|
|
print("Command Queue snapshot key-order regression: %d checks, %d failures" % [checks, failures])
|
|
quit(0 if failures == 0 else 1)
|
|
|
|
func _assert_text_snapshot(snapshot: Dictionary, sorted_text: Array[String]) -> void:
|
|
var converted: Array[String] = []
|
|
for raw_key: Variant in snapshot["idempotency"]:
|
|
_expect(typeof(raw_key) == TYPE_STRING, "saved idempotency key remains String")
|
|
_expect(typeof(snapshot["idempotency"][raw_key]) == TYPE_INT and int(snapshot["idempotency"][raw_key]) == sorted_text.find(String(raw_key)) + 1,
|
|
"saved idempotency value retains int type and original command ID")
|
|
converted.append(String(raw_key))
|
|
_expect(var_to_bytes(converted) == var_to_bytes(sorted_text), "saved key text matches ordinary String lexical order")
|
|
_expect(int(snapshot["version"]) == QueueType.SNAPSHOT_VERSION, "snapshot version remains unchanged")
|
|
|
|
func _command(identity: int, tick: int, priority: int, text: String) -> SimulationCommand:
|
|
return CommandType.new(identity, 0, tick, priority, &"Test", &"actor", &"target",
|
|
{"original_key": text, "nested": {"fixture": &"preserve", "value": identity}}, StringName(text))
|
|
|
|
func _result(identity: int) -> CommandResult:
|
|
return ResultType.succeeded(identity, {"number": identity, "nested": {"fixture": &"preserve"}})
|
|
|
|
func _finish(queue: CommandQueue, snapshot: Dictionary) -> Array[Dictionary]:
|
|
for saved: Dictionary in snapshot["in_flight"]:
|
|
var identity := int(saved["command_id"])
|
|
_expect(queue.complete(identity, _result(identity)).is_success(), "complete saved in-flight command with unchanged result")
|
|
var drained: Array[Dictionary] = []
|
|
for command: SimulationCommand in queue.drain_ready(10):
|
|
drained.append(command.to_dictionary())
|
|
_expect(queue.complete(command.command_id, _result(command.command_id)).is_success(), "complete ready command exactly once")
|
|
return drained
|
|
|
|
func _expect(condition: bool, label: String) -> void:
|
|
checks += 1
|
|
if not condition:
|
|
failures += 1
|
|
push_error(label)
|