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, 06:00 UTC
| 1 | import { describe, expect, it } from '@effect/vitest'; |
| 2 | import { ConfigProvider, Effect, Layer } from 'effect'; |
| 3 | import { runDebugWhoIsMyMaster } from 'src/commands/debug/who-is-my-master/debug.who-is-my-master.handler'; |
| 4 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 5 | import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test'; |
| 6 | |
| 7 | /** A headless terminal whose stdout data lands in `outputs`, over exactly `env`. */ |
| 8 | const masterTest = (env: Record<string, string>) => { |
| 9 | const outputs: Array<string> = []; |
| 10 | const layer = Layer.mergeAll( |
| 11 | Layer.succeed( |
| 12 | TerminalUI, |
| 13 | TerminalUI.of({ |
| 14 | ...terminalUITestImpl, |
| 15 | output: data => |
| 16 | Effect.sync(() => { |
| 17 | outputs.push(data); |
| 18 | }), |
| 19 | }) |
| 20 | ), |
| 21 | ConfigProvider.layer(ConfigProvider.fromEnvRecord(env)) |
| 22 | ); |
| 23 | return { layer, outputs }; |
| 24 | }; |
| 25 | |
| 26 | describe('runDebugWhoIsMyMaster', () => { |
| 27 | it.effect.each<{ |
| 28 | readonly name: string; |
| 29 | readonly env: Record<string, string>; |
| 30 | readonly master: string; |
| 31 | }>([ |
| 32 | { name: 'a CODEX_* variable', env: { CODEX_HOME: '/codex' }, master: 'codex' }, |
| 33 | { name: 'a CLAUDE_* variable', env: { CLAUDE_CODE_ENTRYPOINT: 'cli' }, master: 'claude' }, |
| 34 | { |
| 35 | name: 'both (Codex wins)', |
| 36 | env: { CODEX_HOME: '/codex', CLAUDE_CODE_ENTRYPOINT: 'cli' }, |
| 37 | master: 'codex', |
| 38 | }, |
| 39 | { name: 'neither', env: {}, master: 'user' }, |
| 40 | ])('[Given] $name [Then] prints `$master`', ({ env, master }) => { |
| 41 | const { layer, outputs } = masterTest(env); |
| 42 | return Effect.gen(function* () { |
| 43 | yield* runDebugWhoIsMyMaster(); |
| 44 | |
| 45 | expect(outputs).toEqual([JSON.stringify({ master }, null, 2)]); |
| 46 | }).pipe(Effect.provide(layer)); |
| 47 | }); |
| 48 | }); |