From f9e0d60a9989d11626405b71b66aa261da8ea216 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sun, 10 May 2026 15:16:04 -0700 Subject: [PATCH] test(thread-routing): handle both lark-SDK-present and absent paths The contributor's regression test for Feishu fallback thread routing asserted on attributes specific to the real lark SDK builder (call_args.body, body.receive_id). In test environments without the lark SDK installed, the in-tree fallback (gateway/platforms/feishu.py _build_create_message_request) returns a SimpleNamespace using .request_body instead of .body, causing AttributeError. Now reads via getattr fallback and also verifies receive_id_type is 'thread_id' (not 'chat_id') as a stronger contract check. --- .../test_stream_consumer_thread_routing.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/gateway/test_stream_consumer_thread_routing.py b/tests/gateway/test_stream_consumer_thread_routing.py index 0fe7d13c845..80477574d87 100644 --- a/tests/gateway/test_stream_consumer_thread_routing.py +++ b/tests/gateway/test_stream_consumer_thread_routing.py @@ -179,15 +179,23 @@ class TestFeishuFallbackThreadRouting: # The request should have receive_id_type="thread_id" call_args = mock_client.im.v1.message.create.call_args[0][0] - body = call_args.body + # Lark SDK builder exposes .body; the in-tree fallback exposes .request_body. + # The contributor's branch had the lark SDK installed, the test environment + # may not — handle both shapes. + body = getattr(call_args, "body", None) or getattr(call_args, "request_body", None) + assert body is not None, "request has neither .body nor .request_body" # receive_id should be the thread_id, not the chat_id - import json as _json - body_dict = _json.loads(body) if isinstance(body, str) else body - assert hasattr(body, 'receive_id'), ( - "CreateMessageRequestBody missing receive_id attribute" + receive_id = getattr(body, "receive_id", None) + if receive_id is None and isinstance(body, str): + import json as _json + receive_id = _json.loads(body).get("receive_id") + assert receive_id == "omt_topic_abc", ( + f"Expected receive_id='omt_topic_abc', got '{receive_id}'" ) - assert body.receive_id == "omt_topic_abc", ( - f"Expected receive_id='omt_topic_abc', got '{body.receive_id}'" + # And receive_id_type must be 'thread_id', not 'chat_id' + receive_id_type = getattr(call_args, "receive_id_type", None) + assert receive_id_type == "thread_id", ( + f"Expected receive_id_type='thread_id', got '{receive_id_type}'" ) @pytest.mark.asyncio