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.

Merge branch 'feat/cli-install-shell-flag' into feat/mise-style-installer-rollout

jkomynofdb366d09024
diff --cc docs/lib/source.ts
index 282b78ca1,0c5b25c18..83e5e93ee
--- a/docs/lib/source.ts
+++ b/docs/lib/source.ts
@@@ -259,15 -282,15 +282,15 @@@ export function mdxToCleanMarkdown(cont
result = result.replace(
/<AIToolsBanner\s*\/>/g,
'### For AI tools\n\n' +
- '**Skills:**\n' +
- '```bash\nnpx skills add composiohq/skills\n```\n' +
- '[Skills.sh](https://skills.sh/composiohq/skills/composio) · [GitHub](https://github.com/composiohq/skills)\n\n' +
- '**CLI:**\n' +
- '```bash\ncurl -fsSL https://composio.dev/install | sh\n```\n' +
- '[CLI Reference](/docs/cli)\n\n' +
- '**Context:**\n' +
- '- [llms.txt](/llms.txt) — Documentation index with links\n' +
- '- [llms-full.txt](/llms-full.txt) — Complete documentation in one file'
+ '**Skills:**\n' +
+ '```bash\nnpx skills add composiohq/skills\n```\n' +
+ '[Skills.sh](https://skills.sh/composiohq/skills/composio) · [GitHub](https://github.com/composiohq/skills)\n\n' +
+ '**CLI:**\n' +
- '```bash\ncurl -fsSL https://composio.dev/install | bash\n```\n' +
++ '```bash\ncurl -fsSL https://composio.dev/install | sh\n```\n' +
+ '[CLI Reference](/docs/cli)\n\n' +
+ '**Context:**\n' +
+ '- [llms.txt](/llms.txt) — Documentation index with links\n' +
+ '- [llms-full.txt](/llms-full.txt) — Complete documentation in one file'
);
result = result.replace(
diff --cc install.sh
index 7407c0df3,2a2e37279..cbcf81466
--- a/install.sh
+++ b/install.sh
@@@ -180,394 -206,264 +180,416 @@@ resolve_latest_cli_release()
return 1
}
-# --- Version resolution ---
+detect_target() {
+ platform=$(uname -ms)
+ case $platform in
+ 'MINGW64'* | 'MSYS'* | 'CYGWIN'*)
+ error 'Windows is not supported. Use WSL (https://learn.microsoft.com/windows/wsl/install) and run this script inside your WSL distribution.'
+ ;;
+ 'Darwin x86_64') target=darwin-x64 ;;
+ 'Darwin arm64') target=darwin-aarch64 ;;
+ 'Linux aarch64' | 'Linux arm64') target=linux-aarch64 ;;
+ 'Linux x86_64') target=linux-x64 ;;
+ *) error "Unsupported platform: $platform" ;;
+ esac
-if [[ -z "$version_arg" ]]; then
- info "Finding latest CLI release..."
+ if [ "$target" = darwin-x64 ]; then
+ translated=$(sysctl -n sysctl.proc_translated 2>/dev/null || printf '0')
+ if [ "$translated" = 1 ]; then
+ target=darwin-aarch64
+ info "Your shell is running in Rosetta 2. Downloading for $target instead"
+ fi
+ fi
+}
- latest_release=$(resolve_latest_cli_release) ||
- error "Failed to determine the latest CLI release with a $archive_name asset. Please specify a version manually."
+verify_checksum() {
+ checksum_archive=$1
+ checksum_manifest=$2
+ checksum_name=$3
+ checksum_expected=$(awk -v name="$checksum_name" '$2 == name || $2 == "*" name { print $1; exit }' "$checksum_manifest")
- version=${latest_release%%$'\t'*}
- archive_url=${latest_release#*$'\t'}
+ if [ -z "$checksum_expected" ]; then
+ warn "No checksum entry found for $checksum_name; continuing without verification"
+ return 0
+ fi
+ printf '%s\n' "$checksum_expected" | grep -Eq '^[0-9a-fA-F]{64}$' ||
+ error "Malformed checksum for $checksum_name"
- info "Found latest version: $version"
-else
- version=$version_arg
- archive_url="$github_repo/releases/download/$version/$archive_name"
-fi
+ if command -v sha256sum >/dev/null 2>&1; then
+ checksum_actual=$(sha256sum "$checksum_archive" | awk '{ print $1 }')
+ elif command -v shasum >/dev/null 2>&1; then
+ checksum_actual=$(shasum -a 256 "$checksum_archive" | awk '{ print $1 }')
+ else
+ warn 'No SHA-256 utility found; continuing without verification'
+ return 0
+ fi
-# --- Download into temp directory ---
+ [ "$checksum_expected" = "$checksum_actual" ] ||
+ error "Checksum mismatch for $checksum_name (expected $checksum_expected, got $checksum_actual)"
+ info 'Checksum verified'
+}
-tmpdir="$(mktemp -d)"
-trap 'rm -rf "$tmpdir"' EXIT
+resolve_directory() {
+ resolve_directory_value=$1
+ mkdir -p "$resolve_directory_value" || error "Failed to create directory \"$resolve_directory_value\""
+ (cd "$resolve_directory_value" && pwd -P)
+}
-checksums_url="$github_repo/releases/download/$version/checksums.txt"
+install_bundle() {
+ install_bundle_root=$1
+ install_bundle_dir=$install_bundle_root/composio-$target
-info "Installing Composio CLI $version for $target"
+ if [ ! -f "$install_bundle_dir/composio" ]; then
+ rm -f "$install_bundle_root/$archive_name" "$install_bundle_root/checksums.txt"
+ install_bundle_dir=$install_bundle_root
+ fi
+ [ -f "$install_bundle_dir/composio" ] || error 'Binary not found in extracted archive'
-info "Downloading..."
-curl --fail --location --progress-bar --output "$tmpdir/$archive_name" "$archive_url" ||
- error "Failed to download from \"$archive_url\""
+ if ! find "$install_bundle_dir" -mindepth 1 ! -name composio -print -quit | grep -q .; then
+ warn 'This release archive has no bundled support files. Some CLI features may be unavailable.'
+ fi
-# --- Checksum verification ---
+ # Stage the bundle on the same filesystem as the install dir, then move each
+ # top-level entry into place. rename() replaces a running binary atomically,
+ # where copying through the old inode fails with ETXTBSY on Linux and would
+ # leave a mixed old-binary/new-support-files install behind.
+ install_staging_dir=$resolved_install_dir/.composio-install-staging.$$
+ rm -rf "$install_staging_dir"
+ mkdir -p "$install_staging_dir" ||
+ error "Failed to create staging directory \"$install_staging_dir\""
+ cp -Rp "$install_bundle_dir"/. "$install_staging_dir/" ||
+ error "Failed to stage the CLI bundle in \"$install_staging_dir\""
+ chmod +x "$install_staging_dir/composio" || error 'Failed to set permissions on executable'
+ printf '%s\n' "$version" >"$install_staging_dir/release-tag.txt" ||
+ error "Failed to write install metadata to \"$install_staging_dir/release-tag.txt\""
+
+ for install_entry in "$install_staging_dir"/* "$install_staging_dir"/.[!.]* "$install_staging_dir"/..?*; do
+ [ -e "$install_entry" ] || [ -L "$install_entry" ] || continue
+ install_entry_name=${install_entry##*/}
+ install_entry_target=$resolved_install_dir/$install_entry_name
+ # Directories cannot be replaced by rename(); drop the outgoing entry so
+ # bundle directories are replaced wholesale rather than merged.
+ if [ -d "$install_entry" ] || [ -d "$install_entry_target" ]; then
+ rm -rf "$install_entry_target"
+ fi
+ mv -f "$install_entry" "$install_entry_target" ||
+ error "Failed to install the CLI bundle to \"$resolved_install_dir\""
+ done
+ rm -rf "$install_staging_dir"
+}
-if curl --fail --silent --location --output "$tmpdir/checksums.txt" "$checksums_url" 2>/dev/null; then
- expected=$(grep "$archive_name" "$tmpdir/checksums.txt" | awk '{print $1}')
+install_entry_point() {
+ entry_point=$resolved_bin_dir/composio
+ if [ "$resolved_bin_dir" = "$resolved_install_dir" ]; then
+ return 0
+ fi
+ if [ -d "$entry_point" ]; then
+ error "Cannot replace entry point \"$entry_point\" because it is a directory"
+ fi
+ ln -sf "$resolved_install_dir/composio" "$entry_point" ||
+ error "Failed to create entry point \"$entry_point\""
+}
- if [[ -n "$expected" ]]; then
- if command -v sha256sum &>/dev/null; then
- actual=$(sha256sum "$tmpdir/$archive_name" | awk '{print $1}')
- elif command -v shasum &>/dev/null; then
- actual=$(shasum -a 256 "$tmpdir/$archive_name" | awk '{print $1}')
+path_contains_bin_dir() {
+ case :${PATH:-}: in
+ *:"$resolved_bin_dir":*) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
++# Reject bin dirs that cannot be embedded safely in a managed rc line. The dir
++# is only ever emitted inside double quotes -- `export PATH="<dir>:$PATH"` for
++# bash/zsh and `set --export PATH "<dir>" $PATH` for fish -- so the set is
++# deliberately narrow and mirrors UNSAFE_PATH_CHARS in
++# ts/packages/cli/src/commands/install.cmd.ts, keeping this inline fallback and
++# `composio install` on one contract:
++#
++# ` $ " \ the only characters bash and zsh still expand inside double
++# quotes (fish expands a strict subset). Everything else -- `;`,
++# `|`, `&`, `(`, `)`, `'` -- is literal there, so a bin dir like
++# /Users/o'brien/.local/bin is written verbatim, not rejected.
++# CR LF structural: either would split the managed block into extra lines.
++# : structural: the PATH separator would silently prepend two entries.
++#
++# Aborting rather than escaping is what keeps the two branches equivalent: a dir
++# the CLI refuses must not slip into an rc file just because the CLI could not
++# run. It also means the value reaching append_path_block can no longer carry a
++# character that double quotes would interpret, so no escaping pass is needed
++# (and `${var//x/y}` is a bashism this POSIX script cannot use anyway).
+is_unsafe_path() {
- case $1 in *':'* | *';'* | *'`'* | *'$'* | *'|'* | *'&'* | *'"'* | *"'"* | *'('* | *')'* | *\\*) return 0 ;; esac
++ case $1 in *':'* | *'`'* | *'$'* | *'"'* | *\\*) return 0 ;; esac
+ unsafe_path_cr=$(printf '\r')
+ case $1 in *"$unsafe_path_cr"* | *'
+'*) return 0 ;; esac
+ return 1
+}
+
++# Callers must run is_unsafe_path first, so the only `$` in the result is the
++# `$HOME` this function introduces -- it survives as a live variable reference
++# in the rc line without any user-supplied `$` riding along with it.
+render_bin_dir() {
+ render_bin_dir_value=$1
+ case $render_bin_dir_value in "$HOME"/*) render_bin_dir_value=\$HOME/${render_bin_dir_value#"$HOME"/} ;; esac
+ printf '%s\n' "$render_bin_dir_value"
+}
+
+append_path_block() {
+ append_path_file=$1
+ append_path_shell=$2
+ append_path_bin=$3
+ mkdir -p "$(dirname "$append_path_file")"
+ touch "$append_path_file"
+ grep -Fqx '# Composio CLI' "$append_path_file" 2>/dev/null && return 0
+ case $append_path_shell in
+ fish) append_path_line="set --export PATH \"$append_path_bin\" \$PATH" ;;
+ *) append_path_line="export PATH=\"$append_path_bin:\$PATH\"" ;;
+ esac
+ printf '\n# Composio CLI\n%s\n' "$append_path_line" >>"$append_path_file"
+}
+
+inline_shell_setup() {
+ inline_setup_shell=$1
+ inline_setup_bin_dir=$2
+ is_unsafe_path "$inline_setup_bin_dir" && error "COMPOSIO_BIN_DIR contains unsafe characters"
+ inline_setup_rendered=$(render_bin_dir "$inline_setup_bin_dir")
+ case $inline_setup_shell in
+ zsh) append_path_block "$HOME/.zshrc" zsh "$inline_setup_rendered" ;;
+ fish) append_path_block "$HOME/.config/fish/config.fish" fish "$inline_setup_rendered" ;;
+ bash)
+ append_path_block "$HOME/.bashrc" bash "$inline_setup_rendered"
+ if [ -f "$HOME/.bash_profile" ]; then
+ append_path_block "$HOME/.bash_profile" bash "$inline_setup_rendered"
+ elif [ -f "$HOME/.bash_login" ]; then
+ append_path_block "$HOME/.bash_login" bash "$inline_setup_rendered"
+ fi
+ ;;
+ esac
+}
+
+setup_requested_shell() {
+ if "$exe" install --help 2>&1 | grep -q -- '--shell'; then
+ debug "delegating shell setup to $exe install --shell $requested_shell"
+ if COMPOSIO_CLI_INVOCATION_ORIGIN=installer COMPOSIO_BIN_DIR="$resolved_bin_dir" "$exe" install --shell "$requested_shell"; then
+ shell_configured=cli
else
- actual=""
- warn "No SHA-256 utility found — skipping verification"
+ debug "falling back to inline $requested_shell shell setup"
+ inline_shell_setup "$requested_shell" "$resolved_bin_dir"
+ shell_configured=fallback
fi
+ else
+ debug "falling back to inline $requested_shell shell setup"
+ inline_shell_setup "$requested_shell" "$resolved_bin_dir"
+ shell_configured=fallback
+ fi
- if [[ -n "$actual" && "$expected" != "$actual" ]]; then
- error "Checksum mismatch for $archive_name\n Expected: $expected\n Actual: $actual"
- fi
+ info "Configured $requested_shell shell setup ($shell_configured)."
+ case $requested_shell in
+ zsh) info "Restart your shell or run \`source ~/.zshrc\`." ;;
+ bash) info "Restart your shell or run \`source ~/.bashrc\`." ;;
+ fish) info "Restart your shell or run \`source ~/.config/fish/config.fish\`." ;;
+ esac
+}
+
+print_post_install_help() {
+ [ "${COMPOSIO_INSTALL_HELP:-1}" != 0 ] || return 0
+ is_true "${COMPOSIO_QUIET:-}" && return 0
+
+ shell_name=${SHELL:-}
+ shell_name=${shell_name##*/}
+ shell_route=
+ shell_config=
+ case $shell_name in
+ zsh)
+ shell_route=zsh
+ shell_config=~/.zshrc
+ ;;
+ bash)
+ shell_route=bash
+ shell_config=~/.bashrc
+ ;;
+ fish)
+ shell_route=fish
+ shell_config=~/.config/fish/config.fish
+ ;;
+ esac
- if [[ -n "$actual" ]]; then
- info "Checksum verified"
+ guidance_required=0
+ path_contains_bin_dir || guidance_required=1
+ if [ "$shell_name" = bash ] && { [ -f "$HOME/.bash_profile" ] || [ -f "$HOME/.bash_login" ]; }; then
+ guidance_required=1
+ fi
+
+ printf '\n'
+ if [ -n "$requested_shell" ]; then
+ : # Shell setup already ran; skip the setup suggestion.
+ elif [ -n "$shell_route" ]; then
+ if [ "$guidance_required" = 1 ]; then
+ printf 'Required next step for %s:\n\n' "$shell_name"
+ else
+ printf 'Optional shell setup for future PATH changes:\n\n'
fi
+ printf ' curl -fsSL https://composio.dev/install | COMPOSIO_INSTALL_SHELL=%s sh\n' "$shell_route"
+ printf '\nThis configures %s.\n' "$shell_config"
+ elif path_contains_bin_dir; then
+ printf 'The composio command is available on PATH.\n'
else
- warn "No checksum entry found for $archive_name — skipping verification"
+ printf 'Add %s to PATH, then start a new shell.\n' "$(tildify "$resolved_bin_dir")"
fi
-else
- info "No checksums.txt in release — skipping verification"
-fi
-
-# --- Extract and install ---
+ printf "\nRun \`composio --help\` to get started.\n"
+}
-info "Extracting..."
-unzip -oqd "$tmpdir" "$tmpdir/$archive_name" ||
- error 'Failed to extract archive'
+cleanup() {
+ if [ -n "${tmpdir:-}" ] && [ -d "$tmpdir" ]; then
+ rm -rf "$tmpdir"
+ fi
+ if [ -n "${install_staging_dir:-}" ] && [ -d "$install_staging_dir" ]; then
+ rm -rf "$install_staging_dir"
+ fi
+}
-mkdir -p "$COMPOSIO_INSTALL_DIR" ||
- error "Failed to create install directory \"$COMPOSIO_INSTALL_DIR\""
+cleanup_on_signal() {
+ cleanup_signal=$1
+ trap - 0 1 2 3 15
+ cleanup || :
+ exit $((128 + cleanup_signal))
+}
-exe="$COMPOSIO_INSTALL_DIR/composio"
-release_tag_file="$COMPOSIO_INSTALL_DIR/release-tag.txt"
+main() {
+ install_agent=0
+ install_plugins=${COMPOSIO_INSTALL_PLUGINS:-0}
+ version_arg=
+ requested_shell=${COMPOSIO_INSTALL_SHELL:-}
-install_bundle_support_files() {
- local source_dir="$1"
- local installed_count=0
+ case $install_plugins in
+ 0 | 1) ;;
+ *) error 'COMPOSIO_INSTALL_PLUGINS must be 1 or 0' ;;
+ esac
- while IFS= read -r -d '' source_path; do
- local relative_path=${source_path#"$source_dir"/}
- local target_path="$COMPOSIO_INSTALL_DIR/$relative_path"
+ case $requested_shell in
+ '' | zsh | bash | fish) ;;
+ *) error "COMPOSIO_INSTALL_SHELL must be zsh, bash, or fish (got \"$requested_shell\")" ;;
+ esac
- mkdir -p "$(dirname "$target_path")" ||
- error "Failed to create support file directory \"$(dirname "$target_path")\""
+ while [ "$#" -gt 0 ]; do
+ case $1 in
+ --agent) install_agent=1 ;;
+ --no-plugins) install_plugins=0 ;;
+ -h | --help)
+ print_usage
+ return 0
+ ;;
+ --*) error "Unknown option: $1" ;;
+ *)
+ [ -z "$version_arg" ] || error 'Too many arguments. Expected at most one version tag.'
+ version_arg=$1
+ ;;
+ esac
+ shift
+ done
- mv "$source_path" "$target_path" ||
- error "Failed to install support file \"$relative_path\""
+ COMPOSIO_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"}
+ COMPOSIO_BIN_DIR=${COMPOSIO_BIN_DIR:-"$HOME/.local/bin"}
+
+ validate_identifier COMPOSIO_GITHUB_OWNER "$COMPOSIO_GITHUB_OWNER"
+ validate_identifier COMPOSIO_GITHUB_REPO "$COMPOSIO_GITHUB_REPO"
+ validate_url "$COMPOSIO_GITHUB_URL" ||
+ error "COMPOSIO_GITHUB_URL must use https or an explicitly allowed test host (got \"$COMPOSIO_GITHUB_URL\")"
+ if [ -n "$COMPOSIO_GITHUB_API_BASE_URL" ]; then
+ validate_url "$COMPOSIO_GITHUB_API_BASE_URL" ||
+ error "COMPOSIO_GITHUB_API_BASE_URL must use https or an explicitly allowed test host (got \"$COMPOSIO_GITHUB_API_BASE_URL\")"
+ fi
- installed_count=$((installed_count + 1))
- done < <(find "$source_dir" -mindepth 1 -type f ! -path "$source_dir/composio" -print0)
+ detect_target
+ command -v curl >/dev/null 2>&1 || error 'curl is required to install Composio CLI'
+ command -v unzip >/dev/null 2>&1 || error 'unzip is required to install Composio CLI'
- if (( installed_count == 0 )); then
- warn "This release archive does not include any bundled support files beyond the main binary. Some CLI features may be unavailable in this version."
+ 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
+ archive_name=composio-$target.zip
-# Handle nested directory structure (composio-<target>/composio)
-if [[ -f "$tmpdir/composio-$target/composio" ]]; then
- mv "$tmpdir/composio-$target/composio" "$exe"
- install_bundle_support_files "$tmpdir/composio-$target"
-elif [[ -f "$tmpdir/composio" ]]; then
- mv "$tmpdir/composio" "$exe"
- install_bundle_support_files "$tmpdir"
-else
- error 'Binary not found in extracted archive'
-fi
+ requested_version=$version_arg
+ if [ -z "$requested_version" ]; then
+ requested_version=${COMPOSIO_INSTALL_VERSION:-}
+ fi
-chmod +x "$exe" ||
- error 'Failed to set permissions on executable'
+ if [ -n "$requested_version" ]; then
+ version=$(normalize_version "$requested_version")
+ archive_url=$github_repo/releases/download/$version/$archive_name
+ else
+ info 'Finding latest stable CLI release...'
+ latest_release=$(resolve_latest_cli_release) ||
+ error "Failed to determine the latest CLI release with a $archive_name asset. Specify a version manually."
+ version=$(printf '%s\n' "$latest_release" | sed -n '1p')
+ archive_url=$(printf '%s\n' "$latest_release" | sed -n '2p')
+ [ -n "$version" ] && [ -n "$archive_url" ] || error 'The release API returned an incomplete CLI release'
+ info "Found latest version: $version"
+ fi
+ validate_url "$archive_url" || error "Release API returned an unsafe archive URL \"$archive_url\""
-printf '%s\n' "$version" > "$release_tag_file" ||
- error "Failed to write install metadata to \"$release_tag_file\""
+ checksums_url=$github_repo/releases/download/$version/checksums.txt
+ validate_url "$checksums_url" || error "Refusing unsafe checksum URL \"$checksums_url\""
-success "Composio CLI was installed successfully to $Bold_Green$(tildify "$exe")"
+ tmpdir=$(mktemp -d) || error 'Failed to create a temporary directory'
+ trap cleanup 0
+ trap 'cleanup_on_signal 1' 1
+ trap 'cleanup_on_signal 2' 2
+ trap 'cleanup_on_signal 3' 3
+ trap 'cleanup_on_signal 15' 15
+ debug "temporary directory: $tmpdir"
-# --- Shell integration (PATH + completions) ---
+ info "Installing Composio CLI $version for $target"
+ curl_download "$archive_url" "$tmpdir/$archive_name" 0 ||
+ error "Failed to download from \"$archive_url\""
-# Delegate to the CLI's own install command, which handles:
-# - Idempotent PATH setup in the correct rc file
-# - Shell completions installation
-# If the binary can't run (e.g. missing runtime), fall back to inline setup.
-#
-# Run it with stderr left on the terminal. `composio install` reports which rc
-# file it changed and how to reload the shell, and it treats a redirected stderr
-# as "nobody is watching" — capturing that stream, even to replay it later, is
-# what makes the PATH guidance disappear. The version probe keeps a binary that
-# cannot run at all from spilling loader errors before the fallback takes over.
-
-echo
-
-if "$exe" --version >/dev/null 2>&1 &&
- COMPOSIO_INSTALL_DIR="$COMPOSIO_INSTALL_DIR" COMPOSIO_CLI_INVOCATION_ORIGIN=installer "$exe" install; then
- : # the CLI printed its own shell-integration guidance
-else
- info "Setting up shell integration..."
-
- refresh_command=''
-
- # Every rc line below embeds one of these inside double quotes. `$HOME` is
- # re-applied after escaping so the intended variable reference survives as
- # a literal `$HOME` while any user-supplied `$` stays escaped.
- escaped_install_dir=$(escape_for_double_quotes "$COMPOSIO_INSTALL_DIR")
- escaped_install_dir_fish=$(escape_for_double_quotes "$COMPOSIO_INSTALL_DIR" false)
- home_relative_install_dir=$escaped_install_dir
-
- if [[ $COMPOSIO_INSTALL_DIR = "$HOME"/* ]]; then
- home_relative_install_dir='$HOME/'$(escape_for_double_quotes "${COMPOSIO_INSTALL_DIR#"$HOME"/}")
+ if curl_download "$checksums_url" "$tmpdir/checksums.txt" 1; then
+ verify_checksum "$tmpdir/$archive_name" "$tmpdir/checksums.txt" "$archive_name"
+ else
+ warn 'No checksums.txt in this release; continuing without verification'
fi
- shell_name=$(basename "${SHELL:-}")
- marker='# Composio CLI'
+ info 'Extracting bundle...'
+ unzip -oqd "$tmpdir" "$tmpdir/$archive_name" || error 'Failed to extract archive'
- case $shell_name in
- fish)
- commands=(
- "set --export COMPOSIO_INSTALL_DIR \"$escaped_install_dir_fish\""
- "set --export PATH \$COMPOSIO_INSTALL_DIR \$PATH"
- )
- fish_config=$HOME/.config/fish/config.fish
- if [[ -w $fish_config ]] || [[ -w $(dirname "$fish_config") ]]; then
- mkdir -p "$(dirname "$fish_config")"
- if ! grep -qxF "$marker" "$fish_config" 2>/dev/null; then
- { echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$fish_config"
- info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$fish_config")\""
- else
- info "PATH already configured in \"$(tildify "$fish_config")\""
- fi
- refresh_command="source $(tildify "$fish_config")"
- else
- echo "Manually add the directory to $(tildify "$fish_config") (or similar):"
- for cmd in "${commands[@]}"; do info_bold " $cmd"; done
- fi
- ;;
- zsh)
- commands=(
- "export COMPOSIO_INSTALL_DIR=\"$escaped_install_dir\""
- "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
- )
- zsh_config=$HOME/.zshrc
- if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then touch "$zsh_config"; fi
- if [[ -w $zsh_config ]]; then
- if ! grep -qxF "$marker" "$zsh_config" 2>/dev/null; then
- { echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$zsh_config"
- info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$zsh_config")\""
- else
- info "PATH already configured in \"$(tildify "$zsh_config")\""
- fi
- refresh_command="source $(tildify "$zsh_config")"
- else
- echo "Manually add the directory to $(tildify "$zsh_config") (or similar):"
- for cmd in "${commands[@]}"; do info_bold " $cmd"; done
- fi
- ;;
- bash)
- commands=(
- "export COMPOSIO_INSTALL_DIR=\"$home_relative_install_dir\""
- "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
- )
- bash_configs=("$HOME/.bashrc" "$HOME/.bash_profile")
- if [[ ${XDG_CONFIG_HOME:-} ]]; then
- bash_configs+=("$XDG_CONFIG_HOME/.bash_profile" "$XDG_CONFIG_HOME/.bashrc" "$XDG_CONFIG_HOME/bash_profile" "$XDG_CONFIG_HOME/bashrc")
- fi
- set_manually=true
- for bash_config in "${bash_configs[@]}"; do
- if [[ -w $bash_config ]]; then
- if ! grep -qxF "$marker" "$bash_config" 2>/dev/null; then
- { echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$bash_config"
- info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$bash_config")\""
- else
- info "PATH already configured in \"$(tildify "$bash_config")\""
- fi
- refresh_command="source $bash_config"
- set_manually=false
- break
- fi
- done
- if [[ $set_manually = true ]]; then
- echo "Manually add the directory to ~/.bashrc (or similar):"
- for cmd in "${commands[@]}"; do info_bold " $cmd"; done
- fi
- ;;
- *)
- echo 'Manually add the directory to ~/.bashrc (or similar):'
- info_bold " export COMPOSIO_INSTALL_DIR=\"$home_relative_install_dir\""
- info_bold " export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
- ;;
- esac
+ resolved_install_dir=$(resolve_directory "$COMPOSIO_INSTALL_DIR")
+ resolved_bin_dir=$(resolve_directory "$COMPOSIO_BIN_DIR")
+ install_bundle "$tmpdir"
+ install_entry_point
+
+ exe=$resolved_install_dir/composio
+ "$exe" --version >/dev/null 2>&1 || error 'The installed Composio CLI failed its version check'
+ info "Composio CLI was installed to $(tildify "$exe")"
+ if [ "$resolved_bin_dir" != "$resolved_install_dir" ]; then
+ info "The composio entry point is $(tildify "$resolved_bin_dir/composio")"
+ fi
-fi
+ if [ "$install_plugins" = 1 ]; then
+ info 'Installing plugins for detected agent hosts...'
+ COMPOSIO_CLI_INVOCATION_ORIGIN=installer "$exe" setup --target auto --yes --if-present ||
+ error "Composio CLI was installed, but agent plugin setup failed. Retry with \`composio setup --target auto --yes\`."
+ fi
-if [[ $install_plugins = true ]]; then
- echo
- info "Checking for supported agent hosts..."
- if ! COMPOSIO_CLI_INVOCATION_ORIGIN=installer "$exe" setup --target auto --yes --if-present; then
- error 'Composio CLI was installed, but agent plugin setup failed. Retry with `composio setup --target auto --yes`.'
+ if [ "$install_agent" = 1 ]; then
+ info 'Setting up Composio agent login...'
+ COMPOSIO_CLI_INVOCATION_ORIGIN=installer "$exe" login --agent --no-skill-install ||
+ error 'Failed to sign up or log in as a Composio agent.'
fi
-fi
-if [[ $install_agent = true ]]; then
- echo
- info "Setting up Composio agent login..."
- if ! COMPOSIO_CLI_INVOCATION_ORIGIN=installer "$exe" login --agent --no-skill-install; then
- error 'Failed to sign up/log in as a Composio agent. If this CLI is already signed in as a regular user, run `composio logout` and then `composio signup` or `composio agent login <composio_agent_key>`.'
+ if [ -n "$requested_shell" ]; then
+ setup_requested_shell
fi
-fi
-
-echo
-# No PATH claim here: whichever branch ran above already reported what it did to
-# which file, and whether a reload is needed. Restating it unconditionally would
-# promise a configured PATH even on the branches that only printed manual
-# instructions.
-info "To get started, run:"
-echo
-
-if [[ ${refresh_command:-} ]]; then
- info_bold " $refresh_command"
-fi
-
-info_bold " composio --help"
-if [[ $install_agent = true ]]; then
- info_bold " composio agent whoami"
-else
- info_bold " composio login"
-fi
+
+ print_post_install_help
+}
+
+main "$@"
diff --cc test/install-sh-release-resolution.test.sh
index 3306bbd1c,fb06f7963..0a1cb4991
--- a/test/install-sh-release-resolution.test.sh
+++ b/test/install-sh-release-resolution.test.sh
@@@ -124,543 -104,341 +124,563 @@@ for interpreter in "${interpreters[@]}"
#!/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
+printf '%s\n' "$*" >>"$TEST_CURL_LOG"
+all_args=$*
+output=
+url=
+while (($# > 0)); do
+ case $1 in
+ --output|-o)
+ output=$2
+ shift 2
+ ;;
+ --proto|--proto-redir)
+ shift 2
+ ;;
+ --fail|--silent|--show-error|--location|--progress-bar)
+ shift
+ ;;
+ --*)
+ shift
+ ;;
+ *)
+ url=$1
+ shift
+ ;;
+ esac
done
-printf '%s\n' "$url" >> "$TEST_CURL_LOG"
+case $url in
+https://*)
+ [[ $all_args == *"--proto =https"* && $all_args == *"--proto-redir =https"* ]] || exit 91
+ ;;
+http://*)
+ [[ $all_args == *"--proto =http,https"* && $all_args == *"--proto-redir =https"* ]] || exit 92
+ ;;
+esac
+
+if [[ -n ${TEST_CURL_DELAY_URL:-} && $url == "$TEST_CURL_DELAY_URL" ]]; then
+ printf '%s\n' "$PPID" >"$TEST_CURL_PARENT_PID_FILE"
+ sleep "${TEST_CURL_DELAY_SECONDS:-1}"
+fi
+
+if [[ $url == "$TEST_SCRIPT_URL" ]]; then
+ case ${TEST_BASE_MODE:-ok} in
+ fail) exit 22 ;;
+ empty) : >"$output" ;;
+ ok) cp "$TEST_REPO_ROOT/install.sh" "$output" ;;
+ esac
+ exit 0
+fi
-case "$url" in
+case $url in
"$TEST_API_BASE/repos/$COMPOSIO_GITHUB_OWNER/$COMPOSIO_GITHUB_REPO/releases?per_page=100&page=1")
- cat <<JSON
+ asset_url=${TEST_API_ASSET_URL:-$TEST_ARCHIVE_URL}
+ 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" }
- ]
- }
+ {"tag_name":"$TEST_MISSING_ASSET_TAG","assets":[]},
+ {"tag_name":"@composio/[email protected]","assets":[{"browser_download_url":"https://downloads.example.test/beta/$TEST_ARCHIVE_NAME"}]},
+ {"tag_name":"$TEST_STABLE_TAG","assets":[{"browser_download_url":"$asset_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
- ;;
+ ;;
+"$TEST_ARCHIVE_URL"|*"/releases/download/"*"/$TEST_ARCHIVE_NAME")
+ [[ -n $output ]] || exit 93
+ if [[ ${TEST_REDIRECT_DOWNGRADE:-0} == 1 ]]; then
+ exit 47
+ fi
+ printf 'fake archive\n' >"$output"
+ ;;
+*"/releases/download/"*"/checksums.txt")
+ case ${TEST_CHECKSUM_MODE:-missing} in
+ missing) exit 22 ;;
+ valid) printf '%064d %s\n' 0 "$TEST_ARCHIVE_NAME" | tr '0' 'a' >"$output" ;;
+ mismatch) printf '%064d %s\n' 0 "$TEST_ARCHIVE_NAME" | tr '0' 'b' >"$output" ;;
+ malformed) printf 'not-a-hash %s\n' "$TEST_ARCHIVE_NAME" >"$output" ;;
+ esac
+ ;;
*)
- echo "unexpected curl URL: $url" >&2
- exit 1
- ;;
+ printf 'unexpected curl URL: %s\n' "$url" >&2
+ exit 94
+ ;;
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
+ chmod +x "$fake_bin/curl"
-if [[ -z "$dest" ]]; then
- echo 'fake unzip did not receive a destination' >&2
- exit 1
-fi
+ cat >"$fake_bin/sha256sum" <<'EOF'
+#!/bin/sh
+printf '%s %s\n' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' "$1"
+EOF
+ chmod +x "$fake_bin/sha256sum"
-mkdir -p "$dest"
-cat > "$dest/composio" <<'BIN'
+ cat >"$fake_bin/unzip" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
-
-printf '%s\n' "$*" >> "$TEST_COMPOSIO_LOG"
-
-case "${1:-}" in
-install)
- if [[ -n "${TEST_INSTALL_STDERR:-}" ]]; then
- printf '%s\n' "$TEST_INSTALL_STDERR" >&2
- fi
- exit 0
+dest=
+while (($# > 0)); do
+ case $1 in
+ -d)
+ dest=$2
+ shift 2
;;
-setup)
- if [[ "${COMPOSIO_CLI_INVOCATION_ORIGIN:-}" != 'installer' ]]; then
- echo 'Expected automatic plugin setup telemetry origin to be installer.' >&2
- exit 97
- fi
- exit "${TEST_SETUP_EXIT:-0}"
+ -*d)
+ dest=$2
+ shift 2
;;
+ *) shift ;;
+ esac
+done
+[[ -n $dest ]] || exit 95
+bundle="$dest/composio-$TEST_TARGET"
+mkdir -p "$bundle/services" "$bundle/local-tools-binaries"
+cat >"$bundle/composio" <<'BIN'
+#!/bin/sh
+printf '%s|%s|%s|%s\n' "${COMPOSIO_INSTALL_HELP:-}" "${COMPOSIO_CLI_INVOCATION_ORIGIN:-}" "${COMPOSIO_BIN_DIR:-}" "$*" >>"$TEST_COMPOSIO_LOG"
+case ${1:-} in
--version|version)
- if [[ -n "${TEST_VERSION_STDERR:-}" ]]; then
- printf '%s\n' "$TEST_VERSION_STDERR" >&2
+ printf '%s\n' 'composio fake 98.0.0'
+ exit "${TEST_VERSION_EXIT:-0}"
+ ;;
+setup)
+ [ "${COMPOSIO_CLI_INVOCATION_ORIGIN:-}" = installer ] || exit 96
+ exit "${TEST_SETUP_EXIT:-0}"
+ ;;
+login)
+ [ "${COMPOSIO_CLI_INVOCATION_ORIGIN:-}" = installer ] || exit 97
+ exit 0
+ ;;
+install)
+ if [ "${2:-}" = --help ]; then
+ if [ "${TEST_SHELL_CAPABILITY:-supported}" = supported ]; then
+ printf '%s\n' 'Usage: composio install [--shell zsh|bash|fish]'
+ else
+ printf '%s\n' 'Usage: composio install'
fi
- echo 'composio fake 98.0.0'
- exit "${TEST_VERSION_EXIT:-0}"
- ;;
-*)
exit 0
- ;;
+ fi
+ if [ "${2:-}" = --shell ]; then
+ exit "${TEST_INSTALL_EXIT:-0}"
+ fi
+ exit 98
+ ;;
+*) exit 0 ;;
esac
BIN
-chmod +x "$dest/composio"
+ chmod +x "$bundle/composio"
+ printf '%s\n' 'support' >"$bundle/run-bun.mjs"
+ printf '%s\n' 'service' >"$bundle/services/example.txt"
EOF
-chmod +x "$bin_dir/unzip"
+ chmod +x "$fake_bin/unzip"
+
+ export TEST_REPO_ROOT="$repo_root"
+ export TEST_TARGET="$target"
+ export TEST_ARCHIVE_NAME="$archive_name"
+ export TEST_STABLE_TAG="$stable_tag"
+ export TEST_MISSING_ASSET_TAG="$missing_asset_tag"
+ export TEST_ARCHIVE_URL="$archive_url"
+ export TEST_API_BASE="$api_base"
+ export TEST_SCRIPT_URL="$script_url"
+ export TEST_CURL_LOG="$curl_log"
+ export TEST_COMPOSIO_LOG="$composio_log"
+
+ reset_case() {
+ unset CASE_GITHUB_URL CASE_API_BASE CASE_INSTALL_VERSION CASE_INSTALL_SHELL CASE_PLUGINS CASE_QUIET CASE_DEBUG CASE_HELP
+ unset CASE_ALLOW_HTTP_HOST CASE_CHECKSUM_MODE CASE_API_ASSET_URL CASE_BASE_MODE CASE_REDIRECT_DOWNGRADE
+ unset CASE_SHELL_CAPABILITY CASE_INSTALL_EXIT CASE_SETUP_EXIT CASE_VERSION_EXIT CASE_PATH_PREFIX CASE_UNSET_SHELL
+ unset CASE_CURL_DELAY_URL CASE_CURL_DELAY_SECONDS
+ rm -f "$case_root/curl-parent.pid"
+ : >"$curl_log"
+ : >"$composio_log"
+ }
-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_COMPOSIO_LOG="$composio_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"
-
-run_installer() {
- local test_home="$1"
- local test_install_dir="$2"
- shift 2
+ # Env assignments shared by run_installer and run_variant. Emitted into
+ # common_env_args; each runner appends its own entry-point-specific overrides.
+ common_env() {
+ local home=$1
+ local install_dir=$2
+ local bin_dir=$3
+ common_env_args=(
+ HOME="$home"
+ COMPOSIO_INSTALL_DIR="$install_dir"
+ COMPOSIO_BIN_DIR="$bin_dir"
+ COMPOSIO_INSTALL_PLUGINS="${CASE_PLUGINS:-0}"
+ COMPOSIO_GITHUB_URL="${CASE_GITHUB_URL:-$github_url}"
+ COMPOSIO_GITHUB_API_BASE_URL="${CASE_API_BASE:-$api_base}"
+ COMPOSIO_GITHUB_OWNER=FakeOwner
+ COMPOSIO_GITHUB_REPO=fake-repo
+ TEST_CHECKSUM_MODE="${CASE_CHECKSUM_MODE:-missing}"
+ TEST_SHELL_CAPABILITY="${CASE_SHELL_CAPABILITY:-supported}"
+ TEST_INSTALL_EXIT="${CASE_INSTALL_EXIT:-0}"
+ TEST_CURL_DELAY_URL="${CASE_CURL_DELAY_URL:-}"
+ TEST_CURL_DELAY_SECONDS="${CASE_CURL_DELAY_SECONDS:-1}"
+ TEST_CURL_PARENT_PID_FILE="$case_root/curl-parent.pid"
+ )
+ }
+ run_installer() {
+ local home=$1
+ local install_dir=$2
+ local bin_dir=$3
+ shift 3
+ mkdir -p "$home" "$install_dir" "$bin_dir"
+ local -a installer_command=("$interpreter" "$repo_root/install.sh")
+ if [[ ${CASE_UNSET_SHELL:-0} == 1 ]]; then
+ installer_command=("$interpreter" -c 'unset SHELL; script=$1; shift; . "$script"' unset-shell "$repo_root/install.sh")
+ fi
+ common_env "$home" "$install_dir" "$bin_dir"
env \
- PATH="$bin_dir:$PATH" \
- HOME="$test_home" \
- SHELL="/bin/bash" \
- COMPOSIO_INSTALL_DIR="$test_install_dir" \
- COMPOSIO_INSTALL_PLUGINS="${COMPOSIO_INSTALL_PLUGINS:-1}" \
- COMPOSIO_GITHUB_URL='https://github.example.test' \
- COMPOSIO_GITHUB_API_BASE_URL="$api_base" \
- COMPOSIO_GITHUB_OWNER='FakeOwner' \
- COMPOSIO_GITHUB_REPO='fake-repo' \
- TEST_INSTALL_STDERR="${TEST_INSTALL_STDERR:-}" \
- TEST_SETUP_EXIT="${TEST_SETUP_EXIT:-0}" \
- TEST_VERSION_EXIT="${TEST_VERSION_EXIT:-0}" \
- TEST_VERSION_STDERR="${TEST_VERSION_STDERR:-}" \
- bash "$repo_root/install.sh" "$@"
-}
-
-install_guidance='shell integration guidance from composio install'
-output=$(TEST_INSTALL_STDERR="$install_guidance" run_installer "$home_dir" "$install_dir" 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
-
-if ! grep -qxF -- '--version' "$composio_log"; then
- echo 'Expected installer to probe the downloaded CLI with --version.' >&2
- cat "$composio_log" >&2
- exit 1
-fi
-
-if ! grep -qxF 'install' "$composio_log"; then
- echo 'Expected installer to delegate shell integration to composio install.' >&2
- cat "$composio_log" >&2
- exit 1
-fi
-
-if ! grep -qF "$install_guidance" <<<"$output"; then
- echo 'Expected composio install stderr guidance to remain visible.' >&2
- printf '%s\n' "$output" >&2
- exit 1
-fi
-
-expected_setup='setup --target auto --yes --if-present'
-if ! grep -qxF "$expected_setup" "$composio_log"; then
- echo "Expected installer to invoke: composio $expected_setup" >&2
- cat "$composio_log" >&2
- exit 1
-fi
-
-failed_probe_home="$tmpdir/home-failed-probe"
-failed_probe_install="$tmpdir/install-failed-probe"
-mkdir -p "$failed_probe_home" "$failed_probe_install"
-: > "$failed_probe_home/.bashrc"
-: > "$composio_log"
-loader_error='loader error from an unusable composio binary'
-failed_probe_output=$(
- TEST_VERSION_EXIT=126 \
- TEST_VERSION_STDERR="$loader_error" \
- run_installer "$failed_probe_home" "$failed_probe_install" --no-plugins 2>&1
-)
-if grep -qF "$loader_error" <<<"$failed_probe_output"; then
- echo 'Expected the failed binary probe to suppress loader errors.' >&2
- printf '%s\n' "$failed_probe_output" >&2
- exit 1
-fi
-if grep -qxF 'install' "$composio_log"; then
- echo 'Expected a failed binary probe to skip composio install.' >&2
- cat "$composio_log" >&2
- exit 1
-fi
-if ! grep -qF 'Setting up shell integration...' <<<"$failed_probe_output"; then
- echo 'Expected a failed binary probe to select inline shell integration.' >&2
- printf '%s\n' "$failed_probe_output" >&2
- exit 1
-fi
-if ! grep -qxF '# Composio CLI' "$failed_probe_home/.bashrc"; then
- echo 'Expected inline shell integration to update .bashrc.' >&2
- cat "$failed_probe_home/.bashrc" >&2
- exit 1
-fi
+ PATH="${CASE_PATH_PREFIX:-}$fake_bin:$PATH" \
+ SHELL=/bin/bash \
+ "${common_env_args[@]}" \
+ COMPOSIO_INSTALL_VERSION="${CASE_INSTALL_VERSION:-}" \
+ COMPOSIO_INSTALL_SHELL="${CASE_INSTALL_SHELL:-}" \
+ COMPOSIO_QUIET="${CASE_QUIET:-0}" \
+ COMPOSIO_DEBUG="${CASE_DEBUG:-0}" \
+ COMPOSIO_INSTALL_HELP="${CASE_HELP:-1}" \
+ COMPOSIO_INSTALL_ALLOW_HTTP_HOST="${CASE_ALLOW_HTTP_HOST:-}" \
+ TEST_API_ASSET_URL="${CASE_API_ASSET_URL:-}" \
+ TEST_REDIRECT_DOWNGRADE="${CASE_REDIRECT_DOWNGRADE:-0}" \
+ TEST_SETUP_EXIT="${CASE_SETUP_EXIT:-0}" \
+ TEST_VERSION_EXIT="${CASE_VERSION_EXIT:-0}" \
+ "${installer_command[@]}" "$@"
+ }
-# The inline fallback embeds the install directory in rc lines. A directory
-# holding `$(...)` must land there as literal text, not as a command that runs
-# at every shell start.
-injection_home="$tmpdir/home-injection"
-injection_marker="$tmpdir/injection-marker"
-injection_install="$tmpdir/inject-\$(touch $injection_marker)"
-mkdir -p "$injection_home" "$injection_install"
-: > "$injection_home/.bashrc"
-: > "$composio_log"
-TEST_VERSION_EXIT=126 run_installer "$injection_home" "$injection_install" --no-plugins >/dev/null 2>&1
-bash -c 'source "$1"' _ "$injection_home/.bashrc" >/dev/null 2>&1 || true
-if [[ -e "$injection_marker" ]]; then
- echo 'Expected inline shell integration to escape command substitution in COMPOSIO_INSTALL_DIR.' >&2
- cat "$injection_home/.bashrc" >&2
- exit 1
-fi
-if ! grep -qF '\$(touch' "$injection_home/.bashrc"; then
- echo 'Expected the escaped install directory to be written to .bashrc.' >&2
- cat "$injection_home/.bashrc" >&2
- exit 1
-fi
+ run_variant() {
+ local shell_name=$1
+ local home=$2
+ local install_dir=$3
+ local bin_dir=$4
+ shift 4
+ mkdir -p "$home" "$install_dir" "$bin_dir"
+ common_env "$home" "$install_dir" "$bin_dir"
+ env \
+ PATH="$fake_bin:$PATH" \
+ SHELL="/bin/$shell_name" \
+ "${common_env_args[@]}" \
+ COMPOSIO_INSTALL_SCRIPT_URL="$script_url" \
+ TEST_BASE_MODE="${CASE_BASE_MODE:-ok}" \
+ "$interpreter" "$repo_root/install/$shell_name.sh" "$@"
+ }
-no_plugins_home="$tmpdir/home-no-plugins"
-no_plugins_install="$tmpdir/install-no-plugins"
-mkdir -p "$no_plugins_home" "$no_plugins_install"
-: > "$composio_log"
-run_installer "$no_plugins_home" "$no_plugins_install" --no-plugins >/dev/null 2>&1
-if grep -q '^setup ' "$composio_log"; then
- echo 'Expected --no-plugins to skip agent plugin setup.' >&2
- cat "$composio_log" >&2
- exit 1
-fi
+ reset_case
+ home="$case_root/default-home"
+ install_dir="$case_root/default-install"
+ bin_dir="$case_root/default-bin"
+ output=$(run_installer "$home" "$install_dir" "$bin_dir" 2>&1)
+ [[ $(<"$install_dir/release-tag.txt") == "$stable_tag" ]] || fail "$interpreter_name latest stable resolution"
+ [[ -x "$install_dir/composio" && -f "$install_dir/run-bun.mjs" ]] || fail "$interpreter_name bundle installation"
+ [[ -L "$bin_dir/composio" ]] || fail "$interpreter_name entry-point symlink"
+ expected_install_dir=$(cd "$install_dir" && pwd -P)
+ [[ $(readlink "$bin_dir/composio") == "$expected_install_dir/composio" ]] || fail "$interpreter_name symlink target"
+ assert_contains "$output" "Found latest version: $stable_tag" "$interpreter_name stable discovery"
+ assert_contains "$output" 'Required next step for bash:' "$interpreter_name required PATH guidance"
+ [[ ! -e "$home/.bashrc" ]] || fail "$interpreter_name default flow must not write rc files"
+ [[ $(wc -l <"$composio_log") -eq 1 ]] || fail "$interpreter_name default flow invoked extra CLI commands"
+ grep -Fq '|--version' "$composio_log" || fail "$interpreter_name version probe"
+ [[ ! -s "$case_root/git.log" ]] || fail "$interpreter_name must not use git"
+
+ reset_case
+ equal_dir="$case_root/equal-layout"
+ run_installer "$case_root/equal-home" "$equal_dir" "$equal_dir" "$beta_tag" >/dev/null 2>&1
+ [[ -x "$equal_dir/composio" && ! -L "$equal_dir/composio" ]] || fail "$interpreter_name equal-dir layout"
+ [[ $(<"$equal_dir/release-tag.txt") == "$beta_tag" ]] || fail "$interpreter_name explicit beta tag"
+
+ reset_case
+ upgrade_home="$case_root/upgrade-home"
+ upgrade_install="$case_root/upgrade-install"
+ upgrade_bin="$case_root/upgrade-bin"
+ mkdir -p "$upgrade_install/services"
+ printf '%s\n' stale >"$upgrade_install/services/stale.txt"
+ printf '%s\n' old-binary >"$upgrade_install/composio"
+ run_installer "$upgrade_home" "$upgrade_install" "$upgrade_bin" "$stable_tag" >/dev/null 2>&1
+ [[ -x "$upgrade_install/composio" ]] || fail "$interpreter_name upgrade must replace the existing binary"
+ [[ $(<"$upgrade_install/services/example.txt") == service ]] || fail "$interpreter_name upgrade must install new support files"
+ [[ ! -e "$upgrade_install/services/stale.txt" ]] || fail "$interpreter_name upgrade must replace bundle directories wholesale"
+ [[ -z $(find "$upgrade_install" -maxdepth 1 -name '.composio-install-staging.*' -print -quit) ]] ||
+ fail "$interpreter_name upgrade must clean up the staging directory"
+
+ reset_case
+ legacy_home="$case_root/legacy-home"
+ mkdir -p "$legacy_home"
+ printf '%s\n' 'export COMPOSIO_INSTALL_DIR="$HOME/.composio"' >"$legacy_home/.bashrc"
+ run_installer "$legacy_home" "$case_root/legacy-install" "$case_root/legacy-bin" "$stable_tag" >/dev/null 2>&1
+ [[ -L "$case_root/legacy-bin/composio" ]] || fail "$interpreter_name legacy migration symlink"
+ grep -Fq 'COMPOSIO_INSTALL_DIR' "$legacy_home/.bashrc" || fail "$interpreter_name must preserve legacy rc content"
+
+ reset_case
+ replacement_bin="$case_root/replacement-bin"
+ mkdir -p "$replacement_bin"
+ printf '%s\n' old >"$replacement_bin/composio"
+ run_installer "$case_root/replacement-home" "$case_root/replacement-install" "$replacement_bin" "$stable_tag" >/dev/null 2>&1
+ [[ -L "$replacement_bin/composio" ]] || fail "$interpreter_name regular entry point replacement"
+
+ reset_case
+ directory_bin="$case_root/directory-bin"
+ mkdir -p "$directory_bin/composio"
+ if directory_output=$(run_installer "$case_root/directory-home" "$case_root/directory-install" "$directory_bin" "$stable_tag" 2>&1); then
+ fail "$interpreter_name directory entry point must fail"
+ fi
+ assert_contains "$directory_output" 'because it is a directory' "$interpreter_name directory error"
+
+ reset_case
+ CASE_INSTALL_VERSION=97.0.0
+ precedence_install="$case_root/precedence-install"
+ run_installer "$case_root/precedence-home" "$precedence_install" "$case_root/precedence-bin" 96.0.0 >/dev/null 2>&1
+ [[ $(<"$precedence_install/release-tag.txt") == '@composio/[email protected]' ]] || fail "$interpreter_name version precedence"
+
+ reset_case
+ CASE_INSTALL_VERSION=95.0.0-beta.7
+ env_version_install="$case_root/env-version-install"
+ run_installer "$case_root/env-version-home" "$env_version_install" "$case_root/env-version-bin" >/dev/null 2>&1
+ [[ $(<"$env_version_install/release-tag.txt") == '@composio/[email protected]' ]] || fail "$interpreter_name env beta normalization"
+
+ reset_case
+ if malformed_output=$(run_installer "$case_root/malformed-home" "$case_root/malformed-install" "$case_root/malformed-bin" 1.2.3-rc.1 2>&1); then
+ fail "$interpreter_name malformed prerelease must fail"
+ fi
+ assert_contains "$malformed_output" 'Invalid Composio CLI version' "$interpreter_name malformed version"
+ [[ ! -s "$curl_log" ]] || fail "$interpreter_name malformed version must fail before network"
+
+ reset_case
+ CASE_CHECKSUM_MODE=valid
+ run_installer "$case_root/checksum-home" "$case_root/checksum-install" "$case_root/checksum-bin" "$stable_tag" >/dev/null 2>&1
+
+ for checksum_mode in mismatch malformed; do
+ reset_case
+ CASE_CHECKSUM_MODE=$checksum_mode
+ if checksum_output=$(run_installer "$case_root/$checksum_mode-home" "$case_root/$checksum_mode-install" "$case_root/$checksum_mode-bin" "$stable_tag" 2>&1); then
+ fail "$interpreter_name $checksum_mode checksum must fail"
+ fi
+ grep -qi 'checksum' <<<"$checksum_output" || fail "$interpreter_name $checksum_mode checksum error"
+ done
+
+ reset_case
+ CASE_PLUGINS=1
+ run_installer "$case_root/plugins-home" "$case_root/plugins-install" "$case_root/plugins-bin" "$stable_tag" >/dev/null 2>&1
+ grep -Eq '\|installer\|[^|]*\|setup --target auto --yes --if-present$' "$composio_log" || fail "$interpreter_name plugin opt-in"
+
+ reset_case
+ CASE_QUIET=1
+ quiet_output=$(run_installer "$case_root/quiet-home" "$case_root/quiet-install" "$case_root/quiet-bin" "$stable_tag" 2>&1)
+ assert_not_contains "$quiet_output" 'Installing Composio CLI' "$interpreter_name quiet output"
+
+ reset_case
+ CASE_DEBUG=1
+ debug_output=$(run_installer "$case_root/debug-home" "$case_root/debug-install" "$case_root/debug-bin" "$stable_tag" 2>&1)
+ assert_contains "$debug_output" '+ curl GET' "$interpreter_name debug traces"
+
+ reset_case
+ CASE_HELP=0
+ help_suppressed=$(run_installer "$case_root/help-home" "$case_root/help-install" "$case_root/help-bin" "$stable_tag" 2>&1)
+ assert_not_contains "$help_suppressed" 'next step' "$interpreter_name help suppression"
+
+ reset_case
+ CASE_UNSET_SHELL=1
+ run_installer "$case_root/unset-shell-home" "$case_root/unset-shell-install" "$case_root/unset-shell-bin" "$stable_tag" >/dev/null 2>&1 ||
+ fail "$interpreter_name unset SHELL must not fail after installation"
+
+ # Runs the given command in the background, SIGTERMs it once the delayed
+ # download is reached, and asserts the process exits with 128+15.
+ assert_sigterm_143() {
+ local label=$1
+ local output_file=$2
+ shift 2
+ "$@" >"$output_file" 2>&1 &
+ local signal_job=$!
+ wait_for_file "$case_root/curl-parent.pid" "$interpreter_name $label did not reach delayed download"
+ local signal_pid
+ signal_pid=$(<"$case_root/curl-parent.pid")
+ kill -TERM "$signal_pid"
+ local signal_status=0
+ if wait "$signal_job"; then
+ fail "$interpreter_name $label must terminate after SIGTERM"
+ else
+ signal_status=$?
+ fi
+ [[ $signal_status -eq 143 ]] || fail "$interpreter_name $label SIGTERM status (got $signal_status)"
+ }
-env_opt_out_home="$tmpdir/home-env-opt-out"
-env_opt_out_install="$tmpdir/install-env-opt-out"
-mkdir -p "$env_opt_out_home" "$env_opt_out_install"
-: > "$composio_log"
-COMPOSIO_INSTALL_PLUGINS=0 run_installer "$env_opt_out_home" "$env_opt_out_install" >/dev/null 2>&1
-if grep -q '^setup ' "$composio_log"; then
- echo 'Expected COMPOSIO_INSTALL_PLUGINS=0 to skip agent plugin setup.' >&2
- cat "$composio_log" >&2
- exit 1
-fi
+ reset_case
+ CASE_CURL_DELAY_URL="$github_url/FakeOwner/fake-repo/releases/download/$stable_tag/$archive_name"
+ assert_sigterm_143 'installer' "$case_root/signal-installer.log" \
+ run_installer "$case_root/signal-home" "$case_root/signal-install" "$case_root/signal-bin" "$stable_tag"
+
+ reset_case
+ CASE_CURL_DELAY_URL=$script_url
+ assert_sigterm_143 'shell variant' "$case_root/signal-variant.log" \
+ run_variant zsh "$case_root/signal-variant-home" "$case_root/signal-variant-install" "$case_root/signal-variant-bin" "$stable_tag"
+
+ reset_case
+ CASE_GITHUB_URL='http://127.0.0.1:8929'
+ CASE_API_BASE='http://127.0.0.1:8929/api'
+ run_installer "$case_root/loopback-home" "$case_root/loopback-install" "$case_root/loopback-bin" "$stable_tag" >/dev/null 2>&1
+ grep -Fq -- '--proto =http,https --proto-redir =https' "$curl_log" || fail "$interpreter_name loopback protocol flags"
+
+ for unsafe_url in 'http://evil.example' 'http://[email protected]:8929' 'http://127.0.0.1.evil.example'; do
+ reset_case
+ CASE_GITHUB_URL=$unsafe_url
+ if run_installer "$case_root/unsafe-home-${RANDOM}" "$case_root/unsafe-install-${RANDOM}" "$case_root/unsafe-bin-${RANDOM}" "$stable_tag" >/dev/null 2>&1; then
+ fail "$interpreter_name unsafe configured URL accepted: $unsafe_url"
+ fi
+ [[ ! -s "$curl_log" ]] || fail "$interpreter_name unsafe configured URL reached curl"
+ done
+
+ reset_case
+ CASE_GITHUB_URL='http://host.docker.internal:8080'
+ CASE_API_BASE='http://host.docker.internal:8080/api'
+ if run_installer "$case_root/docker-denied-home" "$case_root/docker-denied-install" "$case_root/docker-denied-bin" "$stable_tag" >/dev/null 2>&1; then
+ fail "$interpreter_name host.docker.internal must require opt-in"
+ fi
+ CASE_ALLOW_HTTP_HOST=host.docker.internal
+ run_installer "$case_root/docker-home" "$case_root/docker-install" "$case_root/docker-bin" "$stable_tag" >/dev/null 2>&1
+
+ reset_case
+ CASE_API_ASSET_URL="http://evil.example/$archive_name"
+ if api_unsafe_output=$(run_installer "$case_root/api-unsafe-home" "$case_root/api-unsafe-install" "$case_root/api-unsafe-bin" 2>&1); then
+ fail "$interpreter_name unsafe API asset URL accepted"
+ fi
+ assert_contains "$api_unsafe_output" 'unsafe archive URL' "$interpreter_name unsafe API URL"
+
+ reset_case
+ CASE_REDIRECT_DOWNGRADE=1
+ if run_installer "$case_root/downgrade-home" "$case_root/downgrade-install" "$case_root/downgrade-bin" "$stable_tag" >/dev/null 2>&1; then
+ fail "$interpreter_name redirect downgrade simulation must fail"
+ fi
+ [[ ! -e "$case_root/downgrade-bin/composio" ]] || fail "$interpreter_name failed download must not install"
+
+ for shell_name in zsh bash fish; do
+ reset_case
+ variant_home="$case_root/variant-$shell_name-home"
+ variant_install="$case_root/variant-$shell_name-install"
+ variant_bin="$case_root/variant-$shell_name-bin"
+ variant_output=$(run_variant "$shell_name" "$variant_home" "$variant_install" "$variant_bin" "$stable_tag" --no-plugins 2>&1)
+ expected_variant_bin=$(cd "$variant_bin" && pwd -P)
+ grep -Fq "|installer|$expected_variant_bin|install --shell $shell_name" "$composio_log" ||
+ fail "$interpreter_name $shell_name variant delegation"
+ assert_contains "$variant_output" "Configured $shell_name shell setup (cli)." "$interpreter_name $shell_name variant confirmation"
+ assert_not_contains "$variant_output" 'Required next step' "$interpreter_name $shell_name variant must not print setup guidance"
+ assert_not_contains "$variant_output" 'Optional shell setup' "$interpreter_name $shell_name variant must not print setup guidance"
+ done
+
+ reset_case
+ CASE_INSTALL_SHELL=zsh
+ direct_home="$case_root/direct-shell-home"
+ direct_bin="$case_root/direct-shell-bin"
+ direct_output=$(run_installer "$direct_home" "$case_root/direct-shell-install" "$direct_bin" "$stable_tag" 2>&1)
+ expected_direct_bin=$(cd "$direct_bin" && pwd -P)
+ grep -Fq "|installer|$expected_direct_bin|install --shell zsh" "$composio_log" || fail "$interpreter_name COMPOSIO_INSTALL_SHELL delegation"
+ assert_contains "$direct_output" 'Configured zsh shell setup (cli).' "$interpreter_name COMPOSIO_INSTALL_SHELL confirmation"
+ assert_not_contains "$direct_output" 'Required next step' "$interpreter_name COMPOSIO_INSTALL_SHELL must not print setup guidance"
+ [[ ! -e "$direct_home/.zshrc" ]] || fail "$interpreter_name COMPOSIO_INSTALL_SHELL CLI path must not write rc files"
+
+ reset_case
+ CASE_INSTALL_SHELL=zsh
+ relative_work="$case_root/relative-shell-work"
+ relative_home="$case_root/relative-shell-home"
+ relative_install="$case_root/relative-shell-install"
+ mkdir -p "$relative_work"
+ (cd "$relative_work" && run_installer "$relative_home" "$relative_install" relative-bin "$stable_tag" >/dev/null 2>&1)
+ expected_relative_bin=$(cd "$relative_work/relative-bin" && pwd -P)
+ grep -Fq "|installer|$expected_relative_bin|install --shell zsh" "$composio_log" ||
+ fail "$interpreter_name relative COMPOSIO_BIN_DIR delegation must receive the resolved absolute path"
+
+ reset_case
+ CASE_INSTALL_SHELL=zsh
+ CASE_SHELL_CAPABILITY=unsupported
+ relative_fallback_work="$case_root/relative-fallback-work"
+ relative_fallback_home="$case_root/relative-fallback-home"
+ relative_fallback_install="$case_root/relative-fallback-install"
+ mkdir -p "$relative_fallback_work"
+ (cd "$relative_fallback_work" && run_installer "$relative_fallback_home" "$relative_fallback_install" relative-bin "$stable_tag" >/dev/null 2>&1)
+ expected_relative_fallback_bin=$(cd "$relative_fallback_work/relative-bin" && pwd -P)
+ grep -Fq "export PATH=\"$expected_relative_fallback_bin:\$PATH\"" "$relative_fallback_home/.zshrc" ||
+ fail "$interpreter_name relative COMPOSIO_BIN_DIR fallback must persist the resolved absolute path"
+
+ reset_case
+ CASE_INSTALL_SHELL=zsh
+ CASE_SHELL_CAPABILITY=unsupported
+ direct_fallback_home="$case_root/direct-fallback-home"
+ direct_fallback_output=$(run_installer "$direct_fallback_home" "$case_root/direct-fallback-install" "$case_root/direct-fallback-bin" "$stable_tag" 2>&1)
+ grep -Fqx '# Composio CLI' "$direct_fallback_home/.zshrc" || fail "$interpreter_name COMPOSIO_INSTALL_SHELL unsupported CLI fallback"
+ assert_contains "$direct_fallback_output" 'Configured zsh shell setup (fallback).' "$interpreter_name COMPOSIO_INSTALL_SHELL fallback confirmation"
+
+ reset_case
+ CASE_INSTALL_SHELL=fish
+ CASE_INSTALL_EXIT=23
+ direct_failed_home="$case_root/direct-failed-home"
+ run_installer "$direct_failed_home" "$case_root/direct-failed-install" "$case_root/direct-failed-bin" "$stable_tag" >/dev/null 2>&1
+ grep -Fqx '# Composio CLI' "$direct_failed_home/.config/fish/config.fish" || fail "$interpreter_name COMPOSIO_INSTALL_SHELL failed delegation fallback"
+
+ reset_case
+ CASE_INSTALL_SHELL=tcsh
+ if invalid_shell_output=$(run_installer "$case_root/invalid-shell-home" "$case_root/invalid-shell-install" "$case_root/invalid-shell-bin" 2>&1); then
+ fail "$interpreter_name invalid COMPOSIO_INSTALL_SHELL must fail"
+ fi
+ assert_contains "$invalid_shell_output" 'COMPOSIO_INSTALL_SHELL must be zsh, bash, or fish' "$interpreter_name invalid COMPOSIO_INSTALL_SHELL message"
+ [[ ! -s "$curl_log" ]] || fail "$interpreter_name invalid COMPOSIO_INSTALL_SHELL must fail before network"
+
+ reset_case
+ CASE_SHELL_CAPABILITY=unsupported
+ fallback_home="$case_root/fallback-home"
+ run_variant zsh "$fallback_home" "$case_root/fallback-install" "$case_root/fallback-bin" "$stable_tag" >/dev/null 2>&1
+ grep -Fqx '# Composio CLI' "$fallback_home/.zshrc" || fail "$interpreter_name unsupported CLI fallback"
+
+ reset_case
+ CASE_INSTALL_EXIT=23
+ failed_install_home="$case_root/failed-install-home"
+ run_variant zsh "$failed_install_home" "$case_root/failed-install-dir" "$case_root/failed-install-bin" "$stable_tag" >/dev/null 2>&1
+ grep -Fqx '# Composio CLI' "$failed_install_home/.zshrc" || fail "$interpreter_name failed --shell fallback"
+
+ reset_case
+ CASE_SHELL_CAPABILITY=unsupported
+ bash_fallback_home="$case_root/bash-fallback-home"
+ mkdir -p "$bash_fallback_home"
+ : >"$bash_fallback_home/.bash_profile"
+ run_variant bash "$bash_fallback_home" "$case_root/bash-fallback-install" "$case_root/bash-fallback-bin" "$stable_tag" >/dev/null 2>&1
+ grep -Fqx '# Composio CLI' "$bash_fallback_home/.bashrc" || fail "$interpreter_name bash fallback bashrc"
+ grep -Fqx '# Composio CLI' "$bash_fallback_home/.bash_profile" || fail "$interpreter_name bash fallback login override"
+
- for unsafe_character in ';' ':'; do
++ # The inline fallback embeds the resolved bin dir in an rc line, so a dir
++ # holding a character double quotes still expand -- `$`, a backtick, `"`, `\`
++ # -- or a structural `:` is refused outright, on the same set
++ # `composio install` refuses. A dir the CLI rejects must not slip into an rc
++ # file just because the CLI could not run.
++ injection_marker="$case_root/injection-marker"
++ unsafe_case=0
++ for unsafe_bin in "inject-\$(touch $injection_marker)" 'inject-`id`' 'inject-"quote"' 'inject\backslash' 'inject:colon'; do
+ reset_case
+ CASE_SHELL_CAPABILITY=unsupported
- unsafe_home="$case_root/unsafe-${unsafe_character//[^[:alnum:]]/delimiter}-variant-home"
- if run_variant zsh "$unsafe_home" "$case_root/unsafe-variant-install" "$case_root/unsafe${unsafe_character}variant-bin" "$stable_tag" >/dev/null 2>&1; then
- fail "$interpreter_name unsafe variant bin dir with $unsafe_character must fail"
++ unsafe_case=$((unsafe_case + 1))
++ unsafe_home="$case_root/unsafe-$unsafe_case-variant-home"
++ if run_variant zsh "$unsafe_home" "$case_root/unsafe-variant-install" "$case_root/$unsafe_bin" "$stable_tag" >/dev/null 2>&1; then
++ fail "$interpreter_name unsafe variant bin dir must fail: $unsafe_bin"
+ fi
- [[ ! -e "$unsafe_home/.zshrc" ]] || fail "$interpreter_name unsafe variant must not write rc file"
++ [[ ! -e "$unsafe_home/.zshrc" ]] || fail "$interpreter_name unsafe variant must not write rc file: $unsafe_bin"
+ done
++ [[ ! -e "$injection_marker" ]] || fail "$interpreter_name command substitution in the bin dir must never run"
++
++ # The denylist stops at what double quotes actually expand: characters that
++ # are literal there stay legal and are written verbatim.
++ reset_case
++ CASE_SHELL_CAPABILITY=unsupported
++ literal_home="$case_root/literal-variant-home"
++ literal_bin="$case_root/o'brien;bin"
++ run_variant zsh "$literal_home" "$case_root/literal-variant-install" "$literal_bin" "$stable_tag" >/dev/null 2>&1
++ expected_literal_bin=$(cd "$literal_bin" && pwd -P)
++ grep -Fq "export PATH=\"$expected_literal_bin:\$PATH\"" "$literal_home/.zshrc" ||
++ fail "$interpreter_name apostrophe bin dir must be written verbatim"
+
+ for base_mode in fail empty; do
+ reset_case
+ CASE_BASE_MODE=$base_mode
+ base_failure_home="$case_root/base-$base_mode-home"
+ if run_variant zsh "$base_failure_home" "$case_root/base-$base_mode-install" "$case_root/base-$base_mode-bin" "$stable_tag" >/dev/null 2>&1; then
+ fail "$interpreter_name $base_mode base installer download must fail"
+ fi
+ [[ ! -e "$base_failure_home/.zshrc" ]] || fail "$interpreter_name $base_mode download must not write rc"
+ done
-failed_setup_home="$tmpdir/home-failed-setup"
-failed_setup_install="$tmpdir/install-failed-setup"
-mkdir -p "$failed_setup_home" "$failed_setup_install"
-: > "$composio_log"
-if failed_output=$(TEST_SETUP_EXIT=23 run_installer "$failed_setup_home" "$failed_setup_install" 2>&1); then
- echo 'Expected installer to fail when detected agent plugin setup fails.' >&2
- exit 1
-fi
-if ! grep -q 'Composio CLI was installed, but agent plugin setup failed' <<<"$failed_output"; then
- echo 'Expected installer to explain how to retry failed plugin setup.' >&2
- printf '%s\n' "$failed_output" >&2
- exit 1
-fi
+ printf 'install scripts passed under %s\n' "$interpreter_name"
+done
-printf 'install.sh release fallback, shell integration, and plugin setup tests passed\n'
+printf 'install.sh release resolution, layout, security, and shell-variant tests passed\n'
diff --cc ts/packages/cli/src/commands/install.cmd.ts
index d90e47a28,9e1f6a5e9..ef82ac3dc
--- a/ts/packages/cli/src/commands/install.cmd.ts
+++ b/ts/packages/cli/src/commands/install.cmd.ts
@@@ -275,6 -328,47 +328,53 @@@ const replaceFilePreservingMode =
yield* fs.rename(tmpPath, writeTarget);
});
+ /**
+ * Apply one rc file's queued changes: a stale managed block is spliced in
+ * place, everything else is appended at the end.
+ */
+ const applyFileChanges = (params: {
+ readonly filePath: string;
++ readonly resolvedWriteTarget: Option.Option<string>;
+ readonly rewritePathBlock: Option.Option<string>;
+ readonly appendBlocks: ReadonlyArray<string>;
+ readonly fs: FileSystem.FileSystem;
+ readonly path: Path.Path;
+ }): Effect.Effect<void, PlatformError> =>
+ Effect.gen(function* () {
+ const { filePath, fs, path } = params;
+
+ // Re-read instead of reusing the pre-check snapshot: two configured paths
+ // can alias the same physical file through symlinks, and this write must
+ // not discard a previous iteration's append.
+ const existingContents = yield* readMaybeMissingFile(filePath, fs);
- const writeTarget = yield* resolveWriteTarget(filePath, fs);
++ // PATH files were already resolved by the caller; only the completion file
++ // needs a fresh resolve.
++ const writeTarget = yield* Option.match(params.resolvedWriteTarget, {
++ onNone: () => resolveWriteTarget(filePath, fs),
++ onSome: Effect.succeed,
++ });
+
+ yield* fs
+ .makeDirectory(path.dirname(writeTarget), { recursive: true })
+ .pipe(
+ Effect.catchAll(e =>
+ Effect.logDebug('Could not create parent directory (may already exist):', e)
+ )
+ );
+
+ const migrated = Option.match(params.rewritePathBlock, {
+ onNone: () => existingContents,
+ onSome: block =>
+ Option.getOrElse(replaceManagedPathBlock(existingContents, block), () => existingContents),
+ });
+ const contents =
+ params.appendBlocks.length > 0
+ ? migrated + '\n' + params.appendBlocks.join('\n\n') + '\n'
+ : migrated;
+
+ yield* replaceFilePreservingMode(writeTarget, contents, fs);
+ });
+
// ---------------------------------------------------------------------------
// Exported logic (reusable from install.sh post-install delegation)
// ---------------------------------------------------------------------------
@@@ -474,26 -566,21 +572,22 @@@ export const installShellIntegration =
}
}
- if (blocksByFile.size > 0) {
- for (const [filePath, blocks] of blocksByFile.entries()) {
- // Re-read instead of reusing the pre-check snapshot: two configured paths
- // can alias the same physical file through symlinks, and this write must
- // not discard a previous iteration's append.
- const existingContents = yield* readMaybeMissingFile(filePath, fs);
- // PATH files were already resolved above; only the completion file needs a fresh resolve.
- const writeTarget =
- pathFileTargets.get(filePath) ?? (yield* resolveWriteTarget(filePath, fs));
-
- yield* fs
- .makeDirectory(path.dirname(writeTarget), { recursive: true })
- .pipe(
- Effect.catchAll(e =>
- Effect.logDebug('Could not create parent directory (may already exist):', e)
- )
- );
-
- const appendContent = '\n' + blocks.join('\n\n') + '\n';
- yield* replaceFilePreservingMode(writeTarget, existingContents + appendContent, fs);
+ const filesToWrite = [...new Set([...pathRewrites, ...blocksByFile.keys()])];
+
+ if (filesToWrite.length > 0) {
+ for (const filePath of filesToWrite) {
+ // A stale managed block is replaced where it stands, so the user's own
+ // ordering survives; everything else is appended.
+ yield* applyFileChanges({
+ filePath,
++ resolvedWriteTarget: Option.fromNullable(pathFileTargets.get(filePath)),
+ rewritePathBlock: pathRewrites.has(filePath)
+ ? Option.some(config.pathBlock)
+ : Option.none(),
+ appendBlocks: blocksByFile.get(filePath) ?? [],
+ fs,
+ path,
+ });
yield* success(`Updated ${tildify(filePath, os.homedir)}`);
}
diff --cc ts/packages/cli/test/__utils__/services/test-layer.ts
index 5bbbd3546,300ccdefe..03db1ee04
--- a/ts/packages/cli/test/__utils__/services/test-layer.ts
+++ b/ts/packages/cli/test/__utils__/services/test-layer.ts
@@@ -85,22 -86,15 +86,26 @@@ export interface TestLiveInput
fixture?: string;
/**
- * Override for the mocked `NodeProcess.execPath`. A relative value resolves
- * against the test home directory, which is only known once the layer builds.
- * Defaults to `<cwd>/composio`.
- * Mock toolkit-related data to use in test.
++ * Override the running-executable path reported by `NodeProcess`.
++ *
++ * A relative value resolves against the per-test home directory, which is a
++ * fresh temp dir created while the layer is being built — so a scenario that
++ * needs an exec path underneath it (e.g. `.local/bin/composio`) can stay
++ * relative instead of spelling out a path it cannot know up front.
++ * Defaults to `<homedir>/composio`.
*/
- toolkitsData?: {
- toolkits?: Toolkits;
- detailedToolkits?: ToolkitDetailed[];
- tools?: Tools;
- triggerTypesAsEnums?: TriggerTypesAsEnums;
- triggerTypes?: TriggerTypes;
- };
+ execPath?: string;
+
+ /**
- * Mock toolkit-related data to use in test.
- */
- toolkitsData?: {
- toolkits?: Toolkits;
- detailedToolkits?: ToolkitDetailed[];
- tools?: Tools;
- triggerTypesAsEnums?: TriggerTypesAsEnums;
- triggerTypes?: TriggerTypes;
- };
++ * Mock toolkit-related data to use in test.
++ */
++toolkitsData?: {
++ toolkits?: Toolkits;
++ detailedToolkits?: ToolkitDetailed[];
++ tools?: Tools;
++ triggerTypesAsEnums?: TriggerTypesAsEnums;
++ triggerTypes?: TriggerTypes;
++};
/**
* Mock auth-config data to use in test.
diff --cc ts/packages/cli/test/src/commands/install.cmd.test.ts
index 480b43151,5d1f3c014..ac376057b
--- a/ts/packages/cli/test/src/commands/install.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/install.cmd.test.ts
@@@ -39,8 -40,15 +40,16 @@@ const capturedStderrUI = makeTerminalUI
const SAFE_PATH = '/usr/bin:/bin';
const TEST_EXEC_PATH = '/usr/local/bin/composio';
const expectedRuntimeBinDir = (): string => path.dirname(TEST_EXEC_PATH);
- const InstallTestLive = (input: Parameters<typeof TestLive>[0] = {}) =>
+
+ /**
+ * `installShellIntegration` reads the running executable from `NodeProcess`, so
+ * a scenario picks its exec path when it builds the layer, not when it calls
- * the command.
++ * the command. A relative override resolves against the per-test home dir,
++ * which only exists once the layer builds.
+ */
+ const TestInstallLive = (input: TestLiveInput = {}) =>
- TestLive({ execPath: () => TEST_EXEC_PATH, ...input });
+ TestLive({ execPath: TEST_EXEC_PATH, ...input });
+
const install = (
params: {
readonly completions?: boolean;
@@@ -843,7 -977,9 +978,7 @@@ describe('CLI: composio install', () =
});
describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin/composio is the running executable', () => {
- layer(TestLive({ execPath: '.local/bin/composio' }))(it => {
- layer(
- TestInstallLive({ execPath: homedir => path.join(homedir, '.local', 'bin', 'composio') })
- )(it => {
++ layer(TestInstallLive({ execPath: '.local/bin/composio' }))(it => {
it.scoped('[Then] the PATH line targets ~/.local/bin via a literal $HOME prefix', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
@@@ -865,8 -1001,27 +1000,25 @@@
});
});
+ describe('[When] the resolved bin dir contains an apostrophe', () => {
- layer(TestInstallLive({ execPath: () => "/opt/o'brien/bin/composio" }))(it => {
++ layer(TestInstallLive({ execPath: "/opt/o'brien/bin/composio" }))(it => {
+ it.scoped("[Then] it is written verbatim, since `'` is literal inside double quotes", () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/zsh');
+
+ yield* install();
+
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ expect(contents).toContain(`export PATH="/opt/o'brien/bin:$PATH"`);
+ })
+ );
+ });
+ });
+
describe('[When] ~/.local/bin/composio is a symlink chain to the running executable', () => {
- layer(TestLive({ execPath: '.composio-dist/composio' }))(it => {
- layer(
- TestInstallLive({ execPath: homedir => path.join(homedir, '.composio-dist', 'composio') })
- )(it => {
++ layer(TestInstallLive({ execPath: '.composio-dist/composio' }))(it => {
it.scoped('[Then] the PATH line still targets ~/.local/bin', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
@@@ -916,7 -1071,9 +1068,7 @@@
});
describe('[When] COMPOSIO_BIN_DIR is set and ~/.local/bin/composio is also the running executable', () => {
- layer(TestLive({ execPath: '.local/bin/composio' }))(it => {
- layer(
- TestInstallLive({ execPath: homedir => path.join(homedir, '.local', 'bin', 'composio') })
- )(it => {
++ layer(TestInstallLive({ execPath: '.local/bin/composio' }))(it => {
it.scoped('[Then] the env var wins over the ~/.local/bin fallback', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
@@@ -1015,7 -1172,7 +1167,7 @@@
});
describe('[When] the runtime executable resolves to an unsafe directory', () => {
- layer(InstallTestLive({ execPath: "/tmp/o'brien/composio" }))(it => {
- layer(TestInstallLive({ execPath: () => '/tmp/we`ird/composio' }))(it => {
++ layer(TestInstallLive({ execPath: '/tmp/we`ird/composio' }))(it => {
it.scoped('[Then] reports an origin-neutral error', () =>
Effect.gen(function* () {
vi.stubEnv('SHELL', '/bin/zsh');