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

main
ts 113 lines 4.17 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { EventSubscription } from "@alchemy.run/aws/Redshift";
3 import * as SNS from "@alchemy.run/aws/SNS";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as redshift from "@distilled.cloud/aws/redshift";
7 import * as Effect from "effect/Effect";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // Ungated typed-error probe: proves the distilled error union carries the
12 // not-found tag this provider's read/delete paths depend on.
13 test.provider(
14 "describeEventSubscriptions on a nonexistent subscription fails with SubscriptionNotFoundFault",
15 () =>
16 Effect.gen(function* () {
17 const error = yield* Effect.flip(
18 redshift.describeEventSubscriptions({
19 SubscriptionName: "alchemy-nonexistent-redshift-sub-probe",
20 }),
21 );
22 expect(error._tag).toBe("SubscriptionNotFoundFault");
23 }),
24 { tags: ["provider:aws", "provider:aws:redshift", "live"] },
25 );
26
27 const readSubscription = (name: string) =>
28 Effect.gen(function* () {
29 const response = yield* redshift.describeEventSubscriptions({
30 SubscriptionName: name,
31 });
32 return response.EventSubscriptionsList?.[0];
33 });
34
35 test.provider(
36 "create with filters, update filters in place, destroy",
37 (stack) =>
38 Effect.gen(function* () {
39 yield* stack.destroy();
40
41 // Create — an SNS topic plus a subscription filtered to cluster
42 // monitoring/management events. Subscriptions are free and instant.
43 const created = yield* stack.deploy(
44 Effect.gen(function* () {
45 const topic = yield* SNS.Topic("Alerts", {});
46 return yield* EventSubscription("Events", {
47 snsTopicArn: topic.topicArn,
48 sourceType: "cluster",
49 eventCategories: ["monitoring", "management"],
50 severity: "INFO",
51 tags: { fixture: "redshift-event-subscription" },
52 });
53 }),
54 );
55
56 expect(created.subscriptionName).toBeDefined();
57 expect(created.eventSubscriptionArn).toContain(":eventsubscription:");
58 expect(created.sourceType).toBe("cluster");
59 expect([...created.eventCategories].sort()).toEqual(["management", "monitoring"]);
60 expect(created.severity).toBe("INFO");
61 expect(created.enabled).toBe(true);
62 expect(created.snsTopicArn).toContain(":sns:");
63
64 // Out-of-band verification via distilled.
65 const observed = yield* readSubscription(created.subscriptionName);
66 expect(observed?.Status).toBe("active");
67 expect(observed?.SourceType).toBe("cluster");
68 expect(
69 observed?.Tags?.some(
70 (t) => t.Key === "fixture" && t.Value === "redshift-event-subscription",
71 ),
72 ).toBe(true);
73
74 // Update — narrow the categories, flip severity, disable delivery.
75 // Same name, so it must modify in place.
76 const updated = yield* stack.deploy(
77 Effect.gen(function* () {
78 const topic = yield* SNS.Topic("Alerts", {});
79 return yield* EventSubscription("Events", {
80 snsTopicArn: topic.topicArn,
81 sourceType: "cluster",
82 eventCategories: ["monitoring"],
83 severity: "ERROR",
84 enabled: false,
85 tags: { fixture: "redshift-event-subscription" },
86 });
87 }),
88 );
89
90 expect(updated.subscriptionName).toBe(created.subscriptionName);
91 expect(updated.eventCategories).toEqual(["monitoring"]);
92 expect(updated.severity).toBe("ERROR");
93 expect(updated.enabled).toBe(false);
94
95 const reobserved = yield* readSubscription(created.subscriptionName);
96 expect(reobserved?.EventCategoriesList).toEqual(["monitoring"]);
97 expect(reobserved?.Severity).toBe("ERROR");
98 expect(reobserved?.Enabled).toBe(false);
99
100 // Destroy and verify gone with the typed not-found tag.
101 yield* stack.destroy();
102 const error = yield* Effect.flip(
103 redshift.describeEventSubscriptions({
104 SubscriptionName: created.subscriptionName,
105 }),
106 );
107 expect(error._tag).toBe("SubscriptionNotFoundFault");
108 }),
109 {
110 tags: ["provider:aws", "provider:aws:redshift", "provider:aws:sns", "live"],
111 timeout: 180_000,
112 },
113 );