Unify Omarchy migrations
This commit is contained in:
@@ -276,11 +276,12 @@ jq -e '
|
||||
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
|
||||
pass "shell config removes widgets with remove alias"
|
||||
|
||||
mapfile -t migrations < <(find "$ROOT/migrations" -maxdepth 1 -type f -name '*.sh' -printf '%f\n' | sort)
|
||||
[[ ${#migrations[@]} -eq 0 ]] || fail "4.0 upgrade is not modeled as a migration"
|
||||
if grep -RIl 'upgrade-to-4\|Omarchy 4\.0 is upgraded' "$ROOT/migrations" >/dev/null; then
|
||||
fail "4.0 upgrade is not modeled as a migration"
|
||||
fi
|
||||
pass "4.0 upgrade is handled outside the migration runner"
|
||||
|
||||
clock_migration=$(grep -rl 'Remove leading zero from bar clock date' "$ROOT/migrations/user" | head -n 1 || true)
|
||||
clock_migration=$(grep -rl 'Remove leading zero from bar clock date' "$ROOT/migrations" | head -n 1 || true)
|
||||
[[ -n $clock_migration ]] || fail "clock date format user migration exists"
|
||||
|
||||
cat >"$TMPDIR/home/.config/omarchy/shell.json" <<'JSON'
|
||||
|
||||
@@ -11,16 +11,16 @@ stub_bin="$test_tmp/bin"
|
||||
test_home="$test_tmp/home"
|
||||
mkdir -p "$stub_bin" "$test_home"
|
||||
|
||||
cat >"$stub_bin/omarchy-migrate-user" <<'SH'
|
||||
cat >"$stub_bin/omarchy-migrate" <<'SH'
|
||||
#!/bin/bash
|
||||
if [[ ${1:-} == "--pending" && ${OMARCHY_TEST_PENDING_MIGRATIONS:-0} == 1 ]]; then
|
||||
echo 200-user.sh
|
||||
echo 200-migration.sh
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
SH
|
||||
chmod +x "$stub_bin/omarchy-migrate-user"
|
||||
chmod +x "$stub_bin/omarchy-migrate"
|
||||
|
||||
cat >"$stub_bin/systemd-run" <<'SH'
|
||||
#!/bin/bash
|
||||
@@ -41,6 +41,6 @@ run_notify 0 >"$test_tmp/not-pending.out" 2>"$test_tmp/not-pending.err"
|
||||
pass "migration notifier ignores users with no pending migrations"
|
||||
|
||||
run_notify 1 >"$test_tmp/pending.out" 2>"$test_tmp/pending.err"
|
||||
grep -q 'Omarchy has pending user migrations' "$test_tmp/pending.err" || fail "migration notifier explains pending migrations without notification system"
|
||||
grep -q 'user/200-user.sh' "$test_tmp/pending.err" || fail "migration notifier lists pending migration names"
|
||||
pass "migration notifier reports pending user migrations"
|
||||
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"
|
||||
|
||||
@@ -9,107 +9,69 @@ trap 'rm -rf "$test_tmp"' EXIT
|
||||
|
||||
test_root="$test_tmp/omarchy"
|
||||
test_home="$test_tmp/home"
|
||||
system_state="$test_tmp/system-state"
|
||||
mkdir -p "$test_root/migrations/system" "$test_root/migrations/user" "$test_home" "$system_state"
|
||||
mkdir -p "$test_root/migrations" "$test_home"
|
||||
|
||||
cat >"$test_root/migrations/system/100-system.sh" <<'SH'
|
||||
cat >"$test_root/migrations/100-first.sh" <<'SH'
|
||||
[[ $OMARCHY_PATH == "$TEST_EXPECTED_OMARCHY_PATH" ]]
|
||||
echo system >>"$TEST_CALLS"
|
||||
echo first >>"$TEST_CALLS"
|
||||
SH
|
||||
cat >"$test_root/migrations/user/200-user.sh" <<'SH'
|
||||
cat >"$test_root/migrations/200-second.sh" <<'SH'
|
||||
[[ $OMARCHY_PATH == "$TEST_EXPECTED_OMARCHY_PATH" ]]
|
||||
echo user >>"$TEST_CALLS"
|
||||
echo second >>"$TEST_CALLS"
|
||||
SH
|
||||
|
||||
calls="$test_tmp/calls"
|
||||
|
||||
if ! HOME="$test_home" OMARCHY_PATH="$test_root" "$ROOT/bin/omarchy-migrate-user" --pending >"$test_tmp/user-pending.out"; then
|
||||
fail "user migration runner reports pending migrations before state exists"
|
||||
if ! HOME="$test_home" OMARCHY_PATH="$test_root" "$ROOT/bin/omarchy-migrate" --pending >"$test_tmp/pending.out"; then
|
||||
fail "migration runner reports pending migrations before state exists"
|
||||
fi
|
||||
grep -q '^200-user\.sh$' "$test_tmp/user-pending.out" || fail "user migration runner lists pending migration filename"
|
||||
pass "user migration runner detects pending migrations"
|
||||
grep -q '^100-first\.sh$' "$test_tmp/pending.out" || fail "migration runner lists first pending migration filename"
|
||||
grep -q '^200-second\.sh$' "$test_tmp/pending.out" || fail "migration runner lists second pending migration filename"
|
||||
pass "migration runner detects pending migrations"
|
||||
|
||||
HOME="$test_home" \
|
||||
OMARCHY_PATH="$test_root" \
|
||||
TEST_EXPECTED_OMARCHY_PATH="$test_root" \
|
||||
TEST_CALLS="$calls" \
|
||||
"$ROOT/bin/omarchy-migrate-user" >"$test_tmp/user-first.out"
|
||||
[[ $(grep -c '^user$' "$calls") -eq 1 ]] || fail "user migration runner runs user migrations"
|
||||
! grep -q '^system$' "$calls" || fail "user migration runner does not run system migrations"
|
||||
[[ -f $test_home/.local/state/omarchy/migrations/user/200-user.sh ]] || fail "user migration runner records user migration marker"
|
||||
pass "user migration runner only runs user migrations"
|
||||
"$ROOT/bin/omarchy-migrate" >"$test_tmp/first-run.out"
|
||||
[[ $(sed -n '1p' "$calls") == "first" ]] || fail "migration runner runs first migration"
|
||||
[[ $(sed -n '2p' "$calls") == "second" ]] || fail "migration runner runs second migration"
|
||||
[[ -f $test_home/.local/state/omarchy/migrations/100-first.sh ]] || fail "migration runner records first migration marker"
|
||||
[[ -f $test_home/.local/state/omarchy/migrations/200-second.sh ]] || fail "migration runner records second migration marker"
|
||||
pass "migration runner runs all migrations"
|
||||
|
||||
HOME="$test_home" \
|
||||
OMARCHY_PATH="$test_root" \
|
||||
TEST_EXPECTED_OMARCHY_PATH="$test_root" \
|
||||
TEST_CALLS="$calls" \
|
||||
"$ROOT/bin/omarchy-migrate-user" >"$test_tmp/user-second.out"
|
||||
[[ $(grep -c '^user$' "$calls") -eq 1 ]] || fail "user migration runner skips completed migrations"
|
||||
pass "user migration runner skips completed migrations"
|
||||
"$ROOT/bin/omarchy-migrate" >"$test_tmp/second-run.out"
|
||||
[[ $(wc -l <"$calls") -eq 2 ]] || fail "migration runner skips completed migrations"
|
||||
pass "migration runner skips completed migrations"
|
||||
|
||||
if HOME="$test_home" OMARCHY_PATH="$test_root" "$ROOT/bin/omarchy-migrate-user" --pending >"$test_tmp/user-not-pending.out"; then
|
||||
fail "user migration runner reports no pending migrations after state exists"
|
||||
if HOME="$test_home" OMARCHY_PATH="$test_root" "$ROOT/bin/omarchy-migrate" --pending >"$test_tmp/not-pending.out"; then
|
||||
fail "migration runner reports no pending migrations after state exists"
|
||||
fi
|
||||
pass "user migration runner detects no pending migrations"
|
||||
|
||||
if ! OMARCHY_PATH="$test_root" OMARCHY_SYSTEM_MIGRATION_STATE="$system_state" "$ROOT/bin/omarchy-migrate-system" --pending >"$test_tmp/system-pending.out"; then
|
||||
fail "system migration runner reports pending migrations before state exists"
|
||||
fi
|
||||
grep -q '^100-system\.sh$' "$test_tmp/system-pending.out" || fail "system migration runner lists pending migration filename"
|
||||
|
||||
OMARCHY_PATH="$test_root" \
|
||||
OMARCHY_SYSTEM_MIGRATION_STATE="$system_state" \
|
||||
TEST_EXPECTED_OMARCHY_PATH="$test_root" \
|
||||
TEST_CALLS="$calls" \
|
||||
"$ROOT/bin/omarchy-migrate-system" >"$test_tmp/system-first.out"
|
||||
[[ $(grep -c '^system$' "$calls") -eq 1 ]] || fail "system migration runner runs system migrations"
|
||||
[[ -f $system_state/100-system.sh ]] || fail "system migration runner records system migration marker"
|
||||
pass "system migration runner only runs system migrations"
|
||||
|
||||
if OMARCHY_PATH="$test_root" OMARCHY_SYSTEM_MIGRATION_STATE="$system_state" "$ROOT/bin/omarchy-migrate-system" --pending >"$test_tmp/system-not-pending.out"; then
|
||||
fail "system migration runner reports no pending migrations after state exists"
|
||||
fi
|
||||
pass "system migration runner detects no pending migrations"
|
||||
pass "migration runner detects no pending migrations"
|
||||
|
||||
failure_root="$test_tmp/failure-omarchy"
|
||||
failure_home="$test_tmp/failure-home"
|
||||
failure_system_state="$test_tmp/failure-system-state"
|
||||
mkdir -p "$failure_root/migrations/system" "$failure_root/migrations/user" "$failure_home" "$failure_system_state"
|
||||
mkdir -p "$failure_root/migrations" "$failure_home"
|
||||
|
||||
cat >"$failure_root/migrations/user/300-fail-user.sh" <<'SH'
|
||||
echo user-before-fail >>"$TEST_CALLS"
|
||||
cat >"$failure_root/migrations/500-fail.sh" <<'SH'
|
||||
echo before-fail >>"$TEST_CALLS"
|
||||
false
|
||||
echo user-after-fail >>"$TEST_CALLS"
|
||||
echo after-fail >>"$TEST_CALLS"
|
||||
SH
|
||||
|
||||
set +e
|
||||
HOME="$failure_home" \
|
||||
OMARCHY_PATH="$failure_root" \
|
||||
TEST_CALLS="$calls" \
|
||||
"$ROOT/bin/omarchy-migrate-user" >"$test_tmp/user-failure.out" 2>"$test_tmp/user-failure.err"
|
||||
user_failure_status=$?
|
||||
"$ROOT/bin/omarchy-migrate" >"$test_tmp/failure.out" 2>"$test_tmp/failure.err"
|
||||
failure_status=$?
|
||||
set -e
|
||||
[[ $user_failure_status -ne 0 ]] || fail "user migration runner exits non-zero when a migration fails"
|
||||
[[ ! -f $failure_home/.local/state/omarchy/migrations/user/300-fail-user.sh ]] || fail "user migration runner does not mark failed migration complete"
|
||||
grep -q '^user-before-fail$' "$calls" || fail "user migration runner started failing migration"
|
||||
! grep -q '^user-after-fail$' "$calls" || fail "user migration runner stops failing migration under strict mode"
|
||||
pass "user migration runner does not mark failed migrations complete"
|
||||
|
||||
cat >"$failure_root/migrations/system/400-fail-system.sh" <<'SH'
|
||||
echo system-before-fail >>"$TEST_CALLS"
|
||||
false
|
||||
echo system-after-fail >>"$TEST_CALLS"
|
||||
SH
|
||||
|
||||
set +e
|
||||
OMARCHY_PATH="$failure_root" \
|
||||
OMARCHY_SYSTEM_MIGRATION_STATE="$failure_system_state" \
|
||||
TEST_CALLS="$calls" \
|
||||
"$ROOT/bin/omarchy-migrate-system" >"$test_tmp/system-failure.out" 2>"$test_tmp/system-failure.err"
|
||||
system_failure_status=$?
|
||||
set -e
|
||||
[[ $system_failure_status -ne 0 ]] || fail "system migration runner exits non-zero when a migration fails"
|
||||
[[ ! -f $failure_system_state/400-fail-system.sh ]] || fail "system migration runner does not mark failed migration complete"
|
||||
grep -q '^system-before-fail$' "$calls" || fail "system migration runner started failing migration"
|
||||
! grep -q '^system-after-fail$' "$calls" || fail "system migration runner stops failing migration under strict mode"
|
||||
pass "system migration runner does not mark failed migrations complete"
|
||||
[[ $failure_status -ne 0 ]] || fail "migration runner exits non-zero when a migration fails"
|
||||
[[ ! -f $failure_home/.local/state/omarchy/migrations/500-fail.sh ]] || fail "migration runner does not mark failed migration complete"
|
||||
grep -q '^before-fail$' "$calls" || fail "migration runner started failing migration"
|
||||
! grep -q '^after-fail$' "$calls" || fail "migration runner stops failing migration under strict mode"
|
||||
pass "migration runner does not mark failed migrations complete"
|
||||
|
||||
@@ -7,57 +7,33 @@ source "$(dirname "$0")/base-test.sh"
|
||||
test_tmp=$(mktemp -d)
|
||||
trap 'rm -rf "$test_tmp"' EXIT
|
||||
|
||||
stub_bin="$test_tmp/bin"
|
||||
test_root="$test_tmp/omarchy"
|
||||
test_home="$test_tmp/home"
|
||||
mkdir -p "$stub_bin" "$test_home"
|
||||
mkdir -p "$test_root/migrations" "$test_home"
|
||||
|
||||
cat >"$stub_bin/omarchy-migrate-system" <<'SH'
|
||||
#!/bin/bash
|
||||
if [[ ${1:-} == "--pending" ]]; then
|
||||
[[ ${OMARCHY_TEST_PENDING_SYSTEM:-1} == 1 ]] || exit 1
|
||||
echo 100-system.sh
|
||||
exit 0
|
||||
fi
|
||||
echo system >>"$TEST_CALLS"
|
||||
cat >"$test_root/migrations/100-migration.sh" <<'SH'
|
||||
echo migration >>"$TEST_CALLS"
|
||||
SH
|
||||
chmod +x "$stub_bin/omarchy-migrate-system"
|
||||
|
||||
cat >"$stub_bin/omarchy-migrate-user" <<'SH'
|
||||
#!/bin/bash
|
||||
if [[ ${1:-} == "--pending" ]]; then
|
||||
[[ ${OMARCHY_TEST_PENDING_USER:-1} == 1 ]] || exit 1
|
||||
echo 200-user.sh
|
||||
exit 0
|
||||
fi
|
||||
echo user >>"$TEST_CALLS"
|
||||
SH
|
||||
chmod +x "$stub_bin/omarchy-migrate-user"
|
||||
|
||||
run_migrate() {
|
||||
HOME="$test_home" \
|
||||
PATH="$stub_bin:$PATH" \
|
||||
OMARCHY_PATH="$test_root" \
|
||||
TEST_CALLS="$test_tmp/calls" \
|
||||
"$ROOT/bin/omarchy-migrate" "$@"
|
||||
}
|
||||
|
||||
: >"$test_tmp/calls"
|
||||
run_migrate >"$test_tmp/migrate.out"
|
||||
[[ $(sed -n '1p' "$test_tmp/calls") == "system" ]] || fail "omarchy-migrate runs system migrations first"
|
||||
[[ $(sed -n '2p' "$test_tmp/calls") == "user" ]] || fail "omarchy-migrate runs user migrations second"
|
||||
[[ $(wc -l <"$test_tmp/calls") -eq 2 ]] || fail "omarchy-migrate only delegates to system and user migration runners"
|
||||
pass "omarchy-migrate runs system and user migrations without force"
|
||||
[[ $(sed -n '1p' "$test_tmp/calls") == "migration" ]] || fail "omarchy-migrate runs pending migrations"
|
||||
pass "omarchy-migrate runs migrations without force"
|
||||
|
||||
run_migrate --pending >"$test_tmp/pending-all.out"
|
||||
grep -q '^system/100-system\.sh$' "$test_tmp/pending-all.out" || fail "omarchy-migrate --pending lists pending system migrations"
|
||||
grep -q '^user/200-user\.sh$' "$test_tmp/pending-all.out" || fail "omarchy-migrate --pending lists pending user migrations"
|
||||
pass "omarchy-migrate --pending lists all pending migrations"
|
||||
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"
|
||||
pass "omarchy-migrate --pending lists pending migrations"
|
||||
|
||||
run_migrate --pending user >"$test_tmp/pending-user.out"
|
||||
grep -q '^user/200-user\.sh$' "$test_tmp/pending-user.out" || fail "omarchy-migrate --pending user lists user migrations"
|
||||
! grep -q '^system/' "$test_tmp/pending-user.out" || fail "omarchy-migrate --pending user omits system migrations"
|
||||
pass "omarchy-migrate --pending user scopes pending output"
|
||||
|
||||
if OMARCHY_TEST_PENDING_SYSTEM=0 OMARCHY_TEST_PENDING_USER=0 run_migrate --pending >"$test_tmp/not-pending.out"; then
|
||||
run_migrate >"$test_tmp/migrate-second.out"
|
||||
if run_migrate --pending >"$test_tmp/not-pending.out"; then
|
||||
fail "omarchy-migrate --pending exits non-zero without pending migrations"
|
||||
fi
|
||||
[[ ! -s $test_tmp/not-pending.out ]] || fail "omarchy-migrate --pending stays quiet without pending migrations"
|
||||
|
||||
Reference in New Issue
Block a user