1
import { describe, expect, layer } from '@effect/vitest';
2
-import { ConfigProvider, Effect } from 'effect';
2
+import { ConfigProvider, Console, Effect } from 'effect';
3
import type { ConnectedAccountItem } from 'src/models/connected-accounts';
4
import { extendConfigProvider } from 'src/services/config';
5
+import { TerminalUI } from 'src/services/terminal-ui';
6
import { ComposioUserContext } from 'src/services/user-context';
7
import { cli, TestLive, MockConsole } from 'test/__utils__';
8
import type { TestLiveInput } from 'test/__utils__/services/test-layer';
88
new Map([['COMPOSIO_USER_API_KEY', 'test_api_key']])
89
).pipe(extendConfigProvider);
90
91
+const terminalUIWithConfirm = (confirmed: boolean) =>
92
+ TerminalUI.of({
93
+ output: data => Console.log(data),
94
+ intro: title => Console.log(`-- ${title} --`),
95
+ outro: message => Console.log(`-- ${message} --`),
96
+ log: {
97
+ info: message => Console.log(message),
98
+ success: message => Console.log(message),
99
+ warn: message => Console.warn(message),
100
+ error: message => Console.error(message),
101
+ step: message => Console.log(message),
102
+ message: message => Console.log(message),
103
+ },
104
+ note: (message, title) => Console.log(title ? `[${title}] ${message}` : message),
105
+ select: (_message, options) => Effect.succeed(options[0]!.value),
106
+ confirm: () => Effect.succeed(confirmed),
107
+ withSpinner: (message, effect, options) =>
108
+ Effect.gen(function* () {
109
+ const result = yield* effect;
110
+ const successMsg =
111
+ typeof options?.successMessage === 'function'
112
+ ? options.successMessage(result)
113
+ : (options?.successMessage ?? message);
114
+ yield* Console.log(successMsg);
115
+ return result;
116
+ }),
117
+ useMakeSpinner: (_message, use) =>
118
+ use({
119
+ message: (_msg: string) => Effect.void,
120
+ stop: (msg?: string) => (msg ? Console.log(msg) : Effect.void),
121
+ error: (msg?: string) => (msg ? Console.error(msg) : Effect.void),
122
+ }),
123
+ });
124
+
125
describe('CLI: composio connections list', () => {
126
layer(TestLive({ baseConfigProvider: testConfigProvider, connectedAccountsData }))(it => {
127
it.scoped('[Given] no filter [Then] prints connection JSON with aliases for duplicates', () =>
234
);
235
});
236
});
237
+
238
+describe('CLI: composio connections remove', () => {
239
+ const confirmedDeleteCalls: string[] = [];
240
+ layer(
241
+ TestLive({
242
+ baseConfigProvider: testConfigProvider,
243
+ connectedAccountsData: {
244
+ items: testConnections,
245
+ onDelete: nanoid => confirmedDeleteCalls.push(nanoid),
246
+ },
247
+ terminalUI: terminalUIWithConfirm(true),
248
+ })
249
+ )(it => {
250
+ it.scoped('[Given] a unique toolkit selector and consent [Then] removes that connection', () =>
251
+ Effect.gen(function* () {
252
+ confirmedDeleteCalls.length = 0;
253
+
254
+ const userContext = yield* ComposioUserContext;
255
+ yield* userContext.login('test_api_key', 'org_test');
256
+ yield* cli(['connections', 'remove', 'gmail']);
257
+
258
+ expect(confirmedDeleteCalls).toEqual(['con_gmail_active']);
259
+
260
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
261
+ expect(lines.join('\n')).toContain('Removed gmail connection.');
262
+ })
263
+ );
264
+ });
265
+
266
+ const deniedDeleteCalls: string[] = [];
267
+ layer(
268
+ TestLive({
269
+ baseConfigProvider: testConfigProvider,
270
+ connectedAccountsData: {
271
+ items: testConnections,
272
+ onDelete: nanoid => deniedDeleteCalls.push(nanoid),
273
+ },
274
+ terminalUI: terminalUIWithConfirm(false),
275
+ })
276
+ )(it => {
277
+ it.scoped('[Given] consent is denied [Then] does not remove the connection', () =>
278
+ Effect.gen(function* () {
279
+ deniedDeleteCalls.length = 0;
280
+
281
+ const userContext = yield* ComposioUserContext;
282
+ yield* userContext.login('test_api_key', 'org_test');
283
+ yield* cli(['connections', 'remove', 'work']);
284
+
285
+ expect(deniedDeleteCalls).toEqual([]);
286
+
287
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
288
+ expect(lines.join('\n')).toContain('No connection removed.');
289
+ })
290
+ );
291
+ });
292
+
293
+ const ambiguousDeleteCalls: string[] = [];
294
+ layer(
295
+ TestLive({
296
+ baseConfigProvider: testConfigProvider,
297
+ connectedAccountsData: {
298
+ items: testConnections,
299
+ onDelete: nanoid => ambiguousDeleteCalls.push(nanoid),
300
+ },
301
+ terminalUI: terminalUIWithConfirm(true),
302
+ })
303
+ )(it => {
304
+ it.scoped(
305
+ '[Given] a selector matches multiple accounts [Then] asks for a unique selector',
306
+ () =>
307
+ Effect.gen(function* () {
308
+ ambiguousDeleteCalls.length = 0;
309
+
310
+ const userContext = yield* ComposioUserContext;
311
+ yield* userContext.login('test_api_key', 'org_test');
312
+ yield* cli(['connections', 'remove', 'github']);
313
+
314
+ expect(ambiguousDeleteCalls).toEqual([]);
315
+
316
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
317
+ expect(lines.join('\n')).toContain('Multiple connections matched "github"');
318
+ })
319
+ );
320
+ });
321
+});