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 218 lines 7.09 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 type { TestLiveInput } from 'test/__utils__/services/test-layer';
5 import type { TriggerInstanceItem } from 'src/models/triggers';
6 import {
7 DIRECTORY_PROJECT_SCOPE,
8 DEFAULT_PROJECT_SCOPE,
9 defaultDeveloperProjectAccountData,
10 inDeveloperProjectDirectory,
11 loginWithoutDeveloperProject,
12 OTHER_DEVELOPER_PROJECT,
13 OTHER_PROJECT_SCOPE,
14 runRecordingRepositoryScopes,
15 } from 'test/__utils__/layers/developer-project';
16
17 const testTriggers: TriggerInstanceItem[] = [
18 {
19 id: 'trg_active_1',
20 uuid: 'uuid-trg-active-1',
21 trigger_name: 'GMAIL_NEW_GMAIL_MESSAGE',
22 connected_account_id: 'con_gmail_1',
23 auth_config_id: 'ac_gmail_1',
24 user_id: 'user_default',
25 disabled_at: null,
26 updated_at: '2026-02-01T00:00:00Z',
27 trigger_data: '',
28 state: {},
29 trigger_config: {},
30 },
31 {
32 id: 'trg_active_2',
33 uuid: 'uuid-trg-active-2',
34 trigger_name: 'SLACK_NEW_MESSAGE',
35 connected_account_id: 'con_slack_1',
36 auth_config_id: 'ac_slack_1',
37 user_id: 'user_123',
38 disabled_at: null,
39 updated_at: '2026-02-02T00:00:00Z',
40 trigger_data: '',
41 state: {},
42 trigger_config: {},
43 },
44 {
45 id: 'trg_disabled_1',
46 uuid: 'uuid-trg-disabled-1',
47 trigger_name: 'GITHUB_COMMIT_EVENT',
48 connected_account_id: 'con_github_1',
49 auth_config_id: 'ac_github_1',
50 user_id: 'user_default',
51 disabled_at: '2026-02-03T00:00:00Z',
52 updated_at: '2026-02-03T00:00:00Z',
53 trigger_data: '',
54 state: {},
55 trigger_config: {},
56 },
57 ];
58
59 const triggersData = {
60 items: testTriggers,
61 } satisfies TestLiveInput['triggersData'];
62
63 const testConfigProvider = ConfigProvider.fromEnv({
64 env: { COMPOSIO_USER_API_KEY: 'test_api_key' },
65 });
66
67 // Logged in, in a directory set up for a developer project.
68 const inProject = { ...inDeveloperProjectDirectory, baseConfigProvider: testConfigProvider };
69
70 describe('CLI: composio dev triggers status', () => {
71 layer(TestLive({ ...inProject, triggersData }))(
72 '[Given] no flags [Then] lists active triggers only',
73 it => {
74 it.effect('lists active trigger instances', () =>
75 Effect.gen(function* () {
76 yield* cli(['dev', 'triggers', 'status']);
77 const lines = yield* MockConsole.getLines({ stripAnsi: true });
78 const output = lines.join('\n');
79
80 expect(output).toContain('trg_active_1');
81 expect(output).toContain('trg_active_2');
82 expect(output).not.toContain('trg_disabled_1');
83 expect(output).toContain('Listing 2 of 2 triggers');
84 })
85 );
86 }
87 );
88
89 layer(TestLive({ ...inProject, triggersData }))(
90 '[Given] --show-disabled [Then] includes disabled triggers',
91 it => {
92 it.effect('includes disabled trigger instances', () =>
93 Effect.gen(function* () {
94 yield* cli(['dev', 'triggers', 'status', '--show-disabled']);
95 const lines = yield* MockConsole.getLines({ stripAnsi: true });
96 const output = lines.join('\n');
97
98 expect(output).toContain('trg_active_1');
99 expect(output).toContain('trg_disabled_1');
100 expect(output).toContain('Listing 3 of 3 triggers');
101 })
102 );
103 }
104 );
105
106 layer(TestLive({ ...inProject, triggersData }))(
107 '[Given] --user-ids [Then] filters by user IDs',
108 it => {
109 it.effect('filters by user_ids', () =>
110 Effect.gen(function* () {
111 yield* cli(['dev', 'triggers', 'status', '--user-ids', 'user_123']);
112 const lines = yield* MockConsole.getLines({ stripAnsi: true });
113 const output = lines.join('\n');
114
115 expect(output).toContain('trg_active_2');
116 expect(output).not.toContain('trg_active_1');
117 expect(output).toContain('Listing 1 of 1 triggers');
118 })
119 );
120 }
121 );
122
123 layer(TestLive({ ...inProject, triggersData }))(
124 '[Given] --trigger-names lowercase [Then] applies case-insensitive filter',
125 it => {
126 it.effect('normalizes trigger names to uppercase', () =>
127 Effect.gen(function* () {
128 yield* cli(['dev', 'triggers', 'status', '--trigger-names', 'gmail_new_gmail_message']);
129 const lines = yield* MockConsole.getLines({ stripAnsi: true });
130 const output = lines.join('\n');
131
132 expect(output).toContain('trg_active_1');
133 expect(output).not.toContain('trg_active_2');
134 expect(output).toContain('Listing 1 of 1 triggers');
135 })
136 );
137 }
138 );
139
140 layer(TestLive({ ...inProject, triggersData }))(
141 '[Given] --toolkits [Then] filters by toolkit slug',
142 it => {
143 it.effect('filters by toolkit prefix in trigger name', () =>
144 Effect.gen(function* () {
145 yield* cli(['dev', 'triggers', 'status', '--toolkits', 'slack']);
146 const lines = yield* MockConsole.getLines({ stripAnsi: true });
147 const output = lines.join('\n');
148
149 expect(output).toContain('trg_active_2');
150 expect(output).not.toContain('trg_active_1');
151 expect(output).toContain('Listing 1 of 2 triggers');
152 })
153 );
154 }
155 );
156
157 layer(TestLive())('[Given] no API key [Then] warns user to login', it => {
158 it.effect('warns user to login', () =>
159 Effect.gen(function* () {
160 const error = yield* cli(['dev', 'triggers', 'status']).pipe(Effect.flip);
161 expect(error).toMatchObject({ _tag: 'commands/NotLoggedInError' });
162 })
163 );
164 });
165 });
166
167 // The request goes to the developer project the command resolved, never to the one the backend
168 // would pick for the key.
169 describe('CLI: composio dev triggers status acts on the developer project', () => {
170 layer(TestLive({ ...inProject, triggersData }))(it => {
171 it.effect.each([
172 { given: 'a directory set up for a project', args: [], scope: DIRECTORY_PROJECT_SCOPE },
173 {
174 given: '--project-name',
175 args: ['--project-name', OTHER_DEVELOPER_PROJECT.name],
176 scope: OTHER_PROJECT_SCOPE,
177 },
178 ])('[Given] $given [Then] lists that project’s triggers', ({ args, scope }) =>
179 Effect.gen(function* () {
180 const { exitCode, calls } = yield* runRecordingRepositoryScopes([
181 ...['dev', 'triggers', 'status'],
182 ...args,
183 ]);
184
185 expect(exitCode).toBe(0);
186 expect(calls).toEqual([
187 { method: 'listActiveTriggers', scope: expect.objectContaining(scope) },
188 ]);
189 })
190 );
191 });
192
193 layer(
194 TestLive({
195 baseConfigProvider: testConfigProvider,
196 triggersData,
197 accountData: defaultDeveloperProjectAccountData(),
198 })
199 )(it => {
200 it.effect(
201 '[Given] a directory set up for no project [Then] acts on the default developer project',
202 () =>
203 Effect.gen(function* () {
204 yield* loginWithoutDeveloperProject;
205 const { exitCode, calls } = yield* runRecordingRepositoryScopes([
206 'dev',
207 'triggers',
208 'status',
209 ]);
210
211 expect(exitCode).toBe(0);
212 expect(calls).toEqual([
213 { method: 'listActiveTriggers', scope: expect.objectContaining(DEFAULT_PROJECT_SCOPE) },
214 ]);
215 })
216 );
217 });
218 });