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 { describe, expect, layer } from '@effect/vitest'; |
| 2 | import { ConfigProvider, Effect } from 'effect'; |
| 3 | import { cli, cliExit, MockConsole, TestLive } from 'test/__utils__'; |
| 4 | import { |
| 5 | DIRECTORY_PROJECT_SCOPE, |
| 6 | DEFAULT_PROJECT_SCOPE, |
| 7 | defaultDeveloperProjectAccountData, |
| 8 | inDeveloperProjectDirectory, |
| 9 | loginWithoutDeveloperProject, |
| 10 | OTHER_DEVELOPER_PROJECT, |
| 11 | OTHER_PROJECT_SCOPE, |
| 12 | } from 'test/__utils__/layers/developer-project'; |
| 13 | import { stubClientResources } from 'test/__utils__/services/stub-composio-client'; |
| 14 | |
| 15 | const testLayer = TestLive({ |
| 16 | baseConfigProvider: ConfigProvider.fromEnv({ env: { COMPOSIO_USER_API_KEY: 'test_api_key' } }), |
| 17 | fixture: 'global-test-user-id', |
| 18 | }); |
| 19 | |
| 20 | const log = { |
| 21 | id: 'log_1', |
| 22 | appName: 'gmail', |
| 23 | status: 'success', |
| 24 | createdAt: '2026-02-25T22:01:22.865Z', |
| 25 | entityId: 'user_1', |
| 26 | connectionId: 'conn_1', |
| 27 | triggerId: 'trigger_1', |
| 28 | triggerNanoId: 'ti_1', |
| 29 | triggerName: 'GMAIL_NEW_GMAIL_MESSAGE', |
| 30 | }; |
| 31 | |
| 32 | describe('CLI: composio dev logs triggers', () => { |
| 33 | layer(testLayer)('[Given] no filters and no logs', it => { |
| 34 | it.effect('[Then] it warns and prints the empty page as the API returned it', () => |
| 35 | Effect.gen(function* () { |
| 36 | const page = { data: [] }; |
| 37 | const stub = stubClientResources(['_internal'], () => Response.json(page)); |
| 38 | yield* cli(['dev', 'logs', 'triggers']).pipe(Effect.provide(stub.layer)); |
| 39 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 40 | |
| 41 | expect(lines.join('\n')).toContain('No trigger logs found for the given filters.'); |
| 42 | expect(lines.at(-1)).toBe(JSON.stringify(page, null, 2)); |
| 43 | expect(stub.requests).toMatchObject([ |
| 44 | { method: 'POST', body: { limit: 30, include_payload: false } }, |
| 45 | ]); |
| 46 | expect(stub.requests[0]?.body).not.toHaveProperty('search_params'); |
| 47 | }) |
| 48 | ); |
| 49 | }); |
| 50 | |
| 51 | layer(testLayer)('[Given] every filter flag', it => { |
| 52 | it.effect('[Then] each is sent as search params in a fixed order and the limit is clamped', () => |
| 53 | Effect.gen(function* () { |
| 54 | const stub = stubClientResources(['_internal'], () => Response.json({ data: [] })); |
| 55 | yield* cli([ |
| 56 | 'dev', |
| 57 | 'logs', |
| 58 | 'triggers', |
| 59 | '--log-id', |
| 60 | 'log_a', |
| 61 | '--connected-account-id', |
| 62 | 'ca_1,ca_2', |
| 63 | '--user-id', |
| 64 | 'user_1', |
| 65 | '--trigger-id', |
| 66 | 'ti_1', |
| 67 | '--trigger', |
| 68 | 'GMAIL_NEW_GMAIL_MESSAGE,SLACK_NEW_MESSAGE', |
| 69 | '--cursor', |
| 70 | 'cur_1', |
| 71 | '--time', |
| 72 | '1d', |
| 73 | '--search', |
| 74 | 'inbox', |
| 75 | '--from', |
| 76 | '1', |
| 77 | '--to', |
| 78 | '2', |
| 79 | '--limit', |
| 80 | '5000', |
| 81 | '--include-payload', |
| 82 | ]).pipe(Effect.provide(stub.layer)); |
| 83 | |
| 84 | expect(stub.requests).toMatchObject([ |
| 85 | { |
| 86 | body: { |
| 87 | cursor: 'cur_1', |
| 88 | time: '1d', |
| 89 | search: 'inbox', |
| 90 | from: 1, |
| 91 | to: 2, |
| 92 | limit: 1000, |
| 93 | include_payload: true, |
| 94 | search_params: [ |
| 95 | { field: 'trigger_name', operation: '==', value: 'GMAIL_NEW_GMAIL_MESSAGE' }, |
| 96 | { field: 'trigger_name', operation: '==', value: 'SLACK_NEW_MESSAGE' }, |
| 97 | { field: 'trigger_id', operation: '==', value: 'ti_1' }, |
| 98 | { field: 'user_id', operation: '==', value: 'user_1' }, |
| 99 | { field: 'connected_account_id', operation: '==', value: 'ca_1' }, |
| 100 | { field: 'connected_account_id', operation: '==', value: 'ca_2' }, |
| 101 | { field: 'log_id', operation: '==', value: 'log_a' }, |
| 102 | ], |
| 103 | }, |
| 104 | }, |
| 105 | ]); |
| 106 | }) |
| 107 | ); |
| 108 | }); |
| 109 | |
| 110 | layer(testLayer)('[Given] a page with a log id and a next cursor', it => { |
| 111 | it.effect('[Then] it lists the logs, hints at the first one, and prints the cursor', () => |
| 112 | Effect.gen(function* () { |
| 113 | const page = { data: [log], nextCursor: 'cur_2' }; |
| 114 | const stub = stubClientResources(['_internal'], () => Response.json(page)); |
| 115 | yield* cli(['dev', 'logs', 'triggers']).pipe(Effect.provide(stub.layer)); |
| 116 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 117 | const output = lines.join('\n'); |
| 118 | |
| 119 | expect(output).toContain('Listing 1 trigger log\n'); |
| 120 | expect(output).toContain('GMAIL_NEW_GMAIL_MESSAGE'); |
| 121 | expect(output).toContain('composio dev logs triggers "log_1"'); |
| 122 | expect(output).toContain('Next cursor: cur_2'); |
| 123 | expect(lines.at(-1)).toBe(JSON.stringify(page, null, 2)); |
| 124 | }) |
| 125 | ); |
| 126 | }); |
| 127 | |
| 128 | layer(testLayer)('[Given] a log id argument', it => { |
| 129 | it.effect('[Then] it fetches that log alone and prints it as the API returned it', () => |
| 130 | Effect.gen(function* () { |
| 131 | const stub = stubClientResources(['_internal'], () => Response.json(log)); |
| 132 | yield* cli(['dev', 'logs', 'triggers', 'log_1']).pipe(Effect.provide(stub.layer)); |
| 133 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 134 | |
| 135 | expect(stub.requests).toMatchObject([{ method: 'GET' }]); |
| 136 | expect(stub.requests[0]?.path).toContain('log_1'); |
| 137 | expect(lines.join('\n')).toContain('Payload:'); |
| 138 | expect(lines.at(-1)).toBe(JSON.stringify(log, null, 2)); |
| 139 | }) |
| 140 | ); |
| 141 | }); |
| 142 | |
| 143 | layer(testLayer)('[Given] an empty log id argument', it => { |
| 144 | it.effect('[Then] it lists logs instead of fetching one', () => |
| 145 | Effect.gen(function* () { |
| 146 | const stub = stubClientResources(['_internal'], () => Response.json({ data: [] })); |
| 147 | yield* cli(['dev', 'logs', 'triggers', '']).pipe(Effect.provide(stub.layer)); |
| 148 | |
| 149 | expect(stub.requests).toMatchObject([{ method: 'POST' }]); |
| 150 | }) |
| 151 | ); |
| 152 | }); |
| 153 | |
| 154 | layer(testLayer)('[Given] the API rejects the list request', it => { |
| 155 | it.effect('[Then] the command fails with TriggerLogsRequestError', () => |
| 156 | Effect.gen(function* () { |
| 157 | const stub = stubClientResources(['_internal'], () => |
| 158 | Response.json( |
| 159 | { error: { message: 'Not allowed', code: 1403, slug: 'Forbidden', status: 403 } }, |
| 160 | { status: 403 } |
| 161 | ) |
| 162 | ); |
| 163 | const failure = yield* cli(['dev', 'logs', 'triggers']).pipe( |
| 164 | Effect.provide(stub.layer), |
| 165 | Effect.flip |
| 166 | ); |
| 167 | |
| 168 | expect(failure).toMatchObject({ |
| 169 | _tag: 'commands/TriggerLogsRequestError', |
| 170 | message: 'Failed to fetch trigger logs.', |
| 171 | }); |
| 172 | }) |
| 173 | ); |
| 174 | }); |
| 175 | |
| 176 | layer(testLayer)('[Given] the API rejects the request for one log', it => { |
| 177 | it.effect('[Then] the failure names the log id', () => |
| 178 | Effect.gen(function* () { |
| 179 | const stub = stubClientResources(['_internal'], () => |
| 180 | Response.json( |
| 181 | { error: { message: 'Not found', code: 1404, slug: 'Not_Found', status: 404 } }, |
| 182 | { status: 404 } |
| 183 | ) |
| 184 | ); |
| 185 | const failure = yield* cli(['dev', 'logs', 'triggers', 'log_missing']).pipe( |
| 186 | Effect.provide(stub.layer), |
| 187 | Effect.flip |
| 188 | ); |
| 189 | |
| 190 | expect(failure).toMatchObject({ |
| 191 | _tag: 'commands/TriggerLogsRequestError', |
| 192 | message: 'Failed to fetch trigger log "log_missing".', |
| 193 | }); |
| 194 | }) |
| 195 | ); |
| 196 | }); |
| 197 | }); |
| 198 | |
| 199 | // The request goes to the developer project the command resolved, never to the one the backend |
| 200 | // would pick for the key. |
| 201 | describe('CLI: composio dev logs triggers acts on the developer project', () => { |
| 202 | const config = ConfigProvider.fromEnv({ env: { COMPOSIO_USER_API_KEY: 'test_api_key' } }); |
| 203 | |
| 204 | layer(TestLive({ ...inDeveloperProjectDirectory, baseConfigProvider: config }))(it => { |
| 205 | it.effect.each([ |
| 206 | { given: 'a directory set up for a project', args: [], scope: DIRECTORY_PROJECT_SCOPE }, |
| 207 | { |
| 208 | given: '--project-name', |
| 209 | args: ['--project-name', OTHER_DEVELOPER_PROJECT.name], |
| 210 | scope: OTHER_PROJECT_SCOPE, |
| 211 | }, |
| 212 | { given: 'a log id', args: ['log_1'], scope: DIRECTORY_PROJECT_SCOPE }, |
| 213 | ])('[Given] $given [Then] reads the logs of that project', ({ args, scope }) => |
| 214 | Effect.gen(function* () { |
| 215 | const stub = stubClientResources(['_internal'], request => Response.json(request.method === 'GET' ? log : { data: [] })); |
| 216 | yield* cli([...['dev', 'logs', 'triggers'], ...args]).pipe(Effect.provide(stub.layer)); |
| 217 | |
| 218 | expect(stub.scopes).toEqual([scope]); |
| 219 | }) |
| 220 | ); |
| 221 | }); |
| 222 | |
| 223 | layer(TestLive({ baseConfigProvider: config, accountData: defaultDeveloperProjectAccountData() }))(it => { |
| 224 | it.effect('[Given] a directory set up for no project [Then] reads the logs of the default developer project', () => |
| 225 | Effect.gen(function* () { |
| 226 | yield* loginWithoutDeveloperProject; |
| 227 | const stub = stubClientResources(['_internal'], request => Response.json(request.method === 'GET' ? log : { data: [] })); |
| 228 | const { exitCode } = yield* cliExit(['dev', 'logs', 'triggers']).pipe(Effect.provide(stub.layer)); |
| 229 | |
| 230 | expect(exitCode).toBe(0); |
| 231 | expect(stub.scopes).toEqual([DEFAULT_PROJECT_SCOPE]); |
| 232 | }) |
| 233 | ); |
| 234 | }); |
| 235 | }); |