@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 110 lines 4.51 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { ConfigurationSet, EventDestination } from "@alchemy.run/aws/PinpointSMSVoiceV2";
3 import { Topic } from "@alchemy.run/aws/SNS";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as smsvoice from "@distilled.cloud/aws/pinpoint-sms-voice-v2";
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 const configSetName = "alchemy-test-smsvoice-event-dest-cs";
13
14 const getConfigSet = (name: string) =>
15 smsvoice.describeConfigurationSets({ ConfigurationSetNames: [name] }).pipe(
16 Effect.map((r) => r.ConfigurationSets?.[0]),
17 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
18 );
19
20 const assertConfigSetGone = (name: string) =>
21 Effect.gen(function* () {
22 const found = yield* getConfigSet(name);
23 if (found !== undefined) {
24 return yield* Effect.fail(new Error(`configuration set '${name}' still exists`));
25 }
26 }).pipe(
27 Effect.retry({
28 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]),
29 }),
30 );
31
32 // Configuration sets, SNS topics, and event destinations are all free and
33 // provision synchronously — the full lifecycle runs ungated.
34 test.provider(
35 "create, update, and destroy an SNS event destination",
36 (stack) =>
37 Effect.gen(function* () {
38 yield* stack.destroy();
39
40 const program = (types: string[], enabled?: boolean) =>
41 Effect.gen(function* () {
42 // Grant End User Messaging SMS permission to publish events.
43 const topic = yield* Topic("Events", {
44 attributes: {
45 Policy: JSON.stringify({
46 Version: "2012-10-17",
47 Statement: [
48 {
49 Effect: "Allow",
50 Principal: { Service: "sms-voice.amazonaws.com" },
51 Action: "sns:Publish",
52 Resource: "*",
53 },
54 ],
55 }),
56 },
57 });
58 const configSet = yield* ConfigurationSet("Config", {
59 configurationSetName: configSetName,
60 });
61 const destination = yield* EventDestination("Dest", {
62 configurationSetName: configSet.configurationSetName,
63 eventDestinationName: "alchemy-test-smsvoice-event-dest",
64 matchingEventTypes: types,
65 ...(enabled === undefined ? {} : { enabled }),
66 snsDestination: { topicArn: topic.topicArn },
67 });
68 return { topic, configSet, destination };
69 });
70
71 // Create.
72 const created = yield* stack.deploy(program(["ALL"]));
73 expect(created.destination.configurationSetName).toBe(configSetName);
74 expect(created.destination.eventDestinationName).toBe("alchemy-test-smsvoice-event-dest");
75 expect(created.destination.enabled).toBe(true);
76 expect(created.destination.matchingEventTypes).toEqual(["ALL"]);
77
78 // Out-of-band verification via distilled.
79 const observedSet = yield* getConfigSet(configSetName);
80 const observed = observedSet?.EventDestinations?.find(
81 (ed) => ed.EventDestinationName === "alchemy-test-smsvoice-event-dest",
82 );
83 expect(observed?.Enabled).toBe(true);
84 expect([...(observed?.MatchingEventTypes ?? [])]).toEqual(["ALL"]);
85 expect(observed?.SnsDestination?.TopicArn).toBe(created.topic.topicArn);
86
87 // No-op redeploy keeps the same destination.
88 const noop = yield* stack.deploy(program(["ALL"]));
89 expect(noop.destination.configurationSetArn).toBe(created.destination.configurationSetArn);
90
91 // Update in place — narrow the event types and disable delivery.
92 const updated = yield* stack.deploy(program(["TEXT_ALL"], false));
93 expect(updated.destination.enabled).toBe(false);
94 expect(updated.destination.matchingEventTypes).toEqual(["TEXT_ALL"]);
95 const reobservedSet = yield* getConfigSet(configSetName);
96 const reobserved = reobservedSet?.EventDestinations?.find(
97 (ed) => ed.EventDestinationName === "alchemy-test-smsvoice-event-dest",
98 );
99 expect(reobserved?.Enabled).toBe(false);
100 expect([...(reobserved?.MatchingEventTypes ?? [])]).toEqual(["TEXT_ALL"]);
101
102 // Destroy and verify out-of-band with a typed wait-until-gone.
103 yield* stack.destroy();
104 yield* assertConfigSetGone(configSetName);
105 }),
106 {
107 tags: ["provider:aws", "provider:aws:pinpointsmsvoicev2", "provider:aws:sns", "live"],
108 timeout: 240_000,
109 },
110 );