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 { Cause, ConfigProvider, Effect, Exit } from 'effect'; |
| 3 | import { extractErrorDetails } from 'src/effect-errors/logic/errors/extract-error-details'; |
| 4 | import { cli, MockConsole, TestLive } from 'test/__utils__'; |
| 5 | import { stubClientResources } from 'test/__utils__/services/stub-composio-client'; |
| 6 | import { detail, log } from './logs.tools.fixtures'; |
| 7 | |
| 8 | const testLayer = TestLive({ |
| 9 | baseConfigProvider: ConfigProvider.fromEnv({ env: { COMPOSIO_USER_API_KEY: 'test_api_key' } }), |
| 10 | fixture: 'global-test-user-id', |
| 11 | }); |
| 12 | |
| 13 | describe('CLI: public tool logs over the API client', () => { |
| 14 | layer(testLayer)(it => { |
| 15 | it.effect( |
| 16 | '[Given] unified logs [Then] renders public metadata and preserves the response on stdout', |
| 17 | () => |
| 18 | Effect.gen(function* () { |
| 19 | const stdoutBefore = (yield* MockConsole.getLines({ stream: 'stdout' })).length; |
| 20 | const page = { logs: [log], next_cursor: null }; |
| 21 | const stub = stubClientResources(['logs'], () => Response.json(page)); |
| 22 | yield* cli(['dev', 'logs', 'tools']).pipe(Effect.provide(stub.layer)); |
| 23 | const stderr = (yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true })).join( |
| 24 | '\n' |
| 25 | ); |
| 26 | expect(stderr).toContain('2026-01-01T00:00:00.000Z log_send_1'); |
| 27 | expect(stderr).toContain('gmail'); |
| 28 | expect(stderr).toContain('GMAIL_SEND_EMAIL'); |
| 29 | expect(stderr).toContain('412ms'); |
| 30 | expect(stderr).toContain('ca_gmail_1'); |
| 31 | expect((yield* MockConsole.getLines({ stream: 'stdout' })).slice(stdoutBefore)).toEqual([ |
| 32 | JSON.stringify(page, null, 2), |
| 33 | ]); |
| 34 | }) |
| 35 | ); |
| 36 | |
| 37 | it.effect( |
| 38 | '[Given] one log id [Then] retrieves public detail and shows its request and response', |
| 39 | () => |
| 40 | Effect.gen(function* () { |
| 41 | const stdoutBefore = (yield* MockConsole.getLines({ stream: 'stdout' })).length; |
| 42 | const stub = stubClientResources(['logs'], () => Response.json(detail)); |
| 43 | yield* cli(['dev', 'logs', 'tools', log.id]).pipe(Effect.provide(stub.layer)); |
| 44 | expect(stub.requests).toEqual([ |
| 45 | { method: 'GET', path: '/api/v3.1/logs/tool_execution/log_send_1' }, |
| 46 | ]); |
| 47 | const stderr = (yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true })).join( |
| 48 | '\n' |
| 49 | ); |
| 50 | expect(stderr).toContain('toolSlug: GMAIL_SEND_EMAIL'); |
| 51 | expect(stderr).toContain('Payload:\n{\n "to": "a@b.c"\n}'); |
| 52 | expect(stderr).toContain('Response:\n{\n "id": "msg_1"\n}'); |
| 53 | expect((yield* MockConsole.getLines({ stream: 'stdout' })).slice(stdoutBefore)).toEqual([ |
| 54 | JSON.stringify(detail, null, 2), |
| 55 | ]); |
| 56 | }) |
| 57 | ); |
| 58 | |
| 59 | it.effect( |
| 60 | '[Given] drifted metadata and status [Then] keeps tolerant rendering without client decoding', |
| 61 | () => |
| 62 | Effect.gen(function* () { |
| 63 | const stdoutBefore = (yield* MockConsole.getLines({ stream: 'stdout' })).length; |
| 64 | const drifted = { |
| 65 | logs: [ |
| 66 | { |
| 67 | id: 'log_drift', |
| 68 | timestamp: log.timestamp, |
| 69 | status: null, |
| 70 | metadata: { |
| 71 | toolkit: null, |
| 72 | tool: { slug: 'GMAIL_SEND_EMAIL' }, |
| 73 | connected_account_id: null, |
| 74 | }, |
| 75 | metrics: {}, |
| 76 | }, |
| 77 | ], |
| 78 | }; |
| 79 | const stub = stubClientResources(['logs'], () => Response.json(drifted)); |
| 80 | yield* cli(['dev', 'logs', 'tools']).pipe(Effect.provide(stub.layer)); |
| 81 | const stderr = (yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true })).join( |
| 82 | '\n' |
| 83 | ); |
| 84 | expect(stderr).toContain('log_drift'); |
| 85 | expect(stderr).toContain('GMAIL_SEND_EMAIL'); |
| 86 | expect(stderr).not.toContain('0ms'); |
| 87 | expect((yield* MockConsole.getLines({ stream: 'stdout' })).slice(stdoutBefore)).toEqual([ |
| 88 | JSON.stringify(drifted, null, 2), |
| 89 | ]); |
| 90 | }) |
| 91 | ); |
| 92 | |
| 93 | it.effect.each([ |
| 94 | { args: [], status: 403, message: 'Failed to fetch tool logs.' }, |
| 95 | { args: ['log_missing'], status: 404, message: 'Failed to fetch tool log "log_missing".' }, |
| 96 | ])( |
| 97 | '[Given] an API error [Then] preserves the error and command context', |
| 98 | ({ args, status, message }) => |
| 99 | Effect.gen(function* () { |
| 100 | const stub = stubClientResources(['logs'], () => |
| 101 | Response.json({ error: { message: 'Not allowed' } }, { status }) |
| 102 | ); |
| 103 | const exit = yield* cli(['dev', 'logs', 'tools', ...args]).pipe( |
| 104 | Effect.provide(stub.layer), |
| 105 | Effect.exit |
| 106 | ); |
| 107 | const failure = Exit.isFailure(exit) ? Cause.squash(exit.cause) : undefined; |
| 108 | expect(failure).toMatchObject({ _tag: 'commands/ToolLogsRequestError', message }); |
| 109 | expect(extractErrorDetails(failure).message).toContain( |
| 110 | `${status} {"error":{"message":"Not allowed"}}` |
| 111 | ); |
| 112 | }) |
| 113 | ); |
| 114 | }); |
| 115 | }); |