Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 78 lines 3.11 KB
Raw
1 import { describe, expect, layer } from '@effect/vitest';
2 import { ConfigProvider, Effect } from 'effect';
3 import { cli, MockConsole, TestLive } from 'test/__utils__';
4 import { stubClientResources } from 'test/__utils__/services/stub-composio-client';
5
6 const testLayer = TestLive({
7 baseConfigProvider: ConfigProvider.fromEnv({ env: { COMPOSIO_USER_API_KEY: 'test_api_key' } }),
8 fixture: 'global-test-user-id',
9 });
10
11 // The API has served trigger logs in snake_case with numeric timestamps and
12 // without `meta`; the response schema the client ships allows none of that.
13 const olderLog = {
14 log_id: 'log_older_1',
15 trigger_id: 'trigger_1',
16 trigger_nano_id: 'ti_older_1',
17 trigger_name: 'SLACK_NEW_MESSAGE',
18 toolkit_key: 'slack',
19 connection_id: 'conn_1',
20 entity_id: 'user_1',
21 status: 'success',
22 created_at: 1767225600000,
23 };
24
25 describe('CLI: composio dev logs triggers over the API client', () => {
26 layer(testLayer)('[Given] a page of trigger logs in an older response shape', it => {
27 it.effect('[Then] the logs are listed and printed as the API returned them', () =>
28 Effect.gen(function* () {
29 const page = { data: [olderLog] };
30 const stub = stubClientResources(['_internal'], () => Response.json(page));
31 yield* cli(['dev', 'logs', 'triggers']).pipe(Effect.provide(stub.layer));
32 const lines = yield* MockConsole.getLines({ stripAnsi: true });
33
34 expect(lines.join('\n')).toContain('ti_older_1');
35 expect(lines.join('\n')).toContain('SLACK_NEW_MESSAGE');
36 expect(lines.at(-1)).toBe(JSON.stringify(page, null, 2));
37 })
38 );
39 });
40
41 layer(testLayer)('[Given] a comma-separated --user-id filter', it => {
42 it.effect.each([
43 {
44 name: 'after the subcommand',
45 args: ['dev', 'logs', 'triggers', '--user-id', 'user_1,user_2'],
46 },
47 {
48 name: 'before the subcommand',
49 args: ['dev', '--user-id', 'user_1,user_2', 'logs', 'triggers'],
50 },
51 ])('[Then] each user id is sent as a search param when passed $name', ({ args }) =>
52 Effect.gen(function* () {
53 const stub = stubClientResources(['_internal'], () => Response.json({ data: [] }));
54 yield* cli(args).pipe(Effect.provide(stub.layer));
55
56 expect(JSON.stringify(stub.requests)).toContain(
57 JSON.stringify({ field: 'user_id', operation: '==', value: 'user_1' })
58 );
59 expect(JSON.stringify(stub.requests)).toContain(
60 JSON.stringify({ field: 'user_id', operation: '==', value: 'user_2' })
61 );
62 })
63 );
64 });
65
66 layer(testLayer)('[Given] one trigger log in an older response shape', it => {
67 it.effect('[Then] its details are shown and it is printed as the API returned it', () =>
68 Effect.gen(function* () {
69 const stub = stubClientResources(['_internal'], () => Response.json(olderLog));
70 yield* cli(['dev', 'logs', 'triggers', 'log_older_1']).pipe(Effect.provide(stub.layer));
71 const lines = yield* MockConsole.getLines({ stripAnsi: true });
72
73 expect(lines.join('\n')).toContain('SLACK_NEW_MESSAGE');
74 expect(lines.at(-1)).toBe(JSON.stringify(olderLog, null, 2));
75 })
76 );
77 });
78 });