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
fix(test): stub pg_restore so the pg-dump assertions stop reading host state
Juan Denise97b5dee3bd6
diff --git a/scripts/test/stubs.sh b/scripts/test/stubs.shindex 7bca7d20..e48e1a66 100644--- a/scripts/test/stubs.sh+++ b/scripts/test/stubs.sh@@ -111,6 +111,34 @@ make_stub_sleep_noop() {make_stub_exit "$1" 0 sleep}+# pg_restore in TOC-listing mode (`pg_restore -l`), the archive check+# verify_pg_dump degrades to when the binary is present. MUST be stubbed:+# otherwise the assertion depends on the HOST. A runner with postgresql-client+# installed runs the real binary, which parses the version bytes after the+# PGDMP magic and rejects the suite's synthetic dumps; a runner without it+# skips the check entirely and accepts anything non-empty. Same fixtures, two+# verdicts. Here a dump is valid iff it carries the PGDMP magic.+make_stub_pg_restore() {+ cat > "$1/pg_restore" <<'PGR_EOF'+#!/usr/bin/env bash+dump=""+for arg in "$@"; do+ case "$arg" in -*) ;; *) dump="$arg" ;; esac+done+if [ -z "$dump" ] || [ ! -s "$dump" ]; then+ echo "pg_restore: error: could not open input file" >&2+ exit 1+fi+if [ "$(head -c 5 "$dump" 2>/dev/null)" != "PGDMP" ]; then+ echo "pg_restore: error: did not find magic string in file header" >&2+ exit 1+fi+printf ';\n; Archive created at 2026-01-01 00:00:00 UTC\n;\n'+exit 0+PGR_EOF+ chmod +x "$1/pg_restore"+}+# make_fresh_box_fixture <root> — lay out the degenerate fresh-box world:# <root>/bin PATH-prepend stubs: systemctl exit 5,# docker with zero containers, curldiff --git a/scripts/test/test_update.sh b/scripts/test/test_update.shindex 9a73ef3f..bf956633 100644--- a/scripts/test/test_update.sh+++ b/scripts/test/test_update.sh@@ -394,6 +394,7 @@ printf 'PGDMP fake contents\n' > "\$out"exit \${PG_DUMP_RC:-0}EOFchmod +x "$STUB_BIN/pg_dump"+make_stub_pg_restore "$STUB_BIN"bk_rc=0(set -Eeuo pipefail@@ -420,7 +421,7 @@ if [ "$bk_rc" -ne 0 ]; thenelsebad "backup_current proceeded despite a failed pg_dump (rc=0)"fi-rm -f "$STUB_BIN/pg_dump"+rm -f "$STUB_BIN/pg_dump" "$STUB_BIN/pg_restore"# --------------------------------------------------------------------------# T10f — backup verification helpers: a backup is only a safety net when it@@ -456,16 +457,23 @@ PYEOFfifi: > "$t/empty.dump"; printf 'PGDMP\nstuff\n' > "$t/full.dump"+# A non-archive that is merely NON-EMPTY is the fixture that separates the two+# verify_pg_dump branches: the size check passes it, only the TOC listing+# catches it. Requires the stub — see make_stub_pg_restore.+printf 'ERROR: connection refused\n' > "$t/garbage.dump"+make_stub_pg_restore "$STUB_BIN"v_rc=0(set -Eeuo pipefail- verify_pg_dump "$t/full.dump" && ! verify_pg_dump "$t/empty.dump" && ! verify_pg_dump "$t/missing.dump"+ verify_pg_dump "$t/full.dump" && ! verify_pg_dump "$t/empty.dump" \+ && ! verify_pg_dump "$t/missing.dump" && ! verify_pg_dump "$t/garbage.dump") >/dev/null 2>&1 || v_rc=$?if [ "$v_rc" -eq 0 ]; then- ok "verify_pg_dump rejects empty/missing dumps (TOC check when pg_restore exists)"+ ok "verify_pg_dump rejects empty/missing/non-archive dumps (TOC check via pg_restore)"elsebad "verify_pg_dump misclassified a fixture (rc=$v_rc)"fi+rm -f "$STUB_BIN/pg_restore"# --------------------------------------------------------------------------# T10g — a failed IN-PLACE PostgreSQL migration must trigger an automatic