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 { describe, expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Core from "@alchemy.run/test/Core"; |
| 5 | import * as glacier from "@distilled.cloud/aws/glacier"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as HttpClient from "effect/http/HttpClient"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import GlacierBindingsFunctionLive, { GlacierBindingsFunction } from "./bindings-handler"; |
| 10 | |
| 11 | const testOptions = { providers: AWS.providers() }; |
| 12 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 13 | |
| 14 | // The vault-based S3 Glacier API rejects accounts created after its 2025 |
| 15 | // closure to new customers with the typed NoLongerSupportedException (see |
| 16 | // the ungated probes below and in Vault.test.ts). The live Lambda E2E needs |
| 17 | // a real vault, so it is gated behind AWS_TEST_GLACIER=1 for entitled |
| 18 | // (grandfathered) accounts. |
| 19 | const RUN_LIVE = !!process.env.AWS_TEST_GLACIER; |
| 20 | |
| 21 | // Ungated typed-error probes: prove the distilled error unions the bindings |
| 22 | // depend on are typed on every account, entitled or not, at near-zero cost. |
| 23 | test.provider( |
| 24 | "listJobs on a nonexistent vault fails with a typed tag", |
| 25 | () => |
| 26 | Effect.gen(function* () { |
| 27 | const error = yield* Effect.flip( |
| 28 | glacier.listJobs({ accountId: "-", vaultName: "alchemy-nonexistent-glacier-vault-probe" }), |
| 29 | ); |
| 30 | expect(["ResourceNotFoundException", "NoLongerSupportedException"]).toContain(error._tag); |
| 31 | }), |
| 32 | { tags: ["provider:aws", "provider:aws:glacier", "live"] }, |
| 33 | ); |
| 34 | |
| 35 | test.provider( |
| 36 | "uploadArchive on a nonexistent vault fails with a typed tag", |
| 37 | () => |
| 38 | Effect.gen(function* () { |
| 39 | const error = yield* Effect.flip( |
| 40 | glacier.uploadArchive({ |
| 41 | accountId: "-", |
| 42 | vaultName: "alchemy-nonexistent-glacier-vault-probe", |
| 43 | body: "alchemy-glacier-probe", |
| 44 | }), |
| 45 | ); |
| 46 | expect([ |
| 47 | "ResourceNotFoundException", |
| 48 | "NoLongerSupportedException", |
| 49 | "MissingParameterValueException", |
| 50 | "InvalidParameterValueException", |
| 51 | ]).toContain(error._tag); |
| 52 | }), |
| 53 | { tags: ["provider:aws", "provider:aws:glacier", "live"] }, |
| 54 | ); |
| 55 | |
| 56 | const sharedStack = Core.scratchStack(testOptions, "GlacierBindings"); |
| 57 | |
| 58 | let baseUrl: string; |
| 59 | |
| 60 | const get = (path: string) => |
| 61 | HttpClient.get(`${baseUrl}${path}`).pipe(Effect.flatMap((r) => r.json)); |
| 62 | const post = (path: string) => |
| 63 | HttpClient.post(`${baseUrl}${path}`).pipe(Effect.flatMap((r) => r.json)); |
| 64 | |
| 65 | describe( |
| 66 | "Glacier Bindings (E2E)", |
| 67 | { tags: ["provider:aws", "provider:aws:glacier", "provider:aws:lambda", "live"] }, |
| 68 | () => { |
| 69 | beforeAll( |
| 70 | Effect.gen(function* () { |
| 71 | if (!RUN_LIVE) return; |
| 72 | yield* Effect.logInfo("Glacier E2E setup: destroying previous run"); |
| 73 | yield* sharedStack.destroy(); |
| 74 | |
| 75 | yield* Effect.logInfo("Glacier E2E setup: deploying vault + Lambda"); |
| 76 | const { functionUrl } = yield* sharedStack.deploy( |
| 77 | Effect.gen(function* () { |
| 78 | return yield* GlacierBindingsFunction; |
| 79 | }).pipe(Effect.provide(GlacierBindingsFunctionLive)), |
| 80 | ); |
| 81 | |
| 82 | expect(functionUrl).toBeTruthy(); |
| 83 | baseUrl = functionUrl!.replace(/\/+$/, ""); |
| 84 | |
| 85 | // Readiness probe — fresh function URLs take seconds to serve 200s. |
| 86 | yield* HttpClient.get(`${baseUrl}/bindings`).pipe( |
| 87 | Effect.flatMap((response) => |
| 88 | response.status === 200 |
| 89 | ? Effect.succeed(response) |
| 90 | : Effect.fail(new Error(`Function not ready: ${response.status}`)), |
| 91 | ), |
| 92 | Effect.retry({ |
| 93 | schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(60)]), |
| 94 | }), |
| 95 | ); |
| 96 | }), |
| 97 | { timeout: 300_000 }, |
| 98 | ); |
| 99 | afterAll( |
| 100 | Effect.gen(function* () { |
| 101 | if (!RUN_LIVE) return; |
| 102 | yield* sharedStack.destroy(); |
| 103 | }), |
| 104 | { timeout: 300_000 }, |
| 105 | ); |
| 106 | |
| 107 | test.provider.skipIf(!RUN_LIVE)("all 13 capabilities initialize in the runtime", () => |
| 108 | Effect.gen(function* () { |
| 109 | const response = (yield* get("/bindings")) as any; |
| 110 | expect(response.bound).toHaveLength(13); |
| 111 | }), |
| 112 | ); |
| 113 | |
| 114 | test.provider.skipIf(!RUN_LIVE)("DescribeVault reads the bound vault's stats", () => |
| 115 | Effect.gen(function* () { |
| 116 | const response = (yield* get("/vault")) as any; |
| 117 | expect(typeof response.vaultName).toBe("string"); |
| 118 | expect(response.numberOfArchives).toBe(0); |
| 119 | }), |
| 120 | ); |
| 121 | |
| 122 | test.provider.skipIf(!RUN_LIVE)( |
| 123 | "ListJobs + ListMultipartUploads round-trip against the empty vault", |
| 124 | () => |
| 125 | Effect.gen(function* () { |
| 126 | const jobs = (yield* get("/jobs")) as any; |
| 127 | expect(jobs.count).toBe(0); |
| 128 | const uploads = (yield* get("/uploads")) as any; |
| 129 | expect(uploads.count).toBe(0); |
| 130 | }), |
| 131 | ); |
| 132 | |
| 133 | test.provider.skipIf(!RUN_LIVE)( |
| 134 | "DescribeJob, GetJobOutput, and ListParts surface the typed not-found", |
| 135 | () => |
| 136 | Effect.gen(function* () { |
| 137 | const job = (yield* get("/jobs/typed-not-found")) as any; |
| 138 | expect(job.typed).toBe(true); |
| 139 | const output = (yield* get("/job-output/typed-not-found")) as any; |
| 140 | expect(output.typed).toBe(true); |
| 141 | const parts = (yield* get("/parts/typed-not-found")) as any; |
| 142 | expect(parts.typed).toBe(true); |
| 143 | }), |
| 144 | ); |
| 145 | |
| 146 | test.provider.skipIf(!RUN_LIVE)("multipart mutation bindings surface the typed not-found", () => |
| 147 | Effect.gen(function* () { |
| 148 | const response = (yield* post("/multipart/typed-not-found")) as any; |
| 149 | expect(response.upload).toBe(true); |
| 150 | expect(response.complete).toBe(true); |
| 151 | expect(response.abort).toBe(true); |
| 152 | }), |
| 153 | ); |
| 154 | |
| 155 | test.provider.skipIf(!RUN_LIVE)( |
| 156 | "DeleteArchive and UploadArchive round-trip typed rejections", |
| 157 | () => |
| 158 | Effect.gen(function* () { |
| 159 | const deleted = (yield* post("/archive/typed-not-found")) as any; |
| 160 | expect(deleted.typed).toBe(true); |
| 161 | // Wrong checksum — rejected before storing, vault stays deletable. |
| 162 | const uploaded = (yield* post("/archive/probe")) as any; |
| 163 | expect(uploaded.typed).toBe(true); |
| 164 | const multipart = (yield* post("/multipart/probe")) as any; |
| 165 | expect(multipart.typed).toBe(true); |
| 166 | }), |
| 167 | ); |
| 168 | |
| 169 | test.provider.skipIf(!RUN_LIVE)( |
| 170 | "InitiateJob starts (or typed-rejects) an inventory retrieval", |
| 171 | () => |
| 172 | Effect.gen(function* () { |
| 173 | const response = (yield* post("/jobs/inventory")) as any; |
| 174 | // A fresh vault has no inventory yet — either the job starts or the |
| 175 | // typed 400 comes back; both prove the grant end-to-end. |
| 176 | if (response.started) { |
| 177 | expect(typeof response.jobId).toBe("string"); |
| 178 | } else { |
| 179 | expect(["InvalidParameterValueException", "ResourceNotFoundException"]).toContain( |
| 180 | response.error, |
| 181 | ); |
| 182 | } |
| 183 | }), |
| 184 | ); |
| 185 | }, |
| 186 | ); |