From 73fdb0fa3fd56bd0fdf1a678c67ea039aaa7b2d1 Mon Sep 17 00:00:00 2001 From: Mario Mohar Date: Thu, 10 Sep 2026 12:58:13 +0200 Subject: [PATCH 1/2] Make the closing plugin rescan best-effort The four plugin commands run under `set -e` and end by asking the shell to rescan. `omarchy-shell` exits 1 when its 2s IPC timeout expires, and that is exactly what happens when the reload the command itself just triggered takes longer than two seconds. So the command dies on that line. For update and remove the work is already done at that point, so they report failure for a run that succeeded. For add and clone the abort lands before the plugin is enabled, leaving it installed but disabled with nothing printed about how to enable it. `omarchy-shell -q` exists for this and is already how ten other commands make best-effort IPC calls. It also suppresses stdout, so the `>/dev/null` goes with it. The call is still made, only its failure stops being fatal. --- bin/omarchy-plugin-add | 2 +- bin/omarchy-plugin-clone | 2 +- bin/omarchy-plugin-remove | 2 +- bin/omarchy-plugin-update | 2 +- test/shell.d/plugin-rescan-test.sh | 196 +++++++++++++++++++++++++++++ 5 files changed, 200 insertions(+), 4 deletions(-) create mode 100755 test/shell.d/plugin-rescan-test.sh diff --git a/bin/omarchy-plugin-add b/bin/omarchy-plugin-add index d77593e913d0..082219b80da7 100755 --- a/bin/omarchy-plugin-add +++ b/bin/omarchy-plugin-add @@ -146,7 +146,7 @@ fi mv "$stage" "$target" echo "Added $id into $target" -omarchy-shell shell rescanPlugins >/dev/null +omarchy-shell -q shell rescanPlugins if [[ -z $enable_after ]]; then if (( ASSUME_YES )) || ! interactive; then diff --git a/bin/omarchy-plugin-clone b/bin/omarchy-plugin-clone index 59ca16172ed4..8d10ac01e439 100755 --- a/bin/omarchy-plugin-clone +++ b/bin/omarchy-plugin-clone @@ -146,7 +146,7 @@ update_manifest "$stage" "$source_id" "$new_id" "$display_name" mv "$stage" "$target_dir" stage="" -omarchy-shell shell rescanPlugins >/dev/null +omarchy-shell -q shell rescanPlugins discovered=0 for (( attempt = 0; attempt < 40; attempt++ )); do if omarchy-plugin-list --json | jq -e --arg id "$new_id" 'any(.[]; .id == $id)' >/dev/null; then diff --git a/bin/omarchy-plugin-remove b/bin/omarchy-plugin-remove index 2e8591f74f6f..c9f4bee70a39 100755 --- a/bin/omarchy-plugin-remove +++ b/bin/omarchy-plugin-remove @@ -114,7 +114,7 @@ else echo "Removed $id. Backup at: $backup" fi -omarchy-shell shell rescanPlugins >/dev/null +omarchy-shell -q shell rescanPlugins if [[ -n $cloned_from && $was_enabled == "true" ]]; then echo "Restored $cloned_from." diff --git a/bin/omarchy-plugin-update b/bin/omarchy-plugin-update index 90a9732e2499..d6355a41348f 100755 --- a/bin/omarchy-plugin-update +++ b/bin/omarchy-plugin-update @@ -128,6 +128,6 @@ for id in "${targets[@]}"; do done if (( UPDATED_ANY )); then - omarchy-shell shell rescanPlugins >/dev/null + omarchy-shell -q shell rescanPlugins fi exit $rc diff --git a/test/shell.d/plugin-rescan-test.sh b/test/shell.d/plugin-rescan-test.sh new file mode 100755 index 000000000000..301e4d0880c1 --- /dev/null +++ b/test/shell.d/plugin-rescan-test.sh @@ -0,0 +1,196 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +require_command git +require_command jq + +TMPDIR=$(mktemp -d) +trap 'rm -rf "$TMPDIR"' EXIT + +git_quiet() { + git -c user.name=Test -c user.email=test@example.com -c init.defaultBranch=main "$@" +} + +write_plugin() { + local dir="$1" + local id="$2" + local name="$3" + + mkdir -p "$dir" + cat >"$dir/manifest.json" <"$dir/Widget.qml" +} + +# A shell that answers everything except rescanPlugins, which fails the way a +# real one does when the reload outruns the 2s IPC timeout: a message on stderr +# and exit 1, unless -q asks for best effort. The plugin commands must survive +# that, because they run under `set -e` and the rescan is the last thing they +# need from the shell, not something their own work depends on. +stub_dir="$TMPDIR/stubs" +mkdir -p "$stub_dir" +cat >"$stub_dir/omarchy-shell" <<'STUB' +#!/bin/bash + +quiet=0 +if [[ ${1:-} == "-q" ]]; then + quiet=1 + shift +fi + +if [[ ${2:-} == "rescanPlugins" ]]; then + printf 'rescanPlugins\n' >>"$RESCAN_LOG" + if (( quiet )); then + exit 0 + fi + echo "omarchy-shell is not responding" >&2 + exit 1 +fi + +if [[ ${2:-} == "listPlugins" ]]; then + if [[ -n ${STUB_PLUGINS:-} ]]; then + printf '%s\n' "$STUB_PLUGINS" + else + find "$HOME/.config/omarchy/plugins" -mindepth 2 -maxdepth 2 -name manifest.json -print0 | + xargs -0 -r jq -s 'map({id: .id, enabled: true})' + fi +fi + +if [[ ${2:-} == "listShellConfig" ]]; then + printf '%s\n' "${STUB_SHELL_CONFIG:-\{\}}" +fi + +exit 0 +STUB +chmod +x "$stub_dir/omarchy-shell" + +export RESCAN_LOG="$TMPDIR/rescans" +: >"$RESCAN_LOG" + +run_plugin_cmd() { + local home="$1" + shift + + HOME="$home" OMARCHY_PATH="$ROOT" PATH="$stub_dir:$ROOT/bin:$PATH" "$@" +} + +# --- update --------------------------------------------------------------- +# +# The rescan is the very last statement, so a failure there can only change the +# exit code, never the outcome: every plugin is already fast forwarded when it +# runs. Reporting failure for work that succeeded is what breaks callers, and +# #10021 and #10326 both want to run this from `omarchy update`. + +update_home="$TMPDIR/update-home" +mkdir -p "$update_home/.config/omarchy/plugins" + +origin="$TMPDIR/origin" +write_plugin "$origin" "acme.updatable" "Updatable" +git_quiet -C "$origin" init -q +git_quiet -C "$origin" add . +git_quiet -C "$origin" commit -qm "Initial" + +installed="$update_home/.config/omarchy/plugins/acme.updatable" +git_quiet clone -q "$origin" "$installed" + +printf 'import QtQuick\nItem { objectName: "second" }\n' >"$origin/Widget.qml" +git_quiet -C "$origin" add . +git_quiet -C "$origin" commit -qm "Second" +want=$(git -C "$origin" rev-parse HEAD) + +output=$(run_plugin_cmd "$update_home" omarchy-plugin-update --yes 2>&1) || + fail "plugin update survives a rescan that times out" "$output" +grep -qF "Updated acme.updatable." <<<"$output" || + fail "plugin update reports the update it performed" "$output" +[[ $(git -C "$installed" rev-parse HEAD) == "$want" ]] || + fail "plugin update fast forwards the checkout" "$output" +pass "plugin update exits 0 when the closing rescan times out" + +grep -qF "is not responding" <<<"$output" && + fail "plugin update leaks the best-effort rescan failure to the user" "$output" +pass "plugin update stays quiet about the best-effort rescan" + +# --- remove --------------------------------------------------------------- + +remove_home="$TMPDIR/remove-home" +mkdir -p "$remove_home/.config/omarchy/plugins" +write_plugin "$remove_home/.config/omarchy/plugins/acme.removable" "acme.removable" "Removable" + +output=$(STUB_PLUGINS='[]' run_plugin_cmd "$remove_home" \ + omarchy-plugin-remove acme.removable --yes 2>&1) || + fail "plugin remove survives a rescan that times out" "$output" +[[ ! -e $remove_home/.config/omarchy/plugins/acme.removable ]] || + fail "plugin remove deletes the plugin directory" "$output" +pass "plugin remove exits 0 when the closing rescan times out" + +# --- add ------------------------------------------------------------------ +# +# Here the rescan is not the last statement. An abort there skips the enable +# decision that follows it, which is how a plugin ends up installed but +# disabled with no word about how to enable it. + +add_home="$TMPDIR/add-home" +mkdir -p "$add_home/.config/omarchy/plugins" + +source_repo="$TMPDIR/source-repo" +write_plugin "$source_repo" "acme.addable" "Addable" +git_quiet -C "$source_repo" init -q +git_quiet -C "$source_repo" add . +git_quiet -C "$source_repo" commit -qm "Initial" + +output=$(run_plugin_cmd "$add_home" omarchy-plugin-add "$source_repo" --yes 2>&1) || + fail "plugin add survives a rescan that times out" "$output" +[[ -f $add_home/.config/omarchy/plugins/acme.addable/manifest.json ]] || + fail "plugin add installs the plugin" "$output" +grep -qF "omarchy plugin enable acme.addable" <<<"$output" || + fail "plugin add still reaches the enable decision after the rescan" "$output" +pass "plugin add reaches the enable decision when the rescan times out" + +# --- clone ---------------------------------------------------------------- +# +# Same shape as add: the clone is on disk when the rescan runs, but discovery, +# enable and the closing message all come after it. + +clone_home="$TMPDIR/clone-home" +mkdir -p "$clone_home/.config/omarchy" "$TMPDIR/clone-stubs" +cp "$stub_dir/omarchy-shell" "$TMPDIR/clone-stubs/omarchy-shell" +for command in omarchy-plugin-enable omarchy-notification-send; do + printf '#!/bin/bash\nexit 0\n' >"$TMPDIR/clone-stubs/$command" +done +chmod +x "$TMPDIR/clone-stubs/"* + +output=$(HOME="$clone_home" USER=tester OMARCHY_PATH="$ROOT" \ + PATH="$TMPDIR/clone-stubs:$ROOT/bin:$PATH" \ + STUB_SHELL_CONFIG='{"bar":{"layout":{"left":[{"id":"omarchy.clock"}],"center":[],"right":[]}}}' \ + omarchy-plugin-clone omarchy.clock 2>&1) || + fail "plugin clone survives a rescan that times out" "$output" +[[ -f $clone_home/.config/omarchy/plugins/tester.clock/manifest.json ]] || + fail "plugin clone writes the clone" "$output" +grep -qF "switched to tester.clock" <<<"$output" || + fail "plugin clone reaches its closing message after the rescan" "$output" +pass "plugin clone completes when the rescan times out" + +# --- the rescan is still attempted ---------------------------------------- +# +# Best effort must not become no effort: -q swallows the failure, it does not +# skip the call. + +(( $(grep -c 'rescanPlugins' "$RESCAN_LOG") == 4 )) || + fail "each command still asks the shell to rescan" "$(cat "$RESCAN_LOG")" +pass "update, remove, add and clone all still request a rescan" From 9acc5c0870065ffeee6dbbd98e6976d182aeea22 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:29:28 +0100 Subject: [PATCH 2/2] Drop the stub-driven rescan test After the merge with quattro, omarchy-plugin-update asks for reloadPlugins, so the test's exact count of four rescanPlugins calls fails, and its update case no longer reaches the failure it stubs. Rather than rework it, drop it: quattro's AGENTS.md asks that a small change get no new test file, that tests not exercise their own stub, and that tests stay in proportion to the change. The fix itself is the same -q flag on four calls, the pattern ten other commands already use for best-effort IPC. Co-Authored-By: Claude Opus 5.5 --- test/shell.d/plugin-rescan-test.sh | 196 ----------------------------- 1 file changed, 196 deletions(-) delete mode 100755 test/shell.d/plugin-rescan-test.sh diff --git a/test/shell.d/plugin-rescan-test.sh b/test/shell.d/plugin-rescan-test.sh deleted file mode 100755 index 301e4d0880c1..000000000000 --- a/test/shell.d/plugin-rescan-test.sh +++ /dev/null @@ -1,196 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" - -require_command git -require_command jq - -TMPDIR=$(mktemp -d) -trap 'rm -rf "$TMPDIR"' EXIT - -git_quiet() { - git -c user.name=Test -c user.email=test@example.com -c init.defaultBranch=main "$@" -} - -write_plugin() { - local dir="$1" - local id="$2" - local name="$3" - - mkdir -p "$dir" - cat >"$dir/manifest.json" <"$dir/Widget.qml" -} - -# A shell that answers everything except rescanPlugins, which fails the way a -# real one does when the reload outruns the 2s IPC timeout: a message on stderr -# and exit 1, unless -q asks for best effort. The plugin commands must survive -# that, because they run under `set -e` and the rescan is the last thing they -# need from the shell, not something their own work depends on. -stub_dir="$TMPDIR/stubs" -mkdir -p "$stub_dir" -cat >"$stub_dir/omarchy-shell" <<'STUB' -#!/bin/bash - -quiet=0 -if [[ ${1:-} == "-q" ]]; then - quiet=1 - shift -fi - -if [[ ${2:-} == "rescanPlugins" ]]; then - printf 'rescanPlugins\n' >>"$RESCAN_LOG" - if (( quiet )); then - exit 0 - fi - echo "omarchy-shell is not responding" >&2 - exit 1 -fi - -if [[ ${2:-} == "listPlugins" ]]; then - if [[ -n ${STUB_PLUGINS:-} ]]; then - printf '%s\n' "$STUB_PLUGINS" - else - find "$HOME/.config/omarchy/plugins" -mindepth 2 -maxdepth 2 -name manifest.json -print0 | - xargs -0 -r jq -s 'map({id: .id, enabled: true})' - fi -fi - -if [[ ${2:-} == "listShellConfig" ]]; then - printf '%s\n' "${STUB_SHELL_CONFIG:-\{\}}" -fi - -exit 0 -STUB -chmod +x "$stub_dir/omarchy-shell" - -export RESCAN_LOG="$TMPDIR/rescans" -: >"$RESCAN_LOG" - -run_plugin_cmd() { - local home="$1" - shift - - HOME="$home" OMARCHY_PATH="$ROOT" PATH="$stub_dir:$ROOT/bin:$PATH" "$@" -} - -# --- update --------------------------------------------------------------- -# -# The rescan is the very last statement, so a failure there can only change the -# exit code, never the outcome: every plugin is already fast forwarded when it -# runs. Reporting failure for work that succeeded is what breaks callers, and -# #10021 and #10326 both want to run this from `omarchy update`. - -update_home="$TMPDIR/update-home" -mkdir -p "$update_home/.config/omarchy/plugins" - -origin="$TMPDIR/origin" -write_plugin "$origin" "acme.updatable" "Updatable" -git_quiet -C "$origin" init -q -git_quiet -C "$origin" add . -git_quiet -C "$origin" commit -qm "Initial" - -installed="$update_home/.config/omarchy/plugins/acme.updatable" -git_quiet clone -q "$origin" "$installed" - -printf 'import QtQuick\nItem { objectName: "second" }\n' >"$origin/Widget.qml" -git_quiet -C "$origin" add . -git_quiet -C "$origin" commit -qm "Second" -want=$(git -C "$origin" rev-parse HEAD) - -output=$(run_plugin_cmd "$update_home" omarchy-plugin-update --yes 2>&1) || - fail "plugin update survives a rescan that times out" "$output" -grep -qF "Updated acme.updatable." <<<"$output" || - fail "plugin update reports the update it performed" "$output" -[[ $(git -C "$installed" rev-parse HEAD) == "$want" ]] || - fail "plugin update fast forwards the checkout" "$output" -pass "plugin update exits 0 when the closing rescan times out" - -grep -qF "is not responding" <<<"$output" && - fail "plugin update leaks the best-effort rescan failure to the user" "$output" -pass "plugin update stays quiet about the best-effort rescan" - -# --- remove --------------------------------------------------------------- - -remove_home="$TMPDIR/remove-home" -mkdir -p "$remove_home/.config/omarchy/plugins" -write_plugin "$remove_home/.config/omarchy/plugins/acme.removable" "acme.removable" "Removable" - -output=$(STUB_PLUGINS='[]' run_plugin_cmd "$remove_home" \ - omarchy-plugin-remove acme.removable --yes 2>&1) || - fail "plugin remove survives a rescan that times out" "$output" -[[ ! -e $remove_home/.config/omarchy/plugins/acme.removable ]] || - fail "plugin remove deletes the plugin directory" "$output" -pass "plugin remove exits 0 when the closing rescan times out" - -# --- add ------------------------------------------------------------------ -# -# Here the rescan is not the last statement. An abort there skips the enable -# decision that follows it, which is how a plugin ends up installed but -# disabled with no word about how to enable it. - -add_home="$TMPDIR/add-home" -mkdir -p "$add_home/.config/omarchy/plugins" - -source_repo="$TMPDIR/source-repo" -write_plugin "$source_repo" "acme.addable" "Addable" -git_quiet -C "$source_repo" init -q -git_quiet -C "$source_repo" add . -git_quiet -C "$source_repo" commit -qm "Initial" - -output=$(run_plugin_cmd "$add_home" omarchy-plugin-add "$source_repo" --yes 2>&1) || - fail "plugin add survives a rescan that times out" "$output" -[[ -f $add_home/.config/omarchy/plugins/acme.addable/manifest.json ]] || - fail "plugin add installs the plugin" "$output" -grep -qF "omarchy plugin enable acme.addable" <<<"$output" || - fail "plugin add still reaches the enable decision after the rescan" "$output" -pass "plugin add reaches the enable decision when the rescan times out" - -# --- clone ---------------------------------------------------------------- -# -# Same shape as add: the clone is on disk when the rescan runs, but discovery, -# enable and the closing message all come after it. - -clone_home="$TMPDIR/clone-home" -mkdir -p "$clone_home/.config/omarchy" "$TMPDIR/clone-stubs" -cp "$stub_dir/omarchy-shell" "$TMPDIR/clone-stubs/omarchy-shell" -for command in omarchy-plugin-enable omarchy-notification-send; do - printf '#!/bin/bash\nexit 0\n' >"$TMPDIR/clone-stubs/$command" -done -chmod +x "$TMPDIR/clone-stubs/"* - -output=$(HOME="$clone_home" USER=tester OMARCHY_PATH="$ROOT" \ - PATH="$TMPDIR/clone-stubs:$ROOT/bin:$PATH" \ - STUB_SHELL_CONFIG='{"bar":{"layout":{"left":[{"id":"omarchy.clock"}],"center":[],"right":[]}}}' \ - omarchy-plugin-clone omarchy.clock 2>&1) || - fail "plugin clone survives a rescan that times out" "$output" -[[ -f $clone_home/.config/omarchy/plugins/tester.clock/manifest.json ]] || - fail "plugin clone writes the clone" "$output" -grep -qF "switched to tester.clock" <<<"$output" || - fail "plugin clone reaches its closing message after the rescan" "$output" -pass "plugin clone completes when the rescan times out" - -# --- the rescan is still attempted ---------------------------------------- -# -# Best effort must not become no effort: -q swallows the failure, it does not -# skip the call. - -(( $(grep -c 'rescanPlugins' "$RESCAN_LOG") == 4 )) || - fail "each command still asks the shell to rescan" "$(cat "$RESCAN_LOG")" -pass "update, remove, add and clone all still request a rescan"