@devries-cameron20 / composio Mirror · read-only / commits / aa41704ca
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 22, 23:15 UTC

Update tests and bugs

haxzie committed Jun 20, 2025 at 11:15 UTC aa41704cadd233ba2bfb2ee1975caa5c0fb7ce49
3 files changed +242 -6
ts/packages/core/src/utils/modifiers/FileToolModifier.ts
+1 -3
@@ -31,7 +31,7 @@ const transformProperties = (properties: JSONSchemaProperty): JSONSchemaProperty
31 };
32 }
33
34 - return properties;
34 + return newProperties;
35 };
36
37 export class FileToolModifier {
@@ -127,8 +127,6 @@ export class FileToolModifier {
127 result: ToolExecuteResponse;
128 }
129 ): Promise<ToolExecuteResponse> {
130 - console.log(JSON.stringify(options.result, null, 2));
131 - console.log(JSON.stringify(tool.outputParameters, null, 2));
130 for (const [key, value] of Object.entries(options.result?.data)) {
131 const fileData = value as { s3url?: string; mimetype?: string };
132
ts/packages/core/test/tools/fileModifiers.test.ts new
+238
@@ -0,0 +1,238 @@
1 +import { describe, it, expect, vi, beforeEach } from 'vitest';
2 +import { FileToolModifier } from '../../src/utils/modifiers/FileToolModifier';
3 +import ComposioClient from '@composio/client';
4 +import { Tool } from '../../src/types/tool.types';
5 +import { ComposioFileUploadError } from '../../src/errors/FileModifierErrors';
6 +import * as fileUtils from '../../src/utils/fileUtils';
7 +
8 +// Mock the fileUtils module
9 +vi.mock('../../src/utils/fileUtils', () => ({
10 + downloadFileFromS3: vi.fn(),
11 + getFileDataAfterUploadingToS3: vi.fn(),
12 +}));
13 +
14 +describe('FileToolModifier', () => {
15 + let fileToolModifier: FileToolModifier;
16 + let mockClient: ComposioClient;
17 +
18 + beforeEach(() => {
19 + mockClient = {
20 + baseURL: 'https://api.composio.dev',
21 + apiKey: 'test-api-key',
22 + } as ComposioClient;
23 + fileToolModifier = new FileToolModifier(mockClient);
24 + vi.clearAllMocks();
25 + });
26 +
27 + describe('modifyToolSchema', () => {
28 + it('should return schema unchanged if no input parameters', async () => {
29 + const schema: Tool = {
30 + slug: 'test-tool',
31 + name: 'Test Tool',
32 + description: 'A test tool',
33 + tags: ['test'],
34 + };
35 +
36 + const result = await fileToolModifier.modifyToolSchema('test-tool', 'test-toolkit', schema);
37 + expect(result).toEqual(schema);
38 + });
39 +
40 + it('should add format: "path" to file_uploadable properties', async () => {
41 + const schema: Tool = {
42 + slug: 'test-tool',
43 + name: 'Test Tool',
44 + description: 'A test tool',
45 + tags: ['test'],
46 + inputParameters: {
47 + type: 'object',
48 + properties: {
49 + file: {
50 + type: 'string',
51 + file_uploadable: true,
52 + },
53 + text: {
54 + type: 'string',
55 + },
56 + },
57 + },
58 + };
59 +
60 + const result = await fileToolModifier.modifyToolSchema('test-tool', 'test-toolkit', schema);
61 + expect(result.inputParameters?.properties?.file).toHaveProperty('format', 'path');
62 + expect(result.inputParameters?.properties?.text).not.toHaveProperty('format');
63 + });
64 + });
65 +
66 + describe('fileUploadModifier', () => {
67 + const mockTool: Tool = {
68 + slug: 'test-tool',
69 + name: 'Test Tool',
70 + description: 'A test tool',
71 + tags: ['test'],
72 + inputParameters: {
73 + type: 'object',
74 + properties: {
75 + file: {
76 + type: 'string',
77 + file_uploadable: true,
78 + },
79 + text: {
80 + type: 'string',
81 + },
82 + },
83 + },
84 + };
85 +
86 + it('should upload file for file_uploadable parameters', async () => {
87 + const mockFileData = {
88 + name: 'file.txt',
89 + mimetype: 'text/plain',
90 + s3key: 'uploads/file.txt',
91 + };
92 + vi.mocked(fileUtils.getFileDataAfterUploadingToS3).mockResolvedValue(mockFileData);
93 +
94 + const params = {
95 + arguments: {
96 + file: '/path/to/file.txt',
97 + text: 'some text',
98 + },
99 + userId: 'test-user',
100 + };
101 +
102 + const result = await fileToolModifier.fileUploadModifier(mockTool, {
103 + toolSlug: 'test-tool',
104 + toolkitSlug: 'test-toolkit',
105 + params,
106 + });
107 +
108 + expect(fileUtils.getFileDataAfterUploadingToS3).toHaveBeenCalledWith(
109 + '/path/to/file.txt',
110 + 'test-tool',
111 + 'test-toolkit',
112 + mockClient
113 + );
114 + expect(result.arguments?.file).toEqual(mockFileData);
115 + expect(result.arguments?.text).toBe('some text');
116 + });
117 +
118 + it('should throw ComposioFileUploadError on upload failure', async () => {
119 + vi.mocked(fileUtils.getFileDataAfterUploadingToS3).mockRejectedValue(
120 + new Error('Upload failed')
121 + );
122 +
123 + const params = {
124 + arguments: {
125 + file: '/path/to/file.txt',
126 + },
127 + userId: 'test-user',
128 + };
129 +
130 + await expect(
131 + fileToolModifier.fileUploadModifier(mockTool, {
132 + toolSlug: 'test-tool',
133 + toolkitSlug: 'test-toolkit',
134 + params,
135 + })
136 + ).rejects.toThrow(ComposioFileUploadError);
137 + });
138 + });
139 +
140 + describe('fileDownloadModifier', () => {
141 + const mockTool: Tool = {
142 + slug: 'test-tool',
143 + name: 'Test Tool',
144 + description: 'A test tool',
145 + tags: ['test'],
146 + };
147 +
148 + it('should download file from S3 URL', async () => {
149 + const mockDownloadResult = {
150 + name: 'file.txt',
151 + mimeType: 'text/plain',
152 + s3Key: 'downloads/file.txt',
153 + filePath: '/downloaded/file.txt',
154 + };
155 + vi.mocked(fileUtils.downloadFileFromS3).mockResolvedValue(mockDownloadResult);
156 +
157 + const result = {
158 + data: {
159 + file: {
160 + s3url: 'https://s3.example.com/file.txt',
161 + mimetype: 'text/plain',
162 + },
163 + },
164 + error: null,
165 + successful: true,
166 + };
167 +
168 + const modifiedResult = await fileToolModifier.fileDownloadModifier(mockTool, {
169 + toolSlug: 'test-tool',
170 + toolkitSlug: 'test-toolkit',
171 + result,
172 + });
173 +
174 + expect(fileUtils.downloadFileFromS3).toHaveBeenCalledWith({
175 + toolSlug: 'test-tool',
176 + s3Url: 'https://s3.example.com/file.txt',
177 + mimeType: 'text/plain',
178 + });
179 +
180 + expect(modifiedResult.data.file).toEqual({
181 + uri: '/downloaded/file.txt',
182 + file_downloaded: true,
183 + s3url: 'https://s3.example.com/file.txt',
184 + mimeType: 'text/plain',
185 + });
186 + });
187 +
188 + it('should handle download failure gracefully', async () => {
189 + vi.mocked(fileUtils.downloadFileFromS3).mockRejectedValue(new Error('Download failed'));
190 +
191 + const result = {
192 + data: {
193 + file: {
194 + s3url: 'https://s3.example.com/file.txt',
195 + mimetype: 'text/plain',
196 + },
197 + },
198 + error: null,
199 + successful: true,
200 + };
201 +
202 + const modifiedResult = await fileToolModifier.fileDownloadModifier(mockTool, {
203 + toolSlug: 'test-tool',
204 + toolkitSlug: 'test-toolkit',
205 + result,
206 + });
207 +
208 + expect(modifiedResult.data.file).toEqual({
209 + uri: '',
210 + file_downloaded: false,
211 + s3url: 'https://s3.example.com/file.txt',
212 + mimeType: 'text/plain',
213 + });
214 + });
215 +
216 + it('should skip fields without s3url', async () => {
217 + const result = {
218 + data: {
219 + text: 'some text',
220 + file: {
221 + other_field: 'value',
222 + },
223 + },
224 + error: null,
225 + successful: true,
226 + };
227 +
228 + const modifiedResult = await fileToolModifier.fileDownloadModifier(mockTool, {
229 + toolSlug: 'test-tool',
230 + toolkitSlug: 'test-toolkit',
231 + result,
232 + });
233 +
234 + expect(fileUtils.downloadFileFromS3).not.toHaveBeenCalled();
235 + expect(modifiedResult).toEqual(result);
236 + });
237 + });
238 +});
ts/packages/core/test/tools/tools.test.ts
+3 -3
@@ -1,7 +1,7 @@
1 import { describe, it, expect, vi } from 'vitest';
2 import { mockClient } from '../utils/mocks/client.mock';
3 import { toolMocks } from '../utils/mocks/data.mock';
4 -import { Tool } from '../../src/types/tool.types';
4 +import { Tool, ToolListParams } from '../../src/types/tool.types';
5 import { Tools } from '../../src/models/Tools';
6 import ComposioClient from '@composio/client';
7 import {
@@ -119,7 +119,7 @@ describe('Tools', () => {
119
120 it('should handle toolkit scopes parameters correctly', async () => {
121 const userId = 'test-user';
122 - const query = {
122 + const query: ToolListParams = {
123 toolkits: ['todoist'],
124 scopes: ['task:add', 'task:read'],
125 limit: 10,
@@ -143,7 +143,7 @@ describe('Tools', () => {
143
144 it('should handle toolkit scopes with search parameters correctly', async () => {
145 const userId = 'test-user';
146 - const query = {
146 + const query: ToolListParams = {
147 toolkits: ['todoist'],
148 scopes: ['task:add'],
149 search: 'add task',