Harden Panama launcher actions
This commit is contained in:
@@ -47,12 +47,16 @@ cat >"$scratch/bin/qs" <<'SH'
|
||||
printf 'qs' >>"$OSD_TEST_LOG"
|
||||
printf ' <%s>' "$@" >>"$OSD_TEST_LOG"
|
||||
printf '\n' >>"$OSD_TEST_LOG"
|
||||
[[ ${OSD_TEST_FAIL_QS:-false} != true ]]
|
||||
SH
|
||||
|
||||
chmod +x "$scratch/bin/"*
|
||||
|
||||
run_helper() {
|
||||
PATH="$scratch/bin:$PATH" OSD_TEST_LOG="$log" "$helper" "$@"
|
||||
PATH="$scratch/bin:$PATH" OSD_TEST_LOG="$log" \
|
||||
OSD_TEST_FAIL_QS="${OSD_TEST_FAIL_QS:-false}" \
|
||||
PANAMA_OSD_STRICT="${PANAMA_OSD_STRICT:-false}" \
|
||||
"$helper" "$@"
|
||||
}
|
||||
|
||||
assert_line() {
|
||||
@@ -95,4 +99,13 @@ assert_line 'qs <ipc> <call> <osd> <message> <media-next> <Horizon — Tycho>'
|
||||
run_helper message notifications-disabled-symbolic 'Do Not Disturb On'
|
||||
assert_line 'qs <ipc> <call> <osd> <message> <notifications-disabled-symbolic> <Do Not Disturb On>'
|
||||
|
||||
: >"$log"
|
||||
if OSD_TEST_FAIL_QS=true PANAMA_OSD_STRICT=1 run_helper message dialog-error-symbolic 'Strict failure'; then
|
||||
printf 'osd helper contract: strict delivery swallowed an IPC failure\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
: >"$log"
|
||||
OSD_TEST_FAIL_QS=true run_helper message dialog-information-symbolic 'Best effort'
|
||||
|
||||
printf 'osd helper contract: PASS\n'
|
||||
|
||||
@@ -37,7 +37,13 @@ case "$*" in
|
||||
'ipc call notifications dnd'|'ipc call caffeine toggle'|'ipc call night-light toggle')
|
||||
printf '%s\n' "${PANAMA_ACTION_TEST_STATE:-true}"
|
||||
;;
|
||||
'ipc call focus start'|'ipc call focus end')
|
||||
printf '%s\n' "${PANAMA_ACTION_TEST_FOCUS_STATE:-true}"
|
||||
;;
|
||||
esac
|
||||
if [[ ${PANAMA_ACTION_TEST_FAIL_KILL:-false} == true && ${1:-} == kill ]]; then
|
||||
exit 1
|
||||
fi
|
||||
[[ ${PANAMA_ACTION_TEST_FAIL_QS:-false} != true ]]
|
||||
EOF
|
||||
|
||||
@@ -53,6 +59,7 @@ make_recorder panama-osd <<'EOF'
|
||||
printf 'panama-osd' >>"$PANAMA_ACTION_TEST_LOG"
|
||||
printf ' <%s>' "$@" >>"$PANAMA_ACTION_TEST_LOG"
|
||||
printf '\n' >>"$PANAMA_ACTION_TEST_LOG"
|
||||
[[ ${PANAMA_ACTION_TEST_FAIL_OSD:-false} != true ]]
|
||||
EOF
|
||||
|
||||
make_recorder panama-prism-gallery <<'EOF'
|
||||
@@ -71,9 +78,29 @@ printf ' <%s>' "$@" >>"$PANAMA_ACTION_TEST_LOG"
|
||||
printf '\n' >>"$PANAMA_ACTION_TEST_LOG"
|
||||
EOF
|
||||
|
||||
make_recorder systemd-inhibit <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
if [[ ${PANAMA_ACTION_TEST_CONFIRMED_STATE:-${PANAMA_ACTION_TEST_STATE:-true}} == true ]]; then
|
||||
printf 'Panama 1000 gib 42 systemd-inhibit sleep:idle Caffeine block\n'
|
||||
fi
|
||||
EOF
|
||||
|
||||
make_recorder pgrep <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
[[ ${PANAMA_ACTION_TEST_CONFIRMED_STATE:-${PANAMA_ACTION_TEST_STATE:-true}} == true ]]
|
||||
EOF
|
||||
|
||||
make_recorder id <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
printf '1000\n'
|
||||
EOF
|
||||
|
||||
run_action() {
|
||||
: >"$command_log"
|
||||
HOME="$work/home" PATH="$fake_bin:$PATH" \
|
||||
PANAMA_ACTION_HELPER_DIR="$fake_bin" \
|
||||
PANAMA_ACTION_CONFIRM_ATTEMPTS=1 \
|
||||
PANAMA_ACTION_CONFIRM_DELAY=0 \
|
||||
PANAMA_ACTION_TEST_LOG="$command_log" \
|
||||
"$dispatcher" "$1"
|
||||
}
|
||||
@@ -119,6 +146,9 @@ assert_commands $'qs <ipc> <call> <focus> <start>\npanama-osd <message> <prefere
|
||||
run_action focus-end
|
||||
assert_commands $'qs <ipc> <call> <focus> <end>\npanama-osd <message> <media-playback-stop-symbolic> <Focus Session Ended>'
|
||||
|
||||
PANAMA_ACTION_TEST_FOCUS_STATE=false run_action focus-end
|
||||
assert_commands $'qs <ipc> <call> <focus> <end>\npanama-osd <message> <dialog-information-symbolic> <No Focus Session Running>'
|
||||
|
||||
run_action capture
|
||||
assert_commands 'qs <ipc> <call> <capture> <open>'
|
||||
|
||||
@@ -135,18 +165,43 @@ run_action gallery
|
||||
assert_commands 'panama-prism-gallery'
|
||||
|
||||
run_action restart-shell
|
||||
assert_commands $'qs <kill>\nquickshell <--daemonize>'
|
||||
assert_commands $'qs <kill>\nquickshell <--daemonize>\nqs <ipc> <show>\npanama-osd <message> <view-refresh-symbolic> <Panama Restarted>'
|
||||
|
||||
if HOME="$work/home" PATH="$fake_bin:$PATH" PANAMA_ACTION_TEST_LOG="$command_log" \
|
||||
PANAMA_ACTION_TEST_FAIL_KILL=true run_action restart-shell
|
||||
assert_commands $'qs <kill>\nquickshell <--daemonize>\nqs <ipc> <show>\npanama-osd <message> <view-refresh-symbolic> <Panama Restarted>'
|
||||
|
||||
if HOME="$work/home" PATH="$fake_bin:$PATH" PANAMA_ACTION_HELPER_DIR="$fake_bin" \
|
||||
PANAMA_ACTION_CONFIRM_ATTEMPTS=1 PANAMA_ACTION_CONFIRM_DELAY=0 PANAMA_ACTION_TEST_LOG="$command_log" \
|
||||
"$dispatcher" definitely-not-an-action >/dev/null 2>&1; then
|
||||
fail 'unknown action was accepted'
|
||||
fi
|
||||
|
||||
: >"$command_log"
|
||||
if PANAMA_ACTION_TEST_FAIL_QS=true HOME="$work/home" PATH="$fake_bin:$PATH" \
|
||||
PANAMA_ACTION_TEST_LOG="$command_log" "$dispatcher" control-center >/dev/null 2>&1; then
|
||||
PANAMA_ACTION_HELPER_DIR="$fake_bin" PANAMA_ACTION_CONFIRM_ATTEMPTS=1 \
|
||||
PANAMA_ACTION_CONFIRM_DELAY=0 PANAMA_ACTION_TEST_LOG="$command_log" \
|
||||
"$dispatcher" control-center >/dev/null 2>&1; then
|
||||
fail 'failed shell action returned success'
|
||||
fi
|
||||
assert_commands $'qs <ipc> <call> <quicksettings> <open>\nnotify-send <-a> <Panama> <-i> <dialog-error-symbolic> <Panama action failed> <The “control center” action could not be completed.>'
|
||||
|
||||
: >"$command_log"
|
||||
if PANAMA_ACTION_TEST_FAIL_OSD=true HOME="$work/home" PATH="$fake_bin:$PATH" \
|
||||
PANAMA_ACTION_HELPER_DIR="$fake_bin" PANAMA_ACTION_CONFIRM_ATTEMPTS=1 \
|
||||
PANAMA_ACTION_CONFIRM_DELAY=0 PANAMA_ACTION_TEST_LOG="$command_log" \
|
||||
"$dispatcher" microphone >/dev/null 2>&1; then
|
||||
fail 'failed Prism OSD delivery returned success'
|
||||
fi
|
||||
assert_commands $'panama-osd <microphone> <toggle>\nnotify-send <-a> <Panama> <-i> <dialog-error-symbolic> <Panama action failed> <The “microphone” action could not be completed.>'
|
||||
|
||||
: >"$command_log"
|
||||
if PANAMA_ACTION_TEST_CONFIRMED_STATE=false HOME="$work/home" PATH="$fake_bin:$PATH" \
|
||||
PANAMA_ACTION_HELPER_DIR="$fake_bin" PANAMA_ACTION_CONFIRM_ATTEMPTS=1 \
|
||||
PANAMA_ACTION_CONFIRM_DELAY=0 PANAMA_ACTION_TEST_LOG="$command_log" \
|
||||
"$dispatcher" caffeine >/dev/null 2>&1; then
|
||||
fail 'unconfirmed Caffeine state returned success'
|
||||
fi
|
||||
grep -Fqx 'notify-send <-a> <Panama> <-i> <dialog-error-symbolic> <Panama action failed> <The “caffeine” action could not be completed.>' "$command_log" \
|
||||
|| fail 'unconfirmed state did not send a failure notification'
|
||||
|
||||
printf 'Panama action contract: PASS\n'
|
||||
|
||||
@@ -9,6 +9,7 @@ fail() {
|
||||
|
||||
active_target=""
|
||||
original_state=""
|
||||
night_light_snapshot=""
|
||||
|
||||
restore_target() {
|
||||
local target="$1" expected="$2" current
|
||||
@@ -22,6 +23,12 @@ cleanup() {
|
||||
if [[ -n $active_target ]]; then
|
||||
restore_target "$active_target" "$original_state"
|
||||
fi
|
||||
if [[ -n $night_light_snapshot ]]; then
|
||||
local enabled automatic
|
||||
enabled="$(jq -r '.enabled' <<<"$night_light_snapshot")"
|
||||
automatic="$(jq -r '.automatic' <<<"$night_light_snapshot")"
|
||||
qs ipc call night-light restore "$enabled" "$automatic" >/dev/null 2>&1 || true
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
@@ -51,6 +58,22 @@ rg -q '^target caffeine$' <<<"$ipc" || fail 'caffeine IPC target is missing'
|
||||
rg -q '^target night-light$' <<<"$ipc" || fail 'night-light IPC target is missing'
|
||||
|
||||
exercise_toggle caffeine
|
||||
|
||||
night_light_snapshot="$(qs ipc call night-light settings)"
|
||||
jq -e '.enabled | type == "boolean"' <<<"$night_light_snapshot" >/dev/null \
|
||||
|| fail 'night-light settings omitted enabled state'
|
||||
jq -e '.automatic | type == "boolean"' <<<"$night_light_snapshot" >/dev/null \
|
||||
|| fail 'night-light settings omitted automatic state'
|
||||
exercise_toggle night-light
|
||||
|
||||
original_enabled="$(jq -r '.enabled' <<<"$night_light_snapshot")"
|
||||
original_automatic="$(jq -r '.automatic' <<<"$night_light_snapshot")"
|
||||
qs ipc call night-light restore "$original_enabled" "$original_automatic" >/dev/null
|
||||
restored_snapshot="$(qs ipc call night-light settings)"
|
||||
[[ "$(jq -r '.enabled' <<<"$restored_snapshot")" == "$original_enabled" ]] \
|
||||
|| fail 'night-light enabled state was not restored'
|
||||
[[ "$(jq -r '.automatic' <<<"$restored_snapshot")" == "$original_automatic" ]] \
|
||||
|| fail 'night-light automatic schedule was not restored'
|
||||
night_light_snapshot=""
|
||||
|
||||
printf 'Panama action IPC contract: PASS\n'
|
||||
|
||||
@@ -4,6 +4,8 @@ set -euo pipefail
|
||||
|
||||
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
installer="$repo_dir/setup/scripts/link-vicinae-scripts"
|
||||
dotfile_installer="$repo_dir/setup/scripts/link-dotfiles"
|
||||
top_level_installer="$repo_dir/install"
|
||||
work="$(mktemp -d /tmp/panama-command-install.XXXXXX)"
|
||||
data_dir="$work/share/vicinae"
|
||||
fake_bin="$work/bin"
|
||||
@@ -20,6 +22,11 @@ cleanup() {
|
||||
trap cleanup EXIT
|
||||
|
||||
[[ -x "$installer" ]] || fail 'Vicinae script installer is missing or not executable'
|
||||
if rg -q 'setup/scripts/link-vicinae-scripts' "$dotfile_installer"; then
|
||||
fail 'link-dotfiles also invokes the command installer'
|
||||
fi
|
||||
rg -Fq 'do "$script"; done' "$top_level_installer" \
|
||||
|| fail 'top-level installer sources setup scripts into one shared shell'
|
||||
|
||||
mkdir -p "$data_dir/scripts/panama" "$fake_bin"
|
||||
printf 'user-owned\n' >"$data_dir/scripts/panama/keep.sh"
|
||||
@@ -37,12 +44,14 @@ PATH="$fake_bin:$PATH" PANAMA_PATH="$repo_dir" VICINAE_DATA_DIR="$data_dir" \
|
||||
PANAMA_VICINAE_TEST_LOG="$vicinae_log" "$installer" >/dev/null
|
||||
|
||||
target="$data_dir/scripts/panama"
|
||||
backup="$data_dir/scripts/panama.pre-panama"
|
||||
backup="$data_dir/backups/panama.pre-panama"
|
||||
[[ -L "$target" ]] || fail 'Panama command directory was not linked'
|
||||
[[ "$(readlink -f "$target")" == "$(readlink -f "$repo_dir/config/local/share/vicinae/scripts")" ]] \
|
||||
|| fail 'runtime command link points outside the tracked source'
|
||||
[[ -f "$backup/keep.sh" ]] || fail 'pre-existing user command directory was not preserved'
|
||||
[[ "$(cat "$backup/keep.sh")" == user-owned ]] || fail 'preserved user command changed'
|
||||
[[ ! -e "$data_dir/scripts/panama.pre-panama" ]] \
|
||||
|| fail 'preserved commands remained inside Vicinae search paths'
|
||||
|
||||
expected_calls=$'vicinae <ping>\nvicinae <cmd> <launch> <core:reload-scripts>'
|
||||
[[ "$(cat "$vicinae_log")" == "$expected_calls" ]] \
|
||||
@@ -55,7 +64,7 @@ PATH="$fake_bin:$PATH" PANAMA_PATH="$repo_dir" VICINAE_DATA_DIR="$data_dir" \
|
||||
PANAMA_VICINAE_TEST_LOG="$vicinae_log" "$installer" >/dev/null
|
||||
[[ -L "$target" ]] || fail 'second install did not leave the command link intact'
|
||||
[[ -f "$backup/keep.sh" ]] || fail 'second install disturbed the original backup'
|
||||
[[ ! -e "$data_dir/scripts/panama.pre-panama.pre-panama" ]] \
|
||||
[[ ! -e "$data_dir/backups/panama.pre-panama.pre-panama" ]] \
|
||||
|| fail 'second install created a duplicate backup'
|
||||
|
||||
printf 'Panama command install contract: PASS\n'
|
||||
|
||||
Reference in New Issue
Block a user