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

main
ts 133 lines 5.21 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import type { SubnetId } from "@alchemy.run/aws/EC2/Subnet";
3 import { Cluster, ClusterSubnetGroup } from "@alchemy.run/aws/Redshift";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as EC2 from "@distilled.cloud/aws/ec2";
7 import * as redshift from "@distilled.cloud/aws/redshift";
8 import * as Effect from "effect/Effect";
9 import * as Redacted from "effect/Redacted";
10 import * as Schedule from "effect/Schedule";
11 import { getDefaultVpc } from "../DefaultVpc.ts";
12
13 const { test } = Test.make({ providers: AWS.providers() });
14
15 // Ungated typed-error probe: proves the distilled error union carries the
16 // not-found tag this provider's read/delete paths depend on.
17 test.provider(
18 "describeClusters on a nonexistent cluster fails with ClusterNotFoundFault",
19 () =>
20 Effect.gen(function* () {
21 const error = yield* Effect.flip(
22 redshift.describeClusters({ ClusterIdentifier: "alchemy-nonexistent-redshift-probe" }),
23 );
24 expect(error._tag).toBe("ClusterNotFoundFault");
25 }),
26 { tags: ["provider:aws", "provider:aws:redshift", "live"] },
27 );
28
29 // Resolve two default-for-AZ subnets in the default VPC.
30 const defaultSubnets = 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 subnetIds = (subnets.Subnets ?? [])
39 .map((s) => s.SubnetId)
40 .filter((id): id is string => id !== undefined)
41 .sort()
42 .slice(0, 2);
43 if (subnetIds.length < 2) {
44 return yield* Effect.die(new Error("default VPC has fewer than 2 default-for-az subnets"));
45 }
46 return subnetIds as SubnetId[];
47 });
48
49 // Deletion is verified as INITIATED (status `deleting`, irreversible) or
50 // fully gone. Full disappearance takes several more minutes server-side;
51 // waiting for it would push the test into its timeout.
52 const assertClusterDeleting = (identifier: string) =>
53 Effect.gen(function* () {
54 const status = yield* redshift.describeClusters({ ClusterIdentifier: identifier }).pipe(
55 Effect.map((r) => r.Clusters?.[0]?.ClusterStatus ?? "gone"),
56 Effect.catchTag("ClusterNotFoundFault", () => Effect.succeed("gone" as const)),
57 );
58 if (status !== "gone" && status !== "deleting") {
59 return yield* Effect.fail(
60 new Error(`cluster '${identifier}' still exists (status: ${status})`),
61 );
62 }
63 }).pipe(
64 Effect.retry({ schedule: Schedule.max([Schedule.fixed("10 seconds"), Schedule.recurs(18)]) }),
65 );
66
67 // Provisioned Redshift clusters take ~5-10 minutes to reach `available` and
68 // bill hourly per node while they exist. The full lifecycle is skipped under
69 // `--fast` and always destroys what it created.
70 test.provider.skipIf(!!process.env.FAST)(
71 "create single-node Redshift cluster, verify, destroy",
72 (stack) =>
73 Effect.gen(function* () {
74 yield* stack.destroy();
75
76 const subnetIds = yield* defaultSubnets;
77
78 const { cluster } = yield* stack.deploy(
79 Effect.gen(function* () {
80 const subnetGroup = yield* ClusterSubnetGroup("WarehouseSubnets", {
81 description: "alchemy redshift cluster subnets",
82 subnetIds,
83 });
84 const cluster = yield* Cluster("Warehouse", {
85 nodeType: "ra3.large",
86 numberOfNodes: 1,
87 masterUsername: "alchemyadmin",
88 masterUserPassword: Redacted.make("AlchemyRedshiftTest1"),
89 dbName: "analytics",
90 clusterSubnetGroupName: subnetGroup.clusterSubnetGroupName,
91 publiclyAccessible: false,
92 encrypted: true,
93 tags: { fixture: "redshift-cluster" },
94 });
95 return { cluster };
96 }),
97 );
98
99 expect(cluster.clusterIdentifier).toBeDefined();
100 expect(cluster.clusterArn).toContain(":cluster:");
101 expect(cluster.clusterStatus).toBe("available");
102 expect(cluster.nodeType).toBe("ra3.large");
103 expect(cluster.numberOfNodes).toBe(1);
104 expect(cluster.dbName).toBe("analytics");
105 expect(cluster.masterUsername).toBe("alchemyadmin");
106 expect(cluster.endpointAddress).toContain("redshift");
107 expect(cluster.endpointPort).toBe(5439);
108 expect(cluster.publiclyAccessible).toBe(false);
109 expect(cluster.encrypted).toBe(true);
110
111 // Out-of-band verification via distilled, tags included.
112 const described = yield* redshift.describeClusters({
113 ClusterIdentifier: cluster.clusterIdentifier,
114 });
115 const observed = described.Clusters?.[0];
116 expect(observed?.ClusterStatus).toBe("available");
117 expect(observed?.NodeType).toBe("ra3.large");
118 expect(observed?.Encrypted).toBe(true);
119 expect(
120 observed?.Tags?.some((t) => t.Key === "fixture" && t.Value === "redshift-cluster"),
121 ).toBe(true);
122
123 // Destroy immediately — clusters bill while they exist — and verify
124 // deletion was initiated out-of-band.
125 yield* stack.destroy();
126 yield* assertClusterDeleting(cluster.clusterIdentifier);
127 }),
128 // create (~5-10 min) + delete initiation, one test.
129 {
130 tags: ["provider:aws", "provider:aws:ec2", "provider:aws:redshift", "live"],
131 timeout: 1_500_000,
132 },
133 );