diff --git a/runtime/entry/entry_shell.gd b/runtime/entry/entry_shell.gd index 423b0f7c..1d1adfd2 100644 --- a/runtime/entry/entry_shell.gd +++ b/runtime/entry/entry_shell.gd @@ -742,15 +742,18 @@ func show_roster(company := {}) -> void: _render_roster_detail(detail, resolved, roster_selected_recruit_id) var footer := HBoxContainer.new() footer.name = "RosterFooter" - footer.custom_minimum_size = Vector2(0, 46 if size.y < 500.0 else 52) + footer.custom_minimum_size = Vector2(0, 44 if size.y < 500.0 else 52) footer.add_theme_constant_override("separation", 8) layout.add_child(footer) footer.add_child(_company_button("RosterBackGuild", _tr("返回公会", "Back to Guild"), back_to_guild, "company_utility", "back")) + var roster_back := footer.get_child(footer.get_child_count() - 1) as Button + roster_back.custom_minimum_size = Vector2(190, footer.custom_minimum_size.y) var spacer := Control.new() spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL footer.add_child(spacer) var dismiss_eligible: bool = not roster_selected_recruit_id.is_empty() and resolved.owned_recruits.size() > 1 and String(resolved.active_contract.get("status", "")) == "market" var dismiss := _company_button("RosterDismiss", _tr("解雇", "Dismiss"), open_dismissal_review.bind(roster_selected_recruit_id), "company_secondary", "utility") + dismiss.custom_minimum_size = Vector2(190, footer.custom_minimum_size.y) _set_entry_button_disabled(dismiss, not dismiss_eligible) dismiss.tooltip_text = _tr("审查 %s 的解雇后果", "Review dismissal consequences for %s") % _recruit_name(_recruit_by_id(resolved, roster_selected_recruit_id)) if dismiss_eligible else _tr("最后一名成员不可解雇,或当前阶段不是 Market", "The last member cannot be dismissed, or the current phase is not Market") footer.add_child(dismiss) @@ -828,14 +831,17 @@ func show_recruit_detail(recruit_id: String) -> void: details.add_child(note) var footer := HBoxContainer.new() footer.name = "RecruitDetailFooter" - footer.custom_minimum_size = Vector2(0, 46 if size.y < 500.0 else 52) + footer.custom_minimum_size = Vector2(0, 44 if size.y < 500.0 else 52) layout.add_child(footer) - footer.add_child(_company_button("RecruitDetailBackRoster", _tr("返回成员", "Back to Roster"), show_roster.bind(guild_company), "company_utility", "back")) + var detail_back := _company_button("RecruitDetailBackRoster", _tr("返回成员", "Back to Roster"), show_roster.bind(guild_company), "company_utility", "back") + detail_back.custom_minimum_size = Vector2(190, footer.custom_minimum_size.y) + footer.add_child(detail_back) var spacer := Control.new() spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL footer.add_child(spacer) var dismiss_eligible: bool = guild_company.owned_recruits.size() > 1 and String(guild_company.active_contract.get("status", "")) == "market" var dismiss := _company_button("RecruitDetailDismiss", _tr("解雇", "Dismiss"), open_dismissal_review.bind(recruit_id), "company_secondary", "utility") + dismiss.custom_minimum_size = Vector2(190, footer.custom_minimum_size.y) _set_entry_button_disabled(dismiss, not dismiss_eligible) dismiss.tooltip_text = _tr("审查 %s 的解雇后果", "Review dismissal consequences for %s") % _recruit_name(recruit) if dismiss_eligible else _tr("最后一名成员不可解雇,或当前阶段不是 Market", "The last member cannot be dismissed, or the current phase is not Market") footer.add_child(dismiss) @@ -918,11 +924,13 @@ func open_dismissal_review(recruit_id: String) -> void: footer.add_theme_constant_override("separation", 8) layout.add_child(footer) var cancel := _company_button("DismissalReviewCancel", _tr("取消", "Cancel"), cancel_dismissal_review, "company_utility", "back") + cancel.custom_minimum_size = Vector2(170 if size.y < 500.0 else 190, footer.custom_minimum_size.y) footer.add_child(cancel) var spacer := Control.new() spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL footer.add_child(spacer) var confirm := _company_button("DismissalReviewConfirm", _tr("确认解雇", "Confirm Dismissal"), commit_dismissal, "company_primary", "confirm") + confirm.custom_minimum_size = Vector2(170 if size.y < 500.0 else 190, footer.custom_minimum_size.y) confirm.tooltip_text = _tr("移除该成员,装备归还库存,金币不变", "Remove this member, return equipment to inventory and leave Coin unchanged") footer.add_child(confirm) confirm.call_deferred("grab_focus") @@ -1028,16 +1036,23 @@ func open_contract_return_review() -> void: notice.name = "ContractReturnNotice" notice.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART facts.add_child(notice) + for fact_node in facts.get_children(): + if fact_node is Label: + fact_node.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + fact_node.size_flags_horizontal = Control.SIZE_EXPAND_FILL var footer := HBoxContainer.new() footer.name = "ContractReturnReviewFooter" footer.custom_minimum_size = Vector2(0, 46 if size.y < 500.0 else 52) footer.add_theme_constant_override("separation", 8) layout.add_child(footer) - footer.add_child(_company_button("ContractReturnCancel", _tr("取消", "Cancel"), cancel_contract_return, "company_utility", "back")) + var cancel := _company_button("ContractReturnCancel", _tr("取消", "Cancel"), cancel_contract_return, "company_utility", "back") + cancel.custom_minimum_size = Vector2(170 if size.y < 500.0 else 190, footer.custom_minimum_size.y) + footer.add_child(cancel) var spacer := Control.new() spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL footer.add_child(spacer) var confirm := _company_button("ContractReturnConfirm", _tr("确认返回公会", "Confirm Return to Guild"), commit_contract_return, "company_primary", "confirm") + confirm.custom_minimum_size = Vector2(170 if size.y < 500.0 else 190, footer.custom_minimum_size.y) confirm.tooltip_text = _tr("保留全部 Company 成长并返回公会", "Retain all Company growth and return to Guild") footer.add_child(confirm) confirm.call_deferred("grab_focus") diff --git a/runtime/tests/dev6/second_cycle_capture_test.gd b/runtime/tests/dev6/second_cycle_capture_test.gd new file mode 100644 index 00000000..2bba99fe --- /dev/null +++ b/runtime/tests/dev6/second_cycle_capture_test.gd @@ -0,0 +1,178 @@ +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 FIXTURES := [ + {"width": 760, "height": 360, "locale": "zh_CN", "scale": 1.0}, + {"width": 844, "height": 390, "locale": "en", "scale": 1.3}, + {"width": 1280, "height": 720, "locale": "zh_CN", "scale": 1.0}, + {"width": 1280, "height": 720, "locale": "en", "scale": 1.3}, +] +const STATES := ["market_ready", "equipment_review", "equipment_equipped", "roster", "recruit_detail", "contract_return_review"] +const SEED := "1234567890abcdeffedcba0987654321" +const CONTRACT_OP := "abcdefabcdefabcdefabcdefabcdefab" +const HIRE_OP_1 := "11112222333344445555666677778888" +const HIRE_OP_2 := "88887777666655554444333322221111" + +var output_root := "" +var failures: Array[String] = [] +var fixture_index := 0 +var viewport_size := Vector2i(844, 390) +var locale := "en" +var text_scale := 1.0 + + +func _initialize() -> void: + call_deferred("run_capture") + + +func run_capture() -> void: + var requested := OS.get_environment("ABG_CAPTURE_FIXTURE_INDEX") + fixture_index = requested.to_int() if not requested.is_empty() else -1 + var indexes := range(FIXTURES.size()) if fixture_index < 0 else [fixture_index] + output_root = OS.get_environment("ABG_EVIDENCE_DIR") + if output_root.is_empty(): + output_root = "/tmp/abg-dev6-candidate" + output_root = output_root.path_join("captures") + DirAccess.make_dir_recursive_absolute(output_root) + for index in indexes: + if index < 0 or index >= FIXTURES.size(): + failures.append("unknown fixture index %d" % index) + continue + var fixture: Dictionary = FIXTURES[index] + viewport_size = Vector2i(int(fixture.width), int(fixture.height)) + locale = String(fixture.locale) + text_scale = float(fixture.scale) + for state in STATES: + await _capture_state(index, String(state), fixture) + if failures.is_empty(): + print("ABG_DEV6_CAPTURE_OK frames=%d states=market_ready,equipment_review,equipment_equipped,roster,recruit_detail,contract_return_review matrix=760x360,844x390,1280x720:zh_CN,en:100,130 layout=inside renderer=normal" % [indexes.size() * STATES.size()]) + quit(0) + else: + for failure in failures: + push_error(failure) + quit(1) + + +func _capture_state(index: int, state: String, fixture: Dictionary) -> void: + var draft_path := "user://dev6_capture_%d_%s.json" % [index, state] + var company_path := "%s.company" % draft_path + _cleanup_path(draft_path) + var company := _create_company(draft_path, company_path) + if company.is_empty(): + failures.append("%s fixture could not create Company" % state) + return + var viewport := SubViewport.new() + viewport.size = viewport_size + viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS + root.add_child(viewport) + var shell := EntryShell.new() + shell.auto_start = false + shell.initial_company_service.path = draft_path + shell.initial_company_service.company_path = company_path + viewport.add_child(shell) + await _frames(3) + var settings := SettingsStore.new().defaults() + settings.setup_completed = true + settings.locale = locale + settings.text_scale = text_scale + shell.settings = settings + shell.setup_draft = settings.duplicate(true) + var equipment_offer := _cheapest_affordable_equipment(company) + var shown_company := company + match state: + "market_ready": shell.show_market(company) + "equipment_review": + shell.market_category = "equipment" + shell.market_selected_kind = "equipment" + shell.market_selected_offer_id = String(equipment_offer.offer_id) + shell.show_equipment_review(String(equipment_offer.offer_id)) + "equipment_equipped": + var service := _contract_service(company_path) + var operation_id := ("%s|capture-equip|%s|%s" % [String(company.company_id), String(equipment_offer.offer_id), String(company.owned_recruits[0].recruit_id)]).sha256_text().substr(0, 32) + var purchased: Dictionary = service.purchase_equipment(operation_id, String(equipment_offer.offer_id), String(company.owned_recruits[0].recruit_id), int(equipment_offer.list_price)) + if not purchased.ok: + failures.append("equipment capture purchase failed: %s" % String(purchased.get("code", "unknown"))) + else: + shown_company = purchased.company + shell.show_market(shown_company) + "roster": shell.show_roster(company) + "recruit_detail": shell.show_recruit_detail(String(company.owned_recruits[0].recruit_id)) + "contract_return_review": + shell.show_market(company) + await _frames(2) + shell.open_contract_return_review() + await _frames(6) + _verify_buttons(shell, state) + await RenderingServer.frame_post_draw + var image := viewport.get_texture().get_image() + if image.is_empty() or image.get_width() != viewport_size.x or image.get_height() != viewport_size.y: + failures.append("%s returns a complete %dx%d frame" % [state, viewport_size.x, viewport_size.y]) + else: + var path := output_root.path_join("fixture%d-%s.png" % [index, state]) + if image.save_png(path) != OK: + failures.append("capture failed: %s" % path) + shell.queue_free() + viewport.queue_free() + await _frames(5) + _cleanup_path(draft_path) + + +func _verify_buttons(node: Node, state: String) -> void: + for child in node.get_children(): + if child is BaseButton and child.is_visible_in_tree(): + var rect: Rect2 = child.get_global_rect() + if rect.position.x < -0.5 or rect.position.y < -0.5 or rect.end.x > viewport_size.x + 0.5 or rect.end.y > viewport_size.y + 0.5: + failures.append("%s button %s outside viewport: %s" % [state, child.name, rect]) + if rect.size.x < 44.0 or rect.size.y < 44.0: + failures.append("%s button %s below 44px: %s" % [state, child.name, rect.size]) + _verify_buttons(child, state) + + +func _create_company(draft_path: String, company_path: String) -> Dictionary: + var draft_service := DraftService.new() + draft_service.path = draft_path + draft_service.company_path = company_path + 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)]) + var committed: Dictionary = draft_service.commit_company() + if not committed.ok: + return {} + var contract := _contract_service(company_path) + var created: Dictionary = contract.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.hire_recruit(HIRE_OP_1, String(offers[0].source_offer_id), 14) + var hired: Dictionary = contract.hire_recruit(HIRE_OP_2, String(offers[1].source_offer_id), 14) + return hired.company if hired.ok else {} + + +func _cheapest_affordable_equipment(company: Dictionary) -> Dictionary: + var chosen: Dictionary = {} + for offer in company.active_contract.market_board.equipment_offers: + if int(offer.list_price) <= int(company.active_contract.coin) and (chosen.is_empty() or int(offer.list_price) < int(chosen.list_price)): + chosen = Dictionary(offer).duplicate(true) + return chosen + + +func _contract_service(path: String) -> RefCounted: + var service := ContractService.new() + service.company_path = path + return service + + +func _cleanup_path(path: String) -> void: + for candidate in [path, "%s.bak" % path, "%s.candidate" % path, "%s.bak.candidate" % path, "%s.company" % path, "%s.company.bak" % path, "%s.company.candidate" % path, "%s.company.bak.candidate" % path, "%s.corrupt" % path]: + if FileAccess.file_exists(candidate): + DirAccess.remove_absolute(candidate) + + +func _frames(count: int) -> void: + for _index in range(count): + await process_frame diff --git a/tools/run_dev6_candidate_suite.sh b/tools/run_dev6_candidate_suite.sh new file mode 100644 index 00000000..40c20e31 --- /dev/null +++ b/tools/run_dev6_candidate_suite.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT=$(cd "$(dirname "$0")/.." && pwd) +EVIDENCE=${ABG_EVIDENCE_DIR:?ABG_EVIDENCE_DIR is required} +SOURCE_REVISION=${ABG_SOURCE_REVISION:?ABG_SOURCE_REVISION is required} +GODOT=${GODOT_BIN:-/Applications/Godot.app/Contents/MacOS/Godot} + +if [[ ! "$SOURCE_REVISION" =~ ^[0-9a-f]{40}$ ]]; then + echo "DEV-6 candidate requires a source-bound 40-character revision" >&2 + exit 85 +fi + +mkdir -p "$EVIDENCE/logs/headless" "$EVIDENCE/logs/normal" "$EVIDENCE/captures" + +strict_scan() { + local log=$1 + if grep -En 'SCRIPT ERROR:|Parse Error:|ERROR:|ObjectDB instances leaked|resources still in use at exit|RID allocations of type|RID of type' "$log"; then + echo "strict diagnostics in $log" >&2 + return 86 + fi +} + +require_marker() { + local log=$1 + local marker=$2 + local count + count=$(grep -Ec "^${marker}( |$)" "$log" || true) + if [ "$count" -ne 1 ]; then + echo "marker $marker count=$count in $log" >&2 + return 87 + fi +} + +run_godot() { + local mode=$1 + local folder=$2 + local script=$3 + local markers=$4 + local suffix="" + if [ -n "${ABG_CAPTURE_FIXTURE_INDEX:-}" ]; then + suffix="_fixture_${ABG_CAPTURE_FIXTURE_INDEX}" + fi + local log="$EVIDENCE/logs/$mode/${folder}_${script%.gd}${suffix}.log" + if [ "$mode" = headless ]; then + "$GODOT" --headless --audio-driver Dummy --path "$ROOT/runtime" --script "res://tests/$folder/$script" >"$log" 2>&1 + else + ABG_EVIDENCE_DIR="$EVIDENCE" \ + ABG_CAPTURE_FIXTURE_INDEX="$ABG_CAPTURE_FIXTURE_INDEX" \ + "$GODOT" --audio-driver Dummy --fixed-fps 60 --disable-vsync --path "$ROOT/runtime" --script "res://tests/$folder/$script" >"$log" 2>&1 + fi + strict_scan "$log" + IFS=',' read -r -a expected_markers <<< "$markers" + for marker in "${expected_markers[@]}"; do + require_marker "$log" "$marker" + done + tail -n 1 "$log" +} + +import_log="$EVIDENCE/logs/import.log" +"$GODOT" --headless --editor --audio-driver Dummy --path "$ROOT/runtime" --import >"$import_log" 2>&1 +strict_scan "$import_log" + +while IFS='|' read -r folder script markers; do + [ -n "$folder" ] || continue + run_godot headless "$folder" "$script" "$markers" +done <<'TESTS' +dev1|boot_service_test.gd|ABG_DEV1_BOOT_OK +dev1|boot_runtime_test.gd|ABG_DEV1_BOOT_RUNTIME_OK +dev1|first_launch_test.gd|ABG_DEV1_FIRST_LAUNCH_OK +dev1|title_state_test.gd|ABG_DEV1_TITLE_OK +dev1|settings_credits_test.gd|ABG_DEV1_SETTINGS_OK +dev1|entry_flow_touch_test.gd|ABG_DEV1_ENTRY_TOUCH_OK +dev2|initial_company_draft_test.gd|ABG_DEV2_DRAFT_OK +dev2|initial_company_choice_test.gd|ABG_DEV2_CHOICE_OK +dev2|initial_company_touch_test.gd|ABG_DEV2_CHOICE_TOUCH_OK +dev2|initial_company_commit_test.gd|ABG_DEV2_COMMIT_OK +dev2|initial_company_commit_touch_test.gd|ABG_DEV2_COMMIT_TOUCH_OK +dev2|initial_company_full_flow_touch_test.gd|ABG_DEV2_FULL_FLOW_TOUCH_OK +dev3|contract_foundation_test.gd|ABG_DEV3_CONTRACT_OK +dev3|guild_contract_choice_test.gd|ABG_DEV3_GUILD_OK +dev3|market_recruit_review_test.gd|ABG_DEV3_MARKET_OK +dev3|hire_transaction_test.gd|ABG_DEV3_HIRE_OK +dev4|formation_risk_foundation_test.gd|ABG_DEV4_FOUNDATION_OK +dev4|party_line_test.gd|ABG_DEV4_PARTY_OK +dev4|readiness_review_test.gd|ABG_DEV4_READY_OK +dev5|battle_foundation_test.gd|ABG_DEV5_BATTLE_OK +dev5|battle_runtime_test.gd|ABG_DEV5_BATTLE_UI_OK +dev5|battle_result_test.gd|ABG_DEV5_RESULT_OK,ABG_DEV5_RECOVERY_OK +dev6|equipment_growth_test.gd|ABG_DEV6_GROWTH_OK +dev6|roster_detail_test.gd|ABG_DEV6_ROSTER_OK +dev6|contract_return_test.gd|ABG_DEV6_RETURN_OK +TESTS + +for fixture_index in 0 1 2 3; do + ABG_CAPTURE_FIXTURE_INDEX=$fixture_index run_godot normal dev6 second_cycle_capture_test.gd ABG_DEV6_CAPTURE_OK +done + +capture_count=$(find "$EVIDENCE/captures" -type f -name '*.png' | wc -l | tr -d ' ') +if [ "$capture_count" -ne 24 ]; then + echo "capture count=$capture_count; expected 24" >&2 + exit 89 +fi + +printf 'ABG_DEV6_CANDIDATE_SUITE_OK source=%s dev1=6 dev2=6 dev3=4 dev4=3 dev5=4 dev6=3 normal_processes=4 captures=%s strict=0 parsed_touch=true no_new_battle=true growth_preserved=true\n' \ + "$SOURCE_REVISION" "$capture_count"