Skip to content

Commit b8c3e46

Browse files
fix(teams): correct channelData precedence in extract_teams_continuation
Upstream chat@4.31 builds the continuation via an object spread where the later source wins when both are present. The port inverted this, doing primary-first with channelData only as a None fallback. Match upstream: - teamsChannelId wins over channel.id - teamsTeamId wins over team.id - channelData.tenant.id wins over conversation.tenantId Flip the pinning test to assert the channelData-native source wins and rename it to test_continuation_channeldata_wins_over_conversation.
1 parent 1da7f9b commit b8c3e46

2 files changed

Lines changed: 25 additions & 21 deletions

File tree

src/chat_sdk/adapters/teams/webhook/continuation.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,29 @@ def extract_teams_continuation(activity: TeamsActivity) -> TeamsContinuation:
4141
4242
``conversation_id`` / ``service_url`` default to ``""`` (upstream ``?? ""``)
4343
so the continuation always carries the two fields a reply needs; the rest
44-
are populated only when present, applying the same channelData fallbacks
45-
as upstream (``channel.id`` then ``teamsChannelId``; ``team.id`` then
46-
``teamsTeamId``; ``conversation.tenantId`` then ``tenant.id``).
44+
are populated only when present. Upstream builds the result with an object
45+
spread where the *later* source wins when both are present, so the
46+
channelData-native fields take precedence: ``teamsChannelId`` over
47+
``channel.id``; ``teamsTeamId`` over ``team.id``; ``channelData.tenant.id``
48+
over ``conversation.tenantId``.
4749
"""
4850
channel_data = _record(activity.get("channelData")) or {}
4951
conversation = _record(activity.get("conversation")) or {}
5052
channel = _record(channel_data.get("channel")) or {}
5153
team = _record(channel_data.get("team")) or {}
5254
tenant = _record(channel_data.get("tenant")) or {}
5355

54-
channel_id = _opt_str(channel.get("id"))
56+
channel_id = _opt_str(channel_data.get("teamsChannelId"))
5557
if channel_id is None:
56-
channel_id = _opt_str(channel_data.get("teamsChannelId"))
58+
channel_id = _opt_str(channel.get("id"))
5759

58-
team_id = _opt_str(team.get("id"))
60+
team_id = _opt_str(channel_data.get("teamsTeamId"))
5961
if team_id is None:
60-
team_id = _opt_str(channel_data.get("teamsTeamId"))
62+
team_id = _opt_str(team.get("id"))
6163

62-
tenant_id = _opt_str(conversation.get("tenantId"))
64+
tenant_id = _opt_str(tenant.get("id"))
6365
if tenant_id is None:
64-
tenant_id = _opt_str(tenant.get("id"))
66+
tenant_id = _opt_str(conversation.get("tenantId"))
6567

6668
conversation_id = conversation.get("id")
6769
service_url = activity.get("serviceUrl")

tests/test_teams_webhook_primitive.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,24 +242,26 @@ def test_continuation_defaults_when_fields_absent(self):
242242
assert continuation.team_id is None
243243
assert continuation.tenant_id is None
244244

245-
def test_continuation_prefers_primary_over_fallback(self):
246-
# ``channel.id`` wins over ``teamsChannelId``; ``team.id`` over
247-
# ``teamsTeamId``; ``conversation.tenantId`` over ``tenant.id``.
245+
def test_continuation_channeldata_wins_over_conversation(self):
246+
# Upstream builds the continuation via an object spread where the later
247+
# source wins: ``teamsChannelId`` beats ``channel.id``; ``teamsTeamId``
248+
# beats ``team.id``; ``channelData.tenant.id`` beats
249+
# ``conversation.tenantId``.
248250
continuation = extract_teams_continuation(
249251
{
250252
"channelData": {
251-
"channel": {"id": "primary-channel"},
252-
"team": {"id": "primary-team"},
253-
"teamsChannelId": "fallback-channel",
254-
"teamsTeamId": "fallback-team",
255-
"tenant": {"id": "fallback-tenant"},
253+
"channel": {"id": "channel-id"},
254+
"team": {"id": "team-id"},
255+
"teamsChannelId": "teams-channel-id",
256+
"teamsTeamId": "teams-team-id",
257+
"tenant": {"id": "channeldata-tenant"},
256258
},
257-
"conversation": {"id": "c", "tenantId": "primary-tenant"},
259+
"conversation": {"id": "c", "tenantId": "conversation-tenant"},
258260
}
259261
)
260-
assert continuation.channel_id == "primary-channel"
261-
assert continuation.team_id == "primary-team"
262-
assert continuation.tenant_id == "primary-tenant"
262+
assert continuation.channel_id == "teams-channel-id"
263+
assert continuation.team_id == "teams-team-id"
264+
assert continuation.tenant_id == "channeldata-tenant"
263265

264266

265267
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)