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
jkomyno committed
Jul 31, 2026 at 18:54 UTC
40f6b8b54e919a6223ad8526c0bd31617b1d05b3
7 files changed
+834
-182
.github/workflows/cli.test-installation.yml
+12
-5
@@ -343,17 +343,17 @@ jobs:
343
config_file=~/.bashrc
344
fi
345
346
- if grep -q "COMPOSIO_INSTALL_DIR" "$config_file"; then
347
- echo "✅ $config_file updated with COMPOSIO_INSTALL_DIR"
346
+ if grep -Fqx '# Composio CLI' "$config_file"; then
347
+ echo "✅ $config_file updated with the Composio CLI marker"
348
else
349
- echo "❌ $config_file not updated with COMPOSIO_INSTALL_DIR"
349
+ echo "❌ $config_file not updated with the Composio CLI marker"
350
echo "=== $config_file contents ==="
351
cat "$config_file"
352
exit 1
353
fi
354
355
- if grep -q 'export PATH=.*COMPOSIO_INSTALL_DIR.*PATH' "$config_file"; then
356
- echo "✅ $config_file updated with PATH"
355
+ if grep -Fqx 'export PATH="$HOME/.composio:$PATH"' "$config_file"; then
356
+ echo "✅ $config_file updated with the installed binary directory"
357
else
358
echo "❌ $config_file PATH not updated"
359
echo "=== $config_file contents ==="
@@ -361,6 +361,13 @@ jobs:
361
exit 1
362
fi
363
364
+ if grep -q 'COMPOSIO_INSTALL_DIR' "$config_file"; then
365
+ echo "❌ $config_file still persists COMPOSIO_INSTALL_DIR"
366
+ echo "=== $config_file contents ==="
367
+ cat "$config_file"
368
+ exit 1
369
+ fi
370
+
371
- name: Test custom install directory
372
shell: bash
373
env:
ts/packages/cli/CHANGELOG.md
+4
@@ -2,6 +2,10 @@
2
3
## Unreleased
4
5
+### Minor Changes
6
+
7
+- `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`.
8
+
9
### Patch Changes
10
11
- Make GitHub release metadata the sole version authority for standalone CLI
ts/packages/cli/lint-boundaries.json
-12
@@ -42,18 +42,6 @@
42
"target": "process.env.COMPOSIO_RUN_ACP_ONLY = acpOnly ? '1' : '0';"
43
}
44
],
45
- "src/commands/install.cmd.ts": [
46
- {
47
- "rule": "eslint-js/no-restricted-syntax",
48
- "reason": "$SHELL is read inside a plain synchronous helper that mirrors install.sh's shell detection, outside any Effect context",
49
- "target": "const shellEnv = process.env.SHELL ?? '';"
50
- },
51
- {
52
- "rule": "eslint-js/no-restricted-syntax",
53
- "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",
54
- "target": "const installDir = process.env.COMPOSIO_INSTALL_DIR ?? path.join(os.homedir, '.composio');"
55
- }
56
- ],
45
"src/commands/run.cmd.ts": [
46
{
47
"rule": "eslint-js/no-restricted-syntax",
ts/packages/cli/src/commands/install.cmd.ts
+223
-74
@@ -1,10 +1,10 @@
1
-import process from 'node:process';
1
import { Command, Options } from '@effect/cli';
2
import { FileSystem, Path } from '@effect/platform';
3
import type { PlatformError } from '@effect/platform/Error';
5
-import { Array as Arr, Effect } from 'effect';
4
+import { Array as Arr, Config, ConfigProvider, Effect, Option } from 'effect';
5
import { ComposioCliUserConfig } from 'src/services/cli-user-config';
6
import { NodeOs } from 'src/services/node-os';
7
+import { NodeProcess } from 'src/services/node-process';
8
import { TerminalUI } from 'src/services/terminal-ui';
9
import { getCompletionScript } from 'src/effects/shell-completions';
10
@@ -22,15 +22,22 @@ const noCompletionsOpt = Options.boolean('no-completions').pipe(
22
Options.withDefault(false)
23
);
24
25
+const SHELLS = ['zsh', 'bash', 'fish'] as const;
26
+
27
+const shellOpt = Options.choice('shell', SHELLS).pipe(
28
+ Options.withDescription('Override automatic shell detection.'),
29
+ Options.optional
30
+);
31
+
32
// ---------------------------------------------------------------------------
33
// Types
34
// ---------------------------------------------------------------------------
35
29
-type Shell = 'bash' | 'zsh' | 'fish';
36
+type Shell = (typeof SHELLS)[number];
37
38
interface ShellConfig {
39
readonly shell: Shell;
33
- readonly pathFile: string;
40
+ readonly pathFiles: readonly string[];
41
readonly completionFile: string;
42
readonly pathBlock: string;
43
readonly completionBlock: string | undefined;
@@ -43,13 +50,30 @@ interface ShellConfig {
50
const MARKER = '# Composio CLI';
51
const COMPLETIONS_MARKER = '# Composio CLI completions';
52
46
-/** Reject install directory paths containing shell metacharacters to prevent injection into rc files. */
47
-const UNSAFE_PATH_CHARS = /[;`$|&"'()\n\r\\]/;
53
+/** Reject bin-dir paths containing shell metacharacters to prevent injection into rc files. */
54
+const UNSAFE_PATH_CHARS = /[:;`$|&"'()\n\r\\]/;
55
const isUnsafePath = (p: string): boolean => UNSAFE_PATH_CHARS.test(p);
56
50
-const detectShell = (path: Path.Path): Shell | undefined => {
51
- // 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
52
- const shellEnv = process.env.SHELL ?? '';
57
+// SHELL, PATH, and COMPOSIO_BIN_DIR are read from the literal environment: SHELL
58
+// and PATH are POSIX-standard (no app prefix applies to them), and COMPOSIO_BIN_DIR
59
+// is already the full env var name, not a suffix the app's `COMPOSIO_`-prefixing
60
+// ambient config provider should prefix again. Read them from a raw provider
61
+// instead (precedent: `src/analytics/dispatch.ts`'s `environmentProvider`).
62
+const environmentProvider = ConfigProvider.fromEnv();
63
+
64
+/** Read an optional env var from the raw environment; provider errors die rather than fail the command. */
65
+const readOptionalEnv = (name: string): Effect.Effect<string | undefined> =>
66
+ Effect.orDie(
67
+ environmentProvider.load(
68
+ Config.option(Config.string(name)).pipe(Config.map(Option.getOrUndefined))
69
+ )
70
+ );
71
+
72
+/** Read an env var from the raw environment, falling back when unset. */
73
+const readEnvWithDefault = (name: string, fallback: string): Effect.Effect<string> =>
74
+ Effect.orDie(environmentProvider.load(Config.string(name).pipe(Config.withDefault(fallback))));
75
+
76
+const detectShellFromEnv = (path: Path.Path, shellEnv: string): Shell | undefined => {
77
const base = path.basename(shellEnv);
78
if (base === 'zsh') return 'zsh';
79
if (base === 'bash') return 'bash';
@@ -57,69 +81,107 @@ const detectShell = (path: Path.Path): Shell | undefined => {
81
return undefined;
82
};
83
84
+const isDirOnPath = (pathEnv: string, dir: string): boolean =>
85
+ pathEnv.split(':').some(entry => entry === dir);
86
+
87
/**
61
- * Return candidate rc file paths for a shell, ordered by preference.
62
- * For bash this mirrors the install.sh fallback: .bashrc then .bash_profile.
88
+ * Bin-dir resolution order: explicit env, then `~/.local/bin` when it already
89
+ * holds a `composio` entry point, then the real binary's own directory.
90
*/
64
-const rcFileCandidates = (path: Path.Path, shell: Shell, homedir: string): string[] => {
65
- switch (shell) {
66
- case 'zsh':
67
- return [path.join(homedir, '.zshrc')];
68
- case 'bash':
69
- return [path.join(homedir, '.bashrc'), path.join(homedir, '.bash_profile')];
70
- case 'fish':
71
- return [path.join(homedir, '.config', 'fish', 'config.fish')];
91
+const resolveBinDir = (params: {
92
+ readonly envBinDir: string | undefined;
93
+ readonly localBinDir: string;
94
+ readonly localBinComposioExists: boolean;
95
+ readonly execPath: string;
96
+ readonly path: Path.Path;
97
+}): string => {
98
+ const trimmedEnvBinDir = params.envBinDir?.trim();
99
+ if (trimmedEnvBinDir && trimmedEnvBinDir.length > 0) {
100
+ return trimmedEnvBinDir;
101
}
102
+ if (params.localBinComposioExists) {
103
+ return params.localBinDir;
104
+ }
105
+ return params.path.dirname(params.execPath);
106
+};
107
+
108
+/**
109
+ * Render a path for embedding in a shell rc file. `~` never expands inside
110
+ * double quotes, so home-relative paths use a literal `$HOME` prefix instead.
111
+ */
112
+const renderWithHome = (dir: string, homedir: string): string =>
113
+ dir === homedir
114
+ ? '$HOME'
115
+ : dir.startsWith(`${homedir}/`)
116
+ ? `$HOME/${dir.slice(homedir.length + 1)}`
117
+ : dir;
118
+
119
+const pathBlockForShell = (shell: Shell, binDir: string, homedir: string): string => {
120
+ const rendered = renderWithHome(binDir, homedir);
121
+ return shell === 'fish'
122
+ ? [MARKER, `set --export PATH "${rendered}" $PATH`].join('\n')
123
+ : [MARKER, `export PATH="${rendered}:$PATH"`].join('\n');
124
};
125
126
+/** Bash startup-file candidates that only bash's login mode reads, in read order. */
127
+const bashLoginOverrideCandidates = (path: Path.Path, homedir: string): string[] => [
128
+ path.join(homedir, '.bash_profile'),
129
+ path.join(homedir, '.bash_login'),
130
+];
131
+
132
/**
76
- * Pick the first existing candidate, or fall back to the first candidate
77
- * (which will be created).
133
+ * First existing bash login-override file, if any. `bash -ilc` reads only the
134
+ * first of `.bash_profile`, `.bash_login`, `.profile` that exists — so an
135
+ * existing override shadows `.profile` and common `.profile` files source
136
+ * `.bashrc`, unless the PATH line also lands in the override. `.profile` is
137
+ * deliberately not a candidate below: when neither override exists, bash reads
138
+ * `.profile` itself, and common `.profile` files already source `.bashrc`, so
139
+ * nothing needs to be written to it.
140
*/
79
-const resolveRcFile = (
80
- candidates: string[],
141
+const resolveBashLoginOverride = (
142
+ candidates: readonly string[],
143
fs: FileSystem.FileSystem
82
-): Effect.Effect<string, PlatformError> =>
144
+): Effect.Effect<string | undefined, PlatformError> =>
145
Effect.gen(function* () {
146
for (const candidate of candidates) {
85
- const exists = yield* fs.exists(candidate);
86
- if (exists) return candidate;
147
+ if (yield* fs.exists(candidate)) return candidate;
148
}
88
- return candidates[0]!;
149
+ return undefined;
150
});
151
91
-const pathBlockForShell = (shell: Shell, installDir: string): string => {
152
+const pathFilesForShell = (
153
+ path: Path.Path,
154
+ shell: Shell,
155
+ homedir: string,
156
+ bashLoginOverride: string | undefined
157
+): string[] => {
158
switch (shell) {
159
+ case 'zsh':
160
+ return [path.join(homedir, '.zshrc')];
161
case 'fish':
94
- return [
95
- MARKER,
96
- `set --export COMPOSIO_INSTALL_DIR "${installDir}"`,
97
- `set --export PATH $COMPOSIO_INSTALL_DIR $PATH`,
98
- ].join('\n');
99
- default:
100
- return [
101
- MARKER,
102
- `export COMPOSIO_INSTALL_DIR="${installDir}"`,
103
- `export PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
104
- ].join('\n');
162
+ return [path.join(homedir, '.config', 'fish', 'config.fish')];
163
+ case 'bash': {
164
+ const bashrc = path.join(homedir, '.bashrc');
165
+ return bashLoginOverride ? [bashrc, bashLoginOverride] : [bashrc];
166
+ }
167
}
168
};
169
170
const buildShellConfig = (
171
path: Path.Path,
172
shell: Shell,
111
- rcFile: string,
112
- installDir: string,
173
+ pathFiles: readonly string[],
174
+ binDir: string,
175
completionScript: string | undefined,
176
homedir: string
177
): ShellConfig => ({
178
shell,
117
- pathFile: rcFile,
179
+ pathFiles,
180
completionFile:
181
shell === 'fish'
182
? path.join(homedir, '.config', 'fish', 'completions', 'composio.fish')
121
- : rcFile,
122
- pathBlock: pathBlockForShell(shell, installDir),
183
+ : pathFiles[0]!,
184
+ pathBlock: pathBlockForShell(shell, binDir, homedir),
185
completionBlock: completionScript ? `${COMPLETIONS_MARKER}\n${completionScript}` : undefined,
186
});
187
@@ -158,14 +220,17 @@ const resolveWriteTarget = (
220
221
export const installShellIntegration = (params: {
222
readonly completions: boolean;
223
+ readonly execPath?: string;
224
+ readonly shell?: Shell;
225
}): Effect.Effect<
226
void,
227
PlatformError,
164
- TerminalUI | NodeOs | FileSystem.FileSystem | Path.Path | ComposioCliUserConfig
228
+ TerminalUI | NodeOs | NodeProcess | FileSystem.FileSystem | Path.Path | ComposioCliUserConfig
229
> =>
230
Effect.gen(function* () {
231
const ui = yield* TerminalUI;
232
const os = yield* NodeOs;
233
+ const nodeProcess = yield* NodeProcess;
234
const fs = yield* FileSystem.FileSystem;
235
const path = yield* Path.Path;
236
@@ -185,26 +250,50 @@ export const installShellIntegration = (params: {
250
251
yield* ui.intro('composio install');
252
188
- // Detect install directory — either from env or default ~/.composio
189
- // 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
190
- const installDir = process.env.COMPOSIO_INSTALL_DIR ?? path.join(os.homedir, '.composio');
253
+ // Resolve the entry-point bin dir: explicit env, then an existing
254
+ // ~/.local/bin/composio, then the runtime executable's own directory.
255
+ const envBinDir = yield* readOptionalEnv('COMPOSIO_BIN_DIR');
256
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
257
+ const localBinComposioExists = yield* fs.exists(path.join(localBinDir, 'composio'));
258
+ const binDir = path.normalize(
259
+ resolveBinDir({
260
+ envBinDir,
261
+ localBinDir,
262
+ localBinComposioExists,
263
+ execPath: params.execPath ?? nodeProcess.execPath,
264
+ path,
265
+ })
266
+ );
267
192
- if (isUnsafePath(installDir)) {
268
+ if (!path.isAbsolute(binDir)) {
269
+ yield* failure('Resolved bin directory must be an absolute path.');
270
+ yield* ui.outro('Aborted.');
271
+ return;
272
+ }
273
+
274
+ if (isUnsafePath(binDir)) {
275
yield* failure(
194
- 'COMPOSIO_INSTALL_DIR contains unsafe characters and cannot be written to shell config.'
276
+ 'Resolved bin directory contains unsafe characters and cannot be written to shell config.'
277
);
278
yield* ui.outro('Aborted.');
279
return;
280
}
281
200
- // Detect user shell
201
- const shell = detectShell(path);
282
+ const isExplicitShell = params.shell !== undefined;
283
+ const shellEnv = yield* readEnvWithDefault('SHELL', '');
284
+ const shell = params.shell ?? detectShellFromEnv(path, shellEnv);
285
+
286
+ const pathEnv = yield* readEnvWithDefault('PATH', '');
287
+ const binDirOnPath = isDirOnPath(pathEnv, binDir);
288
+
289
if (!shell) {
290
+ if (binDirOnPath) {
291
+ yield* success(`PATH: ${tildify(binDir, os.homedir)} is already on $PATH — nothing to do.`);
292
+ yield* ui.outro('Done');
293
+ return;
294
+ }
295
yield* warn('Could not detect your shell. Manually add the following to your shell config:');
204
- yield* note(
205
- `export COMPOSIO_INSTALL_DIR="${installDir}"\nexport PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
206
- 'PATH setup'
207
- );
296
+ yield* note(`export PATH="${renderWithHome(binDir, os.homedir)}:$PATH"`, 'PATH setup');
297
yield* ui.outro('Manual setup required.');
298
return;
299
}
@@ -229,15 +318,28 @@ export const installShellIntegration = (params: {
318
completionScript = lines.length > 0 ? Arr.join(lines, '\n') : undefined;
319
}
320
232
- const rcFile = yield* resolveRcFile(rcFileCandidates(path, shell, os.homedir), fs);
233
- const config = buildShellConfig(path, shell, rcFile, installDir, completionScript, os.homedir);
321
+ const bashLoginOverride =
322
+ shell === 'bash'
323
+ ? yield* resolveBashLoginOverride(bashLoginOverrideCandidates(path, os.homedir), fs)
324
+ : undefined;
325
+ const pathFiles = pathFilesForShell(path, shell, os.homedir, bashLoginOverride);
326
+ const config = buildShellConfig(path, shell, pathFiles, binDir, completionScript, os.homedir);
327
235
- const uniqueTargetFiles = [...new Set([config.pathFile, config.completionFile])];
328
+ const uniqueTargetFiles = [...new Set([...config.pathFiles, config.completionFile])];
329
const existingByFile = new Map<string, string>();
330
for (const filePath of uniqueTargetFiles) {
331
existingByFile.set(filePath, yield* readMaybeMissingFile(filePath, fs));
332
}
333
334
+ // Resolve each configured PATH file's real write target up front so two
335
+ // logical paths that alias the same physical file (a dotfiles setup
336
+ // symlinking .bash_profile -> .bashrc) get the PATH block appended once,
337
+ // not once per alias.
338
+ const pathFileTargets = new Map<string, string>();
339
+ for (const filePath of config.pathFiles) {
340
+ pathFileTargets.set(filePath, yield* resolveWriteTarget(filePath, fs));
341
+ }
342
+
343
const blocksByFile = new Map<string, Array<string>>();
344
const pushBlock = (filePath: string, block: string) => {
345
const blocks = blocksByFile.get(filePath);
@@ -248,10 +350,40 @@ export const installShellIntegration = (params: {
350
}
351
};
352
251
- const existingPathFile = existingByFile.get(config.pathFile) ?? '';
252
- if (!fileContains(existingPathFile, MARKER)) {
253
- pushBlock(config.pathFile, config.pathBlock);
254
- yield* step(`PATH: will add ${tildify(installDir, os.homedir)} to $PATH`);
353
+ // Auto-detected mode may skip the PATH write entirely when the bin dir is
354
+ // already reachable; an explicit --shell always configures its files.
355
+ // Only applies to a genuinely fresh install: if any target file already
356
+ // carries our marker from a prior run, a file that appeared since then
357
+ // (e.g. a freshly created .bash_profile) still needs its own write, even
358
+ // though the invoking process's current $PATH already resolves.
359
+ const anyPathFileAlreadyMarked = config.pathFiles.some(filePath =>
360
+ fileContains(existingByFile.get(filePath) ?? '', MARKER)
361
+ );
362
+ const skipPathWriteForReachability =
363
+ !isExplicitShell && binDirOnPath && !anyPathFileAlreadyMarked;
364
+ let pathWritten = false;
365
+ let loginOverrideWritten = false;
366
+ const queuedPathTargets = new Set<string>();
367
+ for (const filePath of config.pathFiles) {
368
+ const existing = existingByFile.get(filePath) ?? '';
369
+ const target = pathFileTargets.get(filePath)!;
370
+ if (
371
+ fileContains(existing, MARKER) ||
372
+ skipPathWriteForReachability ||
373
+ queuedPathTargets.has(target)
374
+ ) {
375
+ continue;
376
+ }
377
+ pushBlock(filePath, config.pathBlock);
378
+ queuedPathTargets.add(target);
379
+ pathWritten = true;
380
+ if (filePath === bashLoginOverride) loginOverrideWritten = true;
381
+ }
382
+
383
+ if (pathWritten) {
384
+ yield* step(`PATH: will add ${tildify(binDir, os.homedir)} to $PATH`);
385
+ } else if (skipPathWriteForReachability) {
386
+ yield* step('PATH: already on $PATH — nothing to do.');
387
} else {
388
yield* step('PATH: already configured');
389
}
@@ -283,6 +415,7 @@ export const installShellIntegration = (params: {
415
// not discard a previous iteration's append.
416
const existingContents = yield* readMaybeMissingFile(filePath, fs);
417
const writeTarget = yield* resolveWriteTarget(filePath, fs);
418
+ const existingTargetInfo = yield* fs.stat(writeTarget).pipe(Effect.option);
419
420
yield* fs
421
.makeDirectory(path.dirname(writeTarget), { recursive: true })
@@ -296,6 +429,9 @@ export const installShellIntegration = (params: {
429
const tmpPath = `${writeTarget}.composio-tmp`;
430
431
yield* fs.writeFileString(tmpPath, existingContents + appendContent);
432
+ if (Option.isSome(existingTargetInfo)) {
433
+ yield* fs.chmod(tmpPath, existingTargetInfo.value.mode & 0o7777);
434
+ }
435
yield* fs.rename(tmpPath, writeTarget);
436
437
yield* success(`Updated ${tildify(filePath, os.homedir)}`);
@@ -305,14 +441,23 @@ export const installShellIntegration = (params: {
441
}
442
443
if (blocksByFile.size > 0) {
308
- yield* note(
309
- shell === 'fish'
310
- ? 'exec fish'
311
- : shell === 'zsh'
312
- ? `source ${tildify(rcFile, os.homedir)}`
313
- : 'exec $SHELL',
314
- 'Restart your shell to apply changes'
315
- );
444
+ if (shell === 'fish') {
445
+ yield* note('exec fish', 'Restart your shell to apply changes');
446
+ } else if (shell === 'zsh') {
447
+ yield* note(
448
+ `source ${tildify(config.pathFiles[0]!, os.homedir)}`,
449
+ 'Restart your shell to apply changes'
450
+ );
451
+ } else {
452
+ const bashrc = path.join(os.homedir, '.bashrc');
453
+ const hintLines = [`source ${tildify(bashrc, os.homedir)}`];
454
+ if (loginOverrideWritten && bashLoginOverride) {
455
+ hintLines.push(
456
+ `${tildify(bashLoginOverride, os.homedir)} was also updated — that entry applies to new login shells too.`
457
+ );
458
+ }
459
+ yield* note(hintLines.join('\n'), 'Restart your shell to apply changes');
460
+ }
461
}
462
463
yield* ui.outro('Done');
@@ -330,11 +475,15 @@ export const installShellIntegration = (params: {
475
* composio install
476
* composio install --completions
477
* composio install --no-completions
478
+ * composio install --shell zsh
479
* ```
480
*/
481
export const installCmd = Command.make(
482
'install',
337
- { completions: completionsOpt, noCompletions: noCompletionsOpt },
338
- ({ completions, noCompletions }) =>
339
- installShellIntegration({ completions: completions && !noCompletions })
483
+ { completions: completionsOpt, noCompletions: noCompletionsOpt, shell: shellOpt },
484
+ ({ completions, noCompletions, shell }) =>
485
+ installShellIntegration({
486
+ completions: completions && !noCompletions,
487
+ shell: Option.getOrUndefined(shell),
488
+ })
489
).pipe(Command.withDescription('Set up shell integration (PATH and completions).'));
ts/packages/cli/src/services/node-process.ts
+1
@@ -5,6 +5,7 @@ import { Effect } from 'effect';
5
export class NodeProcess extends Effect.Service<NodeProcess>()('services/NodeProcess', {
6
sync: () => ({
7
cwd: process.cwd(),
8
+ execPath: process.execPath,
9
platform: process.platform,
10
arch: process.arch,
11
}),
ts/packages/cli/test/__utils__/services/test-layer.ts
+2
@@ -1,3 +1,4 @@
1
+import path from 'node:path';
2
import * as tempy from 'tempy';
3
import { CliApp, CliConfig } from '@effect/cli';
4
import { Command, FetchHttpClient, FileSystem, Path } from '@effect/platform';
@@ -803,6 +804,7 @@ export const TestLayer = (input?: TestLiveInput) =>
804
NodeProcess,
805
new NodeProcess({
806
cwd,
807
+ execPath: path.join(cwd, 'composio'),
808
platform: 'darwin',
809
arch: 'arm64',
810
})
ts/packages/cli/test/src/commands/install.cmd.test.ts
+592
-91
@@ -1,11 +1,11 @@
1
import path from 'node:path';
2
-import process from 'node:process';
2
import { Writable } from 'node:stream';
4
-import { beforeEach, afterEach } from 'vitest';
3
+import { beforeEach, vi } from 'vitest';
4
import { describe, expect, layer } from '@effect/vitest';
6
-import { Effect } from 'effect';
5
+import { Effect, Exit } from 'effect';
6
import { FileSystem } from '@effect/platform';
7
import { NodeOs } from 'src/services/node-os';
8
+import { installShellIntegration } from 'src/commands/install.cmd';
9
import { makeTerminalUI } from 'src/services/terminal-ui';
10
import { cli, TestLive, MockConsole } from 'test/__utils__';
11
@@ -28,47 +28,63 @@ const capturedStderrUI = makeTerminalUI({
28
stderr: capturedStderr,
29
});
30
31
-describe('CLI: composio install', () => {
32
- let savedShell: string | undefined;
33
- let savedInstallDir: string | undefined;
31
+// A PATH that never contains a test's resolved bin dir. The default fallback
32
+// bin dir (no COMPOSIO_BIN_DIR, no ~/.local/bin/composio) is `dirname(TEST_EXEC_PATH)`,
33
+// which is frequently already on the host's real PATH (a Node/Bun/mise shim
34
+// dir) — exactly what tests must not depend on, so this always overrides it.
35
+const SAFE_PATH = '/usr/bin:/bin';
36
+const TEST_EXEC_PATH = '/usr/local/bin/composio';
37
+const expectedRuntimeBinDir = (): string => path.dirname(TEST_EXEC_PATH);
38
+const install = (
39
+ params: {
40
+ readonly completions?: boolean;
41
+ readonly execPath?: string;
42
+ readonly shell?: string;
43
+ } = {}
44
+) =>
45
+ installShellIntegration({
46
+ completions: params.completions ?? false,
47
+ execPath: params.execPath ?? TEST_EXEC_PATH,
48
+ shell: params.shell as 'zsh' | 'bash' | 'fish' | undefined,
49
+ });
50
+
51
+// NOTE: `@effect/vitest`'s `layer(...)` builds one shared TestLive instance
52
+// (home dir, MockConsole buffer, etc.) for every `it.scoped` nested inside a
53
+// single call. Sharing is only safe when a later test doesn't read state a
54
+// prior test mutated (MockConsole output, rc files under the shared home
55
+// dir) — so each independent scenario below gets its own `layer(...)` call,
56
+// mirroring the file's existing single-test blocks. The two-test blocks that
57
+// remain (zsh's symlink test, the stderr-capture pair) are safe because the
58
+// second test never reads `MockConsole` and resets any file state it cares
59
+// about itself.
60
61
+describe('CLI: composio install', () => {
62
beforeEach(() => {
36
- savedShell = process.env.SHELL;
37
- savedInstallDir = process.env.COMPOSIO_INSTALL_DIR;
63
+ // vitest.config.ts sets `unstubEnvs: true`, so every `vi.stubEnv` call
64
+ // below is automatically reverted after each test — no manual save/restore.
65
+ vi.stubEnv('PATH', SAFE_PATH);
66
+ vi.stubEnv('COMPOSIO_BIN_DIR', '');
67
capturedStdout.chunks.length = 0;
68
capturedStderr.chunks.length = 0;
69
});
70
42
- afterEach(() => {
43
- if (savedShell !== undefined) {
44
- process.env.SHELL = savedShell;
45
- } else {
46
- delete process.env.SHELL;
47
- }
48
- if (savedInstallDir !== undefined) {
49
- process.env.COMPOSIO_INSTALL_DIR = savedInstallDir;
50
- } else {
51
- delete process.env.COMPOSIO_INSTALL_DIR;
52
- }
53
- });
54
-
71
describe('[When] shell is zsh', () => {
72
layer(TestLive())(it => {
73
it.scoped('[Then] creates .zshrc with PATH only by default', () =>
74
Effect.gen(function* () {
75
const os = yield* NodeOs;
60
- process.env.SHELL = '/bin/zsh';
61
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
76
+ vi.stubEnv('SHELL', '/bin/zsh');
77
+ const expectedBinDir = expectedRuntimeBinDir();
78
63
- yield* cli(['install']);
79
+ yield* install();
80
81
const fs = yield* FileSystem.FileSystem;
82
const rcPath = path.join(os.homedir, '.zshrc');
83
const contents = yield* fs.readFileString(rcPath);
84
85
expect(contents).toContain('# Composio CLI');
70
- expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
71
- expect(contents).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
86
+ expect(contents).not.toContain('COMPOSIO_INSTALL_DIR');
87
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
88
expect(contents).not.toContain('# Composio CLI completions');
89
90
const lines = yield* MockConsole.getLines();
@@ -85,8 +101,7 @@ describe('CLI: composio install', () => {
101
Effect.gen(function* () {
102
const os = yield* NodeOs;
103
const fs = yield* FileSystem.FileSystem;
88
- process.env.SHELL = '/bin/zsh';
89
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
104
+ vi.stubEnv('SHELL', '/bin/zsh');
105
106
const rcPath = path.join(os.homedir, '.zshrc');
107
const managedPath = path.join(os.homedir, '.managed-zshrc');
@@ -95,7 +110,7 @@ describe('CLI: composio install', () => {
110
yield* fs.writeFileString(managedPath, '# managed shell config\n');
111
yield* fs.symlink(linkTarget, rcPath);
112
98
- yield* cli(['install']);
113
+ yield* install();
114
115
expect(yield* fs.readLink(rcPath)).toBe(linkTarget);
116
expect(yield* fs.readFileString(managedPath)).toContain('# Composio CLI');
@@ -110,41 +125,188 @@ describe('CLI: composio install', () => {
125
it.scoped('[Then] creates .bashrc with PATH only by default', () =>
126
Effect.gen(function* () {
127
const os = yield* NodeOs;
113
- process.env.SHELL = '/bin/bash';
114
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
128
+ vi.stubEnv('SHELL', '/bin/bash');
129
+ const expectedBinDir = expectedRuntimeBinDir();
130
116
- yield* cli(['install']);
131
+ yield* install();
132
133
const fs = yield* FileSystem.FileSystem;
134
const rcPath = path.join(os.homedir, '.bashrc');
135
const contents = yield* fs.readFileString(rcPath);
136
137
expect(contents).toContain('# Composio CLI');
123
- expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
124
- expect(contents).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
138
+ expect(contents).not.toContain('COMPOSIO_INSTALL_DIR');
139
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
140
expect(contents).not.toContain('# Composio CLI completions');
141
})
142
);
143
});
144
});
145
146
+ describe('[When] bash has neither .bash_profile nor .bash_login', () => {
147
+ layer(TestLive())(it => {
148
+ it.scoped('[Then] only .bashrc is created', () =>
149
+ Effect.gen(function* () {
150
+ const os = yield* NodeOs;
151
+ vi.stubEnv('SHELL', '/bin/bash');
152
+
153
+ yield* install();
154
+
155
+ const fs = yield* FileSystem.FileSystem;
156
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(true);
157
+ expect(yield* fs.exists(path.join(os.homedir, '.bash_profile'))).toBe(false);
158
+ expect(yield* fs.exists(path.join(os.homedir, '.bash_login'))).toBe(false);
159
+ })
160
+ );
161
+ });
162
+ });
163
+
164
+ describe('[When] bash has an existing .bash_profile', () => {
165
+ layer(TestLive())(it => {
166
+ it.scoped(
167
+ '[Then] the PATH block also lands in .bash_profile, and the restart hint mentions it',
168
+ () =>
169
+ Effect.gen(function* () {
170
+ const os = yield* NodeOs;
171
+ const fs = yield* FileSystem.FileSystem;
172
+ vi.stubEnv('SHELL', '/bin/bash');
173
+
174
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
175
+ yield* fs.writeFileString(bashProfilePath, '# existing login config\n');
176
+
177
+ yield* install();
178
+
179
+ const bashrcContents = yield* fs.readFileString(path.join(os.homedir, '.bashrc'));
180
+ const bashProfileContents = yield* fs.readFileString(bashProfilePath);
181
+ expect(bashrcContents).toContain('# Composio CLI');
182
+ expect(bashProfileContents).toContain('# Composio CLI');
183
+
184
+ const lines = yield* MockConsole.getLines();
185
+ const output = lines.join('\n');
186
+ expect(output).toContain('source ~/.bashrc');
187
+ expect(output).toContain('~/.bash_profile');
188
+ expect(output).toContain('login shell');
189
+ expect(output).not.toContain('exec $SHELL');
190
+ })
191
+ );
192
+ });
193
+ });
194
+
195
+ describe('[When] bash updates a private .bash_profile', () => {
196
+ layer(TestLive())(it => {
197
+ it.scoped('[Then] preserves its existing file mode', () =>
198
+ Effect.gen(function* () {
199
+ const os = yield* NodeOs;
200
+ const fs = yield* FileSystem.FileSystem;
201
+ vi.stubEnv('SHELL', '/bin/bash');
202
+
203
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
204
+ yield* fs.writeFileString(bashProfilePath, '# private login config\n');
205
+ yield* fs.chmod(bashProfilePath, 0o600);
206
+
207
+ yield* install();
208
+
209
+ const info = yield* fs.stat(bashProfilePath);
210
+ expect(info.mode & 0o777).toBe(0o600);
211
+ })
212
+ );
213
+ });
214
+ });
215
+
216
+ describe('[When] bash has only .bash_login (no .bash_profile)', () => {
217
+ layer(TestLive())(it => {
218
+ it.scoped('[Then] the PATH block also lands in .bash_login', () =>
219
+ Effect.gen(function* () {
220
+ const os = yield* NodeOs;
221
+ const fs = yield* FileSystem.FileSystem;
222
+ vi.stubEnv('SHELL', '/bin/bash');
223
+
224
+ const bashLoginPath = path.join(os.homedir, '.bash_login');
225
+ yield* fs.writeFileString(bashLoginPath, '# existing login config\n');
226
+
227
+ yield* install();
228
+
229
+ const bashrcContents = yield* fs.readFileString(path.join(os.homedir, '.bashrc'));
230
+ const bashLoginContents = yield* fs.readFileString(bashLoginPath);
231
+ expect(bashrcContents).toContain('# Composio CLI');
232
+ expect(bashLoginContents).toContain('# Composio CLI');
233
+
234
+ const lines = yield* MockConsole.getLines();
235
+ const output = lines.join('\n');
236
+ expect(output).toContain('source ~/.bashrc');
237
+ expect(output).toContain('~/.bash_login');
238
+ expect(output).toContain('login shell');
239
+ })
240
+ );
241
+ });
242
+ });
243
+
244
+ describe('[When] bash has both .bash_profile and .bash_login', () => {
245
+ layer(TestLive())(it => {
246
+ it.scoped('[Then] only .bash_profile receives the login PATH block', () =>
247
+ Effect.gen(function* () {
248
+ const os = yield* NodeOs;
249
+ const fs = yield* FileSystem.FileSystem;
250
+ vi.stubEnv('SHELL', '/bin/bash');
251
+
252
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
253
+ const bashLoginPath = path.join(os.homedir, '.bash_login');
254
+ yield* fs.writeFileString(bashProfilePath, '# existing profile\n');
255
+ yield* fs.writeFileString(bashLoginPath, '# existing login\n');
256
+
257
+ yield* install();
258
+
259
+ const bashProfileContents = yield* fs.readFileString(bashProfilePath);
260
+ const bashLoginContents = yield* fs.readFileString(bashLoginPath);
261
+ expect(bashProfileContents).toContain('# Composio CLI');
262
+ expect(bashLoginContents).not.toContain('# Composio CLI');
263
+ })
264
+ );
265
+ });
266
+ });
267
+
268
+ describe('[When] .bash_profile is symlinked to the same file as .bashrc', () => {
269
+ layer(TestLive())(it => {
270
+ it.scoped('[Then] the PATH block is written exactly once, not once per alias', () =>
271
+ Effect.gen(function* () {
272
+ const os = yield* NodeOs;
273
+ const fs = yield* FileSystem.FileSystem;
274
+ vi.stubEnv('SHELL', '/bin/bash');
275
+
276
+ const bashrcPath = path.join(os.homedir, '.bashrc');
277
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
278
+ const managedPath = path.join(os.homedir, '.managed-bashrc');
279
+ yield* fs.remove(bashrcPath, { force: true });
280
+ yield* fs.writeFileString(managedPath, '# managed shell config\n');
281
+ yield* fs.symlink(managedPath, bashrcPath);
282
+ yield* fs.symlink(managedPath, bashProfilePath);
283
+
284
+ yield* install();
285
+
286
+ const contents = yield* fs.readFileString(managedPath);
287
+ const pathMarkerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
288
+ expect(pathMarkerCount).toBe(1);
289
+ })
290
+ );
291
+ });
292
+ });
293
+
294
describe('[When] shell is fish', () => {
295
layer(TestLive())(it => {
296
it.scoped('[Then] creates config.fish with PATH only by default', () =>
297
Effect.gen(function* () {
298
const os = yield* NodeOs;
136
- process.env.SHELL = '/usr/bin/fish';
137
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
299
+ vi.stubEnv('SHELL', '/usr/bin/fish');
300
139
- yield* cli(['install']);
301
+ yield* install();
302
303
const fs = yield* FileSystem.FileSystem;
304
const rcPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
305
const contents = yield* fs.readFileString(rcPath);
306
307
expect(contents).toContain('# Composio CLI');
146
- expect(contents).toContain('set --export COMPOSIO_INSTALL_DIR');
147
- expect(contents).toContain('set --export PATH $COMPOSIO_INSTALL_DIR $PATH');
308
+ expect(contents).not.toContain('COMPOSIO_INSTALL_DIR');
309
+ expect(contents).toContain('set --export PATH');
310
expect(contents).not.toContain('# Composio CLI completions');
311
})
312
);
@@ -156,17 +318,15 @@ describe('CLI: composio install', () => {
318
it.scoped('[Then] writes PATH block and installs completions', () =>
319
Effect.gen(function* () {
320
const os = yield* NodeOs;
159
- process.env.SHELL = '/bin/bash';
160
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
321
+ vi.stubEnv('SHELL', '/bin/bash');
322
162
- yield* cli(['install', '--completions']);
323
+ yield* install({ completions: true });
324
325
const fs = yield* FileSystem.FileSystem;
326
const rcPath = path.join(os.homedir, '.bashrc');
327
const contents = yield* fs.readFileString(rcPath);
328
329
expect(contents).toContain('# Composio CLI');
169
- expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
330
expect(contents).toContain('# Composio CLI completions');
331
332
const lines = yield* MockConsole.getLines();
@@ -184,10 +344,9 @@ describe('CLI: composio install', () => {
344
() =>
345
Effect.gen(function* () {
346
const os = yield* NodeOs;
187
- process.env.SHELL = '/usr/bin/fish';
188
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
347
+ vi.stubEnv('SHELL', '/usr/bin/fish');
348
190
- yield* cli(['install', '--completions']);
349
+ yield* install({ completions: true });
350
351
const fs = yield* FileSystem.FileSystem;
352
const configPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
@@ -202,7 +361,7 @@ describe('CLI: composio install', () => {
361
const completionContents = yield* fs.readFileString(completionPath);
362
363
expect(configContents).toContain('# Composio CLI');
205
- expect(configContents).toContain('set --export COMPOSIO_INSTALL_DIR');
364
+ expect(configContents).toContain('set --export PATH');
365
expect(configContents).not.toContain('# Composio CLI completions');
366
367
expect(completionContents).toContain('# Composio CLI completions');
@@ -224,8 +383,7 @@ describe('CLI: composio install', () => {
383
Effect.gen(function* () {
384
const os = yield* NodeOs;
385
const fs = yield* FileSystem.FileSystem;
227
- process.env.SHELL = '/usr/bin/fish';
228
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
386
+ vi.stubEnv('SHELL', '/usr/bin/fish');
387
388
const configPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
389
const completionPath = path.join(
@@ -242,7 +400,7 @@ describe('CLI: composio install', () => {
400
yield* fs.symlink(managedPath, configPath);
401
yield* fs.symlink(managedPath, completionPath);
402
245
- yield* cli(['install', '--completions']);
403
+ yield* install({ completions: true });
404
405
const contents = yield* fs.readFileString(managedPath);
406
const pathMarkerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
@@ -260,11 +418,10 @@ describe('CLI: composio install', () => {
418
it.scoped('[Then] keeps config.fish and composio.fish idempotent', () =>
419
Effect.gen(function* () {
420
const os = yield* NodeOs;
263
- process.env.SHELL = '/usr/bin/fish';
264
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
421
+ vi.stubEnv('SHELL', '/usr/bin/fish');
422
266
- yield* cli(['install', '--completions']);
267
- yield* cli(['install', '--completions']);
423
+ yield* install({ completions: true });
424
+ yield* install({ completions: true });
425
426
const fs = yield* FileSystem.FileSystem;
427
const configPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
@@ -297,17 +454,15 @@ describe('CLI: composio install', () => {
454
it.scoped('[Then] writes PATH block but skips completions', () =>
455
Effect.gen(function* () {
456
const os = yield* NodeOs;
300
- process.env.SHELL = '/bin/zsh';
301
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
457
+ vi.stubEnv('SHELL', '/bin/zsh');
458
303
- yield* cli(['install', '--no-completions']);
459
+ yield* install();
460
461
const fs = yield* FileSystem.FileSystem;
462
const rcPath = path.join(os.homedir, '.zshrc');
463
const contents = yield* fs.readFileString(rcPath);
464
465
expect(contents).toContain('# Composio CLI');
310
- expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
466
expect(contents).not.toContain('# Composio CLI completions');
467
468
const lines = yield* MockConsole.getLines();
@@ -323,12 +478,11 @@ describe('CLI: composio install', () => {
478
it.scoped('[Then] does not duplicate entries', () =>
479
Effect.gen(function* () {
480
const os = yield* NodeOs;
326
- process.env.SHELL = '/bin/bash';
327
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
481
+ vi.stubEnv('SHELL', '/bin/bash');
482
483
// Run install twice
330
- yield* cli(['install', '--completions']);
331
- yield* cli(['install', '--completions']);
484
+ yield* install({ completions: true });
485
+ yield* install({ completions: true });
486
487
const fs = yield* FileSystem.FileSystem;
488
const rcPath = path.join(os.homedir, '.bashrc');
@@ -352,17 +506,16 @@ describe('CLI: composio install', () => {
506
Effect.gen(function* () {
507
const os = yield* NodeOs;
508
const fs = yield* FileSystem.FileSystem;
355
- process.env.SHELL = '/bin/zsh';
356
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
509
+ vi.stubEnv('SHELL', '/bin/zsh');
510
511
// Pre-populate .zshrc with existing config
512
const rcPath = path.join(os.homedir, '.zshrc');
513
yield* fs.writeFileString(
514
rcPath,
362
- '# existing config\n# Composio CLI\nexport COMPOSIO_INSTALL_DIR=/old\n# Composio CLI completions\n_composio() {}\n'
515
+ '# existing config\n# Composio CLI\nexport PATH="$HOME/.local/bin:$PATH"\n# Composio CLI completions\n_composio() {}\n'
516
);
517
365
- yield* cli(['install', '--completions']);
518
+ yield* install({ completions: true });
519
520
const lines = yield* MockConsole.getLines();
521
const output = lines.join('\n');
@@ -383,29 +536,54 @@ describe('CLI: composio install', () => {
536
layer(TestLive())(it => {
537
it.scoped('[Then] shows manual setup instructions', () =>
538
Effect.gen(function* () {
386
- process.env.SHELL = '';
539
+ vi.stubEnv('SHELL', '');
540
+ const expectedBinDir = expectedRuntimeBinDir();
541
388
- yield* cli(['install']);
542
+ yield* install();
543
544
const lines = yield* MockConsole.getLines();
545
const output = lines.join('\n');
546
expect(output).toContain('Could not detect your shell');
393
- expect(output).toContain('export COMPOSIO_INSTALL_DIR=');
547
+ expect(output).toContain(`export PATH="${expectedBinDir}:$PATH"`);
548
+ expect(output).not.toContain('COMPOSIO_INSTALL_DIR');
549
expect(output).toContain('Manual setup required.');
550
})
551
);
552
});
553
});
554
555
+ describe('[When] shell cannot be detected but the bin dir is already on $PATH', () => {
556
+ layer(TestLive())(it => {
557
+ it.scoped('[Then] reports already on PATH instead of asking for manual setup', () =>
558
+ Effect.gen(function* () {
559
+ const os = yield* NodeOs;
560
+ vi.stubEnv('SHELL', '');
561
+ const binDir = expectedRuntimeBinDir();
562
+ vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
563
+
564
+ yield* install();
565
+
566
+ const lines = yield* MockConsole.getLines();
567
+ const output = lines.join('\n');
568
+ expect(output).toContain('already on $PATH');
569
+ expect(output).toContain('Done');
570
+ expect(output).not.toContain('Could not detect your shell');
571
+
572
+ const fs = yield* FileSystem.FileSystem;
573
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(false);
574
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(false);
575
+ })
576
+ );
577
+ });
578
+ });
579
+
580
describe('[When] stderr is captured rather than a terminal', () => {
581
layer(TestLive({ terminalUI: capturedStderrUI }))(it => {
582
it.scoped('[Then] still reports the rc file and how to reload the shell', () =>
583
Effect.gen(function* () {
404
- const os = yield* NodeOs;
405
- process.env.SHELL = '/bin/zsh';
406
- process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
584
+ vi.stubEnv('SHELL', '/bin/zsh');
585
408
- yield* cli(['install']);
586
+ yield* install();
587
588
const output = capturedStderr.chunks.join('');
589
expect(output).toContain('PATH: will add');
@@ -417,56 +595,379 @@ describe('CLI: composio install', () => {
595
596
it.scoped('[Then] still shows manual setup instructions for an unknown shell', () =>
597
Effect.gen(function* () {
420
- process.env.SHELL = '';
598
+ vi.stubEnv('SHELL', '');
599
+ const expectedBinDir = expectedRuntimeBinDir();
600
422
- yield* cli(['install']);
601
+ yield* install();
602
603
const output = capturedStderr.chunks.join('');
604
expect(output).toContain('Could not detect your shell');
426
- expect(output).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
605
+ expect(output).toContain(`export PATH="${expectedBinDir}:$PATH"`);
606
})
607
);
608
});
609
});
610
432
- describe('[When] COMPOSIO_INSTALL_DIR is not set', () => {
611
+ describe('[When] --shell zsh overrides a conflicting $SHELL', () => {
612
layer(TestLive())(it => {
434
- it.scoped('[Then] defaults to ~/.composio', () =>
613
+ it.scoped('[Then] writes ~/.zshrc, not ~/.bashrc', () =>
614
Effect.gen(function* () {
615
const os = yield* NodeOs;
437
- process.env.SHELL = '/bin/zsh';
438
- delete process.env.COMPOSIO_INSTALL_DIR;
616
+ vi.stubEnv('SHELL', '/bin/bash');
617
440
- yield* cli(['install']);
618
+ yield* install({ shell: 'zsh' });
619
620
const fs = yield* FileSystem.FileSystem;
443
- const rcPath = path.join(os.homedir, '.zshrc');
444
- const contents = yield* fs.readFileString(rcPath);
621
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(true);
622
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(false);
623
+ })
624
+ );
625
+ });
626
+ });
627
446
- // Should use ~/.composio as the default install directory (quoted)
447
- expect(contents).toContain(
448
- `export COMPOSIO_INSTALL_DIR="${path.join(os.homedir, '.composio')}"`
449
- );
628
+ describe('[When] --shell is parsed by the public CLI', () => {
629
+ layer(TestLive())(it => {
630
+ it.scoped('[Then] a valid override reaches the requested shell integration', () =>
631
+ Effect.gen(function* () {
632
+ const os = yield* NodeOs;
633
+ const fs = yield* FileSystem.FileSystem;
634
+ vi.stubEnv('SHELL', '/bin/bash');
635
+
636
+ yield* cli(['install', '--shell', 'zsh']);
637
+
638
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(true);
639
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(false);
640
})
641
);
642
});
643
});
644
455
- describe('[When] COMPOSIO_INSTALL_DIR contains shell metacharacters', () => {
645
+ describe('[When] --shell has an unsupported value', () => {
646
+ layer(TestLive())(it => {
647
+ it.scoped('[Then] the public CLI rejects it during option parsing', () =>
648
+ Effect.gen(function* () {
649
+ const exit = yield* cli(['install', '--shell', 'powershell']).pipe(Effect.exit);
650
+ expect(Exit.isFailure(exit)).toBe(true);
651
+ })
652
+ );
653
+ });
654
+ });
655
+
656
+ describe('[When] both completion flags are parsed by the public CLI', () => {
657
+ layer(TestLive())(it => {
658
+ it.scoped('[Then] --no-completions takes precedence', () =>
659
+ Effect.gen(function* () {
660
+ const os = yield* NodeOs;
661
+ const fs = yield* FileSystem.FileSystem;
662
+ vi.stubEnv('SHELL', '/bin/bash');
663
+
664
+ yield* cli(['install', '--completions', '--no-completions']);
665
+
666
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.bashrc'));
667
+ expect(contents).toContain('# Composio CLI');
668
+ expect(contents).not.toContain('# Composio CLI completions');
669
+ })
670
+ );
671
+ });
672
+ });
673
+
674
+ describe('[When] --shell bash overrides a conflicting $SHELL', () => {
675
+ layer(TestLive())(it => {
676
+ it.scoped('[Then] writes ~/.bashrc, not ~/.zshrc', () =>
677
+ Effect.gen(function* () {
678
+ const os = yield* NodeOs;
679
+ vi.stubEnv('SHELL', '/bin/zsh');
680
+
681
+ yield* install({ shell: 'bash' });
682
+
683
+ const fs = yield* FileSystem.FileSystem;
684
+ expect(yield* fs.exists(path.join(os.homedir, '.bashrc'))).toBe(true);
685
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(false);
686
+ })
687
+ );
688
+ });
689
+ });
690
+
691
+ describe('[When] --shell fish is passed with $SHELL unset', () => {
692
+ layer(TestLive())(it => {
693
+ it.scoped('[Then] writes config.fish', () =>
694
+ Effect.gen(function* () {
695
+ const os = yield* NodeOs;
696
+ vi.stubEnv('SHELL', '');
697
+
698
+ yield* install({ shell: 'fish' });
699
+
700
+ const fs = yield* FileSystem.FileSystem;
701
+ const rcPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
702
+ expect(yield* fs.exists(rcPath)).toBe(true);
703
+ })
704
+ );
705
+ });
706
+ });
707
+
708
+ describe('[When] --shell is explicit and the bin dir is already on the invoking $PATH', () => {
709
+ layer(TestLive())(it => {
710
+ it.scoped('[Then] still writes the requested shell, and re-running stays idempotent', () =>
711
+ Effect.gen(function* () {
712
+ const os = yield* NodeOs;
713
+ vi.stubEnv('SHELL', '/bin/bash');
714
+ const binDir = expectedRuntimeBinDir();
715
+ vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
716
+
717
+ yield* install({ shell: 'zsh' });
718
+ yield* install({ shell: 'zsh' });
719
+
720
+ const fs = yield* FileSystem.FileSystem;
721
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
722
+ const markerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
723
+ expect(markerCount).toBe(1);
724
+ })
725
+ );
726
+ });
727
+ });
728
+
729
+ describe('[When] auto-detected shell has its bin dir already on $PATH', () => {
730
+ layer(TestLive())(it => {
731
+ it.scoped('[Then] writes nothing and reports already on PATH, with no restart hint', () =>
732
+ Effect.gen(function* () {
733
+ const os = yield* NodeOs;
734
+ vi.stubEnv('SHELL', '/bin/zsh');
735
+ const binDir = expectedRuntimeBinDir();
736
+ vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
737
+
738
+ yield* install();
739
+
740
+ const fs = yield* FileSystem.FileSystem;
741
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(false);
742
+
743
+ const lines = yield* MockConsole.getLines();
744
+ const output = lines.join('\n');
745
+ expect(output).toContain('already on $PATH');
746
+ expect(output).not.toContain('Restart your shell');
747
+ })
748
+ );
749
+ });
750
+ });
751
+
752
+ describe('[When] a new .bash_profile appears after .bashrc was already configured, and the bin dir is already on $PATH', () => {
753
+ layer(TestLive())(it => {
754
+ it.scoped(
755
+ '[Then] the new .bash_profile still gets the PATH block, not skipped by the reachability check',
756
+ () =>
757
+ Effect.gen(function* () {
758
+ const os = yield* NodeOs;
759
+ const fs = yield* FileSystem.FileSystem;
760
+ vi.stubEnv('SHELL', '/bin/bash');
761
+ const binDir = expectedRuntimeBinDir();
762
+ vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
763
+
764
+ // Simulate a prior `composio install` run that already configured .bashrc.
765
+ const bashrcPath = path.join(os.homedir, '.bashrc');
766
+ yield* fs.writeFileString(
767
+ bashrcPath,
768
+ `# Composio CLI\nexport PATH="${binDir}:$PATH"\n`
769
+ );
770
+
771
+ // .bash_profile shows up afterward and was never configured.
772
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
773
+ yield* fs.writeFileString(bashProfilePath, '# existing login config\n');
774
+
775
+ yield* install();
776
+
777
+ const bashProfileContents = yield* fs.readFileString(bashProfilePath);
778
+ expect(bashProfileContents).toContain('# Composio CLI');
779
+ })
780
+ );
781
+ });
782
+ });
783
+
784
+ describe('[When] COMPOSIO_BIN_DIR is set to a custom directory', () => {
785
+ layer(TestLive())(it => {
786
+ it.scoped('[Then] --shell zsh writes a PATH line for the custom directory', () =>
787
+ Effect.gen(function* () {
788
+ const os = yield* NodeOs;
789
+ vi.stubEnv('SHELL', '/bin/bash');
790
+ vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin');
791
+
792
+ yield* install({ shell: 'zsh' });
793
+
794
+ const fs = yield* FileSystem.FileSystem;
795
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
796
+ expect(contents).toContain('export PATH="/custom/bin:$PATH"');
797
+ expect(contents).not.toContain('$HOME');
798
+ })
799
+ );
800
+ });
801
+ });
802
+
803
+ describe('[When] COMPOSIO_BIN_DIR is whitespace-only', () => {
804
+ layer(TestLive())(it => {
805
+ it.scoped('[Then] it is treated as unset, not as a literal bin dir', () =>
806
+ Effect.gen(function* () {
807
+ const os = yield* NodeOs;
808
+ vi.stubEnv('SHELL', '/bin/zsh');
809
+ vi.stubEnv('COMPOSIO_BIN_DIR', ' ');
810
+ const expectedBinDir = expectedRuntimeBinDir();
811
+
812
+ yield* install();
813
+
814
+ const fs = yield* FileSystem.FileSystem;
815
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
816
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
817
+ })
818
+ );
819
+ });
820
+ });
821
+
822
+ describe('[When] COMPOSIO_BIN_DIR has surrounding whitespace around a real value', () => {
823
+ layer(TestLive())(it => {
824
+ it.scoped('[Then] the surrounding whitespace is trimmed before it is used', () =>
825
+ Effect.gen(function* () {
826
+ const os = yield* NodeOs;
827
+ vi.stubEnv('SHELL', '/bin/zsh');
828
+ vi.stubEnv('COMPOSIO_BIN_DIR', ' /custom/bin ');
829
+
830
+ yield* install();
831
+
832
+ const fs = yield* FileSystem.FileSystem;
833
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
834
+ expect(contents).toContain('export PATH="/custom/bin:$PATH"');
835
+ })
836
+ );
837
+ });
838
+ });
839
+
840
+ describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin already has a composio entry point', () => {
841
+ layer(TestLive())(it => {
842
+ it.scoped('[Then] the PATH line targets ~/.local/bin via a literal $HOME prefix', () =>
843
+ Effect.gen(function* () {
844
+ const os = yield* NodeOs;
845
+ const fs = yield* FileSystem.FileSystem;
846
+ vi.stubEnv('SHELL', '/bin/zsh');
847
+
848
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
849
+ yield* fs.makeDirectory(localBinDir, { recursive: true });
850
+ yield* fs.writeFileString(path.join(localBinDir, 'composio'), '');
851
+
852
+ yield* install();
853
+
854
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
855
+ expect(contents).toContain('export PATH="$HOME/.local/bin:$PATH"');
856
+ expect(contents).not.toContain('~/.local/bin');
857
+ })
858
+ );
859
+ });
860
+ });
861
+
862
+ describe('[When] COMPOSIO_BIN_DIR is set and ~/.local/bin also already has a composio entry point', () => {
863
+ layer(TestLive())(it => {
864
+ it.scoped('[Then] the env var wins over the ~/.local/bin fallback', () =>
865
+ Effect.gen(function* () {
866
+ const os = yield* NodeOs;
867
+ const fs = yield* FileSystem.FileSystem;
868
+ vi.stubEnv('SHELL', '/bin/zsh');
869
+ vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin');
870
+
871
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
872
+ yield* fs.makeDirectory(localBinDir, { recursive: true });
873
+ yield* fs.writeFileString(path.join(localBinDir, 'composio'), '');
874
+
875
+ yield* install();
876
+
877
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
878
+ expect(contents).toContain('export PATH="/custom/bin:$PATH"');
879
+ expect(contents).not.toContain('.local/bin');
880
+ })
881
+ );
882
+ });
883
+ });
884
+
885
+ describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin has no composio entry point', () => {
886
+ layer(TestLive())(it => {
887
+ it.scoped('[Then] the PATH line targets the real binary directory', () =>
888
+ Effect.gen(function* () {
889
+ const os = yield* NodeOs;
890
+ vi.stubEnv('SHELL', '/bin/zsh');
891
+ const expectedBinDir = expectedRuntimeBinDir();
892
+
893
+ yield* install();
894
+
895
+ const fs = yield* FileSystem.FileSystem;
896
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
897
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
898
+ })
899
+ );
900
+ });
901
+ });
902
+
903
+ describe('[When] COMPOSIO_BIN_DIR contains shell metacharacters', () => {
904
layer(TestLive())(it => {
905
it.scoped('[Then] aborts with an error', () =>
906
Effect.gen(function* () {
459
- process.env.SHELL = '/bin/zsh';
460
- process.env.COMPOSIO_INSTALL_DIR = '/tmp/x; curl evil.com';
907
+ vi.stubEnv('SHELL', '/bin/zsh');
908
+ vi.stubEnv('COMPOSIO_BIN_DIR', '/tmp/x; curl evil.com');
909
462
- yield* cli(['install']);
910
+ yield* install();
911
912
const lines = yield* MockConsole.getLines();
913
const output = lines.join('\n');
914
+ expect(output).toContain('Resolved bin directory');
915
expect(output).toContain('unsafe characters');
916
expect(output).toContain('Aborted');
917
})
918
);
919
});
920
});
921
+
922
+ describe('[When] COMPOSIO_BIN_DIR is relative', () => {
923
+ layer(TestLive())(it => {
924
+ it.scoped('[Then] aborts instead of persisting a relative PATH entry', () =>
925
+ Effect.gen(function* () {
926
+ vi.stubEnv('SHELL', '/bin/zsh');
927
+ vi.stubEnv('COMPOSIO_BIN_DIR', './bin');
928
+
929
+ yield* install();
930
+
931
+ const output = (yield* MockConsole.getLines()).join('\n');
932
+ expect(output).toContain('must be an absolute path');
933
+ expect(output).toContain('Aborted');
934
+ })
935
+ );
936
+ });
937
+ });
938
+
939
+ describe('[When] COMPOSIO_BIN_DIR contains a PATH delimiter', () => {
940
+ layer(TestLive())(it => {
941
+ it.scoped('[Then] aborts instead of persisting multiple PATH entries', () =>
942
+ Effect.gen(function* () {
943
+ vi.stubEnv('SHELL', '/bin/zsh');
944
+ vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin:/tmp/extra');
945
+
946
+ yield* install();
947
+
948
+ const output = (yield* MockConsole.getLines()).join('\n');
949
+ expect(output).toContain('Resolved bin directory');
950
+ expect(output).toContain('unsafe characters');
951
+ expect(output).toContain('Aborted');
952
+ })
953
+ );
954
+ });
955
+ });
956
+
957
+ describe('[When] the runtime executable resolves to an unsafe directory', () => {
958
+ layer(TestLive())(it => {
959
+ it.scoped('[Then] reports an origin-neutral error', () =>
960
+ Effect.gen(function* () {
961
+ vi.stubEnv('SHELL', '/bin/zsh');
962
+
963
+ yield* install({ execPath: "/tmp/o'brien/composio" });
964
+
965
+ const output = (yield* MockConsole.getLines()).join('\n');
966
+ expect(output).toContain('Resolved bin directory');
967
+ expect(output).not.toContain('COMPOSIO_BIN_DIR contains');
968
+ expect(output).toContain('Aborted');
969
+ })
970
+ );
971
+ });
972
+ });
973
});