Smoketest sibling projects on top of CoreDesktop

The scenario helpers now take a chain of projects from the driver
(SMOKETEST_CHAIN_FILE): CoreDesktop, then sibling projects such as HamPack.
Each gets a fake upstream in the VM; upstream_set and upstream_commit take
an optional project name; smoketest_prepare updates every project in the
installed image; and the new smoketest_build_layer, sibling_add and
install_chain install them. health also runs each installed sibling's
smoketest/health, and a sibling's smoketest/setup runs before each scenario.

Without a chain file, everything works as before, so older drivers and
CoreDesktop's own scenarios are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 10:15:10 -07:00
co-authored by Claude Opus 5.5
parent 4fb35397ee
commit 4f1e18200c
3 changed files with 439 additions and 52 deletions
+256 -49
View File
@@ -3,17 +3,30 @@
# Purpose : Helpers and assertions for smoketest scenarios (see ../README.md).
# Sourced by the driver after it defines vm_exec, vm_put and
# vm_reboot.
#
# A run tests a chain of projects: CoreDesktop, then any sibling projects
# (HamPack, say) the driver was asked for. The driver describes the chain in
# the file SMOKETEST_CHAIN_FILE, one line per project, tab-separated:
#
# name working copy commit under test commit in the image URLs (by spaces)
#
# CoreDesktop comes first, with no URLs: it has COREDESKTOP_URLS. Without a
# chain file, the chain is CoreDesktop alone, at SMOKETEST_REF, in an image at
# IMAGE_REF, as drivers before sibling projects described it.
SMOKETEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
# The CoreDesktop repo whose commits are tested. Overridable for the tests.
SMOKETEST_REPO="${SMOKETEST_REPO:-$(cd "$SMOKETEST_DIR/.." && pwd)}"
# In the VM: the fake upstream, the scratch clone upstream_commit works in, and
# where the fingerprint and health scripts are copied to
# In the VM: the fake upstreams, the scratch clone upstream_commit works in, and
# where the fingerprint, health and setup scripts are copied to
SMOKETEST_VM_DIR="${SMOKETEST_VM_DIR:-/srv/smoketest}"
UPSTREAM="$SMOKETEST_VM_DIR/coredesktop.git"
WORK="$SMOKETEST_VM_DIR/work"
# The chain's first project
ROOT_PROJECT=CoreDesktop
# Every URL CoreDesktop has been cloned from, so install.sh at any baseline
# clones the fake upstream instead
COREDESKTOP_URLS=(
@@ -46,6 +59,82 @@ skip() {
exit "$SKIP_STATUS"
}
# --- The chain ---------------------------------------------------------------
# The chain file's lines, or CoreDesktop's alone without one
chain_lines() {
if [ -n "${SMOKETEST_CHAIN_FILE:-}" ]; then
cat "$SMOKETEST_CHAIN_FILE"
else
printf '%s\t%s\t%s\t%s\t\n' "$ROOT_PROJECT" "$SMOKETEST_REPO" "${SMOKETEST_REF:-}" "${IMAGE_REF:-}"
fi
}
# The projects in the chain, CoreDesktop first, one per line
chain_names() {
chain_lines | cut -f1
}
# The sibling projects in the chain, one per line
chain_siblings() {
chain_names | tail -n +2
}
# chain_field NAME COLUMN: 2 working copy, 3 commit under test, 4 commit in
# the image, 5 URLs
chain_field() {
chain_lines | awk -F'\t' -v n="$1" -v c="$2" '$1 == n { print $c }'
}
project_dir() { chain_field "$1" 2; }
project_sha() { chain_field "$1" 3; }
image_sha() { chain_field "$1" 4; }
# project_urls NAME: the URLs project NAME is cloned from, one per line
project_urls() {
if [ "$1" = "$ROOT_PROJECT" ]; then
printf '%s\n' "${COREDESKTOP_URLS[@]}"
else
chain_field "$1" 5 | tr ' ' '\n' | grep .
fi
}
# The URL a sibling project is added from (its first)
project_url() {
project_urls "$1" | head -n 1
}
# True if project NAME is in this run's chain
in_run() {
chain_names | grep -qxF "$1"
}
# upstream NAME: the project's fake upstream in the VM
upstream() {
if [ "$1" = "$ROOT_PROJECT" ]; then
echo "$UPSTREAM"
else
echo "$SMOKETEST_VM_DIR/$1.git"
fi
}
# sibling_name NAME: the folder in ~/.local/share/siblings that `sibling add`
# clones project NAME into: its URL's last part, without .git
sibling_name() {
local name
name="$(project_url "$1")"
name="${name%/}"
name="${name##*/}"
echo "${name%.git}"
}
# True if sibling project NAME is installed in the VM
sibling_installed() {
vm_exec "test -d ~/.local/share/siblings/$(q "$(sibling_name "$1")")" > /dev/null 2>&1
}
# --- Running things in the VM ------------------------------------------------
# run_in_vm NAME SCRIPT: run SCRIPT in the VM, keeping its output in $OUTPUT,
# its exit status in $STATUS, and both in NN-NAME.log. Doesn't fail on its own:
# check with assert_status. The log is written as SCRIPT runs, so a long one
@@ -79,58 +168,67 @@ progress_ticker() {
done
}
# Called by the driver once the VM is up, before the scenario
smoketest_prepare() {
local urls="" url
for url in "${COREDESKTOP_URLS[@]}"; do
urls+=" $(q "$url")"
done
vm_exec "set -e
[ -d $(q "$UPSTREAM") ] || git init -q --bare --initial-branch=main $(q "$UPSTREAM")
# --- Fake upstreams ----------------------------------------------------------
# Make a bare repo in the VM for each project in the chain, and have git send
# the project's real URLs there, so install.sh, sibling add and update run
# unchanged
setup_upstreams() {
local script="set -e
git config --global user.name 'CoreDesktop Smoketest'
git config --global user.email smoketest@localhost
git config --global --unset-all url.$(q "$UPSTREAM").insteadOf || true
for url in $urls; do
git config --global --add url.$(q "$UPSTREAM").insteadOf \"\$url\"
done" || fail "couldn't set up the fake upstream in the VM"
if [ "${IMAGE:-}" = installed ]; then
git -C "$SMOKETEST_REPO" merge-base --is-ancestor "$IMAGE_REF" "$SMOKETEST_REF" \
|| fail "the installed image is at $IMAGE_REF, which isn't in the history of" \
"the commit under test. Rebuild it: coredesktop-dev smoketest images --installed"
upstream_set "$SMOKETEST_REF"
cd_update
assert_status 0
else
upstream_set "$SMOKETEST_REF"
fi
git config --global user.email smoketest@localhost" name url up
while read -r name; do
up="$(q "$(upstream "$name")")"
script+="
[ -d $up ] || git init -q --bare --initial-branch=main $up
git config --global --unset-all url.$up.insteadOf || true"
while read -r url; do
script+="
git config --global --add url.$up.insteadOf $(q "$url")"
# A sibling may be added by its URL with or without .git; each is matched
# as a prefix, and the longer wins
if [ "$name" != "$ROOT_PROJECT" ] && [[ "$url" == *.git ]]; then
script+="
git config --global --add url.$up.insteadOf $(q "${url%.git}")"
fi
done < <(project_urls "$name")
done < <(chain_names)
vm_exec "$script" || fail "couldn't set up the fake upstreams in the VM"
}
# Called by the driver to make the installed image from the base image
smoketest_install_image() {
smoketest_prepare
upstream_set "$1"
cd_install
assert_status 0
}
# upstream_set REF: point the fake upstream's main at REF, a commit in this repo
# upstream_set [NAME] REF: point project NAME's (default CoreDesktop's) fake
# upstream main at REF, a commit in its working copy
upstream_set() {
local sha
sha="$(git -C "$SMOKETEST_REPO" rev-parse --verify --quiet "$1^{commit}")" \
|| fail "no such commit: $1"
local name="$ROOT_PROJECT" dir sha
if (( $# > 1 )); then
name="$1"
shift
fi
dir="$(project_dir "$name")"
[ -n "$dir" ] || fail "$name isn't in this run's chain"
if ! sha="$(git -C "$dir" rev-parse --verify --quiet "$1^{commit}")"; then
[ "$name" = "$ROOT_PROJECT" ] && fail "no such commit: $1"
fail "no such commit in $name: $1"
fi
# --no-verify: a pre-push hook in the working copy (coredesktop-dev's runs
# make check) is for pushes to the real upstream, not to the VM
GIT_SSH_COMMAND="${VM_GIT_SSH:-ssh}" git -C "$SMOKETEST_REPO" push --quiet --force --no-verify \
"${VM_GIT_URL:-}$UPSTREAM" "$sha:refs/heads/main" || fail "couldn't push $1 to the VM"
GIT_SSH_COMMAND="${VM_GIT_SSH:-ssh}" git -C "$dir" push --quiet --force --no-verify \
"${VM_GIT_URL:-}$(upstream "$name")" "$sha:refs/heads/main" || fail "couldn't push $name $1 to the VM"
}
# upstream_commit MESSAGE SCRIPT: release a new commit, made by running SCRIPT
# (in the VM) in a clone of the fake upstream's main
# upstream_commit [NAME] MESSAGE SCRIPT: release a new commit of project NAME
# (default CoreDesktop), made by running SCRIPT (in the VM) in a clone of its
# fake upstream's main
upstream_commit() {
local name="$ROOT_PROJECT"
if (( $# > 2 )); then
name="$1"
shift
fi
in_run "$name" || fail "$name isn't in this run's chain"
run_in_vm commit "set -e
rm -rf $(q "$WORK")
git clone -q $(q "$UPSTREAM") $(q "$WORK")
git clone -q $(q "$(upstream "$name")") $(q "$WORK")
cd $(q "$WORK")
$2
git add -A
@@ -139,6 +237,75 @@ upstream_commit() {
assert_status 0
}
# Run each project's smoketest/setup in the VM, if it has one: what a project
# needs set up on any machine it's tested on (HamPack's turns off its Windows
# installers, which wait for clicks no one makes)
run_setup_scripts() {
local name script
while read -r name; do
script="$(project_dir "$name")/smoketest/setup"
[ -f "$script" ] || continue
vm_put "$script" "$SMOKETEST_VM_DIR/setup-$name" || fail "couldn't copy $name's setup script to the VM"
run_in_vm "setup-$name" "bash $(q "$SMOKETEST_VM_DIR/setup-$name")"
assert_status 0
done < <(chain_names)
}
# --- Called by the driver ----------------------------------------------------
# Once the VM is up, before the scenario: point each fake upstream at the
# commit under test. On the installed image, update to it.
smoketest_prepare() {
local name image
setup_upstreams
run_setup_scripts
while read -r name; do
if [ "${IMAGE:-}" = installed ]; then
image="$(image_sha "$name")"
git -C "$(project_dir "$name")" merge-base --is-ancestor "$image" "$(project_sha "$name")" \
|| fail "the installed image has $name at $image, which isn't in the history of the" \
"commit under test. Rebuild it: coredesktop-dev smoketest images installed" \
"(with the same --with options)"
fi
upstream_set "$name" "$(project_sha "$name")"
done < <(chain_names)
if [ "${IMAGE:-}" = installed ]; then
cd_update
assert_status 0
fi
}
# To build an image layer: install project NAME at SHA on a machine that has
# the projects before it in the chain, then reboot, as the READMEs say to
smoketest_build_layer() {
local name="$1" sha="$2" other
setup_upstreams
run_setup_scripts
while read -r other; do
upstream_set "$other" "$(image_sha "$other")"
done < <(chain_names | grep -vxF "$name")
upstream_set "$name" "$sha"
if [ "$name" = "$ROOT_PROJECT" ]; then
cd_install
else
sibling_add "$name"
fi
assert_status 0
vm_reboot
}
# For drivers from before smoketest_build_layer: the installed image from the
# base image
smoketest_install_image() {
smoketest_prepare
upstream_set "$1"
cd_install
assert_status 0
}
# --- What a person would run -------------------------------------------------
# Run install.sh the way the README's wget ... | bash does: main's install.sh,
# with no terminal to ask questions on
cd_install() {
@@ -157,6 +324,28 @@ cd_update() {
run_in_vm update "TERM=dumb env$vars ~/.local/bin/update"
}
# sibling_add NAME: add sibling project NAME from its (real) URL, as its README
# says to
sibling_add() {
in_run "$1" || fail "$1 isn't in this run's chain"
run_in_vm "sibling-add-$1" "TERM=dumb ~/.local/bin/sibling add $(q "$(project_url "$1")")"
}
# Install CoreDesktop and every sibling in the chain at the commits under test,
# as a person would on a fresh machine, rebooting where the READMEs say to
install_chain() {
local name added=0
cd_install
assert_status 0
vm_reboot
while read -r name; do
sibling_add "$name"
assert_status 0
added=1
done < <(chain_siblings)
(( added == 0 )) || vm_reboot
}
# fingerprint FILE: save the machine's fingerprint to FILE
fingerprint() {
vm_put "$SMOKETEST_DIR/fingerprint" "$SMOKETEST_VM_DIR/fingerprint" \
@@ -170,13 +359,31 @@ reference_fingerprint() {
echo "$SMOKETEST_SHARED/fresh-install.fingerprint"
}
# Run the health checks; fail the scenario if any fails
# health [NAME...]: run the health checks of the projects named (default:
# CoreDesktop, and each sibling in the chain that's installed in the VM and has
# a smoketest/health); fail the scenario if any fails
health() {
vm_put "$SMOKETEST_DIR/health" "$SMOKETEST_VM_DIR/health" \
|| fail "couldn't copy the health script to the VM"
run_in_vm health "bash $(q "$SMOKETEST_VM_DIR/health")"
printf '%s\n' "$OUTPUT"
[ "$STATUS" -eq 0 ] || fail "the health checks failed"
local names=("$@") name script dest log failed=()
if (( ${#names[@]} == 0 )); then
names=("$ROOT_PROJECT")
while read -r name; do
[ -f "$(project_dir "$name")/smoketest/health" ] && sibling_installed "$name" && names+=("$name")
done < <(chain_siblings)
fi
for name in "${names[@]}"; do
if [ "$name" = "$ROOT_PROJECT" ]; then
script="$SMOKETEST_DIR/health" dest="$SMOKETEST_VM_DIR/health" log=health
else
script="$(project_dir "$name")/smoketest/health"
dest="$SMOKETEST_VM_DIR/health-$name" log="health-$name"
[ -f "$script" ] || fail "$name has no smoketest/health"
fi
vm_put "$script" "$dest" || fail "couldn't copy $name's health script to the VM"
run_in_vm "$log" "bash $(q "$dest")"
printf '%s\n' "$OUTPUT"
[ "$STATUS" -eq 0 ] || failed+=("$name")
done
(( ${#failed[@]} == 0 )) || fail "the health checks failed for: ${failed[*]}"
}
assert_status() {