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 omics from "@distilled.cloud/aws/omics"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as HttpClient from "effect/http/HttpClient"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import OmicsBindingsFunctionLive, { OmicsBindingsFunction } from "./bindings-handler"; |
| 10 | |
| 11 | const testOptions = { providers: AWS.providers() }; |
| 12 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 13 | |
| 14 | // The live Lambda E2E provisions a SequenceStore + ReferenceStore + Lambda and |
| 15 | // exercises the runtime bindings end-to-end. It is gated behind AWS_TEST_OMICS |
| 16 | // (consistent with the async-provisioning lifecycles in Omics.test.ts). The |
| 17 | // ungated typed-error probes below prove the distilled error unions each |
| 18 | // binding depends on on every CI pass, entitled or not, at near-zero cost. |
| 19 | const RUN_LIVE = !!process.env.AWS_TEST_OMICS; |
| 20 | |
| 21 | // Ungated typed-error probes — import the distilled ops directly, so this |
| 22 | // green path never loads the alchemy Omics binding module. |
| 23 | test.provider( |
| 24 | "listReadSets on a nonexistent sequence store fails with a typed tag", |
| 25 | () => |
| 26 | Effect.gen(function* () { |
| 27 | const error = yield* Effect.flip(omics.listReadSets({ sequenceStoreId: "0000000000" })); |
| 28 | expect(["ResourceNotFoundException", "ValidationException"]).toContain(error._tag); |
| 29 | }), |
| 30 | { tags: ["provider:aws", "provider:aws:omics", "live"] }, |
| 31 | ); |
| 32 | |
| 33 | test.provider( |
| 34 | "getRun on a nonexistent id fails with a typed tag", |
| 35 | () => |
| 36 | Effect.gen(function* () { |
| 37 | const error = yield* Effect.flip(omics.getRun({ id: "0000000000" })); |
| 38 | expect(["ResourceNotFoundException", "ValidationException"]).toContain(error._tag); |
| 39 | }), |
| 40 | { tags: ["provider:aws", "provider:aws:omics", "live"] }, |
| 41 | ); |
| 42 | |
| 43 | test.provider( |
| 44 | "listReferences on a nonexistent reference store fails with a typed tag", |
| 45 | () => |
| 46 | Effect.gen(function* () { |
| 47 | const error = yield* Effect.flip(omics.listReferences({ referenceStoreId: "0000000000" })); |
| 48 | expect(["ResourceNotFoundException", "ValidationException"]).toContain(error._tag); |
| 49 | }), |
| 50 | { tags: ["provider:aws", "provider:aws:omics", "live"] }, |
| 51 | ); |
| 52 | |
| 53 | const sharedStack = Core.scratchStack(testOptions, "OmicsBindings"); |
| 54 | |
| 55 | let baseUrl: string; |
| 56 | |
| 57 | const get = (path: string) => |
| 58 | HttpClient.get(`${baseUrl}${path}`).pipe(Effect.flatMap((r) => r.json)); |
| 59 | |
| 60 | describe( |
| 61 | "Omics Bindings (E2E)", |
| 62 | { |
| 63 | tags: [ |
| 64 | "provider:aws", |
| 65 | "provider:aws:batch", |
| 66 | "provider:aws:lambda", |
| 67 | "provider:aws:omics", |
| 68 | "live", |
| 69 | ], |
| 70 | }, |
| 71 | () => { |
| 72 | beforeAll( |
| 73 | Effect.gen(function* () { |
| 74 | if (!RUN_LIVE) return; |
| 75 | yield* Effect.logInfo("Omics E2E setup: destroying previous run"); |
| 76 | yield* sharedStack.destroy(); |
| 77 | |
| 78 | yield* Effect.logInfo("Omics E2E setup: deploying stores + Lambda"); |
| 79 | const { functionUrl } = yield* sharedStack.deploy( |
| 80 | Effect.gen(function* () { |
| 81 | return yield* OmicsBindingsFunction; |
| 82 | }).pipe(Effect.provide(OmicsBindingsFunctionLive)), |
| 83 | ); |
| 84 | |
| 85 | expect(functionUrl).toBeTruthy(); |
| 86 | baseUrl = functionUrl!.replace(/\/+$/, ""); |
| 87 | |
| 88 | // Readiness probe — fresh function URLs take seconds to serve 200s. |
| 89 | yield* HttpClient.get(`${baseUrl}/bindings`).pipe( |
| 90 | Effect.flatMap((response) => |
| 91 | response.status === 200 |
| 92 | ? Effect.succeed(response) |
| 93 | : Effect.fail(new Error(`Function not ready: ${response.status}`)), |
| 94 | ), |
| 95 | Effect.retry({ |
| 96 | schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(60)]), |
| 97 | }), |
| 98 | ); |
| 99 | }), |
| 100 | { timeout: 300_000 }, |
| 101 | ); |
| 102 | afterAll( |
| 103 | Effect.gen(function* () { |
| 104 | if (!RUN_LIVE) return; |
| 105 | yield* sharedStack.destroy(); |
| 106 | }), |
| 107 | { timeout: 300_000 }, |
| 108 | ); |
| 109 | |
| 110 | test.provider.skipIf(!RUN_LIVE)("all 8 capabilities initialize in the runtime", () => |
| 111 | Effect.gen(function* () { |
| 112 | const response = (yield* get("/bindings")) as { bound: string[] }; |
| 113 | expect(response.bound).toHaveLength(8); |
| 114 | }), |
| 115 | ); |
| 116 | |
| 117 | test.provider.skipIf(!RUN_LIVE)( |
| 118 | "ListReadSets + ListReferences round-trip against the empty stores", |
| 119 | () => |
| 120 | Effect.gen(function* () { |
| 121 | const readSets = (yield* get("/readsets")) as { count: number }; |
| 122 | expect(readSets.count).toBe(0); |
| 123 | const references = (yield* get("/references")) as { count: number }; |
| 124 | expect(references.count).toBe(0); |
| 125 | }), |
| 126 | ); |
| 127 | |
| 128 | test.provider.skipIf(!RUN_LIVE)("ListRuns round-trips at the account level", () => |
| 129 | Effect.gen(function* () { |
| 130 | const runs = (yield* get("/runs")) as { count: number }; |
| 131 | expect(runs.count).toBeGreaterThanOrEqual(0); |
| 132 | }), |
| 133 | ); |
| 134 | |
| 135 | test.provider.skipIf(!RUN_LIVE)("GetReadSetMetadata + GetRun surface the typed not-found", () => |
| 136 | Effect.gen(function* () { |
| 137 | const readset = (yield* get("/readset/typed-not-found")) as { typed: boolean }; |
| 138 | expect(readset.typed).toBe(true); |
| 139 | const run = (yield* get("/run/typed-not-found")) as { typed: boolean }; |
| 140 | expect(run.typed).toBe(true); |
| 141 | }), |
| 142 | ); |
| 143 | }, |
| 144 | ); |