@devries-cameron20 / composio Mirror · read-only / commits / e75d145f8
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, 04:45 UTC

test(ts/e2e): add install and upgrade fault rows (#5350)

This PR: - part of [PRDE-2212](https://linear.app/composio/issue/PRDE-2212/cli-e2e-tests-fake-backend-operation-suites-and-agent-journeys-with) - builds on top of https://github.com/ComposioHQ/composio/pull/5349; split from https://github.com/ComposioHQ/composio/pull/5312 - serves missing platform archives and truncated downloads from the local install release server - checks that both download faults fail before creating a CLI entry point - runs upgrade as an ordinary user against a read-only install directory and checks the original binary survives without temporary files ## Context Frozen install, CLI dependency builds, install typecheck, Prettier, and the keyless upgrade suite passed (five tests). The install suite needs packaged Linux release assets and was not run locally. Complete CLI workflow validation after the base merges and this PR is retargeted to `next`.

Alberto Schiabel committed Nov 16, 2026 at 12:27 UTC e75d145f8d4612b8045761914f6d776f3177da6f
4 files changed +118
ts/e2e-tests/cli/install/README.md
+2
@@ -13,6 +13,8 @@ COMPOSIO_INSTALL_E2E_RELEASE_DIR="$PWD/fixture" \
13 pnpm test:e2e:install
14 ```
15
16 +The local server also serves the failure cases under path prefixes: an archive that fails its checksum, a corrupt archive, a release with no archive for the platform (`/missing-asset`), and a download dropped partway (`/truncated`).
17 +
18 Run the same command with `COMPOSIO_INSTALL_E2E_SHELL=zsh` for the shell-variant and bundle-layout assertions. The host server serves the checked-out installer scripts and the local release fixture without publishing it.
19
20 ## Production mode
ts/e2e-tests/cli/install/e2e.test.ts
+41
@@ -326,6 +326,47 @@ test ! -e "$HOME/.local/bin/composio"
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 () => {
ts/e2e-tests/cli/install/release-server.ts
+28
@@ -14,9 +14,31 @@ const ARCHIVE_BY_ARCH = {
14 * installer passes checksum verification and fails at extraction.
15 * - `/checksum-mismatch/...` keeps the genuine checksums.txt, so the installer
16 * fails at checksum verification before extraction.
17 + * - `/missing-asset/...` answers 404 for the archive, as GitHub does for a
18 + * release that has no build for the platform.
19 + * - `/truncated/...` starts sending the genuine archive and drops the
20 + * connection partway, as an interrupted download does.
21 */
22 const CORRUPT_ARCHIVE_BODY = 'not a zip archive\n';
23
24 +/** The first bytes of the archive at `path`, then a dropped connection. */
25 +const truncatedResponse = (path: string): Response => {
26 + const head = readFileSync(path).subarray(0, 64 * 1024);
27 + return new Response(
28 + new ReadableStream<Uint8Array>({
29 + async pull(controller) {
30 + controller.enqueue(head);
31 + // Let the chunk reach curl before the stream fails.
32 + await Bun.sleep(100);
33 + // Failing the stream is how Bun.serve drops a connection mid-body. Closing
34 + // it early instead ends the response cleanly and curl accepts the short file.
35 + controller.error('install e2e: download dropped on purpose');
36 + },
37 + }),
38 + { headers: { 'content-type': 'application/zip' } }
39 + );
40 +};
41 +
42 export interface InstallReleaseServer {
43 baseUrl: string;
44 platform: 'linux/amd64' | 'linux/arm64';
@@ -74,6 +96,12 @@ export function startInstallReleaseServer(options: {
96 }
97
98 if (url.pathname.includes('/releases/download/') && url.pathname.endsWith(archiveName)) {
99 + if (url.pathname.startsWith('/missing-asset/')) {
100 + return new Response('Not Found\n', { status: 404 });
101 + }
102 + if (url.pathname.startsWith('/truncated/')) {
103 + return truncatedResponse(archivePath);
104 + }
105 if (
106 url.pathname.startsWith('/corrupt/') ||
107 url.pathname.startsWith('/checksum-mismatch/')
ts/e2e-tests/cli/upgrade/e2e.test.ts
+47
@@ -88,6 +88,33 @@ fi
88 exit 1
89 `;
90
91 +/**
92 + * An upgrade the process is not allowed to perform: the install directory is
93 + * read-only and the CLI runs as an ordinary user (root would ignore the mode).
94 + */
95 +const readOnlyInstallCommand = `
96 +set -u
97 +install_dir=/opt/composio-readonly
98 +source_dir=/tmp/composio-upgrade-source
99 +mkdir -p "$install_dir" "$source_dir"
100 +cp -r /usr/local/bin/. "$install_dir/"
101 +cp /usr/local/bin/composio "$source_dir/composio"
102 +${sourceBundleSetup}
103 +chmod -R a+rX "$source_dir"
104 +chmod -R a-w "$install_dir"
105 +
106 +before=$(stat -c '%i %s' "$install_dir/composio")
107 +upgrade_status=0
108 +HOME=/tmp/unprivileged-home DEBUG_OVERRIDE_UPGRADE_TARGET="$source_dir/composio" \
109 + setpriv --reuid=1000 --regid=1000 --clear-groups "$install_dir/composio" upgrade || upgrade_status=$?
110 +after=$(stat -c '%i %s' "$install_dir/composio")
111 +version_output=$("$install_dir/composio" version)
112 +version_status=$?
113 +leftovers=$(find "$install_dir" -name '.composio-atomic-replace-*' | wc -l)
114 +printf 'upgrade_status=%s\nbefore=%s\nafter=%s\nversion_status=%s\nversion=%s\nleftovers=%s\n' \
115 + "$upgrade_status" "$before" "$after" "$version_status" "$version_output" "$leftovers"
116 +`;
117 +
118 const outputField = (result: E2ETestResult, name: string): string => {
119 const match = result.stdout.match(new RegExp(`^${name}=(.*)$`, 'm'));
120 expect(match).not.toBeNull();
@@ -113,6 +140,7 @@ e2e(import.meta.url, {
140 defineTests: ({ runCmd }) => {
141 let installedResult: E2ETestResult;
142 let copiedResult: E2ETestResult;
143 + let readOnlyResult: E2ETestResult;
144
145 beforeAll(async () => {
146 installedResult = await runCmd(
@@ -121,6 +149,7 @@ e2e(import.meta.url, {
149 copiedResult = await runCmd(
150 upgradeCommand({ executablePath: '/tmp/composio-copy/composio', copyExecutable: true })
151 );
152 + readOnlyResult = await runCmd(readOnlyInstallCommand);
153 }, TIMEOUTS.FIXTURE);
154
155 describe('composio upgrade', () => {
@@ -132,5 +161,23 @@ e2e(import.meta.url, {
161 expectAtomicUpgrade(copiedResult);
162 });
163 });
164 +
165 + describe('composio upgrade without write permission on the install directory', () => {
166 + it('fails and says which file it could not replace', () => {
167 + expect(outputField(readOnlyResult, 'upgrade_status')).toBe('1');
168 + expect(readOnlyResult.stderr).toContain('permission denied');
169 + expect(readOnlyResult.stderr).toContain('/opt/composio-readonly/');
170 + });
171 +
172 + it('leaves the installed executable untouched and runnable', () => {
173 + expect(outputField(readOnlyResult, 'after')).toBe(outputField(readOnlyResult, 'before'));
174 + expect(outputField(readOnlyResult, 'version_status')).toBe('0');
175 + expect(outputField(readOnlyResult, 'version')).toMatch(/\d+\.\d+\.\d+/);
176 + });
177 +
178 + it('leaves no temporary files behind', () => {
179 + expect(outputField(readOnlyResult, 'leftovers')).toBe('0');
180 + });
181 + });
182 },
183 });