diff --git a/src/adapters/browser-transfer/resumable-upload/presigned-upload-part-executor.ts b/src/adapters/browser-transfer/resumable-upload/presigned-upload-part-executor.ts index 08713993..e2bc849b 100644 --- a/src/adapters/browser-transfer/resumable-upload/presigned-upload-part-executor.ts +++ b/src/adapters/browser-transfer/resumable-upload/presigned-upload-part-executor.ts @@ -91,7 +91,9 @@ export function createPresignedUploadPartExecutor( byteLength: input.part.byteLength, checksumSha256: input.part.checksumSha256, idempotencyKey: input.idempotencyKey, - bytes: Uint8Array.from(input.bytes), + // Q-6.1-3b. The presigned port snapshots `bytes` before any await, + // so a second copy here only doubled the per-part buffer. + bytes: input.bytes, signal: input.signal, }); } catch { diff --git a/tests/unit/resumable-upload-runtime.test.ts b/tests/unit/resumable-upload-runtime.test.ts index a6d51dbe..015c9431 100644 --- a/tests/unit/resumable-upload-runtime.test.ts +++ b/tests/unit/resumable-upload-runtime.test.ts @@ -1083,8 +1083,10 @@ describe("production resumable upload runtime", () => { let forwardedUploadBinding = ""; let forwardedSessionId = ""; let forwardedRequestBinding = ""; + let forwardedBytes: Uint8Array | undefined; const port: PresignedUploadPartPort = { async put(input) { + forwardedBytes = input.bytes; forwardedUploadBinding = input.uploadBindingSha256; forwardedSessionId = input.sessionId; forwardedRequestBinding = input.requestBindingSha256; @@ -1115,6 +1117,7 @@ describe("production resumable upload runtime", () => { expectedSha256: "a".repeat(64), expiresAtEpochMs: 2_000, } as unknown as PresignedUploadPartCapability; + const partBytes = new Uint8Array([1, 2, 3, 4]); const result = await executor.uploadPart({ protocol: RESUMABLE_UPLOAD_PROTOCOL, capability, @@ -1135,7 +1138,7 @@ describe("production resumable upload runtime", () => { byteLength: 4, checksumSha256: "a".repeat(64), }, - bytes: new Uint8Array([1, 2, 3, 4]), + bytes: partBytes, idempotencyKey: "upload-part-idempotency-01", signal: activeSignal, }); @@ -1143,6 +1146,9 @@ describe("production resumable upload runtime", () => { ok: true, value: { receiptToken: "etag.response-01" }, }); + // Q-6.1-3b. The presigned port snapshots the bytes itself, so the bridge + // forwards the part buffer instead of adding a second copy per attempt. + expect(forwardedBytes).toBe(partBytes); expect(forwardedUploadBinding).toBe("b".repeat(64)); expect(forwardedSessionId).toBe("session_01"); expect(forwardedRequestBinding).toBe("c".repeat(64));