| 1 | import * as AWS from "@/AWS"; |
| 2 | import { Broker } from "@/AWS/MQ"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import * as mq from "@distilled.cloud/aws/mq"; |
| 5 | import { expect } from "alchemy-test"; |
| 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({ |
| 20 | BrokerId: "b-00000000-0000-0000-0000-000000000000", |
| 21 | }), |
| 22 | ); |
| 23 | expect(error._tag).toBe("NotFoundException"); |
| 24 | }), |
| 25 | { tags: ["provider:aws", "provider:aws:mq", "live"] }, |
| 26 | ); |
| 27 | |
| 28 | const assertBrokerGone = (brokerId: string) => |
| 29 | Effect.gen(function* () { |
| 30 | const status = yield* mq.describeBroker({ BrokerId: brokerId }).pipe( |
| 31 | Effect.map((r) => r.BrokerState ?? "UNKNOWN"), |
| 32 | Effect.catchTag("NotFoundException", () => |
| 33 | Effect.succeed("GONE" as const), |
| 34 | ), |
| 35 | ); |
| 36 | if (status !== "GONE") { |
| 37 | return yield* Effect.fail( |
| 38 | new Error(`MQ broker still exists (state: ${status})`), |
| 39 | ); |
| 40 | } |
| 41 | }).pipe( |
| 42 | Effect.retry({ |
| 43 | schedule: Schedule.max([ |
| 44 | Schedule.fixed("10 seconds"), |
| 45 | Schedule.recurs(30), |
| 46 | ]), |
| 47 | }), |
| 48 | ); |
| 49 | |
| 50 | // A broker bills per instance-hour and takes 5-10 min to provision, so the |
| 51 | // full lifecycle is gated behind AWS_TEST_SLOW=1 and always destroys. A |
| 52 | // single-instance mq.t3.micro ActiveMQ broker is the cheapest topology; with |
| 53 | // SubnetIds omitted, Amazon MQ places it in a default-VPC subnet. |
| 54 | test.provider.skipIf(!process.env.AWS_TEST_SLOW)( |
| 55 | "create a single-instance ActiveMQ broker, verify RUNNING, destroy, verify gone", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | yield* stack.destroy(); |
| 59 | |
| 60 | const engines = yield* mq.describeBrokerEngineTypes({ |
| 61 | EngineType: "ACTIVEMQ", |
| 62 | }); |
| 63 | const engineVersion = |
| 64 | engines.BrokerEngineTypes?.[0]?.EngineVersions?.[0]?.Name; |
| 65 | expect(engineVersion).toBeDefined(); |
| 66 | |
| 67 | const broker = yield* stack.deploy( |
| 68 | Effect.gen(function* () { |
| 69 | return yield* Broker("Orders", { |
| 70 | brokerName: "alchemy-test-mq-broker", |
| 71 | engineType: "ACTIVEMQ", |
| 72 | engineVersion, |
| 73 | hostInstanceType: "mq.t3.micro", |
| 74 | deploymentMode: "SINGLE_INSTANCE", |
| 75 | publiclyAccessible: true, |
| 76 | users: [ |
| 77 | { |
| 78 | username: "alchemyadmin", |
| 79 | password: Redacted.make("SuperSecretPassw0rd!"), |
| 80 | }, |
| 81 | ], |
| 82 | tags: { team: "messaging" }, |
| 83 | }); |
| 84 | }), |
| 85 | ); |
| 86 | |
| 87 | expect(broker.brokerName).toBe("alchemy-test-mq-broker"); |
| 88 | expect(broker.brokerArn).toContain(":broker:"); |
| 89 | expect(broker.brokerState).toBe("RUNNING"); |
| 90 | expect(broker.endpoints).toBeDefined(); |
| 91 | expect(broker.endpoints!.length).toBeGreaterThan(0); |
| 92 | |
| 93 | // Out-of-band verification via distilled. |
| 94 | const observed = yield* mq.describeBroker({ BrokerId: broker.brokerId }); |
| 95 | expect(observed.BrokerState).toBe("RUNNING"); |
| 96 | // MQ may echo the display casing ("ActiveMQ") rather than the request enum. |
| 97 | expect(observed.EngineType?.toUpperCase()).toBe("ACTIVEMQ"); |
| 98 | expect(observed.HostInstanceType).toBe("mq.t3.micro"); |
| 99 | expect(observed.DeploymentMode).toBe("SINGLE_INSTANCE"); |
| 100 | expect(observed.Tags?.team).toBe("messaging"); |
| 101 | |
| 102 | // Destroy immediately — a running broker bills per instance-hour. |
| 103 | yield* stack.destroy(); |
| 104 | yield* assertBrokerGone(broker.brokerId); |
| 105 | }), |
| 106 | // create (~5-10 min) + delete (~3-5 min) + poll budget. |
| 107 | { tags: ["provider:aws", "provider:aws:mq", "live"], timeout: 1_200_000 }, |
| 108 | ); |