From 83c6dd230c1e9ec35550c6ad077a206b17a99b8b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 13 Sep 2026 10:35:32 +0200 Subject: [PATCH] Keep the conflict tests inside their fixture despite the scope wrapper The update conflict tests stub sudo and pacman, but omarchy-update-pacman now puts systemd-run between them, so on a systemd-booted host the tests would reach for the real system manager. Stub systemd-run to drop the wrapper's options and run the command, and cover the helper's own invocation composition in a new test. Raised by codex review. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_015zcqENR1UbhuwC1v5u3Wop --- test/shell.d/update-file-conflict-test.sh | 10 ++++- test/shell.d/update-package-conflict-test.sh | 10 ++++- test/shell.d/update-pacman-test.sh | 39 ++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100755 test/shell.d/update-pacman-test.sh diff --git a/test/shell.d/update-file-conflict-test.sh b/test/shell.d/update-file-conflict-test.sh index 5fa954ea..526a1c6c 100755 --- a/test/shell.d/update-file-conflict-test.sh +++ b/test/shell.d/update-file-conflict-test.sh @@ -15,6 +15,14 @@ cat >"$stub_bin/sudo" <<'STUB' exec "$@" STUB +# omarchy-update-pacman wraps the transaction in a real PID 1 scope; the tests +# must stay inside the fixture, so drop the wrapper's options and run the command. +cat >"$stub_bin/systemd-run" <<'STUB' +#!/bin/bash +while [[ $1 == -* ]]; do shift; done +exec "$@" +STUB + # Fails the first -Syu with the report under test, then succeeds unless the case # asked for the retry to fail too. cat >"$stub_bin/pacman" <<'STUB' @@ -40,7 +48,7 @@ fi echo "upgrade complete" STUB -chmod +x "$stub_bin/sudo" "$stub_bin/pacman" +chmod +x "$stub_bin/sudo" "$stub_bin/systemd-run" "$stub_bin/pacman" replaced="$test_tmp/replaced" diff --git a/test/shell.d/update-package-conflict-test.sh b/test/shell.d/update-package-conflict-test.sh index cbe6286f..e05e8f7b 100755 --- a/test/shell.d/update-package-conflict-test.sh +++ b/test/shell.d/update-package-conflict-test.sh @@ -17,6 +17,14 @@ cat >"$stub_bin/sudo" <<'STUB' exec "$@" STUB +# omarchy-update-pacman wraps the transaction in a real PID 1 scope; the tests +# must stay inside the fixture, so drop the wrapper's options and run the command. +cat >"$stub_bin/systemd-run" <<'STUB' +#!/bin/bash +while [[ $1 == -* ]]; do shift; done +exec "$@" +STUB + # Fails the first -Syu with the report under test, then succeeds. Every call # records its arguments and which of its streams reached a terminal: pacman puts # its questions on stderr once it is not running --noconfirm, so a retry meant @@ -39,7 +47,7 @@ fi echo "upgrade complete" STUB -chmod +x "$stub_bin/sudo" "$stub_bin/pacman" +chmod +x "$stub_bin/sudo" "$stub_bin/systemd-run" "$stub_bin/pacman" # Everything a blocked qemu-common upgrade leaves on stderr, and no more. The # ":: ... Remove qemu-block-gluster? [y/N]" pacman asked is deliberately absent: diff --git a/test/shell.d/update-pacman-test.sh b/test/shell.d/update-pacman-test.sh new file mode 100755 index 00000000..a9278b37 --- /dev/null +++ b/test/shell.d/update-pacman-test.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -euo pipefail + +source "$(dirname "$0")/base-test.sh" + +test_tmp=$(mktemp -d) +trap 'rm -rf "$test_tmp"' EXIT + +stub_bin="$test_tmp/bin" +mkdir -p "$stub_bin" + +cat >"$stub_bin/sudo" <<'STUB' +#!/bin/bash +printf '%s\n' "$*" >"$SUDO_CALL_LOG" +STUB +chmod +x "$stub_bin/sudo" + +run_helper() { + PATH="$stub_bin:$PATH" SUDO_CALL_LOG="$test_tmp/call" "$ROOT/bin/omarchy-update-pacman" "$@" +} + +# The scope wrapper only applies on a systemd-booted host, so expect what the +# helper's own booted check would decide for this machine. +if [[ -d /run/systemd/system && ! -L /run/systemd/system ]]; then + expected_scope="systemd-run --scope --quiet --collect " +else + expected_scope="" +fi + +run_helper -Syu --noconfirm +[[ $(cat "$test_tmp/call") == "env OMARCHY_UPDATE_PACMAN=1 ${expected_scope}pacman -Syu --noconfirm" ]] || + fail "helper composes the guarded pacman invocation" "$(cat "$test_tmp/call")" +pass "helper composes the guarded pacman invocation" + +LC_ALL=C run_helper -Syu +[[ $(cat "$test_tmp/call") == "env OMARCHY_UPDATE_PACMAN=1 LC_ALL=C ${expected_scope}pacman -Syu" ]] || + fail "helper forwards LC_ALL to the transaction" "$(cat "$test_tmp/call")" +pass "helper forwards LC_ALL to the transaction"