Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(install): resolve latest CLI release from assets (#3411)
Rahul Tarak99324d5a0d03
diff --git a/.github/workflows/cli.test-installation.yml b/.github/workflows/cli.test-installation.ymlindex b14e1bfb0..0ec5375e1 100644--- a/.github/workflows/cli.test-installation.yml+++ b/.github/workflows/cli.test-installation.yml@@ -20,8 +20,19 @@ on:type: stringjobs:+ install-script-unit-tests:+ name: Install Script Unit Tests+ runs-on: ubuntu-latest+ steps:+ - name: Checkout+ uses: actions/checkout@v6++ - name: Test release resolution fallback+ run: bash test/install-sh-release-resolution.test.sh+test-install-script:name: Test Install Script+ needs: install-script-unit-testsruns-on: ${{ matrix.os }}strategy:fail-fast: false@@ -547,7 +558,7 @@ jobs:summary:name: Installation Test Summary- needs: [test-install-script, test-npm-fallback, test-architecture-detection, test-prerequisites]+ needs: [install-script-unit-tests, test-install-script, test-npm-fallback, test-architecture-detection, test-prerequisites]runs-on: ubuntu-latestif: always()@@ -557,6 +568,12 @@ jobs:echo "## Installation Test Results" >> $GITHUB_STEP_SUMMARYecho "" >> $GITHUB_STEP_SUMMARY+ if [[ "${{ needs.install-script-unit-tests.result }}" == "success" ]]; then+ echo "✅ **Install Script Unit Tests**: PASSED" >> $GITHUB_STEP_SUMMARY+ else+ echo "❌ **Install Script Unit Tests**: FAILED" >> $GITHUB_STEP_SUMMARY+ fi+if [[ "${{ needs.test-install-script.result }}" == "success" ]]; thenecho "✅ **Install Script Tests**: PASSED" >> $GITHUB_STEP_SUMMARYelsediff --git a/install.sh b/install.shindex 7eeae3820..77ccf01ce 100755--- a/install.sh+++ b/install.sh@@ -4,6 +4,7 @@ set -euo pipefailCOMPOSIO_GITHUB_OWNER=${COMPOSIO_GITHUB_OWNER-"ComposioHQ"}COMPOSIO_GITHUB_REPO=${COMPOSIO_GITHUB_REPO-"composio"}COMPOSIO_GITHUB_URL=${COMPOSIO_GITHUB_URL-"https://github.com"}+COMPOSIO_GITHUB_API_BASE_URL=${COMPOSIO_GITHUB_API_BASE_URL:-}COMPOSIO_INSTALL_DIR=${COMPOSIO_INSTALL_DIR:-$HOME/.composio}# --- Input validation ---@@ -24,8 +25,23 @@ if [[ ! "$COMPOSIO_GITHUB_REPO" =~ ^[a-zA-Z0-9._-]+$ ]]; thenexit 1fi+if [[ -n "$COMPOSIO_GITHUB_API_BASE_URL" && ! "$COMPOSIO_GITHUB_API_BASE_URL" =~ ^https:// ]]; then+ echo "error: COMPOSIO_GITHUB_API_BASE_URL must start with https:// (got \"$COMPOSIO_GITHUB_API_BASE_URL\")" >&2+ exit 1+fi+github_repo="$COMPOSIO_GITHUB_URL/$COMPOSIO_GITHUB_OWNER/$COMPOSIO_GITHUB_REPO"+if [[ -n "$COMPOSIO_GITHUB_API_BASE_URL" ]]; then+ github_api_base="${COMPOSIO_GITHUB_API_BASE_URL%/}"+elif [[ "$COMPOSIO_GITHUB_URL" = "https://github.com" ]]; then+ github_api_base="https://api.github.com"+else+ github_api_base="${COMPOSIO_GITHUB_URL%/}/api/v3"+fi++github_api_repo="$github_api_base/repos/$COMPOSIO_GITHUB_OWNER/$COMPOSIO_GITHUB_REPO"+# --- Colors (only when interactive) ---Color_Off='' Red='' Green='' Dim='' Bold_White='' Bold_Green=''@@ -57,7 +73,6 @@ tildify() {command -v curl >/dev/null || error 'curl is required to install Composio CLI'command -v unzip >/dev/null || error 'unzip is required to install Composio CLI'-command -v git >/dev/null || error 'git is required to install Composio CLI'install_agent=falseversion_arg=""@@ -113,25 +128,68 @@ if [[ $target = darwin-x64 ]]; thenfifi+archive_name="composio-$target.zip"++resolve_latest_cli_release() {+ local page release_json release_line++ for page in 1 2 3 4 5; do+ release_json=$(curl --fail --silent --location "$github_api_repo/releases?per_page=100&page=$page") || return 1++ release_line=$(printf '%s\n' "$release_json" \+ | sed 's/"tag_name"/\+"tag_name"/g; s/"browser_download_url"/\+"browser_download_url"/g' \+ | awk -v asset_name="$archive_name" '+ BEGIN {+ tag = ""+ stable_cli_release = "^@composio/cli@[0-9]+\\.[0-9]+\\.[0-9]+$"+ }+ /"tag_name":[[:space:]]*"/ {+ tag = $0+ sub(/^.*"tag_name":[[:space:]]*"/, "", tag)+ sub(/".*$/, "", tag)+ if (tag !~ stable_cli_release) {+ tag = ""+ }+ }+ tag != "" && /"browser_download_url":[[:space:]]*"/ && index($0, "/" asset_name "\"") > 0 {+ url = $0+ sub(/^.*"browser_download_url":[[:space:]]*"/, "", url)+ sub(/".*$/, "", url)+ print tag "\t" url+ exit+ }+ ')++ if [[ -n "$release_line" ]]; then+ printf '%s\n' "$release_line"+ return 0+ fi++ if ! printf '%s\n' "$release_json" | grep -q '"tag_name"'; then+ break+ fi+ done++ return 1+}+# --- Version resolution ---if [[ -z "$version_arg" ]]; theninfo "Finding latest CLI release..."- version=$(git ls-remote --tags "$github_repo" "@composio/cli@*" \- | awk '{print $2}' \- | sed 's#^refs/tags/##; s#\^{}$##' \- | grep -E '^@composio/cli@[0-9]+\.[0-9]+\.[0-9]+$' \- | sort -V \- | tail -1)+ latest_release=$(resolve_latest_cli_release) ||+ error "Failed to determine the latest CLI release with a $archive_name asset. Please specify a version manually."- if [[ -z "$version" ]]; then- error "Failed to determine the latest version. Please specify a version manually."- fi+ version=${latest_release%%$'\t'*}+ archive_url=${latest_release#*$'\t'}info "Found latest version: $version"elseversion=$version_arg+ archive_url="$github_repo/releases/download/$version/$archive_name"fi# --- Download into temp directory ---@@ -139,8 +197,6 @@ fitmpdir="$(mktemp -d)"trap 'rm -rf "$tmpdir"' EXIT-archive_name="composio-$target.zip"-archive_url="$github_repo/releases/download/$version/$archive_name"checksums_url="$github_repo/releases/download/$version/checksums.txt"info "Installing Composio CLI $version for $target"diff --git a/package.json b/package.jsonindex 259ca064e..0b16da443 100644--- a/package.json+++ b/package.json@@ -20,7 +20,8 @@"build:packages": "turbo build --filter=./ts/packages/**","cli:record": "turbo run record --filter=./ts/packages/cli","record": "turbo run record",- "test": "turbo test --filter=./ts/packages/** --filter=!@e2e-tests/* && pnpm run test:examples",+ "test": "pnpm run test:install-sh && turbo test --filter=./ts/packages/** --filter=!@e2e-tests/* && pnpm run test:examples",+ "test:install-sh": "bash test/install-sh-release-resolution.test.sh","test:examples": "tsx ts/scripts/validate-examples.ts","test:e2e": "turbo test:e2e --filter='@e2e-tests/*'","test:e2e:node": "turbo test:e2e:node --filter='@e2e-tests/node-*'",diff --git a/test/install-sh-release-resolution.test.sh b/test/install-sh-release-resolution.test.shnew file mode 100755index 000000000..752c52906--- /dev/null+++ b/test/install-sh-release-resolution.test.sh@@ -0,0 +1,227 @@+#!/usr/bin/env bash+set -euo pipefail++repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"++tmpdir="$(mktemp -d)"+trap 'rm -rf "$tmpdir"' EXIT++bin_dir="$tmpdir/bin"+home_dir="$tmpdir/home"+install_dir="$tmpdir/install"+mkdir -p "$bin_dir" "$home_dir" "$install_dir"++platform=$(uname -ms)+case $platform in+'Darwin x86_64') target=darwin-x64 ;;+'Darwin arm64') target=darwin-aarch64 ;;+'Linux aarch64' | 'Linux arm64')+ target=linux-aarch64 ;;+'Linux x86_64') target=linux-x64 ;;+*) echo "Unsupported test platform: $platform" >&2; exit 1 ;;+esac++archive_name="composio-$target.zip"+valid_tag='@composio/[email protected]'+missing_asset_tag='@composio/[email protected]'+tag_without_release='@composio/[email protected]'+api_base='https://api.example.test'+archive_url="https://downloads.example.test/$valid_tag/$archive_name"+curl_log="$tmpdir/curl.log"+git_log="$tmpdir/git.log"++cat > "$bin_dir/curl" <<'EOF'+#!/usr/bin/env bash+set -euo pipefail++output=""+url=""+while [[ $# -gt 0 ]]; do+ case "$1" in+ --output|-o)+ output="$2"+ shift 2+ ;;+ --*)+ shift+ ;;+ *)+ url="$1"+ shift+ ;;+ esac+done++printf '%s\n' "$url" >> "$TEST_CURL_LOG"++case "$url" in+"$TEST_API_BASE/repos/$COMPOSIO_GITHUB_OWNER/$COMPOSIO_GITHUB_REPO/releases?per_page=100&page=1")+ cat <<JSON+[+ {+ "tag_name": "$TEST_MISSING_ASSET_TAG",+ "prerelease": false,+ "draft": false,+ "assets": []+ },+ {+ "tag_name": "@composio/[email protected]",+ "prerelease": true,+ "draft": false,+ "assets": [+ { "name": "$TEST_ARCHIVE_NAME", "browser_download_url": "https://downloads.example.test/@composio/[email protected]/$TEST_ARCHIVE_NAME" }+ ]+ },+ {+ "tag_name": "@composio/[email protected]",+ "prerelease": false,+ "draft": false,+ "assets": [+ { "name": "$TEST_ARCHIVE_NAME", "browser_download_url": "https://downloads.example.test/@composio/[email protected]/$TEST_ARCHIVE_NAME" }+ ]+ },+ {+ "tag_name": "$TEST_VALID_TAG",+ "prerelease": false,+ "draft": false,+ "assets": [+ { "name": "$TEST_ARCHIVE_NAME", "browser_download_url": "$TEST_ARCHIVE_URL" }+ ]+ }+]+JSON+ ;;+"$TEST_ARCHIVE_URL")+ if [[ -z "$output" ]]; then+ echo 'archive download did not pass --output' >&2+ exit 1+ fi+ printf 'fake archive for %s\n' "$TEST_VALID_TAG" > "$output"+ ;;+*checksums.txt)+ exit 22+ ;;+*)+ echo "unexpected curl URL: $url" >&2+ exit 1+ ;;+esac+EOF+chmod +x "$bin_dir/curl"++cat > "$bin_dir/unzip" <<'EOF'+#!/usr/bin/env bash+set -euo pipefail++dest=""+while [[ $# -gt 0 ]]; do+ case "$1" in+ -d)+ dest="$2"+ shift 2+ ;;+ -*)+ # install.sh currently calls unzip with -oqd <dest>, so support the+ # compact flag by treating the next argument as the destination.+ if [[ "$1" == *d ]]; then+ dest="$2"+ shift 2+ else+ shift+ fi+ ;;+ *)+ shift+ ;;+ esac+done++if [[ -z "$dest" ]]; then+ echo 'fake unzip did not receive a destination' >&2+ exit 1+fi++mkdir -p "$dest"+cat > "$dest/composio" <<'BIN'+#!/usr/bin/env bash+case "${1:-}" in+install)+ exit 0+ ;;+--version|version)+ echo 'composio fake 98.0.0'+ exit 0+ ;;+*)+ exit 0+ ;;+esac+BIN+chmod +x "$dest/composio"+EOF+chmod +x "$bin_dir/unzip"++cat > "$bin_dir/git" <<'EOF'+#!/usr/bin/env bash+set -euo pipefail+printf 'git should not be used for install.sh release resolution; fake tag was %s\n' "$TEST_TAG_WITHOUT_RELEASE" >> "$TEST_GIT_LOG"+echo "0000000000000000000000000000000000000000 refs/tags/$TEST_TAG_WITHOUT_RELEASE"+exit 0+EOF+chmod +x "$bin_dir/git"++export TEST_CURL_LOG="$curl_log"+export TEST_GIT_LOG="$git_log"+export TEST_API_BASE="$api_base"+export TEST_ARCHIVE_NAME="$archive_name"+export TEST_ARCHIVE_URL="$archive_url"+export TEST_VALID_TAG="$valid_tag"+export TEST_MISSING_ASSET_TAG="$missing_asset_tag"+export TEST_TAG_WITHOUT_RELEASE="$tag_without_release"++output=$(env \+ PATH="$bin_dir:$PATH" \+ HOME="$home_dir" \+ SHELL="/bin/bash" \+ COMPOSIO_INSTALL_DIR="$install_dir" \+ COMPOSIO_GITHUB_URL='https://github.example.test' \+ COMPOSIO_GITHUB_API_BASE_URL="$api_base" \+ COMPOSIO_GITHUB_OWNER='FakeOwner' \+ COMPOSIO_GITHUB_REPO='fake-repo' \+ bash "$repo_root/install.sh" 2>&1)++printf '%s\n' "$output"++if [[ -s "$git_log" ]]; then+ echo 'Expected install.sh not to call git while resolving latest release.' >&2+ cat "$git_log" >&2+ exit 1+fi++if [[ ! -f "$install_dir/release-tag.txt" ]]; then+ echo 'Expected install.sh to write release-tag.txt.' >&2+ exit 1+fi++installed_tag=$(<"$install_dir/release-tag.txt")+if [[ "$installed_tag" != "$valid_tag" ]]; then+ echo "Expected fallback to $valid_tag, got $installed_tag" >&2+ exit 1+fi++if ! grep -q "Found latest version: $valid_tag" <<<"$output"; then+ echo "Expected installer output to select $valid_tag." >&2+ exit 1+fi++if grep -q "Installing Composio CLI $missing_asset_tag" <<<"$output"; then+ echo "Installer attempted to install release without $archive_name." >&2+ exit 1+fi++if grep -q "$tag_without_release" "$curl_log"; then+ echo 'Installer attempted to use a tag that was not present in releases.' >&2+ exit 1+fi++printf 'install.sh release fallback test passed\n'