The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(discord): apply YAML allow_bots to ingress policy
Chike Okonta954113839b30
diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.pyindex 4521301cd1f..0489c166566 100644--- a/plugins/platforms/discord/adapter.py+++ b/plugins/platforms/discord/adapter.py@@ -4693,7 +4693,8 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):def _get_allow_bots(self) -> str:"""Per-profile DISCORD_ALLOW_BOTS mode (none|mentions|all)."""- return self._gate_env("DISCORD_ALLOW_BOTS", "none").lower().strip() or "none"+ raw = self._gate_raw("allow_bots", "DISCORD_ALLOW_BOTS")+ return str(raw or "none").lower().strip() or "none"def _discord_free_response_channels(self) -> set:"""Channel IDs/names needing no mention; a lone "*" is preserved for wildcard short-circuit."""@@ -6993,6 +6994,7 @@ def _apply_yaml_config(yaml_cfg: dict, discord_cfg: dict) -> dict | None:_gate("allow_from", "DISCORD_ALLOWED_USERS", from_platform_extra=True)_gate("allowed_roles", "DISCORD_ALLOWED_ROLES", from_platform_extra=True)_gate("allow_all_users", "DISCORD_ALLOW_ALL_USERS", from_platform_extra=True, lower=True)+ _gate("allow_bots", "DISCORD_ALLOW_BOTS", from_platform_extra=True, lower=True)approval_mentions_cfg = (discord_cfg["approval_mentions"] if "approval_mentions" in discord_cfgelse platform_extra_cfg.get("approval_mentions")diff --git a/tests/gateway/test_discord_allow_bots_yaml_config.py b/tests/gateway/test_discord_allow_bots_yaml_config.pynew file mode 100644index 00000000000..7ef5d03cd25--- /dev/null+++ b/tests/gateway/test_discord_allow_bots_yaml_config.py@@ -0,0 +1,67 @@+"""config.yaml `discord.allow_bots` must reach the adapter's bot gate.++Invariant: every Discord allowlist gate configurable in `config.yaml` resolves through+`PlatformConfig.extra` even when no `DISCORD_*` env var is set. `allow_bots` regressed+because `_get_allow_bots()` read env only, so a YAML-configured value was silently+ignored and bot-to-bot handoffs stayed blocked.+"""++import importlib+import sys+import types++import pytest+++def adapter_mod():+ sys.modules.pop("plugins.platforms.discord.adapter", None)+ return importlib.import_module("plugins.platforms.discord.adapter")+++def _seed(adapter_mod, yaml_cfg, discord_cfg):+ return adapter_mod._apply_yaml_config(yaml_cfg, discord_cfg)+++def test_yaml_allow_bots_is_seeded_into_extra(adapter_mod, monkeypatch):+ monkeypatch.delenv("DISCORD_ALLOW_BOTS", raising=False)+ seeded = _seed(adapter_mod, {}, {"allow_bots": "mentions"})+ assert seeded is not None+ assert seeded.get("allow_bots") == "mentions"+++def _fake_adapter(adapter_mod, extra, env_overrides=None):+ """A DiscordAdapter shell with only the gate-resolution state populated."""+ adapter = object.__new__(adapter_mod.DiscordAdapter)+ adapter.config = types.SimpleNamespace(extra=extra)+ snapshot = {key: "" for key in adapter_mod._GATE_ENV_KEYS}+ snapshot.update(env_overrides or {})+ adapter._gate_env_snapshot = snapshot+ return adapter+++def test_adapter_reads_allow_bots_from_extra_without_env(adapter_mod, monkeypatch):+ monkeypatch.delenv("DISCORD_ALLOW_BOTS", raising=False)+ monkeypatch.setattr(adapter_mod, "_scoped_gate_env", lambda name, default="": default)++ adapter = _fake_adapter(adapter_mod, {"allow_bots": "mentions"})++ assert adapter._get_allow_bots() == "mentions"+++def test_env_still_wins_over_yaml_for_allow_bots(adapter_mod, monkeypatch):+ monkeypatch.setattr(adapter_mod, "_scoped_gate_env", lambda name, default="": default)++ adapter = _fake_adapter(+ adapter_mod, {"allow_bots": "mentions"}, {"DISCORD_ALLOW_BOTS": "all"}+ )++ assert adapter._get_allow_bots() == "all"+++def test_allow_bots_defaults_to_none_when_unconfigured(adapter_mod, monkeypatch):+ monkeypatch.setattr(adapter_mod, "_scoped_gate_env", lambda name, default="": default)++ adapter = _fake_adapter(adapter_mod, {})++ assert adapter._get_allow_bots() == "none"