-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f35278a
feat(file): add Compress operation to bundle files into a .zip archive
waleedlatif1 3dfc9cc
feat(file): add Decompress operation to extract .zip archives
waleedlatif1 3a9ec67
fix(file): align archive ops with v5 output surface and zip mime
waleedlatif1 6a7d1c2
fix(file): harden compress naming per review
waleedlatif1 aae3d46
fix(file): make decompress extraction atomic and bound per-entry size
waleedlatif1 986c294
fix(file): exclude skipped entries from caps and reject multi-archive…
waleedlatif1 128a80a
fix(file): enforce single-archive decompress at the API boundary
waleedlatif1 cdf521b
docs(file): correct compress description and stale file-output refere…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: {}, | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.