Restore strict migration ordering

This commit is contained in:
acrogenesis
2026-08-29 22:42:33 -06:00
parent 4d697a063c
commit f91d2e5453
9 changed files with 110 additions and 156 deletions
+22 -60
View File
@@ -76,68 +76,30 @@ grep -q '^before-fail$' "$calls" || fail "migration runner started failing migra
! grep -q '^after-fail$' "$calls" || fail "migration runner stops failing migration under strict mode"
pass "migration runner does not mark failed migrations complete"
deferred_root="$test_tmp/deferred-omarchy"
deferred_home="$test_tmp/deferred-home"
deferred_calls="$test_tmp/deferred-calls"
mkdir -p "$deferred_root/migrations" "$deferred_home"
stdin_root="$test_tmp/stdin-omarchy"
stdin_home="$test_tmp/stdin-home"
stdin_calls="$test_tmp/stdin-calls"
mkdir -p "$stdin_root/migrations" "$stdin_home"
cat >"$deferred_root/migrations/100-deferred.sh" <<'SH'
echo deferred >>"$TEST_CALLS"
printf '%s\n' "$OMARCHY_MIGRATION_DEFER_TOKEN" >"$OMARCHY_MIGRATION_DEFER_FILE"
exit 75
cat >"$stdin_root/migrations/100-reader.sh" <<'SH'
IFS= read -r value
printf 'reader:%s\n' "$value" >>"$TEST_CALLS"
SH
cat >"$deferred_root/migrations/200-after.sh" <<'SH'
echo after >>"$TEST_CALLS"
cat >"$stdin_root/migrations/200-after.sh" <<'SH'
echo after-reader >>"$TEST_CALLS"
SH
HOME="$deferred_home" \
OMARCHY_PATH="$deferred_root" \
TEST_CALLS="$deferred_calls" \
"$ROOT/bin/omarchy-migrate" >"$test_tmp/deferred.out"
printf 'migration input\n' | \
HOME="$stdin_home" \
OMARCHY_PATH="$stdin_root" \
TEST_CALLS="$stdin_calls" \
"$ROOT/bin/omarchy-migrate" >"$test_tmp/stdin.out"
grep -q '^deferred$' "$deferred_calls" || fail "migration runner starts a deferred migration"
grep -q '^after$' "$deferred_calls" || fail "migration runner continues after a deferred migration"
[[ ! -f $deferred_home/.local/state/omarchy/migrations/100-deferred.sh ]] ||
fail "migration runner leaves a deferred migration pending"
[[ -f $deferred_home/.local/state/omarchy/migrations/200-after.sh ]] ||
fail "migration runner records a later successful migration"
grep -q 'was deferred and will be retried later' "$test_tmp/deferred.out" ||
fail "migration runner reports a deferred migration"
pass "migration runner leaves exit-75 migrations pending and continues the queue"
HOME="$deferred_home" OMARCHY_PATH="$deferred_root" \
"$ROOT/bin/omarchy-migrate" --pending >"$test_tmp/deferred-pending.out"
grep -q '^100-deferred\.sh$' "$test_tmp/deferred-pending.out" ||
fail "migration runner still reports a deferred migration as pending"
! grep -q '^200-after\.sh$' "$test_tmp/deferred-pending.out" ||
fail "migration runner does not report the completed later migration as pending"
pass "migration runner reports only the deferred migration as pending"
raw_75_root="$test_tmp/raw-75-omarchy"
raw_75_home="$test_tmp/raw-75-home"
raw_75_calls="$test_tmp/raw-75-calls"
mkdir -p "$raw_75_root/migrations" "$raw_75_home"
cat >"$raw_75_root/migrations/100-child-tempfail.sh" <<'SH'
echo child-tempfail >>"$TEST_CALLS"
bash -c 'exit 75'
SH
cat >"$raw_75_root/migrations/200-after.sh" <<'SH'
echo after-tempfail >>"$TEST_CALLS"
SH
set +e
HOME="$raw_75_home" \
OMARCHY_PATH="$raw_75_root" \
TEST_CALLS="$raw_75_calls" \
"$ROOT/bin/omarchy-migrate" >"$test_tmp/raw-75.out" 2>"$test_tmp/raw-75.err"
raw_75_status=$?
set -e
(( raw_75_status == 75 )) ||
fail "migration runner preserves an unmarked child exit 75" "status=$raw_75_status"
grep -q '^child-tempfail$' "$raw_75_calls" || fail "migration runner starts the exit-75 child"
! grep -q '^after-tempfail$' "$raw_75_calls" || fail "migration runner stops after an unmarked exit 75"
[[ ! -f $raw_75_home/.local/state/omarchy/migrations/100-child-tempfail.sh ]] ||
fail "migration runner leaves an unmarked exit-75 migration incomplete"
pass "migration runner does not mistake a child EX_TEMPFAIL for intentional deferral"
grep -q '^reader:migration input$' "$stdin_calls" ||
fail "migration runner preserves the caller's stdin for a migration" "$(cat "$stdin_calls")"
grep -q '^after-reader$' "$stdin_calls" ||
fail "a migration reading stdin does not swallow later queue entries" "$(cat "$stdin_calls")"
[[ -f $stdin_home/.local/state/omarchy/migrations/100-reader.sh &&
-f $stdin_home/.local/state/omarchy/migrations/200-after.sh ]] ||
fail "migration runner marks both stdin-isolated migrations complete"
pass "migration queue uses a private file descriptor instead of migration stdin"