Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * CLI agent sign-in e2e test (PRDE-1138) |
| 3 | * |
| 4 | * A headless agent must reach an authenticated CLI without human action, and |
| 5 | * a human piping `composio login` must never be auto-signed-up as an agent. |
| 6 | */ |
| 7 | |
| 8 | import { e2e, type E2ETestResult } from '@e2e-tests/utils'; |
| 9 | import { TIMEOUTS } from '@e2e-tests/utils/const'; |
| 10 | import { afterAll, beforeAll, describe, expect, it } from 'bun:test'; |
| 11 | import { |
| 12 | startMockAgentsServer, |
| 13 | type MockAgentsServer, |
| 14 | } from '../../../packages/cli/scripts/mock-agents-server'; |
| 15 | |
| 16 | const CACHE_DIR = '/tmp/composio-agent-signin'; |
| 17 | |
| 18 | /** Parses the last stdout line as JSON — the `composio whoami` payload. */ |
| 19 | const lastJsonLine = (stdout: string): Record<string, unknown> => |
| 20 | JSON.parse(stdout.trim().split('\n').at(-1) ?? '{}') as Record<string, unknown>; |
| 21 | |
| 22 | const envPrefix = (server: MockAgentsServer): string => |
| 23 | [ |
| 24 | `COMPOSIO_BASE_URL=${server.dockerBaseUrl}`, |
| 25 | `COMPOSIO_AGENTS_BASE_URL=${server.dockerBaseUrl}`, |
| 26 | `COMPOSIO_CACHE_DIR=${CACHE_DIR}`, |
| 27 | ].join(' '); |
| 28 | |
| 29 | e2e(import.meta.url, { |
| 30 | versions: { |
| 31 | cli: ['current'], |
| 32 | }, |
| 33 | defineTests: ({ runCmd }) => { |
| 34 | let signupServer: MockAgentsServer; |
| 35 | let guardrailServer: MockAgentsServer; |
| 36 | let reuseServer: MockAgentsServer; |
| 37 | let unattendedSignup: E2ETestResult; |
| 38 | let headlessHumanLogin: E2ETestResult; |
| 39 | let storedIdentityLogin: E2ETestResult; |
| 40 | |
| 41 | beforeAll(async () => { |
| 42 | signupServer = await startMockAgentsServer(); |
| 43 | guardrailServer = await startMockAgentsServer(); |
| 44 | reuseServer = await startMockAgentsServer(); |
| 45 | |
| 46 | unattendedSignup = await runCmd( |
| 47 | `${envPrefix(signupServer)} composio login --agent --no-skill-install && ${envPrefix(signupServer)} composio whoami` |
| 48 | ); |
| 49 | |
| 50 | headlessHumanLogin = await runCmd(`${envPrefix(guardrailServer)} composio login`); |
| 51 | |
| 52 | const storedIdentity = JSON.stringify(reuseServer.agentIdentity); |
| 53 | storedIdentityLogin = await runCmd( |
| 54 | [ |
| 55 | `mkdir -p ${CACHE_DIR}`, |
| 56 | `printf '%s' '${storedIdentity}' > ${CACHE_DIR}/agent.json`, |
| 57 | `${envPrefix(reuseServer)} composio login && ${envPrefix(reuseServer)} composio whoami`, |
| 58 | ].join('\n') |
| 59 | ); |
| 60 | }, TIMEOUTS.FIXTURE); |
| 61 | |
| 62 | afterAll(async () => { |
| 63 | await signupServer.close(); |
| 64 | await guardrailServer.close(); |
| 65 | await reuseServer.close(); |
| 66 | }); |
| 67 | |
| 68 | describe('composio login --agent (unattended onboarding)', () => { |
| 69 | it('exits successfully', () => { |
| 70 | expect(unattendedSignup.exitCode).toBe(0); |
| 71 | }); |
| 72 | |
| 73 | it('signs up via agents.composio.dev', () => { |
| 74 | expect(signupServer.requests).toContain('POST /api/signup'); |
| 75 | }); |
| 76 | |
| 77 | it('prints the agent login summary on stdout', () => { |
| 78 | expect(unattendedSignup.stdout).toContain('"account_type":"agent"'); |
| 79 | expect(unattendedSignup.stdout).toContain('"logged_in":true'); |
| 80 | expect(unattendedSignup.stdout).toContain('"status":"READY"'); |
| 81 | }); |
| 82 | |
| 83 | it('leaves the CLI authenticated as the agent (whoami)', () => { |
| 84 | const whoami = lastJsonLine(unattendedSignup.stdout); |
| 85 | expect(whoami.account_type).toBe('agent'); |
| 86 | // whoami's own line, not the login summary before it. |
| 87 | expect(whoami.email).toBe('e2e-agent@agent.composio.ai'); |
| 88 | }); |
| 89 | }); |
| 90 | |
| 91 | describe('composio login (headless, no agent identity)', () => { |
| 92 | it('exits successfully with instructions instead of hanging', () => { |
| 93 | expect(headlessHumanLogin.exitCode).toBe(0); |
| 94 | expect(headlessHumanLogin.stdout).toContain('Open this URL in your browser to log in:'); |
| 95 | expect(headlessHumanLogin.stdout).toContain('composio login --poll'); |
| 96 | }); |
| 97 | |
| 98 | it('offers the unattended agent path', () => { |
| 99 | expect(headlessHumanLogin.stdout).toContain('For unattended agents'); |
| 100 | expect(headlessHumanLogin.stdout).toContain('composio login --agent'); |
| 101 | }); |
| 102 | |
| 103 | it('never auto-signs-up an account', () => { |
| 104 | expect(guardrailServer.requests.filter(request => request.includes('/api/signup'))).toEqual( |
| 105 | [] |
| 106 | ); |
| 107 | }); |
| 108 | }); |
| 109 | |
| 110 | describe('composio login (headless, stored READY agent identity)', () => { |
| 111 | it('completes login unattended by reusing the stored identity', () => { |
| 112 | expect(storedIdentityLogin.exitCode).toBe(0); |
| 113 | expect(storedIdentityLogin.stdout).toContain('"logged_in":true'); |
| 114 | expect(storedIdentityLogin.stdout).not.toContain('Open this URL in your browser'); |
| 115 | }); |
| 116 | |
| 117 | it('refreshes the identity instead of signing up', () => { |
| 118 | expect(reuseServer.requests).toContain('GET /api/whoami'); |
| 119 | expect(reuseServer.requests.filter(request => request.includes('/api/signup'))).toEqual([]); |
| 120 | }); |
| 121 | |
| 122 | it('leaves the CLI authenticated as the agent (whoami)', () => { |
| 123 | const whoami = lastJsonLine(storedIdentityLogin.stdout); |
| 124 | expect(whoami.account_type).toBe('agent'); |
| 125 | expect(whoami.email).toBe('e2e-agent@agent.composio.ai'); |
| 126 | }); |
| 127 | }); |
| 128 | }, |
| 129 | }); |