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
+const log = {
12
+ id: 'log_1',
13
+ appName: 'gmail',
14
+ status: 'success',
15
+ createdAt: '2026-02-25T22:01:22.865Z',
16
+ entityId: 'user_1',
17
+ connectionId: 'conn_1',
18
+ triggerId: 'trigger_1',
19
+ triggerNanoId: 'ti_1',
20
+ triggerName: 'GMAIL_NEW_GMAIL_MESSAGE',
21
+};
22
+
23
+describe('CLI: composio dev logs triggers', () => {
24
+ layer(testLayer)('[Given] no filters and no logs', it => {
25
+ it.effect('[Then] it warns and prints the empty page as the API returned it', () =>
26
+ Effect.gen(function* () {
27
+ const page = { data: [] };
28
+ const stub = stubClientResources(['logs'], () => Response.json(page));
29
+ yield* cli(['dev', 'logs', 'triggers']).pipe(Effect.provide(stub.layer));
30
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
31
+
32
+ expect(lines.join('\n')).toContain('No trigger logs found for the given filters.');
33
+ expect(lines.at(-1)).toBe(JSON.stringify(page, null, 2));
34
+ expect(stub.requests).toMatchObject([
35
+ { method: 'POST', body: { limit: 30, include_payload: false } },
36
+ ]);
37
+ expect(stub.requests[0]?.body).not.toHaveProperty('search_params');
38
+ })
39
+ );
40
+ });
41
+
42
+ layer(testLayer)('[Given] every filter flag', it => {
43
+ it.effect('[Then] each is sent as search params in a fixed order and the limit is clamped', () =>
44
+ Effect.gen(function* () {
45
+ const stub = stubClientResources(['logs'], () => Response.json({ data: [] }));
46
+ yield* cli([
47
+ 'dev',
48
+ 'logs',
49
+ 'triggers',
50
+ '--log-id',
51
+ 'log_a',
52
+ '--connected-account-id',
53
+ 'ca_1,ca_2',
54
+ '--user-id',
55
+ 'user_1',
56
+ '--trigger-id',
57
+ 'ti_1',
58
+ '--trigger',
59
+ 'GMAIL_NEW_GMAIL_MESSAGE,SLACK_NEW_MESSAGE',
60
+ '--cursor',
61
+ 'cur_1',
62
+ '--time',
63
+ '1d',
64
+ '--search',
65
+ 'inbox',
66
+ '--from',
67
+ '1',
68
+ '--to',
69
+ '2',
70
+ '--limit',
71
+ '5000',
72
+ '--include-payload',
73
+ ]).pipe(Effect.provide(stub.layer));
74
+
75
+ expect(stub.requests).toMatchObject([
76
+ {
77
+ body: {
78
+ cursor: 'cur_1',
79
+ time: '1d',
80
+ search: 'inbox',
81
+ from: 1,
82
+ to: 2,
83
+ limit: 1000,
84
+ include_payload: true,
85
+ search_params: [
86
+ { field: 'trigger_name', operation: '==', value: 'GMAIL_NEW_GMAIL_MESSAGE' },
87
+ { field: 'trigger_name', operation: '==', value: 'SLACK_NEW_MESSAGE' },
88
+ { field: 'trigger_id', operation: '==', value: 'ti_1' },
89
+ { field: 'user_id', operation: '==', value: 'user_1' },
90
+ { field: 'connected_account_id', operation: '==', value: 'ca_1' },
91
+ { field: 'connected_account_id', operation: '==', value: 'ca_2' },
92
+ { field: 'log_id', operation: '==', value: 'log_a' },
93
+ ],
94
+ },
95
+ },
96
+ ]);
97
+ })
98
+ );
99
+ });
100
+
101
+ layer(testLayer)('[Given] a page with a log id and a next cursor', it => {
102
+ it.effect('[Then] it lists the logs, hints at the first one, and prints the cursor', () =>
103
+ Effect.gen(function* () {
104
+ const page = { data: [log], nextCursor: 'cur_2' };
105
+ const stub = stubClientResources(['logs'], () => Response.json(page));
106
+ yield* cli(['dev', 'logs', 'triggers']).pipe(Effect.provide(stub.layer));
107
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
108
+ const output = lines.join('\n');
109
+
110
+ expect(output).toContain('Listing 1 trigger log\n');
111
+ expect(output).toContain('GMAIL_NEW_GMAIL_MESSAGE');
112
+ expect(output).toContain('composio dev logs triggers "log_1"');
113
+ expect(output).toContain('Next cursor: cur_2');
114
+ expect(lines.at(-1)).toBe(JSON.stringify(page, null, 2));
115
+ })
116
+ );
117
+ });
118
+
119
+ layer(testLayer)('[Given] a log id argument', it => {
120
+ it.effect('[Then] it fetches that log alone and prints it as the API returned it', () =>
121
+ Effect.gen(function* () {
122
+ const stub = stubClientResources(['logs'], () => Response.json(log));
123
+ yield* cli(['dev', 'logs', 'triggers', 'log_1']).pipe(Effect.provide(stub.layer));
124
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
125
+
126
+ expect(stub.requests).toMatchObject([{ method: 'GET' }]);
127
+ expect(stub.requests[0]?.path).toContain('log_1');
128
+ expect(lines.join('\n')).toContain('Payload:');
129
+ expect(lines.at(-1)).toBe(JSON.stringify(log, null, 2));
130
+ })
131
+ );
132
+ });
133
+
134
+ layer(testLayer)('[Given] an empty log id argument', it => {
135
+ it.effect('[Then] it lists logs instead of fetching one', () =>
136
+ Effect.gen(function* () {
137
+ const stub = stubClientResources(['logs'], () => Response.json({ data: [] }));
138
+ yield* cli(['dev', 'logs', 'triggers', '']).pipe(Effect.provide(stub.layer));
139
+
140
+ expect(stub.requests).toMatchObject([{ method: 'POST' }]);
141
+ })
142
+ );
143
+ });
144
+
145
+ layer(testLayer)('[Given] the API rejects the list request', it => {
146
+ it.effect('[Then] the command fails with TriggerLogsRequestError', () =>
147
+ Effect.gen(function* () {
148
+ const stub = stubClientResources(['logs'], () =>
149
+ Response.json(
150
+ { error: { message: 'Not allowed', code: 1403, slug: 'Forbidden', status: 403 } },
151
+ { status: 403 }
152
+ )
153
+ );
154
+ const failure = yield* cli(['dev', 'logs', 'triggers']).pipe(
155
+ Effect.provide(stub.layer),
156
+ Effect.flip
157
+ );
158
+
159
+ expect(failure).toMatchObject({
160
+ _tag: 'commands/TriggerLogsRequestError',
161
+ message: 'Failed to fetch trigger logs.',
162
+ });
163
+ })
164
+ );
165
+ });
166
+
167
+ layer(testLayer)('[Given] the API rejects the request for one log', it => {
168
+ it.effect('[Then] the failure names the log id', () =>
169
+ Effect.gen(function* () {
170
+ const stub = stubClientResources(['logs'], () =>
171
+ Response.json(
172
+ { error: { message: 'Not found', code: 1404, slug: 'Not_Found', status: 404 } },
173
+ { status: 404 }
174
+ )
175
+ );
176
+ const failure = yield* cli(['dev', 'logs', 'triggers', 'log_missing']).pipe(
177
+ Effect.provide(stub.layer),
178
+ Effect.flip
179
+ );
180
+
181
+ expect(failure).toMatchObject({
182
+ _tag: 'commands/TriggerLogsRequestError',
183
+ message: 'Failed to fetch trigger log "log_missing".',
184
+ });
185
+ })
186
+ );
187
+ });
188
+});