mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 22:04:45 +00:00
test: clear mcp channel broad matchers
This commit is contained in:
@@ -188,35 +188,23 @@ describe("openclaw channel mcp server", () => {
|
||||
});
|
||||
attachReadyGateway(bridge, gatewayRequest);
|
||||
|
||||
await expect(bridge.listConversations()).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
sessionKey,
|
||||
channel: "telegram",
|
||||
to: "-100123",
|
||||
accountId: "acct-1",
|
||||
threadId: 42,
|
||||
}),
|
||||
]),
|
||||
);
|
||||
const conversations = await bridge.listConversations();
|
||||
expect(conversations).toHaveLength(1);
|
||||
expect(conversations[0]?.sessionKey).toBe(sessionKey);
|
||||
expect(conversations[0]?.channel).toBe("telegram");
|
||||
expect(conversations[0]?.to).toBe("-100123");
|
||||
expect(conversations[0]?.accountId).toBe("acct-1");
|
||||
expect(conversations[0]?.threadId).toBe(42);
|
||||
|
||||
const messages = await bridge.readMessages(sessionKey, 5);
|
||||
expect(messages[0]).toMatchObject({
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "hello from transcript" }],
|
||||
});
|
||||
expect(messages[1]).toMatchObject({
|
||||
__openclaw: {
|
||||
id: "msg-attachment",
|
||||
},
|
||||
});
|
||||
expect(extractAttachmentsFromMessage(messages[1])).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
type: "image",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(messages[0]?.role).toBe("assistant");
|
||||
expect(messages[0]?.content).toEqual([{ type: "text", text: "hello from transcript" }]);
|
||||
expect((messages[1]?.__openclaw as { id?: string } | undefined)?.id).toBe("msg-attachment");
|
||||
expect(
|
||||
extractAttachmentsFromMessage(messages[1]).some(
|
||||
(entry) => (entry as { type?: unknown }).type === "image",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("serializes conversation and message payloads into MCP primary content", async () => {
|
||||
@@ -306,15 +294,11 @@ describe("openclaw channel mcp server", () => {
|
||||
|
||||
await flushMcpNotifications();
|
||||
expect(channelNotifications).toHaveLength(1);
|
||||
expect(channelNotifications[0]).toMatchObject({
|
||||
content: "hello Claude",
|
||||
meta: expect.objectContaining({
|
||||
session_key: sessionKey,
|
||||
channel: "imessage",
|
||||
to: "+15551234567",
|
||||
message_id: "msg-user-1",
|
||||
}),
|
||||
});
|
||||
expect(channelNotifications[0]?.content).toBe("hello Claude");
|
||||
expect(channelNotifications[0]?.meta.session_key).toBe(sessionKey);
|
||||
expect(channelNotifications[0]?.meta.channel).toBe("imessage");
|
||||
expect(channelNotifications[0]?.meta.to).toBe("+15551234567");
|
||||
expect(channelNotifications[0]?.meta.message_id).toBe("msg-user-1");
|
||||
|
||||
await mcp.client.notification({
|
||||
method: "notifications/claude/channel/permission_request",
|
||||
@@ -367,13 +351,9 @@ describe("openclaw channel mcp server", () => {
|
||||
|
||||
await flushMcpNotifications();
|
||||
expect(channelNotifications).toHaveLength(2);
|
||||
expect(channelNotifications[1]).toMatchObject({
|
||||
content: "plain string user turn",
|
||||
meta: expect.objectContaining({
|
||||
session_key: sessionKey,
|
||||
message_id: "msg-user-3",
|
||||
}),
|
||||
});
|
||||
expect(channelNotifications[1]?.content).toBe("plain string user turn");
|
||||
expect(channelNotifications[1]?.meta.session_key).toBe(sessionKey);
|
||||
expect(channelNotifications[1]?.meta.message_id).toBe("msg-user-3");
|
||||
} finally {
|
||||
await mcp?.close();
|
||||
}
|
||||
@@ -402,17 +382,16 @@ describe("openclaw channel mcp server", () => {
|
||||
text: "reply from mcp",
|
||||
});
|
||||
|
||||
expect(gatewayRequest).toHaveBeenCalledWith(
|
||||
"send",
|
||||
expect.objectContaining({
|
||||
to: "-100123",
|
||||
channel: "telegram",
|
||||
accountId: "acct-1",
|
||||
threadId: "42",
|
||||
sessionKey: "agent:main:main",
|
||||
message: "reply from mcp",
|
||||
}),
|
||||
);
|
||||
expect(gatewayRequest).toHaveBeenCalledTimes(1);
|
||||
const [method, payload] = gatewayRequest.mock.calls[0] ?? [];
|
||||
expect(method).toBe("send");
|
||||
const sendPayload = payload as Record<string, unknown>;
|
||||
expect(sendPayload.to).toBe("-100123");
|
||||
expect(sendPayload.channel).toBe("telegram");
|
||||
expect(sendPayload.accountId).toBe("acct-1");
|
||||
expect(sendPayload.threadId).toBe("42");
|
||||
expect(sendPayload.sessionKey).toBe("agent:main:main");
|
||||
expect(sendPayload.message).toBe("reply from mcp");
|
||||
});
|
||||
|
||||
test("gets one conversation through sessions.describe without broad listing", async () => {
|
||||
@@ -439,15 +418,12 @@ describe("openclaw channel mcp server", () => {
|
||||
|
||||
attachReadyGateway(bridge, gatewayRequest);
|
||||
|
||||
await expect(bridge.getConversation("agent:main:main")).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
sessionKey: "agent:main:main",
|
||||
channel: "telegram",
|
||||
to: "-100123",
|
||||
accountId: "acct-1",
|
||||
lastMessagePreview: "latest message",
|
||||
}),
|
||||
);
|
||||
const conversation = await bridge.getConversation("agent:main:main");
|
||||
expect(conversation?.sessionKey).toBe("agent:main:main");
|
||||
expect(conversation?.channel).toBe("telegram");
|
||||
expect(conversation?.to).toBe("-100123");
|
||||
expect(conversation?.accountId).toBe("acct-1");
|
||||
expect(conversation?.lastMessagePreview).toBe("latest message");
|
||||
expect(gatewayRequest).toHaveBeenCalledWith("sessions.describe", {
|
||||
key: "agent:main:main",
|
||||
includeDerivedTitles: true,
|
||||
@@ -483,20 +459,16 @@ describe("openclaw channel mcp server", () => {
|
||||
|
||||
attachReadyGateway(bridge, gatewayRequest);
|
||||
|
||||
await expect(bridge.listConversations()).resolves.toEqual([
|
||||
expect.objectContaining({
|
||||
sessionKey: "agent:main:channel-field",
|
||||
channel: "telegram",
|
||||
to: "-100111",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
sessionKey: "agent:main:origin-field",
|
||||
channel: "imessage",
|
||||
to: "+15551230000",
|
||||
accountId: "imessage-default",
|
||||
threadId: "thread-7",
|
||||
}),
|
||||
]);
|
||||
const conversations = await bridge.listConversations();
|
||||
expect(conversations).toHaveLength(2);
|
||||
expect(conversations[0]?.sessionKey).toBe("agent:main:channel-field");
|
||||
expect(conversations[0]?.channel).toBe("telegram");
|
||||
expect(conversations[0]?.to).toBe("-100111");
|
||||
expect(conversations[1]?.sessionKey).toBe("agent:main:origin-field");
|
||||
expect(conversations[1]?.channel).toBe("imessage");
|
||||
expect(conversations[1]?.to).toBe("+15551230000");
|
||||
expect(conversations[1]?.accountId).toBe("imessage-default");
|
||||
expect(conversations[1]?.threadId).toBe("thread-7");
|
||||
});
|
||||
|
||||
test("swallows notification send errors after channel replies are matched", async () => {
|
||||
@@ -567,13 +539,11 @@ describe("openclaw channel mcp server", () => {
|
||||
})) as {
|
||||
structuredContent?: { event?: Record<string, unknown> };
|
||||
};
|
||||
expect(waited.structuredContent?.event).toMatchObject({
|
||||
type: "message",
|
||||
sessionKey: "agent:main:main",
|
||||
messageId: "msg-2",
|
||||
role: "user",
|
||||
text: "inbound live message",
|
||||
});
|
||||
expect(waited.structuredContent?.event?.type).toBe("message");
|
||||
expect(waited.structuredContent?.event?.sessionKey).toBe("agent:main:main");
|
||||
expect(waited.structuredContent?.event?.messageId).toBe("msg-2");
|
||||
expect(waited.structuredContent?.event?.role).toBe("user");
|
||||
expect(waited.structuredContent?.event?.text).toBe("inbound live message");
|
||||
} finally {
|
||||
await mcp.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user