test: Farben/Variablen-Smoke stellt et_divi und die Variablen-Option byte-genau wieder her und scheitert bei fehlgeschlagener Wiederherstellung

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-19 14:39:42 +02:00
co-authored by Claude Sonnet 5.5
parent 02ed5bdbd3
commit e2e28cd1b4
@@ -3,8 +3,9 @@
# detach on a page, snapshots, restore) through the OAuth-protected endpoint against the real Divi. Runs INSIDE the
# DDEV web container:
# cd /home/janniclas/Projekte/WordPress && timeout 900 ddev exec bash wp-content/plugins/WP-LIT-MCP/tests/Integration/divi-colors-variables-smoke.sh
# Creates colors/variables named "LIT Smoke <run> …" and one draft page. The EXIT trap puts the options et_divi (colors,
# customizer colors) and et_divi_global_variables back to what they were and deletes the page by exact ID.
# Creates colors/variables named "LIT Smoke <run> …" and one draft page. The EXIT trap puts the WHOLE options et_divi
# (colors, customizer colors, every other theme option) and et_divi_global_variables back byte-exact (serialized, base64
# through the environment), checks the result and deletes the page by exact ID. A failed restore fails the script.
set -euo pipefail
cd /var/www/html
# shellcheck source=lib.sh
@@ -13,21 +14,30 @@ source wp-content/plugins/WP-LIT-MCP/tests/Integration/lib.sh
ADMIN_LOGIN=$(wp user list --role=administrator --field=user_login | head -1)
RUN="$(date +%s)-$$"
PREFIX="LIT Smoke $RUN"
ORIGINAL_THEME=$(wp option get et_divi --format=json 2>/dev/null || echo '{}')
ORIGINAL_VARIABLES=$(wp option get et_divi_global_variables --format=json 2>/dev/null || echo '{}')
capture() { wp eval "echo base64_encode(serialize(get_option('$1')));"; } # $1 = option name
ORIGINAL_THEME=$(capture et_divi)
ORIGINAL_VARIABLES=$(capture et_divi_global_variables)
# Abort before any change: without a capture there is nothing to restore.
[ -n "$ORIGINAL_THEME" ] || { echo "FAIL: could not capture et_divi"; exit 1; }
[ -n "$ORIGINAL_VARIABLES" ] || { echo "FAIL: could not capture et_divi_global_variables"; exit 1; }
PAGE_ID=""
restore() { # $1 = option name, $2 = name of the environment variable that holds the capture
local LIT_CAPTURE="$2"; export LIT_CAPTURE
LIT_OPTION="$1" wp eval '$n = getenv("LIT_OPTION"); $v = unserialize(base64_decode(getenv(getenv("LIT_CAPTURE")))); update_option($n, $v); exit(serialize(get_option($n)) === serialize($v) ? 0 : 1);' >/dev/null 2>&1 \
|| { echo "FAIL: $1 not restored"; return 1; }
}
cleanup() {
printf '%s' "$LIT_THEME" | wp option update et_divi --format=json >/dev/null 2>&1 \
|| echo "WARN: et_divi not restored"
printf '%s' "$LIT_VARIABLES" | wp option update et_divi_global_variables --format=json >/dev/null 2>&1 \
|| echo "WARN: global variables not restored"
local failed=0
restore et_divi LIT_THEME || failed=1
restore et_divi_global_variables LIT_VARIABLES || failed=1
wp eval 'ET_Core_PageResource::remove_static_resources("all", "all", true);' >/dev/null 2>&1 || true
if [ -n "$PAGE_ID" ]; then wp post delete "$PAGE_ID" --force >/dev/null 2>&1 || true; fi
cleanup_app_passwords_for "$ADMIN_LOGIN"
return "$failed"
}
export LIT_THEME="$ORIGINAL_THEME" LIT_VARIABLES="$ORIGINAL_VARIABLES"
trap 'rc=$?; cleanup; guard_exit "$rc" || exit $?' EXIT
trap 'rc=$?; cleanup || rc=1; guard_exit "$rc" || exit $?' EXIT
connect "$ADMIN_LOGIN"