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

main
ts 256 lines 9.13 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as Core from "@alchemy.run/test/Core";
5 import * as Effect from "effect/Effect";
6 import * as HttpClient from "effect/http/HttpClient";
7 import * as Schedule from "effect/Schedule";
8 import OpenSearchBindingsTestFunctionLive, {
9 OpenSearchBindingsTestFunction,
10 } from "./fixtures/handler";
11
12 const testOptions = { providers: AWS.providers() };
13 const { test, beforeAll, afterAll } = Test.make(testOptions);
14 const sharedStack = Core.scratchStack(testOptions, "OpenSearchBindings");
15
16 // Lambda function URL cold-start (DNS, IAM propagation, init) can take well
17 // over 60s on a fresh deploy.
18 const readinessPolicy = Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(75)]);
19
20 let baseUrl: string;
21
22 const getJson = (path: string) =>
23 HttpClient.get(`${baseUrl}${path}`).pipe(
24 Effect.flatMap((response) =>
25 response.status >= 500
26 ? Effect.fail(new Error(`transient upstream ${response.status}`))
27 : Effect.succeed(response),
28 ),
29 Effect.retry({
30 schedule: Schedule.max([Schedule.exponential("500 millis"), Schedule.recurs(6)]),
31 }),
32 Effect.flatMap((r) => r.json),
33 );
34
35 describe.sequential(
36 "OpenSearch Bindings",
37 { tags: ["provider:aws", "provider:aws:lambda", "provider:aws:opensearch", "live"] },
38 () => {
39 beforeAll(
40 Effect.gen(function* () {
41 yield* Effect.logInfo("OpenSearch test setup: destroying previous resources");
42 yield* sharedStack.destroy();
43
44 yield* Effect.logInfo("OpenSearch test setup: deploying fixture");
45 const { functionUrl } = yield* sharedStack.deploy(
46 Effect.gen(function* () {
47 return yield* OpenSearchBindingsTestFunction;
48 }).pipe(Effect.provide(OpenSearchBindingsTestFunctionLive)),
49 );
50
51 expect(functionUrl).toBeTruthy();
52 baseUrl = functionUrl!.replace(/\/+$/, "");
53
54 const readinessUrl = `${baseUrl}/bindings`;
55 yield* HttpClient.get(readinessUrl).pipe(
56 Effect.flatMap((response) =>
57 response.status === 200
58 ? Effect.succeed(response)
59 : Effect.fail(new Error(`Function not ready: ${response.status}`)),
60 ),
61 Effect.retry({ schedule: readinessPolicy }),
62 );
63 }),
64 { timeout: 240_000 },
65 );
66
67 afterAll(sharedStack.destroy(), { timeout: 120_000 });
68
69 describe("binding registration", () => {
70 test.provider("all capabilities initialize in the runtime", (_stack) =>
71 Effect.gen(function* () {
72 const response = yield* getJson("/bindings");
73 expect((response as any).bound).toHaveLength(19);
74 }),
75 );
76 });
77
78 describe("DescribeDomain", () => {
79 test.provider("surfaces the typed not-found tag for a nonexistent domain", (_stack) =>
80 Effect.gen(function* () {
81 const response = yield* getJson("/domain");
82 expect((response as any).tag).toBe("ResourceNotFoundException");
83 }),
84 );
85 });
86
87 describe("DescribeDomains", () => {
88 test.provider("returns an empty status list for unknown domain names", (_stack) =>
89 Effect.gen(function* () {
90 const response = yield* getJson("/domains-batch");
91 expect((response as any).count).toBe(0);
92 }),
93 );
94 });
95
96 describe("DescribeDomainConfig", () => {
97 test.provider("surfaces the typed not-found tag for a nonexistent domain", (_stack) =>
98 Effect.gen(function* () {
99 const response = yield* getJson("/domain-config");
100 expect((response as any).tag).toBe("ResourceNotFoundException");
101 }),
102 );
103 });
104
105 describe("DescribeDomainHealth", () => {
106 test.provider(
107 // OpenSearch reports a missing domain on this operation as the typed
108 // `BaseException` ("Domain not found"), not ResourceNotFoundException.
109 "surfaces the typed BaseException tag for a nonexistent domain",
110 (_stack) =>
111 Effect.gen(function* () {
112 const response = yield* getJson("/domain-health");
113 expect((response as any).tag).toBe("BaseException");
114 }),
115 );
116 });
117
118 describe("DescribeDomainNodes", () => {
119 test.provider("surfaces the typed BaseException tag for a nonexistent domain", (_stack) =>
120 Effect.gen(function* () {
121 const response = yield* getJson("/domain-nodes");
122 expect((response as any).tag).toBe("BaseException");
123 }),
124 );
125 });
126
127 describe("DescribeDomainChangeProgress", () => {
128 test.provider(
129 // "No progress information found" surfaces as the typed BaseException.
130 "surfaces the typed BaseException tag when no change is in flight",
131 (_stack) =>
132 Effect.gen(function* () {
133 const response = yield* getJson("/change-progress");
134 expect((response as any).tag).toBe("BaseException");
135 }),
136 );
137 });
138
139 describe("ListDomainNames", () => {
140 test.provider("lists the account's domains", (_stack) =>
141 Effect.gen(function* () {
142 const response = yield* getJson("/domain-names");
143 expect((response as any).count).toBeGreaterThanOrEqual(0);
144 }),
145 );
146 });
147
148 describe("DescribeDomainAutoTunes", () => {
149 test.provider("surfaces the typed not-found tag for a nonexistent domain", (_stack) =>
150 Effect.gen(function* () {
151 const response = yield* getJson("/auto-tunes");
152 expect((response as any).tag).toBe("ResourceNotFoundException");
153 }),
154 );
155 });
156
157 describe("ListScheduledActions", () => {
158 test.provider("surfaces the typed not-found tag for a nonexistent domain", (_stack) =>
159 Effect.gen(function* () {
160 const response = yield* getJson("/scheduled-actions");
161 expect((response as any).tag).toBe("ResourceNotFoundException");
162 }),
163 );
164 });
165
166 describe("StartDomainMaintenance", () => {
167 test.provider("surfaces the typed not-found tag for a nonexistent domain", (_stack) =>
168 Effect.gen(function* () {
169 const response = yield* getJson("/start-maintenance-probe");
170 expect((response as any).tag).toBe("ResourceNotFoundException");
171 }),
172 );
173 });
174
175 describe("GetDomainMaintenanceStatus", () => {
176 test.provider("surfaces the typed BaseException tag for a nonexistent domain", (_stack) =>
177 Effect.gen(function* () {
178 const response = yield* getJson("/maintenance-status-probe");
179 expect((response as any).tag).toBe("BaseException");
180 }),
181 );
182 });
183
184 describe("ListDomainMaintenances", () => {
185 test.provider("surfaces the typed BaseException tag for a nonexistent domain", (_stack) =>
186 Effect.gen(function* () {
187 const response = yield* getJson("/maintenances");
188 expect((response as any).tag).toBe("BaseException");
189 }),
190 );
191 });
192
193 describe("StartServiceSoftwareUpdate", () => {
194 test.provider("surfaces the typed not-found tag for a nonexistent domain", (_stack) =>
195 Effect.gen(function* () {
196 const response = yield* getJson("/software-update-probe");
197 expect((response as any).tag).toBe("ResourceNotFoundException");
198 }),
199 );
200 });
201
202 describe("CancelServiceSoftwareUpdate", () => {
203 test.provider("surfaces the typed not-found tag for a nonexistent domain", (_stack) =>
204 Effect.gen(function* () {
205 const response = yield* getJson("/cancel-software-update-probe");
206 expect((response as any).tag).toBe("ResourceNotFoundException");
207 }),
208 );
209 });
210
211 describe("GetUpgradeStatus", () => {
212 test.provider("surfaces the typed not-found tag for a nonexistent domain", (_stack) =>
213 Effect.gen(function* () {
214 const response = yield* getJson("/upgrade-status");
215 expect((response as any).tag).toBe("ResourceNotFoundException");
216 }),
217 );
218 });
219
220 describe("GetUpgradeHistory", () => {
221 test.provider("surfaces the typed not-found tag for a nonexistent domain", (_stack) =>
222 Effect.gen(function* () {
223 const response = yield* getJson("/upgrade-history");
224 expect((response as any).tag).toBe("ResourceNotFoundException");
225 }),
226 );
227 });
228
229 describe("GetCompatibleVersions", () => {
230 test.provider("maps engine versions to upgrade targets", (_stack) =>
231 Effect.gen(function* () {
232 const response = yield* getJson("/compatible-versions");
233 expect((response as any).count).toBeGreaterThan(0);
234 }),
235 );
236 });
237
238 describe("ListVersions", () => {
239 test.provider("lists the supported engine versions", (_stack) =>
240 Effect.gen(function* () {
241 const response = yield* getJson("/versions");
242 expect((response as any).count).toBeGreaterThan(0);
243 }),
244 );
245 });
246
247 describe("ListInstanceTypeDetails", () => {
248 test.provider("lists instance types for an engine version", (_stack) =>
249 Effect.gen(function* () {
250 const response = yield* getJson("/instance-types");
251 expect((response as any).count).toBeGreaterThan(0);
252 }),
253 );
254 });
255 },
256 );