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 path from 'node:path'; |
| 2 | import * as tempy from 'tempy'; |
| 3 | import fs from 'node:fs'; |
| 4 | import { describe, it, vi } from '@effect/vitest'; |
| 5 | import { assertEquals } from '@effect/vitest/utils'; |
| 6 | import * as FileSystem from 'effect/FileSystem'; |
| 7 | import * as BunFileSystem from '@effect/platform-bun/BunFileSystem'; |
| 8 | import * as BunPath from '@effect/platform-bun/BunPath'; |
| 9 | import { ConfigProvider, Effect, Layer } from 'effect'; |
| 10 | import { defaultNodeOs, NodeOs } from 'src/services/node-os'; |
| 11 | import { ComposioCliUserConfig, ComposioCliUserConfigLive } from 'src/services/cli-user-config'; |
| 12 | |
| 13 | describe('ComposioCliUserConfig', () => { |
| 14 | const withMapConfigProvider = (map: Map<string, string>) => |
| 15 | Layer.succeed( |
| 16 | ConfigProvider.ConfigProvider, |
| 17 | ConfigProvider.fromEnv({ env: Object.fromEntries(map) }) |
| 18 | ); |
| 19 | |
| 20 | it.effect('defaults experimental features off in stable releases', () => { |
| 21 | const cwd = tempy.temporaryDirectory(); |
| 22 | const map = new Map([['DEBUG_OVERRIDE_VERSION', '1.2.3']]) satisfies Map<string, string>; |
| 23 | const NodeOsTest = Layer.succeed(NodeOs, defaultNodeOs({ homedir: cwd })); |
| 24 | const CliUserConfigTest = Layer.provideMerge( |
| 25 | ComposioCliUserConfigLive, |
| 26 | Layer.mergeAll(BunFileSystem.layer, BunPath.layer, NodeOsTest, withMapConfigProvider(map)) |
| 27 | ); |
| 28 | |
| 29 | return Effect.gen(function* () { |
| 30 | const config = yield* ComposioCliUserConfig; |
| 31 | assertEquals(config.channel, 'stable'); |
| 32 | assertEquals(config.data.developerModeEnabled, true); |
| 33 | assertEquals(config.data.developerDangerousCommandsEnabled, false); |
| 34 | assertEquals(config.data.experimentalFeatures.listen, undefined); |
| 35 | assertEquals(config.isExperimentalFeatureEnabled('listen'), false); |
| 36 | assertEquals(config.data.artifactDirectory, undefined); |
| 37 | |
| 38 | const fs = yield* FileSystem.FileSystem; |
| 39 | assertEquals(yield* fs.exists(path.join(cwd, '.composio', 'config.json')), true); |
| 40 | }).pipe(Effect.provide(CliUserConfigTest)); |
| 41 | }); |
| 42 | |
| 43 | it.effect('uses installed beta release metadata for experimental defaults', () => { |
| 44 | const cwd = tempy.temporaryDirectory(); |
| 45 | const installDir = tempy.temporaryDirectory(); |
| 46 | const fakeExecPath = path.join(installDir, 'composio'); |
| 47 | fs.writeFileSync(fakeExecPath, 'fake binary'); |
| 48 | fs.writeFileSync(path.join(installDir, 'release-tag.txt'), '@composio/cli@1.2.4-beta.5\n'); |
| 49 | const execPathSpy = vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath); |
| 50 | const map = new Map() satisfies Map<string, string>; |
| 51 | const NodeOsTest = Layer.succeed(NodeOs, defaultNodeOs({ homedir: cwd })); |
| 52 | const CliUserConfigTest = Layer.provideMerge( |
| 53 | ComposioCliUserConfigLive, |
| 54 | Layer.mergeAll(BunFileSystem.layer, BunPath.layer, NodeOsTest, withMapConfigProvider(map)) |
| 55 | ); |
| 56 | |
| 57 | return Effect.gen(function* () { |
| 58 | const config = yield* ComposioCliUserConfig; |
| 59 | assertEquals(config.channel, 'beta'); |
| 60 | assertEquals(config.isExperimentalFeatureEnabled('listen'), true); |
| 61 | }).pipe( |
| 62 | Effect.provide(CliUserConfigTest), |
| 63 | Effect.ensuring(Effect.sync(() => execPathSpy.mockRestore())) |
| 64 | ); |
| 65 | }); |
| 66 | |
| 67 | it.effect('defaults experimental features on in beta releases', () => { |
| 68 | const cwd = tempy.temporaryDirectory(); |
| 69 | const map = new Map([['DEBUG_OVERRIDE_VERSION', '1.2.3-beta.4']]) satisfies Map<string, string>; |
| 70 | const NodeOsTest = Layer.succeed(NodeOs, defaultNodeOs({ homedir: cwd })); |
| 71 | const CliUserConfigTest = Layer.provideMerge( |
| 72 | ComposioCliUserConfigLive, |
| 73 | Layer.mergeAll(BunFileSystem.layer, BunPath.layer, NodeOsTest, withMapConfigProvider(map)) |
| 74 | ); |
| 75 | |
| 76 | return Effect.gen(function* () { |
| 77 | const config = yield* ComposioCliUserConfig; |
| 78 | assertEquals(config.channel, 'beta'); |
| 79 | assertEquals(config.data.developerModeEnabled, true); |
| 80 | assertEquals(config.data.developerDangerousCommandsEnabled, false); |
| 81 | assertEquals(config.data.experimentalFeatures.listen, undefined); |
| 82 | assertEquals(config.isExperimentalFeatureEnabled('listen'), true); |
| 83 | }).pipe(Effect.provide(CliUserConfigTest)); |
| 84 | }); |
| 85 | |
| 86 | it.effect('respects explicit persisted cli settings from config.json', () => { |
| 87 | const cwd = tempy.temporaryDirectory(); |
| 88 | const map = new Map([['DEBUG_OVERRIDE_VERSION', '1.2.3-beta.4']]) satisfies Map<string, string>; |
| 89 | fs.mkdirSync(path.join(cwd, '.composio'), { recursive: true }); |
| 90 | fs.writeFileSync( |
| 91 | path.join(cwd, '.composio', 'config.json'), |
| 92 | JSON.stringify({ |
| 93 | developer: { |
| 94 | enabled: false, |
| 95 | destructive_actions: true, |
| 96 | }, |
| 97 | experimental_features: { |
| 98 | listen: false, |
| 99 | multi_account: false, |
| 100 | }, |
| 101 | artifact_directory: '/tmp/composio-artifacts', |
| 102 | }) |
| 103 | ); |
| 104 | |
| 105 | const NodeOsTest = Layer.succeed(NodeOs, defaultNodeOs({ homedir: cwd })); |
| 106 | const CliUserConfigTest = Layer.provideMerge( |
| 107 | ComposioCliUserConfigLive, |
| 108 | Layer.mergeAll(BunFileSystem.layer, BunPath.layer, NodeOsTest, withMapConfigProvider(map)) |
| 109 | ); |
| 110 | |
| 111 | return Effect.gen(function* () { |
| 112 | const fileSystem = yield* FileSystem.FileSystem; |
| 113 | const config = yield* ComposioCliUserConfig; |
| 114 | assertEquals(config.data.developerModeEnabled, false); |
| 115 | assertEquals(config.data.developerDangerousCommandsEnabled, true); |
| 116 | assertEquals(config.data.experimentalFeatures.listen, false); |
| 117 | assertEquals(config.isExperimentalFeatureEnabled('listen'), false); |
| 118 | assertEquals(config.data.experimentalFeatures.multi_account, false); |
| 119 | assertEquals(config.isExperimentalFeatureEnabled('multi_account'), false); |
| 120 | assertEquals(config.data.artifactDirectory, '/tmp/composio-artifacts'); |
| 121 | |
| 122 | const persisted = yield* fileSystem.readFileString( |
| 123 | path.join(cwd, '.composio', 'config.json'), |
| 124 | 'utf8' |
| 125 | ); |
| 126 | const parsed = JSON.parse(persisted) as { |
| 127 | developer: { |
| 128 | enabled: boolean; |
| 129 | destructive_actions: boolean; |
| 130 | }; |
| 131 | experimental_features: { listen: boolean; multi_account: boolean }; |
| 132 | artifact_directory: string; |
| 133 | }; |
| 134 | |
| 135 | assertEquals(parsed.developer.enabled, false); |
| 136 | assertEquals(parsed.developer.destructive_actions, true); |
| 137 | assertEquals(parsed.experimental_features.listen, false); |
| 138 | assertEquals(parsed.experimental_features.multi_account, false); |
| 139 | assertEquals(parsed.artifact_directory, '/tmp/composio-artifacts'); |
| 140 | }).pipe(Effect.provide(CliUserConfigTest)); |
| 141 | }); |
| 142 | |
| 143 | it.effect('loads legacy flat developer keys and persists nested developer config', () => { |
| 144 | const cwd = tempy.temporaryDirectory(); |
| 145 | const map = new Map([['DEBUG_OVERRIDE_VERSION', '1.2.3-beta.4']]) satisfies Map<string, string>; |
| 146 | fs.mkdirSync(path.join(cwd, '.composio'), { recursive: true }); |
| 147 | fs.writeFileSync( |
| 148 | path.join(cwd, '.composio', 'config.json'), |
| 149 | JSON.stringify({ |
| 150 | developer_mode_enabled: false, |
| 151 | developer_dangerous_commands_enabled: true, |
| 152 | }) |
| 153 | ); |
| 154 | |
| 155 | const NodeOsTest = Layer.succeed(NodeOs, defaultNodeOs({ homedir: cwd })); |
| 156 | const CliUserConfigTest = Layer.provideMerge( |
| 157 | ComposioCliUserConfigLive, |
| 158 | Layer.mergeAll(BunFileSystem.layer, BunPath.layer, NodeOsTest, withMapConfigProvider(map)) |
| 159 | ); |
| 160 | |
| 161 | return Effect.gen(function* () { |
| 162 | const fileSystem = yield* FileSystem.FileSystem; |
| 163 | const config = yield* ComposioCliUserConfig; |
| 164 | assertEquals(config.data.developerModeEnabled, false); |
| 165 | assertEquals(config.data.developerDangerousCommandsEnabled, true); |
| 166 | |
| 167 | yield* config.update({ |
| 168 | developer: { |
| 169 | ...config.raw.developer, |
| 170 | enabled: true, |
| 171 | }, |
| 172 | }); |
| 173 | |
| 174 | const persisted = yield* fileSystem.readFileString( |
| 175 | path.join(cwd, '.composio', 'config.json'), |
| 176 | 'utf8' |
| 177 | ); |
| 178 | const parsed = JSON.parse(persisted) as { |
| 179 | developer: { |
| 180 | enabled: boolean; |
| 181 | destructive_actions: boolean; |
| 182 | }; |
| 183 | developer_mode_enabled?: boolean; |
| 184 | developer_dangerous_commands_enabled?: boolean; |
| 185 | }; |
| 186 | |
| 187 | assertEquals(parsed.developer.enabled, true); |
| 188 | assertEquals(parsed.developer.destructive_actions, true); |
| 189 | assertEquals(parsed.developer_mode_enabled, undefined); |
| 190 | assertEquals(parsed.developer_dangerous_commands_enabled, undefined); |
| 191 | }).pipe(Effect.provide(CliUserConfigTest)); |
| 192 | }); |
| 193 | |
| 194 | it.effect('preserves unknown settings across read-modify-write updates', () => { |
| 195 | const cwd = tempy.temporaryDirectory(); |
| 196 | const map = new Map([['DEBUG_OVERRIDE_VERSION', '1.2.3']]) satisfies Map<string, string>; |
| 197 | fs.mkdirSync(path.join(cwd, '.composio'), { recursive: true }); |
| 198 | fs.writeFileSync( |
| 199 | path.join(cwd, '.composio', 'config.json'), |
| 200 | JSON.stringify({ |
| 201 | future_setting: { |
| 202 | enabled: true, |
| 203 | modes: ['fast', 'safe'], |
| 204 | }, |
| 205 | }) |
| 206 | ); |
| 207 | |
| 208 | const NodeOsTest = Layer.succeed(NodeOs, defaultNodeOs({ homedir: cwd })); |
| 209 | const CliUserConfigTest = Layer.provideMerge( |
| 210 | ComposioCliUserConfigLive, |
| 211 | Layer.mergeAll(BunFileSystem.layer, BunPath.layer, NodeOsTest, withMapConfigProvider(map)) |
| 212 | ); |
| 213 | |
| 214 | return Effect.gen(function* () { |
| 215 | const fileSystem = yield* FileSystem.FileSystem; |
| 216 | const config = yield* ComposioCliUserConfig; |
| 217 | |
| 218 | yield* config.update({ security: 'json' }); |
| 219 | |
| 220 | const persisted = yield* fileSystem.readFileString( |
| 221 | path.join(cwd, '.composio', 'config.json'), |
| 222 | 'utf8' |
| 223 | ); |
| 224 | const parsed = JSON.parse(persisted) as { |
| 225 | security: string; |
| 226 | future_setting: { enabled: boolean; modes: Array<string> }; |
| 227 | }; |
| 228 | |
| 229 | assertEquals(parsed.security, 'json'); |
| 230 | assertEquals(parsed.future_setting, { |
| 231 | enabled: true, |
| 232 | modes: ['fast', 'safe'], |
| 233 | }); |
| 234 | }).pipe(Effect.provide(CliUserConfigTest)); |
| 235 | }); |
| 236 | |
| 237 | it.effect.each([{ storedSubagent: { target: 'gemini' } }, { storedSubagent: null }])( |
| 238 | 'ignores a stored experimental_subagent of $storedSubagent and writes it back unchanged', |
| 239 | ({ storedSubagent }) => { |
| 240 | const cwd = tempy.temporaryDirectory(); |
| 241 | const map = new Map([['DEBUG_OVERRIDE_VERSION', '1.2.3']]) satisfies Map<string, string>; |
| 242 | fs.mkdirSync(path.join(cwd, '.composio'), { recursive: true }); |
| 243 | fs.writeFileSync( |
| 244 | path.join(cwd, '.composio', 'config.json'), |
| 245 | JSON.stringify({ |
| 246 | developer: { enabled: false, destructive_actions: true }, |
| 247 | experimental_subagent: storedSubagent, |
| 248 | security: 'json', |
| 249 | }) |
| 250 | ); |
| 251 | |
| 252 | const NodeOsTest = Layer.succeed(NodeOs, defaultNodeOs({ homedir: cwd })); |
| 253 | const CliUserConfigTest = Layer.provideMerge( |
| 254 | ComposioCliUserConfigLive, |
| 255 | Layer.mergeAll(BunFileSystem.layer, BunPath.layer, NodeOsTest, withMapConfigProvider(map)) |
| 256 | ); |
| 257 | |
| 258 | return Effect.gen(function* () { |
| 259 | const fileSystem = yield* FileSystem.FileSystem; |
| 260 | const config = yield* ComposioCliUserConfig; |
| 261 | assertEquals(config.data.developerModeEnabled, false); |
| 262 | assertEquals(config.data.developerDangerousCommandsEnabled, true); |
| 263 | assertEquals(config.data.security, 'json'); |
| 264 | |
| 265 | yield* config.update({ experimentalFeatures: { listen: true } }); |
| 266 | |
| 267 | const persisted = yield* fileSystem.readFileString( |
| 268 | path.join(cwd, '.composio', 'config.json'), |
| 269 | 'utf8' |
| 270 | ); |
| 271 | const parsed = JSON.parse(persisted) as Record<string, unknown>; |
| 272 | |
| 273 | assertEquals(parsed.developer, { enabled: false, destructive_actions: true }); |
| 274 | assertEquals(parsed.security, 'json'); |
| 275 | assertEquals(parsed.experimental_features, { listen: true }); |
| 276 | assertEquals('experimental_subagent' in parsed, true); |
| 277 | assertEquals(parsed.experimental_subagent, storedSubagent); |
| 278 | }).pipe(Effect.provide(CliUserConfigTest)); |
| 279 | } |
| 280 | ); |
| 281 | |
| 282 | it.effect('replaces malformed persisted config with safe defaults', () => { |
| 283 | const cwd = tempy.temporaryDirectory(); |
| 284 | const map = new Map([['DEBUG_OVERRIDE_VERSION', '1.2.3']]) satisfies Map<string, string>; |
| 285 | fs.mkdirSync(path.join(cwd, '.composio'), { recursive: true }); |
| 286 | fs.writeFileSync(path.join(cwd, '.composio', 'config.json'), JSON.stringify(['not-an-object'])); |
| 287 | |
| 288 | const NodeOsTest = Layer.succeed(NodeOs, defaultNodeOs({ homedir: cwd })); |
| 289 | const CliUserConfigTest = Layer.provideMerge( |
| 290 | ComposioCliUserConfigLive, |
| 291 | Layer.mergeAll(BunFileSystem.layer, BunPath.layer, NodeOsTest, withMapConfigProvider(map)) |
| 292 | ); |
| 293 | |
| 294 | return Effect.gen(function* () { |
| 295 | const config = yield* ComposioCliUserConfig; |
| 296 | assertEquals(config.data.developerModeEnabled, true); |
| 297 | assertEquals(config.data.developerDangerousCommandsEnabled, false); |
| 298 | assertEquals(config.data.security, 'auto'); |
| 299 | |
| 300 | const persisted = fs.readFileSync(path.join(cwd, '.composio', 'config.json'), 'utf8'); |
| 301 | assertEquals(Array.isArray(JSON.parse(persisted)), false); |
| 302 | }).pipe(Effect.provide(CliUserConfigTest)); |
| 303 | }); |
| 304 | }); |