fix(feishu): split fenced code blocks in post payload
This commit is contained in:
@@ -2370,6 +2370,69 @@ class TestAdapterBehavior(unittest.TestCase):
|
||||
elements = payload["zh_cn"]["content"][0]
|
||||
self.assertEqual(elements, [{"tag": "md", "text": "可以用 **粗体** 和 *斜体*。"}])
|
||||
|
||||
@patch.dict(os.environ, {}, clear=True)
|
||||
def test_send_splits_fenced_code_blocks_into_separate_post_rows(self):
|
||||
from gateway.config import PlatformConfig
|
||||
from gateway.platforms.feishu import FeishuAdapter
|
||||
|
||||
adapter = FeishuAdapter(PlatformConfig())
|
||||
captured = {}
|
||||
|
||||
class _MessageAPI:
|
||||
def create(self, request):
|
||||
captured["request"] = request
|
||||
return SimpleNamespace(
|
||||
success=lambda: True,
|
||||
data=SimpleNamespace(message_id="om_codeblock"),
|
||||
)
|
||||
|
||||
adapter._client = SimpleNamespace(
|
||||
im=SimpleNamespace(
|
||||
v1=SimpleNamespace(
|
||||
message=_MessageAPI(),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
async def _direct(func, *args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
|
||||
content = (
|
||||
"确认已入库 ✓\n"
|
||||
"文件路径:`/root/.hermes/profiles/agent_cto/cron/jobs.json`\n"
|
||||
"**解码后的内容:**\n"
|
||||
"```json\n"
|
||||
'{"cron": "list"}\n'
|
||||
"```\n"
|
||||
"后续说明仍应保留。"
|
||||
)
|
||||
|
||||
with patch("gateway.platforms.feishu.asyncio.to_thread", side_effect=_direct):
|
||||
result = asyncio.run(
|
||||
adapter.send(
|
||||
chat_id="oc_chat",
|
||||
content=content,
|
||||
)
|
||||
)
|
||||
|
||||
self.assertTrue(result.success)
|
||||
self.assertEqual(captured["request"].request_body.msg_type, "post")
|
||||
payload = json.loads(captured["request"].request_body.content)
|
||||
rows = payload["zh_cn"]["content"]
|
||||
self.assertEqual(
|
||||
rows,
|
||||
[
|
||||
[
|
||||
{
|
||||
"tag": "md",
|
||||
"text": "确认已入库 ✓\n文件路径:`/root/.hermes/profiles/agent_cto/cron/jobs.json`\n**解码后的内容:**",
|
||||
}
|
||||
],
|
||||
[{"tag": "md", "text": "```json\n{\"cron\": \"list\"}\n```"}],
|
||||
[{"tag": "md", "text": "后续说明仍应保留。"}],
|
||||
],
|
||||
)
|
||||
|
||||
@patch.dict(os.environ, {}, clear=True)
|
||||
def test_send_falls_back_to_text_when_post_payload_is_rejected(self):
|
||||
from gateway.config import PlatformConfig
|
||||
|
||||
Reference in New Issue
Block a user