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 { writeStoredAgentIdentity } from 'src/services/agents'; |
| 5 | import { cli, MockConsole, TestLive } from 'test/__utils__'; |
| 6 | import { agentsJsonResponse, makeAgentIdentity } from 'test/__utils__/models/agent'; |
| 7 | import { exitCodeOf } from 'test/__utils__/exit-code'; |
| 8 | |
| 9 | describe('CLI: composio agent claim', () => { |
| 10 | afterEach(() => { |
| 11 | vi.restoreAllMocks(); |
| 12 | }); |
| 13 | |
| 14 | layer(TestLive())(it => { |
| 15 | it.effect('[Given] an email [Then] invites it and prints the invite as JSON', () => |
| 16 | Effect.gen(function* () { |
| 17 | yield* writeStoredAgentIdentity(makeAgentIdentity()); |
| 18 | const fetchSpy = vi |
| 19 | .spyOn(globalThis, 'fetch') |
| 20 | .mockImplementation(async () => agentsJsonResponse({ status: 'invited' })); |
| 21 | |
| 22 | yield* cli(['agent', 'claim', 'boss@example.com']); |
| 23 | |
| 24 | expect(fetchSpy).toHaveBeenCalledExactlyOnceWith( |
| 25 | expect.stringContaining('/api/claim'), |
| 26 | expect.objectContaining({ |
| 27 | method: 'POST', |
| 28 | body: JSON.stringify({ email: 'boss@example.com' }), |
| 29 | }) |
| 30 | ); |
| 31 | const stdout = yield* MockConsole.getLines({ stream: 'stdout', stripAnsi: true }); |
| 32 | expect(stdout.at(-1)).toBe( |
| 33 | JSON.stringify({ |
| 34 | status: 'invited', |
| 35 | email: 'boss@example.com', |
| 36 | org_id: null, |
| 37 | invite_code: null, |
| 38 | }) |
| 39 | ); |
| 40 | }) |
| 41 | ); |
| 42 | }); |
| 43 | |
| 44 | layer(TestLive({ fixture: 'user-config-example' }))(it => { |
| 45 | it.effect('[Given] the CLI is signed in as a human user [Then] shows a soft auth warning', () => |
| 46 | Effect.gen(function* () { |
| 47 | const fetchSpy = vi.spyOn(globalThis, 'fetch'); |
| 48 | |
| 49 | const exit = yield* Effect.exit(cli(['agent', 'claim', 'boss@example.com'])); |
| 50 | const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n'); |
| 51 | |
| 52 | expect(output).toContain('currently signed in to Composio as a regular user'); |
| 53 | expect(exitCodeOf(exit)).toBe(1); |
| 54 | expect(fetchSpy).not.toHaveBeenCalled(); |
| 55 | }) |
| 56 | ); |
| 57 | }); |
| 58 | }); |