Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * CLI version command e2e test |
| 3 | * |
| 4 | * Verifies that the compiled composio CLI behaves correctly in a scratch container. |
| 5 | */ |
| 6 | |
| 7 | import { |
| 8 | e2e, |
| 9 | parseJsonStdout, |
| 10 | sanitizeOutput, |
| 11 | type E2ETestResult, |
| 12 | type E2ETestResultWithFiles, |
| 13 | } from '@e2e-tests/utils'; |
| 14 | import { TIMEOUTS } from '@e2e-tests/utils/const'; |
| 15 | import { describe, it, expect, beforeAll } from 'bun:test'; |
| 16 | import cliPkg from '../../../packages/cli/package.json' with { type: 'json' }; |
| 17 | |
| 18 | e2e(import.meta.url, { |
| 19 | versions: { |
| 20 | cli: ['current'], |
| 21 | }, |
| 22 | defineTests: ({ runCmd }) => { |
| 23 | const expectedVersion = String(cliPkg.version ?? '').trim(); |
| 24 | let versionResult: E2ETestResult; |
| 25 | let updateAvailableResult: E2ETestResult; |
| 26 | let unknownStatusResult: E2ETestResult; |
| 27 | let redirectedResult: E2ETestResultWithFiles<'out.txt'>; |
| 28 | |
| 29 | beforeAll(async () => { |
| 30 | versionResult = await runCmd('composio version'); |
| 31 | updateAvailableResult = await runCmd( |
| 32 | `mkdir -p .composio && printf '%s' '{"lastChecked":"2099-01-01T00:00:00.000Z","latestVersion":"99.0.0"}' > .composio/update-check.json && HOME="$PWD" composio version --check` |
| 33 | ); |
| 34 | unknownStatusResult = await runCmd( |
| 35 | `mkdir -p .composio && printf '%s' '{"lastAttempted":"2099-01-01T00:00:00.000Z"}' > .composio/update-check.json.attempt && HOME="$PWD" composio version --check` |
| 36 | ); |
| 37 | redirectedResult = await runCmd({ |
| 38 | command: 'composio version > out.txt', |
| 39 | files: ['out.txt'], |
| 40 | }); |
| 41 | }, TIMEOUTS.FIXTURE); |
| 42 | |
| 43 | describe('composio version', () => { |
| 44 | it('exits successfully', () => { |
| 45 | expect(versionResult.exitCode).toBe(0); |
| 46 | }); |
| 47 | |
| 48 | it('stdout matches snapshot', () => { |
| 49 | expect(sanitizeOutput(versionResult.stdout)).toBe(expectedVersion); |
| 50 | }); |
| 51 | |
| 52 | it('stderr matches snapshot', () => { |
| 53 | expect(versionResult.stderr).toBe(''); |
| 54 | }); |
| 55 | }); |
| 56 | |
| 57 | describe('composio version --check with a known update', () => { |
| 58 | it('exits successfully with clean machine-readable output', () => { |
| 59 | expect(updateAvailableResult.exitCode).toBe(0); |
| 60 | expect(updateAvailableResult.stderr).toBe(''); |
| 61 | expect(parseJsonStdout(updateAvailableResult)).toEqual({ |
| 62 | current: expectedVersion, |
| 63 | latestStable: '99.0.0', |
| 64 | updateAvailable: true, |
| 65 | checkStatus: 'update-available', |
| 66 | lastChecked: '2099-01-01T00:00:00.000Z', |
| 67 | }); |
| 68 | }); |
| 69 | }); |
| 70 | |
| 71 | describe('composio version --check when the latest release is unknown', () => { |
| 72 | it('exits successfully without claiming the current version is up to date', () => { |
| 73 | expect(unknownStatusResult.exitCode).toBe(0); |
| 74 | expect(unknownStatusResult.stderr).toBe(''); |
| 75 | expect(parseJsonStdout(unknownStatusResult)).toEqual({ |
| 76 | current: expectedVersion, |
| 77 | latestStable: null, |
| 78 | updateAvailable: false, |
| 79 | checkStatus: 'unknown', |
| 80 | lastChecked: null, |
| 81 | }); |
| 82 | }); |
| 83 | }); |
| 84 | |
| 85 | describe('stdout redirection to out.txt', () => { |
| 86 | it('exits successfully', () => { |
| 87 | expect(redirectedResult.exitCode).toBe(0); |
| 88 | }); |
| 89 | |
| 90 | it('stdout is empty', () => { |
| 91 | expect(redirectedResult.stdout).toBe(''); |
| 92 | }); |
| 93 | |
| 94 | it('stderr is empty', () => { |
| 95 | expect(redirectedResult.stderr).toBe(''); |
| 96 | }); |
| 97 | |
| 98 | it('out.txt matches snapshot', () => { |
| 99 | expect(sanitizeOutput(redirectedResult.files['out.txt'])).toBe(expectedVersion); |
| 100 | }); |
| 101 | }); |
| 102 | }, |
| 103 | }); |