Skip to content

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

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

Dhawal Upadhyaycdc2606e8251
diff --git a/ts/e2e-tests/runtimes/node/custom-tools/e2e.test.ts b/ts/e2e-tests/runtimes/node/custom-tools/e2e.test.ts
index ba12b7808..ce977e990 100644
--- a/ts/e2e-tests/runtimes/node/custom-tools/e2e.test.ts
+++ b/ts/e2e-tests/runtimes/node/custom-tools/e2e.test.ts
@@ -2,7 +2,8 @@
* Custom local tools E2E test.
*
* Verifies local tool execution, Zod validation, session context, error handling,
- * and mixed local+remote execution against the live Composio API.
+ * mixed local+remote chaining, and edge cases against the live Composio API.
+ * Uses weathermap toolkit (no auth needed).
* Requires COMPOSIO_API_KEY in environment.
*/
@@ -41,15 +42,19 @@ e2e(import.meta.url, {
expect(result.stdout).toContain('ZOD_DEFAULTS_OK');
});
- it('error handling works', () => {
+ it('error thrown by tool is wrapped into { data, error }', () => {
expect(result.stdout).toContain('ERROR_HANDLING_OK');
});
- it('multiple local tools work', () => {
+ it('Zod validation failure returns error, does not crash', () => {
+ expect(result.stdout).toContain('ZOD_VALIDATION_FAIL_OK');
+ });
+
+ it('multiple local tools route to correct execute fn', () => {
expect(result.stdout).toContain('MULTIPLE_TOOLS_OK');
});
- it('session context is injected', () => {
+ it('session context injects userId', () => {
expect(result.stdout).toContain('SESSION_CONTEXT_OK');
});
@@ -57,10 +62,18 @@ e2e(import.meta.url, {
expect(result.stdout).toContain('CASE_INSENSITIVE_OK');
});
- it('prefixed slug works', () => {
+ it('prefixed slug (LOCAL_) works', () => {
expect(result.stdout).toContain('PREFIXED_SLUG_OK');
});
+ it('local tool chains into remote tool via SessionContext.execute()', () => {
+ expect(result.stdout).toContain('CHAINED_EXECUTE_OK');
+ });
+
+ it('non-existent tool returns error gracefully', () => {
+ expect(result.stdout).toContain('NONEXISTENT_TOOL_OK');
+ });
+
it('localTools() method works', () => {
expect(result.stdout).toContain('LOCAL_TOOLS_METHOD_OK');
});
diff --git a/ts/e2e-tests/runtimes/node/custom-tools/fixtures/index.mjs b/ts/e2e-tests/runtimes/node/custom-tools/fixtures/index.mjs
index 7db98f7fe..16dbaf605 100644
--- a/ts/e2e-tests/runtimes/node/custom-tools/fixtures/index.mjs
+++ b/ts/e2e-tests/runtimes/node/custom-tools/fixtures/index.mjs
@@ -1,5 +1,9 @@
/**
* E2E fixture: Custom local tools execution flow.
+ * Tests local execution, remote execution, mixed routing, error handling,
+ * and SessionContext chaining against the live Composio API.
+ *
+ * Uses weathermap toolkit (no auth needed, active connection).
* Requires COMPOSIO_API_KEY in environment.
*/
import { Composio } from '@composio/core';
@@ -51,6 +55,41 @@ const throwingTool = CustomTool({
},
});
+// Tool with strict numeric schema — for Zod validation failure test
+const strictTool = CustomTool({
+ slug: 'STRICT_TOOL',
+ name: 'Strict tool',
+ description: 'Tool with strict numeric input',
+ inputParams: z.object({
+ count: z.number(),
+ }),
+ execute: async (input) => {
+ return { doubled: input.count * 2 };
+ },
+});
+
+// Tool that chains into a remote tool via SessionContext.execute()
+const weatherChain = CustomTool({
+ slug: 'WEATHER_CHAIN',
+ name: 'Weather chain',
+ description: 'Fetches weather via remote tool and enriches with local context',
+ inputParams: z.object({
+ city: z.string(),
+ }),
+ execute: async (input, session) => {
+ // Call remote WEATHERMAP_WEATHER tool through SessionContext
+ const weather = await session.execute('WEATHERMAP_WEATHER', {
+ location: input.city,
+ });
+ return {
+ city: input.city,
+ userId: session.userId,
+ weatherData: weather.data,
+ weatherError: weather.error,
+ };
+ },
+});
+
// ── Create session and run tests ─────────────────────────────
const composio = new Composio({ apiKey });
@@ -59,9 +98,9 @@ async function main() {
const userId = `e2e-custom-tools-${Date.now()}`;
const session = await composio.create(userId, {
- toolkits: ['hackernews'],
+ toolkits: ['weathermap'],
manageConnections: false,
- customTools: [getUserContext, enrichedSearch, throwingTool],
+ customTools: [getUserContext, enrichedSearch, throwingTool, strictTool, weatherChain],
});
// ── Test 1: Single local tool execution ──
@@ -85,16 +124,32 @@ async function main() {
console.log('ZOD_DEFAULTS_OK');
}
- // ── Test 3: Error handling ──
+ // ── Test 3: Error handling — throw wrapped into { data, error } ──
{
const result = await session.execute('THROWING_TOOL', {});
if (!result.error || !result.error.includes('intentional error')) {
throw new Error(`ERROR_HANDLING failed: ${JSON.stringify(result)}`);
}
+ // Verify it didn't crash — we got a structured response
+ if (result.data === undefined) {
+ throw new Error(`ERROR_HANDLING no data field: ${JSON.stringify(result)}`);
+ }
console.log('ERROR_HANDLING_OK');
}
- // ── Test 4: Multiple local tools ──
+ // ── Test 4: Zod validation failure — wrong type wrapped into error ──
+ {
+ const result = await session.execute('STRICT_TOOL', { count: 'not-a-number' });
+ if (!result.error) {
+ throw new Error(`ZOD_VALIDATION_FAIL expected error: ${JSON.stringify(result)}`);
+ }
+ if (!result.error.toLowerCase().includes('validation')) {
+ throw new Error(`ZOD_VALIDATION_FAIL expected validation error: ${result.error}`);
+ }
+ console.log('ZOD_VALIDATION_FAIL_OK');
+ }
+
+ // ── Test 5: Multiple local tools route correctly ──
{
const r1 = await session.execute('GET_USER_CONTEXT', { category: 'a' });
const r2 = await session.execute('ENRICHED_SEARCH', { query: 'test' });
@@ -107,7 +162,7 @@ async function main() {
console.log('MULTIPLE_TOOLS_OK');
}
- // ── Test 5: Session context injection ──
+ // ── Test 6: Session context injection (userId) ──
{
const result = await session.execute('ENRICHED_SEARCH', { query: 'context-test' });
if (!result.data?.userId) {
@@ -119,7 +174,7 @@ async function main() {
console.log('SESSION_CONTEXT_OK');
}
- // ── Test 6: Case-insensitive slug ──
+ // ── Test 7: Case-insensitive slug ──
{
const result = await session.execute('get_user_context', { category: 'case-test' });
if (result.data?.preferences?.category !== 'case-test') {
@@ -128,7 +183,7 @@ async function main() {
console.log('CASE_INSENSITIVE_OK');
}
- // ── Test 7: Prefixed slug (LOCAL_) ──
+ // ── Test 8: Prefixed slug (LOCAL_) ──
{
const result = await session.execute('LOCAL_GET_USER_CONTEXT', { category: 'prefix-test' });
if (result.data?.preferences?.category !== 'prefix-test') {
@@ -137,29 +192,65 @@ async function main() {
console.log('PREFIXED_SLUG_OK');
}
- // ── Test 8: localTools() method ──
- // localTools() returns a wrapped tool — we just verify it doesn't throw
- // and returns something non-empty (can't fully test without LLM)
+ // ── Test 9: SessionContext.execute() chaining — local tool calls remote tool ──
+ // This is mixed local+remote execution: local tool runs in-process,
+ // then calls WEATHERMAP_WEATHER on the backend via session.execute()
+ {
+ const result = await session.execute('WEATHER_CHAIN', { city: 'London' });
+ if (result.error) {
+ throw new Error(`CHAINED_EXECUTE failed: ${result.error}`);
+ }
+ if (result.data?.city !== 'London') {
+ throw new Error(`CHAINED_EXECUTE city mismatch: ${JSON.stringify(result)}`);
+ }
+ if (!result.data?.userId) {
+ throw new Error(`CHAINED_EXECUTE missing userId: ${JSON.stringify(result)}`);
+ }
+ // The chained remote call should have returned weather data
+ if (!result.data?.weatherData) {
+ throw new Error(`CHAINED_EXECUTE missing weatherData: ${JSON.stringify(result)}`);
+ }
+ console.log('CHAINED_EXECUTE_OK');
+ }
+
+ // ── Test 10: Non-existent tool returns error gracefully ──
+ // Remote tools that don't exist throw from the backend (400).
+ // Verify the SDK surfaces this as a catchable error, not a silent failure.
+ {
+ let caught = false;
+ try {
+ await session.execute('COMPLETELY_FAKE_TOOL_12345', {});
+ } catch (err) {
+ caught = true;
+ if (!err.message?.includes('not found') && !err.message?.includes('400')) {
+ throw new Error(`NONEXISTENT_TOOL unexpected error: ${err.message}`);
+ }
+ }
+ if (!caught) {
+ throw new Error('NONEXISTENT_TOOL expected an error but got success');
+ }
+ console.log('NONEXISTENT_TOOL_OK');
+ }
+
+ // ── Test 11: localTools() method ──
{
try {
const localTool = await session.localTools();
- // Verify it returned something (provider-specific format)
if (!localTool) {
throw new Error('localTools() returned falsy value');
}
console.log('LOCAL_TOOLS_METHOD_OK');
} catch (err) {
- // If provider doesn't support it, that's OK for this test
+ // Expected — no provider configured in this fixture
if (err.message?.includes('provider')) {
- console.log('LOCAL_TOOLS_METHOD_OK'); // Expected if no provider
+ console.log('LOCAL_TOOLS_METHOD_OK');
} else {
throw err;
}
}
}
- // ── Test 9: session.tools() wrapping ──
- // Verify session.tools() returns wrapped tools and doesn't crash
+ // ── Test 12: session.tools() wrapping ──
{
try {
const tools = await session.tools();
@@ -168,7 +259,7 @@ async function main() {
}
console.log('TOOLS_WRAPPING_OK');
} catch (err) {
- // If provider doesn't support it, that's OK
+ // Expected — no provider configured, standard path used
if (err.message?.includes('provider')) {
console.log('TOOLS_WRAPPING_OK');
} else {