Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions test/shell.d/base-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ shell_ipc_socket() {
printf '%s/omarchy-shell-%s.sock\n' "${XDG_RUNTIME_DIR:-/run/user/$UID}" "${id:0:16}"
}

# A fixture can leave children behind after Quickshell exits; its setsid group
# still reaches them, including children that need KILL after a TERM grace period.
stop_process_group() {
local pid="$1" attempt

kill -TERM -- "-$pid" 2>/dev/null || true
for attempt in {1..20}; do
if ! pgrep -g "$pid" >/dev/null 2>&1; then
wait "$pid" 2>/dev/null || true
return 0
fi
sleep 0.1
done
kill -KILL -- "-$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
}

require_command() {
local command="$1"

Expand Down Expand Up @@ -130,25 +147,9 @@ QML_FIXTURE_TMP=""
QML_FIXTURE_PID=""
QML_FIXTURE_LOG=""

# The fixture's Quickshell and every process it started, deepest last.
qml_fixture_tree() {
local pid=$1 child
printf '%s\n' "$pid"
for child in $(pgrep -P "$pid" 2>/dev/null); do
qml_fixture_tree "$child"
done
}

qml_fixture_cleanup() {
local -a tree=()
local attempt
if [[ -n $QML_FIXTURE_PID ]] && kill -0 "$QML_FIXTURE_PID" 2>/dev/null; then
# Processes a fixture started outlive Quickshell and can still be writing
# into its HOME while that is removed, so stop them with it.
mapfile -t tree < <(qml_fixture_tree "$QML_FIXTURE_PID")
kill "${tree[@]}" 2>/dev/null || true
wait "$QML_FIXTURE_PID" 2>/dev/null || true
fi
[[ -n $QML_FIXTURE_PID ]] && stop_process_group "$QML_FIXTURE_PID"
QML_FIXTURE_PID=""
if [[ -n $QML_FIXTURE_TMP && -d $QML_FIXTURE_TMP ]]; then
# A child that was mid-write when it got the signal can still add a file.
Expand Down Expand Up @@ -185,10 +186,7 @@ run_qml_fixture() {

qml_fixture_scratch
# A second fixture in the same file must not read the first one's result.
if [[ -n $QML_FIXTURE_PID ]] && kill -0 "$QML_FIXTURE_PID" 2>/dev/null; then
kill "$QML_FIXTURE_PID" 2>/dev/null || true
wait "$QML_FIXTURE_PID" 2>/dev/null || true
fi
[[ -n $QML_FIXTURE_PID ]] && stop_process_group "$QML_FIXTURE_PID"
config_dir="$QML_FIXTURE_TMP/$fixture"
result="$QML_FIXTURE_TMP/result.json"
QML_FIXTURE_LOG="$QML_FIXTURE_TMP/quickshell.log"
Expand All @@ -208,7 +206,7 @@ run_qml_fixture() {
QML2_IMPORT_PATH="$ROOT/shell${QML2_IMPORT_PATH:+:$QML2_IMPORT_PATH}" \
QML_IMPORT_PATH="$ROOT/shell${QML_IMPORT_PATH:+:$QML_IMPORT_PATH}" \
PATH="$QML_FIXTURE_TMP/bin:$ROOT/bin:$PATH" \
quickshell -p "$config_dir" --no-color >"$QML_FIXTURE_LOG" 2>&1 &
setsid quickshell -p "$config_dir" --no-color >"$QML_FIXTURE_LOG" 2>&1 &
QML_FIXTURE_PID=$!

for _ in {1..150}; do
Expand Down
21 changes: 21 additions & 0 deletions test/shell.d/plugin-registry-contract-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,24 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
require_quickshell "plugin registry contract test"

run_qml_fixture plugin-registry "plugin registry contract checks pass" services Commons

watcher=""
for _ in {1..30}; do
watcher=$(pgrep -P "$QML_FIXTURE_PID" -x inotifywait) && break
sleep 0.1
done
[[ -n $watcher ]] || fail "fixture starts a plugin watcher"
# A stopped child cannot handle TERM, so cleanup must also reach its KILL fallback.
kill -STOP "$watcher"
kill -KILL "$QML_FIXTURE_PID"
wait "$QML_FIXTURE_PID" 2>/dev/null || true
qml_fixture_cleanup
for _ in {1..100}; do
kill -0 "$watcher" 2>/dev/null || break
sleep 0.01
done
if kill -0 "$watcher" 2>/dev/null; then
kill -KILL "$watcher" 2>/dev/null || true
fail "crashed fixture cleanup stops its surviving plugin watcher"
fi
pass "crashed fixture cleanup stops its surviving plugin watcher"
7 changes: 3 additions & 4 deletions test/shell.d/tray-menu-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ cleanup() {
wait "$pid" 2>/dev/null || true
fi
done
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
if [[ -n $QS_PID ]]; then
stop_process_group "$QS_PID"
fi
[[ -n $TMPDIR && -d $TMPDIR ]] && rm -rf "$TMPDIR"
return 0
Expand Down Expand Up @@ -62,7 +61,7 @@ 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 &
setsid quickshell -p "$config_dir" --no-color >"$qs_log" 2>&1 &
QS_PID=$!

OMARCHY_TRAY_MENU_EVENT_RESULT="$event_result" \
Expand Down