Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: disallow partial overrides of context args in agent chat_stream()
  • Loading branch information
mwbrooks committed Feb 12, 2026
commit 724ea5ff7940388e8d28c4f13c38f8bdf8dff895
5 changes: 5 additions & 0 deletions slack_bolt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def chat_stream(
Returns:
A new ``ChatStream`` instance.
"""
provided = [arg for arg in (channel, thread_ts, recipient_team_id, recipient_user_id) if arg is not None]
if provided and len(provided) < 4:
raise ValueError(
"Either provide all of channel, thread_ts, recipient_team_id, and recipient_user_id, or none of them"
)
resolved_channel = channel or self._channel_id
resolved_thread_ts = thread_ts or self._thread_ts
if resolved_channel is None:
Expand Down
5 changes: 5 additions & 0 deletions slack_bolt/agent/async_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ async def chat_stream(
Returns:
A new ``AsyncChatStream`` instance.
"""
provided = [arg for arg in (channel, thread_ts, recipient_team_id, recipient_user_id) if arg is not None]
if provided and len(provided) < 4:
raise ValueError(
"Either provide all of channel, thread_ts, recipient_team_id, and recipient_user_id, or none of them"
)
resolved_channel = channel or self._channel_id
resolved_thread_ts = thread_ts or self._thread_ts
if resolved_channel is None:
Expand Down
13 changes: 13 additions & 0 deletions tests/scenario_tests/test_events_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ def test_agent_chat_stream_overrides_context_defaults(self):
)
assert stream is not None

def test_agent_chat_stream_rejects_partial_overrides(self):
"""Passing only some of the four context args raises ValueError."""
client = MagicMock(spec=WebClient)
agent = BoltAgentDirect(
client=client,
channel_id="C111",
thread_ts="1234567890.123456",
team_id="T111",
user_id="W222",
)
with pytest.raises(ValueError, match="Either provide all of"):
agent.chat_stream(channel="C999")

def test_agent_chat_stream_passes_extra_kwargs(self):
"""Extra kwargs are forwarded to WebClient.chat_stream()."""
client = MagicMock(spec=WebClient)
Expand Down
14 changes: 14 additions & 0 deletions tests/scenario_tests_async/test_events_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ async def test_agent_chat_stream_overrides_context_defaults(self):
)
assert stream is not None

@pytest.mark.asyncio
async def test_agent_chat_stream_rejects_partial_overrides(self):
"""Passing only some of the four context args raises ValueError."""
client = MagicMock(spec=AsyncWebClient)
agent = AsyncBoltAgent(
client=client,
channel_id="C111",
thread_ts="1234567890.123456",
team_id="T111",
user_id="W222",
)
with pytest.raises(ValueError, match="Either provide all of"):
await agent.chat_stream(channel="C999")

@pytest.mark.asyncio
async def test_agent_chat_stream_passes_extra_kwargs(self):
"""Extra kwargs are forwarded to AsyncWebClient.chat_stream()."""
Expand Down