-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(copilot): surface document render failures #6629
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
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
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,132 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const { renderDocToGrid } = vi.hoisted(() => ({ | ||
| renderDocToGrid: vi.fn(), | ||
| })) | ||
|
|
||
| const { findWorkspaceFileRecord, listAllWorkspaceFilesExecute, readWorkspaceFileContentExecute } = | ||
| vi.hoisted(() => ({ | ||
| findWorkspaceFileRecord: vi.fn(), | ||
| listAllWorkspaceFilesExecute: vi.fn(), | ||
| readWorkspaceFileContentExecute: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@/lib/copilot/tools/server/files/doc-render', () => ({ | ||
| // `odt` exposes the defensive missing-task branch independently from the extension guard. | ||
| isRenderableDocExt: (ext: string) => ['docx', 'odt', 'pdf', 'pptx'].includes(ext.toLowerCase()), | ||
| renderDocToGrid, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/uploads/contexts/workspace/workspace-file-manager', () => ({ | ||
| findWorkspaceFileRecord, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/workspace-files/application/list-workspace-files', () => ({ | ||
| listAllWorkspaceFiles: { execute: listAllWorkspaceFilesExecute }, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/workspace-files/application/read-workspace-file-content', () => ({ | ||
| readWorkspaceFileContent: { execute: readWorkspaceFileContentExecute }, | ||
| })) | ||
|
|
||
| import { WorkspaceVFS } from '@/lib/copilot/vfs/workspace-vfs' | ||
|
|
||
| const MAX_DOC_READ_INPUT_BYTES = 50 * 1024 * 1024 | ||
| const MAX_DOCUMENT_PREVIEW_CODE_BYTES = 1024 * 1024 | ||
|
|
||
| function arrangeRenderRead({ | ||
| name = 'brief.pdf', | ||
| size = 8, | ||
| content = Buffer.from('%PDF-1.7'), | ||
| }: { | ||
| name?: string | ||
| size?: number | ||
| content?: Buffer | { length: number } | ||
| } = {}) { | ||
| const record = { | ||
| id: 'file-1', | ||
| workspaceId: 'ws-1', | ||
| name, | ||
| key: name, | ||
| path: `/api/files/serve/${name}`, | ||
| size, | ||
| type: 'application/octet-stream', | ||
| uploadedBy: 'user-1', | ||
| deletedAt: null, | ||
| uploadedAt: new Date('2026-01-01T00:00:00.000Z'), | ||
| updatedAt: new Date('2026-01-01T00:00:00.000Z'), | ||
| storageContext: 'mothership' as const, | ||
| } | ||
| listAllWorkspaceFilesExecute.mockResolvedValue({ files: [record] }) | ||
| findWorkspaceFileRecord.mockReturnValue(record) | ||
| readWorkspaceFileContentExecute.mockResolvedValue({ content }) | ||
|
|
||
| const vfs = new WorkspaceVFS({ kind: 'session', userId: 'user-1', sessionId: 'session-1' }) | ||
| Object.assign(vfs, { _workspaceId: 'ws-1' }) | ||
| return vfs | ||
| } | ||
|
|
||
| describe('WorkspaceVFS dynamic render reads', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it('marks render exceptions as file read errors', async () => { | ||
| const vfs = arrangeRenderRead() | ||
| renderDocToGrid.mockRejectedValue( | ||
| new Error('Document compiler not configured (MOTHERSHIP_E2B_DOC_TEMPLATE_ID is unset)') | ||
| ) | ||
|
|
||
| const result = await vfs.readFileContent('files/brief.pdf/render') | ||
|
|
||
| expect(result).toEqual({ | ||
| content: | ||
| '{"ok":false,"error":"Document compiler not configured (MOTHERSHIP_E2B_DOC_TEMPLATE_ID is unset)"}', | ||
| totalLines: 1, | ||
| error: 'Document compiler not configured (MOTHERSHIP_E2B_DOC_TEMPLATE_ID is unset)', | ||
| }) | ||
| }) | ||
|
|
||
| it.each([ | ||
| { | ||
| label: 'unsupported extensions', | ||
| name: 'brief.txt', | ||
| error: 'Render supports .pptx, .docx, and .pdf only', | ||
| }, | ||
| { | ||
| label: 'oversized file metadata', | ||
| size: MAX_DOC_READ_INPUT_BYTES + 1, | ||
| error: 'File is too large to render', | ||
| }, | ||
| { | ||
| label: 'oversized fetched buffers', | ||
| content: { length: MAX_DOC_READ_INPUT_BYTES + 1 }, | ||
| error: 'File is too large to render', | ||
| }, | ||
| { | ||
| label: 'oversized source', | ||
| content: Buffer.alloc(MAX_DOCUMENT_PREVIEW_CODE_BYTES + 1, 'a'), | ||
| error: 'File source exceeds maximum size', | ||
| }, | ||
| { | ||
| label: 'missing render tasks', | ||
| name: 'brief.odt', | ||
| content: Buffer.from('document source'), | ||
| error: 'Cannot render this file', | ||
| }, | ||
| ])('marks $label as file read errors', async ({ name, size, content, error }) => { | ||
| const vfs = arrangeRenderRead({ name, size, content }) | ||
|
|
||
| const result = await vfs.readFileContent(`files/${name ?? 'brief.pdf'}/render`) | ||
|
|
||
| expect(result).toEqual({ | ||
| content: JSON.stringify({ ok: false, error }), | ||
| totalLines: 1, | ||
| error, | ||
| }) | ||
| }) | ||
| }) |
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.
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.