@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 68 lines 2.34 KB
Raw
1 import { describe, expect, layer } from '@effect/vitest';
2 import * as FileSystem from 'effect/FileSystem';
3 import { Effect } from 'effect';
4 import path from 'node:path';
5 import { afterEach, vi } from 'vitest';
6 import { setupCacheDir } from 'src/effects/setup-cache-dir';
7 import { writeStoredAgentIdentity } from 'src/services/agents';
8 import { cli, MockConsole, TestLive } from 'test/__utils__';
9 import { agentsJsonResponse, makeAgentIdentity } from 'test/__utils__/models/agent';
10
11 describe('CLI: composio agent inbox', () => {
12 afterEach(() => {
13 vi.restoreAllMocks();
14 });
15
16 layer(TestLive())(it => {
17 it.effect('agent inbox prints only JSON', () =>
18 Effect.gen(function* () {
19 yield* writeStoredAgentIdentity(makeAgentIdentity());
20 const fs = yield* FileSystem.FileSystem;
21 const cacheDir = yield* setupCacheDir;
22 expect((yield* fs.stat(path.join(cacheDir, 'agent.json'))).mode & 0o777).toBe(0o600);
23 const inbox = {
24 count: 1,
25 messages: [
26 {
27 id: 'msg_123',
28 from: 'person@example.com',
29 subject: 'Hello',
30 preview: 'Hi agent',
31 },
32 ],
33 };
34 const fetchSpy = vi
35 .spyOn(globalThis, 'fetch')
36 .mockImplementation(async () => agentsJsonResponse(inbox));
37
38 yield* cli(['agent', 'inbox']);
39 const lines = yield* MockConsole.getLines({ stripAnsi: true });
40
41 expect(fetchSpy).toHaveBeenCalledExactlyOnceWith(
42 expect.stringContaining('/api/mail?limit=50'),
43 expect.objectContaining({
44 method: 'GET',
45 headers: expect.objectContaining({ Authorization: 'Bearer cak_test_agent' }),
46 })
47 );
48 expect(lines).toEqual([JSON.stringify(inbox)]);
49 })
50 );
51
52 it.effect('[Given] --limit [Then] asks the agents API for that many messages', () =>
53 Effect.gen(function* () {
54 yield* writeStoredAgentIdentity(makeAgentIdentity());
55 const fetchSpy = vi
56 .spyOn(globalThis, 'fetch')
57 .mockImplementation(async () => agentsJsonResponse({ count: 0, messages: [] }));
58
59 yield* cli(['agent', 'inbox', '--limit', '5']);
60
61 expect(fetchSpy).toHaveBeenCalledExactlyOnceWith(
62 expect.stringContaining('/api/mail?limit=5'),
63 expect.anything()
64 );
65 })
66 );
67 });
68 });