Merge smoketest-siblings: sibling projects in the smoketest, and the bugs it found
shellcheck / shellcheck (push) Successful in 18s

Sibling projects (HamPack first) can now have smoketest scenarios run on top
of CoreDesktop's, with coredesktop-dev smoketest --with. Their first runs
found three install bugs, fixed here: sibling add on a system not upgraded
lately, and install.sh failing when its upgrade replaced the kernel (now
kept working with kernel-modules-hook).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 04:41:49 -07:00
co-authored by Claude Opus 5.5
15 changed files with 633 additions and 67 deletions
+10
View File
@@ -51,6 +51,16 @@ answer() {
not_called configure
}
@test "finish-install asks for a reboot when the running kernel's modules are only kernel-modules-hook's copy" {
export COREDESKTOP_MODULES_DIR="$BATS_TEST_TMPDIR/modules"
KERNEL=0.0.0-kept-by-hook
mkdir -p "$COREDESKTOP_MODULES_DIR/$KERNEL"
run bash "$REPO/system/finish-install.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"A newer kernel has been installed. Reboot, then run: configure"* ]]
not_called configure
}
@test "finish-install says the install worked before offering configure" {
needs_modules
ITEMS="to do core Federated Core"
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bats
load test_helper
# updates.d/99-reboot-check.sh, with a fake /usr/lib/modules and pacman
setup() {
common_setup
mkdir -p "$HOME/.local/share"
ln -s "$REPO" "$HOME/.local/share/coredesktop"
export COREDESKTOP_MODULES_DIR="$BATS_TEST_TMPDIR/modules"
RUNNING="$COREDESKTOP_MODULES_DIR/$(uname -r)"
NEEDED="$HOME/.local/state/coredesktop/reboot-needed"
# pacman -Qo: the running kernel's modules belong to linux, unless OWNED is empty
export OWNED=linux
stub pacman '[ "$1" = -Qqo ] && [ -n "$OWNED" ] && echo "$OWNED"'
}
@test "reboot check: nothing to do when the running kernel's modules are the installed kernel's" {
mkdir -p "$RUNNING"
run bash "$REPO/updates.d/99-reboot-check.sh"
[ "$status" -eq 0 ]
[ ! -e "$NEEDED" ]
}
@test "reboot check: a reboot is needed when the running kernel's modules are gone" {
run bash "$REPO/updates.d/99-reboot-check.sh"
[[ "$output" == *"Please reboot"*"a newer kernel was installed"* ]]
[ "$(cat "$NEEDED")" = "a newer kernel was installed" ]
}
@test "reboot check: a reboot is needed when they're only kernel-modules-hook's copy" {
mkdir -p "$RUNNING"
OWNED=""
run bash "$REPO/updates.d/99-reboot-check.sh"
[ "$(cat "$NEEDED")" = "a newer kernel was installed" ]
}
+66
View File
@@ -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" ]
}
+143
View File
@@ -238,3 +238,146 @@ upstream_main() {
git -C "$REPO" rev-parse --verify --quiet "$ref^{commit}" > /dev/null || { echo "unknown: $ref"; exit 1; }
done
}
# --- Sibling projects ---
# A sibling project, HamPack, with two commits, and a chain file with
# CoreDesktop and it: CoreDesktop at V1 in the image and V2 under test,
# HamPack likewise at S1 and S2
chain_with_sibling() {
SIB="$BATS_TEST_TMPDIR/HamPack"
git init -q "$SIB"
echo s1 > "$SIB/version"
git -C "$SIB" add version
git -C "$SIB" commit -qm s1
S1="$(git -C "$SIB" rev-parse HEAD)"
echo s2 > "$SIB/version"
git -C "$SIB" commit -qam s2
S2="$(git -C "$SIB" rev-parse HEAD)"
export SMOKETEST_CHAIN_FILE="$BATS_TEST_TMPDIR/chain"
printf 'CoreDesktop\t%s\t%s\t%s\t\n' "$SMOKETEST_REPO" "$V2" "$V1" > "$SMOKETEST_CHAIN_FILE"
printf 'HamPack\t%s\t%s\t%s\t%s\n' "$SIB" "$S2" "$S1" \
"https://example.com/david/HamPack.git https://example.org/HamPack.git" >> "$SMOKETEST_CHAIN_FILE"
SIB_UPSTREAM="$SMOKETEST_VM_DIR/HamPack.git"
# A fake `sibling add`, which clones like the real one, and update and reboot
mkdir -p "$HOME/.local/bin"
printf '%s\n' '#!/bin/bash' 'echo "sibling $*" >> ~/vm.log' \
'git clone -q "$2" ~/.local/share/siblings/"$(basename "${2%.git}")"' > "$HOME/.local/bin/sibling"
printf '%s\n' '#!/bin/bash' 'echo update >> ~/vm.log' > "$HOME/.local/bin/update"
chmod +x "$HOME/.local/bin/sibling" "$HOME/.local/bin/update"
vm_reboot() { echo reboot >> "$HOME/vm.log"; }
}
@test "without a chain file, the chain is CoreDesktop at the commit under test" {
[ "$(chain_names)" = CoreDesktop ]
[ "$(project_sha CoreDesktop)" = "$V2" ]
[ -z "$(chain_siblings)" ]
}
@test "prepare makes a fake upstream for each project, and sends its URLs there" {
chain_with_sibling
smoketest_prepare
[ "$(upstream_main)" = "$V2" ]
[ "$(git --git-dir="$SIB_UPSTREAM" rev-parse main)" = "$S2" ]
for url in https://example.com/david/HamPack.git https://example.com/david/HamPack https://example.org/HamPack.git; do
git clone -q "$url" "$BATS_TEST_TMPDIR/clone"
[ "$(cat "$BATS_TEST_TMPDIR/clone/version")" = s2 ]
rm -rf "$BATS_TEST_TMPDIR/clone"
done
}
@test "prepare on the installed image checks every project's image commit, then updates once" {
chain_with_sibling
export IMAGE=installed
run smoketest_prepare
[ "$status" -eq 0 ]
[ "$(cat "$HOME/vm.log")" = update ]
printf 'HamPack\t%s\t%s\t%s\t%s\n' "$SIB" "$S1" "$S2" https://example.com/HamPack.git \
> "$BATS_TEST_TMPDIR/hampack-line"
sed -i '2d' "$SMOKETEST_CHAIN_FILE"
cat "$BATS_TEST_TMPDIR/hampack-line" >> "$SMOKETEST_CHAIN_FILE"
run smoketest_prepare
[ "$status" -eq 1 ]
[[ "$output" == *"the installed image has HamPack at $S2, which isn't in the history"* ]]
}
@test "upstream_set and upstream_commit take a project's name" {
chain_with_sibling
smoketest_prepare
upstream_set HamPack "$S1"
[ "$(git --git-dir="$SIB_UPSTREAM" rev-parse main)" = "$S1" ]
[ "$(upstream_main)" = "$V2" ]
upstream_commit HamPack "Bump" 'echo s3 > version'
[ "$(git --git-dir="$SIB_UPSTREAM" show main:version)" = s3 ]
[ "$(upstream_main)" = "$V2" ]
run upstream_set HamPack nosuchcommit
[[ "$output" == *"no such commit in HamPack: nosuchcommit"* ]]
run upstream_commit Nope "x" true
[ "$status" -eq 1 ]
[[ "$output" == *"Nope isn't in this run's chain"* ]]
}
@test "building a sibling's layer adds it at its commit, over the others at their image's, and reboots" {
chain_with_sibling
smoketest_build_layer HamPack "$S2"
[ "$(upstream_main)" = "$V1" ]
[ "$(cat "$HOME/.local/share/siblings/HamPack/version")" = s2 ]
[ "$(cat "$HOME/vm.log")" = "$(printf 'sibling add https://example.com/david/HamPack.git\nreboot')" ]
}
@test "building CoreDesktop's layer runs install.sh at its commit" {
vm_reboot() { echo reboot >> "$HOME/vm.log"; }
smoketest_build_layer CoreDesktop "$V1"
[ "$(cat "$HOME/vm.log")" = reboot ]
[ "$(head -n 1 "$HOME/installed")" = v1 ]
}
@test "install_chain installs CoreDesktop, reboots, adds each sibling and reboots again" {
chain_with_sibling
smoketest_prepare
install_chain
[ "$(cat "$HOME/vm.log")" = "$(printf 'reboot\nsibling add https://example.com/david/HamPack.git\nreboot')" ]
[ "$(head -n 1 "$HOME/installed")" = v2 ]
}
@test "a project's setup script runs in the VM before the scenario" {
chain_with_sibling
mkdir -p "$SIB/smoketest"
echo 'echo set up > ~/setup-ran' > "$SIB/smoketest/setup"
smoketest_prepare
[ "$(cat "$HOME/setup-ran")" = "set up" ]
echo 'exit 1' > "$SIB/smoketest/setup"
run smoketest_prepare
[ "$status" -eq 1 ]
[[ "$output" == *"setup-HamPack exited 1"* ]]
}
@test "health checks CoreDesktop, and each sibling that's installed and has health checks" {
chain_with_sibling
mkdir -p "$SIB/smoketest"
echo 'echo hampack healthy' > "$SIB/smoketest/health"
SMOKETEST_DIR="$BATS_TEST_TMPDIR/cd-smoketest"
mkdir -p "$SMOKETEST_DIR"
echo 'echo coredesktop healthy' > "$SMOKETEST_DIR/health"
run health
[ "$status" -eq 0 ]
[[ "$output" == *"coredesktop healthy"* ]]
[[ "$output" != *"hampack healthy"* ]]
mkdir -p "$HOME/.local/share/siblings/HamPack"
run health
[[ "$output" == *"coredesktop healthy"*"hampack healthy"* ]]
echo 'exit 1' > "$SIB/smoketest/health"
run health
[ "$status" -eq 1 ]
[[ "$output" == *"the health checks failed for: HamPack"* ]]
run health CoreDesktop
[ "$status" -eq 0 ]
}
+1 -1
View File
@@ -18,7 +18,7 @@ common_setup() {
# Set when the tests run inside a smoketest (a pre-push hook's checks, say),
# where they would point the smoketest tests at the real VM
unset VM_GIT_SSH VM_GIT_URL SMOKETEST_REPO SMOKETEST_RESULTS SMOKETEST_SHARED \
SMOKETEST_REF SMOKETEST_VM_DIR IMAGE_REF VARIANT
SMOKETEST_REF SMOKETEST_VM_DIR SMOKETEST_CHAIN_FILE IMAGE_REF VARIANT
}
# A test file that needs more setup defines its own setup that calls this first