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

main
ts 83 lines 2.98 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 RedshiftQueryFunctionLive, { RedshiftQueryFunction } from "./fixtures/query-handler";
9
10 const testOptions = { providers: AWS.providers() };
11 const { test, beforeAll, afterAll } = Test.make(testOptions);
12 const sharedStack = Core.scratchStack(testOptions, "RedshiftDataBindings");
13
14 let baseUrl: string;
15
16 // The whole flagship suite deploys a Redshift Serverless namespace + workgroup
17 // (a real-money RPU floor while it exists) plus a Lambda, so it is skipped under
18 // `--fast` and destroys everything in afterAll.
19 describe.skipIf(!!process.env.FAST)(
20 "RedshiftData Bindings",
21 {
22 tags: [
23 "provider:aws",
24 "provider:aws:lambda",
25 "provider:aws:redshiftdata",
26 "provider:aws:redshiftserverless",
27 "live",
28 ],
29 },
30 () => {
31 beforeAll(
32 Effect.gen(function* () {
33 yield* Effect.logInfo("RedshiftData test setup: destroying previous run");
34 yield* sharedStack.destroy();
35
36 yield* Effect.logInfo("RedshiftData test setup: deploying fixture");
37 const { functionUrl } = yield* sharedStack.deploy(
38 Effect.gen(function* () {
39 return yield* RedshiftQueryFunction;
40 }).pipe(Effect.provide(RedshiftQueryFunctionLive)),
41 );
42
43 expect(functionUrl).toBeTruthy();
44 baseUrl = functionUrl!.replace(/\/+$/, "");
45 yield* Effect.logInfo(`RedshiftData test setup: function URL ready (${functionUrl})`);
46 }),
47 // namespace (~1 min) + workgroup create (~2-5 min) + Lambda deploy.
48 { timeout: 900_000 },
49 );
50
51 afterAll(sharedStack.destroy(), { timeout: 600_000 });
52
53 describe("Statements", () => {
54 test.provider(
55 "runs SELECT 1 against the serverless workgroup and returns records",
56 (_stack) =>
57 Effect.gen(function* () {
58 const response = yield* HttpClient.get(`${baseUrl}/query`).pipe(
59 Effect.flatMap((res) =>
60 res.status === 200
61 ? Effect.succeed(res)
62 : Effect.fail(new Error(`query returned ${res.status}`)),
63 ),
64 Effect.retry({
65 schedule: Schedule.max([Schedule.exponential("1 second"), Schedule.recurs(10)]),
66 }),
67 Effect.flatMap((res) => res.json),
68 );
69
70 const body = response as {
71 columns: (string | undefined)[];
72 records: { longValue?: number }[][];
73 totalNumRows: number;
74 };
75 // SELECT 1 AS n => one row, one column, longValue 1.
76 expect(body.records).toHaveLength(1);
77 expect(body.records[0][0]).toMatchObject({ longValue: 1 });
78 }),
79 { timeout: 240_000 },
80 );
81 });
82 },
83 );