fix(feishu): keep streaming replies in existing topics

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-04-30 13:42:37 +08:00
committed by Xubin Ren
parent d82f25e4d4
commit f8fd9f0011
2 changed files with 93 additions and 13 deletions
+70
View File
@@ -165,6 +165,26 @@ class TestSendDelta:
ch._client.im.v1.message.create.assert_called_once()
ch._client.im.v1.message.reply.assert_not_called()
@pytest.mark.asyncio
async def test_group_delta_keeps_existing_topic_when_reply_disabled(self):
ch = _make_channel(reply_to_message=False)
ch._client.cardkit.v1.card.create.return_value = _mock_create_card_response("card_new")
reply_resp = MagicMock()
reply_resp.success.return_value = True
ch._client.im.v1.message.reply.return_value = reply_resp
ch._client.cardkit.v1.card_element.content.return_value = _mock_content_response()
await ch.send_delta(
"oc_chat1",
"Hello ",
metadata={"message_id": "om_001", "chat_type": "group", "thread_id": "ot_001"},
)
ch._client.im.v1.message.reply.assert_called_once()
ch._client.im.v1.message.create.assert_not_called()
request = ch._client.im.v1.message.reply.call_args[0][0]
assert request.request_body.reply_in_thread is not True
@pytest.mark.asyncio
async def test_group_delta_replies_in_thread_when_reply_enabled(self):
ch = _make_channel(reply_to_message=True)
@@ -258,6 +278,32 @@ class TestSendDelta:
ch._client.im.v1.message.create.assert_called_once()
ch._client.im.v1.message.reply.assert_not_called()
@pytest.mark.asyncio
async def test_stream_end_fallback_keeps_existing_topic_when_reply_disabled(self):
ch = _make_channel(reply_to_message=False)
ch._stream_bufs["om_001"] = _FeishuStreamBuf(
text="Fallback content", card_id=None, sequence=0, last_edit=0.0,
)
reply_resp = MagicMock()
reply_resp.success.return_value = True
ch._client.im.v1.message.reply.return_value = reply_resp
await ch.send_delta(
"oc_chat1",
"",
metadata={
"_stream_end": True,
"message_id": "om_001",
"chat_type": "group",
"thread_id": "ot_001",
},
)
ch._client.im.v1.message.reply.assert_called_once()
ch._client.im.v1.message.create.assert_not_called()
request = ch._client.im.v1.message.reply.call_args[0][0]
assert request.request_body.reply_in_thread is not True
@pytest.mark.asyncio
async def test_stream_end_fallback_group_replies_when_reply_enabled(self):
ch = _make_channel(reply_to_message=True)
@@ -406,6 +452,30 @@ class TestToolHintInlineStreaming:
ch._client.im.v1.message.create.assert_called_once()
ch._client.im.v1.message.reply.assert_not_called()
@pytest.mark.asyncio
async def test_tool_hint_keeps_existing_topic_when_reply_disabled(self):
ch = _make_channel(reply_to_message=False)
reply_resp = MagicMock()
reply_resp.success.return_value = True
ch._client.im.v1.message.reply.return_value = reply_resp
msg = OutboundMessage(
channel="feishu", chat_id="oc_chat1",
content='read_file("path")',
metadata={
"_tool_hint": True,
"message_id": "om_001",
"chat_type": "group",
"thread_id": "ot_001",
},
)
await ch.send(msg)
ch._client.im.v1.message.reply.assert_called_once()
ch._client.im.v1.message.create.assert_not_called()
request = ch._client.im.v1.message.reply.call_args[0][0]
assert request.request_body.reply_in_thread is not True
@pytest.mark.asyncio
async def test_tool_hint_group_replies_when_reply_enabled(self):
ch = _make_channel(reply_to_message=True)