extends SceneTree const EntryShell = preload("res://entry/entry_shell.gd") const SettingsStore = preload("res://entry/settings_store.gd") const DraftService = preload("res://entry/initial_company_draft_service.gd") const ContractService = preload("res://entry/guild_contract_service.gd") const FormationService = preload("res://entry/formation_risk_service.gd") const BattleService = preload("res://entry/battle_service.gd") const DRAFT_PATH := "user://bat34_draft.json" const COMPANY_PATH := "user://bat34_company.json" const SEED := "2468ace013579bdf2468ace013579bdf" const CONTRACT_OP := "00112233445566778899aabbccddeeff" const HIRE_OP_1 := "11112222333344445555666677778888" const HIRE_OP_2 := "88887777666655554444333322221111" const ORDER_OP := "abcdefabcdefabcdefabcdefabcdefab" const READY_OP := "fedcbafedcbafedcbafedcbafedcbafe" const BATTLE_OP := "1234567890abcdef1234567890abcdef" var failures: Array[String] = [] var parsed_touches := 0 func _initialize() -> void: call_deferred("run_test") func run_test() -> void: _cleanup() root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS root.content_scale_aspect = Window.CONTENT_SCALE_ASPECT_EXPAND root.size = Vector2i(844, 390) var company := _prepare_company() expect(not company.is_empty(), "fixture prepares a battle-ready Company") if not company.is_empty(): var started: Dictionary = _battle_service().begin_battle(BATTLE_OP, String(company.active_contract.formation.risk_options[1].risk_option_id)) expect(started.ok, "fixture begins one battle receipt") if started.ok: var shell := await _shell() shell.show_battle(started.company, false) await _frames(4) shell.battle_paused = false shell._clear_battle_playback_timer() for _step in range(4): shell.advance_battle_phase() await _frames(1) shell.battle_paused = true shell._clear_battle_playback_timer() var before_hash := _company_hash() shell._battle_live_toggle_inspect() await _frames(3) expect(shell.current_screen == "battle_inspect" and shell.battle_paused, "BAT-003 opens a contained inspect surface and freezes time") expect(shell.find_child("BattleActorEventInspectPanel", true, false) != null and shell.find_child("BattleInspectFacts", true, false) != null, "BAT-003 shows causal actor/event facts") expect(shell.find_child("BattleInspectClose", true, false) != null and shell.find_child("BattleInspectPin", true, false) != null, "BAT-003 exposes close and local pin actions") await _touch(shell.find_child("BattleInspectPin", true, false)) expect(_company_hash() == before_hash and shell.current_screen == "battle_inspect", "pin changes no authoritative battle state") await _touch(shell.find_child("BattleInspectClose", true, false)) expect(shell.current_screen == "battle" and shell.battle_live_state == "paused", "closing BAT-003 returns to the paused battle") shell._battle_live_open_retreat_entry() await _frames(3) expect(shell.current_screen == "battle_pause_controls" and shell.battle_paused, "BAT-004 opens a contained pause/control surface") expect(shell.find_child("BattlePauseControlsPanel", true, false) != null and shell.find_child("BattlePauseLog", true, false) != null, "BAT-004 exposes a readable event log") expect(shell.find_child("BattlePauseResume", true, false) != null and shell.find_child("BattlePauseSpeed", true, false) != null and shell.find_child("BattlePauseRetreat", true, false) != null, "BAT-004 exposes Resume, Speed and Retreat boundary") var baseline_speed: float = shell.battle_speed await _touch(shell.find_child("BattlePauseSpeed", true, false)) expect(shell.battle_speed != baseline_speed and shell.current_screen == "battle_pause_controls", "pause speed cycles locally while remaining paused") await _touch(shell.find_child("BattlePauseLogToggle", true, false)) expect(shell.find_child("BattlePauseLog", true, false) != null and shell.current_screen == "battle_pause_controls", "pause log expands without resuming") await _touch(shell.find_child("BattlePauseRetreat", true, false)) expect(_company_hash() == before_hash and shell.battle_paused, "retreat entry creates no receipt") await _touch(shell.find_child("BattlePauseClose", true, false)) expect(shell.current_screen == "battle" and shell.battle_paused, "closing BAT-004 returns to the paused battlefield") shell.queue_free() await _frames(4) _cleanup() if failures.is_empty(): print("ABG_BAT003_BAT004_RUNTIME_OK inspect=actor,event,cause,hash pin=local_only pause=resume,speed,log,settings,retreat boundary=receipt_freeze focus=touch parsed_touch=%d" % parsed_touches) quit(0) else: for failure in failures: push_error(failure) quit(1) func _shell() -> Control: var shell := EntryShell.new() shell.auto_start = false shell.initial_company_service.path = DRAFT_PATH shell.initial_company_service.company_path = COMPANY_PATH root.add_child(shell) await _frames(3) var settings := SettingsStore.new().defaults() settings.setup_completed = true settings.locale = "en" settings.text_scale = 1.0 shell.settings = settings shell.setup_draft = settings.duplicate(true) return shell func _prepare_company() -> Dictionary: var draft: Dictionary = _draft_service().begin_or_load(SEED) if not draft.ok: return {} _draft_service().set_selection([String(draft.draft.offers[0].offer_id), String(draft.draft.offers[1].offer_id)]) if not _draft_service().commit_company().ok: return {} var created: Dictionary = _contract_service().create_contract(CONTRACT_OP, "CTR-R1-01", "standard") if not created.ok: return {} var offers: Array = created.company.active_contract.market_board.recruit_offers _contract_service().hire_recruit(HIRE_OP_1, String(offers[0].source_offer_id), 14) var hired: Dictionary = _contract_service().hire_recruit(HIRE_OP_2, String(offers[1].source_offer_id), 14) if not hired.ok: return {} var begun: Dictionary = _formation_service().begin_formation() if not begun.ok: return {} var saved: Dictionary = _formation_service().save_order(ORDER_OP, begun.formation.base_front_to_rear_ids) if not saved.ok: return {} var ready: Dictionary = _formation_service().accept_readiness(READY_OP, String(saved.receipt.order_hash)) return ready.company if ready.ok else {} func _draft_service() -> RefCounted: var service := DraftService.new() service.path = DRAFT_PATH service.company_path = COMPANY_PATH return service func _contract_service() -> RefCounted: var service := ContractService.new() service.company_path = COMPANY_PATH return service func _formation_service() -> RefCounted: var service := FormationService.new() service.company_path = COMPANY_PATH return service func _battle_service() -> RefCounted: var service := BattleService.new() service.company_path = COMPANY_PATH return service func _company_hash() -> String: var loaded: Dictionary = _battle_service().load_company() return String(loaded.company.company_hash) if loaded.ok else "" func _touch(control: Control) -> void: if control == null: expect(false, "touch target exists") return var center := control.get_global_rect().get_center() var press := InputEventScreenTouch.new() press.position = center press.pressed = true press.index = 0 Input.parse_input_event(press) await _frames(2) var release := InputEventScreenTouch.new() release.position = center release.pressed = false release.index = 0 Input.parse_input_event(release) parsed_touches += 1 await _frames(5) func _frames(count: int) -> void: for _index in range(count): await process_frame func _cleanup() -> void: for path in [DRAFT_PATH, COMPANY_PATH, "%s.bak" % DRAFT_PATH, "%s.bak" % COMPANY_PATH, "%s.candidate" % DRAFT_PATH, "%s.candidate" % COMPANY_PATH, "%s.bak.candidate" % DRAFT_PATH, "%s.bak.candidate" % COMPANY_PATH, "%s.corrupt" % COMPANY_PATH]: if FileAccess.file_exists(path): DirAccess.remove_absolute(path) func expect(condition: bool, message: String) -> void: if not condition: failures.append("BAT-003/004: %s" % message)