@devries-cameron20 / composio Mirror · read-only / commits / d7d5d46f4
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, 19:45 UTC

fix(ts/e2e): stabilize Tool Router e2e tests (#3605)

This PR: - addresses the Mastra Tool Router E2E timeout seen in https://github.com/ComposioHQ/composio/actions/runs/27758637694/job/82126898492 - addresses the Cloudflare Tool Router AI failure seen in https://github.com/ComposioHQ/composio/actions/runs/27759741357/job/82130692480 - addresses the follow-up Cloudflare basic timeout seen in https://github.com/ComposioHQ/composio/actions/runs/27760548665/job/82133483582 - uses the existing `TIMEOUTS.LLM_LONG` live-LLM budget for both Mastra Tool Router zod-v3 and zod-v4 suites - raises the HTTP MCP connection-phase timeout from Mastra's implicit 3s default to 15s in both zod-v3 and zod-v4 suites - keeps the Cloudflare AI test's `Output.object({ karma })` structured output and validates the returned `response.karma` - asserts that `HACKERNEWS_GET_USER` was called and that `response.karma` equals the structured MCP tool output - removes the extra Cloudflare `prepareStep` steering and `findNumberProperty` extraction helper - avoids explicit `@ai-sdk/mcp` HTTP client close calls in workerd because the close path aborts the pending stream and Vitest reports it as unhandled - gives the live Cloudflare HackerNews compatibility test a 30s budget while leaving the fast smoke tests on Vitest's default timeout - fixes the zod-v3 test label so it reports `zod 3` instead of `zod 4` Verification: - `./ts/e2e-tests/_utils/node_modules/.bin/tsc --noEmit -p ts/e2e-tests/runtimes/node/mastra-tool-router-zod-v3/tsconfig.json` - `./ts/e2e-tests/_utils/node_modules/.bin/tsc --noEmit -p ts/e2e-tests/runtimes/node/mastra-tool-router-zod-v4/tsconfig.json` - `pnpm exec vitest run -t "should connect to MCP server"` from `ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai` - `pnpm exec tsc --noEmit --target es2022 --lib es2022 --module es2022 --moduleResolution Bundler --resolveJsonModule --allowSyntheticDefaultImports --strict --skipLibCheck --types @cloudflare/workers-types src/index.ts` from `ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai` - `pnpm exec vitest run -t "should fetch HackerNews user pg successfully"` from `ts/e2e-tests/runtimes/cloudflare/cf-workers-basic` - `pnpm exec vitest run` from `ts/e2e-tests/runtimes/cloudflare/cf-workers-basic` - `pnpm exec prettier --check ts/e2e-tests/runtimes/cloudflare/cf-workers-basic/test/platform.spec.ts` - `pnpm exec prettier --check ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/src/index.ts ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/test/tool-router-ai.spec.ts ts/e2e-tests/runtimes/node/mastra-tool-router-zod-v3/e2e.test.ts ts/e2e-tests/runtimes/node/mastra-tool-router-zod-v4/e2e.test.ts` - `git diff --check` CI: - `E2E Test Typescript SDK` passed on https://github.com/ComposioHQ/composio/actions/runs/27768379357 Note: the full Cloudflare AI test was not run locally because this checkout's local `OPENAI_API_KEY` is invalid; CI has the repo secret for that path.

Alberto Schiabel committed Jun 18, 2026 at 19:01 UTC d7d5d46f4d54d580a945e75322f4042d016a31d7
5 files changed +232 -171
ts/e2e-tests/runtimes/cloudflare/cf-workers-basic/test/platform.spec.ts
+27 -22
@@ -3,6 +3,7 @@ import { describe, it, expect } from 'vitest';
3 import app from '../src/index';
4
5 const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
6 +const LIVE_API_TEST_TIMEOUT_MS = 30_000;
7
8 describe('@composio/core Cloudflare Workers compatibility', () => {
9 it('should list the available endpoints', async () => {
@@ -89,29 +90,33 @@ describe('@composio/core Cloudflare Workers compatibility', () => {
90 expect(body.error).toContain('not supported in Cloudflare Workers');
91 });
92
92 - it('should fetch HackerNews user pg successfully', async () => {
93 - const request = new IncomingRequest('http://localhost/test/hackernews');
94 - const ctx = createExecutionContext();
95 - const response = await app.fetch(request, env, ctx);
96 - await waitOnExecutionContext(ctx);
97 -
98 - const body = (await response.json()) as {
99 - success: boolean;
100 - message?: string;
101 - error?: string;
102 - data?: {
103 - username: string;
104 - karma: number;
105 - about?: string;
93 + it(
94 + 'should fetch HackerNews user pg successfully',
95 + async () => {
96 + const request = new IncomingRequest('http://localhost/test/hackernews');
97 + const ctx = createExecutionContext();
98 + const response = await app.fetch(request, env, ctx);
99 + await waitOnExecutionContext(ctx);
100 +
101 + const body = (await response.json()) as {
102 + success: boolean;
103 + message?: string;
104 + error?: string;
105 + data?: {
106 + username: string;
107 + karma: number;
108 + about?: string;
109 + };
110 };
107 - };
111
109 - console.log('HackerNews response:', JSON.stringify(body, null, 2));
112 + console.log('HackerNews response:', JSON.stringify(body, null, 2));
113
111 - expect(response.status).toBe(200);
112 - expect(body.success).toBe(true);
113 - expect(body.message).toContain('pg');
114 - expect(body.data?.username).toBe('pg');
115 - expect(body.data?.karma).toBeGreaterThan(0);
116 - });
114 + expect(response.status).toBe(200);
115 + expect(body.success).toBe(true);
116 + expect(body.message).toContain('pg');
117 + expect(body.data?.username).toBe('pg');
118 + expect(body.data?.karma).toBeGreaterThan(0);
119 + },
120 + LIVE_API_TEST_TIMEOUT_MS
121 + );
122 });
ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/src/index.ts
+64 -37
@@ -19,16 +19,28 @@ type Bindings = {
19
20 const app = new Hono<{ Bindings: Bindings }>();
21
22 +const hackerNewsUserOutputSchema = z
23 + .union([
24 + z.object({
25 + username: z.string().optional(),
26 + karma: z.number(),
27 + }),
28 + z.object({
29 + data: z.object({
30 + username: z.string().optional(),
31 + karma: z.number(),
32 + }),
33 + }),
34 + ])
35 + .transform(output => ('data' in output ? output.data : output));
36 +
37 /**
38 * Default route - lists available test endpoints
39 */
40 app.get('/', c => {
41 return c.json({
42 message: 'Tool Router AI E2E Test Worker',
28 - endpoints: [
29 - '/test/mcp-client',
30 - '/test/agent',
31 - ],
43 + endpoints: ['/test/mcp-client', '/test/agent'],
44 });
45 });
46
@@ -55,15 +67,15 @@ app.get('/test/mcp-client', async c => {
67
68 const { mcp } = session;
69
58 - const mcpClient = await createMCPClient({
70 + await createMCPClient({
71 transport: {
72 type: 'http',
73 url: mcp.url,
74 headers: mcp.headers,
75 },
76 });
65 -
66 - c.executionCtx.waitUntil(mcpClient.close());
77 + // Intentionally do not close the HTTP MCP client here: in workerd, @ai-sdk/mcp
78 + // aborts the pending stream and Vitest reports it as an unhandled rejection.
79
80 return c.json({
81 message: 'MCP client connected successfully',
@@ -74,7 +86,7 @@ app.get('/test/mcp-client', async c => {
86 /**
87 * Test: Agent Execution
88 * Tests the full workflow: create session, get tools, run agent with generateText.
77 - *
89 + *
90 * Note: this takes ~40s locally.
91 */
92 app.get('/test/agent', async c => {
@@ -87,6 +99,7 @@ app.get('/test/agent', async c => {
99 const session = await composio.create('default', {
100 toolkits: ['hackernews'],
101 manageConnections: true,
102 + preload: { tools: ['HACKERNEWS_GET_USER'] },
103 tools: {
104 hackernews: {
105 enable: ['HACKERNEWS_GET_USER'],
@@ -103,37 +116,51 @@ app.get('/test/agent', async c => {
116 headers: mcp.headers,
117 },
118 });
106 -
107 - try {
108 - const tools = await mcpClient.tools();
109 - const openai = createOpenAI({ apiKey: c.env.OPENAI_API_KEY });
110 -
111 - const result = await generateText({
112 - model: openai('gpt-5.1-codex'),
113 - prompt: `Look up the HackerNews user "pg", and tell me their karma score.`,
114 - output: Output.object({
115 - schema: z.object({
116 - karma: z.number(),
119 + // Intentionally do not close the HTTP MCP client here: in workerd, @ai-sdk/mcp
120 + // aborts the pending stream and Vitest reports it as an unhandled rejection.
121 +
122 + const tools = await mcpClient.tools({
123 + schemas: {
124 + HACKERNEWS_GET_USER: {
125 + inputSchema: z.object({
126 + username: z.string(),
127 }),
128 + outputSchema: hackerNewsUserOutputSchema,
129 + },
130 + },
131 + });
132 + const openai = createOpenAI({ apiKey: c.env.OPENAI_API_KEY });
133 +
134 + const result = await generateText({
135 + model: openai('gpt-5.1-codex'),
136 + prompt: `Look up the HackerNews user "pg" with HACKERNEWS_GET_USER, then return the exact karma value from that tool result.`,
137 + output: Output.object({
138 + schema: z.object({
139 + karma: z.number(),
140 }),
119 - stopWhen: stepCountIs(10),
120 - tools,
121 - });
122 -
123 - const toolCalls = result.steps.flatMap(step =>
124 - step.toolCalls.map(tc => ({ toolName: tc.toolName }))
125 - );
126 -
127 - return c.json({
128 - message: 'Agent executed successfully',
129 - sessionId,
130 - toolCount: Object.keys(tools).length,
131 - toolCalls,
132 - response: result.output,
133 - });
134 - } finally {
135 - c.executionCtx.waitUntil(mcpClient.close());
136 - }
141 + }),
142 + stopWhen: stepCountIs(10),
143 + tools,
144 + });
145 +
146 + const toolCalls = result.steps.flatMap(step =>
147 + step.toolCalls.map(toolCall => ({ toolName: toolCall.toolName }))
148 + );
149 + const toolResults = result.steps.flatMap(step =>
150 + step.toolResults.map(toolResult => ({
151 + toolName: toolResult.toolName,
152 + output: toolResult.output,
153 + }))
154 + );
155 +
156 + return c.json({
157 + message: 'Agent executed successfully',
158 + sessionId,
159 + toolCount: Object.keys(tools).length,
160 + toolCalls,
161 + toolResults,
162 + response: result.output,
163 + });
164 });
165
166 export default app;
ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai/test/tool-router-ai.spec.ts
+14 -1
@@ -4,6 +4,11 @@ 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/');
@@ -58,6 +63,7 @@ describe('Tool Router AI - Cloudflare Workers compatibility', () => {
63 sessionId?: string;
64 toolCount?: number;
65 toolCalls?: Array<{ toolName: string }>;
66 + toolResults?: Array<{ toolName: string; output: HackerNewsUserOutput }>;
67 response: {
68 karma: number;
69 };
@@ -73,6 +79,13 @@ describe('Tool Router AI - Cloudflare Workers compatibility', () => {
79 expect(typeof body.response.karma).toEqual('number');
80 expect(body.response.karma).toBeGreaterThan(150_000);
81
76 - expect(body.toolCalls).toContainEqual({ toolName: 'COMPOSIO_SEARCH_TOOLS' });
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 });
ts/e2e-tests/runtimes/node/mastra-tool-router-zod-v3/e2e.test.ts
+64 -56
@@ -2,7 +2,7 @@
2 * @composio/mastra + openai + zod 3
3 *
4 * Verifies that @composio/mastra works correctly with zod@3.
5 - *
5 + *
6 * See: https://github.com/ComposioHQ/composio/issues/2109.
7 */
8
@@ -17,6 +17,8 @@ import { createOpenAI } from '@ai-sdk/openai';
17 import { stepCountIs } from 'ai';
18 import { z } from 'zod';
19
20 +const MCP_CONNECT_TIMEOUT_MS = 15_000;
21 +
22 declare module 'bun' {
23 interface Env {
24 COMPOSIO_API_KEY: string;
@@ -31,74 +33,80 @@ e2e(import.meta.url, {
33 OPENAI_API_KEY: Bun.env.OPENAI_API_KEY,
34 },
35 defineTests: () => {
34 - describe('@composio/mastra + openai + zod 4', () => {
35 -
36 + describe('@composio/mastra + openai + zod 3', () => {
37 const composio = new Composio({
38 apiKey: Bun.env.COMPOSIO_API_KEY,
39 provider: new MastraProvider(),
40 });
40 -
41 - it('should work with Tool Router', async () => {
42 - const session = await composio.create('default', {
43 - toolkits: ['hackernews'],
44 - manageConnections: true,
45 - tools: {
46 - hackernews: {
47 - enable: ['HACKERNEWS_GET_USER'],
41 +
42 + it(
43 + 'should work with Tool Router',
44 + async () => {
45 + const session = await composio.create('default', {
46 + toolkits: ['hackernews'],
47 + manageConnections: true,
48 + tools: {
49 + hackernews: {
50 + enable: ['HACKERNEWS_GET_USER'],
51 + },
52 },
49 - },
50 - });
53 + });
54
52 - const { mcp, sessionId } = session;
53 - expect(sessionId).toBeDefined();
55 + const { mcp, sessionId } = session;
56 + expect(sessionId).toBeDefined();
57
55 - // Create a client with an HTTP server (tries Streamable HTTP, falls back to SSE)
56 - const mcpClient = new MCPClient({
57 - servers: {
58 - myHttpClient: {
59 - url: new URL(mcp.url),
60 - requestInit: {
61 - headers: mcp.headers,
58 + // Create a client with an HTTP server (tries Streamable HTTP, falls back to SSE)
59 + const mcpClient = new MCPClient({
60 + timeout: TIMEOUTS.LLM_LONG,
61 + servers: {
62 + myHttpClient: {
63 + url: new URL(mcp.url),
64 + connectTimeout: MCP_CONNECT_TIMEOUT_MS,
65 + requestInit: {
66 + headers: mcp.headers,
67 + },
68 },
69 },
64 - },
65 - });
70 + });
71
67 - const tools = await mcpClient.listTools();
68 - const openai = createOpenAI({ apiKey: Bun.env.OPENAI_API_KEY });
72 + const tools = await mcpClient.listTools();
73 + const openai = createOpenAI({ apiKey: Bun.env.OPENAI_API_KEY });
74
70 - const hackernewsAgent = new Agent({
71 - id: 'test',
72 - name: 'test',
73 - instructions: `You're a helpful Hackernews agent, able to finding information about users.`,
74 - model: openai('gpt-5.1'),
75 - tools,
76 - });
75 + const hackernewsAgent = new Agent({
76 + id: 'test',
77 + name: 'test',
78 + instructions: `You're a helpful Hackernews agent, able to finding information about users.`,
79 + model: openai('gpt-5.1'),
80 + tools,
81 + });
82
78 - const result = await hackernewsAgent.generate('Look up user "pg", and tell me their karma score.', {
79 - structuredOutput: {
80 - schema: z.object({
81 - karma: z.number(),
82 - }),
83 - },
84 - stopWhen: stepCountIs(10),
85 - });
83 + const result = await hackernewsAgent.generate(
84 + 'Look up user "pg", and tell me their karma score.',
85 + {
86 + structuredOutput: {
87 + schema: z.object({
88 + karma: z.number(),
89 + }),
90 + },
91 + stopWhen: stepCountIs(10),
92 + }
93 + );
94
87 - const toolCalls = result.toolCalls.flatMap(toolCall =>
88 - toolCall.payload.toolName
89 - );
90 - const toolCount = Object.keys(tools).length;
95 + const toolCalls = result.toolCalls.flatMap(toolCall => toolCall.payload.toolName);
96 + const toolCount = Object.keys(tools).length;
97
92 - expect(toolCount).toBeGreaterThan(0);
93 - expect(toolCalls).toBeDefined();
94 - expect(result.error).toBeUndefined();
95 - expect(result.object).toBeDefined();
96 - expect(result.object.karma).toBeGreaterThan(0);
97 -
98 - await mcpClient.disconnect();
99 - }, {
100 - timeout: TIMEOUTS.LLM_SHORT,
101 - });
98 + expect(toolCount).toBeGreaterThan(0);
99 + expect(toolCalls).toBeDefined();
100 + expect(result.error).toBeUndefined();
101 + expect(result.object).toBeDefined();
102 + expect(result.object.karma).toBeGreaterThan(0);
103 +
104 + await mcpClient.disconnect();
105 + },
106 + {
107 + timeout: TIMEOUTS.LLM_LONG,
108 + }
109 + );
110 });
103 - }
111 + },
112 });
ts/e2e-tests/runtimes/node/mastra-tool-router-zod-v4/e2e.test.ts
+63 -55
@@ -2,7 +2,7 @@
2 * @composio/mastra + openai + zod 4
3 *
4 * Verifies that @composio/mastra works correctly with zod@4.
5 - *
5 + *
6 * See: https://github.com/ComposioHQ/composio/issues/2109.
7 */
8
@@ -17,6 +17,8 @@ import { createOpenAI } from '@ai-sdk/openai';
17 import { stepCountIs } from 'ai';
18 import { z } from 'zod';
19
20 +const MCP_CONNECT_TIMEOUT_MS = 15_000;
21 +
22 declare module 'bun' {
23 interface Env {
24 COMPOSIO_API_KEY: string;
@@ -32,73 +34,79 @@ e2e(import.meta.url, {
34 },
35 defineTests: () => {
36 describe('@composio/mastra + openai + zod 4', () => {
35 -
37 const composio = new Composio({
38 apiKey: Bun.env.COMPOSIO_API_KEY,
39 provider: new MastraProvider(),
40 });
40 -
41 - it('should work with Tool Router', async () => {
42 - const session = await composio.create('default', {
43 - toolkits: ['hackernews'],
44 - manageConnections: true,
45 - tools: {
46 - hackernews: {
47 - enable: ['HACKERNEWS_GET_USER'],
41 +
42 + it(
43 + 'should work with Tool Router',
44 + async () => {
45 + const session = await composio.create('default', {
46 + toolkits: ['hackernews'],
47 + manageConnections: true,
48 + tools: {
49 + hackernews: {
50 + enable: ['HACKERNEWS_GET_USER'],
51 + },
52 },
49 - },
50 - });
53 + });
54
52 - const { mcp, sessionId } = session;
53 - expect(sessionId).toBeDefined();
55 + const { mcp, sessionId } = session;
56 + expect(sessionId).toBeDefined();
57
55 - // Create a client with an HTTP server (tries Streamable HTTP, falls back to SSE)
56 - const mcpClient = new MCPClient({
57 - servers: {
58 - myHttpClient: {
59 - url: new URL(mcp.url),
60 - requestInit: {
61 - headers: mcp.headers,
58 + // Create a client with an HTTP server (tries Streamable HTTP, falls back to SSE)
59 + const mcpClient = new MCPClient({
60 + timeout: TIMEOUTS.LLM_LONG,
61 + servers: {
62 + myHttpClient: {
63 + url: new URL(mcp.url),
64 + connectTimeout: MCP_CONNECT_TIMEOUT_MS,
65 + requestInit: {
66 + headers: mcp.headers,
67 + },
68 },
69 },
64 - },
65 - });
70 + });
71
67 - const tools = await mcpClient.listTools();
68 - const openai = createOpenAI({ apiKey: Bun.env.OPENAI_API_KEY });
72 + const tools = await mcpClient.listTools();
73 + const openai = createOpenAI({ apiKey: Bun.env.OPENAI_API_KEY });
74
70 - const hackernewsAgent = new Agent({
71 - id: 'test',
72 - name: 'test',
73 - instructions: `You're a helpful Hackernews agent, able to finding information about users.`,
74 - model: openai('gpt-5.1'),
75 - tools,
76 - });
75 + const hackernewsAgent = new Agent({
76 + id: 'test',
77 + name: 'test',
78 + instructions: `You're a helpful Hackernews agent, able to finding information about users.`,
79 + model: openai('gpt-5.1'),
80 + tools,
81 + });
82
78 - const result = await hackernewsAgent.generate('Look up user "pg", and tell me their karma score.', {
79 - structuredOutput: {
80 - schema: z.object({
81 - karma: z.number(),
82 - }),
83 - },
84 - stopWhen: stepCountIs(10),
85 - });
83 + const result = await hackernewsAgent.generate(
84 + 'Look up user "pg", and tell me their karma score.',
85 + {
86 + structuredOutput: {
87 + schema: z.object({
88 + karma: z.number(),
89 + }),
90 + },
91 + stopWhen: stepCountIs(10),
92 + }
93 + );
94
87 - const toolCalls = result.toolCalls.flatMap(toolCall =>
88 - toolCall.payload.toolName
89 - );
90 - const toolCount = Object.keys(tools).length;
95 + const toolCalls = result.toolCalls.flatMap(toolCall => toolCall.payload.toolName);
96 + const toolCount = Object.keys(tools).length;
97
92 - expect(toolCount).toBeGreaterThan(0);
93 - expect(toolCalls).toBeDefined();
94 - expect(result.error).toBeUndefined();
95 - expect(result.object).toBeDefined();
96 - expect(result.object.karma).toBeGreaterThanOrEqual(0);
97 -
98 - await mcpClient.disconnect();
99 - }, {
100 - timeout: TIMEOUTS.LLM_SHORT,
101 - });
98 + expect(toolCount).toBeGreaterThan(0);
99 + expect(toolCalls).toBeDefined();
100 + expect(result.error).toBeUndefined();
101 + expect(result.object).toBeDefined();
102 + expect(result.object.karma).toBeGreaterThanOrEqual(0);
103 +
104 + await mcpClient.disconnect();
105 + },
106 + {
107 + timeout: TIMEOUTS.LLM_LONG,
108 + }
109 + );
110 });
103 - }
111 + },
112 });