From 37341a703223bc44b03570307c271c0f8ea1749c Mon Sep 17 00:00:00 2001 From: Masato Hoshino Date: Wed, 1 Jul 2026 02:28:47 +0900 Subject: [PATCH] fix(googlechat): expose sender bot status in context (#97825) * fix(googlechat): expose sender bot status in context * fix(googlechat): expose sender bot status in context --------- Co-authored-by: Vincent Koc --- extensions/googlechat/src/monitor.test.ts | 70 +++++++++++++++++++++++ extensions/googlechat/src/monitor.ts | 1 + 2 files changed, 71 insertions(+) diff --git a/extensions/googlechat/src/monitor.test.ts b/extensions/googlechat/src/monitor.test.ts index b1cd49469b3..b6f2e27e0cb 100644 --- a/extensions/googlechat/src/monitor.test.ts +++ b/extensions/googlechat/src/monitor.test.ts @@ -255,6 +255,76 @@ describe("googlechat monitor inbound space classification", () => { }); }); +describe("googlechat monitor sender bot status", () => { + function botStatusEvent(senderType: "BOT" | "HUMAN", messageId: string): GoogleChatEvent { + return { + type: "MESSAGE", + space: { name: "spaces/DM", type: "DM" }, + message: { + name: `spaces/DM/messages/${messageId}`, + text: "hello", + sender: { name: "users/sender", displayName: "Sender", type: senderType }, + }, + } satisfies GoogleChatEvent; + } + + it("forwards bot sender status to the inbound context when allowBots is true", async () => { + const { buildContext, core } = createInboundClassificationHarness(); + accessMocks.applyGoogleChatInboundAccessPolicy.mockResolvedValue({ + ok: true, + commandAuthorized: undefined, + effectiveWasMentioned: undefined, + groupBotLoopProtection: undefined, + groupSystemPrompt: undefined, + }); + + await testing.processMessageWithPipeline({ + event: botStatusEvent("BOT", "1"), + account: { + accountId: "work", + config: { allowBots: true }, + credentialSource: "inline", + } as ResolvedGoogleChatAccount, + config: {}, + runtime: { error: vi.fn(), log: vi.fn() }, + core, + mediaMaxMb: 10, + }); + + expect(buildContext).toHaveBeenCalledWith( + expect.objectContaining({ sender: expect.objectContaining({ isBot: true }) }), + ); + }); + + it("omits bot sender status for human senders", async () => { + const { buildContext, core } = createInboundClassificationHarness(); + accessMocks.applyGoogleChatInboundAccessPolicy.mockResolvedValue({ + ok: true, + commandAuthorized: undefined, + effectiveWasMentioned: undefined, + groupBotLoopProtection: undefined, + groupSystemPrompt: undefined, + }); + + await testing.processMessageWithPipeline({ + event: botStatusEvent("HUMAN", "2"), + account: { + accountId: "work", + config: {}, + credentialSource: "inline", + } as ResolvedGoogleChatAccount, + config: {}, + runtime: { error: vi.fn(), log: vi.fn() }, + core, + mediaMaxMb: 10, + }); + + expect(buildContext).toHaveBeenCalledWith( + expect.objectContaining({ sender: expect.objectContaining({ isBot: undefined }) }), + ); + }); +}); + describe("googlechat monitor direct messages", () => { it("creates typing messages by default", async () => { const runTurn = vi.fn(); diff --git a/extensions/googlechat/src/monitor.ts b/extensions/googlechat/src/monitor.ts index 43b91ad8c39..d13eb3e2660 100644 --- a/extensions/googlechat/src/monitor.ts +++ b/extensions/googlechat/src/monitor.ts @@ -311,6 +311,7 @@ async function processMessageWithPipeline(params: { id: senderId, name: senderName || undefined, username: senderEmail, + isBot: isBotSender || undefined, }, conversation: { kind: isGroup ? "channel" : "direct",