Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { assert, describe, expect, layer } from '@effect/vitest'; |
| 2 | import { ConfigProvider, Effect, Layer } from 'effect'; |
| 3 | import { isUsageFailure } from 'src/commands/errors'; |
| 4 | import { ComposioToolkitsRepository } from 'src/services/composio-clients'; |
| 5 | import { cli, MockConsole, TestLive } from 'test/__utils__'; |
| 6 | import { notFoundError } from 'test/__utils__/layers/not-found'; |
| 7 | import { exitCodeOf } from 'test/__utils__/exit-code'; |
| 8 | import { makeToolkitsRepositoryStub } from 'test/__utils__/services/toolkits-repository-stub'; |
| 9 | import { |
| 10 | DIRECTORY_PROJECT_SCOPE, |
| 11 | DEFAULT_PROJECT_SCOPE, |
| 12 | defaultDeveloperProjectAccountData, |
| 13 | inDeveloperProjectDirectory, |
| 14 | loginWithoutDeveloperProject, |
| 15 | OTHER_DEVELOPER_PROJECT, |
| 16 | OTHER_PROJECT_SCOPE, |
| 17 | runRecordingRepositoryScopes, |
| 18 | } from 'test/__utils__/layers/developer-project'; |
| 19 | |
| 20 | const testConfigProvider = ConfigProvider.fromEnv({ |
| 21 | env: { COMPOSIO_USER_API_KEY: 'test_api_key' }, |
| 22 | }); |
| 23 | |
| 24 | const devConfigWithoutProject = { |
| 25 | baseConfigProvider: testConfigProvider, |
| 26 | cliUserConfig: { developerDangerousCommandsEnabled: true }, |
| 27 | } as const; |
| 28 | |
| 29 | const dangerousDevConfig = { ...inDeveloperProjectDirectory, ...devConfigWithoutProject } as const; |
| 30 | |
| 31 | describe('CLI: composio dev triggers enable', () => { |
| 32 | layer(TestLive(dangerousDevConfig))('[Given] enable with ID [Then] enables trigger', it => { |
| 33 | it.effect('enables trigger successfully', () => |
| 34 | Effect.gen(function* () { |
| 35 | yield* cli(['dev', 'triggers', 'enable', 'trg_123']); |
| 36 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 37 | const output = lines.join('\n'); |
| 38 | expect(output).toContain('enabled'); |
| 39 | }) |
| 40 | ); |
| 41 | }); |
| 42 | |
| 43 | layer(TestLive(dangerousDevConfig))( |
| 44 | '[Given] missing ID for enable [Then] fails with a usage error before any request', |
| 45 | it => { |
| 46 | it.effect('raises a CommandInputError naming <id>', () => |
| 47 | Effect.gen(function* () { |
| 48 | // Every repository method dies, so reaching the API fails the test. |
| 49 | const repository = Layer.succeed( |
| 50 | ComposioToolkitsRepository, |
| 51 | makeToolkitsRepositoryStub({}) |
| 52 | ); |
| 53 | const failure = yield* cli(['dev', 'triggers', 'enable']).pipe( |
| 54 | Effect.provide(repository), |
| 55 | Effect.flip |
| 56 | ); |
| 57 | |
| 58 | expect(failure).toMatchObject({ |
| 59 | _tag: 'commands/CommandInputError', |
| 60 | command: 'dev triggers enable', |
| 61 | option: '<id>', |
| 62 | message: expect.stringMatching( |
| 63 | /^Missing required argument: <id>\n[\s\S]*> composio dev triggers status --show-disabled$/ |
| 64 | ), |
| 65 | }); |
| 66 | // The invocation prints the message on stderr, and nothing else. |
| 67 | assert(isUsageFailure(failure)); |
| 68 | expect(yield* MockConsole.getLines()).toEqual([failure.message]); |
| 69 | }) |
| 70 | ); |
| 71 | } |
| 72 | ); |
| 73 | |
| 74 | layer(TestLive(dangerousDevConfig))( |
| 75 | '[Given] the API rejects the enable [Then] reports the failure and exits 1', |
| 76 | it => { |
| 77 | it.effect('prints the fallback message and the status hint', () => |
| 78 | Effect.gen(function* () { |
| 79 | const repository = Layer.succeed( |
| 80 | ComposioToolkitsRepository, |
| 81 | makeToolkitsRepositoryStub({ |
| 82 | enableTrigger: () => Effect.fail(notFoundError('Trigger not found')), |
| 83 | }) |
| 84 | ); |
| 85 | const exit = yield* Effect.exit( |
| 86 | cli(['dev', 'triggers', 'enable', 'trg_missing']).pipe(Effect.provide(repository)) |
| 87 | ); |
| 88 | const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n'); |
| 89 | |
| 90 | expect(output).toContain('Failed to enable trigger "trg_missing".'); |
| 91 | expect(output).toContain('composio dev triggers status --show-disabled'); |
| 92 | expect(output).not.toContain('Trigger "trg_missing" enabled.'); |
| 93 | expect(exitCodeOf(exit)).toBe(1); |
| 94 | }) |
| 95 | ); |
| 96 | } |
| 97 | ); |
| 98 | }); |
| 99 | |
| 100 | // The request goes to the developer project the command resolved, never to the one the backend |
| 101 | // would pick for the key. |
| 102 | describe('CLI: composio dev triggers enable acts on the developer project', () => { |
| 103 | layer(TestLive(dangerousDevConfig))(it => { |
| 104 | it.effect.each([ |
| 105 | { given: 'a directory set up for a project', args: [], scope: DIRECTORY_PROJECT_SCOPE }, |
| 106 | { |
| 107 | given: '--project-name', |
| 108 | args: ['--project-name', OTHER_DEVELOPER_PROJECT.name], |
| 109 | scope: OTHER_PROJECT_SCOPE, |
| 110 | }, |
| 111 | ])('[Given] $given [Then] enables the trigger in that project', ({ args, scope }) => |
| 112 | Effect.gen(function* () { |
| 113 | const { exitCode, calls } = yield* runRecordingRepositoryScopes([ |
| 114 | ...['dev', 'triggers', 'enable', 'trg_123'], |
| 115 | ...args, |
| 116 | ]); |
| 117 | |
| 118 | expect(exitCode).toBe(0); |
| 119 | expect(calls).toEqual([{ method: 'enableTrigger', scope: expect.objectContaining(scope) }]); |
| 120 | }) |
| 121 | ); |
| 122 | }); |
| 123 | |
| 124 | layer( |
| 125 | TestLive({ ...devConfigWithoutProject, accountData: defaultDeveloperProjectAccountData() }) |
| 126 | )(it => { |
| 127 | it.effect( |
| 128 | '[Given] a directory set up for no project [Then] acts on the default developer project', |
| 129 | () => |
| 130 | Effect.gen(function* () { |
| 131 | yield* loginWithoutDeveloperProject; |
| 132 | const { exitCode, calls } = yield* runRecordingRepositoryScopes([ |
| 133 | 'dev', |
| 134 | 'triggers', |
| 135 | 'enable', |
| 136 | 'trg_123', |
| 137 | ]); |
| 138 | |
| 139 | expect(exitCode).toBe(0); |
| 140 | expect(calls).toEqual([ |
| 141 | { method: 'enableTrigger', scope: expect.objectContaining(DEFAULT_PROJECT_SCOPE) }, |
| 142 | ]); |
| 143 | }) |
| 144 | ); |
| 145 | }); |
| 146 | }); |