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

next
sh 306 lines 11.1 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
7 cleanup() {
8 rm -rf "$suite_tmp"
9 }
10 trap cleanup EXIT
11
12 fail() {
13 printf 'FAIL: %s\n' "$*" >&2
14 exit 1
15 }
16
17 stat_inode() {
18 if stat -f '%i' "$1" >/dev/null 2>&1; then
19 stat -f '%i' "$1"
20 else
21 stat -c '%i' "$1"
22 fi
23 }
24
25 stat_mode() {
26 if stat -f '%Lp' "$1" >/dev/null 2>&1; then
27 stat -f '%Lp' "$1"
28 else
29 stat -c '%a' "$1"
30 fi
31 }
32
33 assert_no_predictable_tmp() {
34 if find "$1" -name '*.tmp' -print -quit | grep -q .; then
35 fail "$2 left a predictable *.tmp file behind"
36 fi
37 }
38
39 assert_dir_empty() {
40 if find "$1" -mindepth 1 -print -quit | grep -q .; then
41 fail "$2 left files in the scratch TMPDIR"
42 fi
43 }
44
45 # Extract the uninstall snippet verbatim from the docs so this suite can never
46 # drift from what users actually run: the first ```bash fence after the
47 # "### Uninstall" heading.
48 docs_file="$repo_root/docs/content/docs/cli.mdx"
49 snippet_file="$suite_tmp/uninstall-snippet.sh"
50 awk '
51 /^### Uninstall$/ { in_section = 1; next }
52 in_section && $0 == "```bash" && !captured { in_block = 1; next }
53 in_block && $0 == "```" { captured = 1; in_block = 0; next }
54 in_block { print }
55 ' "$docs_file" >"$snippet_file"
56 [[ -s $snippet_file ]] || fail "could not extract the uninstall snippet from $docs_file"
57 grep -Fq 'for file in' "$snippet_file" || fail "extracted snippet is missing the startup-file loop"
58 grep -Fq 'mktemp' "$snippet_file" || fail "extracted snippet does not stage rewrites through mktemp"
59 ! grep -Fq 'chmod' "$snippet_file" || fail "extracted snippet must not loosen mktemp permissions"
60
61 real_mktemp=$(command -v mktemp)
62
63 # awk stand-in that emits partial output and fails, to prove a broken filter
64 # never reaches the startup file.
65 fail_bin="$suite_tmp/fail-bin"
66 mkdir -p "$fail_bin"
67 cat >"$fail_bin/awk" <<'EOF'
68 #!/usr/bin/env bash
69 printf 'partial filter output\n'
70 exit 1
71 EOF
72 chmod +x "$fail_bin/awk"
73
74 # mktemp stand-in that records mode-at-creation and path of every scratch file
75 # so the suite can assert 0600 under umask 022 and cleanup afterwards.
76 log_bin="$suite_tmp/log-bin"
77 mkdir -p "$log_bin"
78 cat >"$log_bin/mktemp" <<EOF
79 #!/usr/bin/env bash
80 set -euo pipefail
81 out=\$("$real_mktemp" "\$@")
82 if stat -f '%Lp' "\$out" >/dev/null 2>&1; then
83 mode=\$(stat -f '%Lp' "\$out")
84 else
85 mode=\$(stat -c '%a' "\$out")
86 fi
87 printf '%s %s\n' "\$mode" "\$out" >>"\$MKTEMP_LOG"
88 printf '%s\n' "\$out"
89 EOF
90 chmod +x "$log_bin/mktemp"
91
92 interpreters=("$(command -v sh)")
93 if command -v dash >/dev/null 2>&1 && [[ $(command -v dash) != "${interpreters[0]}" ]]; then
94 interpreters+=("$(command -v dash)")
95 fi
96
97 for interpreter in "${interpreters[@]}"; do
98 interpreter_name=$(basename "$interpreter")
99 case_root="$suite_tmp/$interpreter_name"
100
101 run_snippet() {
102 local case_home=$1
103 shift
104 env "$@" \
105 HOME="$case_home" \
106 COMPOSIO_INSTALL_DIR="$case_home/.composio" \
107 COMPOSIO_BIN_DIR="$case_home/.local/bin" \
108 "$interpreter" "$snippet_file"
109 }
110
111 # --- Removes modern POSIX, modern fish, and legacy three-line blocks while
112 # --- keeping unrelated content; also removes release artifacts. Runs with
113 # --- TMPDIR unset to prove mktemp still lands somewhere valid.
114 home_main="$case_root/main-home"
115 mkdir -p "$home_main/.config/fish" "$home_main/.composio/services" "$home_main/.local/bin"
116 printf 'binary\n' >"$home_main/.composio/composio"
117 printf 'service\n' >"$home_main/.composio/services/example.txt"
118 mkdir -p "$home_main/.composio/local-tools-binaries/peekaboo"
119 printf 'sidecar\n' >"$home_main/.composio/local-tools-binaries/peekaboo/peekaboo"
120 printf 'keep me\n' >"$home_main/.composio/user-data.json"
121 ln -s "$home_main/.composio/composio" "$home_main/.local/bin/composio"
122 cat >"$home_main/.zshrc" <<'EOF'
123 # user zshrc top
124 alias ll='ls -l'
125
126 # Composio CLI
127 export PATH="$HOME/.local/bin:$PATH"
128
129 # user zshrc bottom
130 EOF
131 cat >"$home_main/.bashrc" <<'EOF'
132 # user bashrc
133
134 # Composio CLI
135 export COMPOSIO_INSTALL_DIR="$HOME/.composio"
136 export PATH="$COMPOSIO_INSTALL_DIR:$PATH"
137
138 alias gs='git status'
139 EOF
140 cat >"$home_main/.config/fish/config.fish" <<'EOF'
141 # user fish config
142
143 # Composio CLI
144 set --export PATH "$HOME/.local/bin" $PATH
145
146 # Composio CLI
147 set --export COMPOSIO_INSTALL_DIR "$HOME/.composio"
148 set --export PATH $COMPOSIO_INSTALL_DIR $PATH
149
150 set -gx EDITOR vim
151 EOF
152
153 run_snippet "$home_main" -u TMPDIR
154
155 for startup in "$home_main/.zshrc" "$home_main/.bashrc" "$home_main/.config/fish/config.fish"; do
156 ! grep -Fxq '# Composio CLI' "$startup" || fail "$interpreter_name kept the marker in $startup"
157 ! grep -Fq 'COMPOSIO_INSTALL_DIR' "$startup" || fail "$interpreter_name kept a legacy line in $startup"
158 done
159 ! grep -Fq 'export PATH=' "$home_main/.zshrc" || fail "$interpreter_name kept the modern POSIX PATH line"
160 ! grep -Fq 'set --export PATH' "$home_main/.config/fish/config.fish" ||
161 fail "$interpreter_name kept a fish PATH line"
162 grep -Fq "alias ll='ls -l'" "$home_main/.zshrc" || fail "$interpreter_name lost unrelated zshrc content"
163 grep -Fq '# user zshrc bottom' "$home_main/.zshrc" || fail "$interpreter_name lost trailing zshrc content"
164 grep -Fq "alias gs='git status'" "$home_main/.bashrc" || fail "$interpreter_name lost unrelated bashrc content"
165 grep -Fq 'set -gx EDITOR vim' "$home_main/.config/fish/config.fish" ||
166 fail "$interpreter_name lost unrelated fish content"
167 [[ ! -e "$home_main/.local/bin/composio" ]] || fail "$interpreter_name kept the bin entry point"
168 [[ ! -e "$home_main/.composio/composio" ]] || fail "$interpreter_name kept the installed binary"
169 [[ ! -e "$home_main/.composio/services" ]] || fail "$interpreter_name kept the services directory"
170 [[ ! -e "$home_main/.composio/local-tools-binaries" ]] || fail "$interpreter_name kept legacy sidecars"
171 [[ -f "$home_main/.composio/user-data.json" ]] || fail "$interpreter_name deleted user state"
172 assert_no_predictable_tmp "$home_main" "$interpreter_name main case"
173
174 # --- A symlinked startup file stays a symlink; the target keeps its inode
175 # --- and gets the filtered content.
176 home_link="$case_root/symlink-home"
177 tmp_link="$case_root/tmp-link"
178 mkdir -p "$home_link/dotfiles" "$tmp_link"
179 cat >"$home_link/dotfiles/zshrc" <<'EOF'
180 # managed by dotfiles
181 # Composio CLI
182 export PATH="$HOME/.local/bin:$PATH"
183 alias dot='true'
184 EOF
185 ln -s "$home_link/dotfiles/zshrc" "$home_link/.zshrc"
186 link_inode=$(stat_inode "$home_link/dotfiles/zshrc")
187
188 run_snippet "$home_link" TMPDIR="$tmp_link"
189
190 [[ -L "$home_link/.zshrc" ]] || fail "$interpreter_name replaced the startup symlink with a file"
191 [[ $(readlink "$home_link/.zshrc") == "$home_link/dotfiles/zshrc" ]] ||
192 fail "$interpreter_name repointed the startup symlink"
193 [[ $(stat_inode "$home_link/dotfiles/zshrc") == "$link_inode" ]] ||
194 fail "$interpreter_name replaced the symlink target inode"
195 ! grep -Fxq '# Composio CLI' "$home_link/dotfiles/zshrc" ||
196 fail "$interpreter_name kept the marker in the symlink target"
197 grep -Fq "alias dot='true'" "$home_link/dotfiles/zshrc" ||
198 fail "$interpreter_name lost content in the symlink target"
199 assert_dir_empty "$tmp_link" "$interpreter_name symlink case"
200
201 # --- A 0600 startup file keeps its mode, and under umask 022 the scratch
202 # --- file is created 0600 (never more readable) and always removed.
203 home_mode="$case_root/mode-home"
204 tmp_mode="$case_root/tmp-mode"
205 mktemp_log="$case_root/mktemp-mode.log"
206 mkdir -p "$home_mode" "$tmp_mode"
207 : >"$mktemp_log"
208 cat >"$home_mode/.zshrc" <<'EOF'
209 export SECRET_TOKEN=hunter2
210
211 # Composio CLI
212 export PATH="$HOME/.local/bin:$PATH"
213 EOF
214 chmod 600 "$home_mode/.zshrc"
215
216 (
217 umask 022
218 run_snippet "$home_mode" PATH="$log_bin:$PATH" TMPDIR="$tmp_mode" MKTEMP_LOG="$mktemp_log"
219 )
220
221 [[ $(stat_mode "$home_mode/.zshrc") == 600 ]] || fail "$interpreter_name changed the 0600 startup mode"
222 grep -Fq 'SECRET_TOKEN=hunter2' "$home_mode/.zshrc" || fail "$interpreter_name lost the secret line"
223 ! grep -Fxq '# Composio CLI' "$home_mode/.zshrc" || fail "$interpreter_name kept the marker in the 0600 file"
224 [[ -s $mktemp_log ]] || fail "$interpreter_name mode case never called mktemp"
225 while read -r scratch_mode scratch_path; do
226 [[ $scratch_mode == 600 ]] ||
227 fail "$interpreter_name scratch file $scratch_path was created with mode $scratch_mode"
228 [[ ! -e $scratch_path ]] || fail "$interpreter_name left scratch file $scratch_path behind"
229 done <"$mktemp_log"
230 assert_dir_empty "$tmp_mode" "$interpreter_name mode case"
231
232 # --- A failing filter (awk overridden to emit partial output and exit 1)
233 # --- leaves the startup file byte-identical and cleans up its scratch file.
234 home_fail="$case_root/fail-home"
235 tmp_fail="$case_root/tmp-fail"
236 mkdir -p "$home_fail" "$tmp_fail"
237 cat >"$home_fail/.zshrc" <<'EOF'
238 # precious user config
239
240 # Composio CLI
241 export PATH="$HOME/.local/bin:$PATH"
242 EOF
243 cp "$home_fail/.zshrc" "$case_root/fail-before.zshrc"
244
245 run_snippet "$home_fail" PATH="$fail_bin:$PATH" TMPDIR="$tmp_fail"
246
247 cmp -s "$home_fail/.zshrc" "$case_root/fail-before.zshrc" ||
248 fail "$interpreter_name modified the startup file although the filter failed"
249 assert_dir_empty "$tmp_fail" "$interpreter_name failing-filter case"
250 assert_no_predictable_tmp "$home_fail" "$interpreter_name failing-filter case"
251
252 # --- An installer-created ~/.bash_profile that holds only the managed block
253 # --- is deleted, restoring bash's default startup-file selection.
254 home_bp_created="$case_root/bash-profile-created-home"
255 mkdir -p "$home_bp_created"
256 cat >"$home_bp_created/.bash_profile" <<'EOF'
257
258 # Composio CLI
259 export PATH="$HOME/.local/bin:$PATH"
260 EOF
261
262 run_snippet "$home_bp_created" -u TMPDIR
263
264 [[ ! -e "$home_bp_created/.bash_profile" ]] ||
265 fail "$interpreter_name kept an empty leftover .bash_profile"
266
267 # --- Documented edge: a pre-existing, user-owned empty ~/.bash_profile is
268 # --- also removed.
269 home_bp_blank="$case_root/bash-profile-blank-home"
270 mkdir -p "$home_bp_blank"
271 : >"$home_bp_blank/.bash_profile"
272
273 run_snippet "$home_bp_blank" -u TMPDIR
274
275 [[ ! -e "$home_bp_blank/.bash_profile" ]] ||
276 fail "$interpreter_name kept a pre-existing empty .bash_profile"
277
278 # --- A ~/.bash_profile with remaining content (the installer's ~/.profile
279 # --- seed, or any user content) survives with only the block removed.
280 home_bp_keep="$case_root/bash-profile-keep-home"
281 mkdir -p "$home_bp_keep"
282 cat >"$home_bp_keep/.bash_profile" <<'EOF'
283 # Created by the Composio CLI installer.
284 # Bash reads this file instead of ~/.profile in login shells.
285 if [ -f "$HOME/.profile" ]; then
286 . "$HOME/.profile"
287 fi
288
289 # Composio CLI
290 export PATH="$HOME/.local/bin:$PATH"
291 EOF
292
293 run_snippet "$home_bp_keep" -u TMPDIR
294
295 [[ -f "$home_bp_keep/.bash_profile" ]] || fail "$interpreter_name deleted a non-empty .bash_profile"
296 grep -Fq '. "$HOME/.profile"' "$home_bp_keep/.bash_profile" ||
297 fail "$interpreter_name lost the ~/.profile seed content"
298 ! grep -Fxq '# Composio CLI' "$home_bp_keep/.bash_profile" ||
299 fail "$interpreter_name kept the marker in a seeded .bash_profile"
300 ! grep -Fq 'export PATH=' "$home_bp_keep/.bash_profile" ||
301 fail "$interpreter_name kept the managed PATH line in a seeded .bash_profile"
302
303 printf 'docs uninstall snippet passed under %s\n' "$interpreter_name"
304 done
305
306 printf 'docs uninstall snippet tests passed\n'