@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 166 lines 5.63 KB
Raw
1 import { assert, describe, expect, layer } from '@effect/vitest';
2 import { isUsageFailure } from 'src/commands/errors';
3 import { ConfigProvider, Effect } from 'effect';
4 import { cli, TestLive, MockConsole } from 'test/__utils__';
5 import { exitCodeOf } from 'test/__utils__/exit-code';
6 import type { TestLiveInput } from 'test/__utils__/services/test-layer';
7 import type { AuthConfigItem } from 'src/models/auth-configs';
8 import {
9 DIRECTORY_PROJECT_SCOPE,
10 DEFAULT_PROJECT_SCOPE,
11 defaultDeveloperProjectAccountData,
12 inDeveloperProjectDirectory,
13 loginWithoutDeveloperProject,
14 OTHER_DEVELOPER_PROJECT,
15 OTHER_PROJECT_SCOPE,
16 runRecordingRepositoryScopes,
17 } from 'test/__utils__/layers/developer-project';
18
19 const testAuthConfigs: AuthConfigItem[] = [
20 {
21 id: 'ac_gmail_default',
22 name: 'Gmail Default',
23 no_of_connections: 5,
24 status: 'ENABLED',
25 type: 'default',
26 uuid: 'uuid-1',
27 toolkit: { logo: '', slug: 'gmail' },
28 auth_scheme: 'OAUTH2',
29 is_composio_managed: true,
30 is_enabled_for_tool_router: true,
31 created_at: '2026-01-01T00:00:00Z',
32 },
33 ];
34
35 const authConfigsData = {
36 items: testAuthConfigs,
37 } satisfies TestLiveInput['authConfigsData'];
38
39 const testConfigProvider = ConfigProvider.fromEnv({
40 env: { COMPOSIO_USER_API_KEY: 'test_api_key' },
41 });
42
43 // Logged in, in a directory set up for a developer project.
44 const inProject = { ...inDeveloperProjectDirectory, baseConfigProvider: testConfigProvider };
45
46 describe('CLI: composio dev auth-configs info', () => {
47 layer(TestLive({ ...inProject, authConfigsData }))(
48 '[Given] valid ID [Then] displays auth config details',
49 it => {
50 it.effect('shows auth config details', () =>
51 Effect.gen(function* () {
52 yield* cli(['dev', 'auth-configs', 'info', 'ac_gmail_default']);
53 const lines = yield* MockConsole.getLines({ stripAnsi: true });
54 const output = lines.join('\n');
55
56 expect(output).toContain('Gmail Default');
57 expect(output).toContain('ac_gmail_default');
58 expect(output).toContain('gmail');
59 expect(output).toContain('OAUTH2');
60 expect(output).toContain('ENABLED');
61 expect(output).toContain('Yes'); // is_composio_managed
62 })
63 );
64 }
65 );
66
67 layer(TestLive({ ...inProject, authConfigsData }))(
68 '[Given] no ID [Then] fails with a usage error',
69 it => {
70 it.effect('raises a CommandInputError naming <id>', () =>
71 Effect.gen(function* () {
72 const failure = yield* cli(['dev', 'auth-configs', 'info']).pipe(Effect.flip);
73
74 expect(failure).toMatchObject({
75 _tag: 'commands/CommandInputError',
76 option: '<id>',
77 message: expect.stringContaining('Missing required argument: <id>'),
78 });
79 // The invocation prints the message on stderr, and nothing else.
80 assert(isUsageFailure(failure));
81 expect(yield* MockConsole.getLines()).toEqual([failure.message]);
82 })
83 );
84 }
85 );
86
87 layer(TestLive({ ...inProject, authConfigsData }))(
88 '[Given] invalid ID [Then] shows error with hint',
89 it => {
90 it.effect('shows not found error', () =>
91 Effect.gen(function* () {
92 const exit = yield* Effect.exit(cli(['dev', 'auth-configs', 'info', 'ac_nonexistent']));
93 const lines = yield* MockConsole.getLines({ stripAnsi: true });
94 const output = lines.join('\n');
95
96 expect(output).toContain('not found');
97 expect(output).toContain('composio dev auth-configs list');
98 expect(exitCodeOf(exit)).toBe(1);
99 })
100 );
101 }
102 );
103
104 layer(TestLive())('[Given] no API key [Then] warns user to login', it => {
105 it.effect('warns user to login', () =>
106 Effect.gen(function* () {
107 const error = yield* cli(['dev', 'auth-configs', 'info', 'ac_gmail_default']).pipe(
108 Effect.flip
109 );
110 expect(error).toMatchObject({ _tag: 'commands/NotLoggedInError' });
111 })
112 );
113 });
114 });
115
116 // The request goes to the developer project the command resolved, never to the one the backend
117 // would pick for the key.
118 describe('CLI: composio dev auth-configs info acts on the developer project', () => {
119 layer(TestLive({ ...inProject, authConfigsData }))(it => {
120 it.effect.each([
121 { given: 'a directory set up for a project', args: [], scope: DIRECTORY_PROJECT_SCOPE },
122 {
123 given: '--project-name',
124 args: ['--project-name', OTHER_DEVELOPER_PROJECT.name],
125 scope: OTHER_PROJECT_SCOPE,
126 },
127 ])('[Given] $given [Then] reads the auth config from that project', ({ args, scope }) =>
128 Effect.gen(function* () {
129 const { exitCode, calls } = yield* runRecordingRepositoryScopes([
130 ...['dev', 'auth-configs', 'info', 'ac_gmail_default'],
131 ...args,
132 ]);
133
134 expect(exitCode).toBe(0);
135 expect(calls).toEqual([{ method: 'getAuthConfig', scope: expect.objectContaining(scope) }]);
136 })
137 );
138 });
139
140 layer(
141 TestLive({
142 baseConfigProvider: testConfigProvider,
143 authConfigsData,
144 accountData: defaultDeveloperProjectAccountData(),
145 })
146 )(it => {
147 it.effect(
148 '[Given] a directory set up for no project [Then] acts on the default developer project',
149 () =>
150 Effect.gen(function* () {
151 yield* loginWithoutDeveloperProject;
152 const { exitCode, calls } = yield* runRecordingRepositoryScopes([
153 'dev',
154 'auth-configs',
155 'info',
156 'ac_gmail_default',
157 ]);
158
159 expect(exitCode).toBe(0);
160 expect(calls).toEqual([
161 { method: 'getAuthConfig', scope: expect.objectContaining(DEFAULT_PROJECT_SCOPE) },
162 ]);
163 })
164 );
165 });
166 });