Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 139 lines 5.13 KB
Raw
1 import { describe, it } from '@effect/vitest';
2 import { deepStrictEqual } from '@effect/vitest/utils';
3 import { Config, ConfigProvider, Effect, Option } from 'effect';
4 import { APP_CONFIG } from 'src/config';
5 import * as constants from 'src/constants';
6
7 const read = <A>(config: Config.Config<A>, env: Record<string, string>) =>
8 config.parse(ConfigProvider.fromEnvRecord(env));
9
10 const urls = Config.all({ base: APP_CONFIG.BASE_URL, web: APP_CONFIG.WEB_URL });
11
12 describe('APP_CONFIG', () => {
13 it.effect('[Given] an empty environment [Then] every setting takes its default', () =>
14 Effect.gen(function* () {
15 deepStrictEqual(yield* read(Config.all(APP_CONFIG), {}), {
16 USER_API_KEY: undefined,
17 ENVIRONMENT: undefined,
18 BASE_URL: constants.DEFAULT_BASE_URL,
19 WEB_URL: constants.DEFAULT_WEB_URL,
20 BACKEND: {
21 baseURL: constants.DEFAULT_BASE_URL,
22 webURL: constants.DEFAULT_WEB_URL,
23 selectedBy: Option.none(),
24 webURLSet: false,
25 },
26 CACHE_DIR: undefined,
27 SESSION_DIR: undefined,
28 BIN_DIR: undefined,
29 LOG_LEVEL: undefined,
30 ORG_ID: undefined,
31 PROJECT_ID: undefined,
32 AGENTS_BASE_URL: undefined,
33 WEBHOOK_SECRET: undefined,
34 CLI_INVOCATION_ORIGIN: undefined,
35 CLI_PARENT_RUN_ID: undefined,
36 RUN_OUTPUT_DIR: undefined,
37 RUN_STAGED_FILES_FILE: undefined,
38 DISABLE_CONNECTED_ACCOUNT_CACHE: true,
39 TOOLKIT_VERSIONS: Option.none(),
40 });
41 })
42 );
43
44 it.effect('[Given] unprefixed names [Then] they are ignored', () =>
45 Effect.gen(function* () {
46 const actual = yield* read(
47 Config.all({ apiKey: APP_CONFIG.USER_API_KEY, logLevel: APP_CONFIG.LOG_LEVEL }),
48 { USER_API_KEY: 'api_key', LOG_LEVEL: 'Debug' }
49 );
50 deepStrictEqual(actual, { apiKey: undefined, logLevel: undefined });
51 })
52 );
53
54 it.effect('[Given] every COMPOSIO_* variable [Then] values are trimmed and typed', () =>
55 Effect.gen(function* () {
56 const actual = yield* read(Config.all(APP_CONFIG), {
57 COMPOSIO_USER_API_KEY: 'api_key',
58 COMPOSIO_BASE_URL: 'https://test.localhost',
59 COMPOSIO_WEB_URL: 'https://web.localhost',
60 COMPOSIO_CACHE_DIR: ' /tmp/composio-cache ',
61 COMPOSIO_SESSION_DIR: ' ',
62 COMPOSIO_BIN_DIR: '/usr/local/bin',
63 COMPOSIO_LOG_LEVEL: 'Info',
64 COMPOSIO_ORG_ID: 'org_1',
65 COMPOSIO_PROJECT_ID: 'proj_1',
66 COMPOSIO_AGENTS_BASE_URL: 'https://agents.localhost',
67 COMPOSIO_WEBHOOK_SECRET: 'secret',
68 COMPOSIO_CLI_INVOCATION_ORIGIN: 'run',
69 COMPOSIO_CLI_PARENT_RUN_ID: 'run_parent',
70 COMPOSIO_RUN_OUTPUT_DIR: '\t/tmp/composio-output\n',
71 COMPOSIO_RUN_STAGED_FILES_FILE: '/tmp/composio-output/metadata.json',
72 COMPOSIO_DISABLE_CONNECTED_ACCOUNT_CACHE: 'OFF',
73 COMPOSIO_TOOLKIT_VERSION_GMAIL: '20250901_00',
74 });
75 deepStrictEqual(actual, {
76 USER_API_KEY: 'api_key',
77 ENVIRONMENT: undefined,
78 BASE_URL: 'https://test.localhost',
79 WEB_URL: 'https://web.localhost',
80 BACKEND: {
81 baseURL: 'https://test.localhost',
82 webURL: 'https://web.localhost',
83 selectedBy: Option.some('COMPOSIO_BASE_URL' as const),
84 webURLSet: true,
85 },
86 CACHE_DIR: '/tmp/composio-cache',
87 SESSION_DIR: undefined,
88 BIN_DIR: '/usr/local/bin',
89 LOG_LEVEL: 'Info',
90 ORG_ID: 'org_1',
91 PROJECT_ID: 'proj_1',
92 AGENTS_BASE_URL: 'https://agents.localhost',
93 WEBHOOK_SECRET: 'secret',
94 CLI_INVOCATION_ORIGIN: 'run',
95 CLI_PARENT_RUN_ID: 'run_parent',
96 RUN_OUTPUT_DIR: '/tmp/composio-output',
97 RUN_STAGED_FILES_FILE: '/tmp/composio-output/metadata.json',
98 DISABLE_CONNECTED_ACCOUNT_CACHE: false,
99 TOOLKIT_VERSIONS: Option.some({ GMAIL: '20250901_00' }),
100 });
101 })
102 );
103
104 it.effect('[Given] COMPOSIO_ENVIRONMENT [Then] it picks the URL defaults', () =>
105 Effect.gen(function* () {
106 deepStrictEqual(yield* read(urls, { COMPOSIO_ENVIRONMENT: 'staging' }), {
107 base: constants.STAGING_BASE_URL,
108 web: constants.STAGING_WEB_URL,
109 });
110 deepStrictEqual(yield* read(urls, { COMPOSIO_ENVIRONMENT: 'production' }), {
111 base: constants.DEFAULT_BASE_URL,
112 web: constants.DEFAULT_WEB_URL,
113 });
114 deepStrictEqual(yield* read(urls, { COMPOSIO_ENVIRONMENT: 'unknown' }), {
115 base: constants.DEFAULT_BASE_URL,
116 web: constants.DEFAULT_WEB_URL,
117 });
118 })
119 );
120
121 it.effect('[Given] an explicit URL [Then] it beats the COMPOSIO_ENVIRONMENT default', () =>
122 Effect.gen(function* () {
123 deepStrictEqual(
124 yield* read(urls, {
125 COMPOSIO_ENVIRONMENT: 'staging',
126 COMPOSIO_BASE_URL: 'https://custom-backend.localhost',
127 }),
128 { base: 'https://custom-backend.localhost', web: constants.STAGING_WEB_URL }
129 );
130 deepStrictEqual(
131 yield* read(urls, {
132 COMPOSIO_ENVIRONMENT: 'staging',
133 COMPOSIO_WEB_URL: 'https://custom-web.localhost',
134 }),
135 { base: constants.STAGING_BASE_URL, web: 'https://custom-web.localhost' }
136 );
137 })
138 );
139 });