Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
test(core): stub file upload client boundary (#4227)
Alberto Schiabel committed
Aug 24, 2026 at 13:42 UTC
38ed791982cd2f33b1eb68ccd10bb323071cb85a
1 file changed
+6
-20
ts/packages/core/test/tools/fileUploadMatrix.test.ts
+6
-20
@@ -34,9 +34,6 @@ vi.mock('../../src/utils/fileUtils.node', async importOriginal => {
34
return {
35
...actual,
36
downloadFileFromS3: vi.fn(),
37
- // Keep the real `getFileDataAfterUploadingToS3` so path checks run, but
38
- // stub the S3 upload happening inside it.
39
- uploadFileToS3: vi.fn(),
37
};
38
});
39
@@ -184,16 +181,11 @@ describe('File handling matrix — manual Files API bypasses the allowlist', ()
181
});
182
183
describe('File handling matrix — auto upload honors the resolved allowlist', () => {
187
- let getFileDataSpy: ReturnType<typeof vi.spyOn>;
184
+ const createPresignedURLSpy = vi.spyOn(mockClient.files, 'createPresignedURL');
185
186
beforeEach(() => {
187
vi.clearAllMocks();
191
- // Keep the real implementation so allowlist enforcement runs, but stub the
192
- // S3 upload that happens inside it.
193
- getFileDataSpy = vi.spyOn(fileUtilsModule, 'uploadFileToS3' as never);
194
- (getFileDataSpy as unknown as { mockResolvedValue: (v: string) => void }).mockResolvedValue(
195
- 's3-key'
196
- );
188
+ createPresignedURLSpy.mockRejectedValue(new Error('stubbed-presigned-url-request'));
189
});
190
191
const callUpload = async (file: string, fileUploadAllowlist: string[] | undefined) => {
@@ -260,20 +252,14 @@ describe('File handling matrix — auto upload honors the resolved allowlist', (
252
});
253
254
it('does NOT throw an allowlist error when the file is inside an allowed dir', async () => {
263
- // We can't easily stub the S3 upload from outside the module, so we just
264
- // assert the error (if any) is not the allowlist rejection. The happy
265
- // path for `assertPathInsideUploadDirs` itself is covered directly in
266
- // `test/utils/uploadDirAllowlist.test.ts`.
255
const allowed = mkTemp();
256
try {
257
const file = path.join(allowed, 'ok.txt');
258
writeFileSync(file, 'x');
271
- try {
272
- await callUpload(file, [allowed]);
273
- } catch (err) {
274
- expect(err).not.toBeInstanceOf(ComposioFileUploadPathNotAllowedError);
275
- expect(err).not.toBeInstanceOf(ComposioFileNotFoundError);
276
- }
259
+ await expect(callUpload(file, [allowed])).rejects.toThrowError(
260
+ 'stubbed-presigned-url-request'
261
+ );
262
+ expect(createPresignedURLSpy).toHaveBeenCalledTimes(1);
263
} finally {
264
rmSync(allowed, { recursive: true, force: true });
265
}