1
import * as fs from 'node:fs';
2
+import * as os from 'node:os';
3
+import * as path from 'node:path';
4
import { describe, expect, layer } from '@effect/vitest';
5
import { vi, beforeEach, afterEach } from 'vitest';
6
import { ConfigProvider, Effect, Option } from 'effect';
88
);
89
});
90
91
+ layer(
92
+ TestLive({
93
+ baseConfigProvider: testConfigProvider,
94
+ fixture: 'global-test-user-id',
95
+ toolkitsData: {
96
+ tools: [
97
+ {
98
+ name: 'Upload Slack File',
99
+ slug: 'SLACK_UPLOAD_OR_CREATE_A_FILE_IN_SLACK',
100
+ description: 'Uploads a file to Slack',
101
+ tags: ['slack'],
102
+ available_versions: ['20260316_00'],
103
+ input_parameters: {
104
+ type: 'object',
105
+ properties: {
106
+ channels: { type: 'string' },
107
+ file: {
108
+ type: 'object',
109
+ file_uploadable: true,
110
+ title: 'File',
111
+ description: 'Local file accepted by CLI',
112
+ properties: {
113
+ name: { type: 'string' },
114
+ mimetype: { type: 'string' },
115
+ s3key: { type: 'string' },
116
+ },
117
+ required: ['name', 'mimetype', 's3key'],
118
+ },
119
+ },
120
+ },
121
+ output_parameters: {
122
+ type: 'object',
123
+ properties: {},
124
+ },
125
+ },
126
+ ],
127
+ } satisfies TestLiveInput['toolkitsData'],
128
+ })
129
+ )('[Given] file_uploadable schema [Then] execute --get-schema shows a path string input', it => {
130
+ it.scoped('renders the CLI-facing schema instead of the raw FileUploadable object', () =>
131
+ Effect.gen(function* () {
132
+ yield* cli(['execute', 'SLACK_UPLOAD_OR_CREATE_A_FILE_IN_SLACK', '--get-schema']);
133
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
134
+ const output = parseLastJson(lines) as unknown as {
135
+ inputSchema: Record<string, unknown>;
136
+ };
137
+
138
+ expect(output.inputSchema).toEqual({
139
+ type: 'object',
140
+ properties: {
141
+ channels: { type: 'string' },
142
+ file: {
143
+ title: 'File',
144
+ description: 'Local file accepted by CLI',
145
+ format: 'path',
146
+ type: 'string',
147
+ file_uploadable: true,
148
+ },
149
+ },
150
+ });
151
+ })
152
+ );
153
+ });
154
+
155
layer(
156
TestLive({
157
baseConfigProvider: testConfigProvider,
652
);
653
});
654
655
+ layer(
656
+ TestLive({
657
+ baseConfigProvider: testConfigProvider,
658
+ fixture: 'global-test-user-id',
659
+ stdin: { isTTY: true, data: '' },
660
+ toolkitsData: {
661
+ tools: [
662
+ {
663
+ name: 'Send Email',
664
+ slug: 'GMAIL_SEND_EMAIL',
665
+ description: 'Send an email with attachment',
666
+ tags: ['email'],
667
+ available_versions: ['20260316_00'],
668
+ input_parameters: {
669
+ type: 'object',
670
+ properties: {
671
+ recipient_email: { type: 'string' },
672
+ attachment: {
673
+ file_uploadable: true,
674
+ title: 'Attachment',
675
+ description: 'Local path or URL to upload',
676
+ },
677
+ },
678
+ },
679
+ output_parameters: {
680
+ type: 'object',
681
+ properties: {
682
+ message_id: { type: 'string' },
683
+ },
684
+ },
685
+ },
686
+ ],
687
+ } satisfies TestLiveInput['toolkitsData'],
688
+ })
689
+ )(
690
+ '[Given] file_uploadable input as a local path [Then] execute uploads and sends s3key data',
691
+ it => {
692
+ it.scoped('uploads local file paths before Tool Router execution', () =>
693
+ Effect.gen(function* () {
694
+ const tempFile = path.join(os.tmpdir(), `composio-upload-${Date.now()}.txt`);
695
+ fs.writeFileSync(tempFile, 'hello from cli upload', 'utf8');
696
+
697
+ const originalFetch = globalThis.fetch;
698
+ const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation((input, init) => {
699
+ const url =
700
+ typeof input === 'string'
701
+ ? input
702
+ : input instanceof URL
703
+ ? input.toString()
704
+ : input.url;
705
+ if (url === 'https://s3.test.composio.dev/upload') {
706
+ return Promise.resolve(new Response(null, { status: 200 }));
707
+ }
708
+ return originalFetch(input, init);
709
+ });
710
+
711
+ yield* cli([
712
+ 'execute',
713
+ 'GMAIL_SEND_EMAIL',
714
+ '-d',
715
+ JSON.stringify({
716
+ recipient_email: 'a@b.com',
717
+ attachment: tempFile,
718
+ }),
719
+ ]);
720
+
721
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
722
+ const output = parseLastJson(lines);
723
+
724
+ expect(output.successful).toBe(true);
725
+ expect(output.data.arguments).toEqual({
726
+ recipient_email: 'a@b.com',
727
+ attachment: {
728
+ name: path.basename(tempFile),
729
+ mimetype: 'application/octet-stream',
730
+ s3key: `uploads/${path.basename(tempFile)}`,
731
+ },
732
+ });
733
+ expect(fetchSpy).toHaveBeenCalledWith(
734
+ 'https://s3.test.composio.dev/upload',
735
+ expect.objectContaining({
736
+ method: 'PUT',
737
+ headers: expect.objectContaining({
738
+ 'Content-Type': 'application/octet-stream',
739
+ }),
740
+ })
741
+ );
742
+
743
+ fs.rmSync(tempFile, { force: true });
744
+ })
745
+ );
746
+ }
747
+ );
748
+
749
+ layer(
750
+ TestLive({
751
+ baseConfigProvider: testConfigProvider,
752
+ fixture: 'global-test-user-id',
753
+ stdin: { isTTY: true, data: '' },
754
+ toolkitsData: {
755
+ tools: [
756
+ {
757
+ name: 'Upload Slack File',
758
+ slug: 'SLACK_UPLOAD_OR_CREATE_A_FILE_IN_SLACK',
759
+ description: 'Uploads a file to Slack',
760
+ tags: ['slack'],
761
+ available_versions: ['20260316_00'],
762
+ input_parameters: {
763
+ type: 'object',
764
+ properties: {
765
+ channels: { type: 'string' },
766
+ file: {
767
+ type: 'object',
768
+ file_uploadable: true,
769
+ title: 'File',
770
+ description: 'Local file accepted by CLI',
771
+ properties: {
772
+ name: { type: 'string' },
773
+ mimetype: { type: 'string' },
774
+ s3key: { type: 'string' },
775
+ },
776
+ required: ['name', 'mimetype', 's3key'],
777
+ },
778
+ },
779
+ },
780
+ output_parameters: {
781
+ type: 'object',
782
+ properties: {},
783
+ },
784
+ },
785
+ ],
786
+ } satisfies TestLiveInput['toolkitsData'],
787
+ })
788
+ )(
789
+ '[Given] --file for a tool with one file_uploadable input [Then] execute injects it automatically',
790
+ it => {
791
+ it.scoped('injects into the single file_uploadable field before upload hydration', () =>
792
+ Effect.gen(function* () {
793
+ const tempFile = path.join(os.tmpdir(), `composio-inject-${Date.now()}.png`);
794
+ fs.writeFileSync(tempFile, 'png-binary-ish', 'utf8');
795
+
796
+ const originalFetch = globalThis.fetch;
797
+ const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation((input, init) => {
798
+ const url =
799
+ typeof input === 'string'
800
+ ? input
801
+ : input instanceof URL
802
+ ? input.toString()
803
+ : input.url;
804
+ if (url === 'https://s3.test.composio.dev/upload') {
805
+ return Promise.resolve(new Response(null, { status: 200 }));
806
+ }
807
+ return originalFetch(input, init);
808
+ });
809
+
810
+ yield* cli([
811
+ 'execute',
812
+ 'SLACK_UPLOAD_OR_CREATE_A_FILE_IN_SLACK',
813
+ '--skip-connection-check',
814
+ '--file',
815
+ tempFile,
816
+ '-d',
817
+ JSON.stringify({ channels: 'C123' }),
818
+ ]);
819
+
820
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
821
+ const output = parseLastJson(lines);
822
+
823
+ expect(output.successful).toBe(true);
824
+ expect(output.data.arguments).toEqual({
825
+ channels: 'C123',
826
+ file: {
827
+ name: path.basename(tempFile),
828
+ mimetype: 'application/octet-stream',
829
+ s3key: `uploads/${path.basename(tempFile)}`,
830
+ },
831
+ });
832
+ expect(fetchSpy).toHaveBeenCalled();
833
+
834
+ fs.rmSync(tempFile, { force: true });
835
+ })
836
+ );
837
+ }
838
+ );
839
+
840
+ layer(
841
+ TestLive({
842
+ baseConfigProvider: testConfigProvider,
843
+ fixture: 'global-test-user-id',
844
+ stdin: { isTTY: true, data: '' },
845
+ toolkitsData: {
846
+ tools: [
847
+ {
848
+ name: 'Nested Upload',
849
+ slug: 'NESTED_UPLOAD_TOOL',
850
+ description: 'Uploads a nested file',
851
+ tags: ['test'],
852
+ available_versions: ['20260316_00'],
853
+ input_parameters: {
854
+ type: 'object',
855
+ properties: {
856
+ payload: {
857
+ properties: {
858
+ file: {
859
+ file_uploadable: true,
860
+ title: 'File',
861
+ description: 'Nested file path',
862
+ properties: {
863
+ name: { type: 'string' },
864
+ mimetype: { type: 'string' },
865
+ s3key: { type: 'string' },
866
+ },
867
+ },
868
+ },
869
+ },
870
+ },
871
+ },
872
+ output_parameters: {
873
+ type: 'object',
874
+ properties: {},
875
+ },
876
+ },
877
+ ],
878
+ } satisfies TestLiveInput['toolkitsData'],
879
+ })
880
+ )(
881
+ '[Given] a nested file_uploadable path under properties without explicit object type [Then] hydration still uploads it',
882
+ it => {
883
+ it.scoped('treats property-bearing schema nodes as object-like during upload hydration', () =>
884
+ Effect.gen(function* () {
885
+ const tempFile = path.join(os.tmpdir(), `composio-nested-${Date.now()}.png`);
886
+ fs.writeFileSync(tempFile, 'nested-png-binary-ish', 'utf8');
887
+
888
+ const originalFetch = globalThis.fetch;
889
+ vi.spyOn(globalThis, 'fetch').mockImplementation((input, init) => {
890
+ const url =
891
+ typeof input === 'string'
892
+ ? input
893
+ : input instanceof URL
894
+ ? input.toString()
895
+ : input.url;
896
+ if (url === 'https://s3.test.composio.dev/upload') {
897
+ return Promise.resolve(new Response(null, { status: 200 }));
898
+ }
899
+ return originalFetch(input, init);
900
+ });
901
+
902
+ yield* cli([
903
+ 'execute',
904
+ 'NESTED_UPLOAD_TOOL',
905
+ '--skip-connection-check',
906
+ '--file',
907
+ tempFile,
908
+ '-d',
909
+ JSON.stringify({ payload: {} }),
910
+ ]);
911
+
912
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
913
+ const output = parseLastJson(lines);
914
+
915
+ expect(output.successful).toBe(true);
916
+ expect(output.data.arguments).toEqual({
917
+ payload: {
918
+ file: {
919
+ name: path.basename(tempFile),
920
+ mimetype: 'application/octet-stream',
921
+ s3key: `uploads/${path.basename(tempFile)}`,
922
+ },
923
+ },
924
+ });
925
+
926
+ fs.rmSync(tempFile, { force: true });
927
+ })
928
+ );
929
+ }
930
+ );
931
+
932
+ layer(
933
+ TestLive({
934
+ baseConfigProvider: testConfigProvider,
935
+ fixture: 'global-test-user-id',
936
+ stdin: { isTTY: true, data: '' },
937
+ toolkitsData: {
938
+ tools: [
939
+ {
940
+ name: 'Send Email',
941
+ slug: 'GMAIL_SEND_EMAIL',
942
+ description: 'Send an email with attachment',
943
+ tags: ['email'],
944
+ available_versions: ['20260316_00'],
945
+ input_parameters: {
946
+ type: 'object',
947
+ properties: {
948
+ recipient_email: { type: 'string' },
949
+ attachment: {
950
+ file_uploadable: true,
951
+ title: 'Attachment',
952
+ description: 'Local path or URL to upload',
953
+ properties: {
954
+ name: { type: 'string' },
955
+ mimetype: { type: 'string' },
956
+ s3key: { type: 'string' },
957
+ },
958
+ },
959
+ },
960
+ },
961
+ output_parameters: {
962
+ type: 'object',
963
+ properties: {},
964
+ },
965
+ },
966
+ ],
967
+ } satisfies TestLiveInput['toolkitsData'],
968
+ })
969
+ )(
970
+ '[Given] an S3 upload failure [Then] execute surfaces the upload error instead of sending a raw path',
971
+ it => {
972
+ it.scoped('propagates upload failures from file hydration', () =>
973
+ Effect.gen(function* () {
974
+ const tempFile = path.join(os.tmpdir(), `composio-upload-fail-${Date.now()}.txt`);
975
+ fs.writeFileSync(tempFile, 'hello from failed cli upload', 'utf8');
976
+
977
+ const originalFetch = globalThis.fetch;
978
+ vi.spyOn(globalThis, 'fetch').mockImplementation((input, init) => {
979
+ const url =
980
+ typeof input === 'string'
981
+ ? input
982
+ : input instanceof URL
983
+ ? input.toString()
984
+ : input.url;
985
+ if (url === 'https://s3.test.composio.dev/upload') {
986
+ return Promise.resolve(
987
+ new Response('Upload failed', { status: 500, statusText: 'Upload Failed' })
988
+ );
989
+ }
990
+ return originalFetch(input, init);
991
+ });
992
+
993
+ const failure = yield* cli([
994
+ 'execute',
995
+ 'GMAIL_SEND_EMAIL',
996
+ '--skip-connection-check',
997
+ '-d',
998
+ JSON.stringify({
999
+ recipient_email: 'a@b.com',
1000
+ attachment: tempFile,
1001
+ }),
1002
+ ]).pipe(
1003
+ Effect.flip,
1004
+ Effect.map(error => (error instanceof Error ? error.message : String(error)))
1005
+ );
1006
+
1007
+ expect(failure).toContain('Failed to upload file to S3');
1008
+
1009
+ fs.rmSync(tempFile, { force: true });
1010
+ })
1011
+ );
1012
+ }
1013
+ );
1014
+
1015
+ layer(
1016
+ TestLive({
1017
+ baseConfigProvider: testConfigProvider,
1018
+ fixture: 'global-test-user-id',
1019
+ stdin: { isTTY: true, data: '' },
1020
+ toolkitsData: {
1021
+ tools: [
1022
+ {
1023
+ name: 'Send Email',
1024
+ slug: 'GMAIL_SEND_EMAIL',
1025
+ description: 'Send an email',
1026
+ tags: ['email'],
1027
+ available_versions: ['20260316_00'],
1028
+ input_parameters: {
1029
+ type: 'object',
1030
+ properties: {
1031
+ recipient_email: { type: 'string' },
1032
+ },
1033
+ },
1034
+ output_parameters: {
1035
+ type: 'object',
1036
+ properties: {},
1037
+ },
1038
+ },
1039
+ ],
1040
+ } satisfies TestLiveInput['toolkitsData'],
1041
+ })
1042
+ )('[Given] --file for a tool with no file_uploadable input [Then] execute fails clearly', it => {
1043
+ it.scoped('rejects the convenience flag when the schema has no file input', () =>
1044
+ Effect.gen(function* () {
1045
+ const failure = yield* cli([
1046
+ 'execute',
1047
+ 'GMAIL_SEND_EMAIL',
1048
+ '--file',
1049
+ '/tmp/example.txt',
1050
+ ]).pipe(
1051
+ Effect.flip,
1052
+ Effect.map(error => (error instanceof Error ? error.message : String(error)))
1053
+ );
1054
+
1055
+ expect(failure).toContain('has no file_uploadable input');
1056
+ })
1057
+ );
1058
+ });
1059
+
1060
+ layer(
1061
+ TestLive({
1062
+ baseConfigProvider: testConfigProvider,
1063
+ fixture: 'global-test-user-id',
1064
+ stdin: { isTTY: true, data: '' },
1065
+ toolkitsData: {
1066
+ tools: [
1067
+ {
1068
+ name: 'Multi Upload',
1069
+ slug: 'MULTI_UPLOAD_TOOL',
1070
+ description: 'Tool with two uploadable fields',
1071
+ tags: ['test'],
1072
+ available_versions: ['20260316_00'],
1073
+ input_parameters: {
1074
+ type: 'object',
1075
+ properties: {
1076
+ avatar: {
1077
+ type: 'object',
1078
+ file_uploadable: true,
1079
+ properties: {
1080
+ name: { type: 'string' },
1081
+ mimetype: { type: 'string' },
1082
+ s3key: { type: 'string' },
1083
+ },
1084
+ },
1085
+ resume: {
1086
+ type: 'object',
1087
+ file_uploadable: true,
1088
+ properties: {
1089
+ name: { type: 'string' },
1090
+ mimetype: { type: 'string' },
1091
+ s3key: { type: 'string' },
1092
+ },
1093
+ },
1094
+ },
1095
+ },
1096
+ output_parameters: {
1097
+ type: 'object',
1098
+ properties: {},
1099
+ },
1100
+ },
1101
+ ],
1102
+ } satisfies TestLiveInput['toolkitsData'],
1103
+ })
1104
+ )(
1105
+ '[Given] --file for a tool with multiple file_uploadable inputs [Then] execute asks for explicit JSON',
1106
+ it => {
1107
+ it.scoped('fails instead of guessing which file field to use', () =>
1108
+ Effect.gen(function* () {
1109
+ const failure = yield* cli([
1110
+ 'execute',
1111
+ 'MULTI_UPLOAD_TOOL',
1112
+ '--file',
1113
+ '/tmp/example.txt',
1114
+ ]).pipe(
1115
+ Effect.flip,
1116
+ Effect.map(error => (error instanceof Error ? error.message : String(error)))
1117
+ );
1118
+
1119
+ expect(failure).toContain('has multiple file_uploadable inputs');
1120
+ expect(failure).toContain('avatar');
1121
+ expect(failure).toContain('resume');
1122
+ })
1123
+ );
1124
+ }
1125
+ );
1126
+
1127
layer(
1128
TestLive({
1129
baseConfigProvider: testConfigProvider,
1425
1426
expect(output).toContain('USAGE');
1427
expect(output).toContain(
890
- 'composio execute <slug> [-d, --data text] [--dry-run] [--get-schema] [--parallel]'
1428
+ 'composio execute <slug> [-d, --data text] [--file path] [--dry-run] [--get-schema] [--parallel]'
1429
);
1430
expect(output).toContain('composio execute GMAIL_SEND_EMAIL --get-schema');
1431
expect(output).toContain('--parallel');