@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 134 lines 4.82 KB
Raw
1 import os from 'node:os';
2 import path from 'node:path';
3 import { describe, expect, layer } from '@effect/vitest';
4 import { Effect } from 'effect';
5 import { cli, pkg, TestLive, MockConsole } from 'test/__utils__';
6 import { afterEach, vi } from 'vitest';
7
8 describe('CLI: composio', () => {
9 afterEach(() => {
10 vi.unstubAllEnvs();
11 });
12
13 // v4 migration note: v3's `Command.run` returned a `ValidationError.CommandMismatch` for the
14 // caller to render by hand. `effect/cli`'s `Command.runWith` renders parse/validation
15 // errors itself (see `src/invocation/invocation.ts` module docs) before re-failing with
16 // `CliError.ShowHelp`, so these tests now assert on the printed `MockConsole` output instead of inspecting the error
17 // value directly.
18 layer(TestLive())(it => {
19 it.effect('[Given] unknown argument [Then] print error message', () =>
20 Effect.gen(function* () {
21 const args = ['--bar'];
22
23 yield* cli(args).pipe(Effect.catch(() => Effect.void));
24 const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
25
26 expect(output).toContain('--bar');
27 expect(output).toContain('generate');
28 expect(output).toContain('orgs');
29 })
30 );
31 });
32
33 layer(TestLive())(it => {
34 it.effect('[Given] invalid tools subcommand [Then] report tools-scoped mismatch', () =>
35 Effect.gen(function* () {
36 const args = ['tools', 'search', 'metabase', 'put'];
37
38 yield* cli(args).pipe(Effect.catch(() => Effect.void));
39 const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
40
41 expect(output).toContain('search');
42 expect(output).toContain('info');
43 expect(output).toContain('list');
44 })
45 );
46 });
47
48 layer(TestLive())(it => {
49 it.effect('[Given] no args [Then] prints help message', () =>
50 Effect.gen(function* () {
51 yield* cli([]);
52 const lines = yield* MockConsole.getLines({ stripAnsi: true });
53 const output = lines.join('\n');
54 expect(output).toContain('USAGE');
55 expect(output).toContain('composio');
56 expect(output).not.toContain('composio connections list');
57 })
58 );
59 });
60
61 layer(TestLive())(it => {
62 it.effect('[Given] --help flag [Then] prints help message', () =>
63 Effect.gen(function* () {
64 const args = ['--help'];
65 yield* cli(args);
66 const lines = yield* MockConsole.getLines({ stripAnsi: true });
67 const output = lines.join('\n');
68 expect(output.trim().length).toBeGreaterThan(0);
69 expect(output).toContain('Documentation:');
70 expect(output).not.toContain('connections list');
71 })
72 );
73 });
74
75 layer(TestLive())(it => {
76 it.effect('[Given] --version or -v [Then] prints exactly what `composio version` prints', () =>
77 Effect.gen(function* () {
78 // Each spelling runs against a fresh console so the captured lines are comparable.
79 const linesFor = (args: ReadonlyArray<string>) =>
80 Effect.gen(function* () {
81 yield* cli(args);
82 return yield* MockConsole.getLines({ stream: 'stdout' });
83 }).pipe(Effect.provide(TestLive()));
84
85 const expected = yield* linesFor(['version']);
86 expect(expected.join('\n')).toContain(pkg.version);
87 expect(yield* linesFor(['--version'])).toEqual(expected);
88 expect(yield* linesFor(['-v'])).toEqual(expected);
89 })
90 );
91 });
92
93 layer(TestLive())(it => {
94 it.effect("[Given] a typo'd subcommand [Then] suggests the nearest match", () =>
95 Effect.gen(function* () {
96 const args = ['tols'];
97
98 yield* cli(args).pipe(Effect.catch(() => Effect.void));
99 const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
100
101 // v4's parser always computes "Did you mean?" suggestions on
102 // `UnknownSubcommand`/`UnrecognizedOption`; Composio deliberately
103 // keeps them (see `cli-config.ts`) instead of stripping them.
104 expect(output).toContain('Did you mean');
105 expect(output).toContain('tools');
106 })
107 );
108 });
109
110 layer(TestLive())(it => {
111 it.effect('[Given] debug who-is-my-master [Then] it prints the detected master as json', () =>
112 Effect.gen(function* () {
113 vi.stubEnv('CODEX_THREAD_ID', 'thread_123');
114 vi.stubEnv('CLAUDE_CODE_ENTRYPOINT', 'sdk-ts');
115
116 yield* cli(['debug', 'who-is-my-master']);
117 const output = (yield* MockConsole.getLines()).join('\n');
118
119 expect(output).toContain('"master": "codex"');
120 })
121 );
122 });
123
124 layer(TestLive())(it => {
125 it.effect('[Given] artifacts cwd [Then] it prints the current session artifact directory', () =>
126 Effect.gen(function* () {
127 yield* cli(['artifacts', 'cwd']);
128 const output = (yield* MockConsole.getLines()).join('\n').trim();
129
130 expect(output).toContain(path.join(os.tmpdir(), 'composio'));
131 })
132 );
133 });
134 });