Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

feat(cli): add explicit shell setup to install

jkomyno40f6b8b54e91
diff --git a/.github/workflows/cli.test-installation.yml b/.github/workflows/cli.test-installation.yml
index d3363acee..1b6c24cff 100644
--- a/.github/workflows/cli.test-installation.yml
+++ b/.github/workflows/cli.test-installation.yml
@@ -343,17 +343,17 @@ jobs:
config_file=~/.bashrc
fi
- if grep -q "COMPOSIO_INSTALL_DIR" "$config_file"; then
- echo "✅ $config_file updated with COMPOSIO_INSTALL_DIR"
+ if grep -Fqx '# Composio CLI' "$config_file"; then
+ echo "✅ $config_file updated with the Composio CLI marker"
else
- echo "❌ $config_file not updated with COMPOSIO_INSTALL_DIR"
+ echo "❌ $config_file not updated with the Composio CLI marker"
echo "=== $config_file contents ==="
cat "$config_file"
exit 1
fi
- if grep -q 'export PATH=.*COMPOSIO_INSTALL_DIR.*PATH' "$config_file"; then
- echo "✅ $config_file updated with PATH"
+ if grep -Fqx 'export PATH="$HOME/.composio:$PATH"' "$config_file"; then
+ echo "✅ $config_file updated with the installed binary directory"
else
echo "❌ $config_file PATH not updated"
echo "=== $config_file contents ==="
@@ -361,6 +361,13 @@ jobs:
exit 1
fi
+ if grep -q 'COMPOSIO_INSTALL_DIR' "$config_file"; then
+ echo "❌ $config_file still persists COMPOSIO_INSTALL_DIR"
+ echo "=== $config_file contents ==="
+ cat "$config_file"
+ exit 1
+ fi
+
- name: Test custom install directory
shell: bash
env:
diff --git a/ts/packages/cli/CHANGELOG.md b/ts/packages/cli/CHANGELOG.md
index d274acf70..a489d2f4f 100644
--- a/ts/packages/cli/CHANGELOG.md
+++ b/ts/packages/cli/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+### Minor Changes
+
+- `composio install` gains a `--shell <zsh|bash|fish>` flag that overrides `$SHELL` detection, in preparation for the mise-style installer rewrite. The bin-dir PATH target now resolves through `COMPOSIO_BIN_DIR`, an existing `~/.local/bin/composio`, or the real binary's own directory, in that order, instead of hardcoding `~/.composio`; rc blocks write only a PATH line (the `export COMPOSIO_INSTALL_DIR=...` line is gone, since that variable identifies the install bundle, not the PATH entry point). Bash now also writes the PATH line to `~/.bash_profile` or `~/.bash_login` when either already exists, so `bash -ilc` picks it up. The restart hint bug is fixed: bash now prints `source ~/.bashrc` instead of the literal string `exec $SHELL`.
+
### Patch Changes
- Make GitHub release metadata the sole version authority for standalone CLI
diff --git a/ts/packages/cli/lint-boundaries.json b/ts/packages/cli/lint-boundaries.json
index 1b49a6509..027ed510b 100644
--- a/ts/packages/cli/lint-boundaries.json
+++ b/ts/packages/cli/lint-boundaries.json
@@ -42,18 +42,6 @@
"target": "process.env.COMPOSIO_RUN_ACP_ONLY = acpOnly ? '1' : '0';"
}
],
- "src/commands/install.cmd.ts": [
- {
- "rule": "eslint-js/no-restricted-syntax",
- "reason": "$SHELL is read inside a plain synchronous helper that mirrors install.sh's shell detection, outside any Effect context",
- "target": "const shellEnv = process.env.SHELL ?? '';"
- },
- {
- "rule": "eslint-js/no-restricted-syntax",
- "reason": "COMPOSIO_INSTALL_DIR is the handoff variable set by the install.sh bootstrapper for this one-shot post-install step; read directly to stay byte-compatible with the script",
- "target": "const installDir = process.env.COMPOSIO_INSTALL_DIR ?? path.join(os.homedir, '.composio');"
- }
- ],
"src/commands/run.cmd.ts": [
{
"rule": "eslint-js/no-restricted-syntax",
diff --git a/ts/packages/cli/src/commands/install.cmd.ts b/ts/packages/cli/src/commands/install.cmd.ts
index cd91af522..54f5aef93 100644
--- a/ts/packages/cli/src/commands/install.cmd.ts
+++ b/ts/packages/cli/src/commands/install.cmd.ts
@@ -1,10 +1,10 @@
-import process from 'node:process';
import { Command, Options } from '@effect/cli';
import { FileSystem, Path } from '@effect/platform';
import type { PlatformError } from '@effect/platform/Error';
-import { Array as Arr, Effect } from 'effect';
+import { Array as Arr, Config, ConfigProvider, Effect, Option } from 'effect';
import { ComposioCliUserConfig } from 'src/services/cli-user-config';
import { NodeOs } from 'src/services/node-os';
+import { NodeProcess } from 'src/services/node-process';
import { TerminalUI } from 'src/services/terminal-ui';
import { getCompletionScript } from 'src/effects/shell-completions';
@@ -22,15 +22,22 @@ const noCompletionsOpt = Options.boolean('no-completions').pipe(
Options.withDefault(false)
);
+const SHELLS = ['zsh', 'bash', 'fish'] as const;
+
+const shellOpt = Options.choice('shell', SHELLS).pipe(
+ Options.withDescription('Override automatic shell detection.'),
+ Options.optional
+);
+
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
-type Shell = 'bash' | 'zsh' | 'fish';
+type Shell = (typeof SHELLS)[number];
interface ShellConfig {
readonly shell: Shell;
- readonly pathFile: string;
+ readonly pathFiles: readonly string[];
readonly completionFile: string;
readonly pathBlock: string;
readonly completionBlock: string | undefined;
@@ -43,13 +50,30 @@ interface ShellConfig {
const MARKER = '# Composio CLI';
const COMPLETIONS_MARKER = '# Composio CLI completions';
-/** Reject install directory paths containing shell metacharacters to prevent injection into rc files. */
-const UNSAFE_PATH_CHARS = /[;`$|&"'()\n\r\\]/;
+/** Reject bin-dir paths containing shell metacharacters to prevent injection into rc files. */
+const UNSAFE_PATH_CHARS = /[:;`$|&"'()\n\r\\]/;
const isUnsafePath = (p: string): boolean => UNSAFE_PATH_CHARS.test(p);
-const detectShell = (path: Path.Path): Shell | undefined => {
- // eslint-disable-next-line eslint-js/no-restricted-syntax -- $SHELL is read inside a plain synchronous helper that mirrors install.sh's shell detection, outside any Effect context
- const shellEnv = process.env.SHELL ?? '';
+// SHELL, PATH, and COMPOSIO_BIN_DIR are read from the literal environment: SHELL
+// and PATH are POSIX-standard (no app prefix applies to them), and COMPOSIO_BIN_DIR
+// is already the full env var name, not a suffix the app's `COMPOSIO_`-prefixing
+// ambient config provider should prefix again. Read them from a raw provider
+// instead (precedent: `src/analytics/dispatch.ts`'s `environmentProvider`).
+const environmentProvider = ConfigProvider.fromEnv();
+
+/** Read an optional env var from the raw environment; provider errors die rather than fail the command. */
+const readOptionalEnv = (name: string): Effect.Effect<string | undefined> =>
+ Effect.orDie(
+ environmentProvider.load(
+ Config.option(Config.string(name)).pipe(Config.map(Option.getOrUndefined))
+ )
+ );
+
+/** Read an env var from the raw environment, falling back when unset. */
+const readEnvWithDefault = (name: string, fallback: string): Effect.Effect<string> =>
+ Effect.orDie(environmentProvider.load(Config.string(name).pipe(Config.withDefault(fallback))));
+
+const detectShellFromEnv = (path: Path.Path, shellEnv: string): Shell | undefined => {
const base = path.basename(shellEnv);
if (base === 'zsh') return 'zsh';
if (base === 'bash') return 'bash';
@@ -57,69 +81,107 @@ const detectShell = (path: Path.Path): Shell | undefined => {
return undefined;
};
+const isDirOnPath = (pathEnv: string, dir: string): boolean =>
+ pathEnv.split(':').some(entry => entry === dir);
+
/**
- * Return candidate rc file paths for a shell, ordered by preference.
- * For bash this mirrors the install.sh fallback: .bashrc then .bash_profile.
+ * Bin-dir resolution order: explicit env, then `~/.local/bin` when it already
+ * holds a `composio` entry point, then the real binary's own directory.
*/
-const rcFileCandidates = (path: Path.Path, shell: Shell, homedir: string): string[] => {
- switch (shell) {
- case 'zsh':
- return [path.join(homedir, '.zshrc')];
- case 'bash':
- return [path.join(homedir, '.bashrc'), path.join(homedir, '.bash_profile')];
- case 'fish':
- return [path.join(homedir, '.config', 'fish', 'config.fish')];
+const resolveBinDir = (params: {
+ readonly envBinDir: string | undefined;
+ readonly localBinDir: string;
+ readonly localBinComposioExists: boolean;
+ readonly execPath: string;
+ readonly path: Path.Path;
+}): string => {
+ const trimmedEnvBinDir = params.envBinDir?.trim();
+ if (trimmedEnvBinDir && trimmedEnvBinDir.length > 0) {
+ return trimmedEnvBinDir;
}
+ if (params.localBinComposioExists) {
+ return params.localBinDir;
+ }
+ return params.path.dirname(params.execPath);
+};
+
+/**
+ * Render a path for embedding in a shell rc file. `~` never expands inside
+ * double quotes, so home-relative paths use a literal `$HOME` prefix instead.
+ */
+const renderWithHome = (dir: string, homedir: string): string =>
+ dir === homedir
+ ? '$HOME'
+ : dir.startsWith(`${homedir}/`)
+ ? `$HOME/${dir.slice(homedir.length + 1)}`
+ : dir;
+
+const pathBlockForShell = (shell: Shell, binDir: string, homedir: string): string => {
+ const rendered = renderWithHome(binDir, homedir);
+ return shell === 'fish'
+ ? [MARKER, `set --export PATH "${rendered}" $PATH`].join('\n')
+ : [MARKER, `export PATH="${rendered}:$PATH"`].join('\n');
};
+/** Bash startup-file candidates that only bash's login mode reads, in read order. */
+const bashLoginOverrideCandidates = (path: Path.Path, homedir: string): string[] => [
+ path.join(homedir, '.bash_profile'),
+ path.join(homedir, '.bash_login'),
+];
+
/**
- * Pick the first existing candidate, or fall back to the first candidate
- * (which will be created).
+ * First existing bash login-override file, if any. `bash -ilc` reads only the
+ * first of `.bash_profile`, `.bash_login`, `.profile` that exists — so an
+ * existing override shadows `.profile` and common `.profile` files source
+ * `.bashrc`, unless the PATH line also lands in the override. `.profile` is
+ * deliberately not a candidate below: when neither override exists, bash reads
+ * `.profile` itself, and common `.profile` files already source `.bashrc`, so
+ * nothing needs to be written to it.
*/
-const resolveRcFile = (
- candidates: string[],
+const resolveBashLoginOverride = (
+ candidates: readonly string[],
fs: FileSystem.FileSystem
-): Effect.Effect<string, PlatformError> =>
+): Effect.Effect<string | undefined, PlatformError> =>
Effect.gen(function* () {
for (const candidate of candidates) {
- const exists = yield* fs.exists(candidate);
- if (exists) return candidate;
+ if (yield* fs.exists(candidate)) return candidate;
}
- return candidates[0]!;
+ return undefined;
});
-const pathBlockForShell = (shell: Shell, installDir: string): string => {
+const pathFilesForShell = (
+ path: Path.Path,
+ shell: Shell,
+ homedir: string,
+ bashLoginOverride: string | undefined
+): string[] => {
switch (shell) {
+ case 'zsh':
+ return [path.join(homedir, '.zshrc')];
case 'fish':
- return [
- MARKER,
- `set --export COMPOSIO_INSTALL_DIR "${installDir}"`,
- `set --export PATH $COMPOSIO_INSTALL_DIR $PATH`,
- ].join('\n');
- default:
- return [
- MARKER,
- `export COMPOSIO_INSTALL_DIR="${installDir}"`,
- `export PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
- ].join('\n');
+ return [path.join(homedir, '.config', 'fish', 'config.fish')];
+ case 'bash': {
+ const bashrc = path.join(homedir, '.bashrc');
+ return bashLoginOverride ? [bashrc, bashLoginOverride] : [bashrc];
+ }
}
};
const buildShellConfig = (
path: Path.Path,
shell: Shell,
- rcFile: string,
- installDir: string,
+ pathFiles: readonly string[],
+ binDir: string,
completionScript: string | undefined,
homedir: string
): ShellConfig => ({
shell,
- pathFile: rcFile,
+ pathFiles,
completionFile:
shell === 'fish'
? path.join(homedir, '.config', 'fish', 'completions', 'composio.fish')
- : rcFile,
- pathBlock: pathBlockForShell(shell, installDir),
+ : pathFiles[0]!,
+ pathBlock: pathBlockForShell(shell, binDir, homedir),
completionBlock: completionScript ? `${COMPLETIONS_MARKER}\n${completionScript}` : undefined,
});
@@ -158,14 +220,17 @@ const resolveWriteTarget = (
export const installShellIntegration = (params: {
readonly completions: boolean;
+ readonly execPath?: string;
+ readonly shell?: Shell;
}): Effect.Effect<
void,
PlatformError,
- TerminalUI | NodeOs | FileSystem.FileSystem | Path.Path | ComposioCliUserConfig
+ TerminalUI | NodeOs | NodeProcess | FileSystem.FileSystem | Path.Path | ComposioCliUserConfig
> =>
Effect.gen(function* () {
const ui = yield* TerminalUI;
const os = yield* NodeOs;
+ const nodeProcess = yield* NodeProcess;
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
@@ -185,26 +250,50 @@ export const installShellIntegration = (params: {
yield* ui.intro('composio install');
- // Detect install directory — either from env or default ~/.composio
- // eslint-disable-next-line eslint-js/no-restricted-syntax -- COMPOSIO_INSTALL_DIR is the handoff variable set by the install.sh bootstrapper for this one-shot post-install step; read directly to stay byte-compatible with the script
- const installDir = process.env.COMPOSIO_INSTALL_DIR ?? path.join(os.homedir, '.composio');
+ // Resolve the entry-point bin dir: explicit env, then an existing
+ // ~/.local/bin/composio, then the runtime executable's own directory.
+ const envBinDir = yield* readOptionalEnv('COMPOSIO_BIN_DIR');
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
+ const localBinComposioExists = yield* fs.exists(path.join(localBinDir, 'composio'));
+ const binDir = path.normalize(
+ resolveBinDir({
+ envBinDir,
+ localBinDir,
+ localBinComposioExists,
+ execPath: params.execPath ?? nodeProcess.execPath,
+ path,
+ })
+ );
- if (isUnsafePath(installDir)) {
+ if (!path.isAbsolute(binDir)) {
+ yield* failure('Resolved bin directory must be an absolute path.');
+ yield* ui.outro('Aborted.');
+ return;
+ }
+
+ if (isUnsafePath(binDir)) {
yield* failure(
- 'COMPOSIO_INSTALL_DIR contains unsafe characters and cannot be written to shell config.'
+ 'Resolved bin directory contains unsafe characters and cannot be written to shell config.'
);
yield* ui.outro('Aborted.');
return;
}
- // Detect user shell
- const shell = detectShell(path);
+ const isExplicitShell = params.shell !== undefined;
+ const shellEnv = yield* readEnvWithDefault('SHELL', '');
+ const shell = params.shell ?? detectShellFromEnv(path, shellEnv);
+
+ const pathEnv = yield* readEnvWithDefault('PATH', '');
+ const binDirOnPath = isDirOnPath(pathEnv, binDir);
+
if (!shell) {
+ if (binDirOnPath) {
+ yield* success(`PATH: ${tildify(binDir, os.homedir)} is already on $PATH — nothing to do.`);
+ yield* ui.outro('Done');
+ return;
+ }
yield* warn('Could not detect your shell. Manually add the following to your shell config:');
- yield* note(
- `export COMPOSIO_INSTALL_DIR="${installDir}"\nexport PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
- 'PATH setup'
- );
+ yield* note(`export PATH="${renderWithHome(binDir, os.homedir)}:$PATH"`, 'PATH setup');
yield* ui.outro('Manual setup required.');
return;
}
@@ -229,15 +318,28 @@ export const installShellIntegration = (params: {
completionScript = lines.length > 0 ? Arr.join(lines, '\n') : undefined;
}
- const rcFile = yield* resolveRcFile(rcFileCandidates(path, shell, os.homedir), fs);
- const config = buildShellConfig(path, shell, rcFile, installDir, completionScript, os.homedir);
+ const bashLoginOverride =
+ shell === 'bash'
+ ? yield* resolveBashLoginOverride(bashLoginOverrideCandidates(path, os.homedir), fs)
+ : undefined;
+ const pathFiles = pathFilesForShell(path, shell, os.homedir, bashLoginOverride);
+ const config = buildShellConfig(path, shell, pathFiles, binDir, completionScript, os.homedir);
- const uniqueTargetFiles = [...new Set([config.pathFile, config.completionFile])];
+ const uniqueTargetFiles = [...new Set([...config.pathFiles, config.completionFile])];
const existingByFile = new Map<string, string>();
for (const filePath of uniqueTargetFiles) {
existingByFile.set(filePath, yield* readMaybeMissingFile(filePath, fs));
}
+ // Resolve each configured PATH file's real write target up front so two
+ // logical paths that alias the same physical file (a dotfiles setup
+ // symlinking .bash_profile -> .bashrc) get the PATH block appended once,
+ // not once per alias.
+ const pathFileTargets = new Map<string, string>();
+ for (const filePath of config.pathFiles) {
+ pathFileTargets.set(filePath, yield* resolveWriteTarget(filePath, fs));
+ }
+
const blocksByFile = new Map<string, Array<string>>();
const pushBlock = (filePath: string, block: string) => {
const blocks = blocksByFile.get(filePath);
@@ -248,10 +350,40 @@ export const installShellIntegration = (params: {
}
};
- const existingPathFile = existingByFile.get(config.pathFile) ?? '';
- if (!fileContains(existingPathFile, MARKER)) {
- pushBlock(config.pathFile, config.pathBlock);
- yield* step(`PATH: will add ${tildify(installDir, os.homedir)} to $PATH`);
+ // Auto-detected mode may skip the PATH write entirely when the bin dir is
+ // already reachable; an explicit --shell always configures its files.
+ // Only applies to a genuinely fresh install: if any target file already
+ // carries our marker from a prior run, a file that appeared since then
+ // (e.g. a freshly created .bash_profile) still needs its own write, even
+ // though the invoking process's current $PATH already resolves.
+ const anyPathFileAlreadyMarked = config.pathFiles.some(filePath =>
+ fileContains(existingByFile.get(filePath) ?? '', MARKER)
+ );
+ const skipPathWriteForReachability =
+ !isExplicitShell && binDirOnPath && !anyPathFileAlreadyMarked;
+ let pathWritten = false;
+ let loginOverrideWritten = false;
+ const queuedPathTargets = new Set<string>();
+ for (const filePath of config.pathFiles) {
+ const existing = existingByFile.get(filePath) ?? '';
+ const target = pathFileTargets.get(filePath)!;
+ if (
+ fileContains(existing, MARKER) ||
+ skipPathWriteForReachability ||
+ queuedPathTargets.has(target)
+ ) {
+ continue;
+ }
+ pushBlock(filePath, config.pathBlock);
+ queuedPathTargets.add(target);
+ pathWritten = true;
+ if (filePath === bashLoginOverride) loginOverrideWritten = true;
+ }
+
+ if (pathWritten) {
+ yield* step(`PATH: will add ${tildify(binDir, os.homedir)} to $PATH`);
+ } else if (skipPathWriteForReachability) {
+ yield* step('PATH: already on $PATH — nothing to do.');
} else {
yield* step('PATH: already configured');
}
@@ -283,6 +415,7 @@ export const installShellIntegration = (params: {
// not discard a previous iteration's append.
const existingContents = yield* readMaybeMissingFile(filePath, fs);
const writeTarget = yield* resolveWriteTarget(filePath, fs);
+ const existingTargetInfo = yield* fs.stat(writeTarget).pipe(Effect.option);
yield* fs
.makeDirectory(path.dirname(writeTarget), { recursive: true })
@@ -296,6 +429,9 @@ export const installShellIntegration = (params: {
const tmpPath = `${writeTarget}.composio-tmp`;
yield* fs.writeFileString(tmpPath, existingContents + appendContent);
+ if (Option.isSome(existingTargetInfo)) {
+ yield* fs.chmod(tmpPath, existingTargetInfo.value.mode & 0o7777);
+ }
yield* fs.rename(tmpPath, writeTarget);
yield* success(`Updated ${tildify(filePath, os.homedir)}`);
@@ -305,14 +441,23 @@ export const installShellIntegration = (params: {
}
if (blocksByFile.size > 0) {
- yield* note(
- shell === 'fish'
- ? 'exec fish'
- : shell === 'zsh'
- ? `source ${tildify(rcFile, os.homedir)}`
- : 'exec $SHELL',
- 'Restart your shell to apply changes'
- );
+ if (shell === 'fish') {
+ yield* note('exec fish', 'Restart your shell to apply changes');
+ } else if (shell === 'zsh') {
+ yield* note(
+ `source ${tildify(config.pathFiles[0]!, os.homedir)}`,
+ 'Restart your shell to apply changes'
+ );
+ } else {
+ const bashrc = path.join(os.homedir, '.bashrc');
+ const hintLines = [`source ${tildify(bashrc, os.homedir)}`];
+ if (loginOverrideWritten && bashLoginOverride) {
+ hintLines.push(
+ `${tildify(bashLoginOverride, os.homedir)} was also updated — that entry applies to new login shells too.`
+ );
+ }
+ yield* note(hintLines.join('\n'), 'Restart your shell to apply changes');
+ }
}
yield* ui.outro('Done');
@@ -330,11 +475,15 @@ export const installShellIntegration = (params: {
* composio install
* composio install --completions
* composio install --no-completions
+ * composio install --shell zsh
* ```
*/
export const installCmd = Command.make(
'install',
- { completions: completionsOpt, noCompletions: noCompletionsOpt },
- ({ completions, noCompletions }) =>
- installShellIntegration({ completions: completions && !noCompletions })
+ { completions: completionsOpt, noCompletions: noCompletionsOpt, shell: shellOpt },
+ ({ completions, noCompletions, shell }) =>
+ installShellIntegration({
+ completions: completions && !noCompletions,
+ shell: Option.getOrUndefined(shell),
+ })
).pipe(Command.withDescription('Set up shell integration (PATH and completions).'));
diff --git a/ts/packages/cli/src/services/node-process.ts b/ts/packages/cli/src/services/node-process.ts
index d36c2725b..63119ef5a 100644
--- a/ts/packages/cli/src/services/node-process.ts
+++ b/ts/packages/cli/src/services/node-process.ts
@@ -5,6 +5,7 @@ import { Effect } from 'effect';
export class NodeProcess extends Effect.Service<NodeProcess>()('services/NodeProcess', {
sync: () => ({
cwd: process.cwd(),
+ execPath: process.execPath,
platform: process.platform,
arch: process.arch,
}),
diff --git a/ts/packages/cli/test/__utils__/services/test-layer.ts b/ts/packages/cli/test/__utils__/services/test-layer.ts
index 1bcc22c4a..cbf7f5c4f 100644
--- a/ts/packages/cli/test/__utils__/services/test-layer.ts
+++ b/ts/packages/cli/test/__utils__/services/test-layer.ts
@@ -1,3 +1,4 @@
+import path from 'node:path';
import * as tempy from 'tempy';
import { CliApp, CliConfig } from '@effect/cli';
import { Command, FetchHttpClient, FileSystem, Path } from '@effect/platform';
@@ -803,6 +804,7 @@ export const TestLayer = (input?: TestLiveInput) =>
NodeProcess,
new NodeProcess({
cwd,
+ execPath: path.join(cwd, 'composio'),
platform: 'darwin',
arch: 'arm64',
})
diff --git a/ts/packages/cli/test/src/commands/install.cmd.test.ts b/ts/packages/cli/test/src/commands/install.cmd.test.ts
index 127c78766..51521d006 100644
--- a/ts/packages/cli/test/src/commands/install.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/install.cmd.test.ts
@@ -1,11 +1,11 @@
import path from 'node:path';
-import process from 'node:process';
import { Writable } from 'node:stream';
-import { beforeEach, afterEach } from 'vitest';
+import { beforeEach, vi } from 'vitest';
import { describe, expect, layer } from '@effect/vitest';
-import { Effect } from 'effect';
+import { Effect, Exit } from 'effect';
import { FileSystem } from '@effect/platform';
import { NodeOs } from 'src/services/node-os';
+import { installShellIntegration } from 'src/commands/install.cmd';
import { makeTerminalUI } from 'src/services/terminal-ui';
import { cli, TestLive, MockConsole } from 'test/__utils__';
@@ -28,47 +28,63 @@ const capturedStderrUI = makeTerminalUI({
stderr: capturedStderr,
});
-describe('CLI: composio install', () => {
- let savedShell: string | undefined;
- let savedInstallDir: string | undefined;
+// A PATH that never contains a test's resolved bin dir. The default fallback
+// bin dir (no COMPOSIO_BIN_DIR, no ~/.local/bin/composio) is `dirname(TEST_EXEC_PATH)`,
+// which is frequently already on the host's real PATH (a Node/Bun/mise shim
+// dir) — exactly what tests must not depend on, so this always overrides it.
+const SAFE_PATH = '/usr/bin:/bin';
+const TEST_EXEC_PATH = '/usr/local/bin/composio';
+const expectedRuntimeBinDir = (): string => path.dirname(TEST_EXEC_PATH);
+const install = (
+ params: {
+ readonly completions?: boolean;
+ readonly execPath?: string;
+ readonly shell?: string;
+ } = {}
+) =>
+ installShellIntegration({
+ completions: params.completions ?? false,
+ execPath: params.execPath ?? TEST_EXEC_PATH,
+ shell: params.shell as 'zsh' | 'bash' | 'fish' | undefined,
+ });
+
+// NOTE: `@effect/vitest`'s `layer(...)` builds one shared TestLive instance
+// (home dir, MockConsole buffer, etc.) for every `it.scoped` nested inside a
+// single call. Sharing is only safe when a later test doesn't read state a
+// prior test mutated (MockConsole output, rc files under the shared home
+// dir) — so each independent scenario below gets its own `layer(...)` call,
+// mirroring the file's existing single-test blocks. The two-test blocks that
+// remain (zsh's symlink test, the stderr-capture pair) are safe because the
+// second test never reads `MockConsole` and resets any file state it cares
+// about itself.
+describe('CLI: composio install', () => {
beforeEach(() => {
- savedShell = process.env.SHELL;
- savedInstallDir = process.env.COMPOSIO_INSTALL_DIR;
+ // vitest.config.ts sets `unstubEnvs: true`, so every `vi.stubEnv` call
+ // below is automatically reverted after each test — no manual save/restore.
+ vi.stubEnv('PATH', SAFE_PATH);
+ vi.stubEnv('COMPOSIO_BIN_DIR', '');
capturedStdout.chunks.length = 0;
capturedStderr.chunks.length = 0;
});
- afterEach(() => {
- if (savedShell !== undefined) {
- process.env.SHELL = savedShell;
- } else {
- delete process.env.SHELL;
- }
- if (savedInstallDir !== undefined) {
- process.env.COMPOSIO_INSTALL_DIR = savedInstallDir;
- } else {
- delete process.env.COMPOSIO_INSTALL_DIR;
- }
- });
-
describe('[When] shell is zsh', () => {
layer(TestLive())(it => {
it.scoped('[Then] creates .zshrc with PATH only by default', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
- process.env.SHELL = '/bin/zsh';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/bin/zsh');
+ const expectedBinDir = expectedRuntimeBinDir();
- yield* cli(['install']);
+ yield* install();
const fs = yield* FileSystem.FileSystem;
const rcPath = path.join(os.homedir, '.zshrc');
const contents = yield* fs.readFileString(rcPath);
expect(contents).toContain('# Composio CLI');
- expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
- expect(contents).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
+ expect(contents).not.toContain('COMPOSIO_INSTALL_DIR');
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
expect(contents).not.toContain('# Composio CLI completions');
const lines = yield* MockConsole.getLines();
@@ -85,8 +101,7 @@ describe('CLI: composio install', () => {
Effect.gen(function* () {
const os = yield* NodeOs;
const fs = yield* FileSystem.FileSystem;
- process.env.SHELL = '/bin/zsh';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/bin/zsh');
const rcPath = path.join(os.homedir, '.zshrc');
const managedPath = path.join(os.homedir, '.managed-zshrc');
@@ -95,7 +110,7 @@ describe('CLI: composio install', () => {
yield* fs.writeFileString(managedPath, '# managed shell config\n');
yield* fs.symlink(linkTarget, rcPath);
- yield* cli(['install']);
+ yield* install();
expect(yield* fs.readLink(rcPath)).toBe(linkTarget);
expect(yield* fs.readFileString(managedPath)).toContain('# Composio CLI');
@@ -110,41 +125,188 @@ describe('CLI: composio install', () => {
it.scoped('[Then] creates .bashrc with PATH only by default', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
- process.env.SHELL = '/bin/bash';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/bin/bash');
+ const expectedBinDir = expectedRuntimeBinDir();
- yield* cli(['install']);
+ yield* install();
const fs = yield* FileSystem.FileSystem;
const rcPath = path.join(os.homedir, '.bashrc');
const contents = yield* fs.readFileString(rcPath);
expect(contents).toContain('# Composio CLI');
- expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
- expect(contents).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
+ expect(contents).not.toContain('COMPOSIO_INSTALL_DIR');
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
expect(contents).not.toContain('# Composio CLI completions');
})
);
});
});
+ describe('[When] bash has neither .bash_profile nor .bash_login', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] only .bashrc is created', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '/bin/bash');
+
+ yield* install();
+
+ const fs = yield* FileSystem.FileSystem;
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(true);
+ expect(yield* fs.exists(path.join(os.homedir, '.bash_profile'))).toBe(false);
+ expect(yield* fs.exists(path.join(os.homedir, '.bash_login'))).toBe(false);
+ })
+ );
+ });
+ });
+
+ describe('[When] bash has an existing .bash_profile', () => {
+ layer(TestLive())(it => {
+ it.scoped(
+ '[Then] the PATH block also lands in .bash_profile, and the restart hint mentions it',
+ () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/bash');
+
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
+ yield* fs.writeFileString(bashProfilePath, '# existing login config\n');
+
+ yield* install();
+
+ const bashrcContents = yield* fs.readFileString(path.join(os.homedir, '.bashrc'));
+ const bashProfileContents = yield* fs.readFileString(bashProfilePath);
+ expect(bashrcContents).toContain('# Composio CLI');
+ expect(bashProfileContents).toContain('# Composio CLI');
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain('source ~/.bashrc');
+ expect(output).toContain('~/.bash_profile');
+ expect(output).toContain('login shell');
+ expect(output).not.toContain('exec $SHELL');
+ })
+ );
+ });
+ });
+
+ describe('[When] bash updates a private .bash_profile', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] preserves its existing file mode', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/bash');
+
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
+ yield* fs.writeFileString(bashProfilePath, '# private login config\n');
+ yield* fs.chmod(bashProfilePath, 0o600);
+
+ yield* install();
+
+ const info = yield* fs.stat(bashProfilePath);
+ expect(info.mode & 0o777).toBe(0o600);
+ })
+ );
+ });
+ });
+
+ describe('[When] bash has only .bash_login (no .bash_profile)', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] the PATH block also lands in .bash_login', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/bash');
+
+ const bashLoginPath = path.join(os.homedir, '.bash_login');
+ yield* fs.writeFileString(bashLoginPath, '# existing login config\n');
+
+ yield* install();
+
+ const bashrcContents = yield* fs.readFileString(path.join(os.homedir, '.bashrc'));
+ const bashLoginContents = yield* fs.readFileString(bashLoginPath);
+ expect(bashrcContents).toContain('# Composio CLI');
+ expect(bashLoginContents).toContain('# Composio CLI');
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain('source ~/.bashrc');
+ expect(output).toContain('~/.bash_login');
+ expect(output).toContain('login shell');
+ })
+ );
+ });
+ });
+
+ describe('[When] bash has both .bash_profile and .bash_login', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] only .bash_profile receives the login PATH block', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/bash');
+
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
+ const bashLoginPath = path.join(os.homedir, '.bash_login');
+ yield* fs.writeFileString(bashProfilePath, '# existing profile\n');
+ yield* fs.writeFileString(bashLoginPath, '# existing login\n');
+
+ yield* install();
+
+ const bashProfileContents = yield* fs.readFileString(bashProfilePath);
+ const bashLoginContents = yield* fs.readFileString(bashLoginPath);
+ expect(bashProfileContents).toContain('# Composio CLI');
+ expect(bashLoginContents).not.toContain('# Composio CLI');
+ })
+ );
+ });
+ });
+
+ describe('[When] .bash_profile is symlinked to the same file as .bashrc', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] the PATH block is written exactly once, not once per alias', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/bash');
+
+ const bashrcPath = path.join(os.homedir, '.bashrc');
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
+ const managedPath = path.join(os.homedir, '.managed-bashrc');
+ yield* fs.remove(bashrcPath, { force: true });
+ yield* fs.writeFileString(managedPath, '# managed shell config\n');
+ yield* fs.symlink(managedPath, bashrcPath);
+ yield* fs.symlink(managedPath, bashProfilePath);
+
+ yield* install();
+
+ const contents = yield* fs.readFileString(managedPath);
+ const pathMarkerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
+ expect(pathMarkerCount).toBe(1);
+ })
+ );
+ });
+ });
+
describe('[When] shell is fish', () => {
layer(TestLive())(it => {
it.scoped('[Then] creates config.fish with PATH only by default', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
- process.env.SHELL = '/usr/bin/fish';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/usr/bin/fish');
- yield* cli(['install']);
+ yield* install();
const fs = yield* FileSystem.FileSystem;
const rcPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
const contents = yield* fs.readFileString(rcPath);
expect(contents).toContain('# Composio CLI');
- expect(contents).toContain('set --export COMPOSIO_INSTALL_DIR');
- expect(contents).toContain('set --export PATH $COMPOSIO_INSTALL_DIR $PATH');
+ expect(contents).not.toContain('COMPOSIO_INSTALL_DIR');
+ expect(contents).toContain('set --export PATH');
expect(contents).not.toContain('# Composio CLI completions');
})
);
@@ -156,17 +318,15 @@ describe('CLI: composio install', () => {
it.scoped('[Then] writes PATH block and installs completions', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
- process.env.SHELL = '/bin/bash';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/bin/bash');
- yield* cli(['install', '--completions']);
+ yield* install({ completions: true });
const fs = yield* FileSystem.FileSystem;
const rcPath = path.join(os.homedir, '.bashrc');
const contents = yield* fs.readFileString(rcPath);
expect(contents).toContain('# Composio CLI');
- expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
expect(contents).toContain('# Composio CLI completions');
const lines = yield* MockConsole.getLines();
@@ -184,10 +344,9 @@ describe('CLI: composio install', () => {
() =>
Effect.gen(function* () {
const os = yield* NodeOs;
- process.env.SHELL = '/usr/bin/fish';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/usr/bin/fish');
- yield* cli(['install', '--completions']);
+ yield* install({ completions: true });
const fs = yield* FileSystem.FileSystem;
const configPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
@@ -202,7 +361,7 @@ describe('CLI: composio install', () => {
const completionContents = yield* fs.readFileString(completionPath);
expect(configContents).toContain('# Composio CLI');
- expect(configContents).toContain('set --export COMPOSIO_INSTALL_DIR');
+ expect(configContents).toContain('set --export PATH');
expect(configContents).not.toContain('# Composio CLI completions');
expect(completionContents).toContain('# Composio CLI completions');
@@ -224,8 +383,7 @@ describe('CLI: composio install', () => {
Effect.gen(function* () {
const os = yield* NodeOs;
const fs = yield* FileSystem.FileSystem;
- process.env.SHELL = '/usr/bin/fish';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/usr/bin/fish');
const configPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
const completionPath = path.join(
@@ -242,7 +400,7 @@ describe('CLI: composio install', () => {
yield* fs.symlink(managedPath, configPath);
yield* fs.symlink(managedPath, completionPath);
- yield* cli(['install', '--completions']);
+ yield* install({ completions: true });
const contents = yield* fs.readFileString(managedPath);
const pathMarkerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
@@ -260,11 +418,10 @@ describe('CLI: composio install', () => {
it.scoped('[Then] keeps config.fish and composio.fish idempotent', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
- process.env.SHELL = '/usr/bin/fish';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/usr/bin/fish');
- yield* cli(['install', '--completions']);
- yield* cli(['install', '--completions']);
+ yield* install({ completions: true });
+ yield* install({ completions: true });
const fs = yield* FileSystem.FileSystem;
const configPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
@@ -297,17 +454,15 @@ describe('CLI: composio install', () => {
it.scoped('[Then] writes PATH block but skips completions', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
- process.env.SHELL = '/bin/zsh';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/bin/zsh');
- yield* cli(['install', '--no-completions']);
+ yield* install();
const fs = yield* FileSystem.FileSystem;
const rcPath = path.join(os.homedir, '.zshrc');
const contents = yield* fs.readFileString(rcPath);
expect(contents).toContain('# Composio CLI');
- expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
expect(contents).not.toContain('# Composio CLI completions');
const lines = yield* MockConsole.getLines();
@@ -323,12 +478,11 @@ describe('CLI: composio install', () => {
it.scoped('[Then] does not duplicate entries', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
- process.env.SHELL = '/bin/bash';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/bin/bash');
// Run install twice
- yield* cli(['install', '--completions']);
- yield* cli(['install', '--completions']);
+ yield* install({ completions: true });
+ yield* install({ completions: true });
const fs = yield* FileSystem.FileSystem;
const rcPath = path.join(os.homedir, '.bashrc');
@@ -352,17 +506,16 @@ describe('CLI: composio install', () => {
Effect.gen(function* () {
const os = yield* NodeOs;
const fs = yield* FileSystem.FileSystem;
- process.env.SHELL = '/bin/zsh';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/bin/zsh');
// Pre-populate .zshrc with existing config
const rcPath = path.join(os.homedir, '.zshrc');
yield* fs.writeFileString(
rcPath,
- '# existing config\n# Composio CLI\nexport COMPOSIO_INSTALL_DIR=/old\n# Composio CLI completions\n_composio() {}\n'
+ '# existing config\n# Composio CLI\nexport PATH="$HOME/.local/bin:$PATH"\n# Composio CLI completions\n_composio() {}\n'
);
- yield* cli(['install', '--completions']);
+ yield* install({ completions: true });
const lines = yield* MockConsole.getLines();
const output = lines.join('\n');
@@ -383,29 +536,54 @@ describe('CLI: composio install', () => {
layer(TestLive())(it => {
it.scoped('[Then] shows manual setup instructions', () =>
Effect.gen(function* () {
- process.env.SHELL = '';
+ vi.stubEnv('SHELL', '');
+ const expectedBinDir = expectedRuntimeBinDir();
- yield* cli(['install']);
+ yield* install();
const lines = yield* MockConsole.getLines();
const output = lines.join('\n');
expect(output).toContain('Could not detect your shell');
- expect(output).toContain('export COMPOSIO_INSTALL_DIR=');
+ expect(output).toContain(`export PATH="${expectedBinDir}:$PATH"`);
+ expect(output).not.toContain('COMPOSIO_INSTALL_DIR');
expect(output).toContain('Manual setup required.');
})
);
});
});
+ describe('[When] shell cannot be detected but the bin dir is already on $PATH', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] reports already on PATH instead of asking for manual setup', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '');
+ const binDir = expectedRuntimeBinDir();
+ vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
+
+ yield* install();
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain('already on $PATH');
+ expect(output).toContain('Done');
+ expect(output).not.toContain('Could not detect your shell');
+
+ const fs = yield* FileSystem.FileSystem;
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(false);
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(false);
+ })
+ );
+ });
+ });
+
describe('[When] stderr is captured rather than a terminal', () => {
layer(TestLive({ terminalUI: capturedStderrUI }))(it => {
it.scoped('[Then] still reports the rc file and how to reload the shell', () =>
Effect.gen(function* () {
- const os = yield* NodeOs;
- process.env.SHELL = '/bin/zsh';
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+ vi.stubEnv('SHELL', '/bin/zsh');
- yield* cli(['install']);
+ yield* install();
const output = capturedStderr.chunks.join('');
expect(output).toContain('PATH: will add');
@@ -417,56 +595,379 @@ describe('CLI: composio install', () => {
it.scoped('[Then] still shows manual setup instructions for an unknown shell', () =>
Effect.gen(function* () {
- process.env.SHELL = '';
+ vi.stubEnv('SHELL', '');
+ const expectedBinDir = expectedRuntimeBinDir();
- yield* cli(['install']);
+ yield* install();
const output = capturedStderr.chunks.join('');
expect(output).toContain('Could not detect your shell');
- expect(output).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
+ expect(output).toContain(`export PATH="${expectedBinDir}:$PATH"`);
})
);
});
});
- describe('[When] COMPOSIO_INSTALL_DIR is not set', () => {
+ describe('[When] --shell zsh overrides a conflicting $SHELL', () => {
layer(TestLive())(it => {
- it.scoped('[Then] defaults to ~/.composio', () =>
+ it.scoped('[Then] writes ~/.zshrc, not ~/.bashrc', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
- process.env.SHELL = '/bin/zsh';
- delete process.env.COMPOSIO_INSTALL_DIR;
+ vi.stubEnv('SHELL', '/bin/bash');
- yield* cli(['install']);
+ yield* install({ shell: 'zsh' });
const fs = yield* FileSystem.FileSystem;
- const rcPath = path.join(os.homedir, '.zshrc');
- const contents = yield* fs.readFileString(rcPath);
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(true);
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(false);
+ })
+ );
+ });
+ });
- // Should use ~/.composio as the default install directory (quoted)
- expect(contents).toContain(
- `export COMPOSIO_INSTALL_DIR="${path.join(os.homedir, '.composio')}"`
- );
+ describe('[When] --shell is parsed by the public CLI', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] a valid override reaches the requested shell integration', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/bash');
+
+ yield* cli(['install', '--shell', 'zsh']);
+
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(true);
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(false);
})
);
});
});
- describe('[When] COMPOSIO_INSTALL_DIR contains shell metacharacters', () => {
+ describe('[When] --shell has an unsupported value', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] the public CLI rejects it during option parsing', () =>
+ Effect.gen(function* () {
+ const exit = yield* cli(['install', '--shell', 'powershell']).pipe(Effect.exit);
+ expect(Exit.isFailure(exit)).toBe(true);
+ })
+ );
+ });
+ });
+
+ describe('[When] both completion flags are parsed by the public CLI', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] --no-completions takes precedence', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/bash');
+
+ yield* cli(['install', '--completions', '--no-completions']);
+
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.bashrc'));
+ expect(contents).toContain('# Composio CLI');
+ expect(contents).not.toContain('# Composio CLI completions');
+ })
+ );
+ });
+ });
+
+ describe('[When] --shell bash overrides a conflicting $SHELL', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] writes ~/.bashrc, not ~/.zshrc', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '/bin/zsh');
+
+ yield* install({ shell: 'bash' });
+
+ const fs = yield* FileSystem.FileSystem;
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(true);
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(false);
+ })
+ );
+ });
+ });
+
+ describe('[When] --shell fish is passed with $SHELL unset', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] writes config.fish', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '');
+
+ yield* install({ shell: 'fish' });
+
+ const fs = yield* FileSystem.FileSystem;
+ const rcPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
+ expect(yield* fs.exists(rcPath)).toBe(true);
+ })
+ );
+ });
+ });
+
+ describe('[When] --shell is explicit and the bin dir is already on the invoking $PATH', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] still writes the requested shell, and re-running stays idempotent', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '/bin/bash');
+ const binDir = expectedRuntimeBinDir();
+ vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
+
+ yield* install({ shell: 'zsh' });
+ yield* install({ shell: 'zsh' });
+
+ const fs = yield* FileSystem.FileSystem;
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ const markerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
+ expect(markerCount).toBe(1);
+ })
+ );
+ });
+ });
+
+ describe('[When] auto-detected shell has its bin dir already on $PATH', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] writes nothing and reports already on PATH, with no restart hint', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '/bin/zsh');
+ const binDir = expectedRuntimeBinDir();
+ vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
+
+ yield* install();
+
+ const fs = yield* FileSystem.FileSystem;
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(false);
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain('already on $PATH');
+ expect(output).not.toContain('Restart your shell');
+ })
+ );
+ });
+ });
+
+ describe('[When] a new .bash_profile appears after .bashrc was already configured, and the bin dir is already on $PATH', () => {
+ layer(TestLive())(it => {
+ it.scoped(
+ '[Then] the new .bash_profile still gets the PATH block, not skipped by the reachability check',
+ () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/bash');
+ const binDir = expectedRuntimeBinDir();
+ vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
+
+ // Simulate a prior `composio install` run that already configured .bashrc.
+ const bashrcPath = path.join(os.homedir, '.bashrc');
+ yield* fs.writeFileString(
+ bashrcPath,
+ `# Composio CLI\nexport PATH="${binDir}:$PATH"\n`
+ );
+
+ // .bash_profile shows up afterward and was never configured.
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
+ yield* fs.writeFileString(bashProfilePath, '# existing login config\n');
+
+ yield* install();
+
+ const bashProfileContents = yield* fs.readFileString(bashProfilePath);
+ expect(bashProfileContents).toContain('# Composio CLI');
+ })
+ );
+ });
+ });
+
+ describe('[When] COMPOSIO_BIN_DIR is set to a custom directory', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] --shell zsh writes a PATH line for the custom directory', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '/bin/bash');
+ vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin');
+
+ yield* install({ shell: 'zsh' });
+
+ const fs = yield* FileSystem.FileSystem;
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ expect(contents).toContain('export PATH="/custom/bin:$PATH"');
+ expect(contents).not.toContain('$HOME');
+ })
+ );
+ });
+ });
+
+ describe('[When] COMPOSIO_BIN_DIR is whitespace-only', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] it is treated as unset, not as a literal bin dir', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '/bin/zsh');
+ vi.stubEnv('COMPOSIO_BIN_DIR', ' ');
+ const expectedBinDir = expectedRuntimeBinDir();
+
+ yield* install();
+
+ const fs = yield* FileSystem.FileSystem;
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
+ })
+ );
+ });
+ });
+
+ describe('[When] COMPOSIO_BIN_DIR has surrounding whitespace around a real value', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] the surrounding whitespace is trimmed before it is used', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '/bin/zsh');
+ vi.stubEnv('COMPOSIO_BIN_DIR', ' /custom/bin ');
+
+ yield* install();
+
+ const fs = yield* FileSystem.FileSystem;
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ expect(contents).toContain('export PATH="/custom/bin:$PATH"');
+ })
+ );
+ });
+ });
+
+ describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin already has a composio entry point', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] the PATH line targets ~/.local/bin via a literal $HOME prefix', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/zsh');
+
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
+ yield* fs.makeDirectory(localBinDir, { recursive: true });
+ yield* fs.writeFileString(path.join(localBinDir, 'composio'), '');
+
+ yield* install();
+
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ expect(contents).toContain('export PATH="$HOME/.local/bin:$PATH"');
+ expect(contents).not.toContain('~/.local/bin');
+ })
+ );
+ });
+ });
+
+ describe('[When] COMPOSIO_BIN_DIR is set and ~/.local/bin also already has a composio entry point', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] the env var wins over the ~/.local/bin fallback', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/zsh');
+ vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin');
+
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
+ yield* fs.makeDirectory(localBinDir, { recursive: true });
+ yield* fs.writeFileString(path.join(localBinDir, 'composio'), '');
+
+ yield* install();
+
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ expect(contents).toContain('export PATH="/custom/bin:$PATH"');
+ expect(contents).not.toContain('.local/bin');
+ })
+ );
+ });
+ });
+
+ describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin has no composio entry point', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] the PATH line targets the real binary directory', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ vi.stubEnv('SHELL', '/bin/zsh');
+ const expectedBinDir = expectedRuntimeBinDir();
+
+ yield* install();
+
+ const fs = yield* FileSystem.FileSystem;
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
+ })
+ );
+ });
+ });
+
+ describe('[When] COMPOSIO_BIN_DIR contains shell metacharacters', () => {
layer(TestLive())(it => {
it.scoped('[Then] aborts with an error', () =>
Effect.gen(function* () {
- process.env.SHELL = '/bin/zsh';
- process.env.COMPOSIO_INSTALL_DIR = '/tmp/x; curl evil.com';
+ vi.stubEnv('SHELL', '/bin/zsh');
+ vi.stubEnv('COMPOSIO_BIN_DIR', '/tmp/x; curl evil.com');
- yield* cli(['install']);
+ yield* install();
const lines = yield* MockConsole.getLines();
const output = lines.join('\n');
+ expect(output).toContain('Resolved bin directory');
expect(output).toContain('unsafe characters');
expect(output).toContain('Aborted');
})
);
});
});
+
+ describe('[When] COMPOSIO_BIN_DIR is relative', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] aborts instead of persisting a relative PATH entry', () =>
+ Effect.gen(function* () {
+ vi.stubEnv('SHELL', '/bin/zsh');
+ vi.stubEnv('COMPOSIO_BIN_DIR', './bin');
+
+ yield* install();
+
+ const output = (yield* MockConsole.getLines()).join('\n');
+ expect(output).toContain('must be an absolute path');
+ expect(output).toContain('Aborted');
+ })
+ );
+ });
+ });
+
+ describe('[When] COMPOSIO_BIN_DIR contains a PATH delimiter', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] aborts instead of persisting multiple PATH entries', () =>
+ Effect.gen(function* () {
+ vi.stubEnv('SHELL', '/bin/zsh');
+ vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin:/tmp/extra');
+
+ yield* install();
+
+ const output = (yield* MockConsole.getLines()).join('\n');
+ expect(output).toContain('Resolved bin directory');
+ expect(output).toContain('unsafe characters');
+ expect(output).toContain('Aborted');
+ })
+ );
+ });
+ });
+
+ describe('[When] the runtime executable resolves to an unsafe directory', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] reports an origin-neutral error', () =>
+ Effect.gen(function* () {
+ vi.stubEnv('SHELL', '/bin/zsh');
+
+ yield* install({ execPath: "/tmp/o'brien/composio" });
+
+ const output = (yield* MockConsole.getLines()).join('\n');
+ expect(output).toContain('Resolved bin directory');
+ expect(output).not.toContain('COMPOSIO_BIN_DIR contains');
+ expect(output).toContain('Aborted');
+ })
+ );
+ });
+ });
});