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): cover upgrading a running binary
jkomyno committed
Aug 1, 2026 at 19:17 UTC
cf9223879e7e582ba02d986eb819464e790fa66a
5 files changed
+156
-4
pnpm-lock.yaml
+6
@@ -244,6 +244,12 @@ importers:
244
specifier: workspace:*
245
version: link:../../../_utils
246
247
+ ts/e2e-tests/cli/upgrade:
248
+ devDependencies:
249
+ '@e2e-tests/utils':
250
+ specifier: workspace:*
251
+ version: link:../../_utils
252
+
253
ts/e2e-tests/cli/version:
254
devDependencies:
255
'@e2e-tests/utils':
ts/e2e-tests/cli/README.md
+6
-4
@@ -10,10 +10,11 @@ Tests use `runCmd` to execute shell commands in the container and assert on exit
10
11
## Test Suites
12
13
-| Suite | Description | Env Vars |
14
-| --- | --- | --- |
15
-| [version](./version/) | `composio version` output and exit code | None |
16
-| [whoami](./whoami/) | `composio whoami` prints the API key | `COMPOSIO_USER_API_KEY` |
13
+| Suite | Description | Env Vars |
14
+| --------------------- | ------------------------------------------------------ | ----------------------- |
15
+| [upgrade](./upgrade/) | `composio upgrade` replaces a running Linux executable | None |
16
+| [version](./version/) | `composio version` output and exit code | None |
17
+| [whoami](./whoami/) | `composio whoami` prints the API key | `COMPOSIO_USER_API_KEY` |
18
19
## Isolation Tool
20
@@ -28,4 +29,5 @@ pnpm test:e2e:cli
29
# A specific suite
30
cd ts/e2e-tests/cli/version && pnpm test:e2e:cli
31
cd ts/e2e-tests/cli/whoami && pnpm test:e2e:cli
32
+cd ts/e2e-tests/cli/upgrade && pnpm test:e2e:cli
33
```
ts/e2e-tests/cli/upgrade/README.md
new
+11
@@ -0,0 +1,11 @@
1
+# CLI `composio upgrade` Test
2
+
3
+Verifies that the compiled Linux CLI atomically replaces its running executable.
4
+
5
+The suite covers both the installed `/usr/local/bin/composio` path and a copied executable. Each case checks the inode replacement, executable bit, upgrade result, absence of Linux busy-file errors, and a subsequent `composio version` invocation.
6
+
7
+## Running
8
+
9
+```bash
10
+pnpm test:e2e:cli
11
+```
ts/e2e-tests/cli/upgrade/e2e.test.ts
new
+119
@@ -0,0 +1,119 @@
1
+/**
2
+ * CLI upgrade command e2e test
3
+ *
4
+ * Verifies that the compiled Linux binary can replace its running executable.
5
+ */
6
+
7
+import { e2e, type E2ETestResult } from '@e2e-tests/utils';
8
+import { TIMEOUTS } from '@e2e-tests/utils/const';
9
+import { beforeAll, describe, expect, it } from 'bun:test';
10
+
11
+const companionRelativePaths = [
12
+ // RUN_COMPANION_MODULE_FILENAMES
13
+ 'run-helpers-runtime.mjs',
14
+ 'run-subagent-shared.mjs',
15
+ 'run-subagent-acp.mjs',
16
+ 'run-subagent-legacy.mjs',
17
+ 'run-subagent-output-mcp.mjs',
18
+ // RUN_COMPANION_STATIC_ASSET_RELATIVE_PATHS
19
+ 'acp-adapters/claude-code-acp.mjs',
20
+ 'acp-adapters/cli.js',
21
+ 'acp-adapters/codex/darwin-arm64/codex-acp',
22
+ 'acp-adapters/codex/darwin-x64/codex-acp',
23
+ 'acp-adapters/codex/linux-arm64/codex-acp',
24
+ 'acp-adapters/codex/linux-x64/codex-acp',
25
+] as const;
26
+
27
+const sourceBundleSetup = companionRelativePaths
28
+ .map(
29
+ relativePath =>
30
+ `mkdir -p "$(dirname "$source_dir/${relativePath}")"\n: > "$source_dir/${relativePath}"`
31
+ )
32
+ .join('\n');
33
+
34
+const upgradeCommand = ({
35
+ executablePath,
36
+ copyExecutable,
37
+}: {
38
+ executablePath: string;
39
+ copyExecutable: boolean;
40
+}) => `
41
+set -u
42
+executable_path=${executablePath}
43
+source_dir=/tmp/composio-upgrade-source
44
+mkdir -p "$source_dir"
45
+${copyExecutable ? 'mkdir -p "$(dirname "$executable_path")"\ncp /usr/local/bin/composio "$executable_path"' : ''}
46
+cp /usr/local/bin/composio "$source_dir/composio"
47
+${sourceBundleSetup}
48
+
49
+before_inode=$(stat -c '%i' "$executable_path")
50
+upgrade_status=0
51
+DEBUG_OVERRIDE_UPGRADE_TARGET="$source_dir/composio" "$executable_path" upgrade || upgrade_status=$?
52
+after_inode=$(stat -c '%i' "$executable_path" 2>/dev/null)
53
+
54
+if [ -x "$executable_path" ]; then
55
+ executable_status=0
56
+else
57
+ executable_status=1
58
+fi
59
+
60
+version_output=$("$executable_path" version)
61
+version_status=$?
62
+printf 'before_inode=%s\nafter_inode=%s\nupgrade_status=%s\nexecutable_status=%s\nversion_status=%s\nversion=%s\n' \
63
+ "$before_inode" "$after_inode" "$upgrade_status" "$executable_status" "$version_status" "$version_output"
64
+
65
+if [ "$upgrade_status" -eq 0 ] &&
66
+ [ "$executable_status" -eq 0 ] &&
67
+ [ "$version_status" -eq 0 ] &&
68
+ [ -n "$before_inode" ] &&
69
+ [ -n "$after_inode" ] &&
70
+ [ "$before_inode" != "$after_inode" ]; then
71
+ exit 0
72
+fi
73
+exit 1
74
+`;
75
+
76
+const outputField = (result: E2ETestResult, name: string): string => {
77
+ const match = result.stdout.match(new RegExp(`^${name}=(.*)$`, 'm'));
78
+ expect(match).not.toBeNull();
79
+ return match?.[1] ?? '';
80
+};
81
+
82
+const expectAtomicUpgrade = (result: E2ETestResult) => {
83
+ expect(result.exitCode).toBe(0);
84
+ expect(result.stderr).not.toMatch(/ETXTBSY|text[ -]file(?: is)?[ -]busy/i);
85
+ expect(outputField(result, 'upgrade_status')).toBe('0');
86
+ expect(outputField(result, 'executable_status')).toBe('0');
87
+ expect(outputField(result, 'version_status')).toBe('0');
88
+ expect(outputField(result, 'version')).toMatch(/\d+\.\d+\.\d+/);
89
+ expect(outputField(result, 'after_inode')).not.toBe(outputField(result, 'before_inode'));
90
+};
91
+
92
+e2e(import.meta.url, {
93
+ versions: {
94
+ cli: ['current'],
95
+ },
96
+ defineTests: ({ runCmd }) => {
97
+ let installedResult: E2ETestResult;
98
+ let copiedResult: E2ETestResult;
99
+
100
+ beforeAll(async () => {
101
+ installedResult = await runCmd(
102
+ upgradeCommand({ executablePath: '/usr/local/bin/composio', copyExecutable: false })
103
+ );
104
+ copiedResult = await runCmd(
105
+ upgradeCommand({ executablePath: '/tmp/composio-copy/composio', copyExecutable: true })
106
+ );
107
+ }, TIMEOUTS.FIXTURE);
108
+
109
+ describe('composio upgrade', () => {
110
+ it('replaces the running installed executable', () => {
111
+ expectAtomicUpgrade(installedResult);
112
+ });
113
+
114
+ it('replaces an executable running from a copied path', () => {
115
+ expectAtomicUpgrade(copiedResult);
116
+ });
117
+ });
118
+ },
119
+});
ts/e2e-tests/cli/upgrade/package.json
new
+14
@@ -0,0 +1,14 @@
1
+{
2
+ "name": "@e2e-tests/cli-upgrade",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "typecheck": "tsc --noEmit",
8
+ "test:e2e": "bun test e2e.test.ts",
9
+ "test:e2e:cli": "bun test e2e.test.ts"
10
+ },
11
+ "devDependencies": {
12
+ "@e2e-tests/utils": "workspace:*"
13
+ }
14
+}