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.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
test(scripts): chain multi-statement if-subshell assertions (no vacuous passes)
Juan Denis7345807b1290
diff --git a/scripts/test/test_agent_install.sh b/scripts/test/test_agent_install.shindex 05a055ce..195a6e73 100644--- a/scripts/test/test_agent_install.sh+++ b/scripts/test/test_agent_install.sh@@ -84,10 +84,12 @@ printf '[{"tag_name": "v1.6.0"},{"tag_name": "agent-v0.3.2"},{"tag_name": "agent: > "$CURL_LOG"if ! got="$(+ # && chain: set -e is suppressed inside an if-condition substitution, so+ # only an explicit chain makes get_latest_version's status gate the result.set -Eeuo pipefailVERSION="latest"; SERVERKIT_AGENT_VERSION=""; GITHUB_REPO="jhd3197/ServerKit"- get_latest_version >/dev/null- printf '%s' "$VERSION"+ get_latest_version >/dev/null \+ && printf '%s' "$VERSION")"; thenbad "paged discovery aborted under set -Eeuo pipefail"elif [ "$got" = "0.3.2" ]; then@@ -138,8 +140,8 @@ fiif ! got="$(set -Eeuo pipefailVERSION="latest"; SERVERKIT_AGENT_VERSION="9.9.9"; GITHUB_REPO="jhd3197/ServerKit"- get_latest_version >/dev/null- printf '%s' "$VERSION"+ get_latest_version >/dev/null \+ && printf '%s' "$VERSION")"; thenbad "panel-injected version path aborted under set -Eeuo pipefail"elif [ "$got" = "9.9.9" ] && [ ! -s "$CURL_LOG" ]; then@@ -152,8 +154,8 @@ fiif ! got="$(set -Eeuo pipefailVERSION="1.2.3"; SERVERKIT_AGENT_VERSION=""; GITHUB_REPO="jhd3197/ServerKit"- get_latest_version >/dev/null- printf '%s' "$VERSION"+ get_latest_version >/dev/null \+ && printf '%s' "$VERSION")"; thenbad "explicit --version path aborted under set -Eeuo pipefail"elif [ "$got" = "1.2.3" ] && [ ! -s "$CURL_LOG" ]; thendiff --git a/scripts/test/test_install.sh b/scripts/test/test_install.shindex 09e99e6c..5ea75a32 100644--- a/scripts/test/test_install.sh+++ b/scripts/test/test_install.sh@@ -77,7 +77,9 @@ printf '\ninstall.sh + lib unit tests\n\n'# --------------------------------------------------------------------------# T1 — locate_python prefers a supported minor version over a too-old python3.# ---------------------------------------------------------------------------if ! res="$( set -Eeuo pipefail; PATH="$PY_STUB:$PATH"; locate_python >/dev/null 2>&1; printf '%s' "$PYTHON_BIN" )"; then+# && chain: set -e is suppressed inside an if-condition substitution (see T16).+if ! res="$( set -Eeuo pipefail; PATH="$PY_STUB:$PATH"+ locate_python >/dev/null 2>&1 && printf '%s' "$PYTHON_BIN" )"; thenbad "locate_python aborted under set -Eeuo pipefail"elif [ "$res" = "python3.11" ]; thenok "locate_python picks python3.11 when python3 is 3.10 and python3.12 is out of range"@@ -139,7 +141,8 @@ fi# --------------------------------------------------------------------------# T5 — firewall_detect honors the FIREWALL_BACKEND override.# ---------------------------------------------------------------------------if ! res="$( set -Eeuo pipefail; source "$LIB_DIR/firewall.sh"; FIREWALL_BACKEND=ufw firewall_detect )"; then+if ! res="$( set -Eeuo pipefail; source "$LIB_DIR/firewall.sh" \+ && FIREWALL_BACKEND=ufw firewall_detect )"; thenbad "firewall_detect aborted under set -Eeuo pipefail"elif [ "$res" = "ufw" ]; thenok "firewall_detect honors FIREWALL_BACKEND override"@@ -153,17 +156,19 @@ fiif command -v python3 >/dev/null 2>&1; thent6_rc=0res="$(- set -Eeuo pipefail- export SERVERKIT_STATE_FILE="$WORK/state-t6.json"- source "$LIB_DIR/state.sh"- state_set firewall_backend firewalld- state_append firewall_ports 80/tcp- state_append firewall_ports 443/tcp- state_append firewall_ports 80/tcp # duplicate — must be ignored+ # && chain: this capture sits on the left of `||`, where bash+ # suppresses set -e even inside the substitution (see T16).# tr -d '\r' normalizes the CRLF that Python's text-mode stdout emits on# Windows; on Linux there is nothing to strip.- printf '%s|%s' "$(state_get firewall_backend | tr -d '\r')" \- "$(state_list firewall_ports | tr -d '\r' | tr '\n' ',')"+ set -Eeuo pipefail+ export SERVERKIT_STATE_FILE="$WORK/state-t6.json"+ source "$LIB_DIR/state.sh" \+ && state_set firewall_backend firewalld \+ && state_append firewall_ports 80/tcp \+ && state_append firewall_ports 443/tcp \+ && state_append firewall_ports 80/tcp `# duplicate — must be ignored` \+ && printf '%s|%s' "$(state_get firewall_backend | tr -d '\r')" \+ "$(state_list firewall_ports | tr -d '\r' | tr '\n' ',')")" || t6_rc=$?if [ "$t6_rc" -eq 0 ] && [ "$res" = "firewalld|80/tcp,443/tcp," ]; thenok "state.sh set/get/append(dedup)/list roundtrip"@@ -185,11 +190,13 @@ touch "$inst/docker-compose.yml"uninstall_out() { # uninstall_out <extra-env>(+ # && chain: called from if-conditions, where set -e is suppressed+ # all the way down (see T16).set -Eeuo pipefail- source "$LIB_DIR/uninstall.sh"- export SERVERKIT_DIR="$inst" SERVERKIT_UNINSTALL_DRY_RUN=1- eval "$1"- serverkit_uninstall_core 2>&1+ source "$LIB_DIR/uninstall.sh" \+ && export SERVERKIT_DIR="$inst" SERVERKIT_UNINSTALL_DRY_RUN=1 \+ && eval "$1" \+ && serverkit_uninstall_core 2>&1)}@@ -368,8 +375,8 @@ fiif ! res="$(printf 'panel.example.com\n' | (set -Eeuo pipefailPANEL_DOMAIN=""; PANEL_PORT=""; SERVERKIT_FORCE_PROMPT=1- prompt_for_domain >/dev/null 2>&1- printf '%s|%s' "$PANEL_DOMAIN" "$PANEL_PORT"+ prompt_for_domain >/dev/null 2>&1 \+ && printf '%s|%s' "$PANEL_DOMAIN" "$PANEL_PORT"))"; thenbad "prompt_for_domain aborted on a typed domain under set -Eeuo pipefail"elif [ "$res" = "panel.example.com|80" ]; then@@ -495,8 +502,8 @@ printf '#!/bin/sh\n' > "$t/slot/venv/bin/python"; chmod +x "$t/slot/venv/bin/pytif (set -Eeuo pipefailINSTALL_FROM_RELEASE=1; FIRST_SLOT="$t/slot"; VENV_DIR="$t/slot/venv"- build_virtualenv- [ -f "$t/slot/venv/bin/activate" ]+ build_virtualenv \+ && [ -f "$t/slot/venv/bin/activate" ]) >/dev/null 2>&1; thenok "build_virtualenv keeps the venv when source and destination are the same directory"else@@ -505,8 +512,9 @@ fiif (set -Eeuo pipefailINSTALL_FROM_RELEASE=1; FIRST_SLOT="$t/slot"; VENV_DIR="$t/elsewhere/venv"- build_virtualenv- [ -f "$t/elsewhere/venv/bin/activate" ] && [ -f "$t/slot/venv/bin/activate" ]+ build_virtualenv \+ && [ -f "$t/elsewhere/venv/bin/activate" ] \+ && [ -f "$t/slot/venv/bin/activate" ]) >/dev/null 2>&1; thenok "build_virtualenv still copies the release venv to a distinct VENV_DIR"else@@ -519,8 +527,8 @@ elseif (set -Eeuo pipefailINSTALL_FROM_RELEASE=1; FIRST_SLOT="$t/slot"; VENV_DIR="$t/link/venv"- build_virtualenv- [ -x "$t/slot/venv/bin/python" ]+ build_virtualenv \+ && [ -x "$t/slot/venv/bin/python" ]) >/dev/null 2>&1; thenok "build_virtualenv survives the default symlinked layout (/opt/serverkit → slot)"else@@ -790,7 +798,8 @@ fi# under pipefail.# --------------------------------------------------------------------------t="$WORK/t28"; mkdir -p "$t/nofree"-if ! res="$( set -Eeuo pipefail; PATH="$t/nofree"; SAFE_MODE=true; gauge_memory >/dev/null 2>&1; printf '%s' "$SAFE_MODE" )"; then+if ! res="$( set -Eeuo pipefail; PATH="$t/nofree"; SAFE_MODE=true+ gauge_memory >/dev/null 2>&1 && printf '%s' "$SAFE_MODE" )"; thenbad "gauge_memory aborted without 'free' under set -Eeuo pipefail (I14 regression)"elif [ "$res" = "false" ]; thenok "gauge_memory degrades gracefully when 'free' is absent (LXC templates)"@@ -1016,7 +1025,8 @@ EOFchmod +x "$t/sysd/systemctl"svc_rc=0( set -Eeuo pipefail; PATH="$t/sysd:$PATH"- INIT_OVERRIDE=systemd svc_enable nginx; INIT_OVERRIDE=systemd svc_start nginx ) >/dev/null 2>&1 || svc_rc=$?+ INIT_OVERRIDE=systemd svc_enable nginx \+ && INIT_OVERRIDE=systemd svc_start nginx ) >/dev/null 2>&1 || svc_rc=$?if [ "$svc_rc" -eq 0 ] && grep -q 'systemctl enable nginx' "$SVC_LOG" && grep -q 'systemctl start nginx' "$SVC_LOG"; thenok "svc_enable/svc_start drive systemctl on systemd boxes"else@@ -1086,8 +1096,8 @@ VERSION="24.04.1 LTS (Noble Numbat)"OSR_EOFif ! res="$( set -Eeuo pipefailVERSION="sk-sentinel"- SERVERKIT_OS_RELEASE="$t/os-release" identify_system >/dev/null 2>&1- printf '%s|%s' "$VERSION" "$OS_FAMILY" )"; then+ SERVERKIT_OS_RELEASE="$t/os-release" identify_system >/dev/null 2>&1 \+ && printf '%s|%s' "$VERSION" "$OS_FAMILY" )"; thenbad "identify_system aborted under set -Eeuo pipefail"elif [ "$res" = "sk-sentinel|debian" ]; thenok "identify_system keeps the installer's \$VERSION across the os-release source"diff --git a/scripts/test/test_lib.sh b/scripts/test/test_lib.shindex 61a660d1..4f26086f 100644--- a/scripts/test/test_lib.sh+++ b/scripts/test/test_lib.sh@@ -249,8 +249,13 @@ UFW_EOFchmod +x "$t/on/ufw"printf '#!/bin/sh\necho "Status: inactive"\n' > "$t/off/ufw"; chmod +x "$t/off/ufw"fw_rc=0-got="$( set -Eeuo pipefail; source "$LIB_DIR/firewall.sh"; PATH="$t/on" FIREWALL_BACKEND="" firewall_detect )" || fw_rc=$?-got2="$( set -Eeuo pipefail; source "$LIB_DIR/firewall.sh"; PATH="$t/off" FIREWALL_BACKEND="" firewall_detect )" || fw_rc=$?+# && chains: these captures sit on the left of `||` (and the if-conditions+# below), where bash suppresses set -e even inside the subshell/substitution —+# sequential statements would gate only on the LAST one.+got="$( set -Eeuo pipefail; source "$LIB_DIR/firewall.sh" \+ && PATH="$t/on" FIREWALL_BACKEND="" firewall_detect )" || fw_rc=$?+got2="$( set -Eeuo pipefail; source "$LIB_DIR/firewall.sh" \+ && PATH="$t/off" FIREWALL_BACKEND="" firewall_detect )" || fw_rc=$?if [ "$fw_rc" -eq 0 ] && [ "$got" = "ufw" ] && [ "$got2" = "none" ]; thenok "firewall_detect sees an active ufw under pipefail and never misreads 'inactive'"else@@ -258,8 +263,8 @@ elsefierrf="$WORK/fw-noargs.err"-if ( set -Eeuo pipefail; source "$LIB_DIR/firewall.sh"- firewall_open && firewall_close && firewall_manual_hint >/dev/null ) 2>"$errf"; then+if ( set -Eeuo pipefail; source "$LIB_DIR/firewall.sh" \+ && firewall_open && firewall_close && firewall_manual_hint >/dev/null ) 2>"$errf"; thenif grep -q 'unbound variable' "$errf"; thenbad "zero-arg firewall helpers leaked an unbound-variable error"else@@ -278,8 +283,8 @@ fiif command -v python3 >/dev/null 2>&1; thensdir="$WORK/state-as-dir"; mkdir -p "$sdir"errf="$WORK/state-l1.err"- if ( set -Eeuo pipefail; source "$LIB_DIR/state.sh"- SERVERKIT_STATE_FILE="$sdir" state_set firewall_backend ufw ) 2>"$errf"; then+ if ( set -Eeuo pipefail; source "$LIB_DIR/state.sh" \+ && SERVERKIT_STATE_FILE="$sdir" state_set firewall_backend ufw ) 2>"$errf"; thenif grep -q '\[state\]' "$errf"; thenok "state_set warns and exits 0 when the state path is a directory"else@@ -289,25 +294,25 @@ if command -v python3 >/dev/null 2>&1; thenbad "state_set ABORTED when the state path is a directory (L1 regression)"fi- if out="$( set -Eeuo pipefail; source "$LIB_DIR/state.sh"- SERVERKIT_STATE_FILE="$sdir" state_get firewall_backend 2>/dev/null )" \+ if out="$( set -Eeuo pipefail; source "$LIB_DIR/state.sh" \+ && SERVERKIT_STATE_FILE="$sdir" state_get firewall_backend 2>/dev/null )" \&& [ -z "$out" ]; thenok "state_get is quiet-empty (exit 0) on an unreadable state path"elsebad "state_get aborted or printed [$out] on an unreadable state path"fi- if ( set -Eeuo pipefail; source "$LIB_DIR/state.sh"- ports="$(SERVERKIT_STATE_FILE="$sdir" state_list firewall_ports | tr '\n' ' ')"- [ -z "${ports// /}" ] ); then+ if ( set -Eeuo pipefail; source "$LIB_DIR/state.sh" \+ && ports="$(SERVERKIT_STATE_FILE="$sdir" state_list firewall_ports | tr '\n' ' ')" \+ && [ -z "${ports// /}" ] ); thenok "state_list | tr survives set -Eeuo pipefail on an unreadable state path"elsebad "state_list | tr aborted under pipefail (the L2-shaped uninstall killer)"fi: > "$WORK/state-blocker"- if ( set -Eeuo pipefail; source "$LIB_DIR/state.sh"- SERVERKIT_STATE_FILE="$WORK/state-blocker/state.json" state_append firewall_ports 80/tcp ) 2>/dev/null; then+ if ( set -Eeuo pipefail; source "$LIB_DIR/state.sh" \+ && SERVERKIT_STATE_FILE="$WORK/state-blocker/state.json" state_append firewall_ports 80/tcp ) 2>/dev/null; thenok "state_append warns and exits 0 when the state parent is a regular file"elsebad "state_append ABORTED when the state parent is a regular file (L1 regression)"@@ -317,8 +322,8 @@ if command -v python3 >/dev/null 2>&1; then# write may legitimately succeed — the contract under test is only# "never non-zero", which must hold either way.ro="$WORK/state-ro"; mkdir -p "$ro"; chmod 555 "$ro" 2>/dev/null || true- if ( set -Eeuo pipefail; source "$LIB_DIR/state.sh"- SERVERKIT_STATE_FILE="$ro/state.json" state_set k v ) 2>/dev/null; then+ if ( set -Eeuo pipefail; source "$LIB_DIR/state.sh" \+ && SERVERKIT_STATE_FILE="$ro/state.json" state_set k v ) 2>/dev/null; thenok "state_set exits 0 with an unwritable state directory"elsebad "state_set ABORTED on an unwritable state directory (L1 regression)"@@ -380,10 +385,10 @@ fi: > "$CURL_LOG"if (set -Eeuo pipefail- source "$LIB_DIR/uninstall.sh"- export PATH="$t/bin:$PATH"- export SERVERKIT_DIR="$t/inst" SERVERKIT_UNINSTALL_DRY_RUN=1- serverkit_uninstall_core+ source "$LIB_DIR/uninstall.sh" \+ && export PATH="$t/bin:$PATH" \+ && export SERVERKIT_DIR="$t/inst" SERVERKIT_UNINSTALL_DRY_RUN=1 \+ && serverkit_uninstall_core) >/dev/null 2>&1 && [ ! -s "$CURL_LOG" ]; thenok "uninstall --dry-run never phones home (L8)"elsediff --git a/scripts/test/test_update.sh b/scripts/test/test_update.shindex b2b65f95..eb8d4a58 100644--- a/scripts/test/test_update.sh+++ b/scripts/test/test_update.sh@@ -452,12 +452,15 @@ printf 'old-copy\n' > "$t/old/backend/app/plugins/shipped-plugin/__init__.py"printf 'stale\n' > "$t/old/backend/app/plugins/__pycache__/x.pyc"printf 'repo-copy\n' > "$t/new/backend/app/plugins/shipped-plugin/__init__.py"if (+ # One && chain, not sequential statements: bash suppresses set -e inside+ # an if-condition subshell, so only an explicit chain makes every+ # assertion gate the result (same fix as test_install.sh T16).set -Eeuo pipefail- preserve_installed_plugins "$t/old" "$t/new"- [ -f "$t/new/backend/app/plugins/third-party/blueprint.py" ]- [ -f "$t/new/frontend/src/plugins/third-party/index.jsx" ]- [ ! -d "$t/new/backend/app/plugins/__pycache__" ]- grep -q repo-copy "$t/new/backend/app/plugins/shipped-plugin/__init__.py"+ preserve_installed_plugins "$t/old" "$t/new" \+ && [ -f "$t/new/backend/app/plugins/third-party/blueprint.py" ] \+ && [ -f "$t/new/frontend/src/plugins/third-party/index.jsx" ] \+ && [ ! -d "$t/new/backend/app/plugins/__pycache__" ] \+ && grep -q repo-copy "$t/new/backend/app/plugins/shipped-plugin/__init__.py") >/dev/null 2>&1; thenok "preserve_installed_plugins carries user plugins forward without clobbering repo-shipped ones"else@@ -473,8 +476,8 @@ fit="$WORK/t19"; mkdir -p "$t/empty" "$t/ret"prune_survives() {( set -Eeuo pipefail; BACKUP_DIR="$t/empty"- prune_old_backups 'serverkit-tree-*' 10- prune_old_backups 'serverkit-pre-upgrade-*.db' 10 ) &&+ prune_old_backups 'serverkit-tree-*' 10 \+ && prune_old_backups 'serverkit-pre-upgrade-*.db' 10 ) &&( set -Eeuo pipefail; BACKUP_DIR="$t/gone"; prune_old_backups 'serverkit-tree-*' 10 ) &&( set -Eeuo pipefail; BACKUP_DIR="$t/empty"; INSTALL_DIR="$t/no-install"; DRY_RUN=0; cleanup )}@@ -669,11 +672,14 @@ chmod +x "$STUB_BIN/flask"exp="$(cd "$WORK" && pwd)"t24_rc=0res="$(+ # && chain: this capture sits on the left of `||`, where bash suppresses+ # set -e even inside the substitution — sequential statements would let a+ # failing cd/migrate slip through ungated.set -Eeuo pipefailDRY_RUN=0- cd "$WORK"- migrate_database "$t" >/dev/null 2>&1- pwd+ cd "$WORK" \+ && migrate_database "$t" >/dev/null 2>&1 \+ && pwd)" || t24_rc=$?rm -f "$STUB_BIN/flask"if [ "$t24_rc" -eq 0 ] && [ "$res" = "$exp" ]; then@@ -817,13 +823,17 @@ make_stub_curl_fail22 "$t/bindown" # every upstream refuses → "down"t28_rc=0out="$({+ # && chain: this capture sits on the left of `||`, where bash+ # suppresses set -e even inside the substitution. The chain gates on+ # every statement, which is exactly what set -e does to the real+ # (sequential) run block.set -Eeuo pipefailexport PATH="$FRESH/bin:$PATH"APP_LOCATIONS_DIR="$FRESH/etc/nginx/serverkit-locations"; DRY_RUN=0- APP_BASELINE="$(snapshot_app_reachability)"- phase "Verifying App Uptime"- APP_AFTER="$(snapshot_app_reachability)"- report_app_uptime_regressions "$APP_BASELINE" "$APP_AFTER" || true+ APP_BASELINE="$(snapshot_app_reachability)" \+ && phase "Verifying App Uptime" \+ && APP_AFTER="$(snapshot_app_reachability)" \+ && { report_app_uptime_regressions "$APP_BASELINE" "$APP_AFTER" || true; }} 2>&1)" || t28_rc=$?if [ "$t28_rc" -eq 0 ] && printf '%s' "$out" | grep -q 'No managed apps'; then@@ -839,11 +849,11 @@ out="$(set -Eeuo pipefailAPP_LOCATIONS_DIR="$t/loc"; DRY_RUN=0export PATH="$t/binup:$PATH" # app reachable pre-switch- APP_BASELINE="$(snapshot_app_reachability)"- export PATH="$t/bindown:$PATH" # app dead post-switch → regression- phase "Verifying App Uptime"- APP_AFTER="$(snapshot_app_reachability)"- report_app_uptime_regressions "$APP_BASELINE" "$APP_AFTER" || true+ APP_BASELINE="$(snapshot_app_reachability)" \+ && export PATH="$t/bindown:$PATH" `# app dead post-switch → regression` \+ && phase "Verifying App Uptime" \+ && APP_AFTER="$(snapshot_app_reachability)" \+ && { report_app_uptime_regressions "$APP_BASELINE" "$APP_AFTER" || true; }} 2>&1)" || t28_rc=$?if [ "$t28_rc" -eq 0 ] && printf '%s' "$out" | grep -q 'DOWN now'; then