mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:50:43 +00:00
test: tighten MCP channel smoke route contract
This commit is contained in:
@@ -7,10 +7,52 @@ import {
|
||||
connectMcpClient,
|
||||
extractTextFromGatewayPayload,
|
||||
type ClaudeChannelNotification,
|
||||
type GatewayRpcClient,
|
||||
maybeApprovePendingBridgePairing,
|
||||
waitFor,
|
||||
} from "./mcp-channels-harness.ts";
|
||||
|
||||
function summarizeSessionRows(rows: Array<Record<string, unknown>> | undefined) {
|
||||
return (rows ?? []).map((entry) => ({
|
||||
key: entry.key,
|
||||
channel: entry.channel,
|
||||
deliveryContext: entry.deliveryContext,
|
||||
lastChannel: entry.lastChannel,
|
||||
lastTo: entry.lastTo,
|
||||
lastAccountId: entry.lastAccountId,
|
||||
lastThreadId: entry.lastThreadId,
|
||||
}));
|
||||
}
|
||||
|
||||
async function waitForGatewaySeededConversation(gateway: GatewayRpcClient) {
|
||||
let lastList: { sessions?: Array<Record<string, unknown>> } | undefined;
|
||||
try {
|
||||
return await waitFor(
|
||||
"seeded conversation in gateway sessions.list",
|
||||
async () => {
|
||||
lastList = await gateway.request<{ sessions?: Array<Record<string, unknown>> }>(
|
||||
"sessions.list",
|
||||
{ limit: 50, includeDerivedTitles: true, includeLastMessage: true },
|
||||
);
|
||||
return lastList.sessions?.find((entry) => entry.key === "agent:main:main");
|
||||
},
|
||||
60_000,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`gateway sessions.list did not include seeded conversation: ${JSON.stringify(
|
||||
{
|
||||
count: lastList?.sessions?.length ?? 0,
|
||||
sessions: summarizeSessionRows(lastList?.sessions),
|
||||
},
|
||||
null,
|
||||
2,
|
||||
)}`,
|
||||
{ cause: error },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const gatewayUrl = process.env.GW_URL?.trim();
|
||||
const gatewayToken = process.env.GW_TOKEN?.trim();
|
||||
@@ -36,6 +78,18 @@ async function main() {
|
||||
const callTool = <T>(params: Parameters<typeof mcp.callTool>[0]) =>
|
||||
mcp.callTool(params, undefined, { timeout: 240_000 }) as Promise<T>;
|
||||
|
||||
const gatewayConversation = await waitForGatewaySeededConversation(gateway);
|
||||
assert(
|
||||
(gatewayConversation.deliveryContext as { channel?: unknown } | undefined)?.channel ===
|
||||
"imessage",
|
||||
"expected seeded gateway deliveryContext channel",
|
||||
);
|
||||
assert(
|
||||
(gatewayConversation.deliveryContext as { to?: unknown } | undefined)?.to === "+15551234567",
|
||||
"expected seeded gateway deliveryContext target",
|
||||
);
|
||||
|
||||
let lastMcpConversationList: unknown;
|
||||
const conversation = await waitFor(
|
||||
"seeded conversation in conversations_list",
|
||||
async () => {
|
||||
@@ -45,12 +99,22 @@ async function main() {
|
||||
name: "conversations_list",
|
||||
arguments: {},
|
||||
});
|
||||
lastMcpConversationList = listed;
|
||||
return listed.structuredContent?.conversations?.find(
|
||||
(entry) => entry.sessionKey === "agent:main:main",
|
||||
);
|
||||
},
|
||||
240_000,
|
||||
);
|
||||
).catch((error) => {
|
||||
throw new Error(
|
||||
`timeout waiting for seeded MCP conversation: ${JSON.stringify(
|
||||
lastMcpConversationList,
|
||||
null,
|
||||
2,
|
||||
)}`,
|
||||
{ cause: error },
|
||||
);
|
||||
});
|
||||
assert(conversation.channel === "imessage", "expected seeded channel");
|
||||
assert(conversation.to === "+15551234567", "expected seeded target");
|
||||
|
||||
|
||||
@@ -47,10 +47,12 @@ async function main() {
|
||||
sessionId: "sess-main",
|
||||
sessionFile,
|
||||
updatedAt: now,
|
||||
lastChannel: "imessage",
|
||||
lastTo: "+15551234567",
|
||||
lastAccountId: "imessage-default",
|
||||
lastThreadId: "thread-42",
|
||||
deliveryContext: {
|
||||
channel: "imessage",
|
||||
to: "+15551234567",
|
||||
accountId: "imessage-default",
|
||||
threadId: "thread-42",
|
||||
},
|
||||
displayName: "Docker MCP Channel Smoke",
|
||||
derivedTitle: "Docker MCP Channel Smoke",
|
||||
lastMessagePreview: "seeded transcript",
|
||||
|
||||
@@ -323,7 +323,7 @@ describe("openclaw channel mcp server", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("lists routed sessions that only expose modern channel fields", async () => {
|
||||
test("lists routed sessions from deliveryContext without mirrored route fields", async () => {
|
||||
const bridge = new OpenClawChannelBridge({} as never, {
|
||||
claudeChannelMode: "off",
|
||||
verbose: false,
|
||||
@@ -332,21 +332,19 @@ describe("openclaw channel mcp server", () => {
|
||||
sessions: [
|
||||
{
|
||||
key: "agent:main:channel-field",
|
||||
channel: "telegram",
|
||||
deliveryContext: {
|
||||
channel: "telegram",
|
||||
to: "-100111",
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "agent:main:origin-field",
|
||||
origin: {
|
||||
provider: "imessage",
|
||||
deliveryContext: {
|
||||
channel: "imessage",
|
||||
to: "+15551230000",
|
||||
accountId: "imessage-default",
|
||||
threadId: "thread-7",
|
||||
},
|
||||
deliveryContext: {
|
||||
to: "+15551230000",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user