Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { describe, expect, layer } from '@effect/vitest'; |
| 2 | import { ConfigProvider, DateTime, Effect, Layer } from 'effect'; |
| 3 | import { cli, TestLive, MockConsole } from 'test/__utils__'; |
| 4 | import type { TestLiveInput } from 'test/__utils__/services/test-layer'; |
| 5 | import type { Toolkits } from 'src/models/toolkits'; |
| 6 | import { ComposioToolkitsRepository } from 'src/services/composio-clients'; |
| 7 | import { notFoundError } from 'test/__utils__/layers/not-found'; |
| 8 | import { exitCodeOf } from 'test/__utils__/exit-code'; |
| 9 | import { redirectedTerminalUI } from 'test/__utils__/services/redirected-terminal-ui'; |
| 10 | import { makeToolkitsRepositoryStub } from 'test/__utils__/services/toolkits-repository-stub'; |
| 11 | |
| 12 | const testToolkits: Toolkits = [ |
| 13 | { |
| 14 | name: 'Gmail', |
| 15 | slug: 'gmail', |
| 16 | auth_schemes: ['OAUTH2'], |
| 17 | composio_managed_auth_schemes: ['OAUTH2'], |
| 18 | is_local_toolkit: false, |
| 19 | no_auth: false, |
| 20 | meta: { |
| 21 | description: 'Email service to send and receive emails', |
| 22 | categories: [], |
| 23 | created_at: DateTime.makeUnsafe('2024-05-03T11:44:32.061Z'), |
| 24 | updated_at: DateTime.makeUnsafe('2024-05-03T11:44:32.061Z'), |
| 25 | available_versions: ['20250909'], |
| 26 | tools_count: 36, |
| 27 | triggers_count: 2, |
| 28 | }, |
| 29 | }, |
| 30 | { |
| 31 | name: 'Outlook', |
| 32 | slug: 'outlook', |
| 33 | auth_schemes: ['OAUTH2'], |
| 34 | composio_managed_auth_schemes: ['OAUTH2'], |
| 35 | is_local_toolkit: false, |
| 36 | no_auth: false, |
| 37 | meta: { |
| 38 | description: 'Microsoft email service', |
| 39 | categories: [], |
| 40 | created_at: DateTime.makeUnsafe('2024-05-03T11:44:32.061Z'), |
| 41 | updated_at: DateTime.makeUnsafe('2024-05-03T11:44:32.061Z'), |
| 42 | available_versions: [], |
| 43 | tools_count: 28, |
| 44 | triggers_count: 1, |
| 45 | }, |
| 46 | }, |
| 47 | { |
| 48 | name: 'Slack', |
| 49 | slug: 'slack', |
| 50 | auth_schemes: ['OAUTH2'], |
| 51 | composio_managed_auth_schemes: ['OAUTH2'], |
| 52 | is_local_toolkit: false, |
| 53 | no_auth: false, |
| 54 | meta: { |
| 55 | description: 'Messaging platform for teams', |
| 56 | categories: [], |
| 57 | created_at: DateTime.makeUnsafe('2024-05-03T11:44:32.061Z'), |
| 58 | updated_at: DateTime.makeUnsafe('2024-05-03T11:44:32.061Z'), |
| 59 | available_versions: ['20250101', '20260101'], |
| 60 | tools_count: 42, |
| 61 | triggers_count: 5, |
| 62 | }, |
| 63 | }, |
| 64 | ]; |
| 65 | |
| 66 | const toolkitsData = { |
| 67 | toolkits: testToolkits, |
| 68 | } satisfies TestLiveInput['toolkitsData']; |
| 69 | |
| 70 | const testConfigProvider = ConfigProvider.fromEnv({ |
| 71 | env: { COMPOSIO_USER_API_KEY: 'test_api_key' }, |
| 72 | }); |
| 73 | |
| 74 | describe('CLI: composio dev toolkits search', () => { |
| 75 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 76 | '[Given] query "email"', |
| 77 | it => { |
| 78 | it.effect('shows matching toolkits', () => |
| 79 | Effect.gen(function* () { |
| 80 | yield* cli(['dev', 'toolkits', 'search', 'email']); |
| 81 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 82 | const output = lines.join('\n'); |
| 83 | |
| 84 | expect(output).toContain('Gmail'); |
| 85 | expect(output).toContain('Outlook'); |
| 86 | expect(output).not.toContain('Slack'); |
| 87 | expect(output).toContain('Found 2 of 2 toolkits'); |
| 88 | }) |
| 89 | ); |
| 90 | } |
| 91 | ); |
| 92 | |
| 93 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 94 | '[Given] query with no results', |
| 95 | it => { |
| 96 | it.effect('shows "No toolkits found"', () => |
| 97 | Effect.gen(function* () { |
| 98 | yield* cli(['dev', 'toolkits', 'search', 'xyzzy']); |
| 99 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 100 | const output = lines.join('\n'); |
| 101 | |
| 102 | expect(output).toContain('No toolkits found'); |
| 103 | }) |
| 104 | ); |
| 105 | } |
| 106 | ); |
| 107 | |
| 108 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 109 | '[Given] --limit 1', |
| 110 | it => { |
| 111 | it.effect('respects limit', () => |
| 112 | Effect.gen(function* () { |
| 113 | yield* cli(['dev', 'toolkits', 'search', 'email', '--limit', '1']); |
| 114 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 115 | const output = lines.join('\n'); |
| 116 | |
| 117 | expect(output).toContain('Found 1 of 2 toolkits'); |
| 118 | }) |
| 119 | ); |
| 120 | } |
| 121 | ); |
| 122 | |
| 123 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 124 | '[Given] query "email" and --limit 0 [Then] the limit is clamped to 1', |
| 125 | it => { |
| 126 | it.effect('requests one toolkit and writes the rows as JSON to stdout', () => |
| 127 | Effect.gen(function* () { |
| 128 | yield* cli(['dev', 'toolkits', 'search', 'email', '--limit', '0']); |
| 129 | const stderr = yield* MockConsole.getLines({ stripAnsi: true, stream: 'stderr' }); |
| 130 | const stdout = yield* MockConsole.getLines({ stripAnsi: true, stream: 'stdout' }); |
| 131 | |
| 132 | expect(stderr.join('\n')).toContain('Found 1 of 2 toolkits'); |
| 133 | expect(stderr.join('\n')).toContain( |
| 134 | 'To view details:\n> composio dev toolkits info "gmail"' |
| 135 | ); |
| 136 | expect(stdout).toHaveLength(1); |
| 137 | expect(JSON.parse(String(stdout[0]))).toEqual([ |
| 138 | expect.objectContaining({ slug: 'gmail', latest_version: '20250909', connected: null }), |
| 139 | ]); |
| 140 | }) |
| 141 | ); |
| 142 | } |
| 143 | ); |
| 144 | |
| 145 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 146 | '[Given] the search request fails', |
| 147 | it => { |
| 148 | it.effect('[Then] prints the error, writes `[]` to stdout and exits 1', () => |
| 149 | Effect.gen(function* () { |
| 150 | const repository = Layer.succeed( |
| 151 | ComposioToolkitsRepository, |
| 152 | makeToolkitsRepositoryStub({ |
| 153 | searchToolkits: () => Effect.fail(notFoundError('Search unavailable')), |
| 154 | }) |
| 155 | ); |
| 156 | // Redirected streams, as under a script: only plain stderr lines and stdout data show. |
| 157 | const terminal = redirectedTerminalUI(); |
| 158 | const exit = yield* Effect.exit( |
| 159 | cli(['dev', 'toolkits', 'search', 'email']).pipe( |
| 160 | Effect.provide(Layer.mergeAll(repository, terminal.layer)) |
| 161 | ) |
| 162 | ); |
| 163 | |
| 164 | expect(terminal.stderr()).toBe('Search unavailable\n'); |
| 165 | expect(terminal.stdout()).toBe('[]\n'); |
| 166 | expect(exitCodeOf(exit)).toBe(1); |
| 167 | }) |
| 168 | ); |
| 169 | } |
| 170 | ); |
| 171 | |
| 172 | layer(TestLive())('[Given] no API key', it => { |
| 173 | it.effect('warns user to login', () => |
| 174 | Effect.gen(function* () { |
| 175 | const error = yield* cli(['dev', 'toolkits', 'search', 'email']).pipe(Effect.flip); |
| 176 | expect(error).toMatchObject({ _tag: 'commands/NotLoggedInError' }); |
| 177 | }) |
| 178 | ); |
| 179 | }); |
| 180 | }); |