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, 17:15 UTC
test(cli): add hermetic installer e2e coverage
jkomyno committed
Aug 1, 2026 at 16:15 UTC
dadd2f4471796cb4e3430d74575c7f27245f2853
14 files changed
+657
-1
package.json
+1
@@ -34,6 +34,7 @@
34
"test:e2e:node": "turbo test:e2e:node --filter='@e2e-tests/node-*'",
35
"test:e2e:deno": "turbo test:e2e:deno --filter='@e2e-tests/deno-*'",
36
"test:e2e:cli": "turbo test:e2e:cli --filter='@e2e-tests/cli-*'",
37
+ "test:e2e:install": "turbo test:e2e:install --filter='@e2e-tests/cli-install'",
38
"test:e2e:cloudflare": "turbo test:e2e:cloudflare --filter='@e2e-tests/cf-*'",
39
"test:ui": "vitest --ui",
40
"typecheck": "turbo typecheck --filter=./ts/packages/**",
pnpm-lock.yaml
+9
@@ -211,6 +211,15 @@ importers:
211
specifier: workspace:*
212
version: link:../../_utils
213
214
+ ts/e2e-tests/cli/install:
215
+ devDependencies:
216
+ '@e2e-tests/utils':
217
+ specifier: workspace:*
218
+ version: link:../../_utils
219
+ '@types/bun':
220
+ specifier: 'catalog:'
221
+ version: 1.3.14
222
+
223
ts/e2e-tests/cli/setup-plugins:
224
devDependencies:
225
'@e2e-tests/utils':
ts/e2e-tests/_utils/Dockerfile.install
new
+18
@@ -0,0 +1,18 @@
1
+FROM debian:bookworm-slim
2
+
3
+ARG INSTALL_SHELL=bash
4
+
5
+RUN case "$INSTALL_SHELL" in bash|zsh) ;; *) exit 2 ;; esac && \
6
+ apt-get update && \
7
+ apt-get install -y --no-install-recommends bash ca-certificates curl passwd unzip $([ "$INSTALL_SHELL" = zsh ] && printf zsh) && \
8
+ rm -rf /var/lib/apt/lists/* && \
9
+ useradd -m -s "/bin/$INSTALL_SHELL" composio
10
+
11
+ENV HOME=/home/composio
12
+ENV SHELL=/bin/$INSTALL_SHELL
13
+ENV PATH=/usr/local/bin:/usr/bin:/bin
14
+
15
+USER composio
16
+WORKDIR /home/composio
17
+
18
+CMD ["/bin/sh"]
ts/e2e-tests/_utils/src/config.ts
+74
-1
@@ -1,4 +1,4 @@
1
-import { dirname, resolve } from 'node:path';
1
+import { dirname, isAbsolute, resolve } from 'node:path';
2
import { fileURLToPath } from 'node:url';
3
import { readFileSync } from 'node:fs';
4
import { execFileSync } from 'node:child_process';
@@ -12,6 +12,17 @@ import type {
12
SkipInCI,
13
NonEmptyArray,
14
} from './types';
15
+import { INSTALL_E2E_MODES, INSTALL_E2E_SHELLS } from './const';
16
+
17
+export type InstallE2EMode = (typeof INSTALL_E2E_MODES)[number];
18
+export type InstallE2EShell = (typeof INSTALL_E2E_SHELLS)[number];
19
+
20
+export interface InstallE2EConfig {
21
+ mode: InstallE2EMode;
22
+ shell: InstallE2EShell;
23
+ version: string;
24
+ releaseDir?: string;
25
+}
26
27
declare module 'bun' {
28
interface Env {
@@ -19,7 +30,69 @@ declare module 'bun' {
30
COMPOSIO_E2E_NODE_VERSION?: string;
31
COMPOSIO_E2E_DENO_VERSION?: string;
32
COMPOSIO_E2E_CLI_VERSION?: string;
33
+ COMPOSIO_INSTALL_E2E_MODE?: string;
34
+ COMPOSIO_INSTALL_E2E_SHELL?: string;
35
+ COMPOSIO_INSTALL_E2E_VERSION?: string;
36
+ COMPOSIO_INSTALL_E2E_RELEASE_DIR?: string;
37
+ }
38
+}
39
+
40
+function resolveEnumValue<T extends string>(
41
+ name: string,
42
+ value: string | undefined,
43
+ allowed: readonly T[],
44
+ fallback: T
45
+): T {
46
+ const resolved = value || fallback;
47
+ if (!allowed.includes(resolved as T)) {
48
+ throw new Error(`${name} must be one of: ${allowed.join(', ')} (got ${resolved})`);
49
+ }
50
+ return resolved as T;
51
+}
52
+
53
+export function resolveInstallE2EConfig(): InstallE2EConfig {
54
+ const mode = resolveEnumValue(
55
+ 'COMPOSIO_INSTALL_E2E_MODE',
56
+ Bun.env.COMPOSIO_INSTALL_E2E_MODE,
57
+ INSTALL_E2E_MODES,
58
+ 'local'
59
+ );
60
+ const shell = resolveEnumValue(
61
+ 'COMPOSIO_INSTALL_E2E_SHELL',
62
+ Bun.env.COMPOSIO_INSTALL_E2E_SHELL,
63
+ INSTALL_E2E_SHELLS,
64
+ 'bash'
65
+ );
66
+ const version = Bun.env.COMPOSIO_INSTALL_E2E_VERSION || 'latest';
67
+ const releaseDir = Bun.env.COMPOSIO_INSTALL_E2E_RELEASE_DIR;
68
+
69
+ if (
70
+ version !== 'latest' &&
71
+ !/^@composio\/cli@[0-9]+\.[0-9]+\.[0-9]+(?:-beta\.[0-9]+)?$/.test(version)
72
+ ) {
73
+ throw new Error(
74
+ 'COMPOSIO_INSTALL_E2E_VERSION must be latest or a full @composio/cli release tag'
75
+ );
76
}
77
+
78
+ if (mode === 'local') {
79
+ if (!releaseDir) {
80
+ throw new Error('COMPOSIO_INSTALL_E2E_RELEASE_DIR is required in local mode');
81
+ }
82
+ if (!isAbsolute(releaseDir)) {
83
+ throw new Error('COMPOSIO_INSTALL_E2E_RELEASE_DIR must be an absolute path');
84
+ }
85
+ if (version !== 'latest') {
86
+ throw new Error('COMPOSIO_INSTALL_E2E_VERSION is only supported in prod mode');
87
+ }
88
+ }
89
+
90
+ return {
91
+ mode,
92
+ shell,
93
+ version,
94
+ releaseDir,
95
+ };
96
}
97
98
/**
ts/e2e-tests/_utils/src/const.ts
+6
@@ -28,6 +28,12 @@ export const WELL_KNOWN_DENO_VERSIONS = [...toolchainVersions.deno, 'current'] a
28
*/
29
export const WELL_KNOWN_CLI_VERSIONS = ['current'] as const;
30
31
+export const INSTALL_E2E_SHELLS = ['bash', 'zsh'] as const;
32
+
33
+export const INSTALL_E2E_MODES = ['local', 'prod'] as const;
34
+
35
+export const INSTALL_E2E_LOCAL_RELEASE_TAG = '@composio/cli@98.0.0';
36
+
37
export const TIMEOUTS = {
38
DEFAULT: 5_000,
39
FIXTURE: 120_000,
ts/e2e-tests/_utils/src/image-lifecycle.ts
+128
@@ -714,3 +714,131 @@ export async function runCliContainer(options: RunCliContainerOptions): Promise<
714
715
return exec('docker', dockerArgs);
716
}
717
+
718
+// ============================================================================
719
+// CLI installer Docker utilities
720
+// ============================================================================
721
+
722
+export type InstallShell = 'bash' | 'zsh';
723
+export type InstallPlatform = 'linux/amd64' | 'linux/arm64';
724
+
725
+export interface EnsureInstallImageOptions {
726
+ repoRoot?: string;
727
+ dockerfilePath?: string;
728
+ platform?: InstallPlatform;
729
+}
730
+
731
+export interface RunInstallContainerOptions {
732
+ imageTag: string;
733
+ cmd: string[];
734
+ env?: Record<string, string | undefined>;
735
+ labels?: Record<string, string>;
736
+}
737
+
738
+function imageTagForInstallShell(shell: InstallShell): string {
739
+ return `composio-e2e-install:${shell}`;
740
+}
741
+
742
+function defaultInstallLabels(shell: InstallShell): Record<string, string> {
743
+ return {
744
+ 'composio.e2e': 'true',
745
+ 'composio.runtime': 'cli-install',
746
+ 'composio.install_shell': shell,
747
+ };
748
+}
749
+
750
+export async function ensureInstallImage(
751
+ shell: InstallShell,
752
+ options: EnsureInstallImageOptions = {}
753
+): Promise<string> {
754
+ if (shell !== 'bash' && shell !== 'zsh') {
755
+ throw new Error(`ensureInstallImage(${shell}): shell must be bash or zsh`);
756
+ }
757
+
758
+ const repoRoot = options.repoRoot ?? getRepoRoot();
759
+ const dockerfilePath =
760
+ options.dockerfilePath ?? resolve(repoRoot, 'ts/e2e-tests/_utils/Dockerfile.install');
761
+ const platform = options.platform ?? (process.arch === 'arm64' ? 'linux/arm64' : 'linux/amd64');
762
+ const architecture = platform === 'linux/arm64' ? 'arm64' : 'amd64';
763
+ const imageTag = imageTagForInstallShell(shell);
764
+ const inspect = await exec(
765
+ 'docker',
766
+ ['image', 'inspect', '--format', '{{.Architecture}}', imageTag],
767
+ { cwd: repoRoot }
768
+ );
769
+ if (inspect.exitCode === 0 && inspect.stdout.trim() === architecture) {
770
+ return imageTag;
771
+ }
772
+
773
+ const built = await exec(
774
+ 'docker',
775
+ [
776
+ 'build',
777
+ '--platform',
778
+ platform,
779
+ '-f',
780
+ dockerfilePath,
781
+ '--build-arg',
782
+ `INSTALL_SHELL=${shell}`,
783
+ ...labelsToArgs(defaultInstallLabels(shell)),
784
+ '-t',
785
+ imageTag,
786
+ repoRoot,
787
+ ],
788
+ { cwd: repoRoot }
789
+ );
790
+ if (built.exitCode !== 0) {
791
+ const err = new Error(`Failed to build Docker image ${imageTag}`);
792
+ (err as Error & { cause: Error }).cause = new Error(built.stderr || built.stdout);
793
+ throw err;
794
+ }
795
+
796
+ return imageTag;
797
+}
798
+
799
+export async function runInstallContainer(
800
+ options: RunInstallContainerOptions
801
+): Promise<ExecResult> {
802
+ const { imageTag, cmd, env, labels } = options;
803
+ const shellMatch = /^composio-e2e-install:(bash|zsh)$/.exec(imageTag);
804
+ if (!shellMatch) {
805
+ throw new Error(
806
+ 'runInstallContainer({ imageTag, ... }): expected composio-e2e-install:<bash|zsh>'
807
+ );
808
+ }
809
+ if (!Array.isArray(cmd) || cmd.length === 0) {
810
+ throw new Error('runInstallContainer({ cmd, ... }): cmd must be a non-empty array');
811
+ }
812
+
813
+ const shell = shellMatch[1] as InstallShell;
814
+ const inspect = await exec('docker', [
815
+ 'image',
816
+ 'inspect',
817
+ '--format',
818
+ '{{.Architecture}}',
819
+ imageTag,
820
+ ]);
821
+ if (inspect.exitCode !== 0) {
822
+ throw new Error(`Failed to inspect Docker image ${imageTag}: ${inspect.stderr}`);
823
+ }
824
+ const platform = inspect.stdout.trim() === 'arm64' ? 'linux/arm64' : 'linux/amd64';
825
+ const dockerArgs = [
826
+ 'run',
827
+ '--rm',
828
+ '--platform',
829
+ platform,
830
+ ...labelsToArgs({ ...defaultInstallLabels(shell), ...(labels ?? {}) }),
831
+ '--add-host',
832
+ 'host.docker.internal:host-gateway',
833
+ ];
834
+
835
+ for (const [key, value] of Object.entries(env ?? {})) {
836
+ if (value !== undefined) {
837
+ dockerArgs.push('-e', `${key}=${value}`);
838
+ }
839
+ }
840
+
841
+ // Installer tests intentionally do not mount the host's ~/.composio directory.
842
+ dockerArgs.push(imageTag, ...cmd.map(String));
843
+ return exec('docker', dockerArgs);
844
+}
ts/e2e-tests/_utils/src/index.ts
+7
@@ -14,3 +14,10 @@ export type {
14
} from './types';
15
export { e2e } from './e2e';
16
export { sanitizeOutput, parseJsonStdout } from './sanitize';
17
+export { resolveInstallE2EConfig, type InstallE2EConfig } from './config';
18
+export {
19
+ checkDocker,
20
+ ensureInstallImage,
21
+ runInstallContainer,
22
+ type ExecResult,
23
+} from './image-lifecycle';
ts/e2e-tests/cli/install/README.md
new
+29
@@ -0,0 +1,29 @@
1
+# CLI installer E2E tests
2
+
3
+This suite installs the published-style CLI bundle in a clean Debian container. The image has no preinstalled CLI, no `~/.local/bin`, and no host `~/.composio` mount.
4
+
5
+## Local mode
6
+
7
+Build a `@composio/cli@98.0.0` Linux fixture for the host architecture, then point the suite at the absolute directory containing `composio-linux-x64.zip` or `composio-linux-aarch64.zip` and `checksums.txt`:
8
+
9
+```bash
10
+COMPOSIO_INSTALL_E2E_MODE=local \
11
+COMPOSIO_INSTALL_E2E_SHELL=bash \
12
+COMPOSIO_INSTALL_E2E_RELEASE_DIR="$PWD/fixture" \
13
+pnpm test:e2e:install
14
+```
15
+
16
+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.
17
+
18
+## Production mode
19
+
20
+Run the latest stable installer against the live routes:
21
+
22
+```bash
23
+COMPOSIO_INSTALL_E2E_MODE=prod \
24
+COMPOSIO_INSTALL_E2E_SHELL=zsh \
25
+COMPOSIO_INSTALL_E2E_VERSION=latest \
26
+pnpm test:e2e:install
27
+```
28
+
29
+Set `COMPOSIO_INSTALL_E2E_VERSION=@composio/cli@0.3.1` to cover the shell-configuration fallback for a CLI release that predates `composio install --shell`.
ts/e2e-tests/cli/install/e2e.test.ts
new
+217
@@ -0,0 +1,217 @@
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
+} from '@e2e-tests/utils';
10
+import { INSTALL_E2E_LOCAL_RELEASE_TAG } from '@e2e-tests/utils/const';
11
+import { startInstallReleaseServer, type InstallReleaseServer } from './release-server';
12
+
13
+const config = resolveInstallE2EConfig();
14
+const repoRoot = resolve(import.meta.dir, '../../../..');
15
+const timeout = 600_000;
16
+
17
+let imageTag = '';
18
+let releaseServer: InstallReleaseServer | undefined;
19
+
20
+function assertSuccess(result: ExecResult): void {
21
+ if (result.exitCode !== 0) {
22
+ throw new Error(
23
+ `Install container exited ${result.exitCode}\n\nstdout:\n${result.stdout}\n\nstderr:\n${result.stderr}`
24
+ );
25
+ }
26
+ expect(result.exitCode).toBe(0);
27
+}
28
+
29
+function installerEnvironment(): Record<string, string> {
30
+ if (config.mode === 'prod') {
31
+ return {
32
+ INSTALL_BASE_URL: 'https://composio.dev',
33
+ E2E_VERSION: config.version,
34
+ };
35
+ }
36
+
37
+ if (!releaseServer) {
38
+ throw new Error('Local release server is not running');
39
+ }
40
+
41
+ return {
42
+ INSTALL_BASE_URL: releaseServer.baseUrl,
43
+ E2E_RELEASE_TAG: INSTALL_E2E_LOCAL_RELEASE_TAG,
44
+ COMPOSIO_GITHUB_URL: releaseServer.baseUrl,
45
+ COMPOSIO_GITHUB_API_BASE_URL: releaseServer.baseUrl,
46
+ COMPOSIO_INSTALL_SCRIPT_URL: `${releaseServer.baseUrl}/install`,
47
+ COMPOSIO_INSTALL_ALLOW_HTTP_HOST: 'host.docker.internal',
48
+ };
49
+}
50
+
51
+async function run(script: string): Promise<ExecResult> {
52
+ return runInstallContainer({
53
+ imageTag,
54
+ cmd: [config.shell, '-lc', script],
55
+ env: installerEnvironment(),
56
+ });
57
+}
58
+
59
+beforeAll(async () => {
60
+ const docker = await checkDocker({ repoRoot });
61
+ if (docker.exitCode !== 0) {
62
+ throw new Error(`Docker is required for install e2e tests: ${docker.stderr || docker.stdout}`);
63
+ }
64
+
65
+ if (config.mode === 'local') {
66
+ releaseServer = startInstallReleaseServer({
67
+ repoRoot,
68
+ releaseDir: config.releaseDir!,
69
+ });
70
+ }
71
+ imageTag = await ensureInstallImage(config.shell, {
72
+ repoRoot,
73
+ platform: releaseServer?.platform,
74
+ });
75
+}, timeout);
76
+
77
+afterAll(() => {
78
+ releaseServer?.stop();
79
+});
80
+
81
+if (config.mode === 'local' && config.shell === 'bash') {
82
+ describe('local bash installation', () => {
83
+ it(
84
+ 'installs into a virgin home and is available in a fresh login shell',
85
+ async () => {
86
+ const result = await run(`
87
+set -eu
88
+test ! -d "$HOME/.local/bin"
89
+curl -fsSL "$INSTALL_BASE_URL/install" | sh
90
+test -x "$HOME/.composio/composio"
91
+test -L "$HOME/.local/bin/composio"
92
+test "$(readlink -f "$HOME/.local/bin/composio")" = "$HOME/.composio/composio"
93
+test "$(bash -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
94
+test "$(bash -ilc 'composio --version')" = 98.0.0
95
+`);
96
+ assertSuccess(result);
97
+ },
98
+ timeout
99
+ );
100
+
101
+ it(
102
+ 'configures an existing bash login profile only through the bash variant',
103
+ async () => {
104
+ const result = await run(`
105
+set -eu
106
+printf '%s\n' 'export PROFILE_TRAP=1' > "$HOME/.bash_profile"
107
+output=$(curl -fsSL "$INSTALL_BASE_URL/install" | sh)
108
+printf '%s\n' "$output" | grep -F 'Required next step for bash:'
109
+if bash -ilc 'command -v composio' >/dev/null 2>&1; then
110
+ echo 'default installer unexpectedly configured the login shell' >&2
111
+ exit 1
112
+fi
113
+curl -fsSL "$INSTALL_BASE_URL/install/bash" | sh
114
+test "$(bash -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
115
+test "$(bash -ilc 'composio --version')" = 98.0.0
116
+test "$(grep -Fc '# Composio CLI' "$HOME/.bash_profile")" = 1
117
+test "$(grep -Fc '# Composio CLI' "$HOME/.bashrc")" = 1
118
+`);
119
+ assertSuccess(result);
120
+ },
121
+ timeout
122
+ );
123
+ });
124
+}
125
+
126
+if (config.mode === 'local' && config.shell === 'zsh') {
127
+ describe('local zsh installation', () => {
128
+ it(
129
+ 'keeps the bundle beside its support files and configures zsh idempotently',
130
+ async () => {
131
+ const result = await run(`
132
+set -eu
133
+test ! -d "$HOME/.local/bin"
134
+curl -fsSL "$INSTALL_BASE_URL/install/zsh" | sh
135
+curl -fsSL "$INSTALL_BASE_URL/install/zsh" | sh
136
+test -x "$HOME/.composio/composio"
137
+test -L "$HOME/.local/bin/composio"
138
+test "$(readlink -f "$HOME/.local/bin/composio")" = "$HOME/.composio/composio"
139
+test "$(cat "$HOME/.composio/release-tag.txt")" = "$E2E_RELEASE_TAG"
140
+test -f "$HOME/.composio/run-helpers-runtime.mjs"
141
+test -d "$HOME/.composio/local-tools-binaries"
142
+test "$(grep -Fc '# Composio CLI' "$HOME/.zshrc")" = 1
143
+test "$(zsh -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
144
+test "$(zsh -ilc 'composio --version')" = 98.0.0
145
+`);
146
+ assertSuccess(result);
147
+ },
148
+ timeout
149
+ );
150
+ });
151
+}
152
+
153
+if (config.mode === 'local') {
154
+ describe('local failure handling', () => {
155
+ it(
156
+ 'rejects a corrupted release archive before creating the entry point',
157
+ async () => {
158
+ const result = await run(`
159
+set -eu
160
+if curl -fsSL "$INSTALL_BASE_URL/install" | COMPOSIO_GITHUB_URL="$INSTALL_BASE_URL/corrupt" sh -s -- "$E2E_RELEASE_TAG"; then
161
+ echo 'corrupted archive unexpectedly installed' >&2
162
+ exit 1
163
+fi
164
+test ! -e "$HOME/.local/bin/composio"
165
+`);
166
+ assertSuccess(result);
167
+ },
168
+ timeout
169
+ );
170
+ });
171
+}
172
+
173
+if (config.mode === 'prod' && config.version === 'latest') {
174
+ describe(`production latest installation on ${config.shell}`, () => {
175
+ it(
176
+ 'makes composio available in a fresh login shell',
177
+ async () => {
178
+ const route = config.shell === 'bash' ? 'install' : 'install/zsh';
179
+ const result = await run(`
180
+set -eu
181
+test ! -d "$HOME/.local/bin"
182
+curl -fsSL "$INSTALL_BASE_URL/${route}" | sh
183
+test -x "$HOME/.composio/composio"
184
+test -L "$HOME/.local/bin/composio"
185
+test "$(${config.shell} -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
186
+${config.shell} -ilc 'composio --version'
187
+`);
188
+ assertSuccess(result);
189
+ },
190
+ timeout
191
+ );
192
+ });
193
+}
194
+
195
+if (config.mode === 'prod' && config.version !== 'latest') {
196
+ describe(`production ${config.version} compatibility installation`, () => {
197
+ it(
198
+ 'uses inline shell setup when the pinned CLI lacks install --shell',
199
+ async () => {
200
+ const result = await run(`
201
+set -eu
202
+curl -fsSL "$INSTALL_BASE_URL/install" | sh -s -- "$E2E_VERSION"
203
+if "$HOME/.composio/composio" install --help | grep -q -- '--shell'; then
204
+ echo 'expected the pinned CLI to predate install --shell' >&2
205
+ exit 1
206
+fi
207
+curl -fsSL "$INSTALL_BASE_URL/install/${config.shell}" | sh -s -- "$E2E_VERSION"
208
+test "$(grep -Fc '# Composio CLI' "$HOME/.zshrc")" = 1
209
+test "$(zsh -ilc 'command -v composio')" = "$HOME/.local/bin/composio"
210
+zsh -ilc 'composio --version'
211
+`);
212
+ assertSuccess(result);
213
+ },
214
+ timeout
215
+ );
216
+ });
217
+}
ts/e2e-tests/cli/install/package.json
new
+14
@@ -0,0 +1,14 @@
1
+{
2
+ "name": "@e2e-tests/cli-install",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "typecheck": "tsc --noEmit",
8
+ "test:e2e:install": "bun test e2e.test.ts"
9
+ },
10
+ "devDependencies": {
11
+ "@e2e-tests/utils": "workspace:*",
12
+ "@types/bun": "catalog:"
13
+ }
14
+}
ts/e2e-tests/cli/install/release-server.ts
new
+93
@@ -0,0 +1,93 @@
1
+import { existsSync, readFileSync } from 'node:fs';
2
+import { join } from 'node:path';
3
+import { INSTALL_E2E_LOCAL_RELEASE_TAG } from '@e2e-tests/utils/const';
4
+
5
+const ARCHIVE_BY_ARCH = {
6
+ arm64: 'composio-linux-aarch64.zip',
7
+ x64: 'composio-linux-x64.zip',
8
+} as const;
9
+
10
+export interface InstallReleaseServer {
11
+ baseUrl: string;
12
+ platform: 'linux/amd64' | 'linux/arm64';
13
+ stop: () => void;
14
+}
15
+
16
+export function startInstallReleaseServer(options: {
17
+ repoRoot: string;
18
+ releaseDir: string;
19
+}): InstallReleaseServer {
20
+ const preferredArch = process.arch === 'arm64' ? 'arm64' : 'x64';
21
+ const archiveName = ARCHIVE_BY_ARCH[preferredArch];
22
+ const archivePath = join(options.releaseDir, archiveName);
23
+ const checksumsPath = join(options.releaseDir, 'checksums.txt');
24
+ if (!existsSync(archivePath) || !existsSync(checksumsPath)) {
25
+ throw new Error(
26
+ `Local install fixture must contain ${archiveName} and checksums.txt: ${options.releaseDir}`
27
+ );
28
+ }
29
+
30
+ const scripts = new Map([
31
+ ['/install', join(options.repoRoot, 'install.sh')],
32
+ ['/install/bash', join(options.repoRoot, 'install/bash.sh')],
33
+ ['/install/zsh', join(options.repoRoot, 'install/zsh.sh')],
34
+ ['/install/fish', join(options.repoRoot, 'install/fish.sh')],
35
+ ]);
36
+
37
+ let dockerBaseUrl = '';
38
+ const server = Bun.serve({
39
+ hostname: '0.0.0.0',
40
+ port: 0,
41
+ fetch(request) {
42
+ const url = new URL(request.url);
43
+ const scriptPath = scripts.get(url.pathname);
44
+ if (scriptPath) {
45
+ return new Response(Bun.file(scriptPath), {
46
+ headers: { 'content-type': 'text/x-shellscript; charset=utf-8' },
47
+ });
48
+ }
49
+
50
+ if (/^\/repos\/[^/]+\/[^/]+\/releases$/.test(url.pathname)) {
51
+ return Response.json([
52
+ {
53
+ tag_name: INSTALL_E2E_LOCAL_RELEASE_TAG,
54
+ draft: false,
55
+ prerelease: false,
56
+ assets: [
57
+ {
58
+ name: archiveName,
59
+ browser_download_url: `${dockerBaseUrl}/ComposioHQ/composio/releases/download/${encodeURIComponent(INSTALL_E2E_LOCAL_RELEASE_TAG)}/${archiveName}`,
60
+ },
61
+ ],
62
+ },
63
+ ]);
64
+ }
65
+
66
+ if (url.pathname.includes('/releases/download/') && url.pathname.endsWith(archiveName)) {
67
+ if (url.pathname.startsWith('/corrupt/')) {
68
+ return new Response('not a zip archive\n', {
69
+ headers: { 'content-type': 'application/zip' },
70
+ });
71
+ }
72
+ return new Response(Bun.file(archivePath), {
73
+ headers: { 'content-type': 'application/zip' },
74
+ });
75
+ }
76
+
77
+ if (url.pathname.includes('/releases/download/') && url.pathname.endsWith('checksums.txt')) {
78
+ return new Response(readFileSync(checksumsPath), {
79
+ headers: { 'content-type': 'text/plain; charset=utf-8' },
80
+ });
81
+ }
82
+
83
+ return new Response('not found\n', { status: 404 });
84
+ },
85
+ });
86
+
87
+ dockerBaseUrl = `http://host.docker.internal:${server.port}`;
88
+ return {
89
+ baseUrl: dockerBaseUrl,
90
+ platform: preferredArch === 'arm64' ? 'linux/arm64' : 'linux/amd64',
91
+ stop: () => server.stop(true),
92
+ };
93
+}
ts/e2e-tests/cli/install/tsconfig.json
new
+13
@@ -0,0 +1,13 @@
1
+{
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "target": "es2022",
5
+ "module": "esnext",
6
+ "moduleResolution": "bundler",
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "noEmit": true,
10
+ "types": ["bun"]
11
+ },
12
+ "include": ["*.ts"]
13
+}
ts/packages/cli/test/src/services/upgrade-binary.test.ts
+44
@@ -461,6 +461,50 @@ describe('UpgradeBinary', () => {
461
}).pipe(Effect.provide(TestPlatform), Effect.ensuring(restoreStubsAndMocks));
462
});
463
464
+ it.scoped('replaces the bundle target without replacing its entry-point symlink', () => {
465
+ vi.stubGlobal('Bun', { which: vi.fn(() => null) });
466
+
467
+ return Effect.gen(function* () {
468
+ const fs = yield* FileSystem.FileSystem;
469
+ const path = yield* Path.Path;
470
+ const installDir = yield* fs.makeTempDirectoryScoped({
471
+ prefix: 'composio-symlink-upgrade-target-',
472
+ });
473
+ const binDir = yield* fs.makeTempDirectoryScoped({
474
+ prefix: 'composio-symlink-upgrade-entry-',
475
+ });
476
+ const sourceDir = yield* fs.makeTempDirectoryScoped({
477
+ prefix: 'composio-symlink-upgrade-source-',
478
+ });
479
+ const installedBinaryPath = path.join(installDir, 'composio');
480
+ const entryPointPath = path.join(binDir, 'composio');
481
+ const sourceBinaryPath = path.join(sourceDir, 'composio');
482
+
483
+ yield* fs.writeFileString(installedBinaryPath, 'old-binary');
484
+ yield* fs.writeFileString(sourceBinaryPath, 'new-binary');
485
+ yield* fs.symlink(installedBinaryPath, entryPointPath);
486
+ const originalLinkTarget = yield* fs.readLink(entryPointPath);
487
+ vi.spyOn(process, 'execPath', 'get').mockReturnValue(installedBinaryPath);
488
+
489
+ const companionRelativePaths =
490
+ yield* collectExpectedRunCompanionAssetRelativePaths(sourceDir);
491
+ for (const relativePath of companionRelativePaths) {
492
+ const companionPath = path.join(sourceDir, relativePath);
493
+ yield* fs.makeDirectory(path.dirname(companionPath), { recursive: true });
494
+ yield* fs.writeFileString(companionPath, 'support-file');
495
+ }
496
+
497
+ const result = yield* runUpgradeSuccess([
498
+ ['DEBUG_OVERRIDE_UPGRADE_TARGET', sourceBinaryPath],
499
+ ]);
500
+
501
+ expect(result).toBeUndefined();
502
+ expect(yield* fs.readFileString(installedBinaryPath)).toBe('new-binary');
503
+ expect(yield* fs.readLink(entryPointPath)).toBe(originalLinkTarget);
504
+ expect(yield* fs.exists(entryPointPath)).toBe(true);
505
+ }).pipe(Effect.provide(TestPlatform), Effect.ensuring(restoreStubsAndMocks));
506
+ });
507
+
508
it.scoped('uses the installed beta release tag when comparing beta updates', () => {
509
vi.stubGlobal('Bun', { which: vi.fn(() => null) });
510
turbo.jsonc
+4
@@ -46,6 +46,10 @@
46
"env": ["COMPOSIO_API_KEY", "COMPOSIO_BASE_URL", "COMPOSIO_USER_API_KEY", "COMPOSIO_E2E_CLI_VERSION", "OPENAI_API_KEY"],
47
"cache": false
48
},
49
+ "test:e2e:install": {
50
+ "env": ["COMPOSIO_INSTALL_E2E_MODE", "COMPOSIO_INSTALL_E2E_SHELL", "COMPOSIO_INSTALL_E2E_VERSION", "COMPOSIO_INSTALL_E2E_RELEASE_DIR"],
51
+ "cache": false
52
+ },
53
"test:e2e:cloudflare": {
54
"dependsOn": ["^build"],
55
"env": ["COMPOSIO_API_KEY", "COMPOSIO_BASE_URL", "COMPOSIO_USER_API_KEY", "OPENAI_API_KEY"],