fix: guard role_authorized check against MagicMock test sources

Compare source.role_authorized with 'is True' so a MagicMock source
(test fixtures that build bare runners via object.__new__) doesn't
auto-truthy through the gate. The real SessionSource field is a bool,
so production behavior is unchanged. Fixes test_signal_in_allowlist_maps.
This commit is contained in:
teknium1 2026-06-09 22:41:53 -07:00 committed by Teknium
parent 099146fedd
commit 4eadef18a9

View file

@ -209,7 +209,10 @@ class GatewayAuthorizationMixin:
# Adapter-verified role auth: the Discord adapter already confirmed the
# user holds a role in DISCORD_ALLOWED_ROLES before dispatching the message.
if getattr(source, "role_authorized", False):
# Compare with ``is True`` so the real bool field authorizes while a
# MagicMock source (test fixtures using ``object.__new__`` runners with
# mock sources) does not auto-truthy through this gate (see pitfall #13).
if getattr(source, "role_authorized", False) is True:
return True
if getattr(source, "is_bot", False):