Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Update tests for mastra:
haxzie committed
May 26, 2025 at 17:22 UTC
1be8e3778af1d9a8f94ba6277d291bbb2cdc57a6
8 files changed
+549
-13
packages/core/src/index.ts
+1
-1
@@ -5,7 +5,7 @@ export { BaseAgenticProvider, BaseNonAgenticProvider } from './provider/BaseProv
5
export type { BaseComposioProvider } from './provider/BaseProvider';
6
export { OpenAIProvider } from './provider/OpenAIProvider';
7
export { BaseTelemetryTransport, ConsoleTelemetryTransport } from './telemetry/TelemetryTransport';
8
-export { jsonSchemaToModel } from './utils/jsonSchema';
8
+export { jsonSchemaToZodSchema } from './utils/jsonSchema';
9
export { ToolListParamsSchema } from './types/tool.types';
10
export type { Tool, ToolListParams, ToolExecuteParams } from './types/tool.types';
11
export type { Provider, ExecuteToolFn, ExecuteToolFnOptions } from './types/provider.types';
packages/core/src/utils/jsonSchema.ts
+4
-4
@@ -30,7 +30,7 @@ export function jsonSchemaToTsType(jsonSchema: Record<string, unknown>): unknown
30
if (type === 'object') {
31
const properties = jsonSchema.properties;
32
if (properties) {
33
- const nestedModel = jsonSchemaToModel(jsonSchema);
33
+ const nestedModel = jsonSchemaToZodSchema(jsonSchema);
34
return nestedModel;
35
}
36
return Object;
@@ -125,7 +125,7 @@ function jsonSchemaPropertiesToTSTypes(value: {
125
);
126
break;
127
case 'object':
128
- zodType = jsonSchemaToModel(value).describe(
128
+ zodType = jsonSchemaToZodSchema(value).describe(
129
(value.description || '') +
130
(value.examples ? `\nExamples: ${value.examples.join(', ')}` : '')
131
);
@@ -147,7 +147,7 @@ function jsonSchemaPropertiesToTSTypes(value: {
147
*
148
* @example
149
* ```ts
150
- * const zodSchema = jsonSchemaToModel({
150
+ * const zodSchema = jsonSchemaToZodSchema({
151
* type: 'object',
152
* properties: {
153
* name: { type: 'string' },
@@ -157,7 +157,7 @@ function jsonSchemaPropertiesToTSTypes(value: {
157
* console.log(zodSchema);
158
* ```
159
*/
160
-export function jsonSchemaToModel(
160
+export function jsonSchemaToZodSchema(
161
jsonSchema: Record<string, unknown>
162
): z.ZodObject<Record<string, z.ZodTypeAny>> {
163
const properties = jsonSchema.properties as Record<string, unknown>;
packages/providers/langchain/src/index.ts
+2
-2
@@ -9,7 +9,7 @@
9
* @packageDocumentation
10
* @module providers/langchain
11
*/
12
-import { BaseAgenticProvider, jsonSchemaToModel, Tool, ExecuteToolFn } from '@composio/core';
12
+import { BaseAgenticProvider, jsonSchemaToZodSchema, Tool, ExecuteToolFn } from '@composio/core';
13
import { DynamicStructuredTool } from '@langchain/core/tools';
14
15
export type LangChainToolCollection = Array<DynamicStructuredTool>;
@@ -38,7 +38,7 @@ export class LangchainProvider extends BaseAgenticProvider<
38
if (!tool.inputParameters) {
39
throw new Error('Tool input parameters are not defined');
40
}
41
- const parameters = jsonSchemaToModel(tool.inputParameters);
41
+ const parameters = jsonSchemaToZodSchema(tool.inputParameters);
42
return new DynamicStructuredTool({
43
name: toolName,
44
description: description || '',
packages/providers/langchain/test/langchain.test.ts
+2
-2
@@ -23,12 +23,12 @@ vi.mock('@langchain/core/tools', () => {
23
};
24
});
25
26
-// Mock the jsonSchemaToModel function from @composio/core
26
+// Mock the jsonSchemaToZodSchema function from @composio/core
27
vi.mock('@composio/core', async () => {
28
const actual = await vi.importActual('@composio/core');
29
return {
30
...(actual as object),
31
- jsonSchemaToModel: vi.fn().mockImplementation(schema => {
31
+ jsonSchemaToZodSchema: vi.fn().mockImplementation(schema => {
32
return { type: 'mock-schema', originalSchema: schema };
33
}),
34
};
packages/providers/mastra/package.json
+2
-1
@@ -39,6 +39,7 @@
39
"devDependencies": {
40
"@composio/core": "workspace:*",
41
"tsup": "^8.4.0",
42
- "typescript": "^5.8.3"
42
+ "typescript": "^5.8.3",
43
+ "vitest": "^3.1.3"
44
}
45
}
packages/providers/mastra/src/index.ts
+5
-3
@@ -6,7 +6,7 @@
6
* @packageDocumentation
7
* @module providers/mastra
8
*/
9
-import { BaseAgenticProvider, Tool, ExecuteToolFn, jsonSchemaToModel } from '@composio/core';
9
+import { BaseAgenticProvider, Tool, ExecuteToolFn, jsonSchemaToZodSchema } from '@composio/core';
10
import { createTool } from '@mastra/core';
11
12
export type MastraTool = ReturnType<typeof createTool>;
@@ -22,8 +22,10 @@ export class MastraProvider extends BaseAgenticProvider<MastraToolCollection, Ma
22
const mastraTool = createTool({
23
id: tool.slug,
24
description: tool.description ?? '',
25
- inputSchema: tool.inputParameters ? jsonSchemaToModel(tool.inputParameters) : undefined,
26
- outputSchema: tool.outputParameters ? jsonSchemaToModel(tool.outputParameters) : undefined,
25
+ inputSchema: tool.inputParameters ? jsonSchemaToZodSchema(tool.inputParameters) : undefined,
26
+ outputSchema: tool.outputParameters
27
+ ? jsonSchemaToZodSchema(tool.outputParameters)
28
+ : undefined,
29
execute: async ({ context }) => {
30
const result = await executeTool(tool.slug, context);
31
return result;
packages/providers/mastra/test/README.md
new
+72
@@ -0,0 +1,72 @@
1
+# Mastra Provider Tests
2
+
3
+This directory contains comprehensive unit tests for the Mastra provider implementation.
4
+
5
+## Test Coverage
6
+
7
+The test suite covers the following areas:
8
+
9
+### 1. Provider Properties
10
+
11
+- **Name verification**: Ensures the provider has the correct name "mastra"
12
+- **Agentic nature**: Confirms the provider is marked as agentic (supports tool execution)
13
+
14
+### 2. Tool Wrapping (`wrapTool`)
15
+
16
+- **Basic wrapping**: Tests conversion of Composio tools to Mastra createTool format
17
+- **Schema handling**: Tests proper conversion of input/output parameters using jsonSchemaToModel
18
+- **Edge cases**: Handles tools without descriptions, input parameters, or output parameters
19
+- **Execution context**: Tests different context parameter scenarios (empty, missing, populated)
20
+
21
+### 3. Tools Collection (`wrapTools`)
22
+
23
+- **Multiple tools**: Tests wrapping arrays of tools into key-value collections
24
+- **Empty arrays**: Handles empty tool arrays gracefully
25
+- **Key mapping**: Uses tool slugs as collection keys
26
+- **Duplicate handling**: Manages duplicate tool slugs by overwriting
27
+
28
+### 4. Tool Execution (`executeTool`)
29
+
30
+- **Global execution**: Tests integration with the global tool execution function
31
+- **Modifiers support**: Tests passing of beforeExecute/afterExecute modifiers
32
+- **Error handling**: Tests graceful handling of execution errors
33
+
34
+### 5. Mastra Integration
35
+
36
+- **Compatibility**: Ensures generated tools are compatible with Mastra's createTool function
37
+- **Type safety**: Validates correct typing for MastraTool and MastraToolCollection
38
+- **Schema mapping**: Tests proper mapping from Composio tool schemas to Mastra schemas
39
+
40
+### 6. Error Handling
41
+
42
+- **Execution failures**: Tests behavior when tool execution fails
43
+- **Malformed schemas**: Handles tools with null or malformed schema definitions
44
+- **Type safety**: Maintains type safety even with edge cases
45
+
46
+## Test Structure
47
+
48
+The tests follow vitest conventions and include:
49
+
50
+- Comprehensive mocking of `@mastra/core` and `@composio/core`
51
+- Setup and teardown with `beforeEach` for clean test isolation
52
+- Detailed assertions for both successful and error scenarios
53
+- Type-safe test implementations
54
+
55
+## Running Tests
56
+
57
+```bash
58
+# From the mastra provider directory
59
+npm test
60
+
61
+# From the workspace root
62
+pnpm test --filter=@composio/mastra
63
+```
64
+
65
+## Mock Strategy
66
+
67
+The tests use vi.mock() to mock:
68
+
69
+- `@mastra/core` - Specifically the `createTool` function
70
+- `@composio/core` - The `jsonSchemaToModel` function
71
+
72
+This ensures tests are isolated and don't depend on external dependencies while validating the integration contracts.
packages/providers/mastra/test/mastra.test.ts
new
+461
@@ -0,0 +1,461 @@
1
+import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+import { MastraProvider } from '../src';
3
+import { Tool } from '@composio/core';
4
+import { createTool } from '@mastra/core';
5
+
6
+// Define an interface for our mocked Mastra tool
7
+interface MockedMastraTool {
8
+ id: string;
9
+ description: string;
10
+ inputSchema?: any;
11
+ outputSchema?: any;
12
+ execute: Function;
13
+ _isMockedMastraTool: boolean;
14
+}
15
+
16
+// Mock the @mastra/core module
17
+vi.mock('@mastra/core', () => {
18
+ return {
19
+ createTool: vi.fn().mockImplementation(toolConfig => {
20
+ return {
21
+ id: toolConfig.id,
22
+ description: toolConfig.description,
23
+ inputSchema: toolConfig.inputSchema,
24
+ outputSchema: toolConfig.outputSchema,
25
+ execute: toolConfig.execute,
26
+ _isMockedMastraTool: true,
27
+ } as MockedMastraTool;
28
+ }),
29
+ };
30
+});
31
+
32
+// Mock the jsonSchemaToZodSchema function from @composio/core
33
+vi.mock('@composio/core', async () => {
34
+ const actual = await vi.importActual('@composio/core');
35
+ return {
36
+ ...(actual as object),
37
+ jsonSchemaToZodSchema: vi.fn().mockImplementation(schema => {
38
+ return { type: 'mock-zod-schema', originalSchema: schema };
39
+ }),
40
+ };
41
+});
42
+
43
+describe('MastraProvider', () => {
44
+ let provider: MastraProvider;
45
+ let mockTool: Tool;
46
+ let mockExecuteToolFn: any;
47
+
48
+ beforeEach(() => {
49
+ provider = new MastraProvider();
50
+
51
+ // Mock the global execute tool function
52
+ mockExecuteToolFn = vi.fn().mockResolvedValue({
53
+ data: { result: 'success' },
54
+ error: null,
55
+ successful: true,
56
+ });
57
+ provider._setExecuteToolFn(mockExecuteToolFn);
58
+
59
+ // Create a mock Composio tool
60
+ mockTool = {
61
+ slug: 'test-tool',
62
+ name: 'Test Tool',
63
+ description: 'A tool for testing',
64
+ inputParameters: {
65
+ type: 'object',
66
+ properties: {
67
+ input: {
68
+ type: 'string',
69
+ description: 'Test input',
70
+ },
71
+ },
72
+ required: ['input'],
73
+ },
74
+ outputParameters: {
75
+ type: 'object',
76
+ properties: {
77
+ result: {
78
+ type: 'string',
79
+ description: 'Test result',
80
+ },
81
+ },
82
+ },
83
+ toolkit: {
84
+ slug: 'test-toolkit',
85
+ name: 'Test Toolkit',
86
+ },
87
+ tags: [],
88
+ };
89
+
90
+ // Reset mocks before each test
91
+ vi.clearAllMocks();
92
+ });
93
+
94
+ describe('name property', () => {
95
+ it('should have the correct name', () => {
96
+ expect(provider.name).toBe('mastra');
97
+ });
98
+ });
99
+
100
+ describe('_isAgentic property', () => {
101
+ it('should be agentic', () => {
102
+ expect(provider._isAgentic).toBe(true);
103
+ });
104
+ });
105
+
106
+ describe('wrapTool', () => {
107
+ it('should wrap a tool in Mastra createTool format', () => {
108
+ const wrapped = provider.wrapTool(mockTool, mockExecuteToolFn) as unknown as MockedMastraTool;
109
+
110
+ expect(createTool).toHaveBeenCalledWith({
111
+ id: mockTool.slug,
112
+ description: mockTool.description,
113
+ inputSchema: { type: 'mock-zod-schema', originalSchema: mockTool.inputParameters },
114
+ outputSchema: { type: 'mock-zod-schema', originalSchema: mockTool.outputParameters },
115
+ execute: expect.any(Function),
116
+ });
117
+
118
+ expect(wrapped._isMockedMastraTool).toBe(true);
119
+ });
120
+
121
+ it('should handle tools without input parameters', () => {
122
+ const toolWithoutInputParams: Tool = {
123
+ ...mockTool,
124
+ inputParameters: undefined,
125
+ };
126
+
127
+ const wrapped = provider.wrapTool(
128
+ toolWithoutInputParams,
129
+ mockExecuteToolFn
130
+ ) as unknown as MockedMastraTool;
131
+
132
+ expect(createTool).toHaveBeenCalledWith({
133
+ id: toolWithoutInputParams.slug,
134
+ description: toolWithoutInputParams.description,
135
+ inputSchema: undefined,
136
+ outputSchema: { type: 'mock-zod-schema', originalSchema: mockTool.outputParameters },
137
+ execute: expect.any(Function),
138
+ });
139
+
140
+ expect(wrapped._isMockedMastraTool).toBe(true);
141
+ });
142
+
143
+ it('should handle tools without output parameters', () => {
144
+ const toolWithoutOutputParams: Tool = {
145
+ ...mockTool,
146
+ outputParameters: undefined,
147
+ };
148
+
149
+ const wrapped = provider.wrapTool(
150
+ toolWithoutOutputParams,
151
+ mockExecuteToolFn
152
+ ) as unknown as MockedMastraTool;
153
+
154
+ expect(createTool).toHaveBeenCalledWith({
155
+ id: toolWithoutOutputParams.slug,
156
+ description: toolWithoutOutputParams.description,
157
+ inputSchema: { type: 'mock-zod-schema', originalSchema: mockTool.inputParameters },
158
+ outputSchema: undefined,
159
+ execute: expect.any(Function),
160
+ });
161
+
162
+ expect(wrapped._isMockedMastraTool).toBe(true);
163
+ });
164
+
165
+ it('should handle tools without description', () => {
166
+ const toolWithoutDescription: Tool = {
167
+ ...mockTool,
168
+ description: undefined,
169
+ };
170
+
171
+ const wrapped = provider.wrapTool(
172
+ toolWithoutDescription,
173
+ mockExecuteToolFn
174
+ ) as unknown as MockedMastraTool;
175
+
176
+ expect(createTool).toHaveBeenCalledWith({
177
+ id: toolWithoutDescription.slug,
178
+ description: '',
179
+ inputSchema: { type: 'mock-zod-schema', originalSchema: mockTool.inputParameters },
180
+ outputSchema: { type: 'mock-zod-schema', originalSchema: mockTool.outputParameters },
181
+ execute: expect.any(Function),
182
+ });
183
+
184
+ expect(wrapped._isMockedMastraTool).toBe(true);
185
+ });
186
+
187
+ it('should create a function that executes the tool with the right parameters', async () => {
188
+ provider.wrapTool(mockTool, mockExecuteToolFn) as unknown as MockedMastraTool;
189
+
190
+ // Extract the execute function from the call to createTool()
191
+ const executeFunction = (createTool as any).mock.calls[0][0].execute;
192
+
193
+ // Test the execute function
194
+ const context = { input: 'test-value' };
195
+ const result = await executeFunction({ context });
196
+
197
+ expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, context);
198
+ expect(result).toEqual({
199
+ data: { result: 'success' },
200
+ error: null,
201
+ successful: true,
202
+ });
203
+ });
204
+
205
+ it('should handle empty context parameter', async () => {
206
+ provider.wrapTool(mockTool, mockExecuteToolFn) as unknown as MockedMastraTool;
207
+
208
+ // Extract the execute function from the call to createTool()
209
+ const executeFunction = (createTool as any).mock.calls[0][0].execute;
210
+
211
+ // Test the execute function with empty context
212
+ const result = await executeFunction({ context: {} });
213
+
214
+ expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, {});
215
+ expect(result).toEqual({
216
+ data: { result: 'success' },
217
+ error: null,
218
+ successful: true,
219
+ });
220
+ });
221
+
222
+ it('should handle missing context parameter', async () => {
223
+ provider.wrapTool(mockTool, mockExecuteToolFn) as unknown as MockedMastraTool;
224
+
225
+ // Extract the execute function from the call to createTool()
226
+ const executeFunction = (createTool as any).mock.calls[0][0].execute;
227
+
228
+ // Test the execute function without context
229
+ const result = await executeFunction({});
230
+
231
+ expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, undefined);
232
+ expect(result).toEqual({
233
+ data: { result: 'success' },
234
+ error: null,
235
+ successful: true,
236
+ });
237
+ });
238
+ });
239
+
240
+ describe('wrapTools', () => {
241
+ it('should wrap multiple tools in a collection', () => {
242
+ const anotherTool: Tool = {
243
+ ...mockTool,
244
+ slug: 'another-tool',
245
+ name: 'Another Tool',
246
+ };
247
+ const tools = [mockTool, anotherTool];
248
+
249
+ const wrapped = provider.wrapTools(tools, mockExecuteToolFn);
250
+
251
+ // Verify the result has the expected properties
252
+ expect(Object.keys(wrapped)).toHaveLength(2);
253
+ expect(wrapped['test-tool']).toBeDefined();
254
+ expect(wrapped['another-tool']).toBeDefined();
255
+
256
+ // Verify createTool was called with the right parameters for each tool
257
+ expect(createTool).toHaveBeenCalledTimes(2);
258
+ expect(createTool).toHaveBeenCalledWith({
259
+ id: mockTool.slug,
260
+ description: mockTool.description,
261
+ inputSchema: { type: 'mock-zod-schema', originalSchema: mockTool.inputParameters },
262
+ outputSchema: { type: 'mock-zod-schema', originalSchema: mockTool.outputParameters },
263
+ execute: expect.any(Function),
264
+ });
265
+ expect(createTool).toHaveBeenCalledWith({
266
+ id: anotherTool.slug,
267
+ description: anotherTool.description,
268
+ inputSchema: { type: 'mock-zod-schema', originalSchema: anotherTool.inputParameters },
269
+ outputSchema: { type: 'mock-zod-schema', originalSchema: anotherTool.outputParameters },
270
+ execute: expect.any(Function),
271
+ });
272
+ });
273
+
274
+ it('should return an empty object for empty tools array', () => {
275
+ const wrapped = provider.wrapTools([], mockExecuteToolFn);
276
+ expect(wrapped).toEqual({});
277
+ expect(createTool).not.toHaveBeenCalled();
278
+ });
279
+
280
+ it('should use tool slugs as keys in the collection', () => {
281
+ const tools = [
282
+ { ...mockTool, slug: 'first-tool' },
283
+ { ...mockTool, slug: 'second-tool' },
284
+ { ...mockTool, slug: 'third-tool' },
285
+ ];
286
+
287
+ const wrapped = provider.wrapTools(tools, mockExecuteToolFn);
288
+
289
+ expect(Object.keys(wrapped)).toEqual(['first-tool', 'second-tool', 'third-tool']);
290
+ expect(wrapped['first-tool']).toBeDefined();
291
+ expect(wrapped['second-tool']).toBeDefined();
292
+ expect(wrapped['third-tool']).toBeDefined();
293
+ });
294
+
295
+ it('should handle duplicate tool slugs by overwriting', () => {
296
+ const tools = [
297
+ { ...mockTool, slug: 'duplicate-tool', name: 'First Tool' },
298
+ { ...mockTool, slug: 'duplicate-tool', name: 'Second Tool' },
299
+ ];
300
+
301
+ const wrapped = provider.wrapTools(tools, mockExecuteToolFn);
302
+
303
+ expect(Object.keys(wrapped)).toHaveLength(1);
304
+ expect(wrapped['duplicate-tool']).toBeDefined();
305
+ expect(createTool).toHaveBeenCalledTimes(2);
306
+ });
307
+ });
308
+
309
+ describe('executeTool', () => {
310
+ it('should execute a tool using the global execute function', async () => {
311
+ const toolSlug = 'test-tool';
312
+ const toolParams = {
313
+ userId: 'test-user',
314
+ arguments: { input: 'test-value' },
315
+ };
316
+
317
+ const result = await provider.executeTool(toolSlug, toolParams);
318
+
319
+ expect(mockExecuteToolFn).toHaveBeenCalledWith(toolSlug, toolParams, undefined);
320
+ expect(result).toEqual({
321
+ data: { result: 'success' },
322
+ error: null,
323
+ successful: true,
324
+ });
325
+ });
326
+
327
+ it('should pass modifiers to the global execute function', async () => {
328
+ const toolSlug = 'test-tool';
329
+ const toolParams = {
330
+ userId: 'test-user',
331
+ arguments: { input: 'test-value' },
332
+ };
333
+
334
+ const modifiers = {
335
+ beforeExecute: vi.fn(params => params),
336
+ afterExecute: vi.fn(response => response),
337
+ };
338
+
339
+ await provider.executeTool(toolSlug, toolParams, modifiers);
340
+
341
+ expect(mockExecuteToolFn).toHaveBeenCalledWith(toolSlug, toolParams, modifiers);
342
+ });
343
+
344
+ it('should handle execution errors gracefully', async () => {
345
+ const toolSlug = 'test-tool';
346
+ const toolParams = {
347
+ userId: 'test-user',
348
+ arguments: { input: 'test-value' },
349
+ };
350
+
351
+ const errorResponse = {
352
+ data: null,
353
+ error: { message: 'Tool execution failed' },
354
+ successful: false,
355
+ };
356
+
357
+ mockExecuteToolFn.mockResolvedValueOnce(errorResponse);
358
+
359
+ const result = await provider.executeTool(toolSlug, toolParams);
360
+
361
+ expect(result).toEqual(errorResponse);
362
+ });
363
+ });
364
+
365
+ describe('integration with Mastra', () => {
366
+ it('should produce tools compatible with Mastra createTool', () => {
367
+ const wrapped = provider.wrapTool(mockTool, mockExecuteToolFn) as unknown as MockedMastraTool;
368
+
369
+ // Verify the wrapped tool has the expected structure
370
+ expect(wrapped).toHaveProperty('id');
371
+ expect(wrapped).toHaveProperty('description');
372
+ expect(wrapped).toHaveProperty('inputSchema');
373
+ expect(wrapped).toHaveProperty('outputSchema');
374
+ expect(wrapped).toHaveProperty('execute');
375
+
376
+ // The execute property should be a function
377
+ expect(typeof wrapped.execute).toBe('function');
378
+ });
379
+
380
+ it('should create tools with correct id mapping from slug', () => {
381
+ const wrapped = provider.wrapTool(mockTool, mockExecuteToolFn) as unknown as MockedMastraTool;
382
+
383
+ expect(createTool).toHaveBeenCalledWith(
384
+ expect.objectContaining({
385
+ id: mockTool.slug,
386
+ })
387
+ );
388
+ });
389
+
390
+ it('should handle tools without schemas gracefully', () => {
391
+ const minimalTool: Tool = {
392
+ slug: 'minimal-tool',
393
+ name: 'Minimal Tool',
394
+ description: 'A minimal tool',
395
+ tags: [],
396
+ };
397
+
398
+ const wrapped = provider.wrapTool(
399
+ minimalTool,
400
+ mockExecuteToolFn
401
+ ) as unknown as MockedMastraTool;
402
+
403
+ expect(createTool).toHaveBeenCalledWith({
404
+ id: 'minimal-tool',
405
+ description: 'A minimal tool',
406
+ inputSchema: undefined,
407
+ outputSchema: undefined,
408
+ execute: expect.any(Function),
409
+ });
410
+
411
+ expect(wrapped._isMockedMastraTool).toBe(true);
412
+ });
413
+ });
414
+
415
+ describe('error handling', () => {
416
+ it('should handle execution failures in wrapped tools', async () => {
417
+ const errorExecuteToolFn = vi.fn().mockRejectedValue(new Error('Execution failed'));
418
+
419
+ const wrapped = provider.wrapTool(
420
+ mockTool,
421
+ errorExecuteToolFn
422
+ ) as unknown as MockedMastraTool;
423
+ const executeFunction = (createTool as any).mock.calls[0][0].execute;
424
+
425
+ await expect(executeFunction({ context: { input: 'test' } })).rejects.toThrow(
426
+ 'Execution failed'
427
+ );
428
+ });
429
+
430
+ it('should handle tools with malformed schemas', () => {
431
+ const toolWithMalformedSchema: Tool = {
432
+ ...mockTool,
433
+ inputParameters: null as any,
434
+ outputParameters: undefined,
435
+ };
436
+
437
+ expect(() => {
438
+ provider.wrapTool(toolWithMalformedSchema, mockExecuteToolFn);
439
+ }).not.toThrow();
440
+ });
441
+ });
442
+
443
+ describe('type safety', () => {
444
+ it('should maintain correct typing for MastraTool', () => {
445
+ const wrapped = provider.wrapTool(mockTool, mockExecuteToolFn);
446
+
447
+ // Type assertion should work
448
+ expect(wrapped).toBeDefined();
449
+ expect(typeof wrapped).toBe('object');
450
+ });
451
+
452
+ it('should maintain correct typing for MastraToolCollection', () => {
453
+ const tools = [mockTool];
454
+ const wrapped = provider.wrapTools(tools, mockExecuteToolFn);
455
+
456
+ // Should be an object with string keys
457
+ expect(typeof wrapped).toBe('object');
458
+ expect(Array.isArray(wrapped)).toBe(false);
459
+ });
460
+ });
461
+});