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

main
ts 113 lines 4.41 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { ConfigurationSet } from "@alchemy.run/aws/PinpointSMSVoiceV2";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as smsvoice from "@distilled.cloud/aws/pinpoint-sms-voice-v2";
6 import * as Effect from "effect/Effect";
7 import * as Schedule from "effect/Schedule";
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/observe paths depend on.
13 test.provider(
14 "describeConfigurationSets on a nonexistent name fails with ResourceNotFoundException",
15 () =>
16 Effect.gen(function* () {
17 const error = yield* Effect.flip(
18 smsvoice.describeConfigurationSets({
19 ConfigurationSetNames: ["alchemy-nonexistent-config-set-probe"],
20 }),
21 );
22 expect(error._tag).toBe("ResourceNotFoundException");
23 }),
24 {
25 tags: ["provider:aws", "provider:aws:pinpointsmsvoicev2", "live"],
26 timeout: 60_000,
27 },
28 );
29
30 const getConfigSet = (name: string) =>
31 smsvoice.describeConfigurationSets({ ConfigurationSetNames: [name] }).pipe(
32 Effect.map((r) => r.ConfigurationSets?.[0]),
33 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
34 );
35
36 const assertConfigSetGone = (name: string) =>
37 Effect.gen(function* () {
38 const found = yield* getConfigSet(name);
39 if (found !== undefined) {
40 return yield* Effect.fail(new Error(`configuration set '${name}' still exists`));
41 }
42 }).pipe(
43 Effect.retry({
44 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]),
45 }),
46 );
47
48 // Configuration sets are free and provision synchronously — the full
49 // lifecycle (create, no-op, update-in-place, destroy) runs ungated.
50 test.provider(
51 "create, update, and destroy a configuration set",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const props = {
57 configurationSetName: "alchemy-test-smsvoice-config-set",
58 tags: { fixture: "smsvoice-config-set" },
59 };
60
61 // Create.
62 const created = yield* stack.deploy(ConfigurationSet("Config", props));
63 expect(created.configurationSetName).toBe("alchemy-test-smsvoice-config-set");
64 expect(created.configurationSetArn).toContain(":configuration-set/");
65
66 // Out-of-band verification via distilled.
67 const observed = yield* getConfigSet(created.configurationSetName);
68 expect(observed?.ConfigurationSetName).toBe(created.configurationSetName);
69 expect(observed?.DefaultMessageType).toBeUndefined();
70 const tags = yield* smsvoice.listTagsForResource({
71 ResourceArn: created.configurationSetArn,
72 });
73 const tagRecord = Object.fromEntries((tags.Tags ?? []).map((t) => [t.Key, t.Value]));
74 expect(tagRecord.fixture).toBe("smsvoice-config-set");
75 expect(tagRecord["alchemy::id"]).toBe("Config");
76
77 // No-op redeploy keeps the same configuration set.
78 const noop = yield* stack.deploy(ConfigurationSet("Config", props));
79 expect(noop.configurationSetArn).toBe(created.configurationSetArn);
80
81 // Update in place — set a default message type and change a tag; the
82 // ARN must not change.
83 const updated = yield* stack.deploy(
84 ConfigurationSet("Config", {
85 ...props,
86 defaultMessageType: "TRANSACTIONAL",
87 tags: { fixture: "smsvoice-config-set-v2" },
88 }),
89 );
90 expect(updated.configurationSetArn).toBe(created.configurationSetArn);
91 const reobserved = yield* getConfigSet(created.configurationSetName);
92 expect(reobserved?.DefaultMessageType).toBe("TRANSACTIONAL");
93 const retags = yield* smsvoice.listTagsForResource({
94 ResourceArn: created.configurationSetArn,
95 });
96 expect(Object.fromEntries((retags.Tags ?? []).map((t) => [t.Key, t.Value])).fixture).toBe(
97 "smsvoice-config-set-v2",
98 );
99
100 // Removing the prop clears the default message type.
101 yield* stack.deploy(ConfigurationSet("Config", props));
102 const cleared = yield* getConfigSet(created.configurationSetName);
103 expect(cleared?.DefaultMessageType).toBeUndefined();
104
105 // Destroy and verify out-of-band with a typed wait-until-gone.
106 yield* stack.destroy();
107 yield* assertConfigSetGone(created.configurationSetName);
108 }),
109 {
110 tags: ["provider:aws", "provider:aws:pinpointsmsvoicev2", "live"],
111 timeout: 240_000,
112 },
113 );