Files
aetherbound-guild/runtime/tests/fg4/contract1_state_test.gd
T

80 lines
3.5 KiB
GDScript

extends SceneTree
const Fixture = preload("res://tests/fg4/contract1_fixture.gd")
const State = preload("res://fg4/run_state.gd")
var failures: Array[String] = []
var rejected_cases := 0
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
verify_market_entry_and_restore()
verify_rejected_state_boundaries()
if failures.is_empty():
print("ABG_FG4_CONTRACT1_STATE_OK phase=market region=RG-03 contract=CTR-R3-01 prior_routes=24 capacity=10 board=3,4,3 exact_company=true operations=legacy_only rejected_cases=%d" % rejected_cases)
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func verify_market_entry_and_restore() -> void:
var snapshot_value := Fixture.new().market_1_snapshot()
expect(not snapshot_value.is_empty(), "real FG-3 close migrates")
var state := State.new()
expect(state.restore_snapshot(snapshot_value), "migrated state restores")
if snapshot_value.is_empty() or not state.invariants_hold():
return
var run: Dictionary = state.current_run
expect(run.phase == "market" and run.status == "active", "RG-03 starts in active Market phase")
expect(run.region_id == "RG-03" and run.contract_id == "CTR-R3-01", "Region and Contract IDs are exact")
expect(run.market_index == 1 and run.round_index == 1 and run.cleared_rounds == 24, "campaign lineage is exact")
expect(run.line_capacity == 10 and run.market_board.line_capacity == 10, "capacity remains at core cap")
expect(run.route_history.size() == 24 and run.company.size() == run.recruit_records.size(), "history and Company remain complete")
expect(run.available_recruit_offer_ids.size() == 3 and run.available_equipment_offer_ids.size() == 4 and run.available_battle_offer_ids.size() == 3, "Market availability matches 3/4/3 board")
expect(state.operation_receipts.is_empty() and not state.legacy_operation_receipts.is_empty(), "new operation namespace starts empty")
var roundtrip := State.new()
expect(roundtrip.restore_snapshot(state.snapshot()) and roundtrip.snapshot() == state.snapshot(), "snapshot roundtrips byte-equivalent")
func verify_rejected_state_boundaries() -> void:
var original := Fixture.new().market_1_snapshot()
if original.is_empty():
return
var state := State.new()
expect(state.restore_snapshot(original), "negative probe starts valid")
var before := state.snapshot()
var wrong_region := original.duplicate(true)
wrong_region.current_run.region_id = "RG-02"
expect_rejected(state, wrong_region, "region drift")
var wrong_board := original.duplicate(true)
wrong_board.current_run.market_board.pressure_valve.position = 10
expect_rejected(state, wrong_board, "board drift")
var wrong_history := original.duplicate(true)
wrong_history.current_run.cleared_rounds = 23
expect_rejected(state, wrong_history, "cleared history drift")
var wrong_equipment := original.duplicate(true)
var recruit_id := String(wrong_equipment.current_run.company[0])
var instance_id := String(wrong_equipment.current_run.equipped_by_recruit[recruit_id])
if not instance_id.is_empty():
wrong_equipment.current_run.inventory[instance_id].wearer_id = "foreign"
expect_rejected(state, wrong_equipment, "equipment ownership drift")
expect(state.snapshot() == before, "rejected restores never mutate valid state")
func expect_rejected(state, candidate: Dictionary, label: String) -> void:
var rejected: bool = not state.restore_snapshot(candidate)
expect(rejected, "%s rejects" % label)
if rejected:
rejected_cases += 1
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append("FG-4 Contract-1 state: %s" % message)