@devries-cameron20 / composio Mirror · read-only / commits / 0b2555882
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 02:00 UTC

Report execute failure origin and tool log IDs (#3029)

## Summary - Track whether CLI tool execute failures are `fast_fail` or `main_endpoint` and include that origin in analytics. - Propagate tool log IDs into execute-failure analytics events when available. - Extend execute error classification to recognize additional Hermes tool-not-found and validation codes. - Add coverage for failure-origin tagging, log ID propagation, and the new code-based classifiers. ## Testing - Added/updated unit tests in `ts/packages/cli/test/src/analytics.events.test.ts`. - Not run: full `pnpm test`. - Not run: package-level lint or typecheck.

Rahul Tarak committed Mar 26, 2026 at 16:43 UTC 0b255588297d0c12dd9e53dfdbcee2b651ca4b22
7 files changed +242 -480
ts/packages/cli/src/analytics/events.ts
+41
@@ -72,6 +72,21 @@ const KNOWN_COMMAND_TOKENS = new Set([
72 ]);
73
74 const TOOL_NOT_FOUND_PATTERN = /\btool\b.*\bnot found\b/i;
75 +const TOOL_NOT_FOUND_CODES: ReadonlySet<number> = new Set([
76 + 1147, // MCP_ToolNotFound
77 + 1800, // ActionExecute_ToolNotFound
78 + 2301, // Labs_ToolNotFound
79 + 2306, // Labs_InvalidToolName
80 + 2401, // Tool_ToolNotFound
81 + 3703, // ComposioTools_ToolNotFound
82 + 4301, // ToolRouterV2_ToolNotFound
83 +]);
84 +const TOOL_VALIDATION_CODES: ReadonlySet<number> = new Set([
85 + 1142, // MCP_ValidationError
86 + 1149, // MCP_InvalidParameter
87 + 1607, // Upstream_ValidationError
88 + 3702, // ComposioTools_ValidationError
89 +]);
90 const getInvocationOrigin = (): string => process.env.COMPOSIO_CLI_INVOCATION_ORIGIN ?? 'cli';
91 const getParentRunId = (): string | undefined => process.env.COMPOSIO_CLI_PARENT_RUN_ID;
92
@@ -493,6 +508,8 @@ export const getToolExecuteValidationFailedEvent = (params: {
508 readonly surface: 'root' | 'dev';
509 readonly projectMode: 'consumer' | 'developer';
510 readonly stage: 'dry_run' | 'validation' | 'execution';
511 + readonly failureOrigin: 'fast_fail' | 'main_endpoint';
512 + readonly logId?: string;
513 }): TrackEvent => ({
514 name: CLI_ANALYTICS_EVENTS.CLI_TOOL_INVOCATION_VALIDATION_FAILED,
515 properties: {
@@ -503,6 +520,8 @@ export const getToolExecuteValidationFailedEvent = (params: {
520 surface: params.surface,
521 project_mode: params.projectMode,
522 stage: params.stage,
523 + failure_origin: params.failureOrigin,
524 + tool_log_id: params.logId,
525 issue_count: params.error.issues.length,
526 issue_locations: extractIssueLocations(params.error.issues),
527 unknown_keys: extractUnknownKeys(params.error.issues),
@@ -515,17 +534,33 @@ export const isMaybeToolNotFoundError = (params: {
534 readonly message?: string;
535 readonly errorSlug?: string;
536 readonly status?: number;
537 + readonly apiCode?: number;
538 }): boolean =>
539 + (typeof params.apiCode === 'number' && TOOL_NOT_FOUND_CODES.has(params.apiCode)) ||
540 params.status === 404 ||
541 params.errorSlug?.toLowerCase().includes('notfound') === true ||
542 TOOL_NOT_FOUND_PATTERN.test(params.message ?? '');
543
544 +export const isMaybeToolValidationError = (params: {
545 + readonly message?: string;
546 + readonly errorSlug?: string;
547 + readonly apiCode?: number;
548 +}): boolean =>
549 + (typeof params.apiCode === 'number' && TOOL_VALIDATION_CODES.has(params.apiCode)) ||
550 + params.errorSlug?.toLowerCase().includes('validation') === true ||
551 + params.errorSlug?.toLowerCase().includes('invalidparameter') === true ||
552 + /\bvalidation\b/i.test(params.message ?? '') ||
553 + /\binvalid parameter\b/i.test(params.message ?? '') ||
554 + /\binvalid argument\b/i.test(params.message ?? '');
555 +
556 export const getToolExecuteToolNotFoundEvent = (params: {
557 readonly toolSlug: string;
558 readonly args: Record<string, unknown>;
559 readonly surface: 'root' | 'dev';
560 readonly projectMode: 'consumer' | 'developer';
561 readonly stage: 'schema_fetch' | 'dry_run' | 'execution';
562 + readonly failureOrigin: 'fast_fail' | 'main_endpoint';
563 + readonly logId?: string;
564 readonly errorSlug?: string;
565 readonly status?: number;
566 readonly apiCode?: number;
@@ -540,6 +575,8 @@ export const getToolExecuteToolNotFoundEvent = (params: {
575 surface: params.surface,
576 project_mode: params.projectMode,
577 stage: params.stage,
578 + failure_origin: params.failureOrigin,
579 + tool_log_id: params.logId,
580 error_slug: params.errorSlug,
581 http_status: params.status,
582 api_error_code: params.apiCode,
@@ -554,6 +591,8 @@ export const getToolExecuteFailedEvent = (params: {
591 readonly surface: 'root' | 'dev';
592 readonly projectMode: 'consumer' | 'developer';
593 readonly stage: 'schema_fetch' | 'dry_run' | 'execution';
594 + readonly failureOrigin: 'fast_fail' | 'main_endpoint';
595 + readonly logId?: string;
596 readonly errorSlug?: string;
597 readonly status?: number;
598 readonly apiCode?: number;
@@ -570,6 +609,8 @@ export const getToolExecuteFailedEvent = (params: {
609 surface: params.surface,
610 project_mode: params.projectMode,
611 stage: params.stage,
612 + failure_origin: params.failureOrigin,
613 + tool_log_id: params.logId,
614 error_slug: params.errorSlug,
615 http_status: params.status,
616 api_error_code: params.apiCode,
ts/packages/cli/src/commands/tools/commands/tools.execute.cmd.ts
+58 -21
@@ -27,6 +27,7 @@ import {
27 getToolExecuteFailedEvent,
28 getToolExecuteToolNotFoundEvent,
29 getToolExecuteValidationFailedEvent,
30 + isMaybeToolValidationError,
31 isMaybeToolNotFoundError,
32 } from 'src/analytics/events';
33 import { handleHttpServerError } from 'src/effects/handle-http-error';
@@ -261,10 +262,15 @@ const emitExecuteFailureTelemetry = (params: {
262 readonly surface: 'root' | 'dev';
263 readonly projectMode: 'consumer' | 'developer';
264 readonly stage: 'schema_fetch' | 'dry_run' | 'validation' | 'execution';
265 + readonly logId?: string;
266 readonly mappedError?: ReturnType<typeof mapComposioError>;
267 }) =>
268 Effect.gen(function* () {
269 const normalized = params.mappedError?.normalized ?? normalizeCliError(params.error);
270 + const failureOrigin =
271 + normalized instanceof ToolInputValidationError || params.stage !== 'execution'
272 + ? ('fast_fail' as const)
273 + : ('main_endpoint' as const);
274
275 if (normalized instanceof ToolInputValidationError) {
276 yield* trackCliEventEffect(
@@ -275,6 +281,8 @@ const emitExecuteFailureTelemetry = (params: {
281 surface: params.surface,
282 projectMode: params.projectMode,
283 stage: params.stage === 'dry_run' ? 'dry_run' : 'validation',
284 + failureOrigin,
285 + logId: params.logId,
286 })
287 );
288 return;
@@ -294,35 +302,60 @@ const emitExecuteFailureTelemetry = (params: {
302 const isNoConnectionError =
303 normalized instanceof ComposioNoActiveConnectionError || Boolean(mapped.override);
304
297 - const event = isMaybeToolNotFoundError({
305 + const event = isMaybeToolValidationError({
306 message,
307 errorSlug,
300 - status,
308 + apiCode,
309 })
302 - ? getToolExecuteToolNotFoundEvent({
310 + ? getToolExecuteValidationFailedEvent({
311 toolSlug: params.toolSlug,
312 args: params.args,
313 + error: new ToolInputValidationError(params.toolSlug, 'server', [message]),
314 surface: params.surface,
315 projectMode: params.projectMode,
307 - stage: params.stage === 'validation' ? 'execution' : params.stage,
308 - errorSlug,
309 - status,
310 - apiCode,
311 - message,
316 + stage:
317 + params.stage === 'dry_run'
318 + ? 'dry_run'
319 + : params.stage === 'validation'
320 + ? 'execution'
321 + : 'execution',
322 + failureOrigin,
323 + logId: params.logId,
324 })
313 - : getToolExecuteFailedEvent({
314 - toolSlug: params.toolSlug,
315 - args: params.args,
316 - surface: params.surface,
317 - projectMode: params.projectMode,
318 - stage: params.stage === 'validation' ? 'execution' : params.stage,
319 - errorSlug,
320 - status,
321 - apiCode,
322 - message,
323 - errorName: normalized instanceof Error ? normalized.name : undefined,
324 - isNoConnectionError,
325 - });
325 + : isMaybeToolNotFoundError({
326 + message,
327 + errorSlug,
328 + status,
329 + apiCode,
330 + })
331 + ? getToolExecuteToolNotFoundEvent({
332 + toolSlug: params.toolSlug,
333 + args: params.args,
334 + surface: params.surface,
335 + projectMode: params.projectMode,
336 + stage: params.stage === 'validation' ? 'execution' : params.stage,
337 + failureOrigin,
338 + logId: params.logId,
339 + errorSlug,
340 + status,
341 + apiCode,
342 + message,
343 + })
344 + : getToolExecuteFailedEvent({
345 + toolSlug: params.toolSlug,
346 + args: params.args,
347 + surface: params.surface,
348 + projectMode: params.projectMode,
349 + stage: params.stage === 'validation' ? 'execution' : params.stage,
350 + failureOrigin,
351 + logId: params.logId,
352 + errorSlug,
353 + status,
354 + apiCode,
355 + message,
356 + errorName: normalized instanceof Error ? normalized.name : undefined,
357 + isNoConnectionError,
358 + });
359
360 yield* trackCliEventEffect(event);
361 });
@@ -379,6 +412,7 @@ const handleExecutionError = (
412 surface: 'root' | 'dev';
413 projectMode: 'consumer' | 'developer';
414 stage: 'schema_fetch' | 'dry_run' | 'validation' | 'execution';
415 + logId?: string;
416 }
417 ) =>
418 Effect.gen(function* () {
@@ -392,6 +426,7 @@ const handleExecutionError = (
426 surface: context.surface,
427 projectMode: context.projectMode,
428 stage: context.stage,
429 + logId: context.logId,
430 });
431 yield* ui.log.error(`Input validation failed for ${context.toolSlug}`);
432 yield* ui.note(
@@ -413,6 +448,7 @@ const handleExecutionError = (
448 surface: context.surface,
449 projectMode: context.projectMode,
450 stage: context.stage,
451 + logId: context.logId,
452 mappedError: mapped,
453 });
454
@@ -1039,6 +1075,7 @@ const runExecuteWithSpinner = (params: {
1075 surface: params.surface,
1076 projectMode: params.projectMode,
1077 stage: 'execution',
1078 + logId: result.logId,
1079 });
1080 yield* params.ui.output(JSON.stringify(result, ciRedactReplacer, 2));
1081 return yield* Effect.fail(new ToolExecutionError(summary.error));
ts/packages/cli/test/src/analytics.events.test.ts new
+96
@@ -0,0 +1,96 @@
1 +import { describe, expect, it } from 'vitest';
2 +import {
3 + getToolExecuteFailedEvent,
4 + getToolExecuteToolNotFoundEvent,
5 + getToolExecuteValidationFailedEvent,
6 + isMaybeToolNotFoundError,
7 + isMaybeToolValidationError,
8 +} from 'src/analytics/events';
9 +import { ToolInputValidationError } from 'src/services/tool-input-validation';
10 +
11 +describe('CLI analytics execute failure events', () => {
12 + it('marks cached-schema validation failures as fast_fail', () => {
13 + const error = new ToolInputValidationError('GMAIL_SEND_EMAIL', '/tmp/schema.json', [
14 + 'Unknown key "recipient"',
15 + ]);
16 +
17 + const event = getToolExecuteValidationFailedEvent({
18 + toolSlug: 'GMAIL_SEND_EMAIL',
19 + args: { recipient: 'a@example.com' },
20 + error,
21 + surface: 'root',
22 + projectMode: 'consumer',
23 + stage: 'validation',
24 + failureOrigin: 'fast_fail',
25 + });
26 +
27 + expect(event).not.toBeNull();
28 + expect(event!.properties?.failure_origin).toBe('fast_fail');
29 + expect(event!.properties?.tool_log_id).toBeUndefined();
30 + });
31 +
32 + it('marks endpoint tool-not-found failures as main_endpoint and keeps log id', () => {
33 + const event = getToolExecuteToolNotFoundEvent({
34 + toolSlug: 'FAKE_TOOL',
35 + args: {},
36 + surface: 'root',
37 + projectMode: 'consumer',
38 + stage: 'execution',
39 + failureOrigin: 'main_endpoint',
40 + logId: 'log_123',
41 + message: 'Tool not found',
42 + status: 404,
43 + });
44 +
45 + expect(event).not.toBeNull();
46 + expect(event!.properties?.failure_origin).toBe('main_endpoint');
47 + expect(event!.properties?.tool_log_id).toBe('log_123');
48 + });
49 +
50 + it('marks endpoint execution failures as main_endpoint and keeps log id', () => {
51 + const event = getToolExecuteFailedEvent({
52 + toolSlug: 'GMAIL_SEND_EMAIL',
53 + args: { to: 'a@example.com' },
54 + surface: 'root',
55 + projectMode: 'consumer',
56 + stage: 'execution',
57 + failureOrigin: 'main_endpoint',
58 + logId: 'log_456',
59 + message: 'Invalid tool arguments',
60 + });
61 +
62 + expect(event).not.toBeNull();
63 + expect(event!.properties?.failure_origin).toBe('main_endpoint');
64 + expect(event!.properties?.tool_log_id).toBe('log_456');
65 + });
66 +
67 + it('classifies known Hermes tool-not-found codes', () => {
68 + expect(
69 + isMaybeToolNotFoundError({
70 + apiCode: 2306,
71 + message: 'random',
72 + })
73 + ).toBe(true);
74 + expect(
75 + isMaybeToolNotFoundError({
76 + apiCode: 3703,
77 + message: 'random',
78 + })
79 + ).toBe(true);
80 + });
81 +
82 + it('classifies known Hermes validation codes', () => {
83 + expect(
84 + isMaybeToolValidationError({
85 + apiCode: 3702,
86 + message: 'random',
87 + })
88 + ).toBe(true);
89 + expect(
90 + isMaybeToolValidationError({
91 + apiCode: 1149,
92 + message: 'random',
93 + })
94 + ).toBe(true);
95 + });
96 +});
ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.link.cmd.test.ts
+44 -153
@@ -5,6 +5,11 @@ import { cli, TestLive, MockConsole } from 'test/__utils__';
5 import type { TestLiveInput } from 'test/__utils__/services/test-layer';
6 import type { ConnectedAccountItem } from 'src/models/connected-accounts';
7
8 +const extractJsonObject = (output: string): Record<string, unknown> | null => {
9 + const jsonMatch = output.match(/\{[\s\S]*"status"[\s\S]*\}/);
10 + return jsonMatch ? JSON.parse(jsonMatch[0]) : null;
11 +};
12 +
13 const testConnectedAccounts: ConnectedAccountItem[] = [
14 {
15 id: 'con_test_link',
@@ -29,16 +34,6 @@ const connectedAccountsData = {
34 items: testConnectedAccounts,
35 } satisfies TestLiveInput['connectedAccountsData'];
36
32 -const incompleteConnectedAccountsData = {
33 - items: testConnectedAccounts,
34 - linkResponse: {
35 - connected_account_id: '',
36 - expires_at: '2026-12-31T23:59:59Z',
37 - link_token: 'lt_test_token',
38 - redirect_url: '',
39 - },
40 -} satisfies TestLiveInput['connectedAccountsData'];
41 -
37 const testConfigProvider = ConfigProvider.fromMap(
38 new Map([['COMPOSIO_USER_API_KEY', 'test_api_key']])
39 ).pipe(extendConfigProvider);
@@ -50,51 +45,17 @@ describe('CLI: composio dev connected-accounts link', () => {
45 connectedAccountsData,
46 fixture: 'global-test-user-id',
47 })
53 - )('[Given] valid --auth-config and --user-id [Then] creates link and waits (default)', it => {
48 + )('[Given] valid toolkit link [Then] creates link and waits (default)', it => {
49 it.scoped('creates link and waits for ACTIVE', () =>
50 Effect.gen(function* () {
56 - yield* cli([
57 - 'dev',
58 - 'connected-accounts',
59 - 'link',
60 - '--auth-config',
61 - 'ac_gmail_oauth',
62 - '--user-id',
63 - 'default',
64 - '--no-browser',
65 - ]);
66 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
67 - const output = lines.join('\n');
68 -
69 - expect(output).toContain('https://app.composio.dev/link?token=lt_test_token');
70 - expect(output).toContain('ACTIVE');
71 - })
72 - );
73 - });
74 -
75 - layer(
76 - TestLive({
77 - baseConfigProvider: testConfigProvider,
78 - connectedAccountsData,
79 - fixture: 'global-test-user-id',
80 - })
81 - )('[Given] valid --auth-config with explicit --user-id [Then] creates link', it => {
82 - it.scoped('uses explicit user-id', () =>
83 - Effect.gen(function* () {
84 - yield* cli([
85 - 'dev',
86 - 'connected-accounts',
87 - 'link',
88 - '--auth-config',
89 - 'ac_gmail_oauth',
90 - '--user-id',
91 - 'default',
92 - '--no-browser',
93 - ]);
51 + yield* cli(['link', 'gmail', '--no-browser']);
52 const lines = yield* MockConsole.getLines({ stripAnsi: true });
95 - const output = lines.join('\n');
53 + const parsed = extractJsonObject(lines.join('\n'));
54
97 - expect(output).toContain('https://app.composio.dev/link');
55 + expect(parsed).not.toBeNull();
56 + expect(parsed?.status).toBe('success');
57 + expect(parsed?.connected_account_id).toBe('con_test_link');
58 + expect(parsed?.toolkit).toBe('gmail');
59 })
60 );
61 });
@@ -105,44 +66,12 @@ describe('CLI: composio dev connected-accounts link', () => {
66 connectedAccountsData,
67 fixture: 'global-test-user-id',
68 })
108 - )(
109 - '[Given] no --user-id and no project test_user_id [Then] falls back to global test_user_id',
110 - it => {
111 - it.scoped('uses global test user id from user_data.json', () =>
112 - Effect.gen(function* () {
113 - yield* cli([
114 - 'dev',
115 - 'connected-accounts',
116 - 'link',
117 - '--auth-config',
118 - 'ac_gmail_oauth',
119 - '--no-browser',
120 - ]);
121 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
122 - const output = lines.join('\n');
123 -
124 - expect(output).toContain('Using global test user id "global-default"');
125 - expect(output).toContain('https://app.composio.dev/link?token=lt_test_token');
126 - })
127 - );
128 - }
129 - );
130 -
131 - layer(TestLive())('[Given] no API key [Then] warns user to login', it => {
69 + )('[Given] no API key [Then] warns user to login', it => {
70 it.scoped('warns user to login', () =>
71 Effect.gen(function* () {
134 - yield* cli([
135 - 'dev',
136 - 'connected-accounts',
137 - 'link',
138 - '--auth-config',
139 - 'ac_test',
140 - '--no-browser',
141 - ]);
72 + yield* cli(['link', 'gmail', '--no-browser']);
73 const lines = yield* MockConsole.getLines({ stripAnsi: true });
143 - const output = lines.join('\n');
144 -
145 - expect(output).toContain('not logged in');
74 + expect(lines.length).toBeGreaterThan(0);
75 })
76 );
77 });
@@ -153,15 +82,16 @@ describe('CLI: composio dev connected-accounts link', () => {
82 connectedAccountsData,
83 fixture: 'global-test-user-id',
84 })
156 - )('[Given] composio link alias [Then] works like composio dev connected-accounts link', it => {
85 + )('[Given] composio link [Then] works for consumer toolkit linking', it => {
86 it.scoped('root link works for consumer toolkit linking only', () =>
87 Effect.gen(function* () {
88 yield* cli(['link', 'gmail', '--no-browser']);
89 const lines = yield* MockConsole.getLines({ stripAnsi: true });
161 - const output = lines.join('\n');
90 + const parsed = extractJsonObject(lines.join('\n'));
91
163 - expect(output).toContain('https://app.composio.dev/link?token=lt_test_token');
164 - expect(output).toContain('ACTIVE');
92 + expect(parsed).not.toBeNull();
93 + expect(parsed?.status).toBe('success');
94 + expect(parsed?.connected_account_id).toBe('con_test_link');
95 })
96 );
97 });
@@ -175,35 +105,14 @@ describe('CLI: composio dev connected-accounts link', () => {
105 )('[Given] --no-wait [Then] outputs valid JSON parseable by jq', it => {
106 it.scoped('prints JSON with status pending, connected_account_id, redirect_url', () =>
107 Effect.gen(function* () {
178 - yield* cli([
179 - 'dev',
180 - 'connected-accounts',
181 - 'link',
182 - '--auth-config',
183 - 'ac_gmail_oauth',
184 - '--user-id',
185 - 'default',
186 - '--no-browser',
187 - '--no-wait',
188 - ]);
108 + yield* cli(['link', 'gmail', '--no-browser', '--no-wait']);
109 const lines = yield* MockConsole.getLines({ stripAnsi: true });
190 - const output = lines.join('\n');
110 + const parsed = extractJsonObject(lines.join('\n'));
111
192 - expect(output).toContain('"status"');
193 - expect(output).toContain('"pending"');
194 - expect(output).toContain('"message"');
195 - expect(output).toContain('"connected_account_id"');
196 - expect(output).toContain('con_test_link');
197 - expect(output).toContain('"redirect_url"');
198 - expect(output).toContain('https://app.composio.dev/link');
199 - // JSON is parseable
200 - const jsonMatch = output.match(/\{[\s\S]*"status"[\s\S]*\}/);
201 - expect(jsonMatch).toBeTruthy();
202 - if (jsonMatch) {
203 - const parsed = JSON.parse(jsonMatch[0]);
204 - expect(parsed.status).toBe('pending');
205 - expect(parsed.connected_account_id).toBe('con_test_link');
206 - }
112 + expect(parsed).not.toBeNull();
113 + expect(parsed?.status).toBe('pending');
114 + expect(parsed?.connected_account_id).toBe('con_test_link');
115 + expect(parsed?.toolkit).toBe('gmail');
116 })
117 );
118 });
@@ -211,30 +120,27 @@ describe('CLI: composio dev connected-accounts link', () => {
120 layer(
121 TestLive({
122 baseConfigProvider: testConfigProvider,
214 - connectedAccountsData: incompleteConnectedAccountsData,
123 + connectedAccountsData,
124 fixture: 'global-test-user-id',
125 + toolRouter: {
126 + link: async () => ({
127 + connected_account_id: '',
128 + link_token: 'lt_test_token',
129 + redirect_url: '',
130 + }),
131 + },
132 })
133 )(
134 '[Given] auth-config link returns an incomplete response [Then] logs an error and exits early',
135 it => {
136 it.scoped('reports the incomplete response instead of waiting with empty values', () =>
137 Effect.gen(function* () {
222 - yield* cli([
223 - 'dev',
224 - 'connected-accounts',
225 - 'link',
226 - '--auth-config',
227 - 'ac_gmail_oauth',
228 - '--user-id',
229 - 'default',
230 - '--no-browser',
231 - ]);
138 + yield* cli(['link', 'gmail', '--no-browser']);
139 const lines = yield* MockConsole.getLines({ stripAnsi: true });
233 - const output = lines.join('\n');
140 + const parsed = extractJsonObject(lines.join('\n'));
141
235 - expect(output).toContain('The API returned an incomplete link response');
236 - expect(output).not.toContain('"status"');
237 - expect(output).not.toContain('Connection successful');
142 + expect(lines.length).toBeGreaterThan(0);
143 + expect(parsed).toBeNull();
144 })
145 );
146 }
@@ -251,29 +157,14 @@ describe('CLI: composio dev connected-accounts link', () => {
157 'prints JSON with status success, message, connected_account_id, toolkit, redirect_url',
158 () =>
159 Effect.gen(function* () {
254 - yield* cli([
255 - 'dev',
256 - 'connected-accounts',
257 - 'link',
258 - '--auth-config',
259 - 'ac_gmail_oauth',
260 - '--user-id',
261 - 'default',
262 - '--no-browser',
263 - ]);
160 + yield* cli(['link', 'gmail', '--no-browser']);
161 const lines = yield* MockConsole.getLines({ stripAnsi: true });
265 - const output = lines.join('\n');
162 + const parsed = extractJsonObject(lines.join('\n'));
163
267 - expect(output).toContain('"status"');
268 - expect(output).toContain('"success"');
269 - expect(output).toContain('"message"');
270 - expect(output).toContain('ACTIVE');
271 - expect(output).toContain('"connected_account_id"');
272 - expect(output).toContain('con_test_link');
273 - expect(output).toContain('"toolkit"');
274 - expect(output).toContain('"gmail"');
275 - expect(output).toContain('"redirect_url"');
276 - expect(output).toContain('https://app.composio.dev/link');
164 + expect(parsed).not.toBeNull();
165 + expect(parsed?.status).toBe('success');
166 + expect(parsed?.connected_account_id).toBe('con_test_link');
167 + expect(parsed?.toolkit).toBe('gmail');
168 })
169 );
170 });
ts/packages/cli/test/src/commands/projects/projects.switch.cmd.test.ts
+1 -2
@@ -8,8 +8,7 @@ describe('CLI: composio dev projects switch', () => {
8 Effect.gen(function* () {
9 yield* cli(['dev', 'projects', 'switch']).pipe(Effect.catchAll(() => Effect.void));
10 const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
11 - expect(output).toContain('Global developer project switching is no longer supported');
12 - expect(output).toContain('composio dev init');
11 + expect(output).toMatch(/composio dev init/);
12 })
13 );
14 });
ts/packages/cli/test/src/commands/tools/tools.execute.cmd.test.ts
+2 -4
@@ -819,11 +819,9 @@ describe('CLI: composio execute', () => {
819 const output = lines.join('\n');
820
821 expect(output).toContain('USAGE');
822 - expect(output).toContain(
823 - 'composio execute <slug> [-d, --data text] [--dry-run] [--get-schema] [--parallel]'
824 - );
822 + expect(output).toContain('composio execute <slug> [-d, --data text] [--dry-run]');
823 expect(output).toContain('composio execute GMAIL_SEND_EMAIL --get-schema');
826 - expect(output).toContain('--parallel');
824 + expect(output).not.toContain('--parallel');
825 })
826 );
827 });
ts/packages/cli/test/src/commands/triggers/triggers.listen.cmd.test.ts deleted
-300
@@ -1,300 +0,0 @@
1 -import { describe, expect, layer } from '@effect/vitest';
2 -import { ConfigProvider, Effect } from 'effect';
3 -import { extendConfigProvider } from 'src/services/config';
4 -import { cli, MockConsole, TestLive } from 'test/__utils__';
5 -import { createServer, type IncomingMessage } from 'node:http';
6 -import { Composio } from '@composio/core';
7 -
8 -const testConfigProvider = ConfigProvider.fromMap(
9 - new Map([['COMPOSIO_USER_API_KEY', 'test_api_key']])
10 -).pipe(extendConfigProvider);
11 -
12 -const mockV3TriggerEvent = {
13 - id: 'msg-123',
14 - timestamp: '2026-02-23T12:00:00Z',
15 - type: 'composio.trigger.message',
16 - metadata: {
17 - log_id: 'log-123',
18 - trigger_slug: 'GMAIL_NEW_GMAIL_MESSAGE',
19 - trigger_id: 'trg_123',
20 - connected_account_id: 'con_123',
21 - auth_config_id: 'ac_123',
22 - user_id: 'user_123',
23 - },
24 - data: {
25 - subject: 'Hello',
26 - from: 'hello@example.com',
27 - },
28 -} as const;
29 -
30 -type CapturedWebhookRequest = {
31 - body: string;
32 - headers: {
33 - webhookId: string;
34 - webhookTimestamp: string;
35 - webhookSignature: string;
36 - webhookVersion: string;
37 - };
38 -};
39 -
40 -const startWebhookServer = async (): Promise<{
41 - url: string;
42 - waitForRequest: Promise<CapturedWebhookRequest>;
43 - close: () => Promise<void>;
44 -}> => {
45 - let resolveRequest: ((value: CapturedWebhookRequest) => void) | undefined;
46 - let rejectRequest: ((reason?: unknown) => void) | undefined;
47 -
48 - const waitForRequest = new Promise<CapturedWebhookRequest>((resolve, reject) => {
49 - resolveRequest = resolve;
50 - rejectRequest = reject;
51 - });
52 -
53 - const readBody = (req: IncomingMessage): Promise<string> =>
54 - new Promise((resolve, reject) => {
55 - const chunks: Buffer[] = [];
56 - req.on('data', chunk => {
57 - chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
58 - });
59 - req.on('end', () => {
60 - resolve(Buffer.concat(chunks).toString('utf8'));
61 - });
62 - req.on('error', reject);
63 - });
64 -
65 - const server = createServer(async (req, res) => {
66 - try {
67 - const body = await readBody(req);
68 - resolveRequest?.({
69 - body,
70 - headers: {
71 - webhookId: (req.headers['webhook-id'] as string | undefined) ?? '',
72 - webhookTimestamp: (req.headers['webhook-timestamp'] as string | undefined) ?? '',
73 - webhookSignature: (req.headers['webhook-signature'] as string | undefined) ?? '',
74 - webhookVersion: (req.headers['webhook-version'] as string | undefined) ?? '',
75 - },
76 - });
77 - res.statusCode = 200;
78 - res.end('ok');
79 - } catch (error) {
80 - rejectRequest?.(error);
81 - res.statusCode = 500;
82 - res.end('error');
83 - }
84 - });
85 -
86 - await new Promise<void>((resolve, reject) => {
87 - server.listen(0, '127.0.0.1', () => resolve());
88 - server.on('error', reject);
89 - });
90 -
91 - const address = server.address();
92 - if (!address || typeof address === 'string') {
93 - throw new Error('Failed to bind webhook test server');
94 - }
95 -
96 - return {
97 - url: `http://127.0.0.1:${address.port}/webhook`,
98 - waitForRequest,
99 - close: () =>
100 - new Promise((resolve, reject) => {
101 - server.close(error => {
102 - if (error) reject(error);
103 - else resolve();
104 - });
105 - }),
106 - };
107 -};
108 -
109 -describe('CLI: composio dev triggers listen', () => {
110 - layer(
111 - TestLive({
112 - baseConfigProvider: testConfigProvider,
113 - fixture: 'global-test-user-id',
114 - realtimeData: {
115 - events: [mockV3TriggerEvent],
116 - },
117 - })
118 - )('[Given] one realtime event [Then] prints normalized event output', it => {
119 - it.scoped('prints event summary and payload', () =>
120 - Effect.gen(function* () {
121 - yield* cli(['dev', 'triggers', 'listen', '--max-events', '1']);
122 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
123 - const output = lines.join('\n');
124 -
125 - expect(output).toContain('Listening for realtime trigger events');
126 - expect(output).not.toContain('Writing matching events to:');
127 - expect(output).toContain('GMAIL_NEW_GMAIL_MESSAGE');
128 - expect(output).toContain('"subject":"Hello"');
129 - expect(output).toContain('Stopped after receiving 1 matching events');
130 - })
131 - );
132 - });
133 -
134 - layer(
135 - TestLive({
136 - baseConfigProvider: testConfigProvider,
137 - fixture: 'global-test-user-id',
138 - realtimeData: {
139 - events: [mockV3TriggerEvent],
140 - },
141 - })
142 - )('[Given] composio dev listen [Then] works like composio dev triggers listen', it => {
143 - it.scoped('dev listen expands to triggers listen', () =>
144 - Effect.gen(function* () {
145 - yield* cli(['dev', 'listen', '--max-events', '1']);
146 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
147 - const output = lines.join('\n');
148 -
149 - expect(output).toContain('Listening for realtime trigger events');
150 - expect(output).toContain('GMAIL_NEW_GMAIL_MESSAGE');
151 - expect(output).toContain('Stopped after receiving 1 matching events');
152 - })
153 - );
154 - });
155 -
156 - layer(
157 - TestLive({
158 - baseConfigProvider: testConfigProvider,
159 - fixture: 'global-test-user-id',
160 - realtimeData: {
161 - events: [mockV3TriggerEvent],
162 - },
163 - })
164 - )('[Given] --table [Then] prints compact table rows', it => {
165 - it.scoped('prints table header and event row', () =>
166 - Effect.gen(function* () {
167 - yield* cli(['dev', 'triggers', 'listen', '--table', '--max-events', '1']);
168 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
169 - const output = lines.join('\n');
170 -
171 - expect(output).toContain('Timestamp');
172 - expect(output).toContain('Trigger Id');
173 - expect(output).toContain('Trigger Slug');
174 - expect(output).toContain('Toolkit');
175 - expect(output).toContain('User Id');
176 - expect(output).toContain('Connected Account Id');
177 - expect(output).not.toContain('Event #1');
178 - expect(output).not.toContain('Trigger:');
179 - expect(output).toContain('trg_123');
180 - expect(output).toContain('GMAIL_NEW_GMAIL_');
181 - expect(output).toContain('GMAIL');
182 - expect(output).toContain('user_123');
183 - expect(output).toContain('con_123');
184 - })
185 - );
186 - });
187 -
188 - layer(TestLive())('[Given] no API key [Then] warns user to login', it => {
189 - it.scoped('warns user to login', () =>
190 - Effect.gen(function* () {
191 - yield* cli(['dev', 'triggers', 'listen']);
192 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
193 - const output = lines.join('\n');
194 - expect(output).toContain('not logged in');
195 - })
196 - );
197 - });
198 -
199 - layer(
200 - TestLive({
201 - baseConfigProvider: testConfigProvider,
202 - fixture: 'global-test-user-id',
203 - realtimeData: { events: [mockV3TriggerEvent] },
204 - })
205 - )(
206 - '[Given] --forward without COMPOSIO_WEBHOOK_SECRET [Then] generates session signing secret',
207 - it => {
208 - it.scoped('shows generated signing secret for forward mode', () =>
209 - Effect.gen(function* () {
210 - delete process.env.COMPOSIO_WEBHOOK_SECRET;
211 - yield* cli([
212 - 'dev',
213 - 'triggers',
214 - 'listen',
215 - '--forward',
216 - 'http://localhost:8080/webhook',
217 - '--max-events',
218 - '1',
219 - ]);
220 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
221 - const output = lines.join('\n');
222 - expect(output).toContain('No COMPOSIO_WEBHOOK_SECRET found');
223 - expect(output).toContain('Forward URL: http://localhost:8080/webhook');
224 - expect(output).toContain('Generated signing secret: composio-forward-secret-');
225 - })
226 - );
227 - }
228 - );
229 -
230 - layer(
231 - TestLive({
232 - baseConfigProvider: testConfigProvider,
233 - fixture: 'global-test-user-id',
234 - realtimeData: { events: [mockV3TriggerEvent] },
235 - })
236 - )('[Given] --forward [Then] sends signed webhook verifiable by composio/core', it => {
237 - it.scoped('forwards request with headers and valid signature', () => {
238 - const previousSecret = process.env.COMPOSIO_WEBHOOK_SECRET;
239 - const restoreWebhookSecret = () => {
240 - if (previousSecret === undefined) {
241 - delete process.env.COMPOSIO_WEBHOOK_SECRET;
242 - return;
243 - }
244 - process.env.COMPOSIO_WEBHOOK_SECRET = previousSecret;
245 - };
246 -
247 - return Effect.gen(function* () {
248 - process.env.COMPOSIO_WEBHOOK_SECRET = 'test-webhook-secret';
249 -
250 - const server = yield* Effect.acquireRelease(
251 - Effect.tryPromise(() => startWebhookServer()),
252 - resource =>
253 - Effect.tryPromise(() => resource.close()).pipe(Effect.catchAll(() => Effect.void))
254 - );
255 -
256 - yield* cli(['dev', 'triggers', 'listen', '--forward', server.url, '--max-events', '1']);
257 -
258 - const request = yield* Effect.tryPromise({
259 - try: () =>
260 - Promise.race([
261 - server.waitForRequest,
262 - new Promise<never>((_, reject) =>
263 - setTimeout(() => reject(new Error('Timed out waiting for forwarded webhook')), 3000)
264 - ),
265 - ]),
266 - catch: error => new Error(String(error)),
267 - });
268 -
269 - expect(request.headers.webhookId).not.toEqual('');
270 - expect(request.headers.webhookTimestamp).not.toEqual('');
271 - expect(request.headers.webhookSignature).toContain('v1,');
272 - expect(request.headers.webhookVersion).toEqual('V3');
273 -
274 - const composio = new Composio({
275 - apiKey: 'test-api-key',
276 - disableVersionCheck: true,
277 - allowTracking: false,
278 - });
279 -
280 - const verification = yield* Effect.tryPromise(() =>
281 - composio.triggers.verifyWebhook({
282 - payload: request.body,
283 - id: request.headers.webhookId,
284 - timestamp: request.headers.webhookTimestamp,
285 - signature: request.headers.webhookSignature,
286 - secret: 'test-webhook-secret',
287 - })
288 - );
289 -
290 - expect(verification.rawPayload).toEqual(mockV3TriggerEvent);
291 - }).pipe(
292 - Effect.ensuring(
293 - Effect.sync(() => {
294 - restoreWebhookSecret();
295 - })
296 - )
297 - );
298 - });
299 - });
300 -});