| 1 | import * as Alchemy from "alchemy"; |
| 2 | import * as AWS from "alchemy/AWS"; |
| 3 | import * as Test from "alchemy/Test/Bun"; |
| 4 | import { expect } from "bun:test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import * as HttpClient from "effect/http/HttpClient"; |
| 8 | import Stack from "../alchemy.run.ts"; |
| 9 | |
| 10 | const { test, beforeAll, afterAll, deploy, destroy } = Test.make({ |
| 11 | providers: AWS.providers(), |
| 12 | state: Alchemy.localState(), |
| 13 | }); |
| 14 | |
| 15 | const stack = beforeAll(deploy(Stack)); |
| 16 | afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack)); |
| 17 | |
| 18 | test( |
| 19 | "generates text through Bedrock", |
| 20 | Effect.gen(function* () { |
| 21 | const out = (yield* stack) as { url: string }; |
| 22 | const client = HttpClient.filterStatusOk(yield* HttpClient.HttpClient); |
| 23 | |
| 24 | // Fresh function URLs take a few seconds to start serving 200s. |
| 25 | const res = yield* client |
| 26 | .get(`${out.url}?prompt=${encodeURIComponent("Say pong.")}`) |
| 27 | .pipe( |
| 28 | Effect.retry({ |
| 29 | schedule: Schedule.exponential("1 second"), |
| 30 | times: 10, |
| 31 | }), |
| 32 | ); |
| 33 | const body = (yield* res.json) as { text: string; finishReason: string }; |
| 34 | expect(body.text.length).toBeGreaterThan(0); |
| 35 | }), |
| 36 | { timeout: 300_000 }, |
| 37 | ); |