Files
omarchycn/test/shell.d/tray-menu-test.sh
T
David Heinemeier HanssonandClaude Fable 5 d2b090f8fc Isolate XDG dirs in shell tests that launch quickshell with a fake HOME
Faking HOME alone was never enough: the shell QML and the agent usage
updater read XDG_STATE_HOME and XDG_CACHE_HOME directly, so a test
quickshell inherited the session's real paths. The bar widget contract
test instantiated the agents widget, whose refresh ran the real
collectors against the empty fake HOME and wrote hollow "Waiting for
auth" records into the developer's real usage data files — hiding the
agents widget from their bar — while littering the real cache with
per-tmpdir scan files.

Point XDG_CONFIG_HOME, XDG_CACHE_HOME, and XDG_STATE_HOME under the fake
home in every test that boots quickshell with one.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 17:13:39 +02:00

91 lines
2.3 KiB
Bash

#!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
TMPDIR=""
QS_PID=""
MOCK_PID=""
cleanup() {
if [[ -n $MOCK_PID ]] && kill -0 "$MOCK_PID" 2>/dev/null; then
kill "$MOCK_PID" 2>/dev/null || true
wait "$MOCK_PID" 2>/dev/null || true
fi
if [[ -n $QS_PID ]] && kill -0 "$QS_PID" 2>/dev/null; then
kill "$QS_PID" 2>/dev/null || true
wait "$QS_PID" 2>/dev/null || true
fi
[[ -n $TMPDIR && -d $TMPDIR ]] && rm -rf "$TMPDIR"
return 0
}
trap cleanup EXIT
if ! command -v quickshell >/dev/null 2>&1; then
pass "quickshell not installed; skipping tray menu activation test"
exit 0
fi
require_command jq
require_command python
python - <<'PY' || {
import dbus
import gi
PY
pass "python DBus bindings unavailable; skipping tray menu activation test"
exit 0
}
TMPDIR=$(mktemp -d)
config_dir="$TMPDIR/tray-menu-activation"
result="$TMPDIR/result.json"
event_result="$TMPDIR/event"
ready="$TMPDIR/ready"
qs_log="$TMPDIR/quickshell.log"
mock_log="$TMPDIR/mock-sni.log"
mkdir -p "$config_dir" "$TMPDIR/home"
cp "$SHELL_TEST_DIR/fixtures/tray-menu-activation/shell.qml" "$config_dir/shell.qml"
OMARCHY_PATH="$ROOT" \
OMARCHY_QML_TEST_RESULT="$result" \
HOME="$TMPDIR/home" \
XDG_CONFIG_HOME="$TMPDIR/home/.config" \
XDG_CACHE_HOME="$TMPDIR/home/.cache" \
XDG_STATE_HOME="$TMPDIR/home/.local/state" \
quickshell -p "$config_dir" --no-color >"$qs_log" 2>&1 &
QS_PID=$!
OMARCHY_TRAY_MENU_EVENT_RESULT="$event_result" \
OMARCHY_TRAY_MENU_READY="$ready" \
python "$SHELL_TEST_DIR/fixtures/tray-menu-activation/mock-sni.py" >"$mock_log" 2>&1 &
MOCK_PID=$!
for _ in {1..80}; do
[[ -s $event_result ]] && break
if ! kill -0 "$QS_PID" 2>/dev/null; then
sed -n '1,160p' "$qs_log" >&2
fail "tray menu activation quickshell exited before triggering menu item"
fi
if ! kill -0 "$MOCK_PID" 2>/dev/null; then
sed -n '1,160p' "$mock_log" >&2
fail "mock StatusNotifierItem exited before receiving menu event"
fi
sleep 0.1
done
if [[ ! -s $event_result ]]; then
[[ -s $result ]] && jq . "$result" >&2
printf 'Quickshell log:\n' >&2
sed -n '1,160p' "$qs_log" >&2
printf 'Mock SNI log:\n' >&2
sed -n '1,160p' "$mock_log" >&2
fail "tray menu sends DBusMenu clicked event"
fi
pass "tray menu sends DBusMenu clicked event"