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

main
ts 89 lines 3.72 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Broker } 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 Redacted from "effect/Redacted";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 // Ungated typed-error probe: proves the distilled MQ error union carries the
13 // not-found tag the provider's observe/read/delete paths depend on.
14 test.provider(
15 "describeBroker on a nonexistent broker fails with NotFoundException",
16 () =>
17 Effect.gen(function* () {
18 const error = yield* Effect.flip(
19 mq.describeBroker({ BrokerId: "b-00000000-0000-0000-0000-000000000000" }),
20 );
21 expect(error._tag).toBe("NotFoundException");
22 }),
23 { tags: ["provider:aws", "provider:aws:mq", "live"] },
24 );
25
26 const assertBrokerGone = (brokerId: string) =>
27 Effect.gen(function* () {
28 const status = yield* mq.describeBroker({ BrokerId: brokerId }).pipe(
29 Effect.map((r) => r.BrokerState ?? "UNKNOWN"),
30 Effect.catchTag("NotFoundException", () => Effect.succeed("GONE" as const)),
31 );
32 if (status !== "GONE") {
33 return yield* Effect.fail(new Error(`MQ broker still exists (state: ${status})`));
34 }
35 }).pipe(
36 Effect.retry({ schedule: Schedule.max([Schedule.fixed("10 seconds"), Schedule.recurs(30)]) }),
37 );
38
39 // A broker bills per instance-hour and takes 5-10 min to provision, so the
40 // full lifecycle is skipped under `--fast` and always destroys. A
41 // single-instance mq.t3.micro ActiveMQ broker is the cheapest topology; with
42 // SubnetIds omitted, Amazon MQ places it in a default-VPC subnet.
43 test.provider.skipIf(!!process.env.FAST)(
44 "create a single-instance ActiveMQ broker, verify RUNNING, destroy, verify gone",
45 (stack) =>
46 Effect.gen(function* () {
47 yield* stack.destroy();
48
49 const engines = yield* mq.describeBrokerEngineTypes({ EngineType: "ACTIVEMQ" });
50 const engineVersion = engines.BrokerEngineTypes?.[0]?.EngineVersions?.[0]?.Name;
51 expect(engineVersion).toBeDefined();
52
53 const broker = yield* stack.deploy(
54 Effect.gen(function* () {
55 return yield* Broker("Orders", {
56 brokerName: "alchemy-test-mq-broker",
57 engineType: "ACTIVEMQ",
58 engineVersion,
59 hostInstanceType: "mq.t3.micro",
60 deploymentMode: "SINGLE_INSTANCE",
61 publiclyAccessible: true,
62 users: [{ username: "alchemyadmin", password: Redacted.make("SuperSecretPassw0rd!") }],
63 tags: { team: "messaging" },
64 });
65 }),
66 );
67
68 expect(broker.brokerName).toBe("alchemy-test-mq-broker");
69 expect(broker.brokerArn).toContain(":broker:");
70 expect(broker.brokerState).toBe("RUNNING");
71 expect(broker.endpoints).toBeDefined();
72 expect(broker.endpoints!.length).toBeGreaterThan(0);
73
74 // Out-of-band verification via distilled.
75 const observed = yield* mq.describeBroker({ BrokerId: broker.brokerId });
76 expect(observed.BrokerState).toBe("RUNNING");
77 // MQ may echo the display casing ("ActiveMQ") rather than the request enum.
78 expect(observed.EngineType?.toUpperCase()).toBe("ACTIVEMQ");
79 expect(observed.HostInstanceType).toBe("mq.t3.micro");
80 expect(observed.DeploymentMode).toBe("SINGLE_INSTANCE");
81 expect(observed.Tags?.team).toBe("messaging");
82
83 // Destroy immediately — a running broker bills per instance-hour.
84 yield* stack.destroy();
85 yield* assertBrokerGone(broker.brokerId);
86 }),
87 // create (~5-10 min) + delete (~3-5 min) + poll budget.
88 { tags: ["provider:aws", "provider:aws:mq", "live"], timeout: 1_200_000 },
89 );