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

main
ts 112 lines 3.9 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { SubnetGroup } from "@alchemy.run/aws/DAX";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as dax from "@distilled.cloud/aws/dax";
6 import * as EC2 from "@distilled.cloud/aws/ec2";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9 import { getDefaultVpc } from "../DefaultVpc.ts";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // Ungated typed-error probe: prove the distilled error union carries the
14 // not-found tag this provider's read/delete paths depend on.
15 test.provider(
16 "describeSubnetGroups on a nonexistent group fails with SubnetGroupNotFoundFault",
17 () =>
18 Effect.gen(function* () {
19 const error = yield* Effect.flip(
20 dax.describeSubnetGroups({
21 SubnetGroupNames: ["alchemy-nonexistent-dax-subnet-probe"],
22 }),
23 );
24 expect(error._tag).toBe("SubnetGroupNotFoundFault");
25 }),
26 { tags: ["provider:aws", "provider:aws:dax", "live"] },
27 );
28
29 // Resolve default-for-AZ subnets from the account's default VPC.
30 const defaultSubnetIds = Effect.gen(function* () {
31 const vpc = yield* getDefaultVpc;
32 const subnets = yield* EC2.describeSubnets({
33 Filters: [
34 { Name: "vpc-id", Values: [vpc.vpcId] },
35 { Name: "default-for-az", Values: ["true"] },
36 ],
37 });
38 const ids = (subnets.Subnets ?? [])
39 .map((s) => s.SubnetId)
40 .filter((id): id is `subnet-${string}` => id !== undefined)
41 .sort();
42 if (ids.length < 3) {
43 return yield* Effect.die(new Error("default VPC has fewer than 3 default-for-AZ subnets"));
44 }
45 return ids;
46 });
47
48 const assertGone = (name: string) =>
49 dax.describeSubnetGroups({ SubnetGroupNames: [name] }).pipe(
50 Effect.flatMap(() => Effect.fail(new Error(`subnet group '${name}' still exists`))),
51 Effect.catchTag("SubnetGroupNotFoundFault", () => Effect.void),
52 Effect.retry({
53 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
54 }),
55 );
56
57 test.provider(
58 "create, update description and subnets, delete a DAX subnet group",
59 (stack) =>
60 Effect.gen(function* () {
61 yield* stack.destroy();
62
63 const subnetIds = yield* defaultSubnetIds;
64
65 const { group } = yield* stack.deploy(
66 Effect.gen(function* () {
67 const group = yield* SubnetGroup("Subnets", {
68 description: "alchemy dax subnet group",
69 subnetIds: subnetIds.slice(0, 2),
70 });
71 return { group };
72 }),
73 );
74
75 expect(group.subnetGroupName).toBeDefined();
76 expect(group.vpcId).toBeDefined();
77 expect(new Set(group.subnetIds)).toEqual(new Set(subnetIds.slice(0, 2)));
78
79 // Out-of-band verification via distilled.
80 const described = yield* dax.describeSubnetGroups({
81 SubnetGroupNames: [group.subnetGroupName],
82 });
83 const observed = described.SubnetGroups?.[0];
84 expect(observed?.Description).toBe("alchemy dax subnet group");
85 expect(observed?.VpcId).toBeDefined();
86
87 // Update the description and widen the subnet set in place.
88 const { group: updated } = yield* stack.deploy(
89 Effect.gen(function* () {
90 const group = yield* SubnetGroup("Subnets", {
91 description: "alchemy dax subnet group v2",
92 subnetIds: subnetIds.slice(0, 3),
93 });
94 return { group };
95 }),
96 );
97 expect(updated.subnetGroupName).toBe(group.subnetGroupName);
98 expect(new Set(updated.subnetIds)).toEqual(new Set(subnetIds.slice(0, 3)));
99
100 const redescribed = yield* dax.describeSubnetGroups({
101 SubnetGroupNames: [group.subnetGroupName],
102 });
103 expect(redescribed.SubnetGroups?.[0]?.Description).toBe("alchemy dax subnet group v2");
104
105 yield* stack.destroy();
106 yield* assertGone(group.subnetGroupName);
107 }),
108 {
109 tags: ["provider:aws", "provider:aws:dax", "provider:aws:ec2", "live"],
110 timeout: 240_000,
111 },
112 );