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 { describe, expect, test } from 'bun:test'; |
| 2 | import { Effect, Option } from 'effect'; |
| 3 | import { executeReleaseRequest, openReleasePull } from '../scripts/sdk-release/batch'; |
| 4 | import { BATCH_PATH, validateReleaseDiff, type ReleaseFile } from '../scripts/sdk-release/source'; |
| 5 | import { |
| 6 | base, |
| 7 | batch, |
| 8 | betaBatch, |
| 9 | betaFiles, |
| 10 | fakeController, |
| 11 | newManifest, |
| 12 | oldManifest, |
| 13 | releaseFiles, |
| 14 | } from './sdk-release-controller-fixture'; |
| 15 | import { resolvePath, runRelease } from './sdk-release-harness'; |
| 16 | |
| 17 | const validate = ( |
| 18 | files: ReadonlyArray<ReleaseFile>, |
| 19 | plan: Parameters<typeof validateReleaseDiff>[1], |
| 20 | outputs: ReadonlyArray<string> |
| 21 | ) => runRelease(validateReleaseDiff(files, plan, outputs)); |
| 22 | |
| 23 | describe('release-only diff validation', () => { |
| 24 | test('source edits and lock dependency changes fail release-only validation', async () => { |
| 25 | const plan = { releases: [], changesets: [], retainedChangesets: [] }; |
| 26 | await expect( |
| 27 | validate([{ path: 'ts/packages/core/src/index.ts', before: 'x', after: 'y' }], plan, []) |
| 28 | ).rejects.toThrow('Not a planned release output'); |
| 29 | await expect( |
| 30 | validate([{ path: 'pnpm-lock.yaml', before: 'dep: 1', after: 'dep: 2' }], plan, []) |
| 31 | ).rejects.toThrow('Release changes dependency resolution'); |
| 32 | await validate( |
| 33 | [{ path: 'docs/content/changelog/release.mdx', before: 'x', after: 'edited narrative' }], |
| 34 | plan, |
| 35 | ['docs/content/changelog/release.mdx'] |
| 36 | ); |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | describe('release PR', () => { |
| 41 | const open = async ( |
| 42 | fetcher: ReturnType<typeof fakeController>['fetcher'], |
| 43 | files = releaseFiles |
| 44 | ) => runRelease(openReleasePull(await resolvePath('.'), batch, { files }), fetcher); |
| 45 | const writePaths = (writes: ReadonlyArray<{ method: string; path: string }>) => |
| 46 | writes.map(write => `${write.method} ${write.path}`); |
| 47 | |
| 48 | test('a release-only patch is committed on the frozen source and opened as one PR', async () => { |
| 49 | const { fetcher, writes } = fakeController(); |
| 50 | expect(await open(fetcher)).toEqual({ |
| 51 | _tag: 'InReview', |
| 52 | pull: 'https://github.com/ComposioHQ/composio/pull/9', |
| 53 | }); |
| 54 | expect(writePaths(writes)).toEqual([ |
| 55 | 'POST /git/blobs', |
| 56 | 'POST /git/blobs', |
| 57 | 'POST /git/blobs', |
| 58 | 'POST /git/trees', |
| 59 | 'POST /git/commits', |
| 60 | 'POST /git/refs', |
| 61 | 'POST /pulls', |
| 62 | ]); |
| 63 | expect(writes.find(write => write.path === '/git/commits')?.body).toMatchObject({ |
| 64 | parents: [base], |
| 65 | }); |
| 66 | }); |
| 67 | |
| 68 | test('a re-run whose branch already exists moves that branch instead of creating it', async () => { |
| 69 | const { fetcher, writes } = fakeController({ existingBranch: true }); |
| 70 | await open(fetcher); |
| 71 | expect(writes.find(write => write.path.startsWith('/git/refs'))).toEqual({ |
| 72 | method: 'PATCH', |
| 73 | path: '/git/refs/heads/sdk-release/batch-8', |
| 74 | body: { sha: 'e'.repeat(40), force: true }, |
| 75 | }); |
| 76 | }); |
| 77 | |
| 78 | test('a prepared plan that differs from the planned batch is refused before any write', async () => { |
| 79 | const { fetcher, writes } = fakeController(); |
| 80 | const edited = releaseFiles.map(file => |
| 81 | file.path === BATCH_PATH |
| 82 | ? { ...file, after: JSON.stringify({ ...batch, requestedBy: 'someone-else' }) } |
| 83 | : file |
| 84 | ); |
| 85 | await expect(open(fetcher, edited)).rejects.toThrow('Prepared release plan differs'); |
| 86 | expect(writes).toEqual([]); |
| 87 | }); |
| 88 | |
| 89 | test('a patch that touches source outside the release outputs is refused before any write', async () => { |
| 90 | const { fetcher, writes } = fakeController(); |
| 91 | const widened = [ |
| 92 | ...releaseFiles, |
| 93 | { path: 'ts/packages/core/src/backdoor.ts', before: null, after: 'export {};' }, |
| 94 | ]; |
| 95 | await expect(open(fetcher, widened)).rejects.toThrow('Not a planned release output'); |
| 96 | expect(writes).toEqual([]); |
| 97 | }); |
| 98 | |
| 99 | test('a re-run of a dispatched request finds its issue in its own release PR', async () => { |
| 100 | const { fetcher } = fakeController({ openRelease: 'sdk-release/batch-8' }); |
| 101 | const result = await runRelease( |
| 102 | executeReleaseRequest( |
| 103 | Effect.succeed({ channel: 'stable', typescript: 'auto', python: 'skip' }), |
| 104 | { actor: 'requester', runId: '8', sourceSha: base, appSlug: 'sdk-release-app' }, |
| 105 | () => Effect.die('must not plan') |
| 106 | ), |
| 107 | fetcher |
| 108 | ); |
| 109 | expect(result).toEqual({ |
| 110 | outcome: { _tag: 'InReview', pull: 'https://github.com/ComposioHQ/composio/pull/5' }, |
| 111 | issue: Option.some(8), |
| 112 | }); |
| 113 | }); |
| 114 | |
| 115 | test('a release that merged and failed its gate since planning blocks this one', async () => { |
| 116 | const { fetcher, writes } = fakeController({ untaggedNext: true }); |
| 117 | expect(await open(fetcher)).toEqual({ _tag: 'Blocked', release: '8' }); |
| 118 | expect(writes).toEqual([]); |
| 119 | }); |
| 120 | |
| 121 | test('another open release PR opens nothing and the request waits for it', async () => { |
| 122 | const { fetcher, writes } = fakeController({ openRelease: 'sdk-release/batch-7' }); |
| 123 | expect(await open(fetcher)).toEqual({ |
| 124 | _tag: 'Waiting', |
| 125 | pull: 'https://github.com/ComposioHQ/composio/pull/5', |
| 126 | }); |
| 127 | expect(writes).toEqual([]); |
| 128 | }); |
| 129 | |
| 130 | test('a re-run after this request opened its release PR resumes that PR', async () => { |
| 131 | const { fetcher, writes } = fakeController({ openRelease: 'sdk-release/batch-8' }); |
| 132 | expect(await open(fetcher)).toEqual({ |
| 133 | _tag: 'InReview', |
| 134 | pull: 'https://github.com/ComposioHQ/composio/pull/5', |
| 135 | }); |
| 136 | expect(writes).toEqual([]); |
| 137 | }); |
| 138 | |
| 139 | test('a beta release PR commits only its plan, so next keeps its versions and changesets', async () => { |
| 140 | const { fetcher, writes } = fakeController({ beta: true }); |
| 141 | const state = await runRelease( |
| 142 | openReleasePull(await resolvePath('.'), betaBatch, { files: betaFiles }), |
| 143 | fetcher |
| 144 | ); |
| 145 | expect(state).toEqual({ |
| 146 | _tag: 'InReview', |
| 147 | pull: 'https://github.com/ComposioHQ/composio/pull/9', |
| 148 | }); |
| 149 | expect(writePaths(writes)).toEqual([ |
| 150 | 'POST /git/blobs', |
| 151 | 'POST /git/trees', |
| 152 | 'POST /git/commits', |
| 153 | 'POST /git/refs', |
| 154 | 'POST /pulls', |
| 155 | ]); |
| 156 | const opened = writes.find(write => write.path === '/pulls')?.body as { |
| 157 | readonly title: string; |
| 158 | readonly body: string; |
| 159 | }; |
| 160 | expect(opened.title).toBe('chore(release): publish SDK beta packages'); |
| 161 | expect(opened.body).toContain('never touches `latest`'); |
| 162 | expect(opened.body).toContain('A beta opens no docs PR'); |
| 163 | }); |
| 164 | |
| 165 | test('a beta release PR that also writes a changelog is refused before any write', async () => { |
| 166 | const { fetcher, writes } = fakeController({ beta: true }); |
| 167 | const changelog = { path: 'ts/packages/core/CHANGELOG.md', before: null, after: '## beta' }; |
| 168 | await expect( |
| 169 | runRelease( |
| 170 | openReleasePull(await resolvePath('.'), betaBatch, { files: [...betaFiles, changelog] }), |
| 171 | fetcher |
| 172 | ) |
| 173 | ).rejects.toThrow('A beta release PR changes only .github/sdk-release-plan.json'); |
| 174 | expect(writes).toEqual([]); |
| 175 | }); |
| 176 | |
| 177 | test('major targets allow normal Changesets peer-range updates without changing unrelated fields', async () => { |
| 178 | const plan = { |
| 179 | ...batch.plan, |
| 180 | releases: [ |
| 181 | { ...batch.plan.releases[0], newVersion: '2.0.0', type: 'major' as const }, |
| 182 | { |
| 183 | ...batch.plan.releases[0], |
| 184 | name: '@composio/provider', |
| 185 | oldVersion: '0.1.0', |
| 186 | newVersion: '0.1.1', |
| 187 | }, |
| 188 | ], |
| 189 | }; |
| 190 | const provider = { |
| 191 | name: '@composio/provider', |
| 192 | version: '0.1.0', |
| 193 | peerDependencies: { '@composio/core': '>=1.0.0 <2.0.0 || >=2.0.0-beta.0 <2.0.0' }, |
| 194 | }; |
| 195 | await validate( |
| 196 | [ |
| 197 | { |
| 198 | path: 'ts/packages/core/package.json', |
| 199 | before: oldManifest, |
| 200 | after: newManifest.replace('1.0.1', '2.0.0'), |
| 201 | }, |
| 202 | { |
| 203 | path: 'ts/packages/providers/provider/package.json', |
| 204 | before: JSON.stringify(provider), |
| 205 | after: JSON.stringify({ |
| 206 | ...provider, |
| 207 | version: '0.1.1', |
| 208 | peerDependencies: { '@composio/core': '>=2.0.0' }, |
| 209 | }), |
| 210 | }, |
| 211 | ], |
| 212 | plan, |
| 213 | [] |
| 214 | ); |
| 215 | }); |
| 216 | test('coincident client versions and Python dependency literals cannot masquerade as SDK metadata', async () => { |
| 217 | await expect( |
| 218 | validate( |
| 219 | [ |
| 220 | { |
| 221 | path: 'ts/packages/core/package.json', |
| 222 | before: oldManifest, |
| 223 | after: newManifest.replace('"client":"1.0.0"', '"client":"1.0.1"'), |
| 224 | }, |
| 225 | ], |
| 226 | batch.plan, |
| 227 | [] |
| 228 | ) |
| 229 | ).rejects.toThrow('Unplanned dependency'); |
| 230 | }); |
| 231 | }); |