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:
@@ -19,6 +19,9 @@ func _run() -> void:
|
||||
_test_seed_424242_second_arrival_boundary()
|
||||
_test_after_mutation_notifications_are_atomic()
|
||||
_test_deferred_failure_backlog_and_exact_retry()
|
||||
_test_upcoming_reserved_request_capture_and_retry()
|
||||
_test_reserved_enqueue_rejection_is_atomic()
|
||||
_test_external_capture_rejects_invalid_state()
|
||||
_test_daily_payroll_financials_and_crosslink_tamper()
|
||||
_test_legacy_financial_calendar()
|
||||
_cleanup()
|
||||
@@ -391,6 +394,7 @@ func _test_legacy_financial_calendar() -> void:
|
||||
old[&"schema_version"] = 3
|
||||
old.erase(&"legacy_calendar_last_day")
|
||||
old.erase(&"legacy_history_last_day")
|
||||
old.erase(&"legacy_principal_profit_last_day")
|
||||
old[&"consecutive_insolvency_count"] = 0
|
||||
for row: Dictionary in old[&"day_summaries"]:
|
||||
row[&"consecutive_insolvency_count"] = 0
|
||||
@@ -420,3 +424,127 @@ func _expect(condition: bool, label: String) -> void:
|
||||
return
|
||||
_failures += 1
|
||||
push_error(" ✗ %s" % label)
|
||||
|
||||
|
||||
class RecordingInventory:
|
||||
extends InventoryService
|
||||
var successful_reservations: Array[Dictionary] = []
|
||||
func reserve_item(owner_inventory_id: StringName, item_id: StringName, quantity: int, requester_id: StringName, purpose: StringName, created_at: int = -1, expires_at: int = -1, operation_id: StringName = &"") -> Dictionary:
|
||||
var result := super.reserve_item(owner_inventory_id, item_id, quantity, requester_id, purpose, created_at, expires_at, operation_id)
|
||||
if bool(result.get(&"ok", false)):
|
||||
successful_reservations.append({&"result": result.duplicate(true), &"state": create_snapshot()})
|
||||
return result
|
||||
|
||||
|
||||
func _prepare_upcoming_inventory_fixture() -> FacilityInstance:
|
||||
_reset_runtime(424242)
|
||||
_expect(bool(_runtime.enable_production_operations().get(&"ok", false)), "upcoming inventory fixture enables Operations")
|
||||
_clock.advance_minutes(29)
|
||||
# Local integration seam uses the canonical definition and permitted Guest APIs.
|
||||
# It does not establish construction or ordinary OS business acceptance.
|
||||
_runtime._register_operational_facility({&"instance_id": &"upcoming_kitchen", &"definition_id": &"kitchen", &"completed_at": 389})
|
||||
var facility: FacilityInstance = _runtime.facility_service.get_instance(&"upcoming_kitchen")
|
||||
_expect(facility != null, "canonical kitchen registers for reservation integration")
|
||||
if facility == null: return null
|
||||
_expect(bool(_runtime.inventory_service.add_stack(facility.local_inventory_id, &"ingredient/raw_food", 8, 100, -1, 389).get(&"ok", false)), "private fixture holds canonical recipe input")
|
||||
var spawned: CommandResult = _runtime.submit_command(&"spawn_guest", {&"guest_id": &"upcoming_payer", &"guest_type_id": _runtime.get_mvp_guest_definition_ids()[0], &"options": {&"current_cell": _runtime._operations_entrance_cell()}}, &"test")
|
||||
_expect(spawned.is_success(), "dedicated reservation Guest spawns through Runtime command")
|
||||
_expect(bool(_runtime.guest_service.transition_guest(&"upcoming_payer", GuestRuntime.State.DECIDING, 389, &"TEST_FIXTURE").get(&"ok", false)), "dedicated Guest uses permitted decision transition")
|
||||
_expect(_runtime._validate_runtime_crosslinks(_runtime.facility_service, _runtime.guest_service, _runtime.economy_service, _runtime.inventory_service, _runtime.staff_service, 389, _runtime._staffing_projection_enabled), "reservation fixture starts with valid crosslinks")
|
||||
return facility
|
||||
|
||||
|
||||
func _test_upcoming_reserved_request_capture_and_retry() -> void:
|
||||
for failure_phase: StringName in [&"PREPARE", &"AFTER_FIRST_MUTATION"]:
|
||||
var facility := _prepare_upcoming_inventory_fixture()
|
||||
if facility == null: continue
|
||||
var observed := {&"token": {}, &"command_id": -1, &"completions": 0, &"guest": 0, &"economy": 0, &"arrival": 0, &"forced_failures": 0}
|
||||
_runtime.command_completed.connect(func(result: CommandResult) -> void:
|
||||
if result.command_id == observed[&"command_id"]: observed[&"completions"] += 1)
|
||||
_runtime.guest_service.guest_spawned.connect(func(_guest: GuestRuntime) -> void:
|
||||
if not observed[&"token"].is_empty(): observed[&"guest"] += 1)
|
||||
_runtime.economy_service.transaction_posted.connect(func(_id: StringName, _entries: Array) -> void:
|
||||
if not observed[&"token"].is_empty(): observed[&"economy"] += 1)
|
||||
_runtime.operations_coordinator.arrivals_committed.connect(func(_report: Dictionary) -> void:
|
||||
if not observed[&"token"].is_empty(): observed[&"arrival"] += 1)
|
||||
_runtime.set_operations_test_boundary_hook(&"ARRIVAL_PLAN", func(_payload: Dictionary, phase: StringName, token: Variant) -> Dictionary:
|
||||
if phase == &"PREPARE": observed[&"token"] = token.duplicate(true)
|
||||
if phase == failure_phase: observed[&"forced_failures"] += 1
|
||||
return {&"ok": phase != failure_phase, &"reason": &"UPCOMING_REQUEST_ROLLBACK"})
|
||||
_clock.set_paused(false)
|
||||
var queued: CommandResult = _runtime.submit_command(&"create_service_request", {&"request_id": &"upcoming_reserved", &"facility_id": facility.instance_id, &"guest_ids": [&"upcoming_payer"]}, &"test", facility.instance_id, 100, 390, &"upcoming.reserved")
|
||||
observed[&"command_id"] = queued.command_id
|
||||
_expect(queued.is_success(), "upcoming reserved request is queued for minute390")
|
||||
_clock.advance_one_minute()
|
||||
var token: Dictionary = observed[&"token"]
|
||||
_expect(observed[&"forced_failures"] == 1, "specified arrival fault phase is reached exactly once")
|
||||
_expect(not token.is_empty() and int(token.get(&"captured_minute", -1)) == 389 and int(token.get(&"captured_clock_minute", -1)) == 390, "upcoming queue preserves participant389 and captures clock390")
|
||||
_expect(_clock.paused and not _runtime.operations_coordinator.is_external_quarantined() and bool(_runtime.get_operations_report().get(&"runtime_failure_latched", false)), "forced arrival failure rolls back without quarantine")
|
||||
_expect(not token.is_empty() and var_to_bytes(token) == var_to_bytes(_runtime._build_operations_external_state()), "post-command external token restores literally including reservation queues IDs RNG and ledger")
|
||||
_expect(observed[&"guest"] == 0 and observed[&"economy"] == 0 and observed[&"arrival"] == 0, "rolled-back arrival emits no success notification")
|
||||
var request: ServiceRequest = _runtime.facility_service.get_request(&"upcoming_reserved")
|
||||
_expect(request != null and request.created_at == 390 and request.enqueued_at == 390 and request.reserved_inventory_ids.size() == 1, "request effective time and one reserved input survive rollback")
|
||||
if request != null and request.reserved_inventory_ids.size() == 1:
|
||||
var reservation: InventoryReservation = _runtime.inventory_service.get_reservation(request.reserved_inventory_ids[0])
|
||||
_expect(reservation != null and reservation.created_at == 390 and reservation.quantity == 4, "canonical raw-food reservation retains quantity and effective time")
|
||||
_runtime.set_operations_test_boundary_hook(&"ARRIVAL_PLAN", Callable())
|
||||
var retried: Dictionary = _runtime.acknowledge_operations_pause()
|
||||
_expect(bool(retried.get(&"ok", false)) and observed[&"completions"] == 1 and observed[&"arrival"] == 1 and observed[&"guest"] > 0 and observed[&"economy"] > 0, "retry commits arrivals once without replaying reserved request")
|
||||
_expect(_runtime._runtime_aggregate_committed_minute() == 390 and not bool(_runtime.get_operations_report().get(&"runtime_failure_latched", true)), "retry advances every participant suffix once")
|
||||
|
||||
|
||||
func _request_participants() -> Dictionary:
|
||||
return {&"inventory": _runtime.inventory_service.create_snapshot(), &"facilities": _runtime.facility_service.create_snapshot(), &"guests": _runtime.guest_service.create_snapshot(), &"economy": _runtime.economy_service.create_snapshot(), &"events": _runtime.domain_events.create_snapshot(), &"ids": _runtime.id_generator.create_snapshot()}
|
||||
|
||||
|
||||
func _test_reserved_enqueue_rejection_is_atomic() -> void:
|
||||
var facility := _prepare_upcoming_inventory_fixture()
|
||||
if facility == null: return
|
||||
# Zero queue space is an explicit rejection fixture, not a game value change.
|
||||
facility.queue_capacity = 0
|
||||
var recorded := RecordingInventory.new()
|
||||
_expect(recorded.restore_snapshot(_runtime.inventory_service.create_snapshot()), "reservation recording seam starts from exact inventory")
|
||||
_runtime.inventory_service = recorded
|
||||
var observed := {&"calls": 0, &"before": {}, &"after": {}, &"result": {}, &"result_code": -1, &"guest_notifications": -1}
|
||||
var notifications := {&"queue": 0, &"guest": 0}
|
||||
_runtime.unregister_command_executor(&"create_service_request")
|
||||
var installed: bool = _runtime.register_command_executor(&"create_service_request", func(command: SimulationCommand) -> CommandResult:
|
||||
observed[&"calls"] += 1
|
||||
observed[&"before"] = _request_participants()
|
||||
var guest_notifications_before: int = notifications[&"guest"]
|
||||
var result: CommandResult = _runtime._execute_create_service_request(command)
|
||||
observed[&"after"] = _request_participants()
|
||||
observed[&"result"] = result.to_dictionary()
|
||||
observed[&"result_code"] = result.code
|
||||
observed[&"guest_notifications"] = int(notifications[&"guest"]) - guest_notifications_before
|
||||
return result)
|
||||
_expect(installed, "request executor observation wrapper registers successfully")
|
||||
_runtime.facility_service.request_enqueued.connect(func(_request: ServiceRequest) -> void: notifications[&"queue"] += 1)
|
||||
_runtime.guest_service.guest_state_changed.connect(func(_id: StringName, _old: int, _new: int, _reason: StringName) -> void: notifications[&"guest"] += 1)
|
||||
_clock.set_paused(false)
|
||||
var queued: CommandResult = _runtime.submit_command(&"create_service_request", {&"facility_id": facility.instance_id, &"guest_ids": [&"upcoming_payer"]}, &"test", facility.instance_id, 100, 390, &"upcoming.rejected")
|
||||
_expect(queued.is_success(), "reservation rejection command enters normal queue")
|
||||
_clock.advance_one_minute()
|
||||
print("REJECTION_EXECUTOR_OBSERVATION ", JSON.stringify({&"calls": observed[&"calls"], &"result_code": observed[&"result_code"], &"result": observed[&"result"], &"guest_notifications": observed[&"guest_notifications"]}, "", true, true))
|
||||
_expect(observed[&"guest_notifications"] == 0, "failed executor emits no Guest state-change notification")
|
||||
_expect(observed[&"calls"] == 1 and observed[&"result_code"] == CommandResult.Code.VALIDATION_FAILED, "normal executor rejects queue after attempting request once")
|
||||
_expect(recorded.successful_reservations.size() == 1 and not recorded.successful_reservations[0][&"result"][&"reservation_ids"].is_empty(), "input reservation actually succeeds before enqueue rejection")
|
||||
_expect(var_to_bytes(observed[&"before"]) == var_to_bytes(observed[&"after"]), "enqueue rejection restores inventory facility Guest economy events and IDs literally before completion event")
|
||||
_expect(notifications[&"queue"] == 0, "failed enqueue emits no queue-success notification")
|
||||
_expect(_runtime._runtime_aggregate_committed_minute() == 390 and not _runtime.operations_coordinator.is_external_quarantined(), "rejected request leaves subsequent arrival and suffix healthy")
|
||||
|
||||
|
||||
func _test_external_capture_rejects_invalid_state() -> void:
|
||||
_reset_runtime(424242)
|
||||
_expect(bool(_runtime.enable_production_operations().get(&"ok", false)), "strict capture fixture enables Operations")
|
||||
var before := var_to_bytes(_runtime.create_snapshot())
|
||||
_expect(not _runtime._restore_operations_external_state({}) and not _runtime._restore_operations_external_state(null), "empty and invalid-type tokens are rejected")
|
||||
var valid: Dictionary = _runtime._build_operations_external_state()
|
||||
var corrupt: Dictionary = valid.duplicate(true)
|
||||
corrupt.erase(&"economy")
|
||||
_expect(not _runtime._restore_operations_external_state(corrupt), "missing required aggregate token is rejected")
|
||||
_expect(before == var_to_bytes(_runtime.create_snapshot()), "invalid token rejection preserves entire live snapshot")
|
||||
_runtime.facility_service.current_minute += 1
|
||||
_expect(_runtime._capture_operations_external_state().is_empty(), "real participant clock mismatch yields empty capture instead of success")
|
||||
_runtime.facility_service.current_minute -= 1
|
||||
_expect(before == var_to_bytes(_runtime.create_snapshot()), "restored fixture minute preserves canonical state")
|
||||
|
||||
Reference in New Issue
Block a user