@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, 04:45 UTC

next
ts 161 lines 5.38 KB
Raw
1 /**
2 * CLI `composio dev toolkits info` e2e test
3 *
4 * Verifies that the info subcommand returns detailed toolkit JSON in piped mode,
5 * reports an invalid or missing slug on stderr with exit 1, and supports stdout redirection.
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 redirectResult: E2ETestResultWithFiles<'out.json'>;
30 let invalidResult: E2ETestResult;
31 let missingSlugResult: 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-info',
39 'COMPOSIO_USER_API_KEY=uak_mock_toolkits_info',
40 ].join(' ');
41
42 validResult = await runCmd(`${envPrefix} composio dev toolkits info gmail`);
43 redirectResult = await runCmd({
44 command: `${envPrefix} composio dev toolkits info gmail > out.json`,
45 files: ['out.json'],
46 });
47 invalidResult = await runCmd(
48 `${envPrefix} composio dev toolkits info nonexistent_toolkit_xyz12345`
49 );
50 missingSlugResult = await runCmd(`${envPrefix} composio dev toolkits info`);
51 }, TIMEOUTS.FIXTURE);
52
53 afterAll(async () => {
54 await server.close();
55 });
56
57 describe('composio dev toolkits info gmail (valid slug)', () => {
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 valid JSON object', () => {
67 const obj = parseJsonStdout(validResult);
68 expect(typeof obj).toBe('object');
69 expect(Array.isArray(obj)).toBe(false);
70 });
71
72 it('has the correct name and slug', () => {
73 const obj = parseJsonStdout(validResult) as Record<string, unknown>;
74 expect(obj.name).toBe('Gmail');
75 expect(obj.slug).toBe('gmail');
76 });
77
78 it('has meta with description and logo', () => {
79 const obj = parseJsonStdout(validResult) as Record<string, Record<string, unknown>>;
80 expect(obj.meta).toHaveProperty('description');
81 expect(typeof obj.meta.description).toBe('string');
82 expect(obj.meta).toHaveProperty('logo');
83 });
84
85 it('has is_no_auth and enabled', () => {
86 const obj = parseJsonStdout(validResult) as Record<string, unknown>;
87 expect(typeof obj.is_no_auth).toBe('boolean');
88 expect(typeof obj.enabled).toBe('boolean');
89 });
90
91 it('has composio_managed_auth_schemes array', () => {
92 const obj = parseJsonStdout(validResult) as Record<string, unknown>;
93 expect(Array.isArray(obj.composio_managed_auth_schemes)).toBe(true);
94 });
95
96 it('has connected_account (object or null)', () => {
97 const obj = parseJsonStdout(validResult) as Record<string, unknown>;
98 expect(obj).toHaveProperty('connected_account');
99 });
100 });
101
102 describe('composio dev toolkits info gmail > out.json (stdout redirection)', () => {
103 it('exits successfully', () => {
104 expect(redirectResult.exitCode).toBe(0);
105 });
106
107 it('stdout is empty', () => {
108 expect(redirectResult.stdout).toBe('');
109 });
110
111 it('stderr is empty', () => {
112 expect(redirectResult.stderr).toBe('');
113 });
114
115 it('out.json contains valid JSON with slug "gmail"', () => {
116 const content = redirectResult.files['out.json'];
117 const obj = JSON.parse(sanitizeOutput(content));
118 expect(obj.slug).toBe('gmail');
119 });
120 });
121
122 describe('composio dev toolkits info nonexistent_toolkit_xyz12345 (invalid slug)', () => {
123 it('exits 1', () => {
124 expect(invalidResult.exitCode).toBe(1);
125 });
126
127 it('stdout is empty (no data on error)', () => {
128 expect(sanitizeOutput(invalidResult.stdout)).toBe('');
129 });
130
131 it('stderr names the toolkit and the browse hint as plain lines', () => {
132 expect(invalidResult.stderr).toBe(
133 'Toolkit "nonexistent_toolkit_xyz12345" not found.\nBrowse available toolkits:\n> composio dev toolkits list\n'
134 );
135 });
136 });
137
138 describe('composio dev toolkits info (missing slug)', () => {
139 it('exits 1 (usage error)', () => {
140 expect(missingSlugResult.exitCode).toBe(1);
141 });
142
143 it('stdout is empty', () => {
144 expect(sanitizeOutput(missingSlugResult.stdout)).toBe('');
145 });
146
147 it('stderr asks for the slug with an example', () => {
148 expect(missingSlugResult.stderr).toBe(
149 'Missing required argument: <slug>\nTry specifying a toolkit slug, e.g.:\n> composio dev toolkits info "gmail"\n'
150 );
151 });
152 });
153
154 describe('mock API usage', () => {
155 it('requests the detailed toolkit route for known and unknown slugs', () => {
156 expect(server.requests).toContain('GET /api/v3.1/toolkits/gmail');
157 expect(server.requests).toContain('GET /api/v3.1/toolkits/nonexistent_toolkit_xyz12345');
158 });
159 });
160 },
161 });