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

main
ts 127 lines 4.8 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Configuration } from "@alchemy.run/aws/MQ";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as mq from "@distilled.cloud/aws/mq";
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 probes: prove the distilled MQ error union carries the
12 // not-found tag the providers' observe/read/delete paths depend on.
13 test.provider(
14 "describeBroker on a nonexistent broker fails with NotFoundException",
15 () =>
16 Effect.gen(function* () {
17 const error = yield* Effect.flip(
18 mq.describeBroker({ BrokerId: "b-00000000-0000-0000-0000-000000000000" }),
19 );
20 expect(error._tag).toBe("NotFoundException");
21 }),
22 { tags: ["provider:aws", "provider:aws:mq", "live"] },
23 );
24
25 test.provider(
26 "describeConfiguration on a nonexistent configuration fails with NotFoundException",
27 () =>
28 Effect.gen(function* () {
29 const error = yield* Effect.flip(
30 mq.describeConfiguration({ ConfigurationId: "c-00000000-0000-0000-0000-000000000000" }),
31 );
32 expect(error._tag).toBe("NotFoundException");
33 }),
34 { tags: ["provider:aws", "provider:aws:mq", "live"] },
35 );
36
37 const assertConfigurationGone = (configurationId: string) =>
38 Effect.gen(function* () {
39 const status = yield* mq.describeConfiguration({ ConfigurationId: configurationId }).pipe(
40 Effect.map(() => "PRESENT" as const),
41 Effect.catchTag("NotFoundException", () => Effect.succeed("GONE" as const)),
42 );
43 if (status !== "GONE") {
44 return yield* Effect.fail(new Error(`MQ configuration ${configurationId} still exists`));
45 }
46 }).pipe(
47 Effect.retry({ schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]) }),
48 );
49
50 const configDataV1 = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
51 <broker xmlns="http://activemq.apache.org/schema/core">
52 <destinationPolicy>
53 <policyMap>
54 <policyEntries>
55 <policyEntry topic=">">
56 <pendingMessageLimitStrategy>
57 <constantPendingMessageLimitStrategy limit="1000"/>
58 </pendingMessageLimitStrategy>
59 </policyEntry>
60 </policyEntries>
61 </policyMap>
62 </destinationPolicy>
63 </broker>
64 `;
65
66 const configDataV2 = configDataV1.replace('limit="1000"', 'limit="2000"');
67
68 // A configuration is cheap and fast (no broker provisioning), so the full
69 // lifecycle runs ungated: create publishes revision 2 (custom data over the
70 // engine default), a data change publishes revision 3, then destroy.
71 test.provider(
72 "create an ActiveMQ configuration, publish revisions on data change, destroy",
73 (stack) =>
74 Effect.gen(function* () {
75 yield* stack.destroy();
76
77 // Pick a valid ActiveMQ engine version from the live API so the test
78 // never breaks when AWS retires a hardcoded version.
79 const engines = yield* mq.describeBrokerEngineTypes({ EngineType: "ACTIVEMQ" });
80 const engineVersion = engines.BrokerEngineTypes?.[0]?.EngineVersions?.[0]?.Name;
81 expect(engineVersion).toBeDefined();
82
83 const created = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* Configuration("BrokerConfig", {
86 engineType: "ACTIVEMQ",
87 engineVersion,
88 description: "alchemy test config",
89 data: configDataV1,
90 tags: { team: "messaging" },
91 });
92 }),
93 );
94
95 expect(created.configurationArn).toContain(":configuration:");
96 // MQ echoes the display casing ("ActiveMQ") rather than the request enum.
97 expect(created.engineType.toUpperCase()).toBe("ACTIVEMQ");
98 // createConfiguration seeds revision 1; publishing custom data -> 2.
99 expect(created.configurationRevision).toBeGreaterThanOrEqual(2);
100
101 // Out-of-band verification via distilled.
102 const observed = yield* mq.describeConfiguration({
103 ConfigurationId: created.configurationId,
104 });
105 expect(observed.Name).toBe(created.configurationName);
106 expect(observed.Tags?.team).toBe("messaging");
107
108 // A data change publishes a new revision.
109 const updated = yield* stack.deploy(
110 Effect.gen(function* () {
111 return yield* Configuration("BrokerConfig", {
112 engineType: "ACTIVEMQ",
113 engineVersion,
114 description: "alchemy test config v2",
115 data: configDataV2,
116 tags: { team: "messaging" },
117 });
118 }),
119 );
120 expect(updated.configurationId).toBe(created.configurationId);
121 expect(updated.configurationRevision).toBeGreaterThan(created.configurationRevision);
122
123 yield* stack.destroy();
124 yield* assertConfigurationGone(created.configurationId);
125 }),
126 { tags: ["provider:aws", "provider:aws:mq", "live"], timeout: 180_000 },
127 );