@devries-cameron20 / composio Mirror · read-only
Fork 0

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

next
ts 48 lines 1.85 KB
Raw
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 whoami', () => {
10 afterEach(() => {
11 vi.restoreAllMocks();
12 });
13
14 layer(TestLive())(it => {
15 it.effect('[Given] a stored agent identity [Then] prints its summary as JSON', () =>
16 Effect.gen(function* () {
17 yield* writeStoredAgentIdentity(makeAgentIdentity());
18 vi.spyOn(globalThis, 'fetch').mockImplementation(async () =>
19 agentsJsonResponse(makeAgentIdentity())
20 );
21
22 yield* cli(['agent', 'whoami']);
23
24 const stdout = yield* MockConsole.getLines({ stream: 'stdout', stripAnsi: true });
25 expect(JSON.parse(stdout.at(-1) ?? '')).toMatchObject({
26 account_type: 'agent',
27 status: 'READY',
28 email: 'test-agent@agent.composio.ai',
29 });
30 expect(stdout.join('\n')).not.toContain('cak_test_agent');
31 expect(stdout.join('\n')).not.toContain('uak_agent');
32 })
33 );
34 });
35
36 layer(TestLive({ fixture: 'user-config-example' }))(it => {
37 it.effect('[Given] the CLI is signed in as a human user [Then] shows a soft auth warning', () =>
38 Effect.gen(function* () {
39 const exit = yield* Effect.exit(cli(['agent', 'whoami']));
40 const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
41
42 expect(output).toContain('currently signed in to Composio as a regular user');
43 expect(output).toContain('composio agent login <composio_agent_key>');
44 expect(exitCodeOf(exit)).toBe(1);
45 })
46 );
47 });
48 });