


























@@ -5,11 +5,32 @@ import {
55type SlackSystemEventTestOverrides,
66} from "./system-event-test-harness.js";
778-const { messageQueueMock, messageAllowMock } = vi.hoisted(() => ({
8+const { messageQueueMock, messageAllowMock, inboundInfoSpy } = vi.hoisted(() => ({
99messageQueueMock: vi.fn(),
1010messageAllowMock: vi.fn(),
11+inboundInfoSpy: vi.fn(),
1112}));
121314+vi.mock("openclaw/plugin-sdk/runtime-env", async (importOriginal) => {
15+const actual = await importOriginal<typeof import("openclaw/plugin-sdk/runtime-env")>();
16+const makeLogger = () => {
17+const logger = {
18+subsystem: "test",
19+isEnabled: () => true,
20+trace: () => {},
21+debug: () => {},
22+info: inboundInfoSpy,
23+warn: () => {},
24+error: () => {},
25+fatal: () => {},
26+raw: () => {},
27+child: () => logger,
28+};
29+return logger;
30+};
31+return { ...actual, createSubsystemLogger: () => makeLogger() };
32+});
33+1334vi.mock("openclaw/plugin-sdk/system-event-runtime", () => ({
1435enqueueSystemEvent: (...args: unknown[]) => messageQueueMock(...args),
1536}));
@@ -21,6 +42,13 @@ vi.mock("openclaw/plugin-sdk/conversation-runtime", () => ({
2142}));
22432344let registerSlackMessageEvents: typeof import("./messages.js").registerSlackMessageEvents;
45+let formatSlackInboundLogLine: typeof import("./messages.js").formatSlackInboundLogLine;
46+47+function inboundLogLines(): string[] {
48+return inboundInfoSpy.mock.calls
49+.map((call) => call[0])
50+.filter((line): line is string => typeof line === "string" && line.startsWith("Inbound "));
51+}
24522553type MessageHandler = (args: { event: Record<string, unknown>; body: unknown }) => Promise<void>;
2654type RegisteredEventName = "message" | "app_mention";
@@ -57,11 +85,12 @@ function resetMessageMocks(): void {
5785}
58865987beforeAll(async () => {
60-({ registerSlackMessageEvents } = await import("./messages.js"));
88+({ registerSlackMessageEvents, formatSlackInboundLogLine } = await import("./messages.js"));
6189});
62906391beforeEach(() => {
6492resetMessageMocks();
93+inboundInfoSpy.mockClear();
6594});
66956796function makeChangedEvent(overrides?: { channel?: string; user?: string }) {
@@ -387,6 +416,8 @@ describe("registerSlackMessageEvents", () => {
387416});
388417389418expect(handleSlackMessage).not.toHaveBeenCalled();
419+// Dropped DM app_mention (already handled via message.im) must not log a receipt.
420+expect(inboundLogLines()).toEqual([]);
390421});
391422392423it("routes app_mention events from channels to the message handler", async () => {
@@ -397,5 +428,55 @@ describe("registerSlackMessageEvents", () => {
397428});
398429399430expect(handleSlackMessage).toHaveBeenCalledTimes(1);
431+expect(inboundLogLines()).toEqual([
432+"Inbound app_mention slack:T_TEST:channel:C123:user:U1 -> bot:U_BOT (channel, 14 chars)",
433+]);
434+});
435+436+it("logs channel app_mention receipts with zero chars when text is absent", async () => {
437+const { handleSlackMessage } = await invokeRegisteredHandler({
438+eventName: "app_mention",
439+overrides: { dmPolicy: "open" },
440+event: {
441+ ...makeAppMentionEvent({ channel: "C123", channelType: "channel" }),
442+text: undefined,
443+},
444+});
445+446+expect(handleSlackMessage).toHaveBeenCalledTimes(1);
447+expect(inboundLogLines()).toEqual([
448+"Inbound app_mention slack:T_TEST:channel:C123:user:U1 -> bot:U_BOT (channel, 0 chars)",
449+]);
450+});
451+452+it("logs channel app_mention receipts with unknown sender when user is absent", async () => {
453+const { handleSlackMessage } = await invokeRegisteredHandler({
454+eventName: "app_mention",
455+overrides: { dmPolicy: "open" },
456+event: {
457+ ...makeAppMentionEvent({ channel: "C123", channelType: "channel" }),
458+user: undefined,
459+},
460+});
461+462+expect(handleSlackMessage).toHaveBeenCalledTimes(1);
463+expect(inboundLogLines()).toEqual([
464+"Inbound app_mention slack:T_TEST:channel:C123:user:unknown -> bot:U_BOT (channel, 14 chars)",
465+]);
466+});
467+468+it("formats the inbound receipt line with channel, sender, body length, and bot identity", () => {
469+expect(
470+formatSlackInboundLogLine({
471+workspaceId: "T123",
472+channelId: "C456",
473+channelType: "channel",
474+userId: "U789",
475+botUserId: "U_BOT",
476+bodyChars: 42,
477+}),
478+).toBe(
479+"Inbound app_mention slack:T123:channel:C456:user:U789 -> bot:U_BOT (channel, 42 chars)",
480+);
400481});
401482});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。