sibling add: run update first on a system not upgraded for a day
shellcheck / shellcheck (push) Successful in 19s
shellcheck / shellcheck (push) Successful in 19s
A sibling's install.sh installs packages from pacman's package lists. On a system not upgraded for a week or so, those name versions the mirrors have deleted, so the install fails with 404s: HamPack's smoketest found this, adding HamPack to a ten-day-old install. Only update may upgrade the system, so sibling add now runs it first when pacman's log says the last full upgrade is over a day old (or doesn't say). Not when update or install.sh is running it, and a failing update doesn't stop the add. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,29 @@ setup() {
|
||||
ORIGINS="$BATS_TEST_TMPDIR/origins"
|
||||
SIBLINGS="$HOME/.local/share/siblings"
|
||||
mkdir -p "$ORIGINS" "$SIBLINGS"
|
||||
# pacman's log, with an upgrade an hour ago, and an update that logs its runs
|
||||
export SIBLING_PACMAN_LOG="$BATS_TEST_TMPDIR/pacman.log"
|
||||
upgraded_hours_ago 1
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
printf '%s\n' '#!/bin/bash' 'echo "update ran" >> "$HOME/update.log"' > "$HOME/.local/bin/update"
|
||||
chmod +x "$HOME/.local/bin/update"
|
||||
}
|
||||
|
||||
# upgraded_hours_ago N: pacman's log says the last full upgrade was N hours ago
|
||||
upgraded_hours_ago() {
|
||||
{
|
||||
echo "[$(date -d '30 days ago' +%Y-%m-%dT%H:%M:%S%z)] [PACMAN] starting full system upgrade"
|
||||
echo "[$(date -d "$1 hours ago" +%Y-%m-%dT%H:%M:%S%z)] [PACMAN] starting full system upgrade"
|
||||
echo "[$(date +%Y-%m-%dT%H:%M:%S%z)] [PACMAN] Running 'pacman -S foo'"
|
||||
} > "$SIBLING_PACMAN_LOG"
|
||||
}
|
||||
|
||||
# A sibling's origin whose install.sh records that it ran
|
||||
installable() {
|
||||
git init -q -b main "$ORIGINS/$1"
|
||||
echo 'touch "$HOME/installed-$(basename "$PWD")"' > "$ORIGINS/$1/install.sh"
|
||||
git -C "$ORIGINS/$1" add -A
|
||||
git -C "$ORIGINS/$1" commit -qm first
|
||||
}
|
||||
|
||||
# origin NAME: make a repo with one commit, and clone it as a sibling
|
||||
@@ -112,3 +135,46 @@ commit() {
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"No sibling named 'nope' is installed."* ]]
|
||||
}
|
||||
|
||||
@test "sibling add clones the sibling and runs its install.sh" {
|
||||
installable tools
|
||||
run bash "$REPO/sibling" add "$ORIGINS/tools"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f "$HOME/installed-tools" ]
|
||||
[[ "$output" == *"Installed tools "* ]]
|
||||
[ ! -e "$HOME/update.log" ]
|
||||
}
|
||||
|
||||
@test "sibling add runs update first when the last upgrade is over a day old" {
|
||||
installable tools
|
||||
upgraded_hours_ago 50
|
||||
run bash "$REPO/sibling" add "$ORIGINS/tools"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"last upgraded 2 day(s) ago. Running update first"* ]]
|
||||
[ "$(cat "$HOME/update.log")" = "update ran" ]
|
||||
[ -f "$HOME/installed-tools" ]
|
||||
}
|
||||
|
||||
@test "sibling add runs update first when it can't tell when the system was upgraded" {
|
||||
installable tools
|
||||
: > "$SIBLING_PACMAN_LOG"
|
||||
run bash "$REPO/sibling" add "$ORIGINS/tools"
|
||||
[[ "$output" == *"Couldn't tell when this system was last upgraded"* ]]
|
||||
[ "$(cat "$HOME/update.log")" = "update ran" ]
|
||||
}
|
||||
|
||||
@test "sibling add goes on if update fails, and doesn't run update inside update" {
|
||||
installable tools
|
||||
upgraded_hours_ago 50
|
||||
printf '%s\n' '#!/bin/bash' 'echo "update ran" >> "$HOME/update.log"; exit 1' > "$HOME/.local/bin/update"
|
||||
run bash "$REPO/sibling" add "$ORIGINS/tools"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"update reported errors (above); adding the sibling anyway."* ]]
|
||||
[ -f "$HOME/installed-tools" ]
|
||||
|
||||
rm "$HOME/update.log"
|
||||
installable more
|
||||
COREDESKTOP_ALLOW_PACMAN=1 run bash "$REPO/sibling" add "$ORIGINS/more"
|
||||
[ "$status" -eq 0 ]
|
||||
[ ! -e "$HOME/update.log" ]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user