Add optional service widgets on shell refresh

This commit is contained in:
David Heinemeier Hansson
2026-06-23 16:22:27 +02:00
parent 3fd36802ac
commit b30758dd2d
6 changed files with 197 additions and 0 deletions
+60
View File
@@ -300,6 +300,66 @@ jq -e '
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
pass "shell config removes widgets with remove alias"
mock_bin="$TMPDIR/mock-bin"
mkdir -p "$mock_bin"
cat >"$mock_bin/omarchy-refresh-config" <<'SH'
#!/bin/bash
set -euo pipefail
relative_path="${1:-}"
[[ -n $relative_path ]] || exit 1
mkdir -p "$HOME/.config/$(dirname "$relative_path")"
cp "$OMARCHY_PATH/config/$relative_path" "$HOME/.config/$relative_path"
SH
cat >"$mock_bin/omarchy-restart-shell" <<'SH'
#!/bin/bash
set -euo pipefail
mkdir -p "$HOME/.local/state/omarchy"
touch "$HOME/.local/state/omarchy/restart-shell-called"
SH
cat >"$mock_bin/omarchy-shell" <<'SH'
#!/bin/bash
exit 0
SH
cat >"$mock_bin/omarchy-installed-service-dropbox" <<'SH'
#!/bin/bash
set -euo pipefail
[[ ${OMARCHY_TEST_DROPBOX:-0} == "1" ]]
SH
cat >"$mock_bin/omarchy-installed-service-tailscale" <<'SH'
#!/bin/bash
set -euo pipefail
[[ ${OMARCHY_TEST_TAILSCALE:-0} == "1" ]]
SH
chmod +x "$mock_bin"/*
mock_path="$mock_bin:$ROOT/bin:$PATH"
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" PATH="$mock_path" OMARCHY_TEST_DROPBOX=0 OMARCHY_TEST_TAILSCALE=0 omarchy-refresh-shell
jq -e '
def ids: map(.id // .);
(.bar.layout.right | ids | index("omarchy.dropbox") == null) and
(.bar.layout.right | ids | index("omarchy.tailscale") == null)
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
pass "shell refresh keeps optional service widgets absent when services are unavailable"
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" PATH="$mock_path" OMARCHY_TEST_DROPBOX=1 OMARCHY_TEST_TAILSCALE=1 omarchy-refresh-shell
jq -e '
def ids: map(.id // .);
(.bar.layout.right | ids | index("omarchy.dropbox") != null) and
(.bar.layout.right | ids | index("omarchy.tailscale") != null)
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
[[ -f $TMPDIR/home/.local/state/omarchy/restart-shell-called ]] || fail "shell refresh restarts shell"
pass "shell refresh adds optional service widgets when services are available"
if grep -RIl 'upgrade-to-quattro\|Omarchy 4\.0 is upgraded' "$ROOT/migrations" >/dev/null; then
fail "4.0 upgrade is not modeled as a migration"
fi
+101
View File
@@ -0,0 +1,101 @@
#!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
export PATH="$ROOT/bin:$PATH"
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
mock_bin="$TMPDIR/bin"
mkdir -p "$mock_bin"
cat >"$mock_bin/omarchy-cmd-present" <<'SH'
#!/bin/bash
set -euo pipefail
case "${1:-}" in
dropbox-cli)
[[ ${OMARCHY_TEST_DROPBOX_CLI:-0} == "1" ]]
;;
tailscale)
[[ ${OMARCHY_TEST_TAILSCALE_CLI:-0} == "1" ]]
;;
*)
command -v "${1:-}" >/dev/null 2>&1
;;
esac
SH
cat >"$mock_bin/dropbox-cli" <<'SH'
#!/bin/bash
set -euo pipefail
[[ ${OMARCHY_TEST_DROPBOX_RUNNING:-0} == "1" && ${1:-} == "running" ]]
SH
cat >"$mock_bin/tailscale" <<'SH'
#!/bin/bash
set -euo pipefail
[[ ${OMARCHY_TEST_TAILSCALE_STATUS:-0} == "1" && ${1:-} == "status" && ${2:-} == "--json" ]]
SH
cat >"$mock_bin/systemctl" <<'SH'
#!/bin/bash
set -euo pipefail
[[ ${OMARCHY_TEST_TAILSCALE_SYSTEMD:-0} == "1" ]]
SH
cat >"$mock_bin/pgrep" <<'SH'
#!/bin/bash
set -euo pipefail
if (( $# == 0 )); then
exit 1
fi
name="${!#}"
case "$name" in
dropbox)
[[ ${OMARCHY_TEST_DROPBOX_PROCESS:-0} == "1" ]]
;;
tailscaled)
[[ ${OMARCHY_TEST_TAILSCALE_PROCESS:-0} == "1" ]]
;;
*)
exit 1
;;
esac
SH
chmod +x "$mock_bin"/*
mock_path="$mock_bin:$ROOT/bin:$PATH"
PATH="$mock_path" OMARCHY_TEST_DROPBOX_CLI=1 OMARCHY_TEST_DROPBOX_RUNNING=1 omarchy-installed-service-dropbox
pass "installed Dropbox service check accepts running CLI"
PATH="$mock_path" OMARCHY_TEST_DROPBOX_PROCESS=1 omarchy-installed-service-dropbox
pass "installed Dropbox service check accepts running process"
if PATH="$mock_path" omarchy-installed-service-dropbox; then
fail "installed Dropbox service check rejects unavailable service"
fi
pass "installed Dropbox service check rejects unavailable service"
PATH="$mock_path" OMARCHY_TEST_TAILSCALE_CLI=1 OMARCHY_TEST_TAILSCALE_STATUS=1 omarchy-installed-service-tailscale
pass "installed Tailscale service check accepts status JSON"
PATH="$mock_path" OMARCHY_TEST_TAILSCALE_SYSTEMD=1 omarchy-installed-service-tailscale
pass "installed Tailscale service check accepts active systemd service"
PATH="$mock_path" OMARCHY_TEST_TAILSCALE_PROCESS=1 omarchy-installed-service-tailscale
pass "installed Tailscale service check accepts running daemon"
if PATH="$mock_path" omarchy-installed-service-tailscale; then
fail "installed Tailscale service check rejects unavailable service"
fi
pass "installed Tailscale service check rejects unavailable service"