@@ -18,6 +18,17 @@ async def fake_chat_stream(**kwargs):
1818 return fake_chat_stream , call_tracker , mock_stream
1919
2020
21+ def _make_async_api_mock ():
22+ mock_response = MagicMock ()
23+ call_tracker = MagicMock ()
24+
25+ async def fake_api_call (** kwargs ):
26+ call_tracker (** kwargs )
27+ return mock_response
28+
29+ return fake_api_call , call_tracker , mock_response
30+
31+
2132class TestAsyncBoltAgent :
2233 @pytest .mark .asyncio
2334 async def test_chat_stream_uses_context_defaults (self ):
@@ -107,6 +118,116 @@ async def test_chat_stream_passes_extra_kwargs(self):
107118 buffer_size = 512 ,
108119 )
109120
121+ @pytest .mark .asyncio
122+ async def test_set_status_uses_context_defaults (self ):
123+ """AsyncBoltAgent.set_status() passes context defaults to AsyncWebClient.assistant_threads_setStatus()."""
124+ client = MagicMock (spec = AsyncWebClient )
125+ client .assistant_threads_setStatus , call_tracker , _ = _make_async_api_mock ()
126+
127+ agent = AsyncBoltAgent (
128+ client = client ,
129+ channel_id = "C111" ,
130+ thread_ts = "1234567890.123456" ,
131+ team_id = "T111" ,
132+ user_id = "W222" ,
133+ )
134+ await agent .set_status (status = "Thinking..." )
135+
136+ call_tracker .assert_called_once_with (
137+ channel_id = "C111" ,
138+ thread_ts = "1234567890.123456" ,
139+ status = "Thinking..." ,
140+ loading_messages = None ,
141+ )
142+
143+ @pytest .mark .asyncio
144+ async def test_set_status_with_loading_messages (self ):
145+ """AsyncBoltAgent.set_status() forwards loading_messages."""
146+ client = MagicMock (spec = AsyncWebClient )
147+ client .assistant_threads_setStatus , call_tracker , _ = _make_async_api_mock ()
148+
149+ agent = AsyncBoltAgent (
150+ client = client ,
151+ channel_id = "C111" ,
152+ thread_ts = "1234567890.123456" ,
153+ team_id = "T111" ,
154+ user_id = "W222" ,
155+ )
156+ await agent .set_status (
157+ status = "Thinking..." ,
158+ loading_messages = ["Sitting..." , "Waiting..." ],
159+ )
160+
161+ call_tracker .assert_called_once_with (
162+ channel_id = "C111" ,
163+ thread_ts = "1234567890.123456" ,
164+ status = "Thinking..." ,
165+ loading_messages = ["Sitting..." , "Waiting..." ],
166+ )
167+
168+ @pytest .mark .asyncio
169+ async def test_set_status_overrides_context_defaults (self ):
170+ """Explicit channel/thread_ts override context defaults."""
171+ client = MagicMock (spec = AsyncWebClient )
172+ client .assistant_threads_setStatus , call_tracker , _ = _make_async_api_mock ()
173+
174+ agent = AsyncBoltAgent (
175+ client = client ,
176+ channel_id = "C111" ,
177+ thread_ts = "1234567890.123456" ,
178+ team_id = "T111" ,
179+ user_id = "W222" ,
180+ )
181+ await agent .set_status (
182+ status = "Thinking..." ,
183+ channel = "C999" ,
184+ thread_ts = "9999999999.999999" ,
185+ )
186+
187+ call_tracker .assert_called_once_with (
188+ channel_id = "C999" ,
189+ thread_ts = "9999999999.999999" ,
190+ status = "Thinking..." ,
191+ loading_messages = None ,
192+ )
193+
194+ @pytest .mark .asyncio
195+ async def test_set_status_passes_extra_kwargs (self ):
196+ """Extra kwargs are forwarded to AsyncWebClient.assistant_threads_setStatus()."""
197+ client = MagicMock (spec = AsyncWebClient )
198+ client .assistant_threads_setStatus , call_tracker , _ = _make_async_api_mock ()
199+
200+ agent = AsyncBoltAgent (
201+ client = client ,
202+ channel_id = "C111" ,
203+ thread_ts = "1234567890.123456" ,
204+ team_id = "T111" ,
205+ user_id = "W222" ,
206+ )
207+ await agent .set_status (status = "Thinking..." , token = "xoxb-override" )
208+
209+ call_tracker .assert_called_once_with (
210+ channel_id = "C111" ,
211+ thread_ts = "1234567890.123456" ,
212+ status = "Thinking..." ,
213+ loading_messages = None ,
214+ token = "xoxb-override" ,
215+ )
216+
217+ @pytest .mark .asyncio
218+ async def test_set_status_requires_status (self ):
219+ """set_status() raises TypeError when status is not provided."""
220+ client = MagicMock (spec = AsyncWebClient )
221+ agent = AsyncBoltAgent (
222+ client = client ,
223+ channel_id = "C111" ,
224+ thread_ts = "1234567890.123456" ,
225+ team_id = "T111" ,
226+ user_id = "W222" ,
227+ )
228+ with pytest .raises (TypeError ):
229+ await agent .set_status ()
230+
110231 @pytest .mark .asyncio
111232 async def test_import_from_agent_module (self ):
112233 from slack_bolt .agent .async_agent import AsyncBoltAgent as ImportedAsyncBoltAgent
0 commit comments