1
-import { describe, expect, it } from '@effect/vitest';
2
-import { deepStrictEqual } from '@effect/vitest/utils';
3
-
4
-import { Config, ConfigProvider, Effect, Option } from 'effect';
5
-import { APP_CONFIG, UNPREFIXED_CONFIG } from 'src/effects/app-config';
6
-import { extendConfigProvider } from 'src/services/config';
7
-import { DEBUG_OVERRIDE_CONFIG } from 'src/effects/debug-config';
8
-import * as constants from 'src/constants';
9
-
10
-const NORMALIZED_APP_CONFIG_DEFAULTS = {
11
- CACHE_DIR: undefined,
12
- SESSION_DIR: undefined,
13
- BIN_DIR: undefined,
14
- AGENTS_BASE_URL: undefined,
15
- WEBHOOK_SECRET: undefined,
16
- CLI_INVOCATION_ORIGIN: undefined,
17
- CLI_PARENT_RUN_ID: undefined,
18
- RUN_OUTPUT_DIR: undefined,
19
- PERF_DEBUG: false,
20
- TOOL_DEBUG: false,
21
-};
22
-
23
-describe('Config', () => {
24
- describe('[When] using `ConfigProvider.fromMap`', () => {
25
- const withMapConfigProvider = (map: Map<string, string>) =>
26
- Effect.provideService(
27
- ConfigProvider.ConfigProvider,
28
- extendConfigProvider(ConfigProvider.fromEnvRecord(Object.fromEntries(map)))
29
- );
30
-
31
- describe('APP_CONFIG', () => {
32
- it.effect('[When] no map entry is set', () =>
33
- Effect.gen(function* () {
34
- const map = new Map([]) satisfies Map<string, string>;
35
-
36
- const actual = yield* withMapConfigProvider(map)(Config.all(APP_CONFIG));
37
-
38
- deepStrictEqual(actual, {
39
- USER_API_KEY: Option.none(),
40
- ...NORMALIZED_APP_CONFIG_DEFAULTS,
41
- ENVIRONMENT: Option.none(),
42
- BASE_URL: 'https://backend.composio.dev',
43
- LOG_LEVEL: Option.none(),
44
- ORG_ID: Option.none(),
45
- PROJECT_ID: Option.none(),
46
- DISABLE_CONNECTED_ACCOUNT_CACHE: true,
47
- WEB_URL: 'https://dashboard.composio.dev/',
48
- });
49
- })
50
- );
51
-
52
- it.effect('[When] map entries are set without `COMPOSIO_` prefix', () =>
53
- Effect.gen(function* () {
54
- const map = new Map([
55
- ['USER_API_KEY', 'api_key'],
56
- ['BASE_URL', 'https://test.localhost'],
57
- ['CACHE_DIR', '~/.composio'],
58
- ['LOG_LEVEL', 'info'],
59
- ]) satisfies Map<string, string>;
60
-
61
- const actual = yield* withMapConfigProvider(map)(Config.all(APP_CONFIG));
62
-
63
- deepStrictEqual(actual, {
64
- USER_API_KEY: Option.none(),
65
- ...NORMALIZED_APP_CONFIG_DEFAULTS,
66
- ENVIRONMENT: Option.none(),
67
- BASE_URL: 'https://backend.composio.dev',
68
- LOG_LEVEL: Option.none(),
69
- ORG_ID: Option.none(),
70
- PROJECT_ID: Option.none(),
71
- DISABLE_CONNECTED_ACCOUNT_CACHE: true,
72
- WEB_URL: 'https://dashboard.composio.dev/',
73
- });
74
- })
75
- );
76
-
77
- it.effect('[When] env variables are set with `COMPOSIO_` prefix', () =>
78
- Effect.gen(function* () {
79
- const map = new Map([
80
- ['COMPOSIO_USER_API_KEY', 'api_key'],
81
- ['COMPOSIO_BASE_URL', 'https://test.localhost'],
82
- ['COMPOSIO_WEB_URL', 'https://test.localhost'],
83
- ['COMPOSIO_CACHE_DIR', '~/.composio'],
84
- ['COMPOSIO_SESSION_DIR', '/tmp/composio-sessions'],
85
- ['COMPOSIO_BIN_DIR', '/usr/local/bin'],
86
- ['COMPOSIO_LOG_LEVEL', 'Info'],
87
- ['COMPOSIO_AGENTS_BASE_URL', 'https://agents.test.localhost'],
88
- ['COMPOSIO_WEBHOOK_SECRET', 'secret'],
89
- ['COMPOSIO_CLI_INVOCATION_ORIGIN', 'run'],
90
- ['COMPOSIO_CLI_PARENT_RUN_ID', 'run_parent'],
91
- ['COMPOSIO_RUN_ACP_ONLY', '1'],
92
- ['COMPOSIO_RUN_OUTPUT_DIR', '/tmp/composio-output'],
93
- ['COMPOSIO_PERF_DEBUG', '1'],
94
- ['COMPOSIO_TOOL_DEBUG', '1'],
95
- ]) satisfies Map<string, string>;
96
-
97
- const actual = yield* withMapConfigProvider(map)(Config.all(APP_CONFIG));
98
-
99
- deepStrictEqual(actual, {
100
- USER_API_KEY: Option.some('api_key'),
101
- ENVIRONMENT: Option.none(),
102
- BASE_URL: 'https://test.localhost',
103
- WEB_URL: 'https://test.localhost',
104
- CACHE_DIR: '~/.composio',
105
- SESSION_DIR: '/tmp/composio-sessions',
106
- BIN_DIR: '/usr/local/bin',
107
- LOG_LEVEL: Option.some('Info' as const),
108
- ORG_ID: Option.none(),
109
- PROJECT_ID: Option.none(),
110
- AGENTS_BASE_URL: 'https://agents.test.localhost',
111
- WEBHOOK_SECRET: 'secret',
112
- CLI_INVOCATION_ORIGIN: 'run',
113
- CLI_PARENT_RUN_ID: 'run_parent',
114
- RUN_OUTPUT_DIR: '/tmp/composio-output',
115
- PERF_DEBUG: true,
116
- TOOL_DEBUG: true,
117
- DISABLE_CONNECTED_ACCOUNT_CACHE: true,
118
- });
119
- })
120
- );
121
-
122
- it.effect('[When] optional directory values contain whitespace', () =>
123
- Effect.gen(function* () {
124
- const map = new Map([
125
- ['COMPOSIO_CACHE_DIR', ' /tmp/composio-cache '],
126
- ['COMPOSIO_SESSION_DIR', ' '],
127
- ['COMPOSIO_BIN_DIR', ' /usr/local/bin '],
128
- ['COMPOSIO_RUN_OUTPUT_DIR', '\t/tmp/composio-output\n'],
129
- ]) satisfies Map<string, string>;
130
-
131
- const actual = yield* withMapConfigProvider(map)(
132
- Config.all({
133
- cacheDirectory: APP_CONFIG.CACHE_DIR,
134
- sessionDirectory: APP_CONFIG.SESSION_DIR,
135
- binDirectory: APP_CONFIG.BIN_DIR,
136
- runOutputDirectory: APP_CONFIG.RUN_OUTPUT_DIR,
137
- })
138
- );
139
-
140
- deepStrictEqual(actual, {
141
- cacheDirectory: '/tmp/composio-cache',
142
- sessionDirectory: undefined,
143
- binDirectory: '/usr/local/bin',
144
- runOutputDirectory: '/tmp/composio-output',
145
- });
146
- })
147
- );
148
-
149
- it.effect('[When] boolean flags carry blank or unrecognized values', () =>
150
- Effect.gen(function* () {
151
- // These arrive from the ambient environment, where `COMPOSIO_PERF_DEBUG=` and
152
- // stray values are routine. They must resolve to a boolean rather than failing
153
- // config decoding, which would surface as an unrecoverable defect at the call site.
154
- const map = new Map([
155
- ['COMPOSIO_PERF_DEBUG', ''],
156
- ['COMPOSIO_TOOL_DEBUG', 'maybe'],
157
- ['COMPOSIO_DISABLE_CONNECTED_ACCOUNT_CACHE', ' '],
158
- ]) satisfies Map<string, string>;
159
-
160
- const actual = yield* withMapConfigProvider(map)(
161
- Config.all({
162
- perfDebug: APP_CONFIG.PERF_DEBUG,
163
- toolDebug: APP_CONFIG.TOOL_DEBUG,
164
- disableConnectedAccountCache: APP_CONFIG.DISABLE_CONNECTED_ACCOUNT_CACHE,
165
- })
166
- );
167
-
168
- deepStrictEqual(actual, {
169
- // Blank falls back to the flag's own default, ...
170
- perfDebug: false,
171
- // ... which must hold for a default-true flag too, ...
172
- disableConnectedAccountCache: true,
173
- // ... while any other non-falsy value counts as set.
174
- toolDebug: true,
175
- });
176
- })
177
- );
178
-
179
- it.effect('[When] boolean flags carry explicit falsy words', () =>
180
- Effect.gen(function* () {
181
- const map = new Map([
182
- ['COMPOSIO_PERF_DEBUG', '0'],
183
- ['COMPOSIO_TOOL_DEBUG', 'false'],
184
- ['COMPOSIO_DISABLE_CONNECTED_ACCOUNT_CACHE', 'OFF'],
185
- ]) satisfies Map<string, string>;
186
-
187
- const actual = yield* withMapConfigProvider(map)(
188
- Config.all({
189
- perfDebug: APP_CONFIG.PERF_DEBUG,
190
- toolDebug: APP_CONFIG.TOOL_DEBUG,
191
- disableConnectedAccountCache: APP_CONFIG.DISABLE_CONNECTED_ACCOUNT_CACHE,
192
- })
193
- );
194
-
195
- deepStrictEqual(actual, {
196
- perfDebug: false,
197
- toolDebug: false,
198
- disableConnectedAccountCache: false,
199
- });
200
- })
201
- );
202
-
203
- it.effect('[When] COMPOSIO_DISABLE_CONNECTED_ACCOUNT_CACHE is "false"', () =>
204
- Effect.gen(function* () {
205
- const map = new Map([
206
- ['COMPOSIO_DISABLE_CONNECTED_ACCOUNT_CACHE', 'false'],
207
- ]) satisfies Map<string, string>;
208
-
209
- const actual = yield* withMapConfigProvider(map)(Config.all(APP_CONFIG));
210
-
211
- deepStrictEqual(actual, {
212
- USER_API_KEY: Option.none(),
213
- ...NORMALIZED_APP_CONFIG_DEFAULTS,
214
- ENVIRONMENT: Option.none(),
215
- BASE_URL: 'https://backend.composio.dev',
216
- WEB_URL: 'https://dashboard.composio.dev/',
217
- LOG_LEVEL: Option.none(),
218
- ORG_ID: Option.none(),
219
- PROJECT_ID: Option.none(),
220
- DISABLE_CONNECTED_ACCOUNT_CACHE: false,
221
- });
222
- })
223
- );
224
-
225
- it.effect('[When] COMPOSIO_ENVIRONMENT is "production"', () =>
226
- Effect.gen(function* () {
227
- const map = new Map([['COMPOSIO_ENVIRONMENT', 'production']]) satisfies Map<
228
- string,
229
- string
230
- >;
231
-
232
- const actual = yield* withMapConfigProvider(map)(Config.all(APP_CONFIG));
233
-
234
- deepStrictEqual(actual, {
235
- USER_API_KEY: Option.none(),
236
- ...NORMALIZED_APP_CONFIG_DEFAULTS,
237
- ENVIRONMENT: Option.some('production'),
238
- BASE_URL: constants.DEFAULT_BASE_URL,
239
- WEB_URL: constants.DEFAULT_WEB_URL,
240
- LOG_LEVEL: Option.none(),
241
- ORG_ID: Option.none(),
242
- PROJECT_ID: Option.none(),
243
- DISABLE_CONNECTED_ACCOUNT_CACHE: true,
244
- });
245
- })
246
- );
247
-
248
- it.effect('[When] COMPOSIO_ENVIRONMENT is "staging"', () =>
249
- Effect.gen(function* () {
250
- const map = new Map([['COMPOSIO_ENVIRONMENT', 'staging']]) satisfies Map<string, string>;
251
-
252
- const actual = yield* withMapConfigProvider(map)(Config.all(APP_CONFIG));
253
-
254
- deepStrictEqual(actual, {
255
- USER_API_KEY: Option.none(),
256
- ...NORMALIZED_APP_CONFIG_DEFAULTS,
257
- ENVIRONMENT: Option.some('staging'),
258
- BASE_URL: constants.STAGING_BASE_URL,
259
- WEB_URL: 'https://staging-dashboard.composio.dev/',
260
- LOG_LEVEL: Option.none(),
261
- ORG_ID: Option.none(),
262
- PROJECT_ID: Option.none(),
263
- DISABLE_CONNECTED_ACCOUNT_CACHE: true,
264
- });
265
- })
266
- );
267
-
268
- it.effect(
269
- '[When] COMPOSIO_ENVIRONMENT is "staging" but explicit COMPOSIO_BASE_URL is set',
270
- () =>
271
- Effect.gen(function* () {
272
- const map = new Map([
273
- ['COMPOSIO_ENVIRONMENT', 'staging'],
274
- ['COMPOSIO_BASE_URL', 'https://custom-backend.localhost'],
275
- ]) satisfies Map<string, string>;
276
-
277
- const actual = yield* withMapConfigProvider(map)(Config.all(APP_CONFIG));
278
-
279
- deepStrictEqual(actual, {
280
- USER_API_KEY: Option.none(),
281
- ...NORMALIZED_APP_CONFIG_DEFAULTS,
282
- ENVIRONMENT: Option.some('staging'),
283
- BASE_URL: 'https://custom-backend.localhost',
284
- WEB_URL: constants.STAGING_WEB_URL,
285
- LOG_LEVEL: Option.none(),
286
- ORG_ID: Option.none(),
287
- PROJECT_ID: Option.none(),
288
- DISABLE_CONNECTED_ACCOUNT_CACHE: true,
289
- });
290
- })
291
- );
292
-
293
- it.effect(
294
- '[When] COMPOSIO_ENVIRONMENT is "staging" but explicit COMPOSIO_WEB_URL is set',
295
- () =>
296
- Effect.gen(function* () {
297
- const map = new Map([
298
- ['COMPOSIO_ENVIRONMENT', 'staging'],
299
- ['COMPOSIO_WEB_URL', 'https://custom-web.localhost'],
300
- ]) satisfies Map<string, string>;
301
-
302
- const actual = yield* withMapConfigProvider(map)(Config.all(APP_CONFIG));
303
-
304
- deepStrictEqual(actual, {
305
- USER_API_KEY: Option.none(),
306
- ...NORMALIZED_APP_CONFIG_DEFAULTS,
307
- ENVIRONMENT: Option.some('staging'),
308
- BASE_URL: constants.STAGING_BASE_URL,
309
- WEB_URL: 'https://custom-web.localhost',
310
- LOG_LEVEL: Option.none(),
311
- ORG_ID: Option.none(),
312
- PROJECT_ID: Option.none(),
313
- DISABLE_CONNECTED_ACCOUNT_CACHE: true,
314
- });
315
- })
316
- );
317
-
318
- it.effect('[When] COMPOSIO_ENVIRONMENT is an unknown value', () =>
319
- Effect.gen(function* () {
320
- const map = new Map([['COMPOSIO_ENVIRONMENT', 'unknown']]) satisfies Map<string, string>;
321
-
322
- const actual = yield* withMapConfigProvider(map)(Config.all(APP_CONFIG));
323
-
324
- deepStrictEqual(actual, {
325
- USER_API_KEY: Option.none(),
326
- ...NORMALIZED_APP_CONFIG_DEFAULTS,
327
- ENVIRONMENT: Option.some('unknown'),
328
- BASE_URL: constants.DEFAULT_BASE_URL,
329
- WEB_URL: constants.DEFAULT_WEB_URL,
330
- LOG_LEVEL: Option.none(),
331
- ORG_ID: Option.none(),
332
- PROJECT_ID: Option.none(),
333
- DISABLE_CONNECTED_ACCOUNT_CACHE: true,
334
- });
335
- })
336
- );
337
- });
338
-
339
- describe('DEBUG_OVERRIDE_CONFIG', () => {
340
- it.effect('[When] no map entries variable is set', () =>
341
- Effect.gen(function* () {
342
- const map = new Map([]) satisfies Map<string, string>;
343
-
344
- const actual = yield* withMapConfigProvider(map)(Config.all(DEBUG_OVERRIDE_CONFIG));
345
-
346
- deepStrictEqual(actual, {
347
- UPGRADE_TARGET: Option.none(),
348
- VERSION: Option.none(),
349
- });
350
- })
351
- );
352
-
353
- it.effect('[When] map entries are set without `DEBUG_OVERRIDE_` prefix', () =>
354
- Effect.gen(function* () {
355
- const map = new Map([
356
- ['UPGRADE_TARGET', 'upgrade_target'],
357
- ['VERSION', 'x.x.x'],
358
- ]) satisfies Map<string, string>;
359
-
360
- const actual = yield* withMapConfigProvider(map)(Config.all(DEBUG_OVERRIDE_CONFIG));
361
-
362
- deepStrictEqual(actual, {
363
- UPGRADE_TARGET: Option.none(),
364
- VERSION: Option.none(),
365
- });
366
- })
367
- );
368
-
369
- it.effect(
370
- '[When] map entries are set without `DEBUG_OVERRIDE_` but with `COMPOSIO_` prefix',
371
- () =>
372
- Effect.gen(function* () {
373
- const map = new Map([
374
- ['COMPOSIO_UPGRADE_TARGET', 'upgrade_target'],
375
- ['COMPOSIO_VERSION', 'x.x.x'],
376
- ]) satisfies Map<string, string>;
377
-
378
- const actual = yield* withMapConfigProvider(map)(Config.all(DEBUG_OVERRIDE_CONFIG));
379
-
380
- deepStrictEqual(actual, {
381
- UPGRADE_TARGET: Option.none(),
382
- VERSION: Option.none(),
383
- });
384
- })
385
- );
386
- it.effect('[When] map entries are set with `DEBUG_OVERRIDE_` prefix', () =>
387
- Effect.gen(function* () {
388
- const map = new Map([
389
- ['DEBUG_OVERRIDE_UPGRADE_TARGET', 'upgrade_target'],
390
- ['DEBUG_OVERRIDE_VERSION', 'x.x.x'],
391
- ]) satisfies Map<string, string>;
392
-
393
- const actual = yield* withMapConfigProvider(map)(Config.all(DEBUG_OVERRIDE_CONFIG));
394
-
395
- deepStrictEqual(actual, {
396
- UPGRADE_TARGET: Option.some('upgrade_target'),
397
- VERSION: Option.some('x.x.x'),
398
- });
399
- })
400
- );
401
- });
402
-
403
- describe('UNPREFIXED_CONFIG', () => {
404
- it.effect('[Then] it normalizes unprefixed host values into runtime facts', () =>
405
- Effect.gen(function* () {
406
- const provider = ConfigProvider.fromEnvRecord(
407
- Object.fromEntries([
408
- ['npm_config_user_agent', 'pnpm/9.0.0 npm/? node/v22.0.0 darwin arm64'],
409
- ['CI', ' TRUE '],
410
- ['NO_COLOR', '1'],
411
- ['COMPOSIO_CLI_TELEMETRY_DEBUG', 'true'],
412
- ['CODEX_FUTURE_MARKER', 'thread_test'],
413
- ['CLAUDE_FUTURE_MARKER', 'cli'],
414
- ['COMPOSIO_CALLER_AGENT', 'Open-Claw'],
415
- ['VITEST', 'off'],
416
- ])
417
- );
418
-
419
- const actual = yield* Config.all(UNPREFIXED_CONFIG).parse(provider);
420
-
421
- expect(actual).toEqual({
422
- NPM_CONFIG_USER_AGENT: 'pnpm/9.0.0 npm/? node/v22.0.0 darwin arm64',
423
- CI_REDACTION_ENABLED: true,
424
- INTERACTIVE_PERMISSION_UI_DISABLED: true,
425
- NO_COLOR: true,
426
- TELEMETRY_DEBUG: true,
427
- MASTER_SIGNALS: { codex: true, claude: true },
428
- CALLER_AGENT_SIGNALS: {
429
- explicit: 'Open-Claw',
430
- openclaw: false,
431
- claude: true,
432
- codex: true,
433
- },
434
- });
435
- })
436
- );
437
-
438
- it.effect('[Then] an explicit permission UI value overrides CI detection', () =>
439
- Effect.gen(function* () {
440
- const provider = ConfigProvider.fromEnvRecord(
441
- Object.fromEntries([
442
- ['COMPOSIO_DISABLE_PERMISSION_UI', 'false'],
443
- ['CI', 'true'],
444
- ['VITEST', 'true'],
445
- ])
446
- );
447
-
448
- deepStrictEqual(
449
- yield* UNPREFIXED_CONFIG.INTERACTIVE_PERMISSION_UI_DISABLED.parse(provider),
450
- false
451
- );
452
- })
453
- );
454
- });
455
- });
456
-});