fix(discovery): prevent WORDPRESS_ADVANCED_ prefix collision with WORDPRESS_

ProjectManager and SiteManager now skip env vars that belong to a more
specific plugin type (e.g. WORDPRESS_ADVANCED_*) when discovering sites
for a shorter prefix (WORDPRESS_). This prevents ghost projects, ERROR
logs, and false health alerts on startup.

Also downgrades Docker socket errors in WP-CLI to warnings — if Docker
socket is not mounted, WP-CLI features are silently unavailable instead
of logging ERROR and triggering health alerts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
airano
2026-02-18 17:08:34 +03:30
parent 85379ec36c
commit 3b87c01d78
3 changed files with 41 additions and 23 deletions

View File

@@ -211,12 +211,27 @@ class SiteManager:
"""
prefix = plugin_type.upper() + "_"
# Build list of longer prefixes from other plugin types to avoid collisions.
# e.g. WORDPRESS_ must not match WORDPRESS_ADVANCED_ env vars.
from plugins import registry as plugin_registry
all_plugin_types = plugin_registry.get_registered_types()
longer_prefixes = [
pt.upper() + "_"
for pt in all_plugin_types
if pt != plugin_type and pt.upper().startswith(plugin_type.upper() + "_")
]
# Pattern to match: WORDPRESS_SITE1_URL, WORDPRESS_SITE2_USERNAME, etc.
env_pattern = re.compile(f"^{prefix}([A-Z0-9_]+?)_(.+)$")
# Find all unique site IDs
site_ids = set()
for env_key in os.environ.keys():
# Skip env vars that belong to a more specific plugin type
if any(env_key.startswith(lp) for lp in longer_prefixes):
continue
match = env_pattern.match(env_key)
if match:
site_id = match.group(1).lower()