@devries-cameron20 / composio Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
sh 270 lines 8.42 KB
Raw
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5 suite_tmp="$(mktemp -d)"
6 survivor_pid=
7
8 cleanup() {
9 if [[ -n ${survivor_pid:-} ]]; then
10 kill "$survivor_pid" 2>/dev/null || true
11 wait "$survivor_pid" 2>/dev/null || true
12 fi
13 rm -rf "$suite_tmp"
14 }
15 trap cleanup EXIT
16
17 fail() {
18 printf 'FAIL: %s\n' "$*" >&2
19 exit 1
20 }
21
22 stat_inode() {
23 if stat -f '%i' "$1" >/dev/null 2>&1; then
24 stat -f '%i' "$1"
25 else
26 stat -c '%i' "$1"
27 fi
28 }
29
30 assert_no_residue() {
31 local install_dir=$1
32 if find "$install_dir" -maxdepth 1 \( -name '.composio-install.*' -o -name '.composio-aside.*' \) -print -quit | grep -q .; then
33 fail "installer residue remains in $install_dir"
34 fi
35 }
36
37 platform=$(uname -ms)
38 case $platform in
39 'Darwin x86_64') target=darwin-x64 ;;
40 'Darwin arm64') target=darwin-aarch64 ;;
41 'Linux aarch64'|'Linux arm64') target=linux-aarch64 ;;
42 'Linux x86_64') target=linux-x64 ;;
43 *) fail "unsupported test platform: $platform" ;;
44 esac
45
46 fake_bin="$suite_tmp/bin"
47 mkdir -p "$fake_bin"
48
49 cat >"$fake_bin/curl" <<'EOF'
50 #!/usr/bin/env bash
51 set -euo pipefail
52 output=
53 url=
54 while (($# > 0)); do
55 case $1 in
56 --output|-o)
57 output=$2
58 shift 2
59 ;;
60 --proto|--proto-redir)
61 shift 2
62 ;;
63 --fail|--silent|--show-error|--location|--progress-bar)
64 shift
65 ;;
66 --*) shift ;;
67 *)
68 url=$1
69 shift
70 ;;
71 esac
72 done
73
74 case $url in
75 */checksums.txt) exit 22 ;;
76 *) printf 'fixture archive\n' >"$output" ;;
77 esac
78 EOF
79 chmod +x "$fake_bin/curl"
80
81 cat >"$fake_bin/unzip" <<'EOF'
82 #!/usr/bin/env bash
83 set -euo pipefail
84 dest=
85 while (($# > 0)); do
86 case $1 in
87 -d)
88 dest=$2
89 shift 2
90 ;;
91 -*d)
92 dest=$2
93 shift 2
94 ;;
95 *) shift ;;
96 esac
97 done
98
99 bundle="$dest/composio-$TEST_TARGET"
100 mkdir -p "$bundle/services" "$bundle/acp-adapters"
101 printf '%s\n' 'new-support' >"$bundle/run-bun.mjs"
102 printf '%s\n' 'new-service' >"$bundle/services/example.txt"
103 printf '%s\n' 'new-adapter' >"$bundle/acp-adapters/current.txt"
104
105 if [[ ${TEST_ARCHIVE_MODE:-complete} == with-sidecars ]]; then
106 mkdir -p "$bundle/local-tools-binaries/peekaboo"
107 printf '%s\n' bundled-sidecar >"$bundle/local-tools-binaries/peekaboo/peekaboo"
108 fi
109
110 if [[ ${TEST_ARCHIVE_MODE:-complete} == missing-binary ]]; then
111 exit 0
112 fi
113
114 cat >"$bundle/composio" <<'BIN'
115 #!/bin/sh
116 # new-binary-marker
117 case ${1:-} in
118 --version|version) printf '%s\n' 'composio fixture 98.0.0' ;;
119 *) printf '%s\n' 'new-binary' ;;
120 esac
121 BIN
122 chmod +x "$bundle/composio"
123 EOF
124 chmod +x "$fake_bin/unzip"
125
126 cat >"$fake_bin/rm" <<'EOF'
127 #!/usr/bin/env bash
128 set -euo pipefail
129
130 if [[ ${TEST_FAIL_ASIDE_CLEANUP:-} == 1 ]]; then
131 for arg in "$@"; do
132 case $arg in
133 */.composio-aside.acp-adapters) exit 23 ;;
134 esac
135 done
136 fi
137
138 exec /bin/rm "$@"
139 EOF
140 chmod +x "$fake_bin/rm"
141
142 interpreters=("$(command -v sh)")
143 if command -v dash >/dev/null 2>&1 && [[ $(command -v dash) != "${interpreters[0]}" ]]; then
144 interpreters+=("$(command -v dash)")
145 fi
146
147 version='@composio/cli@98.0.0'
148 for interpreter in "${interpreters[@]}"; do
149 interpreter_name=$(basename "$interpreter")
150 case_root="$suite_tmp/$interpreter_name"
151 install_dir="$case_root/install"
152 home="$case_root/home"
153 mkdir -p "$install_dir" "$home"
154
155 run_installer() {
156 local archive_mode=$1
157 local fail_aside_cleanup=${2:-0}
158 env \
159 PATH="$fake_bin:$PATH" \
160 HOME="$home" \
161 COMPOSIO_INSTALL_DIR="$install_dir" \
162 COMPOSIO_BIN_DIR="$install_dir" \
163 COMPOSIO_INSTALL_PLUGINS=0 \
164 COMPOSIO_INSTALL_HELP=0 \
165 COMPOSIO_QUIET=1 \
166 COMPOSIO_GITHUB_URL=https://github.example.test \
167 COMPOSIO_GITHUB_OWNER=FakeOwner \
168 COMPOSIO_GITHUB_REPO=fake-repo \
169 TEST_TARGET="$target" \
170 TEST_ARCHIVE_MODE="$archive_mode" \
171 TEST_FAIL_ASIDE_CLEANUP="$fail_aside_cleanup" \
172 "$interpreter" "$repo_root/install.sh" "$version"
173 }
174
175 run_installer complete >/dev/null 2>&1
176 [[ -x "$install_dir/composio" ]] || fail "$interpreter_name empty install executable"
177 [[ -f "$install_dir/run-bun.mjs" ]] || fail "$interpreter_name empty install support file"
178 [[ -f "$install_dir/services/example.txt" ]] || fail "$interpreter_name empty install service"
179 [[ -f "$install_dir/acp-adapters/current.txt" ]] ||
180 fail "$interpreter_name empty install adapter"
181 [[ $(<"$install_dir/release-tag.txt") == "$version" ]] ||
182 fail "$interpreter_name empty install metadata"
183 assert_no_residue "$install_dir"
184
185 run_installer with-sidecars >/dev/null 2>&1
186 sidecar="$install_dir/local-tools-binaries/peekaboo/peekaboo"
187 [[ -f "$sidecar" ]] || fail "$interpreter_name install removed bundled sidecar"
188 [[ $(<"$sidecar") == bundled-sidecar ]] || fail "$interpreter_name installed sidecar contents"
189 printf '%s\n' outdated >"$sidecar"
190 printf '%s\n' stale >"$install_dir/local-tools-binaries/stale.txt"
191 run_installer with-sidecars >/dev/null 2>&1
192 [[ -f "$sidecar" ]] || fail "$interpreter_name reinstall removed bundled sidecar"
193 [[ $(<"$sidecar") == bundled-sidecar ]] || fail "$interpreter_name reinstall sidecar contents"
194 [[ ! -e "$install_dir/local-tools-binaries/stale.txt" ]] ||
195 fail "$interpreter_name reinstall retained stale sidecar contents"
196 assert_no_residue "$install_dir"
197
198 marker="$case_root/old-process"
199 cat >"$install_dir/composio" <<'EOF'
200 #!/bin/sh
201 marker=$1
202 : >"$marker.ready"
203 while [ ! -f "$marker.release" ]; do
204 sleep 0.05
205 done
206 printf '%s\n' old-process >"$marker.result"
207 EOF
208 chmod +x "$install_dir/composio"
209 printf '%s\n' stale >"$install_dir/acp-adapters/stale.txt"
210 mkdir -p "$install_dir/local-tools-binaries/peekaboo"
211 printf '%s\n' legacy >"$install_dir/local-tools-binaries/peekaboo/peekaboo"
212 old_inode=$(stat_inode "$install_dir/composio")
213 "$install_dir/composio" "$marker" &
214 survivor_pid=$!
215 for _ in {1..100}; do
216 [[ -f "$marker.ready" ]] && break
217 sleep 0.05
218 done
219 [[ -f "$marker.ready" ]] || fail "$interpreter_name old process did not start"
220
221 run_installer complete >/dev/null 2>&1
222 new_inode=$(stat_inode "$install_dir/composio")
223 [[ $new_inode != "$old_inode" ]] || fail "$interpreter_name reinstall kept the binary inode"
224 grep -Fq 'new-binary-marker' "$install_dir/composio" ||
225 fail "$interpreter_name reinstall binary contents"
226 [[ ! -e "$install_dir/acp-adapters/stale.txt" ]] ||
227 fail "$interpreter_name reinstall retained stale directory contents"
228 [[ ! -e "$install_dir/local-tools-binaries" ]] ||
229 fail "$interpreter_name reinstall retained obsolete local-tools-binaries"
230 : >"$marker.release"
231 wait "$survivor_pid"
232 survivor_pid=
233 [[ $(<"$marker.result") == old-process ]] || fail "$interpreter_name old process changed"
234 assert_no_residue "$install_dir"
235
236 binary_before=$(<"$install_dir/composio")
237 support_before=$(<"$install_dir/run-bun.mjs")
238 tag_before=$(<"$install_dir/release-tag.txt")
239 if missing_output=$(run_installer missing-binary 2>&1); then
240 fail "$interpreter_name missing binary archive succeeded"
241 fi
242 grep -Fq 'Binary not found in extracted archive' <<<"$missing_output" ||
243 fail "$interpreter_name missing binary error"
244 [[ $(<"$install_dir/composio") == "$binary_before" ]] ||
245 fail "$interpreter_name missing binary changed executable"
246 [[ $(<"$install_dir/run-bun.mjs") == "$support_before" ]] ||
247 fail "$interpreter_name missing binary changed support file"
248 [[ $(<"$install_dir/release-tag.txt") == "$tag_before" ]] ||
249 fail "$interpreter_name missing binary changed metadata"
250 assert_no_residue "$install_dir"
251
252 printf '%s\n' old-aside >"$install_dir/acp-adapters/recoverable.txt"
253 if ! aside_cleanup_output=$(run_installer complete 1 2>&1); then
254 fail "$interpreter_name aside cleanup failure aborted published install"
255 fi
256 grep -Fq 'Published install entry; previous contents retained at' <<<"$aside_cleanup_output" ||
257 fail "$interpreter_name aside cleanup warning"
258 grep -Fq 'Published CLI; retained recovery staging directory at' <<<"$aside_cleanup_output" ||
259 fail "$interpreter_name retained staging warning"
260 grep -Fq 'new-binary-marker' "$install_dir/composio" ||
261 fail "$interpreter_name aside cleanup did not publish executable"
262 retained_stage=$(find "$install_dir" -maxdepth 1 -type d -name '.composio-install.*' -print -quit)
263 [[ -n $retained_stage ]] || fail "$interpreter_name missing retained recovery staging directory"
264 [[ $(<"$retained_stage/.composio-aside.acp-adapters/recoverable.txt") == old-aside ]] ||
265 fail "$interpreter_name retained aside is not recoverable"
266
267 printf 'install.sh atomic replacement passed under %s\n' "$interpreter_name"
268 done
269
270 printf 'install.sh atomic replacement tests passed\n'