mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-22 05:22:09 +00:00
Merge pull request #21012 from stephenschoettler/fix/ci-pr-check-unblock
fix(ci): unblock shared PR checks
This commit is contained in:
commit
cd64bed55e
10 changed files with 194 additions and 70 deletions
|
|
@ -10,6 +10,80 @@ import pytest
|
|||
from gateway.config import Platform, PlatformConfig
|
||||
|
||||
|
||||
class _FakeDingTalkModel:
|
||||
def __init__(self, **kwargs):
|
||||
self.__dict__.update(kwargs)
|
||||
|
||||
|
||||
class _FakeChatbotMessage(SimpleNamespace):
|
||||
@classmethod
|
||||
def from_dict(cls, data):
|
||||
data = data or {}
|
||||
return cls(
|
||||
message_id=data.get("msgId") or data.get("messageId") or data.get("message_id") or "",
|
||||
conversation_id=data.get("conversationId") or data.get("conversation_id") or "",
|
||||
conversation_type=str(data.get("conversationType") or data.get("conversation_type") or "1"),
|
||||
sender_id=data.get("senderId") or data.get("sender_id") or "",
|
||||
sender_staff_id=data.get("senderStaffId") or data.get("sender_staff_id") or data.get("senderId") or "",
|
||||
sender_nick=data.get("senderNick") or data.get("sender_nick") or "",
|
||||
text=data.get("text") or "",
|
||||
rich_text=data.get("richText") or data.get("rich_text"),
|
||||
rich_text_content=data.get("richTextContent") or data.get("rich_text_content"),
|
||||
session_webhook=data.get("sessionWebhook") or data.get("session_webhook") or "",
|
||||
session_webhook_expired_time=data.get("sessionWebhookExpiredTime") or data.get("session_webhook_expired_time") or 0,
|
||||
create_at=data.get("createAt") or data.get("create_at") or 0,
|
||||
at_users=data.get("atUsers") or data.get("at_users") or [],
|
||||
is_in_at_list=bool(data.get("isInAtList") or data.get("is_in_at_list")),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _fake_dingtalk_optional_sdks(monkeypatch):
|
||||
"""Keep DingTalk adapter tests hermetic when optional SDKs are absent."""
|
||||
from gateway.platforms import dingtalk as dt
|
||||
|
||||
card_models = SimpleNamespace(**{
|
||||
name: _FakeDingTalkModel
|
||||
for name in (
|
||||
"CreateCardRequest",
|
||||
"CreateCardRequestCardData",
|
||||
"CreateCardRequestImGroupOpenSpaceModel",
|
||||
"CreateCardRequestImRobotOpenSpaceModel",
|
||||
"CreateCardHeaders",
|
||||
"DeliverCardRequest",
|
||||
"DeliverCardRequestImGroupOpenDeliverModel",
|
||||
"DeliverCardRequestImRobotOpenDeliverModel",
|
||||
"DeliverCardHeaders",
|
||||
"StreamingUpdateRequest",
|
||||
"StreamingUpdateHeaders",
|
||||
)
|
||||
})
|
||||
robot_models = SimpleNamespace(**{
|
||||
name: _FakeDingTalkModel
|
||||
for name in (
|
||||
"RobotReplyEmotionRequestTextEmotion",
|
||||
"RobotReplyEmotionRequest",
|
||||
"RobotReplyEmotionHeaders",
|
||||
"RobotRecallEmotionRequestTextEmotion",
|
||||
"RobotRecallEmotionRequest",
|
||||
"RobotRecallEmotionHeaders",
|
||||
"RobotMessageFileDownloadRequest",
|
||||
"RobotMessageFileDownloadHeaders",
|
||||
)
|
||||
})
|
||||
|
||||
monkeypatch.setattr(dt, "ChatbotMessage", _FakeChatbotMessage, raising=False)
|
||||
monkeypatch.setattr(
|
||||
dt,
|
||||
"AckMessage",
|
||||
SimpleNamespace(STATUS_OK=200, STATUS_SYSTEM_EXCEPTION=500),
|
||||
raising=False,
|
||||
)
|
||||
monkeypatch.setattr(dt, "tea_util_models", SimpleNamespace(RuntimeOptions=_FakeDingTalkModel), raising=False)
|
||||
monkeypatch.setattr(dt, "dingtalk_card_models", card_models, raising=False)
|
||||
monkeypatch.setattr(dt, "dingtalk_robot_models", robot_models, raising=False)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Requirements check
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
@ -18,7 +92,8 @@ from gateway.config import Platform, PlatformConfig
|
|||
class TestDingTalkRequirements:
|
||||
|
||||
def test_returns_false_when_sdk_missing(self, monkeypatch):
|
||||
with patch.dict("sys.modules", {"dingtalk_stream": None}):
|
||||
with patch.dict("sys.modules", {"dingtalk_stream": None}), \
|
||||
patch("tools.lazy_deps.ensure", side_effect=ImportError("dingtalk_stream unavailable")):
|
||||
monkeypatch.setattr(
|
||||
"gateway.platforms.dingtalk.DINGTALK_STREAM_AVAILABLE", False
|
||||
)
|
||||
|
|
|
|||
|
|
@ -455,7 +455,36 @@ def test_admit_per_group_require_mention_overrides_global():
|
|||
def test_hydrate_bot_identity_populates_self_ids_from_bot_v3_info(monkeypatch):
|
||||
import asyncio
|
||||
|
||||
from gateway.platforms.feishu import FeishuAdapter
|
||||
from gateway.platforms import feishu as feishu_mod
|
||||
FeishuAdapter = feishu_mod.FeishuAdapter
|
||||
|
||||
class _FakeBaseRequestBuilder:
|
||||
def __init__(self):
|
||||
self._request = SimpleNamespace()
|
||||
|
||||
def http_method(self, value):
|
||||
self._request.http_method = value
|
||||
return self
|
||||
|
||||
def uri(self, value):
|
||||
self._request.uri = value
|
||||
return self
|
||||
|
||||
def token_types(self, value):
|
||||
self._request.token_types = value
|
||||
return self
|
||||
|
||||
def build(self):
|
||||
return self._request
|
||||
|
||||
monkeypatch.setattr(
|
||||
feishu_mod,
|
||||
"BaseRequest",
|
||||
SimpleNamespace(builder=lambda: _FakeBaseRequestBuilder()),
|
||||
raising=False,
|
||||
)
|
||||
monkeypatch.setattr(feishu_mod, "HttpMethod", SimpleNamespace(GET="GET"), raising=False)
|
||||
monkeypatch.setattr(feishu_mod, "AccessTokenType", SimpleNamespace(TENANT="TENANT"), raising=False)
|
||||
|
||||
adapter = object.__new__(FeishuAdapter)
|
||||
adapter._bot_open_id = ""
|
||||
|
|
|
|||
|
|
@ -716,8 +716,10 @@ class TestMatrixModuleImport:
|
|||
"sys.meta_path.insert(0, _Blocker())\n"
|
||||
"for k in list(sys.modules):\n"
|
||||
" if k.startswith('mautrix'): del sys.modules[k]\n"
|
||||
"from unittest.mock import patch\n"
|
||||
"from gateway.platforms.matrix import check_matrix_requirements\n"
|
||||
"assert not check_matrix_requirements()\n"
|
||||
"with patch('tools.lazy_deps.ensure', side_effect=ImportError('blocked')):\n"
|
||||
" assert not check_matrix_requirements()\n"
|
||||
"print('OK')\n"
|
||||
)],
|
||||
capture_output=True, text=True, timeout=10,
|
||||
|
|
@ -737,7 +739,8 @@ class TestMatrixRequirements:
|
|||
import mautrix # noqa: F401
|
||||
assert check_matrix_requirements() is True
|
||||
except ImportError:
|
||||
assert check_matrix_requirements() is False
|
||||
with patch("tools.lazy_deps.ensure", side_effect=ImportError("mautrix unavailable")):
|
||||
assert check_matrix_requirements() is False
|
||||
|
||||
def test_check_requirements_without_creds(self, monkeypatch):
|
||||
monkeypatch.delenv("MATRIX_ACCESS_TOKEN", raising=False)
|
||||
|
|
@ -759,7 +762,8 @@ class TestMatrixRequirements:
|
|||
monkeypatch.setenv("MATRIX_ENCRYPTION", "true")
|
||||
|
||||
from gateway.platforms import matrix as matrix_mod
|
||||
with patch.object(matrix_mod, "_check_e2ee_deps", return_value=False):
|
||||
with patch.object(matrix_mod, "_check_e2ee_deps", return_value=False), \
|
||||
patch("tools.lazy_deps.ensure", side_effect=ImportError("mautrix unavailable")):
|
||||
assert matrix_mod.check_matrix_requirements() is False
|
||||
|
||||
def test_check_requirements_encryption_false_no_e2ee_deps_ok(self, monkeypatch):
|
||||
|
|
@ -775,7 +779,8 @@ class TestMatrixRequirements:
|
|||
import mautrix # noqa: F401
|
||||
assert matrix_mod.check_matrix_requirements() is True
|
||||
except ImportError:
|
||||
assert matrix_mod.check_matrix_requirements() is False
|
||||
with patch("tools.lazy_deps.ensure", side_effect=ImportError("mautrix unavailable")):
|
||||
assert matrix_mod.check_matrix_requirements() is False
|
||||
|
||||
def test_check_requirements_encryption_true_with_e2ee_deps(self, monkeypatch):
|
||||
"""MATRIX_ENCRYPTION=true should pass if E2EE deps are available."""
|
||||
|
|
@ -789,7 +794,8 @@ class TestMatrixRequirements:
|
|||
import mautrix # noqa: F401
|
||||
assert matrix_mod.check_matrix_requirements() is True
|
||||
except ImportError:
|
||||
assert matrix_mod.check_matrix_requirements() is False
|
||||
with patch("tools.lazy_deps.ensure", side_effect=ImportError("mautrix unavailable")):
|
||||
assert matrix_mod.check_matrix_requirements() is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue