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

main
ts 86 lines 3.34 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { WorkGroup } from "@alchemy.run/aws/Athena/WorkGroup";
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 wgName = "alchemy-test-athena-wg-lifecycle";
12
13 const getWorkGroup = athena.getWorkGroup({ WorkGroup: wgName }).pipe(
14 Effect.map((res) => res.WorkGroup),
15 Effect.catchTag("WorkGroupNotFound", () => Effect.succeed(undefined)),
16 );
17
18 test.provider(
19 "lifecycle: create with result config, update settings, destroy",
20 (stack) =>
21 Effect.gen(function* () {
22 yield* stack.destroy();
23
24 // Create — enforced result location + a bytes-scanned guardrail.
25 const deployed = yield* stack.deploy(
26 Effect.gen(function* () {
27 return yield* WorkGroup("LifecycleWG", {
28 workGroupName: wgName,
29 outputLocation: "s3://alchemy-athena-wg-test-results/prefix/",
30 enforceWorkGroupConfiguration: true,
31 bytesScannedCutoffPerQuery: 10_000_000,
32 tags: { env: "test" },
33 });
34 }),
35 );
36 expect(deployed.workGroupArn).toContain(`workgroup/${wgName}`);
37 expect(deployed.state).toBe("ENABLED");
38
39 // Out-of-band verification via distilled.
40 const created = yield* getWorkGroup;
41 expect(created?.Name).toBe(wgName);
42 expect(created?.State).toBe("ENABLED");
43 expect(created?.Configuration?.ResultConfiguration?.OutputLocation).toBe(
44 "s3://alchemy-athena-wg-test-results/prefix/",
45 );
46 expect(created?.Configuration?.EnforceWorkGroupConfiguration).toBe(true);
47 expect(created?.Configuration?.BytesScannedCutoffPerQuery).toBe(10_000_000);
48
49 // Tags applied.
50 const tags = yield* athena.listTagsForResource({
51 ResourceARN: deployed.workGroupArn,
52 });
53 expect(tags.Tags?.some((t) => t.Key === "env" && t.Value === "test")).toBe(true);
54
55 // Canonical list() coverage.
56 const provider = yield* Provider.findProvider(WorkGroup);
57 const all = yield* provider.list();
58 expect(all.some((wg) => wg.workGroupName === wgName)).toBe(true);
59
60 // Update — remove the cutoff, disable, retag (in-place, no replacement).
61 yield* stack.deploy(
62 Effect.gen(function* () {
63 return yield* WorkGroup("LifecycleWG", {
64 workGroupName: wgName,
65 outputLocation: "s3://alchemy-athena-wg-test-results/prefix/",
66 enforceWorkGroupConfiguration: true,
67 state: "DISABLED",
68 tags: { env: "prod" },
69 });
70 }),
71 );
72 const updated = yield* getWorkGroup;
73 expect(updated?.State).toBe("DISABLED");
74 expect(updated?.Configuration?.BytesScannedCutoffPerQuery).toBeUndefined();
75 const updatedTags = yield* athena.listTagsForResource({
76 ResourceARN: deployed.workGroupArn,
77 });
78 expect(updatedTags.Tags?.some((t) => t.Key === "env" && t.Value === "prod")).toBe(true);
79
80 // Destroy — provider recursively deletes and it's gone.
81 yield* stack.destroy();
82 const after = yield* getWorkGroup;
83 expect(after).toBeUndefined();
84 }),
85 { tags: ["provider:aws", "provider:aws:athena", "live"], timeout: 180_000 },
86 );