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 run command e2e test |
| 3 | * |
| 4 | * `composio run` spawns the user's script as a child process and forwards its exit |
| 5 | * status to the caller. The forwarding path is process-level: the command handler sets |
| 6 | * `process.exitCode` and returns a *successful* Effect, and the CLI teardown hands that |
| 7 | * code to `runMain`, which force-exits only for a non-zero code. Nothing in-process can |
| 8 | * observe whether that hand-off actually reached the OS, so a `wait`/`$?` assertion |
| 9 | * against the real binary is the only guard against a failing script silently becoming |
| 10 | * exit 0. |
| 11 | * |
| 12 | * The same applies to the `RUN_LOG_FILE=` path announced on stderr: it is only useful if |
| 13 | * the file outlives the process that printed it, which cannot be checked from inside the |
| 14 | * run. |
| 15 | */ |
| 16 | |
| 17 | import { e2e, sanitizeOutput, type E2ETestResult } from '@e2e-tests/utils'; |
| 18 | import { TIMEOUTS } from '@e2e-tests/utils/const'; |
| 19 | import { describe, it, expect, beforeAll } from 'bun:test'; |
| 20 | |
| 21 | /** Marker printed by the successful inline script, unique enough to grep for. */ |
| 22 | const STDOUT_MARKER = 'composio-run-e2e-stdout-marker'; |
| 23 | |
| 24 | /** |
| 25 | * Runs a successful script, then — after the CLI process has exited — reports whether the |
| 26 | * `RUN_LOG_FILE=` path it advertised on stderr still exists. Probe results go to stdout as |
| 27 | * `KEY=value` lines; the CLI's own stderr is parked in a file so it cannot mix in. |
| 28 | */ |
| 29 | const runLogProbeCommand = [ |
| 30 | `composio run 'console.log("run-log-probe")' 2> run-stderr.txt`, |
| 31 | 'run_status=$?', |
| 32 | `run_log_path=$(grep '^RUN_LOG_FILE=' run-stderr.txt | head -n 1 | cut -d= -f2-)`, |
| 33 | 'echo "RUN_STATUS=$run_status"', |
| 34 | 'if [ -n "$run_log_path" ]; then echo "RUN_LOG_ANNOUNCED=yes"; else echo "RUN_LOG_ANNOUNCED=no"; fi', |
| 35 | 'if [ -f "$run_log_path" ]; then echo "RUN_LOG_EXISTS=yes"; else echo "RUN_LOG_EXISTS=no"; fi', |
| 36 | ].join('; '); |
| 37 | |
| 38 | e2e(import.meta.url, { |
| 39 | versions: { |
| 40 | cli: ['current'], |
| 41 | }, |
| 42 | defineTests: ({ runCmd }) => { |
| 43 | let failingScriptResult: E2ETestResult; |
| 44 | let successfulScriptResult: E2ETestResult; |
| 45 | let missingScriptResult: E2ETestResult; |
| 46 | let runLogResult: E2ETestResult; |
| 47 | |
| 48 | beforeAll(async () => { |
| 49 | failingScriptResult = await runCmd(`composio run 'process.exit(7)'`); |
| 50 | successfulScriptResult = await runCmd(`composio run 'console.log("${STDOUT_MARKER}")'`); |
| 51 | missingScriptResult = await runCmd('composio run'); |
| 52 | runLogResult = await runCmd(runLogProbeCommand); |
| 53 | }, TIMEOUTS.FIXTURE); |
| 54 | |
| 55 | describe('composio run with a failing script', () => { |
| 56 | it('forwards the script exit status to the caller', () => { |
| 57 | expect(failingScriptResult.exitCode).toBe(7); |
| 58 | }); |
| 59 | }); |
| 60 | |
| 61 | describe('composio run with a successful script', () => { |
| 62 | it('exits successfully', () => { |
| 63 | expect(successfulScriptResult.exitCode).toBe(0); |
| 64 | }); |
| 65 | |
| 66 | it('forwards script stdout to the caller', () => { |
| 67 | expect(sanitizeOutput(successfulScriptResult.stdout)).toContain(STDOUT_MARKER); |
| 68 | }); |
| 69 | }); |
| 70 | |
| 71 | describe('composio run without inline code or --file', () => { |
| 72 | it('exits non-zero', () => { |
| 73 | expect(missingScriptResult.exitCode).not.toBe(0); |
| 74 | }); |
| 75 | |
| 76 | it('explains what is missing on stderr', () => { |
| 77 | expect(sanitizeOutput(missingScriptResult.stderr)).toContain( |
| 78 | 'Provide inline code or use --file to run a script file.' |
| 79 | ); |
| 80 | }); |
| 81 | |
| 82 | it('writes no data to stdout', () => { |
| 83 | expect(sanitizeOutput(missingScriptResult.stdout)).toBe(''); |
| 84 | }); |
| 85 | }); |
| 86 | |
| 87 | describe('the RUN_LOG_FILE path announced on stderr', () => { |
| 88 | it('is announced', () => { |
| 89 | expect(runLogResult.exitCode).toBe(0); |
| 90 | expect(sanitizeOutput(runLogResult.stdout)).toContain('RUN_STATUS=0'); |
| 91 | expect(sanitizeOutput(runLogResult.stdout)).toContain('RUN_LOG_ANNOUNCED=yes'); |
| 92 | }); |
| 93 | |
| 94 | it('still exists after the CLI process exits', () => { |
| 95 | expect(sanitizeOutput(runLogResult.stdout)).toContain('RUN_LOG_EXISTS=yes'); |
| 96 | }); |
| 97 | }); |
| 98 | }, |
| 99 | }); |