From 9b85485ee8a6f9572b374103467bcccc7394f27e Mon Sep 17 00:00:00 2001 From: veg Date: Mon, 21 Sep 2026 09:32:48 +0000 Subject: [PATCH] fix: party list tags the group only when parties differ on it The tag was shown whenever a party's group differed from TMUX_PARTY_GROUP, which falls back to 'party' when unset. Since host time auto-selects the group, a box gating on 'staff' tagged every line. Compare the visible parties with each other instead. --- party | 29 ++++++++++++++++++----------- tests/95-stub-roundtrip.bats | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/party b/party index ac4a445..9bb95b3 100755 --- a/party +++ b/party @@ -1520,7 +1520,7 @@ cmd_detach() { } cmd_list() { - found=0 + found=0 lines='' first_group='' mixed=0 for rec in $(roster_list); do roster_read "$rec" || continue state=$(party_conn_state "$RR_SOCKET") @@ -1535,29 +1535,36 @@ cmd_list() { # the FS perimeter alone. list_group="${RR_GROUP:-$TMUX_PARTY_GROUP}" id -nG "$USER" 2>/dev/null | tr ' ' '\n' | grep -qx "$list_group" || continue - # Show the group only when it differs from the env/default, to - # keep the common case uncluttered. - group_tag= - if [ -n "$RR_GROUP" ] && [ "$RR_GROUP" != "$TMUX_PARTY_GROUP" ]; then - group_tag=" [group=$RR_GROUP]" - fi + # The group tag only earns its column when the visible parties + # disagree on it. Which group gates a party is decided per host + # (auto-selection), so there is no default to compare against: + # tag every line, then strip the tags below unless they differ. + [ -n "$first_group" ] || first_group="$list_group" + [ "$list_group" = "$first_group" ] || mixed=1 + group_tag=" [group=$list_group]" if [ "$state" = ok ]; then attendees=$("$PARTY_TMUX" -S "$RR_SOCKET" list-clients 2>/dev/null | wc -l | tr -d ' ') - printf '%-12s %-30s %s attendee(s)%s\n' \ - "$RR_HOST_USER" "$RR_PARTY_NAME" "$attendees" "$group_tag" + line=$(printf '%-12s %-30s %s attendee(s)%s' \ + "$RR_HOST_USER" "$RR_PARTY_NAME" "$attendees" "$group_tag") else # Live server, connection refused: we can't count attendees # (list-clients is behind the auth gate: its empty stdout # used to render here as a bogus "0 attendee(s)"), but the # party is real and the caller can ask for an invite. - printf '%-12s %-30s invite-only (ask %s)%s\n' \ - "$RR_HOST_USER" "$RR_PARTY_NAME" "$RR_HOST_USER" "$group_tag" + line=$(printf '%-12s %-30s invite-only (ask %s)%s' \ + "$RR_HOST_USER" "$RR_PARTY_NAME" "$RR_HOST_USER" "$group_tag") fi + lines="$lines$line +" found=$((found+1)) done if [ "$found" -eq 0 ]; then echo "no parties found on this host." + elif [ "$mixed" = 1 ]; then + printf '%s' "$lines" + else + printf '%s' "$lines" | sed 's/ \[group=[^]]*\]$//' fi } diff --git a/tests/95-stub-roundtrip.bats b/tests/95-stub-roundtrip.bats index 693158f..adc292f 100644 --- a/tests/95-stub-roundtrip.bats +++ b/tests/95-stub-roundtrip.bats @@ -855,3 +855,20 @@ STUB run "$PARTY_BIN" detach nobody --party alpha [ "$status" -eq 0 ] } + +@test "list shows the group tag only when visible parties differ on it" { + "$PARTY_BIN" host solo + run "$PARTY_BIN" list + [ "$status" -eq 0 ] + [[ "$output" == *"solo"* ]] + [[ "$output" != *"[group="* ]] + + # A second party gated on another of the caller's groups. + other=$(id -nG | tr ' ' '\n' | grep -vx "$TMUX_PARTY_GROUP" | head -1) + [ -n "$other" ] || skip "caller is in a single group" + "$PARTY_BIN" host duo --group "$other" + run "$PARTY_BIN" list + [ "$status" -eq 0 ] + [[ "$output" == *"solo"*"[group=$TMUX_PARTY_GROUP]"* ]] + [[ "$output" == *"duo"*"[group=$other]"* ]] +}