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 21, 04:45 UTC
| 1 | import { describe, expect, layer } from '@effect/vitest'; |
| 2 | import { ConfigProvider, Effect } from 'effect'; |
| 3 | import type { |
| 4 | SessionCreateParams, |
| 5 | SessionSearchParams, |
| 6 | } from '@composio/client/resources/tool-router'; |
| 7 | import { cli, TestLive, MockConsole } from 'test/__utils__'; |
| 8 | import type { TestLiveInput } from 'test/__utils__/services/test-layer'; |
| 9 | import type { Tools } from 'src/models/tools'; |
| 10 | import { CommandInputError } from 'src/commands/errors'; |
| 11 | import { MissingActingUserError } from 'src/commands/surface'; |
| 12 | |
| 13 | const testTools: Tools = [ |
| 14 | { |
| 15 | name: 'Send Email', |
| 16 | slug: 'GMAIL_SEND_EMAIL', |
| 17 | description: 'Sends an email to a recipient using Gmail', |
| 18 | tags: ['messaging', 'email'], |
| 19 | available_versions: ['20260101_00'], |
| 20 | input_parameters: { type: 'object', properties: {} }, |
| 21 | output_parameters: { type: 'object', properties: {} }, |
| 22 | }, |
| 23 | { |
| 24 | name: 'Send Message', |
| 25 | slug: 'SLACK_SEND_MESSAGE', |
| 26 | description: 'Sends a message to a Slack channel', |
| 27 | tags: ['messaging'], |
| 28 | available_versions: ['20260101_00'], |
| 29 | input_parameters: { type: 'object', properties: {} }, |
| 30 | output_parameters: { type: 'object', properties: {} }, |
| 31 | }, |
| 32 | { |
| 33 | name: 'Create Issue', |
| 34 | slug: 'GITHUB_CREATE_ISSUE', |
| 35 | description: 'Creates a new issue in a GitHub repository', |
| 36 | tags: ['development'], |
| 37 | available_versions: ['20260101_00'], |
| 38 | input_parameters: { type: 'object', properties: {} }, |
| 39 | output_parameters: { type: 'object', properties: {} }, |
| 40 | }, |
| 41 | ]; |
| 42 | |
| 43 | const toolkitsData = { |
| 44 | tools: testTools, |
| 45 | } satisfies TestLiveInput['toolkitsData']; |
| 46 | |
| 47 | const testConfigProvider = ConfigProvider.fromEnv({ |
| 48 | env: { COMPOSIO_USER_API_KEY: 'test_api_key' }, |
| 49 | }); |
| 50 | |
| 51 | const testLiveOptions = { |
| 52 | baseConfigProvider: testConfigProvider, |
| 53 | toolkitsData, |
| 54 | fixture: 'global-test-user-id' as const, |
| 55 | }; |
| 56 | |
| 57 | describe('CLI: composio search', () => { |
| 58 | layer(TestLive(testLiveOptions))('[Given] a blank query [Then] typed validation fails', it => { |
| 59 | it.effect('returns the structured missing-query error', () => |
| 60 | Effect.gen(function* () { |
| 61 | const failure = yield* cli(['search', ' ']).pipe(Effect.flip); |
| 62 | expect(failure).toBeInstanceOf(CommandInputError); |
| 63 | expect(failure).toMatchObject({ |
| 64 | option: '<query>', |
| 65 | message: 'At least one query is required.', |
| 66 | }); |
| 67 | }) |
| 68 | ); |
| 69 | }); |
| 70 | |
| 71 | layer(TestLive(testLiveOptions))('[Given] query "send" [Then] returns JSON by default', it => { |
| 72 | it.effect('returns JSON payload by default', () => |
| 73 | Effect.gen(function* () { |
| 74 | yield* cli(['search', 'send']); |
| 75 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 76 | const output = lines.join('\n'); |
| 77 | const parsed = JSON.parse(String(lines.at(-1))); |
| 78 | |
| 79 | expect(parsed).toHaveProperty('results'); |
| 80 | expect(parsed).toHaveProperty('tool_schemas'); |
| 81 | expect(parsed).toHaveProperty('connected_toolkits'); |
| 82 | expect(parsed).toHaveProperty('next_steps'); |
| 83 | expect(parsed).not.toHaveProperty('session'); |
| 84 | expect(parsed).not.toHaveProperty('time_info'); |
| 85 | expect(parsed).not.toHaveProperty('next_steps_guidance'); |
| 86 | expect(parsed).not.toHaveProperty('success'); |
| 87 | expect(parsed).not.toHaveProperty('error'); |
| 88 | expect(output).toContain('GMAIL_SEND_EMAIL'); |
| 89 | expect(output).toContain('SLACK_SEND_MESSAGE'); |
| 90 | expect(output).toContain('~/.composio/tool_definitions/GMAIL_SEND_EMAIL.json'); |
| 91 | }) |
| 92 | ); |
| 93 | }); |
| 94 | |
| 95 | const customSlug = 'CUSTOM_DEEPWIKI_READ_WIKI_CONTENTS'; |
| 96 | |
| 97 | layer( |
| 98 | TestLive({ |
| 99 | ...testLiveOptions, |
| 100 | toolRouter: { |
| 101 | search: (_sessionId, params) => |
| 102 | Effect.succeed({ |
| 103 | success: true, |
| 104 | error: null, |
| 105 | results: [ |
| 106 | { |
| 107 | index: 1, |
| 108 | use_case: params.queries[0]?.use_case ?? '', |
| 109 | primary_tool_slugs: [customSlug], |
| 110 | related_tool_slugs: [], |
| 111 | toolkits: ['CUSTOM_DEEPWIKI'], |
| 112 | }, |
| 113 | ], |
| 114 | tool_schemas: { |
| 115 | [customSlug]: { |
| 116 | tool_slug: customSlug, |
| 117 | toolkit: 'CUSTOM_DEEPWIKI', |
| 118 | description: 'Read wiki contents', |
| 119 | hasFullSchema: true, |
| 120 | input_schema: { |
| 121 | type: 'object', |
| 122 | properties: { repo: { type: 'string' } }, |
| 123 | required: ['repo'], |
| 124 | }, |
| 125 | output_schema: { type: 'object', properties: {} }, |
| 126 | }, |
| 127 | }, |
| 128 | toolkit_connection_statuses: [], |
| 129 | next_steps_guidance: [], |
| 130 | session: { |
| 131 | id: 'trs_test_session', |
| 132 | generate_id: false, |
| 133 | instructions: 'Reuse this session id for follow-up calls.', |
| 134 | }, |
| 135 | time_info: { |
| 136 | current_time_utc: '2026-01-01T00:00:00.000Z', |
| 137 | current_time_utc_epoch_seconds: 1767225600, |
| 138 | message: 'UTC time', |
| 139 | }, |
| 140 | }), |
| 141 | }, |
| 142 | }) |
| 143 | )('[Given] a remote custom tool schema [Then] search uses the Tool Router schema', it => { |
| 144 | it.effect('does not refetch custom tool schemas through the legacy tools endpoint', () => |
| 145 | Effect.gen(function* () { |
| 146 | yield* cli(['search', 'read wiki contents']); |
| 147 | const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n'); |
| 148 | |
| 149 | expect(output).toContain(customSlug); |
| 150 | expect(output).toContain(`~/.composio/tool_definitions/${customSlug}.json`); |
| 151 | }) |
| 152 | ); |
| 153 | }); |
| 154 | |
| 155 | let schemaRequestSlugs: unknown; |
| 156 | |
| 157 | layer( |
| 158 | TestLive({ |
| 159 | ...testLiveOptions, |
| 160 | toolRouter: { |
| 161 | search: (_sessionId, params) => |
| 162 | Effect.succeed({ |
| 163 | success: true, |
| 164 | error: null, |
| 165 | results: [ |
| 166 | { |
| 167 | index: 1, |
| 168 | use_case: params.queries[0]?.use_case ?? '', |
| 169 | primary_tool_slugs: [customSlug], |
| 170 | related_tool_slugs: [], |
| 171 | toolkits: ['CUSTOM_DEEPWIKI'], |
| 172 | }, |
| 173 | ], |
| 174 | tool_schemas: { |
| 175 | [customSlug]: { |
| 176 | tool_slug: customSlug, |
| 177 | toolkit: 'CUSTOM_DEEPWIKI', |
| 178 | description: 'Read wiki contents', |
| 179 | hasFullSchema: false, |
| 180 | schemaRef: { |
| 181 | tool: 'COMPOSIO_GET_TOOL_SCHEMAS', |
| 182 | args: { tool_slugs: [customSlug] }, |
| 183 | }, |
| 184 | }, |
| 185 | }, |
| 186 | toolkit_connection_statuses: [], |
| 187 | next_steps_guidance: [], |
| 188 | session: { |
| 189 | id: 'trs_test_session', |
| 190 | generate_id: false, |
| 191 | instructions: 'Reuse this session id for follow-up calls.', |
| 192 | }, |
| 193 | time_info: { |
| 194 | current_time_utc: '2026-01-01T00:00:00.000Z', |
| 195 | current_time_utc_epoch_seconds: 1767225600, |
| 196 | message: 'UTC time', |
| 197 | }, |
| 198 | }), |
| 199 | executeMeta: (_sessionId, params) => |
| 200 | Effect.sync(() => { |
| 201 | schemaRequestSlugs = params.arguments?.tool_slugs; |
| 202 | return { |
| 203 | result_type: 'completed' as const, |
| 204 | data: { |
| 205 | success: true, |
| 206 | tool_schemas: { |
| 207 | [customSlug]: { |
| 208 | tool_slug: customSlug, |
| 209 | toolkit: 'CUSTOM_DEEPWIKI', |
| 210 | description: 'Read wiki contents', |
| 211 | input_schema: { |
| 212 | type: 'object', |
| 213 | properties: { repo: { type: 'string' } }, |
| 214 | required: ['repo'], |
| 215 | }, |
| 216 | }, |
| 217 | }, |
| 218 | }, |
| 219 | error: null, |
| 220 | log_id: 'log_test', |
| 221 | }; |
| 222 | }), |
| 223 | }, |
| 224 | }) |
| 225 | )( |
| 226 | '[Given] a remote custom tool schema reference [Then] search resolves it with the Tool Router meta-tool', |
| 227 | it => { |
| 228 | it.effect('does not use the legacy tools endpoint for schema references', () => |
| 229 | Effect.gen(function* () { |
| 230 | yield* cli(['search', 'read wiki contents']); |
| 231 | const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n'); |
| 232 | |
| 233 | expect(output).toContain(customSlug); |
| 234 | expect(schemaRequestSlugs).toEqual([customSlug]); |
| 235 | expect(output).toContain(`~/.composio/tool_definitions/${customSlug}.json`); |
| 236 | }) |
| 237 | ); |
| 238 | } |
| 239 | ); |
| 240 | |
| 241 | layer(TestLive(testLiveOptions))( |
| 242 | '[Given] multiple queries [Then] the CLI returns a batched JSON response', |
| 243 | it => { |
| 244 | it.effect('returns batched results in JSON', () => |
| 245 | Effect.gen(function* () { |
| 246 | yield* cli(['search', 'send', 'create issue']); |
| 247 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 248 | const output = lines.join('\n'); |
| 249 | |
| 250 | expect(JSON.parse(String(lines.at(-1)))).toMatchObject({ |
| 251 | results: [{ use_case: 'send' }, { use_case: 'create issue' }], |
| 252 | }); |
| 253 | expect(output).toContain('GMAIL_SEND_EMAIL'); |
| 254 | expect(output).toContain('SLACK_SEND_MESSAGE'); |
| 255 | expect(output).toContain('GITHUB_CREATE_ISSUE'); |
| 256 | }) |
| 257 | ); |
| 258 | } |
| 259 | ); |
| 260 | |
| 261 | layer(TestLive(testLiveOptions))( |
| 262 | '[Given] query with no results [Then] shows not found message', |
| 263 | it => { |
| 264 | it.effect('shows empty json output', () => |
| 265 | Effect.gen(function* () { |
| 266 | yield* cli(['search', 'nonexistent_query']); |
| 267 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 268 | const output = lines.join('\n'); |
| 269 | |
| 270 | expect(output).toContain('[]'); |
| 271 | }) |
| 272 | ); |
| 273 | } |
| 274 | ); |
| 275 | |
| 276 | layer(TestLive(testLiveOptions))( |
| 277 | '[Given] query "send" --toolkits "gmail" --human [Then] scopes to toolkit', |
| 278 | it => { |
| 279 | it.effect('scopes search to toolkit', () => |
| 280 | Effect.gen(function* () { |
| 281 | yield* cli(['search', 'send', '--toolkits', 'gmail', '--human']); |
| 282 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 283 | const output = lines.join('\n'); |
| 284 | |
| 285 | expect(output).toContain('GMAIL_SEND_EMAIL'); |
| 286 | expect(output).not.toContain('SLACK_SEND_MESSAGE'); |
| 287 | expect(output).not.toContain('"results"'); |
| 288 | expect(output).toContain('Found 1 tools'); |
| 289 | }) |
| 290 | ); |
| 291 | } |
| 292 | ); |
| 293 | |
| 294 | layer(TestLive(testLiveOptions))( |
| 295 | '[Given] search --human [Then] it stays human-readable and omits raw JSON', |
| 296 | it => { |
| 297 | it.effect('does not print raw JSON in human mode', () => |
| 298 | Effect.gen(function* () { |
| 299 | yield* cli(['search', 'send', '--human']); |
| 300 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 301 | const output = lines.join('\n'); |
| 302 | |
| 303 | expect(output).not.toContain('"results"'); |
| 304 | expect(output).not.toContain('"tool_schemas"'); |
| 305 | expect(output).toContain('Found 2 tools'); |
| 306 | expect(output).toContain('composio execute'); |
| 307 | expect(output).toContain('composio link <toolkit>'); |
| 308 | }) |
| 309 | ); |
| 310 | } |
| 311 | ); |
| 312 | |
| 313 | layer(TestLive(testLiveOptions))( |
| 314 | '[Given] search --json [Then] JSON output includes full tool-router payload and next steps', |
| 315 | it => { |
| 316 | it.effect('prints full search response with next steps for jq', () => |
| 317 | Effect.gen(function* () { |
| 318 | yield* cli(['search', 'send', '--json']); |
| 319 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 320 | const output = lines.join('\n'); |
| 321 | const parsed = JSON.parse(String(lines.at(-1))); |
| 322 | |
| 323 | expect(parsed).toHaveProperty('results'); |
| 324 | expect(parsed).toHaveProperty('tool_schemas'); |
| 325 | expect(parsed).toHaveProperty('connected_toolkits'); |
| 326 | expect(parsed).toHaveProperty('next_steps'); |
| 327 | expect(parsed).not.toHaveProperty('session'); |
| 328 | expect(parsed).not.toHaveProperty('time_info'); |
| 329 | expect(parsed).not.toHaveProperty('next_steps_guidance'); |
| 330 | expect(parsed).not.toHaveProperty('success'); |
| 331 | expect(parsed).not.toHaveProperty('error'); |
| 332 | expect(output).toContain('"Execute a tool"'); |
| 333 | expect(output).toContain('"Link a user account"'); |
| 334 | expect(output).toContain('composio execute'); |
| 335 | expect(output).toContain('composio link gmail'); |
| 336 | }) |
| 337 | ); |
| 338 | } |
| 339 | ); |
| 340 | |
| 341 | layer( |
| 342 | TestLive({ |
| 343 | ...testLiveOptions, |
| 344 | toolRouter: { |
| 345 | search: (_sessionId, params) => |
| 346 | Effect.succeed({ |
| 347 | success: true, |
| 348 | error: null, |
| 349 | results: [ |
| 350 | { |
| 351 | index: 1, |
| 352 | use_case: params.queries[0]?.use_case ?? '', |
| 353 | primary_tool_slugs: ['GMAIL_SEND_EMAIL'], |
| 354 | related_tool_slugs: [], |
| 355 | toolkits: ['gmail'], |
| 356 | reference_workbench_snippets: [{ description: 'snippet', code: 'print("hi")' }], |
| 357 | }, |
| 358 | ], |
| 359 | tool_schemas: { |
| 360 | GMAIL_SEND_EMAIL: { |
| 361 | tool_slug: 'GMAIL_SEND_EMAIL', |
| 362 | toolkit: 'gmail', |
| 363 | description: 'Sends an email', |
| 364 | hasFullSchema: true, |
| 365 | input_schema: { type: 'object', properties: {} }, |
| 366 | output_schema: { type: 'object', properties: {} }, |
| 367 | }, |
| 368 | }, |
| 369 | toolkit_connection_statuses: [ |
| 370 | { |
| 371 | toolkit: 'gmail', |
| 372 | description: 'gmail toolkit', |
| 373 | has_active_connection: false, |
| 374 | status_message: 'No active connection', |
| 375 | }, |
| 376 | ], |
| 377 | next_steps_guidance: [], |
| 378 | session: { |
| 379 | id: 'trs_test_session', |
| 380 | generate_id: false, |
| 381 | instructions: 'Reuse this session id for follow-up calls.', |
| 382 | }, |
| 383 | time_info: { |
| 384 | current_time_utc: '2026-01-01T00:00:00.000Z', |
| 385 | current_time_utc_epoch_seconds: 1767225600, |
| 386 | message: 'UTC time', |
| 387 | }, |
| 388 | }), |
| 389 | }, |
| 390 | }) |
| 391 | )( |
| 392 | '[Given] search results with workbench snippets [Then] snippets are removed from JSON output', |
| 393 | it => { |
| 394 | it.effect('omits workbench snippets and emits schema/cache references', () => |
| 395 | Effect.gen(function* () { |
| 396 | yield* cli(['search', 'send']); |
| 397 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 398 | const output = lines.join('\n'); |
| 399 | |
| 400 | expect(output).not.toContain('reference_workbench_snippets'); |
| 401 | expect(output).toContain('~/.composio/tool_definitions/GMAIL_SEND_EMAIL.json'); |
| 402 | expect(output).toContain('"related_tools_path_format"'); |
| 403 | }) |
| 404 | ); |
| 405 | } |
| 406 | ); |
| 407 | |
| 408 | layer( |
| 409 | TestLive({ |
| 410 | baseConfigProvider: testConfigProvider, |
| 411 | fixture: 'global-test-user-id', |
| 412 | toolkitsData: { |
| 413 | tools: [ |
| 414 | { |
| 415 | name: 'Send Email', |
| 416 | slug: 'GMAIL_SEND_EMAIL', |
| 417 | description: 'Sends an email', |
| 418 | tags: [], |
| 419 | available_versions: [], |
| 420 | input_parameters: { |
| 421 | type: 'object', |
| 422 | properties: { |
| 423 | to: { type: 'string' }, |
| 424 | subject: { type: 'string' }, |
| 425 | body: { type: 'string' }, |
| 426 | }, |
| 427 | required: ['to'], |
| 428 | }, |
| 429 | output_parameters: { type: 'object', properties: {} }, |
| 430 | }, |
| 431 | ], |
| 432 | }, |
| 433 | }) |
| 434 | )( |
| 435 | '[Given] search with schema properties [Then] next steps have valid payload and lowercase link', |
| 436 | it => { |
| 437 | it.effect('next steps use valid payload from input_schema and lowercase toolkit', () => |
| 438 | Effect.gen(function* () { |
| 439 | yield* cli(['search', 'send']); |
| 440 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 441 | const parsed = JSON.parse(String(lines.at(-1))); |
| 442 | |
| 443 | expect(parsed.next_steps.steps).toEqual( |
| 444 | expect.arrayContaining([ |
| 445 | { |
| 446 | action: 'Execute a tool', |
| 447 | command: expect.stringMatching( |
| 448 | /composio execute "GMAIL_SEND_EMAIL".*-d '\{"to":"","subject":"","body":""\}'/ |
| 449 | ), |
| 450 | }, |
| 451 | { action: 'Link a user account', command: 'composio link gmail' }, |
| 452 | ]) |
| 453 | ); |
| 454 | }) |
| 455 | ); |
| 456 | } |
| 457 | ); |
| 458 | |
| 459 | layer(TestLive(testLiveOptions))( |
| 460 | '[Given] search with empty schema [Then] next steps execute uses -d "{}"', |
| 461 | it => { |
| 462 | it.effect('next steps use -d "{}" when no schema properties', () => |
| 463 | Effect.gen(function* () { |
| 464 | yield* cli(['search', 'send']); |
| 465 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 466 | const parsed = JSON.parse(String(lines.at(-1))); |
| 467 | |
| 468 | expect(parsed.next_steps.steps).toEqual( |
| 469 | expect.arrayContaining([ |
| 470 | { action: 'Execute a tool', command: expect.stringContaining('-d "{}"') }, |
| 471 | ]) |
| 472 | ); |
| 473 | }) |
| 474 | ); |
| 475 | } |
| 476 | ); |
| 477 | |
| 478 | { |
| 479 | let createParams: SessionCreateParams | undefined; |
| 480 | let searchParams: SessionSearchParams | undefined; |
| 481 | |
| 482 | layer( |
| 483 | TestLive({ |
| 484 | baseConfigProvider: testConfigProvider, |
| 485 | toolkitsData, |
| 486 | fixture: 'global-test-user-id', |
| 487 | toolRouter: { |
| 488 | create: params => |
| 489 | Effect.sync(() => { |
| 490 | createParams = params; |
| 491 | return { |
| 492 | session_id: 'trs_test_session', |
| 493 | config: { |
| 494 | user_id: params.user_id, |
| 495 | execute: {}, |
| 496 | search: {}, |
| 497 | preload: { tools: [] }, |
| 498 | instant: false, |
| 499 | }, |
| 500 | config_version: 1, |
| 501 | mcp: { type: 'http', url: 'https://mcp.test.composio.dev' }, |
| 502 | tool_router_tools: ['COMPOSIO_SEARCH_TOOLS'], |
| 503 | }; |
| 504 | }), |
| 505 | search: (_sessionId, params) => |
| 506 | Effect.sync(() => { |
| 507 | searchParams = params; |
| 508 | return { |
| 509 | success: true, |
| 510 | error: null, |
| 511 | results: [ |
| 512 | { |
| 513 | index: 1, |
| 514 | use_case: params.queries[0]?.use_case ?? '', |
| 515 | primary_tool_slugs: ['GMAIL_SEND_EMAIL'], |
| 516 | related_tool_slugs: [], |
| 517 | toolkits: ['gmail'], |
| 518 | }, |
| 519 | ], |
| 520 | tool_schemas: { |
| 521 | GMAIL_SEND_EMAIL: { |
| 522 | tool_slug: 'GMAIL_SEND_EMAIL', |
| 523 | toolkit: 'gmail', |
| 524 | description: 'Sends an email', |
| 525 | hasFullSchema: true, |
| 526 | input_schema: { type: 'object', properties: {} }, |
| 527 | output_schema: { type: 'object', properties: {} }, |
| 528 | }, |
| 529 | }, |
| 530 | toolkit_connection_statuses: [ |
| 531 | { |
| 532 | toolkit: 'gmail', |
| 533 | description: 'gmail toolkit', |
| 534 | has_active_connection: false, |
| 535 | status_message: 'No active connection', |
| 536 | }, |
| 537 | ], |
| 538 | next_steps_guidance: [], |
| 539 | session: { |
| 540 | id: 'trs_test_session', |
| 541 | generate_id: false, |
| 542 | instructions: 'Reuse this session id for follow-up calls.', |
| 543 | }, |
| 544 | time_info: { |
| 545 | current_time_utc: '2026-01-01T00:00:00.000Z', |
| 546 | current_time_utc_epoch_seconds: 1767225600, |
| 547 | message: 'UTC time', |
| 548 | }, |
| 549 | }; |
| 550 | }), |
| 551 | }, |
| 552 | }) |
| 553 | )('[Given] --toolkits filter [Then] it is passed to session create as enabled toolkits', it => { |
| 554 | it.effect('passes toolkit filter into tool router session', () => |
| 555 | Effect.gen(function* () { |
| 556 | yield* cli(['search', 'send', '--toolkits', 'gmail,outlook']); |
| 557 | |
| 558 | expect(createParams?.toolkits).toEqual({ enable: ['gmail', 'outlook'] }); |
| 559 | expect(createParams?.experimental).toBeUndefined(); |
| 560 | expect(searchParams?.queries[0]?.use_case).toBe('send'); |
| 561 | }) |
| 562 | ); |
| 563 | }); |
| 564 | } |
| 565 | |
| 566 | { |
| 567 | let createParams: SessionCreateParams | undefined; |
| 568 | |
| 569 | layer( |
| 570 | TestLive({ |
| 571 | baseConfigProvider: testConfigProvider, |
| 572 | toolkitsData, |
| 573 | fixture: 'global-test-user-id', |
| 574 | toolRouter: { |
| 575 | create: params => |
| 576 | Effect.sync(() => { |
| 577 | createParams = params; |
| 578 | return { |
| 579 | session_id: 'trs_test_session', |
| 580 | config: { |
| 581 | user_id: params.user_id, |
| 582 | execute: {}, |
| 583 | search: {}, |
| 584 | preload: { tools: [] }, |
| 585 | instant: false, |
| 586 | }, |
| 587 | config_version: 1, |
| 588 | mcp: { type: 'http', url: 'https://mcp.test.composio.dev' }, |
| 589 | tool_router_tools: ['COMPOSIO_SEARCH_TOOLS'], |
| 590 | }; |
| 591 | }), |
| 592 | }, |
| 593 | }) |
| 594 | )( |
| 595 | '[Given] unknown local-style toolkit filter [Then] it is still sent as a remote toolkit', |
| 596 | it => { |
| 597 | it.effect( |
| 598 | 'does not inject experimental custom toolkits for unknown local-style names', |
| 599 | () => |
| 600 | Effect.gen(function* () { |
| 601 | yield* cli(['search', 'inspect local app', '--toolkits', 'local_app']); |
| 602 | |
| 603 | expect(createParams?.toolkits).toEqual({ enable: ['local_app'] }); |
| 604 | expect(createParams?.experimental).toBeUndefined(); |
| 605 | }) |
| 606 | ); |
| 607 | } |
| 608 | ); |
| 609 | } |
| 610 | |
| 611 | { |
| 612 | let searchParams: SessionSearchParams | undefined; |
| 613 | |
| 614 | layer( |
| 615 | TestLive({ |
| 616 | baseConfigProvider: testConfigProvider, |
| 617 | toolkitsData, |
| 618 | fixture: 'global-test-user-id', |
| 619 | toolRouter: { |
| 620 | search: (_sessionId, params) => |
| 621 | Effect.sync(() => { |
| 622 | searchParams = params; |
| 623 | return { |
| 624 | success: true, |
| 625 | error: null, |
| 626 | results: params.queries.map((query, index) => ({ |
| 627 | index: index + 1, |
| 628 | use_case: query.use_case ?? '', |
| 629 | primary_tool_slugs: |
| 630 | query.use_case === 'create issue' |
| 631 | ? ['GITHUB_CREATE_ISSUE'] |
| 632 | : ['GMAIL_SEND_EMAIL'], |
| 633 | related_tool_slugs: [], |
| 634 | toolkits: query.use_case === 'create issue' ? ['github'] : ['gmail'], |
| 635 | })), |
| 636 | tool_schemas: { |
| 637 | GMAIL_SEND_EMAIL: { |
| 638 | tool_slug: 'GMAIL_SEND_EMAIL', |
| 639 | toolkit: 'gmail', |
| 640 | description: 'Sends an email', |
| 641 | hasFullSchema: true, |
| 642 | input_schema: { type: 'object', properties: {} }, |
| 643 | output_schema: { type: 'object', properties: {} }, |
| 644 | }, |
| 645 | GITHUB_CREATE_ISSUE: { |
| 646 | tool_slug: 'GITHUB_CREATE_ISSUE', |
| 647 | toolkit: 'github', |
| 648 | description: 'Creates a GitHub issue', |
| 649 | hasFullSchema: true, |
| 650 | input_schema: { type: 'object', properties: {} }, |
| 651 | output_schema: { type: 'object', properties: {} }, |
| 652 | }, |
| 653 | }, |
| 654 | toolkit_connection_statuses: [], |
| 655 | next_steps_guidance: [], |
| 656 | session: { |
| 657 | id: 'trs_test_session', |
| 658 | generate_id: false, |
| 659 | instructions: 'Reuse this session id for follow-up calls.', |
| 660 | }, |
| 661 | time_info: { |
| 662 | current_time_utc: '2026-01-01T00:00:00.000Z', |
| 663 | current_time_utc_epoch_seconds: 1767225600, |
| 664 | message: 'UTC time', |
| 665 | }, |
| 666 | }; |
| 667 | }), |
| 668 | }, |
| 669 | }) |
| 670 | )( |
| 671 | '[Given] multiple queries [Then] search passes all queries to the tool-router session', |
| 672 | it => { |
| 673 | it.effect('passes batched queries without a parallel flag', () => |
| 674 | Effect.gen(function* () { |
| 675 | yield* cli(['search', 'send', 'create issue']); |
| 676 | |
| 677 | expect(searchParams?.queries.map(query => query.use_case)).toEqual([ |
| 678 | 'send', |
| 679 | 'create issue', |
| 680 | ]); |
| 681 | }) |
| 682 | ); |
| 683 | } |
| 684 | ); |
| 685 | } |
| 686 | |
| 687 | layer( |
| 688 | TestLive({ |
| 689 | baseConfigProvider: testConfigProvider, |
| 690 | toolkitsData, |
| 691 | fixture: 'global-test-user-id', |
| 692 | toolRouter: { |
| 693 | search: (_sessionId, params) => |
| 694 | Effect.succeed({ |
| 695 | success: true, |
| 696 | error: null, |
| 697 | results: [ |
| 698 | { |
| 699 | index: 1, |
| 700 | use_case: params.queries[0]?.use_case ?? '', |
| 701 | primary_tool_slugs: ['GMAIL_SEND_EMAIL'], |
| 702 | related_tool_slugs: [], |
| 703 | toolkits: ['gmail'], |
| 704 | recommended_plan_steps: ['Collect recipient details', 'Execute send action'], |
| 705 | }, |
| 706 | ], |
| 707 | tool_schemas: { |
| 708 | GMAIL_SEND_EMAIL: { |
| 709 | tool_slug: 'GMAIL_SEND_EMAIL', |
| 710 | toolkit: 'gmail', |
| 711 | description: 'Sends an email', |
| 712 | hasFullSchema: true, |
| 713 | input_schema: { type: 'object', properties: {} }, |
| 714 | output_schema: { type: 'object', properties: {} }, |
| 715 | }, |
| 716 | }, |
| 717 | toolkit_connection_statuses: [ |
| 718 | { |
| 719 | toolkit: 'gmail', |
| 720 | description: 'gmail toolkit', |
| 721 | has_active_connection: false, |
| 722 | status_message: 'No active connection', |
| 723 | }, |
| 724 | ], |
| 725 | next_steps_guidance: ['Fallback guidance'], |
| 726 | session: { |
| 727 | id: 'trs_test_session', |
| 728 | generate_id: false, |
| 729 | instructions: 'Reuse this session id for follow-up calls.', |
| 730 | }, |
| 731 | time_info: { |
| 732 | current_time_utc: '2026-01-01T00:00:00.000Z', |
| 733 | current_time_utc_epoch_seconds: 1767225600, |
| 734 | message: 'UTC time', |
| 735 | }, |
| 736 | }), |
| 737 | }, |
| 738 | }) |
| 739 | )('[Given] search response with recommended plan [Then] it prints plan and execute hint', it => { |
| 740 | it.effect('prints plan and command hints', () => |
| 741 | Effect.gen(function* () { |
| 742 | yield* cli(['search', 'send email', '--human']); |
| 743 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 744 | const output = lines.join('\n'); |
| 745 | |
| 746 | expect(output).toContain('Plan:'); |
| 747 | expect(output).toContain('1. Collect recipient details'); |
| 748 | expect(output).toContain('Execute a tool:'); |
| 749 | expect(output).toContain(`composio execute "GMAIL_SEND_EMAIL" -d "{}"`); |
| 750 | expect(output).toContain(`composio link <toolkit>`); |
| 751 | }) |
| 752 | ); |
| 753 | }); |
| 754 | |
| 755 | layer(TestLive())('[Given] no API key [Then] warns user to login', it => { |
| 756 | it.effect('warns user to login', () => |
| 757 | Effect.gen(function* () { |
| 758 | const error = yield* cli(['search', 'send', '--human']).pipe(Effect.flip); |
| 759 | expect(error).toMatchObject({ _tag: 'commands/NotLoggedInError' }); |
| 760 | }) |
| 761 | ); |
| 762 | }); |
| 763 | |
| 764 | { |
| 765 | let createParams: SessionCreateParams | undefined; |
| 766 | |
| 767 | layer( |
| 768 | TestLive({ |
| 769 | ...testLiveOptions, |
| 770 | toolRouter: { |
| 771 | create: params => |
| 772 | Effect.sync(() => { |
| 773 | createParams = params; |
| 774 | return { |
| 775 | session_id: 'trs_test_session', |
| 776 | config: { |
| 777 | user_id: params.user_id, |
| 778 | execute: {}, |
| 779 | search: {}, |
| 780 | preload: { tools: [] }, |
| 781 | instant: false, |
| 782 | }, |
| 783 | config_version: 1, |
| 784 | mcp: { type: 'http', url: 'https://mcp.test.composio.dev' }, |
| 785 | tool_router_tools: ['COMPOSIO_SEARCH_TOOLS'], |
| 786 | }; |
| 787 | }), |
| 788 | }, |
| 789 | }) |
| 790 | )('[Given] consumer search [Then] it uses the resolved consumer user id', it => { |
| 791 | it.effect('uses consumer user id from the resolved project context', () => |
| 792 | Effect.gen(function* () { |
| 793 | yield* cli(['search', 'send']); |
| 794 | |
| 795 | expect(createParams?.user_id).toBe('consumer-user-org_test'); |
| 796 | }) |
| 797 | ); |
| 798 | }); |
| 799 | } |
| 800 | |
| 801 | layer( |
| 802 | TestLive({ |
| 803 | baseConfigProvider: testConfigProvider, |
| 804 | fixture: 'user-config-with-global-context', |
| 805 | toolkitsData, |
| 806 | }) |
| 807 | )('[Given] no explicit --user-id [Then] consumer search does not require one', it => { |
| 808 | it.effect('runs without printing global test user diagnostics', () => |
| 809 | Effect.gen(function* () { |
| 810 | yield* cli(['search', 'send']); |
| 811 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 812 | const output = lines.join('\n'); |
| 813 | |
| 814 | expect(output).toContain('"results"'); |
| 815 | expect(output).toContain('GMAIL_SEND_EMAIL'); |
| 816 | expect(output).not.toContain('Using global test user id'); |
| 817 | }) |
| 818 | ); |
| 819 | }); |
| 820 | |
| 821 | layer(TestLive(testLiveOptions))( |
| 822 | '[Given] composio search [Then] runs the root search flow', |
| 823 | it => { |
| 824 | it.effect('search returns matching tools', () => |
| 825 | Effect.gen(function* () { |
| 826 | yield* cli(['search', 'send', '--human']); |
| 827 | const lines = yield* MockConsole.getLines({ stripAnsi: true }); |
| 828 | const output = lines.join('\n'); |
| 829 | |
| 830 | expect(output).toContain('GMAIL_SEND_EMAIL'); |
| 831 | expect(output).toContain('SLACK_SEND_MESSAGE'); |
| 832 | expect(output).toContain('Found 2 tools'); |
| 833 | }) |
| 834 | ); |
| 835 | } |
| 836 | ); |
| 837 | |
| 838 | layer( |
| 839 | TestLive({ |
| 840 | ...testLiveOptions, |
| 841 | // A response without the field at all, which only a mock can answer. |
| 842 | accountData: { consumerUserId: null }, |
| 843 | }) |
| 844 | )('[Given] no consumer user id [Then] the search fails with the missing-user error', it => { |
| 845 | it.effect('[Then] the message points at composio login', () => |
| 846 | Effect.gen(function* () { |
| 847 | const failure = yield* cli(['search', 'send']).pipe(Effect.flip); |
| 848 | |
| 849 | expect(failure).toBeInstanceOf(MissingActingUserError); |
| 850 | expect(failure).toMatchObject({ |
| 851 | message: 'Missing consumer user id. Run `composio login` and try again.', |
| 852 | }); |
| 853 | }) |
| 854 | ); |
| 855 | }); |
| 856 | |
| 857 | layer( |
| 858 | TestLive({ |
| 859 | ...testLiveOptions, |
| 860 | // The backend's "logged in, but no consumer user" shape counts as no user. |
| 861 | accountData: { consumerUserId: '' }, |
| 862 | }) |
| 863 | )('[Given] an empty consumer user id [Then] the search fails with the missing-user error', it => { |
| 864 | it.effect('[Then] no results are printed', () => |
| 865 | Effect.gen(function* () { |
| 866 | const failure = yield* cli(['search', 'send']).pipe(Effect.flip); |
| 867 | const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n'); |
| 868 | |
| 869 | expect(failure).toBeInstanceOf(MissingActingUserError); |
| 870 | expect(failure).toMatchObject({ |
| 871 | message: 'Missing consumer user id. Run `composio login` and try again.', |
| 872 | }); |
| 873 | expect(output).not.toContain('GMAIL_SEND_EMAIL'); |
| 874 | }) |
| 875 | ); |
| 876 | }); |
| 877 | }); |