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 | /** |
| 2 | * E2E fixture: session.update() with default options against the live API. |
| 3 | * |
| 4 | * Reproduces the @composio/core 0.20.0 regression: update() sent |
| 5 | * `expected_config_version` on every call, and the API rejected the field with |
| 6 | * a 400, so no default update could succeed. Mocked unit tests could not see |
| 7 | * this because they never reach the API's payload validation. |
| 8 | * |
| 9 | * Requires COMPOSIO_API_KEY in environment. |
| 10 | */ |
| 11 | import { Composio } from '@composio/core'; |
| 12 | |
| 13 | const apiKey = process.env.COMPOSIO_API_KEY; |
| 14 | if (!apiKey) { |
| 15 | console.error('COMPOSIO_API_KEY is required'); |
| 16 | process.exit(1); |
| 17 | } |
| 18 | |
| 19 | const composio = new Composio({ apiKey }); |
| 20 | |
| 21 | const toolkitsOf = config => JSON.stringify(config.toolkits); |
| 22 | |
| 23 | async function main() { |
| 24 | const userId = `e2e-tool-router-session-update-${Date.now()}`; |
| 25 | const session = await composio.sessions.create(userId, { toolkits: ['github', 'gmail'] }); |
| 26 | |
| 27 | try { |
| 28 | const versionBefore = session.configVersion; |
| 29 | if (typeof versionBefore !== 'number') { |
| 30 | throw new Error(`expected a numeric configVersion after create, got ${versionBefore}`); |
| 31 | } |
| 32 | console.log('CREATE_OK'); |
| 33 | |
| 34 | // Default options: no precondition, so this must succeed on any project. |
| 35 | const config = await session.update({ toolkits: ['github'] }); |
| 36 | const expected = JSON.stringify({ enabled: ['github'] }); |
| 37 | if (toolkitsOf(config) !== expected) { |
| 38 | throw new Error(`update returned toolkits ${toolkitsOf(config)}, expected ${expected}`); |
| 39 | } |
| 40 | if (!(session.configVersion > versionBefore)) { |
| 41 | throw new Error( |
| 42 | `configVersion did not advance: ${versionBefore} -> ${session.configVersion}` |
| 43 | ); |
| 44 | } |
| 45 | console.log('UPDATE_OK'); |
| 46 | |
| 47 | const reread = await composio.sessions.use(session.sessionId); |
| 48 | if (toolkitsOf(reread.config) !== expected) { |
| 49 | throw new Error(`server kept toolkits ${toolkitsOf(reread.config)}, expected ${expected}`); |
| 50 | } |
| 51 | if (reread.configVersion !== session.configVersion) { |
| 52 | throw new Error( |
| 53 | `server configVersion ${reread.configVersion} != local ${session.configVersion}` |
| 54 | ); |
| 55 | } |
| 56 | console.log('PERSISTED_OK'); |
| 57 | } finally { |
| 58 | await composio.sessions.delete(session.sessionId); |
| 59 | console.log('DELETE_OK'); |
| 60 | } |
| 61 | |
| 62 | console.log('ALL_OK'); |
| 63 | } |
| 64 | |
| 65 | main().catch(err => { |
| 66 | console.log('ERROR:', err?.message || err); |
| 67 | process.exit(1); |
| 68 | }); |