@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 07:15 UTC

next
ts 91 lines 2.89 KB
Raw
1 import { env, createExecutionContext, waitOnExecutionContext } from 'cloudflare:test';
2 import { describe, it, expect } from 'vitest';
3 import app from '../src/index';
4
5 const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
6
7 type HackerNewsUserOutput = {
8 username?: string;
9 karma: number;
10 };
11
12 describe('Tool Router AI - Cloudflare Workers compatibility', () => {
13 it('should list the available endpoints', async () => {
14 const request = new IncomingRequest('http://localhost/');
15 const ctx = createExecutionContext();
16 const response = await app.fetch(request, env, ctx);
17 await waitOnExecutionContext(ctx);
18
19 expect(response.status).toBe(200);
20
21 const body = (await response.json()) as {
22 message: string;
23 endpoints: string[];
24 };
25
26 expect(body.message).toContain('Tool Router AI E2E Test Worker');
27 expect(body.endpoints).toMatchInlineSnapshot(`
28 [
29 "/test/mcp-client",
30 "/test/agent",
31 ]
32 `);
33 });
34
35 it('should connect to MCP server', async () => {
36 const request = new IncomingRequest('http://localhost/test/mcp-client');
37 const ctx = createExecutionContext();
38 const response = await app.fetch(request, env, ctx);
39 await waitOnExecutionContext(ctx);
40
41 const body = (await response.json()) as {
42 success: boolean;
43 message?: string;
44 error?: string;
45 mcpUrl?: string;
46 };
47
48 expect(response.status).toBe(200);
49 expect(body.message).toContain('MCP client connected');
50 expect(body.mcpUrl).toBeDefined();
51 });
52
53 it('should execute agent with Vercel AI SDK', async () => {
54 const request = new IncomingRequest('http://localhost/test/agent');
55 const ctx = createExecutionContext();
56 const response = await app.fetch(request, env, ctx);
57 await waitOnExecutionContext(ctx);
58
59 const body = (await response.json()) as {
60 success: boolean;
61 message?: string;
62 error?: string;
63 sessionId?: string;
64 toolCount?: number;
65 toolCalls?: Array<{ toolName: string }>;
66 toolResults?: Array<{ toolName: string; output: HackerNewsUserOutput }>;
67 response: {
68 karma: number;
69 };
70 };
71
72 expect(response.status).toBe(200);
73 expect(body.message).toContain('Agent executed successfully');
74 expect(body.sessionId).toBeDefined();
75 expect(body.toolCount).toBeGreaterThan(0);
76 expect(body.toolCalls).toBeDefined();
77 expect(body.response).toBeDefined();
78 expect(body.response.karma).toBeDefined();
79 expect(typeof body.response.karma).toEqual('number');
80 expect(body.response.karma).toBeGreaterThan(150_000);
81
82 expect(body.toolCalls).toContainEqual({ toolName: 'HACKERNEWS_GET_USER' });
83
84 const hackerNewsToolResult = body.toolResults?.find(
85 toolResult => toolResult.toolName === 'HACKERNEWS_GET_USER'
86 );
87
88 expect(hackerNewsToolResult).toBeDefined();
89 expect(hackerNewsToolResult?.output.karma).toBe(body.response.karma);
90 });
91 });