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 { pythonVersion } from '../scripts/sdk-release/channel'; |
| 3 | import { |
| 4 | applySdkReleasePlan as applyPlanEffect, |
| 5 | createSdkReleasePlan as createPlanEffect, |
| 6 | type SdkReleaseOptions, |
| 7 | type SdkReleasePlan, |
| 8 | } from '../scripts/sdk-release/plan'; |
| 9 | import type { PythonMetadataOptions } from '../scripts/sdk-release/python-metadata'; |
| 10 | import { discoverPythonPackages as discoverEffect } from '../scripts/sdk-release/python-metadata'; |
| 11 | import { |
| 12 | exists, |
| 13 | readText, |
| 14 | remove, |
| 15 | resolvePath, |
| 16 | runRelease, |
| 17 | symlink, |
| 18 | temporaryDirectories, |
| 19 | writeText, |
| 20 | } from './sdk-release-harness'; |
| 21 | |
| 22 | const roots = temporaryDirectories('composio-sdk-plan-'); |
| 23 | const createSdkReleasePlan = (cwd: string, options?: SdkReleaseOptions) => |
| 24 | runRelease(createPlanEffect(cwd, options)); |
| 25 | const applySdkReleasePlan = (cwd: string, plan: SdkReleasePlan, options?: PythonMetadataOptions) => |
| 26 | runRelease(applyPlanEffect(cwd, plan, options)); |
| 27 | const discoverPythonPackages = (cwd: string) => runRelease(discoverEffect(cwd)); |
| 28 | |
| 29 | async function fixture() { |
| 30 | const cwd = await roots.create(); |
| 31 | const json = (path: string, value: unknown) => |
| 32 | writeText(`${cwd}/${path}`, JSON.stringify(value, null, 2)); |
| 33 | await json('package.json', { |
| 34 | name: 'release-fixture', |
| 35 | private: true, |
| 36 | workspaces: ['packages/*', 'python'], |
| 37 | }); |
| 38 | await writeText(`${cwd}/pnpm-workspace.yaml`, 'packages:\n - packages/*\n - python\n'); |
| 39 | await json('.changeset/config.json', { |
| 40 | changelog: '@changesets/cli/changelog', |
| 41 | format: false, |
| 42 | fixed: [['@composio/core', '@composio/slim']], |
| 43 | linked: [], |
| 44 | privatePackages: { version: true, tag: false }, |
| 45 | ignore: ['@composio/cli'], |
| 46 | baseBranch: 'next', |
| 47 | access: 'public', |
| 48 | updateInternalDependencies: 'patch', |
| 49 | ___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: { |
| 50 | onlyUpdatePeerDependentsWhenOutOfRange: true, |
| 51 | }, |
| 52 | }); |
| 53 | await json('packages/core/package.json', { name: '@composio/core', version: '0.28.0' }); |
| 54 | await json('packages/slim/package.json', { name: '@composio/slim', version: '0.28.0' }); |
| 55 | await json('packages/provider/package.json', { |
| 56 | name: '@composio/provider', |
| 57 | version: '0.11.0', |
| 58 | peerDependencies: { '@composio/core': '^0.28.0 || ^0.29.0' }, |
| 59 | }); |
| 60 | await json('packages/cli/package.json', { |
| 61 | name: '@composio/cli', |
| 62 | version: '0.7.0', |
| 63 | private: true, |
| 64 | }); |
| 65 | await json('python/package.json', { |
| 66 | name: '@composio/python-sdk', |
| 67 | version: '0.31.0', |
| 68 | private: true, |
| 69 | }); |
| 70 | await writeText( |
| 71 | `${cwd}/python/pyproject.toml`, |
| 72 | '[project]\nname = "composio"\nversion = "0.31.0"\n' |
| 73 | ); |
| 74 | await writeText( |
| 75 | `${cwd}/python/setup.py`, |
| 76 | 'from setuptools import setup\nsetup(name="composio")\n' |
| 77 | ); |
| 78 | await writeText(`${cwd}/python/composio/__version__.py`, '__version__ = "0.31.0"\n'); |
| 79 | for (const provider of ['openai', 'outside']) { |
| 80 | await writeText( |
| 81 | `${cwd}/python/providers/${provider}/pyproject.toml`, |
| 82 | `[project]\nname = "composio-${provider}"\nversion = "0.31.0"\n` |
| 83 | ); |
| 84 | await writeText( |
| 85 | `${cwd}/python/providers/${provider}/setup.py`, |
| 86 | `from setuptools import setup\nsetup(name="composio_${provider}", version="0.31.0")\n` |
| 87 | ); |
| 88 | } |
| 89 | await symlink(await resolvePath('node_modules'), `${cwd}/node_modules`); |
| 90 | const note = async ( |
| 91 | id: string, |
| 92 | releases: Record<string, string>, |
| 93 | summary = 'Recorded SDK change.' |
| 94 | ) => |
| 95 | writeText( |
| 96 | `${cwd}/.changeset/${id}.md`, |
| 97 | `---\n${Object.entries(releases) |
| 98 | .map(([name, type]) => `${JSON.stringify(name)}: ${type}`) |
| 99 | .join('\n')}\n---\n\n${summary}\n` |
| 100 | ); |
| 101 | return { cwd, json, note }; |
| 102 | } |
| 103 | |
| 104 | afterEach(() => roots.cleanup()); |
| 105 | |
| 106 | function versions(plan: SdkReleasePlan) { |
| 107 | return Object.fromEntries(plan.releases.map(release => [release.name, release.newVersion])); |
| 108 | } |
| 109 | |
| 110 | describe('SDK release planning', () => { |
| 111 | test('Python-only fragments version private marker and every Python mirror without npm targets', async () => { |
| 112 | const { cwd, note } = await fixture(); |
| 113 | await note('python-fix', { '@composio/python-sdk': 'patch' }, 'Fix connected account updates.'); |
| 114 | const plan = await createSdkReleasePlan(cwd); |
| 115 | expect(versions(plan)).toEqual({ '@composio/python-sdk': '0.31.1' }); |
| 116 | expect(plan.releases[0].language).toBe('python'); |
| 117 | await applySdkReleasePlan(cwd, plan, { updateLockfile: false }); |
| 118 | expect(await readText(`${cwd}/python/CHANGELOG.md`)).toContain( |
| 119 | 'Fix connected account updates.' |
| 120 | ); |
| 121 | expect(await readText(`${cwd}/python/composio/__version__.py`)).toContain('0.31.1'); |
| 122 | const packages = await discoverPythonPackages(cwd); |
| 123 | expect(packages.map(pkg => pkg.name)).toEqual([ |
| 124 | 'composio', |
| 125 | 'composio-openai', |
| 126 | 'composio-outside', |
| 127 | ]); |
| 128 | expect(packages.every(pkg => pkg.version === '0.31.1')).toBe(true); |
| 129 | expect(await readText(`${cwd}/python/providers/outside/setup.py`)).toContain('0.31.1'); |
| 130 | expect(await readText(`${cwd}/python/setup.py`)).toBe( |
| 131 | 'from setuptools import setup\nsetup(name="composio")\n' |
| 132 | ); |
| 133 | }); |
| 134 | |
| 135 | test('a beta plans snapshot versions of the next stable release, suffixed with its run', async () => { |
| 136 | const { cwd, note } = await fixture(); |
| 137 | await note('core-feature', { '@composio/core': 'minor' }, 'Add trigger polling.'); |
| 138 | await note('python-fix', { '@composio/python-sdk': 'patch' }, 'Fix connected accounts.'); |
| 139 | const plan = await createSdkReleasePlan(cwd, { channel: 'beta', run: '19087654321' }); |
| 140 | expect(versions(plan)).toMatchObject({ |
| 141 | '@composio/core': '0.29.0-beta.19087654321', |
| 142 | '@composio/slim': '0.29.0-beta.19087654321', |
| 143 | '@composio/python-sdk': '0.31.1-beta.19087654321', |
| 144 | }); |
| 145 | expect(plan.choices).toMatchObject({ channel: 'beta', run: '19087654321' }); |
| 146 | await applySdkReleasePlan(cwd, plan, { updateLockfile: false }); |
| 147 | expect(JSON.parse(await readText(`${cwd}/packages/core/package.json`)).version).toBe( |
| 148 | '0.29.0-beta.19087654321' |
| 149 | ); |
| 150 | // Python spells the same beta the PEP 440 way, in every mirror. |
| 151 | expect(await readText(`${cwd}/python/composio/__version__.py`)).toContain('0.31.1b19087654321'); |
| 152 | expect( |
| 153 | (await discoverPythonPackages(cwd)).every(pkg => pkg.version === '0.31.1b19087654321') |
| 154 | ).toBe(true); |
| 155 | }); |
| 156 | |
| 157 | test('a beta needs its planning run, so its versions are unique', async () => { |
| 158 | const { cwd, note } = await fixture(); |
| 159 | await note('core-feature', { '@composio/core': 'minor' }); |
| 160 | await expect(createSdkReleasePlan(cwd, { channel: 'beta' })).rejects.toThrow( |
| 161 | 'A beta plan needs its planning run' |
| 162 | ); |
| 163 | }); |
| 164 | |
| 165 | test('mixed recommendations retain TS independent provider versions and per-language overrides', async () => { |
| 166 | const { cwd, note } = await fixture(); |
| 167 | await note('mixed', { |
| 168 | '@composio/core': 'minor', |
| 169 | '@composio/provider': 'patch', |
| 170 | '@composio/python-sdk': 'patch', |
| 171 | }); |
| 172 | const plan = await createSdkReleasePlan(cwd, { python: 'minor' }); |
| 173 | expect(versions(plan)).toEqual({ |
| 174 | '@composio/core': '0.29.0', |
| 175 | '@composio/slim': '0.29.0', |
| 176 | '@composio/provider': '0.11.1', |
| 177 | '@composio/python-sdk': '0.32.0', |
| 178 | }); |
| 179 | expect( |
| 180 | plan.recommended.find(release => release.name === '@composio/python-sdk')?.newVersion |
| 181 | ).toBe('0.31.1'); |
| 182 | }); |
| 183 | |
| 184 | test('lower TS override is applied before fixed-group and peer dependency planning', async () => { |
| 185 | const { cwd, note } = await fixture(); |
| 186 | await note('minor-core', { '@composio/core': 'minor' }); |
| 187 | const plan = await createSdkReleasePlan(cwd, { typescript: 'patch' }); |
| 188 | expect(versions(plan)).toEqual({ '@composio/core': '0.28.1', '@composio/slim': '0.28.1' }); |
| 189 | expect(plan.recommended.find(release => release.name === '@composio/core')?.newVersion).toBe( |
| 190 | '0.29.0' |
| 191 | ); |
| 192 | }); |
| 193 | |
| 194 | test('skipping one language preserves its entry and summary in a mixed fragment', async () => { |
| 195 | const { cwd, note } = await fixture(); |
| 196 | await note( |
| 197 | 'mixed', |
| 198 | { '@composio/core': 'patch', '@composio/python-sdk': 'minor' }, |
| 199 | 'Keep this summary for both SDKs.' |
| 200 | ); |
| 201 | const plan = await createSdkReleasePlan(cwd, { python: 'skip' }); |
| 202 | await applySdkReleasePlan(cwd, plan, { updateLockfile: false }); |
| 203 | const remaining = await readText(`${cwd}/.changeset/mixed.md`); |
| 204 | expect(remaining).toContain('"@composio/python-sdk": minor'); |
| 205 | expect(remaining).not.toContain('@composio/core'); |
| 206 | expect(remaining).toContain('Keep this summary for both SDKs.'); |
| 207 | expect(versions(await createSdkReleasePlan(cwd))).toEqual({ '@composio/python-sdk': '0.32.0' }); |
| 208 | }); |
| 209 | |
| 210 | test('empty auto is a no-op and explicit bumps create honest primary-group maintenance releases', async () => { |
| 211 | const { cwd } = await fixture(); |
| 212 | expect((await createSdkReleasePlan(cwd)).releases).toEqual([]); |
| 213 | const plan = await createSdkReleasePlan(cwd, { typescript: 'patch', python: 'minor' }); |
| 214 | expect(versions(plan)).toEqual({ |
| 215 | '@composio/core': '0.28.1', |
| 216 | '@composio/slim': '0.28.1', |
| 217 | '@composio/python-sdk': '0.32.0', |
| 218 | }); |
| 219 | expect(plan.changesets.map(note => note.summary).join('\n')).toContain( |
| 220 | 'No user-facing changes were recorded' |
| 221 | ); |
| 222 | }); |
| 223 | |
| 224 | test('prerelease mode is not a stable plan', async () => { |
| 225 | const { cwd, json } = await fixture(); |
| 226 | await json('.changeset/pre.json', { mode: 'pre', tag: 'beta' }); |
| 227 | await expect(createSdkReleasePlan(cwd)).rejects.toThrow('prerelease'); |
| 228 | }); |
| 229 | |
| 230 | test.each([ |
| 231 | ['python/composio/__version__.py', '__version__ = "0.30.0"\n'], |
| 232 | ['python/providers/outside/setup.py', 'setup(version="0.30.0")\n'], |
| 233 | ])('rejects Python metadata drift in %s before no-op planning', async (path, contents) => { |
| 234 | const { cwd } = await fixture(); |
| 235 | await writeText(`${cwd}/${path}`, contents); |
| 236 | await expect(createSdkReleasePlan(cwd)).rejects.toThrow('Python version mirror mismatch'); |
| 237 | }); |
| 238 | |
| 239 | test('applying Python release metadata regenerates a real uv workspace lock', async () => { |
| 240 | const { cwd, note } = await fixture(); |
| 241 | await writeText( |
| 242 | `${cwd}/pyproject.toml`, |
| 243 | '[project]\nname = "release-fixture"\nversion = "0.0.0"\nrequires-python = ">=3.11"\n[tool.uv.workspace]\nmembers = ["python", "python/providers/openai"]\n' |
| 244 | ); |
| 245 | await note('python-lock', { '@composio/python-sdk': 'patch' }); |
| 246 | const plan = await createSdkReleasePlan(cwd); |
| 247 | const previousOffline = process.env.UV_OFFLINE; |
| 248 | const previousDownloads = process.env.UV_PYTHON_DOWNLOADS; |
| 249 | process.env.UV_OFFLINE = '1'; |
| 250 | process.env.UV_PYTHON_DOWNLOADS = 'never'; |
| 251 | try { |
| 252 | await applySdkReleasePlan(cwd, plan); |
| 253 | } finally { |
| 254 | if (previousOffline === undefined) delete process.env.UV_OFFLINE; |
| 255 | else process.env.UV_OFFLINE = previousOffline; |
| 256 | if (previousDownloads === undefined) delete process.env.UV_PYTHON_DOWNLOADS; |
| 257 | else process.env.UV_PYTHON_DOWNLOADS = previousDownloads; |
| 258 | } |
| 259 | const lock = await readText(`${cwd}/uv.lock`); |
| 260 | expect(lock).toMatch(/name = "composio"\nversion = "0\.31\.1"/); |
| 261 | expect(lock).toMatch(/name = "composio-openai"\nversion = "0\.31\.1"/); |
| 262 | expect((await discoverPythonPackages(cwd)).every(pkg => pkg.version === '0.31.1')).toBe(true); |
| 263 | }); |
| 264 | |
| 265 | test('ignored CLI and unrelated private package notes cannot enter SDK releases', async () => { |
| 266 | const { cwd, note, json } = await fixture(); |
| 267 | await note('cli', { '@composio/cli': 'patch' }); |
| 268 | await expect(createSdkReleasePlan(cwd)).rejects.toThrow('not an SDK release target'); |
| 269 | await remove(`${cwd}/.changeset/cli.md`); |
| 270 | await json('packages/example/package.json', { |
| 271 | name: 'private-example', |
| 272 | version: '1.0.0', |
| 273 | private: true, |
| 274 | }); |
| 275 | await note('example', { 'private-example': 'patch' }); |
| 276 | await expect(createSdkReleasePlan(cwd)).rejects.toThrow('not an SDK release target'); |
| 277 | }); |
| 278 | |
| 279 | test('application rejects retained entries that were not in the selected source plan', async () => { |
| 280 | const { cwd, note } = await fixture(); |
| 281 | await note('core', { '@composio/core': 'patch' }); |
| 282 | const selected = await createSdkReleasePlan(cwd); |
| 283 | const plan = { |
| 284 | ...selected, |
| 285 | retainedChangesets: [ |
| 286 | ...selected.retainedChangesets, |
| 287 | { |
| 288 | id: 'unrelated', |
| 289 | summary: 'Not an authored fragment.', |
| 290 | releases: [{ name: '@composio/python-sdk', type: 'patch' as const }], |
| 291 | }, |
| 292 | ], |
| 293 | }; |
| 294 | await expect(applySdkReleasePlan(cwd, plan, { updateLockfile: false })).rejects.toThrow( |
| 295 | 'selected source plan' |
| 296 | ); |
| 297 | expect(await exists(`${cwd}/.changeset/unrelated.md`)).toBe(false); |
| 298 | expect(JSON.parse(await readText(`${cwd}/packages/core/package.json`)).version).toBe('0.28.0'); |
| 299 | }); |
| 300 | |
| 301 | test('a changed release input is rejected before application changes versions', async () => { |
| 302 | const { cwd, note } = await fixture(); |
| 303 | await note('core', { '@composio/core': 'patch' }); |
| 304 | const plan = await createSdkReleasePlan(cwd); |
| 305 | await note('new-change', { '@composio/core': 'minor' }); |
| 306 | await expect(applySdkReleasePlan(cwd, plan, { updateLockfile: false })).rejects.toThrow( |
| 307 | 'changed' |
| 308 | ); |
| 309 | expect(JSON.parse(await readText(`${cwd}/packages/core/package.json`)).version).toBe('0.28.0'); |
| 310 | }); |
| 311 | }); |
| 312 | |
| 313 | test('a beta takes the PEP 440 spelling on PyPI and stable versions keep theirs', () => { |
| 314 | expect(pythonVersion('0.31.1-beta.19087654321')).toBe('0.31.1b19087654321'); |
| 315 | expect(pythonVersion('0.31.1')).toBe('0.31.1'); |
| 316 | }); |