@devries-cameron20 / composio-1 / commits / 2be35afb3
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.

test(ts/e2e): add cloudflare/cf-workers-files test suite

jkomyno committed Jan 22, 2026 at 21:11 UTC 2be35afb36b3099ec409dd3c44890f8de6f7ecb6
9 files changed +523 -1
pnpm-lock.yaml
+29 -1
@@ -298,6 +298,34 @@ importers:
298 specifier: 'catalog:'
299 version: 4.37.1(@cloudflare/workers-types@4.20250917.0)
300
301 + ts/e2e-tests/runtimes/cloudflare/cf-workers-files:
302 + dependencies:
303 + '@composio/core':
304 + specifier: workspace:*
305 + version: link:../../../../packages/core
306 + hono:
307 + specifier: 'catalog:'
308 + version: 4.11.4
309 + devDependencies:
310 + '@cloudflare/vitest-pool-workers':
311 + specifier: 'catalog:'
312 + version: 0.9.2(@cloudflare/workers-types@4.20250917.0)(@vitest/runner@3.2.4)(@vitest/snapshot@3.2.4)(vitest@3.2.4)
313 + '@cloudflare/workers-types':
314 + specifier: 'catalog:'
315 + version: 4.20250917.0
316 + dotenv:
317 + specifier: ^16.4.5
318 + version: 16.6.1
319 + typescript:
320 + specifier: 'catalog:'
321 + version: 5.9.3
322 + vitest:
323 + specifier: 'catalog:'
324 + version: 3.2.4(@types/debug@4.1.12)(@types/node@24.10.4)(@vitest/ui@3.2.4)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.20.5)(yaml@2.8.1)
325 + wrangler:
326 + specifier: 'catalog:'
327 + version: 4.37.1(@cloudflare/workers-types@4.20250917.0)
328 +
329 ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai:
330 dependencies:
331 '@ai-sdk/mcp':
@@ -11569,7 +11597,7 @@ snapshots:
11597 sirv: 3.0.1
11598 tinyglobby: 0.2.15
11599 tinyrainbow: 2.0.0
11572 - vitest: 3.2.4(@types/debug@4.1.12)(@types/node@20.19.1)(@vitest/ui@3.2.4)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.20.5)(yaml@2.8.0)
11600 + vitest: 3.2.4(@types/debug@4.1.12)(@types/node@22.15.32)(@vitest/ui@3.2.4)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.20.5)(yaml@2.8.1)
11601
11602 '@vitest/utils@3.2.4':
11603 dependencies:
ts/e2e-tests/runtimes/cloudflare/cf-workers-files/.env.example new
+1
@@ -0,0 +1 @@
1 +COMPOSIO_API_KEY=your-key
ts/e2e-tests/runtimes/cloudflare/cf-workers-files/README.md new
+78
@@ -0,0 +1,78 @@
1 +# Composio Core Files - Cloudflare Workers E2E Test
2 +
3 +This package tests `@composio/core` file operations in Cloudflare Workers environment.
4 +
5 +## Purpose
6 +
7 +Verifies that:
8 +1. `composio.files.upload()` throws the expected "not supported in Cloudflare Workers" error
9 +2. `composio.files.download()` throws the expected "not supported in Cloudflare Workers" error
10 +3. The `FileToolModifier.workerd.ts` is correctly loaded and provides the expected error message when `autoUploadDownloadFiles` is explicitly enabled
11 +4. Composio initializes correctly with the default configuration (`autoUploadDownloadFiles: false` in workerd runtime)
12 +5. Composio can be explicitly initialized with `autoUploadDownloadFiles: false`
13 +
14 +## Endpoints
15 +
16 +| Endpoint | Description |
17 +|----------|-------------|
18 +| `GET /` | Lists all available test endpoints |
19 +| `GET /test/files/upload` | Tests that `files.upload()` throws the expected error |
20 +| `GET /test/files/download` | Tests that `files.download()` throws the expected error |
21 +| `GET /test/file-modifier/error-message` | Tests the error when `autoUploadDownloadFiles: true` is explicitly set |
22 +| `GET /test/auto-upload-disabled` | Tests Composio initialization with explicit `autoUploadDownloadFiles: false` |
23 +| `GET /test/default-config` | Tests Composio initialization with default configuration (no explicit setting) |
24 +
25 +## Running Tests
26 +
27 +```bash
28 +# From the package directory
29 +pnpm test:e2e
30 +
31 +# Or from the monorepo root
32 +pnpm --filter @test-e2e/cf-workers-files test:e2e:cloudflare
33 +```
34 +
35 +## Environment Variables
36 +
37 +Copy `.env.example` to `.env` and set your API key:
38 +
39 +```bash
40 +COMPOSIO_API_KEY=your-composio-api-key
41 +```
42 +
43 +Note: For file operation tests, a dummy API key works since the operations throw errors before making API calls.
44 +
45 +## Default Configuration
46 +
47 +**In Cloudflare Workers (workerd runtime), `autoUploadDownloadFiles` defaults to `false`.**
48 +
49 +This means you can initialize Composio without any special configuration:
50 +
51 +```typescript
52 +const composio = new Composio({
53 + apiKey: 'your-key',
54 +});
55 +// autoUploadDownloadFiles is false by default in workerd
56 +```
57 +
58 +## FileToolModifier Error
59 +
60 +If you explicitly set `autoUploadDownloadFiles: true` and execute a tool with file properties in Cloudflare Workers, the following error is thrown:
61 +
62 +```
63 +File upload/download modifiers are not available on edge runtimes yet.
64 +Please set `autoUploadDownloadFiles: false` or run Composio in another JS runtime (Node.js / Bun).
65 +```
66 +
67 +### Best Practice
68 +
69 +For edge runtimes, use the default configuration or explicitly set `autoUploadDownloadFiles: false`:
70 +
71 +```typescript
72 +const composio = new Composio({
73 + apiKey: 'your-key',
74 + autoUploadDownloadFiles: false, // This is the default for workerd
75 +});
76 +```
77 +
78 +Note that with this configuration, file upload/download operations will not be automatically handled.
ts/e2e-tests/runtimes/cloudflare/cf-workers-files/package.json new
+24
@@ -0,0 +1,24 @@
1 +{
2 + "name": "@test-e2e/cf-workers-files",
3 + "version": "0.0.0",
4 + "private": true,
5 + "type": "module",
6 + "scripts": {
7 + "test:e2e": "vitest run",
8 + "test:e2e:cloudflare": "vitest run",
9 + "dev": "wrangler dev",
10 + "cf-typegen": "wrangler types"
11 + },
12 + "devDependencies": {
13 + "@cloudflare/vitest-pool-workers": "catalog:",
14 + "@cloudflare/workers-types": "catalog:",
15 + "dotenv": "^16.4.5",
16 + "typescript": "catalog:",
17 + "vitest": "catalog:",
18 + "wrangler": "catalog:"
19 + },
20 + "dependencies": {
21 + "@composio/core": "workspace:*",
22 + "hono": "catalog:"
23 + }
24 +}
ts/e2e-tests/runtimes/cloudflare/cf-workers-files/src/index.ts new
+222
@@ -0,0 +1,222 @@
1 +/**
2 + * E2E test worker for @composio/core file operations in Cloudflare Workers.
3 + * Tests that file operations correctly throw errors in edge runtimes
4 + * and that the FileToolModifier.workerd.ts is properly loaded.
5 + */
6 +import { Composio } from '@composio/core';
7 +import { z } from 'zod/v3';
8 +import { Hono } from 'hono';
9 +
10 +type Bindings = {
11 + COMPOSIO_API_KEY: string;
12 +};
13 +
14 +const app = new Hono<{ Bindings: Bindings }>();
15 +
16 +/**
17 + * Default route - lists available test endpoints
18 + */
19 +app.get('/', c => {
20 + return c.json({
21 + message: 'Composio Core Files E2E Test Worker',
22 + endpoints: [
23 + '/test/files/upload',
24 + '/test/files/download',
25 + '/test/file-modifier/error-message',
26 + '/test/auto-upload-disabled',
27 + '/test/default-config',
28 + ],
29 + });
30 +});
31 +
32 +/**
33 + * Test: Files upload operation (should fail in Cloudflare Workers)
34 + * Tests that composio.files.upload() throws an appropriate error in edge runtimes
35 + */
36 +app.get('/test/files/upload', async c => {
37 + try {
38 + const composio = new Composio({
39 + apiKey: c.env.COMPOSIO_API_KEY,
40 + });
41 +
42 + // Attempt to call files.upload - should throw an error
43 + await composio.files.upload({
44 + file: 'https://example.com/test.pdf',
45 + toolSlug: 'test-tool',
46 + toolkitSlug: 'test-toolkit',
47 + });
48 +
49 + // If we get here, the test failed - upload should have thrown
50 + return c.json(
51 + {
52 + error: 'Expected files.upload() to throw an error in Cloudflare Workers, but it did not',
53 + },
54 + { status: 500 }
55 + );
56 + } catch (error) {
57 + const errorMessage = error instanceof Error ? error.message : String(error);
58 + return c.json({
59 + error: errorMessage,
60 + });
61 + }
62 +});
63 +
64 +/**
65 + * Test: Files download operation (should fail in Cloudflare Workers)
66 + * Tests that composio.files.download() throws an appropriate error in edge runtimes
67 + */
68 +app.get('/test/files/download', async c => {
69 + try {
70 + const composio = new Composio({
71 + apiKey: c.env.COMPOSIO_API_KEY,
72 + });
73 +
74 + // Attempt to call files.download - should throw an error
75 + await composio.files.download({
76 + s3Url: 'https://s3.example.com/test.pdf',
77 + toolSlug: 'test-tool',
78 + mimeType: 'application/pdf',
79 + });
80 +
81 + // If we get here, the test failed - download should have thrown
82 + return c.json(
83 + {
84 + error: 'Expected files.download() to throw an error in Cloudflare Workers, but it did not',
85 + },
86 + { status: 500 }
87 + );
88 + } catch (error) {
89 + const errorMessage = error instanceof Error ? error.message : String(error);
90 + return c.json({
91 + error: errorMessage,
92 + });
93 + }
94 +});
95 +
96 +/**
97 + * Test: FileToolModifier behavior (triggers the autoUploadDownloadFiles error)
98 + *
99 + * The FileToolModifier.workerd.ts throws an error when autoUploadDownloadFiles is enabled.
100 + * In workerd runtime, the default is false, so we explicitly enable it here to test the error.
101 + *
102 + * This endpoint actually executes a tool to trigger the real error from FileToolModifier.workerd.ts.
103 + */
104 +app.get('/test/file-modifier/error-message', async c => {
105 + try {
106 + const composio = new Composio({
107 + apiKey: c.env.COMPOSIO_API_KEY,
108 + autoUploadDownloadFiles: true,
109 + });
110 +
111 + // Use a local custom tool to avoid depending on remote Composio tool registry.
112 + // Any execute() call with autoUploadDownloadFiles enabled will trigger FileToolModifier
113 + // in the workerd runtime.
114 + await composio.tools.createCustomTool({
115 + slug: 'CUSTOM_FILE_TOOL',
116 + name: 'Custom File Tool',
117 + inputParams: z.object({
118 + file: z.string(),
119 + }),
120 + execute: async () => ({
121 + data: {},
122 + error: null,
123 + successful: true,
124 + logId: undefined,
125 + sessionInfo: undefined,
126 + }),
127 + });
128 +
129 + await composio.tools.execute('CUSTOM_FILE_TOOL', {
130 + arguments: {
131 + file: 'https://example.com/test.pdf',
132 + },
133 + dangerouslySkipVersionCheck: true,
134 + });
135 +
136 + // If we get here, the test failed - execution should have thrown
137 + return c.json(
138 + {
139 + error: 'Expected tool execution to throw FileToolModifier error, but it did not',
140 + },
141 + { status: 500 }
142 + );
143 + } catch (error) {
144 + const errorMessage = error instanceof Error ? error.message : String(error);
145 + return c.json({
146 + error: errorMessage,
147 + });
148 + }
149 +});
150 +
151 +/**
152 + * Test: Composio initialization with autoUploadDownloadFiles disabled
153 + *
154 + * In workerd runtime (Cloudflare Workers), autoUploadDownloadFiles defaults to false.
155 + * This test verifies that the default configuration works correctly and that
156 + * Composio can be initialized successfully without file upload/download support.
157 + */
158 +app.get('/test/auto-upload-disabled', async c => {
159 + try {
160 + // Explicitly set autoUploadDownloadFiles: false (which is the default for workerd)
161 + // This is the recommended configuration for edge runtimes
162 + const composio = new Composio({
163 + apiKey: c.env.COMPOSIO_API_KEY,
164 + autoUploadDownloadFiles: false,
165 + });
166 +
167 + return c.json({
168 + success: true,
169 + message: 'Composio initialized successfully with autoUploadDownloadFiles: false',
170 + hasProvider: typeof composio.provider !== 'undefined',
171 + hasTools: typeof composio.tools !== 'undefined',
172 + hasFiles: typeof composio.files !== 'undefined',
173 + recommendation:
174 + 'Use this configuration in edge runtimes to avoid FileToolModifier errors. ' +
175 + 'Note that file upload/download operations will not be automatically handled.',
176 + });
177 + } catch (error) {
178 + return c.json(
179 + {
180 + success: false,
181 + error: error instanceof Error ? error.message : String(error),
182 + },
183 + { status: 500 }
184 + );
185 + }
186 +});
187 +
188 +/**
189 + * Test: Composio initialization with default configuration
190 + *
191 + * This test verifies that Composio initializes correctly with the default
192 + * configuration for workerd runtime (autoUploadDownloadFiles: false by default).
193 + * No explicit configuration is provided, relying on the runtime defaults.
194 + */
195 +app.get('/test/default-config', async c => {
196 + try {
197 + // Initialize Composio without explicitly setting autoUploadDownloadFiles
198 + // Should use the workerd default (false)
199 + const composio = new Composio({
200 + apiKey: c.env.COMPOSIO_API_KEY,
201 + });
202 +
203 + return c.json({
204 + success: true,
205 + message: 'Composio initialized successfully with default configuration',
206 + hasProvider: typeof composio.provider !== 'undefined',
207 + hasTools: typeof composio.tools !== 'undefined',
208 + hasFiles: typeof composio.files !== 'undefined',
209 + note: 'In workerd runtime, autoUploadDownloadFiles defaults to false',
210 + });
211 + } catch (error) {
212 + return c.json(
213 + {
214 + success: false,
215 + error: error instanceof Error ? error.message : String(error),
216 + },
217 + { status: 500 }
218 + );
219 + }
220 +});
221 +
222 +export default app;
ts/e2e-tests/runtimes/cloudflare/cf-workers-files/test/files.spec.ts new
+126
@@ -0,0 +1,126 @@
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 +describe('@composio/core Files - Cloudflare Workers compatibility', () => {
8 + it('should list the available endpoints', async () => {
9 + const request = new IncomingRequest('http://localhost/');
10 + const ctx = createExecutionContext();
11 + const response = await app.fetch(request, env, ctx);
12 + await waitOnExecutionContext(ctx);
13 +
14 + expect(response.status).toBe(200);
15 +
16 + const body = (await response.json()) as {
17 + message: string;
18 + endpoints: string[];
19 + };
20 +
21 + expect(body.message).toContain('Composio Core Files E2E Test Worker');
22 + expect(body.endpoints).toMatchInlineSnapshot(`
23 + [
24 + "/test/files/upload",
25 + "/test/files/download",
26 + "/test/file-modifier/error-message",
27 + "/test/auto-upload-disabled",
28 + "/test/default-config",
29 + ]
30 + `);
31 + });
32 +
33 + it('should throw an error when calling files.upload() in Cloudflare Workers', async () => {
34 + const request = new IncomingRequest('http://localhost/test/files/upload');
35 + const ctx = createExecutionContext();
36 + const response = await app.fetch(request, env, ctx);
37 + await waitOnExecutionContext(ctx);
38 +
39 + expect(response.status).toBe(200);
40 +
41 + const body = (await response.json()) as {
42 + error?: string;
43 + };
44 +
45 + expect(body.error).toContain('not supported in Cloudflare Workers');
46 + });
47 +
48 + it('should throw an error when calling files.download() in Cloudflare Workers', async () => {
49 + const request = new IncomingRequest('http://localhost/test/files/download');
50 + const ctx = createExecutionContext();
51 + const response = await app.fetch(request, env, ctx);
52 + await waitOnExecutionContext(ctx);
53 +
54 + expect(response.status).toBe(200);
55 +
56 + const body = (await response.json()) as {
57 + error?: string;
58 + };
59 +
60 + expect(body.error).toContain('not supported in Cloudflare Workers');
61 + });
62 +
63 + it('should throw FileToolModifier error when executing a tool in Cloudflare Workers', async () => {
64 + const request = new IncomingRequest('http://localhost/test/file-modifier/error-message');
65 + const ctx = createExecutionContext();
66 + const response = await app.fetch(request, env, ctx);
67 + await waitOnExecutionContext(ctx);
68 +
69 + expect(response.status).toBe(200);
70 +
71 + const body = (await response.json()) as {
72 + error?: string;
73 + };
74 +
75 + expect(body.error).toContain('not available on edge runtimes');
76 + });
77 +
78 + it('should successfully initialize Composio with autoUploadDownloadFiles disabled', async () => {
79 + const request = new IncomingRequest('http://localhost/test/auto-upload-disabled');
80 + const ctx = createExecutionContext();
81 + const response = await app.fetch(request, env, ctx);
82 + await waitOnExecutionContext(ctx);
83 +
84 + expect(response.status).toBe(200);
85 +
86 + const body = (await response.json()) as {
87 + success: boolean;
88 + message?: string;
89 + hasProvider?: boolean;
90 + hasTools?: boolean;
91 + hasFiles?: boolean;
92 + recommendation?: string;
93 + };
94 +
95 + expect(body.success).toBe(true);
96 + expect(body.message).toContain('autoUploadDownloadFiles: false');
97 + expect(body.hasProvider).toBe(true);
98 + expect(body.hasTools).toBe(true);
99 + expect(body.hasFiles).toBe(true);
100 + });
101 +
102 + it('should successfully initialize Composio with default configuration', async () => {
103 + const request = new IncomingRequest('http://localhost/test/default-config');
104 + const ctx = createExecutionContext();
105 + const response = await app.fetch(request, env, ctx);
106 + await waitOnExecutionContext(ctx);
107 +
108 + expect(response.status).toBe(200);
109 +
110 + const body = (await response.json()) as {
111 + success: boolean;
112 + message?: string;
113 + hasProvider?: boolean;
114 + hasTools?: boolean;
115 + hasFiles?: boolean;
116 + note?: string;
117 + };
118 +
119 + expect(body.success).toBe(true);
120 + expect(body.message).toContain('default configuration');
121 + expect(body.hasProvider).toBe(true);
122 + expect(body.hasTools).toBe(true);
123 + expect(body.hasFiles).toBe(true);
124 + expect(body.note).toContain('autoUploadDownloadFiles defaults to false');
125 + });
126 +});
ts/e2e-tests/runtimes/cloudflare/cf-workers-files/tsconfig.json new
+18
@@ -0,0 +1,18 @@
1 +{
2 + "compilerOptions": {
3 + "target": "es2022",
4 + "lib": ["es2022"],
5 + "module": "es2022",
6 + "moduleResolution": "Bundler",
7 + "resolveJsonModule": true,
8 + "allowJs": true,
9 + "noEmit": true,
10 + "isolatedModules": true,
11 + "allowSyntheticDefaultImports": true,
12 + "forceConsistentCasingInFileNames": true,
13 + "strict": true,
14 + "skipLibCheck": true,
15 + "types": ["@cloudflare/workers-types"]
16 + },
17 + "include": ["src/**/*.ts", "test/**/*.ts"]
18 +}
ts/e2e-tests/runtimes/cloudflare/cf-workers-files/vitest.config.mts new
+19
@@ -0,0 +1,19 @@
1 +import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
2 +import { config } from 'dotenv';
3 +
4 +config();
5 +
6 +export default defineWorkersConfig({
7 + test: {
8 + poolOptions: {
9 + workers: {
10 + wrangler: { configPath: './wrangler.jsonc' },
11 + miniflare: {
12 + bindings: {
13 + COMPOSIO_API_KEY: process.env.COMPOSIO_API_KEY ?? 'test-key',
14 + },
15 + },
16 + },
17 + },
18 + },
19 +});
ts/e2e-tests/runtimes/cloudflare/cf-workers-files/wrangler.jsonc new
+6
@@ -0,0 +1,6 @@
1 +{
2 + "$schema": "node_modules/wrangler/config-schema.json",
3 + "name": "composio-core-files-test",
4 + "main": "src/index.ts",
5 + "compatibility_date": "2025-01-10"
6 +}