-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(files): serve rendered documents instead of source code #6139
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
Open
j15z
wants to merge
13
commits into
staging
Choose a base branch
from
agent-block-file-issue
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ee582e0
fix(files): serve rendered documents to attachments and workflow reads
j15z c2214f0
fix(files): keep render failures retryable and never relabel unrender…
j15z 6a72bba
perf(files): coalesce concurrent renders of the same missing artifact
j15z abe134a
fix(files): refuse unrendered bytes at the download boundary
j15z 78c16ec
fix(files): move the unrenderable error out of the 'use server' module
j15z 5d3107f
fix(files): finish the render cancellation and failure-surfacing edges
j15z 1270bcb
revert(files): drop the concurrent-render coalescing
j15z a98f272
fix(review): simplify generated document attachments
j15z b9060e1
fix(files): mock servable downloads in hydration tests
j15z e3d3ba5
fix(files): preserve rendered attachment semantics
j15z acf9397
fix(files): preserve cached artifact size
j15z f5ef0eb
fix(files): refuse unresolved xlsx source
j15z cb21c93
fix(files): resolve execution artifact workspace
j15z 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
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
56 changes: 56 additions & 0 deletions
56
apps/sim/lib/execution/payloads/materialization.server.test.ts
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,56 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const { mockDownloadServableFileFromStorage, mockVerifyFileAccess } = vi.hoisted(() => ({ | ||
| mockDownloadServableFileFromStorage: vi.fn(), | ||
| mockVerifyFileAccess: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@/lib/uploads/utils/file-utils.server', () => ({ | ||
| downloadServableFileFromStorage: mockDownloadServableFileFromStorage, | ||
| })) | ||
|
|
||
| vi.mock('@/app/api/files/authorization', () => ({ | ||
| verifyFileAccess: mockVerifyFileAccess, | ||
| })) | ||
|
|
||
| import { readUserFileContent } from '@/lib/execution/payloads/materialization.server' | ||
| import type { UserFile } from '@/executor/types' | ||
|
|
||
| const PDF_SOURCE = Buffer.from('from reportlab.pdfgen import canvas') | ||
| const PDF_BYTES = Buffer.from('%PDF-1.4 rendered bytes') | ||
|
|
||
| const generatedPdf: UserFile = { | ||
| id: 'file-1', | ||
| name: 'report.pdf', | ||
| url: '', | ||
| size: PDF_SOURCE.length, | ||
| type: 'text/x-python-pdf', | ||
| key: 'workspace/2f1d8c3e-5b6a-4c7d-8e9f-0a1b2c3d4e5f/1700000000000-abc1234-report.pdf', | ||
| } | ||
|
|
||
| describe('readUserFileContent', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| generatedPdf.size = PDF_SOURCE.length | ||
| mockVerifyFileAccess.mockResolvedValue(true) | ||
| mockDownloadServableFileFromStorage.mockResolvedValue({ | ||
| buffer: PDF_BYTES, | ||
| contentType: 'application/pdf', | ||
| }) | ||
| }) | ||
|
|
||
| it('returns the compiled artifact instead of the stored generation source', async () => { | ||
| const content = await readUserFileContent(generatedPdf, { | ||
| userId: 'user-1', | ||
| encoding: 'base64', | ||
| }) | ||
|
|
||
| expect(mockDownloadServableFileFromStorage).toHaveBeenCalledOnce() | ||
| expect(content).toBe(PDF_BYTES.toString('base64')) | ||
| expect(content).not.toBe(PDF_SOURCE.toString('base64')) | ||
| expect(generatedPdf.size).toBe(PDF_BYTES.length) | ||
| }) | ||
| }) |
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
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.