Skip to content

Commit 1de8380

Browse files
author
hanhui
committed
fix(feishu): honor configured queue scope
1 parent 082ac07 commit 1de8380

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

‎extensions/feishu/src/sequential-key.test.ts‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ const cfg = {
88
feishu: {
99
appId: "cli_test",
1010
appSecret: "secret_test",
11+
groupSessionScope: "group_topic",
1112
groups: {
13+
oc_group_chat: {
14+
groupSessionScope: "group",
15+
},
1216
oc_topic_chat: {
1317
groupSessionScope: "group_topic",
1418
},
@@ -97,7 +101,7 @@ describe("getFeishuSequentialKey", () => {
97101
).resolves.toBe("feishu:default:oc_dm_chat:btw");
98102
});
99103

100-
it("uses the configured topic session scope for group queue keys", async () => {
104+
it("uses configured topic thread_id scope for group queue keys", async () => {
101105
const first = createTextEvent({
102106
text: "topic one",
103107
chatId: "oc_topic_chat",
@@ -119,6 +123,55 @@ describe("getFeishuSequentialKey", () => {
119123
).resolves.toBe("feishu:default:oc_topic_chat:topic:omt_topic_2");
120124
});
121125

126+
it("keeps group queues chat-scoped when groupSessionScope is group", async () => {
127+
const event = createTextEvent({
128+
text: "plain group",
129+
chatId: "oc_group_chat",
130+
chatType: "topic_group",
131+
threadId: "omt_topic_1",
132+
});
133+
134+
await expect(getFeishuSequentialKey({ cfg, accountId: "default", event })).resolves.toBe(
135+
"feishu:default:oc_group_chat",
136+
);
137+
});
138+
139+
it("uses the top-level groupSessionScope thread_id when a group has no override", async () => {
140+
const event = createTextEvent({
141+
text: "global topic scope",
142+
chatId: "oc_global_topic_chat",
143+
chatType: "topic_group",
144+
threadId: "omt_global_topic_1",
145+
});
146+
147+
await expect(getFeishuSequentialKey({ cfg, accountId: "default", event })).resolves.toBe(
148+
"feishu:default:oc_global_topic_chat:topic:omt_global_topic_1",
149+
);
150+
});
151+
152+
it("does not hydrate thread_id when groupSessionScope keeps the chat queue", async () => {
153+
const event = createTextEvent({
154+
text: "plain group without thread id",
155+
chatId: "oc_group_chat",
156+
chatType: "topic_group",
157+
messageId: "om_group_scope_message",
158+
});
159+
let fetched = false;
160+
161+
await expect(
162+
getFeishuSequentialKey({
163+
cfg,
164+
accountId: "default",
165+
event,
166+
fetchMessage: async () => {
167+
fetched = true;
168+
throw new Error("should not fetch for chat-scoped queues");
169+
},
170+
}),
171+
).resolves.toBe("feishu:default:oc_group_chat");
172+
expect(fetched).toBe(false);
173+
});
174+
122175
it("keeps control lanes scoped within the topic queue", async () => {
123176
const event = createTextEvent({
124177
text: "/stop",

‎extensions/feishu/src/sequential-key.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,20 @@ async function resolveFeishuSequentialBaseKey(params: {
6363
}): Promise<string> {
6464
const { accountId, cfg, fetchMessage, parsed, runtime } = params;
6565
const chatId = parsed.chatId?.trim() || "unknown";
66+
const chatKey = `feishu:${accountId}:${chatId}`;
6667
if (!isFeishuGroupChatType(parsed.chatType)) {
67-
return `feishu:${accountId}:${chatId}`;
68+
return chatKey;
6869
}
6970

7071
try {
7172
const account = resolveFeishuRuntimeAccount({ cfg, accountId });
7273
const feishuCfg = account.config;
7374
const groupConfig = resolveFeishuGroupConfig({ cfg: feishuCfg, groupId: chatId });
7475
const groupSessionScope = resolveConfiguredFeishuGroupSessionScope({ groupConfig, feishuCfg });
76+
if (groupSessionScope === "group") {
77+
return chatKey;
78+
}
79+
7580
let effectiveThreadId = parsed.threadId;
7681
if (
7782
parsed.chatType === "topic_group" &&
@@ -108,6 +113,6 @@ async function resolveFeishuSequentialBaseKey(params: {
108113
(runtime?.log ?? console.log)(
109114
`feishu[${accountId}]: failed to resolve scoped sequential key for chat=${chatId}: ${String(err)}`,
110115
);
111-
return `feishu:${accountId}:${chatId}`;
116+
return chatKey;
112117
}
113118
}

0 commit comments

Comments
 (0)