@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 57 lines 2.16 KB
Raw
1 import { Console, Effect, Layer } from 'effect';
2 import {
3 ComposioToolkitsRepository,
4 type ComposioToolkitsRepositoryShape,
5 } from 'src/services/composio-clients';
6 import { TerminalUI } from 'src/services/terminal-ui';
7 import * as MockConsole from '../services/mock-console';
8 import { makeToolkitsRepositoryStub } from '../services/toolkits-repository-stub';
9 import {
10 authConfigRepositoryMethods,
11 resolveAuthConfigsTestData,
12 type AuthConfigsTestData,
13 } from './connected-accounts';
14 import { terminalUITestImpl } from '../services/terminal-ui-test';
15 import { DirectoryProjectTest } from './developer-project';
16
17 /** What an `auth-configs` handler test serves. */
18 export interface AuthConfigsHandlerFixture {
19 /** The auth configs the repository answers from, as `TestLive` serves them. */
20 readonly authConfigsData?: AuthConfigsTestData;
21 /** Repository methods that answer differently, such as a failing request. */
22 readonly repository?: Partial<ComposioToolkitsRepositoryShape>;
23 }
24
25 /**
26 * What an `auth-configs` handler needs without argv or `TestLive`: a headless terminal whose
27 * stdout payloads land in `outputs` (decoration goes to `MockConsole`), the directory's
28 * developer project (`DirectoryProjectTest`), and a repository serving only the auth-config
29 * methods. Any other repository method dies.
30 */
31 export const AuthConfigsHandlerTest = (fixture: AuthConfigsHandlerFixture = {}) => {
32 const outputs: Array<string> = [];
33 const layer = Layer.mergeAll(
34 Layer.effect(Console.Console, MockConsole.make),
35 DirectoryProjectTest,
36 Layer.succeed(
37 TerminalUI,
38 TerminalUI.of({
39 ...terminalUITestImpl,
40 output: data =>
41 Effect.sync(() => {
42 outputs.push(data);
43 }),
44 })
45 ),
46 Layer.succeed(
47 ComposioToolkitsRepository,
48 makeToolkitsRepositoryStub({
49 // Only the auth-config methods: a stray connected-account request dies instead of
50 // answering a catchable API error, so a test fails loudly at the change site.
51 ...authConfigRepositoryMethods(resolveAuthConfigsTestData(fixture.authConfigsData)),
52 ...fixture.repository,
53 })
54 )
55 );
56 return { layer, outputs };
57 };