@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 123 lines 4.44 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { HealthCheck, HostedZone, Record } from "@alchemy.run/aws/Route53";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as route53 from "@distilled.cloud/aws/route-53";
6 import * as Effect from "effect/Effect";
7
8 const { test } = Test.make({ providers: AWS.providers() });
9
10 const normalizeId = (id: string) => id.replace(/^\/hostedzone\//, "");
11
12 const findSet = (sets: route53.ResourceRecordSet[], name: string, setId: string) =>
13 sets.find((s) => s.Name === name && s.SetIdentifier === setId && s.Type === "A");
14
15 const zoneName = "alchemy-route53-routing.alchemy.";
16
17 describe.skipIf(process.env.FAST)(
18 "RoutingPolicy",
19 { tags: ["provider:aws", "provider:aws:route53", "live"] },
20 () => {
21 test.provider(
22 "weighted, failover, and alias routing records",
23 (stack) =>
24 Effect.gen(function* () {
25 yield* stack.destroy();
26
27 const result = yield* stack.deploy(
28 Effect.gen(function* () {
29 const zone = yield* HostedZone("RoutingZone", { name: zoneName });
30
31 // AWS requires a non-alias PRIMARY failover record to have a health
32 // check.
33 const check = yield* HealthCheck("PrimaryCheck", {
34 type: "HTTP",
35 ipAddress: "1.1.1.1",
36 port: 80,
37 resourcePath: "/",
38 requestInterval: "30 seconds",
39 });
40
41 // Weighted pair — same name/type, distinct setIdentifier + weight.
42 yield* Record("Blue", {
43 hostedZoneId: zone.id,
44 name: `api.${zoneName}`,
45 type: "A",
46 ttl: "60 seconds",
47 records: ["1.2.3.4"],
48 setIdentifier: "blue",
49 weight: 90,
50 });
51 yield* Record("Green", {
52 hostedZoneId: zone.id,
53 name: `api.${zoneName}`,
54 type: "A",
55 ttl: "60 seconds",
56 records: ["5.6.7.8"],
57 setIdentifier: "green",
58 weight: 10,
59 });
60
61 // Failover pair — PRIMARY gated on the health check.
62 yield* Record("Primary", {
63 hostedZoneId: zone.id,
64 name: `app.${zoneName}`,
65 type: "A",
66 ttl: "60 seconds",
67 records: ["1.1.1.1"],
68 setIdentifier: "primary",
69 failover: "PRIMARY",
70 healthCheckId: check.id,
71 });
72 yield* Record("Secondary", {
73 hostedZoneId: zone.id,
74 name: `app.${zoneName}`,
75 type: "A",
76 ttl: "60 seconds",
77 records: ["2.2.2.2"],
78 setIdentifier: "secondary",
79 failover: "SECONDARY",
80 });
81
82 return { zoneId: zone.id };
83 }),
84 );
85
86 const zoneId = normalizeId(result.zoneId);
87
88 // Verify out of band.
89 const listed = yield* route53.listResourceRecordSets({
90 HostedZoneId: zoneId,
91 MaxItems: 100,
92 });
93 const sets = listed.ResourceRecordSets ?? [];
94
95 const blue = findSet(sets, `api.${zoneName}`, "blue");
96 const green = findSet(sets, `api.${zoneName}`, "green");
97 expect(blue?.Weight).toBe(90);
98 expect(green?.Weight).toBe(10);
99 // Duration.Input ttl ("60 seconds") lands on the wire as TTL: 60.
100 expect(blue?.TTL).toBe(60);
101
102 const primary = findSet(sets, `app.${zoneName}`, "primary");
103 const secondary = findSet(sets, `app.${zoneName}`, "secondary");
104 expect(primary?.Failover).toBe("PRIMARY");
105 expect(primary?.HealthCheckId).toBeDefined();
106 expect(secondary?.Failover).toBe("SECONDARY");
107
108 // Destroy — this exercises the DELETE builder serializing policy fields
109 // (Weight, Failover, HealthCheckId). A mismatch would fail with
110 // InvalidChangeBatch.
111 yield* stack.destroy();
112
113 // The zone must be fully cleaned up (records deleted, then zone deleted).
114 const gone = yield* route53.getHostedZone({ Id: zoneId }).pipe(
115 Effect.map(() => false),
116 Effect.catchTag("NoSuchHostedZone", () => Effect.succeed(true)),
117 );
118 expect(gone).toBe(true);
119 }),
120 { timeout: 300_000 },
121 );
122 },
123 );