Repository navigation
fix(app): large file attachments #15848
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a45566e
fix: large file attachments
neriousy 175e2b2
feat(persist): add bounded sync and async write functions to handle o…
neriousy 63f57fa
fix: test
neriousy 2016862
Update packages/app/src/utils/persist.ts
neriousy 60f992c
chore: translations
neriousy 534e6f2
Merge branch 'dev' into fix/large-file-attachments
neriousy 12c12e1
Merge branch 'dev' into fix/large-file-attachments
neriousy 057e328
Merge branch 'dev' into fix/large-file-attachments
neriousy 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
77 changes: 77 additions & 0 deletions
77
packages/app/src/components/prompt-input/attachments.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,77 @@ | ||
| import { beforeAll, beforeEach, describe, expect, mock, test } from "bun:test" | ||
| import { createRoot } from "solid-js" | ||
|
|
||
| type PromptStore = { | ||
| current: () => [] | ||
| cursor: () => number | ||
| set: (...args: unknown[]) => void | ||
| } | ||
|
|
||
| let prompt = {} as PromptStore | ||
| const toasts: Array<{ title?: string; description?: string }> = [] | ||
|
|
||
| let createPromptAttachments: typeof import("./attachments").createPromptAttachments | ||
| let MAX_ATTACHMENT_BYTES = 0 | ||
|
|
||
| beforeAll(async () => { | ||
| mock.module("@/context/prompt", () => ({ | ||
| usePrompt: () => prompt, | ||
| })) | ||
| mock.module("@/context/language", () => ({ | ||
| useLanguage: () => ({ | ||
| t: (key: string, params?: { limit?: string }) => { | ||
| if (key === "prompt.toast.attachmentTooLarge.title") return "Attachment too large" | ||
| if (key === "prompt.toast.attachmentTooLarge.description") return `limit:${params?.limit ?? ""}` | ||
| return key | ||
| }, | ||
| }), | ||
| })) | ||
| mock.module("@opencode-ai/ui/toast", () => ({ | ||
| showToast: (value: { title?: string; description?: string }) => { | ||
| toasts.push(value) | ||
| }, | ||
| })) | ||
| const mod = await import("./attachments") | ||
| createPromptAttachments = mod.createPromptAttachments | ||
| MAX_ATTACHMENT_BYTES = mod.MAX_ATTACHMENT_BYTES | ||
| }) | ||
|
|
||
| beforeEach(() => { | ||
| toasts.length = 0 | ||
| prompt = { | ||
| current: () => [], | ||
| cursor: () => 0, | ||
| set: () => undefined, | ||
| } | ||
| }) | ||
|
|
||
| describe("prompt attachments", () => { | ||
| test("rejects oversized attachments before FileReader", async () => { | ||
| const setCalls: unknown[][] = [] | ||
| prompt.set = (...args) => setCalls.push(args) | ||
|
|
||
| const api = createRoot((dispose) => { | ||
| const value = createPromptAttachments({ | ||
| editor: () => undefined, | ||
| isFocused: () => true, | ||
| isDialogActive: () => false, | ||
| setDraggingType: () => undefined, | ||
| focusEditor: () => undefined, | ||
| addPart: () => false, | ||
| }) | ||
| dispose() | ||
| return value | ||
| }) | ||
|
|
||
| await api.addImageAttachment({ | ||
| type: "application/pdf", | ||
| size: MAX_ATTACHMENT_BYTES + 1, | ||
| name: "huge.pdf", | ||
| } as File) | ||
|
|
||
| expect(setCalls).toHaveLength(0) | ||
| expect(toasts).toHaveLength(1) | ||
| expect(toasts[0]?.title).toBe("Attachment too large") | ||
| expect(toasts[0]?.description).toBe("limit:32 MiB") | ||
| }) | ||
| }) |
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
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.