@devries-cameron20 / composio Mirror · read-only / commits / b4b700e04
Fork 0

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

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 17:15 UTC

refactor(cli): drop execPath test bypass, reuse resolved write targets

jkomyno committed Aug 1, 2026 at 17:45 UTC b4b700e04098d58f47ff9f609265ce2eb701810b
3 files changed +52 -47
ts/packages/cli/src/commands/install.cmd.ts
+4 -5
@@ -220,7 +220,6 @@ const resolveWriteTarget = (
220
221 export const installShellIntegration = (params: {
222 readonly completions: boolean;
223 - readonly execPath?: string;
223 readonly shell?: Shell;
224 }): Effect.Effect<
225 void,
@@ -250,8 +249,6 @@ export const installShellIntegration = (params: {
249
250 yield* ui.intro('composio install');
251
253 - // Resolve the entry-point bin dir: explicit env, then an existing
254 - // ~/.local/bin/composio, then the runtime executable's own directory.
252 const envBinDir = yield* readOptionalEnv('COMPOSIO_BIN_DIR');
253 const localBinDir = path.join(os.homedir, '.local', 'bin');
254 const localBinComposioExists = yield* fs.exists(path.join(localBinDir, 'composio'));
@@ -260,7 +257,7 @@ export const installShellIntegration = (params: {
257 envBinDir,
258 localBinDir,
259 localBinComposioExists,
263 - execPath: params.execPath ?? nodeProcess.execPath,
260 + execPath: nodeProcess.execPath,
261 path,
262 })
263 );
@@ -414,7 +411,9 @@ export const installShellIntegration = (params: {
411 // can alias the same physical file through symlinks, and this write must
412 // not discard a previous iteration's append.
413 const existingContents = yield* readMaybeMissingFile(filePath, fs);
417 - const writeTarget = yield* resolveWriteTarget(filePath, fs);
414 + // PATH files were already resolved above; only the completion file needs a fresh resolve.
415 + const writeTarget =
416 + pathFileTargets.get(filePath) ?? (yield* resolveWriteTarget(filePath, fs));
417 const existingTargetInfo = yield* fs.stat(writeTarget).pipe(Effect.option);
418
419 yield* fs
ts/packages/cli/test/__utils__/services/test-layer.ts
+7 -1
@@ -84,6 +84,12 @@ export interface TestLiveInput {
84 */
85 fixture?: string;
86
87 + /**
88 + * Override for the mocked `NodeProcess.execPath`.
89 + * Defaults to `<cwd>/composio`.
90 + */
91 + execPath?: string;
92 +
93 /**
94 * Mock toolkit-related data to use in test.
95 */
@@ -804,7 +810,7 @@ export const TestLayer = (input?: TestLiveInput) =>
810 NodeProcess,
811 new NodeProcess({
812 cwd,
807 - execPath: path.join(cwd, 'composio'),
813 + execPath: input?.execPath ?? path.join(cwd, 'composio'),
814 platform: 'darwin',
815 arch: 'arm64',
816 })
ts/packages/cli/test/src/commands/install.cmd.test.ts
+41 -41
@@ -35,16 +35,16 @@ const capturedStderrUI = makeTerminalUI({
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 InstallTestLive = (input: Parameters<typeof TestLive>[0] = {}) =>
39 + TestLive({ execPath: TEST_EXEC_PATH, ...input });
40 const install = (
41 params: {
42 readonly completions?: boolean;
41 - readonly execPath?: string;
43 readonly shell?: string;
44 } = {}
45 ) =>
46 installShellIntegration({
47 completions: params.completions ?? false,
47 - execPath: params.execPath ?? TEST_EXEC_PATH,
48 shell: params.shell as 'zsh' | 'bash' | 'fish' | undefined,
49 });
50
@@ -69,7 +69,7 @@ describe('CLI: composio install', () => {
69 });
70
71 describe('[When] shell is zsh', () => {
72 - layer(TestLive())(it => {
72 + layer(InstallTestLive())(it => {
73 it.scoped('[Then] creates .zshrc with PATH only by default', () =>
74 Effect.gen(function* () {
75 const os = yield* NodeOs;
@@ -121,7 +121,7 @@ describe('CLI: composio install', () => {
121 });
122
123 describe('[When] shell is bash', () => {
124 - layer(TestLive())(it => {
124 + layer(InstallTestLive())(it => {
125 it.scoped('[Then] creates .bashrc with PATH only by default', () =>
126 Effect.gen(function* () {
127 const os = yield* NodeOs;
@@ -144,7 +144,7 @@ describe('CLI: composio install', () => {
144 });
145
146 describe('[When] bash has neither .bash_profile nor .bash_login', () => {
147 - layer(TestLive())(it => {
147 + layer(InstallTestLive())(it => {
148 it.scoped('[Then] only .bashrc is created', () =>
149 Effect.gen(function* () {
150 const os = yield* NodeOs;
@@ -162,7 +162,7 @@ describe('CLI: composio install', () => {
162 });
163
164 describe('[When] bash has an existing .bash_profile', () => {
165 - layer(TestLive())(it => {
165 + layer(InstallTestLive())(it => {
166 it.scoped(
167 '[Then] the PATH block also lands in .bash_profile, and the restart hint mentions it',
168 () =>
@@ -193,7 +193,7 @@ describe('CLI: composio install', () => {
193 });
194
195 describe('[When] bash updates a private .bash_profile', () => {
196 - layer(TestLive())(it => {
196 + layer(InstallTestLive())(it => {
197 it.scoped('[Then] preserves its existing file mode', () =>
198 Effect.gen(function* () {
199 const os = yield* NodeOs;
@@ -214,7 +214,7 @@ describe('CLI: composio install', () => {
214 });
215
216 describe('[When] bash has only .bash_login (no .bash_profile)', () => {
217 - layer(TestLive())(it => {
217 + layer(InstallTestLive())(it => {
218 it.scoped('[Then] the PATH block also lands in .bash_login', () =>
219 Effect.gen(function* () {
220 const os = yield* NodeOs;
@@ -242,7 +242,7 @@ describe('CLI: composio install', () => {
242 });
243
244 describe('[When] bash has both .bash_profile and .bash_login', () => {
245 - layer(TestLive())(it => {
245 + layer(InstallTestLive())(it => {
246 it.scoped('[Then] only .bash_profile receives the login PATH block', () =>
247 Effect.gen(function* () {
248 const os = yield* NodeOs;
@@ -266,7 +266,7 @@ describe('CLI: composio install', () => {
266 });
267
268 describe('[When] .bash_profile is symlinked to the same file as .bashrc', () => {
269 - layer(TestLive())(it => {
269 + layer(InstallTestLive())(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;
@@ -292,7 +292,7 @@ describe('CLI: composio install', () => {
292 });
293
294 describe('[When] shell is fish', () => {
295 - layer(TestLive())(it => {
295 + layer(InstallTestLive())(it => {
296 it.scoped('[Then] creates config.fish with PATH only by default', () =>
297 Effect.gen(function* () {
298 const os = yield* NodeOs;
@@ -314,7 +314,7 @@ describe('CLI: composio install', () => {
314 });
315
316 describe('[When] --completions is passed', () => {
317 - layer(TestLive())(it => {
317 + layer(InstallTestLive())(it => {
318 it.scoped('[Then] writes PATH block and installs completions', () =>
319 Effect.gen(function* () {
320 const os = yield* NodeOs;
@@ -338,7 +338,7 @@ describe('CLI: composio install', () => {
338 });
339
340 describe('[When] fish shell installs completions', () => {
341 - layer(TestLive())(it => {
341 + layer(InstallTestLive())(it => {
342 it.scoped(
343 '[Then] keeps PATH setup in config.fish and writes completions to composio.fish',
344 () =>
@@ -378,7 +378,7 @@ describe('CLI: composio install', () => {
378 });
379
380 describe('[When] fish config and completions are symlinked to the same file', () => {
381 - layer(TestLive())(it => {
381 + layer(InstallTestLive())(it => {
382 it.scoped('[Then] keeps both PATH and completions blocks', () =>
383 Effect.gen(function* () {
384 const os = yield* NodeOs;
@@ -414,7 +414,7 @@ describe('CLI: composio install', () => {
414 });
415
416 describe('[When] fish shell installs completions twice', () => {
417 - layer(TestLive())(it => {
417 + layer(InstallTestLive())(it => {
418 it.scoped('[Then] keeps config.fish and composio.fish idempotent', () =>
419 Effect.gen(function* () {
420 const os = yield* NodeOs;
@@ -450,7 +450,7 @@ describe('CLI: composio install', () => {
450 });
451
452 describe('[When] --no-completions is passed', () => {
453 - layer(TestLive())(it => {
453 + layer(InstallTestLive())(it => {
454 it.scoped('[Then] writes PATH block but skips completions', () =>
455 Effect.gen(function* () {
456 const os = yield* NodeOs;
@@ -474,7 +474,7 @@ describe('CLI: composio install', () => {
474 });
475
476 describe('[When] install is run twice (idempotency)', () => {
477 - layer(TestLive())(it => {
477 + layer(InstallTestLive())(it => {
478 it.scoped('[Then] does not duplicate entries', () =>
479 Effect.gen(function* () {
480 const os = yield* NodeOs;
@@ -501,7 +501,7 @@ describe('CLI: composio install', () => {
501 });
502
503 describe('[When] .zshrc already has the marker', () => {
504 - layer(TestLive())(it => {
504 + layer(InstallTestLive())(it => {
505 it.scoped('[Then] reports already configured', () =>
506 Effect.gen(function* () {
507 const os = yield* NodeOs;
@@ -533,7 +533,7 @@ describe('CLI: composio install', () => {
533 });
534
535 describe('[When] shell cannot be detected', () => {
536 - layer(TestLive())(it => {
536 + layer(InstallTestLive())(it => {
537 it.scoped('[Then] shows manual setup instructions', () =>
538 Effect.gen(function* () {
539 vi.stubEnv('SHELL', '');
@@ -553,7 +553,7 @@ describe('CLI: composio install', () => {
553 });
554
555 describe('[When] shell cannot be detected but the bin dir is already on $PATH', () => {
556 - layer(TestLive())(it => {
556 + layer(InstallTestLive())(it => {
557 it.scoped('[Then] reports already on PATH instead of asking for manual setup', () =>
558 Effect.gen(function* () {
559 const os = yield* NodeOs;
@@ -578,7 +578,7 @@ describe('CLI: composio install', () => {
578 });
579
580 describe('[When] stderr is captured rather than a terminal', () => {
581 - layer(TestLive({ terminalUI: capturedStderrUI }))(it => {
581 + layer(InstallTestLive({ terminalUI: capturedStderrUI }))(it => {
582 it.scoped('[Then] still reports the rc file and how to reload the shell', () =>
583 Effect.gen(function* () {
584 vi.stubEnv('SHELL', '/bin/zsh');
@@ -609,7 +609,7 @@ describe('CLI: composio install', () => {
609 });
610
611 describe('[When] --shell zsh overrides a conflicting $SHELL', () => {
612 - layer(TestLive())(it => {
612 + layer(InstallTestLive())(it => {
613 it.scoped('[Then] writes ~/.zshrc, not ~/.bashrc', () =>
614 Effect.gen(function* () {
615 const os = yield* NodeOs;
@@ -626,7 +626,7 @@ describe('CLI: composio install', () => {
626 });
627
628 describe('[When] --shell is parsed by the public CLI', () => {
629 - layer(TestLive())(it => {
629 + layer(InstallTestLive())(it => {
630 it.scoped('[Then] a valid override reaches the requested shell integration', () =>
631 Effect.gen(function* () {
632 const os = yield* NodeOs;
@@ -643,7 +643,7 @@ describe('CLI: composio install', () => {
643 });
644
645 describe('[When] --shell has an unsupported value', () => {
646 - layer(TestLive())(it => {
646 + layer(InstallTestLive())(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);
@@ -654,7 +654,7 @@ describe('CLI: composio install', () => {
654 });
655
656 describe('[When] both completion flags are parsed by the public CLI', () => {
657 - layer(TestLive())(it => {
657 + layer(InstallTestLive())(it => {
658 it.scoped('[Then] --no-completions takes precedence', () =>
659 Effect.gen(function* () {
660 const os = yield* NodeOs;
@@ -672,7 +672,7 @@ describe('CLI: composio install', () => {
672 });
673
674 describe('[When] --shell bash overrides a conflicting $SHELL', () => {
675 - layer(TestLive())(it => {
675 + layer(InstallTestLive())(it => {
676 it.scoped('[Then] writes ~/.bashrc, not ~/.zshrc', () =>
677 Effect.gen(function* () {
678 const os = yield* NodeOs;
@@ -689,7 +689,7 @@ describe('CLI: composio install', () => {
689 });
690
691 describe('[When] --shell fish is passed with $SHELL unset', () => {
692 - layer(TestLive())(it => {
692 + layer(InstallTestLive())(it => {
693 it.scoped('[Then] writes config.fish', () =>
694 Effect.gen(function* () {
695 const os = yield* NodeOs;
@@ -706,7 +706,7 @@ describe('CLI: composio install', () => {
706 });
707
708 describe('[When] --shell is explicit and the bin dir is already on the invoking $PATH', () => {
709 - layer(TestLive())(it => {
709 + layer(InstallTestLive())(it => {
710 it.scoped('[Then] still writes the requested shell, and re-running stays idempotent', () =>
711 Effect.gen(function* () {
712 const os = yield* NodeOs;
@@ -727,7 +727,7 @@ describe('CLI: composio install', () => {
727 });
728
729 describe('[When] auto-detected shell has its bin dir already on $PATH', () => {
730 - layer(TestLive())(it => {
730 + layer(InstallTestLive())(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;
@@ -750,7 +750,7 @@ describe('CLI: composio install', () => {
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 => {
753 + layer(InstallTestLive())(it => {
754 it.scoped(
755 '[Then] the new .bash_profile still gets the PATH block, not skipped by the reachability check',
756 () =>
@@ -782,7 +782,7 @@ describe('CLI: composio install', () => {
782 });
783
784 describe('[When] COMPOSIO_BIN_DIR is set to a custom directory', () => {
785 - layer(TestLive())(it => {
785 + layer(InstallTestLive())(it => {
786 it.scoped('[Then] --shell zsh writes a PATH line for the custom directory', () =>
787 Effect.gen(function* () {
788 const os = yield* NodeOs;
@@ -801,7 +801,7 @@ describe('CLI: composio install', () => {
801 });
802
803 describe('[When] COMPOSIO_BIN_DIR is whitespace-only', () => {
804 - layer(TestLive())(it => {
804 + layer(InstallTestLive())(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;
@@ -820,7 +820,7 @@ describe('CLI: composio install', () => {
820 });
821
822 describe('[When] COMPOSIO_BIN_DIR has surrounding whitespace around a real value', () => {
823 - layer(TestLive())(it => {
823 + layer(InstallTestLive())(it => {
824 it.scoped('[Then] the surrounding whitespace is trimmed before it is used', () =>
825 Effect.gen(function* () {
826 const os = yield* NodeOs;
@@ -838,7 +838,7 @@ describe('CLI: composio install', () => {
838 });
839
840 describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin already has a composio entry point', () => {
841 - layer(TestLive())(it => {
841 + layer(InstallTestLive())(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;
@@ -860,7 +860,7 @@ describe('CLI: composio install', () => {
860 });
861
862 describe('[When] COMPOSIO_BIN_DIR is set and ~/.local/bin also already has a composio entry point', () => {
863 - layer(TestLive())(it => {
863 + layer(InstallTestLive())(it => {
864 it.scoped('[Then] the env var wins over the ~/.local/bin fallback', () =>
865 Effect.gen(function* () {
866 const os = yield* NodeOs;
@@ -883,7 +883,7 @@ describe('CLI: composio install', () => {
883 });
884
885 describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin has no composio entry point', () => {
886 - layer(TestLive())(it => {
886 + layer(InstallTestLive())(it => {
887 it.scoped('[Then] the PATH line targets the real binary directory', () =>
888 Effect.gen(function* () {
889 const os = yield* NodeOs;
@@ -901,7 +901,7 @@ describe('CLI: composio install', () => {
901 });
902
903 describe('[When] COMPOSIO_BIN_DIR contains shell metacharacters', () => {
904 - layer(TestLive())(it => {
904 + layer(InstallTestLive())(it => {
905 it.scoped('[Then] aborts with an error', () =>
906 Effect.gen(function* () {
907 vi.stubEnv('SHELL', '/bin/zsh');
@@ -920,7 +920,7 @@ describe('CLI: composio install', () => {
920 });
921
922 describe('[When] COMPOSIO_BIN_DIR is relative', () => {
923 - layer(TestLive())(it => {
923 + layer(InstallTestLive())(it => {
924 it.scoped('[Then] aborts instead of persisting a relative PATH entry', () =>
925 Effect.gen(function* () {
926 vi.stubEnv('SHELL', '/bin/zsh');
@@ -937,7 +937,7 @@ describe('CLI: composio install', () => {
937 });
938
939 describe('[When] COMPOSIO_BIN_DIR contains a PATH delimiter', () => {
940 - layer(TestLive())(it => {
940 + layer(InstallTestLive())(it => {
941 it.scoped('[Then] aborts instead of persisting multiple PATH entries', () =>
942 Effect.gen(function* () {
943 vi.stubEnv('SHELL', '/bin/zsh');
@@ -955,12 +955,12 @@ describe('CLI: composio install', () => {
955 });
956
957 describe('[When] the runtime executable resolves to an unsafe directory', () => {
958 - layer(TestLive())(it => {
958 + layer(InstallTestLive({ execPath: "/tmp/o'brien/composio" }))(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" });
963 + yield* install();
964
965 const output = (yield* MockConsole.getLines()).join('\n');
966 expect(output).toContain('Resolved bin directory');