@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 171 lines 6.28 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Bucket } from "@alchemy.run/aws/S3";
3 import { AccessPoint } from "@alchemy.run/aws/S3Control";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as s3control from "@distilled.cloud/aws/s3-control";
7 import * as Data from "effect/Data";
8 import * as Effect from "effect/Effect";
9 import * as Schedule from "effect/Schedule";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 const ACCOUNT_ID = "391965393224";
14
15 const findAccessPoint = (name: string) =>
16 s3control
17 .getAccessPoint({ AccountId: ACCOUNT_ID, Name: name })
18 .pipe(Effect.catchTag("NoSuchAccessPoint", () => Effect.succeed(undefined)));
19
20 class AccessPointStillExists extends Data.TaggedError("AccessPointStillExists")<{
21 readonly name: string;
22 }> {}
23
24 const assertAccessPointDeleted = (name: string) =>
25 findAccessPoint(name).pipe(
26 Effect.flatMap((ap) =>
27 ap === undefined ? Effect.void : Effect.fail(new AccessPointStillExists({ name })),
28 ),
29 Effect.retry({
30 while: (e) => e._tag === "AccessPointStillExists",
31 schedule: Schedule.max([Schedule.exponential(500), Schedule.recurs(8)]),
32 }),
33 );
34
35 test.provider(
36 "typed NoSuchAccessPoint tag on a nonexistent access point",
37 () =>
38 Effect.gen(function* () {
39 const result = yield* s3control
40 .getAccessPoint({
41 AccountId: ACCOUNT_ID,
42 Name: "alchemy-does-not-exist-xyz",
43 })
44 .pipe(
45 Effect.map(() => "found" as const),
46 // proves the patched typed union — no cast, no catch-all
47 Effect.catchTag("NoSuchAccessPoint", () => Effect.succeed("missing" as const)),
48 );
49 expect(result).toBe("missing");
50 }),
51 { tags: ["provider:aws", "provider:aws:s3control", "live"], timeout: 60_000 },
52 );
53
54 test.provider(
55 "create, update tags, delete access point",
56 (stack) =>
57 Effect.gen(function* () {
58 yield* stack.destroy();
59
60 const deployed = yield* stack.deploy(
61 Effect.gen(function* () {
62 const bucket = yield* Bucket("ApBucket", { forceDestroy: true });
63 const accessPoint = yield* AccessPoint("TestAp", {
64 bucket: bucket.bucketName,
65 tags: { Environment: "test" },
66 });
67 return { bucket, accessPoint };
68 }),
69 );
70
71 expect(deployed.accessPoint.accessPointName).toBeDefined();
72 expect(deployed.accessPoint.accessPointArn).toContain(":accesspoint/");
73 expect(deployed.accessPoint.networkOrigin).toBe("Internet");
74 expect(deployed.accessPoint.bucket).toBe(deployed.bucket.bucketName);
75
76 // out-of-band verification via distilled
77 const live = yield* findAccessPoint(deployed.accessPoint.accessPointName);
78 expect(live?.Bucket).toBe(deployed.bucket.bucketName);
79 // AWS defaults every public-access-block flag to true
80 expect(live?.PublicAccessBlockConfiguration?.BlockPublicAcls).toBe(true);
81
82 const tags = yield* s3control
83 .listTagsForResource({
84 AccountId: ACCOUNT_ID,
85 ResourceArn: deployed.accessPoint.accessPointArn,
86 })
87 .pipe(Effect.map((r) => Object.fromEntries((r.Tags ?? []).map((t) => [t.Key, t.Value]))));
88 expect(tags.Environment).toBe("test");
89 expect(tags["alchemy::id"]).toBe("TestAp");
90
91 // update tags only — same access point, no replacement
92 const updated = yield* stack.deploy(
93 Effect.gen(function* () {
94 const bucket = yield* Bucket("ApBucket", { forceDestroy: true });
95 const accessPoint = yield* AccessPoint("TestAp", {
96 bucket: bucket.bucketName,
97 tags: { Environment: "production", Team: "data" },
98 });
99 return { bucket, accessPoint };
100 }),
101 );
102 expect(updated.accessPoint.accessPointName).toBe(deployed.accessPoint.accessPointName);
103
104 const updatedTags = yield* s3control
105 .listTagsForResource({
106 AccountId: ACCOUNT_ID,
107 ResourceArn: updated.accessPoint.accessPointArn,
108 })
109 .pipe(Effect.map((r) => Object.fromEntries((r.Tags ?? []).map((t) => [t.Key, t.Value]))));
110 expect(updatedTags.Environment).toBe("production");
111 expect(updatedTags.Team).toBe("data");
112
113 yield* stack.destroy();
114 yield* assertAccessPointDeleted(deployed.accessPoint.accessPointName);
115 }),
116 // Generous wall: deploys serialize on the per-profile lock across suites.
117 {
118 tags: ["provider:aws", "provider:aws:s3", "provider:aws:s3control", "live"],
119 timeout: 300_000,
120 },
121 );
122
123 test.provider(
124 "changing public-access-block replaces the access point",
125 (stack) =>
126 Effect.gen(function* () {
127 yield* stack.destroy();
128
129 const first = yield* stack.deploy(
130 Effect.gen(function* () {
131 const bucket = yield* Bucket("ReplBucket", { forceDestroy: true });
132 const accessPoint = yield* AccessPoint("ReplAp", {
133 bucket: bucket.bucketName,
134 });
135 return { bucket, accessPoint };
136 }),
137 );
138
139 const second = yield* stack.deploy(
140 Effect.gen(function* () {
141 const bucket = yield* Bucket("ReplBucket", { forceDestroy: true });
142 const accessPoint = yield* AccessPoint("ReplAp", {
143 bucket: bucket.bucketName,
144 publicAccessBlock: {
145 blockPublicAcls: true,
146 ignorePublicAcls: true,
147 blockPublicPolicy: false,
148 restrictPublicBuckets: false,
149 },
150 });
151 return { bucket, accessPoint };
152 }),
153 );
154
155 // replacement: new physical name, old access point cleaned up
156 expect(second.accessPoint.accessPointName).not.toBe(first.accessPoint.accessPointName);
157 const live = yield* findAccessPoint(second.accessPoint.accessPointName);
158 expect(live?.PublicAccessBlockConfiguration?.BlockPublicPolicy).toBe(false);
159 yield* assertAccessPointDeleted(first.accessPoint.accessPointName);
160
161 yield* stack.destroy();
162 yield* assertAccessPointDeleted(second.accessPoint.accessPointName);
163 }),
164 // Individual steps are fast (<3s solo), but deploys serialize on the
165 // per-profile lock across every concurrently-running suite, so the
166 // last-scheduled test in a busy run can queue for minutes.
167 {
168 tags: ["provider:aws", "provider:aws:s3", "provider:aws:s3control", "live"],
169 timeout: 300_000,
170 },
171 );