@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
md 72 lines 2.53 KB
Rendered Raw
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.