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 | import { describe, expect, layer } from '@effect/vitest'; |
| 2 | import * as FileSystem from 'effect/FileSystem'; |
| 3 | import { Effect, Option } 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 { readStoredAgentIdentity } from 'src/services/agents'; |
| 8 | import { cli, MockConsole, TestLive } from 'test/__utils__'; |
| 9 | import { makeAgentIdentity } from 'test/__utils__/models/agent'; |
| 10 | |
| 11 | describe('CLI: composio agent', () => { |
| 12 | afterEach(() => { |
| 13 | vi.restoreAllMocks(); |
| 14 | }); |
| 15 | |
| 16 | layer(TestLive())(it => { |
| 17 | it.effect('repairs permissions on an existing agent identity before reading it', () => |
| 18 | Effect.gen(function* () { |
| 19 | const fs = yield* FileSystem.FileSystem; |
| 20 | const cacheDir = yield* setupCacheDir; |
| 21 | const agentConfigPath = path.join(cacheDir, 'agent.json'); |
| 22 | const encodedIdentity = `${JSON.stringify(makeAgentIdentity(), null, 2)}\n`; |
| 23 | yield* fs.writeFileString(agentConfigPath, encodedIdentity); |
| 24 | yield* fs.chmod(agentConfigPath, 0o644); |
| 25 | expect((yield* fs.stat(agentConfigPath)).mode & 0o777).toBe(0o644); |
| 26 | |
| 27 | const identity = yield* readStoredAgentIdentity; |
| 28 | |
| 29 | expect(Option.getOrThrow(identity).composio_agent_key).toBe('cak_test_agent'); |
| 30 | expect(yield* fs.readFileString(agentConfigPath, 'utf8')).toBe(encodedIdentity); |
| 31 | expect((yield* fs.stat(agentConfigPath)).mode & 0o777).toBe(0o600); |
| 32 | }) |
| 33 | ); |
| 34 | |
| 35 | it.effect('exposes agent signup as a subcommand', () => |
| 36 | Effect.gen(function* () { |
| 37 | yield* cli(['agent', '--help']); |
| 38 | const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n'); |
| 39 | |
| 40 | expect(output).toContain('signup'); |
| 41 | expect(output).toContain('login'); |
| 42 | expect(output).toContain('whoami'); |
| 43 | expect(output).toContain('claim'); |
| 44 | }) |
| 45 | ); |
| 46 | }); |
| 47 | }); |