mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-21 16:41:56 +00:00
test: merge signal sender-prefix coverage into typing suite
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user