Files
chandra/scripts/test-private-bus.sh
T
nandiandClaude Sonnet 5.5 70b24ffe47
CI / test (push) Canceled after 24m10s
Private bus: don't take over the session's document portal mount
A nested compositor's private D-Bus kept the session's XDG_RUNTIME_DIR, so
an xdg-document-portal activated on it mounted over $XDG_RUNTIME_DIR/doc and
removed the mount when the bus exited. The session's portal kept running
without it, and flatpak apps stopped starting.

The bus now has its own config that starts the document portal with a runtime
directory per compositor. scripts/test-private-bus.sh covers it. The KDE
colors test gets its own runtime directory for the same reason.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 22:06:51 -08:00

45 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Run the private session bus's end-to-end test (compositor/sys): a nested compositor's apps must
# not be able to take over the session's document portal mount. A "host" xdg-document-portal
# mounts doc/ in a throwaway runtime directory, as a login session's does; the test spawns an app
# that asks the compositor's private bus for another one, which must mount elsewhere (and
# xdg-desktop-portal must still work there); the host's mount must still be there after the
# compositor (the test process) and its bus are gone. Needs FUSE, dbus-daemon, xdg-document-portal
# and xdg-desktop-portal; skips without them. Extra arguments go to `moon test`.
set -euo pipefail
cd "$(dirname "$0")/.."
export PATH="$HOME/.moon/bin:$PATH"
XDOC=
for x in /usr/libexec/xdg-document-portal /usr/lib/xdg-document-portal; do
[ -x "$x" ] && XDOC=$x && break
done
skip() { echo "private bus test skipped: $1"; exit 0; }
[ -n "$XDOC" ] || skip "xdg-document-portal not installed"
[ -x "${XDOC%/*}/xdg-desktop-portal" ] || skip "xdg-desktop-portal not installed"
[ -w /dev/fuse ] && command -v fusermount3 >/dev/null || skip "no FUSE"
command -v dbus-daemon >/dev/null && command -v dbus-send >/dev/null || skip "no dbus-daemon"
tmp=$(mktemp -d)
mkdir -m 700 "$tmp/run"
export XDG_RUNTIME_DIR="$tmp/run" XDG_DATA_HOME="$tmp/data"
addr_pid=$(dbus-daemon --session --fork --print-address=1 --print-pid=1)
export DBUS_SESSION_BUS_ADDRESS=$(echo "$addr_pid" | sed -n 1p)
DPID=$(echo "$addr_pid" | sed -n 2p)
cleanup() {
kill ${XPID:-} "$DPID" 2>/dev/null || true
sleep 1
fusermount3 -u -z "$tmp/run/doc" 2>/dev/null || true
rm -rf "$tmp"
}
trap cleanup EXIT
mounted() { grep -q -F " $tmp/run/doc " /proc/self/mountinfo; }
"$XDOC" -v >"$tmp/xdoc.log" 2>&1 &
XPID=$!
for _ in $(seq 50); do mounted && break; sleep 0.1; done
mounted || { cat "$tmp/xdoc.log"; skip "the document portal could not mount here"; }
# WAYLAND_DISPLAY makes the compositor "nested", which is when it starts a private bus.
CHANDRA_PRIVATE_BUS_E2E=1 WAYLAND_DISPLAY=wayland-host \
moon test --target native --warn-list -a compositor/sys "$@"
sleep 2 # for the private bus, and anything it started, to exit
mounted || { echo "FAIL: the host's $tmp/run/doc mount is gone"; cat "$tmp/xdoc.log"; exit 1; }
echo "private bus: ok"