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 { ConfigProvider, Effect } from 'effect'; |
| 3 | import * as Path from 'effect/Path'; |
| 4 | import * as tempy from 'tempy'; |
| 5 | import { NodeOs } from 'src/services/node-os'; |
| 6 | import { cli, MockConsole, TestLive } from 'test/__utils__'; |
| 7 | |
| 8 | const sessionRoot = tempy.temporaryDirectory(); |
| 9 | |
| 10 | describe('CLI: composio artifacts cwd', () => { |
| 11 | layer( |
| 12 | TestLive({ |
| 13 | baseConfigProvider: ConfigProvider.fromEnvRecord({ COMPOSIO_SESSION_DIR: sessionRoot }), |
| 14 | }) |
| 15 | )('[Given] no CLI session for the cwd and `COMPOSIO_SESSION_DIR`', it => { |
| 16 | it.effect('[Then] prints the artifacts root on stdout', () => |
| 17 | Effect.gen(function* () { |
| 18 | yield* cli(['artifacts', 'cwd']); |
| 19 | |
| 20 | expect(yield* MockConsole.getLines({ stream: 'stdout' })).toEqual([sessionRoot]); |
| 21 | expect(yield* MockConsole.getLines({ stream: 'stderr' })).toEqual([]); |
| 22 | }) |
| 23 | ); |
| 24 | }); |
| 25 | |
| 26 | layer(TestLive())('[Given] no CLI session and no configured root', it => { |
| 27 | it.effect('[Then] prints `composio` under the temporary directory', () => |
| 28 | Effect.gen(function* () { |
| 29 | const path = yield* Path.Path; |
| 30 | const os = yield* NodeOs; |
| 31 | yield* cli(['artifacts', 'cwd']); |
| 32 | |
| 33 | expect(yield* MockConsole.getLines({ stream: 'stdout' })).toEqual([ |
| 34 | path.join(os.tmpdir, 'composio'), |
| 35 | ]); |
| 36 | }) |
| 37 | ); |
| 38 | }); |
| 39 | |
| 40 | layer( |
| 41 | TestLive({ |
| 42 | // The fixture stores a login with a current org, so the consumer scope resolves and a |
| 43 | // session is bound to the cwd. |
| 44 | fixture: 'user-config-with-global-context', |
| 45 | baseConfigProvider: ConfigProvider.fromEnvRecord({ |
| 46 | COMPOSIO_SESSION_DIR: sessionRoot, |
| 47 | COMPOSIO_DISABLE_CONNECTED_ACCOUNT_CACHE: 'false', |
| 48 | }), |
| 49 | }) |
| 50 | )('[Given] a CLI session bound to the cwd', it => { |
| 51 | it.effect('[Then] prints that session directory under the artifacts root', () => |
| 52 | Effect.gen(function* () { |
| 53 | const path = yield* Path.Path; |
| 54 | yield* cli(['artifacts', 'cwd']); |
| 55 | |
| 56 | const [directoryPath] = yield* MockConsole.getLines({ stream: 'stdout' }); |
| 57 | expect(path.dirname(directoryPath ?? '')).toBe(sessionRoot); |
| 58 | expect(path.basename(directoryPath ?? '')).toMatch(/^cli_s_[a-z0-9]+_[a-f0-9]{10}$/i); |
| 59 | }) |
| 60 | ); |
| 61 | }); |
| 62 | }); |