1
+import { describe, expect, layer } from '@effect/vitest';
2
+import { ConfigProvider, Effect } from 'effect';
3
+import { extendConfigProvider } from 'src/services/config';
4
+import { cli, TestLive, MockConsole } from 'test/__utils__';
5
+import type { TestLiveInput } from 'test/__utils__/services/test-layer';
6
+import type { Toolkits, ToolkitDetailed } from 'src/models/toolkits';
7
+
8
+const testToolkits: Toolkits = [
9
+ {
10
+ name: 'Gmail',
11
+ slug: 'gmail',
12
+ auth_schemes: ['OAUTH2', 'BEARER_TOKEN'],
13
+ composio_managed_auth_schemes: ['OAUTH2'],
14
+ is_local_toolkit: false,
15
+ no_auth: false,
16
+ meta: {
17
+ description: 'Email service to send and receive emails',
18
+ categories: [],
19
+ created_at: new Date('2024-05-03T11:44:32.061Z') as any,
20
+ updated_at: new Date('2024-05-03T11:44:32.061Z') as any,
21
+ available_versions: [],
22
+ tools_count: 36,
23
+ triggers_count: 2,
24
+ },
25
+ },
26
+];
27
+
28
+const detailedToolkits: ToolkitDetailed[] = [
29
+ {
30
+ name: 'Gmail',
31
+ slug: 'gmail',
32
+ is_local_toolkit: false,
33
+ composio_managed_auth_schemes: ['OAUTH2'],
34
+ no_auth: false,
35
+ meta: {
36
+ description: 'Email service to send and receive emails',
37
+ categories: [],
38
+ created_at: new Date('2024-05-03T11:44:32.061Z') as any,
39
+ updated_at: new Date('2024-05-03T11:44:32.061Z') as any,
40
+ available_versions: [],
41
+ tools_count: 36,
42
+ triggers_count: 2,
43
+ },
44
+ auth_config_details: [
45
+ {
46
+ mode: 'OAUTH2',
47
+ name: 'OAuth 2.0',
48
+ fields: {
49
+ auth_config_creation: { required: [], optional: [] },
50
+ connected_account_initiation: { required: [], optional: [] },
51
+ },
52
+ },
53
+ {
54
+ mode: 'BEARER_TOKEN',
55
+ name: 'Bearer Token',
56
+ fields: {
57
+ auth_config_creation: {
58
+ required: [
59
+ {
60
+ name: 'apiKey',
61
+ displayName: 'API Key',
62
+ description: 'Your API key',
63
+ type: 'string',
64
+ required: true,
65
+ default: null,
66
+ },
67
+ ],
68
+ optional: [],
69
+ },
70
+ connected_account_initiation: {
71
+ required: [
72
+ {
73
+ name: 'apiKey',
74
+ displayName: 'API Key',
75
+ description: 'Your API key',
76
+ type: 'string',
77
+ required: true,
78
+ default: null,
79
+ },
80
+ ],
81
+ optional: [],
82
+ },
83
+ },
84
+ },
85
+ ],
86
+ },
87
+ {
88
+ name: 'Code Interpreter',
89
+ slug: 'codeinterpreter',
90
+ is_local_toolkit: false,
91
+ composio_managed_auth_schemes: [],
92
+ no_auth: true,
93
+ meta: {
94
+ description: 'Execute code snippets',
95
+ categories: [],
96
+ created_at: new Date('2024-05-03T11:44:32.061Z') as any,
97
+ updated_at: new Date('2024-05-03T11:44:32.061Z') as any,
98
+ available_versions: [],
99
+ tools_count: 5,
100
+ triggers_count: 0,
101
+ },
102
+ auth_config_details: [],
103
+ },
104
+];
105
+
106
+const toolkitsData = {
107
+ toolkits: testToolkits,
108
+ detailedToolkits,
109
+} satisfies TestLiveInput['toolkitsData'];
110
+
111
+const testConfigProvider = ConfigProvider.fromMap(
112
+ new Map([['COMPOSIO_API_KEY', 'test_api_key']])
113
+).pipe(extendConfigProvider);
114
+
115
+describe('CLI: composio toolkits info', () => {
116
+ layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
117
+ '[Given] valid slug "gmail"',
118
+ it => {
119
+ it.scoped('shows detailed info with auth schemes', () =>
120
+ Effect.gen(function* () {
121
+ yield* cli(['toolkits', 'info', 'gmail']);
122
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
123
+ const output = lines.join('\n');
124
+
125
+ expect(output).toContain('Gmail');
126
+ expect(output).toContain('gmail');
127
+ expect(output).toContain('Email service to send and receive emails');
128
+ expect(output).toContain('OAUTH2');
129
+ expect(output).toContain('BEARER_TOKEN');
130
+ expect(output).toContain('apiKey');
131
+ expect(output).toContain('AuthConfig creation');
132
+ expect(output).toContain('Connected Account creation');
133
+ })
134
+ );
135
+ }
136
+ );
137
+
138
+ layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
139
+ '[Given] toolkit with no_auth=true',
140
+ it => {
141
+ it.scoped('shows "No authentication required"', () =>
142
+ Effect.gen(function* () {
143
+ yield* cli(['toolkits', 'info', 'codeinterpreter']);
144
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
145
+ const output = lines.join('\n');
146
+
147
+ expect(output).toContain('Code Interpreter');
148
+ expect(output).toContain('No authentication required');
149
+ })
150
+ );
151
+ }
152
+ );
153
+
154
+ layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
155
+ '[Given] invalid slug',
156
+ it => {
157
+ it.scoped('shows error', () =>
158
+ Effect.gen(function* () {
159
+ const result = yield* cli(['toolkits', 'info', 'gmal']).pipe(Effect.either);
160
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
161
+ const output = lines.join('\n');
162
+
163
+ expect(output).toContain('not found');
164
+ })
165
+ );
166
+ }
167
+ );
168
+
169
+ layer(TestLive())('[Given] no API key', it => {
170
+ it.scoped('warns user to login', () =>
171
+ Effect.gen(function* () {
172
+ yield* cli(['toolkits', 'info', 'gmail']);
173
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
174
+ const output = lines.join('\n');
175
+
176
+ expect(output).toContain('not logged in');
177
+ })
178
+ );
179
+ });
180
+});