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

main
ts 80 lines 3.05 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { DataCatalog } from "@alchemy.run/aws/Athena/DataCatalog";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as athena from "@distilled.cloud/aws/athena";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 const catalogName = "alchemy_test_catalog";
12 const fnA = "arn:aws:lambda:us-west-2:391965393224:function:alchemy-athena-cat-a";
13 const fnB = "arn:aws:lambda:us-west-2:391965393224:function:alchemy-athena-cat-b";
14
15 const getCatalog = athena.getDataCatalog({ Name: catalogName, WorkGroup: "primary" }).pipe(
16 Effect.map((res) => res.DataCatalog),
17 Effect.catchTag("DataCatalogNotFound", () => Effect.succeed(undefined)),
18 );
19
20 test.provider(
21 "lifecycle: create LAMBDA catalog, update params/description, destroy",
22 (stack) =>
23 Effect.gen(function* () {
24 yield* stack.destroy();
25
26 // Create — a federated LAMBDA connector (a fake function ARN is accepted
27 // at create time; Athena validates lazily at query time).
28 const created = yield* stack.deploy(
29 Effect.gen(function* () {
30 return yield* DataCatalog("LifecycleCat", {
31 name: catalogName,
32 type: "LAMBDA",
33 description: "initial",
34 parameters: { "metadata-function": fnA, "record-function": fnA },
35 tags: { env: "test" },
36 });
37 }),
38 );
39 expect(created.dataCatalogArn).toContain(`datacatalog/${catalogName}`);
40 expect(created.type).toBe("LAMBDA");
41
42 // Out-of-band verification via distilled.
43 const observed = yield* getCatalog;
44 expect(observed?.Type).toBe("LAMBDA");
45 expect(observed?.Parameters?.["metadata-function"]).toBe(fnA);
46 expect(observed?.Description).toBe("initial");
47
48 // Tags applied.
49 const tags = yield* athena.listTagsForResource({
50 ResourceARN: created.dataCatalogArn,
51 });
52 expect(tags.Tags?.some((t) => t.Key === "env" && t.Value === "test")).toBe(true);
53
54 // Canonical list() coverage.
55 const provider = yield* Provider.findProvider(DataCatalog);
56 const all = yield* provider.list();
57 expect(all.some((c) => c.name === catalogName)).toBe(true);
58
59 // Update — change the record-function param + description in place.
60 yield* stack.deploy(
61 Effect.gen(function* () {
62 return yield* DataCatalog("LifecycleCat", {
63 name: catalogName,
64 type: "LAMBDA",
65 description: "updated",
66 parameters: { "metadata-function": fnA, "record-function": fnB },
67 });
68 }),
69 );
70 const updated = yield* getCatalog;
71 expect(updated?.Parameters?.["record-function"]).toBe(fnB);
72 expect(updated?.Description).toBe("updated");
73
74 // Destroy — the catalog is removed.
75 yield* stack.destroy();
76 const after = yield* getCatalog;
77 expect(after).toBeUndefined();
78 }),
79 { tags: ["provider:aws", "provider:aws:athena", "live"], timeout: 180_000 },
80 );