diff --git a/party b/party index a464a01..a21c1fd 100755 --- a/party +++ b/party @@ -387,6 +387,15 @@ apply_party_perms_file() { # directory. validate_socket_dir_parent() { p="$PARTY_SOCKET_DIR" + # Whitespace in the parent breaks every `for rec in $(roster_list)` + # walker and the unquoted paths embedded in tmux hook/status-right + # strings. Refuse at host time, where the dir is chosen, instead of + # corrupting quietly later. + case "$p" in + *[[:space:]]*) + echo "party: PARTY_SOCKET_DIR must not contain whitespace: $p" >&2 + return 1 ;; + esac if [ ! -d "$p" ]; then echo "party: PARTY_SOCKET_DIR $p does not exist" >&2 return 1 @@ -530,6 +539,12 @@ pick_live_party() { 0) echo "party: no parties found on this host." >&2; return 1 ;; 1) roster_read "$1"; return 0 ;; esac + # 2+ parties need the interactive picker; without a tty read would + # EOF and set -e would kill us with no message. + if [ ! -t 0 ]; then + echo "party: multiple parties running; pass a name (see 'party list')." >&2 + return 1 + fi i=0 for r in "$@"; do i=$((i+1)) diff --git a/tests/20-helpers.bats b/tests/20-helpers.bats index 805c7be..8f37501 100644 --- a/tests/20-helpers.bats +++ b/tests/20-helpers.bats @@ -109,3 +109,30 @@ setup() { # to also confirm a foreign-uid PID is not preventing the result. ! is_party_alive 1 "$PARTY_TMP/no-such-sock" } + +@test "validate_socket_dir_parent refuses whitespace in PARTY_SOCKET_DIR" { + spaced="$PARTY_TMP/with space" + mkdir -p "$spaced" + chmod 0700 "$spaced" + PARTY_SOCKET_DIR="$spaced" run validate_socket_dir_parent + [ "$status" -ne 0 ] + [[ "$output" == *"whitespace"* ]] +} + +@test "pick_live_party without a tty fails with guidance, not a silent death" { + # Two live-looking parties force the numbered picker; stdin is not a + # tty under bats, so the guard must fire before read. + stub="$PARTY_TMP/tmux-ok" + printf '#!/bin/sh\nexit 0\n' > "$stub" + chmod +x "$stub" + export PARTY_TMUX="$stub" + ensure_party_dir "$USER" one + ensure_party_dir "$USER" two + for n in one two; do + d="$PARTY_SOCKET_DIR/party-$USER:$n.d" + printf 'SERVER_PID=1\nGROUP=%s\n' "$(id -gn)" > "$d/roster" + done + run pick_live_party + [ "$status" -ne 0 ] + [[ "$output" == *"pass a name"* ]] +}