@devries-cameron20 / composio Mirror · read-only
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, 06:00 UTC

next
ts 170 lines 5.12 KB
Raw
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 { Hono } from 'hono';
8
9 type Bindings = {
10 COMPOSIO_API_KEY: string;
11 COMPOSIO_BASE_URL: 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/auto-upload-disabled',
26 '/test/default-config',
27 ],
28 });
29 });
30
31 /**
32 * Test: Files upload operation (should fail in Cloudflare Workers)
33 * Tests that composio.files.upload() throws an appropriate error in edge runtimes
34 */
35 app.get('/test/files/upload', async c => {
36 try {
37 const composio = new Composio({
38 apiKey: c.env.COMPOSIO_API_KEY,
39 baseURL: c.env.COMPOSIO_BASE_URL,
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 baseURL: c.env.COMPOSIO_BASE_URL,
73 });
74
75 // Attempt to call files.download - should throw an error
76 await composio.files.download({
77 s3Url: 'https://s3.example.com/test.pdf',
78 toolSlug: 'test-tool',
79 mimeType: 'application/pdf',
80 });
81
82 // If we get here, the test failed - download should have thrown
83 return c.json(
84 {
85 error: 'Expected files.download() to throw an error in Cloudflare Workers, but it did not',
86 },
87 { status: 500 }
88 );
89 } catch (error) {
90 const errorMessage = error instanceof Error ? error.message : String(error);
91 return c.json({
92 error: errorMessage,
93 });
94 }
95 });
96
97 /**
98 * Test: Composio initialization with automatic file upload/download disabled
99 *
100 * In workerd runtime (Cloudflare Workers), dangerouslyAllowAutoUploadDownloadFiles defaults to false.
101 * This test verifies that the default configuration works correctly and that
102 * Composio can be initialized successfully without file upload/download support.
103 */
104 app.get('/test/auto-upload-disabled', async c => {
105 try {
106 // Explicitly keep automatic file handling off (default everywhere)
107 const composio = new Composio({
108 apiKey: c.env.COMPOSIO_API_KEY,
109 baseURL: c.env.COMPOSIO_BASE_URL,
110 dangerouslyAllowAutoUploadDownloadFiles: false,
111 });
112
113 return c.json({
114 success: true,
115 message:
116 'Composio initialized successfully with dangerouslyAllowAutoUploadDownloadFiles: false',
117 hasProvider: typeof composio.provider !== 'undefined',
118 hasTools: typeof composio.tools !== 'undefined',
119 hasFiles: typeof composio.files !== 'undefined',
120 recommendation:
121 'Use this configuration in edge runtimes to avoid FileToolModifier errors. ' +
122 'Note that file upload/download operations will not be automatically handled.',
123 });
124 } catch (error) {
125 return c.json(
126 {
127 success: false,
128 error: error instanceof Error ? error.message : String(error),
129 },
130 { status: 500 }
131 );
132 }
133 });
134
135 /**
136 * Test: Composio initialization with default configuration
137 *
138 * This test verifies that Composio initializes correctly with the default
139 * configuration for workerd runtime (dangerouslyAllowAutoUploadDownloadFiles: false by default).
140 * No explicit configuration is provided, relying on the runtime defaults.
141 */
142 app.get('/test/default-config', async c => {
143 try {
144 // Initialize Composio without explicitly setting dangerouslyAllowAutoUploadDownloadFiles
145 // Should use the workerd default (false)
146 const composio = new Composio({
147 apiKey: c.env.COMPOSIO_API_KEY,
148 baseURL: c.env.COMPOSIO_BASE_URL,
149 });
150
151 return c.json({
152 success: true,
153 message: 'Composio initialized successfully with default configuration',
154 hasProvider: typeof composio.provider !== 'undefined',
155 hasTools: typeof composio.tools !== 'undefined',
156 hasFiles: typeof composio.files !== 'undefined',
157 note: 'In workerd runtime, dangerouslyAllowAutoUploadDownloadFiles defaults to false',
158 });
159 } catch (error) {
160 return c.json(
161 {
162 success: false,
163 error: error instanceof Error ? error.message : String(error),
164 },
165 { status: 500 }
166 );
167 }
168 });
169
170 export default app;