53
fixture: 'global-test-user-id' as const,
54
};
55
56
+const extractFirstJsonObject = (output: string): Record<string, unknown> | null => {
57
+ const start = output.indexOf('{');
58
+ if (start < 0) return null;
59
+
60
+ let depth = 0;
61
+ let inString = false;
62
+ let escaped = false;
63
+
64
+ for (let i = start; i < output.length; i += 1) {
65
+ const char = output[i];
66
+
67
+ if (inString) {
68
+ if (escaped) {
69
+ escaped = false;
70
+ } else if (char === '\\') {
71
+ escaped = true;
72
+ } else if (char === '"') {
73
+ inString = false;
74
+ }
75
+ continue;
76
+ }
77
+
78
+ if (char === '"') {
79
+ inString = true;
80
+ continue;
81
+ }
82
+
83
+ if (char === '{') {
84
+ depth += 1;
85
+ continue;
86
+ }
87
+
88
+ if (char === '}') {
89
+ depth -= 1;
90
+ if (depth === 0) {
91
+ return JSON.parse(output.slice(start, i + 1)) as Record<string, unknown>;
92
+ }
93
+ }
94
+ }
95
+
96
+ return null;
97
+};
98
+
99
describe('CLI: composio search', () => {
100
layer(TestLive(testLiveOptions))('[Given] query "send" [Then] returns JSON by default', it => {
101
it.scoped('returns JSON payload by default', () =>
103
yield* cli(['search', 'send']);
104
const lines = yield* MockConsole.getLines({ stripAnsi: true });
105
const output = lines.join('\n');
63
-
64
- expect(output).toContain('"results"');
65
- expect(output).toContain('"tool_schemas"');
66
- expect(output).toContain('"primary"');
67
- expect(output).toContain('"related_tools_path_format"');
68
- expect(output).toContain('"connected_toolkits"');
69
- expect(output).toContain('"CTA"');
70
- expect(output).not.toContain('"session"');
71
- expect(output).not.toContain('"time_info"');
72
- expect(output).not.toContain('"next_steps_guidance"');
73
- expect(output).not.toContain('"success"');
74
- expect(output).not.toContain('"error"');
106
+ const parsed = extractFirstJsonObject(output);
107
+
108
+ expect(parsed).not.toBeNull();
109
+ expect(parsed).toHaveProperty('results');
110
+ expect(parsed).toHaveProperty('tool_schemas');
111
+ expect(parsed).toHaveProperty('connected_toolkits');
112
+ expect(parsed).toHaveProperty('next_steps');
113
+ expect(parsed).not.toHaveProperty('session');
114
+ expect(parsed).not.toHaveProperty('time_info');
115
+ expect(parsed).not.toHaveProperty('next_steps_guidance');
116
+ expect(parsed).not.toHaveProperty('success');
117
+ expect(parsed).not.toHaveProperty('error');
118
expect(output).toContain('GMAIL_SEND_EMAIL');
119
expect(output).toContain('SLACK_SEND_MESSAGE');
120
expect(output).toContain('~/.composio/tool_definitions/GMAIL_SEND_EMAIL.json');
194
);
195
196
layer(TestLive(testLiveOptions))(
154
- '[Given] search --json [Then] JSON output includes full tool-router payload and CTA',
197
+ '[Given] search --json [Then] JSON output includes full tool-router payload and next steps',
198
it => {
156
- it.scoped('prints full search response with CTA for jq', () =>
199
+ it.scoped('prints full search response with next steps for jq', () =>
200
Effect.gen(function* () {
201
yield* cli(['search', 'send', '--json']);
202
const lines = yield* MockConsole.getLines({ stripAnsi: true });
203
const output = lines.join('\n');
161
-
162
- expect(output).toContain('"results"');
163
- expect(output).toContain('"tool_schemas"');
164
- expect(output).toContain('"connected_toolkits"');
165
- expect(output).toContain('"CTA"');
166
- expect(output).not.toContain('"session"');
167
- expect(output).not.toContain('"time_info"');
168
- expect(output).not.toContain('"next_steps_guidance"');
169
- expect(output).not.toContain('"success"');
170
- expect(output).not.toContain('"error"');
204
+ const parsed = extractFirstJsonObject(output);
205
+
206
+ expect(parsed).not.toBeNull();
207
+ expect(parsed).toHaveProperty('results');
208
+ expect(parsed).toHaveProperty('tool_schemas');
209
+ expect(parsed).toHaveProperty('connected_toolkits');
210
+ expect(parsed).toHaveProperty('next_steps');
211
+ expect(parsed).not.toHaveProperty('session');
212
+ expect(parsed).not.toHaveProperty('time_info');
213
+ expect(parsed).not.toHaveProperty('next_steps_guidance');
214
+ expect(parsed).not.toHaveProperty('success');
215
+ expect(parsed).not.toHaveProperty('error');
216
expect(output).toContain('"Execute a tool"');
172
- expect(output).toContain('"Connect a user account"');
217
+ expect(output).toContain('"Link a user account"');
218
expect(output).toContain('composio execute');
219
expect(output).toContain('composio link gmail');
220
})
289
);
290
291
layer(TestLive({ baseConfigProvider: testConfigProvider, fixture: 'global-test-user-id' }))(
247
- '[Given] search with schema properties [Then] CTA has valid payload and lowercase link',
292
+ '[Given] search with schema properties [Then] next steps have valid payload and lowercase link',
293
it => {
249
- it.scoped('CTA uses valid payload from input_schema and lowercase toolkit', () =>
294
+ it.scoped('next steps use valid payload from input_schema and lowercase toolkit', () =>
295
Effect.gen(function* () {
296
const live = TestLive({
297
baseConfigProvider: testConfigProvider,
322
yield* cli(['search', 'send']).pipe(Effect.provide(live));
323
const lines = yield* MockConsole.getLines({ stripAnsi: true });
324
const output = lines.join('\n');
280
-
281
- const ctaMatch = output.match(/"CTA":\s*\[([\s\S]*?)\]/);
282
- expect(ctaMatch).toBeTruthy();
283
- const ctaJson = `[${ctaMatch![1]}]`;
284
- const cta = JSON.parse(ctaJson) as Array<{ action: string; command: string }>;
285
-
286
- const executeCta = cta.find(c => c.action === 'Execute a tool');
287
- expect(executeCta).toBeTruthy();
288
- expect(executeCta!.command).toContain('composio execute "GMAIL_SEND_EMAIL"');
289
- expect(executeCta!.command).toMatch(/-d '\{"to":"","subject":"","body":""\}'/);
290
-
291
- const linkCta = cta.find(c => c.action === 'Connect a user account');
292
- expect(linkCta).toBeTruthy();
293
- expect(linkCta!.command).toBe('composio link gmail');
325
+ const parsed = extractFirstJsonObject(output);
326
+ const nextSteps = parsed?.next_steps as
327
+ | {
328
+ steps?: Array<{ action: string; command: string }>;
329
+ }
330
+ | undefined;
331
+
332
+ expect(nextSteps?.steps).toBeTruthy();
333
+
334
+ const executeStep = nextSteps?.steps?.find(step => step.action === 'Execute a tool');
335
+ expect(executeStep).toBeTruthy();
336
+ expect(executeStep!.command).toContain('composio execute "GMAIL_SEND_EMAIL"');
337
+ expect(executeStep!.command).toMatch(/-d '\{"to":"","subject":"","body":""\}'/);
338
+
339
+ const linkStep = nextSteps?.steps?.find(step => step.action === 'Link a user account');
340
+ expect(linkStep).toBeTruthy();
341
+ expect(linkStep!.command).toBe('composio link gmail');
342
})
343
);
344
}
345
);
346
347
layer(TestLive(testLiveOptions))(
300
- '[Given] search with empty schema [Then] CTA execute uses -d "{}"',
348
+ '[Given] search with empty schema [Then] next steps execute uses -d "{}"',
349
it => {
302
- it.scoped('CTA uses -d "{}" when no schema properties', () =>
350
+ it.scoped('next steps use -d "{}" when no schema properties', () =>
351
Effect.gen(function* () {
352
yield* cli(['search', 'send']);
353
const lines = yield* MockConsole.getLines({ stripAnsi: true });
354
const output = lines.join('\n');
307
-
308
- const ctaMatch = output.match(/"CTA":\s*\[([\s\S]*?)\]/);
309
- expect(ctaMatch).toBeTruthy();
310
- const ctaJson = `[${ctaMatch![1]}]`;
311
- const cta = JSON.parse(ctaJson) as Array<{ action: string; command: string }>;
312
-
313
- const executeCta = cta.find(c => c.action === 'Execute a tool');
314
- expect(executeCta).toBeTruthy();
315
- expect(executeCta!.command).toContain('-d "{}"');
355
+ const parsed = extractFirstJsonObject(output);
356
+ const nextSteps = parsed?.next_steps as
357
+ | {
358
+ steps?: Array<{ action: string; command: string }>;
359
+ }
360
+ | undefined;
361
+
362
+ const executeStep = nextSteps?.steps?.find(step => step.action === 'Execute a tool');
363
+ expect(executeStep).toBeTruthy();
364
+ expect(executeStep!.command).toContain('-d "{}"');
365
})
366
);
367
}