mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
Under multiplex a secondary profile reads FEISHU_GROUP_POLICY from its own secret scope only (deliberate 0.21.3 isolation), so a profile whose .env carries no FEISHU_* policy keys falls back to `allowlist` with an empty FEISHU_ALLOWED_USERS and every human group message is rejected while DMs keep working. That deny was logged only at DEBUG, making it look like the events never arrived (#111420). Keep the scoped read as is — no environ fallthrough. Instead, the first group drop caused by the untouched allowlist default logs once at WARNING naming the chat and the keys to set (FEISHU_GROUP_POLICY / FEISHU_ALLOWED_USERS in the profile's own .env, or group_rules in its config.yaml). Operator-configured denies (populated allowlist, per-chat rule, non-allowlist policy) and later drops stay at DEBUG. The predicate lives in the topical sibling feishu_admission_diagnostics.py. Docs: the Group Message Policy section now states the per-profile read and where to put the keys under a multiplexed gateway. Co-authored-by: bear0328 <[email protected]> Co-authored-by: NanPan <[email protected]>
67 lines
2.7 KiB
Python
67 lines
2.7 KiB
Python
"""Operator-facing surfacing of the empty-allowlist default deny in Feishu group admission.
|
|
|
|
Secret scoping is deliberate: a secondary multiplex profile never inherits the launch
|
|
profile's FEISHU_GROUP_POLICY. What must not happen is the resulting deny being visible only
|
|
at DEBUG (#111420) — the first such drop is a WARNING naming the keys to set.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import logging
|
|
from types import SimpleNamespace
|
|
|
|
from tests.gateway.feishu_helpers import (
|
|
install_dedup_state,
|
|
make_adapter_skeleton,
|
|
make_message,
|
|
make_sender,
|
|
)
|
|
|
|
_LOGGER = "plugins.platforms.feishu.adapter"
|
|
|
|
|
|
def _group_event(message_id: str, chat_id: str = "oc_chat") -> SimpleNamespace:
|
|
return SimpleNamespace(
|
|
event=SimpleNamespace(
|
|
sender=make_sender(open_id="ou_human"),
|
|
message=make_message(message_id=message_id, chat_type="group", chat_id=chat_id),
|
|
)
|
|
)
|
|
|
|
|
|
def _drops(adapter, caplog, *events) -> list[logging.LogRecord]:
|
|
with caplog.at_level(logging.DEBUG, logger=_LOGGER):
|
|
for ev in events:
|
|
asyncio.run(adapter._handle_message_event_data(ev))
|
|
return [r for r in caplog.records if "group" in r.getMessage().lower() and "dropp" in r.getMessage().lower()]
|
|
|
|
|
|
def test_empty_allowlist_default_deny_warns_once_with_config_keys(caplog):
|
|
adapter = make_adapter_skeleton(group_policy="allowlist")
|
|
install_dedup_state(adapter)
|
|
|
|
records = _drops(adapter, caplog, _group_event("om_1"), _group_event("om_2"), _group_event("om_3"))
|
|
|
|
warnings = [r for r in records if r.levelno == logging.WARNING]
|
|
assert len(warnings) == 1, [r.getMessage() for r in records]
|
|
text = warnings[0].getMessage()
|
|
assert "FEISHU_ALLOWED_USERS" in text and "FEISHU_GROUP_POLICY" in text and "oc_chat" in text
|
|
# Later drops stay at DEBUG — the warning is a one-shot diagnostic, not per-message noise.
|
|
assert sum(r.levelno == logging.DEBUG for r in records) == 3
|
|
|
|
|
|
def test_configured_group_deny_stays_at_debug(caplog):
|
|
"""An operator-chosen deny (populated allowlist, or a per-chat rule) is not the misconfiguration."""
|
|
adapter = make_adapter_skeleton(group_policy="allowlist")
|
|
install_dedup_state(adapter)
|
|
adapter._allowed_group_users = frozenset({"ou_someone_else"})
|
|
|
|
ruled = make_adapter_skeleton(group_policy="allowlist")
|
|
install_dedup_state(ruled)
|
|
from plugins.platforms.feishu.adapter import FeishuGroupRule
|
|
ruled._group_rules = {"oc_chat": FeishuGroupRule(policy="disabled", allowlist=set(), blacklist=set(), require_mention=None)}
|
|
|
|
records = _drops(adapter, caplog, _group_event("om_a")) + _drops(ruled, caplog, _group_event("om_b"))
|
|
|
|
assert records and all(r.levelno == logging.DEBUG for r in records), [r.getMessage() for r in records]
|