Skip to content

Commit 24ac5dd

Browse files
committed
fix: normalize bound delivery binding matches
1 parent 957171b commit 24ac5dd

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎src/infra/outbound/bound-delivery-router.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,34 @@ describe("bound delivery router", () => {
122122
},
123123
expectedConversationId: "thread-2",
124124
},
125+
{
126+
name: "normalizes adapter binding conversations before requester matching",
127+
bindings: [
128+
{
129+
...createDiscordBinding(TARGET_SESSION_KEY, "thread-1", 1),
130+
conversation: {
131+
channel: " discord ",
132+
accountId: " runtime ",
133+
conversationId: " thread-1 ",
134+
},
135+
},
136+
{
137+
...createDiscordBinding(TARGET_SESSION_KEY, "thread-2", 2),
138+
conversation: {
139+
channel: " DISCORD ",
140+
accountId: " Runtime ",
141+
conversationId: " thread-2 ",
142+
},
143+
},
144+
],
145+
requesterConversationId: "thread-2",
146+
failClosed: true,
147+
expected: {
148+
mode: "bound",
149+
reason: "requester-match",
150+
},
151+
expectedConversationId: " thread-2 ",
152+
},
125153
{
126154
name: "falls back for invalid requester conversation values",
127155
bindings: [createDiscordBinding(TARGET_SESSION_KEY, "thread-1", 1)],

‎src/infra/outbound/bound-delivery-router.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ function resolveBindingForRequester(
3232
bindings: SessionBindingRecord[],
3333
): SessionBindingRecord | null {
3434
const matchingChannelAccount = bindings.filter(
35-
(entry) =>
36-
entry.conversation.channel === requester.channel &&
37-
entry.conversation.accountId === requester.accountId,
35+
(entry) => {
36+
const conversation = normalizeConversationRef(entry.conversation);
37+
return (
38+
conversation.channel === requester.channel && conversation.accountId === requester.accountId
39+
);
40+
},
3841
);
3942
if (matchingChannelAccount.length === 0) {
4043
return null;
4144
}
4245

4346
const exactConversation = matchingChannelAccount.find(
44-
(entry) => entry.conversation.conversationId === requester.conversationId,
47+
(entry) =>
48+
normalizeConversationRef(entry.conversation).conversationId === requester.conversationId,
4549
);
4650
if (exactConversation) {
4751
return exactConversation;

0 commit comments

Comments
 (0)