From 7849a3d73f2d3fcf905cac69eff726160f40956a Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Fri, 22 May 2026 14:08:08 -0700 Subject: [PATCH] fix(gateway,discord-plugin): _platform_status must respect is_connected=False, not silently fall back to check_fn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs surfaced by PR #24356 migrating Discord into the registry: 1. plugins/platforms/discord/adapter.py::_is_connected — read DISCORD_BOT_TOKEN via hermes_cli.gateway.get_env_value (the abstraction tests patch) instead of os.getenv directly. The legacy non-registry path used get_env_value; bypassing it broke test_setup_openclaw_migration which patches gateway_mod.get_env_value to simulate a hermetic env. 2. hermes_cli/gateway.py::_platform_status — when entry.is_connected is defined and returns False, return 'not configured' immediately. Don't fall back to entry.check_fn(), which would let 'SDK is installed' override 'no token configured' and incorrectly report the platform as ready. The fallback to check_fn is the right behaviour only when is_connected is None (not registered). Fixes 5 test failures observed on CI for PR #24356: - tests/hermes_cli/test_setup.py::test_setup_gateway_skips_service_install_when_systemctl_missing - tests/hermes_cli/test_setup.py::test_setup_gateway_in_container_shows_docker_guidance - tests/hermes_cli/test_setup_irc.py::TestIRCGatewaySetupFreshInstall::test_setup_gateway_irc_counts_as_messaging_platform - tests/hermes_cli/test_setup_openclaw_migration.py::TestGetSectionConfigSummary::test_gateway_returns_none_without_tokens - tests/hermes_cli/test_setup_openclaw_migration.py::TestSetupWizardSkipsConfiguredSections::test_sections_skipped_when_migration_imported_settings Same _platform_status bug exists for sibling plugin platforms (teams, google_chat) whose check_fn returns true on SDK install alone; their tests just never exercised the registry path before. The bug only became test-visible when Discord migrated into the registry. Validation: 11,167 tests across tests/gateway/ + tests/cron/ + tests/tools/test_send_message_tool.py + tests/hermes_cli/ pass with zero failures. --- hermes_cli/gateway.py | 7 ++++++- plugins/platforms/discord/adapter.py | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py index 4313f6c2541..3af87830cf3 100644 --- a/hermes_cli/gateway.py +++ b/hermes_cli/gateway.py @@ -3737,7 +3737,12 @@ def _platform_status(platform: dict) -> str: configured = bool(entry.is_connected(synthetic)) except Exception: configured = False - if not configured: + else: + # No is_connected hook — fall back to check_fn as a coarse + # "are deps present" gate. Don't fall back when is_connected + # is defined and returned False; that would let "SDK is + # installed" override "no token configured" and incorrectly + # report the platform as ready. try: configured = bool(entry.check_fn()) except Exception: diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py index 30eee2b3da6..efe0b5d1de7 100644 --- a/plugins/platforms/discord/adapter.py +++ b/plugins/platforms/discord/adapter.py @@ -6137,9 +6137,16 @@ def _apply_yaml_config(yaml_cfg: dict, discord_cfg: dict) -> dict | None: def _is_connected(config) -> bool: - """Discord is considered connected when DISCORD_BOT_TOKEN is set.""" - import os - return bool(os.getenv("DISCORD_BOT_TOKEN", "").strip()) + """Discord is considered connected when DISCORD_BOT_TOKEN is set. + + Looks up via ``hermes_cli.gateway.get_env_value`` at call time (not via + the plugin's own bound import) so tests that patch ``gateway_mod.get_env_value`` + — including ``test_setup_openclaw_migration`` — can suppress ambient + ``DISCORD_BOT_TOKEN`` env vars. Matches what the legacy + ``_PLATFORMS["discord"]`` dispatch did before this migration. + """ + import hermes_cli.gateway as gateway_mod + return bool((gateway_mod.get_env_value("DISCORD_BOT_TOKEN") or "").strip()) def _build_adapter(config):