From 2623fff0a5ec7af2312ecb9a5e8f5cdd3e9b7735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Beganovi=C4=87?= Date: Wed, 28 Oct 2026 02:39:16 +0100 Subject: [PATCH 1/7] Wait for Elsewhen's first save before the smoke test edits shell.json (#16859) The transparent bar check from #8307 sets the bar's background with omarchy-bar, which edits shell.json from outside the shell. Elsewhen saves its first-run cities once its timezone probe returns, and that save writes the shell's whole in-memory config back to shell.json. When the probe returns after the edit, the file goes back to an opaque bar, the bar never turns transparent and nothing samples the wallpaper. On a desktop the probe returns before the test gets there. In a VM it returned later in 7 of 8 runs: the file read "background": "opaque" with Elsewhen's cities saved, 30 s after omarchy-bar had reported "Bar background set to none". The unreadable shell.json checks further down already waited for that save. The wait is now one helper, called before both edits, and allows 30 s, since it returns as soon as the cities are saved. (cherry picked from commit 63b6e5be0ea2faf1f7f9c0b3c2db2052cce31827) --- test/shell.d/runtime-smoke-test.sh | 43 ++++++++++++++++++------------ 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/test/shell.d/runtime-smoke-test.sh b/test/shell.d/runtime-smoke-test.sh index 8f644ba2614f..eb8648ef4664 100755 --- a/test/shell.d/runtime-smoke-test.sh +++ b/test/shell.d/runtime-smoke-test.sh @@ -349,6 +349,23 @@ bar_background() { HOME="$SCRATCH_HOME" OMARCHY_PATH="$SCRATCH_ROOT" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-bar" background "$@" } +# Elsewhen saves its first-run cities once its probe returns, and that save +# writes the shell's whole config back to shell.json. Landing after an edit +# from outside the shell, it puts the old config back, so wait for it before +# editing shell.json. A machine slower than a desktop returns the probe late. +wait_for_elsewhen_cities() { + local saved='any(.bar.layout[][]; .id? == "omarchy.elsewhen" and .cities? != null)' + local config="$SCRATCH_HOME/.config/omarchy/shell.json" + + for _ in {1..300}; do + jq -e "$saved" "$config" >/dev/null 2>&1 && return 0 + kill -0 "$SCRATCH_PID" 2>/dev/null || fail_with_log "test shell exited before Elsewhen saved its cities" + sleep 0.1 + done + fail_with_log "Elsewhen saves its first-run cities before shell.json is edited" +} + +wait_for_elsewhen_cities bar_background none >/dev/null for _ in {1..50}; do (( $(text_color_count) > 0 )) && break @@ -632,40 +649,32 @@ pass "bar put leaves a widget already on the bar alone" # A hand edit that drops the closing brace puts the shell on the defaults, # which have no omarchy.microphone. A bar change then applies for the session # only, leaving the file as the user left it until they fix it. -config="$test_home/.config/omarchy/shell.json" -# Elsewhen saves its first-run cities once its probe returns. Landing between -# the edit and the shell's reload, that save would write valid JSON back. -for _ in {1..80}; do - jq -e 'any(.bar.layout[][]; .id? == "omarchy.elsewhen" and .cities? != null)' "$config" >/dev/null 2>&1 && break - kill -0 "$QS_PID" 2>/dev/null || fail_with_log "test shell exited before Elsewhen saved its cities" - sleep 0.1 -done -jq -e 'any(.bar.layout[][]; .id? == "omarchy.elsewhen" and .cities? != null)' "$config" >/dev/null || - fail_with_log "Elsewhen saves its first-run cities before shell.json is edited" +config="$SCRATCH_HOME/.config/omarchy/shell.json" +wait_for_elsewhen_cities sed -i '$ d' "$config" -cp "$config" "$TMPDIR/broken.json" +cp "$config" "$SCRATCH_DIR/broken.json" for _ in {1..80}; do [[ $(center_ids) != *omarchy.microphone* ]] && break - kill -0 "$QS_PID" 2>/dev/null || fail_with_log "test shell exited while reading an unreadable shell.json" + kill -0 "$SCRATCH_PID" 2>/dev/null || fail_with_log "test shell exited while reading an unreadable shell.json" sleep 0.1 done [[ $(center_ids) != *omarchy.microphone* ]] || fail_with_log "shell falls back to defaults on an unreadable shell.json" -[[ $(shell_ipc shell setBarWidget omarchy.clock format '"HH:mm"' '{}') == "ok" ]] || +[[ $(scratch_ipc shell setBarWidget omarchy.clock format '"HH:mm"' '{}') == "ok" ]] || fail_with_log "bar widget setting is applied while shell.json is unreadable" jq -e 'any(.bar.layout[][]; .id? == "omarchy.clock" and .format? == "HH:mm")' \ - <<<"$(shell_ipc shell listShellConfig)" >/dev/null || + <<<"$(scratch_ipc shell listShellConfig)" >/dev/null || fail_with_log "a bar change still applies in memory while shell.json is unreadable" sleep 0.5 -cmp -s "$config" "$TMPDIR/broken.json" || fail "a bar change leaves an unreadable shell.json as the user left it" "$(cat "$config")" +cmp -s "$config" "$SCRATCH_DIR/broken.json" || fail "a bar change leaves an unreadable shell.json as the user left it" "$(cat "$config")" pass "a bar change leaves an unreadable shell.json as the user left it" printf '}\n' >>"$config" for _ in {1..80}; do [[ $(center_ids) == *omarchy.microphone* ]] && break - kill -0 "$QS_PID" 2>/dev/null || fail_with_log "test shell exited while reading a fixed shell.json" + kill -0 "$SCRATCH_PID" 2>/dev/null || fail_with_log "test shell exited while reading a fixed shell.json" sleep 0.1 done -[[ $(shell_ipc shell setBarWidget omarchy.clock format '"H:mm"' '{}') == "ok" ]] || +[[ $(scratch_ipc shell setBarWidget omarchy.clock format '"H:mm"' '{}') == "ok" ]] || fail_with_log "bar widget setting is applied once shell.json is fixed" saved='any(.bar.layout[][]; (.id? // .) == "omarchy.microphone") and any(.bar.layout[][]; .id? == "omarchy.clock" and .format? == "H:mm")' for _ in {1..40}; do From 55feba8631f5b3e5db23d780a5efafa73f8595b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Beganovi=C4=87?= Date: Wed, 28 Oct 2026 11:39:06 +0100 Subject: [PATCH 2/7] Replace the i18n startup test's watched files whole (#16886) The live probe edits files the shell watches: the catalogs, the language selection and the plugin directory. It wrote them in place, which truncates first, and Quickshell's FileView reloads on the change, so a reload between the truncation and the write reads an empty file. With an empty catalog or plugin directory, t("test.hello") returns its key and .arg("Ada") logs "QString::arg: Argument missing", which fails the final log check. CI hit this on a loaded runner. Write each file beside its target and rename it over, so a reload reads either the old file or the new one. In a VM with every vCPU kept busy, the test failed 10 of 40 runs on that warning before this change and 0 of 40 after. Renaming only the catalogs was not enough (13 of 40 failed): the language and plugin directory files are watched too. (cherry picked from commit e6c6a1875fd371d16a69f29ff7a42d84a52f9bbe) --- test/shell.d/i18n-startup-test.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/shell.d/i18n-startup-test.sh b/test/shell.d/i18n-startup-test.sh index 0447a9b2e95c..522d597d2445 100644 --- a/test/shell.d/i18n-startup-test.sh +++ b/test/shell.d/i18n-startup-test.sh @@ -52,9 +52,17 @@ persian = dict(english, language='fa', locale='fa-IR', number='۱۳٫۵', rtl=Tr french_fallback = dict(english, language='fr', locale='fr-FR', number='13,5') -def write_json(path, data): +# The shell watches these files and reloads them as they change, so replace +# each one whole: a file written in place can be read while still empty. +def write_text(path, text): path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(json.dumps(data, ensure_ascii=False), encoding='utf-8') + staged = path.with_name(path.name + '.tmp') + staged.write_text(text, encoding='utf-8') + os.replace(staged, path) + + +def write_json(path, data): + write_text(path, json.dumps(data, ensure_ascii=False)) class Probe: @@ -159,7 +167,7 @@ try: try: probe.wait(english) for language, expected in [('da', danish), ('pt-BR', portuguese), ('fr', french_fallback), ('en', english)]: - probe.language.write_text(language) + write_text(probe.language, language) probe.wait(expected) print('ok - live language changes update shell, plugin, and locale bindings', flush=True) @@ -175,21 +183,21 @@ try: other = probe.path / 'other-plugin' write_json(other / 'en.json', dict(en_catalog, **{'test.hello': 'Other %1', 'test.baseOnly': 'English base'})) - probe.directory.write_text(str(other)) + write_text(probe.directory, str(other)) changed = dict(changed, pluginText='Other Ada') probe.wait(changed) - probe.directory.write_text(str(probe.plugin)) + write_text(probe.directory, str(probe.plugin)) changed = dict(changed, pluginText='Plugin Ada') probe.wait(changed) print('ok - changing the plugin catalog directory refreshes existing bindings', flush=True) - probe.language.write_text('da') + write_text(probe.language, 'da') probe.wait(danish) probe.language.unlink() probe.wait(changed) print('ok - deleting the language selection restores English', flush=True) - probe.language.write_text('da') + write_text(probe.language, 'da') probe.wait(danish) (probe.catalogs / 'da/shell.json').unlink() (probe.plugin / 'da.json').unlink() From f381fb0a61222a5f36ed33d36546162ab21478cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Beganovi=C4=87?= Date: Wed, 28 Oct 2026 11:39:27 +0100 Subject: [PATCH 3/7] Wait for the input-indicator test's fake Fcitx to finish its exec (#16887) The test starts sleep with FCITX_CONFIG_HOME set and at once reads the profile path from that process's /proc environ. Popen returns when the child's close-on-exec pipe closes, early in the kernel's exec, but the new environment is readable only once create_elf_tables sets env_end (fs/binfmt_elf.c). Until then the read is empty (fs/proc/base.c), refused, or the parent's, so the lookup falls back to the caller's own $HOME and the assertion fails on /home//.config/fcitx5/profile, as it did in CI. On a 7.2 kernel, 842 of 2000 reads made right after Popen returned lacked the child's environment, which appeared p50 26 us and p99 44 us later. With the test's VM pinned to one host core, as vCPUs share a core on a busy runner host, the test failed that way in 12 of 150 runs before this change and 0 of 150 after. A real Fcitx owns its bus name long after its exec, so the shell's lookup is unaffected; only the test needs to wait. (cherry picked from commit 79dcccfe5ab3b07a2660a9e99a1c6e3e717237fa) --- test/shell.d/input-indicator-test.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/shell.d/input-indicator-test.sh b/test/shell.d/input-indicator-test.sh index 1229fa9d38c8..2f4b46fbcf03 100755 --- a/test/shell.d/input-indicator-test.sh +++ b/test/shell.d/input-indicator-test.sh @@ -348,6 +348,19 @@ print("ok - the watched profile follows Fcitx's FCITX_CONFIG_HOME override") os.makedirs(scratch.name + "/daemon/fcitx") daemon = subprocess.Popen(["sleep", "30"], cwd=scratch.name, env={"HOME": scratch.name, "FCITX_CONFIG_HOME": "daemon/fcitx"}) +# Popen returns while the exec is still under way, and until it finishes the +# child's /proc environ reads empty, is refused, or is the parent's. Fcitx owns +# its bus name only well after its exec, so wait for the environment here too. +def daemon_environment(): + try: + with open(f"/proc/{daemon.pid}/environ", "rb") as file: + return file.read() + except PermissionError: + return b"" +for _ in range(500): + if b"FCITX_CONFIG_HOME=" in daemon_environment(): + break + time.sleep(0.01) class OwnerBus: def call_sync(self, name, path, interface, method, args, *rest): assert method == "GetConnectionUnixProcessID" and args.unpack() == (indicator.BUS,) From 05d70c097afd4769acacebdbedc7ace37de9f367 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 2 Nov 2026 21:37:57 +0100 Subject: [PATCH 4/7] Keep the agent account test off the network agent-account-exec-test pointed mise at all of etc/mise, so the agents were declared lazy tools. Current mise installs a declared lazy tool before running its wrapper, so offline the test failed fetching claude@latest before it reached the fake CLI. Give it only the wrapper declarations. mise also refuses a wrapper whose tool has no binary, so the first-run install cases now call omarchy-agent-account-exec the way mise hands off to it, with the wrapper directory off PATH. The quattro commit also fixed the dropdown test, which v4-5-0 doesn't have yet; that half goes with the backport that brings the test. (cherry picked from commit 0a54d6fa9284ffe3531a54c74930ace28b88bf3c) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CY6YBoMt9VUxZ6fJqSXaj1 --- test/shell.d/agent-account-exec-test.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/shell.d/agent-account-exec-test.sh b/test/shell.d/agent-account-exec-test.sh index 2cbe92c56b17..e03970fd38a9 100755 --- a/test/shell.d/agent-account-exec-test.sh +++ b/test/shell.d/agent-account-exec-test.sh @@ -48,10 +48,17 @@ SH chmod +x "$real_bin/$provider" done +# Only Omarchy's wrapper declarations: mise installs a declared lazy tool +# before it runs that tool's wrapper, so with omarchy-tools.toml in place it +# would try to fetch the real CLI instead of reaching the fake one. +mise_system_config="$test_tmp/etc/mise" +mkdir -p "$mise_system_config/conf.d" +cp "$ROOT/etc/mise/conf.d/omarchy-agent-accounts.toml" "$mise_system_config/conf.d/" + run_isolated() { env -i HOME="$account_test_home" \ XDG_CONFIG_HOME="$test_tmp/config" XDG_DATA_HOME="$test_tmp/data" XDG_CACHE_HOME="$test_tmp/cache" \ - MISE_DATA_DIR="$mise_data" MISE_SYSTEM_CONFIG_DIR="$ROOT/etc/mise" MISE_OFFLINE=1 \ + MISE_DATA_DIR="$mise_data" MISE_SYSTEM_CONFIG_DIR="$mise_system_config" MISE_OFFLINE=1 \ OMARCHY_PATH="$ROOT" PATH="$mise_data/command-wrappers/bin:$ROOT/bin:$real_bin:/usr/bin" \ "$@" } @@ -165,6 +172,8 @@ run_isolated env OMARCHY_TEST_AGENT_EXIT=42 claude >/dev/null || status=$? pass "account dispatch preserves the agent exit status" # A dispatcher alone must not prevent the CLI from being installed on first use. +# mise itself refuses a wrapper whose tool has no binary yet, so call account +# dispatch the way mise hands off to it: with its wrapper directory off PATH. # Omarchy declares the agent, so installing it must leave the user's config # alone; without that declaration, the user's config selects it. mv "$real_bin/grok" "$test_tmp/grok-fixture" @@ -186,18 +195,18 @@ SH chmod +x "$real_bin/mise" select_account grok side declarations="$ROOT/etc/mise/conf.d/omarchy-tools.toml" -output=$(run_isolated env OMARCHY_MISE_CONFIG_PATH="$declarations" OMARCHY_TEST_EXPECTED_INSTALL="install --quiet grok" grok) +output=$(run_isolated env OMARCHY_MISE_CONFIG_PATH="$declarations" OMARCHY_TEST_EXPECTED_INSTALL="install --quiet grok" PATH="$ROOT/bin:$real_bin:/usr/bin" omarchy-agent-account-exec grok) [[ $output == "$test_tmp/accounts/grok side" ]] || fail "a dispatcher without a CLI installs Omarchy's declared agent and uses the selected account" "$output" pass "a dispatcher without a CLI installs Omarchy's declared agent and uses the selected account" rm "$real_bin/grok" -output=$(run_isolated env OMARCHY_MISE_CONFIG_PATH="$test_tmp/no-declarations.toml" OMARCHY_TEST_EXPECTED_INSTALL="use -g --quiet grok" grok) +output=$(run_isolated env OMARCHY_MISE_CONFIG_PATH="$test_tmp/no-declarations.toml" OMARCHY_TEST_EXPECTED_INSTALL="use -g --quiet grok" PATH="$ROOT/bin:$real_bin:/usr/bin" omarchy-agent-account-exec grok) [[ $output == "$test_tmp/accounts/grok side" ]] || fail "a dispatcher without Omarchy's declaration selects the agent in the user config" "$output" pass "a dispatcher without Omarchy's declaration selects the agent in the user config" rm "$real_bin/grok" status=0 -run_isolated env OMARCHY_MISE_CONFIG_PATH="$declarations" OMARCHY_TEST_EXPECTED_INSTALL="install --quiet grok" OMARCHY_TEST_INSTALL_FAIL=yes grok >/dev/null || status=$? +run_isolated env OMARCHY_MISE_CONFIG_PATH="$declarations" OMARCHY_TEST_EXPECTED_INSTALL="install --quiet grok" OMARCHY_TEST_INSTALL_FAIL=yes PATH="$ROOT/bin:$real_bin:/usr/bin" omarchy-agent-account-exec grok >/dev/null || status=$? (( status == 42 )) || fail "a failed first-run install stops dispatch" "$status" pass "a failed first-run install stops dispatch" rm "$real_bin/mise" From 064818dfc0a659ebc836c551382978a8c5aadeb0 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 2 Nov 2026 21:42:51 +0100 Subject: [PATCH 5/7] Stop a QML fixture's child processes along with its Quickshell The fixture cleanup killed Quickshell and removed its scratch HOME, but the processes Quickshell had started (the agent usage scanner, the plugin directory's inotifywait) outlived it. The scanner could still be writing into home/.cache while rm -rf ran, so cleanup failed with "Directory not empty", and since that rm was the trap's last command, set -e failed a test whose checks had all passed. The watchers were left running against deleted directories after every run. Stop the whole process tree, and retry the removal briefly for a child caught mid-write. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CY6YBoMt9VUxZ6fJqSXaj1 (cherry picked from commit 63fd01867d59a30d1d3bbc394a01377fef3892a6) --- test/shell.d/base-test.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/test/shell.d/base-test.sh b/test/shell.d/base-test.sh index 047abac2e46f..9df5241ec85c 100644 --- a/test/shell.d/base-test.sh +++ b/test/shell.d/base-test.sh @@ -130,13 +130,34 @@ 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 - kill "$QML_FIXTURE_PID" 2>/dev/null || true + # 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 QML_FIXTURE_PID="" - [[ -n $QML_FIXTURE_TMP && -d $QML_FIXTURE_TMP ]] && rm -rf "$QML_FIXTURE_TMP" + 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. + for attempt in {1..20}; do + rm -rf "$QML_FIXTURE_TMP" 2>/dev/null && break + sleep 0.1 + done + [[ ! -e $QML_FIXTURE_TMP ]] || echo "Could not remove $QML_FIXTURE_TMP" >&2 + fi return 0 } From 083b53e11dea037b00538ea4a5189f56421fd6fd Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 2 Nov 2026 21:51:29 +0100 Subject: [PATCH 6/7] Stamp the Kimchi test's repeated reply once The pi scanner counts a reply once per id and timestamp, as a real repeated entry carries both. The test built its repeated a-1 reply with two reply() calls, each stamping fixture_now() to the millisecond, so when the clock ticked between them they were two replies and today's minimax-m3 tokens came out doubled (1850 for 925). Under the full suite that happened often enough to fail. Build the entry once and write it twice. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CY6YBoMt9VUxZ6fJqSXaj1 (cherry picked from commit 93e3b0a50678b300011eaed7e349e7e8e393caed) --- test/shell.d/agent-usage-kimchi-test.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/shell.d/agent-usage-kimchi-test.sh b/test/shell.d/agent-usage-kimchi-test.sh index 47300cbd18d7..d81ae16f9973 100755 --- a/test/shell.d/agent-usage-kimchi-test.sh +++ b/test/shell.d/agent-usage-kimchi-test.sh @@ -297,11 +297,14 @@ expect("a budget cached under its old name is read, elapsed at zero and an unclo sandbox() sessions = harness() / "sessions" / "--home-me--" now = iso_in(0) +# A repeated entry is the same id at the same time. Two calls could stamp it a +# millisecond apart, which would make it two replies. +repeated = reply("a-1", "minimax-m3", {"input": 100, "output": 20, "cacheRead": 800, "cacheWrite": 5, "totalTokens": 925}) write_pi_session(sessions / "today.jsonl", [ {"type": "session", "id": "s-1"}, {"type": "message", "id": "u-1", "timestamp": now, "message": {"role": "user", "content": "hi", "usage": {"input": 999}}}, - reply("a-1", "minimax-m3", {"input": 100, "output": 20, "cacheRead": 800, "cacheWrite": 5, "totalTokens": 925}), - reply("a-1", "minimax-m3", {"input": 100, "output": 20, "cacheRead": 800, "cacheWrite": 5, "totalTokens": 925}), + repeated, + repeated, reply("a-2", "glm-5.3", {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 75}), {"type": "custom", "id": "c-1", "timestamp": now, "data": {"usage": {"input": 999}}}, {"type": "message", "id": "a-3", "message": {"role": "assistant", "model": "glm-5.3", "timestamp": ms_in(0), "usage": {"input": 10, "output": 5}}}, From fcf4bd84d2a7d916008637486cd46a669d8aee45 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 2 Nov 2026 22:10:16 +0100 Subject: [PATCH 7/7] Stop a crashed QML fixture's children through its process group Fixture cleanup found Quickshell's children by walking down from a live Quickshell, so once Quickshell had crashed (a compositor disconnect, say) the walk never ran and its children, such as the plugin directory's inotifywait, were left to init. Start each fixture's Quickshell in a process group of its own with setsid and signal the group, which works whether or not its leader is still alive. A second fixture in the same file stops the first the same way. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CY6YBoMt9VUxZ6fJqSXaj1 --- test/shell.d/base-test.sh | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/test/shell.d/base-test.sh b/test/shell.d/base-test.sh index 9df5241ec85c..30f9d13074f1 100644 --- a/test/shell.d/base-test.sh +++ b/test/shell.d/base-test.sh @@ -130,26 +130,27 @@ 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" +# Each fixture's Quickshell leads a process group of its own (setsid), so +# everything it started can be stopped through the group, even once Quickshell +# itself has crashed and left its children to init. +qml_fixture_stop() { + local group=$QML_FIXTURE_PID attempt + [[ -n $group ]] || return 0 + QML_FIXTURE_PID="" + kill -TERM -- "-$group" 2>/dev/null || true + wait "$group" 2>/dev/null || true + for attempt in {1..20}; do + pgrep -g "$group" >/dev/null 2>&1 || return 0 + sleep 0.1 done + kill -KILL -- "-$group" 2>/dev/null || true } 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 - QML_FIXTURE_PID="" + # Processes a fixture started can still be writing into its HOME while that + # is removed, so stop them first. + qml_fixture_stop 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. for attempt in {1..20}; do @@ -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 + qml_fixture_stop config_dir="$QML_FIXTURE_TMP/$fixture" result="$QML_FIXTURE_TMP/result.json" QML_FIXTURE_LOG="$QML_FIXTURE_TMP/quickshell.log" @@ -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