fix: normalize bound delivery binding matches

This commit is contained in:
Tak Hoffman
2026-04-10 19:35:22 -05:00
parent 957171b2e0
commit 24ac5ddf7f
2 changed files with 36 additions and 4 deletions

View File

@@ -122,6 +122,34 @@ describe("bound delivery router", () => {
},
expectedConversationId: "thread-2",
},
{
name: "normalizes adapter binding conversations before requester matching",
bindings: [
{
...createDiscordBinding(TARGET_SESSION_KEY, "thread-1", 1),
conversation: {
channel: " discord ",
accountId: " runtime ",
conversationId: " thread-1 ",
},
},
{
...createDiscordBinding(TARGET_SESSION_KEY, "thread-2", 2),
conversation: {
channel: " DISCORD ",
accountId: " Runtime ",
conversationId: " thread-2 ",
},
},
],
requesterConversationId: "thread-2",
failClosed: true,
expected: {
mode: "bound",
reason: "requester-match",
},
expectedConversationId: " thread-2 ",
},
{
name: "falls back for invalid requester conversation values",
bindings: [createDiscordBinding(TARGET_SESSION_KEY, "thread-1", 1)],

View File

@@ -32,16 +32,20 @@ function resolveBindingForRequester(
bindings: SessionBindingRecord[],
): SessionBindingRecord | null {
const matchingChannelAccount = bindings.filter(
(entry) =>
entry.conversation.channel === requester.channel &&
entry.conversation.accountId === requester.accountId,
(entry) => {
const conversation = normalizeConversationRef(entry.conversation);
return (
conversation.channel === requester.channel && conversation.accountId === requester.accountId
);
},
);
if (matchingChannelAccount.length === 0) {
return null;
}
const exactConversation = matchingChannelAccount.find(
(entry) => entry.conversation.conversationId === requester.conversationId,
(entry) =>
normalizeConversationRef(entry.conversation).conversationId === requester.conversationId,
);
if (exactConversation) {
return exactConversation;