@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, 04:45 UTC

main
ts 120 lines 4.5 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import type { SubnetId } from "@alchemy.run/aws/EC2/Subnet";
3 import { 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 { getDefaultVpc } from "../DefaultVpc.ts";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // Ungated typed-error probe: proves the distilled error union carries the
14 // not-found tag this provider's read/delete paths depend on.
15 test.provider(
16 "describeClusterSubnetGroups on a nonexistent group fails with ClusterSubnetGroupNotFoundFault",
17 () =>
18 Effect.gen(function* () {
19 const error = yield* Effect.flip(
20 redshift.describeClusterSubnetGroups({
21 ClusterSubnetGroupName: "alchemy-nonexistent-redshift-sng-probe",
22 }),
23 );
24 expect(error._tag).toBe("ClusterSubnetGroupNotFoundFault");
25 }),
26 { tags: ["provider:aws", "provider:aws:redshift", "live"] },
27 );
28
29 // Resolve default-for-AZ subnets in the default VPC (sorted for determinism).
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 if (subnetIds.length < 2) {
43 return yield* Effect.die(new Error("default VPC has fewer than 2 default-for-az subnets"));
44 }
45 return subnetIds as SubnetId[];
46 });
47
48 test.provider(
49 "create, update subnets and tags, destroy",
50 (stack) =>
51 Effect.gen(function* () {
52 yield* stack.destroy();
53
54 const subnetIds = yield* defaultSubnets;
55
56 // Create with a single subnet.
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* ClusterSubnetGroup("Subnets", {
60 description: "alchemy redshift subnet group",
61 subnetIds: subnetIds.slice(0, 1),
62 tags: { fixture: "redshift-subnet-group" },
63 });
64 }),
65 );
66
67 expect(created.clusterSubnetGroupName).toBeDefined();
68 expect(created.clusterSubnetGroupArn).toContain(":subnetgroup:");
69 expect(created.subnetIds).toEqual(subnetIds.slice(0, 1));
70 expect(created.vpcId).toBeDefined();
71 expect(created.tags.fixture).toBe("redshift-subnet-group");
72
73 // Out-of-band verification via distilled, tags included.
74 const observed = yield* redshift.describeClusterSubnetGroups({
75 ClusterSubnetGroupName: created.clusterSubnetGroupName,
76 });
77 const group = observed.ClusterSubnetGroups?.[0];
78 expect(group?.SubnetGroupStatus).toBe("Complete");
79 expect(
80 group?.Tags?.some((t) => t.Key === "fixture" && t.Value === "redshift-subnet-group"),
81 ).toBe(true);
82
83 // Update — expand to two subnets, change description, swap tags.
84 const updated = yield* stack.deploy(
85 Effect.gen(function* () {
86 return yield* ClusterSubnetGroup("Subnets", {
87 description: "alchemy redshift subnet group (updated)",
88 subnetIds: subnetIds.slice(0, 2),
89 tags: { stage: "updated" },
90 });
91 }),
92 );
93
94 expect(updated.clusterSubnetGroupName).toBe(created.clusterSubnetGroupName);
95 expect(updated.description).toBe("alchemy redshift subnet group (updated)");
96 expect([...updated.subnetIds].sort()).toEqual(subnetIds.slice(0, 2));
97 expect(updated.tags.stage).toBe("updated");
98 expect(updated.tags.fixture).toBeUndefined();
99
100 const reobserved = yield* redshift.describeClusterSubnetGroups({
101 ClusterSubnetGroupName: created.clusterSubnetGroupName,
102 });
103 const regroup = reobserved.ClusterSubnetGroups?.[0];
104 expect(regroup?.Subnets?.length).toBe(2);
105 expect(regroup?.Tags?.some((t) => t.Key === "fixture")).toBe(false);
106
107 // Destroy and verify gone with the typed not-found tag.
108 yield* stack.destroy();
109 const error = yield* Effect.flip(
110 redshift.describeClusterSubnetGroups({
111 ClusterSubnetGroupName: created.clusterSubnetGroupName,
112 }),
113 );
114 expect(error._tag).toBe("ClusterSubnetGroupNotFoundFault");
115 }),
116 {
117 tags: ["provider:aws", "provider:aws:ec2", "provider:aws:redshift", "live"],
118 timeout: 120_000,
119 },
120 );