From a395479d8b41a4d774b86e1c765657715547e1ea Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 22 Feb 2026 13:12:57 +0000 Subject: [PATCH] test: merge signal sender-prefix coverage into typing suite --- ...onitor.event-handler.sender-prefix.test.ts | 90 ------------------- ...event-handler.typing-read-receipts.test.ts | 45 +++++++++- 2 files changed, 44 insertions(+), 91 deletions(-) delete mode 100644 src/signal/monitor.event-handler.sender-prefix.test.ts diff --git a/src/signal/monitor.event-handler.sender-prefix.test.ts b/src/signal/monitor.event-handler.sender-prefix.test.ts deleted file mode 100644 index dc9043a2338..00000000000 --- a/src/signal/monitor.event-handler.sender-prefix.test.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; -import type { SignalReactionMessage } from "./monitor/event-handler.types.js"; - -const dispatchMock = vi.fn(); -const readAllowFromMock = vi.fn(); - -vi.mock("../auto-reply/dispatch.js", () => ({ - dispatchInboundMessage: (...args: unknown[]) => dispatchMock(...args), - dispatchInboundMessageWithDispatcher: (...args: unknown[]) => dispatchMock(...args), - dispatchInboundMessageWithBufferedDispatcher: (...args: unknown[]) => dispatchMock(...args), -})); - -vi.mock("../pairing/pairing-store.js", () => ({ - readChannelAllowFromStore: (...args: unknown[]) => readAllowFromMock(...args), - upsertChannelPairingRequest: vi.fn(), -})); - -describe("signal event handler sender prefix", () => { - beforeEach(() => { - dispatchMock.mockClear().mockImplementation(async ({ dispatcher, ctx }) => { - dispatcher.sendFinalReply({ text: "ok" }); - return { queuedFinal: true, counts: { tool: 0, block: 0, final: 1 }, ctx }; - }); - readAllowFromMock.mockClear().mockResolvedValue([]); - }); - - it("prefixes group bodies with sender label", async () => { - let capturedBody = ""; - dispatchMock.mockImplementationOnce(async ({ dispatcher, ctx }) => { - capturedBody = ctx.Body ?? ""; - dispatcher.sendFinalReply({ text: "ok" }); - return { queuedFinal: true, counts: { tool: 0, block: 0, final: 1 } }; - }); - - const { createSignalEventHandler } = await import("./monitor/event-handler.js"); - const handler = createSignalEventHandler({ - runtime: { - log: vi.fn(), - error: vi.fn(), - exit: (code: number): never => { - throw new Error(`exit ${code}`); - }, - }, - cfg: { - agents: { defaults: { model: "anthropic/claude-opus-4-5", workspace: "/tmp/openclaw" } }, - channels: { signal: {} }, - } as never, - baseUrl: "http://localhost", - account: "+15550009999", - accountId: "default", - blockStreaming: false, - historyLimit: 0, - groupHistories: new Map(), - textLimit: 4000, - dmPolicy: "open", - allowFrom: [], - groupAllowFrom: [], - groupPolicy: "open", - reactionMode: "off", - reactionAllowlist: [], - mediaMaxBytes: 1000, - ignoreAttachments: true, - sendReadReceipts: false, - readReceiptsViaDaemon: false, - fetchAttachment: async () => null, - deliverReplies: async () => undefined, - resolveSignalReactionTargets: () => [], - isSignalReactionMessage: (_reaction): _reaction is SignalReactionMessage => false, - shouldEmitSignalReactionNotification: () => false, - buildSignalReactionSystemEventText: () => "", - }); - - const payload = { - envelope: { - sourceNumber: "+15550002222", - sourceName: "Alice", - timestamp: 1700000000000, - dataMessage: { - message: "hello", - groupInfo: { groupId: "group-1", groupName: "Test Group" }, - }, - }, - }; - - await handler({ event: "receive", data: JSON.stringify(payload) }); - - expect(dispatchMock).toHaveBeenCalled(); - expect(capturedBody).toContain("Alice (+15550002222): hello"); - }); -}); diff --git a/src/signal/monitor.event-handler.typing-read-receipts.test.ts b/src/signal/monitor.event-handler.typing-read-receipts.test.ts index f3efd1a0ea6..adc2e77b63a 100644 --- a/src/signal/monitor.event-handler.typing-read-receipts.test.ts +++ b/src/signal/monitor.event-handler.typing-read-receipts.test.ts @@ -7,7 +7,10 @@ import { const sendTypingMock = vi.fn(); const sendReadReceiptMock = vi.fn(); const dispatchInboundMessageMock = vi.fn( - async (params: { replyOptions?: { onReplyStart?: () => void } }) => { + async (params: { + replyOptions?: { onReplyStart?: () => void }; + dispatcher?: { sendFinalReply?: (payload: { text: string }) => void }; + }) => { await Promise.resolve(params.replyOptions?.onReplyStart?.()); return { queuedFinal: false, counts: { tool: 0, block: 0, final: 0 } }; }, @@ -69,4 +72,44 @@ describe("signal event handler typing + read receipts", () => { expect.any(Object), ); }); + + it("prefixes group bodies with sender label", async () => { + let capturedBody = ""; + dispatchInboundMessageMock.mockImplementationOnce( + async (params: { dispatcher?: { sendFinalReply?: (payload: { text: string }) => void } }) => { + const ctx = params as { ctx?: { Body?: string } }; + capturedBody = ctx.ctx?.Body ?? ""; + params.dispatcher?.sendFinalReply?.({ text: "ok" }); + return { queuedFinal: true, counts: { tool: 0, block: 0, final: 1 } }; + }, + ); + + const { createSignalEventHandler } = await import("./monitor/event-handler.js"); + const handler = createSignalEventHandler( + createBaseSignalEventHandlerDeps({ + cfg: { + channels: { signal: {} }, + } as never, + account: "+15550009999", + blockStreaming: false, + historyLimit: 0, + groupHistories: new Map(), + allowFrom: [], + groupAllowFrom: [], + sendReadReceipts: false, + }), + ); + + await handler( + createSignalReceiveEvent({ + dataMessage: { + message: "hello", + groupInfo: { groupId: "group-1", groupName: "Test Group" }, + }, + }), + ); + + expect(dispatchInboundMessageMock).toHaveBeenCalled(); + expect(capturedBody).toContain("Alice (+15550001111): hello"); + }); });