Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

test(scripts): Phase 4 — vm update/uninstall tests + 7-distro CI matrix

Juan Denisf744106d64d5
diff --git a/.github/workflows/scripts-ci.yml b/.github/workflows/scripts-ci.yml
index 45dc0fea..2084dbd4 100644
--- a/.github/workflows/scripts-ci.yml
+++ b/.github/workflows/scripts-ci.yml
@@ -1,24 +1,29 @@
name: Scripts CI
-# Static + unit checks for the shell scripts that install/update ServerKit on a
-# server. These ran nowhere before — so a bug like the 1.7.0 updater silently
-# dying on `set -euo pipefail` was only ever found on a real box. shellcheck
-# catches that whole class statically; test_update.sh exercises the update
-# logic against fixtures with no server.
+# Static + unit checks for the shell scripts that install/update/uninstall
+# ServerKit on a server. These ran nowhere before — so a bug like the 1.7.0
+# updater silently dying on `set -euo pipefail` was only ever found on a real
+# box. shellcheck catches that whole class statically; the test_*.sh suites
+# exercise the install/update/uninstall + lib logic against fixtures with no
+# server, on every supported distro family.
on:
push:
branches: [dev, main]
paths:
- 'scripts/**'
+ - 'templates/**'
- 'install.sh'
+ - 'uninstall.sh'
- 'serverkit'
- '.github/workflows/scripts-ci.yml'
pull_request:
branches: [dev, main]
paths:
- 'scripts/**'
+ - 'templates/**'
- 'install.sh'
+ - 'uninstall.sh'
- 'serverkit'
- '.github/workflows/scripts-ci.yml'
workflow_call:
@@ -33,7 +38,7 @@ jobs:
- name: Syntax check (bash -n)
run: |
status=0
- for f in serverkit scripts/*.sh install.sh; do
+ for f in serverkit install.sh uninstall.sh scripts/*.sh scripts/lib/*.sh scripts/test/*.sh; do
[ -f "$f" ] || continue
if bash -n "$f"; then
echo "ok $f"
@@ -43,39 +48,69 @@ jobs:
done
exit $status
- - name: ShellCheck
+ - name: ShellCheck (error severity — installer/updater/uninstaller surface)
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq shellcheck
- # -x follows `source`d files; the updater + installer are the critical
- # ones. Warnings are advisory; errors fail the job.
- shellcheck --severity=error scripts/update.sh scripts/install.sh install.sh serverkit
+ # Errors fail the job. The CLI + installer carry pre-existing advisory
+ # warnings (unused color vars, etc.), so they are gated at error level.
+ shellcheck --severity=error \
+ scripts/update.sh scripts/install.sh install.sh uninstall.sh serverkit \
+ scripts/lib/*.sh scripts/test/*.sh
- - name: Unit tests (test_update.sh)
- run: bash scripts/test/test_update.sh
+ - name: ShellCheck (warning severity — new libs must stay clean)
+ run: |
+ # The lib/ abstraction was written warning-clean; keep it that way so
+ # quality doesn't rot. -x follows `source`d files.
+ shellcheck --severity=warning -x scripts/lib/*.sh
+
+ - name: Unit tests (update + install + lib)
+ run: |
+ bash scripts/test/test_update.sh
+ bash scripts/test/test_install.sh
+ bash scripts/test/test_lib.sh
cross-distro:
name: unit (${{ matrix.image }})
runs-on: ubuntu-latest
- # ServerKit targets several Linux families; the updater's logic (symlink
- # resolution, locking, refresh_config, detection) must behave the same on
- # Debian- and RHEL-derived hosts, not just the Ubuntu runner. Run the unit
- # suite inside each distro's container so a portability regression fails
- # here instead of on someone's server.
+ # ServerKit targets several Linux families; the scripts' logic (symlink
+ # resolution, locking, refresh_config, deployment/OS/pkg/init detection,
+ # the uninstall matrix) must behave the same on Debian-, RHEL-, and
+ # SUSE-derived hosts, not just the Ubuntu runner. Run the unit suites inside
+ # each distro's container so a portability regression fails here instead of
+ # on someone's server.
strategy:
fail-fast: false
matrix:
- image: ['debian:12', 'rockylinux:9']
+ image:
+ - 'ubuntu:22.04'
+ - 'ubuntu:24.04'
+ - 'debian:12'
+ - 'rockylinux:9'
+ - 'almalinux:9'
+ - 'fedora:40'
+ - 'opensuse/leap:15.5'
steps:
- uses: actions/checkout@v4
- - name: bash -n + unit tests on ${{ matrix.image }}
+ - name: bash -n + unit suites on ${{ matrix.image }}
run: |
- docker run --rm -v "$PWD:/src" -w /src "${{ matrix.image }}" bash -c '
+ docker run --rm -v "$PWD:/src" -w /src "${{ matrix.image }}" sh -c '
set -e
- echo "bash $BASH_VERSION"
- for f in serverkit scripts/*.sh install.sh; do
+ # bash ships in every image here; the suites stub the real tools
+ # (curl/docker/systemd/flask) so nothing else is required. Best-effort
+ # bash install for any stripped-down variant — never fatal (EL9, for
+ # one, has a curl/curl-minimal conflict we deliberately do not touch).
+ command -v bash >/dev/null 2>&1 || {
+ { command -v apt-get >/dev/null 2>&1 && apt-get update -qq && apt-get install -y -qq bash; } ||
+ { command -v dnf >/dev/null 2>&1 && dnf install -y -q bash; } ||
+ { command -v zypper >/dev/null 2>&1 && zypper --non-interactive install bash; } || true
+ }
+ echo "bash $(bash --version | head -1)"
+ for f in serverkit install.sh uninstall.sh scripts/*.sh scripts/lib/*.sh scripts/test/*.sh; do
[ -f "$f" ] || continue
bash -n "$f" && echo "ok $f"
done
bash scripts/test/test_update.sh
+ bash scripts/test/test_install.sh
+ bash scripts/test/test_lib.sh
'
diff --git a/scripts/test/README.md b/scripts/test/README.md
index c3eb1a3e..ab130370 100644
--- a/scripts/test/README.md
+++ b/scripts/test/README.md
@@ -66,7 +66,7 @@ HTML report.
| Ubuntu 22.04 | Multipass | `22.04` |
| Ubuntu 24.04 | Multipass | `24.04` |
| Debian 12 | Vagrant | `generic/debian12` |
-| Fedora | Vagrant | `generic/fedora39` |
+| Fedora 40 | Vagrant | `generic/fedora40` |
| Rocky 9 | Vagrant | `generic/rocky9` |
### Agent pairing test (optional)
@@ -114,6 +114,38 @@ scripts/test/output/<run-id>/
sk-test-debian12-<id>/ ...
```
+## Update & uninstall coverage
+
+Alongside `vm-install.sh`, two more "run inside the VM" scripts exercise the
+other lifecycle stages end-to-end (same contract: log to
+`/var/log/serverkit-test-*.log`, write `OK`/`FAIL` to `/tmp/serverkit-*-status`):
+
+- **`vm-update.sh`** — installs ServerKit, runs the local `scripts/update.sh`
+ with `--force` (full blue/green deploy → migrate → switch → health), then
+ re-runs without `--force` to confirm the "Already up to date" version-gate.
+- **`vm-uninstall.sh`** — installs + seeds sample data, runs the default
+ uninstall and asserts user data is preserved (DB snapshot in
+ `/var/backups/serverkit`, `/var/lib/serverkit` survives), then reinstalls and
+ asserts `--purge` removes the data dirs.
+
+Run them by uploading to a `-Keep` VM and `sudo bash /tmp/vm-update.sh`, or wire
+them into the orchestrator the same way `vm-install.sh` is invoked.
+
+## Fast, serverless unit tests
+
+Most regressions are caught long before a VM is needed. The source-able
+`scripts/test/test_{update,install,lib}.sh` suites exercise the updater,
+installer, and the `scripts/lib/*` abstractions against fixtures and PATH stubs
+— no server, seconds to run, and gated in CI (`.github/workflows/scripts-ci.yml`)
+across Ubuntu 22.04/24.04, Debian 12, Rocky 9, AlmaLinux 9, Fedora 40, and
+openSUSE Leap 15.5 containers.
+
+```bash
+bash scripts/test/test_update.sh
+bash scripts/test/test_install.sh
+bash scripts/test/test_lib.sh
+```
+
## Extending the harness
Add new tests under `harness/test_*.py` — they're plain pytest using a
diff --git a/scripts/test/test_install.sh b/scripts/test/test_install.sh
index cba91e51..a9a953cf 100644
--- a/scripts/test/test_install.sh
+++ b/scripts/test/test_install.sh
@@ -41,6 +41,10 @@ trap 'rm -rf "$WORK"' EXIT
STUB_BIN="$WORK/bin"
PY_STUB="$WORK/pybin"
mkdir -p "$STUB_BIN" "$PY_STUB"
+# A no-op docker stub so the uninstall routine's `command -v docker` succeeds and
+# its compose-down branch runs deterministically — the CI containers don't have
+# docker installed, and we're only asserting on dry-run output anyway.
+printf '#!/usr/bin/env bash\nexit 0\n' > "$STUB_BIN/docker"; chmod +x "$STUB_BIN/docker"
mkpy() { # mkpy <name> <major.minor>
{
printf '#!/usr/bin/env bash\n'
@@ -275,6 +279,17 @@ else
bad "harden_global_tls should have edited in place (Debian-style)"
fi
+# --------------------------------------------------------------------------
+# T11 — choose_pkg_manager halts cleanly when no package manager is present
+# (empty PATH hides apt/dnf/yum/zypper/pacman/apk). No /etc writes happen
+# because the apt branch is never reached.
+# --------------------------------------------------------------------------
+if ( set -Eeuo pipefail; PATH=""; choose_pkg_manager ) >/dev/null 2>&1; then
+ bad "choose_pkg_manager should fail when no package manager exists"
+else
+ ok "choose_pkg_manager halts cleanly when no package manager is found"
+fi
+
# --------------------------------------------------------------------------
printf '\n%d passed, %d failed, %d skipped\n\n' "$PASS" "$FAIL" "$SKIP"
[ "$FAIL" -eq 0 ]
diff --git a/scripts/test/test_lib.sh b/scripts/test/test_lib.sh
index 7b1f91cf..3f37e610 100644
--- a/scripts/test/test_lib.sh
+++ b/scripts/test/test_lib.sh
@@ -57,7 +57,9 @@ for mgr in "${!expect_install[@]}"; do
done
[ "$allok" = "1" ] && ok "pkg_install emits the right command per manager (dry-run)"
-if ( set -Eeuo pipefail; PKG_MGR_OVERRIDE="" PKG_DRY_RUN=0 pkg_install git ) 2>/dev/null; then
+# Empty PATH genuinely hides every package manager (CI distro containers DO ship
+# one, so PKG_MGR_OVERRIDE="" alone would run a real install here).
+if ( set -Eeuo pipefail; PATH="" PKG_MGR_OVERRIDE="" PKG_DRY_RUN=0 pkg_install git ) 2>/dev/null; then
bad "pkg_install must fail (return 1) when no manager is detected"
else
ok "pkg_install returns non-zero when no package manager is present"
@@ -110,7 +112,10 @@ else
bad "is_container should be true for a docker cgroup"
fi
cg2="$WORK/cgroup-host"; printf '0::/init.scope\n' > "$cg2"
-if ( set -Eeuo pipefail; SERVERKIT_IS_CONTAINER="" SERVERKIT_CONTAINERENV_FILE="$WORK/none" SERVERKIT_DOCKERENV_FILE="$WORK/none" SERVERKIT_CGROUP_FILE="$cg2" is_container ); then
+# `container=""` neutralizes the ambient env var that RPM/SUSE base images set
+# (container=oci) — without it this case would see "we're in a container" via the
+# real environment and wrongly report true. We're isolating the cgroup path.
+if ( set -Eeuo pipefail; container="" SERVERKIT_IS_CONTAINER="" SERVERKIT_CONTAINERENV_FILE="$WORK/none" SERVERKIT_DOCKERENV_FILE="$WORK/none" SERVERKIT_CGROUP_FILE="$cg2" is_container ); then
bad "is_container should be false on a plain host cgroup"
else
ok "is_container false on a non-container cgroup"
diff --git a/scripts/test/vm-uninstall.sh b/scripts/test/vm-uninstall.sh
new file mode 100644
index 00000000..6aab1374
--- /dev/null
+++ b/scripts/test/vm-uninstall.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+# Runs inside the test VM. End-to-end test of the unified uninstaller
+# (uninstall.sh + scripts/lib/uninstall.sh), proving the data-handling matrix on
+# a real box:
+# 1. Install ServerKit and seed sample data (a sentinel under /var/lib + a DB).
+# 2. Default uninstall (--yes): the install tree is gone, but user data is
+# preserved — the /var/lib sentinel survives AND a pre-uninstall DB snapshot
+# lands in /var/backups/serverkit.
+# 3. Reinstall.
+# 4. Purge uninstall (--purge --yes): the data dirs (/var/lib, /etc/serverkit)
+# are removed.
+#
+# Writes OK/FAIL to /tmp/serverkit-uninstall-status and a full log to
+# /var/log/serverkit-test-uninstall.log (both pulled back by the harness).
+set -u # not -e: capture failures and still emit a report
+
+SRC=/opt/serverkit-src
+INSTALL_DIR=/opt/serverkit
+LOG=/var/log/serverkit-test-uninstall.log
+STATUS=/tmp/serverkit-uninstall-status
+SENTINEL=/var/lib/serverkit/.vm-uninstall-sentinel
+
+log() { echo "[vm-uninstall] $*" | tee -a "$LOG"; }
+fail() { echo "[vm-uninstall] FAIL: $*" | tee -a "$LOG"; echo FAIL > "$STATUS"; exit 1; }
+
+mkdir -p "$(dirname "$LOG")"
+: > "$LOG"
+
+install_sk() {
+ [ -f "$SRC/install.sh" ] || fail "install.sh not found in $SRC"
+ log "Installing ServerKit (clones release, installs deps)..."
+ bash "$SRC/install.sh" >> "$LOG" 2>&1 || fail "install.sh failed (rc=$?)"
+ [ -d "$INSTALL_DIR" ] || fail "install.sh did not create $INSTALL_DIR"
+}
+
+[ -d "$SRC" ] || fail "source dir $SRC missing — transfer broken"
+
+# 1. Install + seed sample data.
+log "Step 1/4: install + seed data"
+install_sk
+mkdir -p /var/lib/serverkit "$INSTALL_DIR/backend/instance"
+echo "keep-me" > "$SENTINEL"
+[ -f "$INSTALL_DIR/backend/instance/serverkit.db" ] || echo "sample-db" > "$INSTALL_DIR/backend/instance/serverkit.db"
+log "Seeded sentinel + database."
+
+# 2. Default uninstall — data must be preserved.
+log "Step 2/4: default uninstall (data preserved)"
+bash "$SRC/uninstall.sh" --yes >> "$LOG" 2>&1 || fail "default uninstall failed (rc=$?)"
+[ ! -d "$INSTALL_DIR" ] || fail "install dir still present after default uninstall"
+[ -f "$SENTINEL" ] || fail "default uninstall destroyed /var/lib/serverkit data"
+if ls /var/backups/serverkit/serverkit-pre-uninstall-*.db >/dev/null 2>&1; then
+ log "DB snapshot present in /var/backups/serverkit."
+else
+ fail "default uninstall did not snapshot the database to backups"
+fi
+log "Default uninstall preserved user data. OK."
+
+# 3. Reinstall.
+log "Step 3/4: reinstall"
+install_sk
+
+# 4. Purge uninstall — data must be removed.
+log "Step 4/4: purge uninstall (--purge)"
+bash "$SRC/uninstall.sh" --purge --yes >> "$LOG" 2>&1 || fail "purge uninstall failed (rc=$?)"
+[ ! -d "$INSTALL_DIR" ] || fail "install dir still present after purge"
+[ ! -e "$SENTINEL" ] || fail "--purge did not remove /var/lib/serverkit"
+[ ! -d /etc/serverkit ] || fail "--purge did not remove /etc/serverkit"
+log "Purge removed all data. OK."
+
+echo OK > "$STATUS"
+exit 0
diff --git a/scripts/test/vm-update.sh b/scripts/test/vm-update.sh
new file mode 100644
index 00000000..70f5f7f3
--- /dev/null
+++ b/scripts/test/vm-update.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+# Runs inside the test VM. Exercises scripts/update.sh end-to-end on a real box:
+# 1. Install ServerKit (if not already present); capture version V1.
+# 2. Run the LOCAL updater (from /opt/serverkit-src) with --force, so the whole
+# blue/green deploy → migrate → atomic-switch → health-check path runs and
+# we test THIS branch's update.sh (SERVERKIT_NO_SELF_UPDATE=1 keeps it from
+# re-execing into whatever update.sh is on the remote).
+# 3. Verify /api/v1/system/health returns 200 after the update.
+# 4. Re-run WITHOUT --force and confirm the version-gate reports
+# "Already up to date" (the Phase 2 skip-when-current behavior).
+#
+# Writes OK/FAIL to /tmp/serverkit-update-status and a full log to
+# /var/log/serverkit-test-update.log (both pulled back by the harness).
+set -u # not -e: we capture failures and still emit a report
+
+SRC=/opt/serverkit-src
+INSTALL_DIR=/opt/serverkit
+LOG=/var/log/serverkit-test-update.log
+STATUS=/tmp/serverkit-update-status
+
+log() { echo "[vm-update] $*" | tee -a "$LOG"; }
+fail() { echo "[vm-update] FAIL: $*" | tee -a "$LOG"; echo FAIL > "$STATUS"; exit 1; }
+
+mkdir -p "$(dirname "$LOG")"
+: > "$LOG"
+
+health() { curl -fsS http://127.0.0.1:5000/api/v1/system/health >/dev/null 2>&1; }
+wait_health() { local i; for i in $(seq 1 "${1:-60}"); do health && return 0; sleep 2; done; return 1; }
+read_version() { tr -d '\r\n ' < "$INSTALL_DIR/VERSION" 2>/dev/null || echo unknown; }
+
+[ -d "$SRC" ] || fail "source dir $SRC missing — transfer broken"
+
+# 1. Ensure ServerKit is installed.
+if [ ! -d "$INSTALL_DIR" ]; then
+ [ -f "$SRC/install.sh" ] || fail "install.sh not found in $SRC"
+ log "Step 1/4: installing ServerKit (clones release, installs deps)..."
+ bash "$SRC/install.sh" >> "$LOG" 2>&1 || fail "install.sh failed (rc=$?)"
+fi
+wait_health 60 || fail "backend not healthy after install"
+V1="$(read_version)"
+log "Installed version: $V1"
+
+# 2. Forced full update via the LOCAL updater.
+log "Step 2/4: forced update with the local updater (target main)..."
+SERVERKIT_DIR="$INSTALL_DIR" SERVERKIT_NO_SELF_UPDATE=1 \
+ bash "$SRC/scripts/update.sh" --force >> "$LOG" 2>&1 \
+ || fail "update.sh --force failed (see log)"
+
+# 3. Health after update.
+log "Step 3/4: waiting for health after update..."
+wait_health 90 || fail "backend not healthy after update"
+V2="$(read_version)"
+log "Post-update version: $V2"
+
+# 4. Version-gate: a second run without --force should skip.
+log "Step 4/4: re-running without --force (expecting 'Already up to date')..."
+OUT="$(SERVERKIT_DIR="$INSTALL_DIR" SERVERKIT_NO_SELF_UPDATE=1 \
+ bash "$SRC/scripts/update.sh" 2>&1 | tee -a "$LOG")"
+if printf '%s' "$OUT" | grep -qi "Already up to date"; then
+ log "Version-gate correctly skipped the redundant update."
+else
+ # Not fatal: the remote main could have advanced between the two runs. The
+ # health check below is the real gate.
+ log "WARN: second run did not report 'Already up to date' (remote may have advanced)."
+fi
+wait_health 90 || fail "backend not healthy after the second update run"
+
+log "Update test passed (V1=$V1 -> V2=$V2)"
+echo OK > "$STATUS"
+exit 0