"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
test(slack): run the DM pairing tests without the Slack SDK (#1524)
Haozhe Wubf67839b0707
diff --git a/agent/tests/slack_stubs.py b/agent/tests/slack_stubs.pynew file mode 100644index 000000000..1a534a44e--- /dev/null+++ b/agent/tests/slack_stubs.py@@ -0,0 +1,43 @@+"""Import stand-ins for the optional Slack SDK, shared by the Slack tests.++CI installs no channel extras, so ``src.channels.slack`` cannot import+``slack_sdk`` there. Each test file used to stub it its own way; one stubbed+``SocketModeResponse = object``, which then broke any later test that builds a+response (``object(envelope_id=...)`` raises TypeError) depending on import+order (#1524). The stand-ins here accept keyword arguments like the real+classes, and nothing is installed when the real package is present.+"""++from __future__ import annotations++import importlib.util+import sys+import types+++def _module(name: str) -> types.ModuleType:+ module = types.ModuleType(name)+ sys.modules[name] = module+ return module+++def install_slack_stubs() -> None:+ """Make ``src.channels.slack`` importable without the Slack extras."""+ if "slack_sdk" not in sys.modules and importlib.util.find_spec("slack_sdk") is None:+ for name in (+ "slack_sdk",+ "slack_sdk.socket_mode",+ "slack_sdk.socket_mode.request",+ "slack_sdk.socket_mode.response",+ "slack_sdk.socket_mode.websockets",+ "slack_sdk.web",+ "slack_sdk.web.async_client",+ ):+ _module(name)+ keyword_record = (types.SimpleNamespace,)+ sys.modules["slack_sdk.socket_mode.request"].SocketModeRequest = type("SocketModeRequest", keyword_record, {})+ sys.modules["slack_sdk.socket_mode.response"].SocketModeResponse = type("SocketModeResponse", keyword_record, {})+ sys.modules["slack_sdk.socket_mode.websockets"].SocketModeClient = object+ sys.modules["slack_sdk.web.async_client"].AsyncWebClient = object+ if "slackify_markdown" not in sys.modules and importlib.util.find_spec("slackify_markdown") is None:+ _module("slackify_markdown").slackify_markdown = lambda text: textdiff --git a/agent/tests/test_slack_dm_pairing.py b/agent/tests/test_slack_dm_pairing.pyindex aa3cd5f65..fd45b2c5d 100644--- a/agent/tests/test_slack_dm_pairing.py+++ b/agent/tests/test_slack_dm_pairing.py@@ -7,11 +7,15 @@ from __future__ import annotationsimport asynciofrom unittest.mock import AsyncMock-from slack_sdk.socket_mode.request import SocketModeRequest+from tests.slack_stubs import install_slack_stubs-from src.channels.bus.events import OutboundMessage-from src.channels.pairing import PAIRING_CODE_META_KEY-from src.channels.slack import SlackChannel, SlackConfig+install_slack_stubs()++from slack_sdk.socket_mode.request import SocketModeRequest # noqa: E402++from src.channels.bus.events import OutboundMessage # noqa: E402+from src.channels.pairing import PAIRING_CODE_META_KEY # noqa: E402+from src.channels.slack import SlackChannel, SlackConfig # noqa: E402def _channel() -> SlackChannel:diff --git a/agent/tests/test_slack_table_edge_columns.py b/agent/tests/test_slack_table_edge_columns.pyindex d7a2eaaf6..4499a0b94 100644--- a/agent/tests/test_slack_table_edge_columns.py+++ b/agent/tests/test_slack_table_edge_columns.py@@ -3,39 +3,10 @@from __future__ import annotationsimport re-import sys-import types+from tests.slack_stubs import install_slack_stubs-def _stub_slack_deps() -> None:- """Install minimal stubs so slack.py imports without slack_sdk/slackify."""-- def _mod(name: str) -> types.ModuleType:- mod = types.ModuleType(name)- sys.modules[name] = mod- return mod-- for name in (- "slack_sdk",- "slack_sdk.socket_mode",- "slack_sdk.socket_mode.request",- "slack_sdk.socket_mode.response",- "slack_sdk.socket_mode.websockets",- "slack_sdk.web",- "slack_sdk.web.async_client",- ):- _mod(name)-- sys.modules["slack_sdk.socket_mode.request"].SocketModeRequest = object- sys.modules["slack_sdk.socket_mode.response"].SocketModeResponse = object- sys.modules["slack_sdk.socket_mode.websockets"].SocketModeClient = object- sys.modules["slack_sdk.web.async_client"].AsyncWebClient = object-- sm = _mod("slackify_markdown")- sm.slackify_markdown = lambda text: text---_stub_slack_deps()+install_slack_stubs()from src.channels.slack import SlackChannel # noqa: E402