@devries-cameron20 / composio-1 / commits / d711f56a0
Fork 0

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

refactor(cli): move `logs triggers` to the directory shape (#4971)

This PR: - moves `dev logs triggers` to `logs/triggers/logs.triggers.{cmd,handler,errors}.ts` - builds the search params with one `Option.match` per filter, in the same order, and routes to the single-log or list flow - moves the client test beside a new mirrored `logs.triggers.cmd.test.ts` (7 cases) - removes the exemption from `COMMAND_TEST_EXEMPTIONS` (15 → 14) - part of U9 of the CLI command-layout series; no user-visible change, so no CHANGELOG entry ## Context The root `.gitignore` has a bare `logs` rule, so new files under `src/commands/logs/` needed `git add -f`; future moves under `logs/` will hit the same thing. Verified: `pnpm --filter @composio/cli test` (1905 passed), CLI typecheck, `lint:effect`, oxlint, prettier, `validate:command-tests`. `--help` is byte-identical to the `origin/next` binary.

Alberto Schiabel committed Oct 20, 2026 at 15:29 UTC d711f56a04f883e125cba1696ed1ba79e3a42c37
8 files changed +435 -223
ts/packages/cli/scripts/command-tests.ts
-4
@@ -21,10 +21,6 @@ export const COMMAND_TEST_EXEMPTIONS: readonly CommandTestExemption[] = [
21 { command: 'artifacts.cmd.ts', reason: 'no test yet' },
22 { command: 'connections/commands/connections.remove.cmd.ts', reason: 'no test yet' },
23 { command: 'debug.cmd.ts', reason: 'no test yet' },
24 - {
25 - command: 'logs/commands/logs.triggers.cmd.ts',
26 - reason: 'covered by logs.triggers.client.cmd.test.ts; split pending',
27 - },
24 { command: 'orgs/commands/orgs.list.cmd.ts', reason: 'no test yet' },
25 { command: 'signup.cmd.ts', reason: 'no test yet' },
26 { command: 'triggers/commands/triggers.listen.cmd.ts', reason: 'no test yet' },
ts/packages/cli/src/commands/logs/commands/logs.triggers.cmd.ts deleted
-218
@@ -1,218 +0,0 @@
1 -import { Argument, Command, Flag } from 'effect/cli';
2 -import { Effect, Option } from 'effect';
3 -import { failedWith, requestError } from 'src/effects/request-error';
4 -import { TerminalUI } from 'src/services/terminal-ui';
5 -import { CommandSurface } from 'src/commands/surface';
6 -import { ComposioClientSingleton } from 'src/services/composio-clients';
7 -import { clampLimit } from 'src/ui/clamp-limit';
8 -import { nonEmptyOrUndefined, optionalParams } from 'src/utils/optional-params';
9 -import { parseCsv } from 'src/commands/triggers/parse-csv';
10 -import { formatTriggerLogInfo, formatTriggerLogsTable } from '../format';
11 -import { decodeTriggerLogRecord } from '../trigger-log-record';
12 -import { commandHintStep } from 'src/services/command-hints';
13 -import { toSearchParam } from '../utils';
14 -import { idempotent } from 'src/services/composio-request';
15 -
16 -class TriggerLogsRequestError extends requestError('commands/TriggerLogsRequestError') {}
17 -
18 -const cursor = Flag.String('cursor').pipe(
19 - Flag.withDescription('Cursor for pagination'),
20 - Flag.optional
21 -);
22 -
23 -// Declared for its help row, which documents the comma-separated filter in place of the `dev`
24 -// group's shared row. The parser hands every `--user-id` under `dev` to the shared flag, so
25 -// the value is read from `CommandSurface`.
26 -const userId = Flag.String('user-id').pipe(
27 - Flag.withDescription('Filter by user id'),
28 - Flag.optional
29 -);
30 -
31 -const connectedAccountId = Flag.String('connected-account-id').pipe(
32 - Flag.withDescription('Filter by connected account id'),
33 - Flag.optional
34 -);
35 -
36 -const trigger = Flag.String('trigger').pipe(
37 - Flag.withDescription('Filter by trigger name'),
38 - Flag.optional
39 -);
40 -
41 -const triggerId = Flag.String('trigger-id').pipe(
42 - Flag.withDescription('Filter by trigger id'),
43 - Flag.optional
44 -);
45 -
46 -const logIdFilter = Flag.String('log-id').pipe(
47 - Flag.withDescription('Filter by log id'),
48 - Flag.optional
49 -);
50 -
51 -const logId = Argument.String('log_id').pipe(
52 - Argument.withDescription('Trigger log ID'),
53 - Argument.optional
54 -);
55 -
56 -const from = Flag.Int('from').pipe(
57 - Flag.withDescription('Start timestamp (epoch milliseconds)'),
58 - Flag.optional
59 -);
60 -
61 -const to = Flag.Int('to').pipe(
62 - Flag.withDescription('End timestamp (epoch milliseconds)'),
63 - Flag.optional
64 -);
65 -
66 -const limit = Flag.Int('limit').pipe(
67 - Flag.withDefault(30),
68 - Flag.withDescription('Number of logs to fetch (1-1000)')
69 -);
70 -
71 -const time = Flag.Literals('time', ['5m', '30m', '6h', '1d', '1w', '1month', '1y'] as const).pipe(
72 - Flag.optional,
73 - Flag.withDescription('Show logs from a relative time window')
74 -);
75 -
76 -const search = Flag.String('search').pipe(
77 - Flag.withDescription('Full-text search query'),
78 - Flag.optional
79 -);
80 -
81 -const includePayload = Flag.Boolean('include-payload').pipe(
82 - Flag.withDefault(false),
83 - Flag.withDescription('Include payload fields in response')
84 -);
85 -
86 -/**
87 - * List trigger logs with optional filters.
88 - *
89 - * @example
90 - * ```bash
91 - * composio dev logs triggers <log_id>
92 - * composio dev logs triggers --trigger GMAIL_NEW_GMAIL_MESSAGE
93 - * composio dev logs triggers --trigger-id 77ac1dbf-6db0-4039-8dbe-e903b3f2057e
94 - * composio dev logs triggers --connected-account-id ca_123 --user-id user_123
95 - * composio dev logs triggers --log-id log_123
96 - * ```
97 - */
98 -export const logsCmd$Triggers = Command.make(
99 - 'triggers',
100 - {
101 - logId,
102 - cursor,
103 - userId,
104 - connectedAccountId,
105 - trigger,
106 - triggerId,
107 - logIdFilter,
108 - from,
109 - to,
110 - limit,
111 - time,
112 - search,
113 - includePayload,
114 - },
115 - ({
116 - logId,
117 - cursor,
118 - userId,
119 - connectedAccountId,
120 - trigger,
121 - triggerId,
122 - logIdFilter,
123 - from,
124 - to,
125 - limit,
126 - time,
127 - search,
128 - includePayload,
129 - }) =>
130 - Effect.gen(function* () {
131 - const userIdFilter = Option.orElse((yield* CommandSurface).userId, () => userId);
132 - const ui = yield* TerminalUI;
133 - const clientSingleton = yield* ComposioClientSingleton;
134 - const client = yield* clientSingleton.get();
135 - const clampedLimit = clampLimit(limit);
136 - const shorthandSearchParams = [
137 - ...(Option.isSome(trigger)
138 - ? parseCsv(trigger.value).map(value => toSearchParam('trigger_name', value))
139 - : []),
140 - ...(Option.isSome(triggerId)
141 - ? parseCsv(triggerId.value).map(value => toSearchParam('trigger_id', value))
142 - : []),
143 - ...(Option.isSome(userIdFilter)
144 - ? parseCsv(userIdFilter.value).map(value => toSearchParam('user_id', value))
145 - : []),
146 - ...(Option.isSome(connectedAccountId)
147 - ? parseCsv(connectedAccountId.value).map(value =>
148 - toSearchParam('connected_account_id', value)
149 - )
150 - : []),
151 - ...(Option.isSome(logIdFilter)
152 - ? parseCsv(logIdFilter.value).map(value => toSearchParam('log_id', value))
153 - : []),
154 - ];
155 - const triggerLogId = Option.getOrUndefined(logId);
156 -
157 - if (triggerLogId) {
158 - const triggerLog = yield* ui.withSpinner(
159 - `Fetching trigger log "${triggerLogId}"...`,
160 - client.logs.triggers
161 - .retrieve(triggerLogId, idempotent)
162 - .pipe(
163 - failedWith(TriggerLogsRequestError, `Failed to fetch trigger log "${triggerLogId}".`)
164 - )
165 - );
166 - const record = decodeTriggerLogRecord(triggerLog);
167 -
168 - yield* ui.log.info(
169 - `${formatTriggerLogInfo(record)}\n\nPayload:\n${JSON.stringify(record.payload, null, 2)}\n\nResponse:\n${JSON.stringify(record.response, null, 2)}`
170 - );
171 - // Raw API payload for scripts; only human-readable formatting uses the decoded record.
172 - yield* ui.output(JSON.stringify(triggerLog, null, 2));
173 - return;
174 - }
175 -
176 - const response = yield* ui.withSpinner(
177 - 'Fetching trigger logs...',
178 - client.logs.triggers
179 - .list(
180 - {
181 - ...optionalParams({ cursor, from, to, time, search }),
182 - limit: clampedLimit,
183 - include_payload: includePayload,
184 - search_params: nonEmptyOrUndefined(shorthandSearchParams),
185 - },
186 - idempotent
187 - )
188 - .pipe(failedWith(TriggerLogsRequestError, 'Failed to fetch trigger logs.'))
189 - );
190 -
191 - const logs = response.data ?? [];
192 -
193 - if (logs.length === 0) {
194 - yield* ui.log.warn('No trigger logs found for the given filters.');
195 - yield* ui.output(JSON.stringify(response, null, 2));
196 - return;
197 - }
198 -
199 - yield* ui.log.info(
200 - `Listing ${logs.length} trigger log${logs.length === 1 ? '' : 's'}\n\n${formatTriggerLogsTable(logs.map(decodeTriggerLogRecord))}`
201 - );
202 -
203 - const firstLogId = logs[0]?.id;
204 - if (firstLogId) {
205 - yield* ui.log.step(
206 - commandHintStep('To view full details for a log', 'dev.logs.triggers', {
207 - logId: firstLogId,
208 - })
209 - );
210 - }
211 -
212 - if (response.nextCursor) {
213 - yield* ui.log.step(`Next cursor: ${response.nextCursor}`);
214 - }
215 -
216 - yield* ui.output(JSON.stringify(response, null, 2));
217 - })
218 -).pipe(Command.withDescription('List trigger logs.'));
ts/packages/cli/src/commands/logs/logs.cmd.ts
+1 -1
@@ -1,7 +1,7 @@
1 import { Command } from 'effect/cli';
2 import { requireLogin } from 'src/effects/require-auth';
3 import { logsCmd$Tools } from './commands/logs.tools.cmd';
4 -import { logsCmd$Triggers } from './commands/logs.triggers.cmd';
4 +import { logsCmd$Triggers } from './triggers/logs.triggers.cmd';
5
6 /**
7 * CLI entry point for logs commands.
ts/packages/cli/src/commands/logs/triggers/logs.triggers.cmd.ts new
+90
@@ -0,0 +1,90 @@
1 +import { Argument, Command, Flag } from 'effect/cli';
2 +import { runLogsTriggers } from './logs.triggers.handler';
3 +
4 +const cursor = Flag.String('cursor').pipe(
5 + Flag.withDescription('Cursor for pagination'),
6 + Flag.optional
7 +);
8 +
9 +// Declared for its help row, which documents the comma-separated filter in place of the `dev`
10 +// group's shared row. The parser hands every `--user-id` under `dev` to the shared flag, so
11 +// the value is read from `CommandSurface`.
12 +const userId = Flag.String('user-id').pipe(
13 + Flag.withDescription('Filter by user id'),
14 + Flag.optional
15 +);
16 +
17 +const connectedAccountId = Flag.String('connected-account-id').pipe(
18 + Flag.withDescription('Filter by connected account id'),
19 + Flag.optional
20 +);
21 +
22 +const trigger = Flag.String('trigger').pipe(
23 + Flag.withDescription('Filter by trigger name'),
24 + Flag.optional
25 +);
26 +
27 +const triggerId = Flag.String('trigger-id').pipe(
28 + Flag.withDescription('Filter by trigger id'),
29 + Flag.optional
30 +);
31 +
32 +const logIdFilter = Flag.String('log-id').pipe(
33 + Flag.withDescription('Filter by log id'),
34 + Flag.optional
35 +);
36 +
37 +const logId = Argument.String('log_id').pipe(
38 + Argument.withDescription('Trigger log ID'),
39 + Argument.optional
40 +);
41 +
42 +const from = Flag.Int('from').pipe(
43 + Flag.withDescription('Start timestamp (epoch milliseconds)'),
44 + Flag.optional
45 +);
46 +
47 +const to = Flag.Int('to').pipe(
48 + Flag.withDescription('End timestamp (epoch milliseconds)'),
49 + Flag.optional
50 +);
51 +
52 +const limit = Flag.Int('limit').pipe(
53 + Flag.withDefault(30),
54 + Flag.withDescription('Number of logs to fetch (1-1000)')
55 +);
56 +
57 +const time = Flag.Literals('time', ['5m', '30m', '6h', '1d', '1w', '1month', '1y'] as const).pipe(
58 + Flag.optional,
59 + Flag.withDescription('Show logs from a relative time window')
60 +);
61 +
62 +const search = Flag.String('search').pipe(
63 + Flag.withDescription('Full-text search query'),
64 + Flag.optional
65 +);
66 +
67 +const includePayload = Flag.Boolean('include-payload').pipe(
68 + Flag.withDefault(false),
69 + Flag.withDescription('Include payload fields in response')
70 +);
71 +
72 +export const logsCmd$Triggers = Command.make(
73 + 'triggers',
74 + {
75 + logId,
76 + cursor,
77 + userId,
78 + connectedAccountId,
79 + trigger,
80 + triggerId,
81 + logIdFilter,
82 + from,
83 + to,
84 + limit,
85 + time,
86 + search,
87 + includePayload,
88 + },
89 + runLogsTriggers
90 +).pipe(Command.withDescription('List trigger logs.'));
ts/packages/cli/src/commands/logs/triggers/logs.triggers.errors.ts new
+3
@@ -0,0 +1,3 @@
1 +import { requestError } from 'src/effects/request-error';
2 +
3 +export class TriggerLogsRequestError extends requestError('commands/TriggerLogsRequestError') {}
ts/packages/cli/src/commands/logs/triggers/logs.triggers.handler.ts new
+153
@@ -0,0 +1,153 @@
1 +import type { TriggerListParams } from '@composio/client/resources/logs';
2 +import { Array as Arr, Effect, Option, String as Str } from 'effect';
3 +import { CommandSurface } from 'src/commands/surface';
4 +import { parseCsv } from 'src/commands/triggers/parse-csv';
5 +import { failedWith } from 'src/effects/request-error';
6 +import { commandHintStep } from 'src/services/command-hints';
7 +import { ComposioClientSingleton } from 'src/services/composio-clients';
8 +import { idempotent } from 'src/services/composio-request';
9 +import { TerminalUI } from 'src/services/terminal-ui';
10 +import { clampLimit } from 'src/ui/clamp-limit';
11 +import { nonEmptyOrUndefined, optionalParams } from 'src/utils/optional-params';
12 +import { formatTriggerLogInfo, formatTriggerLogsTable } from '../format';
13 +import { decodeTriggerLogRecord } from '../trigger-log-record';
14 +import { toSearchParam, type SearchParam } from '../utils';
15 +import { TriggerLogsRequestError } from './logs.triggers.errors';
16 +
17 +export type LogsTriggersParams = {
18 + readonly logId: Option.Option<string>;
19 + readonly cursor: Option.Option<string>;
20 + /** Read only when the `dev` group's shared `--user-id` is absent. */
21 + readonly userId: Option.Option<string>;
22 + readonly connectedAccountId: Option.Option<string>;
23 + readonly trigger: Option.Option<string>;
24 + readonly triggerId: Option.Option<string>;
25 + readonly logIdFilter: Option.Option<string>;
26 + readonly from: Option.Option<number>;
27 + readonly to: Option.Option<number>;
28 + readonly limit: number;
29 + readonly time: Option.Option<NonNullable<TriggerListParams['time']>>;
30 + readonly search: Option.Option<string>;
31 + readonly includePayload: boolean;
32 +};
33 +
34 +/**
35 + * One `==` search param per comma-separated value of each present filter, in
36 + * the order the filters are given.
37 + */
38 +export const triggerLogSearchParams = (
39 + filters: ReadonlyArray<readonly [field: string, filter: Option.Option<string>]>
40 +): Array<SearchParam> =>
41 + Arr.flatMap(filters, ([field, filter]) =>
42 + Option.match(filter, {
43 + onNone: () => [],
44 + onSome: csv => parseCsv(csv).map(value => toSearchParam(field, value)),
45 + })
46 + );
47 +
48 +const showTriggerLog = (triggerLogId: string) =>
49 + Effect.gen(function* () {
50 + const ui = yield* TerminalUI;
51 + const client = yield* (yield* ComposioClientSingleton).get();
52 + const triggerLog = yield* ui.withSpinner(
53 + `Fetching trigger log "${triggerLogId}"...`,
54 + client.logs.triggers
55 + .retrieve(triggerLogId, idempotent)
56 + .pipe(failedWith(TriggerLogsRequestError, `Failed to fetch trigger log "${triggerLogId}".`))
57 + );
58 + const record = decodeTriggerLogRecord(triggerLog);
59 +
60 + yield* ui.log.info(
61 + `${formatTriggerLogInfo(record)}\n\nPayload:\n${JSON.stringify(record.payload, null, 2)}\n\nResponse:\n${JSON.stringify(record.response, null, 2)}`
62 + );
63 + // Raw API payload for scripts; only human-readable formatting uses the decoded record.
64 + yield* ui.output(JSON.stringify(triggerLog, null, 2));
65 + });
66 +
67 +const listTriggerLogs = ({
68 + cursor,
69 + userId,
70 + connectedAccountId,
71 + trigger,
72 + triggerId,
73 + logIdFilter,
74 + from,
75 + to,
76 + limit,
77 + time,
78 + search,
79 + includePayload,
80 +}: LogsTriggersParams) =>
81 + Effect.gen(function* () {
82 + const userIdFilter = Option.orElse((yield* CommandSurface).userId, () => userId);
83 + const ui = yield* TerminalUI;
84 + const client = yield* (yield* ComposioClientSingleton).get();
85 + const searchParams = triggerLogSearchParams([
86 + ['trigger_name', trigger],
87 + ['trigger_id', triggerId],
88 + ['user_id', userIdFilter],
89 + ['connected_account_id', connectedAccountId],
90 + ['log_id', logIdFilter],
91 + ]);
92 +
93 + const response = yield* ui.withSpinner(
94 + 'Fetching trigger logs...',
95 + client.logs.triggers
96 + .list(
97 + {
98 + ...optionalParams({ cursor, from, to, time, search }),
99 + limit: clampLimit(limit),
100 + include_payload: includePayload,
101 + search_params: nonEmptyOrUndefined(searchParams),
102 + },
103 + idempotent
104 + )
105 + .pipe(failedWith(TriggerLogsRequestError, 'Failed to fetch trigger logs.'))
106 + );
107 +
108 + yield* Arr.match(response.data ?? [], {
109 + onEmpty: () => ui.log.warn('No trigger logs found for the given filters.'),
110 + onNonEmpty: logs =>
111 + Effect.gen(function* () {
112 + yield* ui.log.info(
113 + `Listing ${logs.length} trigger log${logs.length === 1 ? '' : 's'}\n\n${formatTriggerLogsTable(logs.map(decodeTriggerLogRecord))}`
114 + );
115 +
116 + const firstLogId = Arr.headNonEmpty(logs).id;
117 + if (firstLogId) {
118 + yield* ui.log.step(
119 + commandHintStep('To view full details for a log', 'dev.logs.triggers', {
120 + logId: firstLogId,
121 + })
122 + );
123 + }
124 +
125 + if (response.nextCursor) {
126 + yield* ui.log.step(`Next cursor: ${response.nextCursor}`);
127 + }
128 + }),
129 + });
130 +
131 + yield* ui.output(JSON.stringify(response, null, 2));
132 + });
133 +
134 +/**
135 + * Show one trigger log when a log id is given, otherwise list trigger logs
136 + * with optional filters.
137 + *
138 + * @example
139 + * ```bash
140 + * composio dev logs triggers <log_id>
141 + * composio dev logs triggers --trigger GMAIL_NEW_GMAIL_MESSAGE
142 + * composio dev logs triggers --trigger-id 77ac1dbf-6db0-4039-8dbe-e903b3f2057e
143 + * composio dev logs triggers --connected-account-id ca_123 --user-id user_123
144 + * composio dev logs triggers --log-id log_123
145 + * ```
146 + */
147 +export const runLogsTriggers = (params: LogsTriggersParams) =>
148 + Effect.gen(function* () {
149 + return yield* Option.match(Option.filter(params.logId, Str.isNonEmpty), {
150 + onSome: showTriggerLog,
151 + onNone: () => listTriggerLogs(params),
152 + });
153 + });
ts/packages/cli/test/src/commands/logs/triggers/logs.triggers.client.cmd.test.ts renamed
ts/packages/cli/test/src/commands/logs/triggers/logs.triggers.cmd.test.ts new
+188
@@ -0,0 +1,188 @@
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 +});