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

main
ts 127 lines 4.54 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Vpc } from "@alchemy.run/aws/EC2";
3 import {
4 HostedZone,
5 VpcAssociationAuthorization,
6 ZoneVpcAssociation,
7 } from "@alchemy.run/aws/Route53";
8 import { expect } from "@alchemy.run/test";
9 import * as Test from "@alchemy.run/test/Alchemy";
10 import * as route53 from "@distilled.cloud/aws/route-53";
11 import * as Effect from "effect/Effect";
12 import * as Schedule from "effect/Schedule";
13
14 const { test } = Test.make({ providers: AWS.providers() });
15
16 const VPC_REGION = "us-west-2";
17
18 const assertZoneGone = (id: string) =>
19 route53.getHostedZone({ Id: id }).pipe(
20 Effect.flatMap(() => Effect.fail(new Error("hosted zone still exists"))),
21 Effect.catchTag("NoSuchHostedZone", () => Effect.void),
22 Effect.retry({
23 while: (e) => e instanceof Error,
24 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
25 }),
26 );
27
28 test.provider(
29 "associate a second VPC with a private zone and authorize it",
30 (stack) =>
31 Effect.gen(function* () {
32 yield* stack.destroy();
33
34 const deployed = yield* stack.deploy(
35 Effect.gen(function* () {
36 // Route 53 requires DNS support + hostnames on associated VPCs.
37 const primary = yield* Vpc("PrimaryVpc", {
38 cidrBlock: "10.61.0.0/24",
39 enableDnsSupport: true,
40 enableDnsHostnames: true,
41 });
42 const secondary = yield* Vpc("SecondaryVpc", {
43 cidrBlock: "10.62.0.0/24",
44 enableDnsSupport: true,
45 enableDnsHostnames: true,
46 });
47 const zone = yield* HostedZone("PrivateZone", {
48 name: "alchemy-test-assoc.internal",
49 privateZone: true,
50 vpc: { vpcId: primary.vpcId, vpcRegion: VPC_REGION },
51 forceDestroy: true,
52 });
53 const association = yield* ZoneVpcAssociation("SecondaryAssoc", {
54 hostedZoneId: zone.id,
55 vpcId: secondary.vpcId,
56 vpcRegion: VPC_REGION,
57 });
58 const authorization = yield* VpcAssociationAuthorization("SecondaryAuth", {
59 hostedZoneId: zone.id,
60 vpcId: secondary.vpcId,
61 vpcRegion: VPC_REGION,
62 });
63 return { zone, association, authorization, secondary };
64 }),
65 );
66
67 expect(deployed.association.hostedZoneId).toBe(deployed.zone.id);
68 expect(deployed.association.vpcId).toBe(deployed.secondary.vpcId);
69 expect(deployed.authorization.vpcId).toBe(deployed.secondary.vpcId);
70
71 // Out-of-band: the zone reports both VPCs.
72 const detail = yield* route53.getHostedZone({ Id: deployed.zone.id });
73 const vpcIds = (detail.VPCs ?? []).map((vpc) => vpc.VPCId);
74 expect(vpcIds).toContain(deployed.secondary.vpcId);
75 expect(vpcIds).toHaveLength(2);
76
77 // Out-of-band: the authorization is listed for the zone.
78 const authorizations = yield* route53.listVPCAssociationAuthorizations({
79 HostedZoneId: deployed.zone.id,
80 });
81 expect((authorizations.VPCs ?? []).map((vpc) => vpc.VPCId)).toContain(
82 deployed.secondary.vpcId,
83 );
84
85 // Removing just the association (keeping zone + VPCs) disassociates.
86 const remaining = yield* stack.deploy(
87 Effect.gen(function* () {
88 const primary = yield* Vpc("PrimaryVpc", {
89 cidrBlock: "10.61.0.0/24",
90 enableDnsSupport: true,
91 enableDnsHostnames: true,
92 });
93 const secondary = yield* Vpc("SecondaryVpc", {
94 cidrBlock: "10.62.0.0/24",
95 enableDnsSupport: true,
96 enableDnsHostnames: true,
97 });
98 const zone = yield* HostedZone("PrivateZone", {
99 name: "alchemy-test-assoc.internal",
100 privateZone: true,
101 vpc: { vpcId: primary.vpcId, vpcRegion: VPC_REGION },
102 forceDestroy: true,
103 });
104 return { zone, secondary };
105 }),
106 );
107
108 const detailAfter = yield* route53.getHostedZone({
109 Id: remaining.zone.id,
110 });
111 const vpcIdsAfter = (detailAfter.VPCs ?? []).map((vpc) => vpc.VPCId);
112 expect(vpcIdsAfter).not.toContain(remaining.secondary.vpcId);
113 expect(vpcIdsAfter).toHaveLength(1);
114
115 const authorizationsAfter = yield* route53.listVPCAssociationAuthorizations({
116 HostedZoneId: remaining.zone.id,
117 });
118 expect(authorizationsAfter.VPCs ?? []).toHaveLength(0);
119
120 yield* stack.destroy();
121 yield* assertZoneGone(deployed.zone.id);
122 }),
123 {
124 tags: ["provider:aws", "provider:aws:ec2", "provider:aws:route53", "live"],
125 timeout: 180_000,
126 },
127 );