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
ts 477 lines 16 KB
Raw
1 import { resolve } from 'node:path';
2 import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
3 import {
4 checkDocker,
5 ensureInstallImage,
6 resolveInstallE2EConfig,
7 runInstallContainer,
8 type ExecResult,
9 type InstallImage,
10 } from '@e2e-tests/utils';
11 import { INSTALL_E2E_LOCAL_RELEASE_TAG } from '@e2e-tests/utils/const';
12 import { startInstallReleaseServer, type InstallReleaseServer } from './release-server';
13
14 const config = resolveInstallE2EConfig();
15 const repoRoot = resolve(import.meta.dir, '../../../..');
16 const timeout = 600_000;
17
18 let image: InstallImage | undefined;
19 let releaseServer: InstallReleaseServer | undefined;
20
21 /**
22 * POSIX helper injected into container scripts. `! grep` would not trip
23 * `set -e`, so missing-marker assertions go through an explicit branch.
24 */
25 const shellHelpers = `
26 assert_no_marker_block() {
27 if grep -Fq '# Composio CLI' "$1" 2>/dev/null; then
28 echo "unexpected Composio marker block in $1" >&2
29 exit 1
30 fi
31 }
32 `;
33
34 function assertSuccess(result: ExecResult): void {
35 if (result.exitCode !== 0) {
36 throw new Error(
37 `Install container exited ${result.exitCode}\n\nstdout:\n${result.stdout}\n\nstderr:\n${result.stderr}`
38 );
39 }
40 expect(result.exitCode).toBe(0);
41 }
42
43 function installerEnvironment(): Record<string, string> {
44 if (config.mode === 'prod') {
45 return {
46 INSTALL_BASE_URL: 'https://composio.dev',
47 E2E_VERSION: config.version,
48 };
49 }
50
51 if (!releaseServer) {
52 throw new Error('Local release server is not running');
53 }
54
55 return {
56 INSTALL_BASE_URL: releaseServer.baseUrl,
57 E2E_RELEASE_TAG: INSTALL_E2E_LOCAL_RELEASE_TAG,
58 COMPOSIO_GITHUB_URL: releaseServer.baseUrl,
59 COMPOSIO_GITHUB_API_BASE_URL: releaseServer.baseUrl,
60 COMPOSIO_INSTALL_SCRIPT_URL: `${releaseServer.baseUrl}/install`,
61 COMPOSIO_INSTALL_ALLOW_HTTP_HOST: 'host.docker.internal',
62 };
63 }
64
65 async function run(script: string): Promise<ExecResult> {
66 if (!image) {
67 throw new Error('Install image is not ready');
68 }
69 // The test scripts are POSIX sh, which fish cannot interpret: drive fish legs
70 // from bash and let the assertions invoke fish login shells explicitly.
71 const scriptShell = config.shell === 'fish' ? 'bash' : config.shell;
72 return runInstallContainer({
73 ...image,
74 shell: config.shell,
75 cmd: [scriptShell, '-lc', script],
76 env: installerEnvironment(),
77 });
78 }
79
80 beforeAll(async () => {
81 const docker = await checkDocker({ repoRoot });
82 if (docker.exitCode !== 0) {
83 throw new Error(`Docker is required for install e2e tests: ${docker.stderr || docker.stdout}`);
84 }
85
86 if (config.mode === 'local') {
87 releaseServer = startInstallReleaseServer({
88 repoRoot,
89 releaseDir: config.releaseDir!,
90 });
91 }
92 image = await ensureInstallImage(config.shell, {
93 repoRoot,
94 platform: releaseServer?.platform,
95 });
96 }, timeout);
97
98 afterAll(() => {
99 releaseServer?.stop();
100 });
101
102 if (config.mode === 'local' && config.shell === 'bash') {
103 describe('local bash installation', () => {
104 it(
105 'installs into a virgin home and is available in a fresh login shell',
106 async () => {
107 // Docker execs typically leave $SHELL unset, so every default-flow
108 // invocation exports it explicitly for the auto-detection contract.
109 // A login bash never reads ~/.bashrc, so a virgin home must also come
110 // out with a login-mode startup file; `bash -lc` (no -i) proves it.
111 const result = await run(`
112 set -eu
113 ${shellHelpers}
114 test ! -d "$HOME/.local/bin"
115 test ! -e "$HOME/.bash_profile"
116 curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/bash sh
117 test -x "$HOME/.composio/composio"
118 test -L "$HOME/.local/bin/composio"
119 test "$(readlink -f "$HOME/.local/bin/composio")" = "$HOME/.composio/composio"
120 test "$(grep -Fc '# Composio CLI' "$HOME/.bashrc")" = 1
121 test "$(grep -Fc '# Composio CLI' "$HOME/.bash_profile")" = 1
122 grep -Fq '. "$HOME/.profile"' "$HOME/.bash_profile"
123 assert_no_marker_block "$HOME/.profile"
124 test "$(bash -lc 'command -v composio')" = "$HOME/.local/bin/composio"
125 test "$(bash -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
126 test "$(bash -ilc 'composio --version')" = 98.0.0
127 `);
128 assertSuccess(result);
129 },
130 timeout
131 );
132
133 it(
134 'configures an existing bash login profile through the plain default install',
135 async () => {
136 // An existing ~/.bash_profile shadows Debian's ~/.profile, so a fresh
137 // login shell resolves composio only if the installer configured it.
138 const result = await run(`
139 set -eu
140 printf '%s\n' 'export PROFILE_TRAP=1' > "$HOME/.bash_profile"
141 output=$(curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/bash sh)
142 ending=$(printf '%s\n' "$output" | tail -n 3)
143 case_b=$(printf 'Open a new terminal, then run:\n\n composio login')
144 test "$ending" = "$case_b"
145 curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/bash sh
146 test "$(bash -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
147 test "$(bash -ilc 'composio --version')" = 98.0.0
148 test "$(grep -Fc '# Composio CLI' "$HOME/.bash_profile")" = 1
149 test "$(grep -Fc '# Composio CLI' "$HOME/.bashrc")" = 1
150 grep -Fx 'export PROFILE_TRAP=1' "$HOME/.bash_profile"
151 `);
152 assertSuccess(result);
153 },
154 timeout
155 );
156
157 it(
158 'configures bash through COMPOSIO_INSTALL_SHELL idempotently',
159 async () => {
160 const result = await run(`
161 set -eu
162 curl -fsSL "$INSTALL_BASE_URL/install" | COMPOSIO_INSTALL_SHELL=bash sh
163 curl -fsSL "$INSTALL_BASE_URL/install" | COMPOSIO_INSTALL_SHELL=bash sh
164 test "$(bash -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
165 test "$(bash -ilc 'composio --version')" = 98.0.0
166 test "$(grep -Fc '# Composio CLI' "$HOME/.bashrc")" = 1
167 `);
168 assertSuccess(result);
169 },
170 timeout
171 );
172
173 it(
174 'falls back to install-only when $SHELL is unset',
175 async () => {
176 const result = await run(`
177 set -eu
178 ${shellHelpers}
179 printf '%s\n' 'export PROFILE_TRAP=1' > "$HOME/.bash_profile"
180 output=$(curl -fsSL "$INSTALL_BASE_URL/install" | env -u SHELL sh)
181 test -x "$HOME/.composio/composio"
182 test -L "$HOME/.local/bin/composio"
183 if bash -ilc 'command -v composio' >/dev/null 2>&1; then
184 echo 'install-only fallback unexpectedly configured the login shell' >&2
185 exit 1
186 fi
187 assert_no_marker_block "$HOME/.bash_profile"
188 assert_no_marker_block "$HOME/.bashrc"
189 assert_no_marker_block "$HOME/.profile"
190 printf '%s\n' "$output" | grep -F "$HOME/.composio/composio login"
191 `);
192 assertSuccess(result);
193 },
194 timeout
195 );
196
197 it(
198 'skips shell setup when COMPOSIO_INSTALL_SHELL=none despite a recognized $SHELL',
199 async () => {
200 const result = await run(`
201 set -eu
202 ${shellHelpers}
203 printf '%s\n' 'export PROFILE_TRAP=1' > "$HOME/.bash_profile"
204 output=$(curl -fsSL "$INSTALL_BASE_URL/install" | COMPOSIO_INSTALL_SHELL=none SHELL=/bin/bash sh)
205 test -x "$HOME/.composio/composio"
206 test -L "$HOME/.local/bin/composio"
207 if bash -ilc 'command -v composio' >/dev/null 2>&1; then
208 echo 'COMPOSIO_INSTALL_SHELL=none unexpectedly configured the login shell' >&2
209 exit 1
210 fi
211 assert_no_marker_block "$HOME/.bash_profile"
212 assert_no_marker_block "$HOME/.bashrc"
213 assert_no_marker_block "$HOME/.profile"
214 printf '%s\n' "$output" | grep -F "$HOME/.composio/composio login"
215 `);
216 assertSuccess(result);
217 },
218 timeout
219 );
220 });
221 }
222
223 if (config.mode === 'local' && config.shell === 'zsh') {
224 describe('local zsh installation', () => {
225 it(
226 'keeps the bundle beside its support files and configures zsh idempotently',
227 async () => {
228 const result = await run(`
229 set -eu
230 test ! -d "$HOME/.local/bin"
231 curl -fsSL "$INSTALL_BASE_URL/install/zsh" | sh
232 curl -fsSL "$INSTALL_BASE_URL/install/zsh" | sh
233 test -x "$HOME/.composio/composio"
234 test -L "$HOME/.local/bin/composio"
235 test "$(readlink -f "$HOME/.local/bin/composio")" = "$HOME/.composio/composio"
236 test "$(cat "$HOME/.composio/release-tag.txt")" = "$E2E_RELEASE_TAG"
237 test -f "$HOME/.composio/run-helpers-runtime.mjs"
238 test "$(grep -Fc '# Composio CLI' "$HOME/.zshrc")" = 1
239 test "$(zsh -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
240 test "$(zsh -ilc 'composio --version')" = 98.0.0
241 `);
242 assertSuccess(result);
243 },
244 timeout
245 );
246
247 it(
248 'configures zsh idempotently through the plain default install when $SHELL is zsh',
249 async () => {
250 const result = await run(`
251 set -eu
252 test ! -d "$HOME/.local/bin"
253 curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/zsh sh
254 curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/zsh sh
255 test "$(grep -Fc '# Composio CLI' "$HOME/.zshrc")" = 1
256 test "$(zsh -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
257 test "$(zsh -ilc 'composio --version')" = 98.0.0
258 `);
259 assertSuccess(result);
260 },
261 timeout
262 );
263
264 it(
265 'keeps the install successful when shell setup cannot write the startup file',
266 async () => {
267 // A directory at ~/.zshrc blocks both delegated and inline setup.
268 // Contract: binary installed, exit 0, warning, trusted absolute
269 // recovery command on the verified installed executable.
270 const result = await run(`
271 set -eu
272 mkdir "$HOME/.zshrc"
273 combined=$(curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/zsh sh 2>&1)
274 test -x "$HOME/.composio/composio"
275 test -L "$HOME/.local/bin/composio"
276 printf '%s\n' "$combined" | grep -i 'warning'
277 printf '%s\n' "$combined" | grep -F "$HOME/.composio/composio login"
278 `);
279 assertSuccess(result);
280 },
281 timeout
282 );
283 });
284 }
285
286 if (config.mode === 'local' && config.shell === 'fish') {
287 describe('local fish installation', () => {
288 it(
289 'configures fish idempotently and exposes composio in a fresh fish login shell',
290 async () => {
291 const result = await run(`
292 set -eu
293 test ! -d "$HOME/.local/bin"
294 curl -fsSL "$INSTALL_BASE_URL/install/fish" | sh
295 curl -fsSL "$INSTALL_BASE_URL/install/fish" | sh
296 test -x "$HOME/.composio/composio"
297 test -L "$HOME/.local/bin/composio"
298 test "$(readlink -f "$HOME/.local/bin/composio")" = "$HOME/.composio/composio"
299 test "$(grep -Fc '# Composio CLI' "$HOME/.config/fish/config.fish")" = 1
300 test "$(fish -l -c 'command -v composio')" = "$HOME/.local/bin/composio"
301 test "$(fish -l -c 'composio --version')" = 98.0.0
302 `);
303 assertSuccess(result);
304 },
305 timeout
306 );
307 });
308 }
309
310 if (config.mode === 'local') {
311 describe('local failure handling', () => {
312 it(
313 'rejects an archive that fails checksum verification before extraction',
314 async () => {
315 const result = await run(`
316 set -eu
317 if output=$(curl -fsSL "$INSTALL_BASE_URL/install" | COMPOSIO_GITHUB_URL="$INSTALL_BASE_URL/checksum-mismatch" sh -s -- "$E2E_RELEASE_TAG" 2>&1); then
318 echo 'mismatched archive unexpectedly installed' >&2
319 exit 1
320 fi
321 printf '%s\n' "$output" | grep -F 'Checksum mismatch'
322 test ! -e "$HOME/.local/bin/composio"
323 `);
324 assertSuccess(result);
325 },
326 timeout
327 );
328
329 it(
330 'fails when the release has no archive for this platform, before creating the entry point',
331 async () => {
332 const result = await run(`
333 set -eu
334 if output=$(curl -fsSL "$INSTALL_BASE_URL/install" | COMPOSIO_GITHUB_URL="$INSTALL_BASE_URL/missing-asset" sh -s -- "$E2E_RELEASE_TAG" 2>&1); then
335 echo 'install unexpectedly succeeded without an archive' >&2
336 exit 1
337 fi
338 printf '%s\n' "$output" | grep -Fi 'download'
339 test ! -e "$HOME/.local/bin/composio"
340 test ! -e "$HOME/.composio/composio"
341 `);
342 assertSuccess(result);
343 },
344 timeout
345 );
346
347 it(
348 'fails on a download cut off partway, before creating the entry point',
349 async () => {
350 const result = await run(`
351 set -eu
352 if output=$(curl -fsSL "$INSTALL_BASE_URL/install" | COMPOSIO_GITHUB_URL="$INSTALL_BASE_URL/truncated" sh -s -- "$E2E_RELEASE_TAG" 2>&1); then
353 echo 'install unexpectedly succeeded from a truncated archive' >&2
354 exit 1
355 fi
356 # The download itself must fail; reaching checksum verification would mean the partial file was accepted as complete.
357 if printf '%s\n' "$output" | grep -Fq 'Checksum'; then
358 printf '%s\n' "$output" >&2
359 exit 1
360 fi
361 printf '%s\n' "$output" | grep -Fi 'download'
362 test ! -e "$HOME/.local/bin/composio"
363 test ! -e "$HOME/.composio/composio"
364 `);
365 assertSuccess(result);
366 },
367 timeout
368 );
369
370 it(
371 'rejects a corrupted archive at extraction before creating the entry point',
372 async () => {
373 const result = await run(`
374 set -eu
375 if output=$(curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/${config.shell} COMPOSIO_GITHUB_URL="$INSTALL_BASE_URL/corrupt" sh -s -- "$E2E_RELEASE_TAG" 2>&1); then
376 echo 'corrupted archive unexpectedly installed' >&2
377 exit 1
378 fi
379 printf '%s\n' "$output" | grep -F 'Checksum verified'
380 printf '%s\n' "$output" | grep -F 'Failed to extract archive'
381 test ! -e "$HOME/.local/bin/composio"
382 `);
383 assertSuccess(result);
384 },
385 timeout
386 );
387 });
388 }
389
390 if (config.mode === 'prod' && config.version === 'latest') {
391 describe(`production latest installation on ${config.shell}`, () => {
392 it(
393 'makes composio available in a fresh login shell',
394 async () => {
395 // The /install/<shell> variant routes are not provisioned in production
396 // yet (404); select the shell through COMPOSIO_INSTALL_SHELL on the base
397 // route until they ship.
398 const loginShell = (script: string) =>
399 config.shell === 'fish' ? `fish -l -c '${script}'` : `${config.shell} -ilc '${script}'`;
400 const result = await run(`
401 set -eu
402 test ! -d "$HOME/.local/bin"
403 curl -fsSL "$INSTALL_BASE_URL/install" | COMPOSIO_INSTALL_SHELL=${config.shell} SHELL=/bin/${config.shell} sh
404 test -x "$HOME/.composio/composio"
405 test -L "$HOME/.local/bin/composio"
406 test "$(${loginShell('command -v composio')})" = "$HOME/.local/bin/composio"
407 ${loginShell('composio --version')}
408 `);
409 assertSuccess(result);
410 },
411 timeout
412 );
413 });
414 }
415
416 if (config.mode === 'prod' && config.version !== 'latest') {
417 describe(`production ${config.version} compatibility installation`, () => {
418 it(
419 'configures the login shell inline when the pinned CLI lacks install --shell',
420 async () => {
421 const result = await run(`
422 set -eu
423 curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/${config.shell} sh -s -- "$E2E_VERSION"
424 if "$HOME/.composio/composio" install --help | grep -q -- '--shell'; then
425 echo 'expected the pinned CLI to predate install --shell' >&2
426 exit 1
427 fi
428 test "$(grep -Fc '# Composio CLI' "$HOME/.${config.shell}rc")" = 1
429 curl -fsSL "$INSTALL_BASE_URL/install" | COMPOSIO_INSTALL_SHELL=${config.shell} sh -s -- "$E2E_VERSION"
430 test "$(grep -Fc '# Composio CLI' "$HOME/.${config.shell}rc")" = 1
431 test "$(${config.shell} -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
432 ${config.shell} -ilc 'composio --version'
433 `);
434 assertSuccess(result);
435 },
436 timeout
437 );
438
439 it(
440 'persists the resolved absolute bin directory through inline setup',
441 async () => {
442 // A relative COMPOSIO_BIN_DIR must never be persisted raw: the login
443 // shell check runs from / so only an absolute PATH entry can resolve.
444 const result = await run(`
445 set -eu
446 curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/${config.shell} COMPOSIO_BIN_DIR=.composio-bin sh -s -- "$E2E_VERSION"
447 test -x "$HOME/.composio/composio"
448 test -x "$HOME/.composio-bin/composio"
449 test "$(grep -Fc '# Composio CLI' "$HOME/.${config.shell}rc")" = 1
450 test "$(cd / && ${config.shell} -ilc 'command -v composio')" = "$HOME/.composio-bin/composio"
451 (cd / && ${config.shell} -ilc 'composio --version')
452 `);
453 assertSuccess(result);
454 },
455 timeout
456 );
457
458 it(
459 'keeps the pinned install successful when inline setup cannot write the startup file',
460 async () => {
461 // Contract: binary installed, exit 0, warning, trusted absolute
462 // recovery command on the verified installed executable.
463 const result = await run(`
464 set -eu
465 mkdir "$HOME/.${config.shell}rc"
466 combined=$(curl -fsSL "$INSTALL_BASE_URL/install" | SHELL=/bin/${config.shell} sh -s -- "$E2E_VERSION" 2>&1)
467 test -x "$HOME/.composio/composio"
468 test -L "$HOME/.local/bin/composio"
469 printf '%s\n' "$combined" | grep -i 'warning'
470 printf '%s\n' "$combined" | grep -F "$HOME/.composio/composio login"
471 `);
472 assertSuccess(result);
473 },
474 timeout
475 );
476 });
477 }