-
Notifications
You must be signed in to change notification settings - Fork 11
Harden workspace upload failure handling #669
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
3 commits
Select commit
Hold shift + click to select a range
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
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
108 changes: 108 additions & 0 deletions
108
src/features/workspaces/files/workspace-file-upload.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,108 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const { captureException, toastError, uploadFileDirectlyToR2 } = vi.hoisted(() => ({ | ||
| captureException: vi.fn(), | ||
| toastError: vi.fn(), | ||
| uploadFileDirectlyToR2: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("sonner", () => ({ | ||
| toast: { | ||
| error: toastError, | ||
| loading: vi.fn(() => "upload-toast"), | ||
| success: vi.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("#/features/workspaces/upload/workspace-file-direct-upload-client", () => ({ | ||
| uploadFileDirectlyToR2, | ||
| })); | ||
|
|
||
| vi.mock("#/features/workspaces/use-workspace-client-mutation-echo", () => ({ | ||
| prepareWorkspaceClientMutationInput: <T>(input: T) => ({ | ||
| ...input, | ||
| clientMutationId: "test-mutation", | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("#/integrations/posthog/provider", () => ({ | ||
| capturePostHogClientException: captureException, | ||
| })); | ||
|
|
||
| import { runWorkspaceFileUploadBatch } from "#/features/workspaces/files/workspace-file-upload"; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.stubGlobal( | ||
| "fetch", | ||
| vi.fn().mockImplementation(() => | ||
| Promise.resolve( | ||
| new Response( | ||
| JSON.stringify({ | ||
| completionToken: "completion-token", | ||
| uploadUrl: "https://r2.example/upload", | ||
| }), | ||
| { headers: { "content-type": "application/json" }, status: 200 }, | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| }); | ||
|
|
||
| describe("workspace file upload batch failures", () => { | ||
| it("preserves and captures the original upload error once", async () => { | ||
| const error = new Error("Direct file upload failed because of a network error."); | ||
| uploadFileDirectlyToR2.mockRejectedValue(error); | ||
|
|
||
| await runWorkspaceFileUploadBatch({ | ||
| files: [new File([new Uint8Array([1])], "paper.pdf", { type: "application/pdf" })], | ||
| onSuccess: vi.fn(), | ||
| parentId: null, | ||
| workspaceId: "workspace-id", | ||
| }); | ||
|
|
||
| expect(captureException).toHaveBeenCalledOnce(); | ||
| expect(captureException).toHaveBeenCalledWith(error, { | ||
| operation: "workspace_file_upload", | ||
| upload_error_count: 1, | ||
| upload_skipped_count: 0, | ||
| upload_success_count: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it("does not capture a canceled upload", async () => { | ||
| const error = new DOMException("Upload canceled.", "AbortError"); | ||
| uploadFileDirectlyToR2.mockRejectedValue(error); | ||
|
|
||
| await runWorkspaceFileUploadBatch({ | ||
| files: [new File([new Uint8Array([1])], "paper.pdf", { type: "application/pdf" })], | ||
| onSuccess: vi.fn(), | ||
| parentId: null, | ||
| workspaceId: "workspace-id", | ||
| }); | ||
|
|
||
| expect(captureException).not.toHaveBeenCalled(); | ||
| expect(toastError).toHaveBeenCalledWith( | ||
| "Upload canceled.", | ||
| expect.objectContaining({ id: "upload-toast" }), | ||
| ); | ||
| }); | ||
|
|
||
| it("does not reclassify a cache callback failure as an upload failure", async () => { | ||
| const error = new Error("Cache update failed."); | ||
| uploadFileDirectlyToR2.mockResolvedValue(undefined); | ||
|
|
||
| await expect( | ||
| runWorkspaceFileUploadBatch({ | ||
| files: [new File([new Uint8Array([1])], "paper.pdf", { type: "application/pdf" })], | ||
| onSuccess: () => { | ||
| throw error; | ||
| }, | ||
| parentId: null, | ||
| workspaceId: "workspace-id", | ||
| }), | ||
| ).rejects.toBe(error); | ||
|
|
||
| expect(captureException).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a HEIC/HEIF workspace upload is near the advertised 100 MiB limit, intake accepts it because it compares
File.sizetoworkspaceFileUploadLimits.maxFileBytes, but this container compares the HTTPcontent-lengthagainst the same 100 MiB. The conversion client sends the file as multipart/form-data, so the boundary/header bytes make an otherwise valid 100 MiB file exceed this limit and fail during conversion instead of uploading successfully; either allow overhead here or validate the parsed file's size.Useful? React with 👍 / 👎.