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

main
ts 125 lines 4.35 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 RedshiftBindingsTestFunctionLive, {
9 RedshiftBindingsTestFunction,
10 } from "./fixtures/bindings-handler";
11
12 const testOptions = { providers: AWS.providers() };
13 const { test, beforeAll, afterAll } = Test.make(testOptions);
14 const sharedStack = Core.scratchStack(testOptions, "RedshiftBindings");
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 "Redshift Bindings",
37 { tags: ["provider:aws", "provider:aws:lambda", "provider:aws:redshift", "live"] },
38 () => {
39 beforeAll(
40 Effect.gen(function* () {
41 yield* Effect.logInfo("Redshift bindings setup: destroying previous resources");
42 yield* sharedStack.destroy();
43
44 yield* Effect.logInfo("Redshift bindings setup: deploying fixture");
45 const { functionUrl } = yield* sharedStack.deploy(
46 Effect.gen(function* () {
47 return yield* RedshiftBindingsTestFunction;
48 }).pipe(Effect.provide(RedshiftBindingsTestFunctionLive)),
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(5);
74 }),
75 );
76 });
77
78 describe("DescribeClusters", () => {
79 test.provider("surfaces the typed not-found tag for a nonexistent cluster", (_stack) =>
80 Effect.gen(function* () {
81 const response = yield* getJson("/clusters");
82 expect((response as any).tag).toBe("ClusterNotFoundFault");
83 }),
84 );
85 });
86
87 describe("DescribeClusterSnapshots", () => {
88 test.provider("lists the account's manual snapshots", (_stack) =>
89 Effect.gen(function* () {
90 const response = yield* getJson("/snapshots");
91 expect((response as any).count).toBeGreaterThanOrEqual(0);
92 }),
93 );
94 });
95
96 describe("DescribeEvents", () => {
97 test.provider("lists the account's recent Redshift events", (_stack) =>
98 Effect.gen(function* () {
99 const response = yield* getJson("/events");
100 expect((response as any).count).toBeGreaterThanOrEqual(0);
101 }),
102 );
103 });
104
105 describe("DeleteClusterSnapshot", () => {
106 test.provider("surfaces the typed not-found tag for a nonexistent snapshot", (_stack) =>
107 Effect.gen(function* () {
108 const response = yield* getJson("/delete-snapshot-probe");
109 expect((response as any).tag).toBe("ClusterSnapshotNotFoundFault");
110 }),
111 );
112 });
113
114 describe("CopyClusterSnapshot", () => {
115 test.provider(
116 "surfaces the typed not-found tag for a nonexistent source snapshot",
117 (_stack) =>
118 Effect.gen(function* () {
119 const response = yield* getJson("/copy-snapshot-probe");
120 expect((response as any).tag).toBe("ClusterSnapshotNotFoundFault");
121 }),
122 );
123 });
124 },
125 );