From e03b7de959844432ee27bbfab7fc2c46bdd3dee5 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Sun, 12 Apr 2026 19:25:25 +0800 Subject: [PATCH] Preserve full command in mcc-cmd and broaden tests --- tools/mcc-env.sh | 11 ++++++++--- tools/test-mcc-env.sh | 21 ++++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tools/mcc-env.sh b/tools/mcc-env.sh index 28378c9a..eb735894 100644 --- a/tools/mcc-env.sh +++ b/tools/mcc-env.sh @@ -158,7 +158,7 @@ mcc-run() { } mcc-cmd() { local session="" - local command="" + local -a command_parts=() while [[ $# -gt 0 ]]; do case "$1" in --session) @@ -171,17 +171,22 @@ mcc-cmd() { shift ;; *) - command="$1" + command_parts+=("$1") shift ;; esac done - [[ -n "$command" ]] || { echo "Usage: mcc-cmd [--session NAME] " >&2; return 1; } + if [[ ${#command_parts[@]} -eq 0 ]]; then + echo "Usage: mcc-cmd [--session NAME] " >&2 + return 1 + fi session="$(_mcc_resolve_session "$session")" local input_file input_file="$(_mcc_session_input_file "$session")" mkdir -p "$(dirname "$input_file")" + local command + command="${command_parts[*]}" printf '%s\n' "$command" >> "$input_file" } mcc-kill() { pkill -f "MinecraftClient" 2>/dev/null && echo "MCC killed" || echo "No MCC process found"; tmux kill-session -t mcc-debug 2>/dev/null || true; } diff --git a/tools/test-mcc-env.sh b/tools/test-mcc-env.sh index e54ade93..b0bfb18b 100755 --- a/tools/test-mcc-env.sh +++ b/tools/test-mcc-env.sh @@ -80,16 +80,23 @@ input_file="$(_mcc_session_input_file "$session")" rm -rf "$(_mcc_session_root "$session")" mcc-cmd --session "$session" "debug state" -grep -Fq "debug state" "$input_file" +input_contents="$(cat "$input_file")" +assert_eq "debug state" "$input_contents" "session input command is intact" mcc-reset-session --session "$session" [[ ! -e "$(_mcc_session_root "$session")" ]] malformed_log="${TMPDIR:-/tmp}/mcc-env-session-hang-test.log" -if mcc-cmd --session >"$malformed_log" 2>&1; then - echo "FAIL: --session accepted without value" >&2 - cat "$malformed_log" >&2 - exit 1 -fi -grep -Fq -- "--session requires a value" "$malformed_log" +for func in mcc-cmd mcc-reset-session mcc-state mcc-log-mcc; do + set +e + "$func" --session >"$malformed_log" 2>&1 + status=$? + set -e + if [[ $status -eq 0 ]]; then + echo "FAIL: $func accepted --session without a value" >&2 + cat "$malformed_log" >&2 + exit 1 + fi + grep -Fq -- "--session requires a value" "$malformed_log" +done echo "PASS"