-
Notifications
You must be signed in to change notification settings - Fork 7
ENG-1864 Define cross-app asset reference contract #1392
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
maparent
wants to merge
2
commits into
eng-2229-add-a-filename-column-to-filereference
from
eng-1864-define-cross-app-asset-reference-contract
Open
Changes from all commits
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| MAX_IMPORTED_ASSET_BYTES, | ||
| MAX_PUBLISHED_ASSET_BYTES, | ||
| isAssetTooLarge, | ||
| } from "../assetLimits"; | ||
|
|
||
| const MIB = 1024 * 1024; | ||
|
|
||
| describe("asset size caps", () => { | ||
| it("holds each direction as its own named constant", () => { | ||
| expect(MAX_PUBLISHED_ASSET_BYTES).toBe(6 * MIB); | ||
| expect(MAX_IMPORTED_ASSET_BYTES).toBe(6 * MIB); | ||
| }); | ||
| }); | ||
|
|
||
| describe.each([ | ||
| ["publish", MAX_PUBLISHED_ASSET_BYTES], | ||
| ["import", MAX_IMPORTED_ASSET_BYTES], | ||
| ])("the %s cap", (_direction, limit) => { | ||
| it("skips an asset above it, reporting rather than throwing", () => { | ||
| let verdict: boolean | undefined; | ||
| expect(() => { | ||
| verdict = isAssetTooLarge({ size: limit + 1, limit }); | ||
| }).not.toThrow(); | ||
| expect(verdict).toBe(true); | ||
| }); | ||
|
|
||
| it("skips an asset exactly at it", () => { | ||
| expect(isAssetTooLarge({ size: limit, limit })).toBe(true); | ||
| }); | ||
|
|
||
| it("transfers an asset below it", () => { | ||
| expect(isAssetTooLarge({ size: limit - 1, limit })).toBe(false); | ||
| expect(isAssetTooLarge({ size: 0, limit })).toBe(false); | ||
| }); | ||
| }); |
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,47 @@ | ||
| /** | ||
| * Size caps for moving asset bytes across the shared-storage boundary. | ||
| * | ||
| * The two directions are separate constants on purpose. They happen to hold the same | ||
| * number today, but they answer different questions and are expected to diverge: the | ||
| * publish cap is about what we will store and pay for, the import cap about what a | ||
| * browser should shuttle and what it costs a user's quota on the destination platform. | ||
| * Neither may be derived from the other, and neither may be imported from a caller's | ||
| * own limit. | ||
| */ | ||
|
|
||
| /** | ||
| * The largest asset, in bytes, that a platform will copy into shared storage when | ||
| * publishing a node. | ||
| * | ||
| * 6 MiB is Supabase's threshold for a standard upload; above it an uploader is expected | ||
| * to switch to a resumable one, which `addFile` does not implement. It is deliberately | ||
| * not read from the bucket's own `file_size_limit` (50 MiB), because the constraint is | ||
| * the upload method rather than what the bucket would accept. | ||
| */ | ||
| export const MAX_PUBLISHED_ASSET_BYTES = 6 * 1024 * 1024; | ||
|
|
||
| /** | ||
| * The largest asset, in bytes, that a destination will copy out of shared storage into | ||
| * its own storage when importing a node. | ||
| * | ||
| * Same number as the publish cap for now, so there is one figure to reason about, but | ||
| * held separately because the constraint is different: the destination client pulls the | ||
| * bytes down and pushes them back up, in the browser, once per importing graph, spending | ||
| * that user's storage quota. The destination platform's own ceiling is unknown to us. | ||
| */ | ||
| export const MAX_IMPORTED_ASSET_BYTES = 6 * 1024 * 1024; | ||
|
|
||
| /** | ||
| * Whether an asset is too large to transfer under the given cap. | ||
| * | ||
| * Returns a verdict rather than throwing: an oversized asset is a skip, and the node it | ||
| * belongs to still publishes or imports with its content intact. The boundary is | ||
| * inclusive, so an asset exactly at the cap is skipped, matching the guard this replaced. | ||
| */ | ||
| export const isAssetTooLarge = ({ | ||
| size, | ||
| limit, | ||
| }: { | ||
| size: number; | ||
| limit: number; | ||
| }): boolean => size >= limit; |
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.
The error message is inconsistent with the actual check. The code rejects assets when
size >= 6MB(inclusive), but the message says "larger than 6Mb" (exclusive). A user with exactly a 6MB file will see this misleading message.Fix:
Spotted by Graphite

Is this helpful? React 👍 or 👎 to let us know.