mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-24 16:54:43 +00:00
fix(slack): resolve file events with cached workspace team
This commit is contained in:
parent
57f8ba3b19
commit
40351d0923
2 changed files with 33 additions and 0 deletions
|
|
@ -4338,6 +4338,12 @@ class SlackAdapter(BasePlatformAdapter):
|
|||
if not channel_id:
|
||||
channel_id = assistant_meta.get("channel_id", "")
|
||||
team_id = outer_team_id or assistant_meta.get("team_id", "")
|
||||
|
||||
# File-upload events sometimes omit team_id. Resolve from the channel
|
||||
# workspace cache so multi-workspace token lookup uses the right bot.
|
||||
if not team_id and channel_id in self._channel_team:
|
||||
team_id = self._channel_team[channel_id]
|
||||
|
||||
agent_context = self._agent_view_context_for_event(
|
||||
event, str(team_id or ""), str(user_id or "")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2103,6 +2103,33 @@ class TestIncomingDocumentHandling:
|
|||
assert os.path.exists(msg_event.media_urls[0])
|
||||
assert msg_event.media_types == ["application/pdf"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_uses_cached_channel_team_for_file_events_without_team_id(self, adapter):
|
||||
"""File events use the channel workspace cache when Slack omits team_id."""
|
||||
content = b"Hello from workspace two"
|
||||
adapter._channel_team["D123"] = "T_SECOND"
|
||||
|
||||
with patch.object(adapter, "_download_slack_file_bytes", new_callable=AsyncMock) as dl:
|
||||
dl.return_value = content
|
||||
event = self._make_event(
|
||||
text="summarize this",
|
||||
files=[{
|
||||
"mimetype": "text/plain",
|
||||
"name": "workspace-two.txt",
|
||||
"url_private_download": "https://files.slack.com/workspace-two.txt",
|
||||
"size": len(content),
|
||||
}],
|
||||
)
|
||||
assert "team" not in event
|
||||
assert "team_id" not in event
|
||||
|
||||
await adapter._handle_slack_message(event)
|
||||
|
||||
dl.assert_awaited_once()
|
||||
assert dl.await_args.kwargs["team_id"] == "T_SECOND"
|
||||
msg_event = adapter.handle_message.call_args[0][0]
|
||||
assert "Hello from workspace two" in msg_event.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_txt_document_injects_content(self, adapter):
|
||||
"""A .txt file under 100KB should have its content injected into event text."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue