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 { describe, expect, it } from '@effect/vitest'; |
| 2 | import { Effect, Schema } from 'effect'; |
| 3 | import toolkitsJson from 'test/__mocks__/toolkits.json' with { type: 'json' }; |
| 4 | import { Toolkits, toolkitsFromJSON, toolkitsToJSON } from 'src/models/toolkits'; |
| 5 | |
| 6 | describe('ToolkitSlug', () => { |
| 7 | it.effect( |
| 8 | '[Given] cached toolkit data with underscore-prefixed slugs [Then] it decodes successfully', |
| 9 | Effect.fn(function* () { |
| 10 | const toolkits = yield* toolkitsFromJSON(JSON.stringify(toolkitsJson)); |
| 11 | |
| 12 | expect(toolkits.map(toolkit => toolkit.slug)).toEqual( |
| 13 | expect.arrayContaining(['_21risk', '_2chat']) |
| 14 | ); |
| 15 | }) |
| 16 | ); |
| 17 | }); |
| 18 | |
| 19 | describe('Toolkit', () => { |
| 20 | const meta = { |
| 21 | description: 'Project custom toolkit', |
| 22 | categories: [], |
| 23 | created_at: '2025-01-01T00:00:00.000Z', |
| 24 | updated_at: '2025-01-02T00:00:00.000Z', |
| 25 | logo: '', |
| 26 | tools_count: 2, |
| 27 | triggers_count: 0, |
| 28 | version: '20250101_00', |
| 29 | }; |
| 30 | |
| 31 | it.effect( |
| 32 | '[Given] a project custom toolkit without auth fields [Then] it decodes with empty auth defaults', |
| 33 | Effect.fn(function* () { |
| 34 | const [toolkit] = yield* Schema.decodeUnknownEffect(Toolkits)([ |
| 35 | { |
| 36 | slug: 'custom_grain', |
| 37 | name: 'Grain', |
| 38 | type: 'custom', |
| 39 | is_local_toolkit: false, |
| 40 | deprecated: false, |
| 41 | meta, |
| 42 | }, |
| 43 | ]); |
| 44 | |
| 45 | expect(toolkit.slug).toBe('custom_grain'); |
| 46 | expect(toolkit.auth_schemes).toEqual([]); |
| 47 | expect(toolkit.composio_managed_auth_schemes).toEqual([]); |
| 48 | expect(toolkit.no_auth).toBe(false); |
| 49 | }) |
| 50 | ); |
| 51 | |
| 52 | it.effect( |
| 53 | '[Given] a native toolkit with auth fields [Then] it keeps the provided values', |
| 54 | Effect.fn(function* () { |
| 55 | const [toolkit] = yield* Schema.decodeUnknownEffect(Toolkits)([ |
| 56 | { |
| 57 | slug: 'gmail', |
| 58 | name: 'Gmail', |
| 59 | is_local_toolkit: false, |
| 60 | auth_schemes: ['OAUTH2', 'BEARER_TOKEN'], |
| 61 | composio_managed_auth_schemes: ['OAUTH2'], |
| 62 | no_auth: true, |
| 63 | meta, |
| 64 | }, |
| 65 | ]); |
| 66 | |
| 67 | expect(toolkit.auth_schemes).toEqual(['OAUTH2', 'BEARER_TOKEN']); |
| 68 | expect(toolkit.composio_managed_auth_schemes).toEqual(['OAUTH2']); |
| 69 | expect(toolkit.no_auth).toBe(true); |
| 70 | }) |
| 71 | ); |
| 72 | |
| 73 | it.effect( |
| 74 | '[Given] decoded toolkits including a defaulted custom toolkit [Then] the JSON cache round-trip keeps values', |
| 75 | Effect.fn(function* () { |
| 76 | const toolkits = yield* Schema.decodeUnknownEffect(Toolkits)([ |
| 77 | { slug: 'custom_grain', name: 'Grain', is_local_toolkit: false, meta }, |
| 78 | { |
| 79 | slug: 'gmail', |
| 80 | name: 'Gmail', |
| 81 | is_local_toolkit: false, |
| 82 | auth_schemes: ['OAUTH2'], |
| 83 | composio_managed_auth_schemes: ['OAUTH2'], |
| 84 | no_auth: false, |
| 85 | meta, |
| 86 | }, |
| 87 | ]); |
| 88 | |
| 89 | const roundTripped = yield* toolkitsFromJSON(yield* toolkitsToJSON(toolkits)); |
| 90 | |
| 91 | expect(roundTripped).toEqual(toolkits); |
| 92 | expect(roundTripped[0]?.auth_schemes).toEqual([]); |
| 93 | expect(roundTripped[0]?.no_auth).toBe(false); |
| 94 | expect(roundTripped[1]?.auth_schemes).toEqual(['OAUTH2']); |
| 95 | }) |
| 96 | ); |
| 97 | }); |