Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(lizi-mcps): cover helper call_tool transport

tiammomo1d3ce0edec49
diff --git a/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts b/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts
new file mode 100644
index 0000000000..0d55b6f16c
--- /dev/null
+++ b/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts
@@ -0,0 +1,100 @@
+import { Client } from "@modelcontextprotocol/sdk/client/index.js";
+import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
+import { describe, expect, it, vi } from "vitest";
+
+import { createXdtHelperMcpServer } from "../lizi_xdtHelperMcpServer.js";
+
+const TARGET_SESSION_ID = "11111111-1111-4111-8111-111111111111";
+
+function parsePayload(result: unknown): Record<string, unknown> {
+ const content = (
+ result as { content?: Array<{ type: string; text?: string }> }
+ ).content;
+ const first = content?.[0];
+ if (!first || first.type !== "text" || !first.text) {
+ throw new Error("tool result has no text content");
+ }
+ return JSON.parse(first.text) as Record<string, unknown>;
+}
+
+describe("cindy_helper MCP server", () => {
+ it("dispatches a discovered send_to_session call without dropping nested arguments", async () => {
+ const sendToSession = vi.fn(async () => ({
+ ok: true as const,
+ targetSessionId: TARGET_SESSION_ID,
+ agentKind: "codex" as const,
+ wakeKind: "resumed" as const,
+ targetTitle: "Issue follow-up",
+ targetLastUserSendAt: null,
+ }));
+ const server = createXdtHelperMcpServer(
+ { sendToSession },
+ {
+ agentKind: "codex",
+ workingDir: "/repo",
+ sessionId: "dispatcher-session",
+ },
+ );
+ const [clientTransport, serverTransport] =
+ InMemoryTransport.createLinkedPair();
+ const client = new Client({
+ name: "cindy-helper-transport-test",
+ version: "0.0.0",
+ });
+
+ await Promise.all([
+ server.connect(serverTransport),
+ client.connect(clientTransport),
+ ]);
+ try {
+ const topLevelTools = await client.listTools();
+ expect(topLevelTools.tools.map((tool) => tool.name).sort()).toEqual([
+ "call_tool",
+ "list_tools",
+ ]);
+
+ const discovered = parsePayload(
+ await client.callTool({
+ name: "list_tools",
+ arguments: { category: "handoff" },
+ }),
+ );
+ expect(discovered).toMatchObject({
+ ok: true,
+ category: "handoff",
+ });
+ const discoveredTools = discovered.tools as Array<{ name: string }>;
+ expect(discoveredTools.map((tool) => tool.name)).toContain(
+ "send_to_session",
+ );
+
+ const result = await client.callTool({
+ name: "call_tool",
+ arguments: {
+ name: "send_to_session",
+ args: {
+ target_session_id: TARGET_SESSION_ID,
+ message: "Continue the existing task",
+ },
+ },
+ });
+
+ expect(result.isError).not.toBe(true);
+ expect(parsePayload(result)).toMatchObject({
+ ok: true,
+ target_session_id: TARGET_SESSION_ID,
+ wake_kind: "resumed",
+ });
+ expect(sendToSession).toHaveBeenCalledOnce();
+ expect(sendToSession).toHaveBeenCalledWith({
+ targetSessionId: TARGET_SESSION_ID,
+ message: "Continue the existing task",
+ dispatcherSessionId: "dispatcher-session",
+ title: undefined,
+ });
+ } finally {
+ await client.close();
+ await server.close();
+ }
+ });
+});