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, 04:45 UTC
| 1 | import { assert, describe, expect, layer } from '@effect/vitest'; |
| 2 | import { isUsageFailure } from 'src/commands/errors'; |
| 3 | import { ConfigProvider, Effect } from 'effect'; |
| 4 | import { cli, TestLive, MockConsole } from 'test/__utils__'; |
| 5 | import { exitCodeOf } from 'test/__utils__/exit-code'; |
| 6 | import type { TestLiveInput } from 'test/__utils__/services/test-layer'; |
| 7 | import type { Tools } from 'src/models/tools'; |
| 8 | |
| 9 | const testTools: Tools = [ |
| 10 | { |
| 11 | name: 'Send Email', |
| 12 | slug: 'GMAIL_SEND_EMAIL', |
| 13 | description: 'Sends an email to a recipient using Gmail', |
| 14 | tags: ['messaging', 'email'], |
| 15 | available_versions: ['20260101_00'], |
| 16 | input_parameters: { |
| 17 | type: 'object', |
| 18 | properties: { |
| 19 | recipient: { type: 'string', description: 'Email address of recipient' }, |
| 20 | subject: { type: 'string', description: 'Email subject line' }, |
| 21 | body: { type: 'string', description: 'Email body content' }, |
| 22 | cc: { type: 'string', description: 'CC recipients' }, |
| 23 | }, |
| 24 | required: ['recipient', 'subject', 'body'], |
| 25 | }, |
| 26 | output_parameters: { |
| 27 | type: 'object', |
| 28 | properties: { |
| 29 | message_id: { type: 'string', description: 'Unique message identifier' }, |
| 30 | status: { type: 'string', description: 'Delivery status' }, |
| 31 | }, |
| 32 | }, |
| 33 | }, |
| 34 | { |
| 35 | name: 'Create Draft', |
| 36 | slug: 'GMAIL_CREATE_DRAFT', |
| 37 | description: 'Creates a draft email in Gmail', |
| 38 | tags: ['messaging', 'email'], |
| 39 | available_versions: ['20260101_00'], |
| 40 | input_parameters: { type: 'object', properties: {} }, |
| 41 | output_parameters: { type: 'object', properties: {} }, |
| 42 | }, |
| 43 | { |
| 44 | name: 'Slack Upload', |
| 45 | slug: 'SLACK_UPLOAD_OR_CREATE_A_FILE_IN_SLACK', |
| 46 | description: 'Uploads a file to Slack', |
| 47 | tags: ['files', 'slack'], |
| 48 | available_versions: ['20260101_00'], |
| 49 | input_parameters: { |
| 50 | type: 'object', |
| 51 | properties: { |
| 52 | channels: { type: 'string', description: 'Slack channel ID' }, |
| 53 | file: { |
| 54 | type: 'object', |
| 55 | file_uploadable: true, |
| 56 | title: 'File', |
| 57 | description: 'Local file accepted by CLI', |
| 58 | properties: { |
| 59 | name: { type: 'string' }, |
| 60 | mimetype: { type: 'string' }, |
| 61 | s3key: { type: 'string' }, |
| 62 | }, |
| 63 | required: ['name', 'mimetype', 's3key'], |
| 64 | }, |
| 65 | }, |
| 66 | }, |
| 67 | output_parameters: { type: 'object', properties: {} }, |
| 68 | }, |
| 69 | ]; |
| 70 | |
| 71 | const toolkitsData = { |
| 72 | tools: testTools, |
| 73 | } satisfies TestLiveInput['toolkitsData']; |
| 74 | |
| 75 | const testConfigProvider = ConfigProvider.fromEnv({ |
| 76 | env: { COMPOSIO_USER_API_KEY: 'test_api_key' }, |
| 77 | }); |
| 78 | |
| 79 | describe('CLI: composio tools info', () => { |
| 80 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 81 | '[Given] valid slug [Then] displays tool info', |
| 82 | it => { |
| 83 | it.effect('shows brief tool details and cached schema path', () => |
| 84 | Effect.gen(function* () { |
| 85 | yield* cli(['tools', 'info', 'GMAIL_SEND_EMAIL']); |
| 86 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 87 | const output = lines.join('\n'); |
| 88 | |
| 89 | expect(output).toContain('Send Email'); |
| 90 | expect(output).toContain('GMAIL_SEND_EMAIL'); |
| 91 | expect(output).toContain('Schema Cache'); |
| 92 | expect(output).toContain('/tool_definitions/GMAIL_SEND_EMAIL.json'); |
| 93 | expect(output).toContain( |
| 94 | "jq '{required: (.inputSchema.required // []), keys: (.inputSchema.properties | keys)}'" |
| 95 | ); |
| 96 | expect(output).toContain('composio execute "GMAIL_SEND_EMAIL" -d'); |
| 97 | expect(output).toContain('--dry-run'); |
| 98 | }) |
| 99 | ); |
| 100 | } |
| 101 | ); |
| 102 | |
| 103 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 104 | '[Given] file_uploadable tool info [Then] it shows the CLI-facing file schema', |
| 105 | it => { |
| 106 | it.effect('renders file inputs as path strings in JSON output', () => |
| 107 | Effect.gen(function* () { |
| 108 | yield* cli(['tools', 'info', 'SLACK_UPLOAD_OR_CREATE_A_FILE_IN_SLACK']); |
| 109 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 110 | const output = JSON.parse(String(lines.at(-1))) as { |
| 111 | inputSchema: Record<string, unknown>; |
| 112 | }; |
| 113 | |
| 114 | expect(output.inputSchema).toEqual({ |
| 115 | type: 'object', |
| 116 | properties: { |
| 117 | channels: { type: 'string', description: 'Slack channel ID' }, |
| 118 | file: { |
| 119 | title: 'File', |
| 120 | description: 'Local file accepted by CLI', |
| 121 | format: 'path', |
| 122 | type: 'string', |
| 123 | file_uploadable: true, |
| 124 | }, |
| 125 | }, |
| 126 | }); |
| 127 | }) |
| 128 | ); |
| 129 | } |
| 130 | ); |
| 131 | |
| 132 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 133 | '[Given] no slug [Then] fails with a usage error', |
| 134 | it => { |
| 135 | it.effect('raises a CommandInputError naming <slug>', () => |
| 136 | Effect.gen(function* () { |
| 137 | const failure = yield* cli(['tools', 'info']).pipe(Effect.flip); |
| 138 | |
| 139 | expect(failure).toMatchObject({ |
| 140 | _tag: 'commands/CommandInputError', |
| 141 | option: '<slug>', |
| 142 | message: expect.stringContaining('Missing required argument: <slug>'), |
| 143 | }); |
| 144 | // The invocation prints the message on stderr, and nothing else. |
| 145 | assert(isUsageFailure(failure)); |
| 146 | expect(yield* MockConsole.getLines()).toEqual([failure.message]); |
| 147 | }) |
| 148 | ); |
| 149 | } |
| 150 | ); |
| 151 | |
| 152 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 153 | '[Given] invalid slug [Then] shows error and suggestions', |
| 154 | it => { |
| 155 | it.effect('shows not found with suggestions', () => |
| 156 | Effect.gen(function* () { |
| 157 | yield* Effect.exit(cli(['tools', 'info', 'NONEXISTENT_TOOL'])); |
| 158 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 159 | const output = lines.join('\n'); |
| 160 | |
| 161 | expect(output).toContain('not found'); |
| 162 | }) |
| 163 | ); |
| 164 | |
| 165 | it.effect('exits non-zero and reports the missing tool', () => |
| 166 | Effect.gen(function* () { |
| 167 | const exit = yield* Effect.exit(cli(['tools', 'info', 'NONEXISTENT_TOOL'])); |
| 168 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 169 | |
| 170 | expect(lines.join('\n')).toContain('Tool "NONEXISTENT_TOOL" not found.'); |
| 171 | expect(exitCodeOf(exit)).toBe(1); |
| 172 | }) |
| 173 | ); |
| 174 | |
| 175 | it.effect('keeps a zero exit code for a valid slug', () => |
| 176 | Effect.gen(function* () { |
| 177 | const exit = yield* Effect.exit(cli(['tools', 'info', 'GMAIL_SEND_EMAIL'])); |
| 178 | |
| 179 | expect(exitCodeOf(exit)).toBe(0); |
| 180 | }) |
| 181 | ); |
| 182 | } |
| 183 | ); |
| 184 | |
| 185 | layer(TestLive())('[Given] no API key [Then] warns user to login', it => { |
| 186 | it.effect('warns user to login', () => |
| 187 | Effect.gen(function* () { |
| 188 | const error = yield* cli(['tools', 'info', 'GMAIL_SEND_EMAIL']).pipe(Effect.flip); |
| 189 | expect(error).toMatchObject({ _tag: 'commands/NotLoggedInError' }); |
| 190 | }) |
| 191 | ); |
| 192 | }); |
| 193 | }); |