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

main
ts 191 lines 7.36 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { KxDatabase, KxEnvironment } from "@alchemy.run/aws/FinSpace";
3 import { Key } from "@alchemy.run/aws/KMS";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as finspace from "@distilled.cloud/aws/finspace";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 // Amazon FinSpace reached end of support on 2026-10-07
13 // (https://docs.aws.amazon.com/finspace/latest/userguide/amazon-finspace-end-of-support.html).
14 // The control-plane hostname finspace.<region>.amazonaws.com no longer has
15 // A records in any region, so every control-plane call fails before reaching
16 // AWS with:
17 // HttpClientError: Transport error (GET https://finspace.us-west-2.amazonaws.com/kx/environments)
18 // (cause: getaddrinfo ENOTFOUND finspace.us-west-2.amazonaws.com)
19 // A transport failure can't be patched into a typed tag, so all control-plane
20 // tests are gated behind AWS_TEST_FINSPACE=1 for accounts that still have access.
21 const finspaceRetired = !process.env.AWS_TEST_FINSPACE;
22
23 // Ungated typed-error probes: prove the distilled error union carries the
24 // not-found tags the Kx providers' read/delete paths depend on.
25 test.provider.skipIf(finspaceRetired)(
26 "getKxEnvironment on a nonexistent environment fails with ResourceNotFoundException",
27 () =>
28 Effect.gen(function* () {
29 const error = yield* Effect.flip(
30 finspace.getKxEnvironment({ environmentId: "zzzzzzzzzzzzzzzzzzzzzzzzzz" }),
31 );
32 expect(error._tag).toBe("ResourceNotFoundException");
33 }),
34 { tags: ["provider:aws", "provider:aws:finspace", "live"] },
35 );
36
37 test.provider.skipIf(finspaceRetired)(
38 "getKxDatabase on a nonexistent environment fails with ResourceNotFoundException",
39 () =>
40 Effect.gen(function* () {
41 const error = yield* Effect.flip(
42 finspace.getKxDatabase({
43 environmentId: "zzzzzzzzzzzzzzzzzzzzzzzzzz",
44 databaseName: "nodb",
45 }),
46 );
47 expect(error._tag).toBe("ResourceNotFoundException");
48 }),
49 { tags: ["provider:aws", "provider:aws:finspace", "live"] },
50 );
51
52 test.provider.skipIf(finspaceRetired)(
53 "getKxCluster on a nonexistent environment fails with ResourceNotFoundException",
54 () =>
55 Effect.gen(function* () {
56 const error = yield* Effect.flip(
57 finspace.getKxCluster({
58 environmentId: "zzzzzzzzzzzzzzzzzzzzzzzzzz",
59 clusterName: "nocluster",
60 }),
61 );
62 expect(error._tag).toBe("ResourceNotFoundException");
63 }),
64 { tags: ["provider:aws", "provider:aws:finspace", "live"] },
65 );
66
67 // Probes for the scaling-group / volume binding operations: prove the typed
68 // not-found tag so runtime consumers can catch it without casts.
69 test.provider.skipIf(finspaceRetired)(
70 "getKxScalingGroup on a nonexistent environment fails with ResourceNotFoundException",
71 () =>
72 Effect.gen(function* () {
73 const error = yield* Effect.flip(
74 finspace.getKxScalingGroup({
75 environmentId: "zzzzzzzzzzzzzzzzzzzzzzzzzz",
76 scalingGroupName: "nogroup",
77 }),
78 );
79 expect(error._tag).toBe("ResourceNotFoundException");
80 }),
81 { tags: ["provider:aws", "provider:aws:finspace", "live"] },
82 );
83
84 test.provider.skipIf(finspaceRetired)(
85 "getKxVolume on a nonexistent environment fails with ResourceNotFoundException",
86 () =>
87 Effect.gen(function* () {
88 const error = yield* Effect.flip(
89 finspace.getKxVolume({
90 environmentId: "zzzzzzzzzzzzzzzzzzzzzzzzzz",
91 volumeName: "novolume",
92 }),
93 );
94 expect(error._tag).toBe("ResourceNotFoundException");
95 }),
96 { tags: ["provider:aws", "provider:aws:finspace", "live"] },
97 );
98
99 // Deletion is verified as INITIATED (irreversible) or fully gone.
100 const assertKxEnvironmentDeleting = (environmentId: string) =>
101 Effect.gen(function* () {
102 const status = yield* finspace.getKxEnvironment({ environmentId }).pipe(
103 Effect.map((r) => r.status ?? "gone"),
104 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed("gone" as const)),
105 );
106 if (
107 status !== "gone" &&
108 status !== "DELETED" &&
109 status !== "DELETING" &&
110 status !== "DELETE_REQUESTED"
111 ) {
112 return yield* Effect.fail(
113 new Error(`kdb environment '${environmentId}' still exists (${status})`),
114 );
115 }
116 }).pipe(
117 Effect.retry({ schedule: Schedule.max([Schedule.fixed("10 seconds"), Schedule.recurs(18)]) }),
118 );
119
120 // A managed kdb environment takes tens of minutes to provision and FinSpace
121 // is closed to non-onboarded accounts (CreateKxEnvironment rejects). The
122 // full lifecycle is gated behind AWS_TEST_FINSPACE=1 and always destroys
123 // what it created. KxCluster additionally needs a VPC and dedicated
124 // capacity (~30+ min, billed per node-hour) — it is covered by the typed
125 // probe above and exercised only in onboarded accounts.
126 test.provider.skipIf(finspaceRetired)(
127 "create kdb environment + database, verify, update, destroy",
128 (stack) =>
129 Effect.gen(function* () {
130 yield* stack.destroy();
131
132 const { env, db } = yield* stack.deploy(
133 Effect.gen(function* () {
134 const key = yield* Key("KdbKey", { description: "alchemy finspace kdb test key" });
135 const env = yield* KxEnvironment("Kdb", {
136 kmsKeyId: key.keyArn,
137 description: "alchemy kdb test environment",
138 tags: { fixture: "finspace-kx" },
139 });
140 const db = yield* KxDatabase("Ticks", {
141 environmentId: env.environmentId,
142 description: "alchemy kdb test database",
143 tags: { fixture: "finspace-kx" },
144 });
145 return { env, db };
146 }),
147 );
148
149 expect(env.environmentId).toBeDefined();
150 expect(env.status).toBe("CREATED");
151 expect(db.databaseArn).toContain(":kxEnvironment/");
152
153 // Out-of-band verification via distilled.
154 const observedDb = yield* finspace.getKxDatabase({
155 environmentId: env.environmentId,
156 databaseName: db.databaseName,
157 });
158 expect(observedDb.databaseName).toBe(db.databaseName);
159
160 // Update the database description in place (no replacement).
161 const { db: updated } = yield* stack.deploy(
162 Effect.gen(function* () {
163 const key = yield* Key("KdbKey", { description: "alchemy finspace kdb test key" });
164 const env = yield* KxEnvironment("Kdb", {
165 kmsKeyId: key.keyArn,
166 description: "alchemy kdb test environment",
167 tags: { fixture: "finspace-kx" },
168 });
169 const db = yield* KxDatabase("Ticks", {
170 environmentId: env.environmentId,
171 description: "alchemy kdb test database (updated)",
172 tags: { fixture: "finspace-kx" },
173 });
174 return { env, db };
175 }),
176 );
177 expect(updated.databaseName).toBe(db.databaseName);
178 expect(updated.description).toBe("alchemy kdb test database (updated)");
179
180 // Destroy — environments bill while they exist — and verify deletion
181 // was initiated out-of-band.
182 const environmentId = env.environmentId;
183 yield* stack.destroy();
184 yield* assertKxEnvironmentDeleting(environmentId);
185 }),
186 // kdb environment create (tens of minutes) + database + delete, one test.
187 {
188 tags: ["provider:aws", "provider:aws:finspace", "provider:aws:kms", "live"],
189 timeout: 3_000_000,
190 },
191 );