Skip to content

Commit 11ddfda

Browse files
author
AxelHu
committed
test(feishu): update strip-mention tests to reflect new behavior
Update tests to match new behavior where bot's own <at> tag is preserved. Slash commands still work because normalizeFeishuCommandProbeBody strips <at> tags before command parsing.
1 parent e292a62 commit 11ddfda

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

‎extensions/feishu/src/bot.stripBotMention.test.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ describe("normalizeMentions (via parseFeishuMessageEvent)", () => {
2727
expect(ctx.content).toBe("hello world");
2828
});
2929

30-
it("strips bot mention in p2p (addressing prefix, not semantic content)", () => {
30+
it("preserves bot mention in p2p", () => {
3131
const ctx = parseFeishuMessageEvent(
3232
makeEvent("@_bot_1 hello", [{ key: "@_bot_1", name: "Bot", id: { open_id: "ou_bot" } }]),
3333
BOT_OPEN_ID,
3434
);
35-
expect(ctx.content).toBe("hello");
35+
// Bot's own <at> tag is now preserved so LLM can see the complete @ context.
36+
// Command detection uses normalizeFeishuCommandProbeBody which strips <at> tags anyway.
37+
expect(ctx.content).toBe('<at user_id="ou_bot">Bot</at> hello');
3638
});
3739

38-
it("strips bot mention in group so slash commands work (#35994)", () => {
40+
it("preserves bot mention in group so LLM sees complete @ context", () => {
3941
const ctx = parseFeishuMessageEvent(
4042
makeEvent(
4143
"@_bot_1 hello",
@@ -44,10 +46,12 @@ describe("normalizeMentions (via parseFeishuMessageEvent)", () => {
4446
),
4547
BOT_OPEN_ID,
4648
);
47-
expect(ctx.content).toBe("hello");
49+
// Bot's own <at> tag is preserved. Slash commands still work because
50+
// normalizeFeishuCommandProbeBody strips all <at> tags before command parsing.
51+
expect(ctx.content).toBe('<at user_id="ou_bot">Bot</at> hello');
4852
});
4953

50-
it("strips bot mention in group preserving slash command prefix (#35994)", () => {
54+
it("preserves bot mention in group for slash commands (#35994)", () => {
5155
const ctx = parseFeishuMessageEvent(
5256
makeEvent(
5357
"@_bot_1 /model",
@@ -56,18 +60,21 @@ describe("normalizeMentions (via parseFeishuMessageEvent)", () => {
5660
),
5761
BOT_OPEN_ID,
5862
);
59-
expect(ctx.content).toBe("/model");
63+
// Bot's <at> tag is preserved, but slash command is still detected because
64+
// normalizeFeishuCommandProbeBody strips <at> tags before checking for / prefix.
65+
expect(ctx.content).toBe('<at user_id="ou_bot">Bot</at> /model');
6066
});
6167

62-
it("strips bot mention but normalizes other mentions in p2p (mention-forward)", () => {
68+
it("preserves bot mention and other mentions in p2p (mention-forward)", () => {
6369
const ctx = parseFeishuMessageEvent(
6470
makeEvent("@_bot_1 @_user_alice hello", [
6571
{ key: "@_bot_1", name: "Bot", id: { open_id: "ou_bot" } },
6672
{ key: "@_user_alice", name: "Alice", id: { open_id: "ou_alice" } },
6773
]),
6874
BOT_OPEN_ID,
6975
);
70-
expect(ctx.content).toBe('<at user_id="ou_alice">Alice</at> hello');
76+
// All <at> tags are now preserved (including bot's own).
77+
expect(ctx.content).toBe('<at user_id="ou_bot">Bot</at> <at user_id="ou_alice">Alice</at> hello');
7178
});
7279

7380
it("falls back to @name when open_id is absent", () => {

‎extensions/feishu/src/bot.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ export function parseFeishuMessageEvent(
141141
const rawContent = parseMessageContent(event.message.content, event.message.message_type);
142142
const mentionedBot = checkBotMentioned(event, botOpenId);
143143
const hasAnyMention = (event.message.mentions?.length ?? 0) > 0;
144-
// Strip the bot's own mention so slash commands like @Bot /help retain
145-
// the leading /. This applies in both p2p *and* group contexts — the
146-
// mentionedBot flag already captures whether the bot was addressed, so
147-
// keeping the mention tag in content only breaks command detection (#35994).
148-
// Non-bot mentions (e.g. mention-forward targets) are still normalized to <at> tags.
144+
// Preserve ALL <at> tags including the bot's own mention.
145+
// The botStripId parameter is kept for backward compatibility but is now a no-op.
146+
// LLM needs to see the complete @ context to correctly interpret who was mentioned.
147+
// Note: command detection uses `normalizeFeishuCommandProbeBody` which strips all <at>
148+
// tags before command parsing, so slash commands (e.g. @Bot /help) still work correctly.
149149
const content = normalizeMentions(rawContent, event.message.mentions, botOpenId);
150150
const senderOpenId = event.sender.sender_id.open_id?.trim();
151151
const senderUserId = event.sender.sender_id.user_id?.trim();

0 commit comments

Comments
 (0)