Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
test(ts/e2e): add cloudflare/cf-workers-files test suite
jkomyno2be35afb36b3
diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex f2bf69d31..6b529e7d1 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -298,6 +298,34 @@ importers:specifier: 'catalog:'version: 4.37.1(@cloudflare/[email protected])+ ts/e2e-tests/runtimes/cloudflare/cf-workers-files:+ dependencies:+ '@composio/core':+ specifier: workspace:*+ version: link:../../../../packages/core+ hono:+ specifier: 'catalog:'+ version: 4.11.4+ devDependencies:+ '@cloudflare/vitest-pool-workers':+ specifier: 'catalog:'+ version: 0.9.2(@cloudflare/[email protected])(@vitest/[email protected])(@vitest/[email protected])([email protected])+ '@cloudflare/workers-types':+ specifier: 'catalog:'+ version: 4.20250917.0+ dotenv:+ specifier: ^16.4.5+ version: 16.6.1+ typescript:+ specifier: 'catalog:'+ version: 5.9.3+ vitest:+ specifier: 'catalog:'+ version: 3.2.4(@types/[email protected])(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected])+ wrangler:+ specifier: 'catalog:'+ version: 4.37.1(@cloudflare/[email protected])+ts/e2e-tests/runtimes/cloudflare/cf-workers-tool-router-ai:dependencies:'@ai-sdk/mcp':@@ -11569,7 +11597,7 @@ snapshots:sirv: 3.0.1tinyglobby: 0.2.15tinyrainbow: 2.0.0- vitest: 3.2.4(@types/[email protected])(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected])+ vitest: 3.2.4(@types/[email protected])(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected])'@vitest/[email protected]':dependencies:diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/.env.example b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/.env.examplenew file mode 100644index 000000000..68512b6dd--- /dev/null+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/.env.example@@ -0,0 +1 @@+COMPOSIO_API_KEY=your-keydiff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/README.md b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/README.mdnew file mode 100644index 000000000..aaa1c150a--- /dev/null+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/README.md@@ -0,0 +1,78 @@+# Composio Core Files - Cloudflare Workers E2E Test++This package tests `@composio/core` file operations in Cloudflare Workers environment.++## Purpose++Verifies that:+1. `composio.files.upload()` throws the expected "not supported in Cloudflare Workers" error+2. `composio.files.download()` throws the expected "not supported in Cloudflare Workers" error+3. The `FileToolModifier.workerd.ts` is correctly loaded and provides the expected error message when `autoUploadDownloadFiles` is explicitly enabled+4. Composio initializes correctly with the default configuration (`autoUploadDownloadFiles: false` in workerd runtime)+5. Composio can be explicitly initialized with `autoUploadDownloadFiles: false`++## Endpoints++| Endpoint | Description |+|----------|-------------|+| `GET /` | Lists all available test endpoints |+| `GET /test/files/upload` | Tests that `files.upload()` throws the expected error |+| `GET /test/files/download` | Tests that `files.download()` throws the expected error |+| `GET /test/file-modifier/error-message` | Tests the error when `autoUploadDownloadFiles: true` is explicitly set |+| `GET /test/auto-upload-disabled` | Tests Composio initialization with explicit `autoUploadDownloadFiles: false` |+| `GET /test/default-config` | Tests Composio initialization with default configuration (no explicit setting) |++## Running Tests++```bash+# From the package directory+pnpm test:e2e++# Or from the monorepo root+pnpm --filter @test-e2e/cf-workers-files test:e2e:cloudflare+```++## Environment Variables++Copy `.env.example` to `.env` and set your API key:++```bash+COMPOSIO_API_KEY=your-composio-api-key+```++Note: For file operation tests, a dummy API key works since the operations throw errors before making API calls.++## Default Configuration++**In Cloudflare Workers (workerd runtime), `autoUploadDownloadFiles` defaults to `false`.**++This means you can initialize Composio without any special configuration:++```typescript+const composio = new Composio({+ apiKey: 'your-key',+});+// autoUploadDownloadFiles is false by default in workerd+```++## FileToolModifier Error++If you explicitly set `autoUploadDownloadFiles: true` and execute a tool with file properties in Cloudflare Workers, the following error is thrown:++```+File upload/download modifiers are not available on edge runtimes yet.+Please set `autoUploadDownloadFiles: false` or run Composio in another JS runtime (Node.js / Bun).+```++### Best Practice++For edge runtimes, use the default configuration or explicitly set `autoUploadDownloadFiles: false`:++```typescript+const composio = new Composio({+ apiKey: 'your-key',+ autoUploadDownloadFiles: false, // This is the default for workerd+});+```++Note that with this configuration, file upload/download operations will not be automatically handled.diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/package.json b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/package.jsonnew file mode 100644index 000000000..7a4837dce--- /dev/null+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/package.json@@ -0,0 +1,24 @@+{+ "name": "@test-e2e/cf-workers-files",+ "version": "0.0.0",+ "private": true,+ "type": "module",+ "scripts": {+ "test:e2e": "vitest run",+ "test:e2e:cloudflare": "vitest run",+ "dev": "wrangler dev",+ "cf-typegen": "wrangler types"+ },+ "devDependencies": {+ "@cloudflare/vitest-pool-workers": "catalog:",+ "@cloudflare/workers-types": "catalog:",+ "dotenv": "^16.4.5",+ "typescript": "catalog:",+ "vitest": "catalog:",+ "wrangler": "catalog:"+ },+ "dependencies": {+ "@composio/core": "workspace:*",+ "hono": "catalog:"+ }+}diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/src/index.ts b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/src/index.tsnew file mode 100644index 000000000..8b8c9cf38--- /dev/null+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/src/index.ts@@ -0,0 +1,222 @@+/**+ * E2E test worker for @composio/core file operations in Cloudflare Workers.+ * Tests that file operations correctly throw errors in edge runtimes+ * and that the FileToolModifier.workerd.ts is properly loaded.+ */+import { Composio } from '@composio/core';+import { z } from 'zod/v3';+import { Hono } from 'hono';++type Bindings = {+ COMPOSIO_API_KEY: string;+};++const app = new Hono<{ Bindings: Bindings }>();++/**+ * Default route - lists available test endpoints+ */+app.get('/', c => {+ return c.json({+ message: 'Composio Core Files E2E Test Worker',+ endpoints: [+ '/test/files/upload',+ '/test/files/download',+ '/test/file-modifier/error-message',+ '/test/auto-upload-disabled',+ '/test/default-config',+ ],+ });+});++/**+ * Test: Files upload operation (should fail in Cloudflare Workers)+ * Tests that composio.files.upload() throws an appropriate error in edge runtimes+ */+app.get('/test/files/upload', async c => {+ try {+ const composio = new Composio({+ apiKey: c.env.COMPOSIO_API_KEY,+ });++ // Attempt to call files.upload - should throw an error+ await composio.files.upload({+ file: 'https://example.com/test.pdf',+ toolSlug: 'test-tool',+ toolkitSlug: 'test-toolkit',+ });++ // If we get here, the test failed - upload should have thrown+ return c.json(+ {+ error: 'Expected files.upload() to throw an error in Cloudflare Workers, but it did not',+ },+ { status: 500 }+ );+ } catch (error) {+ const errorMessage = error instanceof Error ? error.message : String(error);+ return c.json({+ error: errorMessage,+ });+ }+});++/**+ * Test: Files download operation (should fail in Cloudflare Workers)+ * Tests that composio.files.download() throws an appropriate error in edge runtimes+ */+app.get('/test/files/download', async c => {+ try {+ const composio = new Composio({+ apiKey: c.env.COMPOSIO_API_KEY,+ });++ // Attempt to call files.download - should throw an error+ await composio.files.download({+ s3Url: 'https://s3.example.com/test.pdf',+ toolSlug: 'test-tool',+ mimeType: 'application/pdf',+ });++ // If we get here, the test failed - download should have thrown+ return c.json(+ {+ error: 'Expected files.download() to throw an error in Cloudflare Workers, but it did not',+ },+ { status: 500 }+ );+ } catch (error) {+ const errorMessage = error instanceof Error ? error.message : String(error);+ return c.json({+ error: errorMessage,+ });+ }+});++/**+ * Test: FileToolModifier behavior (triggers the autoUploadDownloadFiles error)+ *+ * The FileToolModifier.workerd.ts throws an error when autoUploadDownloadFiles is enabled.+ * In workerd runtime, the default is false, so we explicitly enable it here to test the error.+ *+ * This endpoint actually executes a tool to trigger the real error from FileToolModifier.workerd.ts.+ */+app.get('/test/file-modifier/error-message', async c => {+ try {+ const composio = new Composio({+ apiKey: c.env.COMPOSIO_API_KEY,+ autoUploadDownloadFiles: true,+ });++ // Use a local custom tool to avoid depending on remote Composio tool registry.+ // Any execute() call with autoUploadDownloadFiles enabled will trigger FileToolModifier+ // in the workerd runtime.+ await composio.tools.createCustomTool({+ slug: 'CUSTOM_FILE_TOOL',+ name: 'Custom File Tool',+ inputParams: z.object({+ file: z.string(),+ }),+ execute: async () => ({+ data: {},+ error: null,+ successful: true,+ logId: undefined,+ sessionInfo: undefined,+ }),+ });++ await composio.tools.execute('CUSTOM_FILE_TOOL', {+ arguments: {+ file: 'https://example.com/test.pdf',+ },+ dangerouslySkipVersionCheck: true,+ });++ // If we get here, the test failed - execution should have thrown+ return c.json(+ {+ error: 'Expected tool execution to throw FileToolModifier error, but it did not',+ },+ { status: 500 }+ );+ } catch (error) {+ const errorMessage = error instanceof Error ? error.message : String(error);+ return c.json({+ error: errorMessage,+ });+ }+});++/**+ * Test: Composio initialization with autoUploadDownloadFiles disabled+ *+ * In workerd runtime (Cloudflare Workers), autoUploadDownloadFiles defaults to false.+ * This test verifies that the default configuration works correctly and that+ * Composio can be initialized successfully without file upload/download support.+ */+app.get('/test/auto-upload-disabled', async c => {+ try {+ // Explicitly set autoUploadDownloadFiles: false (which is the default for workerd)+ // This is the recommended configuration for edge runtimes+ const composio = new Composio({+ apiKey: c.env.COMPOSIO_API_KEY,+ autoUploadDownloadFiles: false,+ });++ return c.json({+ success: true,+ message: 'Composio initialized successfully with autoUploadDownloadFiles: false',+ hasProvider: typeof composio.provider !== 'undefined',+ hasTools: typeof composio.tools !== 'undefined',+ hasFiles: typeof composio.files !== 'undefined',+ recommendation:+ 'Use this configuration in edge runtimes to avoid FileToolModifier errors. ' ++ 'Note that file upload/download operations will not be automatically handled.',+ });+ } catch (error) {+ return c.json(+ {+ success: false,+ error: error instanceof Error ? error.message : String(error),+ },+ { status: 500 }+ );+ }+});++/**+ * Test: Composio initialization with default configuration+ *+ * This test verifies that Composio initializes correctly with the default+ * configuration for workerd runtime (autoUploadDownloadFiles: false by default).+ * No explicit configuration is provided, relying on the runtime defaults.+ */+app.get('/test/default-config', async c => {+ try {+ // Initialize Composio without explicitly setting autoUploadDownloadFiles+ // Should use the workerd default (false)+ const composio = new Composio({+ apiKey: c.env.COMPOSIO_API_KEY,+ });++ return c.json({+ success: true,+ message: 'Composio initialized successfully with default configuration',+ hasProvider: typeof composio.provider !== 'undefined',+ hasTools: typeof composio.tools !== 'undefined',+ hasFiles: typeof composio.files !== 'undefined',+ note: 'In workerd runtime, autoUploadDownloadFiles defaults to false',+ });+ } catch (error) {+ return c.json(+ {+ success: false,+ error: error instanceof Error ? error.message : String(error),+ },+ { status: 500 }+ );+ }+});++export default app;diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/test/files.spec.ts b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/test/files.spec.tsnew file mode 100644index 000000000..37b1fd9bc--- /dev/null+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/test/files.spec.ts@@ -0,0 +1,126 @@+import { env, createExecutionContext, waitOnExecutionContext } from 'cloudflare:test';+import { describe, it, expect } from 'vitest';+import app from '../src/index';++const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;++describe('@composio/core Files - Cloudflare Workers compatibility', () => {+ it('should list the available endpoints', async () => {+ const request = new IncomingRequest('http://localhost/');+ const ctx = createExecutionContext();+ const response = await app.fetch(request, env, ctx);+ await waitOnExecutionContext(ctx);++ expect(response.status).toBe(200);++ const body = (await response.json()) as {+ message: string;+ endpoints: string[];+ };++ expect(body.message).toContain('Composio Core Files E2E Test Worker');+ expect(body.endpoints).toMatchInlineSnapshot(`+ [+ "/test/files/upload",+ "/test/files/download",+ "/test/file-modifier/error-message",+ "/test/auto-upload-disabled",+ "/test/default-config",+ ]+ `);+ });++ it('should throw an error when calling files.upload() in Cloudflare Workers', async () => {+ const request = new IncomingRequest('http://localhost/test/files/upload');+ const ctx = createExecutionContext();+ const response = await app.fetch(request, env, ctx);+ await waitOnExecutionContext(ctx);++ expect(response.status).toBe(200);++ const body = (await response.json()) as {+ error?: string;+ };++ expect(body.error).toContain('not supported in Cloudflare Workers');+ });++ it('should throw an error when calling files.download() in Cloudflare Workers', async () => {+ const request = new IncomingRequest('http://localhost/test/files/download');+ const ctx = createExecutionContext();+ const response = await app.fetch(request, env, ctx);+ await waitOnExecutionContext(ctx);++ expect(response.status).toBe(200);++ const body = (await response.json()) as {+ error?: string;+ };++ expect(body.error).toContain('not supported in Cloudflare Workers');+ });++ it('should throw FileToolModifier error when executing a tool in Cloudflare Workers', async () => {+ const request = new IncomingRequest('http://localhost/test/file-modifier/error-message');+ const ctx = createExecutionContext();+ const response = await app.fetch(request, env, ctx);+ await waitOnExecutionContext(ctx);++ expect(response.status).toBe(200);++ const body = (await response.json()) as {+ error?: string;+ };++ expect(body.error).toContain('not available on edge runtimes');+ });++ it('should successfully initialize Composio with autoUploadDownloadFiles disabled', async () => {+ const request = new IncomingRequest('http://localhost/test/auto-upload-disabled');+ const ctx = createExecutionContext();+ const response = await app.fetch(request, env, ctx);+ await waitOnExecutionContext(ctx);++ expect(response.status).toBe(200);++ const body = (await response.json()) as {+ success: boolean;+ message?: string;+ hasProvider?: boolean;+ hasTools?: boolean;+ hasFiles?: boolean;+ recommendation?: string;+ };++ expect(body.success).toBe(true);+ expect(body.message).toContain('autoUploadDownloadFiles: false');+ expect(body.hasProvider).toBe(true);+ expect(body.hasTools).toBe(true);+ expect(body.hasFiles).toBe(true);+ });++ it('should successfully initialize Composio with default configuration', async () => {+ const request = new IncomingRequest('http://localhost/test/default-config');+ const ctx = createExecutionContext();+ const response = await app.fetch(request, env, ctx);+ await waitOnExecutionContext(ctx);++ expect(response.status).toBe(200);++ const body = (await response.json()) as {+ success: boolean;+ message?: string;+ hasProvider?: boolean;+ hasTools?: boolean;+ hasFiles?: boolean;+ note?: string;+ };++ expect(body.success).toBe(true);+ expect(body.message).toContain('default configuration');+ expect(body.hasProvider).toBe(true);+ expect(body.hasTools).toBe(true);+ expect(body.hasFiles).toBe(true);+ expect(body.note).toContain('autoUploadDownloadFiles defaults to false');+ });+});diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/tsconfig.json b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/tsconfig.jsonnew file mode 100644index 000000000..2dc131ca3--- /dev/null+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/tsconfig.json@@ -0,0 +1,18 @@+{+ "compilerOptions": {+ "target": "es2022",+ "lib": ["es2022"],+ "module": "es2022",+ "moduleResolution": "Bundler",+ "resolveJsonModule": true,+ "allowJs": true,+ "noEmit": true,+ "isolatedModules": true,+ "allowSyntheticDefaultImports": true,+ "forceConsistentCasingInFileNames": true,+ "strict": true,+ "skipLibCheck": true,+ "types": ["@cloudflare/workers-types"]+ },+ "include": ["src/**/*.ts", "test/**/*.ts"]+}diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/vitest.config.mts b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/vitest.config.mtsnew file mode 100644index 000000000..454d4062d--- /dev/null+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/vitest.config.mts@@ -0,0 +1,19 @@+import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';+import { config } from 'dotenv';++config();++export default defineWorkersConfig({+ test: {+ poolOptions: {+ workers: {+ wrangler: { configPath: './wrangler.jsonc' },+ miniflare: {+ bindings: {+ COMPOSIO_API_KEY: process.env.COMPOSIO_API_KEY ?? 'test-key',+ },+ },+ },+ },+ },+});diff --git a/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/wrangler.jsonc b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/wrangler.jsoncnew file mode 100644index 000000000..54c717e07--- /dev/null+++ b/ts/e2e-tests/runtimes/cloudflare/cf-workers-files/wrangler.jsonc@@ -0,0 +1,6 @@+{+ "$schema": "node_modules/wrangler/config-schema.json",+ "name": "composio-core-files-test",+ "main": "src/index.ts",+ "compatibility_date": "2025-01-10"+}