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

main
ts 166 lines 6.07 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { ClusterParameterGroup } from "@alchemy.run/aws/Redshift";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as redshift from "@distilled.cloud/aws/redshift";
6 import * as Effect from "effect/Effect";
7
8 const { test } = Test.make({ providers: AWS.providers() });
9
10 // Ungated typed-error probe: proves the distilled error union carries the
11 // not-found tag this provider's read/delete paths depend on.
12 test.provider(
13 "describeClusterParameterGroups on a nonexistent group fails with ClusterParameterGroupNotFoundFault",
14 () =>
15 Effect.gen(function* () {
16 const error = yield* Effect.flip(
17 redshift.describeClusterParameterGroups({
18 ParameterGroupName: "alchemy-nonexistent-redshift-cpg-probe",
19 }),
20 );
21 expect(error._tag).toBe("ClusterParameterGroupNotFoundFault");
22 }),
23 { tags: ["provider:aws", "provider:aws:redshift", "live"] },
24 );
25
26 // Read the user-sourced parameter overrides out-of-band.
27 const readUserParameters = (name: string) =>
28 Effect.gen(function* () {
29 const response = yield* redshift.describeClusterParameters({
30 ParameterGroupName: name,
31 Source: "user",
32 });
33 return Object.fromEntries(
34 (response.Parameters ?? []).flatMap((p) =>
35 p.ParameterName !== undefined && p.ParameterValue !== undefined
36 ? [[p.ParameterName, p.ParameterValue]]
37 : [],
38 ),
39 );
40 });
41
42 test.provider(
43 "create with parameters, update/reset parameters, destroy",
44 (stack) =>
45 Effect.gen(function* () {
46 yield* stack.destroy();
47
48 // Create with two parameter overrides.
49 const created = yield* stack.deploy(
50 Effect.gen(function* () {
51 return yield* ClusterParameterGroup("Params", {
52 family: "redshift-1.0",
53 parameters: {
54 enable_user_activity_logging: "true",
55 statement_timeout: "60000",
56 },
57 tags: { fixture: "redshift-parameter-group" },
58 });
59 }),
60 );
61
62 expect(created.clusterParameterGroupName).toBeDefined();
63 expect(created.clusterParameterGroupArn).toContain(":parametergroup:");
64 expect(created.family).toBe("redshift-1.0");
65 expect(created.parameters).toEqual({
66 enable_user_activity_logging: "true",
67 statement_timeout: "60000",
68 });
69
70 // Out-of-band verification via distilled.
71 const observedParams = yield* readUserParameters(created.clusterParameterGroupName);
72 expect(observedParams).toEqual({
73 enable_user_activity_logging: "true",
74 statement_timeout: "60000",
75 });
76 const observed = yield* redshift.describeClusterParameterGroups({
77 ParameterGroupName: created.clusterParameterGroupName,
78 });
79 expect(
80 observed.ParameterGroups?.[0]?.Tags?.some(
81 (t) => t.Key === "fixture" && t.Value === "redshift-parameter-group",
82 ),
83 ).toBe(true);
84
85 // Update — change one value, drop the other (reset to engine
86 // default), keep the same name/family/description so it's in-place.
87 const updated = yield* stack.deploy(
88 Effect.gen(function* () {
89 return yield* ClusterParameterGroup("Params", {
90 family: "redshift-1.0",
91 parameters: { statement_timeout: "120000" },
92 tags: { fixture: "redshift-parameter-group" },
93 });
94 }),
95 );
96
97 expect(updated.clusterParameterGroupName).toBe(created.clusterParameterGroupName);
98 expect(updated.parameters).toEqual({ statement_timeout: "120000" });
99
100 const reobservedParams = yield* readUserParameters(created.clusterParameterGroupName);
101 expect(reobservedParams).toEqual({ statement_timeout: "120000" });
102
103 // Destroy and verify gone with the typed not-found tag.
104 yield* stack.destroy();
105 const error = yield* Effect.flip(
106 redshift.describeClusterParameterGroups({
107 ParameterGroupName: created.clusterParameterGroupName,
108 }),
109 );
110 expect(error._tag).toBe("ClusterParameterGroupNotFoundFault");
111 }),
112 { tags: ["provider:aws", "provider:aws:redshift", "live"], timeout: 120_000 },
113 );
114
115 test.provider(
116 "changing the family replaces the parameter group",
117 (stack) =>
118 Effect.gen(function* () {
119 yield* stack.destroy();
120
121 // Engine-generated name so the replacement can create the new group
122 // under a fresh physical name before deleting the old one.
123 const created = yield* stack.deploy(
124 Effect.gen(function* () {
125 return yield* ClusterParameterGroup("ReplaceParams", {
126 family: "redshift-1.0",
127 description: "before replacement",
128 });
129 }),
130 );
131 expect(created.description).toBe("before replacement");
132
133 // Description is create-only — changing it must replace.
134 const replaced = yield* stack.deploy(
135 Effect.gen(function* () {
136 return yield* ClusterParameterGroup("ReplaceParams", {
137 family: "redshift-1.0",
138 description: "after replacement",
139 });
140 }),
141 );
142 expect(replaced.description).toBe("after replacement");
143 expect(replaced.clusterParameterGroupName).not.toBe(created.clusterParameterGroupName);
144
145 // Old group is gone, new group exists.
146 const oldGone = yield* Effect.flip(
147 redshift.describeClusterParameterGroups({
148 ParameterGroupName: created.clusterParameterGroupName,
149 }),
150 );
151 expect(oldGone._tag).toBe("ClusterParameterGroupNotFoundFault");
152 const observed = yield* redshift.describeClusterParameterGroups({
153 ParameterGroupName: replaced.clusterParameterGroupName,
154 });
155 expect(observed.ParameterGroups?.[0]?.Description).toBe("after replacement");
156
157 yield* stack.destroy();
158 const error = yield* Effect.flip(
159 redshift.describeClusterParameterGroups({
160 ParameterGroupName: replaced.clusterParameterGroupName,
161 }),
162 );
163 expect(error._tag).toBe("ClusterParameterGroupNotFoundFault");
164 }),
165 { tags: ["provider:aws", "provider:aws:redshift", "live"], timeout: 120_000 },
166 );