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 { describe, expect, it } from '@effect/vitest'; |
| 2 | import { ConfigProvider, Effect, Layer, Option } from 'effect'; |
| 3 | import { isUsageFailure } from 'src/commands/errors'; |
| 4 | import { runToolsInfo } from 'src/commands/tools/info/tools.info.handler'; |
| 5 | import { |
| 6 | MISSING_SLUG_HINT, |
| 7 | MISSING_SLUG_MESSAGE, |
| 8 | toolNotFoundMessage, |
| 9 | } from 'src/commands/tools/info/tools.info.format'; |
| 10 | import type { Tools } from 'src/models/tools'; |
| 11 | import { ComposioToolkitsRepository } from 'src/services/composio-clients'; |
| 12 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 13 | import { MockConsole, TestLive } from 'test/__utils__'; |
| 14 | import { exitCodeOf } from 'test/__utils__/exit-code'; |
| 15 | import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test'; |
| 16 | import { makeToolkitsRepositoryStub } from 'test/__utils__/services/toolkits-repository-stub'; |
| 17 | |
| 18 | const TOOLS: Tools = [ |
| 19 | { |
| 20 | name: 'Send Email', |
| 21 | slug: 'GMAIL_SEND_EMAIL', |
| 22 | description: 'Sends an email', |
| 23 | tags: ['email'], |
| 24 | available_versions: ['20260101_00'], |
| 25 | input_parameters: { |
| 26 | type: 'object', |
| 27 | properties: { recipient: { type: 'string' } }, |
| 28 | required: ['recipient'], |
| 29 | }, |
| 30 | output_parameters: { type: 'object', properties: {} }, |
| 31 | }, |
| 32 | ]; |
| 33 | |
| 34 | /** |
| 35 | * The `TestLive` stack with the tool catalog above and a terminal whose stdout data lands in |
| 36 | * `outputs`; `runToolsInfo` is called without argv. |
| 37 | */ |
| 38 | const toolsInfoTest = () => { |
| 39 | const outputs: Array<string> = []; |
| 40 | const layer = TestLive({ |
| 41 | baseConfigProvider: ConfigProvider.fromEnv({ |
| 42 | env: { COMPOSIO_USER_API_KEY: 'test_api_key' }, |
| 43 | }), |
| 44 | toolkitsData: { tools: TOOLS }, |
| 45 | terminalUI: TerminalUI.of({ |
| 46 | ...terminalUITestImpl, |
| 47 | output: data => |
| 48 | Effect.sync(() => { |
| 49 | outputs.push(data); |
| 50 | }), |
| 51 | }), |
| 52 | }); |
| 53 | return { layer, outputs }; |
| 54 | }; |
| 55 | |
| 56 | describe('runToolsInfo', () => { |
| 57 | it.effect('[Given] no slug [Then] fails with a usage error before any request', () => { |
| 58 | const { layer, outputs } = toolsInfoTest(); |
| 59 | return Effect.gen(function* () { |
| 60 | const failure = yield* runToolsInfo({ slug: Option.none() }).pipe( |
| 61 | // Every repository method dies, so reaching the API fails the test. |
| 62 | Effect.provide(Layer.succeed(ComposioToolkitsRepository, makeToolkitsRepositoryStub({}))), |
| 63 | Effect.flip |
| 64 | ); |
| 65 | |
| 66 | expect(failure).toMatchObject({ |
| 67 | _tag: 'commands/CommandInputError', |
| 68 | command: 'tools info', |
| 69 | option: '<slug>', |
| 70 | message: `${MISSING_SLUG_MESSAGE}\n${MISSING_SLUG_HINT}`, |
| 71 | }); |
| 72 | // The invocation prints a usage failure on stderr and exits 1. |
| 73 | expect(isUsageFailure(failure)).toBe(true); |
| 74 | expect(yield* MockConsole.getLines()).toEqual([]); |
| 75 | expect(outputs).toEqual([]); |
| 76 | }).pipe(Effect.provide(layer)); |
| 77 | }); |
| 78 | |
| 79 | it.effect('[Given] a known slug [Then] prints the tool and its cached input schema', () => { |
| 80 | const { layer, outputs } = toolsInfoTest(); |
| 81 | return Effect.gen(function* () { |
| 82 | yield* runToolsInfo({ slug: Option.some('GMAIL_SEND_EMAIL') }); |
| 83 | |
| 84 | expect(outputs).toHaveLength(1); |
| 85 | const printed = JSON.parse(outputs[0] ?? '{}') as Record<string, unknown>; |
| 86 | expect(Object.keys(printed)).toEqual([ |
| 87 | 'slug', |
| 88 | 'name', |
| 89 | 'description', |
| 90 | 'toolkit', |
| 91 | 'version', |
| 92 | 'schemaPath', |
| 93 | 'inputSchema', |
| 94 | ]); |
| 95 | expect(printed).toMatchObject({ |
| 96 | slug: 'GMAIL_SEND_EMAIL', |
| 97 | name: 'Send Email', |
| 98 | description: 'Sends an email', |
| 99 | toolkit: 'gmail', |
| 100 | inputSchema: TOOLS[0]?.input_parameters, |
| 101 | }); |
| 102 | expect(printed.schemaPath).toMatch(/\/tool_definitions\/GMAIL_SEND_EMAIL\.json$/); |
| 103 | }).pipe(Effect.provide(layer)); |
| 104 | }); |
| 105 | |
| 106 | it.effect( |
| 107 | '[Given] an unknown slug [Then] reports it with suggestions, prints nothing, and exits 1', |
| 108 | () => { |
| 109 | const { layer, outputs } = toolsInfoTest(); |
| 110 | return Effect.gen(function* () { |
| 111 | const exit = yield* Effect.exit(runToolsInfo({ slug: Option.some('GMAIL_SEND') })); |
| 112 | const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n'); |
| 113 | |
| 114 | expect(output).toContain(toolNotFoundMessage('GMAIL_SEND')); |
| 115 | expect(output).toContain('> composio tools info "GMAIL_SEND_EMAIL"'); |
| 116 | expect(outputs).toEqual([]); |
| 117 | expect(exitCodeOf(exit)).toBe(1); |
| 118 | }).pipe(Effect.provide(layer)); |
| 119 | } |
| 120 | ); |
| 121 | }); |