Fix pending migration notifications

This commit is contained in:
David Heinemeier Hansson
2026-07-20 11:07:44 -07:00
parent 5232505c12
commit 8719b0d031
4 changed files with 41 additions and 6 deletions
+4
View File
@@ -95,3 +95,7 @@ while IFS=$'\t' read -r name file marker; do
touch "$marker"
fi
done < <(migration_entries)
# Clear notifications queued while an update was installing migrations. The
# substring matches both the current and legacy notification titles.
omarchy-notification-dismiss "Omarchy Migrations" >/dev/null 2>&1 || true
+3 -3
View File
@@ -8,12 +8,12 @@ pending_migrations=$(omarchy-migrate --pending 2>/dev/null) || exit 0
pending_count=$(printf '%s\n' "$pending_migrations" | sed '/^[[:space:]]*$/d' | wc -l)
if (( pending_count == 1 )); then
message="1 new Omarchy migration is available. Click to run it in a terminal."
message="Click to run 1 pending migration."
else
message="$pending_count new Omarchy migrations are available. Click to run them in a terminal."
message="Click to run $pending_count pending migrations."
fi
notify_command=$(printf 'if [[ -n $(omarchy-notification-send -u critical -g  "Run Omarchy Migrations" %q -a) ]]; then omarchy-launch-floating-terminal-with-presentation omarchy-migrate; fi' "$message")
notify_command=$(printf 'if [[ -n $(omarchy-notification-send -u critical -g  "Pending Omarchy Migrations" %q -a) ]]; then omarchy-launch-floating-terminal-with-presentation omarchy-migrate; fi' "$message")
if omarchy-cmd-present systemd-run; then
unit="omarchy-migrations-notification-$(date +%Y%m%d%H%M%S)"
+21 -2
View File
@@ -24,14 +24,27 @@ chmod +x "$stub_bin/omarchy-migrate"
cat >"$stub_bin/systemd-run" <<'SH'
#!/bin/bash
exit 1
if [[ ${OMARCHY_TEST_SYSTEMD_RUN:-run} == "fail" ]]; then
exit 1
fi
command=${!#}
bash -c "$command"
SH
chmod +x "$stub_bin/systemd-run"
cat >"$stub_bin/omarchy-notification-send" <<'SH'
#!/bin/bash
printf '%s\n' "$@" >"$OMARCHY_TEST_NOTIFY_ARGS"
SH
chmod +x "$stub_bin/omarchy-notification-send"
run_notify() {
HOME="$test_home" \
PATH="$stub_bin:$ROOT/bin:$PATH" \
OMARCHY_TEST_PENDING_MIGRATIONS="$1" \
OMARCHY_TEST_NOTIFY_ARGS="$test_tmp/notify-args" \
OMARCHY_TEST_SYSTEMD_RUN="${2:-run}" \
"$ROOT/bin/omarchy-migrate-notify"
}
@@ -40,7 +53,13 @@ run_notify 0 >"$test_tmp/not-pending.out" 2>"$test_tmp/not-pending.err"
[[ ! -s $test_tmp/not-pending.err ]] || fail "migration notifier stays quiet on stderr without pending migrations"
pass "migration notifier ignores users with no pending migrations"
run_notify 1 >"$test_tmp/pending.out" 2>"$test_tmp/pending.err"
run_notify 1 fail >"$test_tmp/pending.out" 2>"$test_tmp/pending.err"
grep -q 'Omarchy has pending migrations' "$test_tmp/pending.err" || fail "migration notifier explains pending migrations without notification system"
grep -q '200-migration.sh' "$test_tmp/pending.err" || fail "migration notifier lists pending migration names"
pass "migration notifier reports pending migrations"
run_notify 1 >"$test_tmp/notified.out" 2>"$test_tmp/notified.err"
grep -Fx 'Pending Omarchy Migrations' "$test_tmp/notify-args" >/dev/null || fail "migration notifier uses pending migrations title"
grep -Fx 'Click to run 1 pending migration.' "$test_tmp/notify-args" >/dev/null || fail "migration notifier describes the pending migration"
grep -Fx '' "$test_tmp/notify-args" >/dev/null || fail "migration notifier includes the large-slot glyph"
pass "migration notifier uses the actionable notification format"
+13 -1
View File
@@ -9,7 +9,14 @@ trap 'rm -rf "$test_tmp"' EXIT
test_root="$test_tmp/omarchy"
test_home="$test_tmp/home"
mkdir -p "$test_root/migrations" "$test_home"
stub_bin="$test_tmp/bin"
mkdir -p "$test_root/migrations" "$test_home" "$stub_bin"
cat >"$stub_bin/omarchy-notification-dismiss" <<'SH'
#!/bin/bash
printf '%s\n' "$1" >>"$TEST_DISMISSALS"
SH
chmod +x "$stub_bin/omarchy-notification-dismiss"
cat >"$test_root/migrations/100-migration.sh" <<'SH'
echo migration >>"$TEST_CALLS"
@@ -18,7 +25,9 @@ SH
run_migrate() {
HOME="$test_home" \
OMARCHY_PATH="$test_root" \
PATH="$stub_bin:$ROOT/bin:$PATH" \
TEST_CALLS="$test_tmp/calls" \
TEST_DISMISSALS="$test_tmp/dismissals" \
"$ROOT/bin/omarchy-migrate" "$@"
}
@@ -27,6 +36,9 @@ run_migrate >"$test_tmp/migrate.out"
[[ $(sed -n '1p' "$test_tmp/calls") == "migration" ]] || fail "omarchy-migrate runs pending migrations"
pass "omarchy-migrate runs migrations without force"
grep -Fx 'Omarchy Migrations' "$test_tmp/dismissals" >/dev/null || fail "omarchy-migrate dismisses migration notifications"
pass "omarchy-migrate clears completed migration notifications"
rm -rf "$test_home/.local/state/omarchy/migrations"
run_migrate --pending >"$test_tmp/pending.out"
grep -q '^100-migration\.sh$' "$test_tmp/pending.out" || fail "omarchy-migrate --pending lists pending migrations"