test: divi-library smoke hygiene (M-14)
Per-run editor login and role, deleted only when this run created them (and refused when they exist); the allowed-roles option is deleted again when it was absent; the run-token fallback covers pages too; readOnlyHint must be false, not just missing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,15 +13,26 @@ cd /var/www/html
|
|||||||
source wp-content/plugins/WP-LIT-MCP/tests/Integration/lib.sh
|
source wp-content/plugins/WP-LIT-MCP/tests/Integration/lib.sh
|
||||||
|
|
||||||
ADMIN_LOGIN=$(wp user list --role=administrator --field=user_login | head -1)
|
ADMIN_LOGIN=$(wp user list --role=administrator --field=user_login | head -1)
|
||||||
EDITOR_LOGIN=lit-lib-editor
|
|
||||||
EDITOR_ROLE=lit_lib_editor
|
|
||||||
STAGE3=$PLUGIN/tests/Fixtures/divi/stage3
|
STAGE3=$PLUGIN/tests/Fixtures/divi/stage3
|
||||||
RUN="$(date +%s)-$$"
|
RUN="$(date +%s)-$$"
|
||||||
PREFIX="LIT Smoke $RUN"
|
PREFIX="LIT Smoke $RUN"
|
||||||
ORIGINAL_ROLES=$(wp option get lit_mcp_allowed_roles --format=json 2>/dev/null || echo '["administrator"]')
|
# Per-run names: cleanup never touches an account or role that existed before this run.
|
||||||
|
EDITOR_LOGIN="lit-lib-editor-$RUN"
|
||||||
|
EDITOR_ROLE="lit_lib_editor_${RUN//-/_}"
|
||||||
|
EDITOR_CREATED=0
|
||||||
|
ROLE_CREATED=0
|
||||||
|
ORIGINAL_ROLES=$(wp option get lit_mcp_allowed_roles --format=json 2>/dev/null || echo '__none__')
|
||||||
ORIGINAL_EXPOSURE=$(wp option get lit_mcp_exposure --format=json 2>/dev/null || echo '__none__')
|
ORIGINAL_EXPOSURE=$(wp option get lit_mcp_exposure --format=json 2>/dev/null || echo '__none__')
|
||||||
CREATED_POSTS=()
|
CREATED_POSTS=()
|
||||||
|
|
||||||
|
restore_roles() {
|
||||||
|
if [ "$ORIGINAL_ROLES" = "__none__" ]; then
|
||||||
|
wp option delete lit_mcp_allowed_roles >/dev/null 2>&1 || true
|
||||||
|
else
|
||||||
|
wp option update lit_mcp_allowed_roles "$ORIGINAL_ROLES" --format=json >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
restore_exposure() {
|
restore_exposure() {
|
||||||
if [ "$ORIGINAL_EXPOSURE" = "__none__" ]; then
|
if [ "$ORIGINAL_EXPOSURE" = "__none__" ]; then
|
||||||
wp option delete lit_mcp_exposure >/dev/null 2>&1 || true
|
wp option delete lit_mcp_exposure >/dev/null 2>&1 || true
|
||||||
@@ -31,12 +42,13 @@ restore_exposure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
# Library entries of this run whose ID a stopped run could not record (title prefix with the run token).
|
# Pages and library entries of this run whose ID a stopped run could not record (title prefix with the run token).
|
||||||
local found
|
local found
|
||||||
found=$(LIT_PREFIX="$PREFIX " wp eval '
|
found=$(LIT_PREFIX="$PREFIX " wp eval '
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
echo implode(" ", $wpdb->get_col($wpdb->prepare(
|
echo implode(" ", $wpdb->get_col($wpdb->prepare(
|
||||||
"SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_title LIKE %s",
|
"SELECT ID FROM $wpdb->posts WHERE post_type IN (%s, %s) AND post_title LIKE %s",
|
||||||
|
"page",
|
||||||
"et_pb_layout",
|
"et_pb_layout",
|
||||||
$wpdb->esc_like((string) getenv("LIT_PREFIX")) . "%"
|
$wpdb->esc_like((string) getenv("LIT_PREFIX")) . "%"
|
||||||
)));' 2>/dev/null || true)
|
)));' 2>/dev/null || true)
|
||||||
@@ -59,10 +71,14 @@ foreach (array_unique(array_filter(explode(" ", (string) getenv("LIT_IDS")))) as
|
|||||||
wp post delete "$id" --force >/dev/null 2>&1 || true
|
wp post delete "$id" --force >/dev/null 2>&1 || true
|
||||||
done
|
done
|
||||||
cleanup_app_passwords_for "$ADMIN_LOGIN"
|
cleanup_app_passwords_for "$ADMIN_LOGIN"
|
||||||
|
if [ "$EDITOR_CREATED" = 1 ]; then
|
||||||
cleanup_app_passwords_for "$EDITOR_LOGIN"
|
cleanup_app_passwords_for "$EDITOR_LOGIN"
|
||||||
wp user delete "$EDITOR_LOGIN" --yes >/dev/null 2>&1 || true
|
wp user delete "$EDITOR_LOGIN" --yes >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
if [ "$ROLE_CREATED" = 1 ]; then
|
||||||
wp role delete "$EDITOR_ROLE" >/dev/null 2>&1 || true
|
wp role delete "$EDITOR_ROLE" >/dev/null 2>&1 || true
|
||||||
wp option update lit_mcp_allowed_roles "$ORIGINAL_ROLES" --format=json >/dev/null 2>&1 || true
|
fi
|
||||||
|
restore_roles
|
||||||
restore_exposure
|
restore_exposure
|
||||||
}
|
}
|
||||||
trap 'rc=$?; cleanup; guard_exit "$rc" || exit $?' EXIT
|
trap 'rc=$?; cleanup; guard_exit "$rc" || exit $?' EXIT
|
||||||
@@ -161,7 +177,7 @@ connect "$ADMIN_LOGIN"
|
|||||||
|
|
||||||
# 1. Exposure: lit-library-insert direct, the other new tools indirect, 22 direct lit tools
|
# 1. Exposure: lit-library-insert direct, the other new tools indirect, 22 direct lit tools
|
||||||
LIST=$(rpc tools/list '{}')
|
LIST=$(rpc tools/list '{}')
|
||||||
echo "$LIST" | jq -e '.result.tools[] | select(.name == "lit-library-insert") | .annotations.readOnlyHint != true' >/dev/null \
|
echo "$LIST" | jq -e '.result.tools[] | select(.name == "lit-library-insert") | .annotations.readOnlyHint == false' >/dev/null \
|
||||||
|| fail "lit-library-insert is not a direct write tool"
|
|| fail "lit-library-insert is not a direct write tool"
|
||||||
for t in lit-library-list lit-library-save lit-divi-node-copy lit-divi-dynamic-sources; do
|
for t in lit-library-list lit-library-save lit-divi-node-copy lit-divi-dynamic-sources; do
|
||||||
if echo "$LIST" | jq -e --arg t "$t" '.result.tools[] | select(.name == $t)' >/dev/null; then fail "$t must be indirect"; fi
|
if echo "$LIST" | jq -e --arg t "$t" '.result.tools[] | select(.name == $t)' >/dev/null; then fail "$t must be indirect"; fi
|
||||||
@@ -368,10 +384,15 @@ done
|
|||||||
pass "admin (unfiltered_html) may save interactions, Lottie source and custom HTML to the library"
|
pass "admin (unfiltered_html) may save interactions, Lottie source and custom HTML to the library"
|
||||||
|
|
||||||
# 10. Temporary editor without unfiltered_html and without edit_private_pages
|
# 10. Temporary editor without unfiltered_html and without edit_private_pages
|
||||||
|
if wp user get "$EDITOR_LOGIN" >/dev/null 2>&1 || wp role exists "$EDITOR_ROLE" >/dev/null 2>&1; then
|
||||||
|
fail "user $EDITOR_LOGIN or role $EDITOR_ROLE exists already"
|
||||||
|
fi
|
||||||
wp role create "$EDITOR_ROLE" "LIT Smoke Bibliothek" --clone=editor >/dev/null
|
wp role create "$EDITOR_ROLE" "LIT Smoke Bibliothek" --clone=editor >/dev/null
|
||||||
|
ROLE_CREATED=1
|
||||||
wp cap remove "$EDITOR_ROLE" unfiltered_html edit_private_pages >/dev/null
|
wp cap remove "$EDITOR_ROLE" unfiltered_html edit_private_pages >/dev/null
|
||||||
wp option update lit_mcp_allowed_roles "[\"administrator\",\"$EDITOR_ROLE\"]" --format=json >/dev/null
|
wp option update lit_mcp_allowed_roles "[\"administrator\",\"$EDITOR_ROLE\"]" --format=json >/dev/null
|
||||||
wp user create "$EDITOR_LOGIN" lit-lib-editor@example.invalid --role="$EDITOR_ROLE" >/dev/null
|
wp user create "$EDITOR_LOGIN" "$EDITOR_LOGIN@example.invalid" --role="$EDITOR_ROLE" >/dev/null
|
||||||
|
EDITOR_CREATED=1
|
||||||
[ "$(LIT_LOGIN="$EDITOR_LOGIN" LIT_ID="$PRIVATE_ID" wp eval '
|
[ "$(LIT_LOGIN="$EDITOR_LOGIN" LIT_ID="$PRIVATE_ID" wp eval '
|
||||||
$u = get_user_by("login", getenv("LIT_LOGIN"));
|
$u = get_user_by("login", getenv("LIT_LOGIN"));
|
||||||
echo (user_can($u, "unfiltered_html") ? "html " : "") . (user_can($u, "edit_post", (int) getenv("LIT_ID")) ? "private" : "");')" = "" ] \
|
echo (user_can($u, "unfiltered_html") ? "html " : "") . (user_can($u, "edit_post", (int) getenv("LIT_ID")) ? "private" : "");')" = "" ] \
|
||||||
|
|||||||
Reference in New Issue
Block a user