Read org.freedesktop.appearance accent-color and color-scheme from org.freedesktop.portal.Settings over GDBus in the GTK stub and follow SettingChanged. The accent recolours the selected tab, sliders, peak meters and the checked Default button through an application-priority GtkCssProvider (named colours and --accent-* variables too, for themes that use them); the colour scheme sets the theme's dark/light variant. Without a portal or accent the theme's own stays. Colour conversion, WCAG contrast (readable foreground on the accent, readable accent text on the window) and the CSS live in model/accent.mbt with unit tests. The smoke test runs a fake portal on a private session bus, switches the accent live from green to orange and renders the tabs again (docs/screenshots/accent-*.png). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
198 lines
9.0 KiB
Bash
Executable File
198 lines
9.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# Headless smoke test: start a private PipeWire + WirePlumber (two null
|
|
# sinks, a loopback virtual microphone, a playback and a capture stream),
|
|
# run every moonmix-probe action and check its effect, then, if
|
|
# gtk4-broadwayd is available, render GUI screenshots: with the theme's
|
|
# accent and, through a fake XDG Desktop Portal, with a system accent colour.
|
|
#
|
|
# Only this *test harness* uses pw-cat (to create a playing stream); moonmix
|
|
# itself talks to PipeWire through libwireplumber.
|
|
#
|
|
# tools/smoke-test.sh [screenshot-prefix]
|
|
set -eu
|
|
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
|
BUILD="$ROOT/_build/native/debug/build/cmd"
|
|
PROBE="$BUILD/moonmix-probe/moonmix-probe.exe"
|
|
GUI="$BUILD/moonmix/moonmix.exe"
|
|
SHOTS="${1:-}"
|
|
|
|
export XDG_RUNTIME_DIR="$(mktemp -d)"
|
|
export PIPEWIRE_RUNTIME_DIR="$XDG_RUNTIME_DIR"
|
|
export XDG_CONFIG_HOME="$XDG_RUNTIME_DIR/config"
|
|
export XDG_STATE_HOME="$XDG_RUNTIME_DIR/state"
|
|
mkdir -p "$XDG_CONFIG_HOME/pipewire/pipewire.conf.d" "$XDG_STATE_HOME"
|
|
cat > "$XDG_CONFIG_HOME/pipewire/pipewire.conf.d/moonmix-test.conf" <<'CONF'
|
|
context.objects = [
|
|
{ factory = adapter
|
|
args = { factory.name = support.null-audio-sink
|
|
node.name = "test_speakers" node.description = "Test Speakers"
|
|
device.form-factor = "speaker"
|
|
media.class = "Audio/Sink" audio.position = [ FL FR ]
|
|
monitor.channel-volumes = true object.linger = true } }
|
|
{ factory = adapter
|
|
args = { factory.name = support.null-audio-sink
|
|
node.name = "test_headphones" node.description = "Test Headphones"
|
|
device.form-factor = "headphone"
|
|
media.class = "Audio/Sink" audio.position = [ FL FR ]
|
|
object.linger = true } }
|
|
]
|
|
# The microphone is a loopback virtual source, like echo-cancel creates.
|
|
context.modules = [
|
|
{ name = libpipewire-module-loopback
|
|
args = {
|
|
node.description = "Test Microphone"
|
|
capture.props = { node.name = "test_mic_capture" node.passive = true audio.position = [ MONO ] }
|
|
playback.props = { node.name = "test_mic" device.form-factor = "microphone" media.class = "Audio/Source" audio.position = [ MONO ] }
|
|
} }
|
|
]
|
|
CONF
|
|
|
|
# Ubuntu's WirePlumber asks snapd before granting clients access; there is
|
|
# no snapd in a sandbox/CI container, so turn that off for the test session.
|
|
mkdir -p "$XDG_CONFIG_HOME/wireplumber/wireplumber.conf.d"
|
|
cat > "$XDG_CONFIG_HOME/wireplumber/wireplumber.conf.d/moonmix-test.conf" <<'CONF'
|
|
wireplumber.profiles = {
|
|
main = {
|
|
support.snapd-permission-prompting = disabled
|
|
script.client.access-snap = disabled
|
|
}
|
|
}
|
|
CONF
|
|
|
|
PIDS=""
|
|
cleanup() { for p in $PIDS; do kill "$p" 2>/dev/null || true; done; [ -n "${KEEP:-}" ] || rm -rf "$XDG_RUNTIME_DIR"; }
|
|
trap cleanup EXIT INT TERM PIPE
|
|
|
|
pipewire >"$XDG_RUNTIME_DIR/pipewire.log" 2>&1 & PIDS="$PIDS $!"
|
|
sleep 1
|
|
wireplumber >"$XDG_RUNTIME_DIR/wireplumber.log" 2>&1 & PIDS="$PIDS $!"
|
|
|
|
# wait_for <pattern>: poll the probe (up to ~20 s) until it prints pattern.
|
|
wait_for() {
|
|
for _ in $(seq 1 40); do
|
|
"$PROBE" 2>/dev/null | grep -q -- "$1" && return 0
|
|
sleep 0.5
|
|
done
|
|
echo "timed out waiting for '$1'"
|
|
return 1
|
|
}
|
|
# Let WirePlumber finish its startup (it has picked a default sink) before
|
|
# any stream appears: streams that show up while it is still initialising
|
|
# can wedge its event queue, after which nothing gets linked.
|
|
wait_for '\[default'
|
|
LOGS="$XDG_RUNTIME_DIR"
|
|
# Two minutes of stereo s16 48 kHz noise as a WAV file (header written by
|
|
# hand: no python/sox needed), so the peak meters have a signal; it only
|
|
# plays into the private null sinks. Reading raw audio from a device made
|
|
# older pw-cat (PipeWire 1.4) exit without creating a stream, so it is a file.
|
|
le32() { printf "\\$(printf %03o $(($1 & 255)))\\$(printf %03o $(($1 >> 8 & 255)))\\$(printf %03o $(($1 >> 16 & 255)))\\$(printf %03o $(($1 >> 24 & 255)))"; }
|
|
DATA=23040000
|
|
{ printf 'RIFF'; le32 $((DATA + 36)); printf 'WAVEfmt '; le32 16
|
|
printf '\001\000\002\000'; le32 48000; le32 192000; printf '\004\000\020\000'
|
|
printf 'data'; le32 $DATA; head -c $DATA /dev/urandom; } > "$LOGS/noise.wav"
|
|
{ pw-play -P '{ application.name = "Test Player" application.icon-name = "applications-multimedia-symbolic" media.name = "Smoke test tone" }' \
|
|
"$LOGS/noise.wav"; echo "pw-play exited with $?"; } >"$LOGS/play.log" 2>&1 & PIDS="$PIDS $!"
|
|
pw-cat --record --raw --rate 48000 --channels 1 --format s16 \
|
|
-P '{ application.name = "Test Recorder" application.icon-name = "audio-input-microphone" media.name = "Mic capture" }' \
|
|
/dev/null >"$LOGS/record.log" 2>&1 & PIDS="$PIDS $!"
|
|
wait_for 'Test Player | .*-> ' || true
|
|
|
|
fail=0
|
|
OUT="$LOGS/probe.out"
|
|
# step <expected-pattern> <probe args...>: run the probe and require the
|
|
# pattern in what it prints after the action.
|
|
step() {
|
|
want=$1; shift
|
|
echo "### $* (expect: $want)"
|
|
if ! "$PROBE" "$@" >"$OUT" 2>&1; then
|
|
echo "FAIL: probe exited with an error"; fail=1
|
|
fi
|
|
cat "$OUT"
|
|
# After an action the probe prints the state again; check only that part.
|
|
if ! sed -n '/^== action/,$p' "$OUT" | grep -q -- "$want" && ! { [ $# -eq 0 ] && grep -q -- "$want" "$OUT"; }; then
|
|
echo "FAIL: expected '$want'"; fail=1
|
|
fi
|
|
}
|
|
step 'Test Player | 100%'
|
|
# Change the volume of the sink the test stream plays to: in CI (PipeWire
|
|
# 1.4) a volume set on an idle, suspended null sink was not applied.
|
|
step 'Test Speakers | 50% (-18.06 dB)' volume test_speakers 50
|
|
step 'Test Microphone | .*muted' mute test_mic 1
|
|
step 'Test Headphones | .*\[default\]' default test_headphones
|
|
STREAM=$("$PROBE" | awk -F: '/Test Player/ {gsub(/ /,"",$1); print $1; exit}')
|
|
step 'Test Player | .*-> Test Speakers' move "${STREAM:-0}" test_speakers
|
|
|
|
# meter <node>: a peak meter on it must see the noise.
|
|
meter() {
|
|
echo "### meter $1"
|
|
"$PROBE" meter "$1" >"$OUT" 2>&1 || { echo "FAIL: no signal on $1's meter"; fail=1; }
|
|
grep '^== meter' "$OUT"
|
|
}
|
|
meter "${STREAM:-0}"
|
|
meter test_speakers
|
|
|
|
if [ "$fail" != 0 ]; then
|
|
echo "### diagnostics"
|
|
echo "--- pw-play playback:"; cat "$LOGS/play.log"
|
|
echo "--- pw-cat record:"; cat "$LOGS/record.log"
|
|
echo "--- wireplumber (warnings/errors):"
|
|
grep -E '^[EWC] ' "$LOGS/wireplumber.log" | grep -viE 'rtkit|d-?bus|bluez|camera|session bus|system bus' | tail -40
|
|
if command -v pw-dump >/dev/null; then
|
|
echo "--- nodes:"
|
|
pw-dump 2>/dev/null | python3 -c '
|
|
import json, sys
|
|
for o in json.load(sys.stdin):
|
|
t = o["type"].split(":")[-1]; i = o.get("info") or {}; p = i.get("props") or {}
|
|
if t == "Link": print("link", i.get("output-node-id"), "->", i.get("input-node-id"), i.get("state"))
|
|
if t == "Node":
|
|
props = (i.get("params") or {}).get("Props") or [{}]
|
|
print("node", o["id"], p.get("node.name"), p.get("media.class"), i.get("state"),
|
|
"vol", props[0].get("channelVolumes"), "mute", props[0].get("mute"))
|
|
' 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$SHOTS" ] && [ -x "$GUI" ]; then
|
|
echo "### GUI screenshots -> $SHOTS-<tab>.png"
|
|
if command -v gtk4-broadwayd >/dev/null; then
|
|
gtk4-broadwayd :5 >/dev/null 2>&1 & PIDS="$PIDS $!"
|
|
sleep 1
|
|
gui() { MOONMIX_ICON_DIR="$ROOT/data/icons" GDK_BACKEND=broadway BROADWAY_DISPLAY=:5 timeout 30 stdbuf -oL "$GUI"; }
|
|
# Default look: no session bus, so no portal and the theme's own accent.
|
|
DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/no-bus" MOONMIX_SCREENSHOT="$SHOTS" gui || fail=1
|
|
# System accent: a fake org.freedesktop.portal.Settings on a private
|
|
# session bus reports a green accent, then switches to orange while
|
|
# moonmix runs (SettingChanged); it takes the shots once orange is applied.
|
|
PY=""
|
|
for p in python3 /usr/bin/python3; do
|
|
if "$p" -c 'from gi.repository import Gio' 2>/dev/null; then PY=$p; break; fi
|
|
done
|
|
if [ -n "$PY" ] && command -v dbus-daemon >/dev/null; then
|
|
echo "### system accent colour (fake portal) -> $SHOTS-accent-<tab>.png"
|
|
dbus-daemon --session --nofork --address="unix:path=$XDG_RUNTIME_DIR/bus" \
|
|
>/dev/null 2>&1 & PIDS="$PIDS $!"
|
|
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
|
|
for _ in $(seq 1 40); do [ -S "$XDG_RUNTIME_DIR/bus" ] && break; sleep 0.25; done
|
|
mkfifo "$LOGS/portal.in"
|
|
"$PY" "$ROOT/tools/fake-portal.py" 0.2 0.82 0.48 0 <"$LOGS/portal.in" >"$LOGS/portal.log" 2>&1 & PIDS="$PIDS $!"
|
|
exec 4>"$LOGS/portal.in"
|
|
for _ in $(seq 1 40); do grep -q ready "$LOGS/portal.log" 2>/dev/null && break; sleep 0.25; done
|
|
MOONMIX_SCREENSHOT="$SHOTS-accent" MOONMIX_SCREENSHOT_ACCENT="#ff7800" gui >"$LOGS/accent.log" 2>&1 & GUIPID=$!
|
|
for _ in $(seq 1 40); do grep -q 'accent #33d17a' "$LOGS/accent.log" && break; sleep 0.25; done
|
|
echo "1 0.471 0 0" >&4 || true
|
|
wait "$GUIPID" || fail=1
|
|
exec 4>&-
|
|
cat "$LOGS/accent.log"
|
|
if ! grep -q 'accent #33d17a, light' "$LOGS/accent.log" || ! grep -q 'accent #ff7800, light' "$LOGS/accent.log"; then
|
|
echo "FAIL: accent colour not read from the portal or not updated live"
|
|
cat "$LOGS/portal.log"; fail=1
|
|
fi
|
|
else
|
|
echo "python3 with gi or dbus-daemon not found; skipping the accent colour screenshots"
|
|
fi
|
|
else
|
|
echo "gtk4-broadwayd not found; skipping GUI"
|
|
fi
|
|
fi
|
|
exit $fail
|