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, test } from 'bun:test'; |
| 2 | import { |
| 3 | checkStrictConsumer, |
| 4 | npmInstallArgs, |
| 5 | pythonRequirement, |
| 6 | verifyPublishedProviders, |
| 7 | } from '../scripts/sdk-release/consumers'; |
| 8 | import { |
| 9 | makeExecutable, |
| 10 | readText, |
| 11 | resolvePath, |
| 12 | runRelease, |
| 13 | symlink, |
| 14 | temporaryDirectories, |
| 15 | writeText, |
| 16 | } from './sdk-release-harness'; |
| 17 | import { run, withoutReleaseTokens } from '../scripts/sdk-release/runtime'; |
| 18 | |
| 19 | const directories = temporaryDirectories('sdk-consumer-'); |
| 20 | afterEach(directories.cleanup); |
| 21 | |
| 22 | const release = (name: string, newVersion: string) => ({ name, newVersion }); |
| 23 | |
| 24 | describe('candidate package source', () => { |
| 25 | test('SDK packages install from candidate files, never by registry name', () => { |
| 26 | const args = npmInstallArgs( |
| 27 | '/work/sdk-candidate/typescript', |
| 28 | [release('@composio/core', '1.2.3'), release('@composio/openai', '2.0.0')], |
| 29 | ['typescript@5.9.3'] |
| 30 | ); |
| 31 | expect(args).toContain('/work/sdk-candidate/typescript/composio-core-1.2.3.tgz'); |
| 32 | expect(args).toContain('/work/sdk-candidate/typescript/composio-openai-2.0.0.tgz'); |
| 33 | expect(args.filter(arg => arg.startsWith('@composio/'))).toEqual([]); |
| 34 | |
| 35 | const wheels = ['composio-0.9.0-py3-none-any.whl', 'composio_openai-0.9.0-py3-none-any.whl']; |
| 36 | const python = '/work/sdk-candidate/python'; |
| 37 | expect(pythonRequirement(python, wheels, 'composio-openai', '0.9.0')).toBe( |
| 38 | '/work/sdk-candidate/python/composio_openai-0.9.0-py3-none-any.whl' |
| 39 | ); |
| 40 | expect(pythonRequirement(python, wheels, 'composio', '0.9.0')).toBe( |
| 41 | '/work/sdk-candidate/python/composio-0.9.0-py3-none-any.whl' |
| 42 | ); |
| 43 | expect(pythonRequirement(python, wheels, 'composio-gemini', '0.9.0')).toBeUndefined(); |
| 44 | }); |
| 45 | }); |
| 46 | |
| 47 | const exec = (cwd: string, executable: string, args: ReadonlyArray<string>) => |
| 48 | runRelease(run(executable, args, { cwd, env: withoutReleaseTokens })); |
| 49 | |
| 50 | /** Packs a one-file package whose exports declare `./dist/index.js` and `./dist/index.d.ts`. */ |
| 51 | const fixtureTarball = async (root: string, files: Record<string, string>) => { |
| 52 | await writeText( |
| 53 | `${root}/package/package.json`, |
| 54 | JSON.stringify({ |
| 55 | name: '@composio/release-fixture', |
| 56 | version: '1.0.0', |
| 57 | type: 'module', |
| 58 | exports: { '.': { types: './dist/index.d.ts', import: './dist/index.js' } }, |
| 59 | }) |
| 60 | ); |
| 61 | for (const [name, contents] of Object.entries(files)) |
| 62 | await writeText(`${root}/package/${name}`, contents); |
| 63 | await exec(root, 'tar', ['-czf', 'fixture.tgz', 'package']); |
| 64 | return `${root}/fixture.tgz`; |
| 65 | }; |
| 66 | |
| 67 | /** Installs the tarball offline into a consumer project that borrows the repository TypeScript. */ |
| 68 | const consumerWith = async (tarball: string) => { |
| 69 | const directory = await directories.create(); |
| 70 | await writeText(`${directory}/package.json`, JSON.stringify({ private: true, type: 'module' })); |
| 71 | await exec(directory, 'npm', ['install', '--offline', '--ignore-scripts', '--no-audit', tarball]); |
| 72 | await symlink( |
| 73 | await resolvePath('node_modules/typescript'), |
| 74 | `${directory}/node_modules/typescript` |
| 75 | ); |
| 76 | await writeText(`${directory}/node_modules/.bin/.keep`, ''); |
| 77 | await symlink('../typescript/bin/tsc', `${directory}/node_modules/.bin/tsc`); |
| 78 | return directory; |
| 79 | }; |
| 80 | |
| 81 | describe('strict npm consumer', () => { |
| 82 | test('a candidate tarball missing a declared export fails, and the complete tarball passes', async () => { |
| 83 | const complete = await fixtureTarball(await directories.create(), { |
| 84 | 'dist/index.js': 'export const value = 1;\n', |
| 85 | 'dist/index.d.ts': 'export declare const value: number;\n', |
| 86 | }); |
| 87 | await runRelease( |
| 88 | checkStrictConsumer(await consumerWith(complete), ['@composio/release-fixture'], []) |
| 89 | ); |
| 90 | |
| 91 | const missing = await fixtureTarball(await directories.create(), { |
| 92 | 'dist/index.js': 'export const value = 1;\n', |
| 93 | }); |
| 94 | await expect( |
| 95 | runRelease( |
| 96 | checkStrictConsumer(await consumerWith(missing), ['@composio/release-fixture'], []) |
| 97 | ) |
| 98 | ).rejects.toThrow('@composio/release-fixture'); |
| 99 | }); |
| 100 | }); |
| 101 | |
| 102 | describe('candidate core with published providers', () => { |
| 103 | test('installs the candidate core with each published provider, skips unpublished ones and names the one that fails', async () => { |
| 104 | const cwd = await directories.create(); |
| 105 | const candidates = await directories.create(); |
| 106 | const work = await directories.create(); |
| 107 | await writeText(`${cwd}/mise.toml`, '[tools]\npython = "3.12.13"\n'); |
| 108 | await writeText(`${cwd}/python/composio/__version__.py`, '__version__ = "1.0.0"\n'); |
| 109 | await writeText( |
| 110 | `${cwd}/python/pyproject.toml`, |
| 111 | '[project]\nname = "composio"\nversion = "1.0.0"\n' |
| 112 | ); |
| 113 | for (const provider of ['openai', 'broken', 'brandnew']) { |
| 114 | await writeText( |
| 115 | `${cwd}/python/providers/${provider}/pyproject.toml`, |
| 116 | `[project]\nname = "composio-${provider}"\nversion = "1.0.0"\n` |
| 117 | ); |
| 118 | await writeText(`${cwd}/python/providers/${provider}/setup.py`, 'setup(version="1.0.0")\n'); |
| 119 | } |
| 120 | await writeText(`${candidates}/composio-1.0.0-py3-none-any.whl`, 'wheel'); |
| 121 | await writeText(`${candidates}/composio_openai-1.0.0-py3-none-any.whl`, 'wheel'); |
| 122 | const bin = `${cwd}/fake-bin`; |
| 123 | const log = `${cwd}/uv.log`; |
| 124 | await writeText( |
| 125 | `${bin}/uv`, |
| 126 | [ |
| 127 | '#!/bin/sh', |
| 128 | `echo "$@" >> ${log}`, |
| 129 | 'if [ "$1" = venv ]; then', |
| 130 | ' mkdir -p "$4/bin"', |
| 131 | ` printf '#!/bin/sh\\ncase "$0" in *composio-broken*) echo "ImportError: boom" >&2; exit 1;; esac\\n' > "$4/bin/python"`, |
| 132 | ' chmod +x "$4/bin/python"', |
| 133 | 'fi', |
| 134 | ].join('\n') |
| 135 | ); |
| 136 | await makeExecutable(`${bin}/uv`); |
| 137 | const previous = process.env.PATH; |
| 138 | try { |
| 139 | process.env.PATH = `${bin}:${previous}`; |
| 140 | await expect( |
| 141 | runRelease(verifyPublishedProviders(cwd, candidates, '1.0.0', work), async input => |
| 142 | String(input).includes('/composio-brandnew/') |
| 143 | ? new Response('{}', { status: 404 }) |
| 144 | : new Response('{}') |
| 145 | ) |
| 146 | ).rejects.toThrow('Candidate composio breaks the latest published composio-broken'); |
| 147 | } finally { |
| 148 | process.env.PATH = previous; |
| 149 | } |
| 150 | const installs = (await readText(log)) |
| 151 | .split('\n') |
| 152 | .filter(line => line.startsWith('pip install')); |
| 153 | const core = `${candidates}/composio-1.0.0-py3-none-any.whl`; |
| 154 | expect(installs).toHaveLength(2); |
| 155 | expect(installs[0]).toContain(core); |
| 156 | expect(installs[0]).toMatch(/ composio-broken$/); |
| 157 | expect(installs[1]).toContain(core); |
| 158 | expect(installs[1]).toMatch(/ composio-openai$/); |
| 159 | }); |
| 160 | }); |