


























@@ -2,7 +2,7 @@ import type { EnvelopeFormatOptions } from "openclaw/plugin-sdk/channel-inbound"
22import { beforeEach, describe, expect, it, vi } from "vitest";
33import type { ClawdbotConfig, PluginRuntime } from "../runtime-api.js";
44import type { FeishuMessageEvent } from "./bot.js";
5-import { handleFeishuMessage } from "./bot.js";
5+import { clearGroupNameCache, handleFeishuMessage } from "./bot.js";
66import { setFeishuRuntime } from "./runtime.js";
7788const { mockCreateFeishuReplyDispatcher, mockCreateFeishuClient, mockResolveAgentRoute } =
@@ -46,6 +46,7 @@ function createRuntimeEnv() {
46464747describe("broadcast dispatch", () => {
4848const finalizeInboundContextCalls: Array<Record<string, unknown>> = [];
49+const mockGetChatInfo = vi.fn();
4950const mockFinalizeInboundContext: PluginRuntime["channel"]["reply"]["finalizeInboundContext"] = (
5051ctx,
5152) => {
@@ -125,6 +126,8 @@ describe("broadcast dispatch", () => {
125126agents: { list: [{ id: "main" }, { id: "susan" }] },
126127channels: {
127128feishu: {
129+appId: "cli_test",
130+appSecret: "sec_test", // pragma: allowlist secret
128131groups: {
129132"oc-broadcast-group": {
130133requireMention: true,
@@ -166,6 +169,7 @@ describe("broadcast dispatch", () => {
166169167170beforeEach(() => {
168171vi.clearAllMocks();
172+clearGroupNameCache();
169173finalizeInboundContextCalls.length = 0;
170174mockResolveAgentRoute.mockReturnValue({
171175agentId: "main",
@@ -182,6 +186,14 @@ describe("broadcast dispatch", () => {
182186get: vi.fn().mockResolvedValue({ data: { user: { name: "Sender" } } }),
183187},
184188},
189+im: {
190+chat: {
191+get: mockGetChatInfo.mockResolvedValue({
192+code: 0,
193+data: { name: "Broadcast Team" },
194+}),
195+},
196+},
185197});
186198setFeishuRuntime(runtimeStub);
187199});
@@ -205,6 +217,15 @@ describe("broadcast dispatch", () => {
205217const sessionKeys = finalizeInboundContextCalls.map((call) => call.SessionKey);
206218expect(sessionKeys).toContain("agent:susan:feishu:group:oc-broadcast-group");
207219expect(sessionKeys).toContain("agent:main:feishu:group:oc-broadcast-group");
220+expect(mockGetChatInfo).toHaveBeenCalledTimes(1);
221+expect(finalizeInboundContextCalls).toEqual(
222+expect.arrayContaining([
223+expect.objectContaining({
224+GroupSubject: "Broadcast Team",
225+ConversationLabel: "Broadcast Team",
226+}),
227+]),
228+);
208229expect(mockCreateFeishuReplyDispatcher).toHaveBeenCalledTimes(1);
209230expect(mockCreateFeishuReplyDispatcher).toHaveBeenCalledWith(
210231expect.objectContaining({ agentId: "main" }),
@@ -227,6 +248,7 @@ describe("broadcast dispatch", () => {
227248228249expect(mockDispatchReplyFromConfig).not.toHaveBeenCalled();
229250expect(mockCreateFeishuReplyDispatcher).not.toHaveBeenCalled();
251+expect(mockGetChatInfo).not.toHaveBeenCalled();
230252});
231253232254it("skips broadcast dispatch when bot identity is unknown (requireMention=true)", async () => {
@@ -244,12 +266,15 @@ describe("broadcast dispatch", () => {
244266245267expect(mockDispatchReplyFromConfig).not.toHaveBeenCalled();
246268expect(mockCreateFeishuReplyDispatcher).not.toHaveBeenCalled();
269+expect(mockGetChatInfo).not.toHaveBeenCalled();
247270});
248271249272it("preserves single-agent dispatch when no broadcast config", async () => {
250273const cfg: ClawdbotConfig = {
251274channels: {
252275feishu: {
276+appId: "cli_test",
277+appSecret: "sec_test", // pragma: allowlist secret
253278groups: {
254279"oc-broadcast-group": {
255280requireMention: false,
@@ -281,8 +306,11 @@ describe("broadcast dispatch", () => {
281306expect(finalizeInboundContextCalls).toContainEqual(
282307expect.objectContaining({
283308SessionKey: "agent:main:feishu:group:oc-broadcast-group",
309+GroupSubject: "Broadcast Team",
310+ConversationLabel: "Broadcast Team",
284311}),
285312);
313+expect(mockGetChatInfo).toHaveBeenCalledTimes(1);
286314});
287315288316it("cross-account broadcast dedup: second account skips dispatch", async () => {
@@ -291,6 +319,8 @@ describe("broadcast dispatch", () => {
291319agents: { list: [{ id: "main" }, { id: "susan" }] },
292320channels: {
293321feishu: {
322+appId: "cli_test",
323+appSecret: "sec_test", // pragma: allowlist secret
294324groups: {
295325"oc-broadcast-group": {
296326requireMention: false,
@@ -320,6 +350,7 @@ describe("broadcast dispatch", () => {
320350expect(mockDispatchReplyFromConfig).toHaveBeenCalledTimes(2);
321351322352mockDispatchReplyFromConfig.mockClear();
353+mockGetChatInfo.mockClear();
323354finalizeInboundContextCalls.length = 0;
324355325356await handleFeishuMessage({
@@ -329,6 +360,7 @@ describe("broadcast dispatch", () => {
329360accountId: "account-B",
330361});
331362expect(mockDispatchReplyFromConfig).not.toHaveBeenCalled();
363+expect(mockGetChatInfo).not.toHaveBeenCalled();
332364});
333365334366it("skips unknown agents not in agents.list", async () => {
@@ -337,6 +369,8 @@ describe("broadcast dispatch", () => {
337369agents: { list: [{ id: "main" }, { id: "susan" }] },
338370channels: {
339371feishu: {
372+appId: "cli_test",
373+appSecret: "sec_test", // pragma: allowlist secret
340374groups: {
341375"oc-broadcast-group": {
342376requireMention: false,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。