Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 692 lines 25.7 KB
Raw
1 import { describe, expect, it, layer } from '@effect/vitest';
2 import { Cause, ConfigProvider, Effect, Exit, FileSystem, Path } from 'effect';
3 import { buildRootCommand } from 'src/commands';
4 import { CommandInputError } from 'src/commands/errors';
5 import { ComposioCliUserConfig } from 'src/services/cli-user-config';
6 import { ProjectResolutionError } from 'src/services/command-project';
7 import type { ConnectedAccountItem } from 'src/models/connected-accounts';
8 import { NodeProcess } from 'src/services/node-process';
9 import { ComposioUserContext } from 'src/services/user-context';
10 import {
11 cli,
12 cliExit,
13 MockConsole,
14 recordedInvocationCalls,
15 resetInvocationCalls,
16 TestLive,
17 } from 'test/__utils__';
18 import { exitCodeOf } from 'test/__utils__/exit-code';
19 import { makeOrgProject } from 'test/__utils__/models/account';
20
21 const SHARED_PROJECT_DESCRIPTION =
22 'Developer project to use instead of the one configured in this directory';
23 const SHARED_USER_DESCRIPTION =
24 'User id to act as or filter by. Without it, commands that act as a user use the test user id of this directory (for its own project), then the global one, and name it on stderr.';
25 // `dev logs tools|triggers` declare a comma-separated `--user-id` filter of their own, which
26 // `withSharedFlags` accepts below a group entry and the help page shows in place of the shared row.
27 const OWN_USER_ID_PAGES = ['dev logs tools', 'dev logs triggers'];
28
29 // A fresh layer per page: the mock console keeps every line written under one layer.
30 const helpPage = (path: ReadonlyArray<string>) =>
31 Effect.gen(function* () {
32 yield* Effect.exit(cli([...path, '--help']));
33 return (yield* MockConsole.getLines({ stripAnsi: true, stream: 'stdout' })).join('\n');
34 }).pipe(Effect.provide(TestLive()));
35
36 const subcommandPaths = (
37 command: import('effect/cli').Command.Command.Any,
38 prefix: ReadonlyArray<string>
39 ): ReadonlyArray<ReadonlyArray<string>> =>
40 command.subcommands
41 .flatMap(group => group.commands)
42 .filter(child => child.name !== 'help' && !child.unlisted)
43 .flatMap(child => {
44 const path = [...prefix, child.name];
45 return [path, ...subcommandPaths(child, path)];
46 });
47
48 const root = buildRootCommand({ isDevModeEnabled: true, isExperimentalFeatureEnabled: () => true });
49 const devCommand = root.subcommands.flatMap(group => group.commands).find(c => c.name === 'dev')!;
50 const devPages = subcommandPaths(devCommand, ['dev']).map(path => ({ path, name: path.join(' ') }));
51 const rootPages = subcommandPaths(root, [])
52 .filter(path => path[0] !== 'dev' && path[0] !== 'listen')
53 .map(path => ({ path, name: path.join(' ') }));
54
55 describe('CommandSurface: the dev group shares --user-id and --project-name', () => {
56 it.effect.each(devPages)('documents both shared flags once on `$name`', ({ path, name }) =>
57 Effect.gen(function* () {
58 const page = yield* helpPage(path);
59 const rows = page.split('\n').filter(line => line.trimStart().startsWith('--'));
60 expect(
61 rows.filter(row => row.includes('--project-name string')),
62 name
63 ).toHaveLength(1);
64 expect(
65 rows.filter(row => row.includes('--user-id string')),
66 name
67 ).toHaveLength(1);
68 expect(page, name).toContain(SHARED_PROJECT_DESCRIPTION);
69 if (!OWN_USER_ID_PAGES.includes(name)) {
70 expect(page, name).toContain(SHARED_USER_DESCRIPTION);
71 }
72 })
73 );
74
75 it.effect.each(rootPages)('keeps the shared flags off the root page `$name`', ({ path }) =>
76 Effect.gen(function* () {
77 const page = yield* helpPage(path);
78 expect(page).not.toContain('--user-id');
79 expect(page).not.toContain('--project-name');
80 })
81 );
82
83 layer(TestLive())(it => {
84 it.effect('rejects --user-id on a root command, which has no such flag', () =>
85 Effect.gen(function* () {
86 const result = yield* Effect.result(cli(['search', 'send an email', '--user-id', 'alice']));
87 expect(result._tag).toBe('Failure');
88 const stderr = (yield* MockConsole.getLines({ stripAnsi: true, stream: 'stderr' })).join(
89 '\n'
90 );
91 expect(stderr).toContain('--user-id');
92 })
93 );
94 });
95
96 layer(
97 TestLive({
98 baseConfigProvider: ConfigProvider.fromEnv({
99 env: {
100 COMPOSIO_USER_API_KEY: 'test_api_key',
101 COMPOSIO_ORG_ID: 'org_test',
102 COMPOSIO_PROJECT_ID: 'dev_project_test',
103 },
104 }),
105 connectedAccountsData: {
106 items: ['alice', 'bob'].map(userId => ({
107 id: `con_${userId}`,
108 status: 'ACTIVE',
109 status_reason: null,
110 is_disabled: false,
111 user_id: userId,
112 toolkit: { slug: 'gmail' },
113 auth_config: {
114 id: 'ac_gmail',
115 auth_scheme: 'OAUTH2',
116 is_composio_managed: true,
117 is_disabled: false,
118 },
119 created_at: '2026-01-01T00:00:00Z',
120 updated_at: '2026-01-01T00:00:00Z',
121 test_request_endpoint: 'https://gmail.googleapis.com/gmail/v1/users/me/profile',
122 })),
123 },
124 })
125 )(it => {
126 it.effect.each([
127 {
128 name: 'after the subcommand',
129 args: ['dev', 'connected-accounts', 'list', '--user-id', 'alice'],
130 },
131 {
132 name: 'before the subcommand',
133 args: ['dev', '--user-id', 'alice', 'connected-accounts', 'list'],
134 },
135 ])('reaches the handler when passed $name', ({ args }) =>
136 Effect.gen(function* () {
137 const userContext = yield* ComposioUserContext;
138 yield* userContext.login('test_api_key', 'org_test');
139 yield* cli(args);
140 const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
141 expect(output).toContain('con_alice');
142 expect(output).not.toContain('con_bob');
143 })
144 );
145 });
146 });
147
148 describe('CommandSurface: --project-name reaches the project resolver', () => {
149 layer(
150 TestLive({
151 baseConfigProvider: ConfigProvider.fromEnv({
152 env: { COMPOSIO_USER_API_KEY: 'test_api_key', COMPOSIO_ORG_ID: 'org_test' },
153 }),
154 accountData: { projects: [] },
155 })
156 )(it => {
157 it.effect.each(
158 [
159 {
160 name: 'after the subcommand',
161 args: ['dev', 'connected-accounts', 'link', 'gmail', '--list', '--project-name', 'nope'],
162 },
163 {
164 name: 'before the subcommand',
165 args: ['dev', '--project-name', 'nope', 'connected-accounts', 'link', 'gmail', '--list'],
166 },
167 { name: 'to connected-accounts list', args: ['dev', 'connected-accounts', 'list'] },
168 { name: 'to toolkits info', args: ['dev', 'toolkits', 'info', 'gmail'] },
169 { name: 'to triggers listen', args: ['dev', 'triggers', 'listen'] },
170 { name: 'to listen', args: ['dev', 'listen'] },
171 ].map(({ name, args }) =>
172 args.includes('--project-name')
173 ? { name, args }
174 : { name, args: [...args, '--project-name', 'nope'] }
175 )
176 )('looks the named project up when passed $name', ({ args }) =>
177 Effect.gen(function* () {
178 const userContext = yield* ComposioUserContext;
179 yield* userContext.login('test_api_key', 'org_test');
180 const error = yield* Effect.flip(cli(args));
181 expect(error).toBeInstanceOf(ProjectResolutionError);
182 expect((error as ProjectResolutionError).message).toContain(
183 'Developer project "nope" was not found in org "org_test"'
184 );
185 })
186 );
187 });
188 });
189
190 describe('CommandSurface: toolkits list reports the named project it cannot find', () => {
191 layer(
192 TestLive({
193 baseConfigProvider: ConfigProvider.fromEnv({
194 env: { COMPOSIO_USER_API_KEY: 'test_api_key', COMPOSIO_ORG_ID: 'org_test' },
195 }),
196 accountData: { projects: [] },
197 })
198 )(it => {
199 // `toolkits list` prints every failure on stderr itself, then fails already reported.
200 it.effect('looks the named project up', () =>
201 Effect.gen(function* () {
202 const userContext = yield* ComposioUserContext;
203 yield* userContext.login('test_api_key', 'org_test');
204 const exit = yield* Effect.exit(cli(['dev', 'toolkits', 'list', '--project-name', 'nope']));
205 const stderr = (yield* MockConsole.getLines({ stripAnsi: true, stream: 'stderr' })).join(
206 '\n'
207 );
208 expect(stderr).toContain('Developer project "nope" was not found in org "org_test"');
209 expect(exitCodeOf(exit)).toBe(1);
210 })
211 );
212 });
213 });
214
215 describe('CommandSurface: playground-execute --parallel keeps the shared flags', () => {
216 layer(
217 TestLive({
218 baseConfigProvider: ConfigProvider.fromEnv({
219 env: { COMPOSIO_USER_API_KEY: 'test_api_key', COMPOSIO_ORG_ID: 'org_test' },
220 }),
221 accountData: { projects: [] },
222 })
223 )(it => {
224 it.effect.each([
225 {
226 name: 'after the subcommand',
227 args: ['dev', 'playground-execute', '--parallel', 'GMAIL_SEND_EMAIL', '-d', '{}'],
228 shared: ['--project-name', 'nope'],
229 },
230 {
231 name: 'before the subcommand',
232 args: ['dev', '--project-name', 'nope', 'playground-execute', '--parallel'],
233 shared: ['GMAIL_SEND_EMAIL', '-d', '{}'],
234 },
235 ])('looks the named project up when --project-name is passed $name', ({ args, shared }) =>
236 Effect.gen(function* () {
237 const userContext = yield* ComposioUserContext;
238 yield* userContext.login('test_api_key', 'org_test');
239 const error = yield* Effect.flip(cli([...args, ...shared, '--skip-checks']));
240 expect(error).toBeInstanceOf(ProjectResolutionError);
241 expect((error as ProjectResolutionError).message).toContain(
242 'Developer project "nope" was not found in org "org_test"'
243 );
244 })
245 );
246 });
247
248 const sessionUserIds: Array<string> = [];
249 layer(
250 TestLive({
251 baseConfigProvider: ConfigProvider.fromEnv({
252 env: {
253 COMPOSIO_USER_API_KEY: 'test_api_key',
254 COMPOSIO_ORG_ID: 'org_test',
255 COMPOSIO_PROJECT_ID: 'dev_project_test',
256 },
257 }),
258 fixture: 'global-test-user-id',
259 stdin: { isTTY: true, data: '' },
260 toolRouter: {
261 create: params =>
262 Effect.sync(() => {
263 sessionUserIds.push(params.user_id);
264 return {
265 session_id: 'trs_test_session',
266 config: {
267 user_id: params.user_id,
268 execute: {},
269 search: {},
270 preload: { tools: [] },
271 instant: false,
272 },
273 config_version: 1,
274 mcp: { type: 'http' as const, url: 'https://mcp.test.composio.dev' },
275 tool_router_tools: [],
276 };
277 }),
278 },
279 })
280 )(it => {
281 it.effect('runs as the --user-id passed before the subcommand', () =>
282 Effect.gen(function* () {
283 const userContext = yield* ComposioUserContext;
284 yield* userContext.login('test_api_key', 'org_test');
285 sessionUserIds.length = 0;
286 yield* cli([
287 'dev',
288 '--user-id',
289 'alice',
290 'playground-execute',
291 '--parallel',
292 '--skip-checks',
293 'GMAIL_SEND_EMAIL',
294 '-d',
295 '{}',
296 'GITHUB_CREATE_ISSUE',
297 '-d',
298 '{}',
299 ]);
300 expect(sessionUserIds.length).toBeGreaterThan(0);
301 expect(new Set(sessionUserIds)).toEqual(new Set(['alice']));
302 })
303 );
304 });
305 });
306
307 describe('CommandSurface: playground-execute --parallel finds its command name', () => {
308 const executedSlugs: Array<string> = [];
309 layer(
310 TestLive({
311 baseConfigProvider: ConfigProvider.fromEnv({
312 env: {
313 COMPOSIO_USER_API_KEY: 'test_api_key',
314 COMPOSIO_ORG_ID: 'org_test',
315 COMPOSIO_PROJECT_ID: 'dev_project_test',
316 },
317 }),
318 stdin: { isTTY: true, data: '' },
319 accountData: {
320 projects: [
321 makeOrgProject({ id: 'proj_pe', name: 'playground-execute', orgId: 'org_test' }),
322 ],
323 },
324 toolsExecutor: { onExecute: slug => executedSlugs.push(slug) },
325 })
326 )(it => {
327 it.effect.each([
328 { flag: '--user-id', args: ['--user-id', 'playground-execute'] },
329 { flag: '--project-name', args: ['--project-name', 'playground-execute'] },
330 ])('does not take a $flag value that spells it for the command', ({ args }) =>
331 Effect.gen(function* () {
332 yield* (yield* ComposioUserContext).login('test_api_key', 'org_test', 'global_user');
333 executedSlugs.length = 0;
334 yield* cli([
335 'dev',
336 ...args,
337 'playground-execute',
338 '--parallel',
339 '--skip-checks',
340 'GMAIL_SEND_EMAIL',
341 '-d',
342 '{}',
343 'GITHUB_CREATE_ISSUE',
344 '-d',
345 '{}',
346 ]);
347 expect(executedSlugs.toSorted()).toEqual(['GITHUB_CREATE_ISSUE', 'GMAIL_SEND_EMAIL']);
348 })
349 );
350 });
351 });
352
353 // Commands that act on no project or for no user reject the shared flag they cannot honor.
354 // `dev init` and `dev projects` declare both unsupported for every command under them, and
355 // `dev auth-configs` declares --user-id so; the message still names the command that ran.
356 const rejectingCommands = [
357 { command: ['init'], args: [], flags: ['--project-name', '--user-id'] },
358 { command: ['auth-configs', 'list'], args: [], flags: ['--user-id'] },
359 { command: ['auth-configs', 'info'], args: ['ac_1'], flags: ['--user-id'] },
360 { command: ['auth-configs', 'create'], args: ['--toolkit', 'gmail'], flags: ['--user-id'] },
361 { command: ['projects', 'list'], args: [], flags: ['--project-name', '--user-id'] },
362 { command: ['toolkits', 'search'], args: ['email'], flags: ['--project-name', '--user-id'] },
363 { command: ['toolkits', 'version'], args: ['gmail'], flags: ['--project-name', '--user-id'] },
364 { command: ['connected-accounts', 'info'], args: ['ca_1'], flags: ['--user-id'] },
365 { command: ['connected-accounts', 'whoami'], args: ['ca_1'], flags: ['--user-id'] },
366 { command: ['triggers', 'list'], args: ['gmail'], flags: ['--project-name', '--user-id'] },
367 {
368 command: ['triggers', 'info'],
369 args: ['GMAIL_NEW_GMAIL_MESSAGE'],
370 flags: ['--project-name', '--user-id'],
371 },
372 { command: ['triggers', 'status'], args: [], flags: ['--user-id'] },
373 { command: ['triggers', 'enable'], args: ['ti_1'], flags: ['--user-id'] },
374 { command: ['triggers', 'disable'], args: ['ti_1'], flags: ['--user-id'] },
375 ].flatMap(({ command, args, flags }) =>
376 flags.flatMap(flag =>
377 (['before', 'after'] as const).map(position => {
378 const path = ['dev', ...command].join(' ');
379 return {
380 argv:
381 position === 'before'
382 ? ['dev', flag, 'other', ...command, ...args]
383 : ['dev', ...command, ...args, flag, 'other'],
384 flag,
385 path,
386 name: `${path} ${flag} (${position} the command)`,
387 };
388 })
389 )
390 );
391
392 const rejectionMessage = (command: string, flag: string) =>
393 flag === '--project-name'
394 ? `\`composio ${command}\` cannot target another project yet. Remove --project-name, or run it from that project's directory.`
395 : `\`composio ${command}\` does not act as a user. Remove --user-id.`;
396
397 describe('CommandSurface: dev commands that cannot honor a shared flag reject it', () => {
398 layer(
399 TestLive({
400 baseConfigProvider: ConfigProvider.fromEnv({
401 env: { COMPOSIO_USER_API_KEY: 'test_api_key', COMPOSIO_ORG_ID: 'org_test' },
402 }),
403 })
404 )(it => {
405 it.effect.each(rejectingCommands)('rejects `$name`', ({ argv, flag, path }) =>
406 Effect.gen(function* () {
407 const userContext = yield* ComposioUserContext;
408 yield* userContext.login('test_api_key', 'org_test');
409 yield* resetInvocationCalls;
410 const { exit, exitCode } = yield* cliExit(argv);
411 expect(exitCode).toBe(1);
412 const error = Exit.isFailure(exit) ? Cause.squash(exit.cause) : undefined;
413 expect(error).toBeInstanceOf(CommandInputError);
414 expect(error).toMatchObject({
415 command: path,
416 option: flag,
417 message: rejectionMessage(path, flag),
418 });
419 const lifecycle = (yield* recordedInvocationCalls).flatMap(call =>
420 call.service === 'CommandLifecycleTelemetry' && call.event !== 'pluginHintShown'
421 ? [`${call.event} ${call.context.commandPath}`]
422 : []
423 );
424 expect(lifecycle).toEqual([`invoked ${path}`, `failed ${path}`]);
425 })
426 );
427 });
428 });
429
430 describe('CommandSurface: the developer-mode toggle rejects the shared flags', () => {
431 // A fresh layer per case: a toggle that went through would turn developer mode off, and the
432 // next case would then parse without the shared flags.
433 it.effect.each([
434 { args: ['dev', '--mode', 'off', '--project-name', 'other'], flag: '--project-name' },
435 { args: ['dev', '--user-id', 'alice', '--mode', 'off'], flag: '--user-id' },
436 ])('rejects `$args` and keeps developer mode on', ({ args, flag }) =>
437 Effect.gen(function* () {
438 const error = yield* Effect.flip(cli(args));
439 expect(error).toBeInstanceOf(CommandInputError);
440 expect(error).toMatchObject({ command: 'dev', option: flag });
441 expect((yield* ComposioCliUserConfig).isDevModeEnabled()).toBe(true);
442 }).pipe(Effect.provide(TestLive()), Effect.scoped)
443 );
444
445 it.effect('still toggles without them', () =>
446 Effect.gen(function* () {
447 yield* cli(['dev', '--mode', 'off']);
448 expect((yield* ComposioCliUserConfig).isDevModeEnabled()).toBe(false);
449 }).pipe(Effect.provide(TestLive()), Effect.scoped)
450 );
451 });
452
453 describe('CommandSurface: a named project does not borrow the directory test user', () => {
454 // The directory belongs to `dir-project` and configures its own test user; the global one is
455 // what login stores. A `--project-name` naming another project must fall back to the global one.
456 const writeDirectoryProject = Effect.gen(function* () {
457 const fs = yield* FileSystem.FileSystem;
458 const path = yield* Path.Path;
459 const { cwd } = yield* NodeProcess;
460 yield* fs.makeDirectory(path.join(cwd, '.composio'), { recursive: true });
461 yield* fs.writeFileString(
462 path.join(cwd, '.composio', 'project.json'),
463 JSON.stringify({ org_id: 'org_test', project_id: 'proj_dir', test_user_id: 'directory_user' })
464 );
465 });
466
467 /** The users the command opened sessions as, and the fallback notices it printed. */
468 const sessionUser = (args: ReadonlyArray<string>) =>
469 Effect.gen(function* () {
470 const userIds: Array<string> = [];
471 const lines = yield* Effect.gen(function* () {
472 yield* writeDirectoryProject;
473 yield* (yield* ComposioUserContext).login('test_api_key', 'org_test', 'global_user');
474 yield* Effect.exit(cli(args));
475 return yield* MockConsole.getLines({ stripAnsi: true });
476 }).pipe(
477 Effect.provide(
478 TestLive({
479 baseConfigProvider: ConfigProvider.fromEnv({
480 env: { COMPOSIO_USER_API_KEY: 'test_api_key', COMPOSIO_ORG_ID: 'org_test' },
481 }),
482 accountData: { projects },
483 stdin: { isTTY: true, data: '' },
484 toolRouter: {
485 create: params =>
486 Effect.sync(() => {
487 userIds.push(params.user_id);
488 return {
489 session_id: 'trs_test_session',
490 config: {
491 user_id: params.user_id,
492 execute: {},
493 search: {},
494 preload: { tools: [] },
495 instant: false,
496 },
497 config_version: 1,
498 mcp: { type: 'http' as const, url: 'https://mcp.test.composio.dev' },
499 tool_router_tools: [],
500 };
501 }),
502 },
503 })
504 ),
505 Effect.scoped
506 );
507 return {
508 users: [...new Set(userIds)],
509 notices: lines.filter(line => /^Using (global )?test user id/u.test(line)),
510 };
511 });
512
513 const projects = [
514 makeOrgProject({ id: 'proj_dir', name: 'dir-project', orgId: 'org_test' }),
515 makeOrgProject({ id: 'proj_other', name: 'other-project', orgId: 'org_test' }),
516 ];
517 const sessionCommands = [
518 { command: 'toolkits list', args: ['dev', 'toolkits', 'list'] },
519 { command: 'toolkits info', args: ['dev', 'toolkits', 'info', 'gmail'] },
520 {
521 command: 'playground-execute',
522 args: ['dev', 'playground-execute', 'GMAIL_SEND_EMAIL', '-d', '{}', '--skip-checks'],
523 },
524 {
525 command: 'playground-execute --parallel',
526 args: [
527 'dev',
528 'playground-execute',
529 '--parallel',
530 'GMAIL_SEND_EMAIL',
531 '-d',
532 '{}',
533 'GMAIL_FETCH_EMAILS',
534 '-d',
535 '{}',
536 '--skip-checks',
537 ],
538 },
539 {
540 command: 'connected-accounts link',
541 args: ['dev', 'connected-accounts', 'link', 'gmail', '--no-wait'],
542 },
543 ];
544 const projectCases = [
545 {
546 project: ['--project-name', 'other-project'],
547 expected: 'global_user',
548 notice: 'Using global test user id "global_user"',
549 },
550 {
551 project: ['--project-name', 'dir-project'],
552 expected: 'directory_user',
553 notice: 'Using test user id "directory_user"',
554 },
555 { project: [], expected: 'directory_user', notice: 'Using test user id "directory_user"' },
556 ];
557
558 it.effect.each(
559 sessionCommands.flatMap(({ command, args }) =>
560 projectCases.map(({ project, expected, notice }) => ({
561 args: [...args, ...project],
562 expected,
563 notice,
564 name: `${command} ${project.join(' ') || 'without --project-name'}`,
565 }))
566 )
567 )('`$name` opens its session as $expected and says so once', ({ args, expected, notice }) =>
568 Effect.gen(function* () {
569 expect(yield* sessionUser(args)).toEqual({ users: [expected], notices: [notice] });
570 })
571 );
572
573 const accountFor = (userId: string, id: string): ConnectedAccountItem => ({
574 id,
575 alias: id,
576 word_id: id,
577 status: 'ACTIVE',
578 status_reason: null,
579 is_disabled: false,
580 user_id: userId,
581 toolkit: { slug: 'gmail' },
582 auth_config: {
583 id: 'ac_gmail_oauth',
584 auth_scheme: 'OAUTH2',
585 is_composio_managed: true,
586 is_disabled: false,
587 },
588 created_at: '2026-01-01T00:00:00Z',
589 updated_at: '2026-01-15T00:00:00Z',
590 test_request_endpoint: '',
591 });
592
593 it.effect.each([
594 { project: ['--project-name', 'other-project'], expected: 'ca_global', other: 'ca_dir' },
595 { project: ['--project-name', 'dir-project'], expected: 'ca_dir', other: 'ca_global' },
596 { project: [], expected: 'ca_dir', other: 'ca_global' },
597 ])('`connected-accounts link --list $project` lists $expected', ({ project, expected, other }) =>
598 Effect.gen(function* () {
599 yield* writeDirectoryProject;
600 yield* (yield* ComposioUserContext).login('test_api_key', 'org_test', 'global_user');
601 yield* cli(['dev', 'connected-accounts', 'link', 'gmail', '--list', ...project]);
602 const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
603 expect(output).toContain(expected);
604 expect(output).not.toContain(other);
605 }).pipe(
606 Effect.provide(
607 TestLive({
608 baseConfigProvider: ConfigProvider.fromEnv({
609 env: { COMPOSIO_USER_API_KEY: 'test_api_key', COMPOSIO_ORG_ID: 'org_test' },
610 }),
611 accountData: { projects },
612 connectedAccountsData: {
613 items: [accountFor('global_user', 'ca_global'), accountFor('directory_user', 'ca_dir')],
614 },
615 })
616 ),
617 Effect.scoped
618 )
619 );
620
621 it.effect.each([
622 { project: 'other-project', expected: 'Using global test user id "global_user"' },
623 { project: 'dir-project', expected: 'Using test user id "directory_user"' },
624 ])(
625 '`connected-accounts link --auth-config --project-name $project` warns `$expected`',
626 ({ project, expected }) =>
627 Effect.gen(function* () {
628 yield* writeDirectoryProject;
629 yield* (yield* ComposioUserContext).login('test_api_key', 'org_test', 'global_user');
630 yield* Effect.exit(
631 cli([
632 'dev',
633 'connected-accounts',
634 'link',
635 '--auth-config',
636 'ac_gmail_oauth',
637 '--no-wait',
638 '--project-name',
639 project,
640 ])
641 );
642 const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
643 expect(output).toContain(expected);
644 }).pipe(
645 Effect.provide(
646 TestLive({
647 baseConfigProvider: ConfigProvider.fromEnv({
648 env: { COMPOSIO_USER_API_KEY: 'test_api_key', COMPOSIO_ORG_ID: 'org_test' },
649 }),
650 accountData: { projects },
651 })
652 ),
653 Effect.scoped
654 )
655 );
656 // A login without session info stores no global test user; the directory's does not carry over.
657 it.effect.each([
658 {
659 command: 'playground-execute',
660 args: ['dev', 'playground-execute', 'GMAIL_SEND_EMAIL', '-d', '{}', '--skip-checks'],
661 },
662 {
663 command: 'connected-accounts link --list',
664 args: ['dev', 'connected-accounts', 'link', 'gmail', '--list'],
665 },
666 {
667 command: 'connected-accounts link --auth-config',
668 args: ['dev', 'connected-accounts', 'link', '--auth-config', 'ac_gmail_oauth', '--no-wait'],
669 },
670 ])('`$command --project-name` without any test user points at --user-id and login', ({ args }) =>
671 Effect.gen(function* () {
672 yield* writeDirectoryProject;
673 yield* (yield* ComposioUserContext).login('test_api_key', 'org_test');
674 const error = yield* Effect.flip(cli([...args, '--project-name', 'other-project']));
675 expect(error).toMatchObject({
676 message:
677 'Missing user id. Provide --user-id, or run `composio login` to store a global test user id.',
678 });
679 }).pipe(
680 Effect.provide(
681 TestLive({
682 baseConfigProvider: ConfigProvider.fromEnv({
683 env: { COMPOSIO_USER_API_KEY: 'test_api_key', COMPOSIO_ORG_ID: 'org_test' },
684 }),
685 accountData: { projects },
686 stdin: { isTTY: true, data: '' },
687 })
688 ),
689 Effect.scoped
690 )
691 );
692 });