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 | /** |
| 2 | * CLI `composio dev toolkits search` e2e test |
| 3 | * |
| 4 | * Verifies that the search subcommand returns matching toolkits as JSON in piped mode, |
| 5 | * respects --limit, supports stdout redirection, and handles no-result queries. |
| 6 | */ |
| 7 | |
| 8 | import { |
| 9 | e2e, |
| 10 | sanitizeOutput, |
| 11 | parseJsonStdout, |
| 12 | type E2ETestResult, |
| 13 | type E2ETestResultWithFiles, |
| 14 | } from '@e2e-tests/utils'; |
| 15 | import { TIMEOUTS } from '@e2e-tests/utils/const'; |
| 16 | import { afterAll, beforeAll, describe, expect, it } from 'bun:test'; |
| 17 | import { |
| 18 | startMockToolkitsListServer, |
| 19 | type MockToolkitsServer, |
| 20 | } from '../../../../packages/cli/scripts/mock-toolkits-server'; |
| 21 | |
| 22 | e2e(import.meta.url, { |
| 23 | versions: { |
| 24 | cli: ['current'], |
| 25 | }, |
| 26 | defineTests: ({ runCmd }) => { |
| 27 | let server: MockToolkitsServer; |
| 28 | let validResult: E2ETestResult; |
| 29 | let limitResult: E2ETestResult; |
| 30 | let redirectResult: E2ETestResultWithFiles<'out.json'>; |
| 31 | let noResultsResult: E2ETestResult; |
| 32 | |
| 33 | beforeAll(async () => { |
| 34 | server = await startMockToolkitsListServer(); |
| 35 | |
| 36 | const envPrefix = [ |
| 37 | `COMPOSIO_BASE_URL=${server.dockerBaseUrl}`, |
| 38 | 'COMPOSIO_CACHE_DIR=/tmp/composio-toolkits-search', |
| 39 | 'COMPOSIO_USER_API_KEY=uak_mock_toolkits_search', |
| 40 | ].join(' '); |
| 41 | |
| 42 | validResult = await runCmd(`${envPrefix} composio dev toolkits search gmail`); |
| 43 | limitResult = await runCmd(`${envPrefix} composio dev toolkits search gmail --limit 1`); |
| 44 | redirectResult = await runCmd({ |
| 45 | command: `${envPrefix} composio dev toolkits search gmail --limit 1 > out.json`, |
| 46 | files: ['out.json'], |
| 47 | }); |
| 48 | noResultsResult = await runCmd( |
| 49 | `${envPrefix} composio dev toolkits search xyznonexistent_abc_12345` |
| 50 | ); |
| 51 | }, TIMEOUTS.FIXTURE); |
| 52 | |
| 53 | afterAll(async () => { |
| 54 | await server.close(); |
| 55 | }); |
| 56 | |
| 57 | describe('composio dev toolkits search gmail (known query)', () => { |
| 58 | it('exits successfully', () => { |
| 59 | expect(validResult.exitCode).toBe(0); |
| 60 | }); |
| 61 | |
| 62 | it('stderr is empty', () => { |
| 63 | expect(validResult.stderr).toBe(''); |
| 64 | }); |
| 65 | |
| 66 | it('stdout is a JSON array with at least 1 element', () => { |
| 67 | const items = parseJsonStdout(validResult); |
| 68 | expect(Array.isArray(items)).toBe(true); |
| 69 | expect((items as Array<unknown>).length).toBeGreaterThanOrEqual(1); |
| 70 | }); |
| 71 | |
| 72 | it('first element has slug "gmail"', () => { |
| 73 | const items = parseJsonStdout(validResult) as Array<{ slug: string }>; |
| 74 | expect(items[0].slug).toBe('gmail'); |
| 75 | }); |
| 76 | |
| 77 | it('each element has the expected shape', () => { |
| 78 | const items = parseJsonStdout(validResult) as Array<Record<string, unknown>>; |
| 79 | for (const item of items) { |
| 80 | expect(item).toHaveProperty('name'); |
| 81 | expect(item).toHaveProperty('slug'); |
| 82 | expect(item).toHaveProperty('tools_count'); |
| 83 | expect(item).toHaveProperty('triggers_count'); |
| 84 | expect(item).toHaveProperty('description'); |
| 85 | } |
| 86 | }); |
| 87 | }); |
| 88 | |
| 89 | describe('composio dev toolkits search gmail --limit 1 (with limit)', () => { |
| 90 | it('exits successfully', () => { |
| 91 | expect(limitResult.exitCode).toBe(0); |
| 92 | }); |
| 93 | |
| 94 | it('stderr is empty', () => { |
| 95 | expect(limitResult.stderr).toBe(''); |
| 96 | }); |
| 97 | |
| 98 | it('stdout is a JSON array with exactly 1 element', () => { |
| 99 | const items = parseJsonStdout(limitResult); |
| 100 | expect(Array.isArray(items)).toBe(true); |
| 101 | expect(items as Array<unknown>).toHaveLength(1); |
| 102 | }); |
| 103 | |
| 104 | it('the element has slug "gmail"', () => { |
| 105 | const items = parseJsonStdout(limitResult) as Array<{ slug: string }>; |
| 106 | expect(items[0].slug).toBe('gmail'); |
| 107 | }); |
| 108 | }); |
| 109 | |
| 110 | describe('composio dev toolkits search gmail --limit 1 > out.json (stdout redirection)', () => { |
| 111 | it('exits successfully', () => { |
| 112 | expect(redirectResult.exitCode).toBe(0); |
| 113 | }); |
| 114 | |
| 115 | it('stdout is empty', () => { |
| 116 | expect(redirectResult.stdout).toBe(''); |
| 117 | }); |
| 118 | |
| 119 | it('stderr is empty', () => { |
| 120 | expect(redirectResult.stderr).toBe(''); |
| 121 | }); |
| 122 | |
| 123 | it('out.json contains a JSON array with slug "gmail"', () => { |
| 124 | const items = JSON.parse(sanitizeOutput(redirectResult.files['out.json'])); |
| 125 | expect(Array.isArray(items)).toBe(true); |
| 126 | expect(items).toHaveLength(1); |
| 127 | expect(items[0].slug).toBe('gmail'); |
| 128 | }); |
| 129 | }); |
| 130 | |
| 131 | describe('composio dev toolkits search xyznonexistent_abc_12345 (no results)', () => { |
| 132 | it('exits successfully', () => { |
| 133 | expect(noResultsResult.exitCode).toBe(0); |
| 134 | }); |
| 135 | |
| 136 | it('stderr is empty', () => { |
| 137 | expect(noResultsResult.stderr).toBe(''); |
| 138 | }); |
| 139 | |
| 140 | it('stdout is an empty JSON array (no results)', () => { |
| 141 | expect(sanitizeOutput(noResultsResult.stdout)).toBe('[]'); |
| 142 | }); |
| 143 | }); |
| 144 | |
| 145 | describe('mock API usage', () => { |
| 146 | it('requests the toolkit catalog for each search scenario', () => { |
| 147 | expect(server.requests).toContain('GET /api/v3.1/toolkits?search=gmail&limit=10'); |
| 148 | expect(server.requests).toContain('GET /api/v3.1/toolkits?search=gmail&limit=1'); |
| 149 | expect(server.requests).toContain( |
| 150 | 'GET /api/v3.1/toolkits?search=xyznonexistent_abc_12345&limit=10' |
| 151 | ); |
| 152 | }); |
| 153 | }); |
| 154 | }, |
| 155 | }); |