repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
quickshell/nugu/smoke.sh
RawFile outline
#!/bin/sh
set -eu
# Run the Nugu Quickshell scaffold through the named-config path without touching
# live ~/.config/quickshell. The temporary XDG_CONFIG_HOME proves the config is
# self-contained: only this directory is symlinked into the test home.
if [ "${NUGU_QS_INSIDE_SMOKE:-}" != 1 ] && [ "${NUGU_QS_NO_DBUS_RUN_SESSION:-}" != 1 ]; then
exec dbus-run-session -- env NUGU_QS_INSIDE_SMOKE=1 "$0" "$@"
fi
config_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
repo_dir=$(CDPATH= cd -- "$config_dir/../.." && pwd -P)
tmp=${TMPDIR:-/tmp}/nugu-qs-smoke.$$
home_tmp=$tmp/home
log_out=${NUGU_QS_SMOKE_OUT:-/tmp/nugu-qs-smoke.out}
log_err=${NUGU_QS_SMOKE_ERR:-/tmp/nugu-qs-smoke.err}
screenshot_dir=${NUGU_QS_SMOKE_SCREENSHOT_DIR:-}
qs_pid=
cleanup() {
if [ -n "$qs_pid" ]; then
kill "$qs_pid" 2>/dev/null || true
wait "$qs_pid" 2>/dev/null || true
fi
rm -rf "$tmp"
}
trap cleanup EXIT INT TERM
fail() {
printf 'FAIL: %s\n' "$1" >&2
printf '%s\n' '--- qs stdout ---' >&2
sed -n '1,120p' "$log_out" >&2 2>/dev/null || true
printf '%s\n' '--- qs stderr ---' >&2
sed -n '1,120p' "$log_err" >&2 2>/dev/null || true
exit 1
}
ipc() {
HOME="$home_tmp" XDG_CONFIG_HOME="$tmp" qs ipc -c nugu call nugu "$@"
}
assert_contains() {
haystack=$1
needle=$2
label=$3
case "$haystack" in
*"$needle"*) ;;
*) fail "$label missing $needle in $haystack" ;;
esac
}
assert_theme_state() {
mode=$1
source=$2
state=$3
label=$4
python - "$config_dir/nugu.json" "$mode" "$source" "$state" "$label" <<'PY'
import json, sys
palette_path, mode, source, state_text, label = sys.argv[1:]
state = json.loads(state_text)
palette = json.load(open(palette_path))[mode]
expected = {
"mode": mode,
"source": source,
"error": palette["error"],
"warning": palette["warning"],
"info": palette["info"],
"debug": palette["debug"],
"contentNormal": palette["content"]["normal"],
"contentBackdrop": palette["content"]["backdrop"],
"contentAccent": palette["content"]["accent"],
"uiNormal": palette["ui"]["normal"],
"uiBackdrop": palette["ui"]["backdrop"],
"uiAccent": palette["ui"]["accent"],
"uiFocus": palette["ui"]["focus"],
}
for key, value in expected.items():
if state.get(key) != value:
raise SystemExit(f"{label}: {key} expected {value!r}, got {state.get(key)!r} in {state_text}")
PY
}
wait_theme() {
expected=$1
label=$2
value=
i=0
while [ "$i" -lt 30 ]; do
value=$(ipc themeMode)
case "$value" in
*"$expected"*) printf '%s' "$value"; return 0 ;;
esac
i=$((i + 1))
sleep 0.1
done
fail "$label did not become $expected; last value: $value"
}
hold_theme() {
expected=$1
label=$2
value=
i=0
while [ "$i" -lt 8 ]; do
value=$(ipc themeMode)
case "$value" in
*"$expected"*) ;;
*) fail "$label changed away from $expected; value: $value" ;;
esac
i=$((i + 1))
sleep 0.1
done
printf '%s' "$value"
}
capture_screenshot() {
label=$1
[ -n "$screenshot_dir" ] || return 0
command -v grim >/dev/null 2>&1 || fail 'grim is required when NUGU_QS_SMOKE_SCREENSHOT_DIR is set'
mkdir -p "$screenshot_dir"
# Capture only the top-left scaffold region of the focused monitor. Full-screen
# screenshots risk leaking private desktop contents; this crop contains the
# Quickshell diagnostics swatches and rollout bar only.
geometry=$(hyprctl monitors -j | python -c 'import json, sys; monitors = json.load(sys.stdin); monitor = next((m for m in monitors if m.get("focused")), monitors[0]); x = int(monitor.get("x", 0)); y = int(monitor.get("y", 0)); w = min(460, int(monitor.get("width", 460))); h = min(170, int(monitor.get("height", 170))); print(f"{x},{y} {w}x{h}")')
grim -g "$geometry" "$screenshot_dir/nugu-qs-$label.png" || fail "screenshot failed for $label"
}
mkdir -p "$tmp/quickshell" "$home_tmp/.cache/nugu"
printf 'dark' >"$home_tmp/.cache/nugu/mode"
ln -s "$config_dir" "$tmp/quickshell/nugu"
: >"$log_out"
: >"$log_err"
audit_output=$("$config_dir/audit.sh") || fail 'static Quickshell audit failed'
cd "$repo_dir"
HOME="$home_tmp" XDG_CONFIG_HOME="$tmp" QS_NO_RELOAD_POPUP=1 qs -c nugu >"$log_out" 2>"$log_err" &
qs_pid=$!
sleep 4
state_initial=$(ipc scaffoldState)
assert_contains "$state_initial" '"themeSource":"auto"' initial-state
assert_contains "$state_initial" '"diagnostics":false' initial-state
assert_contains "$state_initial" '"bar":false' initial-state
assert_contains "$state_initial" '"nativeNotifications":false' initial-state
ipc showDiagnostics >/dev/null
ipc showBar >/dev/null
mode_dark=$(ipc setThemeMode dark)
state_dark_open=$(ipc scaffoldState)
theme_dark_state=$(ipc themeState)
assert_contains "$mode_dark" 'dark' theme-dark
assert_contains "$state_dark_open" '"theme":"dark"' dark-open-state
assert_contains "$state_dark_open" '"themeSource":"preview"' dark-open-state
assert_contains "$state_dark_open" '"diagnostics":true' dark-open-state
assert_contains "$state_dark_open" '"bar":true' dark-open-state
assert_contains "$state_dark_open" '"nativeNotifications":false' dark-open-state
assert_theme_state dark preview "$theme_dark_state" dark-theme-state
capture_screenshot dark
mode_light=$(ipc setThemeMode light)
state_light_open=$(ipc scaffoldState)
theme_light_state=$(ipc themeState)
assert_contains "$mode_light" 'light' theme-light
assert_contains "$state_light_open" '"theme":"light"' light-open-state
assert_contains "$state_light_open" '"themeSource":"preview"' light-open-state
assert_contains "$state_light_open" '"diagnostics":true' light-open-state
assert_contains "$state_light_open" '"bar":true' light-open-state
assert_contains "$state_light_open" '"nativeNotifications":false' light-open-state
assert_theme_state light preview "$theme_light_state" light-theme-state
capture_screenshot light
printf 'light' >"$home_tmp/.cache/nugu/mode"
mode_auto_request=$(ipc setThemeMode auto)
mode_auto_light=$(wait_theme light theme-auto-light)
source_auto_light=$(ipc themeSource)
theme_auto_light_state=$(ipc themeState)
assert_contains "$mode_auto_light" 'light' theme-auto-light
assert_contains "$source_auto_light" 'auto' theme-source-auto-light
assert_theme_state light auto "$theme_auto_light_state" auto-light-theme-state
printf 'dark' >"$home_tmp/.cache/nugu/mode"
mode_auto_watch_dark=$(wait_theme dark theme-auto-watch-dark)
source_auto_dark=$(ipc themeSource)
theme_auto_dark_state=$(ipc themeState)
assert_contains "$mode_auto_watch_dark" 'dark' theme-auto-watch-dark
assert_contains "$source_auto_dark" 'auto' theme-source-auto-dark
assert_theme_state dark auto "$theme_auto_dark_state" auto-dark-theme-state
mode_preview_dark=$(ipc setThemeMode dark)
source_preview_dark=$(ipc themeSource)
assert_contains "$mode_preview_dark" 'dark' theme-preview-dark
assert_contains "$source_preview_dark" 'preview' theme-source-preview-dark
printf 'light' >"$home_tmp/.cache/nugu/mode"
mode_preview_hold_dark=$(hold_theme dark theme-preview-hold-dark)
assert_contains "$mode_preview_hold_dark" 'dark' theme-preview-hold-dark
mode_preview_light=$(ipc setThemeMode light)
assert_contains "$mode_preview_light" 'light' theme-preview-light
printf 'dark' >"$home_tmp/.cache/nugu/mode"
ipc reloadTheme >/dev/null
mode_after_reload=$(hold_theme light theme-preview-reload-holds-light)
assert_contains "$mode_after_reload" 'light' theme-preview-reload-holds-light
mode_auto_return=$(ipc setThemeMode auto)
mode_after_auto_return=$(wait_theme dark theme-auto-return-dark)
theme_auto_return_state=$(ipc themeState)
assert_contains "$mode_after_auto_return" 'dark' theme-auto-return-dark
assert_theme_state dark auto "$theme_auto_return_state" auto-return-theme-state
ipc hideAll >/dev/null
state_hidden=$(ipc scaffoldState)
assert_contains "$state_hidden" '"themeSource":"auto"' hidden-state
assert_contains "$state_hidden" '"theme":"dark"' hidden-state
assert_contains "$state_hidden" '"diagnostics":false' hidden-state
assert_contains "$state_hidden" '"bar":false' hidden-state
assert_contains "$state_hidden" '"launcher":false' hidden-state
assert_contains "$state_hidden" '"clipboardPicker":false' hidden-state
assert_contains "$state_hidden" '"powerMenu":false' hidden-state
assert_contains "$state_hidden" '"nativeNotifications":false' hidden-state
if ! grep -q 'Configuration Loaded' "$log_out"; then
fail 'Quickshell did not report Configuration Loaded'
fi
if grep -E 'TypeError|ReferenceError|Syntax|Binding loop|required|failed to create|insufficiently annotated' "$log_out" "$log_err" >/dev/null 2>&1; then
fail 'QML error pattern detected'
fi
printf 'PASS nugu quickshell scaffold smoke\n'
printf '%s\n' "$audit_output"
printf 'initial=%s\n' "$state_initial"
printf 'dark_open=%s\n' "$state_dark_open"
printf 'dark_theme_state=%s\n' "$theme_dark_state"
printf 'light_open=%s\n' "$state_light_open"
printf 'light_theme_state=%s\n' "$theme_light_state"
printf 'auto_request=%s\n' "$mode_auto_request"
printf 'auto_light=%s\n' "$mode_auto_light"
printf 'auto_light_source=%s\n' "$source_auto_light"
printf 'auto_light_theme_state=%s\n' "$theme_auto_light_state"
printf 'auto_watch_dark=%s\n' "$mode_auto_watch_dark"
printf 'auto_dark_source=%s\n' "$source_auto_dark"
printf 'auto_dark_theme_state=%s\n' "$theme_auto_dark_state"
printf 'preview_dark=%s\n' "$mode_preview_dark"
printf 'preview_dark_source=%s\n' "$source_preview_dark"
printf 'preview_hold_dark=%s\n' "$mode_preview_hold_dark"
printf 'preview_light=%s\n' "$mode_preview_light"
printf 'after_preview_reload=%s\n' "$mode_after_reload"
printf 'auto_return=%s\n' "$mode_auto_return"
printf 'after_auto_return=%s\n' "$mode_after_auto_return"
printf 'auto_return_theme_state=%s\n' "$theme_auto_return_state"
printf 'hidden=%s\n' "$state_hidden"
if [ -n "$screenshot_dir" ]; then
printf 'screenshot_dark=%s\n' "$screenshot_dir/nugu-qs-dark.png"
printf 'screenshot_light=%s\n' "$screenshot_dir/nugu-qs-light.png"
fi