From d51656c9e43277318acc01f442224834bb91b0e0 Mon Sep 17 00:00:00 2001 From: veg Date: Mon, 21 Sep 2026 09:46:05 +0000 Subject: [PATCH] refactor: drop dead weight (unused param, duplicate checks, dead code) - tmux_party_setup_server took an unused name parameter; drop it. - validate_party_name ran two separate case blocks with a length check between them; merge into one case now that the length check (which an empty name always passes) runs first. - roster_read now applies the RR_GROUP fallback to TMUX_PARTY_GROUP once, so cmd_join, cmd_invite, and cmd_list no longer each repeat ${RR_GROUP:-$TMUX_PARTY_GROUP}. - socket_path had no caller in party; remove it and its test. --- party | 45 ++++++++++++++++++++++---------------------- tests/30-roster.bats | 5 ----- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/party b/party index 3d14d21..8ecaa03 100755 --- a/party +++ b/party @@ -103,16 +103,18 @@ EOF # name as a flag, so such a party could never be addressed. validate_party_name() { name="$1" - case "$name" in - '' ) echo "party: name must not be empty" >&2; return 2 ;; - esac # Length cap: 63 keeps the full socket path comfortably below the - # 108-char sun_path limit for typical USERs. + # 108-char sun_path limit for typical USERs. Runs before the empty/ + # shape checks below; an empty name has length 0, so it always + # passes this check and falls through to the '' case there. if [ "${#name}" -gt 63 ]; then echo "party: name '$name' too long (max 63 chars)" >&2 return 2 fi case "$name" in + '' ) + echo "party: name must not be empty" >&2 + return 2 ;; -* ) echo "party: name must not start with '-'" >&2 return 2 ;; @@ -200,10 +202,6 @@ roster_record_path() { printf '%s/roster\n' "$(party_dir_path "$1" "$2")" } -socket_path() { - printf '%s/sock\n' "$(party_dir_path "$1" "$2")" -} - # Roster I/O # ---------- # @@ -326,6 +324,10 @@ roster_read() { '' | \#*) ;; esac done < "$rec" + # A roster written before --group existed (or otherwise missing + # GROUP=) gates on the default group; callers can rely on RR_GROUP + # always naming the party's actual perimeter. + [ -n "$RR_GROUP" ] || RR_GROUP=$TMUX_PARTY_GROUP return 0 } @@ -565,7 +567,7 @@ party_self_path() { # All commands run against -S "$sock". Every literal name embedded # is shell-quoted to survive tmux's parser. tmux_party_setup_server() { - sock="$1" name="$2" + sock="$1" # Write a tiny notification helper next to the socket. The leading dot # keeps it out of typical `ls` listings. The per-party private dir @@ -872,7 +874,7 @@ EOF # apply_party_perms_file widens it AFTER server-access -aw runs. "$PARTY_TMUX" -S "$sock" new-session -d -s "$name" - tmux_party_setup_server "$sock" "$name" + tmux_party_setup_server "$sock" # Auth gate FIRST, server-access runs BEFORE we widen FS perms. # This closes the connect-before-allowlist race: without this order, @@ -1192,7 +1194,7 @@ EOF # segments. : >> "$logfile" chmod 0640 "$logfile" - chgrp "${RR_GROUP:-$TMUX_PARTY_GROUP}" "$logfile" + chgrp "$RR_GROUP" "$logfile" # Filter to unpiped panes ourselves rather than trusting `-o` to # skip them: on tmux 3.5a, `-o` toggles an existing pipe closed @@ -1253,10 +1255,9 @@ EOF # FS perimeter on the per-party dir already blocks non-group readers # at roster_list; this preflight just turns that into a friendlier # error than "party not found" when membership is the actual cause. - party_group="${RR_GROUP:-$TMUX_PARTY_GROUP}" - if ! user_in_group "$USER" "$party_group"; then + if ! user_in_group "$USER" "$RR_GROUP"; then cat >&2 <&2 </dev/null | wc -l | tr -d ' ') line=$(printf '%-12s %-30s %s attendee(s)%s' \ diff --git a/tests/30-roster.bats b/tests/30-roster.bats index 9aa94a1..dc19fa1 100644 --- a/tests/30-roster.bats +++ b/tests/30-roster.bats @@ -17,11 +17,6 @@ setup() { [ "$out" = "$PARTY_SOCKET_DIR/party-veg:debug-the-deploy.d" ] } -@test "socket_path lives inside the per-party private dir" { - out=$(socket_path "veg" "debug-the-deploy") - [ "$out" = "$PARTY_SOCKET_DIR/party-veg:debug-the-deploy.d/sock" ] -} - @test "roster_write then roster_read round-trips all fields" { ensure_party_dir "$USER" "rt-test" rec=$(roster_record_path "$USER" "rt-test")