#!/bin/bash set -euo pipefail repo_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)" helper="$repo_dir/config/dot/quickshell/scripts/panama-osd" scratch="$(mktemp -d)" trap 'rm -rf "$scratch"' EXIT mkdir -p "$scratch/bin" log="$scratch/calls" cat >"$scratch/bin/wpctl" <<'SH' #!/bin/bash printf 'wpctl' >>"$OSD_TEST_LOG" printf ' <%s>' "$@" >>"$OSD_TEST_LOG" printf '\n' >>"$OSD_TEST_LOG" if [[ $1 == "get-volume" ]]; then printf '%s\n' "${WPCTL_OUTPUT:-Volume: 0.58}" fi SH cat >"$scratch/bin/brightnessctl" <<'SH' #!/bin/bash printf 'brightnessctl' >>"$OSD_TEST_LOG" printf ' <%s>' "$@" >>"$OSD_TEST_LOG" printf '\n' >>"$OSD_TEST_LOG" if [[ " $* " == *" -m "* && " $* " != *" set "* ]]; then printf '%s\n' "${BRIGHTNESS_OUTPUT:-intel_backlight,backlight,500,1000,50%}" fi SH cat >"$scratch/bin/playerctl" <<'SH' #!/bin/bash printf 'playerctl' >>"$OSD_TEST_LOG" printf ' <%s>' "$@" >>"$OSD_TEST_LOG" printf '\n' >>"$OSD_TEST_LOG" if [[ $1 == "metadata" ]]; then printf '%s\n' "${PLAYER_OUTPUT:-Horizon — Tycho}" elif [[ $1 == "status" ]]; then printf '%s\n' "${PLAYER_STATUS:-Playing}" fi SH cat >"$scratch/bin/qs" <<'SH' #!/bin/bash printf 'qs' >>"$OSD_TEST_LOG" printf ' <%s>' "$@" >>"$OSD_TEST_LOG" printf '\n' >>"$OSD_TEST_LOG" SH chmod +x "$scratch/bin/"* run_helper() { PATH="$scratch/bin:$PATH" OSD_TEST_LOG="$log" "$helper" "$@" } assert_line() { local expected="$1" grep -Fqx -- "$expected" "$log" || { printf 'osd helper contract: missing call\n%s\nactual:\n' "$expected" >&2 cat "$log" >&2 exit 1 } } : >"$log" run_helper volume up 6 assert_line 'wpctl <-l> <1> <@DEFAULT_AUDIO_SINK@> <6%+>' assert_line 'wpctl <@DEFAULT_AUDIO_SINK@>' assert_line 'qs <58> <100> <58%>' : >"$log" WPCTL_OUTPUT='Volume: 0.58 [MUTED]' run_helper volume toggle assert_line 'wpctl <@DEFAULT_AUDIO_SINK@> ' assert_line 'qs <58> <100> ' : >"$log" WPCTL_OUTPUT='Volume: 0.72 [MUTED]' run_helper microphone toggle assert_line 'wpctl <@DEFAULT_AUDIO_SOURCE@> ' assert_line 'qs <72> <100> ' : >"$log" run_helper brightness up 5 assert_line 'brightnessctl <-e4> <-n2> <5%+>' assert_line 'brightnessctl <-m> <-c> ' assert_line 'qs <50> <100> <50%>' : >"$log" run_helper media next assert_line 'playerctl ' assert_line 'qs ' : >"$log" run_helper message notifications-disabled-symbolic 'Do Not Disturb On' assert_line 'qs ' printf 'osd helper contract: PASS\n'