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)
Co-authored-by: Cursor <cursoragent@cursor.com>
Musthaq Ahamad committed
Feb 25, 2026 at 16:29 UTC
4fda636aba7ed01a8b3dad9863cd51301d8c8625
10 files changed
+443
-61
.github/workflows/build-cli-binaries.yml
+20
-7
@@ -3,13 +3,14 @@ name: Build CLI Binaries
3
on:
4
push:
5
tags:
6
+ # Temporary compatibility window: support both legacy v* and package-scoped CLI tags.
7
- 'v*'
8
+ - '@composio/cli@*'
9
workflow_dispatch:
10
inputs:
11
version:
10
- description: 'Version to build (e.g., v1.0.0)'
11
- required: false
12
- default: 'dev'
12
+ description: 'Semver version to release (e.g., 1.0.0)'
13
+ required: true
14
15
permissions:
16
contents: write
@@ -38,6 +39,16 @@ jobs:
39
- name: Checkout
40
uses: actions/checkout@v6
41
42
+ - name: Validate manual version input
43
+ if: github.event_name == 'workflow_dispatch'
44
+ run: |
45
+ version="${{ inputs.version }}"
46
+ if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
47
+ echo "Invalid semver version: '$version'"
48
+ echo "Expected format like: 1.2.3, 1.2.3-beta.1, 1.2.3+build.7"
49
+ exit 1
50
+ fi
51
+
52
- name: Setup Node.js, pnpm, Bun
53
uses: ./.github/actions/setup-node-pnpm-bun
54
@@ -97,8 +108,8 @@ jobs:
108
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
109
uses: softprops/action-gh-release@v2
110
with:
100
- tag_name: ${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref_name }}
101
- name: ${{ github.event_name == 'workflow_dispatch' && format('CLI {0} (Manual Build)', inputs.version) || github.ref_name }}
111
+ tag_name: ${{ github.event_name == 'workflow_dispatch' && format('@composio/cli@{0}', inputs.version) || github.ref_name }}
112
+ name: ${{ github.event_name == 'workflow_dispatch' && format('CLI @composio/cli@{0} (Manual Build)', inputs.version) || github.ref_name }}
113
files: |
114
ts/packages/cli/dist/binaries/${{ matrix.artifact }}.zip
115
draft: false
@@ -114,7 +125,7 @@ jobs:
125
if: always() && !cancelled() && (startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch')
126
uses: ./.github/workflows/cli.test-installation.yml
127
with:
117
- version: ${{ inputs.version || github.ref_name }}
128
+ version: ${{ github.event_name == 'workflow_dispatch' && format('@composio/cli@{0}', inputs.version) || github.ref_name }}
129
130
create-install-instructions:
131
name: Create Install Instructions
@@ -128,6 +139,7 @@ jobs:
139
140
- name: Create installation README
141
run: |
142
+ RELEASE_TAG="${{ github.event_name == 'workflow_dispatch' && format('@composio/cli@{0}', inputs.version) || github.ref_name }}"
143
cat > INSTALL.md << 'EOF'
144
# Composio CLI Installation
145
@@ -140,7 +152,7 @@ jobs:
152
153
### Install specific version
154
```bash
143
- curl -fsSL https://raw.githubusercontent.com/ComposioHQ/composio/main/install.sh | bash -s -- ${{ github.ref_name }}
155
+ curl -fsSL https://raw.githubusercontent.com/ComposioHQ/composio/main/install.sh | bash -s -- RELEASE_TAG_PLACEHOLDER
156
```
157
158
## Manual Installation
@@ -175,6 +187,7 @@ jobs:
187
188
Windows support coming soon!
189
EOF
190
+ sed -i.bak "s|RELEASE_TAG_PLACEHOLDER|$RELEASE_TAG|g" INSTALL.md && rm -f INSTALL.md.bak
191
192
- name: Upload install instructions
193
uses: actions/upload-artifact@v6
.github/workflows/cli.test-installation.yml
+51
-9
@@ -3,17 +3,18 @@ name: Test Installation
3
on:
4
push:
5
tags:
6
+ # Temporary compatibility window: support both legacy v* and package-scoped CLI tags.
7
- 'v*'
8
+ - '@composio/cli@*'
9
workflow_dispatch:
10
inputs:
11
version:
10
- description: 'Version to test (e.g., v1.0.0)'
11
- required: false
12
- default: 'latest'
12
+ description: 'Semver version to test (e.g., 1.0.0)'
13
+ required: true
14
workflow_call:
15
inputs:
16
version:
16
- description: 'Version to test'
17
+ description: 'Release tag or semver version to test'
18
required: false
19
default: 'latest'
20
type: string
@@ -69,6 +70,41 @@ jobs:
70
- name: Checkout
71
uses: actions/checkout@v6
72
73
+ - name: Resolve and validate target release
74
+ id: release_target
75
+ shell: bash
76
+ run: |
77
+ raw_input="${{ inputs.version }}"
78
+ if [[ -z "$raw_input" || "$raw_input" == "latest" ]]; then
79
+ echo "use_latest=true" >> "$GITHUB_OUTPUT"
80
+ echo "release_tag=" >> "$GITHUB_OUTPUT"
81
+ exit 0
82
+ fi
83
+
84
+ # For manual runs, require semver input and build the release tag.
85
+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
86
+ if [[ ! "$raw_input" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
87
+ echo "Invalid semver version: '$raw_input'"
88
+ echo "Expected format like: 1.2.3, 1.2.3-beta.1, 1.2.3+build.7"
89
+ exit 1
90
+ fi
91
+ echo "use_latest=false" >> "$GITHUB_OUTPUT"
92
+ echo "release_tag=@composio/cli@$raw_input" >> "$GITHUB_OUTPUT"
93
+ exit 0
94
+ fi
95
+
96
+ # For workflow_call / push, accept a full package tag, semver, or legacy v* tag.
97
+ if [[ "$raw_input" =~ ^@composio/cli@ ]]; then
98
+ echo "use_latest=false" >> "$GITHUB_OUTPUT"
99
+ echo "release_tag=$raw_input" >> "$GITHUB_OUTPUT"
100
+ elif [[ "$raw_input" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
101
+ echo "use_latest=false" >> "$GITHUB_OUTPUT"
102
+ echo "release_tag=@composio/cli@$raw_input" >> "$GITHUB_OUTPUT"
103
+ else
104
+ echo "use_latest=false" >> "$GITHUB_OUTPUT"
105
+ echo "release_tag=$raw_input" >> "$GITHUB_OUTPUT"
106
+ fi
107
+
108
- name: Setup shell environment
109
run: |
110
if [[ "${{ matrix.shell }}" == "zsh" ]]; then
@@ -97,7 +133,7 @@ jobs:
133
fi
134
135
- name: Test install script (latest version)
100
- if: inputs.version == 'latest' || inputs.version == ''
136
+ if: steps.release_target.outputs.use_latest == 'true'
137
shell: bash
138
run: |
139
echo "Testing installation with auto-detected latest CLI version..."
@@ -127,13 +163,14 @@ jobs:
163
fi
164
165
- name: Test install script (specific version)
130
- if: inputs.version != 'latest' && inputs.version != ''
166
+ if: steps.release_target.outputs.use_latest != 'true'
167
shell: bash
168
run: |
133
- echo "Testing installation with version: ${{ inputs.version }}"
169
+ RELEASE_TAG="${{ steps.release_target.outputs.release_tag }}"
170
+ echo "Testing installation with version: ${RELEASE_TAG}"
171
172
# Test the install script with specific version
136
- bash install.sh ${{ inputs.version }}
173
+ bash install.sh "${RELEASE_TAG}"
174
175
# Verify installation
176
source ~/.bashrc 2>/dev/null || source ~/.zshrc 2>/dev/null || true
@@ -259,7 +296,12 @@ jobs:
296
297
# Test with custom directory using the same version as the workflow
298
export COMPOSIO_INSTALL="/tmp/custom-composio"
262
- bash install.sh ${{ inputs.version || 'cli@0.1.24-2' }}
299
+ if [[ "${{ steps.release_target.outputs.use_latest }}" == "true" ]]; then
300
+ bash install.sh
301
+ else
302
+ RELEASE_TAG="${{ steps.release_target.outputs.release_tag }}"
303
+ bash install.sh "${RELEASE_TAG}"
304
+ fi
305
306
# Verify custom installation
307
if [[ -f "/tmp/custom-composio/bin/composio" ]]; then
install.sh
+9
-5
@@ -63,7 +63,7 @@ command -v curl >/dev/null ||
63
error 'curl is required to install Composio CLI'
64
65
if [[ $# -gt 1 ]]; then
66
- error 'Too many arguments, only 1 is allowed. You can specify a specific version to install. (e.g. "v0.1.24")'
66
+ error 'Too many arguments, only 1 is allowed. You can specify a specific release tag to install. (e.g. "@composio/cli@0.1.24")'
67
fi
68
69
# Determine platform and architecture
@@ -117,16 +117,20 @@ if [[ $# = 0 ]]; then
117
'Darwin'*)
118
# BSD/MacOS: Use extended regex with -E
119
version=$(git ls-remote --tags "$github_repo" \
120
- | awk -F'/' '{print $3}' \
121
- | grep -E "^v\d+\.\d+\.\d+.*" \
120
+ | awk '{print $2}' \
121
+ | sed 's#^refs/tags/##' \
122
+ | sed 's#\^{}$##' \
123
+ | grep -E "^@composio/cli@\d+\.\d+\.\d+.*" \
124
| sort -V \
125
| tail -n1)
126
;;
127
*)
128
# Unix/Linux: Use Perl-compatible regex with -P
129
version=$(git ls-remote --tags "$github_repo" \
128
- | awk -F'/' '{print $3}' \
129
- | grep -P "^v\d+\.\d+\.\d+.*" \
130
+ | awk '{print $2}' \
131
+ | sed 's#^refs/tags/##' \
132
+ | sed 's#\^{}$##' \
133
+ | grep -P "^@composio/cli@\d+\.\d+\.\d+.*" \
134
| sort -V \
135
| tail -n1)
136
;;
package.json
+1
@@ -6,6 +6,7 @@
6
"workspaces": [
7
"ts/packages/core",
8
"ts/packages/json-schema-to-zod",
9
+ "ts/packages/cli",
10
"ts/packages/providers/*"
11
],
12
"scripts": {
ts/docs/internal/release.md
+37
@@ -2,6 +2,43 @@
2
3
This document outlines the release processes for the Composio SDK. We support both automated releases through GitHub Actions and manual releases when needed.
4
5
+## CLI Binary Release Process
6
+
7
+The CLI binary release process is separate from npm publishing.
8
+
9
+- `@composio/cli` is marked private and is not published to npm via Changesets.
10
+- CLI binaries are built and published as GitHub Release assets by `.github/workflows/build-cli-binaries.yml`.
11
+- Install and upgrade flows (`install.sh` and `composio upgrade`) download binaries from GitHub Releases.
12
+
13
+### Triggers
14
+
15
+The CLI binary workflow supports two tag formats during the migration window:
16
+
17
+- Legacy: `v*`
18
+- New package-scoped tags: `@composio/cli@*`
19
+
20
+It also supports manual runs (`workflow_dispatch`).
21
+
22
+### Manual CLI Binary Release
23
+
24
+When running **Build CLI Binaries** manually:
25
+
26
+1. Enter a plain semver version (for example `1.2.3`).
27
+2. The workflow validates semver format.
28
+3. The workflow creates/publishes the release under tag `@composio/cli@<version>`.
29
+
30
+### What the workflow does
31
+
32
+1. Builds CLI binaries for Linux/macOS (x64 + arm64)
33
+2. Creates platform zip archives (`composio-<platform>.zip`)
34
+3. Publishes assets to the GitHub Release
35
+4. Runs `.github/workflows/cli.test-installation.yml` to validate installation paths and shell integration
36
+
37
+### Notes
38
+
39
+- The temporary dual-tag support (`v*` + `@composio/cli@*`) is intended to keep older installed CLIs upgradeable during migration.
40
+- After migration, legacy `v*` support can be removed.
41
+
42
## Automated Release Process
43
44
The automated release process is triggered when code is merged into the `main` branch or manually through GitHub Actions.
ts/packages/cli/README.md
+14
@@ -66,6 +66,20 @@ Additionally, `composio upgrade` supports the following environment variables:
66
| COMPOSIO_GITHUB_TAG | The tag to use when fetching the Composio CLI binary from Github | latest |
67
| COMPOSIO_GITHUB_ACCESS_TOKEN | The access token for the GitHub API. Useful during development to avoid getting rate-limited by Github | None |
68
69
+### CLI binary release tags
70
+
71
+CLI binaries are published as GitHub release assets.
72
+
73
+- Current tag format: `@composio/cli@<semver>` (for example `@composio/cli@0.1.24`)
74
+- Temporary compatibility: legacy `v<semver>` tags are also supported during migration
75
+- `composio upgrade` and `install.sh` can resolve either format during the compatibility window
76
+
77
+If you pin upgrades with `COMPOSIO_GITHUB_TAG`, prefer the package-scoped tag format:
78
+
79
+```bash
80
+COMPOSIO_GITHUB_TAG='@composio/cli@0.1.24' composio upgrade
81
+```
82
+
83
## Caching
84
85
The CLI implements a file-based caching system for improved performance and offline capabilities.
ts/packages/cli/package.json
+1
@@ -3,6 +3,7 @@
3
"version": "0.1.24",
4
"description": "Composio CLI",
5
"main": "./dist/bin.mjs",
6
+ "private": true,
7
"bin": {
8
"composio": "./bin/composio.mjs"
9
},
ts/packages/cli/src/effects/compare-semver.ts
+4
-3
@@ -14,9 +14,10 @@ export const semverComparator = (
14
version2: string
15
): Effect.Effect<number, CompareSemverError, never> =>
16
Effect.gen(function* () {
17
- // Remove 'v' or `cli@` prefix if present
18
- const v1 = version1.replace(/^(v|cli@)/, '');
19
- const v2 = version2.replace(/^(v|cli@)/, '');
17
+ // Remove known release tag prefixes before semver comparison.
18
+ const stripPrefix = (version: string) => version.replace(/^(@composio\/cli@|v|cli@)/, '');
19
+ const v1 = stripPrefix(version1);
20
+ const v2 = stripPrefix(version2);
21
22
/**
23
* Comparison result of `semver.compare(clean1, clean2)`.
ts/packages/cli/src/services/upgrade-binary.ts
+114
-37
@@ -25,12 +25,16 @@ export const CLI_BINARY_NAME = 'composio';
25
26
type GitHubRelease = {
27
tag_name: string;
28
+ prerelease?: boolean;
29
+ draft?: boolean;
30
assets: Array<{
31
name: string;
32
browser_download_url: string;
33
}>;
34
};
35
36
+const CLI_RELEASE_TAG_PATTERN = /^@composio\/cli@\d+\.\d+\.\d+.*$/;
37
+
38
// Service to manage CLI binary upgrades
39
export class UpgradeBinary extends Effect.Service<UpgradeBinary>()('services/UpgradeBinary', {
40
accessors: true,
@@ -43,63 +47,136 @@ export class UpgradeBinary extends Effect.Service<UpgradeBinary>()('services/Upg
47
/**
48
* Fetch latest release from GitHub
49
*/
46
- const fetchLatestRelease = (): Effect.Effect<GitHubRelease, UpgradeBinaryError, never> =>
50
+ const fetchGitHubJson = <T>({
51
+ url,
52
+ fetchErrorMessage,
53
+ parseErrorMessage,
54
+ }: {
55
+ url: string;
56
+ fetchErrorMessage: string;
57
+ parseErrorMessage: string;
58
+ }): Effect.Effect<T, UpgradeBinaryError, never> =>
59
Effect.gen(function* () {
48
- const urlSuffix = yield* githubConfig.TAG.pipe(
49
- Option.match({
50
- onNone: Effect.fn(function* () {
51
- yield* Effect.logDebug('No tag specified, using latest release');
52
- return 'latest';
53
- }),
54
- onSome: Effect.fn(function* (tag) {
55
- yield* Effect.logDebug(`Using tag: ${tag}`);
56
- return `tags/${tag}`;
57
- }),
58
- })
59
- );
60
-
61
- const url = `${githubConfig.API_BASE_URL}/repos/${githubConfig.OWNER}/${githubConfig.REPO}/releases/${urlSuffix}`;
60
yield* Effect.logDebug(`GET ${url}`);
61
64
- const response = yield* Effect.gen(function* () {
65
- const resp = yield* httpClient.get(url);
66
- if (resp.status < 200 || resp.status >= 300) {
67
- const json = yield* resp.json;
68
- const keyValues = Object.entries(json as object);
69
- const pretty = renderPrettyError(keyValues);
70
-
71
- return yield* Effect.fail(
72
- new UpgradeBinaryError({
73
- cause: `HTTP ${resp.status}\n${pretty}`,
74
- })
75
- );
76
- }
77
- return resp;
78
- }).pipe(
62
+ const response = yield* httpClient.get(url).pipe(
63
Effect.catchAll(error =>
64
Effect.fail(
65
new UpgradeBinaryError({
66
cause: error,
83
- message: `Failed to fetch ${urlSuffix} release from GitHub`,
67
+ message: fetchErrorMessage,
68
})
69
)
70
)
71
);
72
89
- const release = yield* Effect.gen(function* () {
90
- return yield* response.json;
91
- }).pipe(
73
+ if (response.status < 200 || response.status >= 300) {
74
+ const pretty = yield* response.json.pipe(
75
+ Effect.map(json => renderPrettyError(Object.entries(json as object))),
76
+ Effect.catchAll(() => Effect.succeed(''))
77
+ );
78
+
79
+ const cause = pretty ? `HTTP ${response.status}\n${pretty}` : `HTTP ${response.status}`;
80
+ return yield* Effect.fail(
81
+ new UpgradeBinaryError({
82
+ cause,
83
+ message: fetchErrorMessage,
84
+ })
85
+ );
86
+ }
87
+
88
+ return (yield* response.json.pipe(
89
Effect.catchAll(error =>
90
Effect.fail(
91
new UpgradeBinaryError({
92
cause: error,
96
- message: 'Failed to parse GitHub release JSON response',
93
+ message: parseErrorMessage,
94
})
95
)
96
)
100
- );
97
+ )) as T;
98
+ });
99
+
100
+ const fetchLatestRelease = (): Effect.Effect<GitHubRelease, UpgradeBinaryError, never> =>
101
+ Effect.gen(function* () {
102
+ const release = yield* githubConfig.TAG.pipe(
103
+ Option.match({
104
+ onNone: Effect.fn(function* () {
105
+ yield* Effect.logDebug(
106
+ 'No tag specified, resolving latest package-scoped CLI release'
107
+ );
108
+ const url = `${githubConfig.API_BASE_URL}/repos/${githubConfig.OWNER}/${githubConfig.REPO}/releases?per_page=100`;
109
+ const releases = yield* fetchGitHubJson<unknown>({
110
+ url,
111
+ fetchErrorMessage: 'Failed to fetch releases from GitHub',
112
+ parseErrorMessage: 'Failed to parse GitHub releases JSON response',
113
+ });
114
+
115
+ if (!Array.isArray(releases)) {
116
+ return yield* Effect.fail(
117
+ new UpgradeBinaryError({
118
+ cause: new Error('GitHub releases response was not an array'),
119
+ message: 'Unexpected response while resolving latest CLI release',
120
+ })
121
+ );
122
+ }
123
+
124
+ const cliReleases = releases.filter(
125
+ (release): release is GitHubRelease =>
126
+ typeof release === 'object' &&
127
+ release !== null &&
128
+ 'tag_name' in release &&
129
+ typeof release.tag_name === 'string' &&
130
+ ('prerelease' in release ? release.prerelease === false : true) &&
131
+ ('draft' in release ? release.draft === false : true) &&
132
+ CLI_RELEASE_TAG_PATTERN.test(release.tag_name)
133
+ );
134
+
135
+ if (cliReleases.length === 0) {
136
+ return yield* Effect.fail(
137
+ new UpgradeBinaryError({
138
+ cause: new Error('No package-scoped CLI releases found'),
139
+ message:
140
+ 'Failed to determine latest CLI release from @composio/cli tags on GitHub',
141
+ })
142
+ );
143
+ }
144
+
145
+ let latest = cliReleases[0];
146
+ for (const release of cliReleases.slice(1)) {
147
+ const comparison = yield* semverComparator(latest.tag_name, release.tag_name).pipe(
148
+ Effect.mapError(
149
+ error =>
150
+ new UpgradeBinaryError({
151
+ cause: error,
152
+ message: 'Failed to compare CLI release versions',
153
+ })
154
+ )
155
+ );
156
+
157
+ if (comparison < 0) {
158
+ latest = release;
159
+ }
160
+ }
161
102
- return release as GitHubRelease;
162
+ yield* Effect.logDebug(`Resolved latest CLI release tag: ${latest.tag_name}`);
163
+ return latest;
164
+ }),
165
+ onSome: Effect.fn(function* (tag) {
166
+ yield* Effect.logDebug(`Using tag: ${tag}`);
167
+ const encodedTag = encodeURIComponent(tag);
168
+ const url = `${githubConfig.API_BASE_URL}/repos/${githubConfig.OWNER}/${githubConfig.REPO}/releases/tags/${encodedTag}`;
169
+ const release = yield* fetchGitHubJson<GitHubRelease>({
170
+ url,
171
+ fetchErrorMessage: `Failed to fetch tags/${tag} release from GitHub`,
172
+ parseErrorMessage: 'Failed to parse GitHub release JSON response',
173
+ });
174
+
175
+ return release as GitHubRelease;
176
+ }),
177
+ })
178
+ );
179
+ return release;
180
});
181
182
/**
ts/packages/cli/test/src/services/upgrade-binary.test.ts
new
+192
@@ -0,0 +1,192 @@
1
+import { describe, expect, it, vi } from '@effect/vitest';
2
+import { ConfigProvider, Effect, Layer } from 'effect';
3
+import { FetchHttpClient } from '@effect/platform';
4
+import { BunFileSystem } from '@effect/platform-bun';
5
+import { createServer, type IncomingMessage, type ServerResponse } from 'node:http';
6
+import { TerminalUI } from 'src/services/terminal-ui';
7
+import { UpgradeBinary, UpgradeBinaryError } from 'src/services/upgrade-binary';
8
+import { NodeOs } from 'src/services/node-os';
9
+
10
+const TerminalUINoop = Layer.succeed(
11
+ TerminalUI,
12
+ TerminalUI.of({
13
+ output: () => Effect.void,
14
+ intro: () => Effect.void,
15
+ outro: () => Effect.void,
16
+ log: {
17
+ info: () => Effect.void,
18
+ success: () => Effect.void,
19
+ warn: () => Effect.void,
20
+ error: () => Effect.void,
21
+ step: () => Effect.void,
22
+ message: () => Effect.void,
23
+ },
24
+ note: () => Effect.void,
25
+ select: (_message, options) => Effect.succeed(options[0].value),
26
+ confirm: () => Effect.succeed(true),
27
+ withSpinner: (_message, effect) => effect,
28
+ useMakeSpinner: (_message, use) =>
29
+ use({
30
+ message: () => Effect.void,
31
+ stop: () => Effect.void,
32
+ error: () => Effect.void,
33
+ }),
34
+ })
35
+);
36
+
37
+const NodeOsTest = Layer.succeed(
38
+ NodeOs,
39
+ new NodeOs({
40
+ homedir: '/tmp',
41
+ platform: 'darwin',
42
+ arch: 'arm64',
43
+ })
44
+);
45
+
46
+const runUpgrade = (configEntries: ReadonlyArray<[string, string]>) =>
47
+ Effect.gen(function* () {
48
+ const service = yield* UpgradeBinary;
49
+ return yield* Effect.flip(service.upgrade());
50
+ }).pipe(
51
+ Effect.provide(UpgradeBinary.Default),
52
+ Effect.provide(FetchHttpClient.layer),
53
+ Effect.provide(BunFileSystem.layer),
54
+ Effect.provide(TerminalUINoop),
55
+ Effect.provide(NodeOsTest),
56
+ Effect.withConfigProvider(ConfigProvider.fromMap(new Map(configEntries))),
57
+ Effect.scoped,
58
+ Effect.runPromise
59
+ );
60
+
61
+const withHttpServer = async (
62
+ handler: (req: IncomingMessage, res: ServerResponse) => void,
63
+ run: (apiBaseUrl: string) => Promise<void>
64
+) => {
65
+ const server = createServer(handler);
66
+
67
+ await new Promise<void>((resolve, reject) => {
68
+ server.once('error', reject);
69
+ server.listen({ port: 0, host: '127.0.0.1' }, () => {
70
+ server.off('error', reject);
71
+ resolve();
72
+ });
73
+ });
74
+
75
+ const address = server.address();
76
+ if (address === null || typeof address === 'string') {
77
+ throw new Error('Failed to bind test server to an ephemeral port');
78
+ }
79
+
80
+ const apiBaseUrl = `http://127.0.0.1:${address.port}`;
81
+
82
+ try {
83
+ await run(apiBaseUrl);
84
+ } finally {
85
+ await new Promise<void>((resolve, reject) => {
86
+ server.close(error => {
87
+ if (error) {
88
+ reject(error);
89
+ return;
90
+ }
91
+ resolve();
92
+ });
93
+ });
94
+ }
95
+};
96
+
97
+describe('UpgradeBinary', () => {
98
+ it('wraps non-2xx releases fetch failures with fetch context (no tag branch)', async () => {
99
+ vi.stubGlobal('Bun', { which: vi.fn(() => null) });
100
+
101
+ try {
102
+ await withHttpServer(
103
+ (_req, res) => {
104
+ res.writeHead(500, { 'content-type': 'application/json' });
105
+ res.end(JSON.stringify({ message: 'rate limited' }));
106
+ },
107
+ async apiBaseUrl => {
108
+ const error = await runUpgrade([
109
+ ['GITHUB_API_BASE_URL', apiBaseUrl],
110
+ ['GITHUB_OWNER', 'test-owner'],
111
+ ['GITHUB_REPO', 'test-repo'],
112
+ ]);
113
+
114
+ expect(error).toBeInstanceOf(UpgradeBinaryError);
115
+ if (!(error instanceof UpgradeBinaryError)) {
116
+ throw error;
117
+ }
118
+ expect(error.message).toBe('Failed to fetch releases from GitHub');
119
+ expect(String(error.cause)).toContain('HTTP 500');
120
+ }
121
+ );
122
+ } finally {
123
+ vi.unstubAllGlobals();
124
+ vi.restoreAllMocks();
125
+ }
126
+ });
127
+
128
+ it('wraps tagged release JSON parse failures with parse context (tag branch)', async () => {
129
+ vi.stubGlobal('Bun', { which: vi.fn(() => null) });
130
+
131
+ try {
132
+ await withHttpServer(
133
+ (_req, res) => {
134
+ res.writeHead(200, { 'content-type': 'application/json' });
135
+ res.end('not-json');
136
+ },
137
+ async apiBaseUrl => {
138
+ const error = await runUpgrade([
139
+ ['GITHUB_API_BASE_URL', apiBaseUrl],
140
+ ['GITHUB_OWNER', 'test-owner'],
141
+ ['GITHUB_REPO', 'test-repo'],
142
+ ['GITHUB_TAG', 'v9.9.9'],
143
+ ]);
144
+
145
+ expect(error).toBeInstanceOf(UpgradeBinaryError);
146
+ if (!(error instanceof UpgradeBinaryError)) {
147
+ throw error;
148
+ }
149
+ expect(error.message).toBe('Failed to parse GitHub release JSON response');
150
+ }
151
+ );
152
+ } finally {
153
+ vi.unstubAllGlobals();
154
+ vi.restoreAllMocks();
155
+ }
156
+ });
157
+
158
+ it('URL-encodes slash-containing tags in tagged release request path', async () => {
159
+ vi.stubGlobal('Bun', { which: vi.fn(() => null) });
160
+ let receivedPath = '';
161
+
162
+ try {
163
+ await withHttpServer(
164
+ (req, res) => {
165
+ receivedPath = req.url ?? '';
166
+ res.writeHead(500, { 'content-type': 'application/json' });
167
+ res.end(JSON.stringify({ message: 'forced failure' }));
168
+ },
169
+ async apiBaseUrl => {
170
+ const tag = '@composio/cli@0.1.24';
171
+ const error = await runUpgrade([
172
+ ['GITHUB_API_BASE_URL', apiBaseUrl],
173
+ ['GITHUB_OWNER', 'test-owner'],
174
+ ['GITHUB_REPO', 'test-repo'],
175
+ ['GITHUB_TAG', tag],
176
+ ]);
177
+
178
+ expect(error).toBeInstanceOf(UpgradeBinaryError);
179
+ if (!(error instanceof UpgradeBinaryError)) {
180
+ throw error;
181
+ }
182
+ expect(receivedPath).toBe(
183
+ `/repos/test-owner/test-repo/releases/tags/${encodeURIComponent(tag)}`
184
+ );
185
+ }
186
+ );
187
+ } finally {
188
+ vi.unstubAllGlobals();
189
+ vi.restoreAllMocks();
190
+ }
191
+ });
192
+});