Skip to content
Merged
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
29 changes: 24 additions & 5 deletions bin/omarchy-bar
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,37 @@ bar_widget_default_section() {
}

# Asks the shell to place a widget, waiting out one still coming up. Answers 0
# with the reply in PUT_RESULT, 1 when there was no shell to ask. Only an
# absent shell is carried on from: omarchy-migrate marks a 0 return as done.
# with the reply in PUT_RESULT, 1 when there was no definitive answer to act
# on (no shell, or one that never settled). A 1 is carried on from: the caller
# treats it as done, so a shell that cannot be asked must not fail the update
# (omacom/omarchy#13301).
PUT_RESULT=""
SHELL_ANSWERED=0
ask_to_put() {
local id="$1" placement="$2" attempt absent=0
local id="$1" placement="$2" attempt absent=0 timeouts=0
for (( attempt = 0; attempt < ${OMARCHY_SHELL_READY_ATTEMPTS:-50}; attempt++ )); do
if PUT_RESULT=$(omarchy-shell shell putBarWidget "$id" "$placement" 2>&1); then
SHELL_ANSWERED=1
[[ $PUT_RESULT == "not ready" ]] || return 0
elif [[ $PUT_RESULT == *"not ready"* ]]; then
SHELL_ANSWERED=1
elif [[ $PUT_RESULT == *"is not responding"* ]]; then
# A transient IPC timeout, not a verdict: identical putBarWidget calls
# flap ok/fail within minutes on the same machine, and the 2s default
# window is racy right after an update drops new code into the shell.
# Ask again instead of failing on the first miss; a put that landed late
# is left where it is. Each miss costs the whole window, so only a few.
SHELL_ANSWERED=1
if (( timeouts == 0 )); then
echo "omarchy-shell is not responding; asking again" >&2
fi
if (( ++timeouts >= ${OMARCHY_SHELL_TIMEOUT_ATTEMPTS:-5} )); then
break
fi
elif [[ $PUT_RESULT == *"is not running"* ]]; then
# Answered once and now gone: it stopped mid-request.
if (( SHELL_ANSWERED )); then
fail "omarchy-shell did not become ready; $id was not put on the bar"
break
fi
# A shell being spawned has no socket yet, and nothing says a launch is
# under way, so give one a few seconds to turn up.
Expand All @@ -259,7 +274,11 @@ ask_to_put() {
fi
sleep 0.1
done
fail "omarchy-shell did not become ready; $id was not put on the bar"
# Never a definitive answer. Carried on like an absent shell — the update
# finishes and the migration marks done — rather than wedging every
# subsequent update on a shell that keeps timing out.
echo "omarchy-shell did not become ready; $id was not put on the bar" >&2
return 1
}

# Placement lives in the shell, which owns the config it has in memory. Putting
Expand Down
51 changes: 42 additions & 9 deletions test/shell.d/bar-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,20 @@ case ${OMARCHY_TEST_SHELL_STATE:-ready} in
echo "Function not found." >&2
exit 1
;;
flapping)
# IPC timeout on every ask: the 2s default window keeps expiring.
echo >>"$OMARCHY_TEST_SHELL_MARKER"
echo "omarchy-shell is not responding" >&2
exit 1
;;
slow)
# Misses the IPC window once, then answers.
if [[ ! -e $OMARCHY_TEST_SHELL_MARKER ]]; then
touch "$OMARCHY_TEST_SHELL_MARKER"
echo "omarchy-shell is not responding" >&2
exit 1
fi
;;
scanning)
# Answering IPC, but has not read the plugins yet.
if [[ ! -e $OMARCHY_TEST_SHELL_MARKER ]]; then
Expand Down Expand Up @@ -442,17 +456,36 @@ put_output=$(PATH="$put_tmp/bin:$ROOT/bin:$PATH" OMARCHY_TEST_SHELL_STATE=spawni
pass "put waits for a shell that is being spawned"

put_output=$(PATH="$put_tmp/bin:$ROOT/bin:$PATH" OMARCHY_TEST_SHELL_STATE=starting OMARCHY_SHELL_READY_ATTEMPTS=2 \
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) &&
fail "put fails when the shell never becomes ready" "$put_output"
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) ||
fail "put carries on when the shell never becomes ready" "$put_output"
[[ $put_output == *"did not become ready"* ]] || fail "put says the shell never became ready" "$put_output"
pass "put fails when the shell never becomes ready"
pass "put carries on when the shell never becomes ready"

put_output=$(PATH="$put_tmp/bin:$ROOT/bin:$PATH" OMARCHY_TEST_SHELL_STATE=slow \
OMARCHY_TEST_SHELL_MARKER="$put_tmp/slow" \
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) ||
fail "put asks again after a timeout" "$put_output"
[[ $put_output == *"omarchy.keyboard-layout is on the bar" ]] || fail "put places once the shell answers in time" "$put_output"
pass "put asks again when the shell misses the IPC window"

# A shell that answers nothing but IPC timeouts must be carried on from the
# same way: failing the first timeout wedges every subsequent update on a
# shell that keeps missing the 2s window (omacom/omarchy#13301), and asking
# it the full ready budget holds the update for over a minute.
put_output=$(PATH="$put_tmp/bin:$ROOT/bin:$PATH" OMARCHY_TEST_SHELL_STATE=flapping OMARCHY_SHELL_TIMEOUT_ATTEMPTS=2 \
OMARCHY_TEST_SHELL_MARKER="$put_tmp/timeouts" \
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) ||
fail "put carries on when the shell only times out" "$put_output"
[[ $put_output == *"did not become ready"* ]] || fail "put says the shell never settled" "$put_output"
(( $(wc -l <"$put_tmp/timeouts") == 2 )) || fail "put stops asking a shell that keeps timing out" "$put_output"
pass "put gives up on a shell that keeps timing out"

put_output=$(PATH="$put_tmp/bin:$ROOT/bin:$PATH" OMARCHY_TEST_SHELL_STATE=crashing \
OMARCHY_TEST_SHELL_MARKER="$put_tmp/started" \
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) &&
fail "put fails when a starting shell disappears" "$put_output"
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) ||
fail "put carries on when a starting shell disappears" "$put_output"
[[ $put_output == *"did not become ready"* ]] || fail "put keeps a lost shell retryable" "$put_output"
pass "put fails when a starting shell disappears"
pass "put carries on when a starting shell disappears"

put_output=$(PATH="$put_tmp/bin:$ROOT/bin:$PATH" OMARCHY_TEST_SHELL_STATE=oldshell \
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) ||
Expand All @@ -462,10 +495,10 @@ pass "put falls back against a shell that has not restarted yet"

put_output=$(PATH="$put_tmp/bin:$ROOT/bin:$PATH" OMARCHY_TEST_SHELL_STATE=vanishing \
OMARCHY_TEST_SHELL_MARKER="$put_tmp/vanished" \
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) &&
fail "put fails when the shell goes away mid-fallback" "$put_output"
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) ||
fail "put carries on when the shell goes away mid-fallback" "$put_output"
[[ $put_output == *"did not become ready"* ]] || fail "put remembers the shell answered once" "$put_output"
pass "put fails when the shell goes away mid-fallback"
pass "put carries on when the shell goes away mid-fallback"

put_output=$(PATH="$put_tmp/bin:$ROOT/bin:$PATH" OMARCHY_TEST_SHELL_STATE=unsupported \
"$ROOT/bin/omarchy-bar" put omarchy.keyboard-layout --after omarchy.clock 2>&1) &&
Expand Down
Loading