From 1997ce4bbeafb9e21fef65439628f02c5f333fcf Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 13:20:50 +0900 Subject: [PATCH] fix(browser-transfer): drop the bridge's second copy of each part (Q-6.1-3b) The multipart-to-presigned bridge copied every part with Uint8Array.from and the presigned executor then snapshotted the same bytes with slice() before any await. The executor's snapshot is the one the public port needs, so the bridge now forwards the part buffer as is. The executor still re-digests its own copy against the part checksum, so a port that mutated the buffer would fail closed rather than upload other bytes. partBufferCopyFactor is left at 4; changing a policy default is a contract migration. Verified: the bridge test now asserts the port receives the part buffer itself (failed before: it got a copy) + all gates. Co-Authored-By: Claude Opus 5.5 --- .../resumable-upload/presigned-upload-part-executor.ts | 4 +++- tests/unit/resumable-upload-runtime.test.ts | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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));