| 1 | import { orderedParts } from "@/Git/BlobStore.ts"; |
| 2 | import { describe, expect, test } from "alchemy-test"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { RuntimeContext } from "@/RuntimeContext.ts"; |
| 5 | import { makeMemoryBlobStore } from "./harness/store.ts"; |
| 6 | |
| 7 | describe("multipart parts", { tags: ["unit", "local"] }, () => { |
| 8 | test("orderedParts sorts by part number regardless of settle order", () => { |
| 9 | // The push pipeline's hasher isolates upload parts concurrently and the |
| 10 | // small tail settles before earlier parts do. |
| 11 | const parts = [1, 3, 6, 2, 5, 4].map((partNumber) => ({ |
| 12 | partNumber, |
| 13 | etag: `e${partNumber}`, |
| 14 | })); |
| 15 | expect(orderedParts(parts).map((p) => p.partNumber)).toEqual([ |
| 16 | 1, 2, 3, 4, 5, 6, |
| 17 | ]); |
| 18 | }); |
| 19 | test("the memory store enforces R2's uniform-part rule as R2 does", async () => { |
| 20 | const blobs = makeMemoryBlobStore(); |
| 21 | const result = await Effect.runPromise( |
| 22 | Effect.gen(function* () { |
| 23 | const upload = yield* blobs.multipart("k"); |
| 24 | const parts = [ |
| 25 | yield* blobs.uploadPart("k", upload.uploadId, 1, new Uint8Array(8)), |
| 26 | yield* blobs.uploadPart("k", upload.uploadId, 3, new Uint8Array(3)), |
| 27 | yield* blobs.uploadPart("k", upload.uploadId, 2, new Uint8Array(8)), |
| 28 | ]; |
| 29 | // As given: [1, 3, 2] puts the small part in the middle → rejected. |
| 30 | const unsorted = yield* Effect.result(upload.complete(parts)); |
| 31 | const sorted = yield* Effect.result( |
| 32 | upload.complete(orderedParts(parts)), |
| 33 | ); |
| 34 | const head = yield* blobs.head("k"); |
| 35 | return { |
| 36 | unsorted: unsorted._tag, |
| 37 | sorted: sorted._tag, |
| 38 | size: head?.size, |
| 39 | }; |
| 40 | }).pipe(Effect.provide(RuntimeContext.phantom)), |
| 41 | ); |
| 42 | expect(result.unsorted).toBe("Failure"); |
| 43 | expect(result.sorted).toBe("Success"); |
| 44 | expect(result.size).toBe(19); |
| 45 | }); |
| 46 | }); |