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, expect, test } from 'bun:test'; |
| 2 | import { formatJson, run, sha256Hex, spawn } from '../scripts/sdk-release/runtime'; |
| 3 | import { |
| 4 | readText, |
| 5 | resolvePath, |
| 6 | runRelease, |
| 7 | temporaryDirectories, |
| 8 | writeText, |
| 9 | } from './sdk-release-harness'; |
| 10 | import { batch, candidateRoutes, head } from './sdk-release-controller-fixture'; |
| 11 | |
| 12 | const directories = temporaryDirectories('sdk-candidate-pin-'); |
| 13 | afterEach(() => directories.cleanup()); |
| 14 | |
| 15 | const tarball = 'composio-core-1.0.1.tgz'; |
| 16 | |
| 17 | /** The archive release-PR run 41 uploaded for `@composio/core@1.0.1`. */ |
| 18 | const approvedArchive = async () => { |
| 19 | const directory = await directories.create(); |
| 20 | const bytes = new TextEncoder().encode('approved tarball bytes'); |
| 21 | await writeText(`${directory}/${tarball}`, 'approved tarball bytes'); |
| 22 | await writeText( |
| 23 | `${directory}/candidate.json`, |
| 24 | formatJson({ |
| 25 | sourceSha: head, |
| 26 | producerRun: 41, |
| 27 | language: 'typescript', |
| 28 | files: [{ name: tarball, sha256: await runRelease(sha256Hex(bytes)), size: bytes.length }], |
| 29 | }) |
| 30 | ); |
| 31 | const zip = `${directory}/candidate.zip`; |
| 32 | await runRelease( |
| 33 | run('zip', ['-j', '-q', zip, `${directory}/${tarball}`, `${directory}/candidate.json`]) |
| 34 | ); |
| 35 | const archive = new Uint8Array(await Bun.file(zip).arrayBuffer()); |
| 36 | return { zip, digest: `sha256:${await runRelease(sha256Hex(archive))}` }; |
| 37 | }; |
| 38 | |
| 39 | /** The tag run's pinning job for tag run 9, run as the CLI on a fresh checkout. */ |
| 40 | const pinAttempt = async ( |
| 41 | archive: { zip: string; digest: string }, |
| 42 | options: { expired?: boolean; headAuthor?: string } = {} |
| 43 | ) => { |
| 44 | const directory = await directories.create(); |
| 45 | await writeText(`${directory}/package.json`, JSON.stringify({ name: 'root', private: true })); |
| 46 | await writeText(`${directory}/pnpm-workspace.yaml`, "packages: ['core']\n"); |
| 47 | await writeText( |
| 48 | `${directory}/core/package.json`, |
| 49 | JSON.stringify({ name: '@composio/core', version: '1.0.1' }) |
| 50 | ); |
| 51 | await writeText(`${directory}/.github/sdk-release-plan.json`, JSON.stringify(batch)); |
| 52 | const routes = candidateRoutes(archive.digest, options); |
| 53 | const preload = `${directory}/fetch.ts`; |
| 54 | await writeText( |
| 55 | preload, |
| 56 | `const routes = ${JSON.stringify(routes)}; |
| 57 | globalThis.fetch = async input => { |
| 58 | const url = new URL(String(input)); |
| 59 | if (url.hostname === 'artifacts.test') return new Response(Bun.file(${JSON.stringify(archive.zip)})); |
| 60 | if (url.pathname.endsWith('/actions/artifacts/77/zip')) |
| 61 | return new Response(null, { status: 302, headers: { location: 'https://artifacts.test/77.zip' } }); |
| 62 | const route = Object.keys(routes).find(key => url.pathname.endsWith(key)); |
| 63 | return route ? Response.json(routes[route]) : new Response('{}', { status: 502 }); |
| 64 | }; |
| 65 | ` |
| 66 | ); |
| 67 | const output = `${directory}/output`; |
| 68 | await writeText(output, ''); |
| 69 | const summary = `${directory}/summary`; |
| 70 | await writeText(summary, ''); |
| 71 | const result = await runRelease( |
| 72 | spawn( |
| 73 | 'bun', |
| 74 | ['--preload', preload, await resolvePath('scripts/sdk-release/candidates.ts'), 'approve'], |
| 75 | { |
| 76 | cwd: directory, |
| 77 | env: { |
| 78 | GITHUB_RUN_ID: '9', |
| 79 | GITHUB_SHA: head, |
| 80 | GITHUB_REF: 'refs/tags/sdk-release/8', |
| 81 | GITHUB_OUTPUT: output, |
| 82 | GITHUB_STEP_SUMMARY: summary, |
| 83 | SDK_READ_TOKEN: 'fixture', |
| 84 | SDK_RELEASE_APP_SLUG: 'sdk-release-app', |
| 85 | SDK_RELEASE_TOKEN: '', |
| 86 | }, |
| 87 | } |
| 88 | ) |
| 89 | ); |
| 90 | return { |
| 91 | exitCode: result.exitCode, |
| 92 | stderr: result.stderr, |
| 93 | output: await readText(output), |
| 94 | tarball: () => readText(`${directory}/sdk-candidate/typescript/${tarball}`), |
| 95 | }; |
| 96 | }; |
| 97 | |
| 98 | test('the tag run pins the approved release-PR artifact and its languages as job outputs', async () => { |
| 99 | const archive = await approvedArchive(); |
| 100 | const pinned = await pinAttempt(archive); |
| 101 | expect({ exitCode: pinned.exitCode, stderr: pinned.stderr }).toMatchObject({ exitCode: 0 }); |
| 102 | expect(await pinned.tarball()).toBe('approved tarball bytes'); |
| 103 | expect(pinned.output).toBe( |
| 104 | [ |
| 105 | 'issue=8', |
| 106 | `approved=${JSON.stringify({ typescript: { run: 41, artifactId: 77, digest: archive.digest } })}`, |
| 107 | 'typescript=true', |
| 108 | 'python=false', |
| 109 | '', |
| 110 | ].join('\n') |
| 111 | ); |
| 112 | }); |
| 113 | |
| 114 | test('a failed adoption still names the request issue, so the publish status reaches it', async () => { |
| 115 | const pinned = await pinAttempt(await approvedArchive(), { expired: true }); |
| 116 | expect(pinned.exitCode).not.toBe(0); |
| 117 | expect(pinned.output).toBe('issue=8\n'); |
| 118 | }); |
| 119 | |
| 120 | test('a release tag on a commit the App did not make names no issue for the bot to write to', async () => { |
| 121 | const pinned = await pinAttempt(await approvedArchive(), { expired: true, headAuthor: 'writer' }); |
| 122 | expect(pinned.exitCode).not.toBe(0); |
| 123 | expect(pinned.output).toBe(''); |
| 124 | }); |