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, it } from '@effect/vitest'; |
| 2 | import { Effect, Option } from 'effect'; |
| 3 | import { runAuthConfigsInfo } from 'src/commands/auth-configs/info/auth-configs.info.handler'; |
| 4 | import { isUsageFailure } from 'src/commands/errors'; |
| 5 | import { MockConsole } from 'test/__utils__'; |
| 6 | import { exitCodeOf } from 'test/__utils__/exit-code'; |
| 7 | import { AuthConfigsHandlerTest } from 'test/__utils__/layers/auth-configs'; |
| 8 | import { makeAuthConfigItem } from 'test/__utils__/models/auth-configs'; |
| 9 | |
| 10 | const gmail = makeAuthConfigItem(); |
| 11 | |
| 12 | describe('runAuthConfigsInfo', () => { |
| 13 | it.effect('[Given] a known ID [Then] prints the auth config JSON to stdout', () => { |
| 14 | const { layer, outputs } = AuthConfigsHandlerTest({ |
| 15 | authConfigsData: { items: [gmail] }, |
| 16 | }); |
| 17 | return Effect.gen(function* () { |
| 18 | yield* runAuthConfigsInfo({ id: Option.some('ac_gmail_default') }); |
| 19 | |
| 20 | expect(outputs).toEqual([JSON.stringify(gmail, null, 2)]); |
| 21 | const decoration = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n'); |
| 22 | expect(decoration).toContain('[Auth Config: Gmail Default]'); |
| 23 | expect(decoration).toContain('Tool Router: Enabled'); |
| 24 | }).pipe(Effect.provide(layer)); |
| 25 | }); |
| 26 | |
| 27 | it.effect('[Given] no ID [Then] fails with a usage error before any request', () => { |
| 28 | // The stub repository dies on any call, so reaching the API fails the test. |
| 29 | const { layer, outputs } = AuthConfigsHandlerTest({ |
| 30 | repository: { getAuthConfig: () => Effect.die('getAuthConfig must not be called') }, |
| 31 | }); |
| 32 | return Effect.gen(function* () { |
| 33 | const failure = yield* runAuthConfigsInfo({ id: Option.none() }).pipe(Effect.flip); |
| 34 | |
| 35 | expect(failure).toMatchObject({ |
| 36 | _tag: 'commands/CommandInputError', |
| 37 | command: 'dev auth-configs info', |
| 38 | option: '<id>', |
| 39 | message: expect.stringMatching( |
| 40 | /^Missing required argument: <id>\n[\s\S]*> composio dev auth-configs list$/ |
| 41 | ), |
| 42 | }); |
| 43 | // The invocation prints a usage failure on stderr and exits 1. |
| 44 | expect(isUsageFailure(failure)).toBe(true); |
| 45 | expect(yield* MockConsole.getLines()).toEqual([]); |
| 46 | expect(outputs).toEqual([]); |
| 47 | }).pipe(Effect.provide(layer)); |
| 48 | }); |
| 49 | |
| 50 | it.effect( |
| 51 | '[Given] an unknown ID [Then] reports the API error with the list hint and exits 1', |
| 52 | () => { |
| 53 | const { layer, outputs } = AuthConfigsHandlerTest({ |
| 54 | authConfigsData: { items: [gmail] }, |
| 55 | }); |
| 56 | return Effect.gen(function* () { |
| 57 | const exit = yield* Effect.exit(runAuthConfigsInfo({ id: Option.some('ac_missing') })); |
| 58 | |
| 59 | const stderr = (yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true })).join( |
| 60 | '\n' |
| 61 | ); |
| 62 | expect(stderr).toContain('Auth config "ac_missing" not found.'); |
| 63 | expect(stderr).toContain( |
| 64 | 'Browse available auth configs:\n> composio dev auth-configs list' |
| 65 | ); |
| 66 | expect(outputs).toEqual([]); |
| 67 | expect(exitCodeOf(exit)).toBe(1); |
| 68 | }).pipe(Effect.provide(layer)); |
| 69 | } |
| 70 | ); |
| 71 | }); |