#!/usr/bin/env bats

load 'helpers'

setup() {
  setup_party_sandbox
  load_party_lib
}

@test "apply_party_perms_file sets mode g+rw on a regular file" {
  require_party_group
  f="$PARTY_TMP/f"
  : > "$f"
  apply_party_perms_file "$f"
  m=$(stat -c '%a' "$f" 2>/dev/null || stat -f '%Lp' "$f")
  case "$m" in
    *6[0-9])  ;;   # group has rw
    *) echo "mode=$m"; false ;;
  esac
  g=$(stat -c '%G' "$f" 2>/dev/null || stat -f '%Sg' "$f")
  [ "$g" = "$TMUX_PARTY_GROUP" ]
}

@test "validate_socket_dir_parent accepts an owner-only-writable parent" {
  # PARTY_SOCKET_DIR is the per-party dir's parent. Created at mode 0700
  # by setup_party_sandbox (owner-only, neither group- nor world-writable),
  # which validate_socket_dir_parent should accept without complaint.
  validate_socket_dir_parent
}
