| 1 | import * as Cloudflare from "@/Cloudflare"; |
| 2 | import * as Provider from "@/Provider"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: Cloudflare.providers() }); |
| 9 | |
| 10 | const logLevel = Effect.provideService( |
| 11 | MinimumLogLevel, |
| 12 | process.env.DEBUG ? "Debug" : "Info", |
| 13 | ); |
| 14 | |
| 15 | test.provider( |
| 16 | "list enumerates the deployed R2 bucket", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | yield* stack.destroy(); |
| 20 | |
| 21 | const bucket = yield* stack.deploy( |
| 22 | Effect.gen(function* () { |
| 23 | return yield* Cloudflare.R2.Bucket("ListResource", { |
| 24 | forceDestroy: true, |
| 25 | name: "alchemy-r2bucket-list-test", |
| 26 | }); |
| 27 | }), |
| 28 | ); |
| 29 | |
| 30 | const provider = yield* Provider.findProvider(Cloudflare.R2.Bucket); |
| 31 | const all = yield* provider.list(); |
| 32 | |
| 33 | const found = all.find((b) => b.bucketName === bucket.bucketName); |
| 34 | expect(found).toBeDefined(); |
| 35 | expect(found?.accountId).toEqual(bucket.accountId); |
| 36 | expect(found?.jurisdiction).toEqual(bucket.jurisdiction); |
| 37 | expect(found?.storageClass).toEqual(bucket.storageClass); |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | }).pipe(logLevel), |
| 41 | // `list()` is genuinely O(account buckets): it enumerates every R2 bucket |
| 42 | // across all three jurisdictions and hydrates each (custom domains + |
| 43 | // lifecycle), all with bounded per-item retries (no unbounded hang). The |
| 44 | // provider no longer wastes the consistency-retry budget on buckets a |
| 45 | // parallel suite is concurrently deleting, but a heavily-populated shared |
| 46 | // account can still take a while — keep a modest margin over the 120s |
| 47 | // default for the genuine enumeration cost. |
| 48 | { |
| 49 | tags: ["provider:cloudflare", "provider:cloudflare:r2", "live"], |
| 50 | timeout: 180_000, |
| 51 | }, |
| 52 | ); |