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

main
ts 77 lines 2.57 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Activity } from "@alchemy.run/aws/StepFunctions";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as sfn from "@distilled.cloud/aws/sfn";
6 import * as Data from "effect/Data";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 class ActivityStillExists extends Data.TaggedError("ActivityStillExists")<{
13 readonly activityArn: string;
14 }> {}
15
16 const assertActivityDeleted = (activityArn: string) =>
17 sfn.describeActivity({ activityArn }).pipe(
18 Effect.flatMap(() => Effect.fail(new ActivityStillExists({ activityArn }))),
19 Effect.catchTag("ActivityDoesNotExist", () => Effect.void),
20 Effect.retry({
21 while: (e) => e._tag === "ActivityStillExists",
22 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
23 }),
24 );
25
26 test.provider(
27 "create, update tags, destroy activity",
28 (stack) =>
29 Effect.gen(function* () {
30 const activity = yield* stack.deploy(
31 Effect.gen(function* () {
32 return yield* Activity("Worker", {
33 tags: { Environment: "test" },
34 });
35 }),
36 );
37
38 expect(activity.activityArn).toContain(":activity:");
39 expect(activity.activityName).toBeDefined();
40
41 // out-of-band verification via distilled
42 const created = yield* sfn.describeActivity({
43 activityArn: activity.activityArn,
44 });
45 expect(created.name).toBe(activity.activityName);
46
47 const tags = yield* sfn.listTagsForResource({
48 resourceArn: activity.activityArn,
49 });
50 const tagRecord = Object.fromEntries((tags.tags ?? []).map((t) => [t.key, t.value]));
51 expect(tagRecord.Environment).toBe("test");
52 expect(tagRecord["alchemy::id"]).toBe("Worker");
53
54 // tag update converges in place
55 const updated = yield* stack.deploy(
56 Effect.gen(function* () {
57 return yield* Activity("Worker", {
58 tags: { Environment: "test", Extra: "1" },
59 });
60 }),
61 );
62 expect(updated.activityArn).toBe(activity.activityArn);
63 const afterUpdate = yield* sfn.listTagsForResource({
64 resourceArn: activity.activityArn,
65 });
66 expect(Object.fromEntries((afterUpdate.tags ?? []).map((t) => [t.key, t.value])).Extra).toBe(
67 "1",
68 );
69
70 yield* stack.destroy();
71 yield* assertActivityDeleted(activity.activityArn);
72 }),
73 {
74 tags: ["provider:aws", "provider:aws:stepfunctions", "live"],
75 timeout: 120_000,
76 },
77 );