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 { AWSEnvironment } from "@alchemy.run/aws/Environment"; |
| 3 | import { describe, expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as Core from "@alchemy.run/test/Core"; |
| 6 | import * as quicksight from "@distilled.cloud/aws/quicksight"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as HttpClient from "effect/http/HttpClient"; |
| 9 | import * as Schedule from "effect/Schedule"; |
| 10 | import QuickSightBindingsFunctionLive, { QuickSightBindingsFunction } from "./bindings-handler"; |
| 11 | |
| 12 | const testOptions = { providers: AWS.providers() }; |
| 13 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 14 | |
| 15 | // The testing account has no QuickSight subscription, so the live Lambda E2E |
| 16 | // (which needs a real data source + dataset + dashboard) is gated behind |
| 17 | // AWS_TEST_QUICKSIGHT=1 for entitled accounts. The ungated probes below prove |
| 18 | // the typed error unions the bindings depend on, on every account. |
| 19 | const SUBSCRIBED = !!process.env.AWS_TEST_QUICKSIGHT; |
| 20 | |
| 21 | // Ungated typed-error probes. |
| 22 | test.provider( |
| 23 | "createIngestion on a nonexistent dataset fails with a typed tag", |
| 24 | () => |
| 25 | Effect.gen(function* () { |
| 26 | const { accountId } = yield* AWSEnvironment.current; |
| 27 | const error = yield* Effect.flip( |
| 28 | quicksight.createIngestion({ |
| 29 | AwsAccountId: accountId, |
| 30 | DataSetId: "alchemy-nonexistent-quicksight-dataset-probe", |
| 31 | IngestionId: "alchemy-quicksight-ingestion-probe", |
| 32 | }), |
| 33 | ); |
| 34 | expect([ |
| 35 | "ResourceNotFoundException", |
| 36 | "InvalidParameterValueException", |
| 37 | "AccessDeniedException", |
| 38 | ]).toContain(error._tag); |
| 39 | }), |
| 40 | { tags: ["provider:aws", "provider:aws:quicksight", "live"], timeout: 60_000 }, |
| 41 | ); |
| 42 | |
| 43 | test.provider( |
| 44 | "generateEmbedUrlForRegisteredUser for a nonexistent user fails with a typed tag", |
| 45 | () => |
| 46 | Effect.gen(function* () { |
| 47 | const { accountId, region } = yield* AWSEnvironment.current; |
| 48 | const error = yield* Effect.flip( |
| 49 | quicksight.generateEmbedUrlForRegisteredUser({ |
| 50 | AwsAccountId: accountId, |
| 51 | UserArn: `arn:aws:quicksight:${region}:${accountId}:user/default/alchemy-nonexistent-user-probe`, |
| 52 | ExperienceConfiguration: { |
| 53 | Dashboard: { InitialDashboardId: "alchemy-nonexistent-dashboard-probe" }, |
| 54 | }, |
| 55 | }), |
| 56 | ); |
| 57 | expect([ |
| 58 | "QuickSightUserNotFoundException", |
| 59 | "ResourceNotFoundException", |
| 60 | "InvalidParameterValueException", |
| 61 | "AccessDeniedException", |
| 62 | "UnsupportedUserEditionException", |
| 63 | ]).toContain(error._tag); |
| 64 | }), |
| 65 | { tags: ["provider:aws", "provider:aws:quicksight", "live"], timeout: 60_000 }, |
| 66 | ); |
| 67 | |
| 68 | test.provider( |
| 69 | "describeDashboardSnapshotJob on a nonexistent dashboard fails with a typed tag", |
| 70 | () => |
| 71 | Effect.gen(function* () { |
| 72 | const { accountId } = yield* AWSEnvironment.current; |
| 73 | const error = yield* Effect.flip( |
| 74 | quicksight.describeDashboardSnapshotJob({ |
| 75 | AwsAccountId: accountId, |
| 76 | DashboardId: "alchemy-nonexistent-quicksight-dashboard-probe", |
| 77 | SnapshotJobId: "alchemy-nonexistent-snapshot-job-probe", |
| 78 | }), |
| 79 | ); |
| 80 | expect([ |
| 81 | "ResourceNotFoundException", |
| 82 | "InvalidParameterValueException", |
| 83 | "AccessDeniedException", |
| 84 | "UnsupportedUserEditionException", |
| 85 | ]).toContain(error._tag); |
| 86 | }), |
| 87 | { tags: ["provider:aws", "provider:aws:quicksight", "live"], timeout: 60_000 }, |
| 88 | ); |
| 89 | |
| 90 | const sharedStack = Core.scratchStack(testOptions, "QuickSightBindings"); |
| 91 | |
| 92 | let baseUrl: string; |
| 93 | |
| 94 | const get = (path: string) => |
| 95 | HttpClient.get(`${baseUrl}${path}`).pipe(Effect.flatMap((r) => r.json)); |
| 96 | const post = (path: string) => |
| 97 | HttpClient.post(`${baseUrl}${path}`).pipe(Effect.flatMap((r) => r.json)); |
| 98 | |
| 99 | describe( |
| 100 | "QuickSight Bindings (E2E)", |
| 101 | { tags: ["provider:aws", "provider:aws:lambda", "provider:aws:quicksight", "live"] }, |
| 102 | () => { |
| 103 | beforeAll( |
| 104 | Effect.gen(function* () { |
| 105 | if (!SUBSCRIBED) return; |
| 106 | yield* Effect.logInfo("QuickSight E2E setup: destroying previous run"); |
| 107 | yield* sharedStack.destroy(); |
| 108 | |
| 109 | yield* Effect.logInfo( |
| 110 | "QuickSight E2E setup: deploying data source + dataset + dashboard + Lambda", |
| 111 | ); |
| 112 | const { functionUrl } = yield* sharedStack.deploy( |
| 113 | Effect.gen(function* () { |
| 114 | return yield* QuickSightBindingsFunction; |
| 115 | }).pipe(Effect.provide(QuickSightBindingsFunctionLive)), |
| 116 | ); |
| 117 | |
| 118 | expect(functionUrl).toBeTruthy(); |
| 119 | baseUrl = functionUrl!.replace(/\/+$/, ""); |
| 120 | |
| 121 | // Readiness probe — fresh function URLs take seconds to serve 200s. |
| 122 | yield* HttpClient.get(`${baseUrl}/bindings`).pipe( |
| 123 | Effect.flatMap((response) => |
| 124 | response.status === 200 |
| 125 | ? Effect.succeed(response) |
| 126 | : Effect.fail(new Error(`Function not ready: ${response.status}`)), |
| 127 | ), |
| 128 | Effect.retry({ |
| 129 | schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(60)]), |
| 130 | }), |
| 131 | ); |
| 132 | }), |
| 133 | { timeout: 300_000 }, |
| 134 | ); |
| 135 | afterAll( |
| 136 | Effect.gen(function* () { |
| 137 | if (!SUBSCRIBED) return; |
| 138 | yield* sharedStack.destroy(); |
| 139 | }), |
| 140 | { timeout: 300_000 }, |
| 141 | ); |
| 142 | |
| 143 | test.provider.skipIf(!SUBSCRIBED)("all 9 capabilities initialize in the runtime", () => |
| 144 | Effect.gen(function* () { |
| 145 | const response = (yield* get("/bindings")) as any; |
| 146 | expect(response.bound).toHaveLength(9); |
| 147 | }), |
| 148 | ); |
| 149 | |
| 150 | test.provider.skipIf(!SUBSCRIBED)( |
| 151 | "ListIngestions reads the bound dataset's refresh history", |
| 152 | () => |
| 153 | Effect.gen(function* () { |
| 154 | const response = (yield* get("/ingestions")) as any; |
| 155 | expect(typeof response.count).toBe("number"); |
| 156 | }), |
| 157 | ); |
| 158 | |
| 159 | test.provider.skipIf(!SUBSCRIBED)( |
| 160 | "CreateIngestion + DescribeIngestion + CancelIngestion round-trip", |
| 161 | () => |
| 162 | Effect.gen(function* () { |
| 163 | const response = (yield* post("/ingestion")) as any; |
| 164 | // DIRECT_QUERY dataset → typed 400; SPICE dataset → started + status. |
| 165 | if (response.started) { |
| 166 | expect(typeof response.id).toBe("string"); |
| 167 | } else { |
| 168 | expect(["InvalidParameterValueException", "ResourceNotFoundException"]).toContain( |
| 169 | response.error, |
| 170 | ); |
| 171 | } |
| 172 | }), |
| 173 | ); |
| 174 | |
| 175 | test.provider.skipIf(!SUBSCRIBED)( |
| 176 | "snapshot-job describe bindings surface the typed not-found", |
| 177 | () => |
| 178 | Effect.gen(function* () { |
| 179 | const response = (yield* get("/snapshot-job/typed-not-found")) as any; |
| 180 | expect(response.describe).toBe(true); |
| 181 | expect(response.result).toBe(true); |
| 182 | }), |
| 183 | ); |
| 184 | |
| 185 | test.provider.skipIf(!SUBSCRIBED)( |
| 186 | "StartDashboardSnapshotJob starts (or typed-rejects) a PDF export", |
| 187 | () => |
| 188 | Effect.gen(function* () { |
| 189 | const response = (yield* post("/snapshot-job")) as any; |
| 190 | if (response.started) { |
| 191 | expect(typeof response.jobId).toBe("string"); |
| 192 | } else { |
| 193 | expect(typeof response.error).toBe("string"); |
| 194 | } |
| 195 | }), |
| 196 | ); |
| 197 | |
| 198 | test.provider.skipIf(!SUBSCRIBED)( |
| 199 | "embed-URL bindings reach the API with the injected account id", |
| 200 | () => |
| 201 | Effect.gen(function* () { |
| 202 | const registered = (yield* get("/embed-url")) as any; |
| 203 | expect(typeof registered.typed).toBe("string"); |
| 204 | const anonymous = (yield* get("/embed-url-anon")) as any; |
| 205 | expect(anonymous.ok === true || typeof anonymous.error === "string").toBe(true); |
| 206 | }), |
| 207 | ); |
| 208 | }, |
| 209 | ); |