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
| 1 | /** |
| 2 | * CLI plugin setup end-to-end tests. |
| 3 | * |
| 4 | * Runs the compiled standalone binary with HOME=/tmp in fresh Debian |
| 5 | * containers. The host executables implement the native Claude Code and Codex |
| 6 | * JSON contracts while recording every command for exact invocation checks. |
| 7 | */ |
| 8 | |
| 9 | import { e2e, type E2ETestResult, type E2ETestResultWithFiles } from '@e2e-tests/utils'; |
| 10 | import { TIMEOUTS } from '@e2e-tests/utils/const'; |
| 11 | import { beforeAll, describe, expect, it } from 'bun:test'; |
| 12 | |
| 13 | const setupFixture = (host: 'claude' | 'codex') => ` |
| 14 | set -eu |
| 15 | mkdir -p /tmp/bin /tmp/host-state |
| 16 | cp fixtures/fake-agent-host.sh /tmp/bin/${host} |
| 17 | chmod +x /tmp/bin/${host} |
| 18 | ${ |
| 19 | host === 'claude' |
| 20 | ? `# Keep this suite focused on packaged plugin orchestration. The standalone |
| 21 | # skill asset download and extraction path has deterministic HTTP/ZIP coverage. |
| 22 | mkdir -p /tmp/.claude/skills /tmp/.agents/skills/composio-cli |
| 23 | printf '%s\n' '# composio-cli' > /tmp/.agents/skills/composio-cli/SKILL.md |
| 24 | printf '@composio/cli@%s\n' "$(composio version)" > /tmp/.agents/skills/composio-cli/.composio-release-tag |
| 25 | ln -s ../../.agents/skills/composio-cli /tmp/.claude/skills/composio-cli` |
| 26 | : '' |
| 27 | } |
| 28 | export HOST_STATE_DIR=/tmp/host-state |
| 29 | export PATH=/tmp/bin:$PATH |
| 30 | composio setup --target ${host} --yes |
| 31 | cp /tmp/host-state/commands.log first-run.log |
| 32 | : > /tmp/host-state/commands.log |
| 33 | composio setup --target ${host} --yes |
| 34 | composio setup --uninstall --target ${host} --yes |
| 35 | composio setup --uninstall --target ${host} --yes |
| 36 | ${ |
| 37 | host === 'claude' |
| 38 | ? `test ! -L /tmp/.claude/skills/composio-cli |
| 39 | test ! -e /tmp/.agents/skills/composio-cli` |
| 40 | : '' |
| 41 | } |
| 42 | cp /tmp/host-state/commands.log second-run.log |
| 43 | `; |
| 44 | |
| 45 | const legacyCodexFixture = ` |
| 46 | set -eu |
| 47 | mkdir -p /tmp/bin /tmp/host-state |
| 48 | cp fixtures/fake-agent-host.sh /tmp/bin/codex |
| 49 | chmod +x /tmp/bin/codex |
| 50 | touch /tmp/host-state/codex-without-json |
| 51 | export HOST_STATE_DIR=/tmp/host-state |
| 52 | export PATH=/tmp/bin:$PATH |
| 53 | composio setup --target auto --yes |
| 54 | `; |
| 55 | |
| 56 | const legacyCodexIfPresentFixture = legacyCodexFixture.replace( |
| 57 | 'composio setup --target auto --yes', |
| 58 | 'composio setup --target auto --yes --if-present' |
| 59 | ); |
| 60 | |
| 61 | const legacyClaudeFixture = ` |
| 62 | set -eu |
| 63 | mkdir -p /tmp/bin /tmp/host-state |
| 64 | cp fixtures/fake-agent-host.sh /tmp/bin/claude |
| 65 | chmod +x /tmp/bin/claude |
| 66 | touch /tmp/host-state/claude-without-json |
| 67 | export HOST_STATE_DIR=/tmp/host-state |
| 68 | export PATH=/tmp/bin:$PATH |
| 69 | composio setup --target auto --yes |
| 70 | `; |
| 71 | |
| 72 | const claudeWithLegacyCodexFixture = ` |
| 73 | set -eu |
| 74 | mkdir -p /tmp/bin /tmp/host-state |
| 75 | cp fixtures/fake-agent-host.sh /tmp/bin/claude |
| 76 | cp fixtures/fake-agent-host.sh /tmp/bin/codex |
| 77 | chmod +x /tmp/bin/claude /tmp/bin/codex |
| 78 | touch /tmp/host-state/codex-without-json |
| 79 | mkdir -p /tmp/.claude/skills /tmp/.agents/skills/composio-cli |
| 80 | printf '%s\n' '# composio-cli' > /tmp/.agents/skills/composio-cli/SKILL.md |
| 81 | printf '@composio/cli@%s\n' "$(composio version)" > /tmp/.agents/skills/composio-cli/.composio-release-tag |
| 82 | ln -s ../../.agents/skills/composio-cli /tmp/.claude/skills/composio-cli |
| 83 | export HOST_STATE_DIR=/tmp/host-state |
| 84 | export PATH=/tmp/bin:$PATH |
| 85 | composio setup --target auto --yes |
| 86 | test -f /tmp/host-state/claude-plugin |
| 87 | test ! -f /tmp/host-state/codex-plugin |
| 88 | `; |
| 89 | |
| 90 | const codexWithLegacyClaudeFixture = ` |
| 91 | set -eu |
| 92 | mkdir -p /tmp/bin /tmp/host-state |
| 93 | cp fixtures/fake-agent-host.sh /tmp/bin/claude |
| 94 | cp fixtures/fake-agent-host.sh /tmp/bin/codex |
| 95 | chmod +x /tmp/bin/claude /tmp/bin/codex |
| 96 | touch /tmp/host-state/claude-without-json |
| 97 | export HOST_STATE_DIR=/tmp/host-state |
| 98 | export PATH=/tmp/bin:$PATH |
| 99 | composio setup --target auto --yes |
| 100 | test ! -f /tmp/host-state/claude-plugin |
| 101 | test -f /tmp/host-state/codex-plugin |
| 102 | `; |
| 103 | |
| 104 | const failedClaudeInspectionFixture = ` |
| 105 | set -eu |
| 106 | mkdir -p /tmp/bin /tmp/host-state |
| 107 | cp fixtures/fake-agent-host.sh /tmp/bin/claude |
| 108 | chmod +x /tmp/bin/claude |
| 109 | touch /tmp/host-state/claude-inspection-fails |
| 110 | export HOST_STATE_DIR=/tmp/host-state |
| 111 | export PATH=/tmp/bin:$PATH |
| 112 | composio setup --target auto --yes |
| 113 | `; |
| 114 | |
| 115 | e2e(import.meta.url, { |
| 116 | versions: { |
| 117 | cli: ['current'], |
| 118 | }, |
| 119 | defineTests: ({ runCmd }) => { |
| 120 | let claude: E2ETestResultWithFiles<'first-run.log' | 'second-run.log'>; |
| 121 | let codex: E2ETestResultWithFiles<'first-run.log' | 'second-run.log'>; |
| 122 | let unavailable: E2ETestResult; |
| 123 | let skippedUnavailable: E2ETestResult; |
| 124 | let skippedUnavailableUninstall: E2ETestResult; |
| 125 | let legacyClaude: E2ETestResult; |
| 126 | let legacyCodex: E2ETestResult; |
| 127 | let legacyCodexIfPresent: E2ETestResult; |
| 128 | let claudeWithLegacyCodex: E2ETestResult; |
| 129 | let codexWithLegacyClaude: E2ETestResult; |
| 130 | let failedClaudeInspection: E2ETestResult; |
| 131 | |
| 132 | beforeAll(async () => { |
| 133 | // The shared E2E runner derives container names from Date.now(), so keep |
| 134 | // these fresh-container cases sequential to avoid same-millisecond names. |
| 135 | claude = await runCmd({ |
| 136 | command: setupFixture('claude'), |
| 137 | files: ['first-run.log', 'second-run.log'], |
| 138 | }); |
| 139 | codex = await runCmd({ |
| 140 | command: setupFixture('codex'), |
| 141 | files: ['first-run.log', 'second-run.log'], |
| 142 | }); |
| 143 | unavailable = await runCmd('composio setup --target auto --yes'); |
| 144 | skippedUnavailable = await runCmd('composio setup --target auto --yes --if-present'); |
| 145 | skippedUnavailableUninstall = await runCmd( |
| 146 | 'composio setup --uninstall --target auto --yes --if-present' |
| 147 | ); |
| 148 | legacyClaude = await runCmd(legacyClaudeFixture); |
| 149 | legacyCodex = await runCmd(legacyCodexFixture); |
| 150 | legacyCodexIfPresent = await runCmd(legacyCodexIfPresentFixture); |
| 151 | claudeWithLegacyCodex = await runCmd(claudeWithLegacyCodexFixture); |
| 152 | codexWithLegacyClaude = await runCmd(codexWithLegacyClaudeFixture); |
| 153 | failedClaudeInspection = await runCmd(failedClaudeInspectionFixture); |
| 154 | }, TIMEOUTS.FIXTURE); |
| 155 | |
| 156 | describe.each([ |
| 157 | { |
| 158 | host: 'claude' as const, |
| 159 | result: () => claude, |
| 160 | marketplaceCommand: |
| 161 | 'claude plugin marketplace add https://github.com/ComposioHQ/composio-plugin-cc.git --scope user', |
| 162 | installCommand: 'claude plugin install composio@composio --scope user', |
| 163 | additionalMutationCommands: ['claude plugin enable composio@composio --scope user'], |
| 164 | uninstallCommand: 'claude plugin uninstall composio@composio --scope user --yes', |
| 165 | }, |
| 166 | { |
| 167 | host: 'codex' as const, |
| 168 | result: () => codex, |
| 169 | marketplaceCommand: |
| 170 | 'codex plugin marketplace add https://github.com/ComposioHQ/composio-plugin-openai.git --json', |
| 171 | installCommand: 'codex plugin add composio@composio --json', |
| 172 | additionalMutationCommands: [], |
| 173 | uninstallCommand: 'codex plugin remove composio@composio --json', |
| 174 | }, |
| 175 | ])( |
| 176 | '$host setup', |
| 177 | ({ |
| 178 | result, |
| 179 | marketplaceCommand, |
| 180 | installCommand, |
| 181 | additionalMutationCommands, |
| 182 | uninstallCommand, |
| 183 | }) => { |
| 184 | it('installs once and uninstalls once with idempotent reruns', () => { |
| 185 | const execution = result(); |
| 186 | expect(execution.exitCode).toBe(0); |
| 187 | expect(execution.stdout).toBe(''); |
| 188 | expect(execution.stderr).toBe(''); |
| 189 | |
| 190 | const firstRunCommands = execution.files['first-run.log'].trim().split('\n'); |
| 191 | expect(firstRunCommands.filter(command => command === marketplaceCommand)).toHaveLength( |
| 192 | 1 |
| 193 | ); |
| 194 | expect(firstRunCommands.filter(command => command === installCommand)).toHaveLength(1); |
| 195 | |
| 196 | const secondRunCommands = execution.files['second-run.log'].trim().split('\n'); |
| 197 | const mutationCommands = [ |
| 198 | marketplaceCommand, |
| 199 | installCommand, |
| 200 | ...additionalMutationCommands, |
| 201 | ]; |
| 202 | expect( |
| 203 | secondRunCommands.filter(command => |
| 204 | mutationCommands.some(mutation => mutation === command) |
| 205 | ) |
| 206 | ).toEqual([]); |
| 207 | expect(secondRunCommands.filter(command => command === uninstallCommand)).toHaveLength(1); |
| 208 | }); |
| 209 | } |
| 210 | ); |
| 211 | |
| 212 | describe('automatic host detection', () => { |
| 213 | it('fails clearly when neither supported host is installed', () => { |
| 214 | expect(unavailable.exitCode).not.toBe(0); |
| 215 | expect(unavailable.stdout).toBe(''); |
| 216 | expect(unavailable.stderr).toContain('No supported agent host was detected'); |
| 217 | }); |
| 218 | |
| 219 | it('can skip cleanly when invoked by an installer', () => { |
| 220 | expect(skippedUnavailable.exitCode).toBe(0); |
| 221 | expect(skippedUnavailable.stdout).toBe(''); |
| 222 | expect(skippedUnavailable.stderr).toBe(''); |
| 223 | }); |
| 224 | |
| 225 | it('can skip uninstall cleanly when no host is present', () => { |
| 226 | expect(skippedUnavailableUninstall.exitCode).toBe(0); |
| 227 | expect(skippedUnavailableUninstall.stdout).toBe(''); |
| 228 | expect(skippedUnavailableUninstall.stderr).toBe(''); |
| 229 | }); |
| 230 | }); |
| 231 | |
| 232 | describe('agent compatibility', () => { |
| 233 | it('exits with Claude update instructions when no supported host remains', () => { |
| 234 | expect(legacyClaude.exitCode).not.toBe(0); |
| 235 | expect(legacyClaude.stdout).toBe(''); |
| 236 | expect(legacyClaude.stderr).toContain('requires JSON plugin inspection'); |
| 237 | expect(legacyClaude.stderr).toContain('claude update'); |
| 238 | }); |
| 239 | |
| 240 | it('exits with upgrade instructions when no supported host remains', () => { |
| 241 | expect(legacyCodex.exitCode).not.toBe(0); |
| 242 | expect(legacyCodex.stdout).toBe(''); |
| 243 | expect(legacyCodex.stderr).toContain('requires Codex 0.139.0 or newer'); |
| 244 | expect(legacyCodex.stderr).toContain('codex update'); |
| 245 | expect(legacyCodex.stderr).not.toContain("unexpected argument '--json'"); |
| 246 | }); |
| 247 | |
| 248 | it('skips an unsupported-only host when invoked by an installer', () => { |
| 249 | expect(legacyCodexIfPresent.exitCode).toBe(0); |
| 250 | expect(legacyCodexIfPresent.stdout).toBe(''); |
| 251 | expect(legacyCodexIfPresent.stderr).toBe(''); |
| 252 | }); |
| 253 | |
| 254 | it('continues with Claude when Codex is unsupported', () => { |
| 255 | expect(claudeWithLegacyCodex.exitCode).toBe(0); |
| 256 | expect(claudeWithLegacyCodex.stdout).toBe(''); |
| 257 | expect(claudeWithLegacyCodex.stderr).toBe(''); |
| 258 | }); |
| 259 | |
| 260 | it('continues with Codex when Claude is unsupported', () => { |
| 261 | expect(codexWithLegacyClaude.exitCode).toBe(0); |
| 262 | expect(codexWithLegacyClaude.stdout).toBe(''); |
| 263 | expect(codexWithLegacyClaude.stderr).toBe(''); |
| 264 | }); |
| 265 | }); |
| 266 | |
| 267 | describe('graceful failures', () => { |
| 268 | it('reports the failed host, recovery command, and no generic usage dump', () => { |
| 269 | expect(failedClaudeInspection.exitCode).not.toBe(0); |
| 270 | expect(failedClaudeInspection.stdout).toBe(''); |
| 271 | expect(failedClaudeInspection.stderr).toContain('Composio setup was unsuccessful.'); |
| 272 | expect(failedClaudeInspection.stderr).toContain( |
| 273 | 'Failed to inspect Claude Code plugins: native inspection failed.' |
| 274 | ); |
| 275 | expect(failedClaudeInspection.stderr).toContain('composio setup --yes --target claude'); |
| 276 | expect(failedClaudeInspection.stderr).not.toContain('USAGE'); |
| 277 | expect(failedClaudeInspection.stderr).not.toContain('effect-errors'); |
| 278 | }); |
| 279 | }); |
| 280 | }, |
| 281 | }); |