1import * as AWS from "@/AWS";
2import { Bucket } from "@/AWS/S3";
3import { MultiRegionAccessPoint } from "@/AWS/S3Control";
4import * as Test from "@/Test/Alchemy";
5import { Region } from "@distilled.cloud/aws/Region";
6import * as s3control from "@distilled.cloud/aws/s3-control";
7import { expect } from "alchemy-test";
8import * as Effect from "effect/Effect";
9
10const { test } = Test.make({ providers: AWS.providers() });
11
12const ACCOUNT_ID = "391965393224";
13
14// Multi-Region Access Point control-plane requests route through us-west-2.
15const findMrap = (name: string) =>
16 s3control
17 .getMultiRegionAccessPoint({ AccountId: ACCOUNT_ID, Name: name })
18 .pipe(
19 Effect.map((r) => r.AccessPoint),
20 Effect.catchTag("NoSuchMultiRegionAccessPoint", () =>
21 Effect.succeed(undefined),
22 ),
23 Effect.provideService(Region, Effect.succeed("us-west-2")),
24 );
25
26test.provider(
27 "typed NoSuchMultiRegionAccessPoint tag on a nonexistent access point",
28 () =>
29 Effect.gen(function* () {
30 const result = yield* s3control
31 .getMultiRegionAccessPoint({
32 AccountId: ACCOUNT_ID,
33 Name: "alchemy-does-not-exist-xyz",
34 })
35 .pipe(
36 Effect.map(() => "found" as const),
37 // proves the patched typed union — no cast, no catch-all
38 Effect.catchTag("NoSuchMultiRegionAccessPoint", () =>
39 Effect.succeed("missing" as const),
40 ),
41 Effect.provideService(Region, Effect.succeed("us-west-2")),
42 );
43 expect(result).toBe("missing");
44 }),
45 { tags: ["provider:aws", "provider:aws:s3control", "live"], timeout: 60_000 },
46);
47
48// Multi-Region Access Point provisioning is asynchronous and can consume the
49// entire 240s suite ceiling, so the full lifecycle remains explicitly gated.
50test.provider.skipIf(!process.env.AWS_TEST_SLOW)(
51 "create and delete multi-region access point (slow, gated)",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const deployed = yield* stack.deploy(
57 Effect.gen(function* () {
58 const bucket = yield* Bucket("MrapBucket", { forceDestroy: true });
59 const mrap = yield* MultiRegionAccessPoint("TestMrap", {
60 regions: [{ bucket: bucket.bucketName }],
61 });
62 return { bucket, mrap };
63 }),
64 );
65
66 expect(deployed.mrap.multiRegionAccessPointName).toBeDefined();
67 expect(deployed.mrap.status).toBe("READY");
68 expect(deployed.mrap.alias).toBeDefined();
69 expect(deployed.mrap.multiRegionAccessPointArn).toBe(
70 `arn:aws:s3::${ACCOUNT_ID}:accesspoint/${deployed.mrap.alias}`,
71 );
72
73 // out-of-band verification via distilled
74 const live = yield* findMrap(deployed.mrap.multiRegionAccessPointName);
75 expect(live?.Status).toBe("READY");
76 expect(live?.Regions?.[0]?.Bucket).toBe(deployed.bucket.bucketName);
77
78 yield* stack.destroy();
79
80 const afterDestroy = yield* findMrap(
81 deployed.mrap.multiRegionAccessPointName,
82 );
83 expect(afterDestroy).toBeUndefined();
84 }),
85 {
86 tags: ["provider:aws", "provider:aws:s3", "provider:aws:s3control", "live"],
87 timeout: 240_000,
88 },
89);