@devries-cameron20 / composio Mirror · read-only / commits / d1bc94c58
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, 13:30 UTC

test(ts/e2e): exercise core tool execution under Deno (#4418)

This PR: - builds on top of https://github.com/ComposioHQ/composio/pull/3901 - adds a second Deno e2e suite, `@e2e-tests/deno-tool-execution`, that drives the runtime instead of the import surface: session creation over `fetch`, custom-tool registration, Zod validation/defaults/failures, and in-process local tool execution - mirrors the node `custom-tools` suite trimmed to its local-execution half; remote coverage (tool chaining, weathermap) stays node-only - imports the workspace's built dist via a relative path: a version-less `npm:@composio/core` resolves from the registry (published pre-migration 0.18.1), ignoring the pnpm workspace symlink, so the direct path is what makes the suite test the Effect v4 build CI bakes into the image - keeps the only backend call to `composio.create()`; requires `COMPOSIO_API_KEY` (CI provides it, the runner passes it into the container) ## Context The existing `deno/esm-basic` suite stops at the import/export surface and, despite its `deno.jsonc` comment, resolves `npm:@composio/core` from the registry rather than the workspace — so nothing under Deno exercised the Effect v4 runtime. This suite closes that gap. A side observation for a follow-up: `esm-basic` has the same registry-resolution drift and tests the published package, contrary to its README. Validation: - full local Deno matrix passes against the staging backend: 22 tests / 2 suites (11 + 11), fixture markers `SESSION_CREATE_OK` through `ALL_OK` all observed - `pnpm --filter @e2e-tests/deno-tool-execution typecheck` and prettier clean - `pnpm-lock.yaml` updated for the new workspace importer Merge after #3901.

Alberto Schiabel committed Sep 10, 2026 at 18:33 UTC d1bc94c580c86491f930c79828449e5a45313c56
6 files changed +366
pnpm-lock.yaml
+13
@@ -380,6 +380,19 @@ importers:
380 specifier: workspace:*
381 version: link:../../../_utils
382
383 + ts/e2e-tests/runtimes/deno/tool-execution:
384 + dependencies:
385 + '@composio/core':
386 + specifier: workspace:*
387 + version: link:../../../../packages/core
388 + zod:
389 + specifier: 'catalog:'
390 + version: 4.5.4
391 + devDependencies:
392 + '@e2e-tests/utils':
393 + specifier: workspace:*
394 + version: link:../../../_utils
395 +
396 ts/e2e-tests/runtimes/node/cjs-basic:
397 devDependencies:
398 '@composio/core':
ts/e2e-tests/runtimes/deno/tool-execution/README.md new
+60
@@ -0,0 +1,60 @@
1 +# Deno Core Tool Execution Test
2 +
3 +Verifies that `@composio/core`'s runtime — not just its import surface — works in Deno:
4 +session creation over `fetch`, custom-tool registration, Zod input validation, and
5 +in-process local tool execution on the Effect v4 build.
6 +
7 +## Why This Exists
8 +
9 +The `esm-basic` suite proves the package can be imported under Deno. It deliberately stops
10 +there. This suite drives the actual runtime machinery — the code most likely to break on a
11 +non-Node runtime (provider wiring, schema validation, session context injection, tool
12 +routing) — inside the same Deno 2.6.7 image.
13 +
14 +Local tools execute in-process, so the only backend call is `composio.create()`. Remote
15 +coverage (tool chaining, missing-tool errors, weathermap execution) lives in the node
16 +`custom-tools` suite, which this mirrors.
17 +
18 +Requires `COMPOSIO_API_KEY` in the environment. CI provides it and the runner passes it
19 +into the container.
20 +
21 +## What It Tests
22 +
23 +| Test | Description |
24 +| ---------------------- | ------------------------------------------------------- |
25 +| Session create | `composio.create()` succeeds over `fetch` |
26 +| Local execute | Custom tool runs in-process and returns data |
27 +| Zod defaults | `.default()` values applied to omitted input |
28 +| Error handling | Thrown tool errors wrap into `{ data, error }` |
29 +| Zod validation failure | Wrong-typed input surfaces a validation error, no crash |
30 +| Multiple tools | Each slug routes to its own execute fn |
31 +| Session context | `ctx.userId` matches the session's user |
32 +| Case-insensitive slugs | `get_user_context` resolves |
33 +| Prefixed slugs | `LOCAL_GET_USER_CONTEXT` resolves |
34 +
35 +## Fixture
36 +
37 +```
38 +fixtures/
39 +└── test.ts # Deno test script
40 +```
41 +
42 +The fixture imports the workspace's **built dist directly** via a relative path
43 +(`../../../../../packages/core/dist/index.mjs`), so it exercises the local Effect v4 build
44 +baked into the image by the CI Build step — not whatever version `npm:@composio/core`
45 +would resolve to from the registry. A version-less `npm:` specifier ignores the pnpm
46 +workspace symlink and downloads the published package, which is why the direct path is
47 +load-bearing here.
48 +
49 +`zod` comes in via `npm:zod/v3`, matching the node `custom-tools` fixture's schema
50 +surface.
51 +
52 +## Isolation Tool
53 +
54 +**Docker** with Deno version: 2.6.7
55 +
56 +## Running
57 +
58 +```bash
59 +pnpm test:e2e:deno
60 +```
ts/e2e-tests/runtimes/deno/tool-execution/e2e.test.ts new
+84
@@ -0,0 +1,84 @@
1 +/**
2 + * Core tool execution E2E test for Deno.
3 + *
4 + * The `esm-basic` suite proves `@composio/core` imports under Deno;
5 + * this suite proves the runtime works there — session creation over
6 + * fetch, custom-tool registration, Zod validation, and in-process
7 + * local tool execution on the Effect v4 build.
8 + *
9 + * Requires COMPOSIO_API_KEY in the environment (CI provides it; the
10 + * runner passes it into the container).
11 + */
12 +
13 +import { e2e, type E2ETestResult } from '@e2e-tests/utils';
14 +import { TIMEOUTS } from '@e2e-tests/utils/const';
15 +import { describe, it, expect, beforeAll } from 'bun:test';
16 +
17 +declare module 'bun' {
18 + interface Env {
19 + COMPOSIO_API_KEY: string;
20 + }
21 +}
22 +
23 +e2e(import.meta.url, {
24 + versions: {
25 + deno: ['2.6.7'],
26 + },
27 + usesFixtures: true,
28 + env: {
29 + COMPOSIO_API_KEY: Bun.env.COMPOSIO_API_KEY,
30 + },
31 + defineTests: ({ runFixture }) => {
32 + let result: E2ETestResult;
33 +
34 + beforeAll(async () => {
35 + result = await runFixture({ filename: 'test.ts' });
36 + }, TIMEOUTS.FIXTURE);
37 +
38 + describe('Core tool execution (Deno)', () => {
39 + it('exits successfully', () => {
40 + expect(result.exitCode).toBe(0);
41 + });
42 +
43 + it('creates a session over fetch', () => {
44 + expect(result.stdout).toContain('SESSION_CREATE_OK');
45 + });
46 +
47 + it('executes a local custom tool', () => {
48 + expect(result.stdout).toContain('LOCAL_EXECUTE_OK');
49 + });
50 +
51 + it('applies Zod defaults', () => {
52 + expect(result.stdout).toContain('ZOD_DEFAULTS_OK');
53 + });
54 +
55 + it('wraps a thrown tool error into { data, error }', () => {
56 + expect(result.stdout).toContain('ERROR_HANDLING_OK');
57 + });
58 +
59 + it('surfaces Zod validation failures as errors', () => {
60 + expect(result.stdout).toContain('ZOD_VALIDATION_FAIL_OK');
61 + });
62 +
63 + it('routes multiple local tools to the right execute fn', () => {
64 + expect(result.stdout).toContain('MULTIPLE_TOOLS_OK');
65 + });
66 +
67 + it('injects session context (userId)', () => {
68 + expect(result.stdout).toContain('SESSION_CONTEXT_OK');
69 + });
70 +
71 + it('matches slugs case-insensitively', () => {
72 + expect(result.stdout).toContain('CASE_INSENSITIVE_OK');
73 + });
74 +
75 + it('resolves LOCAL_-prefixed slugs', () => {
76 + expect(result.stdout).toContain('PREFIXED_SLUG_OK');
77 + });
78 +
79 + it('completes all tests', () => {
80 + expect(result.stdout).toContain('ALL_OK');
81 + });
82 + });
83 + },
84 +});
ts/e2e-tests/runtimes/deno/tool-execution/fixtures/test.ts new
+179
@@ -0,0 +1,179 @@
1 +/**
2 + * Tool execution E2E fixture for @composio/core in Deno.
3 + *
4 + * Exercises the runtime path, not just the import surface: session
5 + * creation over fetch, custom-tool registration, Zod validation, and
6 + * in-process local tool execution.
7 + *
8 + * The core import is a relative path into the workspace's built dist
9 + * (baked into the e2e image by the CI Build step), so this suite tests
10 + * the local Effect v4 build rather than whatever `npm:@composio/core`
11 + * would resolve to from the registry. Requires COMPOSIO_API_KEY in the
12 + * environment (the e2e runner passes it into the container).
13 + */
14 +
15 +import {
16 + Composio,
17 + experimental_createTool as createCustomTool,
18 +} from '../../../../../packages/core/dist/index.mjs';
19 +import { z } from 'npm:zod/v3';
20 +
21 +const apiKey = Deno.env.get('COMPOSIO_API_KEY');
22 +if (!apiKey) {
23 + console.error('COMPOSIO_API_KEY is required');
24 + Deno.exit(1);
25 +}
26 +
27 +// ── Define custom tools (local execute fns) ──────────────────
28 +
29 +const getUserContext = createCustomTool('GET_USER_CONTEXT', {
30 + name: 'Get user context',
31 + description: 'Retrieve user preferences and history',
32 + inputParams: z.object({
33 + category: z.string().default('all'),
34 + }),
35 + execute: async input => ({ preferences: { category: input.category, source: 'local' } }),
36 +});
37 +
38 +const enrichedSearch = createCustomTool('ENRICHED_SEARCH', {
39 + name: 'Enriched search',
40 + description: 'Search and enrich results with user context',
41 + inputParams: z.object({
42 + query: z.string(),
43 + }),
44 + execute: async (input, ctx) => ({
45 + query: input.query,
46 + userId: ctx.userId,
47 + }),
48 +});
49 +
50 +const throwingTool = createCustomTool('THROWING_TOOL', {
51 + name: 'Throwing tool',
52 + description: 'A tool that always throws an error',
53 + inputParams: z.object({}),
54 + execute: async () => {
55 + throw new Error('intentional error for testing');
56 + },
57 +});
58 +
59 +const strictTool = createCustomTool('STRICT_TOOL', {
60 + name: 'Strict tool',
61 + description: 'Tool with strict numeric input',
62 + inputParams: z.object({
63 + count: z.number(),
64 + }),
65 + execute: async input => ({ doubled: input.count * 2 }),
66 +});
67 +
68 +// ── Create session and run tests ─────────────────────────────
69 +
70 +const composio = new Composio({ apiKey });
71 +
72 +async function main() {
73 + const userId = `e2e-deno-tools-${Date.now()}`;
74 +
75 + const session = await composio.create(userId, {
76 + toolkits: ['weathermap'],
77 + manageConnections: false,
78 + experimental: {
79 + customTools: [getUserContext, enrichedSearch, throwingTool, strictTool],
80 + },
81 + });
82 + if (!session.sessionId) {
83 + throw new Error('SESSION_CREATE failed: missing sessionId');
84 + }
85 + console.log('SESSION_CREATE_OK');
86 +
87 + // ── Test 1: Single local tool execution ──
88 + {
89 + const result = await session.execute('GET_USER_CONTEXT', { category: 'prefs' });
90 + if (result.data?.preferences?.category !== 'prefs') {
91 + throw new Error(`LOCAL_EXECUTE failed: ${JSON.stringify(result)}`);
92 + }
93 + if (result.data?.preferences?.source !== 'local') {
94 + throw new Error(`LOCAL_EXECUTE source mismatch: ${JSON.stringify(result)}`);
95 + }
96 + console.log('LOCAL_EXECUTE_OK');
97 + }
98 +
99 + // ── Test 2: Zod defaults applied ──
100 + {
101 + const result = await session.execute('GET_USER_CONTEXT', {});
102 + if (result.data?.preferences?.category !== 'all') {
103 + throw new Error(`ZOD_DEFAULTS failed: ${JSON.stringify(result)}`);
104 + }
105 + console.log('ZOD_DEFAULTS_OK');
106 + }
107 +
108 + // ── Test 3: Error handling — throw wrapped into { data, error } ──
109 + {
110 + const result = await session.execute('THROWING_TOOL', {});
111 + if (!result.error || !result.error.includes('intentional error')) {
112 + throw new Error(`ERROR_HANDLING failed: ${JSON.stringify(result)}`);
113 + }
114 + if (result.data === undefined) {
115 + throw new Error(`ERROR_HANDLING no data field: ${JSON.stringify(result)}`);
116 + }
117 + console.log('ERROR_HANDLING_OK');
118 + }
119 +
120 + // ── Test 4: Zod validation failure — wrong type wrapped into error ──
121 + {
122 + const result = await session.execute('STRICT_TOOL', { count: 'not-a-number' });
123 + if (!result.error) {
124 + throw new Error(`ZOD_VALIDATION_FAIL expected error: ${JSON.stringify(result)}`);
125 + }
126 + if (!result.error.toLowerCase().includes('validation')) {
127 + throw new Error(`ZOD_VALIDATION_FAIL expected validation error: ${result.error}`);
128 + }
129 + console.log('ZOD_VALIDATION_FAIL_OK');
130 + }
131 +
132 + // ── Test 5: Multiple local tools route correctly ──
133 + {
134 + const r1 = await session.execute('GET_USER_CONTEXT', { category: 'a' });
135 + const r2 = await session.execute('ENRICHED_SEARCH', { query: 'test' });
136 + if (r1.data?.preferences?.category !== 'a') {
137 + throw new Error(`MULTIPLE_TOOLS r1 failed: ${JSON.stringify(r1)}`);
138 + }
139 + if (r2.data?.query !== 'test') {
140 + throw new Error(`MULTIPLE_TOOLS r2 failed: ${JSON.stringify(r2)}`);
141 + }
142 + console.log('MULTIPLE_TOOLS_OK');
143 + }
144 +
145 + // ── Test 6: Session context injection (userId) ──
146 + {
147 + const result = await session.execute('ENRICHED_SEARCH', { query: 'context-test' });
148 + if (result.data?.userId !== userId) {
149 + throw new Error(`SESSION_CONTEXT userId mismatch: expected ${userId}, got ${JSON.stringify(result)}`);
150 + }
151 + console.log('SESSION_CONTEXT_OK');
152 + }
153 +
154 + // ── Test 7: Case-insensitive slug ──
155 + {
156 + const result = await session.execute('get_user_context', { category: 'case-test' });
157 + if (result.data?.preferences?.category !== 'case-test') {
158 + throw new Error(`CASE_INSENSITIVE failed: ${JSON.stringify(result)}`);
159 + }
160 + console.log('CASE_INSENSITIVE_OK');
161 + }
162 +
163 + // ── Test 8: Prefixed slug (LOCAL_) ──
164 + {
165 + const result = await session.execute('LOCAL_GET_USER_CONTEXT', { category: 'prefix-test' });
166 + if (result.data?.preferences?.category !== 'prefix-test') {
167 + throw new Error(`PREFIXED_SLUG failed: ${JSON.stringify(result)}`);
168 + }
169 + console.log('PREFIXED_SLUG_OK');
170 + }
171 +
172 + console.log('ALL_OK');
173 +}
174 +
175 +main().catch((err: unknown) => {
176 + const message = err instanceof Error ? err.message : String(err);
177 + console.log('ERROR:', message);
178 + Deno.exit(1);
179 +});
ts/e2e-tests/runtimes/deno/tool-execution/package.json new
+18
@@ -0,0 +1,18 @@
1 +{
2 + "name": "@e2e-tests/deno-tool-execution",
3 + "version": "0.0.0",
4 + "private": true,
5 + "type": "module",
6 + "scripts": {
7 + "typecheck": "tsc --noEmit",
8 + "test:e2e": "bun test e2e.test.ts",
9 + "test:e2e:deno": "bun test e2e.test.ts"
10 + },
11 + "dependencies": {
12 + "@composio/core": "workspace:*",
13 + "zod": "catalog:"
14 + },
15 + "devDependencies": {
16 + "@e2e-tests/utils": "workspace:*"
17 + }
18 +}
ts/e2e-tests/runtimes/deno/tool-execution/tsconfig.json new
+12
@@ -0,0 +1,12 @@
1 +{
2 + "$schema": "https://json.schemastore.org/tsconfig",
3 + "compilerOptions": {
4 + "target": "es2022",
5 + "module": "esnext",
6 + "moduleResolution": "bundler",
7 + "strict": true,
8 + "skipLibCheck": true,
9 + "noEmit": true
10 + },
11 + "include": ["e2e.test.ts"]
12 +}