The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Namespace, Workgroup } from "@alchemy.run/aws/RedshiftServerless"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as redshiftserverless from "@distilled.cloud/aws/redshift-serverless"; |
| 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 error union carries the |
| 12 | // not-found tag the providers' observe/read/delete paths depend on. |
| 13 | test.provider( |
| 14 | "getWorkgroup on a nonexistent workgroup fails with ResourceNotFoundException", |
| 15 | () => |
| 16 | Effect.gen(function* () { |
| 17 | const error = yield* Effect.flip( |
| 18 | redshiftserverless.getWorkgroup({ workgroupName: "alchemy-nonexistent-probe-wg" }), |
| 19 | ); |
| 20 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 21 | }), |
| 22 | { tags: ["provider:aws", "provider:aws:redshiftserverless", "live"] }, |
| 23 | ); |
| 24 | |
| 25 | test.provider( |
| 26 | "getNamespace on a nonexistent namespace fails with ResourceNotFoundException", |
| 27 | () => |
| 28 | Effect.gen(function* () { |
| 29 | const error = yield* Effect.flip( |
| 30 | redshiftserverless.getNamespace({ namespaceName: "alchemy-nonexistent-probe-ns" }), |
| 31 | ); |
| 32 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 33 | }), |
| 34 | { tags: ["provider:aws", "provider:aws:redshiftserverless", "live"] }, |
| 35 | ); |
| 36 | |
| 37 | const assertNamespaceGone = (name: string) => |
| 38 | Effect.gen(function* () { |
| 39 | const status = yield* redshiftserverless.getNamespace({ namespaceName: name }).pipe( |
| 40 | Effect.map((r) => (r.namespace?.status ?? "UNKNOWN").toUpperCase()), |
| 41 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed("GONE" as const)), |
| 42 | ); |
| 43 | if (status !== "GONE") { |
| 44 | return yield* Effect.fail(new Error(`Redshift namespace still exists (status: ${status})`)); |
| 45 | } |
| 46 | }).pipe( |
| 47 | Effect.retry({ schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(24)]) }), |
| 48 | ); |
| 49 | |
| 50 | const assertWorkgroupGone = (name: string) => |
| 51 | Effect.gen(function* () { |
| 52 | const status = yield* redshiftserverless.getWorkgroup({ workgroupName: name }).pipe( |
| 53 | Effect.map((r) => (r.workgroup?.status ?? "UNKNOWN").toUpperCase()), |
| 54 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed("GONE" as const)), |
| 55 | ); |
| 56 | if (status !== "GONE") { |
| 57 | return yield* Effect.fail(new Error(`Redshift workgroup still exists (status: ${status})`)); |
| 58 | } |
| 59 | }).pipe( |
| 60 | Effect.retry({ schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(24)]) }), |
| 61 | ); |
| 62 | |
| 63 | // A namespace is cheap but a workgroup bills against its RPU floor while it |
| 64 | // exists, so the full lifecycle is skipped under `--fast` and always |
| 65 | // destroys immediately (workgroup, then namespace). |
| 66 | test.provider.skipIf(!!process.env.FAST)( |
| 67 | "create a namespace + minimal workgroup, verify AVAILABLE, destroy, verify gone", |
| 68 | (stack) => |
| 69 | Effect.gen(function* () { |
| 70 | // Clean slate in case a previous run died mid-flight. |
| 71 | yield* stack.destroy(); |
| 72 | |
| 73 | const { namespace, workgroup } = yield* stack.deploy( |
| 74 | Effect.gen(function* () { |
| 75 | const namespace = yield* Namespace("AnalyticsNamespace", { |
| 76 | namespaceName: "alchemy-test-rs-lifecycle-ns", |
| 77 | dbName: "dev", |
| 78 | adminUsername: "alchemyadmin", |
| 79 | manageAdminPassword: true, |
| 80 | }); |
| 81 | const workgroup = yield* Workgroup("AnalyticsWorkgroup", { |
| 82 | workgroupName: "alchemy-test-rs-lifecycle-wg", |
| 83 | namespaceName: namespace.namespaceName, |
| 84 | baseCapacity: 8, |
| 85 | publiclyAccessible: false, |
| 86 | }); |
| 87 | return { namespace, workgroup }; |
| 88 | }), |
| 89 | ); |
| 90 | |
| 91 | expect(namespace.namespaceName).toBe("alchemy-test-rs-lifecycle-ns"); |
| 92 | expect(namespace.namespaceArn).toContain(":namespace/"); |
| 93 | expect(namespace.status.toUpperCase()).toBe("AVAILABLE"); |
| 94 | // manageAdminPassword => a Secrets Manager secret is provisioned. |
| 95 | expect(namespace.adminPasswordSecretArn).toBeDefined(); |
| 96 | |
| 97 | expect(workgroup.workgroupName).toBe("alchemy-test-rs-lifecycle-wg"); |
| 98 | expect(workgroup.workgroupArn).toContain(":workgroup/"); |
| 99 | expect(workgroup.status.toUpperCase()).toBe("AVAILABLE"); |
| 100 | expect(workgroup.endpointAddress).toBeDefined(); |
| 101 | expect(workgroup.endpointPort).toBe(5439); |
| 102 | expect(workgroup.publiclyAccessible).toBe(false); |
| 103 | |
| 104 | // Out-of-band verification via distilled. |
| 105 | const observedWg = yield* redshiftserverless.getWorkgroup({ |
| 106 | workgroupName: workgroup.workgroupName, |
| 107 | }); |
| 108 | expect(observedWg.workgroup?.status?.toUpperCase()).toBe("AVAILABLE"); |
| 109 | expect(observedWg.workgroup?.baseCapacity).toBe(8); |
| 110 | expect(observedWg.workgroup?.namespaceName).toBe(namespace.namespaceName); |
| 111 | |
| 112 | const observedNs = yield* redshiftserverless.getNamespace({ |
| 113 | namespaceName: namespace.namespaceName, |
| 114 | }); |
| 115 | expect(observedNs.namespace?.status?.toUpperCase()).toBe("AVAILABLE"); |
| 116 | |
| 117 | // Destroy immediately — a running workgroup bills its RPU floor. |
| 118 | yield* stack.destroy(); |
| 119 | yield* assertWorkgroupGone(workgroup.workgroupName); |
| 120 | yield* assertNamespaceGone(namespace.namespaceName); |
| 121 | }), |
| 122 | // namespace (~1 min) + workgroup create (~2-5 min) + delete (~3-5 min). |
| 123 | { tags: ["provider:aws", "provider:aws:redshiftserverless", "live"], timeout: 1_200_000 }, |
| 124 | ); |