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

main
ts 99 lines 3.49 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { DBSubnetGroup } from "@alchemy.run/aws/Neptune";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as EC2 from "@distilled.cloud/aws/ec2";
6 import * as neptune from "@distilled.cloud/aws/neptune";
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 // Resolve two default-for-AZ subnets from the account's default VPC.
14 const defaultSubnetIds = Effect.gen(function* () {
15 const vpc = yield* getDefaultVpc;
16 const subnets = yield* EC2.describeSubnets({
17 Filters: [
18 { Name: "vpc-id", Values: [vpc.vpcId] },
19 { Name: "default-for-az", Values: ["true"] },
20 ],
21 });
22 const ids = (subnets.Subnets ?? [])
23 .map((s) => s.SubnetId)
24 .filter((id): id is `subnet-${string}` => id !== undefined)
25 .sort();
26 if (ids.length < 2) {
27 return yield* Effect.die(new Error("default VPC has fewer than 2 default-for-AZ subnets"));
28 }
29 return ids;
30 });
31
32 const assertGone = (name: string) =>
33 neptune.describeDBSubnetGroups({ DBSubnetGroupName: name }).pipe(
34 Effect.flatMap(() => Effect.fail(new Error(`subnet group '${name}' still exists`))),
35 Effect.catchTag("DBSubnetGroupNotFoundFault", () => Effect.void),
36 Effect.retry({
37 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
38 }),
39 );
40
41 test.provider(
42 "create, update description, delete a Neptune DB subnet group",
43 (stack) =>
44 Effect.gen(function* () {
45 yield* stack.destroy();
46
47 const subnetIds = yield* defaultSubnetIds;
48
49 const { group } = yield* stack.deploy(
50 Effect.gen(function* () {
51 const group = yield* DBSubnetGroup("Subnets", {
52 description: "alchemy neptune subnet group",
53 subnetIds: subnetIds.slice(0, 2),
54 tags: { fixture: "neptune-subnet-group" },
55 });
56 return { group };
57 }),
58 );
59
60 expect(group.dbSubnetGroupName).toBeDefined();
61 expect(group.dbSubnetGroupArn).toContain(":subgrp:");
62 expect(new Set(group.subnetIds)).toEqual(new Set(subnetIds.slice(0, 2)));
63
64 // Out-of-band verification.
65 const described = yield* neptune.describeDBSubnetGroups({
66 DBSubnetGroupName: group.dbSubnetGroupName,
67 });
68 const observed = described.DBSubnetGroups?.[0];
69 expect(observed?.DBSubnetGroupDescription).toBe("alchemy neptune subnet group");
70 expect(observed?.VpcId).toBeDefined();
71
72 // Update the description in place (name unchanged).
73 const { group: updated } = yield* stack.deploy(
74 Effect.gen(function* () {
75 const group = yield* DBSubnetGroup("Subnets", {
76 description: "alchemy neptune subnet group v2",
77 subnetIds: subnetIds.slice(0, 2),
78 tags: { fixture: "neptune-subnet-group", env: "test" },
79 });
80 return { group };
81 }),
82 );
83 expect(updated.dbSubnetGroupName).toBe(group.dbSubnetGroupName);
84
85 const redescribed = yield* neptune.describeDBSubnetGroups({
86 DBSubnetGroupName: group.dbSubnetGroupName,
87 });
88 expect(redescribed.DBSubnetGroups?.[0]?.DBSubnetGroupDescription).toBe(
89 "alchemy neptune subnet group v2",
90 );
91
92 yield* stack.destroy();
93 yield* assertGone(group.dbSubnetGroupName);
94 }),
95 {
96 tags: ["provider:aws", "provider:aws:ec2", "provider:aws:neptune", "live"],
97 timeout: 240_000,
98 },
99 );