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 { Effect } from 'effect'; |
| 3 | import { afterEach, vi } from 'vitest'; |
| 4 | import { runSignup } from 'src/commands/signup/signup.handler'; |
| 5 | import type { AgentIdentity } from 'src/services/agents'; |
| 6 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 7 | import { MockConsole, TestLive } from 'test/__utils__'; |
| 8 | import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test'; |
| 9 | |
| 10 | const readyIdentity: AgentIdentity = { |
| 11 | status: 'READY', |
| 12 | slug: 'test-agent', |
| 13 | email: 'test-agent@agent.composio.ai', |
| 14 | composio_agent_key: 'cak_test_agent', |
| 15 | composio: { |
| 16 | member_id: 'mem_agent', |
| 17 | org_id: 'org_agent', |
| 18 | project_id: 'proj_agent', |
| 19 | user_api_key: 'uak_agent', |
| 20 | }, |
| 21 | }; |
| 22 | |
| 23 | /** A headless terminal whose stdout payloads land in `outputs`. */ |
| 24 | const capturingTest = () => { |
| 25 | const outputs: Array<{ readonly data: string; readonly force: boolean }> = []; |
| 26 | const terminalUI = TerminalUI.of({ |
| 27 | ...terminalUITestImpl, |
| 28 | output: (data, options) => |
| 29 | Effect.sync(() => { |
| 30 | outputs.push({ data, force: options?.force ?? false }); |
| 31 | }), |
| 32 | }); |
| 33 | return { outputs, layer: TestLive({ terminalUI }) }; |
| 34 | }; |
| 35 | |
| 36 | const noLogin = capturingTest(); |
| 37 | |
| 38 | describe('runSignup', () => { |
| 39 | afterEach(() => { |
| 40 | vi.restoreAllMocks(); |
| 41 | }); |
| 42 | |
| 43 | layer(noLogin.layer)(it => { |
| 44 | it.effect( |
| 45 | '[Given] --no-login [Then] names `composio signup` and prints the summary as data', |
| 46 | () => |
| 47 | Effect.gen(function* () { |
| 48 | vi.spyOn(globalThis, 'fetch').mockImplementation( |
| 49 | async () => |
| 50 | new Response(JSON.stringify(readyIdentity), { |
| 51 | status: 200, |
| 52 | headers: { 'Content-Type': 'application/json' }, |
| 53 | }) |
| 54 | ); |
| 55 | |
| 56 | yield* runSignup({ noWait: false, noLogin: true, force: false }); |
| 57 | |
| 58 | expect(yield* MockConsole.getLines({ stripAnsi: true })).toEqual([ |
| 59 | '-- composio signup --', |
| 60 | 'composio signup signs you up as a Composio agent. This flow is fully non-interactive and does not open a browser.', |
| 61 | [ |
| 62 | '[Composio Agent] Type: agent', |
| 63 | 'Status: READY', |
| 64 | 'Email: test-agent@agent.composio.ai', |
| 65 | 'Slug: test-agent', |
| 66 | 'Current Org ID: org_agent', |
| 67 | 'Project ID: proj_agent', |
| 68 | 'Agent key: stored in ~/.composio/agent.json', |
| 69 | ].join('\n'), |
| 70 | '-- Agent setup complete. --', |
| 71 | ]); |
| 72 | expect(noLogin.outputs).toEqual([ |
| 73 | { |
| 74 | data: JSON.stringify({ |
| 75 | account_type: 'agent', |
| 76 | status: 'READY', |
| 77 | slug: 'test-agent', |
| 78 | email: 'test-agent@agent.composio.ai', |
| 79 | org_id: 'org_agent', |
| 80 | project_id: 'proj_agent', |
| 81 | member_id: 'mem_agent', |
| 82 | claimed_by: null, |
| 83 | claimed_at: null, |
| 84 | logged_in: false, |
| 85 | }), |
| 86 | force: false, |
| 87 | }, |
| 88 | ]); |
| 89 | }) |
| 90 | ); |
| 91 | }); |
| 92 | }); |