@devries-cameron20 / composio Mirror · read-only / commits / cdc2606e8
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 22, 03:15 UTC

test(e2e): expand custom tools fixture with mixed routing and error cases

- Add WEATHER_CHAIN tool: local tool calls remote WEATHERMAP_WEATHER via SessionContext.execute() — proves mixed local+remote in same session - Add Zod validation failure test (wrong type → error, no crash) - Add non-existent tool test (backend 400 → catchable error) - Add STRICT_TOOL with z.number() schema for validation testing - Switch from hackernews to weathermap toolkit (simpler, active connection) - 12 test cases total, all passing against production API Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Dhawal Upadhyay committed Mar 10, 2026 at 18:43 UTC cdc2606e8251e9db45d104df16e889629499f4fe
2 files changed +125 -21
ts/e2e-tests/runtimes/node/custom-tools/e2e.test.ts
+18 -5
@@ -2,7 +2,8 @@
2 * Custom local tools E2E test.
3 *
4 * Verifies local tool execution, Zod validation, session context, error handling,
5 - * and mixed local+remote execution against the live Composio API.
5 + * mixed local+remote chaining, and edge cases against the live Composio API.
6 + * Uses weathermap toolkit (no auth needed).
7 * Requires COMPOSIO_API_KEY in environment.
8 */
9
@@ -41,15 +42,19 @@ e2e(import.meta.url, {
42 expect(result.stdout).toContain('ZOD_DEFAULTS_OK');
43 });
44
44 - it('error handling works', () => {
45 + it('error thrown by tool is wrapped into { data, error }', () => {
46 expect(result.stdout).toContain('ERROR_HANDLING_OK');
47 });
48
48 - it('multiple local tools work', () => {
49 + it('Zod validation failure returns error, does not crash', () => {
50 + expect(result.stdout).toContain('ZOD_VALIDATION_FAIL_OK');
51 + });
52 +
53 + it('multiple local tools route to correct execute fn', () => {
54 expect(result.stdout).toContain('MULTIPLE_TOOLS_OK');
55 });
56
52 - it('session context is injected', () => {
57 + it('session context injects userId', () => {
58 expect(result.stdout).toContain('SESSION_CONTEXT_OK');
59 });
60
@@ -57,10 +62,18 @@ e2e(import.meta.url, {
62 expect(result.stdout).toContain('CASE_INSENSITIVE_OK');
63 });
64
60 - it('prefixed slug works', () => {
65 + it('prefixed slug (LOCAL_) works', () => {
66 expect(result.stdout).toContain('PREFIXED_SLUG_OK');
67 });
68
69 + it('local tool chains into remote tool via SessionContext.execute()', () => {
70 + expect(result.stdout).toContain('CHAINED_EXECUTE_OK');
71 + });
72 +
73 + it('non-existent tool returns error gracefully', () => {
74 + expect(result.stdout).toContain('NONEXISTENT_TOOL_OK');
75 + });
76 +
77 it('localTools() method works', () => {
78 expect(result.stdout).toContain('LOCAL_TOOLS_METHOD_OK');
79 });
ts/e2e-tests/runtimes/node/custom-tools/fixtures/index.mjs
+107 -16
@@ -1,5 +1,9 @@
1 /**
2 * E2E fixture: Custom local tools execution flow.
3 + * Tests local execution, remote execution, mixed routing, error handling,
4 + * and SessionContext chaining against the live Composio API.
5 + *
6 + * Uses weathermap toolkit (no auth needed, active connection).
7 * Requires COMPOSIO_API_KEY in environment.
8 */
9 import { Composio } from '@composio/core';
@@ -51,6 +55,41 @@ const throwingTool = CustomTool({
55 },
56 });
57
58 +// Tool with strict numeric schema — for Zod validation failure test
59 +const strictTool = CustomTool({
60 + slug: 'STRICT_TOOL',
61 + name: 'Strict tool',
62 + description: 'Tool with strict numeric input',
63 + inputParams: z.object({
64 + count: z.number(),
65 + }),
66 + execute: async (input) => {
67 + return { doubled: input.count * 2 };
68 + },
69 +});
70 +
71 +// Tool that chains into a remote tool via SessionContext.execute()
72 +const weatherChain = CustomTool({
73 + slug: 'WEATHER_CHAIN',
74 + name: 'Weather chain',
75 + description: 'Fetches weather via remote tool and enriches with local context',
76 + inputParams: z.object({
77 + city: z.string(),
78 + }),
79 + execute: async (input, session) => {
80 + // Call remote WEATHERMAP_WEATHER tool through SessionContext
81 + const weather = await session.execute('WEATHERMAP_WEATHER', {
82 + location: input.city,
83 + });
84 + return {
85 + city: input.city,
86 + userId: session.userId,
87 + weatherData: weather.data,
88 + weatherError: weather.error,
89 + };
90 + },
91 +});
92 +
93 // ── Create session and run tests ─────────────────────────────
94
95 const composio = new Composio({ apiKey });
@@ -59,9 +98,9 @@ async function main() {
98 const userId = `e2e-custom-tools-${Date.now()}`;
99
100 const session = await composio.create(userId, {
62 - toolkits: ['hackernews'],
101 + toolkits: ['weathermap'],
102 manageConnections: false,
64 - customTools: [getUserContext, enrichedSearch, throwingTool],
103 + customTools: [getUserContext, enrichedSearch, throwingTool, strictTool, weatherChain],
104 });
105
106 // ── Test 1: Single local tool execution ──
@@ -85,16 +124,32 @@ async function main() {
124 console.log('ZOD_DEFAULTS_OK');
125 }
126
88 - // ── Test 3: Error handling ──
127 + // ── Test 3: Error handling — throw wrapped into { data, error } ──
128 {
129 const result = await session.execute('THROWING_TOOL', {});
130 if (!result.error || !result.error.includes('intentional error')) {
131 throw new Error(`ERROR_HANDLING failed: ${JSON.stringify(result)}`);
132 }
133 + // Verify it didn't crash — we got a structured response
134 + if (result.data === undefined) {
135 + throw new Error(`ERROR_HANDLING no data field: ${JSON.stringify(result)}`);
136 + }
137 console.log('ERROR_HANDLING_OK');
138 }
139
97 - // ── Test 4: Multiple local tools ──
140 + // ── Test 4: Zod validation failure — wrong type wrapped into error ──
141 + {
142 + const result = await session.execute('STRICT_TOOL', { count: 'not-a-number' });
143 + if (!result.error) {
144 + throw new Error(`ZOD_VALIDATION_FAIL expected error: ${JSON.stringify(result)}`);
145 + }
146 + if (!result.error.toLowerCase().includes('validation')) {
147 + throw new Error(`ZOD_VALIDATION_FAIL expected validation error: ${result.error}`);
148 + }
149 + console.log('ZOD_VALIDATION_FAIL_OK');
150 + }
151 +
152 + // ── Test 5: Multiple local tools route correctly ──
153 {
154 const r1 = await session.execute('GET_USER_CONTEXT', { category: 'a' });
155 const r2 = await session.execute('ENRICHED_SEARCH', { query: 'test' });
@@ -107,7 +162,7 @@ async function main() {
162 console.log('MULTIPLE_TOOLS_OK');
163 }
164
110 - // ── Test 5: Session context injection ──
165 + // ── Test 6: Session context injection (userId) ──
166 {
167 const result = await session.execute('ENRICHED_SEARCH', { query: 'context-test' });
168 if (!result.data?.userId) {
@@ -119,7 +174,7 @@ async function main() {
174 console.log('SESSION_CONTEXT_OK');
175 }
176
122 - // ── Test 6: Case-insensitive slug ──
177 + // ── Test 7: Case-insensitive slug ──
178 {
179 const result = await session.execute('get_user_context', { category: 'case-test' });
180 if (result.data?.preferences?.category !== 'case-test') {
@@ -128,7 +183,7 @@ async function main() {
183 console.log('CASE_INSENSITIVE_OK');
184 }
185
131 - // ── Test 7: Prefixed slug (LOCAL_) ──
186 + // ── Test 8: Prefixed slug (LOCAL_) ──
187 {
188 const result = await session.execute('LOCAL_GET_USER_CONTEXT', { category: 'prefix-test' });
189 if (result.data?.preferences?.category !== 'prefix-test') {
@@ -137,29 +192,65 @@ async function main() {
192 console.log('PREFIXED_SLUG_OK');
193 }
194
140 - // ── Test 8: localTools() method ──
141 - // localTools() returns a wrapped tool — we just verify it doesn't throw
142 - // and returns something non-empty (can't fully test without LLM)
195 + // ── Test 9: SessionContext.execute() chaining — local tool calls remote tool ──
196 + // This is mixed local+remote execution: local tool runs in-process,
197 + // then calls WEATHERMAP_WEATHER on the backend via session.execute()
198 + {
199 + const result = await session.execute('WEATHER_CHAIN', { city: 'London' });
200 + if (result.error) {
201 + throw new Error(`CHAINED_EXECUTE failed: ${result.error}`);
202 + }
203 + if (result.data?.city !== 'London') {
204 + throw new Error(`CHAINED_EXECUTE city mismatch: ${JSON.stringify(result)}`);
205 + }
206 + if (!result.data?.userId) {
207 + throw new Error(`CHAINED_EXECUTE missing userId: ${JSON.stringify(result)}`);
208 + }
209 + // The chained remote call should have returned weather data
210 + if (!result.data?.weatherData) {
211 + throw new Error(`CHAINED_EXECUTE missing weatherData: ${JSON.stringify(result)}`);
212 + }
213 + console.log('CHAINED_EXECUTE_OK');
214 + }
215 +
216 + // ── Test 10: Non-existent tool returns error gracefully ──
217 + // Remote tools that don't exist throw from the backend (400).
218 + // Verify the SDK surfaces this as a catchable error, not a silent failure.
219 + {
220 + let caught = false;
221 + try {
222 + await session.execute('COMPLETELY_FAKE_TOOL_12345', {});
223 + } catch (err) {
224 + caught = true;
225 + if (!err.message?.includes('not found') && !err.message?.includes('400')) {
226 + throw new Error(`NONEXISTENT_TOOL unexpected error: ${err.message}`);
227 + }
228 + }
229 + if (!caught) {
230 + throw new Error('NONEXISTENT_TOOL expected an error but got success');
231 + }
232 + console.log('NONEXISTENT_TOOL_OK');
233 + }
234 +
235 + // ── Test 11: localTools() method ──
236 {
237 try {
238 const localTool = await session.localTools();
146 - // Verify it returned something (provider-specific format)
239 if (!localTool) {
240 throw new Error('localTools() returned falsy value');
241 }
242 console.log('LOCAL_TOOLS_METHOD_OK');
243 } catch (err) {
152 - // If provider doesn't support it, that's OK for this test
244 + // Expected — no provider configured in this fixture
245 if (err.message?.includes('provider')) {
154 - console.log('LOCAL_TOOLS_METHOD_OK'); // Expected if no provider
246 + console.log('LOCAL_TOOLS_METHOD_OK');
247 } else {
248 throw err;
249 }
250 }
251 }
252
161 - // ── Test 9: session.tools() wrapping ──
162 - // Verify session.tools() returns wrapped tools and doesn't crash
253 + // ── Test 12: session.tools() wrapping ──
254 {
255 try {
256 const tools = await session.tools();
@@ -168,7 +259,7 @@ async function main() {
259 }
260 console.log('TOOLS_WRAPPING_OK');
261 } catch (err) {
171 - // If provider doesn't support it, that's OK
262 + // Expected — no provider configured, standard path used
263 if (err.message?.includes('provider')) {
264 console.log('TOOLS_WRAPPING_OK');
265 } else {