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 { isUsageFailure } from 'src/commands/errors'; |
| 3 | import { ConfigProvider, Effect } from 'effect'; |
| 4 | import { cli, MockConsole, TestLive } from 'test/__utils__'; |
| 5 | import { exitCodeOf } from 'test/__utils__/exit-code'; |
| 6 | import type { TriggerTypes } from 'src/models/trigger-types'; |
| 7 | import type { TestLiveInput } from 'test/__utils__/services/test-layer'; |
| 8 | |
| 9 | const testTriggerTypes: TriggerTypes = [ |
| 10 | { |
| 11 | slug: 'GMAIL_NEW_GMAIL_MESSAGE', |
| 12 | name: 'NEW_GMAIL_MESSAGE', |
| 13 | description: 'Fires when a new message arrives in Gmail', |
| 14 | instructions: 'Connect Gmail and subscribe to this trigger', |
| 15 | toolkit: { name: 'Gmail', slug: 'gmail' }, |
| 16 | type: 'webhook', |
| 17 | config: { |
| 18 | type: 'object', |
| 19 | properties: { |
| 20 | label: { type: 'string', description: 'Label filter for inbox messages' }, |
| 21 | include_spam: { |
| 22 | type: 'boolean', |
| 23 | description: 'Include spam messages', |
| 24 | default: false, |
| 25 | }, |
| 26 | }, |
| 27 | required: ['label'], |
| 28 | }, |
| 29 | payload: { |
| 30 | type: 'object', |
| 31 | properties: { |
| 32 | subject: { type: 'string', description: 'Email subject line' }, |
| 33 | from: { type: 'string', description: 'Sender email address' }, |
| 34 | }, |
| 35 | required: ['subject'], |
| 36 | }, |
| 37 | }, |
| 38 | { |
| 39 | slug: 'SLACK_NEW_MESSAGE', |
| 40 | name: 'NEW_MESSAGE', |
| 41 | description: 'Fires when a new message is posted in Slack', |
| 42 | instructions: 'Connect Slack and subscribe to this trigger', |
| 43 | toolkit: { name: 'Slack', slug: 'slack' }, |
| 44 | type: 'webhook', |
| 45 | config: { type: 'object', properties: {} }, |
| 46 | payload: { type: 'object', properties: {} }, |
| 47 | }, |
| 48 | ]; |
| 49 | |
| 50 | const toolkitsData = { |
| 51 | triggerTypes: testTriggerTypes, |
| 52 | } satisfies TestLiveInput['toolkitsData']; |
| 53 | |
| 54 | const testConfigProvider = ConfigProvider.fromEnv({ |
| 55 | env: { COMPOSIO_USER_API_KEY: 'test_api_key' }, |
| 56 | }); |
| 57 | |
| 58 | describe('CLI: composio dev triggers info', () => { |
| 59 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 60 | '[Given] root triggers info [Then] displays trigger info with root-level hint', |
| 61 | it => { |
| 62 | it.effect('supports the top-level triggers info entrypoint', () => |
| 63 | Effect.gen(function* () { |
| 64 | yield* cli(['triggers', 'info', 'GMAIL_NEW_GMAIL_MESSAGE']); |
| 65 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 66 | const output = lines.join('\n'); |
| 67 | |
| 68 | expect(output).toContain('GMAIL_NEW_GMAIL_MESSAGE'); |
| 69 | expect(output).toContain('composio triggers list "gmail"'); |
| 70 | }) |
| 71 | ); |
| 72 | } |
| 73 | ); |
| 74 | |
| 75 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 76 | '[Given] valid slug [Then] displays trigger type info', |
| 77 | it => { |
| 78 | it.effect('shows trigger details with config and payload fields', () => |
| 79 | Effect.gen(function* () { |
| 80 | yield* cli(['dev', 'triggers', 'info', 'GMAIL_NEW_GMAIL_MESSAGE']); |
| 81 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 82 | const output = lines.join('\n'); |
| 83 | |
| 84 | expect(output).toContain('NEW_GMAIL_MESSAGE'); |
| 85 | expect(output).toContain('GMAIL_NEW_GMAIL_MESSAGE'); |
| 86 | expect(output).toContain('Config Fields'); |
| 87 | expect(output).toContain('label'); |
| 88 | expect(output).toContain('required'); |
| 89 | expect(output).toContain('Payload Fields'); |
| 90 | expect(output).toContain('subject'); |
| 91 | expect(output).toContain('default:'); |
| 92 | expect(output).toContain('false'); |
| 93 | expect(output).toContain('composio dev triggers list "gmail"'); |
| 94 | }) |
| 95 | ); |
| 96 | } |
| 97 | ); |
| 98 | |
| 99 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 100 | '[Given] no slug [Then] fails with a usage error', |
| 101 | it => { |
| 102 | it.effect('raises a CommandInputError naming <slug>', () => |
| 103 | Effect.gen(function* () { |
| 104 | const failure = yield* cli(['dev', 'triggers', 'info']).pipe(Effect.flip); |
| 105 | |
| 106 | expect(failure).toMatchObject({ |
| 107 | _tag: 'commands/CommandInputError', |
| 108 | command: 'dev triggers info', |
| 109 | option: '<slug>', |
| 110 | message: |
| 111 | 'Missing required argument: <slug>\nTry specifying a trigger slug, e.g.:\n> composio dev triggers info "GMAIL_NEW_GMAIL_MESSAGE"', |
| 112 | }); |
| 113 | // The invocation prints the message on stderr, and nothing else. |
| 114 | assert(isUsageFailure(failure)); |
| 115 | expect(yield* MockConsole.getLines()).toEqual([failure.message]); |
| 116 | }) |
| 117 | ); |
| 118 | |
| 119 | it.effect('names the root command on the root tree', () => |
| 120 | Effect.gen(function* () { |
| 121 | const failure = yield* cli(['triggers', 'info']).pipe(Effect.flip); |
| 122 | |
| 123 | expect(failure).toMatchObject({ |
| 124 | _tag: 'commands/CommandInputError', |
| 125 | command: 'triggers info', |
| 126 | message: expect.stringContaining('> composio triggers info "GMAIL_NEW_GMAIL_MESSAGE"'), |
| 127 | }); |
| 128 | }) |
| 129 | ); |
| 130 | } |
| 131 | ); |
| 132 | |
| 133 | layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))( |
| 134 | '[Given] invalid slug [Then] shows not found hint', |
| 135 | it => { |
| 136 | it.effect('shows not found fallback hint', () => |
| 137 | Effect.gen(function* () { |
| 138 | const exit = yield* Effect.exit(cli(['dev', 'triggers', 'info', 'NONEXISTENT_TRIGGER'])); |
| 139 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 140 | const output = lines.join('\n'); |
| 141 | |
| 142 | expect(output).toContain('not found'); |
| 143 | expect(output).toContain('composio dev triggers list "<toolkit>"'); |
| 144 | // One plain stderr emission: the message, then the hint. |
| 145 | expect(lines).toEqual([ |
| 146 | 'Trigger "NONEXISTENT_TRIGGER" not found.', |
| 147 | 'Browse available trigger types:\n> composio dev triggers list "<toolkit>"', |
| 148 | ]); |
| 149 | expect(exitCodeOf(exit)).toBe(1); |
| 150 | }) |
| 151 | ); |
| 152 | } |
| 153 | ); |
| 154 | |
| 155 | layer(TestLive())('[Given] no API key [Then] warns user to login', it => { |
| 156 | it.effect('warns user to login', () => |
| 157 | Effect.gen(function* () { |
| 158 | const error = yield* cli(['dev', 'triggers', 'info', 'GMAIL_NEW_GMAIL_MESSAGE']).pipe( |
| 159 | Effect.flip |
| 160 | ); |
| 161 | expect(error).toMatchObject({ _tag: 'commands/NotLoggedInError' }); |
| 162 | }) |
| 163 | ); |
| 164 | }); |
| 165 | }); |