Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

chore(cli): migrate binary release tags and docs (#2719)

Musthaq Ahamad4fda636aba7e
diff --git a/.github/workflows/build-cli-binaries.yml b/.github/workflows/build-cli-binaries.yml
index a3b20c589..504bbd1a8 100644
--- a/.github/workflows/build-cli-binaries.yml
+++ b/.github/workflows/build-cli-binaries.yml
@@ -3,13 +3,14 @@ name: Build CLI Binaries
on:
push:
tags:
+ # Temporary compatibility window: support both legacy v* and package-scoped CLI tags.
- 'v*'
+ - '@composio/cli@*'
workflow_dispatch:
inputs:
version:
- description: 'Version to build (e.g., v1.0.0)'
- required: false
- default: 'dev'
+ description: 'Semver version to release (e.g., 1.0.0)'
+ required: true
permissions:
contents: write
@@ -38,6 +39,16 @@ jobs:
- name: Checkout
uses: actions/checkout@v6
+ - name: Validate manual version input
+ if: github.event_name == 'workflow_dispatch'
+ run: |
+ version="${{ inputs.version }}"
+ if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
+ echo "Invalid semver version: '$version'"
+ echo "Expected format like: 1.2.3, 1.2.3-beta.1, 1.2.3+build.7"
+ exit 1
+ fi
+
- name: Setup Node.js, pnpm, Bun
uses: ./.github/actions/setup-node-pnpm-bun
@@ -97,8 +108,8 @@ jobs:
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
uses: softprops/action-gh-release@v2
with:
- tag_name: ${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref_name }}
- name: ${{ github.event_name == 'workflow_dispatch' && format('CLI {0} (Manual Build)', inputs.version) || github.ref_name }}
+ tag_name: ${{ github.event_name == 'workflow_dispatch' && format('@composio/cli@{0}', inputs.version) || github.ref_name }}
+ name: ${{ github.event_name == 'workflow_dispatch' && format('CLI @composio/cli@{0} (Manual Build)', inputs.version) || github.ref_name }}
files: |
ts/packages/cli/dist/binaries/${{ matrix.artifact }}.zip
draft: false
@@ -114,7 +125,7 @@ jobs:
if: always() && !cancelled() && (startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch')
uses: ./.github/workflows/cli.test-installation.yml
with:
- version: ${{ inputs.version || github.ref_name }}
+ version: ${{ github.event_name == 'workflow_dispatch' && format('@composio/cli@{0}', inputs.version) || github.ref_name }}
create-install-instructions:
name: Create Install Instructions
@@ -128,6 +139,7 @@ jobs:
- name: Create installation README
run: |
+ RELEASE_TAG="${{ github.event_name == 'workflow_dispatch' && format('@composio/cli@{0}', inputs.version) || github.ref_name }}"
cat > INSTALL.md << 'EOF'
# Composio CLI Installation
@@ -140,7 +152,7 @@ jobs:
### Install specific version
```bash
- curl -fsSL https://raw.githubusercontent.com/ComposioHQ/composio/main/install.sh | bash -s -- ${{ github.ref_name }}
+ curl -fsSL https://raw.githubusercontent.com/ComposioHQ/composio/main/install.sh | bash -s -- RELEASE_TAG_PLACEHOLDER
```
## Manual Installation
@@ -175,6 +187,7 @@ jobs:
Windows support coming soon!
EOF
+ sed -i.bak "s|RELEASE_TAG_PLACEHOLDER|$RELEASE_TAG|g" INSTALL.md && rm -f INSTALL.md.bak
- name: Upload install instructions
uses: actions/upload-artifact@v6
diff --git a/.github/workflows/cli.test-installation.yml b/.github/workflows/cli.test-installation.yml
index 9fe7a353a..415f829b7 100644
--- a/.github/workflows/cli.test-installation.yml
+++ b/.github/workflows/cli.test-installation.yml
@@ -3,17 +3,18 @@ name: Test Installation
on:
push:
tags:
+ # Temporary compatibility window: support both legacy v* and package-scoped CLI tags.
- 'v*'
+ - '@composio/cli@*'
workflow_dispatch:
inputs:
version:
- description: 'Version to test (e.g., v1.0.0)'
- required: false
- default: 'latest'
+ description: 'Semver version to test (e.g., 1.0.0)'
+ required: true
workflow_call:
inputs:
version:
- description: 'Version to test'
+ description: 'Release tag or semver version to test'
required: false
default: 'latest'
type: string
@@ -69,6 +70,41 @@ jobs:
- name: Checkout
uses: actions/checkout@v6
+ - name: Resolve and validate target release
+ id: release_target
+ shell: bash
+ run: |
+ raw_input="${{ inputs.version }}"
+ if [[ -z "$raw_input" || "$raw_input" == "latest" ]]; then
+ echo "use_latest=true" >> "$GITHUB_OUTPUT"
+ echo "release_tag=" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+
+ # For manual runs, require semver input and build the release tag.
+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
+ if [[ ! "$raw_input" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
+ echo "Invalid semver version: '$raw_input'"
+ echo "Expected format like: 1.2.3, 1.2.3-beta.1, 1.2.3+build.7"
+ exit 1
+ fi
+ echo "use_latest=false" >> "$GITHUB_OUTPUT"
+ echo "release_tag=@composio/cli@$raw_input" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+
+ # For workflow_call / push, accept a full package tag, semver, or legacy v* tag.
+ if [[ "$raw_input" =~ ^@composio/cli@ ]]; then
+ echo "use_latest=false" >> "$GITHUB_OUTPUT"
+ echo "release_tag=$raw_input" >> "$GITHUB_OUTPUT"
+ elif [[ "$raw_input" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
+ echo "use_latest=false" >> "$GITHUB_OUTPUT"
+ echo "release_tag=@composio/cli@$raw_input" >> "$GITHUB_OUTPUT"
+ else
+ echo "use_latest=false" >> "$GITHUB_OUTPUT"
+ echo "release_tag=$raw_input" >> "$GITHUB_OUTPUT"
+ fi
+
- name: Setup shell environment
run: |
if [[ "${{ matrix.shell }}" == "zsh" ]]; then
@@ -97,7 +133,7 @@ jobs:
fi
- name: Test install script (latest version)
- if: inputs.version == 'latest' || inputs.version == ''
+ if: steps.release_target.outputs.use_latest == 'true'
shell: bash
run: |
echo "Testing installation with auto-detected latest CLI version..."
@@ -127,13 +163,14 @@ jobs:
fi
- name: Test install script (specific version)
- if: inputs.version != 'latest' && inputs.version != ''
+ if: steps.release_target.outputs.use_latest != 'true'
shell: bash
run: |
- echo "Testing installation with version: ${{ inputs.version }}"
+ RELEASE_TAG="${{ steps.release_target.outputs.release_tag }}"
+ echo "Testing installation with version: ${RELEASE_TAG}"
# Test the install script with specific version
- bash install.sh ${{ inputs.version }}
+ bash install.sh "${RELEASE_TAG}"
# Verify installation
source ~/.bashrc 2>/dev/null || source ~/.zshrc 2>/dev/null || true
@@ -259,7 +296,12 @@ jobs:
# Test with custom directory using the same version as the workflow
export COMPOSIO_INSTALL="/tmp/custom-composio"
- bash install.sh ${{ inputs.version || '[email protected]' }}
+ if [[ "${{ steps.release_target.outputs.use_latest }}" == "true" ]]; then
+ bash install.sh
+ else
+ RELEASE_TAG="${{ steps.release_target.outputs.release_tag }}"
+ bash install.sh "${RELEASE_TAG}"
+ fi
# Verify custom installation
if [[ -f "/tmp/custom-composio/bin/composio" ]]; then
diff --git a/install.sh b/install.sh
index efa31f617..45a521da5 100644
--- a/install.sh
+++ b/install.sh
@@ -63,7 +63,7 @@ command -v curl >/dev/null ||
error 'curl is required to install Composio CLI'
if [[ $# -gt 1 ]]; then
- error 'Too many arguments, only 1 is allowed. You can specify a specific version to install. (e.g. "v0.1.24")'
+ error 'Too many arguments, only 1 is allowed. You can specify a specific release tag to install. (e.g. "@composio/[email protected]")'
fi
# Determine platform and architecture
@@ -117,16 +117,20 @@ if [[ $# = 0 ]]; then
'Darwin'*)
# BSD/MacOS: Use extended regex with -E
version=$(git ls-remote --tags "$github_repo" \
- | awk -F'/' '{print $3}' \
- | grep -E "^v\d+\.\d+\.\d+.*" \
+ | awk '{print $2}' \
+ | sed 's#^refs/tags/##' \
+ | sed 's#\^{}$##' \
+ | grep -E "^@composio/cli@\d+\.\d+\.\d+.*" \
| sort -V \
| tail -n1)
;;
*)
# Unix/Linux: Use Perl-compatible regex with -P
version=$(git ls-remote --tags "$github_repo" \
- | awk -F'/' '{print $3}' \
- | grep -P "^v\d+\.\d+\.\d+.*" \
+ | awk '{print $2}' \
+ | sed 's#^refs/tags/##' \
+ | sed 's#\^{}$##' \
+ | grep -P "^@composio/cli@\d+\.\d+\.\d+.*" \
| sort -V \
| tail -n1)
;;
diff --git a/package.json b/package.json
index 97266b969..7ab8871ca 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,7 @@
"workspaces": [
"ts/packages/core",
"ts/packages/json-schema-to-zod",
+ "ts/packages/cli",
"ts/packages/providers/*"
],
"scripts": {
diff --git a/ts/docs/internal/release.md b/ts/docs/internal/release.md
index c5930c5a9..55ad0406d 100644
--- a/ts/docs/internal/release.md
+++ b/ts/docs/internal/release.md
@@ -2,6 +2,43 @@
This document outlines the release processes for the Composio SDK. We support both automated releases through GitHub Actions and manual releases when needed.
+## CLI Binary Release Process
+
+The CLI binary release process is separate from npm publishing.
+
+- `@composio/cli` is marked private and is not published to npm via Changesets.
+- CLI binaries are built and published as GitHub Release assets by `.github/workflows/build-cli-binaries.yml`.
+- Install and upgrade flows (`install.sh` and `composio upgrade`) download binaries from GitHub Releases.
+
+### Triggers
+
+The CLI binary workflow supports two tag formats during the migration window:
+
+- Legacy: `v*`
+- New package-scoped tags: `@composio/cli@*`
+
+It also supports manual runs (`workflow_dispatch`).
+
+### Manual CLI Binary Release
+
+When running **Build CLI Binaries** manually:
+
+1. Enter a plain semver version (for example `1.2.3`).
+2. The workflow validates semver format.
+3. The workflow creates/publishes the release under tag `@composio/cli@<version>`.
+
+### What the workflow does
+
+1. Builds CLI binaries for Linux/macOS (x64 + arm64)
+2. Creates platform zip archives (`composio-<platform>.zip`)
+3. Publishes assets to the GitHub Release
+4. Runs `.github/workflows/cli.test-installation.yml` to validate installation paths and shell integration
+
+### Notes
+
+- The temporary dual-tag support (`v*` + `@composio/cli@*`) is intended to keep older installed CLIs upgradeable during migration.
+- After migration, legacy `v*` support can be removed.
+
## Automated Release Process
The automated release process is triggered when code is merged into the `main` branch or manually through GitHub Actions.
diff --git a/ts/packages/cli/README.md b/ts/packages/cli/README.md
index 2f8a7079c..5ddfd33de 100644
--- a/ts/packages/cli/README.md
+++ b/ts/packages/cli/README.md
@@ -66,6 +66,20 @@ Additionally, `composio upgrade` supports the following environment variables:
| COMPOSIO_GITHUB_TAG | The tag to use when fetching the Composio CLI binary from Github | latest |
| COMPOSIO_GITHUB_ACCESS_TOKEN | The access token for the GitHub API. Useful during development to avoid getting rate-limited by Github | None |
+### CLI binary release tags
+
+CLI binaries are published as GitHub release assets.
+
+- Current tag format: `@composio/cli@<semver>` (for example `@composio/[email protected]`)
+- Temporary compatibility: legacy `v<semver>` tags are also supported during migration
+- `composio upgrade` and `install.sh` can resolve either format during the compatibility window
+
+If you pin upgrades with `COMPOSIO_GITHUB_TAG`, prefer the package-scoped tag format:
+
+```bash
+COMPOSIO_GITHUB_TAG='@composio/[email protected]' composio upgrade
+```
+
## Caching
The CLI implements a file-based caching system for improved performance and offline capabilities.
diff --git a/ts/packages/cli/package.json b/ts/packages/cli/package.json
index ac3ef33c6..56883dd7a 100644
--- a/ts/packages/cli/package.json
+++ b/ts/packages/cli/package.json
@@ -3,6 +3,7 @@
"version": "0.1.24",
"description": "Composio CLI",
"main": "./dist/bin.mjs",
+ "private": true,
"bin": {
"composio": "./bin/composio.mjs"
},
diff --git a/ts/packages/cli/src/effects/compare-semver.ts b/ts/packages/cli/src/effects/compare-semver.ts
index 89fc8b656..7e40bca33 100644
--- a/ts/packages/cli/src/effects/compare-semver.ts
+++ b/ts/packages/cli/src/effects/compare-semver.ts
@@ -14,9 +14,10 @@ export const semverComparator = (
version2: string
): Effect.Effect<number, CompareSemverError, never> =>
Effect.gen(function* () {
- // Remove 'v' or `cli@` prefix if present
- const v1 = version1.replace(/^(v|cli@)/, '');
- const v2 = version2.replace(/^(v|cli@)/, '');
+ // Remove known release tag prefixes before semver comparison.
+ const stripPrefix = (version: string) => version.replace(/^(@composio\/cli@|v|cli@)/, '');
+ const v1 = stripPrefix(version1);
+ const v2 = stripPrefix(version2);
/**
* Comparison result of `semver.compare(clean1, clean2)`.
diff --git a/ts/packages/cli/src/services/upgrade-binary.ts b/ts/packages/cli/src/services/upgrade-binary.ts
index 090ce1477..2826357c4 100644
--- a/ts/packages/cli/src/services/upgrade-binary.ts
+++ b/ts/packages/cli/src/services/upgrade-binary.ts
@@ -25,12 +25,16 @@ export const CLI_BINARY_NAME = 'composio';
type GitHubRelease = {
tag_name: string;
+ prerelease?: boolean;
+ draft?: boolean;
assets: Array<{
name: string;
browser_download_url: string;
}>;
};
+const CLI_RELEASE_TAG_PATTERN = /^@composio\/cli@\d+\.\d+\.\d+.*$/;
+
// Service to manage CLI binary upgrades
export class UpgradeBinary extends Effect.Service<UpgradeBinary>()('services/UpgradeBinary', {
accessors: true,
@@ -43,63 +47,136 @@ export class UpgradeBinary extends Effect.Service<UpgradeBinary>()('services/Upg
/**
* Fetch latest release from GitHub
*/
- const fetchLatestRelease = (): Effect.Effect<GitHubRelease, UpgradeBinaryError, never> =>
+ const fetchGitHubJson = <T>({
+ url,
+ fetchErrorMessage,
+ parseErrorMessage,
+ }: {
+ url: string;
+ fetchErrorMessage: string;
+ parseErrorMessage: string;
+ }): Effect.Effect<T, UpgradeBinaryError, never> =>
Effect.gen(function* () {
- const urlSuffix = yield* githubConfig.TAG.pipe(
- Option.match({
- onNone: Effect.fn(function* () {
- yield* Effect.logDebug('No tag specified, using latest release');
- return 'latest';
- }),
- onSome: Effect.fn(function* (tag) {
- yield* Effect.logDebug(`Using tag: ${tag}`);
- return `tags/${tag}`;
- }),
- })
- );
-
- const url = `${githubConfig.API_BASE_URL}/repos/${githubConfig.OWNER}/${githubConfig.REPO}/releases/${urlSuffix}`;
yield* Effect.logDebug(`GET ${url}`);
- const response = yield* Effect.gen(function* () {
- const resp = yield* httpClient.get(url);
- if (resp.status < 200 || resp.status >= 300) {
- const json = yield* resp.json;
- const keyValues = Object.entries(json as object);
- const pretty = renderPrettyError(keyValues);
-
- return yield* Effect.fail(
- new UpgradeBinaryError({
- cause: `HTTP ${resp.status}\n${pretty}`,
- })
- );
- }
- return resp;
- }).pipe(
+ const response = yield* httpClient.get(url).pipe(
Effect.catchAll(error =>
Effect.fail(
new UpgradeBinaryError({
cause: error,
- message: `Failed to fetch ${urlSuffix} release from GitHub`,
+ message: fetchErrorMessage,
})
)
)
);
- const release = yield* Effect.gen(function* () {
- return yield* response.json;
- }).pipe(
+ if (response.status < 200 || response.status >= 300) {
+ const pretty = yield* response.json.pipe(
+ Effect.map(json => renderPrettyError(Object.entries(json as object))),
+ Effect.catchAll(() => Effect.succeed(''))
+ );
+
+ const cause = pretty ? `HTTP ${response.status}\n${pretty}` : `HTTP ${response.status}`;
+ return yield* Effect.fail(
+ new UpgradeBinaryError({
+ cause,
+ message: fetchErrorMessage,
+ })
+ );
+ }
+
+ return (yield* response.json.pipe(
Effect.catchAll(error =>
Effect.fail(
new UpgradeBinaryError({
cause: error,
- message: 'Failed to parse GitHub release JSON response',
+ message: parseErrorMessage,
})
)
)
- );
+ )) as T;
+ });
+
+ const fetchLatestRelease = (): Effect.Effect<GitHubRelease, UpgradeBinaryError, never> =>
+ Effect.gen(function* () {
+ const release = yield* githubConfig.TAG.pipe(
+ Option.match({
+ onNone: Effect.fn(function* () {
+ yield* Effect.logDebug(
+ 'No tag specified, resolving latest package-scoped CLI release'
+ );
+ const url = `${githubConfig.API_BASE_URL}/repos/${githubConfig.OWNER}/${githubConfig.REPO}/releases?per_page=100`;
+ const releases = yield* fetchGitHubJson<unknown>({
+ url,
+ fetchErrorMessage: 'Failed to fetch releases from GitHub',
+ parseErrorMessage: 'Failed to parse GitHub releases JSON response',
+ });
+
+ if (!Array.isArray(releases)) {
+ return yield* Effect.fail(
+ new UpgradeBinaryError({
+ cause: new Error('GitHub releases response was not an array'),
+ message: 'Unexpected response while resolving latest CLI release',
+ })
+ );
+ }
+
+ const cliReleases = releases.filter(
+ (release): release is GitHubRelease =>
+ typeof release === 'object' &&
+ release !== null &&
+ 'tag_name' in release &&
+ typeof release.tag_name === 'string' &&
+ ('prerelease' in release ? release.prerelease === false : true) &&
+ ('draft' in release ? release.draft === false : true) &&
+ CLI_RELEASE_TAG_PATTERN.test(release.tag_name)
+ );
+
+ if (cliReleases.length === 0) {
+ return yield* Effect.fail(
+ new UpgradeBinaryError({
+ cause: new Error('No package-scoped CLI releases found'),
+ message:
+ 'Failed to determine latest CLI release from @composio/cli tags on GitHub',
+ })
+ );
+ }
+
+ let latest = cliReleases[0];
+ for (const release of cliReleases.slice(1)) {
+ const comparison = yield* semverComparator(latest.tag_name, release.tag_name).pipe(
+ Effect.mapError(
+ error =>
+ new UpgradeBinaryError({
+ cause: error,
+ message: 'Failed to compare CLI release versions',
+ })
+ )
+ );
+
+ if (comparison < 0) {
+ latest = release;
+ }
+ }
- return release as GitHubRelease;
+ yield* Effect.logDebug(`Resolved latest CLI release tag: ${latest.tag_name}`);
+ return latest;
+ }),
+ onSome: Effect.fn(function* (tag) {
+ yield* Effect.logDebug(`Using tag: ${tag}`);
+ const encodedTag = encodeURIComponent(tag);
+ const url = `${githubConfig.API_BASE_URL}/repos/${githubConfig.OWNER}/${githubConfig.REPO}/releases/tags/${encodedTag}`;
+ const release = yield* fetchGitHubJson<GitHubRelease>({
+ url,
+ fetchErrorMessage: `Failed to fetch tags/${tag} release from GitHub`,
+ parseErrorMessage: 'Failed to parse GitHub release JSON response',
+ });
+
+ return release as GitHubRelease;
+ }),
+ })
+ );
+ return release;
});
/**
diff --git a/ts/packages/cli/test/src/services/upgrade-binary.test.ts b/ts/packages/cli/test/src/services/upgrade-binary.test.ts
new file mode 100644
index 000000000..df99444e3
--- /dev/null
+++ b/ts/packages/cli/test/src/services/upgrade-binary.test.ts
@@ -0,0 +1,192 @@
+import { describe, expect, it, vi } from '@effect/vitest';
+import { ConfigProvider, Effect, Layer } from 'effect';
+import { FetchHttpClient } from '@effect/platform';
+import { BunFileSystem } from '@effect/platform-bun';
+import { createServer, type IncomingMessage, type ServerResponse } from 'node:http';
+import { TerminalUI } from 'src/services/terminal-ui';
+import { UpgradeBinary, UpgradeBinaryError } from 'src/services/upgrade-binary';
+import { NodeOs } from 'src/services/node-os';
+
+const TerminalUINoop = Layer.succeed(
+ TerminalUI,
+ TerminalUI.of({
+ output: () => Effect.void,
+ intro: () => Effect.void,
+ outro: () => Effect.void,
+ log: {
+ info: () => Effect.void,
+ success: () => Effect.void,
+ warn: () => Effect.void,
+ error: () => Effect.void,
+ step: () => Effect.void,
+ message: () => Effect.void,
+ },
+ note: () => Effect.void,
+ select: (_message, options) => Effect.succeed(options[0].value),
+ confirm: () => Effect.succeed(true),
+ withSpinner: (_message, effect) => effect,
+ useMakeSpinner: (_message, use) =>
+ use({
+ message: () => Effect.void,
+ stop: () => Effect.void,
+ error: () => Effect.void,
+ }),
+ })
+);
+
+const NodeOsTest = Layer.succeed(
+ NodeOs,
+ new NodeOs({
+ homedir: '/tmp',
+ platform: 'darwin',
+ arch: 'arm64',
+ })
+);
+
+const runUpgrade = (configEntries: ReadonlyArray<[string, string]>) =>
+ Effect.gen(function* () {
+ const service = yield* UpgradeBinary;
+ return yield* Effect.flip(service.upgrade());
+ }).pipe(
+ Effect.provide(UpgradeBinary.Default),
+ Effect.provide(FetchHttpClient.layer),
+ Effect.provide(BunFileSystem.layer),
+ Effect.provide(TerminalUINoop),
+ Effect.provide(NodeOsTest),
+ Effect.withConfigProvider(ConfigProvider.fromMap(new Map(configEntries))),
+ Effect.scoped,
+ Effect.runPromise
+ );
+
+const withHttpServer = async (
+ handler: (req: IncomingMessage, res: ServerResponse) => void,
+ run: (apiBaseUrl: string) => Promise<void>
+) => {
+ const server = createServer(handler);
+
+ await new Promise<void>((resolve, reject) => {
+ server.once('error', reject);
+ server.listen({ port: 0, host: '127.0.0.1' }, () => {
+ server.off('error', reject);
+ resolve();
+ });
+ });
+
+ const address = server.address();
+ if (address === null || typeof address === 'string') {
+ throw new Error('Failed to bind test server to an ephemeral port');
+ }
+
+ const apiBaseUrl = `http://127.0.0.1:${address.port}`;
+
+ try {
+ await run(apiBaseUrl);
+ } finally {
+ await new Promise<void>((resolve, reject) => {
+ server.close(error => {
+ if (error) {
+ reject(error);
+ return;
+ }
+ resolve();
+ });
+ });
+ }
+};
+
+describe('UpgradeBinary', () => {
+ it('wraps non-2xx releases fetch failures with fetch context (no tag branch)', async () => {
+ vi.stubGlobal('Bun', { which: vi.fn(() => null) });
+
+ try {
+ await withHttpServer(
+ (_req, res) => {
+ res.writeHead(500, { 'content-type': 'application/json' });
+ res.end(JSON.stringify({ message: 'rate limited' }));
+ },
+ async apiBaseUrl => {
+ const error = await runUpgrade([
+ ['GITHUB_API_BASE_URL', apiBaseUrl],
+ ['GITHUB_OWNER', 'test-owner'],
+ ['GITHUB_REPO', 'test-repo'],
+ ]);
+
+ expect(error).toBeInstanceOf(UpgradeBinaryError);
+ if (!(error instanceof UpgradeBinaryError)) {
+ throw error;
+ }
+ expect(error.message).toBe('Failed to fetch releases from GitHub');
+ expect(String(error.cause)).toContain('HTTP 500');
+ }
+ );
+ } finally {
+ vi.unstubAllGlobals();
+ vi.restoreAllMocks();
+ }
+ });
+
+ it('wraps tagged release JSON parse failures with parse context (tag branch)', async () => {
+ vi.stubGlobal('Bun', { which: vi.fn(() => null) });
+
+ try {
+ await withHttpServer(
+ (_req, res) => {
+ res.writeHead(200, { 'content-type': 'application/json' });
+ res.end('not-json');
+ },
+ async apiBaseUrl => {
+ const error = await runUpgrade([
+ ['GITHUB_API_BASE_URL', apiBaseUrl],
+ ['GITHUB_OWNER', 'test-owner'],
+ ['GITHUB_REPO', 'test-repo'],
+ ['GITHUB_TAG', 'v9.9.9'],
+ ]);
+
+ expect(error).toBeInstanceOf(UpgradeBinaryError);
+ if (!(error instanceof UpgradeBinaryError)) {
+ throw error;
+ }
+ expect(error.message).toBe('Failed to parse GitHub release JSON response');
+ }
+ );
+ } finally {
+ vi.unstubAllGlobals();
+ vi.restoreAllMocks();
+ }
+ });
+
+ it('URL-encodes slash-containing tags in tagged release request path', async () => {
+ vi.stubGlobal('Bun', { which: vi.fn(() => null) });
+ let receivedPath = '';
+
+ try {
+ await withHttpServer(
+ (req, res) => {
+ receivedPath = req.url ?? '';
+ res.writeHead(500, { 'content-type': 'application/json' });
+ res.end(JSON.stringify({ message: 'forced failure' }));
+ },
+ async apiBaseUrl => {
+ const tag = '@composio/[email protected]';
+ const error = await runUpgrade([
+ ['GITHUB_API_BASE_URL', apiBaseUrl],
+ ['GITHUB_OWNER', 'test-owner'],
+ ['GITHUB_REPO', 'test-repo'],
+ ['GITHUB_TAG', tag],
+ ]);
+
+ expect(error).toBeInstanceOf(UpgradeBinaryError);
+ if (!(error instanceof UpgradeBinaryError)) {
+ throw error;
+ }
+ expect(receivedPath).toBe(
+ `/repos/test-owner/test-repo/releases/tags/${encodeURIComponent(tag)}`
+ );
+ }
+ );
+ } finally {
+ vi.unstubAllGlobals();
+ vi.restoreAllMocks();
+ }
+ });
+});