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 { afterEach, describe, expect, it, vi } from 'vitest'; |
| 2 | |
| 3 | const platformMock = vi.hoisted(() => ({ |
| 4 | supportsFileSystem: false, |
| 5 | homedir: vi.fn(() => null), |
| 6 | joinPath: vi.fn((...segments: string[]) => segments.join('/')), |
| 7 | readFileSync: vi.fn(() => { |
| 8 | throw new Error('File system operations are not supported in this runtime environment'); |
| 9 | }), |
| 10 | })); |
| 11 | |
| 12 | vi.mock('#platform', () => ({ platform: platformMock })); |
| 13 | |
| 14 | import { getSDKConfig } from '../../src/utils/sdk'; |
| 15 | import { ComposioNoAPIKeyError } from '../../src/errors/SDKErrors'; |
| 16 | |
| 17 | describe('getSDKConfig on edge runtimes', () => { |
| 18 | afterEach(() => { |
| 19 | vi.unstubAllEnvs(); |
| 20 | vi.clearAllMocks(); |
| 21 | }); |
| 22 | |
| 23 | it('never touches file system APIs when resolving an omitted key', () => { |
| 24 | vi.stubEnv('COMPOSIO_API_KEY', 'ak_envKeyValue'); |
| 25 | |
| 26 | expect(getSDKConfig().apiKey).toBe('ak_envKeyValue'); |
| 27 | expect(platformMock.homedir).not.toHaveBeenCalled(); |
| 28 | expect(platformMock.readFileSync).not.toHaveBeenCalled(); |
| 29 | }); |
| 30 | |
| 31 | it('throws the no-key error without touching file system APIs', () => { |
| 32 | vi.stubEnv('COMPOSIO_API_KEY', undefined); |
| 33 | |
| 34 | expect(() => getSDKConfig()).toThrow(ComposioNoAPIKeyError); |
| 35 | expect(platformMock.homedir).not.toHaveBeenCalled(); |
| 36 | expect(platformMock.readFileSync).not.toHaveBeenCalled(); |
| 37 | }); |
| 38 | |
| 39 | it('never touches file system APIs when the project key is disabled', () => { |
| 40 | vi.stubEnv('COMPOSIO_API_KEY', 'ak_envKeyValue'); |
| 41 | |
| 42 | expect( |
| 43 | getSDKConfig('https://explicit.example.com', null, { userApiKey: 'uak_userKeyValue' }) |
| 44 | ).toEqual({ baseURL: 'https://explicit.example.com', apiKey: null }); |
| 45 | expect(platformMock.homedir).not.toHaveBeenCalled(); |
| 46 | expect(platformMock.readFileSync).not.toHaveBeenCalled(); |
| 47 | }); |
| 48 | }); |