@devries-cameron20 / composio Mirror · read-only / commits / c2163e066
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, 04:30 UTC

fix(e2e): use parseJsonStdout in CLI toolkits tests

Replace bare JSON.parse(sanitizeOutput(result.stdout)) with the new parseJsonStdout helper so that CLI errors (e.g. 401) produce clear messages instead of cryptic 'SyntaxError: JSON Parse error: Unexpected EOF'.

jkomyno committed Mar 9, 2026 at 14:08 UTC c2163e0660a68c840fe0bbb83ba37f28bc9efdc2
3 files changed +21 -19
ts/e2e-tests/cli/toolkits/info/e2e.test.ts
+7 -6
@@ -8,6 +8,7 @@
8 import {
9 e2e,
10 sanitizeOutput,
11 + parseJsonStdout,
12 type E2ETestResult,
13 type E2ETestResultWithFiles,
14 } from '@e2e-tests/utils';
@@ -53,37 +54,37 @@ e2e(import.meta.url, {
54 });
55
56 it('stdout is a valid JSON object', () => {
56 - const obj = JSON.parse(sanitizeOutput(validResult.stdout));
57 + const obj = parseJsonStdout(validResult);
58 expect(typeof obj).toBe('object');
59 expect(Array.isArray(obj)).toBe(false);
60 });
61
62 it('has the correct name and slug', () => {
62 - const obj = JSON.parse(sanitizeOutput(validResult.stdout));
63 + const obj = parseJsonStdout(validResult) as Record<string, unknown>;
64 expect(obj.name).toBe('Gmail');
65 expect(obj.slug).toBe('gmail');
66 });
67
68 it('has meta with description and logo', () => {
68 - const obj = JSON.parse(sanitizeOutput(validResult.stdout));
69 + const obj = parseJsonStdout(validResult) as Record<string, Record<string, unknown>>;
70 expect(obj.meta).toHaveProperty('description');
71 expect(typeof obj.meta.description).toBe('string');
72 expect(obj.meta).toHaveProperty('logo');
73 });
74
75 it('has is_no_auth and enabled', () => {
75 - const obj = JSON.parse(sanitizeOutput(validResult.stdout));
76 + const obj = parseJsonStdout(validResult) as Record<string, unknown>;
77 expect(typeof obj.is_no_auth).toBe('boolean');
78 expect(typeof obj.enabled).toBe('boolean');
79 });
80
81 it('has composio_managed_auth_schemes array', () => {
81 - const obj = JSON.parse(sanitizeOutput(validResult.stdout));
82 + const obj = parseJsonStdout(validResult) as Record<string, unknown>;
83 expect(Array.isArray(obj.composio_managed_auth_schemes)).toBe(true);
84 });
85
86 it('has connected_account (object or null)', () => {
86 - const obj = JSON.parse(sanitizeOutput(validResult.stdout));
87 + const obj = parseJsonStdout(validResult) as Record<string, unknown>;
88 expect(obj).toHaveProperty('connected_account');
89 });
90 });
ts/e2e-tests/cli/toolkits/list/e2e.test.ts
+6 -6
@@ -5,7 +5,7 @@
5 * supports --query filtering (exact, prefix, no fuzzy), and respects --limit.
6 */
7
8 -import { e2e, sanitizeOutput, type E2ETestResult } from '@e2e-tests/utils';
8 +import { e2e, sanitizeOutput, parseJsonStdout, type E2ETestResult } from '@e2e-tests/utils';
9 import { TIMEOUTS } from '@e2e-tests/utils/const';
10 import { describe, it, expect, beforeAll } from 'bun:test';
11
@@ -43,18 +43,18 @@ e2e(import.meta.url, {
43 });
44
45 it('stdout is a JSON array with 1 element', () => {
46 - const items = JSON.parse(sanitizeOutput(exactResult.stdout));
46 + const items = parseJsonStdout(exactResult);
47 expect(Array.isArray(items)).toBe(true);
48 expect(items).toHaveLength(1);
49 });
50
51 it('the element has slug "gmail"', () => {
52 - const items = JSON.parse(sanitizeOutput(exactResult.stdout));
52 + const items = parseJsonStdout(exactResult) as Array<{ slug: string }>;
53 expect(items[0].slug).toBe('gmail');
54 });
55
56 it('the element has the expected shape', () => {
57 - const item = JSON.parse(sanitizeOutput(exactResult.stdout))[0];
57 + const item = (parseJsonStdout(exactResult) as Array<Record<string, unknown>>)[0];
58 expect(item).toHaveProperty('name');
59 expect(item).toHaveProperty('slug');
60 expect(item).toHaveProperty('description');
@@ -75,13 +75,13 @@ e2e(import.meta.url, {
75 });
76
77 it('stdout is a JSON array with 1 element', () => {
78 - const items = JSON.parse(sanitizeOutput(prefixResult.stdout));
78 + const items = parseJsonStdout(prefixResult);
79 expect(Array.isArray(items)).toBe(true);
80 expect(items).toHaveLength(1);
81 });
82
83 it('the element has slug "gmail"', () => {
84 - const items = JSON.parse(sanitizeOutput(prefixResult.stdout));
84 + const items = parseJsonStdout(prefixResult) as Array<{ slug: string }>;
85 expect(items[0].slug).toBe('gmail');
86 });
87 });
ts/e2e-tests/cli/toolkits/search/e2e.test.ts
+8 -7
@@ -8,6 +8,7 @@
8 import {
9 e2e,
10 sanitizeOutput,
11 + parseJsonStdout,
12 type E2ETestResult,
13 type E2ETestResultWithFiles,
14 } from '@e2e-tests/utils';
@@ -53,18 +54,18 @@ e2e(import.meta.url, {
54 });
55
56 it('stdout is a JSON array with at least 1 element', () => {
56 - const items = JSON.parse(sanitizeOutput(validResult.stdout));
57 + const items = parseJsonStdout(validResult);
58 expect(Array.isArray(items)).toBe(true);
58 - expect(items.length).toBeGreaterThanOrEqual(1);
59 + expect((items as Array<unknown>).length).toBeGreaterThanOrEqual(1);
60 });
61
62 it('first element has slug "gmail"', () => {
62 - const items = JSON.parse(sanitizeOutput(validResult.stdout));
63 + const items = parseJsonStdout(validResult) as Array<{ slug: string }>;
64 expect(items[0].slug).toBe('gmail');
65 });
66
67 it('each element has the expected shape', () => {
67 - const items = JSON.parse(sanitizeOutput(validResult.stdout));
68 + const items = parseJsonStdout(validResult) as Array<Record<string, unknown>>;
69 for (const item of items) {
70 expect(item).toHaveProperty('name');
71 expect(item).toHaveProperty('slug');
@@ -85,13 +86,13 @@ e2e(import.meta.url, {
86 });
87
88 it('stdout is a JSON array with exactly 1 element', () => {
88 - const items = JSON.parse(sanitizeOutput(limitResult.stdout));
89 + const items = parseJsonStdout(limitResult);
90 expect(Array.isArray(items)).toBe(true);
90 - expect(items).toHaveLength(1);
91 + expect(items as Array<unknown>).toHaveLength(1);
92 });
93
94 it('the element has slug "gmail"', () => {
94 - const items = JSON.parse(sanitizeOutput(limitResult.stdout));
95 + const items = parseJsonStdout(limitResult) as Array<{ slug: string }>;
96 expect(items[0].slug).toBe('gmail');
97 });
98 });