* Fail the snapshot when Snapper is installed but has no configs omarchy-snapshot create loops over the configs snapper reports. With none, the loop body never runs, so it prints "Create system snapshot" and exits 0 without capturing anything. Every update then reports a snapshot it never took, and the absence only surfaces when a rollback is needed and the snapshot list turns out to be empty. * Say so when the update proceeds without a snapshot The update ignores exit 127 so a system without snapper updates quietly. Any other snapshot failure was being swallowed by the same expression, which let the update continue with no indication that it was now unprotected. Keep continuing, but say it out loud. * Point the snapshot repair hint at how the installer runs it Also hold the green header until a snapshot will actually be attempted, so the no-config failure doesn't open with a success banner. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Continue the quattro upgrade when the pre-upgrade snapshot fails The upgrade runs under set -e, so the new non-zero exit from an unconfigured Snapper would have aborted a re-run at the snapshot step instead of proceeding like omarchy-update does. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: David Heinemeier Hansson <david@hey.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
105 lines
3.3 KiB
Bash
105 lines
3.3 KiB
Bash
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
|
|
|
snapshot="$ROOT/bin/omarchy-snapshot"
|
|
|
|
test_tmp=$(mktemp -d)
|
|
trap 'rm -rf "$test_tmp"' EXIT
|
|
|
|
fake_bin="$test_tmp/bin"
|
|
mkdir -p "$fake_bin"
|
|
|
|
cat >"$fake_bin/sudo" <<'STUB'
|
|
#!/bin/bash
|
|
exec "$@"
|
|
STUB
|
|
chmod +x "$fake_bin/sudo"
|
|
|
|
cat >"$fake_bin/omarchy-cmd-missing" <<'STUB'
|
|
#!/bin/bash
|
|
exit 1
|
|
STUB
|
|
chmod +x "$fake_bin/omarchy-cmd-missing"
|
|
|
|
cat >"$fake_bin/omarchy-version" <<'STUB'
|
|
#!/bin/bash
|
|
echo 4.0.0
|
|
STUB
|
|
chmod +x "$fake_bin/omarchy-version"
|
|
|
|
# Snapper with no configs: list-configs prints only the CSV header.
|
|
cat >"$fake_bin/snapper" <<'STUB'
|
|
#!/bin/bash
|
|
printf 'snapper %s\n' "$*" >>"$TEST_LOG"
|
|
if [[ "$*" == *"list-configs"* ]]; then
|
|
echo "config,subvolume"
|
|
fi
|
|
STUB
|
|
chmod +x "$fake_bin/snapper"
|
|
|
|
# A snapshot that silently creates nothing reads as a successful snapshot, so
|
|
# an unconfigured Snapper has to fail loudly instead of passing for a backup.
|
|
: >"$test_tmp/calls.log"
|
|
set +e
|
|
stderr=$(TEST_LOG="$test_tmp/calls.log" PATH="$fake_bin:$PATH" \
|
|
bash "$snapshot" create 2>&1 >/dev/null)
|
|
status=$?
|
|
set -e
|
|
|
|
(( status != 0 )) || fail "snapshot create fails when Snapper has no configs"
|
|
grep -qF 'No Snapper configs found' <<<"$stderr" ||
|
|
fail "snapshot create reports that no snapshot was created" "$stderr"
|
|
! grep -q '^snapper -c .* create ' "$test_tmp/calls.log" ||
|
|
fail "snapshot create does not invent a config to snapshot"
|
|
pass "snapshot create fails loudly when Snapper is installed but unconfigured"
|
|
|
|
cat >"$fake_bin/snapper" <<'STUB'
|
|
#!/bin/bash
|
|
printf 'snapper %s\n' "$*" >>"$TEST_LOG"
|
|
if [[ "$*" == *"list-configs"* ]]; then
|
|
echo "config,subvolume"
|
|
echo "root,/"
|
|
fi
|
|
STUB
|
|
chmod +x "$fake_bin/snapper"
|
|
|
|
: >"$test_tmp/calls.log"
|
|
TEST_LOG="$test_tmp/calls.log" PATH="$fake_bin:$PATH" \
|
|
bash "$snapshot" create >/dev/null
|
|
|
|
grep -qFx 'snapper -c root create -c number -d 4.0.0' "$test_tmp/calls.log" ||
|
|
fail "snapshot create snapshots each configured subvolume" "$(cat "$test_tmp/calls.log")"
|
|
grep -qFx 'snapper -c root cleanup number' "$test_tmp/calls.log" ||
|
|
fail "snapshot create prunes older snapshots"
|
|
pass "snapshot create snapshots every configured Snapper config"
|
|
|
|
# Snapper being deliberately absent is the one skip that stays quiet, and the
|
|
# update has to keep treating it as such.
|
|
cat >"$fake_bin/omarchy-cmd-missing" <<'STUB'
|
|
#!/bin/bash
|
|
exit 0
|
|
STUB
|
|
chmod +x "$fake_bin/omarchy-cmd-missing"
|
|
|
|
set +e
|
|
TEST_LOG="$test_tmp/calls.log" PATH="$fake_bin:$PATH" \
|
|
bash "$snapshot" create >/dev/null 2>&1
|
|
status=$?
|
|
set -e
|
|
|
|
(( status == 127 )) || fail "snapshot create exits 127 without snapper" "got $status"
|
|
grep -qF 'omarchy-snapshot create || (($? == 127))' "$ROOT/bin/omarchy-update" ||
|
|
fail "update ignores only the missing-snapper exit code"
|
|
pass "snapshot create keeps the quiet 127 path for systems without snapper"
|
|
|
|
# The quattro upgrade runs under set -e, so a failed snapshot has to be warned
|
|
# past there too or it aborts the whole upgrade at the snapshot step.
|
|
grep -qF 'omarchy-snapshot create || (($? == 127))' "$ROOT/bin/omarchy-upgrade-to-quattro" ||
|
|
fail "upgrade ignores only the missing-snapper exit code"
|
|
grep -qF 'Continuing the upgrade without a snapshot' "$ROOT/bin/omarchy-upgrade-to-quattro" ||
|
|
fail "upgrade continues past a failed snapshot instead of aborting"
|
|
pass "upgrade to quattro survives a failed snapshot without passing it off"
|