Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(backup): warn about plugin code left in the legacy ./plugins

Yudhi Armyndharisfa5f41fb3f2b
diff --git a/docs/11-operational-runbooks.md b/docs/11-operational-runbooks.md
index 01d20f536..4ec0da325 100644
--- a/docs/11-operational-runbooks.md
+++ b/docs/11-operational-runbooks.md
@@ -607,6 +607,8 @@ User-managed files outside that list (for example the project-level `.env`) must
# STORAGE_TYPE=s3 it holds only files the app could not
# write to the bucket, so back up the bucket separately)
# - plugin-packages/ — installed plugin code from PLUGINS_DIR
+# (not packages in a legacy ./plugins, which the app still loads while
+# PLUGINS_DIR is unset; backup.sh warns about those)
# - plugin-state/ — registry + ctx.storage state under OPENWA_DATA_DIR
# - .env.generated / .api-key — generated configuration and bootstrap secret
# (.api-key from BOOTSTRAP_KEY_FILE when that is set)
diff --git a/scripts/backup.sh b/scripts/backup.sh
index a145f340d..ceec7653a 100755
--- a/scripts/backup.sh
+++ b/scripts/backup.sh
@@ -198,6 +198,14 @@ if [ -d "$PLUGIN_PACKAGES_DIR" ]; then
cp -pRH "$PLUGIN_PACKAGES_DIR" "$STAGE/plugin-packages"
fi
+# With PLUGINS_DIR unset the app also loads packages from ./plugins, its default up to 0.12.1 (see
+# plugin-package-scanner.ts). The archive does not carry that directory, so say so.
+if [ -z "$(openwa_resolve PLUGINS_DIR '')" ] &&
+ [ -n "$(find -H ./plugins -mindepth 2 -maxdepth 2 -name manifest.json ! -path './plugins/.*' 2>/dev/null)" ]; then
+ log "WARN: ./plugins holds plugin packages the app still loads, and this archive does not carry them;"
+ log " move them into $PLUGIN_PACKAGES_DIR, or set PLUGINS_DIR=./plugins, and back up again"
+fi
+
if [ -d "$PLUGIN_STATE_DIR" ]; then
log "Backing up plugin registry and persisted state"
cp -pRH "$PLUGIN_STATE_DIR" "$STAGE/plugin-state"
diff --git a/scripts/smoke-test-backup-restore.sh b/scripts/smoke-test-backup-restore.sh
index a1b1d59cd..f7ee33c3a 100755
--- a/scripts/smoke-test-backup-restore.sh
+++ b/scripts/smoke-test-backup-restore.sh
@@ -36,6 +36,7 @@
# (w) the default colocated plugins dir is rebuilt from both archive members, even when they differ
# (x) a relocated BOOTSTRAP_KEY_FILE is archived and restored there, and an unwritable one is refused
# before any database is written (that half skipped as root)
+# (y) plugin packages in the legacy ./plugins, which the archive does not carry, are reported
#
# Usage: ./scripts/smoke-test-backup-restore.sh
# Requires: bash, tar, node (restore.sh path resolution). sqlite3 is optional (see (c) and (k)).
@@ -1112,5 +1113,24 @@ if [ "$(id -u)" -ne 0 ]; then
fi
pass "(x) BOOTSTRAP_KEY_FILE is honoured by backup and by restore"
+echo ""
+echo "==> (y) plugin code in the legacy ./plugins is reported, since the archive does not carry it"
+# With PLUGINS_DIR unset the app still loads packages from ./plugins, the default up to 0.12.1, but
+# the archive holds only <data dir>/plugins, so a restore brings back a registry with no code.
+Y="$WORK/y"
+mkdir -p "$Y/data" "$Y/plugins/legacy-bot"
+make_fixture "$Y/data/main.sqlite" "yankee-main"
+make_fixture "$Y/data/openwa.sqlite" "yankee-data"
+printf '{"id":"legacy-bot"}' >"$Y/plugins/legacy-bot/manifest.json"
+OUT_Y="$(cd "$Y" && BACKUP_DIR="$Y/out" "$BACKUP" 2>&1)"
+if ! printf '%s' "$OUT_Y" | grep -q 'WARN: ./plugins holds plugin packages'; then
+ fail "(y) plugin code in the legacy ./plugins was left out without a warning"
+fi
+OUT_Y="$(cd "$Y" && PLUGINS_DIR="$Y/plugins" BACKUP_DIR="$Y/out2" "$BACKUP" 2>&1)"
+if printf '%s' "$OUT_Y" | grep -q 'WARN: ./plugins'; then
+ fail "(y) the legacy ./plugins was reported although PLUGINS_DIR names the plugin dir"
+fi
+pass "(y) packages in the legacy ./plugins are reported when PLUGINS_DIR is unset"
+
echo ""
echo "All smoke tests passed!"