diff --git a/src/adapters/browser-transfer/resumable-upload/resumable-upload-runtime.ts b/src/adapters/browser-transfer/resumable-upload/resumable-upload-runtime.ts index 794738e4..e1df57e7 100644 --- a/src/adapters/browser-transfer/resumable-upload/resumable-upload-runtime.ts +++ b/src/adapters/browser-transfer/resumable-upload/resumable-upload-runtime.ts @@ -216,7 +216,7 @@ export function createResumableUploadRuntime( } let request: UploadRequestSnapshot; try { - request = snapshotRequest(input, dependencies.policy); + request = snapshotRequest(input); } catch { return browserDataFailure("INVALID_INPUT", "UPLOAD_SESSION"); } @@ -1742,7 +1742,6 @@ function quarantinedOutcome( function snapshotRequest( input: ResumableUploadRequest, - policy: ResumableUploadRuntimePolicy, ): UploadRequestSnapshot { if ( !input || @@ -1759,14 +1758,8 @@ function snapshotRequest( ) { throw new TypeError("Upload request is invalid."); } + // R-1.4. Size limits are checked by executeUpload as LIMIT_EXCEEDED. const source = snapshotUploadSource(input.source); - if ( - source.byteLength > policy.maxFileBytes || - Math.ceil(source.byteLength / policy.partSizeBytes) > - policy.maxPartCount - ) { - throw new TypeError("Upload request exceeds policy."); - } return Object.freeze({ uploadKey: input.uploadKey, purpose: input.purpose, diff --git a/tests/unit/resumable-upload-runtime.test.ts b/tests/unit/resumable-upload-runtime.test.ts index 9a5f5c42..757c2b15 100644 --- a/tests/unit/resumable-upload-runtime.test.ts +++ b/tests/unit/resumable-upload-runtime.test.ts @@ -215,6 +215,36 @@ describe("production resumable upload runtime", () => { }); }); + // R-1.4. The size check used to throw inside request validation and surface + // as INVALID_INPUT; a file over the policy limit is LIMIT_EXCEEDED. + it("reports a source over maxFileBytes as LIMIT_EXCEEDED", async () => { + const harness = createControlHarness(); + const createSession = vi.spyOn(harness.control, "createSession"); + const runtime = createResumableUploadRuntime({ + controlPlane: harness.control, + partExecutor: executorFor(harness), + checkpoints: new MemoryCheckpointStore(), + mutationLock: noContentionLock, + crypto, + // A valid policy already bounds the part count by maxFileBytes. + policy: runtimePolicy({ maxFileBytes: 4 }), + now: () => 1_000, + sleep: async () => {}, + }); + const result = await runtime.upload({ + uploadKey: "upload_key_too_large", + purpose: "attachment", + mediaType: "application/octet-stream", + source: byteStreamSource(new Uint8Array([1, 2, 3, 4, 5])), + signal: activeSignal, + }); + expect(result).toMatchObject({ + ok: false, + error: { code: "LIMIT_EXCEEDED" }, + }); + expect(createSession).not.toHaveBeenCalled(); + }); + it("fails closed when server list-parts disagrees with the current source manifest", async () => { const checkpoints = new MemoryCheckpointStore(); const harness = createControlHarness({