@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 187 lines 5.85 KB
Raw
1 import path from 'node:path';
2 import { describe, expect, layer } from '@effect/vitest';
3 import { Effect } from 'effect';
4 import * as FileSystem from 'effect/FileSystem';
5 import { NodeProcess } from 'src/services/node-process';
6 import { cli, TestLive, MockConsole } from 'test/__utils__';
7 import { makeTestToolkits } from 'test/__utils__/models/toolkits';
8 import { TRIGGER_TYPES_GMAIL } from 'test/__mocks__/trigger-types-gmail';
9 import { TOOLS_TYPES_GMAIL } from 'test/__mocks__/tools-types-gmail';
10 import type { TestLiveInput } from 'test/__utils__/services/test-layer';
11
12 describe('CLI: composio generate', () => {
13 const appClientData = {
14 toolkits: makeTestToolkits([
15 {
16 name: 'Gmail',
17 slug: 'gmail',
18 },
19 {
20 name: 'Slack',
21 slug: 'slack',
22 },
23 ]),
24 tools: [...TOOLS_TYPES_GMAIL.slice(0, 3)],
25 triggerTypes: [...TRIGGER_TYPES_GMAIL.slice(0, 3)],
26 triggerTypesAsEnums: [...TRIGGER_TYPES_GMAIL.slice(0, 3).map(triggerType => triggerType.slug)],
27 } satisfies TestLiveInput['toolkitsData'];
28
29 layer(
30 TestLive({
31 fixture: 'python-project',
32 })
33 )(it => {
34 it.effect('[Given] a valid Python project in cwd [Then] it detects its language', () =>
35 Effect.gen(function* () {
36 const process = yield* NodeProcess;
37 const cwd = process.cwd;
38
39 const args = ['generate', '--output-dir', cwd];
40 yield* cli(args);
41 const lines = yield* MockConsole.getLines();
42 const output = lines.join('\n');
43 expect(output).toContain('Project type detected: Python');
44 })
45 );
46 });
47
48 layer(
49 TestLive({
50 fixture: 'typescript-project',
51 })
52 )(it => {
53 it.effect('[Given] a valid TypeScript project in cwd [Then] it detects its language', () =>
54 Effect.gen(function* () {
55 const process = yield* NodeProcess;
56 const cwd = process.cwd;
57
58 const args = ['generate', '--output-dir', cwd];
59 yield* cli(args);
60 const lines = yield* MockConsole.getLines();
61 const output = lines.join('\n');
62 expect(output).toContain('Project type detected: TypeScript');
63 })
64 );
65 });
66
67 layer(
68 TestLive({
69 fixture: 'typescript-pnpm-monorepo',
70 })
71 )(it => {
72 it.effect('[Given] a pnpm monorepo project in cwd [Then] it detects TypeScript', () =>
73 Effect.gen(function* () {
74 const process = yield* NodeProcess;
75 const cwd = process.cwd;
76
77 const args = ['generate', '--output-dir', cwd];
78 yield* cli(args);
79 const lines = yield* MockConsole.getLines();
80 const output = lines.join('\n');
81 expect(output).toContain('Project type detected: TypeScript');
82 })
83 );
84 });
85
86 layer(
87 TestLive({
88 fixture: 'typescript-bun-project',
89 })
90 )(it => {
91 it.effect('[Given] a bun project in cwd [Then] it detects TypeScript', () =>
92 Effect.gen(function* () {
93 const process = yield* NodeProcess;
94 const cwd = process.cwd;
95
96 const args = ['generate', '--output-dir', cwd];
97 yield* cli(args);
98 const lines = yield* MockConsole.getLines();
99 const output = lines.join('\n');
100 expect(output).toContain('Project type detected: TypeScript');
101 })
102 );
103 });
104
105 layer(
106 TestLive({
107 fixture: 'python-uv-project',
108 })
109 )(it => {
110 it.effect('[Given] a uv Python project in cwd [Then] it detects Python', () =>
111 Effect.gen(function* () {
112 const process = yield* NodeProcess;
113 const cwd = process.cwd;
114
115 const args = ['generate', '--output-dir', cwd];
116 yield* cli(args);
117 const lines = yield* MockConsole.getLines();
118 const output = lines.join('\n');
119 expect(output).toContain('Project type detected: Python');
120 })
121 );
122 });
123
124 layer(
125 TestLive({
126 fixture: 'typescript-project',
127 toolkitsData: appClientData,
128 })
129 )(it => {
130 it.effect(
131 '[Given] TypeScript project with --toolkits [Then] it filters output to specified toolkits',
132 () =>
133 Effect.gen(function* () {
134 const process = yield* NodeProcess;
135 const cwd = process.cwd;
136 const fs = yield* FileSystem.FileSystem;
137 const outputDir = path.join(cwd, '.generated', 'composio-filtered');
138
139 const args = ['generate', '--toolkits', 'gmail', '--output-dir', outputDir];
140 yield* cli(args);
141
142 const lines = yield* MockConsole.getLines();
143 const output = lines.join('\n');
144 expect(output).toContain('Project type detected: TypeScript');
145
146 // Check generated files - only gmail.ts should exist
147 const files = yield* fs.readDirectory(outputDir);
148 const fileNames = files.map(file => path.basename(file));
149
150 expect(fileNames).toContain('gmail.ts');
151 expect(fileNames).not.toContain('slack.ts');
152 })
153 );
154 });
155
156 layer(
157 TestLive({
158 fixture: 'python-project',
159 toolkitsData: appClientData,
160 })
161 )(it => {
162 it.effect(
163 '[Given] Python project with --toolkits [Then] it filters output to specified toolkits',
164 () =>
165 Effect.gen(function* () {
166 const process = yield* NodeProcess;
167 const cwd = process.cwd;
168 const fs = yield* FileSystem.FileSystem;
169 const outputDir = path.join(cwd, '.generated', 'composio-filtered');
170
171 const args = ['generate', '--toolkits', 'gmail', '--output-dir', outputDir];
172 yield* cli(args);
173
174 const lines = yield* MockConsole.getLines();
175 const output = lines.join('\n');
176 expect(output).toContain('Project type detected: Python');
177
178 // Check generated files - only gmail.py should exist
179 const files = yield* fs.readDirectory(outputDir);
180 const fileNames = files.map(file => path.basename(file));
181
182 expect(fileNames).toContain('gmail.py');
183 expect(fileNames).not.toContain('slack.py');
184 })
185 );
186 });
187 });