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
| 1 | import { describe, expect, layer } from '@effect/vitest'; |
| 2 | import { Effect } from 'effect'; |
| 3 | import { buildRootCommand } from 'src/commands'; |
| 4 | import { cli, MockConsole, TestLive } from 'test/__utils__'; |
| 5 | import { exitCodeOf } from 'test/__utils__/exit-code'; |
| 6 | |
| 7 | const capture = (args: ReadonlyArray<string>) => |
| 8 | Effect.gen(function* () { |
| 9 | const exitCode = exitCodeOf(yield* Effect.exit(cli(args))); |
| 10 | const stdout = (yield* MockConsole.getLines({ stripAnsi: true, stream: 'stdout' })).join('\n'); |
| 11 | const stderr = (yield* MockConsole.getLines({ stripAnsi: true, stream: 'stderr' })).join('\n'); |
| 12 | return { exitCode, stdout, stderr }; |
| 13 | }).pipe(Effect.provide(TestLive())); |
| 14 | |
| 15 | const commandPaths = ( |
| 16 | command: ReturnType<typeof buildRootCommand> | import('effect/cli').Command.Command.Any, |
| 17 | prefix: ReadonlyArray<string> = [] |
| 18 | ): ReadonlyArray<ReadonlyArray<string>> => |
| 19 | command.subcommands |
| 20 | .flatMap(group => group.commands) |
| 21 | .filter(child => child.name !== 'help' && !child.unlisted) |
| 22 | .flatMap(child => { |
| 23 | const path = [...prefix, child.name]; |
| 24 | return [path, ...commandPaths(child, path)]; |
| 25 | }); |
| 26 | |
| 27 | // Experimental commands in the test config must be enabled independently of the graph. |
| 28 | const visibleCommandPaths = commandPaths( |
| 29 | buildRootCommand({ isDevModeEnabled: true, isExperimentalFeatureEnabled: () => true }) |
| 30 | ) |
| 31 | .filter(path => path[0] !== 'listen') |
| 32 | .map(path => ({ path, command: path.join(' ') })); |
| 33 | |
| 34 | describe('framework command help', () => { |
| 35 | layer(TestLive())(it => { |
| 36 | it.effect.each(visibleCommandPaths)( |
| 37 | 'renders $command from the same definitions used by parsing', |
| 38 | ({ path }) => |
| 39 | Effect.gen(function* () { |
| 40 | const flag = yield* capture([...path, '--help']); |
| 41 | const alias = yield* capture(['help', ...path]); |
| 42 | expect(flag.exitCode).toBe(0); |
| 43 | expect(alias.exitCode).toBe(0); |
| 44 | expect(alias.stdout).toBe(flag.stdout); |
| 45 | expect(flag.stdout).toContain('USAGE'); |
| 46 | expect(flag.stderr).toBe(''); |
| 47 | expect(alias.stderr).toBe(''); |
| 48 | }) |
| 49 | ); |
| 50 | |
| 51 | it.effect('includes flags previously missing from the hand-written pages', () => |
| 52 | Effect.gen(function* () { |
| 53 | expect((yield* capture(['version', '--help'])).stdout).toContain('--check'); |
| 54 | const run = yield* capture(['run', '--help']); |
| 55 | expect(run.stdout).toContain('--skip-checks'); |
| 56 | expect(run.stdout).not.toContain('--logs-off'); |
| 57 | expect(run.stdout).not.toContain('--perf-debug'); |
| 58 | }) |
| 59 | ); |
| 60 | |
| 61 | it.effect.each([ |
| 62 | { args: ['help', 'frobnicate'] }, |
| 63 | { args: ['help', 'orgz'] }, |
| 64 | { args: ['tools', 'frobnicate'] }, |
| 65 | ])('keeps errors for $args on stderr with a failing exit code', ({ args }) => |
| 66 | Effect.gen(function* () { |
| 67 | const output = yield* capture(args); |
| 68 | expect(output.exitCode).toBe(1); |
| 69 | expect(output.stdout).toBe(''); |
| 70 | expect(output.stderr).toContain('Unknown subcommand'); |
| 71 | }) |
| 72 | ); |
| 73 | |
| 74 | it.effect('suggests the closest subcommand on stderr', () => |
| 75 | Effect.gen(function* () { |
| 76 | expect((yield* capture(['help', 'orgz'])).stderr).toContain('Did you mean'); |
| 77 | }) |
| 78 | ); |
| 79 | |
| 80 | it.effect.each([ |
| 81 | { args: [] }, |
| 82 | { args: ['help'] }, |
| 83 | { args: ['help', '--help'] }, |
| 84 | { args: ['--help'] }, |
| 85 | { args: ['-h'] }, |
| 86 | ])('supports bare help, help aliases, and redundant help flags: $args', ({ args }) => |
| 87 | Effect.gen(function* () { |
| 88 | const output = yield* capture(args); |
| 89 | expect(output.exitCode).toBe(0); |
| 90 | expect(output.stdout).toContain('Documentation:'); |
| 91 | expect(output.stderr).toBe(''); |
| 92 | }) |
| 93 | ); |
| 94 | |
| 95 | it.effect.each([ |
| 96 | { path: ['login'], flag: '--agent' }, |
| 97 | { path: ['search'], flag: '--json' }, |
| 98 | { path: ['dev', 'connected-accounts', 'link'], flag: '--auth-config' }, |
| 99 | { path: ['dev', 'connected-accounts', 'link'], flag: '--user-id' }, |
| 100 | { path: ['dev', 'triggers', 'listen'], flag: '--user-id' }, |
| 101 | { path: ['dev', 'triggers', 'listen'], flag: '--forward' }, |
| 102 | { path: ['dev', 'triggers', 'listen'], flag: '--max-events' }, |
| 103 | { path: ['dev', 'triggers', 'disable'], flag: '--dangerously-allow' }, |
| 104 | ])('documents $flag on the previously unreachable $path page', ({ path, flag }) => |
| 105 | Effect.gen(function* () { |
| 106 | const output = yield* capture([...path, '--help']); |
| 107 | expect(output.exitCode).toBe(0); |
| 108 | expect(output.stdout).toContain(flag); |
| 109 | }) |
| 110 | ); |
| 111 | |
| 112 | it.effect('documents the previously unreachable dev projects switch page', () => |
| 113 | Effect.gen(function* () { |
| 114 | const projectSwitch = yield* capture(['dev', 'projects', 'switch', '--help']); |
| 115 | expect(projectSwitch.stdout).toContain('composio dev projects switch'); |
| 116 | expect(projectSwitch.stdout).toContain('Switch the developer project'); |
| 117 | }) |
| 118 | ); |
| 119 | |
| 120 | it.effect('keeps hidden commands and flags off the root help page', () => |
| 121 | Effect.gen(function* () { |
| 122 | const root = yield* capture(['--help']); |
| 123 | expect(root.stdout).not.toContain('composio files'); |
| 124 | expect(root.stdout).not.toContain('MODE'); |
| 125 | expect(root.stdout).not.toContain('api-info'); |
| 126 | expect(root.stdout).not.toContain('--tool-debug'); |
| 127 | }) |
| 128 | ); |
| 129 | |
| 130 | it.effect.each([{ path: ['execute'] }, { path: ['dev', 'playground-execute'] }])( |
| 131 | 'renders $path parallel help through the framework before executing any tools', |
| 132 | ({ path }) => |
| 133 | Effect.gen(function* () { |
| 134 | const help = yield* capture([ |
| 135 | ...path, |
| 136 | '--parallel', |
| 137 | 'GMAIL_SEND_EMAIL', |
| 138 | '-d', |
| 139 | '{}', |
| 140 | 'GITHUB_CREATE_ISSUE', |
| 141 | '--help', |
| 142 | ]); |
| 143 | expect(help.exitCode).toBe(0); |
| 144 | expect(help.stdout).toContain('--parallel'); |
| 145 | expect(help.stdout).toContain('--get-schema'); |
| 146 | expect(help.stderr).toBe(''); |
| 147 | }) |
| 148 | ); |
| 149 | |
| 150 | it.effect('preserves native help after a value-taking option', () => |
| 151 | Effect.gen(function* () { |
| 152 | const output = yield* capture(['orgs', '--log-level', 'Debug', 'list', '--help']); |
| 153 | expect(output.exitCode).toBe(0); |
| 154 | expect(output.stdout).toContain('composio orgs list'); |
| 155 | expect(output.stdout).toContain('--limit'); |
| 156 | expect(output.stderr).toBe(''); |
| 157 | }) |
| 158 | ); |
| 159 | }); |
| 160 | }); |