#!/usr/bin/env bash # Public entry for the first playable client gate. It delegates process # ownership and post-exit validation to run_client_gate.sh. set -euo pipefail cd "$(dirname "$0")/.." app="${MT_PLAYABLE_APP:-$PWD/build/export-native-trees-20260911/mtgodot-poc.app}" config="" output="" mode="playable" timeout="180" allow=0 repeat=1 suite="full" usage() { cat <<'EOF' 用法: script/playable_test.sh --config CONFIG [选项] --app APP 导出包路径 --output DIR 单次运行输出目录(repeat=1) --suite full 当前固定为 full/playable --allow-gameplay 允许发送游戏状态变更请求 --repeat N 独立进程运行次数,默认 1 --timeout-seconds N 每次墙钟超时,默认 180 EOF } while [ "$#" -gt 0 ]; do case "$1" in --app) app="$2"; shift 2 ;; --config) config="$2"; shift 2 ;; --output) output="$2"; shift 2 ;; --suite) suite="$2"; shift 2 ;; --allow-gameplay) allow=1; shift ;; --repeat) repeat="$2"; shift 2 ;; --timeout-seconds) timeout="$2"; shift 2 ;; --help) usage; exit 0 ;; *) echo "未知选项: $1" >&2; usage >&2; exit 2 ;; esac done if [ -z "$config" ] || [ ! -f "$config" ]; then echo "需要 --config CONFIG" >&2; exit 2; fi if [ "$suite" != "full" ] && [ "$suite" != "playable" ]; then echo "--suite 只支持 full/playable" >&2; exit 2; fi if ! [[ "$repeat" =~ ^[1-9][0-9]*$ ]]; then echo "--repeat 必须是正整数" >&2; exit 2; fi if [ "$repeat" -gt 1 ] && [ -n "$output" ]; then echo "repeat>1 时不能指定单一 --output" >&2; exit 2; fi root="$output" if [ -z "$root" ]; then root="${MT_PLAYABLE_OUTPUT:-$PWD/build/playable/suite-$(date +%Y%m%d-%H%M%S)-$$}"; fi mkdir -p "$root" failed=0 for index in $(seq 1 "$repeat"); do run_dir="$root" if [ "$repeat" -gt 1 ]; then run_dir="$root/run-$index"; fi args=(--app "$app" --config "$config" --output "$run_dir" --mode "$mode" --timeout-seconds "$timeout") if [ "$allow" -eq 1 ]; then args+=(--allow-gameplay); fi if ! bash script/run_client_gate.sh "${args[@]}"; then failed=$((failed + 1)); fi done if [ "$failed" -ne 0 ]; then echo "PLAYABLE SUITE: FAIL runs=$failed/$repeat" >&2; exit 1; fi echo "PLAYABLE SUITE: PASS runs=$repeat root=$root"