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
| 1 | // Import the BunFileSystem submodule directly (as a namespace, matching its own named export |
| 2 | // shape); the package's barrel (`@effect/platform-bun`) unconditionally re-exports BunRedis, |
| 3 | // which imports the `bun` builtin at module scope and crashes Node's ESM resolver (vitest runs |
| 4 | // under Node, not Bun). |
| 5 | import * as BunFileSystem from '@effect/platform-bun/BunFileSystem'; |
| 6 | import { Effect, FileSystem } from 'effect'; |
| 7 | import { afterEach, beforeEach, vi } from 'vitest'; |
| 8 | import { clearInProcessMemos } from 'src/utils/memoize-in-process'; |
| 9 | |
| 10 | // Point every test at a fresh, empty config directory so nothing reads or |
| 11 | // writes the developer's real `~/.composio`. An empty directory holds no |
| 12 | // permission snapshot, so the tool-permission gate resolves to 'skip' instead |
| 13 | // of spawning the native approval dialog / browser prompt from the developer's |
| 14 | // real enhanced-controls state. Tests that need a specific directory stub |
| 15 | // COMPOSIO_CACHE_DIR themselves; stubs applied inside a test win over this one. |
| 16 | let testConfigDirectory: string | undefined; |
| 17 | |
| 18 | const runFs = <A, E>(effect: Effect.Effect<A, E, FileSystem.FileSystem>): Promise<A> => |
| 19 | Effect.runPromise(effect.pipe(Effect.provide(BunFileSystem.layer))); |
| 20 | |
| 21 | // Process-lifetime memos (tool versions, connected-account lists) would |
| 22 | // otherwise carry one case's mocked answer into the next. |
| 23 | beforeEach(clearInProcessMemos); |
| 24 | |
| 25 | beforeEach(async () => { |
| 26 | testConfigDirectory = await runFs( |
| 27 | Effect.flatMap(FileSystem.FileSystem, fs => |
| 28 | fs.makeTempDirectory({ prefix: 'composio-cli-test-config-' }) |
| 29 | ) |
| 30 | ); |
| 31 | vi.stubEnv('COMPOSIO_CACHE_DIR', testConfigDirectory); |
| 32 | }); |
| 33 | |
| 34 | afterEach(async () => { |
| 35 | const directory = testConfigDirectory; |
| 36 | testConfigDirectory = undefined; |
| 37 | if (directory) { |
| 38 | await runFs( |
| 39 | Effect.flatMap(FileSystem.FileSystem, fs => |
| 40 | fs.remove(directory, { recursive: true, force: true }) |
| 41 | ) |
| 42 | ); |
| 43 | } |
| 44 | }); |