@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 113 lines 4.45 KB
Raw
1 import { describe, expect, layer } from '@effect/vitest';
2 import { Effect } from 'effect';
3 import { cli, TestLive, MockConsole } from 'test/__utils__';
4 import { retryHint } from 'src/effects/retry-advice';
5 import { exitCodeOf } from 'test/__utils__/exit-code';
6 import { makeOrgProject } from 'test/__utils__/models/account';
7 import { redirectedTerminalUI } from 'test/__utils__/services/redirected-terminal-ui';
8
9 describe('CLI: composio dev init', () => {
10 describe('dev init --help', () => {
11 layer(TestLive({ fixture: 'typescript-project' }))(it => {
12 it.effect('[Then] shows --no-browser and --yes, no --org-id or --project-id', () =>
13 Effect.gen(function* () {
14 yield* cli(['dev', 'init', '--help']);
15 const lines = yield* MockConsole.getLines({ stripAnsi: true });
16 const output = lines.join('\n');
17 expect(output).toContain('--no-browser');
18 expect(output).toContain('--yes');
19 expect(output).not.toContain('--org-id');
20 expect(output).not.toContain('--project-id');
21 })
22 );
23 });
24 });
25
26 describe('dev init without a usable login', () => {
27 layer(TestLive({ fixture: 'user-config-example' }))(it => {
28 it.effect('[Given] an API key but no org [Then] fails with a usage error', () =>
29 Effect.gen(function* () {
30 const failure = yield* cli(['dev', 'init', '--yes']).pipe(Effect.flip);
31
32 expect(failure).toMatchObject({
33 _tag: 'commands/CommandInputError',
34 command: 'dev init',
35 message: 'No global API key or org ID found. Please try `composio login` first.',
36 });
37 })
38 );
39 });
40 });
41
42 describe('dev init in an org without projects', () => {
43 layer(TestLive({ fixture: 'user-config-with-global-context', accountData: { projects: [] } }))(
44 it => {
45 it.effect('[Given] no projects [Then] says so on a redirected stderr and exits 1', () =>
46 Effect.gen(function* () {
47 const terminal = redirectedTerminalUI();
48 const exit = yield* Effect.exit(
49 cli(['dev', 'init', '--yes']).pipe(Effect.provide(terminal.layer))
50 );
51
52 expect(terminal.stderr()).toBe(
53 'No projects found for your organization.\nCreate a project at https://platform.composio.dev, then run `composio dev init` again.\n'
54 );
55 expect(terminal.stdout()).toBe('');
56 expect(exitCodeOf(exit)).toBe(1);
57 })
58 );
59 }
60 );
61 });
62
63 describe('dev init with the API unreachable', () => {
64 const projectGuidance =
65 'Create a project at https://platform.composio.dev, then run `composio dev init` again.';
66
67 layer(TestLive({ fixture: 'user-config-with-global-context' }))(it => {
68 it.effect('[Given] no project list [Then] fails with the project guidance', () =>
69 Effect.gen(function* () {
70 const result = yield* Effect.result(cli(['dev', 'init', '--yes']));
71 const lines = yield* MockConsole.getLines({ stripAnsi: true });
72
73 expect(result._tag).toBe('Failure');
74 expect(lines.slice(0, -2)).toEqual([
75 '-- composio dev init --',
76 'Could not fetch projects from the server.',
77 projectGuidance,
78 '-- --',
79 'Unexpected response from the server.',
80 projectGuidance,
81 '-- --',
82 ]);
83 // The command fails with the client's error after its guidance, which the invocation
84 // reports as a defect, then says the request is safe to send again.
85 expect(lines.at(-2)).toContain('@composio/client/APIConnectionError');
86 expect(lines.at(-1)).toBe(retryHint('safe'));
87 })
88 );
89 });
90
91 layer(
92 TestLive({
93 fixture: 'user-config-with-global-context',
94 accountData: { projects: [makeOrgProject({ id: 'p1', name: 'One' })] },
95 })
96 )(it => {
97 it.effect('[Given] no session info [Then] warns with the transport reason and finishes', () =>
98 Effect.gen(function* () {
99 yield* cli(['dev', 'init', '--yes']);
100 const lines = yield* MockConsole.getLines({ stripAnsi: true });
101
102 expect(lines.slice(0, 4)).toEqual([
103 '-- composio dev init --',
104 'Using developer project "One"',
105 'Could not create .env.local from session info.',
106 'No test data for auth.session.retrieveInfo',
107 ]);
108 expect(lines[4]).toMatch(/^Project initialized in /);
109 })
110 );
111 });
112 });
113 });