1
import { describe, expect, it, layer } from '@effect/vitest';
2
-import { ConfigProvider, Effect, FileSystem, Path } from 'effect';
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';
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 { cli, MockConsole, TestLive } from 'test/__utils__';
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
351
});
352
353
// `dev logs tools|triggers` honor --user-id as their filter and reject only --project-name.
354
+// `dev logs`, `dev auth-configs` and `dev projects` declare the flags unsupported for every
355
+// command under them; the message still names the command that ran.
356
const rejectingCommands = [
348
- { path: ['init'], flags: ['--project-name', '--user-id'] },
349
- { path: ['logs', 'tools'], flags: ['--project-name'] },
350
- { path: ['logs', 'triggers'], flags: ['--project-name'] },
351
- { path: ['auth-configs', 'list'], flags: ['--project-name', '--user-id'] },
352
- { path: ['projects', 'list'], flags: ['--project-name', '--user-id'] },
353
- { path: ['toolkits', 'search', 'email'], flags: ['--project-name', '--user-id'] },
354
- { path: ['toolkits', 'version', 'gmail'], flags: ['--project-name', '--user-id'] },
355
- { path: ['connected-accounts', 'info', 'ca_1'], flags: ['--project-name', '--user-id'] },
356
- { path: ['connected-accounts', 'whoami', 'ca_1'], flags: ['--project-name', '--user-id'] },
357
- { path: ['triggers', 'list', 'gmail'], flags: ['--project-name', '--user-id'] },
358
- { path: ['triggers', 'info', 'GMAIL_NEW_GMAIL_MESSAGE'], flags: ['--project-name', '--user-id'] },
359
- { path: ['triggers', 'status'], flags: ['--project-name', '--user-id'] },
357
+ { command: ['init'], args: [], flags: ['--project-name', '--user-id'] },
358
+ { command: ['logs', 'tools'], args: [], flags: ['--project-name'] },
359
+ { command: ['logs', 'triggers'], args: [], flags: ['--project-name'] },
360
+ { command: ['auth-configs', 'list'], args: [], flags: ['--project-name', '--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
{
361
- path: ['triggers', 'create', 'GMAIL_NEW_GMAIL_MESSAGE'],
362
- flags: ['--project-name'],
365
+ command: ['connected-accounts', 'info'],
366
+ args: ['ca_1'],
367
+ flags: ['--project-name', '--user-id'],
368
},
364
- { path: ['triggers', 'enable', 'ti_1'], flags: ['--project-name', '--user-id'] },
365
- { path: ['triggers', 'disable', 'ti_1'], flags: ['--project-name', '--user-id'] },
366
-].flatMap(({ path, flags }) =>
367
- flags.map(flag => ({ path, flag, name: `dev ${path.join(' ')} ${flag}` }))
369
+ {
370
+ command: ['connected-accounts', 'whoami'],
371
+ args: ['ca_1'],
372
+ flags: ['--project-name', '--user-id'],
373
+ },
374
+ { command: ['triggers', 'list'], args: ['gmail'], flags: ['--project-name', '--user-id'] },
375
+ {
376
+ command: ['triggers', 'info'],
377
+ args: ['GMAIL_NEW_GMAIL_MESSAGE'],
378
+ flags: ['--project-name', '--user-id'],
379
+ },
380
+ { command: ['triggers', 'status'], args: [], flags: ['--project-name', '--user-id'] },
381
+ { command: ['triggers', 'create'], args: ['GMAIL_NEW_GMAIL_MESSAGE'], flags: ['--project-name'] },
382
+ { command: ['triggers', 'enable'], args: ['ti_1'], flags: ['--project-name', '--user-id'] },
383
+ { command: ['triggers', 'disable'], args: ['ti_1'], flags: ['--project-name', '--user-id'] },
384
+].flatMap(({ command, args, flags }) =>
385
+ flags.flatMap(flag =>
386
+ (['before', 'after'] as const).map(position => {
387
+ const path = ['dev', ...command].join(' ');
388
+ return {
389
+ argv:
390
+ position === 'before'
391
+ ? ['dev', flag, 'other', ...command, ...args]
392
+ : ['dev', ...command, ...args, flag, 'other'],
393
+ flag,
394
+ path,
395
+ name: `${path} ${flag} (${position} the command)`,
396
+ };
397
+ })
398
+ )
399
);
400
401
+const rejectionMessage = (command: string, flag: string) =>
402
+ flag === '--project-name'
403
+ ? `\`composio ${command}\` cannot target another project yet. Remove --project-name, or run it from that project's directory.`
404
+ : `\`composio ${command}\` does not act as a user. Remove --user-id.`;
405
+
406
describe('CommandSurface: dev commands that cannot honor a shared flag reject it', () => {
407
layer(
408
TestLive({
411
}),
412
})
413
)(it => {
378
- it.effect.each(rejectingCommands)('rejects `$name`', ({ path, flag }) =>
414
+ it.effect.each(rejectingCommands)('rejects `$name`', ({ argv, flag, path }) =>
415
Effect.gen(function* () {
416
const userContext = yield* ComposioUserContext;
417
yield* userContext.login('test_api_key', 'org_test');
382
- const error = yield* Effect.flip(cli(['dev', flag, 'other', ...path]));
418
+ yield* resetInvocationCalls;
419
+ const { exit, exitCode } = yield* cliExit(argv);
420
+ expect(exitCode).toBe(1);
421
+ const error = Exit.isFailure(exit) ? Cause.squash(exit.cause) : undefined;
422
expect(error).toBeInstanceOf(CommandInputError);
384
- expect(error).toMatchObject({ option: flag });
423
+ expect(error).toMatchObject({
424
+ command: path,
425
+ option: flag,
426
+ message: rejectionMessage(path, flag),
427
+ });
428
+ const lifecycle = (yield* recordedInvocationCalls).flatMap(call =>
429
+ call.service === 'CommandLifecycleTelemetry' && call.event !== 'pluginHintShown'
430
+ ? [`${call.event} ${call.context.commandPath}`]
431
+ : []
432
+ );
433
+ expect(lifecycle).toEqual([`invoked ${path}`, `failed ${path}`]);
434
})
435
);
436
});