Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(file): add Compress and Decompress operations to the File block#5100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f35278a3dfc9cc3a9ec676a7d1c2aae3d46986c294128a80acdf521bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { fileCompressTool, fileDecompressTool } from '@/tools/file/compress' | ||
| describe('fileCompressTool', () => { | ||
| it('builds a compress request body from file IDs and archive name', () => { | ||
| const body = fileCompressTool.request.body?.({ | ||
| fileId: ['wf_a', 'wf_b'], | ||
| archiveName: 'documents.zip', | ||
| _context: { workspaceId: 'ws_1' }, | ||
| } as Parameters<NonNullable<typeof fileCompressTool.request.body>>[0]) | ||
| expect(body).toMatchObject({ | ||
| operation: 'compress', | ||
| fileId: ['wf_a', 'wf_b'], | ||
| archiveName: 'documents.zip', | ||
| workspaceId: 'ws_1', | ||
| }) | ||
| }) | ||
| it('forwards a selected file object when no IDs are provided', () => { | ||
| const fileInput = { id: 'wf_c', name: 'report.pdf' } | ||
| const body = fileCompressTool.request.body?.({ | ||
| fileInput, | ||
| workspaceId: 'ws_2', | ||
| } as Parameters<NonNullable<typeof fileCompressTool.request.body>>[0]) | ||
| expect(body).toMatchObject({ | ||
| operation: 'compress', | ||
| fileInput, | ||
| workspaceId: 'ws_2', | ||
| }) | ||
| }) | ||
| it('returns the compressed archive on success', async () => { | ||
| const archive = { | ||
| id: 'wf_zip', | ||
| name: 'archive.zip', | ||
| size: 1024, | ||
| url: 'https://example.com/archive.zip', | ||
| type: 'application/zip', | ||
| key: 'workspace/ws_1/archive.zip', | ||
| } | ||
| const result = await fileCompressTool.transformResponse?.( | ||
| Response.json({ | ||
| success: true, | ||
| data: { | ||
| id: archive.id, | ||
| name: archive.name, | ||
| size: archive.size, | ||
| url: archive.url, | ||
| files: [archive], | ||
| }, | ||
| }) | ||
| ) | ||
| expect(result).toMatchObject({ | ||
| success: true, | ||
| output: { id: 'wf_zip', name: 'archive.zip', size: 1024, files: [archive] }, | ||
| }) | ||
| }) | ||
| it('propagates route failures as tool failures', async () => { | ||
| const result = await fileCompressTool.transformResponse?.( | ||
| Response.json({ success: false, error: 'Combined input is too large to compress.' }) | ||
| ) | ||
| expect(result).toMatchObject({ | ||
| success: false, | ||
| error: 'Combined input is too large to compress.', | ||
| output: {}, | ||
| }) | ||
| }) | ||
| }) | ||
| describe('fileDecompressTool', () => { | ||
| it('builds a decompress request body from a file ID', () => { | ||
| const body = fileDecompressTool.request.body?.({ | ||
| fileId: 'wf_zip', | ||
| _context: { workspaceId: 'ws_1' }, | ||
| } as Parameters<NonNullable<typeof fileDecompressTool.request.body>>[0]) | ||
| expect(body).toMatchObject({ | ||
| operation: 'decompress', | ||
| fileId: 'wf_zip', | ||
| workspaceId: 'ws_1', | ||
| }) | ||
| }) | ||
| it('returns the extracted files on success', async () => { | ||
| const extracted = [ | ||
| { id: 'wf_a', name: 'a.txt', url: 'https://example.com/a.txt', key: 'k/a.txt' }, | ||
| { id: 'wf_b', name: 'b.txt', url: 'https://example.com/b.txt', key: 'k/b.txt' }, | ||
| ] | ||
| const result = await fileDecompressTool.transformResponse?.( | ||
| Response.json({ success: true, data: { files: extracted } }) | ||
| ) | ||
| expect(result).toMatchObject({ | ||
| success: true, | ||
| output: { files: extracted }, | ||
| }) | ||
| }) | ||
| it('propagates route failures as tool failures', async () => { | ||
| const result = await fileDecompressTool.transformResponse?.( | ||
| Response.json({ success: false, error: '"data.txt" is not a valid .zip archive' }) | ||
| ) | ||
| expect(result).toMatchObject({ | ||
| success: false, | ||
| error: '"data.txt" is not a valid .zip archive', | ||
| output: {}, | ||
| }) | ||
| }) | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.